OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM > Class Template Reference

Implementation of BlockD on a concrete PLATFORM. More...

#include <blockD.h>

+ Inheritance diagram for olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >:
+ Collaboration diagram for olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >:

Public Types

using value_t = T
 
using descriptor_t = DESCRIPTOR
 

Public Member Functions

 ConcreteBlockD (Vector< int, DESCRIPTOR::d > size, int padding=0)
 
void setProcessingContext (ProcessingContext context) override
 Set processing context.
 
void resize (Vector< int, DESCRIPTOR::d > size) override
 
template<typename FIELD_TYPE >
bool hasData () const
 
template<typename FIELD_TYPE >
const auto & getData () const
 
template<typename FIELD_TYPE >
auto & getData ()
 
template<typename FIELD >
const auto & getField (FIELD field=FIELD()) const
 
template<typename FIELD >
auto & getField (FIELD field=FIELD())
 
bool hasCommunicatable (std::type_index field) const override
 
CommunicatablegetCommunicatable (std::type_index field) override
 
template<typename FIELD >
void setParameter (FieldD< T, DESCRIPTOR, FIELD > value)
 
template<typename PARAMETER , Platform _PLATFORM, typename FIELD >
void setParameter (FieldArrayD< T, DESCRIPTOR, _PLATFORM, FIELD > &fieldArray)
 
template<typename PARAMETER , typename FIELD >
void setParameter (AbstractFieldArrayD< T, DESCRIPTOR, FIELD > &abstractFieldArray)
 
auto & getDataRegistry ()
 Return reference to Data's FieldTypeRegistry.
 
template<typename OPERATOR >
void apply ()
 
std::size_t getNblock () const override
 Number of data blocks for the serializable interface.
 
std::size_t getSerializableSize () const override
 Binary size for the serializer.
 
