24#ifndef BLOCK_REDUCTION_3D2D_HH
25#define BLOCK_REDUCTION_3D2D_HH
41void BlockReduction3D2D<T>::updateBlockAnalytical(BlockData<2,T,T>& block)
43 AnalyticalFfromSuperF3D<T> analyticalF(*_f);
45 for ( std::tuple<int,int,int>& pos : _rankLocalSubplane ) {
46 const int& iX = std::get<0>(pos);
47 const int& iY = std::get<1>(pos);
48 const Vector<T,3> physR = this->getPhysR(iX, iY);
50 for (
int iSize = 0; iSize < _f->getTargetDim(); ++iSize ) {
51 block.get({iX, iY}, iSize) = T();
54 T output[_f->getTargetDim()];
55 const T input[3] { physR[0], physR[1], physR[2] };
57 if (analyticalF(output, input)) {
58 for (
int iSize = 0; iSize < _f->getTargetDim(); ++iSize ) {
59 block.get({iX, iY}, iSize) += output[iSize];
66void BlockReduction3D2D<T>::updateBlockDiscrete(BlockData<2,T,T>& block)
68 CuboidGeometry3D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
70 for ( std::tuple<int,int,int>& pos : _rankLocalSubplane ) {
71 const int& iX = std::get<0>(pos);
72 const int& iY = std::get<1>(pos);
73 const int& iC = std::get<2>(pos);
74 const Vector<T,3> physR = this->getPhysR(iX, iY);
76 for (
int iSize = 0; iSize < _f->getTargetDim(); ++iSize ) {
77 block.get({iX, iY}, iSize) = T();
80 T output[_f->getTargetDim()];
81 int input[4] { iC, 0, 0, 0 };
82 geometry.get(iC).getLatticeR(&input[1], physR);
84 if (_f(output, input)) {
85 for (
int iSize = 0; iSize < _f->getTargetDim(); ++iSize ) {
86 block.get({iX, iY}, iSize) += output[iSize];
99 BlockDataF2D<T,T>(lattice.getNx(), lattice.getNy(), f->getTargetDim()),
102 _reductionMode(reductionMode)
104 this->
getName() =
"planeReduction(" + _f->getName() +
")";
109 const bool spansAxisPlane = hyperplane.
isXYPlane() ||
113 if ( !spansAxisPlane ||
117 clerr <<
"Given hyperplane is not trivially discretizable. "
118 <<
"Use BlockDataReductionMode::Analytical instead."
137 std::forward<decltype(f)>(f),
151 std::forward<decltype(f)>(f),
153 hyperplane, resolution),
163 std::forward<decltype(f)>(f),
165 resolution, syncMode)
174 std::forward<decltype(f)>(f),
176 resolution, syncMode)
185 std::forward<decltype(f)>(f),
187 .centeredIn(f->getSuperStructure().getCuboidGeometry().getMotherCuboid())
189 resolution, syncMode)
198 _rankLocalSubplane.clear();
200 for (
int iX = 0; iX < this->getNx(); ++iX ) {
201 for (
int iY = 0; iY < this->getNy(); ++iY ) {
208 if ( geometry.
getC(physR, iC) ) {
210 _rankLocalSubplane.emplace_back(iX, iY, iC);
220 _f->getSuperStructure().communicate();
222#ifdef PARALLEL_MODE_MPI
223 std::unique_ptr<BlockData<2,T,T>> localBlockData(
224 new BlockData<2,T,T>({{this->getNx(), this->getNy()}, 0}, _f->getTargetDim()));
226 switch ( _reductionMode ) {
228 updateBlockAnalytical(*localBlockData);
231 updateBlockDiscrete(*localBlockData);
235 switch ( _syncMode ) {
245 delete this->_blockData;
247 this->_blockData = localBlockData.release();
248 this->_owning =
true;
252 switch ( _reductionMode ) {
254 updateBlockAnalytical(this->getBlockData());
257 updateBlockDiscrete(this->getBlockData());
266 return *this->_blockData;
272 return this->_rankLocalSubplane;
BlockDataF2D can store data of any BlockFunctor2D.
BlockReduction3D2D reduces the data of a SuperF3D functor to the intersection between a given hyperpl...
void initialize()
Initialize rank-local list of plane points to be stored in _blockData.
void update()
Updates and writes the data to _blockData using _rankLocalSubplane.
BlockStructureD< 2 > & getBlockStructure() override
Overload of virtual function from class BlockF2D.
BlockReduction3D2D(FunctorPtr< SuperF3D< T > > &&f, const HyperplaneLattice3D< T > &lattice, BlockDataSyncMode syncMode=BlockDataSyncMode::ReduceAndBcast, BlockDataReductionMode reductionMode=BlockDataReductionMode::Analytical)
Construction using functor and hyperplane lattice.
const std::vector< std::tuple< int, int, int > > & getRankLocalSubplane() const
A cuboid geometry represents a voxel mesh.
bool getC(T physR[3], int &iC) const
Returns true and the cuboid number of the nearest lattice position to the given physical position if ...
T getMinDeltaR() const
Returns the minimum delta in the structure.
Smart pointer for managing the various ways of passing functors around.
std::string & getName()
read and write access to name
Parametrization of a hyperplane lattice.
const Hyperplane3D< T > & getHyperplane() const
Base class for all LoadBalancer.
bool isLocal(const int &glob)
returns whether glob is on this process
class for marking output with some text
represents all functors that operate on a SuperStructure<T,3> in general
void bCast(T *sendBuf, int sendCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Broadcast data from one processor to multiple processors.
void reduce(T &sendVal, T &recvVal, MPI_Op op, int root=0, MPI_Comm=MPI_COMM_WORLD)
Reduction operation toward one processor.
Wrapper functions that simplify the use of MPI.
Top level namespace for all of OpenLB.
BlockDataReductionMode
Mode of reducing block data from given, possibly higher dimensional data.
@ Discrete
Read block data from discrete lattice locations.
@ Analytical
Interpolate block data at exact physical locations.
BlockDataSyncMode
Mode of synchronizing functor block data between processes.
@ ReduceOnly
optimize for usage in e.g. BlockGifWriter, full data only available on main rank
@ None
optimize for usage in e.g. SuperLatticeFlux3D, only rank-local data available
@ ReduceAndBcast
default behavior, full block data available on all ranks after update
Definition of a analytical 2D plane embedded in 3D space.