24#ifndef CELL_INDEX_LIST_D_H
25#define CELL_INDEX_LIST_D_H
48template <
typename T,
typename DESCRIPTOR,
typename... FIELDS>
52 std::size_t _capacity;
63 _capacity(indices.
size()),
66 for (std::size_t i=0; i < indices.size(); ++i) {
67 _fields.template get<descriptors::CELL_ID>()[0][i] = indices[i];
76 std::size_t
append(std::size_t iCell);
86 template <
typename FIELD>
89 return _fields.template get<FIELD>().getRowPointer(index);
93 template <
typename FIELD>
96 return _fields.template getField<FIELD>(index);
99 template <
typename FIELD>
102 return _fields.template setField<FIELD>(index, v);
105 template <
typename FIELD>
108 return _fields.template get<FIELD>();
113 bool*
getBlock(std::size_t iBlock, std::size_t& sizeBlock,
bool loadingMode)
override;
117template <
typename T,
typename DESCRIPTOR,
typename... FIELDS>
120 if (_count == _capacity) {
122 _fields.resize(_capacity);
124 _fields.template get<descriptors::CELL_ID>()[0][_count] = iCell;
128template <
typename T,
typename DESCRIPTOR,
typename... FIELDS>
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];
137 std::vector<bool> swapped(_count,
false);
138 for (std::size_t i=0; i < _count; ++i) {
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;
149 next_j = permutation[next_j];
154template <
typename T,
typename DESCRIPTOR,
typename... FIELDS>
158 + _fields.getNblock();
161template <
typename T,
typename DESCRIPTOR,
typename... FIELDS>
164 return 2 *
sizeof(std::size_t)
165 + _fields.getSerializableSize();
168template <
typename T,
typename DESCRIPTOR,
typename... FIELDS>
171 std::size_t currentBlock = 0;
172 bool* dataPtr =
nullptr;
174 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _count);
175 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _capacity);
176 if (loadingMode && iBlock == 2) {
177 _fields.resize(_capacity);
179 registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _fields, loadingMode);
List of cell indices and associated field data.
const auto & getFieldArray() const
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
Returns the address of the i-th block and its size.
auto getField(std::size_t index) const
Return copy of FIELD data at index.
std::size_t getNblock() const override
Returns the number of blocks.
void sort()
Ascending sort of cell indices.
std::size_t getSerializableSize() const override
Returns the binary size of the data to be saved.
auto getFieldPointer(std::size_t index)
Return pointer to FIELD at index.
std::size_t append(std::size_t iCell)
Append cell index and allocate attached field data.
void setField(std::size_t index, const FieldD< T, DESCRIPTOR, FIELD > &v)
Set FIELD data at index.
CellIndexListD(std::size_t capacity=64)
CellIndexListD(std::vector< CellID > &&indices)
Storage for a fixed set of static FIELDS and arbitrary custom fields.
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
Top level namespace for all of OpenLB.