bool * getBlock (std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
 Return a pointer to the memory of the current block and its size for the serializable interface.
 
void postLoad () override
 Reinit population structure after deserialization.
 
- Public Member Functions inherited from olb::BlockD< T, DESCRIPTOR >
 BlockD (Vector< int, DESCRIPTOR::d > size, int padding, Platform platform)
 
virtual ~BlockD ()
 
Platform getPlatform () const
 Return platform used to process lattice.
 
template<Platform PLATFORM>
ConcreteBlockD< T, DESCRIPTOR, PLATFORM > & asConcrete ()
 
template<typename FIELD_TYPE >
bool hasData ()
 Return whether FIELD_TYPE is available / has been allocated.
 
template<typename FIELD_TYPE >
const auto & getData (FIELD_TYPE field=FIELD_TYPE{}) const
 Return abstract interface for concrete FIELD_TYPE data.
 
template<typename FIELD_TYPE >
auto & getData (FIELD_TYPE field=FIELD_TYPE{})
 Return abstract interface for concrete FIELD_TYPE data.
 
template<typename FIELD >
const auto & getField (FIELD field=FIELD{}) const
 Return abstract interface for FIELD array.
 
template<typename FIELD >
auto getField (LatticeR< DESCRIPTOR::d > loc) const
 Return value of FIELD at loc.
 
template<typename FIELD >
auto & getField (FIELD field=FIELD{})
 Return abstract interface for FIELD array.
 
template<typename FIELD >
void setField (LatticeR< DESCRIPTOR::d > loc, const FieldD< T, DESCRIPTOR, FIELD > &fieldD)
 Set FIELD to fieldD at loc.
 
template<typename FIELD >
void setParameter (FieldD< T, DESCRIPTOR, FIELD > value)
 Set value of parameter FIELD.
 
template<typename PARAMETER , typename FIELD >
void setParameter (AbstractFieldArrayD< T, DESCRIPTOR, FIELD > &fieldArray)
 
template<typename PARAMETER , Platform PLATFORM, typename FIELD >
void setParameter (FieldArrayD< T, DESCRIPTOR, PLATFORM, FIELD > &fieldArray)
 
BlockLatticeRowView< T, DESCRIPTOR > get (std::size_t iCell)
 
template<typename OPERATOR >
void apply ()
 
- Public Member Functions inherited from olb::BlockStructureD< D >
 BlockStructureD (Vector< int, D > size, int padding=0)
 
 BlockStructureD ()
 
void resize (Vector< int, D > size)
 
auto getCore () const
 
int getNx () const
 Read only access to block width.
 
int getNy () const
 Read only access to block height.
 
int getNz () const
 Read only access to block height.
 
LatticeR< D > getExtent () const
 
int getPadding () const
 Read only access to padding.
 
std::size_t getNcells () const
 Get number of cells.
 
CellID getCellId (LatticeR< D > latticeR) const
 Get 1D cell ID.
 
template<typename... L>
std::enable_if_t< sizeof...(L)==D, CellIDgetCellId (L... latticeR) const
 
LatticeR< D > getLatticeR (CellID iCell) const
 
CellDistance getNeighborDistance (LatticeR< D > dir) const
 Get 1D neighbor distance.
 
bool isInside (LatticeR< D > latticeR) const
 Return whether location is valid.
 
bool isInsideCore (LatticeR< D > latticeR) const
 Return whether location is inside core.
 
bool isPadding (LatticeR< D > latticeR) const
 Return whether location is valid.
 
bool isPadding (LatticeR< D > latticeR, int overlap) const
 
bool isPadding (CellID iCell) const
 
template<typename... L>
std::enable_if_t< sizeof...(L)==D, bool > isInside (L... latticeR) const
 
CellDistance getNeighborhoodRadius (LatticeR< D > latticeR) const
 Return maximum valid neighborhood sphere radius w.r.t. latticeR.
 
template<typename F >
void forSpatialLocations (F f) const
 
template<typename F >
void forSpatialLocationsParallel (F f) const
 
template<typename F >
void forSpatialLocations (LatticeR< D > min, LatticeR< D > max, F f) const
 
template<typename F >
void forCoreSpatialLocations (F f) const
 
template<typename F >
void forCellIndices (F f) const
 
- Public Member Functions inherited from olb::Serializable
virtual ~Serializable ()=default
 
template<bool includeLogOutputDir = true>
bool save (std::string fileName="", const bool enforceUint=false)
 Save Serializable into file fileName
 
template<bool includeLogOutputDir = true>
bool load (std::string fileName="", const bool enforceUint=false)
 Load Serializable from file fileName
 
bool save (std::uint8_t *buffer)
 Save Serializable into buffer of length getSerializableSize
 
bool load (const std::uint8_t *buffer)
 Load Serializable from buffer of length getSerializableSize
 

Static Public Attributes

static constexpr Platform platform = PLATFORM
 

Additional Inherited Members

- Protected Member Functions inherited from olb::BlockD< T, DESCRIPTOR >
template<typename F >
auto dispatch (F &&f) const
 Calls f on concrete implementation of the BlockD interface.
 
template<typename F >
auto dispatch (F &&f)
 
- Protected Member Functions inherited from olb::Serializable
template<typename DataType >
void registerVar (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, const DataType &data, const size_t arrayLength=1) const
 Register primitive data types (int, double, ...) or arrays of those.
 
template<typename DataType >
void registerSerializableOfConstSize (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, DataType &data, const bool loadingMode=false)
 Register Serializable object of constant size.
 
template<typename DataType >
void registerSerializablesOfConstSize (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, DataType *data, const size_t arrayLength, const bool loadingMode=false)
 Register an array of Serializable objects of constant size.
 
- Protected Attributes inherited from olb::BlockD< T, DESCRIPTOR >
const Platform _platform
 
- Protected Attributes inherited from olb::BlockStructureD< D >
LatticeR< D > _core
 
LatticeR< D > _size
 
LatticeR< D > _projection
 
int _padding
 

Detailed Description

template<typename T, typename DESCRIPTOR, Platform PLATFORM>
class olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >

Implementation of BlockD on a concrete PLATFORM.

Definition at line 32 of file cell.h.

Member Typedef Documentation

◆ descriptor_t

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
using olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::descriptor_t = DESCRIPTOR

Definition at line 259 of file blockD.h.

◆ value_t

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
using olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::value_t = T

Definition at line 258 of file blockD.h.

Constructor & Destructor Documentation

◆ ConcreteBlockD()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::ConcreteBlockD ( Vector< int, DESCRIPTOR::d > size,
int padding = 0 )

Definition at line 43 of file blockD.hh.

44 : BlockD<T,DESCRIPTOR>(size, padding, PLATFORM),
45 _data(this->getNcells()),
46 _descriptorFields()
47{
48 DESCRIPTOR::fields_t::for_each([&](auto id) {
49 using field = typename decltype(id)::type;
50 auto& fieldArray = _data.template get<Array<field>>();
51 _descriptorFields.template set<field>(&fieldArray);
52 _communicatables[typeid(field)] = std::unique_ptr<Communicatable>(new ConcreteCommunicatable<
53 ColumnVector<typename ImplementationOf<typename field::template column_type<T>,PLATFORM>::type,
54 DESCRIPTOR::template size<field>()>
55 >(fieldArray));
56 });
57}
BlockD(Vector< int, DESCRIPTOR::d > size, int padding, Platform platform)
Definition blockD.hh:33
BlockLatticeRowView< T, DESCRIPTOR > get(std::size_t iCell)
Definition blockD.h:230
std::size_t getNcells() const
Get number of cells.
std::enable_if_t< DESCRIPTOR::d==2, std::shared_ptr< SuperF2D< T > > > field(SuperLattice< T, DESCRIPTOR > &sLattice)
Returns external field functor.

References olb::BlockD< T, DESCRIPTOR >::get().

+ Here is the call graph for this function:

Member Function Documentation

◆ apply()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename OPERATOR >
void olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::apply ( )
inline

Definition at line 335 of file blockD.h.

335 {
336 static_assert(OPERATOR::scope == OperatorScope::PerBlock,
337 "OPERATOR is not PerBlock scoped");
338 OPERATOR{}.apply(*this);
339 }
#define OPERATOR(OP, rhs)
Definition aDiffTape.h:64
@ PerBlock
Per-block application, i.e. OPERATOR::apply is passed a ConcreteBlockLattice.

References OPERATOR, and olb::PerBlock.

◆ getBlock()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
bool * olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::getBlock ( std::size_t iBlock,
std::size_t & sizeBlock,
bool loadingMode )
overridevirtual

Return a pointer to the memory of the current block and its size for the serializable interface.

Implements olb::Serializable.

Definition at line 145 of file blockD.hh.

146{
147 std::size_t currentBlock = 0;
148 bool* dataPtr = nullptr;
149 this->registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _data, loadingMode);
150 return dataPtr;
151}
void registerSerializableOfConstSize(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, DataType &data, const bool loadingMode=false)
Register Serializable object of constant size.
Definition serializer.h:239

