hydrocode_Radial_Lag 0.3
This is an implementation of fully explict forward Euler scheme for multi-D radially symmetric compressible flows on Lagrangian coordinate
hydrocode.c
浏览该文件的文档.
1
94#include <stdio.h>
95#include <stdlib.h>
96#include <string.h>
97#include <math.h>
98
99#include "../include/var_struc.h"
100#include "../include/file_io.h"
101#include "../include/finite_volume.h"
102#include "../include/meshing.h"
103
104
105#ifdef DOXYGEN_PREDEFINED
110#define NODATPLOT
115#define HDF5PLOT
120#define NOTECPLOT
121#endif
122
123double config[N_CONF];
124
125#define CV_INIT_FV_RESET_MEM(v, N) \
126 do { \
127 CV.v = (double **)malloc(N * sizeof(double *)); \
128 if(CV.v == NULL) \
129 { \
130 printf("NOT enough memory! %s\n", #v); \
131 retval = 5; \
132 goto return_NULL; \
133 } \
134 for(k = 0; k < N; ++k) \
135 { \
136 CV.v[k] = (double *)malloc(Md * sizeof(double)); \
137 if(CV.v[k] == NULL) \
138 { \
139 printf("NOT enough memory! %s[%d]\n", #v, k); \
140 retval = 5; \
141 goto return_NULL; \
142 } \
143 } \
144 memmove(CV.v[0]+1, FV0.v, Ncell * sizeof(double)); \
145 free(FV0.v); \
146 FV0.v = NULL; \
147 } while(0)
148
164int main(int argc, char *argv[])
165{
166 int k, j, retval = 0;
167 // Initialize configuration data array
168 for(k = 1; k < N_CONF; k++)
169 config[k] = INFINITY;
170
171 char * scheme = NULL; // Riemann_exact(Godunov), GRP
172 arg_preprocess(4, argc, argv, scheme);
173
174 // Set dimension.
175 config[0] = (double)1; // Dimension of input data = 1
176
177 // The number of times steps of the fluid data stored for plotting.
178 int N, N_plot;
179 double *time_plot;
180 /*
181 * We read the initial data files.
182 * The function initialize return a point pointing to the position
183 * of a block of memory consisting (Ncell) variables of type double.
184 * The (Ncell) array elements of these variables are the initial value.
185 */
186 struct flu_var FV0 = initialize_1D(argv[1], &N, &N_plot, &time_plot); // Structure of initial data array pointer.
187 const int Ncell = (int)config[3]; // Number of computing cells in r direction
188 const int Md = Ncell+2; // Max vector dimension
189 const int order = (int)config[9];
190 double gamma = config[6];
191 int M = atoi(argv[4]); // M=1 planar; M=2 cylindrical; M=3 spherical
192 if(M != 1 && M != 2 && M != 3)
193 {
194 printf("Wrong spatial dimension number!\n");
195 exit(4);
196 }
197
198 struct radial_mesh_var rmv = radial_mesh_init(argv[1]);
199 radial_mesh_update(&rmv);
200
201 // Structure of fluid variables in computational cells array pointer.
202 struct cell_var_stru CV = {NULL};
203 double ** R = NULL;
204 double * cpu_time = (double *)malloc(N * sizeof(double));
205 R = (double **)malloc(N * sizeof(double *));
206 if(cpu_time == NULL)
207 {
208 printf("NOT enough memory! CPU_time\n");
209 retval = 5;
210 goto return_NULL;
211 }
212 if(R == NULL)
213 {
214 printf("NOT enough memory! R\n");
215 retval = 5;
216 goto return_NULL;
217 }
218 for(k = 0; k < N; ++k)
219 {
220 R[k] = (double *)malloc(Md * sizeof(double));
221 if(R[k] == NULL)
222 {
223 printf("NOT enough memory! R[%d]\n", k);
224 retval = 5;
225 goto return_NULL;
226 }
227 }
228
232#ifdef MULTIFLUID_BASICS
234 FV0.gamma = CV.gamma[0];
235 for(k = 1; k < N; ++k)
236 {
237 free(CV.gamma[k]);
238 CV.gamma[k] = CV.gamma[0];
239 }
240#endif
241 CV.E = (double **)malloc(N * sizeof(double *));
242 if(CV.E == NULL)
243 {
244 printf("NOT enough memory! E\n");
245 retval = 5;
246 goto return_NULL;
247 }
248 for(k = 0; k < N; ++k)
249 {
250 CV.E[k] = (double *)malloc(Md * sizeof(double));
251 if(CV.E[k] == NULL)
252 {
253 printf("NOT enough memory! E[%d]\n", k);
254 retval = 5;
255 goto return_NULL;
256 }
257 }
258 for(j = 1; j <= Ncell; ++j)
259 {
260#ifdef MULTIFLUID_BASICS
261 gamma = CV.gamma[0][j];
262#endif
263 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];
264 }
265
266 // Use GRP/Godunov scheme to solve it on Lagrangian coordinate.
267 config[8] = (double)1;
268 switch(order)
269 {
270 case 1:
271 config[41] = 0.0; // alpha = 0.0
272 case 2:
273 GRP_solver_radial_LAG_source(CV, &rmv, R, M, cpu_time, argv[2], N, &N_plot, time_plot);
274 break;
275 default:
276 printf("NOT appropriate order of the scheme! The order is %d.\n", order);
277 retval = 4;
278 goto return_NULL;
279 }
280
281 memmove(R[N_plot-1], rmv.RR, (Ncell+1) * sizeof(double));
282#ifndef NODATPLOT
283 file_1D_write(Ncell+1, N_plot, CV, R, cpu_time, argv[2], time_plot);
284#endif
285#ifdef HDF5PLOT
286 file_1D_write_HDF5(Ncell+1, N_plot, CV, R, cpu_time, argv[2], time_plot);
287#endif
288#ifndef NOTECPLOT
289 FV0.RHO = CV.RHO[N_plot-1];
290 FV0.U = CV.U[N_plot-1];
291 FV0.P = CV.P[N_plot-1];
292 file_radial_write_TEC(FV0, rmv.RR, argv[2], time_plot[N_plot-1]);
293#endif
294
295return_NULL:
297
298 FV0.RHO = NULL;
299 FV0.U = NULL;
300 FV0.P = NULL;
301 for(k = 0; k < N; ++k)
302 {
303 free(CV.E[k]);
304 free(CV.RHO[k]);
305 free(CV.U[k]);
306 free(CV.P[k]);
307 free(R[k]);
308 CV.E[k] = NULL;
309 CV.RHO[k] = NULL;
310 CV.U[k] = NULL;
311 CV.P[k] = NULL;
312 R[k] = NULL;
313 }
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#ifdef MULTIFLUID_BASICS
323 FV0.gamma = NULL;
324 free(CV.gamma[0]);
325 for(k = 0; k < N; ++k)
326 CV.gamma[k] = NULL;
327 free(CV.gamma);
328 CV.gamma = NULL;
329#endif
330 free(R);
331 R = NULL;
332 free(cpu_time);
333 cpu_time = NULL;
334
335 return retval;
336}
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 file_radial_write_TEC(const struct flu_var FV, const double *R, const char *problem, const double time)
This function write the radially symmetric 2-D solution into Tecplot output '.tec' files.
void GRP_solver_radial_LAG_source(struct cell_var_stru CV, struct radial_mesh_var *rmv, double *R[], const int M, double *cpu_time, const char *problem, int N_T, int *N_plot, double time_plot[])
This function use GRP scheme to solve radially(cylindrically) symmetric compressible flows of motion ...
int main(int argc, char *argv[])
This is the main function which constructs the main structure of the radially symmetric Lagrangian hy...
Definition: hydrocode.c:164
#define CV_INIT_FV_RESET_MEM(v, N)
Definition: hydrocode.c:125
double config[N_CONF]
Initial configuration data array.
Definition: hydrocode.c:123
void radial_mesh_update(struct radial_mesh_var *rmv)
This function updates radially symmetric meshing variables after each time step update.
Definition: radial_mesh.c:57
struct radial_mesh_var radial_mesh_init(const char *example)
This function initializes radially symmetric meshing variables.
Definition: radial_mesh.c:19
void radial_mesh_mem_free(struct radial_mesh_var *rmv)
This function free memory for storing radially symmetric meshing variables.
Definition: radial_mesh.c:94
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 ** gamma
Definition: var_struc.h:72
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
double * gamma
Definition: var_struc.h:52
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