OpenLB 1.8.1
Loading...
Searching...
No Matches
blockD.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2024 Adrian Kummerlaender
4 *
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#ifndef BLOCK_D_HH
26#define BLOCK_D_HH
27
28#include "blockD.h"
29
30namespace olb {
31
32template<typename T, typename DESCRIPTOR>
34 : BlockStructure<DESCRIPTOR>(size, padding),
35 _platform(platform)
36{ }
37
38template<typename T, typename DESCRIPTOR>
41
42template<typename T, typename DESCRIPTOR, Platform PLATFORM>
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}
58
59template<typename T, typename DESCRIPTOR, Platform PLATFORM>
61{
62 static_cast<BlockStructureD<DESCRIPTOR::d>*>(this)->resize(size);
63 _data.resize(this->getNcells());
64}
65
66template<typename T, typename DESCRIPTOR, Platform PLATFORM>
67template<typename FIELD_TYPE>
69{
70 return _data.template provides<FIELD_TYPE>();
71}
72
73template<typename T, typename DESCRIPTOR, Platform PLATFORM>
74template<typename FIELD_TYPE>
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}
81
82template<typename T, typename DESCRIPTOR, Platform PLATFORM>
83template<typename FIELD_TYPE>
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}
107
108template<typename T, typename DESCRIPTOR, Platform PLATFORM>
109template<typename FIELD>
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}
119
120template<typename T, typename DESCRIPTOR, Platform PLATFORM>
121template<typename FIELD>
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}
131
132template<typename T, typename DESCRIPTOR, Platform PLATFORM>
134{
135 return _data.getNblock();
136}
137
138template<typename T, typename DESCRIPTOR, Platform PLATFORM>
140{
141 return _data.getSerializableSize();
142}
143
144template<typename T, typename DESCRIPTOR, Platform PLATFORM>
145bool* ConcreteBlockD<T,DESCRIPTOR,PLATFORM>::getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode)
146{
147 std::size_t currentBlock = 0;
148 bool* dataPtr = nullptr;
149 this->registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _data, loadingMode);
150 return dataPtr;
151}
152
153template<typename T, typename DESCRIPTOR, Platform PLATFORM>
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}
163
164}
165
166#endif
BlockD(Vector< int, DESCRIPTOR::d > size, int padding, Platform platform)
Definition blockD.hh:33
virtual ~BlockD()
Definition blockD.hh:39
BlockLatticeRowView< T, DESCRIPTOR > get(std::size_t iCell)
Definition blockD.h:230
Base of a regular block.
Vector of columns.
const auto & getData() const
Definition blockD.hh:75
void resize(Vector< int, DESCRIPTOR::d > size) override
Definition blockD.hh:60
ConcreteBlockD(Vector< int, DESCRIPTOR::d > size, int padding=0)
Definition blockD.hh:43
void postLoad() override
Reinit population structure after deserialization.
Definition blockD.hh:154
bool hasData() const
Definition blockD.hh:68
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.
Definition blockD.hh:145
std::size_t getSerializableSize() const override
Binary size for the serializer.
Definition blockD.hh:139
std::size_t getNblock() const override
Number of data blocks for the serializable interface.
Definition blockD.hh:133
const auto & getField(FIELD field=FIELD()) const
Definition blockD.hh:122
SoA storage for instances of a single FIELD.
Plain old scalar vector.
Top level namespace for all of OpenLB.
Platform
OpenLB execution targets.
Definition platform.h:35
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45
Specializable declarator for concrete implementations of abstract storage types.
Definition column.h:56