OpenLB 1.7
Loading...
Searching...
No Matches
dualMrtDynamics.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2013 Mathias J. Krause, Geng Liu
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
33#ifndef DUAL_MRT_DYNAMICS_H
34#define DUAL_MRT_DYNAMICS_H
35
36//#include "optiStructure.h"
37//#include "solver3D.h"
38
39
40
41// All OpenLB code is contained in this namespace.
42namespace olb {
43
45namespace opti {
46
47
48template<typename T> class Controller;
49template<typename T, typename DESCRIPTOR> class DualController;
50
51
52
53
55template<typename T, typename DESCRIPTOR, typename MOMENTA=momenta::BulkTuple>
56class DualForcedMRTdynamics : public MRTdynamics<T,DESCRIPTOR,MOMENTA> {
57public:
59 DualForcedMRTdynamics(T omega_);
60
63 LatticeStatistics<T>& statistics_);
64
65 virtual void defineRho(Cell<T,DESCRIPTOR>& cell, T rho);
66private:
67
68 T Mt_S_M[DESCRIPTOR::q][DESCRIPTOR::q];
69 T invM_invMt[DESCRIPTOR::q][DESCRIPTOR::q];
70 T Mt_S_invMt[DESCRIPTOR::q][DESCRIPTOR::q];
71};
72
74
78template<typename T, typename DESCRIPTOR, typename MOMENTA>
80 T omega_)
81 : MRTdynamics<T,DESCRIPTOR,MOMENTA>(omega_)
82{
83 T rt[DESCRIPTOR::q]; // relaxation times vector.
84 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
85 rt[iPop] = DESCRIPTOR::S[iPop];
86 }
87 for (int iPop = 0; iPop < DESCRIPTOR::shearIndexes; ++iPop) {
88 rt[DESCRIPTOR::shearViscIndexes[iPop]] = omega_;
89 }
90
91 T tmp[DESCRIPTOR::q][DESCRIPTOR::q];
92
93 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
94 for (int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
95 Mt_S_M[iPop][jPop] = T();
96 Mt_S_invMt[iPop][jPop] = T();
97 invM_invMt[iPop][jPop] = T();
98 tmp[iPop][jPop] = T();
99 }
100 }
101
102 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
103 for (int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
104 for (int kPop=0; kPop < DESCRIPTOR::q; ++kPop) {
105 if (jPop==kPop) {
106 tmp[iPop][jPop] += DESCRIPTOR::M[kPop][iPop]*rt[kPop];
107 }
108 }
109 }
110 }
111 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
112 for (int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
113 for (int kPop=0; kPop < DESCRIPTOR::q; ++kPop) {
114 Mt_S_M[iPop][jPop] += tmp[iPop][kPop]**DESCRIPTOR::M[kPop][jPop];
115 Mt_S_invMt[iPop][jPop] += tmp[iPop][kPop]**DESCRIPTOR::invM[jPop][kPop];
116 invM_invMt[iPop][jPop] += DESCRIPTOR::invM[iPop][kPop]**DESCRIPTOR::invM[jPop][kPop];
117 }
118 }
119 }
120
121 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
122 for (int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
123 //std::cout << Mt_S_M[iPop][jPop];
124 // std::cout <<Mt_S_invMt[iPop][jPop];
125 // std::cout <<invM_invMt[iPop][jPop];
126 //if (iPop == jPop) {
127 // Mt_S_M[iPop][jPop] = omega_;
128 // Mt_S_invMt[iPop][jPop] = omega_;
129 // invM_invMt[iPop][jPop] = 1.;
130 //}
131 }
132 }
133
134 OLB_PRECONDITION( DESCRIPTOR::template provides<descriptors::FORCE>() );
135}
136
137template<typename T, typename DESCRIPTOR, typename MOMENTA>
139{
140
141 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
142 cell[iPop]=rho;
143 }
144}
145
146
147
148template<typename T, typename DESCRIPTOR, typename MOMENTA>
150 Cell<T,DESCRIPTOR>& cell,
151 LatticeStatistics<T>& statistics )
152{
153
154 cell.revert();
155
156
157 T rho_phi_x = T();
158 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
159 rho_phi_x += cell[iPop];
160 }
161
162 // Who am I?
163 T* ct = cell[DESCRIPTOR::q+3];
164 int c[3];
165 c[0] = (int)ct[0];
166 c[1] = (int)ct[1];
167 c[2] = (int)ct[2];
168
169
170
171 // Preparation
172 auto pop_f = cell.template getFieldPointer<descriptors::F>();
173 auto dJdF = cell.template getFieldPointer<descriptors::DJDF>();
174
175 T rho_f;
176 T u_f[3];
177 rho_f = T();
178 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
179 u_f[iD] = T();
180 }
181 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
182 rho_f += pop_f[iPop];
183 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
184 u_f[iD] += pop_f[iPop]*descriptors::c<DESCRIPTOR>(iPop,iD);
185 }
186 }
187 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
188 u_f[iD] /= rho_f;
189 }
190
191 // Computation of dual equillibrium
192 T Meq_phi[DESCRIPTOR::q][DESCRIPTOR::q];
193 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
194 T u_c = T();
195 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
196 u_c += u_f[iD]*descriptors::c<DESCRIPTOR>(iPop,iD);
197 }
198 for (int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
199 T sum = T();
200 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
201 sum += (u_f[iD]*u_f[iD] + 2.*descriptors::c<DESCRIPTOR>(jPop,iD)*(descriptors::c<DESCRIPTOR>(iPop,iD)-u_f[iD]))*descriptors::invCs2<T,DESCRIPTOR>()*0.5+(u_c*descriptors::c<DESCRIPTOR>(iPop,iD)*(2.*descriptors::c<DESCRIPTOR>(jPop,iD)-u_f[iD]))*descriptors::invCs2<T,DESCRIPTOR>()*descriptors::invCs2<T,DESCRIPTOR>()*0.5;
202 }
203 Meq_phi[iPop][jPop] = descriptors::t<T,DESCRIPTOR>(iPop)*(1.+sum);
204 }
205 }
206
207 // Computation of dual force
208 auto force = cell.template getFieldPointer<descriptors::FORCE>();
209 T F1_phi[DESCRIPTOR::q][DESCRIPTOR::q];
210 T F2_phi[DESCRIPTOR::q][DESCRIPTOR::q];
211 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
212 T f_c = T();
213 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
214 f_c += force[iD]*descriptors::c<DESCRIPTOR>(iPop,iD);
215 }
216 for (int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
217 T sum = T();
218 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
219 sum += (f_c*descriptors::c<DESCRIPTOR>(iPop,iD)-force[iD]/(T)descriptors::invCs2<T,DESCRIPTOR>())*descriptors::c<DESCRIPTOR>(jPop,iD);
220 }
221 F1_phi[iPop][jPop] = descriptors::t<T,DESCRIPTOR>(iPop)*descriptors::invCs2<T,DESCRIPTOR>()*f_c;
222 F2_phi[iPop][jPop] = descriptors::t<T,DESCRIPTOR>(iPop)*descriptors::invCs2<T,DESCRIPTOR>()*descriptors::invCs2<T,DESCRIPTOR>()*sum;
223 }
224 }
225
226
227 // Computation of dual collision
228 T dualMRTcollision[DESCRIPTOR::q];
229 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
230 dualMRTcollision[iPop] = T();
231 for (int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
232 T I=T();
233 if (iPop==jPop) {
234 I=T(1);
235 }
236 dualMRTcollision[iPop] += (I - (I - Meq_phi[jPop][iPop])*Mt_S_invMt[iPop][iPop] + F1_phi[jPop][iPop] + F2_phi[jPop][iPop]*(1. - 0.5*Mt_S_invMt[iPop][iPop]))*cell[jPop];
237 }
238 }
239
240
241 // Adding dirivitive of objective and writing back to cell
242 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
243 cell[iPop] = dualMRTcollision[iPop] + dJdF[iPop];
244 }
245
246 // Incrementing statistic values for convergence
247 T phi2 = T();
248 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
249 phi2 += cell[iPop]*cell[iPop];
250 }
251
252 statistics.incrementStats(1.0 + cell[0], phi2);
253 cell.revert();
254}
255
256
257
258
259
260
261
262} // namespace opti
263
264} // namespace olb
265
266#endif
Highest-level interface to Cell data.
Definition cell.h:148
void revert()
Revert ("bounce-back") the distribution functions.
Definition cell.hh:190
void incrementStats(T rho, T uSqr)
Implementation of the dual MRT collision step with external force.
virtual CellStatistic< T > collide(Cell< T, DESCRIPTOR > &cell, LatticeStatistics< T > &statistics_)
Collision step.
virtual void defineRho(Cell< T, DESCRIPTOR > &cell, T rho)
Set particle density.
DualForcedMRTdynamics(T omega_)
Constructor.
Top level namespace for all of OpenLB.
Optimization Code.
#define OLB_PRECONDITION(COND)
Definition olbDebug.h:46
Return value of any collision.
Definition interface.h:43
Dynamics constructed as a tuple of momenta, equilibrium and collision.
Definition interface.h:182