-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFVM.h
341 lines (281 loc) · 6.13 KB
/
FVM.h
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#ifndef FVM_H
#define FVM_H
#include <iostream>
#include <vector>
#include <cmath>
#include <fstream>
#include "Eigen/Dense"
#include <functional>
using namespace std;
//#define HeatDiff1D
//#define HeatDiff2D
#define HeatConv2D
//#define MMSVerification
#if defined HeatDiff1D
class FVM {
public:
FVM(double error_req);
void solve();
void write_csv(string filename);
private:
//-------------------------------------------------User Defined Parameters--------------------------------
int nx=100;
double xL=1;
double k=1.0;
double Su=0.0;
double Sp=0.0;
#define Dirichlet_E
double phi_e=0.0;
#define Dirichlet_W
double phi_w=100.0;
#define No_Convection
//----------------------------------------------------------------------------------------------------------
int ny=1;
double yL=0.1;
double dx = xL/nx;
double dy = yL/ny;
double error_req;
#define Neumann_N
double dphi_n=0.0;
#define Neumann_S
double dphi_s=0.0;
Eigen::MatrixXd phi;
Eigen::MatrixXd phi_old;
Eigen::MatrixXd A_P;
Eigen::MatrixXd A_E;
Eigen::MatrixXd A_W;
Eigen::MatrixXd A_N;
Eigen::MatrixXd A_S;
Eigen::MatrixXd b;
void initialize();
double compute_error();
};
#endif
#if defined HeatDiff2D
class FVM {
public:
FVM(double error_req);
void solve();
void write_csv(string filename);
private:
//-------------------------------------------------User Defined Parameters--------------------------------
int nx=100;
int ny=100;
double xL=1.0;
double yL=1.0;
double k=1.0;
double Su=0.0;
double Sp=0.0;
//boundary conditions
#define Dirichlet_E
double phi_e=0.0;
#define Dirichlet_W
double phi_w=1.0;
#define Dirichlet_N
double phi_n=1.0;
#define Dirichlet_S
double phi_s=0.0;
#define No_Convection
//-------------------------------------------------------------------------------------------------------
double error_req;
double dx = xL/nx;
double dy = yL/ny;
Eigen::MatrixXd phi;
Eigen::MatrixXd phi_old;
Eigen::MatrixXd A_P;
Eigen::MatrixXd A_E;
Eigen::MatrixXd A_W;
Eigen::MatrixXd A_N;
Eigen::MatrixXd A_S;
Eigen::MatrixXd b;
void initialize();
double compute_error();
};
#endif
#if defined HeatConv2D
class FVM {
public:
FVM(double error_req);
void solve();
void write_csv(string filename);
private:
//-------------------------------------------------User Defined Parameters--------------------------------
int nx=100;
int ny=100;
double xL=1.0;
double yL=1.0;
double k=1.0;
double Su=0.0;
double Sp=0.0;
double rho=1.0;
double u=10.0;
double v=-10.0;
//Diffusion boundary conditions
#define Dirichlet_E
double phi_e=0.0;
#define Dirichlet_W
double phi_w=1.0;
#define Dirichlet_N
double phi_n=1.0;
#define Dirichlet_S
double phi_s=0.0;
//Convection boundary conditions
#define Inlet_W
#define Inlet_N
#define Outlet_E
#define Outlet_S
//-------------------------------------------------------------------------------------------------------
double error_req;
double dx = xL/nx;
double dy = yL/ny;
Eigen::MatrixXd phi;
Eigen::MatrixXd phi_old;
Eigen::MatrixXd A_P;
Eigen::MatrixXd A_E;
Eigen::MatrixXd A_W;
Eigen::MatrixXd A_N;
Eigen::MatrixXd A_S;
Eigen::MatrixXd b;
void initialize();
double compute_error();
};
#endif
#if defined MMSVerification
class FVM {
public:
FVM(double error_req);
void solve();
void write_csv(string filename);
private:
//-------------------------------------------------User Defined Parameters--------------------------------
int nx=10;
int ny=10;
double xL=1.0;
double yL=1.0;
double k=1.0;
double Su=0.0;
double Sp=0.0;
double rho=1.0;
double u=1.0;
double v=1.0;
//Diffusion boundary conditions
#define Dirichlet_E
double phi_e=0.0;
#define Dirichlet_W
double phi_w=0.0;
#define Neumann_N
double dphi_n=0.0;
#define Neumann_S
double dphi_s=0.0;
//Convection boundary conditions
#define Inlet_W
#define Outlet_N
#define Outlet_E
#define Inlet_S
//-------------------------------------------------------------------------------------------------------
double error_req;
double dx = xL/nx;
double dy = yL/ny;
Eigen::MatrixXd phi;
Eigen::MatrixXd phi_old;
Eigen::MatrixXd A_P;
Eigen::MatrixXd A_E;
Eigen::MatrixXd A_W;
Eigen::MatrixXd A_N;
Eigen::MatrixXd A_S;
Eigen::MatrixXd b;
void initialize();
double compute_error();
void verify();
double phifunction(double x, double y);
double gaussQuad(function<double(double, double)> func, double llim_x, double ulim_x, double llim_y, double ulim_y);
double L2norm();
};
#endif
//Boundary Condition Definition
#if defined Dirichlet_E
int dir_e = 1;
int neu_e = 0;
double dphi_e = 0.0;
#endif
#if defined Dirichlet_W
int dir_w = 1;
int neu_w = 0;
double dphi_w = 0.0;
#endif
#if defined Dirichlet_N
int dir_n = 1;
int neu_n = 0;
double dphi_n = 0.0;
#endif
#if defined Dirichlet_S
int dir_s = 1;
int neu_s = 0;
double dphi_s = 0.0;
#endif
#if defined Neumann_E
int dir_e = 0;
int neu_e = 1;
double phi_e = 0.0;
#endif
#if defined Neumann_W
int dir_w = 0;
int neu_w = 1;
double phi_w = 0.0;
#endif
#if defined Neumann_N
int dir_n = 0;
int neu_n = 1;
double phi_n = 0.0;
#endif
#if defined Neumann_S
int dir_s = 0;
int neu_s = 1;
double phi_s = 0.0;
#endif
#if defined No_Convection
double rho=0.0;
double u=0.0;
double v=0.0;
int in_w=0;
int out_w=0;
int in_e=0;
int out_e=0;
int in_n=0;
int out_n=0;
int in_s=0;
int out_s=0;
#endif
#if defined Inlet_E
int in_e=1;
int out_e=0;
#endif
#if defined Inlet_W
int in_w=1;
int out_w=0;
#endif
#if defined Inlet_N
int in_n=1;
int out_n=0;
#endif
#if defined Inlet_S
int in_s=1;
int out_s=0;
#endif
#if defined Outlet_E
int in_e=0;
int out_e=1;
#endif
#if defined Outlet_W
int in_w=0;
int out_w=1;
#endif
#if defined Outlet_N
int in_n=0;
int out_n=1;
#endif
#if defined Outlet_S
int in_s=0;
int out_s=1;
#endif
#endif