◆ getCommunicatable()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
Communicatable & olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::getCommunicatable ( std::type_index field)
inlineoverridevirtual

Implements olb::BlockD< T, DESCRIPTOR >.

Definition at line 286 of file blockD.h.

286 {
287 return *_communicatables.at(field).get();
288 }

◆ getData() [1/2]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD_TYPE >
auto & olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::getData ( )

Definition at line 84 of file blockD.hh.

85{
86 if (_data.template provides<FIELD_TYPE>()) {
87 return _data.template get<FIELD_TYPE>();
88 } else {
89 // TODO: Implement more generic approach to constructing arbitrary data from specific args
90 auto& data = _data.template allocate<FIELD_TYPE>(this->getNcells());
91 // Manage serializables and communicatables for array fields
92 using concrete_data_t = typename FIELD_TYPE::template type<T,DESCRIPTOR,PLATFORM>;
93 if constexpr (std::is_base_of_v<ColumnVectorBase,concrete_data_t>) {
94 using field_t = typename concrete_data_t::field_t;
95 if constexpr (field_t::isSerializable()) {
96 _data.template setSerialization<FIELD_TYPE>(true);
97 }
98 _communicatables[typeid(field_t)] = std::unique_ptr<Communicatable>(new ConcreteCommunicatable<
99 ColumnVector<typename ImplementationOf<typename field_t::template column_type<T>,PLATFORM>::type,
100 DESCRIPTOR::template size<field_t>()>
101 >(data));
102 }
103 return data;
104 }
105 __builtin_unreachable();
106}

