OpenLB 1.7
Loading...
Searching...
No Matches
superIntegralF3D.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_3D_HH
25#define SUPER_INTEGRAL_F_3D_HH
26
27#include "utilities/omath.h"
28#include <vector>
29
30#include "superIntegralF3D.h"
31#include "blockIntegralF3D.h"
34
35namespace olb {
36
37
38template <typename T, typename W>
40 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF)
41 : SuperF3D<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 BlockSum3D<T,W>(_f->getBlockF(iC),
54 _indicatorF->getBlockIndicatorF(iC))
55 );
56 }
57 }
58}
59
60template <typename T, typename W>
62 SuperGeometry<T,3>& superGeometry,
63 const int material)
64 : SuperSum3D(
65 std::forward<decltype(f)>(f),
66 superGeometry.getMaterialIndicator(material))
67{ }
68
69template <typename T, typename W>
70bool SuperSum3D<T,W>::operator() (W output[], const int input[])
71{
73 CuboidGeometry3D<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 Cuboid3D<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 for (inputTmp[3] = 0; inputTmp[3] < cuboid.getNz(); ++inputTmp[3]) {
91 if (_indicatorF(inputTmp)) {
92 _f(outputTmp,inputTmp);
93 for (int i = 0; i < _f->getTargetDim(); ++i) {
94 output[i] += outputTmp[i];
95 }
96 voxels += 1;
97 }
98 }
99 }
100 }
101 }
102 output[_f->getTargetDim()] = voxels;
103 }
104 else {
105 for (int iC = 0; iC < load.size(); ++iC) {
106 this->getBlockF(iC)(output, input);
107 }
108 }
109
110#ifdef PARALLEL_MODE_MPI
111 for (int i = 0; i < this->getTargetDim(); ++i) {
112 singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
113 }
114#endif
115 return true;
116}
117
118
119template <typename T, typename W>
121 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF)
122 : SuperF3D<T,W>(f->getSuperStructure(), f->getTargetDim()),
123 _f(std::move(f)),
124 _indicatorF(std::move(indicatorF))
125{
126 this->getName() = "Integral("+_f->getName()+")";
127
128 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
129
130 if ( _f->getBlockFSize() == load.size() &&
131 _indicatorF->getBlockFSize() == load.size() ) {
132 for (int iC = 0; iC < load.size(); ++iC) {
133 this->_blockF.emplace_back(
134 new BlockIntegral3D<T,W>(_f->getBlockF(iC),
135 _indicatorF->getBlockIndicatorF(iC))
136 );
137 }
138 }
139}
140
141template <typename T, typename W>
143 SuperGeometry<T,3>& superGeometry,
144 const int material)
146 std::forward<decltype(f)>(f),
147 superGeometry.getMaterialIndicator(material))
148{ }
149
150template <typename T, typename W>
151bool SuperIntegral3D<T,W>::operator() (W output[], const int input[])
152{
154 CuboidGeometry3D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
155 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
156
157 for (int i = 0; i < this->getTargetDim(); ++i) {
158 output[i] = W(0);
159 }
160
161 if (this->_blockF.empty()) {
162 W outputTmp[_f->getTargetDim()];
163 int inputTmp[_f->getSourceDim()];
164
165 for (int iC = 0; iC < load.size(); ++iC) {
166 const Cuboid3D<T> cuboid = geometry.get(load.glob(iC));
167 const W weight = util::pow(cuboid.getDeltaR(), 3);
168 inputTmp[0] = load.glob(iC);
169 for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) {
170 for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) {
171 for (inputTmp[3] = 0; inputTmp[3] < cuboid.getNz(); ++inputTmp[3]) {
172 if (_indicatorF(inputTmp)) {
173 _f(outputTmp,inputTmp);
174 for (int i = 0; i < this->getTargetDim(); ++i) {
175 output[i] += outputTmp[i] * weight;
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183 else {
184 for (int iC = 0; iC < load.size(); ++iC) {
185 this->getBlockF(iC)(output, input);
186 }
187 }
188
189#ifdef PARALLEL_MODE_MPI
190 for (int i = 0; i < this->getTargetDim(); ++i) {
191 singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
192 }
193#endif
194 return true;
195}
196
197
198}
199
200#endif
BlockIntegral3D integrates f on a indicated subset.
BlockSum3D sums all components of f over a indicated subset.
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)
SuperIntegral3D integrates f on a indicated subset.
bool operator()(W output[], const int input[]) override
SuperIntegral3D(FunctorPtr< SuperF3D< T, W > > &&f, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
Constructor for integrating f on a indicated subset.
virtual void communicate()
SuperSum3D sums all components of f over a indicated subset.
SuperSum3D(FunctorPtr< SuperF3D< T, W > > &&f, FunctorPtr< SuperIndicatorF3D< 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()
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.