LBIBCell
 All Classes Functions Variables Friends Pages
tutorial_02.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 
44 int main(
45  int argc,
46  char* argv[]) {
47  try {
48  std::stringstream fileName;
49 
50  //create output folder and clear content:
51  std::string outfolder = "output/";
52  const int mk = mkdir(outfolder.c_str(), 0777);
53  if (mk==1) {
54  lbm_fail("Cannot create the output directory.");
55  }
56  auto ret = system("exec rm -r output/*");
57 
58  //set up log facility:
59  std::shared_ptr<std::ostream> pStream(new std::ofstream(outfolder+"log.txt"));
60  if (!pStream) {
61  lbm_fail("Cannot open the log file.");
62  }
63  UtilLib::Log::setStream(pStream);
64 
65  LbmLib::Parameters.loadGlobalSimulationParameters("config/tutorial_02_parameters.txt");
66  LbmLib::Parameters.printParameters();
67 
68  //LbmLib::geometry::Geometry geo("config/tutorial_02_geometry.txt");
69  LbmLib::geometry::Geometry geo("config/vtk/Cells_10000.vtm");
71 
73  LbmLib::Parameters.getReportSteps());
74 
75  LbmLib::SimulationRunner simRunner(build, reporter);
76 
77  // vtk cell reporter:
78  fileName.str("");
79  fileName << outfolder+"Cells";
80  reporter.registerReporter(std::unique_ptr < LbmLib::reportHandler::
81  AbstractReportFunctor > (new LbmLib::reportHandler::
82  vtkCellReporter(
83  geo.getConnections(),
84  build.getCellTypeTrackerMap(),
85  fileName.str()
86  )
87  )
88  );
89 
90  // vtk force reporter:
91  fileName.str("");
92  fileName << outfolder+"Cells";
93  reporter.registerReporter(std::unique_ptr < LbmLib::reportHandler::
94  AbstractReportFunctor > (new LbmLib::reportHandler::
95  vtkForceReporter(
96  geo.getGeometryNodes(),
97  simRunner.getForceSolver(),
98  fileName.str()
99  )
100  )
101  );
102 
103  // vtk CDE reporter:
104  fileName.str("");
105  fileName << outfolder+"Cells";
106  reporter.registerReporter(std::unique_ptr < LbmLib::reportHandler::
107  AbstractReportFunctor > (new LbmLib::reportHandler::
108  vtkCDEReporter(
109  build.getPhysicalNodes(),
110  1, // cde coarseningfactor; 1=full resolution
111  fileName.str()
112  )
113  )
114  );
115 
116  // vtk fluid reporter:
117  fileName.str("");
118  fileName << outfolder+"Cells";
119  reporter.registerReporter(std::unique_ptr < LbmLib::reportHandler::
120  AbstractReportFunctor > (new LbmLib::reportHandler::
121  vtkFluidReporter(
122  build.getPhysicalNodes(),
123  4, // cde coarseningfactor; 1=full resolution
124  fileName.str()
125  )
126  )
127  );
128 
129  simRunner.initSolvers();
130  simRunner.initForceSolver("config/force.txt");
131 
132  simRunner.addMassSolver("MassSolverBoxOutlet");
133  simRunner.addBioSolver("tutorial_02_BioSolverGrowth");
134  simRunner.addBioSolver("tutorial_02_BioSolverMembraneTension");
135  simRunner.addBioSolver("tutorial_02_BioSolverCellJunction");
136  simRunner.addBioSolver("tutorial_02_BioSolverCellDivision");
137 
138 
139  simRunner.runSimulation();
140 
141  } catch(const std::exception& exp) {
142  std::cout << exp.what() << std::endl;
143  }
144 
145  return 0;
146 }
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