VPTissue Reference Manual
DHelper.h
Go to the documentation of this file.
1 #ifndef SIMPT_DEFAULT_DELTA_HAMILTONIAN_DHELPER_H_INCLUDED
2 #define SIMPT_DEFAULT_DELTA_HAMILTONIAN_DHELPER_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include "bio/Cell.h"
23 #include "bio/Node.h"
24 #include "bio/Wall.h"
25 #include "math/array3.h"
26 #include "math/Geom.h"
28 
29 #include <array>
30 
31 using namespace std;
32 using namespace boost::property_tree;
33 
34 namespace SimPT_Default {
35 namespace DeltaHamiltonian {
36 
37 using namespace SimPT_Sim;
38 
42 class DHelper
43 {
44 public:
48  static double AlignmentTerm(
49  const std::array<double, 3>& old_axis, const std::array<double, 3>& new_axis)
50  {
51  // orth_alignment orthogonal to intended alignment.
52  const auto old_a = Normalize(old_axis);
53  const auto new_a = Normalize(new_axis);
54  const array<double, 3> orth_alignment {{-1.0, 0.0, 0.0}};
55  const double alignment_old = InnerProduct(old_a, orth_alignment);
56  const double alignment_new = InnerProduct(new_a, orth_alignment);
57 
58  return (alignment_old - alignment_new);
59  }
60 
66  static double BendingTerm(
67  const array<double, 3>& nb1_p, const array<double, 3>& nb2_p,
68  const array<double, 3>& now_p, const array<double, 3>& mov_p)
69  {
70  auto t1 = Geom::CircumCircle(nb1_p[0], nb1_p[1], now_p[0], now_p[1], nb2_p[0], nb2_p[1]);
71  double const r1 = get<2>(t1);
72  auto t2 = Geom::CircumCircle(nb1_p[0], nb1_p[1], mov_p[0], mov_p[1], nb2_p[0], nb2_p[1]);
73  double const r2 = get<2>(t2);
74  assert(r1 > 0.0 && r2 > 0.0 && "Circumcenter radius singular!");
75 
76  return pow((1.0 / r2 - 1.0 / r1), 2);
77  }
78 
82  static double ElasticWallTerm(
83  const Cell* cell, Node* n, const std::list<Wall*>& node_owning_walls, double stiffness,
84  const std::array<double, 3>& nb1_p, const std::array<double, 3>& nb2_p,
85  const std::array<double, 3>& now_p, const std::array<double, 3>& mov_p)
86  {
87  double contrib = 0.0;
88  for (auto& wall : node_owning_walls) {
89 
90  const auto& c1 = wall->GetC1();
91  const auto& c2 = wall->GetC2();
92  if (c1 == cell || c2 == cell) {
93 
94  const bool check = (cell == c1 || cell->IsBoundaryPolygon());
95  const auto wall_beg = check ? wall->GetN1() : wall->GetN2();
96  const auto wall_end = check ? wall->GetN2() : wall->GetN1();
97  const auto stiff = (c1->IsBoundaryPolygon() || c2->IsBoundaryPolygon()) ? stiffness * wall->GetStrength() : 1.0 * wall->GetStrength();
98  const auto rest_l = wall->GetRestLength();
99  const auto old_l = wall->GetLength();
100 
101  double new_l = old_l;
102  new_l += (n != wall_beg) ? Norm(mov_p - nb1_p) - Norm(now_p - nb1_p) : 0.0;
103  new_l += (n != wall_end) ? Norm(nb2_p - mov_p) - Norm(nb2_p - now_p) : 0.0;
104  contrib += stiff * (pow(new_l - rest_l, 2) - pow(old_l - rest_l, 2)) / (2.0 * rest_l);
105  }
106  }
107  return contrib;
108  }
109 };
110 
111 } // namespace
112 } // namespace
113 
114 #endif // end-of-include-guard
STL namespace.
A cell contains walls and nodes.
Definition: Cell.h:48
Node in cell wall.
Definition: Node.h:39
Combo header for circular iterator.
Namespace for components of the Default model group.
Namespace for the core simulator.
Interface for Cell.
Interface for Node.
Helper function for writing DeltaHamiltonians.
Definition: DHelper.h:42
Interface for Geom.
Extending std with arithmetic for std::array.
static double AlignmentTerm(const std::array< double, 3 > &old_axis, const std::array< double, 3 > &new_axis)
Alignment term.
Definition: DHelper.h:48
static double ElasticWallTerm(const Cell *cell, Node *n, const std::list< Wall * > &node_owning_walls, double stiffness, const std::array< double, 3 > &nb1_p, const std::array< double, 3 > &nb2_p, const std::array< double, 3 > &now_p, const std::array< double, 3 > &mov_p)
Elastic wall term.
Definition: DHelper.h:82
static double BendingTerm(const array< double, 3 > &nb1_p, const array< double, 3 > &nb2_p, const array< double, 3 > &now_p, const array< double, 3 > &mov_p)
Bending term.
Definition: DHelper.h:66
Interface for Wall.