OpenLB 1.8.1
Loading...
Searching...
No Matches
dualLbHelpers.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2014 Mathias J. Krause
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
30#ifndef DUAL_LB_HELPERS_H
31#define DUAL_LB_HELPERS_H
32
33#include "dynamics/lbm.h"
34
35namespace olb {
36
38namespace opti {
39
41template<typename T, typename DESCRIPTOR>
43
44 static T equilibrium(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
45 {
47 T sum = T();
48 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
49 sum += (u[iD] - descriptors::c<DESCRIPTOR>(jPop,iD))*(u[iD] - descriptors::c<DESCRIPTOR>(iPop,iD));
50 }
51 return (descriptors::invCs2<T,DESCRIPTOR>()*sum + T(1))/rho*eq;
52 }
53
54 static T equilibrium2(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
55 {
56 T u_c = T();
57 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
58 u_c += u[iD]*descriptors::c<DESCRIPTOR>(iPop,iD);
59 }
60 T sum = T();
61 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
62 sum += (u[iD]*u[iD] + 2.*descriptors::c<DESCRIPTOR>(jPop,iD)*(descriptors::c<DESCRIPTOR>(iPop,iD)-u[iD]) )
64 + (u_c*descriptors::c<DESCRIPTOR>(iPop,iD)*(2.*descriptors::c<DESCRIPTOR>(jPop,iD)-u[iD]))
66 }
67 return descriptors::t<T,DESCRIPTOR>(iPop)*(1.+sum);
68 }
69
71 // identical computation to standard lbm, but different arguments
72 static void computeRhoU(T const* cell, T& rho, T u[DESCRIPTOR::d])
73 {
74
75 rho = T();
76 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
77 u[iD] = T();
78 }
79 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
80 rho += cell[iPop];
81 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
82 u[iD] += cell[iPop]*descriptors::c<DESCRIPTOR>(iPop,iD);
83 }
84 }
85 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
86 u[iD] /= rho;
87 }
88 }
89
90 static void computeRhoU(ConstCell<T,DESCRIPTOR>& cell, T& rho, T u[DESCRIPTOR::d])
91 {
92 computeRhoU(&cell[0], rho, u);
93 }
94
95}; // struct dualLbHelpers
96
97template <typename DESCRIPTOR>
99{
101 template <concepts::MinimalCell CELL, typename V=typename CELL::value_t>
102 static V dRhoDf(CELL& cell, int jPop) any_platform
103 {
104 return V{1};
105 }
106
108 template <concepts::MinimalCell CELL, typename DJDF, typename V=typename CELL::value_t>
109 static void dJDf(CELL& cell, DJDF& djdf, int jPop) any_platform
110 {
111 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
112 djdf[iD] = descriptors::c<DESCRIPTOR>(jPop,iD);
113 }
114 }
115
117 template <concepts::MinimalCell CELL, typename DUDF, typename V=typename CELL::value_t>
118 static void dUDf(CELL& cell, DUDF& dudf, int jPop) any_platform
119 {
120 V rho, u[DESCRIPTOR::d];
121 lbm<DESCRIPTOR>::computeRhoU(cell, rho, u);
122 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
123 dudf[iD] = (descriptors::c<DESCRIPTOR>(jPop,iD) - u[iD]) / rho;
124 }
125 }
126
128 template <concepts::MinimalCell CELL, typename DPIDF, typename V=typename CELL::value_t>
129 static void dPiDf(CELL& cell, DPIDF& dpidf, int jPop) any_platform
130 {
131 V rho, u[DESCRIPTOR::d];
132 lbm<DESCRIPTOR>::computeRhoU(cell, rho, u);
133
134 int iPi = 0;
135 for (int iAlpha=0; iAlpha < DESCRIPTOR::d; ++iAlpha) {
136 for (int iBeta=iAlpha; iBeta < DESCRIPTOR::d; ++iBeta) {
137 dpidf[iPi] = descriptors::c<DESCRIPTOR>(jPop,iAlpha) * descriptors::c<DESCRIPTOR>(jPop,iBeta)
138 - descriptors::c<DESCRIPTOR>(jPop,iAlpha) * u[iBeta]
139 - u[iAlpha] * (descriptors::c<DESCRIPTOR>(jPop,iBeta) - u[iBeta]);
140 if (iAlpha==iBeta) {
141 dpidf[iPi] -= V{1} / descriptors::invCs2<V,DESCRIPTOR>();
142 }
143 ++iPi;
144 }
145 }
146 }
147};
148
149} // namespace opti
150
151} // namespace olb
152
153
154#endif
Highest-level interface to read-only Cell data.
Definition interface.h:36
constexpr T invCs2() any_platform
Definition functions.h:107
constexpr T t(unsigned iPop, tag::CUM) any_platform
Definition cum.h:108
constexpr int c(unsigned iPop, unsigned iDim) any_platform
Definition functions.h:83
Top level namespace for all of OpenLB.
Optimization Code.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:77
static V secondOrder(int iPop, const RHO &rho, const U &u, const USQR &uSqr) any_platform
Computation of equilibrium distribution, second order in u.
Definition lbm.h:51
static void computeRhoU(CELL &cell, RHO &rho, U &u) any_platform
Computation of hydrodynamic variables.
Definition lbm.h:301
Derivative of Objective functional regarding populations.
Definition fields.h:552
This structure forwards the calls to the appropriate helper class.
static T equilibrium2(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
static void computeRhoU(T const *cell, T &rho, T u[DESCRIPTOR::d])
Computation of hydrodynamic variables.
static T equilibrium(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
static void computeRhoU(ConstCell< T, DESCRIPTOR > &cell, T &rho, T u[DESCRIPTOR::d])
static void dUDf(CELL &cell, DUDF &dudf, int jPop) any_platform
derive velocity u by population component
static V dRhoDf(CELL &cell, int jPop) any_platform
derive rho by population component
static void dPiDf(CELL &cell, DPIDF &dpidf, int jPop) any_platform
derive stress pi by population component
static void dJDf(CELL &cell, DJDF &djdf, int jPop) any_platform
derive momentum j by population component