VPTissue Reference Manual
delta_hamiltonian/ModifiedGC.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "ModifiedGC.h"
21 
22 #include "bio/Cell.h"
23 #include "bio/GeoData.h"
24 #include "bio/Mesh.h"
25 #include "bio/NeighborNodes.h"
26 #include "bio/Node.h"
27 #include "math/Geom.h"
28 #include "sim/CoreData.h"
30 
31 #include <cassert>
32 
33 using namespace std;
34 using namespace boost::property_tree;
35 
36 namespace SimPT_Default {
37 namespace DeltaHamiltonian {
38 
39 ModifiedGC::ModifiedGC(const CoreData& cd)
40 {
41  assert( cd.Check() && "CoreData not ok in ModifiedGC DeltaHamiltonian");
42  Initialize(cd);
43 }
44 
45 void ModifiedGC::Initialize(const CoreData& cd)
46 {
47  m_mesh = cd.m_mesh.get();
48  const auto& p = cd.m_parameters->get_child("cell_mechanics");
49 
50  m_lambda_bend = p.get<double>("lambda_bend");
51  m_lambda_cell_length = p.get<double>("lambda_celllength");
52  m_lambda_length = p.get<double>("lambda_length");
53  m_rp_stiffness = p.get<double>("relative_perimeter_stiffness");
54  m_target_node_distance = p.get<double>("target_node_distance");
55 }
56 
57 double ModifiedGC::operator()(const NeighborNodes& nb, Node* n, std::array<double, 3> move)
58 {
59  double dh = 0.0;
60 
61  const Cell* cell = nb.GetCell();
62  const auto& nb1 = nb.GetNb1();
63  const auto& nb2 = nb.GetNb2();
64  const array<double, 3> now_p = *n;
65  const array<double, 3> mov_p = now_p + move;
66  const array<double, 3> nb1_p = *nb1;
67  const array<double, 3> nb2_p = *nb2;
68  const auto& owningWalls = m_mesh->GetNodeOwningWalls(n);
69 
70  if (!cell->IsBoundaryPolygon()) {
71 
72  // --------------------------------------------------------------------------------------------
73  // Cell area:
74  // --------------------------------------------------------------------------------------------
75  const auto del_area = 0.5 * ((mov_p[0] - now_p[0]) * (nb1_p[1] - nb2_p[1])
76  + (mov_p[1] - now_p[1]) * (nb2_p[0] - nb1_p[0]));
77  const auto old_area = cell->GetArea();
78  const auto tar_area = cell->GetTargetArea();
79  const auto old_fact = (old_area - tar_area) / old_area;
80  const auto new_fact = (old_area - del_area - tar_area) / (old_area - del_area);
81 
82  dh += 1000 * (new_fact * new_fact - old_fact * old_fact);
83 
84  // --------------------------------------------------------------------------------------------
85  // Wall length:
86  // --------------------------------------------------------------------------------------------
87  const auto old1 = Norm(now_p - nb1_p) - m_target_node_distance;
88  const auto old2 = Norm(now_p - nb2_p) - m_target_node_distance;
89  const auto new1 = Norm(mov_p - nb1_p) - m_target_node_distance;
90  const auto new2 = Norm(mov_p - nb2_p) - m_target_node_distance;
91 
92  const bool at_b = n->IsAtBoundary();
93  double w1 = (at_b && nb1->IsAtBoundary()) ? m_rp_stiffness : 1.0;
94  double w2 = (at_b && nb2->IsAtBoundary()) ? m_rp_stiffness : 1.0;
95 
96  for (auto& wall : owningWalls) {
97  if (wall->GetC1() == cell || wall->GetC2() == cell) {
98  const auto w = wall->GetStrength();
99  const auto n1 = wall->GetN1();
100  const auto n2 = wall->GetN2();
101 
102  if ( ((n1 == n) && (n2 == nb1)) || ((n2 == n) && (n1 == nb1)) ) {
103  w1 = (at_b && nb1->IsAtBoundary()) ? m_rp_stiffness * w : w;
104  }
105  if ( ((n1 == n) && (n2 == nb2)) || ((n2 == n) && (n1 == nb2)) ) {
106  w2 = (at_b && nb2->IsAtBoundary()) ? m_rp_stiffness * w : w;
107  }
108  }
109  }
110 
111  dh += m_lambda_length * (w1 * (new1 * new1 - old1 * old1) + w2 * (new2 * new2 - old2 * old2));
112  }
113 
114  return dh;
115 }
116 
117 } // namespace
118 } // namespace
Core data with mesh, parameters, random engine and time data.
Definition: CoreData.h:38
STL namespace.
A cell contains walls and nodes.
Definition: Cell.h:48
Node in cell wall.
Definition: Node.h:39
Cell * GetCell() const
Return the cell of this Neighbor pair.
Core data used during model execution.
Combo header for circular iterator.
Interface for NeighborNodes.
Interface for DeltaHamiltonian::ModifiedGC.
Interface/Implementation for GeoData.
Namespace for components of the Default model group.
Interface for Cell.
Node * GetNb1() const
Return first node of this Neighbor pair.
Structure of neighboring nodes: two neighboring nodes from standpoint of a given cell with an orderin...
Definition: NeighborNodes.h:34
Interface for Node.
Node * GetNb2() const
Return second node of this Neighbor pair.
Interface for Geom.
double GetArea() const
Return the area of the cell.
Definition: Cell.cpp:178
bool Check() const
Verify all pointers non-null.
Definition: CoreData.h:53
Interface for Mesh.