OpenLB 1.7
Loading...
Searching...
No Matches
superLpNorm3D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2017 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef SUPER_LP_NORM_3D_HH
25#define SUPER_LP_NORM_3D_HH
26
27#include "superLpNorm3D.h"
28#include "blockLpNorm3D.h"
34
35namespace olb {
36
37template <typename T, typename W, int P>
39 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF)
40 : SuperF3D<T,W>(f->getSuperStructure(),1),
41 _f(std::move(f)),
42 _indicatorF(std::move(indicatorF))
43{
44 OLB_ASSERT(_f->getSourceDim() == _indicatorF->getSourceDim(),
45 "functor source dimension equals indicator source dimension");
46
47 this->getName() = "L" + std::to_string(P) + "Norm(" + _f->getName() + ")";
48
49 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
50
51 if ( _f->getBlockFSize() == load.size() &&
52 _indicatorF->getBlockFSize() == load.size() ) {
53 for (int iC = 0; iC < load.size(); ++iC) {
54 this->_blockF.emplace_back(
55 new BlockLpNorm3D<T,W,P>(_f->getBlockF(iC),
56 _indicatorF->getBlockIndicatorF(iC))
57 );
58 }
59 }
60}
61
62template <typename T, typename W, int P>
64 SuperGeometry<T,3>& geometry,
65 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF)
66 : SuperLpNorm3D(std::forward<decltype(f)>(f),
67 std::forward<decltype(indicatorF)>(indicatorF))
68{ }
69
70template <typename T, typename W, int P>
72 SuperGeometry<T,3>& geometry,
73 std::vector<int> materials)
74 : SuperLpNorm3D(std::forward<decltype(f)>(f),
75 geometry.getMaterialIndicator(std::move(materials)))
76{ }
77
78template <typename T, typename W, int P>
80 SuperGeometry<T,3>& geometry,
81 int material)
82 : SuperLpNorm3D(std::forward<decltype(f)>(f),
83 geometry.getMaterialIndicator(material))
84{ }
85
86template <typename T, typename W, int P>
87bool SuperLpNorm3D<T,W,P>::operator() (W output[], const int input[])
88{
90 CuboidGeometry3D<T>& cGeometry = _f->getSuperStructure().getCuboidGeometry();
91 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
92
93 output[0] = W(0);
94 W outputTmp[_f->getTargetDim()];
95 int inputTmp[_f->getSourceDim()];
96
97 for (int iC = 0; iC < load.size(); ++iC) {
98 Cuboid3D<T>& cuboid = cGeometry.get(load.glob(iC));
99
100 const int nX = cuboid.getNx();
101 const int nY = cuboid.getNy();
102 const int nZ = cuboid.getNz();
103 const T weight = util::pow(cuboid.getDeltaR(), 3);
104
105 inputTmp[0] = load.glob(iC);
106
107 for (inputTmp[1] = 0; inputTmp[1] < nX; ++inputTmp[1]) {
108 for (inputTmp[2] = 0; inputTmp[2] < nY; ++inputTmp[2]) {
109 for (inputTmp[3] = 0; inputTmp[3] < nZ; ++inputTmp[3]) {
110 if (_indicatorF(inputTmp)) {
111 _f(outputTmp, inputTmp);
112 for (int iDim = 0; iDim < _f->getTargetDim(); ++iDim) {
113 output[0] = LpNormImpl<T,W,P>()(output[0], outputTmp[iDim], weight);
114 }
115 }
116 }
117 }
118 }
119 }
120
121#ifdef PARALLEL_MODE_MPI
122 if (P == 0) {
123 singleton::mpi().reduceAndBcast(output[0], MPI_MAX);
124 }
125 else {
126 singleton::mpi().reduceAndBcast(output[0], MPI_SUM);
127 }
128#endif
129
130 output[0] = LpNormImpl<T,W,P>().enclose(output[0]);
131
132 return true;
133}
134
135}
136
137#endif
Block level functor that returns the Lp norm over omega of the euklid norm of the input block functor...
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
T getDeltaR() const
Read only access to the distance of cuboid nodes.
Definition cuboid3D.hh:141
int getNz() const
Read access to cuboid depth.
Definition cuboid3D.hh:159
int getNy() const
Read access to cuboid height.
Definition cuboid3D.hh:153
int getNx() const
Read access to cuboid width.
Definition cuboid3D.hh:147
A cuboid geometry represents a voxel mesh.
Cuboid3D< T > & get(int iC)
Read and write access to a single cuboid.
Smart pointer for managing the various ways of passing functors around.
Definition functorPtr.h:60
std::string & getName()
read and write access to name
Definition genericF.hh:51
Base class for all LoadBalancer.
int glob(int loc) const
represents all functors that operate on a SuperStructure<T,3> in general
SuperStructure< T, 3 > & getSuperStructure()
std::vector< std::unique_ptr< BlockF3D< W > > > _blockF
Super functors may consist of several BlockF3D<W> derived functors.
Representation of a statistic for a parallel 2D geometry.
Base indicator functor (discrete)
Functor that returns the Lp norm over omega of the the euklid norm of the input functor.
SuperLpNorm3D(FunctorPtr< SuperF3D< T, W > > &&f, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
bool operator()(W output[], const int input[]) override
has to be implemented for 'every' derived class
virtual void communicate()
void reduceAndBcast(T &reductVal, MPI_Op op, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Reduction operation, followed by a broadcast.
MpiManager & mpi()
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112
Top level namespace for all of OpenLB.
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45
Lp norm functor implementation details specific to the P parameter.
Representation of a parallel 2D geometry – header file.