-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinterface.c
More file actions
317 lines (277 loc) · 12.9 KB
/
interface.c
File metadata and controls
317 lines (277 loc) · 12.9 KB
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// 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-2025 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-liquid interface.
// -------------------------------------------------------------------
int apecss_interface_setdefaultoptions(struct APECSS_Interface *Interface)
{
Interface->sigma = 0.0;
Interface->LipidCoatingModel = APECSS_LIPIDCOATING_NONE;
Interface->sigma0 = 0.02;
Interface->Elasticity = 0.5;
Interface->Viscosity = 7.5e-9;
Interface->GompertzC = 0.0;
Interface->get_surfacetension = apecss_interface_surfacetension_clean;
Interface->get_pressure_surfacetension = apecss_interface_surfacetensionpressure_clean;
Interface->get_pressurederivative_surfacetension = apecss_interface_surfacetensionpressurederivative_clean;
Interface->get_pressure_viscous = apecss_interface_pressure_viscous_clean;
Interface->get_pressurederivative_viscous_expl = apecss_interface_pressurederivative_viscous_cleanexpl;
Interface->get_pressurederivative_viscous_impl = apecss_interface_pressurederivative_viscous_cleanimpl;
return (0);
}
int apecss_interface_readoptions(struct APECSS_Interface *Interface, 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, "interface", 9) == 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, "surfacetensioncoeff", 19) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Interface->sigma = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "lipidcoatingmodel", 17) == 0)
{
if ((l = apecss_readoneoption(OptionsFile, option3)) == EOF)
{
StatusSection = 0;
StatusFile = 0;
}
else
{
line += l - 1;
if (strncasecmp(option3, "none", 4) == 0)
{
Interface->LipidCoatingModel = APECSS_LIPIDCOATING_NONE;
}
else if (strncasecmp(option3, "marmottant", 10) == 0)
{
Interface->LipidCoatingModel = APECSS_LIPIDCOATING_MARMOTTANT;
}
else if (strncasecmp(option3, "gompertz-marmottant", 19) == 0)
{
Interface->LipidCoatingModel = APECSS_LIPIDCOATING_MARMOTTANT + APECSS_LIPIDCOATING_GOMPERTZFUNCTION;
}
}
}
else if (strncasecmp(option2, "sigmainit", 9) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Interface->sigma0 = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "elasticity", 10) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Interface->Elasticity = APECSS_STRINGTOFLOAT(option3);
}
else if (strncasecmp(option2, "dilatationalviscosity", 21) == 0)
{
l = apecss_readoneoption(OptionsFile, option3);
Interface->Viscosity = APECSS_STRINGTOFLOAT(option3);
}
else
{
sprintf(str, "An unknown option of INTERFACE is given: %s, line %i", option2, line);
apecss_erroronscreen(1, str);
}
}
}
else if (strncasecmp(option, "bubble", 6) == 0 || strncasecmp(option, "gas", 3) == 0 || strncasecmp(option, "liquid", 6) == 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_interface_processoptions(struct APECSS_Interface *Interface)
{
// Set the appropriate function pointers associated with bubble coating
if (Interface->LipidCoatingModel & APECSS_LIPIDCOATING_MARMOTTANT)
{
if (Interface->LipidCoatingModel & APECSS_LIPIDCOATING_GOMPERTZFUNCTION)
{
Interface->get_surfacetension = apecss_interface_surfacetension_gompertzmarmottant;
Interface->get_pressure_surfacetension = apecss_interface_surfacetensionpressure_gompertzmarmottant;
Interface->get_pressurederivative_surfacetension = apecss_interface_surfacetensionpressurederivative_gompertzmarmottant;
Interface->GompertzC = 2.0 * Interface->Elasticity * APECSS_E * APECSS_SQRT(1.0 + Interface->sigma * 0.5 / Interface->Elasticity) / Interface->sigma;
}
else
{
Interface->get_surfacetension = apecss_interface_surfacetension_marmottant;
Interface->get_pressure_surfacetension = apecss_interface_surfacetensionpressure_marmottant;
Interface->get_pressurederivative_surfacetension = apecss_interface_surfacetensionpressurederivative_marmottant;
}
Interface->get_pressure_viscous = apecss_interface_pressure_viscous_marmottant;
Interface->get_pressurederivative_viscous_expl = apecss_interface_pressurederivative_viscous_marmottantexpl;
Interface->get_pressurederivative_viscous_impl = apecss_interface_pressurederivative_viscous_marmottantimpl;
}
else
{
Interface->get_surfacetension = apecss_interface_surfacetension_clean;
Interface->get_pressure_surfacetension = apecss_interface_surfacetensionpressure_clean;
Interface->get_pressurederivative_surfacetension = apecss_interface_surfacetensionpressurederivative_clean;
Interface->get_pressure_viscous = apecss_interface_pressure_viscous_clean;
Interface->get_pressurederivative_viscous_expl = apecss_interface_pressurederivative_viscous_cleanexpl;
Interface->get_pressurederivative_viscous_impl = apecss_interface_pressurederivative_viscous_cleanimpl;
}
return (0);
}
// -------------------------------------------------------------------
// SURFACE TENSION COEFFICIENT
// -------------------------------------------------------------------
// Functions defining the surface tension coefficient and its
// derivative, based on the chosen model.
// -------------------------------------------------------------------
// The function for surface tension is chosen in
// apecss_interface_processoptions() and associated with the function
// pointer Interface->get_surfacetension().
// -------------------------------------------------------------------
APECSS_FLOAT apecss_interface_surfacetension_clean(APECSS_FLOAT R, struct APECSS_Bubble *Bubble) { return (Bubble->Interface->sigma); }
APECSS_FLOAT apecss_interface_surfacetension_marmottant(APECSS_FLOAT R, struct APECSS_Bubble *Bubble)
{
APECSS_FLOAT sigma;
if (R < Bubble->Rbuck)
sigma = 0.0;
else if (R > Bubble->Rrupt)
sigma = Bubble->Interface->sigma;
else
sigma = Bubble->Interface->Elasticity * (APECSS_POW2(R) / APECSS_POW2(Bubble->Rbuck) - 1.0);
return (sigma);
}
APECSS_FLOAT apecss_interface_surfacetension_gompertzmarmottant(APECSS_FLOAT R, struct APECSS_Bubble *Bubble)
{
return (Bubble->Interface->sigma * APECSS_EXP(-Bubble->GompertzB * APECSS_EXP(Bubble->Interface->GompertzC * (1.0 - R / Bubble->Rbuck))));
}
APECSS_FLOAT apecss_interface_surfacetensionderivative_marmottant(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Bubble *Bubble)
{
APECSS_FLOAT dot_sigma;
if (R < Bubble->Rbuck)
dot_sigma = 0.0;
else if (R > Bubble->Rrupt)
dot_sigma = 0.0;
else
dot_sigma = 2.0 * Bubble->Interface->Elasticity * R * U / APECSS_POW2(Bubble->Rbuck);
return (dot_sigma);
}
APECSS_FLOAT apecss_interface_surfacetensionderivative_gompertzmarmottant(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Bubble *Bubble)
{
return (apecss_interface_surfacetension_gompertzmarmottant(R, Bubble) * U * Bubble->GompertzB * Bubble->Interface->GompertzC *
APECSS_EXP(Bubble->Interface->GompertzC * (1.0 - R / Bubble->Rbuck)) / Bubble->Rbuck);
}
// -------------------------------------------------------------------
// SURFACE TENSION PRESSURE
// -------------------------------------------------------------------
// Functions defining the pressure contribution due to surface tension
// -------------------------------------------------------------------
// The functions are chosen in apecss_interface_processoptions() and
// associated with the function pointers:
// - Interface->get_pressure_surfacetension()
// - Interface->get_pressurederivative_surfacetension()
// -------------------------------------------------------------------
APECSS_FLOAT apecss_interface_surfacetensionpressure_clean(APECSS_FLOAT R, struct APECSS_Bubble *Bubble)
{
return (Bubble->dimensionality * Bubble->Interface->sigma / R);
}
APECSS_FLOAT apecss_interface_surfacetensionpressure_marmottant(APECSS_FLOAT R, struct APECSS_Bubble *Bubble)
{
return (2.0 * apecss_interface_surfacetension_marmottant(R, Bubble) / R);
}
APECSS_FLOAT apecss_interface_surfacetensionpressure_gompertzmarmottant(APECSS_FLOAT R, struct APECSS_Bubble *Bubble)
{
return (2.0 * apecss_interface_surfacetension_gompertzmarmottant(R, Bubble) / R);
}
APECSS_FLOAT apecss_interface_surfacetensionpressurederivative_clean(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Bubble *Bubble)
{
return (Bubble->dimensionality * Bubble->Interface->sigma * U / APECSS_POW2(R));
}
APECSS_FLOAT apecss_interface_surfacetensionpressurederivative_marmottant(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Bubble *Bubble)
{
return (2.0 * (apecss_interface_surfacetension_marmottant(R, Bubble) * U / APECSS_POW2(R) -
apecss_interface_surfacetensionderivative_marmottant(R, U, Bubble) / R));
}
APECSS_FLOAT apecss_interface_surfacetensionpressurederivative_gompertzmarmottant(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Bubble *Bubble)
{
return (2.0 * (apecss_interface_surfacetension_gompertzmarmottant(R, Bubble) * U / APECSS_POW2(R) -
apecss_interface_surfacetensionderivative_gompertzmarmottant(R, U, Bubble) / R));
}
// -------------------------------------------------------------------
// VISCOUS PRESSURE
// -------------------------------------------------------------------
// Functions defining the pressure contribution due to viscous
// stresses of the interface coating.
// -------------------------------------------------------------------
// The functions are chosen in apecss_interface_processoptions() and
// associated with the function pointers:
// - Interface->get_pressure_viscous()
// - Interface->get_pressurederivative_viscous_expl()
// - Interface->get_pressurederivative_viscous_impl()
// -------------------------------------------------------------------
APECSS_FLOAT apecss_interface_pressure_viscous_clean(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Interface *Interface) { return (0.0); }
APECSS_FLOAT apecss_interface_pressure_viscous_marmottant(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Interface *Interface)
{
return (4.0 * Interface->Viscosity * U / APECSS_POW2(R));
}
APECSS_FLOAT apecss_interface_pressurederivative_viscous_cleanexpl(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Interface *Interface) { return (0.0); }
APECSS_FLOAT apecss_interface_pressurederivative_viscous_marmottantexpl(APECSS_FLOAT R, APECSS_FLOAT U, struct APECSS_Interface *Interface)
{
return (8.0 * Interface->Viscosity * APECSS_POW2(U) / APECSS_POW3(R));
}
APECSS_FLOAT apecss_interface_pressurederivative_viscous_cleanimpl(APECSS_FLOAT R, struct APECSS_Interface *Interface) { return (0.0); }
APECSS_FLOAT apecss_interface_pressurederivative_viscous_marmottantimpl(APECSS_FLOAT R, struct APECSS_Interface *Interface)
{
return (4.0 * Interface->Viscosity / APECSS_POW2(R));
}