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
file_1D_in.c
浏览该文件的文档.
1
6#include <math.h>
7#include <string.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <stdbool.h>
11
12#include "../include/var_struc.h"
13#include "../include/file_io.h"
14
15
17#define N_MAX_1D 1000
18
24#define STR_FLU_INI(sfv, err_exit) \
25 do { \
26 strcpy(add, add_in); \
27 strcat(add, #sfv ".txt"); \
28 if((fp = fopen(add, "r")) == NULL) \
29 { \
30 strcpy(add, add_in); \
31 strcat(add, #sfv ".dat"); \
32 } \
33 if((fp = fopen(add, "r")) == NULL) \
34 { \
35 printf("Cannot open initial data file: %s!\n", #sfv); \
36 if(err_exit) \
37 exit(1); \
38 r = false; \
39 } \
40 if(r) \
41 { \
42 num_cell = flu_var_count(fp, add); \
43 if (num_cell < 1) \
44 { \
45 printf("Error in counting fluid variables in initial data file: %s!\n", #sfv); \
46 fclose(fp); \
47 exit(2); \
48 } \
49 if(isinf(config[3])) \
50 config[3] = (double)num_cell; \
51 else if(num_cell != (int)config[3]) \
52 { \
53 printf("Input unequal! num_%s=%d, num_cell=%d.\n", #sfv, num_cell, (int)config[3]); \
54 exit(2); \
55 } \
56 FV0.sfv = (double*)malloc(num_cell * sizeof(double)); \
57 if(FV0.sfv == NULL) \
58 { \
59 printf("NOT enough memory! %s\n", #sfv); \
60 exit(5); \
61 } \
62 if(flu_var_read(fp, FV0.sfv, num_cell)) \
63 { \
64 fclose(fp); \
65 exit(2); \
66 } \
67 fclose(fp); \
68 } \
69 else \
70 { \
71 FV0.sfv = (double*)malloc(num_cell * sizeof(double)); \
72 if(FV0.sfv == NULL) \
73 { \
74 printf("NOT enough memory! %s\n", #sfv); \
75 exit(5); \
76 } \
77 } \
78 } while(0)
79
93struct flu_var initialize_1D(const char * name, int * N, int * N_plot, double * time_plot[])
94{
95 struct flu_var FV0 = {NULL}; // Structure of initial data array pointer.
96
97 char add_in[FILENAME_MAX+40];
98 // Get the address of the initial data folder of the test example.
99 example_io(name, add_in, 1);
100
101 /*
102 * Read the configuration data.
103 * The detail could be seen in the definition of array config
104 * referring to file 'doc/config.csv'.
105 */
106 configurate(add_in);
107 printf(" delta_x\t= %g\n", config[10]);
108 printf(" bondary\t= %d\n", (int)config[17]);
109
110 (*N) = time_plot_read(add_in, N_MAX_1D, N_plot, time_plot);
111
112 char add[FILENAME_MAX+40]; // The address of the velocity/pressure/density file to read in.
113 FILE * fp; // The pointer to the above data files.
114 int num_cell = (int)config[3]; // The number of the numbers in the above data files.
115 _Bool r = true; // r: Whether to read data file successfully.
116
117 // Open the initial data files and initializes the reading of data.
118 STR_FLU_INI(RHO, 1);
119 STR_FLU_INI(U, 1);
120 STR_FLU_INI(P, 1);
121#ifdef MULTIFLUID_BASICS
122#ifdef MULTIPHASE_BASICS
123 STR_FLU_INI(Z_a, 1);
124 STR_FLU_INI(RHO_b,1);
125 STR_FLU_INI(U_b, 1);
126 STR_FLU_INI(V_b, 1);
127 STR_FLU_INI(P_b, 1);
128#else
129 STR_FLU_INI(PHI, 1);
130 STR_FLU_INI(Z_a, 0);
131 if(!r)
132 {
133 for(int i = 0; i < num_cell; i++)
134 FV0.Z_a[i] = FV0.PHI[i];
135 printf("\t Initial volume fraction 'Z_a' is initialized by mass fraction 'PHI'.\n");
136 r = true;
137 }
139 if(!r)
140 {
141 for(int i = 0; i < num_cell; i++)
142 FV0.gamma[i] = 1.0 + 1.0 / (FV0.Z_a[i]/(config[6]-1.0) + (1.0-FV0.Z_a[i])/(config[106]-1.0));
143 printf("\t Initial specific heat rate 'gamma' is initialized by volume fraction 'Z_a'.\n");
144 r = true;
145 }
146#endif
147#endif
148
149 printf("'%s' data initialized, grid cell number = %d.\n", add_in, num_cell);
150 return FV0;
151}
void configurate(const char *add_in)
This function controls configuration data reading and validation.
#define STR_FLU_INI(sfv, err_exit)
Count out and read in 1-D data of the initial fluid variable 'sfv'. If the initial data file does not...
Definition: file_1D_in.c:24
#define N_MAX_1D
The maximum number of 1-D data dimension storing fluid variables in memory.
Definition: file_1D_in.c:17
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
double config[N_CONF]
Initial configuration data array.
Definition: hydrocode.c:123
void example_io(const char *example, char *add_mkdir, const int i_or_o)
This function produces folder path for data input or output.
Definition: io_control.c:40
int time_plot_read(const char *add_in, const int N_max, int *N_plot, double *time_plot[])
This function reads the time data file for plotting 'time_plot.dat' and initialize tha array 'time_pl...
Definition: io_control.c:288
pointer structure of FLUid VARiables array.
Definition: var_struc.h:48
double * P
Definition: var_struc.h:49
double * PHI
Definition: var_struc.h:52
double * RHO
Definition: var_struc.h:49
double * U
Definition: var_struc.h:49
double * gamma
Definition: var_struc.h:52
double * Z_a
Definition: var_struc.h:51