LBIBCell
 All Classes Functions Variables Friends Pages
tutorial_02_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/tutorial_02_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 double RADIUS = 1.0;
39  const double K = 0.02;
40  const double L0 = 0.5;
41  std::stringstream forcedescriptor;
42 }
43 
44 tutorial_02_BioSolverCellJunction::tutorial_02_BioSolverCellJunction() : BioBaseSolver()
45 {}
46 
48  geometry::GeometryHandler& geometryhandler,
49  solver::ForceSolver& forcesolver
50  ) {
51  if (Parameters.getCurrentIteration()%FREQUENCY != 0) {
52  return;
53  }
54 
55  // delete old junctions
56  forcesolver.deleteForceType(7);
57 
58  // build new junctions
59  auto tempnodesmap = geometryhandler.getGeometry().getGeometryNodes();
60  auto nodes_length = tempnodesmap.size();
61  std::vector<std::map<unsigned int,std::shared_ptr<nodes::GeometryNode> >::const_iterator> helper_nodes;
62  auto nodes_it = tempnodesmap.begin();
63 
64  // create array of iterators sequentally:
65  for (size_t j=0;
66  j<nodes_length;
67  ++j) {
68  helper_nodes.push_back(nodes_it++);
69  }
70 
71 #pragma omp parallel for schedule(static) private(forcedescriptor)
72  for (size_t j=0;
73  j<nodes_length;
74  ++j) {
75  std::shared_ptr<nodes::GeometryNode> closestnode =
76  geometryhandler.getGeometry().getGeometryNodesWithinRadiusWithAvoidanceClosest(helper_nodes[j]->second->getXPos(),
77  helper_nodes[j]->second->getYPos(),
78  RADIUS,
79  helper_nodes[j]->second->getDomainIdOfAdjacentConnections());
80  if (closestnode != nullptr) {
81  forcedescriptor.str( std::string() ); // reset
82  forcedescriptor.clear(); //clear flags
83  forcedescriptor << "7\t" // type
84  << helper_nodes[j]->second->getId() << "\t" // nodeID 1
85  << closestnode->getId() << "\t" // nodeID 2
86  << K << "\t" // spring constant
87  << L0; // resting length
88  forcesolver.addForce(&forcedescriptor);
89 
90  forcedescriptor.str( std::string() ); // reset
91  forcedescriptor.clear(); //clear flags
92  forcedescriptor << "7\t" // type
93  << closestnode->getId() << "\t" // nodeID 1
94  << helper_nodes[j]->second->getId() << "\t" // nodeID 2
95  << K << "\t" // spring constant
96  << L0; // resting length
97  forcesolver.addForce(&forcedescriptor);
98  }
99  }
100 }
101 
102 const std::string tutorial_02_BioSolverCellJunction::name = "tutorial_02_BioSolverCellJunction";
103 }
104 } // end namespace
105 
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
virtual void applyBioProcess(geometry::GeometryHandler &geometryhandler, solver::ForceSolver &forcesolver)
Applies biological processes.
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