HydroCODE_1D 0.1
This is a implementation of fully explict forward Euler scheme for 1-D Euler equations of motion on Lagrangian/Eulerian coordinate
hydrocode.c
浏览该文件的文档.
1
87#include <errno.h>
88#include <stdio.h>
89#include <stdlib.h>
90#include <string.h>
91#include <math.h>
92
93#include "../include/var_struc.h"
94#include "../include/file_io.h"
95#include "../include/finite_volume.h"
96
97
98#ifdef DOXYGEN_PREDEFINED
103#define NODATPLOT
108#define HDF5PLOT
109#endif
110
111double config[N_CONF];
112
116#define CV_INIT_MEM(v, N) \
117 do { \
118 CV.v = (double **)malloc(N * sizeof(double *)); \
119 if(CV.v == NULL) \
120 { \
121 printf("NOT enough memory! %s\n", #v); \
122 retval = 5; \
123 goto return_NULL; \
124 } \
125 CV.v[0] = FV0.v; \
126 for(k = 1; k < N; ++k) \
127 { \
128 CV.v[k] = (double *)malloc(m * sizeof(double)); \
129 if(CV.v[k] == NULL) \
130 { \
131 printf("NOT enough memory! %s[%d]\n", #v, k); \
132 retval = 5; \
133 goto return_NULL; \
134 } \
135 } \
136 } while (0)
137
150int main(int argc, char *argv[])
151{
152 int k, j, retval = 0;
153 // Initialize configuration data array
154 for(k = 1; k < N_CONF; k++)
155 config[k] = INFINITY;
156
157 char * scheme = NULL; // Riemann_exact(Godunov), GRP
158 arg_preprocess(4, argc, argv, scheme);
159
160 // Set dimension.
161 config[0] = (double)1; // Dimensionality = 1
162
163 // The number of times steps of the fluid data stored for plotting.
164 int N, N_plot;
165 double * time_plot;
166 /*
167 * We read the initial data files.
168 * The function initialize return a point pointing to the position
169 * of a block of memory consisting (m) variables of type double.
170 * The (m) array elements of these variables are the initial value.
171 */
172 struct flu_var FV0 = initialize_1D(argv[1], &N, &N_plot, &time_plot); // Structure of initial data array pointer.
173 /*
174 * (m) is the number of initial value as well as the number of grids.
175 * As (m) is frequently use to represent the number of grids,
176 * we do not use the name such as num_cell here to correspond to
177 * notation in the math theory.
178 */
179 const int m = (int)config[3];
180 const double h = config[10], gamma = config[6];
181 const int order = (int)config[9];
182
183 // Structure of fluid variables in computational cells array pointer.
184 struct cell_var_stru CV = {NULL};
185 double ** X = NULL;
186 double * cpu_time = (double *)malloc(N * sizeof(double));
187 X = (double **)malloc(N * sizeof(double *));
188 if(cpu_time == NULL)
189 {
190 printf("NOT enough memory! CPU_time\n");
191 retval = 5;
192 goto return_NULL;
193 }
194 if(X == NULL)
195 {
196 printf("NOT enough memory! X\n");
197 retval = 5;
198 goto return_NULL;
199 }
200 for(k = 0; k < N; ++k)
201 {
202 X[k] = (double *)malloc((m+1) * sizeof(double));
203 if(X[k] == NULL)
204 {
205 printf("NOT enough memory! X[%d]\n", k);
206 retval = 5;
207 goto return_NULL;
208 }
209 }
210 // Initialize arrays of fluid variables in cells.
211 CV_INIT_MEM(RHO, N);
212 CV_INIT_MEM(U, N);
213 CV_INIT_MEM(P, N);
214 CV.E = (double **)malloc(N * sizeof(double *));
215 if(CV.E == NULL)
216 {
217 printf("NOT enough memory! E\n");
218 retval = 5;
219 goto return_NULL;
220 }
221 for(k = 0; k < N; ++k)
222 {
223 CV.E[k] = (double *)malloc(m * sizeof(double));
224 if(CV.E[k] == NULL)
225 {
226 printf("NOT enough memory! E[%d]\n", k);
227 retval = 5;
228 goto return_NULL;
229 }
230 }
231 // Initialize the values of energy in computational cells and x-coordinate of the cell interfaces.
232 for(j = 0; j <= m; ++j)
233 X[0][j] = h * j;
234 for(j = 0; j < m; ++j)
235 CV.E[0][j] = 0.5*CV.U[0][j]*CV.U[0][j] + CV.P[0][j]/(gamma - 1.0)/CV.RHO[0][j];
236
237 if (strcmp(argv[4],"LAG") == 0) // Use GRP/Godunov scheme to solve it on Lagrangian coordinate.
238 {
239 config[8] = (double)1;
240 switch(order)
241 {
242 case 1:
243 Godunov_solver_LAG_source(m, CV, X, cpu_time, &N, time_plot);
244 break;
245 case 2:
246 GRP_solver_LAG_source(m, CV, X, cpu_time, &N, time_plot);
247 break;
248 default:
249 printf("NOT appropriate order of the scheme! The order is %d.\n", order);
250 retval = 4;
251 goto return_NULL;
252 }
253 }
254 else if (strcmp(argv[4],"EUL") == 0) // Use GRP/Godunov scheme to solve it on Eulerian coordinate.
255 {
256 config[8] = (double)0;
257 for (k = 1; k < N; ++k)
258 for (j = 0; j <= m; ++j)
259 X[k][j] = X[0][j];
260 switch(order)
261 {
262 case 1:
263 Godunov_solver_EUL_source(m, CV, cpu_time, &N, time_plot);
264 break;
265 case 2:
266 GRP_solver_EUL_source(m, CV, cpu_time, &N, time_plot);
267 break;
268 default:
269 printf("NOT appropriate order of the scheme! The order is %d.\n", order);
270 retval = 4;
271 goto return_NULL;
272 }
273 }
274 else
275 {
276 printf("NOT appropriate coordinate framework! The framework is %s.\n", argv[4]);
277 retval = 4;
278 goto return_NULL;
279 }
280
281 // Write the final data down.
282#ifndef NODATPLOT
283 file_1D_write(m, N, CV, X, cpu_time, argv[2], time_plot);
284#endif
285#ifdef HDF5PLOT
286 file_1D_write_HDF5(m, N, CV, X, cpu_time, argv[2], time_plot);
287#endif
288
289 return_NULL:
290 free(FV0.RHO);
291 free(FV0.U);
292 free(FV0.P);
293 FV0.RHO = NULL;
294 FV0.U = NULL;
295 FV0.P = NULL;
296 for(k = 1; k < N; ++k)
297 {
298 free(CV.E[k]);
299 free(CV.RHO[k]);
300 free(CV.U[k]);
301 free(CV.P[k]);
302 free(X[k]);
303 CV.E[k] = NULL;
304 CV.RHO[k] = NULL;
305 CV.U[k] = NULL;
306 CV.P[k] = NULL;
307 X[k] = NULL;
308 }
309 free(CV.E[0]);
310 CV.E[0] = NULL;
311 CV.RHO[0] = NULL;
312 CV.U[0] = NULL;
313 CV.P[0] = NULL;
314 free(CV.E);
315 free(CV.RHO);
316 free(CV.U);
317 free(CV.P);
318 CV.E = NULL;
319 CV.RHO = NULL;
320 CV.U = NULL;
321 CV.P = NULL;
322 free(X);
323 X = NULL;
324 free(cpu_time);
325 cpu_time = NULL;
326
327 return retval;
328}
struct flu_var initialize_1D(const char *name, int *N, int *N_plot, double *time_plot[])
This function reads the 1-D initial data file of density/velocity/pressure and performs some other in...
Definition: file_1D_in.c:93
void file_1D_write(const int m, const int N, const struct cell_var_stru CV, double *X[], const double *cpu_time, const char *problem, const double time_plot[])
This function write the 1-D solution into output '.dat' files.
Definition: file_1D_out.c:49
void file_1D_write_HDF5(const int m, const int N, const struct cell_var_stru CV, double *X[], const double *cpu_time, const char *problem, double time_plot[])
This function write the 1-D solution into HDF5 output '.h5' files.
Definition: file_out_hdf5.c:54
void Godunov_solver_EUL_source(const int m, struct cell_var_stru CV, double *cpu_time, int *N_plot, double time_plot[])
This function use Godunov scheme to solve 1-D Euler equations of motion on Eulerian coordinate.
void Godunov_solver_LAG_source(const int m, struct cell_var_stru CV, double *X[], double *cpu_time, int *N_plot, double time_plot[])
This function use Godunov scheme to solve 1-D Euler equations of motion on Lagrangian coordinate.
void GRP_solver_EUL_source(const int m, struct cell_var_stru CV, double *cpu_time, int *N_plot, double time_plot[])
This function use GRP scheme to solve 1-D Euler equations of motion on Eulerian coordinate.
void GRP_solver_LAG_source(const int m, struct cell_var_stru CV, double *X[], double *cpu_time, int *N_plot, double time_plot[])
This function use GRP scheme to solve 1-D Euler equations of motion on Lagrangian coordinate.
int main(int argc, char *argv[])
This is the main function which constructs the main structure of the 1-D Lagrangian/Eulerian hydrocod...
Definition: hydrocode.c:150
double config[N_CONF]
Initial configuration data array.
Definition: hydrocode.c:111
#define CV_INIT_MEM(v, N)
N memory allocations to the initial fluid variable 'v' in the structure cell_var_stru.
Definition: hydrocode.c:116
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 ** 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
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