-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetData-LidDriven.c
More file actions
129 lines (110 loc) · 3.54 KB
/
getData-LidDriven.c
File metadata and controls
129 lines (110 loc) · 3.54 KB
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
/**
# getting Data from simulation snapshot
## Author
Vatsal Sanjay
Email: vatsalsy@comphy-lab.org
CoMPhy Lab
Physics of Fluids Department
Last updated: Mar 8, 2025
*/
#include "utils.h"
#include "output.h"
#include "poisson.h"
vector u[];
char filename[1000];
int nx, ny, len;
double xmin, ymin, xmax, ymax, Deltax, Deltay;
scalar T[], vel[], psi[], omega[];
scalar * list = NULL;
/**
Main entry point for processing fluid dynamics simulation data.
This function validates the command-line arguments and initializes the simulation
by reading in the file name and domain parameters (xmin, ymin, xmax, ymax, ny). It registers
the necessary scalar fields (T, vel, psi), restores simulation data, applies Dirichlet
boundary conditions for both the velocity and streamfunction, computes the velocity magnitude
and vorticity, and then solves the Poisson equation to update the streamfunction. Finally, it calculates grid spacing and interpolates the scalar fields over the designated grid.
## Command-line arguments:
- arguments[0]: Program name.
- arguments[1]: Filename of the simulation snapshot.
- arguments[2]: Lower bound (xmin) of the x-domain.
- arguments[3]: Lower bound (ymin) of the y-domain.
- arguments[4]: Upper bound (xmax) of the x-domain.
- arguments[5]: Upper bound (ymax) of the y-domain.
- arguments[6]: Number of grid points along the y-direction (ny).
## Return
Returns 1 if the argument validation fails; otherwise, the program proceeds with simulation processing.
*/
int main(int a, char const *arguments[])
{
if (a != 7) {
fprintf(ferr, "Error: Expected 6 arguments\n");
fprintf(ferr, "Usage: %s <filename> <xmin> <ymin> <xmax> <ymax> <ny>\n", arguments[0]);
return 1;
}
snprintf (filename, sizeof(filename), "%s", arguments[1]);
xmin = atof(arguments[2]); ymin = atof(arguments[3]);
xmax = atof(arguments[4]); ymax = atof(arguments[5]);
ny = atoi(arguments[6]);
list = list_add (list, T);
list = list_add (list, vel);
list = list_add (list, psi);
/*
Actual run and codes!
*/
restore (file = filename);
// Top moving wall
u.t[top] = dirichlet(1);
/**
For the other no-slip boundaries this gives */
u.t[bottom] = dirichlet(0);
u.t[left] = dirichlet(0);
u.t[right] = dirichlet(0);
// solve for the streamfunction
psi[top] = dirichlet(0);
psi[bottom] = dirichlet(0);
psi[left] = dirichlet(0);
psi[right] = dirichlet(0);
foreach() {
vel[] = sqrt(sq(u.x[])+sq(u.y[]));
}
foreach() {
omega[] = (u.y[1] - u.y[-1] - u.x[0,1] + u.x[0,-1])/(2.*Delta);
psi[] = 0.;
}
poisson (psi, omega);
FILE * fp = ferr;
Deltay = (double)((ymax-ymin)/(ny));
// fprintf(ferr, "%g\n", Deltay);
nx = (int)((xmax - xmin)/Deltay);
// fprintf(ferr, "%d\n", nx);
Deltax = (double)((xmax-xmin)/(nx));
// fprintf(ferr, "%g\n", Deltax);
len = list_len(list);
// fprintf(ferr, "%d\n", len);
double ** field = (double **) matrix_new (nx, ny+1, len*sizeof(double));
for (int i = 0; i < nx; i++) {
double x = Deltax*(i+1./2) + xmin;
for (int j = 0; j < ny; j++) {
double y = Deltay*(j+1./2) + ymin;
int k = 0;
for (scalar s in list){
field[i][len*j + k++] = interpolate (s, x, y);
}
}
}
for (int i = 0; i < nx; i++) {
double x = Deltax*(i+1./2) + xmin;
for (int j = 0; j < ny; j++) {
double y = Deltay*(j+1./2) + ymin;
fprintf (fp, "%g %g", x, y);
int k = 0;
for (scalar s in list){
fprintf (fp, " %g", field[i][len*j + k++]);
}
fputc ('\n', fp);
}
}
fflush (fp);
fclose (fp);
matrix_free (field);
}