LBIBCell
 All Classes Functions Variables Friends Pages
tutorial_01_BioSolverAreaRegulator.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/solver/BioSolver/tutorial_01_BioSolverAreaRegulator.hpp>
23 #include <LbmLib/include/GlobalSimulationParameters.hpp>
24 #include <LbmLib/include/geometry/GeometryHandler.hpp>
25 #include <LbmLib/include/nodes/PhysicalNode.hpp>
26 #include <vector>
27 #include <string>
28 #include <iostream>
29 #include <omp.h>
30 
31 namespace LbmLib {
32 namespace solver {
33 namespace {
34  const unsigned int FREQUENCY = 1;
35  const double TARGETAREA = 200.0;
36  const double KP = 0.00001;
37  const double MAXSOURCE = 0.004;
38 }
39 
40 tutorial_01_BioSolverAreaRegulator::tutorial_01_BioSolverAreaRegulator() : BioBaseSolver()
41 {}
42 
44  geometry::GeometryHandler& geometryhandler,
45  solver::ForceSolver& forcesolver
46  ) {
47  std::map<unsigned int,double> areas;
48  std::map<unsigned int,double> sourcemap;
49  unsigned int domainid;
50 
51  if (Parameters.getCurrentIteration()%FREQUENCY != 0) {
52  return;
53  }
54 
55  // compute areas
56  areas = geometryhandler.computeAreas();
57 
58  // update targetareamap
59  for (auto it : areas) {
60  if ( this->targetareamap_.find(it.first) == this->targetareamap_.end() ) { // not existing yet
61  this->targetareamap_[it.first] = TARGETAREA; // default
62  }
63  }
64 
65  // compute source
66  for (auto it : areas) {
67  sourcemap[it.first] = KP*(this->targetareamap_[it.first] - areas[it.first]);
68  }
69 
70  // modify the sourcemap
71  for (auto it : sourcemap)
72  {
73  if (sourcemap[it.first] > MAXSOURCE) { // upper threshold
74  sourcemap[it.first] = MAXSOURCE;
75  }
76  else if (sourcemap[it.first] < -MAXSOURCE) {
77  sourcemap[it.first] = -MAXSOURCE; // lower threshold
78  }
79  }
80 
81  // add mass to the cells
82 #pragma omp parallel for schedule(dynamic) private(domainid)
83  for (unsigned int ity = 0;
84  ity < geometryhandler.getPhysicalNodes().size();
85  ity++) { // loop y direction
86  for (unsigned int itx = 0;
87  itx < geometryhandler.getPhysicalNodes()[0].size();
88  itx++) { // loop x direction
89  domainid = geometryhandler.getPhysicalNodes()[ity][itx]->getDomainIdentifier();
90  if (domainid != 0) {
91  if (geometryhandler.getPhysicalNodes()[ity][itx]->getCellType()==1) { // max prolif for celltype=1
92  geometryhandler.getPhysicalNodes()[ity][itx]->getFluidSolver().addMass(MAXSOURCE);
93  }
94  else { // regulated area for other celltypes
95  geometryhandler.getPhysicalNodes()[ity][itx]->getFluidSolver().addMass(sourcemap[domainid]);
96  }
97  }
98  }
99  }
100 }
101 
102 const std::string tutorial_01_BioSolverAreaRegulator::name = "tutorial_01_BioSolverAreaRegulator";
103 }
104 } // end namespace
The actual force solver.
Definition: ForceSolver.hpp:43
const std::map< unsigned int, double > computeAreas() const
Compute the areas of the domains by using the domainIdentifiers.
virtual void applyBioProcess(geometry::GeometryHandler &geometryhandler, solver::ForceSolver &forcesolver)
Applies biological processes.
const std::vector< std::vector< nodes::PhysicalNode * > > & getPhysicalNodes() const
getPhysicalNodes Getter method for the physical node grid
class responsible for generating the internal geometry representation