OpenLB 1.8.1
Loading...
Searching...
No Matches
operator.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 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 GPU_CUDA_OPERATOR_H
25#define GPU_CUDA_OPERATOR_H
26
27#include "core/operator.h"
28
29#include "dynamics/dynamics.h"
30
31#include "device.h"
32#include "mask.h"
33#include "context.h"
34#include "dynamics.h"
35
36namespace olb {
37
38namespace gpu::cuda {
39
40template <typename T, typename DESCRIPTOR, typename... DYNAMICS>
41std::function<void(ConcreteBlockLattice<T,DESCRIPTOR,Platform::GPU_CUDA>&)> getFusedCollisionO();
42
43}
44
45
47template <typename T, typename DESCRIPTOR, typename DYNAMICS>
48class ConcreteBlockCollisionO<T,DESCRIPTOR,Platform::GPU_CUDA,DYNAMICS> final
49 : public BlockCollisionO<T,DESCRIPTOR,Platform::GPU_CUDA> {
50private:
51 std::unique_ptr<DYNAMICS> _dynamics;
52
55
56 gpu::cuda::Dynamics<T,DESCRIPTOR>** _dynamicsOfCells;
57
59
61 bool _modified;
62
64
71
72public:
74
75 std::type_index id() const override
76 {
77 return typeid(DYNAMICS);
78 }
79
80 std::size_t weight() const override
81 {
82 return _mask->weight();
83 }
84
85 void set(CellID iCell, bool state, bool overlap) override
86 {
88 if constexpr (!std::is_same_v<DYNAMICS,NoDynamics<T,DESCRIPTOR>>) {
89 if (!overlap) {
90 _mask->set(iCell, state);
91 }
92 }
93 if (state) {
94 _dynamicsOfCells[iCell] = _deviceDynamics.get();
95 }
96 _modified = true;
97 }
98
100 {
101 return _dynamics.get();
102 }
103
105
107
112 CollisionDispatchStrategy strategy) override
113 {
114 switch (strategy) {
116 return applyDominant(block, subdomain);
118 return applyIndividual(block, subdomain);
119 default:
120 throw std::runtime_error("Invalid collision dispatch strategy");
121 }
122 }
123
124};
125
126
128template <typename T, typename DESCRIPTOR, concepts::CellOperator OPERATOR>
130 : public BlockO<T,DESCRIPTOR,Platform::GPU_CUDA> {
131private:
133 bool _modified;
134
136
137public:
139
140 std::type_index id() const override
141 {
142 return typeid(OPERATOR);
143 }
144
145 std::size_t weight() const override
146 {
147 return _cells.size();
148 }
149
150 void set(CellID iCell, bool state) override
151 {
152 if (state) {
153 _cells.push_back(iCell);
154 _modified = true;
155 }
156 }
157
159 {
160 _modified = false;
161 }
162
164
165};
166
167
169template <typename T, typename DESCRIPTOR, concepts::CellOperator OPERATOR>
171 : public BlockO<T,DESCRIPTOR,Platform::GPU_CUDA> {
172private:
174 bool _modified;
175
177
179
180public:
182
183 std::type_index id() const override
184 {
185 return typeid(OPERATOR);
186 }
187
188 std::size_t weight() const override
189 {
190 return _cells.size();
191 }
192
193 void set(CellID iCell, bool state) override
194 {
195 if (state) {
196 _cells.push_back(iCell);
197 _modified = true;
198 }
199 }
200
202 {
203 _modified = false;
204 _parameters = &block.template getData<OperatorParameters<OPERATOR>>();
205 }
206
208
209};
210
211
213
216template <typename T, typename DESCRIPTOR, concepts::BlockOperator OPERATOR>
218 : public BlockO<T,DESCRIPTOR,Platform::GPU_CUDA> {
219public:
220 std::type_index id() const override
221 {
222 return typeid(OPERATOR);
223 }
224
225 std::size_t weight() const override
226 {
227 return 0;
228 }
229
230 void set(CellID iCell, bool state) override
231 {
232 throw std::logic_error("BlockO::set not supported for OperatorScope::PerBlock");
233 }
234
236 {
237 OPERATOR().setup(block);
238 }
239
241 {
242 OPERATOR().apply(block);
243 }
244
245};
246
247
249template <typename COUPLER, typename COUPLEES>
251 final : public AbstractCouplingO<COUPLEES> {
252private:
253 template <typename VALUED_DESCRIPTOR>
254 using ptr_to_lattice = ConcreteBlockLattice<typename VALUED_DESCRIPTOR::value_t,
255 typename VALUED_DESCRIPTOR::descriptor_t,
257
258 utilities::TypeIndexedTuple<typename COUPLEES::template map_values<
260 >> _lattices;
261
262 typename AbstractCouplingO<COUPLEES>::ParametersD _parameters;
263
264 std::unique_ptr<ConcreteBlockMask<typename COUPLEES::values_t::template get<0>::value_t,
265 Platform::GPU_CUDA>> _mask;
266
267public:
268 template <typename LATTICES>
269 ConcreteBlockCouplingO(LATTICES&& lattices):
270 _lattices{lattices}
271 { }
272
273 std::type_index id() const override {
274 return typeid(COUPLER);
275 }
276
278 return _parameters;
279 }
280
281 void set(CellID iCell, bool state) override;
282
283 void execute() override;
284
285};
286
288template <typename COUPLER, typename COUPLEES>
290 final : public AbstractCouplingO<COUPLEES> {
291private:
292 template <typename VALUED_DESCRIPTOR>
293 using ptr_to_lattice = ConcreteBlockLattice<typename VALUED_DESCRIPTOR::value_t,
294 typename VALUED_DESCRIPTOR::descriptor_t,
296
297 utilities::TypeIndexedTuple<typename COUPLEES::template map_values<
299 >> _lattices;
300
301 typename COUPLER::parameters::template decompose_into<
303 > _parameters;
304
305 std::unique_ptr<ConcreteBlockMask<typename COUPLEES::values_t::template get<0>::value_t,
306 Platform::GPU_CUDA>> _mask;
307
308public:
309 template <typename LATTICES>
310 ConcreteBlockCouplingO(LATTICES&& lattices):
311 _lattices{lattices}
312 { }
313
314 std::type_index id() const override {
315 return typeid(COUPLER);
316 }
317
319 return _parameters;
320 }
321
322 void set(CellID iCell, bool state) override;
323
324 void execute() override;
325
326};
327
329template <typename COUPLER, typename COUPLEES>
331 final : public AbstractCouplingO<COUPLEES> {
332private:
333 template <typename VALUED_DESCRIPTOR>
334 using ptr_to_lattice = std::conditional_t<
335 VALUED_DESCRIPTOR::descriptor_t::template provides<descriptors::POPULATION>(),
336 ConcreteBlockLattice<typename VALUED_DESCRIPTOR::value_t,
337 typename VALUED_DESCRIPTOR::descriptor_t,
339 ConcreteBlockD<typename VALUED_DESCRIPTOR::value_t,
340 typename VALUED_DESCRIPTOR::descriptor_t,
342 >*;
343
344 utilities::TypeIndexedTuple<typename COUPLEES::template map_values<
345 ptr_to_lattice
346 >> _lattices;
347
348 Cuboid<
351 >& _cuboid;
352
354 typename meta::merge<
355 typename COUPLER::parameters,
359 >
360 >
361 > _parameters;
362
363public:
364 template <typename LATTICES>
365 ConcreteBlockPointCouplingO(LATTICES&& lattices,
368 _lattices{lattices},
369 _cuboid{cuboid}
370 { }
371
372 std::type_index id() const override {
373 return typeid(COUPLER);
374 }
375
377 return _parameters;
378 }
379
380 void set(CellID iCell, bool state) override;
381
382 void execute() override;
383
384};
385
386}
387
388#include "communicator.h"
389#include "statistics.h"
390
391#endif
#define OPERATOR(OP, rhs)
Definition aDiffTape.h:64
std::size_t weight() const override
Returns number of assigned cells.
Definition operator.h:80
void set(CellID iCell, bool state, bool overlap) override
Set whether iCell is covered by the present collision step.
Definition operator.h:85
void apply(ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA > &block, ConcreteBlockMask< T, Platform::GPU_CUDA > &subdomain, CollisionDispatchStrategy strategy) override
Apply collision to subdomain of block using strategy.
Definition operator.h:110
Collision operation of concrete DYNAMICS on concrete block lattices of PLATFORM.
Definition operator.h:104
AbstractCouplingO< COUPLEES >::AbstractParameters & getParameters() override
Return reference to parameters of coupling operator.
Definition operator.h:318
AbstractCouplingO< COUPLEES >::AbstractParameters & getParameters() override
Return reference to parameters of coupling operator.
Definition operator.h:277
Coupling of COUPLEES using concrete OPERATOR with SCOPE on PLATFORM lattices.
Definition operator.h:135
Implementation of BlockD on a concrete PLATFORM.
Definition cell.h:32
Implementation of BlockLattice on a concrete PLATFORM.
void setup(ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA > &block) override
Definition operator.h:201
std::size_t weight() const override
Get number of cells covered by operator (optional)
Definition operator.h:188
void set(CellID iCell, bool state) override
Set whether iCell is covered by the operator (optional)
Definition operator.h:193
void set(CellID iCell, bool state) override
Set whether iCell is covered by the operator (optional)
Definition operator.h:230
std::size_t weight() const override
Get number of cells covered by operator (optional)
Definition operator.h:225
void apply(ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA > &block) override
Definition operator.h:240
void setup(ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA > &block) override
Definition operator.h:235
std::size_t weight() const override
Get number of cells covered by operator (optional)
Definition operator.h:145
void setup(ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA > &block) override
Definition operator.h:158
void set(CellID iCell, bool state) override
Set whether iCell is covered by the operator (optional)
Definition operator.h:150
Block application of concrete OPERATOR called using SCOPE on PLATFORM.
Definition operator.h:58
AbstractCouplingO< COUPLEES >::AbstractParameters & getParameters() override
Return reference to parameters of coupling operator.
Definition operator.h:376
ConcreteBlockPointCouplingO(LATTICES &&lattices, Cuboid< typename AbstractCouplingO< COUPLEES >::value_t, AbstractCouplingO< COUPLEES >::descriptor_t::d > &cuboid)
Definition operator.h:365
Particle coupling of COUPLEES using concrete OPERATOR with SCOPE on PLATFORM lattices.
Definition operator.h:139
Plain column for CUDA GPU targets.
Definition column.h:49
void push_back(T value)
Definition column.hh:102
std::size_t size() const override
Definition column.hh:128
Basic wrapper for device stream.
Definition device.h:121
Managed pointer for device-side memory.
Definition device.h:79
std::function< void(ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA > &)> getFusedCollisionO()
Helper for constructing fused collision operators.
Definition operator.hh:280
typename LIST_A::template decompose_into< LIST_B::template include > merge
Merge elements of LIST_A and LIST_B into new list.
Definition meta.h:344
Top level namespace for all of OpenLB.
std::uint32_t CellID
Type for sequential block-local cell indices.
Platform
OpenLB execution targets.
Definition platform.h:35
@ GPU_CUDA
Vector CPU (AVX2 / AVX-512 collision)
CollisionDispatchStrategy
Collision dispatch strategy.
Definition operator.h:81
@ Individual
Apply all dynamics individually (async for Platform::GPU_CUDA)
@ Dominant
Apply dominant dynamics using mask and fallback to virtual dispatch for others.
@ PerBlock
Per-block application, i.e. OPERATOR::apply is passed a ConcreteBlockLattice.
@ PerCell
Per-cell application, i.e. OPERATOR::apply is passed a CELL concept implementation.
@ PerCellWithParameters
Per-cell application with parameters, i.e. OPERATOR::apply is passed a CELL concept implementation an...
Base of block-wide coupling operators executed by SuperLatticeCoupling.
Definition operator.h:108
typename COUPLEES::values_t::template get< 0 >::value_t value_t
Value type used for coupling parameters.
Definition operator.h:110
Dynamic access interface for FIELD-valued parameters.
Collision operation on concrete blocks of PLATFORM.
Definition operator.h:90
Base of block-wide operators such as post processors.
Definition operator.h:44
Concrete storage of ParametersD in olb::Data.
Interface for per-cell dynamics.
Definition interface.h:56
Set of FIELD-valued parameters.
Virtual interface for device-side dynamically-dispatched dynamics access.
Definition dynamics.hh:41
Plain wrapper for list of types.
Definition meta.h:276
Mapping between KEYs and instances of type VALUEs.