OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::Data< T, DESCRIPTOR, PLATFORM > Class Template Referencefinal

Storage of any FIELD_TYPE data on PLATFORM. More...

#include <data.h>

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

Public Member Functions

template<typename FIELD_TYPE >
bool provides () const
 Returns true iff FIELD_TYPE is allocated and can be accessed.
 
template<typename FIELD_TYPE , typename... ARGS>
auto & allocate (ARGS &&... args)
 Allocate and return FIELD_TYPE data.
 
template<typename FIELD_TYPE >
void setSerialization (bool active)
 Sets FIELD_TYPE serialization state to active.
 
template<typename FIELD_TYPE >
auto & get ()
 Return reference to data of FIELD_TYPE.
 
template<typename FIELD >
FieldArrayD< T, DESCRIPTOR, PLATFORM, FIELD > & getFieldArray ()
 Return reference to data of Array<FIELD>, i.e. FieldArrayD<FIELD>
 
void setProcessingContext (ProcessingContext context)
 
template<typename F >
void forEach (F f)
 Call f for each managed AnyFieldType.
 
template<typename TYPE , typename F >
void forEachCastable (F f)
 Call f for each managed AnyFieldType of TYPE.
 
auto & getRegistry ()
 Expose FieldTypeRegistry for device-support.
 
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.
 
- 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
 
virtual void postLoad ()
 

Additional Inherited Members

- 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.
 

Detailed Description

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

Storage of any FIELD_TYPE data on PLATFORM.

Manages access and serialization of dynamically allocated FIELD_TYPE data. This is the core storage class used for ConcreteBlockLattice on any platform supported by OpenLB.

Definition at line 155 of file data.h.

Member Function Documentation

◆ allocate()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD_TYPE , typename... ARGS>
auto & olb::Data< T, DESCRIPTOR, PLATFORM >::allocate ( ARGS &&... args)
inline

Allocate and return FIELD_TYPE data.

Must only be called once for each FIELD_TYPE

Definition at line 176 of file data.h.

176 {
177 _map[typeid(FIELD_TYPE)] = std::make_unique<AnyFieldType<T,DESCRIPTOR,PLATFORM>>(
178 meta::id<FIELD_TYPE>(), std::forward<decltype(args)>(args)...);
179
180 AnyFieldType<T,DESCRIPTOR,PLATFORM>* newField = _map[typeid(FIELD_TYPE)].get();
181 _registry.template track<FIELD_TYPE>(newField);
182 return *newField->template as<FIELD_TYPE>();
183 }
auto & get()
Return reference to data of FIELD_TYPE.
Definition data.h:202

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

+ Here is the call graph for this function:

◆ forEach()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename F >
void olb::Data< T, DESCRIPTOR, PLATFORM >::forEach ( F f)
inline

Call f for each managed AnyFieldType.

Definition at line 223 of file data.h.

223 {
224 for (auto& [_, field] : _map) {
225 f(*field);
226 }
227 }
+ Here is the caller graph for this function:

◆ forEachCastable()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename TYPE , typename F >
void olb::Data< T, DESCRIPTOR, PLATFORM >::forEachCastable ( F f)
inline

Call f for each managed AnyFieldType of TYPE.

Used to e.g. iterate over all field arrays

Definition at line 234 of file data.h.

234 {
235 forEach([&f](AnyFieldType<T,DESCRIPTOR,PLATFORM>& any) {
236 if (auto casted = any.template tryAs<TYPE>()) {
237 f(*casted);
238 }
239 });
240 }
void forEach(F f)
Call f for each managed AnyFieldType.
Definition data.h:223

References olb::Data< T, DESCRIPTOR, PLATFORM >::forEach().

+ Here is the call graph for this function:

◆ get()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD_TYPE >
auto & olb::Data< T, DESCRIPTOR, PLATFORM >::get ( )
inline

Return reference to data of FIELD_TYPE.

Definition at line 202 of file data.h.

202 {
203 return *_registry.template get<FIELD_TYPE>()->template as<FIELD_TYPE>();
204 }
+ Here is the caller graph for this function:

◆ getBlock()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
bool * olb::Data< 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 277 of file data.h.

278{
279 std::size_t currentBlock = 0;
280 bool* dataPtr = nullptr;
281
282 for (const auto& [_, serializable] : _serializationNames) {
283 registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, *serializable, loadingMode);
284 }
285
286 return dataPtr;
287}
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

◆ getFieldArray()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD >
FieldArrayD< T, DESCRIPTOR, PLATFORM, FIELD > & olb::Data< T, DESCRIPTOR, PLATFORM >::getFieldArray ( )
inline

Return reference to data of Array<FIELD>, i.e. FieldArrayD<FIELD>

Most common field type, used for any lattice structured data in ConcreteBlockLattice

Definition at line 211 of file data.h.

211 {
212 return get<Array<FIELD>>();
213 }

◆ getNblock()

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

Number of data blocks for the serializable interface.

Implements olb::Serializable.

Definition at line 257 of file data.h.

258{
259 std::size_t nBlock = 0;
260 for (const auto& [_, serializable] : _serializationNames) {
261 nBlock += serializable->getNblock();
262 }
263 return nBlock;
264}

◆ getRegistry()

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

Expose FieldTypeRegistry for device-support.

Definition at line 243 of file data.h.

243 {
244 return _registry;
245 }
+ Here is the caller graph for this function:

◆ getSerializableSize()

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

Binary size for the serializer.

Implements olb::Serializable.

Definition at line 267 of file data.h.

268{
269 std::size_t size = 0;
270 for (const auto& [_, serializable] : _serializationNames) {
271 size += serializable->getSerializableSize();
272 }
273 return size;
274}

◆ provides()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD_TYPE >
bool olb::Data< T, DESCRIPTOR, PLATFORM >::provides ( ) const
inline

Returns true iff FIELD_TYPE is allocated and can be accessed.

Definition at line 167 of file data.h.

167 {
168 return _registry.template provides<FIELD_TYPE>();
169 }

◆ setProcessingContext()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
void olb::Data< T, DESCRIPTOR, PLATFORM >::setProcessingContext ( ProcessingContext context)
inline

Definition at line 215 of file data.h.

215 {
216 for (auto& [_, field] : _map) {
217 field->setProcessingContext(context);
218 }
219 }
std::enable_if_t< DESCRIPTOR::d==2, std::shared_ptr< SuperF2D< T > > > field(SuperLattice< T, DESCRIPTOR > &sLattice)
Returns external field functor.
+ Here is the caller graph for this function:

◆ setSerialization()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
template<typename FIELD_TYPE >
void olb::Data< T, DESCRIPTOR, PLATFORM >::setSerialization ( bool active)
inline

Sets FIELD_TYPE serialization state to active.

By default Data doesn't (de)serialize any fields but ConcreteBlockLattice sets all descriptor-declared field arrays to active.

Definition at line 192 of file data.h.

192 {
193 if (active) {
194 _serializationNames[meta::name<FIELD_TYPE>()] = _registry.template get<FIELD_TYPE>()->asSerializable();
195 } else {
196 _serializationNames.erase(meta::name<FIELD_TYPE>());
197 }
198 }

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