hemocell
Loading...
Searching...
No Matches
hemocell.h
Go to the documentation of this file.
1/*
2This file is part of the HemoCell library
3
4HemoCell is developed and maintained by the Computational Science Lab
5in the University of Amsterdam. Any questions or remarks regarding this library
6can be sent to: info@hemocell.eu
7
8When using the HemoCell library in scientific work please cite the
9corresponding paper: https://doi.org/10.3389/fphys.2017.00563
10
11The HemoCell library is free software: you can redistribute it and/or
12modify it under the terms of the GNU Affero General Public License as
13published by the Free Software Foundation, either version 3 of the
14License, or (at your option) any later version.
15
16The library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU Affero General Public License for more details.
20
21You should have received a copy of the GNU Affero General Public License
22along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24#ifndef HEMOCELL_H
25#define HEMOCELL_H
26
27//Load Constants
28#include "constant_defaults.h"
29#include "config.h"
30
31/* CORE libs */
32#include "hemoCellFields.h"
33
34/* IO */
35#include "loadBalancer.h"
36#include "profiler.h"
37
38/* MECHANICS */
39#include "cellMechanics.h"
40#include "constantConversion.h"
41
42/* Helpers */
43#include "preInlet.h"
44// #include "leesEdwardsBC.h"
45
46/* Always used palabos functions in case files*/
47#ifndef COMPILING_HEMOCELL_LIBRARY
48#include "voxelizeDomain.h"
49#include "palabos3D.h"
50#include "palabos3D.hh"
51#endif
52
53namespace hemo {
54
66class HemoCell {
67public:
74 enum class MPIHandle { Internal, External };
75
90 HemoCell(const std::string & configFileName, int argc, char * argv[],
92 const char * caseConfiguration = HEMOCELL_BUILD_CONFIGURATION);
93
94 /*
95 * Clean up hemocell
96 */
97 ~HemoCell();
98
105
111 void initializeCellfield();
112
125 template <class Mechanics>
126 void addCellType(std::string name, int constructType) {
127 HemoCellField * cellfield = cellfields->addCellType(name, constructType);
128 Mechanics * mechanics = new Mechanics(*cellfield->materialCfg, *cellfield);
129 cellfield->mechanics = mechanics;
130 cellfield->statistics();
131 }
132
139 void setOutputs(std::string name, std::vector<int> outputs);
140
141 bool repulsionEnabled = false;
155 void setRepulsion(T repulsionConstant, T repulsionCutoff);
156
157 // Lees-Edwards boundary condition
158 bool leesEdwardsBC = false;
162
168 void setMaterialTimeScaleSeparation(std::string name, unsigned int separation);
169
170 //Enable solidify mechanics of a celltype
171 void enableSolidifyMechanics(std::string name) {
172 hlog << "(HemoCell) Enabling Solidify Mechanics for " << name << " mechanical model" << std::endl;
173 (*cellfields)[name]->doSolidifyMechanics = true;
174 }
175
182 void setParticleVelocityUpdateTimeScaleSeparation(unsigned int separation);
183
187 void setRepulsionTimeScaleSeperation(unsigned int separation);
188
190 void setSolidifyTimeScaleSeperation(unsigned int separation);
191
196 void setInteriorViscosityTimeScaleSeperation(unsigned int separation, unsigned int separation_entire_grid);
197
207 void enableBoundaryParticles(T boundaryRepulsionConstant, T boundaryRepulsionCutoff, unsigned int timestep = 1);
208
216 void setInitialMinimumDistanceFromSolid(std::string name, T distance);
217
232
234 void setFluidOutputs(std::vector<int> outputs);
235
237 void setCEPACOutputs(std::vector<int> outputs);
238
245 void setSystemPeriodicity(unsigned int axis, bool bePeriodic);
246
255 void setSystemPeriodicityLimit(unsigned int axis, int limit);
256
257 //Load the particles
258private:
260
261public:
267 void loadParticles();
268
271 void loadCheckPoint();
272
274 void saveCheckPoint();
275
277 bool outputInSiUnits = true;
278
282 void writeOutput();
283
289 void iterate();
290
300 void checkExitSignals();
301
303 unsigned int exitSignalCheckInterval = 100;
306
307 //Load balancing library functions
310
313
315 void doRestructure(bool checkpoint_avail = true);
316
318 void initializeLattice(plb::MultiBlockManagement3D const & management);
319
332 void initializeLatticeFromFlagMatrix(plb::MultiBlockManagement3D const & management,
333 plb::MultiScalarField3D<int> & flagMatrix);
334
336
337 bool partOfpreInlet = false;
338
339 std::map<plint, plint> BlockToMpi;
340
343 plb::MultiBlockLattice3D<T, DESCRIPTOR> *lattice = 0, *preinlet_lattice = 0, *domain_lattice = 0;
344
345 plb::MultiBlockManagement3D *preinlet_lattice_management = 0, *domain_lattice_management = 0;
346
347 Config * cfg = 0;
350 unsigned int iter = 0;
351
352 plb::XMLreader * documentXML = 0; //Needed for legacy checkpoint reading TODO fix
353
356 unsigned int getLastOutputIteration() const { return lastOutputAt; }
358 void setLastOutputIteration(unsigned int iteration) { lastOutputAt = iteration; }
359
360private:
362 unsigned int lastOutputAt = 0;
363 std::chrono::high_resolution_clock::duration lastOutput = std::chrono::high_resolution_clock::duration::zero();
364
366 void sanityCheck();
368 bool sanityCheckDone = false;
369};
370}
371#endif // HEMOCELL_H
Definition config.h:91
Definition hemoCellField.h:42
Config * materialCfg
Definition hemoCellField.h:56
CellMechanics * mechanics
Definition hemoCellField.h:86
void statistics()
Definition hemoCellField.cpp:160
Definition hemoCellFields.h:54
HemoCellField * addCellType(std::string name_, int constructType)
Add a cell type with a certain mesh; its name also selects name_.xml and name_.pos
Definition hemoCellFields.cpp:140
Definition hemocell.h:66
T calculateFractionalLoadImbalance()
Calculate and return the fractional load imbalance.
Definition hemoCell.cpp:465
void sanityCheck()
To be run right before the first iteration, all checking should move here.
Definition hemoCell.cpp:700
void loadCheckPoint()
Definition hemoCell.cpp:274
plb::MultiBlockLattice3D< T, DESCRIPTOR > * preinlet_lattice
Definition hemocell.h:343
plb::MultiBlockManagement3D * preinlet_lattice_management
Definition hemocell.h:345
void setParticleVelocityUpdateTimeScaleSeparation(unsigned int separation)
Interpolate the fluid velocity to the vertices (and synchronise the particle envelopes) every separat...
Definition hemoCell.cpp:476
bool repulsionEnabled
Definition hemocell.h:141
std::map< plint, plint > BlockToMpi
Definition hemocell.h:339
bool sanityCheckDone
Checked in iteration, do sanity check when not yet done.
Definition hemocell.h:368
void doRestructure(bool checkpoint_avail=true)
Restructure the grid, has an optional argument to specify whether a checkpoint from this iteration is...
Definition hemoCell.cpp:695
void setRepulsionTimeScaleSeperation(unsigned int separation)
Definition hemoCell.cpp:483
void setFluidOutputs(std::vector< int > outputs)
Select the fluid fields written by writeOutput() (OUTPUT_* constants).
Definition hemoCell.cpp:197
void setPlaceCellsAcrossPeriodicBoundaries(bool place)
Also place the cells of the .pos files that cross a periodic boundary (default: off,...
Definition hemoCell.cpp:503
void initializeLattice(plb::MultiBlockManagement3D const &management)
Initialize the fluid field with the given management, should be done after specifing the pre inlets a...
Definition hemoCell.cpp:573
void setOutputs(std::string name, std::vector< int > outputs)
Select the cell fields written by writeOutput() for a cell type.
Definition hemoCell.cpp:191
void setInteriorViscosityTimeScaleSeperation(unsigned int separation, unsigned int separation_entire_grid)
Definition hemoCell.cpp:493
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 setCEPACOutputs(std::vector< int > outputs)
Select the CEPAC fields written by writeOutput() (OUTPUT_* constants).
Definition hemoCell.cpp:203
void loadParticles()
Place the cells listed in the <name>.pos files (positions in micrometre, rotations in degrees,...
Definition hemoCell.cpp:229
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
bool boundaryRepulsionEnabled
Definition hemocell.h:142
PreInlet * preInlet
Definition hemocell.h:335
void setSystemPeriodicityLimit(unsigned int axis, int limit)
Number of periodic images of a cell distinguishable along axis (default 100 for each axis)....
Definition hemoCell.cpp:220
double * LEcurrentDisplacement
Definition hemocell.h:161
HemoCellFields * cellfields
The cellfields contains the particle field and all celltypes.
Definition hemocell.h:349
void enableBoundaryParticles(T boundaryRepulsionConstant, T boundaryRepulsionCutoff, unsigned int timestep=1)
Enable repulsion between vertices and wall (solid) nodes. Collective (detects the wall nodes next to ...
Definition hemoCell.cpp:546
void saveCheckPoint()
Save a checkpoint to <outputDirectory>/<checkpointDirectory>/. Collective.
Definition hemoCell.cpp:281
LoadBalancer * loadBalancer
Definition hemocell.h:341
void checkExitSignals()
Act on a caught exit signal (SIGINT, SIGTERM, SIGHUP, SIGQUIT, SIGUSR1, SIGUSR2).
Definition hemoCell.cpp:357
unsigned int iter
Definition hemocell.h:350
bool outputInSiUnits
Write output in SI units (default) or in lattice units.
Definition hemocell.h:277
void setSolidifyTimeScaleSeperation(unsigned int separation)
Run the solidification step every separation iterations (default 1).
Definition hemoCell.cpp:488
void doLoadBalance()
Load balance the domain (only necessary with nAtomic blocks > nMpi processors, also checkpoints.
unsigned int getLastOutputIteration() const
Definition hemocell.h:356
void setLastOutputIteration(unsigned int iteration)
Restore the last output iteration (used when loading a checkpoint).
Definition hemocell.h:358
bool checkpointOnExitSignal
Save a checkpoint before exiting on a caught signal.
Definition hemocell.h:305
unsigned int lastOutputAt
Store the last time (iteration) output occured.
Definition hemocell.h:362
plb::MultiBlockManagement3D * domain_lattice_management
Definition hemocell.h:345
plb::XMLreader * documentXML
Definition hemocell.h:352
MPIHandle
Switch to indicate if the MPI instance is managed externally. The MPI instance is typically invoked w...
Definition hemocell.h:74
void setRepulsion(T repulsionConstant, T repulsionCutoff)
Enable repulsion between vertices of different cells.
Definition hemoCell.cpp:539
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
void writeOutput()
Definition hemoCell.cpp:291
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
~HemoCell()
Definition hemoCell.cpp:154
void latticeEquilibrium(T rho, hemo::Array< T, 3 > vel)
Initialise every fluid node at equilibrium.
Definition hemoCell.cpp:173
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 enableSolidifyMechanics(std::string name)
Definition hemocell.h:171
bool leesEdwardsBC
Definition hemocell.h:158
plb::MultiBlockLattice3D< T, DESCRIPTOR > * domain_lattice
Definition hemocell.h:343
bool partOfpreInlet
Definition hemocell.h:337
unsigned int exitSignalCheckInterval
Iterations between collective exit-signal checks in iterate() (0 disables them).
Definition hemocell.h:303
std::chrono::high_resolution_clock::duration lastOutput
Definition hemocell.h:363
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
bool loadParticlesIsCalled
Definition hemocell.h:259
Definition loadBalancer.h:31
Definition preInlet.h:55
#define HEMOCELL_BUILD_CONFIGURATION
Definition constant_defaults.h:233
double T
Definition constant_defaults.h:137
int argc
Definition main.cpp:32
char ** argv
Definition main.cpp:33
Definition config.cpp:37
Logfile hlog
Definition logfile.cpp:26
Definition array.h:40