◆ getData() [2/2]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD_TYPE >
const auto & olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::getData ( ) const

Definition at line 75 of file blockD.hh.

76{
77 OLB_ASSERT(_data.template provides<FIELD_TYPE>(),
78 "FIELD_TYPE must be allocated to be accessed");
79 return _data.template get<FIELD_TYPE>();
80}
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45

References OLB_ASSERT.

◆ getDataRegistry()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
auto & olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::getDataRegistry ( )
inline

Return reference to Data's FieldTypeRegistry.

Only of interest for implementing specific device support

Definition at line 330 of file blockD.h.

330 {
331 return _data.getRegistry();
332 }

References olb::ConcreteData< T, DESCRIPTOR, PLATFORM >::getRegistry().

+ Here is the call graph for this function:

◆ getField() [1/2]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD >
auto & olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::getField ( FIELD field = FIELD())

Definition at line 110 of file blockD.hh.

111{
112 if constexpr (DESCRIPTOR::fields_t::template contains<FIELD>()) {
113 return static_cast<FieldArrayD<T,DESCRIPTOR,PLATFORM,FIELD>&>(*_descriptorFields.template get<FIELD>());
114 } else {
115 return getData<Array<FIELD>>();
116 }
117 __builtin_unreachable();
118}
const auto & getData() const
Definition blockD.hh:75

◆ getField() [2/2]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD >
const auto & olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::getField ( FIELD field = FIELD()) const

Definition at line 122 of file blockD.hh.

123{
124 if constexpr (DESCRIPTOR::fields_t::template contains<FIELD>()) {
125 return static_cast<const FieldArrayD<T,DESCRIPTOR,PLATFORM,FIELD>&>(*_descriptorFields.template get<FIELD>());
126 } else {
127 return getData<Array<FIELD>>();
128 }
129 __builtin_unreachable();
130}

◆ getNblock()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
std::size_t olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::getNblock ( ) const
overridevirtual

Number of data blocks for the serializable interface.

Implements olb::Serializable.

Definition at line 133 of file blockD.hh.

134{
135 return _data.getNblock();
136}

◆ getSerializableSize()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
std::size_t olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::getSerializableSize ( ) const
overridevirtual

Binary size for the serializer.

Implements olb::Serializable.

Definition at line 139 of file blockD.hh.

140{
141 return _data.getSerializableSize();
142}

◆ hasCommunicatable()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
bool olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::hasCommunicatable ( std::type_index field) const
inlineoverridevirtual

Implements olb::BlockD< T, DESCRIPTOR >.

Definition at line 283 of file blockD.h.

283 {
284 return _communicatables.find(field) != _communicatables.end();
285 }

◆ hasData()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD_TYPE >
bool olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::hasData ( ) const

Definition at line 68 of file blockD.hh.

69{
70 return _data.template provides<FIELD_TYPE>();
71}

◆ postLoad()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
void olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::postLoad ( )
overridevirtual

Reinit population structure after deserialization.

Reimplemented from olb::Serializable.

Definition at line 154 of file blockD.hh.

155{
156 if constexpr (DESCRIPTOR::template provides<descriptors::POPULATION>()) {
157 auto& population = getField<descriptors::POPULATION>();
158 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
159 population[iPop].postLoad();
160 }
161 }
162}
const auto & getField(FIELD field=FIELD()) const
Definition blockD.hh:122

