forked from li12242/AdvectionDiffusionSolver_FDM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
96 lines (68 loc) · 2.37 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
#include "math.h"
#include "timeEvolution.h"
#define np 101 // number of points along single axis
int InitConst(structMesh *, physics *);
//double** InitVar(structMesh*, physics*, double **);
int InitVar(structMesh*, physics*, double ***);
int Finalization(structMesh *, double **);
int main(){
structMesh *mesh = (structMesh *)calloc(1, sizeof(structMesh)); // allocate memory
physics *phy = (physics *)calloc(1, sizeof(physics));
double **concentration = NULL;
InitConst(mesh, phy);
concentration = BuildMatrix(np, np);
// concentration = InitVar(mesh, phy, concentration);
InitVar(mesh, phy, &concentration);
PrintMatrix("con1", concentration, mesh->ny, mesh->nx);
timeEvolution(mesh, phy, concentration);
PrintMatrix("con2", concentration, mesh->ny, mesh->nx);
Finalization(mesh, concentration);
return 0;
}
int InitConst(structMesh *mesh, physics *phy){
double xmin, xmax, ymin, ymax;
int icol, irow;
// initialize the mesh
xmin = 0.0; xmax = 2.0;
ymin = 0.0; ymax = 2.0;
mesh->nx = np;
mesh->ny = np;
mesh->dx = (xmax - xmin)/(double)(mesh->nx - 1);
mesh->dy = (ymax - ymin)/(double)(mesh->ny - 1);
mesh->x = BuildVector(mesh->nx);
mesh->y = BuildVector(mesh->ny);
for (icol=0; icol< mesh->nx-1; icol++) {
mesh->x[icol+1] = mesh->x[icol] + mesh->dx;
}
for (irow=0; irow< mesh->ny-1; irow++) {
mesh->y[irow+1] = mesh->y[irow] + mesh->dy;
}
// initialize physics constant
phy->u = 1.0;
phy->v = 1.0;
phy->Dx = 0.01;
phy->Dy = 0.01;
return 0;
}
//double** InitVar(structMesh *mesh, physics *phy, double ***concentration){
int InitVar(structMesh *mesh, physics *phy, double ***concentration){
int irow, icol;
// set the initial condiation
for (irow=0; irow< mesh->ny; irow++) {
for (icol=0; icol< mesh->nx; icol++) {
(*concentration)[irow][icol] = exp(-pow(mesh->x[icol] - 0.5, 2.0)/phy->Dx
- pow(mesh->y[irow] - 0.5, 2.0)/phy->Dy);
}
}
// return concentration;
return 0;
}
int Finalization(structMesh *mesh, double **concentration){
DestroyVector(mesh->x);
DestroyVector(mesh->y);
DestroyMatrix(concentration);
return 0;
}