VPTissue Reference Manual
Mesh.h
Go to the documentation of this file.
1 #ifndef MESH_H_INCLUDED
2 #define MESH_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 "Cell.h"
23 #include "NeighborNodes.h"
24 #include "Node.h"
26 
27 #include <boost/property_tree/ptree.hpp>
28 #include <array>
29 #include <list>
30 #include <map>
31 #include <memory>
32 #include <set>
33 #include <string>
34 #include <tuple>
35 #include <vector>
36 
37 namespace SimPT_Editor {
38  class EditableMesh;
39 }
40 
41 namespace SimPT_Sim {
42 
43 class Edge;
44 class Node;
45 class MeshState;
46 class Wall;
47 
48 
62 class Mesh
63 {
64 public:
66  Mesh(unsigned int num_chemicals);
67 
69  void AddNodeToCell(Cell* c, Node* n, Node* nb1, Node* nb2);
70 
71  Cell* BuildBoundaryPolygon(const std::vector<unsigned int>& node_ids);
72 
73  Cell* BuildCell();
74 
75  Cell* BuildCell(const std::vector<unsigned int>& node_ids);
76 
77  Cell* BuildCell(unsigned int id, const std::vector<unsigned int>& node_ids);
78 
79  Node* BuildNode(const std::array<double, 3>& vec, bool at_boundary);
80 
81  Node* BuildNode(unsigned int id, const std::array<double, 3>& vec, bool at_boundary);
82 
83  Wall* BuildWall(Node* n1, Node* n2, Cell* c1, Cell* c2);
84 
85  Wall* BuildWall(unsigned int id, Node* n1, Node* n2, Cell* c1, Cell* c2);
86 
89  void ConstructNeighborList(Cell* cell);
90 
92  //void ConstructNeighborList(Cell* cell) { ConstructNeighborList(cell); }
93 
95  void Derivatives(double* derivs);
96 
99  Cell* FindEdgeNeighbor(Cell* cell, Edge edge) const;
100 
102  Wall* FindWall(const Edge& edge) const;
103 
105  Cell* GetBoundaryPolygon() const { return m_boundary_polygon; }
106 
108  const std::vector<Cell*>& GetCells() const { return m_cells; }
109 
111  std::vector<Cell*>& GetCells() { return m_cells; }
112 
115  std::vector<NeighborNodes> GetEdgeOwners(const Edge& edge) const;
116 
118  std::list<Cell*> const& GetNeighbors(Cell* c) const { return m_wall_neighbors.at(c); }
119 
121  std::list<Cell*>& GetNeighbors(Cell* c) { return m_wall_neighbors[c]; }
122 
124  std::list<NeighborNodes>& GetNodeOwningNeighbors(Node* n) { return m_node_owning_neighbors[n]; }
125 
127  const std::list<NeighborNodes>& GetNodeOwningNeighbors(Node* n) const { return m_node_owning_neighbors.at(n); }
128 
130  std::list<Wall*>& GetNodeOwningWalls(Node* n) { return m_node_owning_walls[n]; }
131 
133  const std::list<Wall*>& GetNodeOwningWalls(Node* n) const { return m_node_owning_walls.at(n); }
134 
136  const std::vector<Node*>& GetNodes() const { return m_nodes; }
137 
139  std::vector<Node*>& GetNodes() { return m_nodes; }
140 
141  // The chemical count.
142  unsigned int GetNumChemicals() const { return m_num_chemicals; }
143 
145  MeshState GetState() const;
146 
148  const std::vector<Wall*>& GetWalls() const { return m_walls; }
149 
151  std::vector<Wall*>& GetWalls() { return m_walls; }
152 
154  bool IsAtBoundary(const Edge* e) const;
155 
157  bool IsAtBoundary(Wall* w) const;
158 
160  bool IsInBoundaryPolygon(Node* n) const;
161 
163  std::ostream& Print(std::ostream& os) const;
164 
166  void RemoveFromNeighborList(Cell* cell);
167 
170  void RemoveNodeFromOwnerLists(Node* node);
171 
173  boost::property_tree::ptree ToPtree() const;
174 
176  void UpdateNodeOwningNeighbors(Cell* cell);
177 
179  //void UpdateNodeOwningNeighbors(Cell* cell) { UpdateNodeOwningNeighbors(cell); }
180 
186  void UpdateNodeOwningWalls(Wall *wall);
187 
189  //void UpdateNodeOwningWalls(Wall* wall) { UpdateNodeOwningWalls(wall); }
190 
191 public:
193  void getValues(double* values);
194 
196  void setValues(double x, double* y);
197 
198 private:
199  friend class MeshCheck;
200  friend class CBMBuilder;
201  friend class SimPT_Editor::EditableMesh;
202 
203 private:
209  void AddConsecutiveNodeToCell(Cell* c, Node* n, Node* nb1, Node* nb2);
210 
213  Node* FindNextBoundaryNode(Node*) const;
214 
217  void FixWallIDs();
218 
221  void FixNodeIDs();
222 
225  void FixCellIDs();
226 
227 private:
229  Cell* m_boundary_polygon;
230 
233 
235  std::vector<Cell*> m_cells;
236 
238  unsigned int m_cell_next_id;
239 
242 
244  std::vector<Node*> m_nodes;
245 
247  unsigned int m_node_next_id;
248 
250  std::map<Node*, std::list<NeighborNodes>> m_node_owning_neighbors;
251 
253  std::map<Node*, std::list<Wall*>> m_node_owning_walls;
254 
256  const unsigned int m_num_chemicals;
257 
260 
262  std::vector<Wall*> m_walls;
263 
265  unsigned int m_wall_next_id;
266 
268  std::map<Cell*, std::list<Cell*>> m_wall_neighbors;
269 };
270 
271 }
272 
273 #endif // end_of_include_guard
Cell * FindEdgeNeighbor(Cell *cell, Edge edge) const
Find the neighbor to this cell with respect to the given edge.
Definition: Mesh.cpp:267
void getValues(double *values)
Used for interacting with ODE-solvers.
bool IsAtBoundary(const Edge *e) const
True iff the edge is on the mesh boundary.
Definition: Mesh.cpp:636
A cell contains walls and nodes.
Definition: Cell.h:48
void RemoveNodeFromOwnerLists(Node *node)
Removes the node from the 'node owning neighbors' and 'node owning walls' lists.
Definition: Mesh.cpp:763
Namespace for SimPT tissue editor package.
Definition: Cell.h:32
Node in cell wall.
Definition: Node.h:39
std::list< Wall * > & GetNodeOwningWalls(Node *n)
The walls that contain the given node somewhere on the wall.
Definition: Mesh.h:130
MeshState GetState() const
The current state of the mesh as a self-contained object.
Definition: Mesh.cpp:494
std::vector< Wall * > & GetWalls()
The walls of this mesh.
Definition: Mesh.h:151
void UpdateNodeOwningWalls(Wall *wall)
Set ownerships of node <-> cell or update them after cell division.
Definition: Mesh.cpp:829
void UpdateNodeOwningNeighbors(Cell *cell)
Set ownerships of node <-> cell or update them after cell division.
Definition: Mesh.cpp:806
Interface for NeighborNodes.
const std::vector< Cell * > & GetCells() const
The cells of this mesh, EXCLUDING the boundary polygon.
Definition: Mesh.h:108
The Copy-Based Mesh Builder directs the Mesh building process using another mesh. ...
Definition: CBMBuilder.h:32
const std::list< Wall * > & GetNodeOwningWalls(Node *n) const
The walls that contain the given node somewhere on the wall.
Definition: Mesh.h:133
Namespace for the core simulator.
void ConstructNeighborList(Cell *cell)
Constructs neighbor list by looping over walls and registering adjoining cell for that wall...
Definition: Mesh.cpp:252
An Edge connects two nodes and is ambidextrous.
Definition: Edge.h:31
std::list< Cell * > const & GetNeighbors(Cell *c) const
Get the adjacent cells to the given cell (i.e. sharing a wall).
Definition: Mesh.h:118
std::ostream & Print(std::ostream &os) const
Solely for debugging purposes.
Definition: Mesh.cpp:668
Interface for Cell.
std::vector< NeighborNodes > GetEdgeOwners(const Edge &edge) const
Find the intersecting neighbors of the end points of the edge.
Definition: Mesh.cpp:455
std::vector< Node * > & GetNodes()
The nodes of the mesh.
Definition: Mesh.h:139
Checks mesh concistency.
Definition: MeshCheck.h:29
void setValues(double x, double *y)
Used for interacting with ODE-solvers.
std::list< Cell * > & GetNeighbors(Cell *c)
Get the adjacent cells to the given cell (i.e. sharing a wall).
Definition: Mesh.h:121
void AddNodeToCell(Cell *c, Node *n, Node *nb1, Node *nb2)
Add node to cell between existing neighbor nodes.
Definition: Mesh.cpp:84
const std::list< NeighborNodes > & GetNodeOwningNeighbors(Node *n) const
Get the neighbors associated with this node.
Definition: Mesh.h:127
Mesh(unsigned int num_chemicals)
Constructs empty Mesh.
Definition: Mesh.cpp:69
Cell * GetBoundaryPolygon() const
Get the boundary polygon of the mesh.
Definition: Mesh.h:105
void RemoveFromNeighborList(Cell *cell)
Removes the cell from the neighbor list (only do this when deleting this cell).
Definition: Mesh.cpp:758
bool IsInBoundaryPolygon(Node *n) const
True iff the node is one of the nodes of the boundary polygon.
Definition: Mesh.cpp:657
Interface for Node.
const std::vector< Node * > & GetNodes() const
The nodes of the mesh.
Definition: Mesh.h:136
std::list< NeighborNodes > & GetNodeOwningNeighbors(Node *n)
Get the neighbors associated with this node.
Definition: Mesh.h:124
void Derivatives(double *derivs)
Constructs neighbor list by looping over walls and registering.
boost::property_tree::ptree ToPtree() const
Convert the mesh to a ptree.
Definition: Mesh.cpp:769
Interface and implementation for SegmentedVector class.
Structure of cells; key data structure.
Definition: Mesh.h:62
std::vector< Cell * > & GetCells()
The cells of this mesh, EXCLUDING the boundary polygon.
Definition: Mesh.h:111
Wall * FindWall(const Edge &edge) const
Find the wall including the edge.
Definition: Mesh.cpp:373
const std::vector< Wall * > & GetWalls() const
The walls of this mesh.
Definition: Mesh.h:148
An editable mesh with actions to alter the construction of the mesh.
Definition: EditableMesh.h:35
A cell wall, runs between cell corner points and consists of wall elements.
Definition: Wall.h:48
Container that stores objects "almost contiguously" and guarantees that pointers/iterators are not in...