LBIBCell
 All Classes Functions Variables Friends Pages
BioSolverCellJunction.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/BioSolverCellJunction.hpp>
23 #include <LbmLib/include/nodes/GeometryNode.hpp>
24 #include <LbmLib/include/geometry/GeometryHandler.hpp>
25 #include <LbmLib/include/solver/ForceSolver.hpp>
26 #include <LbmLib/include/GlobalSimulationParameters.hpp>
27 #include <vector>
28 #include <string>
29 #include <iostream>
30 #include <random>
31 #include <memory>
32 #include <omp.h>
33 
34 namespace LbmLib {
35 namespace solver {
36 namespace {
37  const unsigned int FREQUENCY = 10;
38  const int seed = 1;
39  static std::mt19937 gen(seed);
40  //static std::random_device rd;
41  //static std::mt19937 gen(rd());
42  std::uniform_int_distribution<> dis(1,2);
43  std::stringstream forcedescriptor;
44  const double RADIUS = 1.0;
45  const double K = 0.02;
46  const double L0 = 0.5;
47 }
48 
49 BioSolverCellJunction::BioSolverCellJunction() : BioBaseSolver()
50 {}
51 
53  geometry::GeometryHandler& geometryhandler,
54  solver::ForceSolver& forcesolver
55  ) {
56  if (Parameters.getCurrentIteration()%FREQUENCY != 0) {
57  return;
58  }
59 
60  // step 1: delete old junctions
61  forcesolver.deleteForceType(7);
62 
63  // step 2: build new junctions
64  auto tempnodesmap = geometryhandler.getGeometry().getGeometryNodes();
65  auto nodes_length = tempnodesmap.size();
66  std::vector<std::map<unsigned int,std::shared_ptr<nodes::GeometryNode> >::const_iterator> helper_nodes;
67  auto nodes_it = tempnodesmap.begin();
68 
69  // create array of iterators sequentally:
70  for (size_t j=0;
71  j<nodes_length;
72  ++j) {
73  helper_nodes.push_back(nodes_it++);
74  }
75 
76 #pragma omp parallel for schedule(static) private(forcedescriptor)
77  for (size_t j=0;
78  j<nodes_length;
79  ++j) {
80  std::shared_ptr<nodes::GeometryNode> closestnode =
81  geometryhandler.getGeometry().getGeometryNodesWithinRadiusWithAvoidanceClosest(helper_nodes[j]->second->getXPos(),
82  helper_nodes[j]->second->getYPos(),
83  RADIUS,
84  helper_nodes[j]->second->getDomainIdOfAdjacentConnections());
85  if (closestnode != nullptr) {
86  forcedescriptor.str( std::string() ); // reset
87  forcedescriptor.clear(); //clear flags
88  forcedescriptor << "7\t" // type
89  << helper_nodes[j]->second->getId() << "\t" // nodeID 1
90  << closestnode->getId() << "\t" // nodeID 2
91  << K << "\t" // spring constant
92  << L0; // resting length
93  forcesolver.addForce(&forcedescriptor);
94 
95  forcedescriptor.str( std::string() ); // reset
96  forcedescriptor.clear(); //clear flags
97  forcedescriptor << "7\t" // type
98  << closestnode->getId() << "\t" // nodeID 1
99  << helper_nodes[j]->second->getId() << "\t" // nodeID 2
100  << K << "\t" // spring constant
101  << L0; // resting length
102  forcesolver.addForce(&forcedescriptor);
103  }
104  }
105 }
106 
107 const std::string BioSolverCellJunction::name = "BioSolverCellJunction";
108 }
109 } // end namespace
110 
virtual void applyBioProcess(geometry::GeometryHandler &geometryhandler, solver::ForceSolver &forcesolver)
Applies biological processes.
void deleteForceType(const unsigned int forcetype)
reset all forces
The actual force solver.
Definition: ForceSolver.hpp:43
const std::map< unsigned int, std::shared_ptr< nodes::GeometryNode > > & getGeometryNodes() const
Getter for the geometry nodes.
Definition: Geometry.hpp:92
const Geometry & getGeometry() const
getter for the geometry
void addForce(std::stringstream *const forcedescriptor)
add a force
std::shared_ptr< nodes::GeometryNode > getGeometryNodesWithinRadiusWithAvoidanceClosest(const double x, const double y, const double radius, const unsigned int avoidDomainID) const
getGeometryNodesWithinRadiusWithAvoidanceClosest Return closest GeometryNode, but only nodes with dom...
Definition: Geometry.cpp:366
class responsible for generating the internal geometry representation