OpenLB 1.7
Loading...
Searching...
No Matches
superPlaneIntegralF3D.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_PLANE_INTEGRAL_F_3D_HH
25#define SUPER_PLANE_INTEGRAL_F_3D_HH
26
30
31namespace olb {
32
33
34template<typename T>
36{
37 Vector<int,4> latticeR;
38 //get nearest lattice point
39 if ( _geometry.getCuboidGeometry().getFloorLatticeR(physR, latticeR) ) {
40 const int& iX = latticeR[1];
41 const int& iY = latticeR[2];
42 const int& iZ = latticeR[3];
43
44 // interpolation is possible iff all neighbours are within the indicated subset
45 return _integrationIndicatorF->operator()( iC, iX, iY, iZ )
46 && _integrationIndicatorF->operator()(iC, iX, iY, iZ+1)
47 && _integrationIndicatorF->operator()(iC, iX, iY+1, iZ )
48 && _integrationIndicatorF->operator()(iC, iX, iY+1, iZ+1)
49 && _integrationIndicatorF->operator()(iC, iX+1, iY, iZ )
50 && _integrationIndicatorF->operator()(iC, iX+1, iY, iZ+1)
51 && _integrationIndicatorF->operator()(iC, iX+1, iY+1, iZ )
52 && _integrationIndicatorF->operator()(iC, iX+1, iY+1, iZ+1);
53 }
54 else {
55 return false;
56 }
57}
58
59template<typename T>
62 SuperGeometry<T,3>& geometry,
63 const HyperplaneLattice3D<T>& hyperplaneLattice,
64 FunctorPtr<SuperIndicatorF3D<T>>&& integrationIndicator,
65 FunctorPtr<IndicatorF2D<T>>&& subplaneIndicator,
67 : SuperF3D<T>(f->getSuperStructure(), 2 + f->getTargetDim()),
68 _geometry(geometry),
69 _f(std::move(f)),
70 _integrationIndicatorF(std::move(integrationIndicator)),
71 _subplaneIndicatorF(std::move(subplaneIndicator)),
72 _reductionF(*_f,
73 hyperplaneLattice,
75 mode),
76 _origin(hyperplaneLattice.getHyperplane().origin),
77 _u(hyperplaneLattice.getVectorU()),
78 _v(hyperplaneLattice.getVectorV()),
79 _normal(hyperplaneLattice.getHyperplane().normal)
80{
81 this->getName() = "SuperPlaneIntegralF3D";
82
84 _u = normalize(_u);
85 _v = normalize(_v);
86
87 for ( const std::tuple<int,int,int>& pos : _reductionF.getRankLocalSubplane() ) {
88 const int& i = std::get<0>(pos);
89 const int& j = std::get<1>(pos);
90 const int& iC = std::get<2>(pos);
91 const Vector<T,3> physR = _reductionF.getPhysR(i, j);
92 if (isToBeIntegrated(physR, iC)) {
93 // check if interpolated hyperplane is to be restricted further
94 // e.g. using IndicatorCircle2D
95 if ( _subplaneIndicatorF ) {
96 // determine physical coordinates relative to original hyperplane origin
97 // [!] different from _reductionF._origin in the general case.
98 const Vector<T,3> physRelativeToOrigin = physR - _origin;
99 const T physOnHyperplane[2] {
100 physRelativeToOrigin * _u,
101 physRelativeToOrigin * _v
102 };
103
104 if ( _subplaneIndicatorF->operator()(physOnHyperplane) ) {
105 _rankLocalSubplane.emplace_back(i, j);
106 }
107 }
108 else {
109 // plane is not restricted further
110 _rankLocalSubplane.emplace_back(i, j);
111 }
112 }
113 }
114}
115
116template<typename T>
119 SuperGeometry<T,3>& geometry,
120 const Hyperplane3D<T>& hyperplane,
121 FunctorPtr<SuperIndicatorF3D<T>>&& integrationIndicator,
122 FunctorPtr<IndicatorF2D<T>>&& subplaneIndicator,
125 std::forward<decltype(f)>(f),
126 geometry,
127 HyperplaneLattice3D<T>(geometry.getCuboidGeometry(), hyperplane),
128 std::forward<decltype(integrationIndicator)>(integrationIndicator),
129 std::forward<decltype(subplaneIndicator)>(subplaneIndicator),
130 mode)
131{ }
132
133template<typename T>
136 SuperGeometry<T,3>& geometry,
137 const Hyperplane3D<T>& hyperplane,
138 FunctorPtr<SuperIndicatorF3D<T>>&& integrationIndicator,
141 std::forward<decltype(f)>(f),
142 geometry,
143 hyperplane,
144 std::forward<decltype(integrationIndicator)>(integrationIndicator),
145 nullptr,
146 mode)
147{ }
148
149template<typename T>
152 SuperGeometry<T,3>& geometry,
153 const Vector<T,3>& origin, const Vector<T,3>& u, const Vector<T,3>& v,
154 std::vector<int> materials,
157 std::forward<decltype(f)>(f),
158 geometry,
159 Hyperplane3D<T>().originAt(origin).spannedBy(u, v),
160 geometry.getMaterialIndicator(std::forward<decltype(materials)>(materials)),
161 mode)
162{ }
163
164template<typename T>
167 SuperGeometry<T,3>& geometry,
168 const Vector<T,3>& origin, const Vector<T,3>& u, const Vector<T,3>& v,
171 std::forward<decltype(f)>(f),
172 geometry,
173 origin, u, v,
174 std::vector<int>(1,1),
175 mode)
176{ }
177
178template<typename T>
181 SuperGeometry<T,3>& geometry,
182 const Vector<T,3>& origin, const Vector<T,3>& normal,
183 std::vector<int> materials,
186 std::forward<decltype(f)>(f),
187 geometry,
188 Hyperplane3D<T>().originAt(origin).normalTo(normal),
189 geometry.getMaterialIndicator(std::forward<decltype(materials)>(materials)),
190 mode)
191{ }
192
193template<typename T>
196 SuperGeometry<T,3>& geometry,
197 const Vector<T,3>& origin, const Vector<T,3>& normal,
200 std::forward<decltype(f)>(f),
201 geometry,
202 origin, normal,
203 std::vector<int>(1,1),
204 mode)
205{ }
206
207template<typename T>
210 SuperGeometry<T,3>& geometry,
211 const Vector<T,3>& normal,
212 std::vector<int> materials,
215 std::forward<decltype(f)>(f),
216 geometry,
217 Hyperplane3D<T>()
218 .centeredIn(geometry.getCuboidGeometry().getMotherCuboid())
219 .normalTo(normal),
220 geometry.getMaterialIndicator(std::forward<decltype(materials)>(materials)),
221 mode)
222{ }
223
224template<typename T>
227 SuperGeometry<T,3>& geometry,
228 const Vector<T,3>& normal,
231 std::forward<decltype(f)>(f),
232 geometry,
233 normal,
234 std::vector<int>(1,1),
235 mode)
236{ }
237
238template<typename T>
241 SuperGeometry<T,3>& geometry,
242 const IndicatorCircle3D<T>& circle, std::vector<int> materials,
245 std::forward<decltype(f)>(f),
246 geometry,
247 Hyperplane3D<T>().originAt(circle.getCenter()).normalTo(circle.getNormal()),
248 geometry.getMaterialIndicator(std::forward<std::vector<int>>(materials)),
249 std::unique_ptr<IndicatorF2D<T>>(new IndicatorCircle2D<T>({0,0}, circle.getRadius())),
250mode)
251{ }
252
253template<typename T>
256 SuperGeometry<T,3>& geometry,
257 const IndicatorCircle3D<T>& circle,
260 std::forward<decltype(f)>(f),
261 geometry,
262 circle,
263 std::vector<int>(1,1),
264 mode)
265{ }
266
267template<typename T>
268bool SuperPlaneIntegralF3D<T>::operator()(T output[], const int input[])
269{
270 this->getSuperStructure().communicate();
271
272 _reductionF.update();
273
274 const int flowDim = _reductionF.getTargetDim();
275
276 std::vector<T> flow(flowDim,0.);
277
278 for ( std::tuple<int,int>& pos : _rankLocalSubplane ) {
279 T outputTmp[flowDim];
280 const int inputTmp[2] { std::get<0>(pos), std::get<1>(pos) };
281
282 _reductionF(outputTmp, inputTmp);
283
284 for ( int j = 0; j < flowDim; j++ ) {
285 flow[j] += outputTmp[j];
286 }
287 }
288
289 int vox = _rankLocalSubplane.size();
290
291#ifdef PARALLEL_MODE_MPI
292 for ( int j = 0; j < flowDim; j++ ) {
293 singleton::mpi().reduceAndBcast(flow[j], MPI_SUM);
294 }
295 singleton::mpi().reduceAndBcast(vox, MPI_SUM);
296#endif
297
298 const T h = _reductionF.getPhysSpacing();
299
300 switch ( flowDim ) {
301 case 1: {
302 output[0] = flow[0] * h * h;
303 break;
304 }
305 case 3: {
306 output[0] = (h*h * Vector<T,3>(flow)) * _normal;
307 break;
308 }
309 }
310
311 // area
312 output[1] = vox * h * h;
313 // write flow to output[2..]
314 std::copy_n(flow.cbegin(), flowDim, &output[2]);
315
316 return true;
317}
318
319
320}
321
322#endif
Groups all include files for the directory genericFunctions.
Smart pointer for managing the various ways of passing functors around.
Definition functorPtr.h:60
int getTargetDim() const
read only access to member variable _n
Definition genericF.hh:45
std::string & getName()
read and write access to name
Definition genericF.hh:51
Parametrization of a hyperplane lattice.
indicator function for a 2D circle
indicator function for a 3D circle
IndicatorF2D is an application from .
represents all functors that operate on a SuperStructure<T,3> in general
Representation of a statistic for a parallel 2D geometry.
Base indicator functor (discrete)
Surface integral of a subset of a interpolated hyperplane.
SuperPlaneIntegralF3D(FunctorPtr< SuperF3D< T > > &&f, SuperGeometry< T, 3 > &geometry, const HyperplaneLattice3D< T > &hyperplaneLattice, FunctorPtr< SuperIndicatorF3D< T > > &&integrationIndicator, FunctorPtr< IndicatorF2D< T > > &&subplaneIndicator, BlockDataReductionMode mode=BlockDataReductionMode::Analytical)
Primary constructor.
bool operator()(T output[], const int input[]) override
Returns the plane integral in the following structure:
BlockReduction3D2D< T > _reductionF
Functor describing plane to be interpolated and integrated.
Vector< T, 3 > _v
Span vector v as given by hyperplane definition, normalized to h.
Vector< T, 3 > _origin
Origin vector as given by hyperplane definition, (0,0) in respect to the subplane indicator _subplane...
FunctorPtr< IndicatorF2D< T > > _subplaneIndicatorF
Indicator describing the relevant subset of the interpolated hyperplane.
Vector< T, 3 > _u
Span vector u as given by hyperplane definition, normalized to h.
std::vector< std::tuple< int, int > > _rankLocalSubplane
Subset of the discrete plane points given by _reductionF as indicated by _integrationIndicatorF.
Vector< T, 3 > _normal
Orthogonal vector to _u and _v.
bool isToBeIntegrated(const Vector< T, 3 > &physR, int iC)
This is determined using the _integrationIndicatorF indicated subset of the 2d plane reduced by _redu...
Plain old scalar vector.
Definition vector.h:47
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.
BlockDataReductionMode
Mode of reducing block data from given, possibly higher dimensional data.
constexpr Vector< T, D > normalize(const ScalarVector< T, D, IMPL > &a, T scale=T{1})
Definition vector.h:245
BlockDataSyncMode
Mode of synchronizing functor block data between processes.
@ None
optimize for usage in e.g. SuperLatticeFlux3D, only rank-local data available
Definition of a analytical 2D plane embedded in 3D space.