OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::opti::SimpleGeometrySerializer< S, dim > Class Template Reference

This class serializes the cells inside the geometry. More...

#include <serialization.h>

+ Inheritance diagram for olb::opti::SimpleGeometrySerializer< S, dim >:
+ Collaboration diagram for olb::opti::SimpleGeometrySerializer< S, dim >:

Public Member Functions

 SimpleGeometrySerializer (CuboidDecomposition< S, dim > &cGeometry)
 
 SimpleGeometrySerializer (SuperGeometry< S, dim > &sGeometry)
 
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
 
- Public Member Functions inherited from olb::opti::GeometrySerializer< S, dim >
std::size_t getSerializedCellIndex (LatticeR< dim+1 > latticeR) const
 Compute serialized cell index from lattice coordinates.
 
std::size_t getSerializedComponentIndex (const int latticeR[], unsigned iD, 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.
 
std::size_t getSerializedComponentIndex (LatticeAndFieldR coords, unsigned fieldDim) const
 Get index of field component from lattice coordinates and component index.
 
LatticeAndFieldR getLatticeAndFieldR (std::size_t index, unsigned fieldDim) const
 Get lattice coordinates and field component from serialized field index.
 

Protected Attributes

CuboidDecomposition< S, dim > & _cGeometry
 
const unsigned _noCuboids
 

Detailed Description

template<typename S, unsigned dim>
class olb::opti::SimpleGeometrySerializer< S, dim >

This class serializes the cells inside the geometry.

Formula for serialized cell index (3d): cuboid_offset + NX*NY*z + NX*y + x Formula for serialized field component index: fieldDim * cellIndex + fieldComponent

This class is not intended to be used in performance-relevant context. Index computations could be accellerated if desired.

Definition at line 114 of file serialization.h.

Constructor & Destructor Documentation

◆ SimpleGeometrySerializer() [1/2]

template<typename S , unsigned dim>
olb::opti::SimpleGeometrySerializer< S, dim >::SimpleGeometrySerializer ( CuboidDecomposition< S, dim > & cGeometry)
inline

Definition at line 126 of file serialization.h.

127 : _cGeometry(cGeometry),
129 {
130 _cuboidSizes.reserve(_noCuboids);
131 _offsets.reserve(_noCuboids);
132 for (unsigned i = 0; i < _noCuboids; ++i) {
133 _cuboidSizes.push_back(_cGeometry.get(i).getLatticeVolume());
134 }
135 _offsets.push_back(0);
136 for (unsigned i = 1; i < _noCuboids; ++i) {
137 _offsets.push_back(_offsets[i-1] + _cuboidSizes[i-1]);
138 }
139
140 const auto mc = _cGeometry.getMotherCuboid();
141 if constexpr (dim == 2) {
142 _noCells = (mc.getNx() + 1) * (mc.getNy() + 1);
143 } else {
144 _noCells = (mc.getNx() + 1) * (mc.getNy() + 1) * (mc.getNz() + 1);
145 }
146 }
int size() const
Returns number of cuboids in decomposition.
const Cuboid< T, D > & get(int iC) const
Read access to a single cuboid.
const Cuboid< T, D > & getMotherCuboid() const
Returns the smallest cuboid that includes all cuboids of the structure.
std::size_t getLatticeVolume() const
Returns the number of Nodes in the volume.
Definition cuboid.hh:62
CuboidDecomposition< S, dim > & _cGeometry

References olb::opti::SimpleGeometrySerializer< S, dim >::_cGeometry, olb::opti::SimpleGeometrySerializer< S, dim >::_noCuboids, olb::CuboidDecomposition< T, D >::get(), olb::Cuboid< T, D >::getLatticeVolume(), and olb::CuboidDecomposition< T, D >::getMotherCuboid().

+ Here is the call graph for this function:

◆ SimpleGeometrySerializer() [2/2]

template<typename S , unsigned dim>
olb::opti::SimpleGeometrySerializer< S, dim >::SimpleGeometrySerializer ( SuperGeometry< S, dim > & sGeometry)
inline

Definition at line 148 of file serialization.h.

149 : SimpleGeometrySerializer(sGeometry.getCuboidDecomposition())
150 { }
SimpleGeometrySerializer(CuboidDecomposition< S, dim > &cGeometry)

Member Function Documentation

◆ getLatticeR()

template<typename S , unsigned dim>
LatticeR< dim+1 > olb::opti::SimpleGeometrySerializer< S, dim >::getLatticeR ( std::size_t index) const
inlineoverridevirtual

Get lattice coordinates from serialized cell index.

Implements olb::opti::GeometrySerializer< S, dim >.

Definition at line 171 of file serialization.h.

171 {
172 const auto cuboidIt = std::upper_bound(_offsets.begin(), _offsets.end(), index) - 1;
173 LatticeR<dim+1> res;
174 res[0] = std::distance(_offsets.begin(), cuboidIt);
175
176 const Cuboid<S,dim>& c = _cGeometry.get(res[0]);
177 const std::size_t nX = c.getNx();
178 if constexpr (dim == 2) {
179 // index = cuboid_offset + NX*y + x
180 const auto divByNx = std::ldiv((long int) index - *cuboidIt, (long int) nX);
181 res[2] = divByNx.quot;
182 res[1] = divByNx.rem;
183 } else {
184 // index = cuboid_offset + NX*NY*z + NX*y + x
185 const std::size_t nY = c.getNy();
186 const auto divByNxNy = std::ldiv((long int) index - *cuboidIt, (long int) nX*nY);
187 res[3] = divByNxNy.quot;
188 const auto divByNx = std::ldiv(divByNxNy.rem, (long int) nX);
189 res[2] = divByNx.quot;
190 res[1] = divByNx.rem;
191 }
192 return res;
193 }
platform_constant int c[Q][D]
Definition functions.h:57
Vector< std::int32_t, D > LatticeR
Type for spatial block-local lattice coordinates.

References olb::opti::SimpleGeometrySerializer< S, dim >::_cGeometry, and olb::CuboidDecomposition< T, D >::get().

+ Here is the call graph for this function:

◆ getNoCells()

template<typename S , unsigned dim>
unsigned olb::opti::SimpleGeometrySerializer< S, dim >::getNoCells ( ) const
inlineoverridevirtual

Implements olb::opti::GeometrySerializer< S, dim >.

Definition at line 195 of file serialization.h.

195 {
196 return _noCells;
197 }

◆ getSerializedCellIndex()

template<typename S , unsigned dim>
std::size_t olb::opti::SimpleGeometrySerializer< S, dim >::getSerializedCellIndex ( const int latticeR[]) const
inlineoverridevirtual

Compute serialized cell index from lattice coordinates.

Implements olb::opti::GeometrySerializer< S, dim >.

Definition at line 153 of file serialization.h.

153 {
154 const Cuboid<S,dim>& c = _cGeometry.get(latticeR[0]);
155 const int nX = c.getNx();
156 const int nY = c.getNy();
157 std::size_t res;
158 if constexpr (dim == 2) {
159 // cuboid_offset + NX*y + x
160 res = _offsets[latticeR[0]] + nX*latticeR[2] + latticeR[1];
161 } else {
162 // cuboid_offset + NX*NY*z + NX*y + x
163 res = _offsets[latticeR[0]] + nX*nY*latticeR[3] + nX*latticeR[2] + latticeR[1];
164 }
165 return res;
166 }

References olb::opti::SimpleGeometrySerializer< S, dim >::_cGeometry, and olb::CuboidDecomposition< T, D >::get().

+ Here is the call graph for this function:

Member Data Documentation

◆ _cGeometry

template<typename S , unsigned dim>
CuboidDecomposition<S,dim>& olb::opti::SimpleGeometrySerializer< S, dim >::_cGeometry
protected

Definition at line 117 of file serialization.h.

◆ _noCuboids

template<typename S , unsigned dim>
const unsigned olb::opti::SimpleGeometrySerializer< S, dim >::_noCuboids
protected

Definition at line 118 of file serialization.h.


The documentation for this class was generated from the following file: