OpenLB 1.7
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 T computeEquilibrium(int iPop, T rho, T* u) __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 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
63 cell[iPop] = computeEquilibrium(iPop, rho, u);
64 }
65 }
66
68 T rho, T* u, T* pi) __device__ {
69 iniEquilibrium(cell, rho, u);
70 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
71 cell[iPop] += equilibrium<DESCRIPTOR>::template fromPiToFneq<T>(iPop, pi);
72 }
73 }
74
75 virtual void inverseShiftRhoU(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u) __device__ = 0;
76
77};
78
80template <typename T, typename DESCRIPTOR, typename DYNAMICS>
81class ConcreteDynamics final : public Dynamics<T,DESCRIPTOR> {
82private:
84
85public:
87 _parameters{parameters} {
88 }
89
90 CellStatistic<T> collide(DeviceContext<T,DESCRIPTOR> lattice, CellID iCell) override __device__ {
91 DataOnlyCell<T,DESCRIPTOR> cell(lattice, iCell);
92 return DYNAMICS().apply(cell, *_parameters);
93 }
94
95 T computeRho(DataOnlyCell<T,DESCRIPTOR>& cell) override __device__ {
96 return DYNAMICS::MomentaF().computeRho(cell);
97 }
98 void computeU(DataOnlyCell<T,DESCRIPTOR>& cell, T* u) override __device__ {
99 DYNAMICS::MomentaF().computeU(cell, u);
100 }
101 void computeJ(DataOnlyCell<T,DESCRIPTOR>& cell, T* j) override __device__ {
102 DYNAMICS::MomentaF().computeJ(cell, j);
103 }
104 void computeRhoU(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u) override __device__ {
105 DYNAMICS::MomentaF().computeRhoU(cell, rho, u);
106 }
107 void computeStress(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* pi) override __device__ {
108 DYNAMICS::MomentaF().computeStress(cell, rho, u, pi);
109 }
110 void computeAllMomenta(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* pi) override __device__ {
111 DYNAMICS::MomentaF().computeAllMomenta(cell, rho, u, pi);
112 }
113
114 T getOmegaOrFallback(T fallback) override __device__ {
115 if constexpr (DYNAMICS::parameters::template contains<descriptors::OMEGA>()) {
116 return _parameters->template get<descriptors::OMEGA>();
117 } else {
118 return fallback;
119 }
120 }
121
122 T computeEquilibrium(int iPop, T rho, T* u) override __device__ {
123 return DYNAMICS().computeEquilibrium(iPop, rho, u);
124 }
125
126 void defineRho(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho) override __device__ {
127 typename DYNAMICS::MomentaF().defineRho(cell, rho);
128 }
129
130 void defineU(DataOnlyCell<T,DESCRIPTOR>& cell, T* u) override __device__ {
131 typename DYNAMICS::MomentaF().defineU(cell, u);
132 }
133
134 void defineRhoU(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u) override __device__ {
135 typename DYNAMICS::MomentaF().defineRhoU(cell, rho, u);
136 }
137
138 void defineAllMomenta(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u, T* pi) override __device__ {
139 typename DYNAMICS::MomentaF().defineAllMomenta(cell, rho, u, pi);
140 }
141
142 void inverseShiftRhoU(DataOnlyCell<T,DESCRIPTOR>& cell, T& rho, T* u) override __device__ {
143 typename DYNAMICS::MomentaF().inverseShiftRhoU(cell, rho, u);
144 }
145};
146
149 template <typename T, typename DESCRIPTOR>
150 bool operator()(DeviceContext<T,DESCRIPTOR>& lattice, CellID iCell) __device__ {
151 if (auto* collisionO = lattice.template getField<DYNAMICS<T,DESCRIPTOR>>()[0][iCell]) {
152 collisionO->collide(lattice, iCell);
153 return true;
154 }
155 return false;
156 }
157
158 template <typename T, typename DESCRIPTOR>
159 bool operator()(DeviceContext<T,DESCRIPTOR>& lattice, CellID iCell, CellStatistic<T>& statistic) __device__ {
160 if (auto* collisionO = lattice.template getField<DYNAMICS<T,DESCRIPTOR>>()[0][iCell]) {
161 statistic = collisionO->collide(lattice, iCell);
162 return true;
163 }
164 return false;
165 }
166
167};
168
169}
170
171}
172
173
174}
175
176#endif
Implementation of gpu::cuda::Dynamics for concrete DYNAMICS.
Definition dynamics.hh:81
void defineU(DataOnlyCell< T, DESCRIPTOR > &cell, T *u) override __device__
Definition dynamics.hh:130
CellStatistic< T > collide(DeviceContext< T, DESCRIPTOR > lattice, CellID iCell) override __device__
Definition dynamics.hh:90
void computeAllMomenta(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *pi) override __device__
Definition dynamics.hh:110
void computeJ(DataOnlyCell< T, DESCRIPTOR > &cell, T *j) override __device__
Definition dynamics.hh:101
void inverseShiftRhoU(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u) override __device__
Definition dynamics.hh:142
T computeEquilibrium(int iPop, T rho, T *u) override __device__
Definition dynamics.hh:122
ConcreteDynamics(ParametersOfOperatorD< T, DESCRIPTOR, DYNAMICS > *parameters) __device__
Definition dynamics.hh:86
void defineAllMomenta(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *pi) override __device__
Definition dynamics.hh:138
void computeU(DataOnlyCell< T, DESCRIPTOR > &cell, T *u) override __device__
Definition dynamics.hh:98
void defineRho(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho) override __device__
Definition dynamics.hh:126
void computeStress(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u, T *pi) override __device__
Definition dynamics.hh:107
T computeRho(DataOnlyCell< T, DESCRIPTOR > &cell) override __device__
Definition dynamics.hh:95
T getOmegaOrFallback(T fallback) override __device__
Definition dynamics.hh:114
void defineRhoU(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u) override __device__
Definition dynamics.hh:134
void computeRhoU(DataOnlyCell< T, DESCRIPTOR > &cell, T &rho, T *u) override __device__
Definition dynamics.hh:104
Device-side implementation of the data-only Cell concept for collision steps.
Definition context.hh:140
Structure for passing pointers to on-device data into CUDA kernels.
Definition context.hh:55
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:43
On-device field mirroring BlockDynamicsMap.
Definition dynamics.h:39
Last node in a MaskedDynamics chain in kernel::call_operators.
Definition dynamics.hh:148
bool operator()(DeviceContext< T, DESCRIPTOR > &lattice, CellID iCell, CellStatistic< T > &statistic) __device__
Definition dynamics.hh:159
bool operator()(DeviceContext< T, DESCRIPTOR > &lattice, CellID iCell) __device__
Definition dynamics.hh:150
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:67
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 T computeEquilibrium(int iPop, T rho, T *u) __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 defineU(DataOnlyCell< T, DESCRIPTOR > &cell, T *u) __device__=0