-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
66 lines (56 loc) · 2.31 KB
/
main.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
/*
main.cpp (Multigrid)
Jess Robertson, 2011-01-28
Test code for multigrid library.
*/
#include <iostream>
#include "multigrid.hpp"
using namespace mgrid;
void check_boundary_conditions(const int nx, const int nz) {
// Define a boundary point for neumann and dirichlet conditions
BoundaryPoint neumannCondition = { neumann, 0.0 };
BoundaryPoint dirichletCondition = { dirichlet, 0.0 };
// Make a stack with default settings, set some basic conditions
Settings settings;
Stack stack(settings);
stack.boundaryConditions.set(leftBoundary, neumannCondition);
stack.boundaryConditions.set(rightBoundary, dirichletCondition);
stack.boundaryConditions.set(topBoundary, neumannCondition);
// Make up some condition for the bottom boundary
Boundary boundary(nx);
Boundary::iterator bIter;
int val = 0;
for (bIter = boundary.begin(); bIter != boundary.end(); bIter++, val++) {
bIter->value = val;
if (val > 5) {
bIter->conditionType = dirichlet;
} else {
bIter->conditionType = neumann;
}
}
stack.boundaryConditions.set(bottomBoundary, boundary);
// Check that boundary conditions have been set
BoundaryFlag boundaryFlag = bottomBoundary;
for (Level level=3; level>=0; level--) {
std::cout << "Level: " << level << std::endl;
foreach(BoundaryPoint pt, stack[level].boundaryConditions.get(boundaryFlag))
std::cout << "{" << pt.conditionType << ", " << pt.value << "} ";
std::cout << std::endl;
std::cout.flush();
}
}
int main (int argc, char const *argv[]) {
// Make a stack with default settings, set some basic conditions
Settings settings;
settings.aspectRatio = 4;
Stack stack(settings);
stack.boundaryConditions.set(leftBoundary, zeroNeumannCondition);
stack.boundaryConditions.set(rightBoundary, zeroDirichletCondition);
stack.boundaryConditions.set(topBoundary, zeroNeumannCondition);
stack.boundaryConditions.set(bottomBoundary, zeroDirichletCondition);
for (int i=stack.finestLevel; i > stack.coarsestLevel; i--) {
std::cout << "(" << stack[i].length(0)
<< ", " << stack[i].length(1) << ")" << std::endl;
}
return 0;
}