-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathFF.C
276 lines (244 loc) · 9.16 KB
/
FF.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
272
273
274
275
276
#include "FF.H"
#include "Utilities.H"
using namespace Foam;
preciceAdapter::FF::FluidFluid::FluidFluid(
const Foam::fvMesh& mesh)
: mesh_(mesh)
{
}
bool preciceAdapter::FF::FluidFluid::configure(const IOdictionary& adapterConfig)
{
DEBUG(adapterInfo("Configuring the FF module..."));
// Read the FF-specific options from the adapter's configuration file
if (!readConfig(adapterConfig))
{
return false;
}
// NOTE: If you want to add a new solver type, which you can manually
// specify in the configuration, add it here. See also the methods
// addWriters() and addReaders().
// Check the solver type and determine it if needed
if (
solverType_.compare("compressible") == 0 || solverType_.compare("incompressible") == 0)
{
DEBUG(adapterInfo("Known solver type: " + solverType_));
}
else if (solverType_.compare("none") == 0)
{
DEBUG(adapterInfo("Determining the solver type..."));
solverType_ = determineSolverType();
}
else
{
DEBUG(adapterInfo("Determining the solver type for the FF module... (override by setting solverType to one of {compressible, incompressible})"));
solverType_ = determineSolverType();
}
return true;
}
bool preciceAdapter::FF::FluidFluid::readConfig(const IOdictionary& adapterConfig)
{
const dictionary& FFdict = adapterConfig.subOrEmptyDict("FF");
// Read the solver type (if not specified, it is determined automatically)
solverType_ = FFdict.lookupOrDefault<word>("solverType", "");
DEBUG(adapterInfo(" user-defined solver type : " + solverType_));
// Read the name of the velocity field (if different)
nameU_ = FFdict.lookupOrDefault<word>("nameU", "U");
DEBUG(adapterInfo(" velocity field name : " + nameU_));
// Read the name of the pressure field (if different)
nameP_ = FFdict.lookupOrDefault<word>("nameP", "p");
DEBUG(adapterInfo(" pressure field name : " + nameP_));
// Read the name of the temperature field (if different)
nameT_ = FFdict.lookupOrDefault<word>("nameT", "T");
DEBUG(adapterInfo(" temperature field name : " + nameT_));
// Read the name of the phase variable field (if different)
nameAlpha_ = FFdict.lookupOrDefault<word>("nameAlpha", "alpha");
DEBUG(adapterInfo(" phase variable (alpha) field name : " + nameAlpha_));
// Read the name of the face flux field (if different)
namePhi_ = FFdict.lookupOrDefault<word>("namePhi", "phi");
DEBUG(adapterInfo(" face flux field name : " + namePhi_));
// Check whether to enable flux correction for velocity
fluxCorrection_ = FFdict.lookupOrDefault<bool>("fluxCorrection", false);
DEBUG(adapterInfo(" flux correction of velocity is set to : " + std::to_string(fluxCorrection_)));
return true;
}
std::string preciceAdapter::FF::FluidFluid::determineSolverType()
{
// NOTE: When coupling a different variable, you may want to
// add more cases here. Or you may provide the solverType in the config.
std::string solverType = "unknown";
dimensionSet pressureDimensionsCompressible(1, -1, -2, 0, 0, 0, 0);
dimensionSet pressureDimensionsIncompressible(0, 2, -2, 0, 0, 0, 0);
if (mesh_.foundObject<volScalarField>("p"))
{
const volScalarField& p_ = mesh_.lookupObject<volScalarField>("p");
if (p_.dimensions() == pressureDimensionsCompressible)
solverType = "compressible";
else if (p_.dimensions() == pressureDimensionsIncompressible)
solverType = "incompressible";
// TODO: Add special case for multiphase solvers.
// Currently, interFoam is misclassified as "compressible".
}
if (solverType == "unknown")
adapterInfo("Failed to determine the solver type. "
"Please specify your solver type in the FF section of the "
"preciceDict. Known solver types for FF are: "
"incompressible and "
"compressible",
"error");
DEBUG(adapterInfo("Automatically determined solver type : " + solverType));
return solverType;
}
bool preciceAdapter::FF::FluidFluid::addWriters(std::string dataName, Interface* interface)
{
bool found = true; // Set to false later, if needed.
if (dataName.find("VelocityGradient") == 0)
{
interface->addCouplingDataWriter(
dataName,
new VelocityGradient(mesh_, nameU_));
DEBUG(adapterInfo("Added writer: Velocity Gradient."));
}
else if (dataName.find("Velocity") == 0)
{
interface->addCouplingDataWriter(
dataName,
new Velocity(mesh_, nameU_, namePhi_, fluxCorrection_));
DEBUG(adapterInfo("Added writer: Velocity."));
}
else if (dataName.find("PressureGradient") == 0)
{
interface->addCouplingDataWriter(
dataName,
new PressureGradient(mesh_, nameP_));
DEBUG(adapterInfo("Added writer: Pressure Gradient."));
}
else if (dataName.find("Pressure") == 0)
{
interface->addCouplingDataWriter(
dataName,
new Pressure(mesh_, nameP_));
DEBUG(adapterInfo("Added writer: Pressure."));
}
else if (dataName.find("FlowTemperatureGradient") == 0)
{
interface->addCouplingDataWriter(
dataName,
new TemperatureGradient(mesh_, nameT_));
DEBUG(adapterInfo("Added writer: Flow Temperature Gradient."));
}
else if (dataName.find("FlowTemperature") == 0)
{
interface->addCouplingDataWriter(
dataName,
new Temperature(mesh_, nameT_));
DEBUG(adapterInfo("Added writer: Flow Temperature."));
}
else if (dataName.find("AlphaGradient") == 0)
{
interface->addCouplingDataWriter(
dataName,
new AlphaGradient(mesh_, nameAlpha_));
DEBUG(adapterInfo("Added writer: Alpha Gradient."));
}
else if (dataName.find("Alpha") == 0)
{
interface->addCouplingDataWriter(
dataName,
new Alpha(mesh_, nameAlpha_));
DEBUG(adapterInfo("Added writer: Alpha."));
}
else if (dataName.find("Phi") == 0)
{
interface->addCouplingDataWriter(
dataName,
new Phi(mesh_, namePhi_));
DEBUG(adapterInfo("Added writer: Phi."));
}
else
{
found = false;
}
// NOTE: If you want to couple another variable, you need
// to add your new coupling data user as a coupling data
// writer here (and as a reader below).
// The argument of the dataName.compare() needs to match
// the one provided in the adapter's configuration file.
return found;
}
bool preciceAdapter::FF::FluidFluid::addReaders(std::string dataName, Interface* interface)
{
bool found = true; // Set to false later, if needed.
if (dataName.find("VelocityGradient") == 0)
{
interface->addCouplingDataReader(
dataName,
new VelocityGradient(mesh_, nameU_));
DEBUG(adapterInfo("Added reader: VelocityGradient."));
}
else if (dataName.find("Velocity") == 0)
{
interface->addCouplingDataReader(
dataName,
new Velocity(mesh_, nameU_, namePhi_));
DEBUG(adapterInfo("Added reader: Velocity."));
}
else if (dataName.find("PressureGradient") == 0)
{
interface->addCouplingDataReader(
dataName,
new PressureGradient(mesh_, nameP_));
DEBUG(adapterInfo("Added reader: Pressure Gradient."));
}
else if (dataName.find("Pressure") == 0)
{
interface->addCouplingDataReader(
dataName,
new Pressure(mesh_, nameP_));
DEBUG(adapterInfo("Added reader: Pressure."));
}
else if (dataName.find("FlowTemperatureGradient") == 0)
{
interface->addCouplingDataReader(
dataName,
new TemperatureGradient(mesh_, nameT_));
DEBUG(adapterInfo("Added reader: Flow Temperature Gradient."));
}
else if (dataName.find("FlowTemperature") == 0)
{
interface->addCouplingDataReader(
dataName,
new Temperature(mesh_, nameT_));
DEBUG(adapterInfo("Added reader: Flow Temperature."));
}
else if (dataName.find("AlphaGradient") == 0)
{
interface->addCouplingDataReader(
dataName,
new AlphaGradient(mesh_, nameAlpha_));
DEBUG(adapterInfo("Added reader: Alpha Gradient."));
}
else if (dataName.find("Alpha") == 0)
{
interface->addCouplingDataReader(
dataName,
new Alpha(mesh_, nameAlpha_));
DEBUG(adapterInfo("Added reader: Alpha."));
}
else if (dataName.find("Phi") == 0)
{
interface->addCouplingDataReader(
dataName,
new Phi(mesh_, namePhi_));
DEBUG(adapterInfo("Added reader: Phi."));
}
else
{
found = false;
}
// NOTE: If you want to couple another variable, you need
// to add your new coupling data user as a coupling data
// reader here (and as a writer above).
// The argument of the dataName.compare() needs to match
// the one provided in the adapter's configuration file.
return found;
}