-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathCHT.C
299 lines (266 loc) · 10.9 KB
/
CHT.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include "CHT.H"
#include "Utilities.H"
using namespace Foam;
preciceAdapter::CHT::ConjugateHeatTransfer::ConjugateHeatTransfer(
const Foam::fvMesh& mesh)
: mesh_(mesh)
{
}
bool preciceAdapter::CHT::ConjugateHeatTransfer::configure(const IOdictionary& adapterConfig)
{
DEBUG(adapterInfo("Configuring the CHT module..."));
// Read the CHT-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 || solverType_.compare("basic") == 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 CHT module... (override by setting solverType to one of {compressible, incompressible, basic})"));
solverType_ = determineSolverType();
}
return true;
}
bool preciceAdapter::CHT::ConjugateHeatTransfer::readConfig(const IOdictionary& adapterConfig)
{
const dictionary& CHTdict = adapterConfig.subOrEmptyDict("CHT");
// Read the solver type (if not specified, it is determined automatically)
solverType_ = CHTdict.lookupOrDefault<word>("solverType", "");
DEBUG(adapterInfo(" user-defined solver type : " + solverType_));
// Read the name of the temperature field (if different)
nameT_ = CHTdict.lookupOrDefault<word>("nameT", "T");
DEBUG(adapterInfo(" temperature field name : " + nameT_));
// Read the name of the conductivity parameter for basic solvers (if different)
nameKappa_ = CHTdict.lookupOrDefault<word>("nameKappa", "k");
DEBUG(adapterInfo(" conductivity name for basic solvers : " + nameKappa_));
// Read the name of the density parameter for incompressible solvers (if different)
nameRho_ = CHTdict.lookupOrDefault<word>("nameRho", "rho");
DEBUG(adapterInfo(" density name for incompressible solvers : " + nameRho_));
// Read the name of the heat capacity parameter for incompressible solvers (if different)
nameCp_ = CHTdict.lookupOrDefault<word>("nameCp", "Cp");
DEBUG(adapterInfo(" heat capacity name for incompressible solvers : " + nameCp_));
// Read the name of the Prandtl number parameter for incompressible solvers (if different)
namePr_ = CHTdict.lookupOrDefault<word>("namePr", "Pr");
DEBUG(adapterInfo(" Prandtl number name for incompressible solvers : " + namePr_));
// Read the name of the turbulent thermal diffusivity field for incompressible solvers (if different)
nameAlphat_ = CHTdict.lookupOrDefault<word>("nameAlphat", "alphat");
DEBUG(adapterInfo(" Turbulent thermal diffusivity field name for incompressible solvers : " + nameAlphat_));
return true;
}
std::string preciceAdapter::CHT::ConjugateHeatTransfer::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";
}
}
if (solverType == "unknown")
{
adapterInfo("Failed to determine the solver type. "
"Please specify your solver type in the CHT section of the "
"preciceDict. Known solver types for CHT are: "
"basic, incompressible and "
"compressible",
"error");
}
DEBUG(adapterInfo("Automatically determined solver type : " + solverType));
return solverType;
}
bool preciceAdapter::CHT::ConjugateHeatTransfer::addWriters(std::string dataName, Interface* interface)
{
bool found = true; // Set to false later, if needed.
if (dataName.find("Sink-Temperature") == 0)
{
interface->addCouplingDataWriter(
dataName,
new SinkTemperature(mesh_, nameT_));
DEBUG(adapterInfo("Added writer: Sink Temperature."));
}
else if (dataName.find("Temperature") == 0)
{
interface->addCouplingDataWriter(
dataName,
new Temperature(mesh_, nameT_));
DEBUG(adapterInfo("Added writer: Temperature."));
}
else if (dataName.find("Heat-Flux") == 0)
{
if (solverType_.compare("compressible") == 0)
{
interface->addCouplingDataWriter(
dataName,
new HeatFlux_Compressible(mesh_, nameT_));
DEBUG(adapterInfo("Added writer: Heat Flux for compressible solvers."));
}
else if (solverType_.compare("incompressible") == 0)
{
interface->addCouplingDataWriter(
dataName,
new HeatFlux_Incompressible(mesh_, nameT_, nameRho_, nameCp_, namePr_, nameAlphat_));
DEBUG(adapterInfo("Added writer: Heat Flux for incompressible solvers. "));
}
else if (solverType_.compare("basic") == 0)
{
interface->addCouplingDataWriter(
dataName,
new HeatFlux_Basic(mesh_, nameT_, nameKappa_));
DEBUG(adapterInfo("Added writer: Heat Flux for basic solvers. "));
}
else
{
adapterInfo("Unknown solver type - cannot add heat flux.",
"error");
}
}
else if (dataName.find("Heat-Transfer-Coefficient") == 0)
{
if (solverType_.compare("compressible") == 0)
{
interface->addCouplingDataWriter(
dataName,
new HeatTransferCoefficient_Compressible(mesh_, nameT_));
DEBUG(adapterInfo("Added writer: Heat Transfer Coefficient for compressible solvers."));
}
else if (solverType_.compare("incompressible") == 0)
{
interface->addCouplingDataWriter(
dataName,
new HeatTransferCoefficient_Incompressible(mesh_, nameT_, nameRho_, nameCp_, namePr_, nameAlphat_));
DEBUG(adapterInfo("Added writer: Heat Transfer Coefficient for incompressible solvers. "));
}
else if (solverType_.compare("basic") == 0)
{
interface->addCouplingDataWriter(
dataName,
new HeatTransferCoefficient_Basic(mesh_, nameT_, nameKappa_));
DEBUG(adapterInfo("Added writer: Heat Transfer Coefficient for basic solvers. "));
}
else
{
adapterInfo("Unknown solver type - cannot add heat transfer coefficient.",
"error");
}
}
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::CHT::ConjugateHeatTransfer::addReaders(std::string dataName, Interface* interface)
{
bool found = true; // Set to false later, if needed.
if (dataName.find("Sink-Temperature") == 0)
{
interface->addCouplingDataReader(
dataName,
new SinkTemperature(mesh_, nameT_));
DEBUG(adapterInfo("Added reader: Sink Temperature."));
}
else if (dataName.find("Temperature") == 0)
{
interface->addCouplingDataReader(
dataName,
new Temperature(mesh_, nameT_));
DEBUG(adapterInfo("Added reader: Temperature."));
}
else if (dataName.find("Heat-Flux") == 0)
{
if (solverType_.compare("compressible") == 0)
{
interface->addCouplingDataReader(
dataName,
new HeatFlux_Compressible(mesh_, nameT_));
DEBUG(adapterInfo("Added reader: Heat Flux for compressible solvers."));
}
else if (solverType_.compare("incompressible") == 0)
{
interface->addCouplingDataReader(
dataName,
new HeatFlux_Incompressible(mesh_, nameT_, nameRho_, nameCp_, namePr_, nameAlphat_));
DEBUG(adapterInfo("Added reader: Heat Flux for incompressible solvers. "));
}
else if (solverType_.compare("basic") == 0)
{
interface->addCouplingDataReader(
dataName,
new HeatFlux_Basic(mesh_, nameT_, nameKappa_));
DEBUG(adapterInfo("Added reader: Heat Flux for basic solvers. "));
}
else
{
adapterInfo("Unknown solver type - cannot add heat flux.",
"error");
}
}
else if (dataName.find("Heat-Transfer-Coefficient") == 0)
{
if (solverType_.compare("compressible") == 0)
{
interface->addCouplingDataReader(
dataName,
new HeatTransferCoefficient_Compressible(mesh_, nameT_));
DEBUG(adapterInfo("Added reader: Heat Transfer Coefficient for compressible solvers."));
}
else if (solverType_.compare("incompressible") == 0)
{
interface->addCouplingDataReader(
dataName,
new HeatTransferCoefficient_Incompressible(mesh_, nameT_, nameRho_, nameCp_, namePr_, nameAlphat_));
DEBUG(adapterInfo("Added reader: Heat Transfer Coefficient for incompressible solvers. "));
}
else if (solverType_.compare("basic") == 0)
{
interface->addCouplingDataReader(
dataName,
new HeatTransferCoefficient_Basic(mesh_, nameT_, nameKappa_));
DEBUG(adapterInfo("Added reader: Heat Transfer Coefficient for basic solvers. "));
}
else
{
adapterInfo("Unknown solver type - cannot add heat transfer coefficient.",
"error");
}
}
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;
}