-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cc
138 lines (127 loc) · 4.41 KB
/
test.cc
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#define EIGEN_RUNTIME_NO_MALLOC
#include <iostream>
#include <fstream>
#include <vector>
#include "PatchVariable.hh"
#include "Dynamics.hh"
#include "ShallowWater.hh"
#include "TimeStepping.hh"
//#include "Advection.hh"
using namespace std;
void test_finite_difference(){
FiniteDifference<1> diff;
FiniteInterpolation<4> half;
HyperDifference<4> hypr;
ArrayXXf a(5, 5);
a << 1,2,3,4,1,
4,5,6,4,2,
7,8,9,4,3,
7,2,1,4,2,
2,5,1,4,6;
cout << a << endl;
cout << diff.x(a, 2) << endl;
cout << diff.y(a, 2) << endl;
cout << half.x(a) << endl;
cout << half.y(a) << endl;
cout << hypr.x(a, 2) << endl;
cout << hypr.y(a, 2) << endl;
}
void test_nonstaggered_grid(){
PatchVariable<TileVariable,1,2,2> b(6, 6, 'i');
cout << b.value << endl << endl;
cout << b.tile[0][0].main() << endl << endl;
cout << b.tile[0][1].main() << endl << endl;
cout << b.tile[1][0].main() << endl << endl;
cout << b.tile[1][1].main() << endl << endl;
cout << b.tile[0][0].mainx() << endl << endl;
cout << b.tile[0][0].mainy() << endl << endl;
}
void test_staggered_grid(){
PatchVariable<TileVariable,1,2,2> a(7, 6, 'x');
cout << a.value << endl << endl;
cout << a.value_t << endl << endl;
cout << a.tile[0][0].main() << endl << endl;
cout << a.tile[0][1].main() << endl << endl;
cout << a.tile[1][0].main() << endl << endl;
cout << a.tile[1][1].main() << endl << endl;
cout << a.tile[0][0].mainx() << endl << endl;
cout << a.tile[0][0].mainy() << endl << endl;
cout << a.tile[0][0].u_to_v() << endl << endl;
a.tile[0][0].main() += 2;
cout << a.value << endl << endl;
}
void test_dynamics(){
PatchVariable<TileVariable, O_INTERP/2, NTILES_IN_X, NTILES_IN_Y> a(6, 6, 'i');
PatchVariable<TileVariable, O_INTERP/2, NTILES_IN_X, NTILES_IN_Y> u(7, 6, 'x');
PatchVariable<TileVariable, O_INTERP/2, NTILES_IN_X, NTILES_IN_Y> v(6, 7, 'y');
Dynamics<O_INTERP> dyn;
u.setLeftRightZero();
v.setBottomTopZero();
cout << "==================== initial value ==================== " << endl;
cout << a.value << endl << endl;
cout << u.value << endl << endl;
cout << v.value << endl << endl;
cout << "Total Sum " << a.value.sum() << endl;
cout << "==================== domain decomposition ==================== " << endl;
//a.clean_t(); u.clean_t(); v.clean_t();
for (int i = 0; i < NTILES_IN_X * NTILES_IN_Y; i++){
dyn.advection(u(i), v(i), a(i));
dyn.self_advection(u(i), v(i));
dyn.coriolis(u(i), v(i));
dyn.gradient(a(i), u(i), v(i));
}
a.update(1.); u.update(1.); v.update(1.);
cout << a.value << endl << endl;
cout << u.value << endl << endl;
cout << v.value << endl << endl;
cout << "Total Sum " << a.value.sum() << endl;
}
int main(){
//internal::set_is_malloc_allowed(false);
//test_finite_difference();
//test_nonstaggered_grid();
//test_staggered_grid();
//test_dynamics();
//
typedef PatchVariable<TileVariable, O_INTERP/2, NTILES_IN_X, NTILES_IN_Y> Patch;
typedef std::vector<Patch> StateVector;
typedef ShallowWater<O_INTERP, NTILES_IN_X, NTILES_IN_Y> ForwardModel;
Patch a(6, 6, 'i');
Patch u(7, 6, 'x');
Patch v(6, 7, 'y');
ForwardModel forward;
u.setLeftRightZero();
v.setBottomTopZero();
StateVector state;
state.push_back(a);
state.push_back(u);
state.push_back(v);
for (size_t i = 0; i < state.size(); i++){
state[i].reset_ptr();
cout << state[i].value << endl << endl;
}
cout << state[0].value.sum() << endl << endl;
forward(state);
for (size_t i = 0; i < state.size(); i++){
state[i].update(1.0);
cout << state[i].value << endl << endl;
}
cout << state[0].value.sum() << endl << endl;
Runge_Kutta<4, StateVector> stepper;
stepper.do_step(forward, state, 0.5);
/*
TimeStepper<4, StateVector, ShallowWater> stepper;
for (int i = 0; i < 5; i++){
cout << u.value << endl << endl;
cout << v.value << endl << endl;
cout << a.value << endl << endl;
cout << "Total Sum: " << a.value.sum() << endl;
forward(u, v, a);
cout << "Forward step #" << i << " :"<< endl;
cout << u.value << endl << endl;
cout << v.value << endl << endl;
cout << a.value << endl << endl;
cout << "Total Sum: " << a.value.sum() << endl;
}
*/
}