29 #ifndef SERIALIZATION_H
30 #define SERIALIZATION_H
55template<
typename S,
unsigned dim>
78 unsigned iD,
unsigned fieldDim)
const {
84 unsigned iD,
unsigned fieldDim)
const {
90 unsigned fieldDim)
const {
97 const auto fieldCoord = std::div((
long int) index, (
long int) fieldDim);
98 const auto geomCoord =
getLatticeR(fieldCoord.quot);
99 return {geomCoord, (std::size_t) fieldCoord.rem};
113template<
typename S,
unsigned dim>
121 std::vector<unsigned> _cuboidSizes;
122 std::vector<unsigned> _offsets;
135 _offsets.push_back(0);
137 _offsets.push_back(_offsets[i-1] + _cuboidSizes[i-1]);
141 if constexpr (dim == 2) {
142 _noCells = (mc.getNx() + 1) * (mc.getNy() + 1);
144 _noCells = (mc.getNx() + 1) * (mc.getNy() + 1) * (mc.getNz() + 1);
155 const int nX = c.getNx();
156 const int nY = c.getNy();
158 if constexpr (dim == 2) {
160 res = _offsets[latticeR[0]] + nX*latticeR[2] + latticeR[1];
163 res = _offsets[latticeR[0]] + nX*nY*latticeR[3] + nX*latticeR[2] + latticeR[1];
172 const auto cuboidIt = std::upper_bound(_offsets.begin(), _offsets.end(), index) - 1;
174 res[0] = std::distance(_offsets.begin(), cuboidIt);
177 const std::size_t nX = c.getNx();
178 if constexpr (dim == 2) {
180 const auto divByNx = std::ldiv((
long int) index - *cuboidIt, (
long int) nX);
181 res[2] = divByNx.quot;
182 res[1] = divByNx.rem;
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;
208template<
typename S,
unsigned dim>
213 std::vector<L> _coords;
222 : _indicator(std::move(indicator))
226 for (
unsigned iC = 0; iC < cGeometry.size(); ++iC) {
228 const int nX = cGeometry.get(iC).getNx();
229 const int nY = cGeometry.get(iC).getNy();
230 for (
int iX=0; iX<nX; iX++) {
232 for (
int iY=0; iY<nY; iY++) {
234 if constexpr (dim == 2) {
235 if (_indicator(latticeR.
data())) {
236 _coords.push_back(latticeR);
239 const int nZ = cGeometry.get(iC).getNz();
240 for (
int iZ=0; iZ<nZ; iZ++) {
243 if (_indicator(latticeR.
data())) {
244 _coords.push_back(latticeR);
264 _indicator(&isInside, latticeR);
267 clout <<
"Warning: the passed cell does not lie in the indicated domain "
268 <<
"and can therefore not be accessed." << std::endl;
272 const L point (latticeR);
273 const auto upper = std::upper_bound(
274 _coords.begin(), _coords.end(), point, [](
const L& a,
const L& b){
275 return lex_smaller(a, b);
277 return std::distance(_coords.begin(), upper - 1);
286 if (index >= _coords.size()) {
288 clout <<
"Warning: the passed index is higher than the number of cells "
289 <<
"which are marked by indicator." << std::endl;
293 return _coords[index];
297 return _coords.size();
307template <
typename T,
typename DESCRIPTOR>
310 static constexpr unsigned d = DESCRIPTOR::d;
318 int iC,
unsigned dataDim, std::function<T(T)> projection)
323 this->
getName() =
"BlockLatticeSerialDataF";
328 if (this->getBlock().isInsideCore(input)) {
329 int latticeR[4] = {
_iC, input[0], input[1], 0};
330 if constexpr (
d == 3) {
331 latticeR[3] = input[2];
334 for (
int i = 0; i < this->getTargetDim(); ++i) {
352template <
typename T,
typename DESCRIPTOR>
355 std::shared_ptr<const GeometrySerializer<T,DESCRIPTOR::d>>
_serializer;
360 std::function<T(T)> projection = [](T x){
return x; })
364 this->
getName() =
"SuperLatticeSerialDataF";
367 this->_blockF.reserve(maxC);
369 for (
int iC = 0; iC < maxC; ++iC) {
370 this->_blockF.emplace_back(
384 std::function<T(T)> projection = [](T x){
return x; })
401template<
typename S,
unsigned dim>
406 material = sGeometry.
get(latticeR);
408#ifdef PARALLEL_MODE_MPI
417template <
unsigned D,
typename T>
421 const auto loadBalancer = f.getSuperGeometry().getLoadBalancer();
425#ifdef PARALLEL_MODE_MPI
434template <
unsigned D,
typename T,
typename U=T>
437 const auto loadBalancer = f.getSuperStructure().getLoadBalancer();
441#ifdef PARALLEL_MODE_MPI
465template <
typename FIELD,
typename T,
typename DESCRIPTOR,
typename C=std::vector<T>>
472 constexpr unsigned dim = DESCRIPTOR::d;
473 constexpr unsigned fieldDim = DESCRIPTOR::template size<FIELD>();
479 for (
int iC=0; iC<cGeometry.size(); iC++) {
481 const int nX = cGeometry.get(iC).getNx();
482 const int nY = cGeometry.get(iC).getNy();
483 const int nZ = cGeometry.get(iC).getNz();
484 for (
int iX=0; iX<nX; iX++) {
486 for (
int iY=0; iY<nY; iY++) {
488 for (
int iZ=0; iZ<nZ; iZ++) {
494 for (
unsigned iDim=0; iDim<fieldDim; iDim++) {
495 const auto cell = sLattice.
get(latticeR);
497 = cell.template getFieldComponent<FIELD>(iDim);
500#ifdef PARALLEL_MODE_MPI
503 for (
unsigned iDim=0; iDim<fieldDim; iDim++) {
505 result[index] = dataHelp[iDim];
518 template<
typename,SolverMode>
typename SOLVER,
520 template<
typename...>
typename PRIMAL_DYNAMICS,
536 template<
typename,SolverMode>
typename SOLVER,
538 template<
typename...>
typename PRIMAL_DYNAMICS,
539 typename C=std::vector<T>>
541 std::shared_ptr<SOLVER<T,SolverMode::Reference>> solver)
543 using descriptor =
typename SOLVER<T,SolverMode::Reference>::AdjointLbSolver::DESCRIPTOR;
545 CONTROLLED_FIELD, T, descriptor, C>(
566 template<
typename,SolverMode>
typename SOLVER,
568 template<
typename...>
typename PRIMAL_DYNAMICS,
569 typename C=std::vector<T>>
571 std::shared_ptr<SOLVER<T,SolverMode::Reference>> solver)
574 std::transform(result.begin(), result.end(), result.begin(), [&](
auto r){
575 return optiCase._projection->inverse(r);
Decomposition of a physical volume into a set of disjoint cuboids.
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.
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(LatticeR< D+1 > 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.
Cell< T, DESCRIPTOR > get(LatticeR< DESCRIPTOR::d+1 > latticeR)
Get local cell interface.
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
CuboidDecomposition< T, D > & getCuboidDecomposition()
Read and write access to cuboid geometry.
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 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 implements the evaluation of the goal functional and its derivatives by using adjoint LBM.
std::size_t _dimCtrl
upper limit for the number of control variables (#voxels * field-dimension)
std::shared_ptr< SuperIndicatorF< S, dim > > _controlIndicator
Marks, where there are active control variables.
std::shared_ptr< GeometrySerializer< S, dim > > _serializer
This class serializes the cells inside the geometry.
SimpleGeometrySerializer(CuboidDecomposition< S, dim > &cGeometry)
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.
CuboidDecomposition< S, dim > & _cGeometry
unsigned getNoCells() const override
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.
bool evaluateSuperIndicatorFglobally(SuperIndicatorF< T, D > &f, const int input[])
Helper that gives global access to the values of an indicator.
bool evaluateSuperFglobally(SuperF< D, T, U > &f, U *output, const int input[])
Helper that gives global access to the values of a functor.
C getControl(OptiCaseDual< T, SOLVER, CONTROLLED_FIELD, PRIMAL_DYNAMICS, C > &optiCase, std::shared_ptr< SOLVER< T, SolverMode::Reference > > solver)
Get control values of some simulation in the context of adjoint optimization Take values of FIELD,...
C serialDataFromField(SuperLattice< T, DESCRIPTOR > &sLattice, const GeometrySerializer< T, DESCRIPTOR::d > &serializer, SuperIndicatorF< T, DESCRIPTOR::d > &indicator, unsigned controlDim)
Take values of a field and put them into a long vector Idea: FIELD[cartesianCoordinates] = result[ser...
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, SuperF2D< T, U >, SuperF3D< T, U > > SuperF
std::conditional_t< D==2, IndicatorF2D< T >, IndicatorF3D< T > > IndicatorF
std::string getName(OperatorScope scope)
Returns human-readable name of scope.
std::conditional_t< D==2, SuperIndicatorF2D< T >, SuperIndicatorF3D< T > > SuperIndicatorF
An OptiCase using Adjoint-based Differentiation.
Bundle for lattice coordinates + field component.
std::size_t fieldComponent
LatticeR< dim+1 > latticeR
Creates a container of type C.
Representation of a parallel 2D geometry – header file.