hemocell
Loading...
Searching...
No Matches
pipeflow_setup.h
Go to the documentation of this file.
1// Shared setup of the small pipeflow case (same domain, lattice and cell
2// types as Validation.Pipeflow) for integration tests.
3#ifndef HEMOCELL_TESTS_PIPEFLOW_SETUP_H
4#define HEMOCELL_TESTS_PIPEFLOW_SETUP_H
5
6#include <hemocell.h>
7#include "test_support.h"
9#include "rbcHighOrderModel.h"
10#include "pltSimpleModel.h"
11#include "palabos3D.h"
12#include "palabos3D.hh"
13
14#include <algorithm>
15#include <memory>
16#include <string>
17#include <vector>
18
19namespace pipeflow_test {
20
21constexpr const char * pipeflow_config = "tests/validation/pipeflow/config_pipeflow.xml";
22constexpr const char * pipeflow_geometry = "examples/pipeflow/tube.stl";
23constexpr const char * rbc_name = "tests/validation/pipeflow/RBC";
24constexpr const char * plt_name = "tests/validation/pipeflow/PLT";
25
26// The pipeflow configuration with its output in the tests' output directory
27// (hemo_test::testConfig()); pipeflow_config itself is the original file.
28inline std::string pipeflowConfig() {
30}
31
33 std::unique_ptr<plb::MultiScalarField3D<int>> flagMatrix;
34 std::unique_ptr<plb::VoxelizedDomain3D<T>> voxelizedDomain;
35 plb::Array<T, 3> drivingForce;
36};
37
38// Same domain, lattice and cell types as Validation.Pipeflow, without loading
39// particles (that differs between a fresh start and a restart). `RbcModel` is
40// the constitutive model of the RBC type; `rbc` and `plt` name the cell types
41// (their .xml and .pos files).
42template <class RbcModel = hemo::RbcHighOrderModel>
43void setupPipeflow(hemo::HemoCell & hemocell, PipeflowSetup & setup, T rbcMinimumDistanceFromSolid = 0.5,
44 const std::string & rbc = rbc_name, const std::string & plt = plt_name) {
45 hemo::Config * cfg = hemocell.cfg;
46 hemo::getFlagMatrixFromSTL(pipeflow_geometry, (*cfg)["domain"]["fluidEnvelope"].read<int>(),
47 (*cfg)["domain"]["refDirN"].read<int>(), (*cfg)["domain"]["refDir"].read<int>(),
48 setup.voxelizedDomain, setup.flagMatrix, (*cfg)["domain"]["blockSize"].read<int>(),
49 (*cfg)["domain"]["particleEnvelope"].read<int>());
51
52 hemocell.initializeLatticeFromFlagMatrix(setup.voxelizedDomain->getMultiBlockManagement(), *setup.flagMatrix);
53
54 const T poiseuilleForce =
56 setup.drivingForce = plb::Array<T, 3>(poiseuilleForce, 0., 0.);
57
58 hemocell.lattice->initialize();
59 hemocell.initializeCellfield();
60 hemocell.addCellType<RbcModel>(rbc, hemo::RBC_FROM_SPHERE);
61 hemocell.setMaterialTimeScaleSeparation(rbc, (*cfg)["ibm"]["stepMaterialEvery"].read<int>());
62 hemocell.setInitialMinimumDistanceFromSolid(rbc, rbcMinimumDistanceFromSolid);
64 hemocell.setMaterialTimeScaleSeparation(plt, (*cfg)["ibm"]["stepMaterialEvery"].read<int>());
65 hemocell.setParticleVelocityUpdateTimeScaleSeparation((*cfg)["ibm"]["stepParticleEvery"].read<int>());
66 hemocell.setSystemPeriodicity(0, true);
67}
68
69inline void iterate(hemo::HemoCell & hemocell, const PipeflowSetup & setup, unsigned int steps) {
70 for (unsigned int i = 0; i < steps; i++) {
71 hemocell.iterate();
72 setExternalVector(*hemocell.lattice, hemocell.lattice->getBoundingBox(),
73 DESCRIPTOR<T>::ExternalField::forceBeginsAt, setup.drivingForce);
74 }
75}
76
77// State of a run on this rank, for exact comparisons between runs with the
78// same decomposition.
79struct State {
80 // Particles of every local block in storage order (the order sets the
81 // summation order of force spreading), without the residence time, which
82 // output brings up to date; cell IDs minus the `idShift` of captureState().
83 std::vector<T> particles;
84 // Populations and external force of the bulk nodes of every local block.
85 std::vector<T> fluid;
86};
87
88inline State captureState(hemo::HemoCell & hemocell, plb::plint idShift = 0) {
89 State state;
90 plb::MultiParticleField3D<hemo::HemoCellParticleField> & field = *hemocell.cellfields->immersedParticles;
91 for (plb::plint bid : field.getLocalInfo().getBlocks()) {
92 for (const hemo::HemoCellParticle & p : field.getComponent(bid).particles) {
93 for (const hemo::Array<T, 3> * a : {&p.sv.v, &p.sv.position, &p.sv.force, &p.sv.force_repulsion}) {
94 state.particles.insert(state.particles.end(), a->begin(), a->end());
95 }
96 state.particles.push_back(T(p.sv.cellId - idShift));
97 state.particles.push_back(T(p.sv.vertexId));
98 state.particles.push_back(T(p.sv.celltype));
99 }
100 }
101 plb::MultiBlockLattice3D<T, DESCRIPTOR> & lattice = *hemocell.lattice;
102 for (plb::plint bid : lattice.getLocalInfo().getBlocks()) {
103 plb::SmartBulk3D bulk(lattice.getMultiBlockManagement(), bid);
104 const plb::Box3D box = bulk.toLocal(bulk.getBulk());
105 plb::BlockLattice3D<T, DESCRIPTOR> & block = lattice.getComponent(bid);
106 for (plb::plint x = box.x0; x <= box.x1; x++) {
107 for (plb::plint y = box.y0; y <= box.y1; y++) {
108 for (plb::plint z = box.z0; z <= box.z1; z++) {
109 plb::Cell<T, DESCRIPTOR> & cell = block.get(x, y, z);
110 for (plb::plint i = 0; i < DESCRIPTOR<T>::q; i++) { state.fluid.push_back(cell[i]); }
111 const T * force = cell.getExternal(DESCRIPTOR<T>::ExternalField::forceBeginsAt);
112 state.fluid.insert(state.fluid.end(), force, force + 3);
113 }
114 }
115 }
116 }
117 return state;
118}
119
120// Index of the first difference (exact comparison), -1 if identical.
121inline long firstDifference(const std::vector<T> & a, const std::vector<T> & b) {
122 if (a.size() != b.size()) { return long(std::min(a.size(), b.size())); }
123 for (size_t i = 0; i < a.size(); i++) {
124 if (a[i] != b[i]) { return long(i); }
125 }
126 return -1;
127}
128
129} // namespace pipeflow_test
130
131#endif
Definition config.h:91
plb::MultiParticleField3D< HemoCellParticleField > * immersedParticles
palabos field storing the particles
Definition hemoCellFields.h:235
Definition hemoCellParticle.h:44
Definition hemocell.h:66
void setParticleVelocityUpdateTimeScaleSeparation(unsigned int separation)
Interpolate the fluid velocity to the vertices (and synchronise the particle envelopes) every separat...
Definition hemoCell.cpp:476
void initializeCellfield()
Create the cell fields and the particle field on the current lattice. Collective. Call after the latt...
Definition hemoCell.cpp:179
void addCellType(std::string name, int constructType)
Add a cell type with constitutive model Mechanics.
Definition hemocell.h:126
void initializeLatticeFromFlagMatrix(plb::MultiBlockManagement3D const &management, plb::MultiScalarField3D< int > &flagMatrix)
Create the fluid lattice of a voxelised geometry without a pre-inlet.
Definition hemoCell.cpp:556
HemoCellFields * cellfields
The cellfields contains the particle field and all celltypes.
Definition hemocell.h:349
void setInitialMinimumDistanceFromSolid(std::string name, T distance)
Reject initial vertices of a cell type closer than distance to a solid node: vertices within floor(di...
Definition hemoCell.cpp:510
Config * cfg
Definition hemocell.h:347
plb::MultiBlockLattice3D< T, DESCRIPTOR > * lattice
The fluid lattice.
Definition hemocell.h:343
void iterate()
Advance the coupled fluid and cells by one time step. Collective. The lattice force is reset at the e...
Definition hemoCell.cpp:377
void setMaterialTimeScaleSeparation(std::string name, unsigned int separation)
Evaluate the constitutive model of a cell type every separation iterations (default 1)....
Definition hemoCell.cpp:470
void setSystemPeriodicity(unsigned int axis, bool bePeriodic)
Set periodicity of the fluid and the particle field together. Call after initializeCellfield() and be...
Definition hemoCell.cpp:210
static T u_lbm_max
Definition constantConversion.h:38
static T pipe_radius
Definition constantConversion.h:43
static T nu_lbm
Definition constantConversion.h:38
static void lbm_pipe_parameters(Config &cfg, plb::MultiScalarField3D< int > *sf)
Definition constantConversion.cpp:61
Definition pltSimpleModel.h:33
double T
Definition constant_defaults.h:137
Definition cell.py:1
std::string testConfig(const std::string &path, const std::function< void(std::string &)> &edit=nullptr)
A copy of the configuration file path whose output directory lies in outputRoot(),...
Definition test_support.h:36
void getFlagMatrixFromSTL(std::string meshFileName, plb::plint extendedEnvelopeWidth, plb::plint refDirLength, plb::plint refDir, std::unique_ptr< plb::VoxelizedDomain3D< T > > &voxelizedDomain, std::unique_ptr< plb::MultiScalarField3D< int > > &flagMatrix, plint blockSize, int particleEnvelope)
Definition voxelizeDomain.cpp:66
constexpr int RBC_FROM_SPHERE
Definition constant_defaults.h:99
constexpr int ELLIPSOID_FROM_SPHERE
Definition constant_defaults.h:101
Definition pipeflow_setup.h:19
State captureState(hemo::HemoCell &hemocell, plb::plint idShift=0)
Definition pipeflow_setup.h:88
constexpr const char * pipeflow_geometry
Definition pipeflow_setup.h:22
constexpr const char * plt_name
Definition pipeflow_setup.h:24
long firstDifference(const std::vector< T > &a, const std::vector< T > &b)
Definition pipeflow_setup.h:121
std::string pipeflowConfig()
Definition pipeflow_setup.h:28
constexpr const char * pipeflow_config
Definition pipeflow_setup.h:21
void iterate(hemo::HemoCell &hemocell, const PipeflowSetup &setup, unsigned int steps)
Definition pipeflow_setup.h:69
constexpr const char * rbc_name
Definition pipeflow_setup.h:23
void setupPipeflow(hemo::HemoCell &hemocell, PipeflowSetup &setup, T rbcMinimumDistanceFromSolid=0.5, const std::string &rbc=rbc_name, const std::string &plt=plt_name)
Definition pipeflow_setup.h:43
Definition array.h:40
Definition pipeflow_setup.h:32
std::unique_ptr< plb::VoxelizedDomain3D< T > > voxelizedDomain
Definition pipeflow_setup.h:34
plb::Array< T, 3 > drivingForce
Definition pipeflow_setup.h:35
std::unique_ptr< plb::MultiScalarField3D< int > > flagMatrix
Definition pipeflow_setup.h:33
Definition pipeflow_setup.h:79
std::vector< T > fluid
Definition pipeflow_setup.h:85
std::vector< T > particles
Definition pipeflow_setup.h:83