29 #ifndef SERIALIZATION_H
30 #define SERIALIZATION_H
50template<
typename S,
unsigned dim>
73 unsigned iD,
unsigned fieldDim)
const {
79 unsigned iD,
unsigned fieldDim)
const {
85 unsigned fieldDim)
const {
92 const auto fieldCoord = std::div((
long int) index, (
long int) fieldDim);
93 const auto geomCoord =
getLatticeR(fieldCoord.quot);
94 return {geomCoord, (std::size_t) fieldCoord.rem};
108template<
typename S,
unsigned dim>
116 std::vector<unsigned> _cuboidSizes;
117 std::vector<unsigned> _offsets;
128 _cuboidSizes.push_back(
_cGeometry.get(i).getLatticeVolume());
130 _offsets.push_back(0);
132 _offsets.push_back(_offsets[i-1] + _cuboidSizes[i-1]);
136 if constexpr (dim == 2) {
137 _noCells = (mc.getNx() + 1) * (mc.getNy() + 1);
139 _noCells = (mc.getNx() + 1) * (mc.getNy() + 1) * (mc.getNz() + 1);
150 const int nX = c.getNx();
151 const int nY = c.getNy();
153 if constexpr (dim == 2) {
155 res = _offsets[latticeR[0]] + nX*latticeR[2] + latticeR[1];
158 res = _offsets[latticeR[0]] + nX*nY*latticeR[3] + nX*latticeR[2] + latticeR[1];
167 const auto cuboidIt = std::upper_bound(_offsets.begin(), _offsets.end(), index) - 1;
169 res[0] = std::distance(_offsets.begin(), cuboidIt);
172 const std::size_t nX = c.getNx();
173 if constexpr (dim == 2) {
175 const auto divByNx = std::div((
long int) index - *cuboidIt, (
long int) nX);
176 res[2] = divByNx.quot;
177 res[1] = divByNx.rem;
180 const std::size_t nY = c.getNy();
181 const auto divByNxNy = std::div((
long int) index - *cuboidIt, (
long int) nX*nY);
182 res[3] = divByNxNy.quot;
183 const auto divByNx = std::div(divByNxNy.rem, (
long int) nX);
184 res[2] = divByNx.quot;
185 res[1] = divByNx.rem;
203template<
typename S,
unsigned dim>
208 std::vector<L> _coords;
217 : _indicator(std::move(indicator))
221 for (
unsigned iC = 0; iC < cGeometry.getNc(); ++iC) {
223 const int nX = cGeometry.get(iC).getNx();
224 const int nY = cGeometry.get(iC).getNy();
225 for (
int iX=0; iX<nX; iX++) {
227 for (
int iY=0; iY<nY; iY++) {
229 if constexpr (dim == 2) {
230 if (_indicator(latticeR.
data())) {
231 _coords.push_back(latticeR);
234 const int nZ = cGeometry.get(iC).getNz();
235 for (
int iZ=0; iZ<nZ; iZ++) {
238 if (_indicator(latticeR.
data())) {
239 _coords.push_back(latticeR);
259 _indicator(&isInside, latticeR);
262 clout <<
"Warning: the passed cell does not lie in the indicated domain "
263 <<
"and can therefore not be accessed." << std::endl;
267 const L point (latticeR);
268 const auto upper = std::upper_bound(
269 _coords.begin(), _coords.end(), point, [](
const L& a,
const L& b){
270 return lex_smaller(a, b);
272 return std::distance(_coords.begin(), upper - 1);
281 if (index >= _coords.size()) {
283 clout <<
"Warning: the passed index is higher than the number of cells "
284 <<
"which are marked by indicator." << std::endl;
288 return _coords[index];
292 return _coords.size();
297template<
typename S,
unsigned dim>
302 material = sGeometry.
get(latticeR);
304#ifdef PARALLEL_MODE_MPI
311template <
typename T,
typename DESCRIPTOR>
314 static constexpr unsigned d = DESCRIPTOR::d;
322 int iC,
unsigned dataDim, std::function<T(T)> projection)
327 this->getName() =
"BlockLatticeSerialDataF";
332 if (this->getBlock().isInsideCore(input)) {
333 int latticeR[4] = {
_iC, input[0], input[1], 0};
334 if constexpr (
d == 3) {
335 latticeR[3] = input[2];
338 for (
int i = 0; i < this->getTargetDim(); ++i) {
356template <
typename T,
typename DESCRIPTOR>
359 std::shared_ptr<const GeometrySerializer<T,DESCRIPTOR::d>>
_serializer;
364 std::function<T(T)> projection = [](T x){
return x; })
368 this->getName() =
"SuperLatticeSerialDataF";
371 this->_blockF.reserve(maxC);
373 for (
int iC = 0; iC < maxC; ++iC) {
374 this->_blockF.emplace_back(
388 std::function<T(T)> projection = [](T x){
return x; })
Platform-abstracted block lattice for external access and inter-block interaction.
Smart pointer for managing the various ways of passing functors around.
class for marking output with some text
Representation of a statistic for a parallel 2D geometry.
int get(int iCglob, LatticeR< D > latticeR) const
Read only access to the material numbers, error handling: returns 0 if data is not available.
Super class maintaining block lattices for a cuboid decomposition.
BlockLattice< T, DESCRIPTOR > & getBlock(int locC)
Return BlockLattice with local index locC.
CuboidGeometry< T, D > & getCuboidGeometry()
Read and write access to cuboid geometry.
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
constexpr const T * data() const any_platform
static constexpr unsigned d
const GeometrySerializer< T, d > & _serializer
bool operator()(T output[], const int input[])
std::function< T(T)> _projection
BlockLatticeSerialDataF(BlockLattice< T, DESCRIPTOR > &blockLattice, Controller< T > &controller, const GeometrySerializer< T, d > &serializer, int iC, unsigned dataDim, std::function< T(T)> projection)
Controller< T > & _controller
S const & getControl(int i) const
This class serializes the cells inside the geometry.
virtual unsigned getNoCells() const =0
std::size_t getSerializedCellIndex(LatticeR< dim+1 > latticeR) const
Compute serialized cell index from lattice coordinates.
virtual std::size_t getSerializedCellIndex(const int latticeR[]) const =0
Compute serialized cell index from lattice coordinates.
std::size_t getSerializedComponentIndex(LatticeAndFieldR coords, unsigned fieldDim) const
Get index of field component from lattice coordinates and component index.
std::size_t getSerializedComponentIndex(LatticeR< dim+1 > latticeR, unsigned iD, unsigned fieldDim) const
Get index of field component from lattice coordinates and component index.
virtual LatticeR< dim+1 > getLatticeR(std::size_t index) const =0
Get lattice coordinates from serialized cell index.
LatticeAndFieldR getLatticeAndFieldR(std::size_t index, unsigned fieldDim) const
Get lattice coordinates and field component from serialized field index.
std::size_t getSerializedComponentIndex(const int latticeR[], unsigned iD, unsigned fieldDim) const
Get index of field component from lattice coordinates and component index.
This class serializes the cells inside the geometry.
SimpleGeometrySerializer(SuperGeometry< S, dim > &sGeometry)
const unsigned _noCuboids
std::size_t getSerializedCellIndex(const int latticeR[]) const override
Compute serialized cell index from lattice coordinates.
LatticeR< dim+1 > getLatticeR(std::size_t index) const override
Get lattice coordinates from serialized cell index.
unsigned getNoCells() const override
CuboidGeometry< S, dim > & _cGeometry
SimpleGeometrySerializer(CuboidGeometry< S, dim > &cGeometry)
This class serializes the cells which are marked by indicator.
SparseGeometrySerializer(SuperGeometry< S, dim > &superGeometry, FunctorPtr< SuperIndicatorF< S, dim > > &&indicator)
SparseGeometrySerializer(SuperGeometry< S, dim > &superGeometry, FunctorPtr< IndicatorF< S, dim > > &&indicator)
unsigned getNoCells() const override
std::size_t getSerializedCellIndex(const int latticeR[]) const override
Compute serialized cell index from lattice coordinates.
LatticeR< dim+1 > getLatticeR(std::size_t index) const override
Get lattice coordinates from serialized cell index.
A data field whose values are managed by a controller.
SuperLatticeSerialDataF(SuperLattice< T, DESCRIPTOR > &superLattice, Controller< T > &controller, unsigned dataDim, std::shared_ptr< const GeometrySerializer< T, DESCRIPTOR::d > > serializer, std::function< T(T)> projection=[](T x){ return x;})
std::shared_ptr< const GeometrySerializer< T, DESCRIPTOR::d > > _serializer
SuperLatticeSerialDataF(SuperLattice< T, DESCRIPTOR > &superLattice, Controller< T > &controller, unsigned dataDim, std::function< T(T)> projection=[](T x){ return x;})
void bCast(T *sendBuf, int sendCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Broadcast data from one processor to multiple processors.
int getRank() const
Returns the process ID.
The description of a Controller – header file.
int getMaterialGlobally(SuperGeometry< S, dim > &sGeometry, LatticeR< dim+1 > latticeR)
Helper that gives global access to material numbers.
Top level namespace for all of OpenLB.
std::conditional_t< DESCRIPTOR::d==2, SuperLatticeF2D< T, DESCRIPTOR >, SuperLatticeF3D< T, DESCRIPTOR > > SuperLatticeF
std::conditional_t< D==2, SuperIndicatorFfromIndicatorF2D< T >, SuperIndicatorFfromIndicatorF3D< T > > SuperIndicatorFfromIndicatorF
std::conditional_t< DESCRIPTOR::d==2, BlockLatticeF2D< T, DESCRIPTOR >, BlockLatticeF3D< T, DESCRIPTOR > > BlockLatticeF
std::conditional_t< D==2, CuboidGeometry2D< T >, CuboidGeometry3D< T > > CuboidGeometry
std::conditional_t< D==2, IndicatorF2D< T >, IndicatorF3D< T > > IndicatorF
std::conditional_t< D==2, SuperIndicatorF2D< T >, SuperIndicatorF3D< T > > SuperIndicatorF
std::conditional_t< D==2, Cuboid2D< T >, Cuboid3D< T > > Cuboid
Bundle for lattice coordinates + field component.
std::size_t fieldComponent
LatticeR< dim+1 > latticeR
Representation of a parallel 2D geometry – header file.