OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
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 (CuboidGeometry< 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

CuboidGeometry< 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 109 of file serialization.h.

Constructor & Destructor Documentation

◆ SimpleGeometrySerializer() [1/2]

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

Definition at line 121 of file serialization.h.

122 : _cGeometry(cGeometry),
123 _noCuboids(_cGeometry.getNc())
124 {
125 _cuboidSizes.reserve(_noCuboids);
126 _offsets.reserve(_noCuboids);
127 for (unsigned i = 0; i < _noCuboids; ++i) {
128 _cuboidSizes.push_back(_cGeometry.get(i).getLatticeVolume());
129 }
130 _offsets.push_back(0);
131 for (unsigned i = 1; i < _noCuboids; ++i) {
132 _offsets.push_back(_offsets[i-1] + _cuboidSizes[i-1]);
133 }
134
135 const auto mc = _cGeometry.getMotherCuboid();
136 if constexpr (dim == 2) {
137 _noCells = (mc.getNx() + 1) * (mc.getNy() + 1);
138 } else {
139 _noCells = (mc.getNx() + 1) * (mc.getNy() + 1) * (mc.getNz() + 1);
140 }
141 }
CuboidGeometry< S, dim > & _cGeometry

References olb::opti::SimpleGeometrySerializer< S, dim >::_cGeometry, and olb::opti::SimpleGeometrySerializer< S, dim >::_noCuboids.

◆ SimpleGeometrySerializer() [2/2]

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

Definition at line 143 of file serialization.h.

145 { }
CuboidGeometry< T, D > & getCuboidGeometry()
Read and write access to cuboid geometry.
SimpleGeometrySerializer(CuboidGeometry< 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 166 of file serialization.h.

166 {
167 const auto cuboidIt = std::upper_bound(_offsets.begin(), _offsets.end(), index) - 1;
168 LatticeR<dim+1> res;
169 res[0] = std::distance(_offsets.begin(), cuboidIt);
170
171 const Cuboid<S,dim>& c = _cGeometry.get(res[0]);
172 const std::size_t nX = c.getNx();
173 if constexpr (dim == 2) {
174 // index = cuboid_offset + NX*y + x
175 const auto divByNx = std::div((long int) index - *cuboidIt, (long int) nX);
176 res[2] = divByNx.quot;
177 res[1] = divByNx.rem;
178 } else {
179 // index = cuboid_offset + NX*NY*z + NX*y + x
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;
186 }
187 return res;
188 }
platform_constant int c[Q][D]

References olb::opti::SimpleGeometrySerializer< S, dim >::_cGeometry.

◆ getNoCells()

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

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

Definition at line 190 of file serialization.h.

190 {
191 return _noCells;
192 }

◆ 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 148 of file serialization.h.

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

References olb::opti::SimpleGeometrySerializer< S, dim >::_cGeometry.

Member Data Documentation

◆ _cGeometry

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

Definition at line 112 of file serialization.h.

◆ _noCuboids

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

Definition at line 113 of file serialization.h.


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