HArD::Core3D
Hybrid Arbitrary Degree::Core 3D - Library to implement 3D schemes with vertex, edge, face and cell polynomials as unknowns
DirectedGraph.hpp
Go to the documentation of this file.
1 // Classes to assist with mesh handling and coarsening
2 
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 #include <algorithm>
7 #include <functional>
8 #include <random>
9 #include <fstream>
10 #include <Eigen/Dense>
11 #include <assert.h>
12 
13 #ifndef _DIRECTEDGRAPH_HPP
14 #define _DIRECTEDGRAPH_HPP
15 
26 // ----------------------------------------------------------------------------
27 // Free functions
28 // ----------------------------------------------------------------------------
29 
31 typedef std::vector<std::vector<std::size_t>> Array;
32 
33 // ----------------------------------------------------------------------------
34 // DirectedFace class definition
35 // ----------------------------------------------------------------------------
36 
42 {
43 public:
45  std::vector<std::size_t> V;
46 
48  DirectedFace();
49 
51  ~DirectedFace();
52 
55  DirectedFace(std::vector<std::size_t>);
56 
58  void add_vertex(
59  size_t
60  );
61 };
62 
64 bool operator==(const DirectedFace &, const DirectedFace &);
65 
66 // ----------------------------------------------------------------------------
67 // DirectedCell class definition
68 // ----------------------------------------------------------------------------
69 
76 {
77 public:
79  std::vector<DirectedFace> T;
80 
82  std::vector<std::size_t> part;
83 
85  DirectedCell();
86 
88  DirectedCell(std::size_t);
89 
91  ~DirectedCell();
92 
96  std::vector<DirectedFace> &,
97  std::size_t
98  );
99 
101  void add_face(
102  DirectedFace &
103  );
104 
106  void remove_face(
107  std::size_t
108  );
109 
113  void append_cell(
114  DirectedCell &
115  );
116 
117  bool check_cell();
118 
120  bool has_face(
121  DirectedFace
122  );
123 
125  void print(); // Useful for debugging
126 };
127 
128 // ----------------------------------------------------------------------------
129 // NodeArray class definition
130 // ----------------------------------------------------------------------------
131 
137 {
138 public:
141 
143  CellNodeArray();
144 
146  ~CellNodeArray();
147 
151  Array &
152  );
153 
155  bool node_exists(
156  std::size_t
157  );
158 
160  void renum_nodes(
161  std::size_t
162  );
163 
165  void print(
166  std::ofstream *,
167  std::size_t
168  );
169 };
170 
172 {
173 public:
175  std::vector<CellNodeArray> GA;
176 
178  GraphNodeArray();
179 
181  ~GraphNodeArray();
182 
186  std::vector<CellNodeArray> &
187  );
188 
190  bool node_exists(
191  std::size_t
192  );
193 
195  void renum_nodes(
196  std::size_t
197  );
198 
200  void print(
201  std::ofstream *
202  );
203 };
204 
206 {
207 public:
209  std::vector<DirectedCell> G;
210 
212  DirectedGraph();
213 
215  ~DirectedGraph();
216 
220  std::vector<DirectedCell> &
221  );
222 
224  void add_cell(
225  DirectedCell &
226  );
227 
229  void remove_cell(
230  std::size_t
231  );
232 
234  bool test_graph();
235 
237  void randomise();
238 
240  void order();
241 
243  void coarsen();
244 
247 
249  std::string get_partition();
250 
252  void plotfile(
253  std::ofstream *,
254  std::vector<Eigen::VectorXd> &
255  );
256 
257 private:
258  /* Checks is there exists a shared face, and checks if there exists
259  a shared node at a non-face interface i.e. they touch at a corner.
260  Must be true, false to return true. Also stores a vector of shared
261  faces to pass to merge_cells - which deletes them.
262  */
263  bool can_merge(std::size_t, std::size_t, std::vector<size_t> &);
264 
265  /* Appends second cell to the first. Removes second cell. Removes
266  duplicate faces of first cell then orders faces. Handles
267  non-simply connected case.
268  */
269  void merge_cells(std::size_t, std::size_t, std::vector<size_t> &);
270 
271  // Random boolean generator for coarsen()
272  std::knuth_b rand_engine;
273  bool random_bool(double);
274 };
275 
277 
278 #endif
Definition: DirectedGraph.hpp:137
Definition: DirectedGraph.hpp:76
Definition: DirectedGraph.hpp:42
Definition: DirectedGraph.hpp:206
Definition: DirectedGraph.hpp:172
void add_vertex(size_t)
Add a vertex to face.
Definition: DirectedGraph.cpp:11
~DirectedGraph()
Default constructor.
Definition: DirectedGraph.cpp:182
void renum_nodes(std::size_t)
Subtracts one from all nodes greater than a given node.
Definition: DirectedGraph.cpp:114
DirectedCell()
Null Constructor.
Definition: DirectedGraph.cpp:33
Array A
The cell-node array.
Definition: DirectedGraph.hpp:140
void plotfile(std::ofstream *, std::vector< Eigen::VectorXd > &)
Outputs to a .dat file for gnuplot to read.
void add_cell(DirectedCell &)
Appends a cell to the end of the graph.
Definition: DirectedGraph.cpp:185
void randomise()
Randomise order of cells in graph.
Definition: DirectedGraph.cpp:205
bool has_face(DirectedFace)
Tests if cell has an face.
Definition: DirectedGraph.cpp:57
std::vector< DirectedCell > G
Vector of cells that form the graph.
Definition: DirectedGraph.hpp:209
void print(std::ofstream *)
Prints the cell node array to an out file stream.
Definition: DirectedGraph.cpp:167
void remove_cell(std::size_t)
Removes cell from a given position.
Definition: DirectedGraph.cpp:190
bool node_exists(std::size_t)
Test if a given node exists in the cell-node array.
Definition: DirectedGraph.cpp:147
void renum_nodes(std::size_t)
Subtracts one from all nodes greater than a given node.
Definition: DirectedGraph.cpp:159
GraphNodeArray graph_to_array()
Returns the cell-node array the graph corresponds to.
Definition: DirectedGraph.cpp:288
GraphNodeArray()
Null constructor.
Definition: DirectedGraph.cpp:144
~DirectedCell()
Destructor.
Definition: DirectedGraph.cpp:35
std::vector< std::size_t > part
The cell ID's of the cell's that have formed this cell.
Definition: DirectedGraph.hpp:82
void order()
Order cells in graph by the number of faces in each cell.
Definition: DirectedGraph.cpp:215
std::vector< std::vector< std::size_t > > Array
Type definition for a matrix of unsigned ints.
Definition: DirectedGraph.hpp:31
DirectedGraph()
Null constructor.
Definition: DirectedGraph.cpp:181
bool test_graph()
Test if graph has duplicate faces or unordered cells.
Definition: DirectedGraph.cpp:195
~CellNodeArray()
Default constructor.
Definition: DirectedGraph.cpp:100
std::string get_partition()
Returns list of fine cells that each coarse cell consists of.
Definition: DirectedGraph.cpp:307
void remove_face(std::size_t)
Remove face at a given position.
Definition: DirectedGraph.cpp:46
void add_face(DirectedFace &)
Method to append an face to the end of the cell.
Definition: DirectedGraph.cpp:41
DirectedFace()
Null constructor.
Definition: DirectedGraph.cpp:7
std::vector< CellNodeArray > GA
The cell-node array.
Definition: DirectedGraph.hpp:175
~DirectedFace()
Destructor.
Definition: DirectedGraph.cpp:8
void append_cell(DirectedCell &)
Definition: DirectedGraph.cpp:51
std::vector< DirectedFace > T
The faces the cell consists of.
Definition: DirectedGraph.hpp:79
~GraphNodeArray()
Default constructor.
Definition: DirectedGraph.cpp:145
bool operator==(const DirectedFace &, const DirectedFace &)
Boolean operation to test if two faces are equal.
Definition: DirectedGraph.cpp:18
CellNodeArray()
Null constructor.
Definition: DirectedGraph.cpp:99
bool node_exists(std::size_t)
Test if a given node exists in the cell-node array.
Definition: DirectedGraph.cpp:102
void coarsen()
Coarsen the graph by merging cells.
Definition: DirectedGraph.cpp:229
void print(std::ofstream *, std::size_t)
Prints the cell node array to an out file stream.
Definition: DirectedGraph.cpp:128
void print()
Prints all the faces of the cell.
Definition: DirectedGraph.cpp:69
bool check_cell()
Definition: DirectedGraph.cpp:82
std::vector< std::size_t > V
vector of vertices
Definition: DirectedGraph.hpp:45