OpenLB 1.7
Loading...
Searching...
No Matches
blockReduction2D2D.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 BLOCK_REDUCTION_2D2D_HH
25#define BLOCK_REDUCTION_2D2D_HH
26
27#include <limits>
28#include "utilities/omath.h"
29
30#include "blockReduction2D2D.h"
39
40namespace olb {
41
42
43template <typename T>
44void BlockReduction2D2D<T>::updateToWantedResolution(int resolution)
45{
46 if (resolution>0) {
47 if (_nx > _ny) {
48 T newH = _nx*_h/(T)resolution;
49 _nx = resolution;
50 _ny = (int)(_ny*_h/newH) + 1;
51 _h = newH;
52 }
53 else {
54 T newH = _ny*_h/(T)resolution;
55 _ny = resolution;
56 _nx = (int)(_nx*_h/newH) + 1;
57 _h = newH;
58 }
59 if (this->_owning) {
60 delete this->_blockData;
61 }
62 this->_blockData = new BlockData<2,T,T>({{_nx, _ny}, 0}, _f->getTargetDim());
63 this->_owning = true;
64 }
65}
66
67template <typename T>
69 FunctorPtr<SuperF2D<T>>&& f, int resolution, BlockDataSyncMode mode)
70 : BlockDataF2D<T,T>(f->getSuperStructure().getCuboidGeometry().getMotherCuboid().getNx(),
71 f->getSuperStructure().getCuboidGeometry().getMotherCuboid().getNy(),
72 f->getTargetDim()),
73 _f(std::move(f)),
74 _origin(_f->getSuperStructure().getCuboidGeometry().getMotherCuboid().getOrigin()),
75 _h(_f->getSuperStructure().getCuboidGeometry().getMinDeltaR()),
76 _nx(_f->getSuperStructure().getCuboidGeometry().getMotherCuboid().getNx()),
77 _ny(_f->getSuperStructure().getCuboidGeometry().getMotherCuboid().getNy()),
78 _syncMode(mode)
79{
80 this->getName() = "planeReduction(" + _f->getName() + ")";
81
82 _origin[0] -= 10*std::numeric_limits<T>::epsilon();
83 _origin[1] -= 10*std::numeric_limits<T>::epsilon();
84
85 // changes _h, _nx, _ny to match resolution
86 updateToWantedResolution(resolution);
87 // intialize list of relevant rank local points
88 initialize();
89 // first update of data
90 update();
91}
92
93template <typename T>
94Vector<T,2> BlockReduction2D2D<T>::getPhysR(const int& iX, const int& iY) const
95{
96 return Vector<T,2> {
97 _origin[0] + T(iX) * _h,
98 _origin[1] + T(iY) * _h
99 };
100}
101
102template <typename T>
104{
107 .originAt({_origin[0], _origin[1], 0})
108 .spannedBy({1,0,0}, {0,1,0}),
109 _h, _nx, _ny);
110}
111
112template <typename T>
114{
115 const CuboidGeometry2D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
116 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
117
118 _rankLocalSubplane.clear();
119
120 for ( int iX = 0; iX < _nx; ++iX ) {
121 for ( int iY = 0; iY < _ny; ++iY ) {
122 const Vector<T,2> physR = getPhysR(iX, iY);
123
124 // Schedule plane point for storage if its physical position intersects the
125 // mother cuboid and the cuboid of the nearest lattice position is local to
126 // the current rank:
127 int iC;
128 if ( geometry.getC(physR, iC) ) {
129 if ( load.isLocal(iC) ) {
130 _rankLocalSubplane.emplace_back(iX, iY, iC);
131 }
132 }
133 }
134 }
135}
136
137template <typename T>
139{
140 _f->getSuperStructure().communicate();
141
142 AnalyticalFfromSuperF2D<T> analyticalF(*_f);
143
144#ifdef PARALLEL_MODE_MPI
145 std::unique_ptr<BlockData<2,T,T>> localBlockData(
146 new BlockData<2,T,T>({{_nx, _ny}, 0}, this->getTargetDim()));
147#endif
148
149 for ( std::tuple<int,int,int>& pos : _rankLocalSubplane ) {
150 const int& iX = std::get<0>(pos);
151 const int& iY = std::get<1>(pos);
152 const Vector<T,2> physR = getPhysR(iX, iY);
153
154 for ( int iSize = 0; iSize < _f->getTargetDim(); ++iSize ) {
155 this->_blockData->get({iX, iY}, iSize) = T();
156 }
157
158 T output[_f->getTargetDim()];
159 const T input[2] { physR[0], physR[1] };
160
161 if (analyticalF(output, input)) {
162 for ( int iSize = 0; iSize < _f->getTargetDim(); ++iSize ) {
163#ifdef PARALLEL_MODE_MPI
164 localBlockData->get({iX, iY}, iSize) += output[iSize];
165#else
166 this->_blockData->get({iX, iY}, iSize) += output[iSize];
167#endif
168 }
169 }
170 }
171
172#ifdef PARALLEL_MODE_MPI
173 switch ( _syncMode ) {
175 singleton::mpi().reduce(*localBlockData, this->getBlockData(), MPI_SUM);
176 singleton::mpi().bCast(this->getBlockData());
177 break;
179 singleton::mpi().reduce(*localBlockData, this->getBlockData(), MPI_SUM);
180 break;
182 if (this->_owning) {
183 delete this->_blockData;
184 }
185 this->_blockData = localBlockData.release();
186 this->_owning = true;
187 break;
188 }
189#endif
190}
191
192template <typename T>
194{
195 return *this->_blockData;
196}
197
198
199} // end namespace olb
200
201#endif
Converts super functions to analytical functions.
BlockDataF2D can store data of any BlockFunctor2D.
void initialize()
Initialize rank-local list of points to be stored in _blockData.
HyperplaneLattice3D< T > getPlaneDiscretizationIn3D() const
Returns embedding of the discretized plane in 3D space.
void update()
Updates and writes the data to _blockData using _rankLocalSubplane.
Vector< T, 2 > getPhysR(const int &iX, const int &iY) const
Transform lattice coordinates to their physical location.
BlockReduction2D2D(FunctorPtr< SuperF2D< T > > &&f, int resolution=600, BlockDataSyncMode mode=BlockDataSyncMode::ReduceAndBcast)
BlockStructureD< 2 > & getBlockStructure() override
Overload of virtual function from class BlockF2D.
Base of a regular block.
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 ...
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
Parametrization of a hyperplane lattice.
Base class for all LoadBalancer.
bool isLocal(const int &glob)
returns whether glob is on this process
represents all functors that operate on a SuperStructure<T,2> in general
Plain old scalar vector.
Definition vector.h:47
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.
MpiManager & mpi()
Top level namespace for all of OpenLB.
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.