Debian Codegraph @

pkg/lbm/HydrodynamicsLawLBM.hpp

raw
1 /*************************************************************************
2 * Copyright (C) 2009-2012 by Franck Lominé *
3 * [email protected] *
4 * *
5 * This program is free software; it is licensed under the terms of the *
6 * GNU General Public License v2 or later. See file LICENSE for details. *
7 * *
8 * Luc Scholtès [email protected] *
9 * and Luc Sibille [email protected] also contributed to this *
10 * code. *
11 * *
12 * Lominé F., Scholtès L., Sibille L., Poullain P. (2013) *
13 * Modelling of fluid-solid interaction in granular media with coupled *
14 * LB/DE methods: application to piping erosion. International Journal *
15 * for Numerical and Analytical Methods in Geomechanics, 37(6):577-596 *
16 * doi: 10.1002/nag.1109 *
17 * *
18 * Sibille L., Lominé F., Marot D. (2012) Investigation In Modelling *
19 * Piping Erosion With a Coupled «Lattice Boltzmann – Discrete Element» *
20 * Numerical Method. in Proc. 6th Int. Conference on Scour and Erosion *
21 * (ICSE-6), pp. 93-100. *
22 * *
23 *************************************************************************/
24 #ifdef LBM_ENGINE
25
26 #pragma once
27 #include <core/GlobalEngine.hpp>
28 #include <pkg/lbm/LBMbody.hpp>
29 #include <pkg/lbm/LBMlink.hpp>
30 #include <pkg/lbm/LBMnode.hpp>
31
32 namespace yade { // Cannot have #include directive inside.
33
34 class HydrodynamicsLawLBM : public GlobalEngine {
35 private:
36 std::ofstream ofile;
37
38 public:
39 bool firstRun, /*! = 1 if it is the first iteration during 1 YADE simulation*/
40 use_ConvergenceCriterion, /*! use stop condition based on the convergence criterion*/
41 SAVE_VELOCITY, /*! Switch to save node velocities*/
42 SAVE_VELOCITYCOMP, /*! Switch to save node velocities in each directions*/
43 SAVE_RHO, /*! Switch to save node densities*/
44 SAVE_FORCES, /*! Switch to save node force and momentum on grid*/
45 SAVE_BODIES, /*! Switch to save particle nodes*/
46 SAVE_NODEBD, /*! Switch to save fluid or solid boundary nodes*/
47 SAVE_NODEISNEW, /*! Switch to save new fluid/solid nodes*/
48 SAVE_DEBUGFILES, /*! Switch to save some debug data*/
49 SAVE_OBSERVEDPTC, /*! Switch to save properties of the observed particle*/
50 SAVE_OBSERVEDNODE, /*! Switch to save properties of the observed node*/
51 SAVE_CONTACTINFO, /*! Switch to save contact properties*/
52 SAVE_SPHERES, /*! Switch to save spheres properties*/
53 COMPRESS_DATA, /*! Switch to enable file compression*/
54 Xperiodicity, /*! Switch to activate lattice periodicity in x direction*/
55 Yperiodicity, /*! Switch to activate lattice periodicity in y direction*/
56 Zperiodicity; /*! Switch to activate lattice periodicity in z direction*/
57
58 int NB_BODIES, /*! Number of bodies*/
59 NB_GRAINS, /*! number of grains*/
60 NB_DYNGRAINS, /*! number of dynamic grains*/
61 NB_DYNBODIES, /*! number of dynamic bodies*/
62 NB_WALLS, /*! Number of walls*/
63 DEM_ITER, /*! Number of iteration of the DEM loop*/
64 LBM_ITER, /*! Number of iteration of the LBM loop*/
65 MODE, /*! 1->only a LBM loop, 2->lbm subcycling, 3->lbm subcycling after lbm loop*/
66 dim, /*! dimension*/
67 NbDir, /*! number of directions of the lattice model*/
68 NbNodes, /*! Total number of nodes*/
69 NbFluidNodes, /*! Number of fluid nodes*/
70 NbSolidNodes, /*! Number of solid nodes*/
71 NbParticleNodes, /*! Number of particle nodes*/
72 NbContacts, /*! Number of Contact*/
73 InitialNumberOfDynamicParticles, /*! Initial number of dynamic particles*/
74 NumberOfDynamicParticles, /*! Number of dynamic particles*/
75 Ny, /*! Number of grid divisions in y direction */
76 Nz, /*! Number of grid divisions in z direction */
77 NumberPtcEroded, /*! The bumber of eroded/removed particles*/
78 iter, /*! LBM Iteration number in current DEM loop (=1 in mode=2)*/
79 IdFirstSphere; /*! Id of the first sphere*/
80
81 Real height, /*! System height */
82 width, /*! System width */
83 depth, /*! System depth */
84 halfWallthickness, /*! Half Wall thickness */
85 Wallthickness, /*! Wall thickness */
86 cub, /*! A temporary variable to calculate equilibrium distribution function */
87 c, /*! Lattice speed */
88 c2, /*! The squared lattice speed*/
89 dx, /*! The lattice size*/
90 invdx, /*! 1 / lattice size*/
91 dx2, /*! The squared lattice size*/
92 uMax, /// TODO: PLEASE EXPLAIN uMax
93 cs, /*! c/sqrt(3) */
94 dt, /*! LBM timestep */
95 invdt, /*! one over LBM timestep */
96 nu, /*! LBM kinematic viscosity */
97 feqb, /*! Equilibrium distribution function*/
98 omega, /*! 1/tau */
99 Lx0, /*! LBM grid size in x direction*/
100 Ly0, /*! LBM grid size in y direction*/
101 Lz0, /*! LBM grid size in z direction*/
102 outside_limit, /*! the x coordinate of a point outside the system*/
103 DEMdt, /*! timestep for the DEM iteration*/
104 DEMdt0, /*! original timestep for the DEM iteration*/
105 newDEMdt, /*! the new timestep for the DEM iteration*/
106 Vr, /*! Volume of the removed particles*/
107 Vo, /*! Initial volume of dynamic particles */
108 VmeanFluidC, /*! Current mean fluid velocity */
109 PrevVmeanFluidC, /*! Previous mean fluid velocity */
110 PrevPrevVmeanFluidC, /*! Previous previous mean fluid velocity */
111 VmaxC, /*! Maximum velocity during the current time step*/
112 VminC, /*! Minimum velocity during the current time step*/
113 RhomaxC, /*! Maximum density during the current time step*/
114 RhominC, /*! Minimum density during the current time step*/
115 LBM_TIME, /*! The time ellapsed in the LB method*/
116 DEM_TIME, /*! The time ellapsed in the DE method*/
117 RhoTot, /*! Cumulative density*/
118 FmoyCur, /*! Mean force at the current LB iteration*/
119 FmoyPrev, /*! Mean force at the previous LB iteration*/
120 FmoyPrevPrev, /*! Mean force at 2 previous LB iteration*/
121 UMaxtheo, /// TODO: PLEASE EXPLAIN UMaxtheo
122 MaxBodyRadius, /*! Max radius of spheres*/
123 MinBodyRadius, /*! Min radius of spheres*/
124 MeanBodyRadius; /*! Mean radius of spheres*/
125
126 std::string LBMlogFile, /*! Name of the logfile */
127 LBMmachFile, /*! Name of the stat file */
128 LBMcontactsFile, /*! Name of the contact file */
129 RemovedPtcFile, /*! Name of the file to store removed particle informations*/
130 ObservedPtcFile, /*! Name of the file to store observed particle informations*/
131 ObservedNodeFile, /*! Name of the file to store observed particle informations*/
132 lbm_dir, /*! Directory name to save LBM files */
133 dem_dir, /*! Directory name to save DEM files */
134 cntct_dir; /*! Directory name to save contact properties */
135
136 std::stringstream spherefile_name; /*! Name of the file where sphere data are saved*/
137
138 vector<int> IdOfNextErodedPtc, /*! List of particles which will be eroded*/
139 opp; /*! opposite nodes */
140
141 vector<Real> w; /*! Weighting factor */
142
143 vector<LBMnode> nodes; /*! the LBM nodes*/
144 vector<LBMlink> links; /*! the LBM links*/
145 vector<LBMbody> LBbodies; /*! the LBM bodies*/
146
147 vector<Vector3r> eib; /*! node velocity directions*/
148
149 Vector3r FhTotale; ///Total hydrodynamic force
150
151 virtual ~HydrodynamicsLawLBM();
152 bool isActivated() override;
153 void action() override;
154 void save(int iter_number, Real timestep);
155 void saveStats(int iter_number, Real timestep);
156 void saveEroded(int iter_number, Real timestep);
157 void saveContacts(int iter_number, Real timestep);
158 void saveObservedNode(int iter_number, Real timestep);
159 void saveObservedPtc(int iter_number, Real timestep);
160 void createNewFiles();
161 //void createDirectories(); // ModLuc: to create directories only if necessary
162 void createDirectories(bool dirLBM, bool dirDem, bool dirCntct);
163 void writelogfile();
164 void modeTransition();
165 void LbmEnd();
166 void CalculateAndApplyForcesAndTorquesOnBodies(bool mean, bool apply);
167
168 // clang-format off
169 YADE_CLASS_BASE_DOC_ATTRS_CTOR(HydrodynamicsLawLBM,GlobalEngine,"Engine to simulate fluid flow (with the lattice Boltzmann method) with a coupling with the discrete element method.\n If you use this Engine, please cite and refer to F. Lominé et al. International Journal For Numerical and Analytical Method in Geomechanics, 2012, doi: 10.1002/nag.1109",
170
171 ((int,WallYm_id,0,,"Identifier of the Y- wall"))
172 ((bool,useWallYm,true,,"Set true if you want that the LBM see the wall in Ym"))
173 ((int,YmBCType,2,,"Boundary condition for the wall in Ym (-1: unused, 1: pressure condition, 2: velocity condition)."))
174 ((Vector3r,YmBcVel,Vector3r::Zero(),,"(!!! not fully implemented !!) The velocity imposed at the boundary"))
175 ((Real,YmBcRho,-1,,"(!!! not fully implemented !!) The density imposed at the boundary"))
176 ((int,WallYp_id,1,,"Identifier of the Y+ wall"))
177 ((bool,useWallYp,true,,"Set true if you want that the LBM see the wall in Yp"))
178 ((int,YpBCType,2,,"Boundary condition for the wall in Yp (-1: unused, 1: pressure condition, 2: velocity condition)."))
179 ((Vector3r,YpBcVel,Vector3r::Zero(),,"(!!! not fully implemented !!) The velocity imposed at the boundary"))
180 ((Real,YpBcRho,-1,,"(!!! not fully implemented !!) The density imposed at the boundary"))
181 ((int,WallXm_id,2,,"Identifier of the X- wall"))
182 ((bool,useWallXm,false,,"Set true if you want that the LBM see the wall in Xm"))
183 ((int,XmBCType,1,,"Boundary condition for the wall in Xm (-1: unused, 1: pressure condition, 2: velocity condition)."))
184 ((Vector3r,XmBcVel,Vector3r::Zero(),,"(!!! not fully implemented !!) The velocity imposed at the boundary"))
185 ((Real,XmBcRho,-1,,"(!!! not fully implemented !!) The density imposed at the boundary"))
186 ((int,WallXp_id,3,,"Identifier of the X+ wall"))
187 ((bool,useWallXp,false,,"Set true if you want that the LBM see the wall in Xp"))
188 ((int,XpBCType,1,,"Boundary condition for the wall in Xp (-1: unused, 1: pressure condition, 2: velocity condition)."))
189 ((Vector3r,XpBcVel,Vector3r::Zero(),,"(!!! not fully implemented !!) The velocity imposed at the boundary"))
190 ((Real,XpBcRho,-1,,"(!!! not fully implemented !!) The density imposed at the boundary"))
191 ((int,WallZp_id,5,,"Identifier of the Z+ wall"))
192 ((bool,useWallZp,false,,"Set true if you want that the LBM see the wall in Zp"))
193 ((int,ZpBCType,-1,,"Boundary condition for the wall in Zp (-1: unused, 1: pressure condition, 2: velocity condition)."))
194 ((Vector3r,ZpBcVel,Vector3r::Zero(),,"(!!! not fully implemented !!) The velocity imposed at the boundary"))
195 ((Real,zpBcRho,-1,,"(!!! not fully implemented !!) The density imposed at the boundary"))
196 ((int,WallZm_id,4,,"Identifier of the Z- wall"))
197 ((bool,useWallZm,false,,"Set true if you want that the LBM see the wall in Zm"))
198 ((int,ZmBCType,-1,,"Boundary condition for the wall in Zm (-1: unused, 1: pressure condition, 2: velocity condition)."))
199 ((Vector3r,ZmBcVel,Vector3r::Zero(),,"(!!! not fully implemented !!) The velocity imposed at the boundary"))
200 ((Real,ZmBcRho,-1,,"(!!! not fully implemented !!) The density imposed at the boundary"))
201 ((int,XmYmZpBCType,2,,"Boundary condition for the corner node XmYmZp (-1: unused, 1: pressure condition, 2: velocity condition)."))
202 ((int,XmYpZpBCType,2,,"Boundary condition for the corner node XmYpZp (-1: unused, 1: pressure condition, 2: velocity condition)."))
203 ((int,XpYmZpBCType,2,,"Boundary condition for the corner node XpYmZp (-1: unused, 1: pressure condition, 2: velocity condition)."))
204 ((int,XpYpZpBCType,2,,"Boundary condition for the corner node XpYpZp (-1: unused, 1: pressure condition, 2: velocity condition)."))
205 ((int,XmYmZmBCType,-1,,"Boundary condition for the corner node XmYmZm (not used with d2q9, -1: unused, 1: pressure condition, 2: velocity condition)."))
206 ((int,XmYpZmBCType,-1,,"Boundary condition for the corner node XmYpZm (not used with d2q9, -1: unused, 1: pressure condition, 2: velocity condition)."))
207 ((int,XpYmZmBCType,-1,,"Boundary condition for the corner node XpYmZm (not used with d2q9, -1: unused, 1: pressure condition, 2: velocity condition)."))
208 ((int,XpYpZmBCType,-1,,"Boundary condition for the corner node XpYpZm (not used with d2q9, -1: unused, 1: pressure condition, 2: velocity condition)."))
209
210 ((int,defaultLbmInitMode,0,,"Switch between the two initialisation methods"))
211 ((Vector3r,dP,Vector3r(0.,0.,0.),,"Pressure difference between input and output"))
212 ((Real,Rho,1000.,,"Fluid density"))
213 ((Real,Nu,0.000001,,"Fluid kinematic viscosity"))
214 ((Real,tau,0.6,,"Relaxation time"))
215 ((int,Nx,1000,,"The number of grid division in x direction"))
216 ((int,IterMax,1,,"This variable can be used to do several LBM iterations during one DEM iteration. "))
217 ((int,IterPrint,1,,"Print info on screen every IterPrint iterations"))
218 ((int,SaveMode,1,,"Save Mode (1-> default, 2-> in time (not yet implemented)"))
219 ((int,IterSave,100,,"Data are saved every IterSave LBM iteration (or see TimeSave)"))
220 ((Real,TimeSave,-1,,"Data are saved at constant time interval (or see IterSave)"))
221 ((int,SaveGridRatio,1,,"Grid data are saved every SaveGridRatio * IterSave LBM iteration (with SaveMode=1)"))
222 ((int,IterSubCyclingStart,-1,,"Iteration number when the subcycling process starts"))
223 ((int,DemIterLbmIterRatio,-1,,"Ratio between DEM and LBM iterations for subcycling"))
224 ((bool,EngineIsActivated,true,,"To activate (or not) the engine"))
225 ((bool,applyForcesAndTorques,true,,"Switch to apply forces and torques"))
226 ((int,ObservedNode,-1,,"The identifier of the node that will be observed (-1 means none)"))
227 ((int,ObservedPtc,-1,,"The identifier of the particle that will be observed (-1 means the first one)"))
228 ((Real,RadFactor,1.0,,"The radius of DEM particules seen by the LBM is the real radius of particules*RadFactor"))
229 ((Real,ConvergenceThreshold,0.000001,,""))
230 ((std::string,LBMSavedData," ",,"a list of data that will be saved. Can use velocity,velXY,forces,rho,bodies,nodeBD,newNode,observedptc,observednode,contacts,spheres,bz2"))
231 ((std::string,periodicity," ",,"periodicity"))
232 ((std::string,bc," ",,"Boundary condition"))
233 ((std::string,model,"d2q9",,"The LB model. Until now only d2q9 is implemented"))
234 ((int,removingCriterion ,0,,"Criterion to remove a sphere (1->based on particle position, 2->based on particle velocity"))
235 ((Real,VelocityThreshold,-1.,,"Velocity threshold when removingCriterion=2"))
236 ((Real,EndTime,-1,,"the time to stop the simulation"))
237 ((Vector3r,CstBodyForce,Vector3r::Zero(),,"A constant body force (=that does not vary in time or space, otherwise the implementation introduces errors)"))
238 ((Real,VbCutOff,-1,,"the minimum boundary velocity that is taken into account"))
239 ,
240 firstRun = true;
241 omega = 1.0/tau;
242 DEM_TIME = 0.;
243 LBM_TIME = 0.;
244 iter = 0;
245 use_ConvergenceCriterion = true;
246 MODE=0;
247 dim=0;
248 NbDir=0;
249 NbNodes=0;
250 NbFluidNodes=0;
251 NbSolidNodes=0;
252 NbParticleNodes=0;
253 NbContacts=0;
254 InitialNumberOfDynamicParticles=0;
255 NumberOfDynamicParticles=0;
256 NumberPtcEroded=0;
257 Vr=0.;
258 Vo=0.;
259 MaxBodyRadius=-1000000.;
260 MinBodyRadius=1000000.;
261 MeanBodyRadius=0.;
262 lbm_dir="lbm-nodes";
263 dem_dir="dem-bodies";
264 cntct_dir="contacts";
265 LBMlogFile ="LBM.log";
266 LBMmachFile ="LBM.mach";
267 LBMcontactsFile ="LBM.cntct";
268 RemovedPtcFile="eroded.dat";
269 ObservedPtcFile="observedPtc.dat";
270 ObservedNodeFile="observedNode.dat";
271 COMPRESS_DATA = false;
272 SAVE_VELOCITY = false;
273 SAVE_VELOCITYCOMP = false;
274 SAVE_RHO = false;
275 SAVE_FORCES = false;
276 SAVE_BODIES = false;
277 SAVE_NODEBD = false;
278 SAVE_NODEISNEW = false;
279 SAVE_DEBUGFILES = false;
280 SAVE_OBSERVEDPTC= false;
281 SAVE_OBSERVEDNODE=false;
282 SAVE_CONTACTINFO =false;
283 SAVE_SPHERES = false; //to save spheres_* files only if it is required by the operator
284 Xperiodicity = false;
285 Yperiodicity = false;
286 Zperiodicity = false;
287 Ny = 0;Nz = 0;
288 FmoyCur=0.;FmoyPrev=0.;
289 FmoyPrevPrev=0.;VmeanFluidC=0.;PrevVmeanFluidC=0.;PrevPrevVmeanFluidC=0.;
290 LBM_ITER=0;
291 DEM_ITER=0;
292 IdFirstSphere=-1;
293 timingDeltas=shared_ptr<TimingDeltas>(new TimingDeltas);
294
295 );
296 // clang-format on
297 DECLARE_LOGGER;
298 };
299
300
301 REGISTER_SERIALIZABLE(HydrodynamicsLawLBM);
302
303 } // namespace yade
304
305 #endif //LBM_ENGINE