-
Notifications
You must be signed in to change notification settings - Fork 5
/
poisson.cpp
73 lines (60 loc) · 2.34 KB
/
poisson.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @file poisson.cpp
* Test script for treating for using the GraphSymmetricMatrix class
* and solving a Poisson equation.
*
* @brief Reads in two files specified on the command line.
* First file: 3D Points (one per line) defined by three doubles.
* Second file: Eges (one per line) defined by 2 indices into the point list
* of the first file.
*
* Launches an SFML_Viewer to visualize the solution.
*/
#include "CME212/SFML_Viewer.hpp"
#include "GraphSymmetricMatrix.hpp"
// HW3: YOUR CODE HERE
// Define visual_iteration that inherits from cyclic_iteration
int main(int argc, char** argv)
{
// Check arguments
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " NODES_FILE TETS_FILE\n";
exit(1);
}
// Define an empty Graph
GraphType graph;
{
// Create a nodes_file from the first input argument
std::ifstream nodes_file(argv[1]);
// Interpret each line of the nodes_file as a 3D Point and add to the Graph
std::vector<NodeType> node_vec;
Point p;
while (CME212::getline_parsed(nodes_file, p))
node_vec.push_back(graph.add_node(2*p - Point(1,1,0)));
// Create a tets_file from the second input argument
std::ifstream tets_file(argv[2]);
// Interpret each line of the tets_file as four ints which refer to nodes
std::array<int,4> t;
while (CME212::getline_parsed(tets_file, t)) {
graph.add_edge(node_vec[t[0]], node_vec[t[1]]);
graph.add_edge(node_vec[t[0]], node_vec[t[2]]);
graph.add_edge(node_vec[t[1]], node_vec[t[3]]);
graph.add_edge(node_vec[t[2]], node_vec[t[3]]);
}
}
// Get the edge length, should be the same for each edge
auto it = graph.edge_begin();
assert(it != graph.edge_end());
double h = norm((*it).node1().position() - (*it).node2().position());
// Make holes in our Graph
remove_box(graph, Box3D(Point(-0.8+h,-0.8+h,-1), Point(-0.4-h,-0.4-h,1)));
remove_box(graph, Box3D(Point( 0.4+h,-0.8+h,-1), Point( 0.8-h,-0.4-h,1)));
remove_box(graph, Box3D(Point(-0.8+h, 0.4+h,-1), Point(-0.4-h, 0.8-h,1)));
remove_box(graph, Box3D(Point( 0.4+h, 0.4+h,-1), Point( 0.8-h, 0.8-h,1)));
remove_box(graph, Box3D(Point(-0.6+h,-0.2+h,-1), Point( 0.6-h, 0.2-h,1)));
// HW3: YOUR CODE HERE
// Define b using the graph, f, and g.
// Construct the GraphSymmetricMatrix A using the graph
// Solve Au = b using MTL.
return 0;
}