◆ resize()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
void olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::resize ( Vector< int, DESCRIPTOR::d > size)
overridevirtual

Implements olb::BlockD< T, DESCRIPTOR >.

Definition at line 60 of file blockD.hh.

61{
62 static_cast<BlockStructureD<DESCRIPTOR::d>*>(this)->resize(size);
63 _data.resize(this->getNcells());
64}
void resize(Vector< int, DESCRIPTOR::d > size) override
Definition blockD.hh:60
+ Here is the caller graph for this function:

◆ setParameter() [1/3]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename PARAMETER , typename FIELD >
void olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::setParameter ( AbstractFieldArrayD< T, DESCRIPTOR, FIELD > & abstractFieldArray)
inline

Definition at line 320 of file blockD.h.

321 {
322 auto& fieldArray = dynamic_cast<FieldArrayD<T,DESCRIPTOR,PLATFORM,FIELD>&>(abstractFieldArray);
323 setParameter<PARAMETER>(fieldArray);
324 }
void setParameter(FieldD< T, DESCRIPTOR, FIELD > value)
Definition blockD.h:291

References olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::setParameter().

+ Here is the call graph for this function:

◆ setParameter() [2/3]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename PARAMETER , Platform _PLATFORM, typename FIELD >
void olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::setParameter ( FieldArrayD< T, DESCRIPTOR, _PLATFORM, FIELD > & fieldArray)
inline

Definition at line 303 of file blockD.h.

304 {
305 if constexpr (PLATFORM == Platform::GPU_CUDA) {
306 static_assert(PLATFORM == _PLATFORM, "FieldArrayD must be available on PLATFORM");
307 }
308 FieldD<T,DESCRIPTOR,PARAMETER> fieldArrayPointers;
309 for (unsigned iD=0; iD < fieldArray.d; ++iD) {
310 if constexpr (PLATFORM == Platform::GPU_CUDA) {
311 fieldArrayPointers[iD] = fieldArray[iD].deviceData();
312 } else {
313 fieldArrayPointers[iD] = fieldArray[iD].data();
314 }
315 }
316 setParameter<PARAMETER>(std::move(fieldArrayPointers));
317 }
@ GPU_CUDA
Vector CPU (AVX2 / AVX-512 collision)
Vector< typename FIELD::template value_type< T >, DESCRIPTOR::template size< FIELD >() > FieldD
Vector storing a single field instance.
Definition vector.h:480

References olb::ColumnVector< COLUMN, D >::d, olb::GPU_CUDA, and olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::setParameter().

+ Here is the call graph for this function:

◆ setParameter() [3/3]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD >
void olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::setParameter ( FieldD< T, DESCRIPTOR, FIELD > value)
inline

Definition at line 291 of file blockD.h.

292 {
293 _data.template forEachCastable<AbstractedConcreteParameters<T,DESCRIPTOR>>([&](auto* parameters) {
294 auto& params = parameters->asAbstract();
295 if (params.template provides<FIELD>()) {
296 params.template set<FIELD>(value);
297 parameters->setProcessingContext(ProcessingContext::Simulation);
298 }
299 });
300 }
@ Simulation
Data available on host for e.g. functor evaluation.

References olb::Simulation.

+ Here is the caller graph for this function:

◆ setProcessingContext()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
void olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::setProcessingContext ( ProcessingContext )
inlineoverridevirtual

Set processing context.

This is currently used to trigger data transfers between host and GPU data for Platform::GPU_CUDA.

Implements olb::BlockD< T, DESCRIPTOR >.

Definition at line 265 of file blockD.h.

265 {
266 _data.setProcessingContext(context);
267 }

References olb::ConcreteData< T, DESCRIPTOR, PLATFORM >::setProcessingContext().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ platform

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
Platform olb::ConcreteBlockD< T, DESCRIPTOR, PLATFORM >::platform = PLATFORM
staticconstexpr

Definition at line 261 of file blockD.h.


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