OpenLB 1.8.1
Loading...
Searching...
No Matches
dynamics.hh
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_DYNAMICS_HH
25#define GPU_CUDA_DYNAMICS_HH
26
27#include "dynamics.h"
28#include "dynamics/lbm.h"
29
30namespace olb {
31
32namespace gpu {
33
34namespace cuda {
35
36template <typename T, typename DESCRIPTOR> class DeviceContext;
37template <typename T, typename DESCRIPTOR> class DataOnlyCell;
38
40template <typename T, typename DESCRIPTOR>
41struct Dynamics {
42 virtual CellStatistic<T> collide(DeviceContext<T,DESCRIPTOR> lattice, CellID iCell) __device__ = 0;
43
44 virtual T computeRho (DataOnlyCell<T,DESCRIPTOR>& cell ) __device__ = 0;
45 virtual void computeU (DataOnlyCell<T,DESCRIPTOR>& cell, T* u) __device__ = 0;
46 virtual void computeJ (DataOnlyCell<T,DESCRIPTOR>& cell, T* j) __device__ = 0;
47 virtual void computeRhoU(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u) __device__ = 0;
48
49 virtual void computeStress (DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* pi) __device__ = 0;
50 virtual void computeAllMomenta(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* pi) __device__ = 0;
51
52 virtual void defineRho (DataOnlyCell<T,DESCRIPTOR>& cell, T& rho ) __device__ = 0;
53 virtual void defineU (DataOnlyCell<T,DESCRIPTOR>& cell, T* u ) __device__ = 0;
54 virtual void defineRhoU (DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u ) __device__ = 0;
55 virtual void defineAllMomenta(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* pi) __device__ = 0;
56
57 virtual void computeEquilibrium(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* fEq) __device__ = 0;
58
59 virtual T getOmegaOrFallback(T fallback) __device__ = 0;
60
61 void iniEquilibrium(DataOnlyCell<T,DESCRIPTOR>& cell, T rho, T* u) __device__ {
62 T fEq[DESCRIPTOR::q] { };
63 computeEquilibrium(cell, rho, u, fEq);
64 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
65 cell[iPop] = fEq[iPop];
66 }
67 }
68
70 T rho, T* u, T* pi) __device__ {
71 iniEquilibrium(cell, rho, u);
72 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
73 cell[iPop] += equilibrium<DESCRIPTOR>::template fromPiToFneq<T>(iPop, pi);
74 }
75 }
76
77 virtual void inverseShiftRhoU(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u) __device__ = 0;
78
79};
80
82template <typename T, typename DESCRIPTOR, typename DYNAMICS>
83class ConcreteDynamics final : public Dynamics<T,DESCRIPTOR> {
84private:
86
87public:
89 _parameters{parameters} {
90 }
91
92 CellStatistic<T> collide(DeviceContext<T,DESCRIPTOR> lattice, CellID iCell) override __device__ {
93 DataOnlyCell<T,DESCRIPTOR> cell(lattice, iCell);
94 return DYNAMICS().collide(cell, *_parameters);
95 }
96
97 T computeRho(DataOnlyCell<T,DESCRIPTOR>& cell) override __device__ {
98 return DYNAMICS::MomentaF().computeRho(cell);
99 }
100 void computeU(DataOnlyCell<T,DESCRIPTOR>& cell, T* u) override __device__ {
101 DYNAMICS::MomentaF().computeU(cell, u);
102 }
103 void computeJ(DataOnlyCell<T,DESCRIPTOR>& cell, T* j) override __device__ {
104 DYNAMICS::MomentaF().computeJ(cell, j);
105 }
106 void computeRhoU(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u) override __device__ {
107 DYNAMICS::MomentaF().computeRhoU(cell, rho, u);
108 }
109 void computeStress(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* pi) override __device__ {
110 DYNAMICS::MomentaF().computeStress(cell, rho, u, pi);
111 }
112 void computeAllMomenta(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* pi) override __device__ {
113 DYNAMICS::MomentaF().computeAllMomenta(cell, rho, u, pi);
114 }
115
116 T getOmegaOrFallback(T fallback) override __device__ {
117 if constexpr (DYNAMICS::parameters::template contains<descriptors::OMEGA>()) {
118 return _parameters->template get<descriptors::OMEGA>();
119 } else {
120 return fallback;
121 }
122 }
123
124 void computeEquilibrium(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* fEq) override __device__ {
125 DYNAMICS::EquilibriumF().compute(cell, rho, u, fEq);
126 }
127
128 void defineRho(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho) override __device__ {
129 typename DYNAMICS::MomentaF().defineRho(cell, rho);
130 }
131
132 void defineU(DataOnlyCell<T,DESCRIPTOR>& cell, T* u) override __device__ {
133 typename DYNAMICS::MomentaF().defineU(cell, u);
134 }
135
136 void defineRhoU(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u) override __device__ {
137 typename DYNAMICS::MomentaF().defineRhoU(cell, rho, u);
138 }
139
140 void defineAllMomenta(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* pi) override __device__ {
141 typename DYNAMICS::MomentaF().defineAllMomenta(cell, rho, u, pi);
142 }
143
144 void inverseShiftRhoU(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u) override __device__ {
145 typename DYNAMICS::MomentaF().inverseShiftRhoU(cell, rho, u);
146 }
147};
148
151 template <typename T, typename DESCRIPTOR>
152 bool operator()(DeviceContext<T,DESCRIPTOR>& lattice, CellID iCell) __device__ {
153 if (auto* collisionO = lattice.template getField<DYNAMICS<T,DESCRIPTOR>>()[0][iCell]) {
154 collisionO->collide(lattice, iCell);
155 return true;
156 }
157 return false;
158 }
159
160 template <typename T, typename DESCRIPTOR>
161 bool operator()(DeviceContext<T,DESCRIPTOR>& lattice, CellID iCell, CellStatistic<T>& statistic) __device__ {
162 if (auto* collisionO = lattice.template getField<DYNAMICS<T,DESCRIPTOR>>()[0][iCell]) {
163 statistic = collisionO->collide(lattice, iCell);
164 return true;
165 }
166 return false;
167 }
168
169};
170
171}
172
173}
174
175
176}
177
178#endif
Implementation of gpu::cuda::Dynamics for concrete DYNAMICS.
Definition dynamics.hh:83
void defineU(DataOnlyCell< T, DESCRIPTOR > &cell, T *u) override __device__
Definition dynamics.hh:132
CellStatistic< T > collide(DeviceContext< T, DESCRIPTOR > lattice, CellID iCell) override __device__
Definition dynamics.hh:92
void computeAllMomenta(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *pi) override __device__
Definition dynamics.hh:112
void computeJ(DataOnlyCell< T, DESCRIPTOR > &cell, T *j) override __device__
Definition dynamics.hh:103
void inverseShiftRhoU(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u) override __device__
Definition dynamics.hh:144
ConcreteDynamics(ParametersOfOperatorD< T, DESCRIPTOR, DYNAMICS > *parameters) __device__
Definition dynamics.hh:88
void defineAllMomenta(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *pi) override __device__
Definition dynamics.hh:140
void computeEquilibrium(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *fEq) override __device__
Definition dynamics.hh:124
void computeU(DataOnlyCell< T, DESCRIPTOR > &cell, T *u) override __device__
Definition dynamics.hh:100
void defineRho(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho) override __device__
Definition dynamics.hh:128
void computeStress(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *pi) override __device__
Definition dynamics.hh:109
T computeRho(DataOnlyCell< T, DESCRIPTOR > &cell) override __device__
Definition dynamics.hh:97
T getOmegaOrFallback(T fallback) override __device__
Definition dynamics.hh:116
void defineRhoU(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u) override __device__
Definition dynamics.hh:136
void computeRhoU(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u) override __device__
Definition dynamics.hh:106
Device-side implementation of the data-only Cell concept for collision steps.
Definition dynamics.hh:37
Structure for passing pointers to on-device data into CUDA kernels.
Definition dynamics.hh:36
Top level namespace for all of OpenLB.
std::uint32_t CellID
Type for sequential block-local cell indices.
typename ParametersD< T, DESCRIPTOR >::template include< typename OPERATOR::parameters > ParametersOfOperatorD
Deduce ParametersD of OPERATOR w.r.t. T and DESCRIPTOR.
Return value of any collision.
Definition interface.h:45
On-device field mirroring BlockDynamicsMap.
Definition dynamics.h:39
Last node in a MaskedDynamics chain in kernel::call_operators.
Definition dynamics.hh:150
bool operator()(DeviceContext< T, DESCRIPTOR > &lattice, CellID iCell, CellStatistic< T > &statistic) __device__
Definition dynamics.hh:161
bool operator()(DeviceContext< T, DESCRIPTOR > &lattice, CellID iCell) __device__
Definition dynamics.hh:152
Virtual interface for device-side dynamically-dispatched dynamics access.
Definition dynamics.hh:41
void iniRegularized(DataOnlyCell< T, DESCRIPTOR > &cell, T rho, T *u, T *pi) __device__
Definition dynamics.hh:69
virtual T getOmegaOrFallback(T fallback) __device__=0
virtual void defineRho(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho) __device__=0
virtual T computeRho(DataOnlyCell< T, DESCRIPTOR > &cell) __device__=0
virtual void computeStress(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *pi) __device__=0
virtual void defineAllMomenta(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *pi) __device__=0
virtual void computeRhoU(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u) __device__=0
virtual void inverseShiftRhoU(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u) __device__=0
virtual void computeAllMomenta(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *pi) __device__=0
virtual void computeJ(DataOnlyCell< T, DESCRIPTOR > &cell, T *j) __device__=0
virtual CellStatistic< T > collide(DeviceContext< T, DESCRIPTOR > lattice, CellID iCell) __device__=0
virtual void defineRhoU(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u) __device__=0
virtual void computeU(DataOnlyCell< T, DESCRIPTOR > &cell, T *u) __device__=0
void iniEquilibrium(DataOnlyCell< T, DESCRIPTOR > &cell, T rho, T *u) __device__
Definition dynamics.hh:61
virtual void computeEquilibrium(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *fEq) __device__=0
virtual void defineU(DataOnlyCell< T, DESCRIPTOR > &cell, T *u) __device__=0