24#ifndef BLOCK_REDUCTION_2D1D_HH
25#define BLOCK_REDUCTION_2D1D_HH
43void BlockReduction2D1D<T>::updateBlockAnalytical(BlockData<2,T,T>& block)
45 AnalyticalFfromSuperF2D<T> analyticalF(*_f);
47 for ( std::tuple<int,int>& pos : _rankLocalSubplane ) {
48 const int& i = std::get<0>(pos);
49 const Vector<T,2> physR = this->getPhysR(i);
51 for (
int iSize = 0; iSize < _f->getTargetDim(); ++iSize ) {
52 block.get({i, 0}, iSize) = T();
55 T output[_f->getTargetDim()];
56 const T input[2] { physR[0], physR[1] };
58 if (analyticalF(output, input)) {
59 for (
int iSize = 0; iSize < _f->getTargetDim(); ++iSize ) {
60 block.get({i, 0}, iSize) += output[iSize];
67void BlockReduction2D1D<T>::updateBlockDiscrete(BlockData<2,T,T>& block)
69 CuboidGeometry2D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
71 for ( std::tuple<int,int>& pos : _rankLocalSubplane ) {
72 const int& i = std::get<0>(pos);
73 const int& iC = std::get<1>(pos);
74 const Vector<T,2> physR = this->getPhysR(i);
76 for (
int iSize = 0; iSize < _f->getTargetDim(); ++iSize ) {
77 block.get({i, 0}, iSize) = T();
80 T output[_f->getTargetDim()];
81 int input[3] { iC, 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({i, 0}, iSize) += output[iSize];
102 _reductionMode(reductionMode)
104 this->
getName() =
"lineReduction(" + _f->getName() +
")";
112 if ( !spansAxisPlane ||
116 clerr <<
"Given hyperplane is not trivially discretizable. "
117 <<
"Use BlockDataReductionMode::Analytical instead."
136 std::forward<decltype(f)>(f),
149 std::forward<decltype(f)>(f),
151 hyperplane, resolution),
161 std::forward<decltype(f)>(f),
162 Hyperplane2D<T>().originAt(origin).parallelTo(direction),
163 resolution, mode) { }
168 const int input[2] = { i, 0 };
178 _rankLocalSubplane.clear();
180 for (
int i = 0; i < this->getN(); ++i ) {
187 if ( geometry.
getC(physR, iC) ) {
189 _rankLocalSubplane.emplace_back(i, iC);
198 _f->getSuperStructure().communicate();
200#ifdef PARALLEL_MODE_MPI
201 std::unique_ptr<BlockData<2,T,T>> localBlockData(
204 switch ( _reductionMode ) {
206 updateBlockAnalytical(*localBlockData);
209 updateBlockDiscrete(*localBlockData);
213 switch ( _syncMode ) {
223 delete this->_blockData;
225 this->_blockData = localBlockData.release();
226 this->_owning =
true;
230 switch ( _reductionMode ) {
232 updateBlockAnalytical(this->getBlockData());
235 updateBlockDiscrete(this->getBlockData());
244 return *this->_blockData;
250 return this->_rankLocalSubplane;
BlockDataF2D can store data of any BlockFunctor2D.
BlockReduction2D1D reduces the data of a SuperF2D functor to the intersection between a given 2D hype...
BlockReduction2D1D(FunctorPtr< SuperF2D< T > > &&f, const HyperplaneLattice2D< T > &lattice, BlockDataSyncMode syncMode=BlockDataSyncMode::ReduceAndBcast, BlockDataReductionMode reductionMode=BlockDataReductionMode::Analytical)
Construction using functor and hyperplane lattice.
const std::vector< std::tuple< int, int > > & getRankLocalSubplane() const
void update()
Updates and writes the data to _blockData using _rankLocalSubplane.
void initialize()
Initialize rank-local list of plane points to be stored in _blockData.
bool operator()(T output[], int i)
Custom operator for easier access to 1-dimensional block data.
BlockStructureD< 2 > & getBlockStructure() override
Overload of virtual function from class BlockF2D.
A cuboid structure represents the grid of a considered domain.
bool getC(std::vector< T > physR, 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 maximum/minimum delata 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 (i.e. a line lattice).
const Hyperplane2D< 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,2> 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, generic template code.
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 line embedded in 2D space.
bool isParallelToY() const
bool isParallelToX() const