OpenLB 1.7
Loading...
Searching...
No Matches
superPlaneIntegralF2D.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_PLANE_INTEGRAL_F_2D_HH
25#define SUPER_PLANE_INTEGRAL_F_2D_HH
26
31
32namespace olb {
33
34
35template<typename T>
37{
38 Vector<int,3> latticeR;
39 //get nearest lattice point
40 if ( _geometry.getCuboidGeometry().getFloorLatticeR(physR, latticeR) ) {
41 const int& iX = latticeR[1];
42 const int& iY = latticeR[2];
43
44 // interpolation is possible iff all neighbours are within the indicated subset
45 return _integrationIndicatorF->operator()( iC, iX, iY )
46 && _integrationIndicatorF->operator()(iC, iX, iY+1)
47 && _integrationIndicatorF->operator()(iC, iX+1, iY )
48 && _integrationIndicatorF->operator()(iC, iX+1, iY+1);
49 }
50 else {
51 return false;
52 }
53}
54
55template<typename T>
58 SuperGeometry<T,2>& geometry,
59 const HyperplaneLattice2D<T>& hyperplaneLattice,
60 FunctorPtr<SuperIndicatorF2D<T>>&& integrationIndicator,
61 FunctorPtr<IndicatorF1D<T>>&& subplaneIndicator,
63 : SuperF2D<T>(f->getSuperStructure(), 2 + f->getTargetDim()),
64 _geometry(geometry),
65 _f(std::move(f)),
66 _integrationIndicatorF(std::move(integrationIndicator)),
67 _subplaneIndicatorF(std::move(subplaneIndicator)),
68 _reductionF(*_f,
69 hyperplaneLattice,
71 mode),
72 _origin(hyperplaneLattice.getHyperplane().origin),
73 _u(hyperplaneLattice.getVectorU()),
74 _normal(hyperplaneLattice.getHyperplane().normal)
75{
76 this->getName() = "SuperPlaneIntegralF2D";
77
79 _u = normalize(_u);
80
81 for ( const std::tuple<int,int>& pos : _reductionF.getRankLocalSubplane() ) {
82 const int& i = std::get<0>(pos);
83 const int& iC = std::get<1>(pos);
84 const Vector<T,2> physR = _reductionF.getPhysR(i);
85 if (isToBeIntegrated(physR, iC)) {
86 // check if interpolated hyperplane is to be restricted further
87 // e.g. using IndicatorCircle2D
88 if ( _subplaneIndicatorF ) {
89 // determine physical coordinates relative to original hyperplane origin
90 // [!] different from _reductionF._origin in the general case.
91 const Vector<T,2> physRelativeToOrigin = physR - _origin;
92 const T physOnHyperplane = physRelativeToOrigin * _u;
93
94 if ( _subplaneIndicatorF->operator()(&physOnHyperplane) ) {
95 _rankLocalSubplane.emplace_back(i);
96 }
97 }
98 else {
99 // plane is not restricted further
100 _rankLocalSubplane.emplace_back(i);
101 }
102 }
103 }
104}
105
106template<typename T>
109 SuperGeometry<T,2>& geometry,
110 const Hyperplane2D<T>& hyperplane,
111 FunctorPtr<SuperIndicatorF2D<T>>&& integrationIndicator,
112 FunctorPtr<IndicatorF1D<T>>&& subplaneIndicator,
115 std::forward<decltype(f)>(f),
116 geometry,
117 HyperplaneLattice2D<T>(geometry.getCuboidGeometry(), hyperplane),
118 std::forward<decltype(integrationIndicator)>(integrationIndicator),
119 std::forward<decltype(subplaneIndicator)>(subplaneIndicator),
120 mode)
121{ }
122
123template<typename T>
126 SuperGeometry<T,2>& geometry,
127 const Hyperplane2D<T>& hyperplane,
128 FunctorPtr<SuperIndicatorF2D<T>>&& integrationIndicator,
131 std::forward<decltype(f)>(f),
132 geometry,
133 hyperplane,
134 std::forward<decltype(integrationIndicator)>(integrationIndicator),
135 nullptr,
136 mode)
137{ }
138
139template<typename T>
142 SuperGeometry<T,2>& geometry,
143 const Vector<T,2>& origin, const Vector<T,2>& u,
144 std::vector<int> materials,
147 std::forward<decltype(f)>(f),
148 geometry,
149 Hyperplane2D<T>().originAt(origin).parallelTo(u),
150 geometry.getMaterialIndicator(std::forward<decltype(materials)>(materials)),
151 mode)
152{ }
153
154template<typename T>
157 SuperGeometry<T,2>& geometry,
158 const Vector<T,2>& origin, const Vector<T,2>& u,
161 std::forward<decltype(f)>(f),
162 geometry,
163 origin, u,
164 std::vector<int>(1,1),
165 mode)
166{ }
167
168
169template<typename T>
170bool SuperPlaneIntegralF2D<T>::operator()(T output[], const int input[])
171{
172 this->getSuperStructure().communicate();
173
174 _reductionF.update();
175
176 const int flowDim = _reductionF.getTargetDim();
177
178 std::vector<T> flow(flowDim,0.);
179
180 for ( int pos : _rankLocalSubplane ) {
181 T outputTmp[flowDim];
182 _reductionF(outputTmp, pos);
183
184 for ( int j = 0; j < flowDim; j++ ) {
185 flow[j] += outputTmp[j];
186 }
187 }
188
189 int vox = _rankLocalSubplane.size();
190
191#ifdef PARALLEL_MODE_MPI
192 for ( int j = 0; j < flowDim; j++ ) {
193 singleton::mpi().reduceAndBcast(flow[j], MPI_SUM);
194 }
195 singleton::mpi().reduceAndBcast(vox, MPI_SUM);
196#endif
197
198 const T h = _reductionF.getPhysSpacing();
199
200 switch ( flowDim ) {
201 case 1: {
202 output[0] = flow[0] * h;
203 break;
204 }
205 case 2: {
206 output[0] = (h * Vector<T,2>(flow)) * _normal;
207 break;
208 }
209 }
210
211 // area
212 output[1] = vox * h;
213 // write flow to output[2..]
214 std::copy_n(flow.cbegin(), flowDim, &output[2]);
215
216 return true;
217}
218
219
220}
221
222#endif
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 (i.e. a line lattice).
IndicatorF1D is an application from .
represents all functors that operate on a SuperStructure<T,2> in general
Representation of a statistic for a parallel 2D geometry.
Surface integral of a subset of a interpolated hyperplane.
FunctorPtr< IndicatorF1D< T > > _subplaneIndicatorF
Indicator describing the relevant subset of the interpolated hyperplane.
BlockReduction2D1D< T > _reductionF
Functor describing line to be interpolated and integrated.
Vector< T, 2 > _normal
Orthogonal vector to _u.
SuperPlaneIntegralF2D(FunctorPtr< SuperF2D< T > > &&f, SuperGeometry< T, 2 > &geometry, const HyperplaneLattice2D< T > &hyperplaneLattice, FunctorPtr< SuperIndicatorF2D< T > > &&integrationIndicator, FunctorPtr< IndicatorF1D< T > > &&subplaneIndicator, BlockDataReductionMode mode=BlockDataReductionMode::Analytical)
Primary constructor.
std::vector< int > _rankLocalSubplane
Subset of the discrete line points given by _reductionF as indicated by _integrationIndicatorF.
bool isToBeIntegrated(const Vector< T, 2 > &physR, int iC)
This is determined using the _integrationIndicatorF indicated subset of the 2d hyperplane reduced by ...
Vector< T, 2 > _u
Direction vector u as given by hyperplane definition, normalized to h.
bool operator()(T output[], const int input[]) override
Returns the line integral in the following structure:
Vector< T, 2 > _origin
Origin vector as given by hyperplane definition, (0,0) in respect to the subplane indicator _subplane...
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.
Groups all include files for the directory genericFunctions.
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 line embedded in 2D space.