VPTissue Reference Manual
MeshState.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  */
19 #include "MeshState.h"
20 
21 #include <iostream>
22 #include <iomanip>
23 
24 using namespace std;
25 using boost::property_tree::ptree;
26 
27 namespace SimPT_Sim {
28 
29 MeshState::MeshState()
30 {
31  SetNumNodes(0);
32  SetNumCells(0);
33  SetNumWalls(0);
34 }
35 
37 // Nodes
39 
40 size_t MeshState::GetNumNodes() const
41 {
42  return m_num_nodes;
43 }
44 
45 void MeshState::SetNumNodes(size_t n)
46 {
47  // Make sure that all containers are resized to hold n nodes
48  m_num_nodes = n;
49  m_nodes_id.resize(n);
50  m_nodes_x.resize(n);
51  m_nodes_y.resize(n);
52  m_nodes_attr.SetNum(n);
53 }
54 
55 int MeshState::GetNodeID(size_t node_idx) const
56 {
57  return m_nodes_id.at(node_idx);
58 }
59 
60 double MeshState::GetNodeX(size_t node_idx) const
61 {
62  return m_nodes_x.at(node_idx);
63 }
64 
65 double MeshState::GetNodeY(size_t node_idx) const
66 {
67  return m_nodes_y.at(node_idx);
68 }
69 
70 void MeshState::SetNodeID(size_t node_idx, int value)
71 {
72  m_nodes_id.at(node_idx) = value;
73 }
74 
75 void MeshState::SetNodeX(size_t node_idx, double value)
76 {
77  m_nodes_x.at(node_idx) = value;
78 }
79 
80 void MeshState::SetNodeY(size_t node_idx, double value)
81 {
82  m_nodes_y.at(node_idx) = value;
83 }
84 
85 vector<int> MeshState::GetNodesID() const
86 {
87  return m_nodes_id;
88 }
89 
90 vector<double> MeshState::GetNodesX() const
91 {
92  return m_nodes_x;
93 }
94 
95 vector<double> MeshState::GetNodesY() const
96 {
97  return m_nodes_y;
98 }
99 
100 void MeshState::SetNodesID(vector<int> values)
101 {
102  if (values.size() != m_num_nodes) {
103  throw runtime_error("MeshState::SetNodesID(): Number of IDs doesn't match number of nodes.");
104  } else {
105  m_nodes_id = values;
106  }
107 }
108 
109 void MeshState::SetNodesX(vector<double> values)
110 {
111  if (values.size() != m_num_nodes) {
112  throw runtime_error("MeshState::SetNodesX(): Number of X coords doesn't match number of nodes.");
113  } else {
114  m_nodes_x = values;
115  }
116 }
117 
118 void MeshState::SetNodesY(vector<double> values)
119 {
120  if (values.size() != m_num_nodes) {
121  throw runtime_error("MeshState::SetNodesY(): Number of Y coords doesn't match number of nodes.");
122  } else {
123  m_nodes_y = values;
124  }
125 }
126 
128 // Cells
130 
131 size_t MeshState::GetNumCells() const
132 {
133  return m_num_cells;
134 }
135 
136 void MeshState::SetNumCells(size_t n)
137 {
138  // Make sure that all containers are resized to hold n cells
139  m_num_cells = n;
140  m_cells_id.resize(n);
141  m_cells_nodes.resize(n);
142  m_cells_walls.resize(n);
143  m_cells_attr.SetNum(n);
144 }
145 
146 int MeshState::GetCellID(size_t cell_idx) const
147 {
148  return m_cells_id.at(cell_idx);
149 }
150 
151 size_t MeshState::GetCellNumNodes(size_t cell_idx) const
152 {
153  return m_cells_nodes.at(cell_idx).size();
154 }
155 
156 vector<int> MeshState::GetCellNodes(size_t cell_idx) const
157 {
158  return m_cells_nodes.at(cell_idx);
159 }
160 
161 size_t MeshState::GetCellNumWalls(size_t cell_idx) const
162 {
163  return m_cells_walls.at(cell_idx).size();
164 }
165 
166 vector<int> MeshState::GetCellWalls(size_t cell_idx) const
167 {
168  return m_cells_walls.at(cell_idx);
169 }
170 
171 void MeshState::SetCellID(size_t cell_idx, int value)
172 {
173  m_cells_id.at(cell_idx) = value;
174 }
175 
176 void MeshState::SetCellNodes(size_t cell_idx, vector<int> node_ids)
177 {
178  m_cells_nodes.at(cell_idx) = node_ids;
179 }
180 
181 void MeshState::SetCellWalls(size_t cell_idx, vector<int> wall_ids)
182 {
183  m_cells_walls.at(cell_idx) = wall_ids;
184 }
185 
186 vector<int> MeshState::GetCellsID() const
187 {
188  return m_cells_id;
189 }
190 
191 vector<size_t> MeshState::GetCellsNumNodes() const
192 {
193  vector<size_t> cells_num_nodes(m_num_cells);
194  size_t cell_idx = 0;
195  for (vector<int> cell_nodes : m_cells_nodes) {
196  cells_num_nodes[cell_idx++] = cell_nodes.size();
197  }
198  return cells_num_nodes;
199 }
200 
201 vector<size_t> MeshState::GetCellsNumWalls() const
202 {
203  vector<size_t> cells_num_walls(m_num_cells);
204  size_t cell_idx = 0;
205  for (vector<int> cell_walls : m_cells_walls) {
206  cells_num_walls[cell_idx++] = cell_walls.size();
207  }
208  return cells_num_walls;
209 }
210 
211 void MeshState::SetCellsID(vector<int> values)
212 {
213  if (values.size() != m_num_cells) {
214  throw runtime_error("MeshState::SetCellsID(): Number of IDs doesn't match number of cells.");
215  } else {
216  m_cells_id = values;
217  }
218 }
219 
220 vector<int> MeshState::GetBoundaryPolygonNodes() const
221 {
222  return m_boundary_polygon_nodes;
223 }
224 
225 vector<int> MeshState::GetBoundaryPolygonWalls() const
226 {
227  return m_boundary_polygon_walls;
228 }
229 
230 void MeshState::SetBoundaryPolygonNodes(vector<int> node_ids)
231 {
232  m_boundary_polygon_nodes = node_ids;
233 }
234 
235 void MeshState::SetBoundaryPolygonWalls(vector<int> wall_ids)
236 {
237  m_boundary_polygon_walls = wall_ids;
238 }
239 
241 // Walls
243 
244 size_t MeshState::GetNumWalls() const
245 {
246  return m_num_walls;
247 }
248 
249 void MeshState::SetNumWalls(size_t n)
250 {
251  // Make sure that all containers are resized to hold n walls
252  m_num_walls = n;
253  m_walls_id.resize(n);
254  m_walls_cells.resize(n);
255  m_walls_nodes.resize(n);
256  m_walls_attr.SetNum(n);
257 }
258 
259 int MeshState::GetWallID(size_t wall_idx) const
260 {
261  return m_walls_id.at(wall_idx);
262 }
263 
264 pair<int, int> MeshState::GetWallNodes(size_t wall_idx) const
265 {
266  return m_walls_nodes.at(wall_idx);
267 }
268 
269 pair<int, int> MeshState::GetWallCells(size_t wall_idx) const
270 {
271  return m_walls_cells.at(wall_idx);
272 }
273 
274 void MeshState::SetWallID(size_t wall_idx, int value)
275 {
276  m_walls_id.at(wall_idx) = value;
277 }
278 
279 void MeshState::SetWallNodes(size_t wall_idx, pair<int, int> nodes_ids)
280 {
281  m_walls_nodes.at(wall_idx) = nodes_ids;
282 }
283 
284 void MeshState::SetWallCells(size_t wall_idx, pair<int, int> cells_ids)
285 {
286  m_walls_cells.at(wall_idx) = cells_ids;
287 }
288 
289 vector<int> MeshState::GetWallsID() const
290 {
291  return m_walls_id;
292 }
293 
294 void MeshState::SetWallsID(vector<int> values)
295 {
296  if (values.size() != m_num_walls) {
297  throw runtime_error("setWallsID(): Number of IDs doesn't match number of walls.");
298  } else {
299  m_walls_id = values;
300  }
301 }
302 
303 void MeshState::PrintToStream(ostream& out) const
304 {
305  out << "MeshState:" << endl;
306 
308  out << "Nodes:" << endl;
309  out << setw(6) << "ID" << setw(16) << "X" << setw(16) << "Y";
310  for (string name : NodeAttributeContainer().GetNames<int>()) {
311  out << setw(20) << (name + " [i]");
312  }
313  for (string name : NodeAttributeContainer().GetNames<double>()) {
314  out << setw(20) << (name + " [d]");
315  }
316  for (string name : NodeAttributeContainer().GetNames<string>()) {
317  out << setw(20) << (name + " [s]");
318  }
319  out << endl;
320  for (size_t idx = 0; idx < NodeAttributeContainer().GetNum(); ++idx) {
321  out << setw(6) << m_nodes_id[idx];
322  out << setw(16) << m_nodes_x[idx];
323  out << setw(16) << m_nodes_y[idx];
324  for (string name : NodeAttributeContainer().GetNames<int>()) {
325  out << setw(20) << NodeAttributeContainer().Get<int>(idx, name);
326  }
327  for (string name : NodeAttributeContainer().GetNames<double>()) {
328  out << setw(20) << NodeAttributeContainer().Get<double>(idx, name);
329  }
330  for (string name : NodeAttributeContainer().GetNames<string>()) {
331  out << setw(20) << NodeAttributeContainer().Get<string>(idx, name);
332  }
333  out << endl;
334  }
335 
337  out << "Cells:" << endl;
338  out << setw(6) << "ID";
339  for (string name : CellAttributeContainer().GetNames<int>()) {
340  out << setw(20) << (name + " [i]");
341  }
342  for (string name : CellAttributeContainer().GetNames<double>()) {
343  out << setw(20) << (name + " [d]");
344  }
345  for (string name : CellAttributeContainer().GetNames<string>()) {
346  out << setw(20) << (name + " [s]");
347  }
348  out << setw(8) << "Nodes / Walls" << endl;
349  for (size_t idx = 0; idx < CellAttributeContainer().GetNum(); ++idx) {
350  out << setw(6) << m_cells_id[idx];
351  for (string name : CellAttributeContainer().GetNames<int>()) {
352  out << setw(20) << CellAttributeContainer().Get<int>(idx, name);
353  }
354  for (string name : CellAttributeContainer().GetNames<double>()) {
355  out << setw(20) << CellAttributeContainer().Get<double>(idx, name);
356  }
357  for (string name : CellAttributeContainer().GetNames<string>()) {
358  out << setw(20) << CellAttributeContainer().Get<string>(idx, name);
359  }
360  out << " [ ";
361  for (const int node_id : m_cells_nodes[idx]) {
362  out << node_id << " ";
363  }
364  out << "] / [ ";
365  for (const int wall_id : m_cells_walls[idx]) {
366  out << wall_id << " ";
367  }
368  out << "]" << endl;
369  }
370 
372  out << "Boundary polygon : Nodes / Walls" << endl;
373  out << " [ ";
374  for (const int node_id : m_boundary_polygon_nodes) {
375  out << node_id << " ";
376  }
377  out << "] / [ ";
378  for (const int wall_id : m_boundary_polygon_walls) {
379  out << wall_id << " ";
380  }
381  out << "]" << endl;
382 
384  out << "Walls:" << endl;
385  out << setw(6) << "ID" <<
386  setw(8) << "cell_1" << setw(8) << "cell_2"
387  << setw(8) << "node_1" << setw(8) << "node_2";
388  for (string name : WallAttributeContainer().GetNames<int>()) {
389  out << setw(20) << (name + " [i]");
390  }
391  for (string name : WallAttributeContainer().GetNames<double>()) {
392  out << setw(20) << (name + " [d]");
393  }
394  for (string name : WallAttributeContainer().GetNames<string>()) {
395  out << setw(20) << (name + " [s]");
396  }
397  out << endl;
398  for (size_t idx = 0; idx < WallAttributeContainer().GetNum(); ++idx) {
399  out << setw(6) << m_walls_id[idx];
400  out << setw(8) << m_walls_cells[idx].first;
401  out << setw(8) << m_walls_cells[idx].second;
402  out << setw(8) << m_walls_nodes[idx].first;
403  out << setw(8) << m_walls_nodes[idx].second;
404  for (string name : WallAttributeContainer().GetNames<int>()) {
405  out << setw(20) << WallAttributeContainer().Get<int>(idx, name);
406  }
407  for (string name : WallAttributeContainer().GetNames<double>()) {
408  out << setw(20) << WallAttributeContainer().Get<double>(idx, name);
409  }
410  for (string name : WallAttributeContainer().GetNames<string>()) {
411  out << setw(20) << WallAttributeContainer().Get<string>(idx, name);
412  }
413  out << endl;
414  }
415 }
416 
417 }
STL namespace.
Interface of MeshState.
Namespace for the core simulator.