OpenLB 1.7
Loading...
Searching...
No Matches
superIntegralF2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2018 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_INTEGRAL_F_2D_HH
25#define SUPER_INTEGRAL_F_2D_HH
26
27#include <cmath>
28#include <vector>
29
30#include "superIntegralF2D.h"
31#include "blockIntegralF2D.h"
34
35namespace olb {
36
37
38template <typename T, typename W>
40 FunctorPtr<SuperIndicatorF2D<T>>&& indicatorF)
41 : SuperF2D<T,W>(f->getSuperStructure(), f->getTargetDim()+1),
42 _f(std::move(f)),
43 _indicatorF(std::move(indicatorF))
44{
45 this->getName() = "Sum("+_f->getName()+")";
46
47 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
48
49 if ( _f->getBlockFSize() == load.size() &&
50 _indicatorF->getBlockFSize() == load.size() ) {
51 for (int iC = 0; iC < load.size(); ++iC) {
52 this->_blockF.emplace_back(
53 new BlockSum2D<T,W>(_f->getBlockF(iC),
54 _indicatorF->getBlockIndicatorF(iC))
55 );
56 }
57 }
58}
59
60template <typename T, typename W>
62 SuperGeometry<T,2>& superGeometry,
63 const int material)
64 : SuperSum2D(
65 std::forward<decltype(f)>(f),
66 superGeometry.getMaterialIndicator(material))
67{ }
68
69template <typename T, typename W>
70bool SuperSum2D<T,W>::operator() (W output[], const int input[])
71{
73 CuboidGeometry2D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
74 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
75
76 for (int i = 0; i < this->getTargetDim(); ++i) {
77 output[i] = W(0);
78 }
79
80 if (this->_blockF.empty()) {
81 W outputTmp[_f->getTargetDim()];
82 int inputTmp[_f->getSourceDim()];
83 std::size_t voxels(0);
84
85 for (int iC = 0; iC < load.size(); ++iC) {
86 const Cuboid2D<T> cuboid = geometry.get(load.glob(iC));
87 inputTmp[0] = load.glob(iC);
88 for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) {
89 for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) {
90 if (_indicatorF(inputTmp)) {
91 _f(outputTmp,inputTmp);
92 for (int i = 0; i < _f->getTargetDim(); ++i) {
93 output[i] += outputTmp[i];
94 }
95 voxels += 1;
96 }
97 }
98 }
99 }
100 output[_f->getTargetDim()] = voxels;
101 }
102 else {
103 for (int iC = 0; iC < load.size(); ++iC) {
104 this->getBlockF(iC)(output, input);
105 }
106 }
107
108#ifdef PARALLEL_MODE_MPI
109 for (int i = 0; i < this->getTargetDim(); ++i) {
110 singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
111 }
112#endif
113 return true;
114}
115
116
117template <typename T, typename W>
119 FunctorPtr<SuperIndicatorF2D<T>>&& indicatorF)
120 : SuperF2D<T,W>(f->getSuperStructure(), f->getTargetDim()),
121 _f(std::move(f)),
122 _indicatorF(std::move(indicatorF))
123{
124 this->getName() = "Integral("+_f->getName()+")";
125
126 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
127
128 if ( _f->getBlockFSize() == load.size() &&
129 _indicatorF->getBlockFSize() == load.size() ) {
130 for (int iC = 0; iC < load.size(); ++iC) {
131 this->_blockF.emplace_back(
132 new BlockIntegral2D<T,W>(_f->getBlockF(iC),
133 _indicatorF->getBlockIndicatorF(iC))
134 );
135 }
136 }
137}
138
139template <typename T, typename W>
141 SuperGeometry<T,2>& superGeometry,
142 const int material)
144 std::forward<decltype(f)>(f),
145 superGeometry.getMaterialIndicator(material))
146{ }
147
148template <typename T, typename W>
149bool SuperIntegral2D<T,W>::operator() (W output[], const int input[])
150{
152 CuboidGeometry2D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
153 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
154
155 for (int i = 0; i < this->getTargetDim(); ++i) {
156 output[i] = W(0);
157 }
158
159 if (this->_blockF.empty()) {
160 W outputTmp[_f->getTargetDim()];
161 int inputTmp[_f->getSourceDim()];
162
163 for (int iC = 0; iC < load.size(); ++iC) {
164 const Cuboid2D<T> cuboid = geometry.get(load.glob(iC));
165 const W weight = pow(cuboid.getDeltaR(), 2);
166 inputTmp[0] = load.glob(iC);
167 for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) {
168 for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) {
169 if (_indicatorF(inputTmp)) {
170 _f(outputTmp,inputTmp);
171 for (int i = 0; i < this->getTargetDim(); ++i) {
172 output[i] += outputTmp[i] * weight;
173 }
174 }
175 }
176 }
177 }
178 }
179 else {
180 for (int iC = 0; iC < load.size(); ++iC) {
181 this->getBlockF(iC)(output, input);
182 }
183 }
184
185#ifdef PARALLEL_MODE_MPI
186 for (int i = 0; i < this->getTargetDim(); ++i) {
187 singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
188 }
189#endif
190 return true;
191}
192
193
194}
195
196#endif
BlockIntegral2D integrates f on a indicated subset.
BlockSum2D sums all components of f over a indicated subset.
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.
SuperIntegral2D integrates f on a indicated subset.
bool operator()(W output[], const int input[]) override
SuperIntegral2D(FunctorPtr< SuperF2D< T, W > > &&f, FunctorPtr< SuperIndicatorF2D< T > > &&indicatorF)
Constructor for integrating f on a indicated subset.
virtual void communicate()
SuperSum2D sums all components of f over a indicated subset.
SuperSum2D(FunctorPtr< SuperF2D< T, W > > &&f, FunctorPtr< SuperIndicatorF2D< T > > &&indicatorF)
Constructor for summing f on a indicated subset.
void reduceAndBcast(T &reductVal, MPI_Op op, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Reduction operation, followed by a broadcast.
MpiManager & mpi()
Top level namespace for all of OpenLB.