| 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 |
#include "HydrodynamicsLawLBM.hpp" |
| 27 |
#include <lib/base/AliasNamespaces.hpp> |
| 28 |
#include <lib/high-precision/Constants.hpp> |
| 29 |
#include <core/Omega.hpp> |
| 30 |
#include <core/Scene.hpp> |
| 31 |
#include <pkg/common/Box.hpp> |
| 32 |
#include <pkg/common/Sphere.hpp> |
| 33 |
#include <pkg/dem/CohesiveFrictionalContactLaw.hpp> |
| 34 |
#include <boost/filesystem.hpp> |
| 35 |
|
| 36 |
namespace yade { // Cannot have #include directive inside. |
| 37 |
|
| 38 |
using math::max; |
| 39 |
using math::min; // using inside .cpp file is ok. |
| 40 |
|
| 41 |
inline Vector3i vect3rToVect3i(Vector3r vect) |
| 42 |
{ |
| 43 |
Vector3i newvect((int)vect[0], (int)vect[1], (int)vect[2]); |
| 44 |
return (newvect); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
HydrodynamicsLawLBM::~HydrodynamicsLawLBM() {}; |
| 49 |
|
| 50 |
bool HydrodynamicsLawLBM::isActivated() |
| 51 |
{ |
| 52 |
DEM_ITER = scene->iter; //+1; |
| 53 |
if (EngineIsActivated) { |
| 54 |
if ((DEM_ITER % DemIterLbmIterRatio == 0) && (DEM_ITER != DemIterLbmIterRatio)) { |
| 55 |
if (DEM_ITER == 0) { |
| 56 |
DEMdt0 = scene->dt; |
| 57 |
scene->dt = 1.e-50; |
| 58 |
} |
| 59 |
return (true); |
| 60 |
} else { |
| 61 |
if (applyForcesAndTorques) CalculateAndApplyForcesAndTorquesOnBodies(false, true); |
| 62 |
return (false); |
| 63 |
} |
| 64 |
} else |
| 65 |
return (false); |
| 66 |
} |
| 67 |
|
| 68 |
void HydrodynamicsLawLBM::action() |
| 69 |
{ |
| 70 |
timingDeltas->start(); |
| 71 |
NB_BODIES = scene->bodies->size(); |
| 72 |
int I, J, step = 0; |
| 73 |
NbFluidNodes = 0; |
| 74 |
NbSolidNodes = 0; |
| 75 |
Real CurMinVelOfPtc = 1000000.; |
| 76 |
Real CurMaxVelOfPtc = -1000000.; |
| 77 |
int ErrorCriterion = 2; |
| 78 |
/*------------------------------------------------------------------*/ |
| 79 |
/* AT FIRST ITERATION */ |
| 80 |
/*------------------------------------------------------------------*/ |
| 81 |
if (firstRun) { |
| 82 |
// createNewFiles(); //this line is move further to create files only when the recording configuration chosen by the operator is known |
| 83 |
bool initVbCutOff = false; |
| 84 |
if (VbCutOff == -1) initVbCutOff = true; |
| 85 |
halfWallthickness = 1000000.; |
| 86 |
NB_WALLS = 0; |
| 87 |
//NB_DYNWALLS=0; |
| 88 |
NB_DYNGRAINS = 0; |
| 89 |
LBMbody tmpbody; |
| 90 |
for (const auto& b : *scene->bodies) { |
| 91 |
if (!b) continue; // deleted bodies |
| 92 |
if (b->shape->getClassName() == "Box") { |
| 93 |
Vector3r ext(YADE_PTR_CAST<Box>(b->shape)->extents); |
| 94 |
if (ext[0] < halfWallthickness) halfWallthickness = ext[0]; |
| 95 |
if (ext[1] < halfWallthickness) halfWallthickness = ext[1]; |
| 96 |
if (ext[2] < halfWallthickness) halfWallthickness = ext[2]; |
| 97 |
NB_WALLS++; |
| 98 |
tmpbody.setAsBox(); |
| 99 |
tmpbody.saveProperties = false; |
| 100 |
//if(b->isDynamic()) NB_DYNWALLS++; |
| 101 |
} |
| 102 |
if (b->shape->getClassName() == "Sphere") { |
| 103 |
const shared_ptr<Sphere>& sph = YADE_PTR_CAST<Sphere>(b->shape); |
| 104 |
if (IdFirstSphere == -1) IdFirstSphere = b->getId(); |
| 105 |
tmpbody.setAsPtc(); |
| 106 |
Real r = sph->radius; |
| 107 |
if (b->isDynamic()) { |
| 108 |
NB_DYNGRAINS++; |
| 109 |
/*--- computation of the initial volume ---*/ |
| 110 |
if (!strcmp(model.c_str(), "d2q9")) Vo += Mathr::PI * (r * r); |
| 111 |
else |
| 112 |
Vo += 4. / 3. * Mathr::PI * (r * r * r); |
| 113 |
if (initVbCutOff) VbCutOff = max(VbCutOff, b->state->vel.norm() + r * b->state->angVel.norm()); |
| 114 |
tmpbody.saveProperties = true; |
| 115 |
} else { |
| 116 |
if (b->state->pos[1] > 0.) tmpbody.saveProperties = true; |
| 117 |
else |
| 118 |
tmpbody.saveProperties = false; |
| 119 |
} |
| 120 |
/*--- computation of Rmean Rmax Rmin --*/ |
| 121 |
MaxBodyRadius = max(r, MaxBodyRadius); |
| 122 |
MinBodyRadius = min(r, MinBodyRadius); |
| 123 |
MeanBodyRadius += r; |
| 124 |
} |
| 125 |
|
| 126 |
LBbodies.push_back(tmpbody); |
| 127 |
} |
| 128 |
Wallthickness = 2.0 * halfWallthickness; |
| 129 |
NB_GRAINS = NB_BODIES - NB_WALLS; |
| 130 |
//Luc: is it right to count the walls as dynamic bodies? |
| 131 |
//Franck why not ? Enhancement (see next line is coming ;-)) |
| 132 |
NB_DYNBODIES = NB_WALLS + NB_DYNGRAINS; |
| 133 |
//NB_DYNBODIES=NB_DYNWALLS+NB_DYNGRAINS; |
| 134 |
MeanBodyRadius = MeanBodyRadius / NB_GRAINS; |
| 135 |
InitialNumberOfDynamicParticles = NB_DYNGRAINS; |
| 136 |
|
| 137 |
/*-------------------------------------------------------------------------*/ |
| 138 |
/* D2Q9 model configuration */ |
| 139 |
/*-------------------------------------------------------------------------*/ |
| 140 |
if (!strcmp(model.c_str(), "d2q9")) { |
| 141 |
dim = 2; |
| 142 |
/*--------------------------------------*/ |
| 143 |
/* D2Q9 model: 6 2 5 */ |
| 144 |
/* 3 _\|/__1 */ |
| 145 |
/* /|\ */ |
| 146 |
/* 7 4 8 */ |
| 147 |
/*--------------------------------------*/ |
| 148 |
/*----------- D2Q9 constants ---------*/ |
| 149 |
w.push_back(4.0 / 9.0); |
| 150 |
for (int aa = 1; aa <= 4; aa++) |
| 151 |
w.push_back(1.0 / 9.0); |
| 152 |
for (int aa = 5; aa <= 8; aa++) |
| 153 |
w.push_back(1.0 / 36.0); |
| 154 |
|
| 155 |
/*--------- node position vectors ----*/ |
| 156 |
eib.push_back(Vector3r(0., 0., 0.)); //0 |
| 157 |
eib.push_back(Vector3r(1., 0., 0.)); //1 |
| 158 |
eib.push_back(Vector3r(0., 1., 0.)); //2 |
| 159 |
eib.push_back(Vector3r(-1., 0., 0.)); //3 |
| 160 |
eib.push_back(Vector3r(0., -1., 0.)); //4 |
| 161 |
eib.push_back(Vector3r(1., 1., 0.)); //5 |
| 162 |
eib.push_back(Vector3r(-1., 1., 0.)); //6 |
| 163 |
eib.push_back(Vector3r(-1., -1., 0.)); //7 |
| 164 |
eib.push_back(Vector3r(1., -1., 0.)); //8 |
| 165 |
NbDir = (int)eib.size(); |
| 166 |
|
| 167 |
/*-------------- opposite nodes --------*/ |
| 168 |
opp.push_back(0); |
| 169 |
opp.push_back(3); |
| 170 |
opp.push_back(4); |
| 171 |
opp.push_back(1); |
| 172 |
opp.push_back(2); |
| 173 |
opp.push_back(7); |
| 174 |
opp.push_back(8); |
| 175 |
opp.push_back(5); |
| 176 |
opp.push_back(6); |
| 177 |
} else { |
| 178 |
cerr << "This model is not implemented yet: " << model << endl; |
| 179 |
exit(-1); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
int res = 0; |
| 184 |
int ll = 0; |
| 185 |
bool CreateLbmDir = false; //Flag to create directories if required by the recording configuration |
| 186 |
bool CreateDemDir = false; //Flag to create directories if required by the recording configuration |
| 187 |
bool CreateCntctDir = false; //Flag to create directories if required by the recording configuration |
| 188 |
/*-------------------------------------------------------------------------*/ |
| 189 |
/* Recording configuration */ |
| 190 |
/*-------------------------------------------------------------------------*/ |
| 191 |
ll = LBMSavedData.size(); |
| 192 |
res = LBMSavedData.find("Velocity"); |
| 193 |
if (res >= 0 && res < ll) { |
| 194 |
SAVE_VELOCITY = true; |
| 195 |
SAVE_VELOCITYCOMP = true; |
| 196 |
CreateLbmDir = true; |
| 197 |
} |
| 198 |
res = LBMSavedData.find("velocity"); |
| 199 |
if (res >= 0 && res < ll) { |
| 200 |
SAVE_VELOCITY = true; |
| 201 |
SAVE_VELOCITYCOMP = true; |
| 202 |
CreateLbmDir = true; |
| 203 |
} |
| 204 |
res = LBMSavedData.find("VelXY"); |
| 205 |
if (res >= 0 && res < ll) { |
| 206 |
SAVE_VELOCITYCOMP = true; |
| 207 |
CreateLbmDir = true; |
| 208 |
} |
| 209 |
res = LBMSavedData.find("velXY"); |
| 210 |
if (res >= 0 && res < ll) { |
| 211 |
SAVE_VELOCITYCOMP = true; |
| 212 |
CreateLbmDir = true; |
| 213 |
} |
| 214 |
res = LBMSavedData.find("Rho"); |
| 215 |
if (res >= 0 && res < ll) { |
| 216 |
SAVE_RHO = true; |
| 217 |
CreateLbmDir = true; |
| 218 |
} |
| 219 |
res = LBMSavedData.find("rho"); |
| 220 |
if (res >= 0 && res < ll) { |
| 221 |
SAVE_RHO = true; |
| 222 |
CreateLbmDir = true; |
| 223 |
} |
| 224 |
res = LBMSavedData.find("Forces"); |
| 225 |
if (res >= 0 && res < ll) { |
| 226 |
SAVE_FORCES = true; |
| 227 |
CreateLbmDir = true; |
| 228 |
} |
| 229 |
res = LBMSavedData.find("forces"); |
| 230 |
if (res >= 0 && res < ll) { |
| 231 |
SAVE_FORCES = true; |
| 232 |
CreateLbmDir = true; |
| 233 |
} |
| 234 |
res = LBMSavedData.find("Bodies"); |
| 235 |
if (res >= 0 && res < ll) { |
| 236 |
SAVE_BODIES = true; |
| 237 |
CreateLbmDir = true; |
| 238 |
} |
| 239 |
res = LBMSavedData.find("bodies"); |
| 240 |
if (res >= 0 && res < ll) { |
| 241 |
SAVE_BODIES = true; |
| 242 |
CreateLbmDir = true; |
| 243 |
} |
| 244 |
res = LBMSavedData.find("NodeBD"); |
| 245 |
if (res >= 0 && res < ll) { |
| 246 |
SAVE_NODEBD = true; |
| 247 |
CreateLbmDir = true; |
| 248 |
} |
| 249 |
res = LBMSavedData.find("nodeBD"); |
| 250 |
if (res >= 0 && res < ll) { |
| 251 |
SAVE_NODEBD = true; |
| 252 |
CreateLbmDir = true; |
| 253 |
} |
| 254 |
res = LBMSavedData.find("NewNode"); |
| 255 |
if (res >= 0 && res < ll) { |
| 256 |
SAVE_NODEISNEW = true; |
| 257 |
CreateLbmDir = true; |
| 258 |
} |
| 259 |
res = LBMSavedData.find("newNode"); |
| 260 |
if (res >= 0 && res < ll) { |
| 261 |
SAVE_NODEISNEW = true; |
| 262 |
CreateLbmDir = true; |
| 263 |
} |
| 264 |
res = LBMSavedData.find("bz2"); |
| 265 |
if (res >= 0 && res < ll) COMPRESS_DATA = true; |
| 266 |
res = LBMSavedData.find("ObservedPtc"); |
| 267 |
if (res >= 0 && res < ll) SAVE_OBSERVEDPTC = true; |
| 268 |
res = LBMSavedData.find("observedptc"); |
| 269 |
if (res >= 0 && res < ll) SAVE_OBSERVEDPTC = true; |
| 270 |
res = LBMSavedData.find("observedPtc"); |
| 271 |
if (res >= 0 && res < ll) SAVE_OBSERVEDPTC = true; |
| 272 |
res = LBMSavedData.find("ObservedNode"); |
| 273 |
if (res >= 0 && res < ll) SAVE_OBSERVEDNODE = true; // does not activate any recording in a a file currently |
| 274 |
res = LBMSavedData.find("observednode"); |
| 275 |
if (res >= 0 && res < ll) SAVE_OBSERVEDNODE = true; |
| 276 |
res = LBMSavedData.find("observedNode"); |
| 277 |
if (res >= 0 && res < ll) SAVE_OBSERVEDNODE = true; |
| 278 |
res = LBMSavedData.find("contacts"); |
| 279 |
if (res >= 0 && res < ll) { |
| 280 |
SAVE_CONTACTINFO = true; |
| 281 |
CreateCntctDir = true; |
| 282 |
} // SAVE_CONTACTINFO does not activate any (anymore) recording excepted the creation of a directory |
| 283 |
res = LBMSavedData.find("Contacts"); |
| 284 |
if (res >= 0 && res < ll) { |
| 285 |
SAVE_CONTACTINFO = true; |
| 286 |
CreateCntctDir = true; |
| 287 |
} |
| 288 |
res = LBMSavedData.find("spheres"); |
| 289 |
if (res >= 0 && res < ll) { |
| 290 |
SAVE_SPHERES = true; |
| 291 |
CreateDemDir = true; |
| 292 |
} // To save spheres_* file only if it is required by the operator |
| 293 |
res = LBMSavedData.find("Spheres"); |
| 294 |
if (res >= 0 && res < ll) { |
| 295 |
SAVE_SPHERES = true; |
| 296 |
CreateDemDir = true; |
| 297 |
} // To save spheres_* file only if it is required by the operator |
| 298 |
|
| 299 |
// if(NB_DYNGRAINS==1) SAVE_OBSERVEDPTC =true; //Commented to avoid recording of observedPtc if not chosen by the operator |
| 300 |
if ((ObservedPtc == -1) && (NB_GRAINS > 0) && (SAVE_OBSERVEDPTC)) |
| 301 |
ObservedPtc = IdFirstSphere; //Condition If(SAVE_OBSERVEDPTC) is added to save observedPtc only if it is required by the operator |
| 302 |
if ((SAVE_OBSERVEDPTC) && ((unsigned)ObservedPtc >= LBbodies.size())) { |
| 303 |
cerr << "Error: ObservedPtc>bodies.size()" << endl; |
| 304 |
exit(-1); |
| 305 |
} |
| 306 |
if ((SAVE_SPHERES) && (NB_GRAINS < 1)) { |
| 307 |
cerr << "Error: saving of sphere properties is switched on whereas NB_GRAINS<1" << endl; |
| 308 |
exit(-1); |
| 309 |
} |
| 310 |
|
| 311 |
createDirectories(CreateLbmDir, CreateDemDir, CreateCntctDir); |
| 312 |
createNewFiles(); // Files are created now, since we know what the operator wants to record (ObservedPtc ... etc) |
| 313 |
|
| 314 |
|
| 315 |
/*--------------------------------------------------------------*/ |
| 316 |
/* Periodicity configuration */ |
| 317 |
/*--------------------------------------------------------------*/ |
| 318 |
ll = periodicity.size(); |
| 319 |
res = periodicity.find("x"); |
| 320 |
if (res >= 0 && res < ll) Xperiodicity = true; |
| 321 |
res = periodicity.find("y"); |
| 322 |
if (res >= 0 && res < ll) Yperiodicity = true; |
| 323 |
res = periodicity.find("z"); |
| 324 |
if (res >= 0 && res < ll) Zperiodicity = true; |
| 325 |
cerr << "Periodicity (XYZ): " << Xperiodicity << " " << Yperiodicity << " " << Zperiodicity << endl; |
| 326 |
|
| 327 |
|
| 328 |
/*--------------------------------------------------------------*/ |
| 329 |
/* Lattice definition */ |
| 330 |
/*--------------------------------------------------------------*/ |
| 331 |
cerr << "---- Lattice setup -----" << endl; |
| 332 |
State* sWallYm = Body::byId(WallYm_id, scene)->state.get(); |
| 333 |
State* sWallYp = Body::byId(WallYp_id, scene)->state.get(); |
| 334 |
State* sWallXm = Body::byId(WallXm_id, scene)->state.get(); |
| 335 |
State* sWallXp = Body::byId(WallXp_id, scene)->state.get(); |
| 336 |
State* sWallZp = Body::byId(WallZp_id, scene)->state.get(); |
| 337 |
State* sWallZm = Body::byId(WallZm_id, scene)->state.get(); |
| 338 |
|
| 339 |
height = sWallYp->se3.position.y() - sWallYm->se3.position.y(); |
| 340 |
width = sWallXp->se3.position.x() - sWallXm->se3.position.x(); |
| 341 |
depth = sWallZp->se3.position.z() - sWallZm->se3.position.z(); |
| 342 |
|
| 343 |
|
| 344 |
Lx0 = width - Wallthickness; |
| 345 |
Ly0 = height - Wallthickness; |
| 346 |
Lz0 = depth - Wallthickness; |
| 347 |
Real Lx1 = width + Wallthickness; |
| 348 |
Real Ly1 = height + Wallthickness; |
| 349 |
Real Lz1 = depth + Wallthickness; |
| 350 |
/*--------------------------------------------------------------*/ |
| 351 |
/* Computation of number of lattice nodes in each direction */ |
| 352 |
/*--------------------------------------------------------------*/ |
| 353 |
dx = Lx0 / (Real)(Nx - 1); |
| 354 |
invdx = 1. / dx; |
| 355 |
|
| 356 |
//Number of nodes (after-correction) |
| 357 |
Ny = int(math::ceil(invdx * Ly1)) + 1; |
| 358 |
dx = Ly1 / (Real)(Ny - 1); |
| 359 |
invdx = 1. / dx; |
| 360 |
dx2 = dx * dx; |
| 361 |
Nx = int(math::ceil(invdx * Lx1)) + 1; |
| 362 |
Ny = int(math::ceil(invdx * Ly1)) + 1; |
| 363 |
Nz = 1; |
| 364 |
|
| 365 |
cerr << "LXYZ0= " << Lx0 << " " << Ly0 << " " << Lz0 << endl; |
| 366 |
cerr << "LXYZ1= " << Lx1 << " " << Ly1 << " " << Lz1 << endl; |
| 367 |
cerr << "Ny= " << Ny << " " |
| 368 |
<< " Nx*Ly0/Lx0=" << Nx * Ly0 / Lx0 << endl; |
| 369 |
cerr << "Wallthickness= " << Wallthickness << " " |
| 370 |
<< " dx=" << dx << endl; |
| 371 |
|
| 372 |
/*-------------------------------------------------------*/ |
| 373 |
/* Verification of wall positionning in positive regions */ |
| 374 |
/*-------------------------------------------------------*/ |
| 375 |
if (sWallYm->se3.position.y() - halfWallthickness < 0.) { |
| 376 |
cerr << "Wall position error: please avoid negatives region (Y)" << endl; |
| 377 |
exit(-1); |
| 378 |
} |
| 379 |
if (sWallXm->se3.position.x() - halfWallthickness < 0.) { |
| 380 |
cerr << "Wall position error: please avoid negatives region (X)" << endl; |
| 381 |
exit(-1); |
| 382 |
} |
| 383 |
if ((dim == 3) && (sWallZm->se3.position.z() - halfWallthickness < 0.)) { |
| 384 |
cerr << "Wall position error: please avoid negatives region (Z)" << endl; |
| 385 |
exit(-1); |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
/*--------------------------------------------------------------*/ |
| 390 |
/* Some tests about the validity of parameters */ |
| 391 |
/*--------------------------------------------------------------*/ |
| 392 |
if ((NB_DYNGRAINS == 0) && (use_ConvergenceCriterion) && (ErrorCriterion == 1)) { |
| 393 |
cerr << "ERROR: can't use ErrorCriterion=1 when (NB_DYNGRAINS=0" << endl; |
| 394 |
exit(-1); |
| 395 |
} |
| 396 |
if ((ObservedNode != -1) && (ObservedNode >= Nx * Ny)) { |
| 397 |
cerr << "Warning ObservedNode is >= Nx*Ny ... exit" << endl; |
| 398 |
exit(-1); |
| 399 |
} |
| 400 |
if ((SaveMode != 1) && (SaveMode != 2)) { |
| 401 |
cerr << "Warning unknown SaveMode." << SaveMode << endl; |
| 402 |
exit(-1); |
| 403 |
} |
| 404 |
if ((SaveMode == 1) && (IterSave <= 0)) { |
| 405 |
cerr << "Warning SaveMode==1 and IterSave<=0." << endl; |
| 406 |
exit(-1); |
| 407 |
} |
| 408 |
if ((SaveMode == 2) && (TimeSave <= 0)) { |
| 409 |
cerr << "Warning SaveMode==2 and TimeSave<=0." << endl; |
| 410 |
exit(-1); |
| 411 |
} |
| 412 |
/*---------------------------------------------------------------*/ |
| 413 |
/*------------------ general node initialization ----------------*/ |
| 414 |
/*---------------------------------------------------------------*/ |
| 415 |
LBMnode aa; |
| 416 |
for (int nidx = 0; nidx < Nx * Ny; nidx++) { |
| 417 |
nodes.push_back(aa); |
| 418 |
} |
| 419 |
bool j_update = false; |
| 420 |
int j = 0; |
| 421 |
for (int nidx = 0; nidx < Nx * Ny; nidx++) { |
| 422 |
int i = nidx - j * Nx; |
| 423 |
if ((nidx + 1) % Nx == 0) j_update = true; |
| 424 |
int k = 0; |
| 425 |
|
| 426 |
nodes[nidx].SetCellIndexesAndPosition(i, j, k); |
| 427 |
nodes[nidx].DispatchBoundaryConditions(Nx, Ny, Nz); |
| 428 |
NbNodes++; |
| 429 |
for (int dndx = 0; dndx < NbDir; dndx++) { |
| 430 |
nodes[nidx].links_id.push_back(-1); |
| 431 |
I = nodes[nidx].i + int(math::round(eib[dndx].x())); // XXX: this is suspicious |
| 432 |
J = nodes[nidx].j + int(math::round(eib[dndx].y())); |
| 433 |
if (((I == i) && (J == j)) || (I == -1) || (J == -1) || (I == Nx) || (J == Ny)) { |
| 434 |
nodes[nidx].neighbour_id.push_back(-1); |
| 435 |
} else { |
| 436 |
nodes[nidx].neighbour_id.push_back(I + J * Nx); |
| 437 |
} |
| 438 |
} |
| 439 |
if (j_update) { |
| 440 |
j++; |
| 441 |
j_update = false; |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
//////////////////////////////////////////////////////////////////////////////////// |
| 446 |
///FIXME(flomine#1): periodicity should be implemented from links to facilitate the streaming step |
| 447 |
///FIXME(flomine#1): to be optimise and bug should be corrected (cf test version) |
| 448 |
LBMlink bb; |
| 449 |
int link_id = -1; |
| 450 |
for (int nidx = 0; nidx < Nx * Ny; nidx++) { |
| 451 |
int Ia = nodes[nidx].i; |
| 452 |
int Ja = nodes[nidx].j; |
| 453 |
for (int dndx = 0; dndx < NbDir; dndx++) { |
| 454 |
if (dndx == 0) continue; |
| 455 |
bb.PointingOutside = false; |
| 456 |
if ((!strcmp(model.c_str(), "d2q9")) && ((dndx == 1) || (dndx == 2) || (dndx == 5) || (dndx == 6))) { |
| 457 |
link_id++; |
| 458 |
bb.i = dndx; |
| 459 |
bb.nid1 = nidx; |
| 460 |
bb.nid2 = nodes[nidx].neighbour_id[dndx]; |
| 461 |
if (bb.nid2 == -1) bb.PointingOutside = true; |
| 462 |
links.push_back(bb); |
| 463 |
nodes[bb.nid1].links_id[dndx] = link_id; |
| 464 |
if (bb.nid2 != -1) nodes[bb.nid2].links_id[opp[dndx]] = link_id; |
| 465 |
} else if (!strcmp(model.c_str(), "d2q9")) { |
| 466 |
if ((Ia == 0) && (Ja != 0) && ((dndx == 3) || (dndx == 7))) { |
| 467 |
link_id++; |
| 468 |
bb.i = dndx; |
| 469 |
bb.nid1 = nidx; |
| 470 |
bb.nid2 = nodes[nidx].neighbour_id[dndx]; |
| 471 |
bb.PointingOutside = true; |
| 472 |
if (bb.nid2 != -1) { |
| 473 |
cerr << "ERROR: bb.id2!=-1" << endl; |
| 474 |
exit(-1); |
| 475 |
} |
| 476 |
links.push_back(bb); |
| 477 |
nodes[bb.nid1].links_id[dndx] = link_id; |
| 478 |
if (bb.nid2 != -1) nodes[bb.nid2].links_id[opp[dndx]] = link_id; |
| 479 |
} else if ((Ja == 0) && (Ia != 0) && ((dndx == 4) || (dndx == 7) || (dndx == 8))) { |
| 480 |
link_id++; |
| 481 |
bb.i = dndx; |
| 482 |
bb.nid1 = nidx; |
| 483 |
bb.nid2 = nodes[nidx].neighbour_id[dndx]; |
| 484 |
bb.PointingOutside = true; |
| 485 |
if (bb.nid2 != -1) { |
| 486 |
cerr << "ERROR: bb.id2!=-1" << endl; |
| 487 |
exit(-1); |
| 488 |
} |
| 489 |
links.push_back(bb); |
| 490 |
nodes[bb.nid1].links_id[dndx] = link_id; |
| 491 |
if (bb.nid2 != -1) nodes[bb.nid2].links_id[opp[dndx]] = link_id; |
| 492 |
} else if ((Ia == 0) && (Ja == 0) && ((dndx == 3) || (dndx == 4) || (dndx == 7) || (dndx == 8))) { |
| 493 |
link_id++; |
| 494 |
bb.i = dndx; |
| 495 |
bb.nid1 = nidx; |
| 496 |
bb.nid2 = nodes[nidx].neighbour_id[dndx]; |
| 497 |
bb.PointingOutside = true; |
| 498 |
if (bb.nid2 != -1) { |
| 499 |
cerr << "ERROR: bb.id2!=-1" << endl; |
| 500 |
exit(-1); |
| 501 |
} |
| 502 |
links.push_back(bb); |
| 503 |
nodes[bb.nid1].links_id[dndx] = link_id; |
| 504 |
if (bb.nid2 != -1) nodes[bb.nid2].links_id[opp[dndx]] = link_id; |
| 505 |
} |
| 506 |
} else { |
| 507 |
cerr << "ERROR: Unknow model type: " << model << endl; |
| 508 |
exit(-1); |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
//////////////////////////////////////////////////////////////////////////////////// |
| 513 |
|
| 514 |
if ((ConvergenceThreshold == -1) || (ConvergenceThreshold == 0)) use_ConvergenceCriterion = false; |
| 515 |
else { |
| 516 |
use_ConvergenceCriterion = true; |
| 517 |
ErrorCriterion = int(math::round(ConvergenceThreshold)); |
| 518 |
} |
| 519 |
/*------------------------------------------------------------------*/ |
| 520 |
/*------------------------ LBM PARAMETERS --------------------------*/ |
| 521 |
/*------------------------------------------------------------------*/ |
| 522 |
UMaxtheo = dP.norm() / (8. * Rho * Nu) * (height * height / width); |
| 523 |
if (defaultLbmInitMode) { |
| 524 |
uMax = 0.1; |
| 525 |
c = UMaxtheo / uMax; |
| 526 |
cs = c / sqrt(3.); |
| 527 |
dt = dx / c; |
| 528 |
nu = dt / (dx * dx / Nu); |
| 529 |
tau = 3. * nu + 0.5; |
| 530 |
} else { |
| 531 |
nu = (1.0 / 3.0) * (tau - 0.5); |
| 532 |
dt = nu * (dx * dx / Nu); |
| 533 |
c = dx / dt; |
| 534 |
cs = c / sqrt(3.); |
| 535 |
uMax = UMaxtheo / c; |
| 536 |
} |
| 537 |
omega = 1.0 / tau; |
| 538 |
c2 = c * c; |
| 539 |
invdt = 1. / dt; |
| 540 |
MaxBodyRadius = invdx * MaxBodyRadius; |
| 541 |
MinBodyRadius = invdx * MinBodyRadius; |
| 542 |
MeanBodyRadius = invdx * MeanBodyRadius; |
| 543 |
outside_limit = 1.5 * width; |
| 544 |
} //end if FirstRun |
| 545 |
|
| 546 |
/*************************************************************************/ |
| 547 |
/* SOLID OBSTACLES SET-UP */ |
| 548 |
/*************************************************************************/ |
| 549 |
Real Rmin = 1000.; |
| 550 |
int newFluidCells_couter = 0; |
| 551 |
int newObstacleCells_couter = 0; |
| 552 |
|
| 553 |
State* sWallYm = Body::byId(WallYm_id, scene)->state.get(); |
| 554 |
State* sWallYp = Body::byId(WallYp_id, scene)->state.get(); |
| 555 |
State* sWallXm = Body::byId(WallXm_id, scene)->state.get(); |
| 556 |
State* sWallXp = Body::byId(WallXp_id, scene)->state.get(); |
| 557 |
State* sWallZp = Body::byId(WallZp_id, scene)->state.get(); |
| 558 |
State* sWallZm = Body::byId(WallZm_id, scene)->state.get(); |
| 559 |
|
| 560 |
timingDeltas->checkpoint("Reinit:Nodes0"); |
| 561 |
#ifdef YADE_OPENMP |
| 562 |
#pragma omp parallel for |
| 563 |
#endif |
| 564 |
for (int nidx = 0; nidx < Nx * Ny; nidx++) { |
| 565 |
/*------------------------------------------*/ |
| 566 |
/* Reinitialization: */ |
| 567 |
/*------------------------------------------*/ |
| 568 |
nodes[nidx].body_id = -1; |
| 569 |
nodes[nidx].setAsFluid(); |
| 570 |
nodes[nidx].isObstacleBoundary = false; |
| 571 |
nodes[nidx].isFluidBoundary = false; |
| 572 |
nodes[nidx].isNewObstacle = false; |
| 573 |
nodes[nidx].isNewFluid = false; |
| 574 |
|
| 575 |
/*--- according to X+ ---*/ |
| 576 |
if (useWallXp && (nodes[nidx].i >= invdx * (sWallXp->se3.position.x() - halfWallthickness))) { |
| 577 |
nodes[nidx].setAsObstacle(); |
| 578 |
nodes[nidx].isObstacleBoundary = true; |
| 579 |
nodes[nidx].body_id = WallXp_id; |
| 580 |
NbSolidNodes++; |
| 581 |
} |
| 582 |
/*--- according to X- ---*/ |
| 583 |
else if (useWallXm && (nodes[nidx].i <= invdx * (sWallXm->se3.position.x() + halfWallthickness))) { |
| 584 |
nodes[nidx].setAsObstacle(); |
| 585 |
nodes[nidx].isObstacleBoundary = true; |
| 586 |
nodes[nidx].body_id = WallXm_id; |
| 587 |
NbSolidNodes++; |
| 588 |
} |
| 589 |
/*--- according to Y+ ---*/ |
| 590 |
else if (useWallYp && (nodes[nidx].j >= invdx * (sWallYp->se3.position.y() - halfWallthickness))) { |
| 591 |
nodes[nidx].setAsObstacle(); |
| 592 |
nodes[nidx].isObstacleBoundary = true; |
| 593 |
nodes[nidx].body_id = WallYp_id; |
| 594 |
NbSolidNodes++; |
| 595 |
} |
| 596 |
/*--- according to Y- ---*/ |
| 597 |
else if (useWallYm && (nodes[nidx].j <= invdx * (sWallYm->se3.position.y() + halfWallthickness))) { |
| 598 |
nodes[nidx].setAsObstacle(); |
| 599 |
nodes[nidx].isObstacleBoundary = true; |
| 600 |
nodes[nidx].body_id = WallYm_id; |
| 601 |
NbSolidNodes++; |
| 602 |
} |
| 603 |
/*--- according to Z+ ---*/ |
| 604 |
else if (useWallZp && (nodes[nidx].k >= invdx * (sWallZp->se3.position.z() - halfWallthickness))) { |
| 605 |
nodes[nidx].setAsObstacle(); |
| 606 |
nodes[nidx].isObstacleBoundary = true; |
| 607 |
nodes[nidx].body_id = WallZp_id; |
| 608 |
NbSolidNodes++; |
| 609 |
} |
| 610 |
/*--- according to Z- ---*/ |
| 611 |
else if (useWallZm && (nodes[nidx].k <= invdx * (sWallZm->se3.position.z() + halfWallthickness))) { |
| 612 |
nodes[nidx].setAsObstacle(); |
| 613 |
nodes[nidx].isObstacleBoundary = true; |
| 614 |
nodes[nidx].body_id = WallZm_id; |
| 615 |
NbSolidNodes++; |
| 616 |
} |
| 617 |
|
| 618 |
if (firstRun) { nodes[nidx].wasObstacle = nodes[nidx].isObstacle; } |
| 619 |
} |
| 620 |
|
| 621 |
/*---------------------------------------------------------------*/ |
| 622 |
/*- Solid particle detection and recording of their properties --*/ |
| 623 |
/*---------------------------------------------------------------*/ |
| 624 |
NumberOfDynamicParticles = 0; |
| 625 |
if (removingCriterion != 0) IdOfNextErodedPtc.clear(); |
| 626 |
for (const auto& b : *scene->bodies) { |
| 627 |
if (!b) continue; // deleted bodies |
| 628 |
State* state = b->state.get(); |
| 629 |
const int id = b->getId(); |
| 630 |
//if ((b->shape->getClassName()=="Sphere")&&(b->isDynamic())){ //ModLuc: removing of b->isDynamic() in order that non dynamic particle can be seen by the LBM |
| 631 |
if (b->shape->getClassName() == "Sphere") { |
| 632 |
const shared_ptr<Sphere>& sphere = YADE_PTR_CAST<Sphere>(b->shape); |
| 633 |
|
| 634 |
LBbodies[id].pos = invdx * state->pos; |
| 635 |
LBbodies[id].vel = (state->vel) / c; |
| 636 |
LBbodies[id].AVel = (state->angVel) * dt; |
| 637 |
LBbodies[id].radius = invdx * RadFactor * (sphere->radius); |
| 638 |
|
| 639 |
CurMinVelOfPtc = min(CurMinVelOfPtc, state->vel.norm()); |
| 640 |
CurMaxVelOfPtc = max(CurMaxVelOfPtc, state->vel.norm()); |
| 641 |
|
| 642 |
Vector3r posMax = LBbodies[id].pos + Vector3r(LBbodies[id].radius, LBbodies[id].radius, LBbodies[id].radius); |
| 643 |
Vector3r posMin = LBbodies[id].pos - Vector3r(LBbodies[id].radius, LBbodies[id].radius, LBbodies[id].radius); |
| 644 |
|
| 645 |
Vector3r dist = Vector3r::Zero(); |
| 646 |
for (int ii = int(math::round(posMin[0])) - 1; ii <= int(math::round(posMax[0])) + 1; ii++) |
| 647 |
for (int jj = int(math::round(posMin[1])) - 1; jj <= int(math::round(posMax[1])) + 1; jj++) { |
| 648 |
if ((ii == -1) || (ii == Nx) || (jj == -1) || (jj == Ny)) continue; |
| 649 |
if ((ii < -1) || (ii > Nx) || (jj < -1) || (jj > Ny)) continue; |
| 650 |
if (LBbodies[id].radius < Rmin) Rmin = LBbodies[id].radius; |
| 651 |
int nidx = ii + jj * Nx; |
| 652 |
dist = nodes[nidx].posb - LBbodies[id].pos; |
| 653 |
if (dist.norm() < LBbodies[id].radius) { |
| 654 |
nodes[nidx].body_id = id; |
| 655 |
nodes[nidx].setAsObstacle(); |
| 656 |
NbSolidNodes++; |
| 657 |
NbParticleNodes++; |
| 658 |
} |
| 659 |
if (firstRun) { nodes[nidx].wasObstacle = nodes[nidx].isObstacle; } |
| 660 |
} |
| 661 |
/*-------------------------------------------------------------------*/ |
| 662 |
/* ///NOTE : this should be removed since it can be done with python */ |
| 663 |
///Fck: pas en MODE 1 |
| 664 |
/*-------------------------------------------------------------------*/ |
| 665 |
//cerr <<"Check removing"<<endl; |
| 666 |
//if(removingCriterion!=0){ //ModLuc adding of b->isDynamic() to remove only dynamic particles and not already removed particles changed into non dynamic |
| 667 |
if ((removingCriterion != 0) && (b->isDynamic())) { |
| 668 |
switch (removingCriterion) { |
| 669 |
case 1: |
| 670 |
/* criterion with respect to the particle postion in x direction */ |
| 671 |
if (LBbodies[id].pos.x() > (invdx * (sWallXp->se3.position.x()) - 1.05 * MaxBodyRadius / RadFactor)) { |
| 672 |
IdOfNextErodedPtc.push_back(id); |
| 673 |
} |
| 674 |
break; |
| 675 |
case 2: |
| 676 |
/* criterion on particle velocity */ |
| 677 |
if ((LBbodies[id].vel.norm() > VelocityThreshold) |
| 678 |
|| (LBbodies[id].pos.x() > (invdx * (sWallXp->se3.position.x()) - 2. * LBbodies[id].radius))) { |
| 679 |
IdOfNextErodedPtc.push_back(id); |
| 680 |
} |
| 681 |
break; |
| 682 |
default: exit(-1); break; |
| 683 |
} |
| 684 |
} |
| 685 |
//NumberOfDynamicParticles++; //ModLuc: to still count only dynamic particles and not all particles |
| 686 |
if (b->isDynamic()) NumberOfDynamicParticles++; |
| 687 |
} |
| 688 |
|
| 689 |
LBbodies[id].force = Vector3r::Zero(); |
| 690 |
LBbodies[id].momentum = Vector3r::Zero(); |
| 691 |
} |
| 692 |
|
| 693 |
|
| 694 |
/*------------------------------------------------------------------*/ |
| 695 |
/*------------------ detection of boundary nodes -------------------*/ |
| 696 |
/*------------------------------------------------------------------*/ |
| 697 |
#ifdef YADE_OPENMP |
| 698 |
#pragma omp parallel for |
| 699 |
#endif |
| 700 |
for (int nidx = 0; nidx < Nx * Ny; nidx++) |
| 701 |
if (nodes[nidx].isObstacle) { |
| 702 |
for (unsigned int n = 0; n < nodes[nidx].neighbour_id.size(); n++) { |
| 703 |
if (nodes[nidx].neighbour_id[n] != -1) { |
| 704 |
int nidx2 = nodes[nidx].neighbour_id[n]; |
| 705 |
if (nodes[nidx].isObstacle != nodes[nidx2].isObstacle) { |
| 706 |
nodes[nidx].isObstacleBoundary = true; |
| 707 |
nodes[nidx2].isFluidBoundary = true; |
| 708 |
int BodyId = nodes[nidx].body_id; |
| 709 |
int lid = nodes[nidx].links_id[n]; |
| 710 |
links[lid].isBd = true; |
| 711 |
links[lid].sid = nidx; |
| 712 |
links[lid].fid = nidx2; |
| 713 |
links[lid].idx_sigma_i = opp[n]; |
| 714 |
if (LBbodies[BodyId].isPtc()) { |
| 715 |
links[lid].DistMid = nodes[nidx].posb - 0.5 * eib[links[lid].idx_sigma_i] - LBbodies[BodyId].pos; |
| 716 |
links[lid].VbMid = LBbodies[BodyId].vel + LBbodies[BodyId].AVel.cross(links[lid].DistMid); |
| 717 |
if (links[lid].VbMid.norm() < VbCutOff) links[lid].VbMid = Vector3r::Zero(); |
| 718 |
} |
| 719 |
if (LBbodies[BodyId].isBox()) { |
| 720 |
links[lid].DistMid = Vector3r::Zero(); |
| 721 |
links[lid].VbMid = Vector3r::Zero(); |
| 722 |
} |
| 723 |
} |
| 724 |
} |
| 725 |
} |
| 726 |
} |
| 727 |
#ifdef YADE_OPENMP |
| 728 |
#pragma omp parallel for |
| 729 |
#endif |
| 730 |
for (int nidx = 0; nidx < Nx * Ny; nidx++) |
| 731 |
if ((nodes[nidx].isObstacle) && (!nodes[nidx].isObstacleBoundary)) { |
| 732 |
nodes[nidx].setAsFluid(); |
| 733 |
NbSolidNodes--; |
| 734 |
if (firstRun) nodes[nidx].wasObstacle = nodes[nidx].isObstacle; |
| 735 |
} |
| 736 |
|
| 737 |
NbFluidNodes = NbNodes - NbSolidNodes; |
| 738 |
/*----------------------------------------------------------------------*/ |
| 739 |
|
| 740 |
if (firstRun) { |
| 741 |
/*------------------------------------------------------------------*/ |
| 742 |
/*------------------------------- MODE -----------------------------*/ |
| 743 |
/*------------------------------------------------------------------*/ |
| 744 |
if ((IterSubCyclingStart <= 0) && (IterMax > 1)) MODE = 1; |
| 745 |
if ((IterSubCyclingStart <= 0) && (IterMax == 1)) MODE = 2; |
| 746 |
if (IterSubCyclingStart > 0) MODE = 3; |
| 747 |
|
| 748 |
/*------------------------------------------------------------------*/ |
| 749 |
/*---------------------------- SUBCYCLING --------------------------*/ |
| 750 |
/*------------------------------------------------------------------*/ |
| 751 |
if (MODE == 3 && IterMax < IterSubCyclingStart) { |
| 752 |
cerr << "Exit because Itermax<IterSubCyclingStart" << endl; |
| 753 |
exit(-1); |
| 754 |
} |
| 755 |
if (DemIterLbmIterRatio == -1) { |
| 756 |
if (MODE == 1) DemIterLbmIterRatio = 1; |
| 757 |
else |
| 758 |
DemIterLbmIterRatio = int(dt / DEMdt0); |
| 759 |
newDEMdt = dt / DemIterLbmIterRatio; |
| 760 |
} else { |
| 761 |
newDEMdt = dt / DemIterLbmIterRatio; |
| 762 |
} |
| 763 |
scene->dt = newDEMdt; |
| 764 |
if (SaveMode == 2) { |
| 765 |
IterSave = int(math::round(TimeSave / (dt))); |
| 766 |
if (TimeSave < dt) { |
| 767 |
cerr << "Warning SaveMode==2 and TimeSave<dt." << endl; |
| 768 |
exit(-1); |
| 769 |
} |
| 770 |
} |
| 771 |
writelogfile(); |
| 772 |
|
| 773 |
/*------------------------------------------*/ |
| 774 |
/* Initialization of distribution functions */ |
| 775 |
/*------------------------------------------*/ |
| 776 |
for (int nidx = 0; nidx < Nx * Ny; nidx++) { |
| 777 |
nodes[nidx].rhob = 1.; |
| 778 |
nodes[nidx].velb = Vector3r::Zero(); |
| 779 |
for (int didx = 0; didx < NbDir; didx++) { |
| 780 |
cub = 3.0 * eib[didx].dot(nodes[nidx].velb); |
| 781 |
feqb = w[didx] * nodes[nidx].rhob |
| 782 |
* (1.0 + cub + 0.5 * (cub * cub) |
| 783 |
- 1.5 * ((nodes[nidx].velb.x() * nodes[nidx].velb.x()) + (nodes[nidx].velb.y() * nodes[nidx].velb.y()))); |
| 784 |
nodes[nidx].f.push_back(feqb); |
| 785 |
nodes[nidx].fpostcol.push_back(0.); |
| 786 |
nodes[nidx].fprecol.push_back(0.); |
| 787 |
} |
| 788 |
} |
| 789 |
firstRun = false; |
| 790 |
} |
| 791 |
|
| 792 |
/*----------------------------------------------------------------------*/ |
| 793 |
/* FOR ALL ITERATIONS */ |
| 794 |
/*----------------------------------------------------------------------*/ |
| 795 |
Real Error = 1.0; |
| 796 |
DEMdt = scene->dt; |
| 797 |
DEM_TIME = DEM_ITER * DEMdt; |
| 798 |
for (iter = 0; iter < IterMax; iter++) { |
| 799 |
step += 1; |
| 800 |
LBM_ITER++; |
| 801 |
LBM_TIME = LBM_ITER * dt; |
| 802 |
|
| 803 |
/*------------------------------------------------------------------*/ |
| 804 |
/* REINITIALIZATION RELATIVE TO THE MODE 1 */ |
| 805 |
/*------------------------------------------------------------------*/ |
| 806 |
if (MODE == 1) { |
| 807 |
for (const auto& b : *scene->bodies) { |
| 808 |
if (!b) continue; |
| 809 |
const int id = b->getId(); |
| 810 |
LBbodies[id].force = Vector3r::Zero(); |
| 811 |
LBbodies[id].momentum = Vector3r::Zero(); |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
/*------------------------------------------------------------------*/ |
| 816 |
/* GENERAL REINITIALIZATION */ |
| 817 |
/*------------------------------------------------------------------*/ |
| 818 |
// Vector3r WallBottomVel=Vector3r::Zero();//m s-1 |
| 819 |
FmoyCur = 0.; |
| 820 |
VmeanFluidC = 0.; |
| 821 |
VmaxC = -1000000.; |
| 822 |
VminC = 1000000.; |
| 823 |
RhomaxC = -1000000.; |
| 824 |
RhominC = 1000000.; |
| 825 |
RhoTot = 0.; |
| 826 |
/*------------------------------------------------------------------*/ |
| 827 |
/* Loop on nodes */ |
| 828 |
/*------------------------------------------------------------------*/ |
| 829 |
#ifdef YADE_OPENMP |
| 830 |
#pragma omp parallel for |
| 831 |
#endif |
| 832 |
for (int nidx = 0; nidx < Nx * Ny; nidx++) { |
| 833 |
if (nodes[nidx].checkIsNewObstacle()) { |
| 834 |
newObstacleCells_couter++; |
| 835 |
} else { |
| 836 |
if (nodes[nidx].checkIsNewFluid()) { newFluidCells_couter++; } |
| 837 |
} |
| 838 |
if (nodes[nidx].applyBC) { |
| 839 |
Vector3r U = Vector3r::Zero(); |
| 840 |
Real density = 0.; |
| 841 |
/*----------- inlet ------------*/ |
| 842 |
if (nodes[nidx].applyXmBC) { |
| 843 |
if (XmBCType == 1) { |
| 844 |
density = 1.0 + dP.x() / (Rho * cs * cs); |
| 845 |
U = Vector3r( |
| 846 |
1.0 |
| 847 |
- ((nodes[nidx].f[0] + nodes[nidx].f[2] + nodes[nidx].f[4]) |
| 848 |
+ 2.0 * (nodes[nidx].f[3] + nodes[nidx].f[6] + nodes[nidx].f[7])) |
| 849 |
/ density, |
| 850 |
0., |
| 851 |
0.); |
| 852 |
} else if (XmBCType == 2) { |
| 853 |
U = Vector3r::Zero(); |
| 854 |
density = (nodes[nidx].f[0] + nodes[nidx].f[2] + nodes[nidx].f[4] |
| 855 |
+ 2. * (nodes[nidx].f[3] + nodes[nidx].f[6] + nodes[nidx].f[7])) |
| 856 |
/ (1. - U.x()); |
| 857 |
} |
| 858 |
nodes[nidx].MixteBC(model, density, U, "Xm"); |
| 859 |
/*----------- outlet ------------*/ |
| 860 |
} else if (nodes[nidx].applyXpBC) { |
| 861 |
if (XpBCType == 1) { |
| 862 |
density = 1.0; |
| 863 |
U = Vector3r( |
| 864 |
-1.0 |
| 865 |
+ ((nodes[nidx].f[0] + nodes[nidx].f[2] + nodes[nidx].f[4]) |
| 866 |
+ 2.0 * (nodes[nidx].f[1] + nodes[nidx].f[5] + nodes[nidx].f[8])) |
| 867 |
/ density, |
| 868 |
0., |
| 869 |
0.); |
| 870 |
} else if (XpBCType == 2) { |
| 871 |
U = Vector3r::Zero(); |
| 872 |
density = (nodes[nidx].f[0] + nodes[nidx].f[2] + nodes[nidx].f[4] |
| 873 |
+ 2. * (nodes[nidx].f[1] + nodes[nidx].f[5] + nodes[nidx].f[8])) |
| 874 |
/ (1. + U.x()); |
| 875 |
} |
| 876 |
nodes[nidx].MixteBC(model, density, U, "Xp"); |
| 877 |
/*----------- top ------------*/ |
| 878 |
} else if (nodes[nidx].applyYpBC) { |
| 879 |
if (YpBCType == 1) { |
| 880 |
density = 1.0; |
| 881 |
U = Vector3r( |
| 882 |
0., |
| 883 |
-1.0 |
| 884 |
+ ((nodes[nidx].f[0] + nodes[nidx].f[1] + nodes[nidx].f[3]) |
| 885 |
+ 2.0 * (nodes[nidx].f[2] + nodes[nidx].f[5] + nodes[nidx].f[6])) |
| 886 |
/ density, |
| 887 |
0.); |
| 888 |
} else if (YpBCType == 2) { |
| 889 |
U = Vector3r::Zero(); |
| 890 |
density = (nodes[nidx].f[0] + nodes[nidx].f[1] + nodes[nidx].f[3] |
| 891 |
+ 2. * (nodes[nidx].f[2] + nodes[nidx].f[5] + nodes[nidx].f[6])) |
| 892 |
/ (1. + U.y()); |
| 893 |
} |
| 894 |
nodes[nidx].MixteBC(model, density, U, "Yp"); |
| 895 |
/*----------- bottom ------------*/ |
| 896 |
} else if (nodes[nidx].applyYmBC) { |
| 897 |
if (YmBCType == 1) { |
| 898 |
density = 1.0; |
| 899 |
U = Vector3r( |
| 900 |
0., |
| 901 |
1.0 |
| 902 |
- ((nodes[nidx].f[0] + nodes[nidx].f[1] + nodes[nidx].f[3]) |
| 903 |
+ 2.0 * (nodes[nidx].f[4] + nodes[nidx].f[7] + nodes[nidx].f[8])) |
| 904 |
/ density, |
| 905 |
0.); |
| 906 |
} else if (YmBCType == 2) { |
| 907 |
U = Vector3r::Zero(); |
| 908 |
density = (nodes[nidx].f[0] + nodes[nidx].f[1] + nodes[nidx].f[3] |
| 909 |
+ 2. * (nodes[nidx].f[4] + nodes[nidx].f[7] + nodes[nidx].f[8])) |
| 910 |
/ (1. - U.y()); |
| 911 |
} |
| 912 |
nodes[nidx].MixteBC(model, density, U, "Ym"); |
| 913 |
/*----------- bottom-left ------------*/ |
| 914 |
} else if (nodes[nidx].applyYmXmBC) { |
| 915 |
if (XmYmZpBCType == 1) { |
| 916 |
cerr << "XmYmZpType=1 not implemented . Exit" << endl; |
| 917 |
exit(-1); |
| 918 |
} else if (XmYmZpBCType == 2) { |
| 919 |
U = Vector3r::Zero(); |
| 920 |
density = nodes[nidx + 1].rhob; |
| 921 |
} |
| 922 |
nodes[nidx].MixteBC(model, density, U, "XmYmZp"); |
| 923 |
/*----------- top-left ------------*/ |
| 924 |
} else if (nodes[nidx].applyYpXmBC) { |
| 925 |
if (XmYpZpBCType == 1) { |
| 926 |
cerr << "XmYpZpBCType=1 not implemented . Exit" << endl; |
| 927 |
exit(-1); |
| 928 |
} else if (XmYpZpBCType == 2) { |
| 929 |
U = Vector3r::Zero(); |
| 930 |
density = nodes[nidx + 1].rhob; |
| 931 |
} |
| 932 |
nodes[nidx].MixteBC(model, density, U, "XmYpZp"); |
| 933 |
/*----------- bottom-right ------------*/ |
| 934 |
} else if (nodes[nidx].applyYmXpBC) { |
| 935 |
if (XpYmZpBCType == 1) { |
| 936 |
cerr << "XpYmZpBCType=1 not implemented . Exit" << endl; |
| 937 |
exit(-1); |
| 938 |
} else if (XpYmZpBCType == 2) { |
| 939 |
U = Vector3r::Zero(); |
| 940 |
density = nodes[nidx - 1].rhob; |
| 941 |
} |
| 942 |
nodes[nidx].MixteBC(model, density, U, "XpYmZp"); |
| 943 |
/*----------- top-right ------------*/ |
| 944 |
} else if (nodes[nidx].applyYpXpBC) { |
| 945 |
if (XpYpZpBCType == 1) { |
| 946 |
cerr << "XpYpZpBCType=1 not implemented . Exit" << endl; |
| 947 |
exit(-1); |
| 948 |
} else if (XpYpZpBCType == 2) { |
| 949 |
U = Vector3r::Zero(); |
| 950 |
density = nodes[nidx - 1].rhob; |
| 951 |
} |
| 952 |
nodes[nidx].MixteBC(model, density, U, "XpYpZp"); |
| 953 |
} else { |
| 954 |
cerr << "ERROR: node " << nidx << ". Looking for a BC to apply ..." << endl; |
| 955 |
exit(-1); |
| 956 |
} |
| 957 |
} |
| 958 |
|
| 959 |
nodes[nidx].rhob = 0.; |
| 960 |
nodes[nidx].velb = Vector3r::Zero(); |
| 961 |
nodes[nidx].IsolNb = 0; |
| 962 |
if (nodes[nidx].isFluidBoundary) { nodes[nidx].IsolNb = 8; } |
| 963 |
|
| 964 |
for (int dndx = 0; dndx < NbDir; dndx++) { |
| 965 |
nodes[nidx].fprecol[dndx] = nodes[nidx].f[dndx]; |
| 966 |
nodes[nidx].velb += eib[dndx] * nodes[nidx].f[dndx]; |
| 967 |
nodes[nidx].rhob += nodes[nidx].f[dndx]; |
| 968 |
if ((nodes[nidx].isFluidBoundary) && (nodes[nidx].neighbour_id[dndx] != -1)) { |
| 969 |
int ns = nodes[nidx].neighbour_id[dndx]; |
| 970 |
if (!nodes[ns].isObstacle) nodes[nidx].IsolNb = nodes[nidx].IsolNb - 1; |
| 971 |
if (nodes[nidx].IsolNb < 0) { |
| 972 |
cerr << "isolNb<0" << endl; |
| 973 |
exit(-1); |
| 974 |
} |
| 975 |
} |
| 976 |
} |
| 977 |
nodes[nidx].velb /= nodes[nidx].rhob; |
| 978 |
|
| 979 |
Real temp0 = 1.5 * ((nodes[nidx].velb.x() * nodes[nidx].velb.x()) + (nodes[nidx].velb.y() * nodes[nidx].velb.y())); |
| 980 |
Real cub0 = 3.0 * eib[0].dot(nodes[nidx].velb); |
| 981 |
nodes[nidx].fpostcol[0] |
| 982 |
= nodes[nidx].f[0] - omega * (nodes[nidx].f[0] - (nodes[nidx].rhob * w[0] * (1. + cub0 + 0.5 * (cub0 * cub0) - temp0))); |
| 983 |
|
| 984 |
|
| 985 |
nodes[nidx].fpostcol[0] = nodes[nidx].fpostcol[0] + (nodes[nidx].rhob * w[0]) / c2 * eib[0].dot(CstBodyForce); |
| 986 |
nodes[nidx].f[0] = nodes[nidx].fpostcol[0]; |
| 987 |
RhoTot += nodes[nidx].rhob; |
| 988 |
if (nodes[nidx].body_id == -1) |
| 989 |
if (VmaxC < c * nodes[nidx].velb.norm()) VmaxC = c * nodes[nidx].velb.norm(); |
| 990 |
if (VminC > c * nodes[nidx].velb.norm()) VminC = c * nodes[nidx].velb.norm(); |
| 991 |
if (RhomaxC < Rho * nodes[nidx].rhob) RhomaxC = Rho * nodes[nidx].rhob; |
| 992 |
if (RhominC > Rho * nodes[nidx].rhob) RhominC = Rho * nodes[nidx].rhob; |
| 993 |
if (!nodes[nidx].isObstacle) VmeanFluidC += c * nodes[nidx].velb.norm(); |
| 994 |
} |
| 995 |
|
| 996 |
#ifdef YADE_OPENMP |
| 997 |
#pragma omp parallel for |
| 998 |
#endif |
| 999 |
for (unsigned int lid = 0; lid < links.size(); lid++) { |
| 1000 |
int nidx1 = links[lid].nid1; |
| 1001 |
int nidx2 = links[lid].nid2; |
| 1002 |
int dndx1 = links[lid].i; |
| 1003 |
int dndx2 = opp[links[lid].i]; |
| 1004 |
|
| 1005 |
/*-------------------------------------------------- ---------------*/ |
| 1006 |
/* equilibrium functions and collisions */ |
| 1007 |
/*------------------------------------------------------------------*/ |
| 1008 |
Real temp1 = 1.5 * ((nodes[nidx1].velb.x() * nodes[nidx1].velb.x()) + (nodes[nidx1].velb.y() * nodes[nidx1].velb.y())); |
| 1009 |
Real cub1 = 3.0 * eib[dndx1].dot(nodes[nidx1].velb); |
| 1010 |
nodes[nidx1].fpostcol[dndx1] = nodes[nidx1].fprecol[dndx1] |
| 1011 |
- omega * (nodes[nidx1].fprecol[dndx1] - (nodes[nidx1].rhob * w[dndx1] * (1. + cub1 + 0.5 * (cub1 * cub1) - temp1))); |
| 1012 |
nodes[nidx1].fpostcol[dndx1] = nodes[nidx1].fpostcol[dndx1] + (nodes[nidx1].rhob * w[dndx1]) / c2 * eib[dndx1].dot(CstBodyForce); |
| 1013 |
if (!links[lid].PointingOutside) { |
| 1014 |
Real temp2 = 1.5 * ((nodes[nidx2].velb.x() * nodes[nidx2].velb.x()) + (nodes[nidx2].velb.y() * nodes[nidx2].velb.y())); |
| 1015 |
Real cub2 = 3.0 * eib[dndx2].dot(nodes[nidx2].velb); |
| 1016 |
nodes[nidx2].fpostcol[dndx2] = nodes[nidx2].fprecol[dndx2] |
| 1017 |
- omega * (nodes[nidx2].fprecol[dndx2] - (nodes[nidx2].rhob * w[dndx2] * (1. + cub2 + 0.5 * (cub2 * cub2) - temp2))); |
| 1018 |
nodes[nidx2].fpostcol[dndx2] |
| 1019 |
= nodes[nidx2].fpostcol[dndx2] + (nodes[nidx2].rhob * w[dndx2]) / c2 * eib[dndx2].dot(CstBodyForce); |
| 1020 |
} |
| 1021 |
|
| 1022 |
/*-------------------------------------------------- ---------------*/ |
| 1023 |
/* Streaming */ |
| 1024 |
/*------------------------------------------------------------------*/ |
| 1025 |
if (links[lid].PointingOutside) { |
| 1026 |
/// Periodicity is currently disabled until it is implemented through the link list. |
| 1027 |
///FIXME |
| 1028 |
I = nodes[nidx1].i |
| 1029 |
+ int(math::round( |
| 1030 |
eib[dndx1] |
| 1031 |
.x())); // XXX: this is suspicious. Anyway, you have to select the int(…) conversion policy: math::floor, math::ceil, math::round |
| 1032 |
J = nodes[nidx1].j |
| 1033 |
+ int(math::round( |
| 1034 |
eib[dndx1] |
| 1035 |
.y())); // It is quite frequent that you can have e.g. 11.99999999993 and it should be int==12. But it becomes 11. |
| 1036 |
if (Xperiodicity) { |
| 1037 |
if (I == Nx) { |
| 1038 |
I = 0; |
| 1039 |
} else { |
| 1040 |
if (I == -1) { I = Nx - 1; } |
| 1041 |
} |
| 1042 |
} |
| 1043 |
if (Yperiodicity) { |
| 1044 |
if (J == Ny) { |
| 1045 |
J = 0; |
| 1046 |
} else { |
| 1047 |
if (J == -1) { J = Ny - 1; } |
| 1048 |
} |
| 1049 |
} |
| 1050 |
} else { |
| 1051 |
nodes[nidx1].f[dndx2] = nodes[nidx2].fpostcol[dndx2]; |
| 1052 |
nodes[nidx2].f[dndx1] = nodes[nidx1].fpostcol[dndx1]; |
| 1053 |
} |
| 1054 |
|
| 1055 |
if (links[lid].isBd == false) continue; |
| 1056 |
|
| 1057 |
int idx_sigma_i = links[lid].idx_sigma_i; |
| 1058 |
int sid = links[lid].sid; |
| 1059 |
int fid = links[lid].fid; |
| 1060 |
int BodyId = nodes[sid].body_id; |
| 1061 |
|
| 1062 |
|
| 1063 |
/*--- forces and momenta for this boundary link ---*/ |
| 1064 |
links[lid].ct = 3.0 * w[idx_sigma_i] * nodes[sid].rhob * eib[links[lid].idx_sigma_i].dot(links[lid].VbMid); |
| 1065 |
Vector3r force_ij = eib[links[lid].idx_sigma_i] * (nodes[fid].fpostcol[idx_sigma_i] - links[lid].ct); |
| 1066 |
Vector3r lubforce_ij = Vector3r::Zero(); |
| 1067 |
Vector3r totalforce_ij = force_ij + lubforce_ij; |
| 1068 |
Vector3r totalmomentum_ij = links[lid].DistMid.cross(totalforce_ij); |
| 1069 |
|
| 1070 |
/* Sum over all boundary links of all boundary nodes */ |
| 1071 |
LBbodies[BodyId].force = LBbodies[BodyId].force + totalforce_ij; |
| 1072 |
LBbodies[BodyId].momentum = LBbodies[BodyId].momentum + totalmomentum_ij; |
| 1073 |
|
| 1074 |
/*------------------------------------------------------*/ |
| 1075 |
/* Modified Bounce back rule */ |
| 1076 |
if (nodes[fid].IsolNb >= 5) { |
| 1077 |
links[lid].VbMid = Vector3r::Zero(); |
| 1078 |
links[lid].ct = 0.; |
| 1079 |
} |
| 1080 |
nodes[fid].f[opp[idx_sigma_i]] = nodes[fid].fpostcol[idx_sigma_i] - 2.0 * links[lid].ct; |
| 1081 |
nodes[sid].f[idx_sigma_i] = nodes[sid].fpostcol[opp[idx_sigma_i]] + 2.0 * links[lid].ct; |
| 1082 |
if ((MODE == 2) || ((MODE == 3) && (IterMax == 1))) { links[lid].ReinitDynamicalProperties(); } |
| 1083 |
} |
| 1084 |
VmeanFluidC = VmeanFluidC / NbFluidNodes; |
| 1085 |
|
| 1086 |
|
| 1087 |
/*---------------------------------------------*/ |
| 1088 |
/* Stop criteria */ |
| 1089 |
/*---------------------------------------------*/ |
| 1090 |
// if(use_ConvergenceCriterion){ |
| 1091 |
// switch(ErrorCriterion){ |
| 1092 |
// case 1: |
| 1093 |
// /*--------------------------------------------------------*/ |
| 1094 |
// /* Criterion based on the mean force */ |
| 1095 |
// /*--------------------------------------------------------*/ |
| 1096 |
// if((LBM_ITER > 1000) & (LBM_ITER % 10 == 0)){ |
| 1097 |
// for (int s=NB_WALLS ; s<NB_BODIES; s++) {FmoyCur = FmoyCur + LBbodies[s].force.norm();} |
| 1098 |
// FmoyCur = FmoyCur/(NB_DYNGRAINS); |
| 1099 |
// if (FmoyCur!=0.){ |
| 1100 |
// Real ErrorA = math::abs(FmoyCur-FmoyPrev)/math::abs(FmoyCur); |
| 1101 |
// Real ErrorB = math::abs(FmoyCur-FmoyPrevPrev)/math::abs(FmoyCur); |
| 1102 |
// Error=max(ErrorA,ErrorB); |
| 1103 |
// FmoyPrevPrev=FmoyPrev; |
| 1104 |
// FmoyPrev=FmoyCur; |
| 1105 |
// } |
| 1106 |
// } |
| 1107 |
// break; |
| 1108 |
// case 2: |
| 1109 |
// /*--------------------------------------------------------*/ |
| 1110 |
// /* Criterion based on the mean velocity */ |
| 1111 |
// /*--------------------------------------------------------*/ |
| 1112 |
// if((LBM_ITER > 100) & (LBM_ITER % 10 == 0)){ |
| 1113 |
// if (VmeanFluidC!=0.){ |
| 1114 |
// Real ErrorA = math::abs(VmeanFluidC-PrevVmeanFluidC)/math::abs(VmeanFluidC); |
| 1115 |
// //Real ErrorB = math::abs(VmeanFluidC-PrevPrevVmeanFluidC)/math::abs(VmeanFluidC); |
| 1116 |
// //Error=max(ErrorA,ErrorB); |
| 1117 |
// Error= ErrorA; |
| 1118 |
// PrevPrevVmeanFluidC=PrevVmeanFluidC; |
| 1119 |
// PrevVmeanFluidC=VmeanFluidC; |
| 1120 |
// } |
| 1121 |
// } |
| 1122 |
// break; |
| 1123 |
// default: |
| 1124 |
// cerr <<"Unknow ErrorCriterion value ! "<<endl; |
| 1125 |
// exit(-1); |
| 1126 |
// break; |
| 1127 |
// } |
| 1128 |
// } |
| 1129 |
|
| 1130 |
if (LBM_ITER % IterPrint == 0) { |
| 1131 |
cerr.precision(6); |
| 1132 |
cerr << "__________________________________________________________________________" << endl; |
| 1133 |
cerr << "| Run in mode : " << MODE << endl; |
| 1134 |
cerr << "| New Obstacle nodes: " << newObstacleCells_couter << " New Fluid nodes: " << newFluidCells_couter << endl; |
| 1135 |
cout << "| height/width/depth (m) " << height << " / " << width << " / " << depth << endl; |
| 1136 |
cerr << "|------------------------------------------------------------------------|" << endl; |
| 1137 |
cerr << "| \t\tDEM\t\t | \t\tLBM\t\t |" << endl; |
| 1138 |
cerr << "|------------------------------------------------------------------------|" << endl; |
| 1139 |
cerr << "| t (s)\t: " << DEM_TIME << "\t\t | t (s)\t\t: " << LBM_TIME << "\t\t " << endl; |
| 1140 |
cerr << "| Iter\t\t: " << DEM_ITER << "\t\t | Iter\t\t: " << LBM_ITER << "\t\t " << endl; |
| 1141 |
cerr << "| Nb dyn ptc\t: " << NumberOfDynamicParticles << "\t\t | M\t\t: " << VmaxC / c << "\t " << endl; |
| 1142 |
cerr << "| \t\t\t\t | " << VminC << "\t< <V(t)> (m/s)= " << VmeanFluidC << "\t< " << VmaxC << "\t " << endl; |
| 1143 |
cerr << "| \t\t\t\t | " << RhominC << "\t< rho(t) (m3/kg) <" << RhomaxC << "\t " << endl; |
| 1144 |
cerr << "| \t\t\t\t | RhoTot (adim) \t: " << RhoTot << "\t " << endl; |
| 1145 |
if (ObservedPtc != -1) { |
| 1146 |
Vector3r tmp = 2. * Rho * c2 * dx * LBbodies[ObservedPtc].force; |
| 1147 |
cerr << "| \t\t\t\t\t | F (N) \t: " << tmp << "\t " << endl; |
| 1148 |
tmp = LBbodies[ObservedPtc].pos * dx; |
| 1149 |
cerr << "| \t\t\t\t\t | pos (m) \t: " << tmp << "\t " << endl; |
| 1150 |
tmp = LBbodies[ObservedPtc].vel * c; |
| 1151 |
cerr << "| \t\t\t\t\t | VPtc (m/s)\t: " << tmp << "\t \t\t\t\t " << endl; |
| 1152 |
} |
| 1153 |
if (((MODE == 2) || (MODE == 3)) && (NB_DYNGRAINS > 0)) { |
| 1154 |
cerr << "| VminPtcC (m/s)\t: " << CurMinVelOfPtc << "\t |\t\t\t\t " << endl; |
| 1155 |
cerr << "| VmaxPtcC (m/s)\t: " << CurMaxVelOfPtc << "\t |\t\t\t\t " << endl; |
| 1156 |
} |
| 1157 |
if (((MODE == 1) && firstRun) || (MODE == 2) || (MODE == 3)) { |
| 1158 |
cerr << "| \t\t\t\t\t | NbNodes\t: " << NbNodes << "\t " << endl; |
| 1159 |
cerr << "| \t\t\t\t\t | Fluid nodes\t: " << NbFluidNodes << "\t\t " << endl; |
| 1160 |
cerr << "| \t\t\t\t\t | Solid nodes\t: " << NbSolidNodes << "\t\t " << endl; |
| 1161 |
} |
| 1162 |
if (ObservedNode != -1) { |
| 1163 |
cerr << "| \t\t\t\t\t | Track node\t: " << ObservedNode << "\t\t " << endl; |
| 1164 |
cerr << "| \t\t\t\t\t | \t V(m/s)\t: " << nodes[ObservedNode].velb.norm() << "\t\t " << endl; |
| 1165 |
cerr << "| \t\t\t\t\t | \t rho\t: " << Rho * nodes[ObservedNode].rhob << "\t\t " << endl; |
| 1166 |
} |
| 1167 |
if (use_ConvergenceCriterion) { |
| 1168 |
cerr << "| \t\t\t\t\t | Error\t: " << Error << "\t\t " << endl; |
| 1169 |
cerr << "| \t\t\t\t\t | with criterion " << ErrorCriterion << " \t\t " << endl; |
| 1170 |
} |
| 1171 |
cerr << "|------------------------------------------------------------------------|" << endl; |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
/*-------------------------------------------------------------------------------*/ |
| 1176 |
/*------------- RESULT RECORDING DURING COMPUTATION (MODE 1)--------------------*/ |
| 1177 |
/*-------------------------------------------------------------------------------*/ |
| 1178 |
if (((iter % (IterSave * DemIterLbmIterRatio) == 0) || (firstRun)) && MODE == 1) { |
| 1179 |
if (((iter % (IterSave * SaveGridRatio * DemIterLbmIterRatio) == 0) || (firstRun)) && MODE == 1) save(iter, dt); |
| 1180 |
saveStats(iter, dt); |
| 1181 |
if (SAVE_OBSERVEDPTC) { |
| 1182 |
CalculateAndApplyForcesAndTorquesOnBodies(true, false); |
| 1183 |
saveObservedPtc(iter, dt); |
| 1184 |
} |
| 1185 |
if (SAVE_OBSERVEDNODE) saveObservedNode(iter, dt); |
| 1186 |
} |
| 1187 |
|
| 1188 |
|
| 1189 |
if ((IterSubCyclingStart > 0) && (iter + 1 >= IterSubCyclingStart)) { modeTransition(); } |
| 1190 |
if ((Error < ConvergenceThreshold) && (use_ConvergenceCriterion)) { |
| 1191 |
if (MODE == 1) break; |
| 1192 |
if (MODE == 3) modeTransition(); |
| 1193 |
} |
| 1194 |
if ((EndTime > 0) && (LBM_TIME > EndTime)) LbmEnd(); |
| 1195 |
//if((InitialNumberOfDynamicParticles!=0)&&(NumberPtcEroded==InitialNumberOfDynamicParticles)) LbmEnd(); |
| 1196 |
} |
| 1197 |
/*------------------- End of the LBM loop (iterations) --------------------*/ |
| 1198 |
|
| 1199 |
|
| 1200 |
if (MODE == 1) { |
| 1201 |
cerr << "LBM ended after " << step << " iterations"; |
| 1202 |
cerr << " | LBM_ITER = " << LBM_ITER << " | Error = " << Error << endl; |
| 1203 |
} |
| 1204 |
|
| 1205 |
/*--------------------------------------------------------------------------------*/ |
| 1206 |
/*-------------- APPLICATION OF HYDRODYNAMIC FORCES ON SPHERES -------------------*/ |
| 1207 |
/*--------------------------------------------------------------------------------*/ |
| 1208 |
if (applyForcesAndTorques) CalculateAndApplyForcesAndTorquesOnBodies(true, true); |
| 1209 |
|
| 1210 |
/*----------------------------------------------------------------------------*/ |
| 1211 |
/*----------------- SPHERES ARE MOVED OUTSIDE THE SIMULATION DOMAIN --------- */ |
| 1212 |
/*----------------------------------------------------------------------------*/ |
| 1213 |
//if(removingCriterion!=0){ |
| 1214 |
// for(unsigned int aa=0; aa<IdOfNextErodedPtc.size();aa++){ |
| 1215 |
// int IdRemoved=IdOfNextErodedPtc[aa]; |
| 1216 |
// LBbodies[IdRemoved].isEroded=true; |
| 1217 |
// shared_ptr<Body> b=Body::byId(IdRemoved); |
| 1218 |
// const shared_ptr<Sphere>& sphere = YADE_PTR_CAST<Sphere> ( b->shape ); |
| 1219 |
// Real r=sphere->radius; |
| 1220 |
// outside_limit=outside_limit+1.1*r; |
| 1221 |
// b->state->pos=Vector3r(outside_limit,0.,0.); |
| 1222 |
// b->setDynamic(false); |
| 1223 |
// NB_DYNGRAINS--; |
| 1224 |
// NB_DYNBODIES--; |
| 1225 |
// outside_limit=outside_limit+1.1*r; |
| 1226 |
// cerr <<"Eroded Ptc: "<<IdRemoved<<endl; |
| 1227 |
// NumberPtcEroded+=1; |
| 1228 |
// if(!strcmp(model.c_str(), "d2q9" )) Vr += Mathr::PI*(r*r); |
| 1229 |
// else Vr += 4./3.*Mathr::PI*(r*r*r); |
| 1230 |
// } |
| 1231 |
// if(IdOfNextErodedPtc.size()!=0) saveEroded(DEM_ITER,DEMdt); |
| 1232 |
//} |
| 1233 |
|
| 1234 |
/*----------------------------------------------------------------------------*/ |
| 1235 |
/*------------- RESULT RECORDING AT THE END OF THE COMPUTATION ---------------*/ |
| 1236 |
/*----------------------------------------------------------------------------*/ |
| 1237 |
if (((DEM_ITER % (IterSave * DemIterLbmIterRatio) == 0) || (firstRun)) && IterMax == 1) { |
| 1238 |
if (((DEM_ITER % (IterSave * SaveGridRatio * DemIterLbmIterRatio) == 0) || (firstRun)) && IterMax == 1) save(DEM_ITER, DEMdt); |
| 1239 |
saveStats(DEM_ITER, DEMdt); |
| 1240 |
//saveEroded(DEM_ITER,DEMdt); |
| 1241 |
if (SAVE_OBSERVEDPTC) saveObservedPtc(DEM_ITER, DEMdt); |
| 1242 |
if (SAVE_OBSERVEDNODE) saveObservedNode(DEM_ITER, DEMdt); |
| 1243 |
} |
| 1244 |
} |
| 1245 |
|
| 1246 |
void HydrodynamicsLawLBM::save(int iter_number, Real /*timestep*/) |
| 1247 |
{ |
| 1248 |
/*--------------------------------------------*/ |
| 1249 |
/* Recording of properties of LBM nodes */ |
| 1250 |
/*--------------------------------------------*/ |
| 1251 |
|
| 1252 |
bool saveLBMdata = false; // Flag to avoid to loop over all the lbm node if no lbm data are saved but only spheres data |
| 1253 |
|
| 1254 |
std::stringstream Vfile_name; |
| 1255 |
std::stringstream Vxfile_name; |
| 1256 |
std::stringstream Vyfile_name; |
| 1257 |
std::ofstream Vfile; |
| 1258 |
std::ofstream Vxfile; |
| 1259 |
std::ofstream Vyfile; |
| 1260 |
|
| 1261 |
std::stringstream FxLBMfile_name; |
| 1262 |
std::stringstream FyLBMfile_name; |
| 1263 |
std::stringstream MzLBMfile_name; |
| 1264 |
std::ofstream FxLBMfile; |
| 1265 |
std::ofstream FyLBMfile; |
| 1266 |
std::ofstream MzLBMfile; |
| 1267 |
|
| 1268 |
std::stringstream Rhofile_name; |
| 1269 |
std::ofstream Rhofile; |
| 1270 |
|
| 1271 |
std::stringstream Bodiesfile_name; |
| 1272 |
std::ofstream Bodiesfile; |
| 1273 |
|
| 1274 |
std::stringstream NodeBoundaryfile_name; |
| 1275 |
std::ofstream NodeBoundaryfile; |
| 1276 |
|
| 1277 |
std::stringstream NewNodefile_name; |
| 1278 |
std::ofstream NewNodefile; |
| 1279 |
|
| 1280 |
|
| 1281 |
/*--- VELOCITIES ---*/ |
| 1282 |
if (SAVE_VELOCITY) { |
| 1283 |
Vfile_name << lbm_dir << "/V" |
| 1284 |
<< "_"; |
| 1285 |
Vfile_name.width(10); |
| 1286 |
Vfile_name.fill('0'); |
| 1287 |
Vfile_name << iter_number; |
| 1288 |
Vfile.open(Vfile_name.str().c_str()); |
| 1289 |
|
| 1290 |
saveLBMdata = true; |
| 1291 |
} |
| 1292 |
|
| 1293 |
if (SAVE_VELOCITYCOMP) { |
| 1294 |
Vxfile_name << lbm_dir << "/Vx" |
| 1295 |
<< "_"; |
| 1296 |
Vxfile_name.width(10); |
| 1297 |
Vyfile_name << lbm_dir << "/Vy" |
| 1298 |
<< "_"; |
| 1299 |
Vyfile_name.width(10); |
| 1300 |
|
| 1301 |
Vxfile_name.fill('0'); |
| 1302 |
Vxfile_name << iter_number; |
| 1303 |
Vyfile_name.fill('0'); |
| 1304 |
Vyfile_name << iter_number; |
| 1305 |
|
| 1306 |
Vxfile.open(Vxfile_name.str().c_str()); |
| 1307 |
Vyfile.open(Vyfile_name.str().c_str()); |
| 1308 |
|
| 1309 |
saveLBMdata = true; |
| 1310 |
} |
| 1311 |
|
| 1312 |
/*--- FORCES ---*/ |
| 1313 |
if (SAVE_FORCES) { |
| 1314 |
FxLBMfile_name << lbm_dir << "/Fx" |
| 1315 |
<< "_"; |
| 1316 |
FxLBMfile_name.width(10); |
| 1317 |
FyLBMfile_name << lbm_dir << "/Fy" |
| 1318 |
<< "_"; |
| 1319 |
FyLBMfile_name.width(10); |
| 1320 |
MzLBMfile_name << lbm_dir << "/Mz" |
| 1321 |
<< "_"; |
| 1322 |
MzLBMfile_name.width(10); |
| 1323 |
|
| 1324 |
FxLBMfile_name.fill('0'); |
| 1325 |
FxLBMfile_name << iter_number; |
| 1326 |
FyLBMfile_name.fill('0'); |
| 1327 |
FyLBMfile_name << iter_number; |
| 1328 |
MzLBMfile_name.fill('0'); |
| 1329 |
MzLBMfile_name << iter_number; |
| 1330 |
|
| 1331 |
FxLBMfile.open(FxLBMfile_name.str().c_str()); |
| 1332 |
FyLBMfile.open(FyLBMfile_name.str().c_str()); |
| 1333 |
MzLBMfile.open(MzLBMfile_name.str().c_str()); |
| 1334 |
|
| 1335 |
saveLBMdata = true; |
| 1336 |
} |
| 1337 |
|
| 1338 |
/*--- DENSITY ---*/ |
| 1339 |
if (SAVE_RHO) { |
| 1340 |
Rhofile_name << lbm_dir << "/Rho" |
| 1341 |
<< "_"; |
| 1342 |
Rhofile_name.width(10); |
| 1343 |
Rhofile_name.fill('0'); |
| 1344 |
Rhofile_name << iter_number; |
| 1345 |
Rhofile.open(Rhofile_name.str().c_str()); |
| 1346 |
|
| 1347 |
saveLBMdata = true; |
| 1348 |
} |
| 1349 |
|
| 1350 |
/*--- BODIES ---*/ |
| 1351 |
if (SAVE_BODIES) { |
| 1352 |
Bodiesfile_name << lbm_dir << "/Bodies" |
| 1353 |
<< "_"; |
| 1354 |
Bodiesfile_name.width(10); |
| 1355 |
Bodiesfile_name.fill('0'); |
| 1356 |
Bodiesfile_name << iter_number; |
| 1357 |
Bodiesfile.open(Bodiesfile_name.str().c_str()); |
| 1358 |
|
| 1359 |
saveLBMdata = true; |
| 1360 |
} |
| 1361 |
|
| 1362 |
/*--- BOUNDARY NODES ---*/ |
| 1363 |
if (SAVE_NODEBD) { |
| 1364 |
NodeBoundaryfile_name << lbm_dir << "/NodeBoundary" |
| 1365 |
<< "_"; |
| 1366 |
NodeBoundaryfile_name.width(10); |
| 1367 |
NodeBoundaryfile_name.fill('0'); |
| 1368 |
NodeBoundaryfile_name << iter_number; |
| 1369 |
NodeBoundaryfile.open(NodeBoundaryfile_name.str().c_str()); |
| 1370 |
|
| 1371 |
saveLBMdata = true; |
| 1372 |
} |
| 1373 |
|
| 1374 |
/*--- NEW NODES ---*/ |
| 1375 |
if (SAVE_NODEISNEW) { |
| 1376 |
NewNodefile_name << lbm_dir << "/NewNode" |
| 1377 |
<< "_"; |
| 1378 |
NewNodefile_name.width(10); |
| 1379 |
NewNodefile_name.fill('0'); |
| 1380 |
NewNodefile_name << iter_number; |
| 1381 |
NewNodefile.open(NewNodefile_name.str().c_str()); |
| 1382 |
|
| 1383 |
saveLBMdata = true; |
| 1384 |
} |
| 1385 |
|
| 1386 |
|
| 1387 |
if (saveLBMdata) { //Condition to avoid to loop over all the lbm node if no lbm data are saved but only spheres data |
| 1388 |
|
| 1389 |
cerr << "| Saving (" << iter_number << ")" << endl; |
| 1390 |
|
| 1391 |
for (int nidx = 0; nidx < Nx * Ny; nidx++) { |
| 1392 |
if (SAVE_BODIES) Bodiesfile << nodes[nidx].body_id << " "; |
| 1393 |
if (SAVE_VELOCITY) Vfile << c * nodes[nidx].velb.norm() << " "; |
| 1394 |
if (SAVE_VELOCITYCOMP) { |
| 1395 |
Vxfile << c * nodes[nidx].velb.x() << " "; |
| 1396 |
Vyfile << c * nodes[nidx].velb.y() << " "; |
| 1397 |
} |
| 1398 |
if (SAVE_FORCES) { |
| 1399 |
if (nodes[nidx].body_id >= 0) { |
| 1400 |
FxLBMfile << 2. * Rho * c2 * dx * (LBbodies[nodes[nidx].body_id].force.x()) << " "; |
| 1401 |
FyLBMfile << 2. * Rho * c2 * dx * (LBbodies[nodes[nidx].body_id].force.y()) << " "; |
| 1402 |
MzLBMfile << 2. * Rho * c2 * dx2 * LBbodies[nodes[nidx].body_id].momentum.z() << " "; |
| 1403 |
} else { |
| 1404 |
FxLBMfile << 0. << " "; |
| 1405 |
FyLBMfile << 0. << " "; |
| 1406 |
MzLBMfile << 0. << " "; |
| 1407 |
} |
| 1408 |
} |
| 1409 |
if (SAVE_RHO) Rhofile << Rho * nodes[nidx].rhob << " "; |
| 1410 |
if (SAVE_NODEBD) { |
| 1411 |
int tmp = 0; |
| 1412 |
if (nodes[nidx].isObstacleBoundary) tmp = nodes[nidx].isObstacleBoundary; |
| 1413 |
if (nodes[nidx].isFluidBoundary) tmp = -1; |
| 1414 |
NodeBoundaryfile << tmp << " "; |
| 1415 |
} |
| 1416 |
if (SAVE_NODEISNEW) { |
| 1417 |
int tmp = 0; |
| 1418 |
if (nodes[nidx].isNewObstacle) tmp = nodes[nidx].isNewObstacle; |
| 1419 |
if (nodes[nidx].isNewFluid) tmp = -1; |
| 1420 |
NewNodefile << tmp << " "; |
| 1421 |
} |
| 1422 |
|
| 1423 |
if (nodes[nidx].i == Nx - 1) { |
| 1424 |
if (SAVE_BODIES) Bodiesfile << endl; |
| 1425 |
if (SAVE_VELOCITY) Vfile << endl; |
| 1426 |
if (SAVE_VELOCITYCOMP) { |
| 1427 |
Vxfile << endl; |
| 1428 |
Vyfile << endl; |
| 1429 |
} |
| 1430 |
if (SAVE_FORCES) { |
| 1431 |
FxLBMfile << endl; |
| 1432 |
FyLBMfile << endl; |
| 1433 |
MzLBMfile << endl; |
| 1434 |
} |
| 1435 |
if (SAVE_RHO) Rhofile << endl; |
| 1436 |
if (SAVE_NODEBD) NodeBoundaryfile << endl; |
| 1437 |
if (SAVE_NODEISNEW) NewNodefile << endl; |
| 1438 |
} |
| 1439 |
} |
| 1440 |
} |
| 1441 |
|
| 1442 |
std::stringstream cmd; |
| 1443 |
cmd << "bzip2"; |
| 1444 |
if (SAVE_BODIES) { |
| 1445 |
Bodiesfile.close(); |
| 1446 |
cmd << " " << Bodiesfile_name.str().c_str(); |
| 1447 |
} |
| 1448 |
if (SAVE_VELOCITY) { |
| 1449 |
Vfile.close(); |
| 1450 |
cmd << " " << Vfile_name.str().c_str(); |
| 1451 |
} |
| 1452 |
if (SAVE_VELOCITYCOMP) { |
| 1453 |
Vxfile.close(); |
| 1454 |
Vyfile.close(); |
| 1455 |
cmd << " " << Vxfile_name.str().c_str() << " " << Vyfile_name.str().c_str(); |
| 1456 |
} |
| 1457 |
if (SAVE_FORCES) { |
| 1458 |
FxLBMfile.close(); |
| 1459 |
FyLBMfile.close(); |
| 1460 |
MzLBMfile.close(); |
| 1461 |
cmd << " " << FxLBMfile_name.str().c_str() << " " << FyLBMfile_name.str().c_str() << " " << MzLBMfile_name.str().c_str(); |
| 1462 |
} |
| 1463 |
if (SAVE_RHO) { |
| 1464 |
Rhofile.close(); |
| 1465 |
cmd << " " << Rhofile_name.str().c_str(); |
| 1466 |
} |
| 1467 |
if (SAVE_NODEBD) { |
| 1468 |
NodeBoundaryfile.close(); |
| 1469 |
cmd << " " << NodeBoundaryfile_name.str().c_str(); |
| 1470 |
} |
| 1471 |
if (SAVE_NODEISNEW) { |
| 1472 |
NewNodefile.close(); |
| 1473 |
cmd << " " << NewNodefile_name.str().c_str(); |
| 1474 |
} |
| 1475 |
//cmd<<"&"; |
| 1476 |
if (COMPRESS_DATA) { |
| 1477 |
if (std::system(cmd.str().c_str())) cerr << "bzip error" << endl; |
| 1478 |
} |
| 1479 |
|
| 1480 |
|
| 1481 |
/*--------------------------------------------*/ |
| 1482 |
/* Recording of properties of DEM objects */ |
| 1483 |
/*--------------------------------------------*/ |
| 1484 |
if (SAVE_SPHERES) { //condition to save spheres properties only if it is required by the operator, checking if NB_GRAINS > 0 is done earlier when recording configuration is done |
| 1485 |
spherefile_name.str(""); |
| 1486 |
spherefile_name << dem_dir << "/spheres"; |
| 1487 |
cerr << " Write DEM data in " << spherefile_name.str().c_str() << endl; |
| 1488 |
spherefile_name << "_"; |
| 1489 |
spherefile_name.width(10); |
| 1490 |
spherefile_name.fill('0'); |
| 1491 |
spherefile_name << iter_number; |
| 1492 |
std::ofstream spherefile; |
| 1493 |
spherefile.open(spherefile_name.str().c_str()); |
| 1494 |
|
| 1495 |
for (unsigned int l = 0; l < LBbodies.size(); l++) { |
| 1496 |
if (LBbodies[l].isPtc()) { |
| 1497 |
if ((!LBbodies[l].isEroded) && (LBbodies[l].saveProperties)) { |
| 1498 |
spherefile << l << " "; /* Id*/ |
| 1499 |
spherefile << dx * LBbodies[l].pos.x() << " " << dx * LBbodies[l].pos.y() << " " << dx * LBbodies[l].pos.z() |
| 1500 |
<< " "; /* x, y, z*/ |
| 1501 |
spherefile << dx * LBbodies[l].radius << " "; /* r*/ |
| 1502 |
spherefile << c * LBbodies[l].vel.x() << " " << c * LBbodies[l].vel.y() << " " << c * LBbodies[l].vel.z() |
| 1503 |
<< " "; /* Vx, Vy, Vz*/ |
| 1504 |
spherefile << invdt * LBbodies[l].AVel.x() << " " << invdt * LBbodies[l].AVel.y() << " " << invdt * LBbodies[l].AVel.z() |
| 1505 |
<< " "; /* Wx, Wy, Wz*/ |
| 1506 |
spherefile << LBbodies[l].Fh.x() << " " << LBbodies[l].Fh.y() << " " << LBbodies[l].Fh.z() << " "; /* Fhx, Fhy, Fhz */ |
| 1507 |
spherefile << LBbodies[l].Mh.x() << " " << LBbodies[l].Mh.y() << " " << LBbodies[l].Mh.z() << endl; /* Mhx, Mhy, Mhz */ |
| 1508 |
} |
| 1509 |
} |
| 1510 |
} |
| 1511 |
spherefile.close(); |
| 1512 |
} |
| 1513 |
|
| 1514 |
#ifdef LBM_VERBOSE |
| 1515 |
cerr << "END: HydrodynamicsLawLBM::save()" << endl; |
| 1516 |
#endif |
| 1517 |
return; |
| 1518 |
} |
| 1519 |
|
| 1520 |
void HydrodynamicsLawLBM::saveStats(int iter_number, Real timestep) |
| 1521 |
{ |
| 1522 |
#ifdef LBM_VERBOSE |
| 1523 |
cerr << "START: HydrodynamicsLawLBM::saveStats()" << endl; |
| 1524 |
#endif |
| 1525 |
cerr << "| Save stats ..." << endl; |
| 1526 |
std::ofstream file(LBMmachFile.c_str(), ios::app); |
| 1527 |
file << iter_number << " " << iter_number * timestep << " " << VmaxC << " " << VmaxC / c << endl; |
| 1528 |
#ifdef LBM_VERBOSE |
| 1529 |
cerr << "END: HydrodynamicsLawLBM::saveStats()" << endl; |
| 1530 |
#endif |
| 1531 |
return; |
| 1532 |
} |
| 1533 |
//void HydrodynamicsLawLBM::saveEroded(int iter_number, Real timestep) |
| 1534 |
//{ |
| 1535 |
// |
| 1536 |
// cerr << "| Save Eroded Ptc ..."<<endl; |
| 1537 |
// std::ofstream file(RemovedPtcFile.c_str(), ios::app); |
| 1538 |
// file <<iter_number<<" "<<iter_number*timestep<<" "<<NumberPtcEroded<<" "<<Vr<<" "<<Vr/Vo<<" "<<FhTotale<<endl; |
| 1539 |
// |
| 1540 |
// return; |
| 1541 |
//} |
| 1542 |
void HydrodynamicsLawLBM::saveObservedPtc(int iter_number, Real timestep) |
| 1543 |
{ |
| 1544 |
cerr << "| Save Observed Ptc ..." << endl; |
| 1545 |
std::ofstream file(ObservedPtcFile.c_str(), ios::app); |
| 1546 |
file << iter_number << " " << iter_number * timestep << " "; |
| 1547 |
file << dx * LBbodies[ObservedPtc].pos.x() << " " << dx * LBbodies[ObservedPtc].pos.y() << " " << dx * LBbodies[ObservedPtc].pos.z() << " "; |
| 1548 |
file << dx * LBbodies[ObservedPtc].radius << " "; |
| 1549 |
file << c * LBbodies[ObservedPtc].vel.x() << " " << c * LBbodies[ObservedPtc].vel.y() << " " << c * LBbodies[ObservedPtc].vel.z() << " "; |
| 1550 |
file << invdt * LBbodies[ObservedPtc].AVel.x() << " " << invdt * LBbodies[ObservedPtc].AVel.y() << " " << invdt * LBbodies[ObservedPtc].AVel.z() << " "; |
| 1551 |
file << LBbodies[ObservedPtc].Fh.x() << " " << LBbodies[ObservedPtc].Fh.y() << " " << LBbodies[ObservedPtc].Fh.z() << " "; |
| 1552 |
file << LBbodies[ObservedPtc].Mh.x() << " " << LBbodies[ObservedPtc].Mh.y() << " " << LBbodies[ObservedPtc].Mh.z() << endl; |
| 1553 |
|
| 1554 |
return; |
| 1555 |
} |
| 1556 |
void HydrodynamicsLawLBM::saveObservedNode(int /*iter_number*/, Real /*timestep*/) { return; } |
| 1557 |
/* |
| 1558 |
_________________________________________________________________________ |
| 1559 |
*/ |
| 1560 |
|
| 1561 |
void HydrodynamicsLawLBM::createNewFiles() |
| 1562 |
{ |
| 1563 |
//spherefile_name<<dem_dir<<"/spheres"; //Useless here |
| 1564 |
|
| 1565 |
std::ofstream file(LBMmachFile.c_str()); |
| 1566 |
file << "#iter_number\t time\t VmaxC\t VmaxC/c" << endl; |
| 1567 |
file.close(); |
| 1568 |
|
| 1569 |
if (removingCriterion != 0) { |
| 1570 |
std::ofstream file2(RemovedPtcFile.c_str()); |
| 1571 |
file2 << "#Iter time NumberPtcEroded Vr Vr/Vo FhTotale" << endl; |
| 1572 |
file2.close(); |
| 1573 |
} |
| 1574 |
|
| 1575 |
if (SAVE_CONTACTINFO) { |
| 1576 |
std::ofstream file3(LBMcontactsFile.c_str()); |
| 1577 |
file3 << "#Iter time NumberOfContact" << endl; |
| 1578 |
file3.close(); |
| 1579 |
} |
| 1580 |
//if(NB_GRAINS>0) {ofstream file3(spherefile_name.str().c_str());file3.close();} //For what this line is used for? It seems to work without |
| 1581 |
|
| 1582 |
if (SAVE_OBSERVEDPTC) { //Condition to create observedPtc file only if the recording is required by the operator |
| 1583 |
std::ofstream file4(ObservedPtcFile.c_str()); |
| 1584 |
file4 << "#iter t x y z r Vx Vy Vz Wx Wy Wz Fx Fy Fz Mx My Mz" << endl; |
| 1585 |
file4.close(); |
| 1586 |
} |
| 1587 |
|
| 1588 |
if (SAVE_OBSERVEDNODE) { //Condition to create observedNode file only if the recording is required by the operator |
| 1589 |
std::ofstream file5(ObservedNodeFile.c_str()); |
| 1590 |
file5.close(); |
| 1591 |
} |
| 1592 |
|
| 1593 |
|
| 1594 |
return; |
| 1595 |
} |
| 1596 |
|
| 1597 |
void HydrodynamicsLawLBM::createDirectories(bool dirLBM, bool dirDem, bool dirCntct) |
| 1598 |
{ |
| 1599 |
//bfs::create_directory(bfs::path(lbm_dir)); //ModLuc: to create only necessary directory |
| 1600 |
if (dirLBM) bfs::create_directory(bfs::path(lbm_dir)); |
| 1601 |
//if(NB_GRAINS>0) bfs::create_directory(bfs::path(dem_dir)); //ModLuc: to create only necessary directory |
| 1602 |
if (dirDem) bfs::create_directory(bfs::path(dem_dir)); |
| 1603 |
//if(SAVE_CONTACTINFO) bfs::create_directory(bfs::path(cntct_dir)); //ModLuc: to create only necessary directory |
| 1604 |
if (dirCntct) bfs::create_directory(bfs::path(cntct_dir)); |
| 1605 |
|
| 1606 |
return; |
| 1607 |
} |
| 1608 |
|
| 1609 |
void HydrodynamicsLawLBM::writelogfile() |
| 1610 |
{ |
| 1611 |
std::ofstream file(LBMlogFile.c_str()); |
| 1612 |
file << "File format: 1" << endl; |
| 1613 |
file << "System parameters: " << endl; |
| 1614 |
file << "\t Lx0= " << Lx0 << endl; |
| 1615 |
file << "\t Ly0= " << Ly0 << endl; |
| 1616 |
file << "\t Lz0= " << Lz0 << endl; |
| 1617 |
file << "\t Wallthickness= " << Wallthickness << endl; |
| 1618 |
file << "\t dP= " << dP << endl; |
| 1619 |
file << "\t Nu= " << Nu << endl; |
| 1620 |
file << "\t Rho= " << Rho << endl; |
| 1621 |
file << "\t dx= " << dx << endl; |
| 1622 |
file << "\t Nx= " << Nx << endl; |
| 1623 |
file << "\t Ny= " << Ny << endl; |
| 1624 |
file << "\t Nz= " << Nz << endl; |
| 1625 |
file << "LBM parameters: " << endl; |
| 1626 |
file << "\t tau= " << tau << " omega= " << omega << endl; |
| 1627 |
file << "\t IterMax= " << IterMax << endl; |
| 1628 |
file << "\t SaveMode= " << SaveMode << endl; |
| 1629 |
file << "\t IterSave= " << IterSave << endl; |
| 1630 |
file << "\t SaveGridRatio= " << SaveGridRatio << endl; |
| 1631 |
file << "\t DemIterLbmIterRatio= " << DemIterLbmIterRatio << endl; |
| 1632 |
file << "\t ConvergenceThreshold= " << ConvergenceThreshold << endl; |
| 1633 |
file << "\t Predicted Mach number (may be false)= " << UMaxtheo / c << endl; |
| 1634 |
file << "\t LBM dt= " << dt << endl; |
| 1635 |
file << "DEM parameters: " << endl; |
| 1636 |
file << "\t DEM dt= " << DEMdt0 << endl; |
| 1637 |
file << "\t DEM adjusted dt= " << newDEMdt << endl; |
| 1638 |
file << "Particles: " << endl; |
| 1639 |
file << "\t InitialNumberOfDynamicParticles= " << InitialNumberOfDynamicParticles << endl; |
| 1640 |
file << "\t NB_BODIES= " << NB_BODIES << " NB_GRAINS= " << NB_GRAINS << endl; |
| 1641 |
file << "\t NB_DYNBODIES= " << NB_DYNBODIES << " NB_DYNGRAINS= " << NB_DYNGRAINS << endl; |
| 1642 |
file << "\t Rmin / Rmax / Rmean = " << dx * MinBodyRadius << " / " << dx * MaxBodyRadius << " / " << dx * MeanBodyRadius << endl; |
| 1643 |
if (NB_GRAINS > 0) file << "\t NbNodePerPtc= " << NbParticleNodes / NB_GRAINS << endl; |
| 1644 |
else |
| 1645 |
file << "\t NbNodePerPtc= " << -1 << endl; |
| 1646 |
file << "\t Vo= " << Vo << endl; |
| 1647 |
file << "Misc :" << endl; |
| 1648 |
file << "\t VbCutOff= " << VbCutOff << endl; |
| 1649 |
//file <<"\t CstBodyForceDensity= "<<CstBodyForceDensity<<endl; |
| 1650 |
file << "Memory usage" << endl; |
| 1651 |
file << "\t Nodes= " << nodes.size() << endl; |
| 1652 |
file << "\t links= " << links.size() << endl; |
| 1653 |
|
| 1654 |
file.close(); |
| 1655 |
return; |
| 1656 |
} |
| 1657 |
|
| 1658 |
void HydrodynamicsLawLBM::modeTransition() |
| 1659 |
{ |
| 1660 |
cerr << "Mode transition " << endl; |
| 1661 |
IterMax = 1; |
| 1662 |
IterSubCyclingStart = -1; |
| 1663 |
LBM_ITER = 1; |
| 1664 |
use_ConvergenceCriterion = false; |
| 1665 |
return; |
| 1666 |
} |
| 1667 |
|
| 1668 |
void HydrodynamicsLawLBM::LbmEnd() |
| 1669 |
{ |
| 1670 |
if (MODE == 1) IterMax = iter; |
| 1671 |
Omega::instance().stop(); |
| 1672 |
Omega::instance().saveSimulation("end.xml"); |
| 1673 |
} |
| 1674 |
|
| 1675 |
void HydrodynamicsLawLBM::CalculateAndApplyForcesAndTorquesOnBodies(bool mean, bool apply) |
| 1676 |
{ |
| 1677 |
/*--------------------------------------------------------------------------------*/ |
| 1678 |
/*---------------- APPLICATION OF HYDRODYNAMIC FORCES ON SPHERES -----------------*/ |
| 1679 |
/*--------------------------------------------------------------------------------*/ |
| 1680 |
if (mean) FhTotale = Vector3r::Zero(); |
| 1681 |
for (const auto& b : *scene->bodies) { |
| 1682 |
if (!b) continue; |
| 1683 |
const int id = b->getId(); |
| 1684 |
//if ( ((b->isDynamic())&&(b->shape->getClassName()=="Sphere")) || (b->shape->getClassName()=="Box") ){ //ModLuc: remove the condition (b->isDynamic()) to be able to apply force and torque on non dynamic bodies, by this way hydrodynamic force and torque on bodies can be read through python even if bodies are non dynamic. |
| 1685 |
if ((b->shape->getClassName() == "Sphere") || (b->shape->getClassName() == "Box")) { |
| 1686 |
if (mean) { |
| 1687 |
LBbodies[id].fp = LBbodies[id].force; |
| 1688 |
LBbodies[id].force = 0.5 * (LBbodies[id].fp + LBbodies[id].fm); |
| 1689 |
LBbodies[id].fm = LBbodies[id].fp; |
| 1690 |
LBbodies[id].mp = LBbodies[id].momentum; |
| 1691 |
LBbodies[id].momentum = 0.5 * (LBbodies[id].mp + LBbodies[id].mm); |
| 1692 |
LBbodies[id].mm = LBbodies[id].mp; |
| 1693 |
LBbodies[id].Fh = 2. * Rho * c2 * dx * LBbodies[id].force; |
| 1694 |
LBbodies[id].Mh = 2. * Rho * c2 * dx2 * LBbodies[id].momentum; |
| 1695 |
FhTotale = FhTotale + LBbodies[id].Fh; |
| 1696 |
} |
| 1697 |
if (apply) { |
| 1698 |
scene->forces.addForce(id, LBbodies[id].Fh); |
| 1699 |
scene->forces.addTorque(id, LBbodies[id].Mh); |
| 1700 |
} |
| 1701 |
} |
| 1702 |
} |
| 1703 |
return; |
| 1704 |
} |
| 1705 |
YADE_PLUGIN((HydrodynamicsLawLBM)); |
| 1706 |
|
| 1707 |
} // namespace yade |
| 1708 |
|
| 1709 |
#endif //LBM_ENGINE |