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

List of cell indices and associated field data. More...

#include <cellIndexListD.h>

+ Inheritance diagram for olb::CellIndexListD< T, DESCRIPTOR, FIELDS >:
+ Collaboration diagram for olb::CellIndexListD< T, DESCRIPTOR, FIELDS >:

Public Member Functions

 CellIndexListD (std::size_t capacity=64)
 
 CellIndexListD (std::vector< CellID > &&indices)
 
std::size_t size () const
 
std::size_t append (std::size_t iCell)
 Append cell index and allocate attached field data.
 
void sort ()
 Ascending sort of cell indices.
 
template<typename FIELD >
auto getFieldPointer (std::size_t index)
 Return pointer to FIELD at index.
 
template<typename FIELD >
auto getField (std::size_t index) const
 Return copy of FIELD data at index.
 
template<typename FIELD >
void setField (std::size_t index, const FieldD< T, DESCRIPTOR, FIELD > &v)
 Set FIELD data at index.
 
template<typename FIELD >
const auto & getFieldArray () const
 
std::size_t getNblock () const override
 Returns the number of blocks.
 
std::size_t getSerializableSize () const override
 Returns the binary size of the data to be saved.
 
bool * getBlock (std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
 Returns the address of the i-th block and its size.
 
- 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, typename... FIELDS>
class olb::CellIndexListD< T, DESCRIPTOR, FIELDS >

List of cell indices and associated field data.

To be used as a possible input for upcoming Operators.

e.g. a velocity boundary operator accepts such a CellIndexListD containing the indices of boundary cells together with the velocity field to be applied.

Definition at line 49 of file cellIndexListD.h.

Constructor & Destructor Documentation

◆ CellIndexListD() [1/2]

template<typename T , typename DESCRIPTOR , typename... FIELDS>
olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::CellIndexListD ( std::size_t capacity = 64)
inline

Definition at line 56 of file cellIndexListD.h.

56 :
57 _count(0),
58 _capacity(capacity),
59 _fields(capacity)
60 { }

◆ CellIndexListD() [2/2]

template<typename T , typename DESCRIPTOR , typename... FIELDS>
olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::CellIndexListD ( std::vector< CellID > && indices)
inline

Definition at line 62 of file cellIndexListD.h.

62 :
63 _capacity(indices.size()),
64 _fields(_capacity)
65 {
66 for (std::size_t i=0; i < indices.size(); ++i) {
67 _fields.template get<descriptors::CELL_ID>()[0][i] = indices[i];
68 }
69 }

Member Function Documentation

◆ append()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
std::size_t olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::append ( std::size_t iCell)

Append cell index and allocate attached field data.

Definition at line 118 of file cellIndexListD.h.

119{
120 if (_count == _capacity) {
121 _capacity *= 2;
122 _fields.resize(_capacity);
123 }
124 _fields.template get<descriptors::CELL_ID>()[0][_count] = iCell;
125 return _count++;
126}

◆ getBlock()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
bool * olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::getBlock ( std::size_t iBlock,
std::size_t & sizeBlock,
bool loadingMode )
overridevirtual

Returns the address of the i-th block and its size.

Parameters
iBlockIndex of the block to be returned
sizeBlockReference to the size of the returned block
Returns
Pointer to the current block

Each getBlock() method should look like this:

std::size_t currentBlock = 0;
bool* dataPtr = nullptr;

// ... register methods...

return dataPtr;

Implements olb::Serializable.

Definition at line 169 of file cellIndexListD.h.

170{
171 std::size_t currentBlock = 0;
172 bool* dataPtr = nullptr;
173
174 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _count);
175 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _capacity);
176 if (loadingMode && iBlock == 2) {
177 _fields.resize(_capacity);
178 }
179 registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _fields, loadingMode);
180
181 return dataPtr;
182}
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.
Definition serializer.h:212
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

◆ getField()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
template<typename FIELD >
auto olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::getField ( std::size_t index) const
inline

Return copy of FIELD data at index.

Definition at line 94 of file cellIndexListD.h.

95 {
96 return _fields.template getField<FIELD>(index);
97 }

◆ getFieldArray()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
template<typename FIELD >
const auto & olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::getFieldArray ( ) const
inline

Definition at line 106 of file cellIndexListD.h.

107 {
108 return _fields.template get<FIELD>();
109 }

◆ getFieldPointer()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
template<typename FIELD >
auto olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::getFieldPointer ( std::size_t index)
inline

Return pointer to FIELD at index.

Definition at line 87 of file cellIndexListD.h.

88 {
89 return _fields.template get<FIELD>().getRowPointer(index);
90 }

◆ getNblock()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
std::size_t olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::getNblock ( ) const
overridevirtual

Returns the number of blocks.

All Serializable classes have to implement this method.

Implements olb::Serializable.

Definition at line 155 of file cellIndexListD.h.

156{
157 return 2
158 + _fields.getNblock();
159}

◆ getSerializableSize()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
std::size_t olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::getSerializableSize ( ) const
overridevirtual

Returns the binary size of the data to be saved.

This method must be overloaded by all child classes.

Implements olb::Serializable.

Definition at line 162 of file cellIndexListD.h.

163{
164 return 2 * sizeof(std::size_t)
165 + _fields.getSerializableSize();
166}

◆ setField()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
template<typename FIELD >
void olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::setField ( std::size_t index,
const FieldD< T, DESCRIPTOR, FIELD > & v )
inline

Set FIELD data at index.

Definition at line 100 of file cellIndexListD.h.

101 {
102 return _fields.template setField<FIELD>(index, v);
103 }

◆ size()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
std::size_t olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::size ( ) const
inline

Definition at line 71 of file cellIndexListD.h.

71 {
72 return _count;
73 };

◆ sort()

template<typename T , typename DESCRIPTOR , typename... FIELDS>
void olb::CellIndexListD< T, DESCRIPTOR, FIELDS >::sort ( )

Ascending sort of cell indices.

Attached data is moved accordingly. Only useful for when processing chunks of sequential cell indices.

Definition at line 129 of file cellIndexListD.h.

130{
131 auto& cell_id = _fields.template get<descriptors::CELL_ID>()[0];
132 std::vector<std::size_t> permutation(_count);
133 std::iota(permutation.begin(), permutation.end(), 0);
134 std::sort(permutation.begin(), permutation.end(), [&cell_id](auto i, auto j) {
135 return cell_id[i] < cell_id[j];
136 });
137 std::vector<bool> swapped(_count, false);
138 for (std::size_t i=0; i < _count; ++i) {
139 if (swapped[i]) {
140 continue;
141 }
142 swapped[i] = true;
143 std::size_t prev_j = i;
144 std::size_t next_j = permutation[i];
145 while (prev_j != next_j && !swapped[next_j]) {
146 _fields.swap(prev_j, next_j);
147 swapped[next_j] = true;
148 prev_j = next_j;
149 next_j = permutation[next_j];
150 }
151 }
152}

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