HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
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
12#ifndef _DIRECTEDGRAPH_HPP
13#define _DIRECTEDGRAPH_HPP
14
25// ----------------------------------------------------------------------------
26// Free functions
27// ----------------------------------------------------------------------------
28
30typedef std::vector<std::vector<std::size_t>> Array;
31
32// ----------------------------------------------------------------------------
33// DirectedEdge class definition
34// ----------------------------------------------------------------------------
35
41{
42public:
44 std::size_t a;
45
47 std::size_t b;
48
51
54
57 DirectedEdge(size_t, size_t);
58
61};
62
64bool operator==(const DirectedEdge &, const DirectedEdge &);
65
66// ----------------------------------------------------------------------------
67// DirectedCell class definition
68// ----------------------------------------------------------------------------
69
76{
77public:
79 std::vector<DirectedEdge> T;
80
82 std::vector<std::size_t> part;
83
86
88 DirectedCell(std::size_t);
89
92
96 std::vector<DirectedEdge> &,
97 std::size_t
98 );
99
101 void add_edge(
102 DirectedEdge &
103 );
104
106 void remove_edge(
107 std::size_t
108 );
109
113 void append_cell(
114 DirectedCell &
115 );
116
118 bool check_nodes();
119
121 bool is_ordered();
122
125
127 std::vector<DirectedEdge> order_edges();
128
130 bool has_edge(
132 );
133
135 void print(); // Useful for debugging
136};
137
138// ----------------------------------------------------------------------------
139// NodeArray class definition
140// ----------------------------------------------------------------------------
141
147{
148public:
151
153 NodeArray();
154
156 ~NodeArray();
157
160 NodeArray(
161 Array &
162 );
163
165 bool node_exists(
166 std::size_t
167 );
168
170 void renum_nodes(
171 std::size_t
172 );
173
175 void print(
176 std::ofstream *,
177 std::size_t width = 6
178 );
179};
180
182{
183public:
185 std::vector<DirectedCell> G;
186
189
192
196 std::vector<DirectedCell> &
197 );
198
200 void add_cell(
201 DirectedCell &
202 );
203
205 void remove_cell(
206 std::size_t
207 );
208
210 bool test_graph();
211
213 void randomise();
214
216 void order();
217
219 void coarsen();
220
223
225 std::string get_partition();
226
228 void plotfile(
229 std::ofstream *,
230 std::vector<Eigen::VectorXd> &
231 );
232
233private:
234 /* Checks if there exists a shared edge, and checks if there exists
235 a shared node at a non-edge interface i.e. they touch at a corner.
236 Must be true, false to return true. Also stores a vector of shared
237 edges to pass to merge_cells - which deletes them.
238 */
239 bool can_merge(std::size_t, std::size_t, std::vector<size_t> &);
240
241 /* Appends second cell to the first. Removes second cell. Removes
242 duplicate edges of first cell then orders edges. Handles
243 non-simply connected case.
244 */
245 void merge_cells(std::size_t, std::size_t, std::vector<size_t> &);
246
247 // Random boolean generator for coarsen()
248 std::knuth_b rand_engine;
249 bool random_bool(double);
250};
251
253
254#endif
Definition DirectedGraph.hpp:76
Definition DirectedGraph.hpp:41
Definition DirectedGraph.hpp:182
Definition DirectedGraph.hpp:147
~DirectedGraph()
Default constructor.
Definition DirectedGraph.cpp:257
DirectedCell()
Null Constructor.
Definition DirectedGraph.cpp:25
Array A
The cell-node array.
Definition DirectedGraph.hpp:150
DirectedEdge(size_t, size_t)
Class Constructor: Initialises the edge with the two nodes that form the edge.
void plotfile(std::ofstream *, std::vector< Eigen::VectorXd > &)
Outputs to a .dat file for gnuplot to read.
Definition DirectedGraph.cpp:403
bool check_nodes()
Checks for repeated or lone nodes.
Definition DirectedGraph.cpp:148
void remove_edge(std::size_t)
Remove edge at a given position.
Definition DirectedGraph.cpp:38
bool has_edge(DirectedEdge)
Tests if cell has an edge.
Definition DirectedGraph.cpp:182
NodeArray()
Null constructor.
Definition DirectedGraph.cpp:207
void add_cell(DirectedCell &)
Appends a cell to the end of the graph.
Definition DirectedGraph.cpp:260
std::size_t b
Node number of the edge head.
Definition DirectedGraph.hpp:47
void randomise()
Randomise order of cells in graph.
Definition DirectedGraph.cpp:291
void remove_duplicate_edges()
Method to remove all edge - antiedge pairs.
Definition DirectedGraph.cpp:49
std::vector< DirectedCell > G
Vector of cells that form the graph.
Definition DirectedGraph.hpp:185
void remove_cell(std::size_t)
Removes cell from a given position.
Definition DirectedGraph.cpp:265
bool operator==(const DirectedEdge &, const DirectedEdge &)
Boolean operation to test if two edges are equal.
Definition DirectedGraph.cpp:16
~NodeArray()
Default constructor.
Definition DirectedGraph.cpp:208
bool is_ordered()
Tests if the edges of the cell are ordered.
Definition DirectedGraph.cpp:68
~DirectedCell()
Destructor.
Definition DirectedGraph.cpp:27
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 edges in each cell.
Definition DirectedGraph.cpp:301
std::vector< std::vector< std::size_t > > Array
Type definition for a matrix of unsigned ints.
Definition DirectedGraph.hpp:30
DirectedGraph()
Null constructor.
Definition DirectedGraph.cpp:256
bool test_graph()
Test if graph has duplicate edges or unordered cells.
Definition DirectedGraph.cpp:270
std::string get_partition()
Returns list of fine cells that each coarse cell consists of.
Definition DirectedGraph.cpp:388
NodeArray graph_to_array()
Returns the cell-node array the graph corresponds to.
Definition DirectedGraph.cpp:374
~DirectedEdge()
Destructor.
Definition DirectedGraph.cpp:8
void renum_nodes(std::size_t)
Subtracts one from all nodes greater than a given node.
Definition DirectedGraph.cpp:222
DirectedEdge anti_edge()
Returns the edge consisting of the same nodes, pointing in the opposite direction.
Definition DirectedGraph.cpp:11
void add_edge(DirectedEdge &)
Method to append an edge to the end of the cell.
Definition DirectedGraph.cpp:33
void append_cell(DirectedCell &)
Definition DirectedGraph.cpp:43
std::vector< DirectedEdge > order_edges()
Orders the cell edges - returns vector of edges to be removed.
Definition DirectedGraph.cpp:84
DirectedEdge()
Null constructor.
Definition DirectedGraph.cpp:7
void print(std::ofstream *, std::size_t width=6)
Prints the cell node array to an out file stream.
Definition DirectedGraph.cpp:236
std::size_t a
Node number of the edge tail.
Definition DirectedGraph.hpp:44
void coarsen()
Coarsen the graph by merging cells.
Definition DirectedGraph.cpp:315
void print()
Prints all the edges of the cell.
Definition DirectedGraph.cpp:194
bool node_exists(std::size_t)
Test if a given node exists in the cell-node array.
Definition DirectedGraph.cpp:210
std::vector< DirectedEdge > T
The edges the cell consists of.
Definition DirectedGraph.hpp:79