VPTissue Reference Manual
NodeMover.h
Go to the documentation of this file.
1 #ifndef NODE_MOVER_H_INCLUDED
2 #define NODE_MOVER_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 "math/CSRMatrix.h"
24 #include "sim/CoreData.h"
25 
26 #include <boost/property_tree/ptree.hpp>
27 #include <array>
28 #include <map>
29 #include <memory>
30 #include <set>
31 #include <unordered_set>
32 #include <vector>
33 
34 //#define EDGE_BASED_INC
35 
36 namespace SimPT_Sim {
37 
38 class Cell;
39 class Mesh;
40 class Node;
41 class Sim;
42 
46 class NodeMover
47 {
48 public:
53  {
54  MetropolisInfo(unsigned int dc = 0U, unsigned int uc = 0U, double dd = 0.0, double ud = 0.0)
55  : down_count(dc), up_count(uc), down_dh(dd), up_dh(ud)
56  {}
57  unsigned int down_count;
58  unsigned int up_count;
59  double down_dh;
60  double up_dh;
61 
62  MetropolisInfo& operator+=(const MetropolisInfo& other)
63  {
64  down_count += other.down_count;
65  up_count += other.up_count;
66  down_dh += other.down_dh;
67  up_dh += other.up_dh;
68  return *this;
69  }
70  };
71 
75  struct MoveInfo
76  {
77  MoveInfo(Node* no = nullptr, bool da = false, bool ma = false,
78  double sd = 0.0, std::array<double, 3> d = {{0.0, 0.0, 0.0}})
79  : node(no), dh_accept(da), mc_accept(ma), dh(sd), displacement(d)
80  {}
81  Node* node;
82  bool dh_accept;
83  bool mc_accept;
84  double dh;
85  std::array<double,3> displacement;
86  };
87 
88 public:
90  NodeMover();
91 
93  NodeMover(const CoreData& cd);
94 
96  double GetTissueEnergy() const { return m_tissue_energy; }
97 
99  void Initialize(const CoreData& cd);
100 
102  MetropolisInfo SweepOverNodes(double step_size, double temperature);
103 
104 // /// Sweep over all nodes, do metropolis move for each of them.
105 // /// Uses parallization based on node-cell-node incidence.
106 // MetropolisInfo SweepOverNodes(const CSRMatrix& nci, double step_size, double temperature);
107 //
108 // /// Sweep over all nodes, do metropolis move for each of them.
109 // /// Uses parallelization based on node-edge-node incidence and
110 // /// can only be used with the DeltaHamiltonian approach.
111 // MetropolisInfo SweepOverNodes(const CSRMatrix& nci, const CSRMatrix& nei, double step_size, double temperature);
112 //
114  inline bool UsesDeltaHamiltonian() const { return m_delta_hamiltonian != nullptr; }
115 
116 private:
118  void CalculateCellEnergies();
119 
121  void CalculateCellEnergiesDelta();
122 
123 // /// Calculate lookahead blocks with node-cell-node incidence.
124 // std::vector<size_t> GetLookaheadsByCells(const std::vector<unsigned int>& indices, const CSRMatrix& nci) const;
125 //
126 // /// Calculate lookahead blocks with node-edge-node incidence.
127 // std::vector<size_t> GetLookaheadsByEdges(const std::vector<unsigned int>& indices, const CSRMatrix& nni) const;
128 
130  bool IsNonIntersecting(Node* node, const std::array<double, 3>& move) const;
131 
133  MetropolisInfo MoveNode(Node* n, double step_size, double temperature);
134 
136  MetropolisInfo MoveNodeDelta(Node* n, double step_size, double temperature);
137 
139  MoveInfo MoveAcceptance(Node* node, double step_size, double temperature);
140 
142  MetropolisInfo MoveExecution(const MoveInfo& move);
143 
144 private:
145  CoreData m_cd;
146  std::map<Cell*, double> m_cell_energies;
147  HamiltonianComponent m_hamiltonian;
148  DeltaHamiltonianComponent m_delta_hamiltonian;
149  Mesh* m_mesh;
150  double m_tissue_energy;
151 
152 private:
155  std::vector<std::function<std::array<double,3>()> > m_mc_move_generator;
156 
159  std::vector<std::function<double()> > m_normal_generator;
160 
163  std::vector<std::function<double()> > m_uniform_generator;
164 };
165 
166 } // namespace
167 
168 #endif // end_of_include_guard
std::function< double(Cell *)> HamiltonianComponent
Hamiltonian component interface.
std::function< double(const NeighborNodes &, Node *, std::array< double, 3 >)> DeltaHamiltonianComponent
DeltaHamiltonian component interface.
Core data with mesh, parameters, random engine and time data.
Definition: CoreData.h:38
Node in cell wall.
Definition: Node.h:39
Core data used during model execution.
double GetTissueEnergy() const
Get current energy for the whole tissue.
Definition: NodeMover.h:96
Interface of Model Components.
MetropolisInfo SweepOverNodes(double step_size, double temperature)
Sweep over all nodes, do metropolis move for each of them.
Definition: NodeMover.cpp:234
Cell mechanics by displacement and insertion of nodes.
Definition: NodeMover.h:46
Namespace for the core simulator.
bool UsesDeltaHamiltonian() const
Using the delta-hamiltonian.
Definition: NodeMover.h:114
NodeMover()
Straight initialization of empty object.
Definition: NodeMover.cpp:49
Information related to (potential) move of a node in the mesh.
Definition: NodeMover.h:75
void Initialize(const CoreData &cd)
Initializes based on values in property tree.
Definition: NodeMover.cpp:81
Structure of cells; key data structure.
Definition: Mesh.h:62
Information gathered to evaluat effects of Metropolis Algorithm.
Definition: NodeMover.h:52