OpenLB 1.7
Loading...
Searching...
No Matches
superLpNorm2D.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_2D_HH
25#define SUPER_LP_NORM_2D_HH
26
27#include "superLpNorm2D.h"
28#include "blockLpNorm2D.h"
33
34namespace olb {
35
36template <typename T, typename W, int P>
38 FunctorPtr<SuperIndicatorF2D<T>>&& indicatorF)
39 : SuperF2D<T,W>(f->getSuperStructure(),1),
40 _f(std::move(f)),
41 _indicatorF(std::move(indicatorF))
42{
43 OLB_ASSERT(_f->getSourceDim() == _indicatorF->getSourceDim(),
44 "functor source dimension equals indicator source dimension");
45
46 this->getName() = "L" + std::to_string(P) + "Norm(" + _f->getName() + ")";
47
48 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
49
50 if ( _f->getBlockFSize() == load.size() &&
51 _indicatorF->getBlockFSize() == load.size() ) {
52 for (int iC = 0; iC < load.size(); ++iC) {
53 this->_blockF.emplace_back(
54 new BlockLpNorm2D<T,W,P>(_f->getBlockF(iC),
55 _indicatorF->getBlockIndicatorF(iC))
56 );
57 }
58 }
59}
60
61template <typename T, typename W, int P>
63 SuperGeometry<T,2>& geometry,
64 FunctorPtr<SuperIndicatorF2D<T>>&& indicatorF)
65 : SuperLpNorm2D(std::forward<decltype(f)>(f),
66 std::forward<decltype(indicatorF)>(indicatorF))
67{ }
68
69template <typename T, typename W, int P>
71 SuperGeometry<T,2>& geometry,
72 std::vector<int> materials)
73 : SuperLpNorm2D(std::forward<decltype(f)>(f),
74 geometry.getMaterialIndicator(std::move(materials)))
75{ }
76
77template <typename T, typename W, int P>
79 SuperGeometry<T,2>& geometry,
80 int material)
81 : SuperLpNorm2D(std::forward<decltype(f)>(f),
82 geometry.getMaterialIndicator(material))
83{ }
84
85template <typename T, typename W, int P>
86bool SuperLpNorm2D<T,W,P>::operator() (W output[], const int input[])
87{
89 CuboidGeometry2D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
90 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
91
92 output[0] = W(0);
93 W outputTmp[_f->getTargetDim()];
94 int inputTmp[3];
95
96 for (int iC = 0; iC < load.size(); ++iC) {
97 Cuboid2D<T>& cuboid = geometry.get(load.glob(iC));
98
99 const int nX = cuboid.getNx();
100 const int nY = cuboid.getNy();
101 const T weight = util::pow(cuboid.getDeltaR(), 2);
102
103 inputTmp[0] = load.glob(iC);
104
105 for (inputTmp[1] = 0; inputTmp[1] < nX; ++inputTmp[1]) {
106 for (inputTmp[2] = 0; inputTmp[2] < nY; ++inputTmp[2]) {
107 if (_indicatorF(inputTmp)) {
108 _f(outputTmp, inputTmp);
109 for (int iDim = 0; iDim < _f->getTargetDim(); ++iDim) {
110 output[0] = LpNormImpl<T,W,P>()(output[0], outputTmp[iDim], weight);
111 }
112 }
113 }
114 }
115 }
116
117#ifdef PARALLEL_MODE_MPI
118 if (P == 0) {
119 singleton::mpi().reduceAndBcast(output[0], MPI_MAX);
120 }
121 else {
122 singleton::mpi().reduceAndBcast(output[0], MPI_SUM);
123 }
124#endif
125
126 output[0] = LpNormImpl<T,W,P>().enclose(output[0]);
127
128 return true;
129}
130
131}
132
133#endif
Block level functor that returns the Lp norm over omega of the euklid norm of the input block functor...
A regular single 2D cuboid is the basic component of a 2D cuboid structure which defines the grid.
Definition cuboid2D.h:54
T getDeltaR() const
Read access to the distance of cuboid nodes.
Definition cuboid2D.hh:106
int getNx() const
Read access to cuboid width.
Definition cuboid2D.hh:112
int getNy() const
Read access to cuboid height.
Definition cuboid2D.hh:118
A cuboid structure represents the grid of a considered domain.
Cuboid2D< T > & get(int i)
Read and write access to the cuboids.
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,2> in general
std::vector< std::unique_ptr< BlockF2D< W > > > _blockF
Super functors may consist of several BlockF2D<W> derived functors.
SuperStructure< T, 2 > & getSuperStructure()
Representation of a statistic for a parallel 2D geometry.
Functor that returns the Lp norm over omega of the the euklid norm of the input functor.
bool operator()(W output[], const int input[]) override
has to be implemented for 'every' derived class
SuperLpNorm2D(FunctorPtr< SuperF2D< T, W > > &&f, FunctorPtr< SuperIndicatorF2D< T > > &&indicatorF)
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.