HydroCODE_2D 0.1
This is a implementation of fully explict forward Euler scheme for 2-D Euler equations of motion on Eulerian coordinate
hydrocode.c
浏览该文件的文档.
1
94#include <errno.h>
95#include <stdio.h>
96#include <stdlib.h>
97#include <string.h>
98#include <math.h>
99
100#include "../include/var_struc.h"
101#include "../include/file_io.h"
102#include "../include/finite_volume.h"
103
104
105#ifdef DOXYGEN_PREDEFINED
110#define NODATPLOT
115#define HDF5PLOT
120#define NOTECPLOT
121#endif
122
123double config[N_CONF];
124
128#define CV_INIT_MEM(v, N) \
129 do { \
130 for(k = 0; k < N; ++k) \
131 { \
132 CV[k].v = (double **)malloc(n_x * sizeof(double *)); \
133 if(CV[k].v == NULL) \
134 { \
135 printf("NOT enough memory! CV[%d].%s\n", k, #v); \
136 retval = 5; \
137 goto return_NULL; \
138 } \
139 for(j = 0; j < n_x; ++j) \
140 { \
141 CV[k].v[j] = (double *)malloc(n_y * sizeof(double)); \
142 if(CV[k].v[j] == NULL) \
143 { \
144 printf("NOT enough memory! CV[%d].%s[%d]\n", k, #v, j); \
145 retval = 5; \
146 goto return_NULL; \
147 } \
148 } \
149 } \
150 } while (0)
151
164int main(int argc, char *argv[])
165{
166 int k, i, j, retval = 0;
167 // Initialize configuration data array
168 for(k = 1; k < N_CONF; k++)
169 config[k] = INFINITY;
170 char * scheme = NULL; // Riemann_exact(Godunov), GRP
171 arg_preprocess(4, argc, argv, scheme);
172
173 // Set dimension.
174 config[0] = (double)2; // Dimensionality = 2
175
176 // The number of times steps of the fluid data stored for plotting.
177 int N, N_plot;
178 double * time_plot;
179 /*
180 * We read the initial data files.
181 * The function initialize return a point pointing to the position
182 * of a block of memory consisting (n_x*n_y) variables of type double.
183 * The (n_x*n_y) array elements of these variables are the initial value.
184 */
185 struct flu_var FV0 = initialize_2D(argv[1], &N, &N_plot, &time_plot); // Structure of initial data array pointer.
186 /*
187 * (n_x*n_y) is the number of initial value as well as the number of grids.
188 * As (n_x*n_y) is frequently use to represent the number of grids,
189 * we do not use the name such as num_cell here to correspond to
190 * notation in the math theory.
191 */
192 const int n_x = (int)config[13], n_y = (int)config[14];
193 const double h_x = config[10], h_y = config[11], gamma = config[6];
194 const int order = (int)config[9];
195 const _Bool dim_split = (_Bool)config[33]; // Dimensional splitting?
196
197 // Structure of fluid variables in computational cells array pointer.
198 struct cell_var_stru * CV = (struct cell_var_stru*)malloc(N * sizeof(struct cell_var_stru));
199 double ** X, ** Y;
200 double * cpu_time = (double *)malloc(N * sizeof(double));
201 X = (double **)malloc((n_x+1) * sizeof(double *));
202 Y = (double **)malloc((n_x+1) * sizeof(double *));
203 if(cpu_time == NULL)
204 {
205 printf("NOT enough memory! CPU_time\n");
206 retval = 5;
207 goto return_NULL;
208 }
209 if(X == NULL || Y == NULL)
210 {
211 printf("NOT enough memory! X or Y\n");
212 retval = 5;
213 goto return_NULL;
214 }
215 for(j = 0; j <= n_x; ++j)
216 {
217 X[j] = (double *)malloc((n_y+1) * sizeof(double));
218 Y[j] = (double *)malloc((n_y+1) * sizeof(double));
219 if(X[j] == NULL || Y[j] == NULL)
220 {
221 printf("NOT enough memory! X[%d] or Y[%d]\n", j, j);
222 retval = 5;
223 goto return_NULL;
224 }
225 }
226 if(CV == NULL)
227 {
228 printf("NOT enough memory! Cell Variables\n");
229 retval = 5;
230 goto return_NULL;
231 }
232 // Initialize arrays of fluid variables in cells.
233 CV_INIT_MEM(RHO, N);
234 CV_INIT_MEM(U, N);
235 CV_INIT_MEM(V, N);
236 CV_INIT_MEM(P, N);
237 CV_INIT_MEM(E, N);
238 // Initialize the values of energy in computational cells and (x,y)-coordinate of the cell interfaces.
239 for(j = 0; j <= n_x; ++j)
240 for(i = 0; i <= n_y; ++i)
241 {
242 X[j][i] = j * h_x;
243 Y[j][i] = i * h_y;
244 }
245 for(j = 0; j < n_x; ++j)
246 for(i = 0; i < n_y; ++i)
247 {
248 CV[0].RHO[j][i] = FV0.RHO[i*n_x + j];
249 CV[0].U[j][i] = FV0.U[i*n_x + j];
250 CV[0].V[j][i] = FV0.V[i*n_x + j];
251 CV[0].P[j][i] = FV0.P[i*n_x + j];
252 CV[0].E[j][i] = 0.5*CV[0].U[j][i]*CV[0].U[j][i] + CV[0].P[j][i]/(gamma - 1.0)/CV[0].RHO[j][i];
253 CV[0].E[j][i] += 0.5*CV[0].V[j][i]*CV[0].V[j][i];
254 }
255
256 if (strcmp(argv[4],"EUL") == 0) // Use GRP/Godunov scheme to solve it on Eulerian coordinate.
257 {
258 config[8] = (double)0;
259 switch(order)
260 {
261 case 1:
262 config[41] = 0.0; // alpha = 0.0
263 case 2:
264 if (dim_split)
265 GRP_solver_2D_split_EUL_source(n_x, n_y, CV, X, Y, cpu_time, argv[2], N, &N_plot, time_plot);
266 else
267 GRP_solver_2D_EUL_source(n_x, n_y, CV, X, Y, cpu_time, argv[2], N, &N_plot, time_plot);
268 break;
269 default:
270 printf("NOT appropriate order of the scheme! The order is %d.\n", order);
271 retval = 4;
272 goto return_NULL;
273 }
274 }
275 else
276 {
277 printf("NOT appropriate coordinate framework! The framework is %s.\n", argv[4]);
278 retval = 4;
279 goto return_NULL;
280 }
281
282 // Write the final data down.
283#ifndef NODATPLOT
284 file_2D_write(n_x, n_y, N_plot, CV, X, Y, cpu_time, argv[2], time_plot);
285#endif
286#ifdef HDF5PLOT
287 file_2D_write_HDF5(n_x, n_y, N_plot, CV, X, Y, cpu_time, argv[2], time_plot);
288#endif
289#ifndef NOTECPLOT
290 file_2D_write_POINT_TEC(n_x, n_y, 1, CV + N_plot-1, X, Y, cpu_time, argv[2], time_plot + N_plot-1);
291#endif
292
293 return_NULL:
294 free(FV0.RHO);
295 free(FV0.U);
296 free(FV0.V);
297 free(FV0.P);
298 FV0.RHO = NULL;
299 FV0.U = NULL;
300 FV0.V = NULL;
301 FV0.P = NULL;
302 for(k = 0; k < N; ++k)
303 {
304 for(j = 0; j < n_x; ++j)
305 {
306 free(CV[k].RHO[j]);
307 free(CV[k].U[j]);
308 free(CV[k].V[j]);
309 free(CV[k].P[j]);
310 free(CV[k].E[j]);
311 CV[k].RHO[j] = NULL;
312 CV[k].U[j] = NULL;
313 CV[k].V[j] = NULL;
314 CV[k].P[j] = NULL;
315 CV[k].E[j] = NULL;
316 }
317 free(CV[k].RHO);
318 free(CV[k].U);
319 free(CV[k].V);
320 free(CV[k].P);
321 free(CV[k].E);
322 CV[k].RHO = NULL;
323 CV[k].U = NULL;
324 CV[k].V = NULL;
325 CV[k].P = NULL;
326 CV[k].E = NULL;
327 }
328 free(CV);
329 CV = NULL;
330 for(j = 0; j <= n_x; ++j)
331 {
332 free(X[j]);
333 free(Y[j]);
334 X[j] = NULL;
335 Y[j] = NULL;
336 }
337 free(X);
338 free(Y);
339 X = NULL;
340 Y = NULL;
341 free(cpu_time);
342 cpu_time = NULL;
343
344 return retval;
345}
struct flu_var initialize_2D(const char *name, int *N, int *N_plot, double *time_plot[])
This function reads the 2-D initial data file of density/velocity/pressure.
Definition: file_2D_in.c:119
void file_2D_write(const int n_x, const int n_y, const int N, const struct cell_var_stru CV[], double **X, double **Y, const double *cpu_time, const char *problem, const double time_plot[])
This function write the 2-D solution into output '.dat' files.
Definition: file_2D_out.c:55
void file_2D_write_POINT_TEC(const int n_x, const int n_y, const int N, const struct cell_var_stru CV[], double **X, double **Y, const double *cpu_time, const char *problem, const double time_plot[])
This function write the 2-D solution into Tecplot output files with point data.
Definition: file_2D_out.c:103
void file_2D_write_HDF5(const int n_x, const int n_y, const int N, const struct cell_var_stru CV[], double **X, double **Y, const double *cpu_time, const char *problem, double time_plot[])
This function write the 2-D solution into HDF5 output '.h5' files.
void GRP_solver_2D_EUL_source(const int m, const int n, struct cell_var_stru *CV, double **X, double **Y, double *cpu_time, const char *problem, int N_T, int *N_plot, double time_plot[])
This function use GRP scheme to solve 2-D Euler equations of motion on Eulerian coordinate without di...
void GRP_solver_2D_split_EUL_source(const int m, const int n, struct cell_var_stru *CV, double **X, double **Y, double *cpu_time, const char *problem, int N_T, int *N_plot, double time_plot[])
This function use GRP scheme to solve 2-D Euler equations of motion on Eulerian coordinate with dimen...
int main(int argc, char *argv[])
This is the main function which constructs the main structure of the 2-D Eulerian hydrocode.
Definition: hydrocode.c:164
double config[N_CONF]
Initial configuration data array.
Definition: hydrocode.c:123
#define CV_INIT_MEM(v, N)
N memory allocations to the initial fluid variable 'v' in the structure cell_var_stru.
Definition: hydrocode.c:128
pointer structure of VARiables on STRUctural computational grid CELLs.
Definition: var_struc.h:61
double ** E
specific total energy.
Definition: var_struc.h:62
double ** U
Definition: var_struc.h:63
double ** RHO
Definition: var_struc.h:63
double ** V
Definition: var_struc.h:63
double ** P
density, velocity components in direction x and y, pressure.
Definition: var_struc.h:63
pointer structure of FLUid VARiables array.
Definition: var_struc.h:48
double * P
Definition: var_struc.h:49
double * RHO
Definition: var_struc.h:49
double * U
Definition: var_struc.h:49
double * V
Definition: var_struc.h:49
void arg_preprocess(const int argc_least, const int argc, char *argv[], char *scheme)
This is a functions preprocesses ARGuments.
Definition: terminal_io.c:26
#define N_CONF
Define the number of configuration parameters.
Definition: var_struc.h:41