22 #include <LbmLib/include/geometry/GeometryHandler.hpp>
23 #include <LbmLib/include/nodes/BoundaryNode.hpp>
24 #include <LbmLib/include/nodes/PhysicalNode.hpp>
26 #include <LbmLib/include/SimulationRunner.hpp>
28 #include <LbmLib/include/reportHandler/ReportHandler.hpp>
29 #include <LbmLib/include/solver/MassSolver/MassSolverFactory.hpp>
31 #include <LbmLib/include/GlobalSimulationParameters.hpp>
32 #include <LbmLib/include/solver/BoundaryAbstractSolver.hpp>
33 #include <LbmLib/include/solver/CDESolver/CDEAbstractSolver.hpp>
34 #include <LbmLib/include/solver/FluidSolver/FluidSolver.hpp>
35 #include <UtilLib/include/ProgressBar.hpp>
54 geometryHandler_(geometry),
55 reportHandler_(reportHandler)
57 this->setTau(Parameters.getTauFluid());
58 const auto& cdeSolvers = Parameters.getCdeSolvers();
59 for (
const auto& cdeSolver : cdeSolvers)
61 this->addCDESolver(cdeSolver.first);
62 this->setTau(cdeSolver.second, cdeSolver.first);
72 for (t = 1; t < Parameters.getIterations()+1; t++) {
73 this->calculateForce();
74 this->distributeForce();
79 this->collectVelocity();
83 this->remeshBoundary();
84 if (Parameters.getCurrentIteration()%10 == 0) {
86 this->coarsenBoundary();
89 this->applyMassSolvers();
90 this->applyBioSolvers();
93 this->checkLatticeIntegrity();
94 this->checkBoundaryIntegrity();
101 }
catch(
const std::exception& exp) {
102 Parameters.setReportSteps(1);
104 this->
writeSimulation(
"output/CRASH_forceOut_" + std::to_string(t) +
".txt",
105 "output/CRASH_geoOut_" + std::to_string(t) +
".txt",
106 "output/CRASH_parameterOut_" + std::to_string(t) +
".txt",
107 "output/CRASH_solverOut_" + std::to_string(t) +
".txt");
108 std::cout << exp.what() << std::endl;
113 const std::string& forceFileName,
114 const std::string& geometryFileName,
115 const std::string& parameterFileName,
116 const std::string& solverFileName)
const {
119 Parameters.writeGlobalSimulationParameters(parameterFileName);
122 std::ofstream fileStream;
123 fileStream.open(solverFileName);
124 if (fileStream.is_open()) {
125 fileStream <<
"#Solvers (xPos\tyPos\tDistributions...)\n";
126 fileStream <<
"#BEGIN FluidSolver\n";
129 i->getFluidSolver().writeSolver(&fileStream);
132 fileStream <<
"#END FluidSolver\n";
135 fileStream <<
"#BEGIN " << cde->getName() <<
"\n";
138 i->getCDESolver(cde->getId()).writeSolver(&fileStream);
141 fileStream <<
"#END " << cde->getName() <<
"\n";
145 "Cannot open the output file for the force solver.");
152 std::ifstream fileStream;
153 fileStream.open(filename);
154 if (fileStream.is_open()) {
156 std::string solverName(
"");
157 while (std::getline(fileStream, line)) {
158 std::stringstream lineStream(line);
159 if (line.at(0) !=
'#') {
161 lineStream >> x >> y;
162 if (solverName ==
"FluidSolver") {
164 .loadSolver(&lineStream);
169 solverName).loadSolver(&lineStream);
171 }
else if (line.find(
"#BEGIN") != std::string::npos) {
173 lineStream >> temp >> solverName;
174 }
else if (line.find(
"#END") != std::string::npos) {
179 lbm_fail(
"Cannot find the force file.");
184 void SimulationRunner::moveGeometry() {
190 void SimulationRunner::remeshBoundary() {
194 const_cast<geometry::GeometryHandler&>(this->geometryHandler_).remeshBoundary()
201 void SimulationRunner::coarsenBoundary()
205 const_cast<geometry::GeometryHandler&
>(this->geometryHandler_).coarsenBoundary();
209 void SimulationRunner::checkLatticeIntegrity()
211 const_cast<geometry::GeometryHandler&
>(this->geometryHandler_).checkLatticeIntegrity();
214 void SimulationRunner::checkBoundaryIntegrity()
216 const_cast<geometry::GeometryHandler&
>(this->geometryHandler_).checkBoundaryNodeIntegrity();
220 void SimulationRunner::collectVelocity() {
221 typedef std::map<unsigned int,std::shared_ptr<nodes::GeometryNode> >::const_iterator MapIterator;
222 std::vector<MapIterator> helper_vector;
229 helper_vector.push_back(it);
233 #pragma omp parallel for schedule(static)
234 for (
size_t it=0; it<helper_vector.size(); ++it) {
235 helper_vector[it]->second->collectVelocity();
239 void SimulationRunner::calculateForce() {
244 void SimulationRunner::collide() {
245 #pragma omp parallel for schedule(dynamic)
248 for (
unsigned int i = 0;
251 nodes::PhysicalNode* node =
253 node->getFluidSolver().collide();
254 for (
auto j = node->getCDESolvers().begin();
255 j != node->getCDESolvers().end();
263 void SimulationRunner::advect() {
264 #pragma omp parallel for schedule(dynamic)
268 for (
unsigned int i = 0;
272 nodes::PhysicalNode* node =
274 node->getFluidSolver().advect();
275 for (
auto j = node->getCDESolvers().begin();
276 j != node->getCDESolvers().end();
284 for (
const auto bd : it->getBoundarySolvers()) {
297 i->getFluidSolver().initSolver();
298 for (
const auto& cde : i->getCDESolvers()) {
312 i->getFluidSolver().setVelocity(fluidVelocity);
313 i->getFluidSolver().initSolver();
314 for (
const auto& cde : i->getCDESolvers()) {
322 void SimulationRunner::preAdvect() {
323 typedef std::unordered_set<nodes::BoundaryNode*>::const_iterator ListIterator;
324 std::vector<ListIterator> helper_vector;
327 std::unordered_set<nodes::BoundaryNode*> tempBoundaryNodes = this->geometryHandler_.
getBoundaryNodes();
328 for (ListIterator it=tempBoundaryNodes.begin();
329 it != tempBoundaryNodes.end();
331 helper_vector.push_back(it);
334 #pragma omp parallel for schedule(dynamic)
336 it<helper_vector.size();
338 for (
const auto bd : (*helper_vector[it])->getBoundarySolvers()) {
339 bd.second->preAdvect();
344 void SimulationRunner::postAdvect() {
345 typedef std::unordered_set<nodes::BoundaryNode*>::const_iterator ListIterator;
346 std::vector<ListIterator> helper_vector;
349 std::unordered_set<nodes::BoundaryNode*> tempBoundaryNodes = this->geometryHandler_.
getBoundaryNodes();
350 for (ListIterator it=tempBoundaryNodes.begin();
351 it != tempBoundaryNodes.end();
353 helper_vector.push_back(it);
356 #pragma omp parallel for schedule(dynamic)
358 it<helper_vector.size();
360 for (
const auto bd : (*helper_vector[it])->getBoundarySolvers()) {
361 bd.second->postAdvect();
366 void SimulationRunner::applyMassSolvers()
368 for (
auto it : this->massSolvers_) {
373 void SimulationRunner::applyBioSolvers()
375 for (
auto it : this->bioSolvers_) {
376 (*it).applyBioProcess(const_cast<geometry::GeometryHandler&>(this->geometryHandler_),
383 void SimulationRunner::addCDESolver(
const std::string& name) {
387 i->addCDESolver(name);
398 return this->forceSolver_;
410 void SimulationRunner::setTau(
412 const std::string& name) {
417 i->getFluidSolver().setTau(tau);
419 i->getCDESolverSlow(name).setTau(tau);
425 void SimulationRunner::distributeForce() {
426 typedef std::map<unsigned int,std::shared_ptr<nodes::GeometryNode> >::const_iterator MapIterator;
429 #pragma omp parallel for collapse(1) schedule(dynamic)
440 std::vector<MapIterator> helper_vector;
444 helper_vector.push_back(it);
449 #pragma omp parallel for schedule(static)
450 for (
size_t it=0; it< helper_vector.size(); ++it) {
451 helper_vector[it]->second->distributeForce();
void addMassSolver(const std::string &name)
adds a mass solver to the simulation
~SimulationRunner()
Destructor.
SimulationRunner(const geometry::GeometryHandler &geometry, const reportHandler::ReportHandler &reportHandler)
constructor
void initSolvers()
initSolvers Initialises the solvers
const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > & getGeometryNodes() const
Getter for the geometry nodes.
void runSimulation()
runSimulation Runs the main Simulation loop
void addBioSolver(const std::string &name)
Adds a BioSolver.
bool checkGeometryIntegrity(void) const
checkGeometryIntegrity
a class for reporting the current simulation status. Usage: construct an object of this class with th...
const Geometry & getGeometry() const
getter for the geometry
const solver::ForceSolver & getForceSolver(void)
getForceSolver Returns a reference to the solver::ForceSolver
void writeSimulation(const std::string &forceFileName, const std::string &geometryFileName, const std::string ¶meterFileName, const std::string &solverFileName) const
writes the simulation to the files
void writeForceSolver(const std::string &filename) const
writes the forces to the file
void initForceSolver(const std::string &fileName)
Inits the Force solver to calculate the forces on the geometry nodes.
void writeCrashReport(unsigned int time) const
writeCrashReport Dumps the reporters when crashed.
const std::unordered_set< nodes::BoundaryNode * > & getBoundaryNodes() const
Getter for the Boundary nodes.
void writeReport(unsigned int time) const
writeReport Writes the report if the time step fits to the reportStep
void writeGeometry(const std::string &fileName) const
writeGeometry Writes the geometry to the file
void loadForceFile(const std::string &filename)
loading of the force solver
const std::vector< std::vector< nodes::PhysicalNode * > > & getPhysicalNodes() const
getPhysicalNodes Getter method for the physical node grid
the report handler which stores the reporters
class responsible for generating the internal geometry representation
void deleteAllForces()
reset all forces
void calculateForce(const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > &nodes)
calculates the Force