Skip to content

Commit 14df4d5

Browse files
ChrisPsenicaChris Psenica
and
Chris Psenica
authored
wallDistanceMethod Flag Added To daOptions (#796)
* Adding wallDistanceMethod for daOption. Options are daCustom and default. This option is a flag for manually computing distance terms for CHT. I added a dedicated unit test for this (solid, incompressible, compressible) and removed it from previous unit tests. * There was a bug in the unit test where it was trying to switch to the directory it was already in. This has been fixed. * Fixing path for compressible unit test --------- Co-authored-by: Chris Psenica <[email protected]>
1 parent b47e789 commit 14df4d5

10 files changed

+417
-65
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ __pycache__
2828
reg_test_files*
2929
tests/*.txt
3030
tests/*.txt.orig
31+
.vscode/settings.json

dafoam/pyDAFoam.py

+3
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ def __init__(self):
601601
# }
602602
}
603603

604+
## Whether to use OpenFOAMs snGrad() function or to manually compute distance for wall interfaces
605+
self.wallDistanceMethod = "default"
606+
604607

605608
class PYDAFOAM(object):
606609
"""

src/adjoint/DAFunction/DAFunctionWallHeatFlux.C

+14-31
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ DAFunctionWallHeatFlux::DAFunctionWallHeatFlux(
4141
{
4242

4343
// check and assign values for scheme and formulation
44-
formMode_ = functionDict_.lookupOrDefault<word>("formulation", "default");
44+
distanceMode_ = daOption_.getAllOptions().getWord("wallDistanceMethod");
45+
if (distanceMode_ != "daCustom" && distanceMode_ != "default")
46+
{
47+
FatalErrorIn(" ") << "wallDistanceMethod: "
48+
<< distanceMode_ << " not supported!"
49+
<< " Options are: default and daCustom."
50+
<< abort(FatalError);
51+
}
4552
calcMode_ = functionDict_.lookupOrDefault<bool>("byUnitArea", true);
4653

4754
if (mesh_.thisDb().foundObject<DATurbulenceModel>("DATurbulenceModel"))
@@ -146,12 +153,12 @@ scalar DAFunctionWallHeatFlux::calcFunction()
146153
if (!wallHeatFluxBf[patchI].coupled())
147154
{
148155
// use OpenFOAM's snGrad()
149-
if (formMode_ == "default")
156+
if (distanceMode_ == "default")
150157
{
151158
wallHeatFluxBf[patchI] = Cp_ * alphaEffBf[patchI] * TBf[patchI].snGrad();
152159
}
153160
// use DAFOAM's custom formulation
154-
else if (formMode_ == "daCustom")
161+
else if (distanceMode_ == "daCustom")
155162
{
156163
forAll(wallHeatFluxBf[patchI], faceI)
157164
{
@@ -165,14 +172,6 @@ scalar DAFunctionWallHeatFlux::calcFunction()
165172
wallHeatFluxBf[patchI][faceI] = Cp_ * alphaEffBf[patchI][faceI] * dTdz;
166173
}
167174
}
168-
// error message incase of invalid entry
169-
else
170-
{
171-
FatalErrorIn(" ") << "formulation: "
172-
<< formMode_ << " not supported!"
173-
<< " Options are: default and daCustom."
174-
<< abort(FatalError);
175-
}
176175
}
177176
}
178177
}
@@ -191,12 +190,12 @@ scalar DAFunctionWallHeatFlux::calcFunction()
191190
if (!wallHeatFluxBf[patchI].coupled())
192191
{
193192
// use OpenFOAM's snGrad()
194-
if (formMode_ == "default")
193+
if (distanceMode_ == "default")
195194
{
196195
wallHeatFluxBf[patchI] = alphaEffBf[patchI] * heBf[patchI].snGrad();
197196
}
198197
// use DAFOAM's custom formulation
199-
else if (formMode_ == "daCustom")
198+
else if (distanceMode_ == "daCustom")
200199
{
201200
forAll(wallHeatFluxBf[patchI], faceI)
202201
{
@@ -210,14 +209,6 @@ scalar DAFunctionWallHeatFlux::calcFunction()
210209
wallHeatFluxBf[patchI][faceI] = alphaEffBf[patchI][faceI] * dHedz;
211210
}
212211
}
213-
// error message incase of invalid entry
214-
else
215-
{
216-
FatalErrorIn(" ") << "formulation: "
217-
<< formMode_ << " not supported!"
218-
<< " Options are: default and daCustom."
219-
<< abort(FatalError);
220-
}
221212
}
222213
}
223214
}
@@ -236,12 +227,12 @@ scalar DAFunctionWallHeatFlux::calcFunction()
236227
{
237228

238229
// use OpenFOAM's snGrad()
239-
if (formMode_ == "default")
230+
if (distanceMode_ == "default")
240231
{
241232
wallHeatFluxBf[patchI] = k_ * TBf[patchI].snGrad();
242233
}
243234
// use DAFOAM's custom formulation
244-
else if (formMode_ == "daCustom")
235+
else if (distanceMode_ == "daCustom")
245236
{
246237
forAll(wallHeatFluxBf[patchI], faceI)
247238
{
@@ -255,14 +246,6 @@ scalar DAFunctionWallHeatFlux::calcFunction()
255246
wallHeatFluxBf[patchI][faceI] = k_ * dTdz;
256247
}
257248
}
258-
// error message incase of invalid entry
259-
else
260-
{
261-
FatalErrorIn(" ") << "formulation: "
262-
<< formMode_ << " not supported!"
263-
<< " Options are: default and daCustom."
264-
<< abort(FatalError);
265-
}
266249
}
267250
}
268251
}

src/adjoint/DAFunction/DAFunctionWallHeatFlux.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected:
4444
bool calcMode_;
4545

4646
/// if calculating wallHeatFlux by OpenFOAMs snGrad() or DAFOAM's custom (daCustom) formulation
47-
word formMode_;
47+
word distanceMode_;
4848

4949
public:
5050
TypeName("wallHeatFlux");

src/adjoint/DAInput/DAInputThermalCoupling.C

+52-9
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,19 @@ DAInputThermalCoupling::DAInputThermalCoupling(
3636
// NOTE: always sort the patch because the order of the patch element matters in CHT coupling
3737
sort(patches_);
3838

39+
// check discipline
3940
discipline_ = daOption_.getAllOptions().getWord("discipline");
4041

42+
// check coupling mode and validate
43+
distanceMode_ = daOption_.getAllOptions().getWord("wallDistanceMethod");
44+
if (distanceMode_ != "daCustom" && distanceMode_ != "default")
45+
{
46+
FatalErrorIn(" ") << "wallDistanceMethod: "
47+
<< distanceMode_ << " not supported!"
48+
<< " Options are: default and daCustom."
49+
<< abort(FatalError);
50+
}
51+
4152
size_ = 0;
4253
forAll(patches_, idxI)
4354
{
@@ -83,6 +94,7 @@ void DAInputThermalCoupling::run(const scalarList& input)
8394

8495
// ********* second loop, set the valueFraction:
8596
// neighKDeltaCoeffs / ( neighKDeltaCoeffs + myKDeltaCoeffs)
97+
scalar deltaCoeffs = 0;
8698

8799
if (discipline_ == "aero")
88100
{
@@ -116,8 +128,19 @@ void DAInputThermalCoupling::run(const scalarList& input)
116128

117129
forAll(mesh_.boundaryMesh()[patchI], faceI)
118130
{
119-
// deltaCoeffs = 1 / d
120-
scalar deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
131+
if (distanceMode_ == "default")
132+
{
133+
// deltaCoeffs = 1 / d
134+
deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
135+
}
136+
else if (distanceMode_ == "daCustom")
137+
{
138+
label nearWallCellIndex = mesh_.boundaryMesh()[patchI].faceCells()[faceI];
139+
vector c1 = mesh_.Cf().boundaryField()[patchI][faceI];
140+
vector c2 = mesh_.C()[nearWallCellIndex];
141+
scalar d = mag(c1 - c2);
142+
deltaCoeffs = 1 / d;
143+
}
121144
scalar alphaEffBf = alphaEff.boundaryField()[patchI][faceI];
122145
scalar myKDeltaCoeffs = Cp * alphaEffBf * deltaCoeffs;
123146
// NOTE: we continue to use the counterI from the first loop
@@ -175,8 +198,19 @@ void DAInputThermalCoupling::run(const scalarList& input)
175198

176199
forAll(mesh_.boundaryMesh()[patchI], faceI)
177200
{
178-
// deltaCoeffs = 1 / d
179-
scalar deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
201+
if (distanceMode_ == "default")
202+
{
203+
// deltaCoeffs = 1 / d
204+
deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
205+
}
206+
else if (distanceMode_ == "daCustom")
207+
{
208+
label nearWallCellIndex = mesh_.boundaryMesh()[patchI].faceCells()[faceI];
209+
vector c1 = mesh_.Cf().boundaryField()[patchI][faceI];
210+
vector c2 = mesh_.C()[nearWallCellIndex];
211+
scalar d = mag(c1 - c2);
212+
deltaCoeffs = 1 / d;
213+
}
180214
scalar alphaEffBf = alphaEff.boundaryField()[patchI][faceI];
181215
scalar myKDeltaCoeffs = tmpVal * alphaEffBf * deltaCoeffs;
182216
// NOTE: we continue to use the counterI from the first loop
@@ -206,13 +240,22 @@ void DAInputThermalCoupling::run(const scalarList& input)
206240
word patchName = patches_[idxI];
207241
label patchI = mesh_.boundaryMesh().findPatchID(patchName);
208242

209-
mixedFvPatchField<scalar>& mixedPatch =
210-
refCast<mixedFvPatchField<scalar>>(T.boundaryFieldRef()[patchI]);
211-
212243
forAll(mesh_.boundaryMesh()[patchI], faceI)
213244
{
214-
// deltaCoeffs = 1 / d
215-
scalar deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
245+
if (distanceMode_ == "default")
246+
{
247+
// deltaCoeffs = 1 / d
248+
deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
249+
}
250+
else if (distanceMode_ == "daCustom")
251+
{
252+
label nearWallCellIndex = mesh_.boundaryMesh()[patchI].faceCells()[faceI];
253+
vector c1 = mesh_.Cf().boundaryField()[patchI][faceI];
254+
vector c2 = mesh_.C()[nearWallCellIndex];
255+
scalar d = mag(c1 - c2);
256+
deltaCoeffs = 1 / d;
257+
}
258+
mixedFvPatchField<scalar>& mixedPatch = refCast<mixedFvPatchField<scalar>>(T.boundaryFieldRef()[patchI]);
216259
scalar myKDeltaCoeffs = k * deltaCoeffs;
217260
// NOTE: we continue to use the counterI from the first loop
218261
scalar neighKDeltaCoeffs = input[counterI];

src/adjoint/DAInput/DAInputThermalCoupling.H

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ protected:
5555
/// whether this is flow or solid
5656
word discipline_;
5757

58+
/// if calculating wallHeatFlux by OpenFOAMs snGrad() or DAFOAM's custom (daCustom) formulation
59+
word distanceMode_;
60+
5861
public:
5962
TypeName("thermalCouplingInput");
6063
// Constructors

src/adjoint/DAOutput/DAOutputThermalCoupling.C

100644100755
+51-6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,19 @@ DAOutputThermalCoupling::DAOutputThermalCoupling(
3939
// NOTE: always sort the patch because the order of the patch element matters in CHT coupling
4040
sort(patches_);
4141

42+
// check discipline
4243
discipline_ = daOption_.getAllOptions().getWord("discipline");
4344

45+
// check coupling mode and validate
46+
distanceMode_ = daOption_.getAllOptions().getWord("wallDistanceMethod");
47+
if (distanceMode_ != "daCustom" && distanceMode_ != "default")
48+
{
49+
FatalErrorIn(" ") << "wallDistanceMethod: "
50+
<< distanceMode_ << " not supported!"
51+
<< " Options are: default and daCustom."
52+
<< abort(FatalError);
53+
}
54+
4455
size_ = 0;
4556
forAll(patches_, idxI)
4657
{
@@ -81,6 +92,7 @@ void DAOutputThermalCoupling::run(scalarList& output)
8192
}
8293

8394
// ********* second loop, get the (kappa / d) coefficient
95+
scalar deltaCoeffs = 0;
8496

8597
if (discipline_ == "aero")
8698
{
@@ -111,8 +123,19 @@ void DAOutputThermalCoupling::run(scalarList& output)
111123
label patchI = mesh_.boundaryMesh().findPatchID(patchName);
112124
forAll(mesh_.boundaryMesh()[patchI], faceI)
113125
{
114-
// deltaCoeffs = 1 / d
115-
scalar deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
126+
if (distanceMode_ == "default")
127+
{
128+
// deltaCoeffs = 1 / d
129+
deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
130+
}
131+
else if (distanceMode_ == "daCustom")
132+
{
133+
label nearWallCellIndex = mesh_.boundaryMesh()[patchI].faceCells()[faceI];
134+
vector c1 = mesh_.Cf().boundaryField()[patchI][faceI];
135+
vector c2 = mesh_.C()[nearWallCellIndex];
136+
scalar d = mag(c1 - c2);
137+
deltaCoeffs = 1 / d;
138+
}
116139
scalar alphaEffBf = alphaEff.boundaryField()[patchI][faceI];
117140
// NOTE: we continue to use the counterI from the first loop
118141
output[counterI] = Cp * alphaEffBf * deltaCoeffs;
@@ -165,8 +188,19 @@ void DAOutputThermalCoupling::run(scalarList& output)
165188
label patchI = mesh_.boundaryMesh().findPatchID(patchName);
166189
forAll(mesh_.boundaryMesh()[patchI], faceI)
167190
{
168-
// deltaCoeffs = 1 / d
169-
scalar deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
191+
if (distanceMode_ == "default")
192+
{
193+
// deltaCoeffs = 1 / d
194+
deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
195+
}
196+
else if (distanceMode_ == "daCustom")
197+
{
198+
label nearWallCellIndex = mesh_.boundaryMesh()[patchI].faceCells()[faceI];
199+
vector c1 = mesh_.Cf().boundaryField()[patchI][faceI];
200+
vector c2 = mesh_.C()[nearWallCellIndex];
201+
scalar d = mag(c1 - c2);
202+
deltaCoeffs = 1 / d;
203+
}
170204
scalar alphaEffBf = alphaEff.boundaryField()[patchI][faceI];
171205
// NOTE: we continue to use the counterI from the first loop
172206
output[counterI] = tmpVal * alphaEffBf * deltaCoeffs;
@@ -195,8 +229,19 @@ void DAOutputThermalCoupling::run(scalarList& output)
195229
label patchI = mesh_.boundaryMesh().findPatchID(patchName);
196230
forAll(mesh_.boundaryMesh()[patchI], faceI)
197231
{
198-
// deltaCoeffs = 1 / d
199-
scalar deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
232+
if (distanceMode_ == "default")
233+
{
234+
// deltaCoeffs = 1 / d
235+
deltaCoeffs = T.boundaryField()[patchI].patch().deltaCoeffs()[faceI];
236+
}
237+
else if (distanceMode_ == "daCustom")
238+
{
239+
label nearWallCellIndex = mesh_.boundaryMesh()[patchI].faceCells()[faceI];
240+
vector c1 = mesh_.Cf().boundaryField()[patchI][faceI];
241+
vector c2 = mesh_.C()[nearWallCellIndex];
242+
scalar d = mag(c1 - c2);
243+
deltaCoeffs = 1 / d;
244+
}
200245
// NOTE: we continue to use the counterI from the first loop
201246
output[counterI] = k * deltaCoeffs;
202247
counterI++;

src/adjoint/DAOutput/DAOutputThermalCoupling.H

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ protected:
5151
/// whether this is flow or solid
5252
word discipline_;
5353

54+
/// if calculating wallHeatFlux by OpenFOAMs snGrad() or DAFOAM's custom (daCustom) formulation
55+
word distanceMode_;
56+
5457
public:
5558
TypeName("thermalCouplingOutput");
5659
// Constructors

0 commit comments

Comments
 (0)