LBIBCell
 All Classes Functions Variables Friends Pages
tutorial_01.cpp
1 /* Copyright (c) 2013 David Sichau <mail"at"sichau"dot"eu>
2  * 2013-2015 Simon Tanaka <tanakas"at"gmx"dot"ch>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 #include <LbmLib/include/geometry/Geometry.hpp>
23 #include <LbmLib/include/geometry/GeometryHandler.hpp>
24 #include <LbmLib/include/SimulationRunner.hpp>
25 
26 #include <LbmLib/include/reportHandler/ReportHandler.hpp>
27 #include <LbmLib/include/reportHandler/vtkCellReporter.hpp>
28 #include <LbmLib/include/reportHandler/vtkForceReporter.hpp>
29 #include <LbmLib/include/reportHandler/vtkCDEReporter.hpp>
30 #include <LbmLib/include/reportHandler/vtkFluidReporter.hpp>
31 #include <LbmLib/include/reportHandler/vtkCellPNGReporter.hpp>
32 
33 #include <iostream>
34 #include <string>
35 #include <fstream>
36 #include <sys/stat.h>
37 
38 int main(
39  int argc,
40  char* argv[]) {
41  try {
42  std::stringstream fileName;
43 
44  //create output folder and clear content:
45  std::string outfolder = "output/";
46  const int mk = mkdir(outfolder.c_str(), 0777);
47  if (mk==1) {
48  lbm_fail("Cannot create the output directory.");
49  }
50  auto ret = system("exec rm -r output/*");
51 
52  //set up log facility:
53  std::shared_ptr<std::ostream> pStream(new std::ofstream(outfolder+"log.txt"));
54  if (!pStream) {
55  lbm_fail("Cannot open the log file.");
56  }
57  UtilLib::Log::setStream(pStream);
58 
59  LbmLib::Parameters.loadGlobalSimulationParameters("config/tutorial_01_parameters.txt");
60  LbmLib::Parameters.printParameters();
61 
62  //LbmLib::geometry::Geometry geo("config/tutorial_01_geometry.txt");
63  LbmLib::geometry::Geometry geo("config/vtk/Cells_0.vtm");
64  LbmLib::geometry::GeometryHandler geohandler(geo);
65 
67  LbmLib::Parameters.getReportSteps());
68 
69  LbmLib::SimulationRunner simRunner(geohandler, reporter);
70 
71  // vtk cell reporter:
72  fileName.str("");
73  fileName << outfolder+"Cells";
74  reporter.registerReporter(std::unique_ptr < LbmLib::reportHandler::
75  AbstractReportFunctor > (new LbmLib::reportHandler::
76  vtkCellReporter(
77  geo.getConnections(),
78  geohandler.getCellTypeTrackerMap(),
79  fileName.str()
80  )
81  )
82  );
83 
84  // vtk cell PNG reporter:
85  fileName.str("");
86  fileName << outfolder+"Cells";
87  reporter.registerReporter(std::unique_ptr < LbmLib::reportHandler::
88  AbstractReportFunctor > (new LbmLib::reportHandler::
89  vtkCellPNGReporter(
90  geo.getConnections(),
91  fileName.str()
92  )
93  )
94  );
95 
96  // vtk force reporter:
97  fileName.str("");
98  fileName << outfolder+"Cells";
99  reporter.registerReporter(std::unique_ptr < LbmLib::reportHandler::
100  AbstractReportFunctor > (new LbmLib::reportHandler::
101  vtkForceReporter(
102  geo.getGeometryNodes(),
103  simRunner.getForceSolver(),
104  fileName.str()
105  )
106  )
107  );
108 
109  // vtk CDE reporter:
110  fileName.str("");
111  fileName << outfolder+"Cells";
112  reporter.registerReporter(std::unique_ptr < LbmLib::reportHandler::
113  AbstractReportFunctor > (new LbmLib::reportHandler::
114  vtkCDEReporter(
115  geohandler.getPhysicalNodes(),
116  1, // cde coarseningfactor; 1=full resolution
117  fileName.str()
118  )
119  )
120  );
121 
122  // vtk fluid reporter:
123  fileName.str("");
124  fileName << outfolder+"Cells";
125  reporter.registerReporter(std::unique_ptr < LbmLib::reportHandler::
126  AbstractReportFunctor > (new LbmLib::reportHandler::
127  vtkFluidReporter(
128  geohandler.getPhysicalNodes(),
129  4, // cde coarseningfactor; 1=full resolution
130  fileName.str()
131  )
132  )
133  );
134 
135  simRunner.initSolvers();
136  simRunner.initForceSolver("config/force.txt");
137 
138  simRunner.addMassSolver("MassSolverBoxOutlet");
139  simRunner.addBioSolver("tutorial_01_BioSolverAreaRegulator");
140  simRunner.addBioSolver("tutorial_01_BioSolverMembraneTension");
141  simRunner.addBioSolver("tutorial_01_BioSolverCellJunction");
142  simRunner.addBioSolver("tutorial_01_BioSolverDifferentiation");
143  simRunner.addBioSolver("tutorial_01_BioSolverCellDivision");
144 
145  simRunner.runSimulation();
146 
147  } catch(const std::exception& exp) {
148  std::cout << exp.what() << std::endl;
149  }
150 
151  return 0;
152 }
the main simulation class
void loadGlobalSimulationParameters(const std::string &fileName)
loads the parameters from the file
static void setStream(std::shared_ptr< std::ostream > pStream)
Definition: Log.cpp:91
void printParameters() const
prints the parameters to the standard output
class representing the external geometry
Definition: Geometry.hpp:68
the report handler which stores the reporters
class responsible for generating the internal geometry representation