-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgas.c
271 lines (244 loc) · 9.49 KB
/
gas.c
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// This source file is part of APECSS, an open-source software toolbox
// for the computation of pressure-driven bubble dynamics and acoustic
// emissions in spherical symmetry.
//
// Copyright (C) 2022-2024 The APECSS Developers
//
// The APECSS Developers are listed in the README.md file available in
// the GitHub repository at https://github.com/polycfd/apecss.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include "apecss.h"
// -------------------------------------------------------------------
// OPTIONS
// -------------------------------------------------------------------
// Functions initializing, processing and handling the options of the
// gas phase.
// -------------------------------------------------------------------
int apecss_gas_setdefaultoptions(struct APECSS_Gas *Gas)
{
Gas->EoS = APECSS_GAS_IG;
Gas->Gamma = 1.4;
Gas->B = 0.0;
Gas->b = 0.0;
Gas->dmol = -1.0;
Gas->mmol = -1.0;
Gas->pref = 1.0e5;
Gas->rhoref = 1.2;
Gas->get_pressure = apecss_gas_pressure_ig;
Gas->get_pressurederivative = apecss_gas_pressurederivative_ig;
return (0);
}
int apecss_gas_readoptions(struct APECSS_Gas *Gas, char *OptionsDir)
{
int l = 0;
int line = 0;
FILE *OptionsFile;
char str[APECSS_STRINGLENGTH_SPRINTF];
char option[APECSS_STRINGLENGTH], option2[APECSS_STRINGLENGTH], option3[APECSS_STRINGLENGTH];
int StatusFile = 1;
int StatusSection = 1;
if ((OptionsFile = fopen(OptionsDir, "r")) == (FILE *) NULL)
{
sprintf(str, "File %s cannot be opened for reading.\n", OptionsDir);
apecss_erroronscreen(1, str);
}
while ((l = apecss_readoneoption(OptionsFile, option)) != EOF && StatusFile == 1)
{
line += l;
if (strncasecmp(option, "gas", 3) == 0)
{
StatusSection = 1;
while (StatusSection == 1 && (l = apecss_readoneoption(OptionsFile, option2)) != EOF)
{
line += l;
if (strncasecmp(option2, "END", 3) == 0)
{
StatusSection = 0;
}
else if (strncasecmp(option2, "eos", 3) == 0)
{
if ((l = apecss_readoneoption(OptionsFile, option3)) == EOF)
{
StatusSection = 0;
StatusFile = 0;
}
else
{
line += l - 1;
if (strncasecmp(option3, "ig", 2) == 0)
{
Gas->EoS = APECSS_GAS_IG;
}
else if (strncasecmp(option3, "hc", 2) == 0)
{
Gas->EoS = APECSS_GAS_HC;
}
else if (strncasecmp(option3, "nasg", 4) == 0)
{
Gas->EoS = APECSS_GAS_NASG;
}
}
}
else if (strncasecmp(option2, "polytropicexponent", 18) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Gas->Gamma = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "referencepressure", 17) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Gas->pref = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "referencedensity", 16) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Gas->rhoref = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "covolume", 8) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Gas->b = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "taitpressureconst", 17) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Gas->B = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "molecularweight", 15) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Gas->mmol = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "moleculardiameter", 17) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Gas->dmol = APECSS_STRINGTOFLOAT(option3);
}
else
{
sprintf(str, "An unknown option of GAS is given: %s, line %i", option2, line);
apecss_erroronscreen(1, str);
}
}
}
else if (strncasecmp(option, "bubble", 6) == 0 || strncasecmp(option, "liquid", 6) == 0 || strncasecmp(option, "interface", 9) == 0 ||
strncasecmp(option, "results", 7) == 0 || strncasecmp(option, "odesolver", 9) == 0)
{
StatusSection = 1;
while (StatusSection == 1 && (l = apecss_readoneoption(OptionsFile, option2)) != EOF)
{
line += l;
if (strncasecmp(option2, "END", 3) == 0)
{
StatusSection = 0;
}
else
{
// Nothing to be done here.
}
}
}
else
{
sprintf(str, "An unknown Section is given: %s, line %i", option, line);
apecss_erroronscreen(1, str);
}
}
fclose(OptionsFile);
return (0);
}
int apecss_gas_processoptions(struct APECSS_Gas *Gas)
{
if (Gas->EoS == APECSS_GAS_IG)
{
// Set the function pointers for the pressure
Gas->get_pressure = apecss_gas_pressure_ig;
Gas->get_pressurederivative = apecss_gas_pressurederivative_ig;
// Compute the reference coefficient for the gas
Gas->Kref = Gas->rhoref / (APECSS_POW(Gas->pref, 1.0 / Gas->Gamma));
}
else if (Gas->EoS == APECSS_GAS_NASG)
{
// Set the function pointers for the pressure
Gas->get_pressure = apecss_gas_pressure_nasg;
Gas->get_pressurederivative = apecss_gas_pressurederivative_nasg;
if (Gas->mmol > 0.0 && Gas->dmol > 0.0)
{
// Compute the co-volume based on the molecular properties
Gas->b = APECSS_AVOGADRO * 4.0 * APECSS_PI * APECSS_POW3(Gas->dmol) / (6.0 * Gas->mmol);
}
// Compute the reference coefficient for the gas
Gas->Kref = Gas->rhoref / (APECSS_POW(Gas->pref + Gas->B, 1.0 / Gas->Gamma) * (1.0 - Gas->b * Gas->rhoref));
}
else if (Gas->EoS == APECSS_GAS_HC)
{
// Set the function pointers for the pressure
Gas->get_pressure = apecss_gas_pressure_hc;
Gas->get_pressurederivative = apecss_gas_pressurederivative_hc;
// Compute the reference coefficient for the gas
Gas->Kref = Gas->rhoref / (APECSS_POW(Gas->pref, 1.0 / Gas->Gamma));
}
else
{
apecss_erroronscreen(1, "Defined equation of state for the gas is unknown.");
}
return (0);
}
// -------------------------------------------------------------------
// PROPERTIES
// -------------------------------------------------------------------
// Functions defining the density of the gas phase.
// -------------------------------------------------------------------
APECSS_FLOAT apecss_gas_density_constmass(APECSS_FLOAT R, struct APECSS_Bubble *Bubble)
{
return (Bubble->rhoG0 * APECSS_POW(Bubble->R0 / R, Bubble->dimensionality + 1.0));
}
APECSS_FLOAT apecss_gas_densityderivative_constmass(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Bubble *Bubble)
{
return (-(Bubble->dimensionality + 1.0) * apecss_gas_density_constmass(R, Bubble) * U / R);
}
// -------------------------------------------------------------------
// PRESSURE
// -------------------------------------------------------------------
// Functions defining the gas pressure and its derivatives.
// -------------------------------------------------------------------
// The functions are chosen in apecss_gas_processoptions() and
// associated with the function pointers:
// - Gas->get_pressure()
// - Gas->get_pressurederivative()
// -------------------------------------------------------------------
APECSS_FLOAT apecss_gas_pressure_ig(APECSS_FLOAT *Sol, struct APECSS_Bubble *Bubble)
{
return (Bubble->pG0 * APECSS_POW(Bubble->R0 / Sol[1], (Bubble->dimensionality + 1.0) * Bubble->Gas->Gamma));
}
APECSS_FLOAT apecss_gas_pressure_hc(APECSS_FLOAT *Sol, struct APECSS_Bubble *Bubble)
{
return (Bubble->pG0 * APECSS_POW((APECSS_POW(Bubble->R0, Bubble->dimensionality + 1.0) - APECSS_POW(Bubble->r_hc, Bubble->dimensionality + 1.0)) /
(APECSS_POW(Sol[1], Bubble->dimensionality + 1.0) - APECSS_POW(Bubble->r_hc, Bubble->dimensionality + 1.0)),
Bubble->Gas->Gamma));
}
APECSS_FLOAT apecss_gas_pressure_nasg(APECSS_FLOAT *Sol, struct APECSS_Bubble *Bubble)
{
APECSS_FLOAT rhoG = apecss_gas_density_constmass(Sol[1], Bubble);
return (-Bubble->Gas->B +
(Bubble->pG0 + Bubble->Gas->B) *
APECSS_POW((rhoG * (1.0 - Bubble->Gas->b * Bubble->rhoG0)) / (Bubble->rhoG0 * (1.0 - Bubble->Gas->b * rhoG)), Bubble->Gas->Gamma));
}
APECSS_FLOAT apecss_gas_pressurederivative_ig(APECSS_FLOAT *Sol, APECSS_FLOAT t, struct APECSS_Bubble *Bubble)
{
return (-(Bubble->dimensionality + 1.0) * apecss_gas_pressure_ig(Sol, Bubble) * Bubble->Gas->Gamma * Sol[0] / Sol[1]);
}
APECSS_FLOAT apecss_gas_pressurederivative_hc(APECSS_FLOAT *Sol, APECSS_FLOAT t, struct APECSS_Bubble *Bubble)
{
return (-(Bubble->dimensionality + 1.0) * apecss_gas_pressure_hc(Sol, Bubble) * Bubble->Gas->Gamma * APECSS_POW2(Sol[1]) * Sol[0] /
(APECSS_POW3(Sol[1]) - APECSS_POW3(Bubble->r_hc)));
}
APECSS_FLOAT apecss_gas_pressurederivative_nasg(APECSS_FLOAT *Sol, APECSS_FLOAT t, struct APECSS_Bubble *Bubble)
{
APECSS_FLOAT rhoG = apecss_gas_density_constmass(Sol[1], Bubble);
return (apecss_gas_densityderivative_constmass(Sol[1], Sol[0], Bubble) * Bubble->Gas->Gamma * (apecss_gas_pressure_nasg(Sol, Bubble) + Bubble->Gas->B) /
(rhoG * (1.0 - Bubble->Gas->b * rhoG)));
}