OpenLB 1.7
Loading...
Searching...
No Matches
fieldParametersD.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef FIELD_PARAMETERS_D_H
25#define FIELD_PARAMETERS_D_H
26
27#include "fieldArrayD.h"
28
29#include <stdexcept>
30
31namespace olb {
32
34template <typename T, typename DESCRIPTOR, typename FIELD>
36private:
37 std::conditional_t<
38 DESCRIPTOR::template size<FIELD>() == 1,
39 typename FIELD::template value_type<T>,
41 > _data;
42
43public:
44 using data_t = decltype(_data);
45
46 ParameterD() = default;
47
48 template <typename V>
50 _data(rhs.read()) { }
51
52 const auto& read() const any_platform {
53 return _data;
54 }
55
57 return _data;
58 }
59
61 if constexpr (DESCRIPTOR::template size<FIELD>() == 1) {
62 _data = value[0];
63 } else {
64 _data = value;
65 }
66 }
67
69 if constexpr (DESCRIPTOR::template size<FIELD>() == 1) {
70 _data = value[0];
71 } else {
72 _data = value;
73 }
74 }
75};
76
78template <typename T, typename DESCRIPTOR>
80 virtual ~AbstractParameters() = default;
81
82 template <typename FIELD>
83 bool provides() const {
84 if (auto concrete = dynamic_cast<const ParameterD<T,DESCRIPTOR,FIELD>*>(this)) {
85 return true;
86 } else {
87 return false;
88 }
89 };
90
91 template <typename FIELD>
92 auto get() const {
93 if (auto concrete = dynamic_cast<const ParameterD<T,DESCRIPTOR,FIELD>*>(this)) {
94 return concrete->read();
95 } else {
96 throw std::invalid_argument("FIELD not provided by this parameter set");
97 }
98 };
99
100 template <typename FIELD>
102 if (auto concrete = dynamic_cast<const ParameterD<T,DESCRIPTOR,FIELD>*>(this)) {
103 return concrete->read();
104 } else {
105 return fallback;
106 }
107 }
108
109 template <typename FIELD>
111 if (auto concrete = dynamic_cast<ParameterD<T,DESCRIPTOR,FIELD>*>(this)) {
112 return concrete->write(std::forward<decltype(value)>(value));
113 } else {
114 throw std::invalid_argument("FIELD not provided by this parameter set");
115 }
116 };
117
118 template <typename FIELD>
119 void set(const FieldD<T,DESCRIPTOR,FIELD>& value) {
120 if (auto concrete = dynamic_cast<ParameterD<T,DESCRIPTOR,FIELD>*>(this)) {
121 return concrete->write(value);
122 } else {
123 throw std::invalid_argument("FIELD not provided by this parameter set");
124 }
125 };
126
127};
128
130template <typename T, typename DESCRIPTOR, typename... FIELDS>
131struct ParametersD final : public AbstractParameters<T,DESCRIPTOR>
132 , public ParameterD<T,DESCRIPTOR,FIELDS>...
133{
134 using fields_t = meta::list<FIELDS...>;
135
136 template <typename... Fs>
137 using include_fields = ParametersD<T,DESCRIPTOR,FIELDS...,Fs...>;
139 template <typename FIELD_LIST>
140 using include = typename FIELD_LIST::template decompose_into<include_fields>;
141
142 ParametersD() = default;
143
144 template <typename V>
148
149 template <typename FIELD>
150 bool provides() const any_platform {
151 return fields_t::template contains<FIELD>();
152 }
153
154 template <typename FIELD>
155 const auto& get() const any_platform {
156 return static_cast<const ParameterD<T,DESCRIPTOR,FIELD>*>(this)->read();
157 }
158
159 template <typename V>
160 ParametersD<V,DESCRIPTOR,FIELDS...> copyAs() const any_platform {
161 return ParametersD<V,DESCRIPTOR,FIELDS...>(*this);
162 }
163
164 template <typename FIELD>
166 return static_cast<ParameterD<T,DESCRIPTOR,FIELD>*>(this)->read();
167 }
168
169 template <typename FIELD>
171 return static_cast<ParameterD<T,DESCRIPTOR,FIELD>*>(this)->write(
172 std::forward<decltype(value)>(value));
173 };
174
175 template <typename FIELD>
177 return static_cast<ParameterD<T,DESCRIPTOR,FIELD>*>(this)->write(value);
178 };
179
180};
181
183template <typename T, typename DESCRIPTOR, typename OPERATOR>
185 typename OPERATOR::parameters
186>;
187
189template <typename DYNAMICS>
191 typename DYNAMICS::value_t,
192 typename DYNAMICS::descriptor_t
193>::template include<
194 typename DYNAMICS::parameters
195>;
196
198
201template <typename T, typename DESCRIPTOR>
207
209
214template <typename T, typename DESCRIPTOR, Platform PLATFORM, typename PARAMETERS>
215struct ConcreteParametersD final : public AbstractedConcreteParameters<T,DESCRIPTOR>
216 , public Serializable {
218
219 ConcreteParametersD(std::size_t): // TODO: Implement more generic non-cellwise field allocation in Data
220 parameters{}
221 { }
222
227
228 void setProcessingContext(ProcessingContext context) override { }
229
231 std::size_t getNblock() const override;
233 std::size_t getSerializableSize() const override;
235 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
236
237};
238
239
240}
241
242#endif
Storage of a single FIELD-valued parameter.
auto & read() any_platform
ParameterD(const ParameterD< V, DESCRIPTOR, FIELD > &rhs) any_platform
void write(const FieldD< T, DESCRIPTOR, FIELD > &value) any_platform
const auto & read() const any_platform
void write(FieldD< T, DESCRIPTOR, FIELD > &&value) any_platform
ParameterD()=default
decltype(_data) data_t
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
Definition serializer.h:145
Plain old scalar vector.
Definition vector.h:47
Top level namespace for all of OpenLB.
ProcessingContext
OpenLB processing contexts.
Definition platform.h:55
typename ParametersD< T, DESCRIPTOR >::template include< typename OPERATOR::parameters > ParametersOfOperatorD
Deduce ParametersD of OPERATOR w.r.t. T and DESCRIPTOR.
typename ParametersD< typename DYNAMICS::value_t, typename DYNAMICS::descriptor_t >::template include< typename DYNAMICS::parameters > ParametersOfDynamicsD
Deduce ParametersD of DYNAMICS w.r.t. its value type and descriptor.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78
Dynamic access interface for FIELD-valued parameters.
void set(const FieldD< T, DESCRIPTOR, FIELD > &value)
void set(FieldD< T, DESCRIPTOR, FIELD > &&value)
auto getOrFallback(typename ParameterD< T, DESCRIPTOR, FIELD >::data_t &&fallback) const
virtual ~AbstractParameters()=default
Abstract base of ConcreteParametersD.
virtual void setProcessingContext(ProcessingContext context)=0
virtual AbstractParameters< T, DESCRIPTOR > & asAbstract()=0
Concrete storage of ParametersD in olb::Data.
std::size_t getNblock() const override
Number of data blocks for the serializable interface.
AbstractParameters< T, DESCRIPTOR > & asAbstract() override
Return abstract interface to host-side parameters.
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 setProcessingContext(ProcessingContext context) override
ParametersD< T, DESCRIPTOR >::template include< PARAMETERS > parameters
std::size_t getSerializableSize() const override
Binary size for the serializer.
Set of FIELD-valued parameters.
bool provides() const any_platform
ParametersD< V, DESCRIPTOR, FIELDS... > copyAs() const any_platform
typename FIELD_LIST::template decompose_into< include_fields > include
Return ParametersD containing FIELDS in addition to all entries of FIELD_LIST.
const auto & get() const any_platform
ParametersD()=default
auto & get() any_platform
void set(FieldD< T, DESCRIPTOR, FIELD > &&value) any_platform
void set(const FieldD< T, DESCRIPTOR, FIELD > &value) any_platform
ParametersD(const ParametersD< V, DESCRIPTOR, FIELDS... > &rhs) any_platform