Skip to content

Commit 3840b47

Browse files
fsimonisMakisHFujikawas
authored
Add channel-transport transport OpenFOAM (#551)
Co-authored-by: Gerasimos Chourdakis <gerasimos.chourdakis@ipvs.uni-stuttgart.de> Co-authored-by: June <94080048+Fujikawas@users.noreply.github.com>
1 parent 74177ef commit 3840b47

24 files changed

Lines changed: 782 additions & 10 deletions

File tree

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ postProcessing/
6868
*.foam
6969
*.OpenFOAM
7070
dynamicCode
71-
Make/*
72-
!Make/files
73-
!Make/options
74-
lnInclude/
71+
**/Make/*
72+
!**/Make/files
73+
!**/Make/options
7574

7675
# CalculiX
7776
spooles.out

changelog-entries/551.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added OpenFOAM variant of the transport participant to the channel-transport tutorial.

channel-transport/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Transport participant:
4545

4646
* Nutils with support for [adaptive mesh refinement](https://precice.org/couple-your-code-moving-or-changing-meshes.html#pseudo-reference-domain). For more information, have a look at the [Nutils adapter documentation](https://precice.org/adapter-nutils.html). This solver requires a preCICE release with [remeshing support](couple-your-code-moving-or-changing-meshes.html#remeshing-using-precice).
4747

48+
* OpenFOAM. This case uses a modified version of scalarTransportFoam, which recomputes `phi` after the preCICE adapter reads the velocity field. Find it in the `solver-openfoam` folder. Read more details in the [OpenFOAM adapter](https://precice.org/adapter-openfoam-overview.html).
49+
4850
## Running the simulation
4951

5052
For the fluid solver, use Nutils for ease of installation and OpenFOAM for speed.

channel-transport/metadata.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ participants:
77
- Transport
88

99
cases:
10+
fluid-nutils:
11+
participant: Fluid
12+
directory: ./fluid-nutils
13+
run: ./run.sh
14+
component: nutils-adapter
15+
1016
fluid-openfoam:
1117
participant: Fluid
1218
directory: ./fluid-openfoam
1319
run: ./run.sh
1420
component: openfoam-adapter
1521

16-
fluid-nutils:
17-
participant: Fluid
18-
directory: ./fluid-nutils
22+
transport-nutils:
23+
participant: Transport
24+
directory: ./transport-nutils
1925
run: ./run.sh
2026
component: nutils-adapter
2127

22-
transport-nutils:
28+
transport-openfoam:
2329
participant: Transport
24-
directory: ./transport-nutils
30+
directory: ./transport-openfoam
2531
run: ./run.sh
26-
component: nutils-adapter
32+
component: openfoam-adapter
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
#
5+
# Proposed clang-format-11 style for OpenFOAM, trying to follow the OpenFOAM style guide:
6+
# https://develop.openfoam.com/Development/openfoam/-/wikis/coding/style/style
7+
# Configuration developed for the OpenFOAM-preCICE adapter code:
8+
# https://github.com/precice/openfoam-adapter
9+
# Contribute to the discussion at the respective OpenFOAM issue:
10+
# https://develop.openfoam.com/Development/openfoam/-/issues/1634
11+
#
12+
# Keep `public:` at the first indentation level
13+
AccessModifierOffset: -4
14+
# Undocumented guideline: align arguments after an open bracket.
15+
AlignAfterOpenBracket: Align
16+
AlignConsecutiveMacros: false
17+
AlignConsecutiveAssignments: false
18+
AlignConsecutiveBitFields: false
19+
AlignConsecutiveDeclarations: false
20+
AlignEscapedNewlines: Right
21+
# Align operands after operators (+,*,<<) (see BreakBeforeBinaryOperators)
22+
AlignOperands: AlignAfterOperator
23+
AlignTrailingComments: true
24+
AllowAllArgumentsOnNextLine: true
25+
AllowAllConstructorInitializersOnNextLine: true
26+
AllowAllParametersOfDeclarationOnNextLine: true
27+
AllowShortEnumsOnASingleLine: true
28+
AllowShortBlocksOnASingleLine: Never
29+
AllowShortCaseLabelsOnASingleLine: false
30+
AllowShortFunctionsOnASingleLine: All
31+
AllowShortLambdasOnASingleLine: All
32+
AllowShortIfStatementsOnASingleLine: Always
33+
AllowShortLoopsOnASingleLine: false
34+
# Guideline: Splitting return type and function name
35+
# (this guideline is apparently not strictly followed in OpenFOAM)
36+
# AlwaysBreakAfterReturnType: All
37+
AlwaysBreakBeforeMultilineStrings: false
38+
AlwaysBreakTemplateDeclarations: Yes
39+
BinPackArguments: false
40+
BinPackParameters: false
41+
# Covered by "BreakBeforeBraces"
42+
BraceWrapping:
43+
AfterCaseLabel: true
44+
AfterClass: true
45+
AfterControlStatement: Always
46+
AfterEnum: true
47+
AfterFunction: true
48+
AfterNamespace: true
49+
AfterObjCDeclaration: true
50+
AfterStruct: true
51+
AfterUnion: true
52+
AfterExternBlock: true
53+
BeforeCatch: true
54+
BeforeElse: true
55+
BeforeLambdaBody: true
56+
BeforeWhile: true
57+
IndentBraces: true
58+
SplitEmptyFunction: true
59+
SplitEmptyRecord: true
60+
SplitEmptyNamespace: true
61+
# Guideline (almost): Splitting long lines at an = sign. Indent after split.
62+
# Guideline (almost): Splitting formulae over several lines.
63+
BreakBeforeBinaryOperators: NonAssignment
64+
# Always break before braces: if, for, functions, classes, etc.
65+
BreakBeforeBraces: Allman
66+
BreakBeforeInheritanceComma: false
67+
BreakInheritanceList: BeforeColon
68+
# Guideline (almost): Splitting logical tests over several lines.
69+
BreakBeforeTernaryOperators: true
70+
BreakConstructorInitializersBeforeComma: false
71+
# Undocumented guideline (almost): Have the initializer : in a new line.
72+
BreakConstructorInitializers: BeforeColon
73+
BreakStringLiterals: true
74+
# Here we could set the 80 charactes limit, but that would lead to more aggressive changes.
75+
ColumnLimit: 0
76+
CommentPragmas: '^ IWYU pragma:'
77+
CompactNamespaces: false
78+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
79+
ConstructorInitializerIndentWidth: 0
80+
ContinuationIndentWidth: 4
81+
Cpp11BracedListStyle: true
82+
DeriveLineEnding: true
83+
DerivePointerAlignment: false
84+
DisableFormat: false
85+
# Undocumented guideline: add line after "public:" etc (since clang-format 12)
86+
# EmptyLineAfterAccessModifier: Always
87+
ExperimentalAutoDetectBinPacking: false
88+
FixNamespaceComments: false
89+
# Guideline: Macro loops are like for loops, but without a space.
90+
ForEachMacros:
91+
- forAllIters
92+
- forAllConstIters
93+
- forAllReverseIters
94+
- forAllConstReverseIters
95+
- forAll
96+
- forAllReverse
97+
- forAllIter
98+
- forAllConstIter
99+
IncludeBlocks: Preserve
100+
IncludeCategories:
101+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
102+
Priority: 2
103+
SortPriority: 0
104+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
105+
Priority: 3
106+
SortPriority: 0
107+
- Regex: '.*'
108+
Priority: 1
109+
SortPriority: 0
110+
IncludeIsMainRegex: '(Test)?$'
111+
IncludeIsMainSourceRegex: ''
112+
IndentCaseLabels: false
113+
IndentCaseBlocks: false
114+
IndentGotoLabels: true
115+
IndentPPDirectives: None
116+
IndentExternBlock: AfterExternBlock
117+
# Guideline: The normal indentation is 4 spaces per logical level.
118+
IndentWidth: 4
119+
IndentWrappedFunctionNames: false
120+
InsertTrailingCommas: None
121+
KeepEmptyLinesAtTheStartOfBlocks: true
122+
MacroBlockBegin: ''
123+
MacroBlockEnd: ''
124+
# Required to not change code following the guidelines
125+
# "Leave two empty lines between sections" and
126+
# "Use two empty lines between functions"
127+
MaxEmptyLinesToKeep: 2
128+
NamespaceIndentation: None
129+
PenaltyBreakAssignment: 2
130+
PenaltyBreakBeforeFirstCallParameter: 19
131+
PenaltyBreakComment: 300
132+
PenaltyBreakFirstLessLess: 120
133+
PenaltyBreakString: 1000
134+
PenaltyBreakTemplateDeclaration: 10
135+
PenaltyExcessCharacter: 1000000
136+
PenaltyReturnTypeOnItsOwnLine: 60
137+
PointerAlignment: Left
138+
ReflowComments: true
139+
# Do not change the order of include statements (could be catastrophic for OpenFOAM)
140+
SortIncludes: false
141+
SortUsingDeclarations: false
142+
SpaceAfterCStyleCast: false
143+
SpaceAfterLogicalNot: false
144+
# No "template <T>" (guideline already used, but not documented)
145+
SpaceAfterTemplateKeyword: false
146+
SpaceBeforeAssignmentOperators: true
147+
# No a{1} (no guideline)
148+
SpaceBeforeCpp11BracedList: true
149+
SpaceBeforeCtorInitializerColon: true
150+
SpaceBeforeInheritanceColon: true
151+
# Guideline: Spaces in "if ()", "for ()", but not "forAll ()".
152+
SpaceBeforeParens: ControlStatementsExceptForEachMacros
153+
# Guideline: Range-based for should have a space surrounding the ':'.
154+
SpaceBeforeRangeBasedForLoopColon: true
155+
SpaceInEmptyBlock: false
156+
SpaceInEmptyParentheses: false
157+
SpacesBeforeTrailingComments: 1
158+
SpacesInAngles: false
159+
SpacesInConditionalStatement: false
160+
# No "arr[3] = [ 1, 2, 3 ]" (no guideline).
161+
SpacesInContainerLiterals: false
162+
SpacesInCStyleCastParentheses: false
163+
SpacesInParentheses: false
164+
SpacesInSquareBrackets: false
165+
SpaceBeforeSquareBrackets: false
166+
# Treat the code as C++11 or later
167+
Standard: Latest
168+
StatementMacros:
169+
TabWidth: 4
170+
UseCRLF: false
171+
# Guideline: No tab characters - only use spaces for indentation.
172+
UseTab: Never
173+
WhitespaceSensitiveMacros:
174+
...
175+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dynamicScalarTransportFoam.C
2+
3+
EXE = $(FOAM_USER_APPBIN)/dynamicScalarTransportFoam
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
EXE_INC = \
2+
-I$(LIB_SRC)/finiteVolume/lnInclude \
3+
-I$(LIB_SRC)/meshTools/lnInclude \
4+
-I$(LIB_SRC)/sampling/lnInclude
5+
6+
EXE_LIBS = \
7+
-lfiniteVolume \
8+
-lfvOptions \
9+
-lmeshTools \
10+
-lsampling
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
set -e -u
3+
4+
wclean
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Info << "Reading field T\n"
2+
<< endl;
3+
4+
volScalarField T(
5+
IOobject(
6+
"T",
7+
runTime.timeName(),
8+
mesh,
9+
IOobject::MUST_READ,
10+
IOobject::AUTO_WRITE),
11+
mesh);
12+
13+
Info << "Reading field U\n"
14+
<< endl;
15+
16+
volVectorField U(
17+
IOobject(
18+
"U",
19+
runTime.timeName(),
20+
mesh,
21+
IOobject::MUST_READ,
22+
IOobject::AUTO_WRITE),
23+
mesh);
24+
25+
Info << "Reading transportProperties\n"
26+
<< endl;
27+
28+
IOdictionary transportProperties(
29+
IOobject(
30+
"transportProperties",
31+
runTime.constant(),
32+
mesh,
33+
IOobject::MUST_READ_IF_MODIFIED,
34+
IOobject::NO_WRITE));
35+
36+
Info << "Reading diffusivity DT\n"
37+
<< endl;
38+
39+
dimensionedScalar DT("DT", dimViscosity, transportProperties);
40+
41+
#include "createPhi.H"
42+
43+
#include "createFvOptions.H"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// This file is based on the OpenFOAM example application scalarTransportFoam
3+
//
4+
// GitLab link: https://gitlab.com/openfoam/core/openfoam/-/tree/master/applications/solvers/basic/scalarTransportFoam
5+
//
6+
// This modified version doesn't expect a static velocity field U, instead, it repomputes it every time step.
7+
// Therefore it allows the preCICE adapter to provide the velocities.
8+
9+
#include "fvCFD.H"
10+
#include "fvOptions.H"
11+
#include "simpleControl.H"
12+
13+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
14+
15+
int main(int argc, char* argv[])
16+
{
17+
argList::addNote(
18+
"Dynamic scalar transport equation solver.");
19+
20+
#include "addCheckCaseOptions.H"
21+
#include "setRootCaseLists.H"
22+
#include "createTime.H"
23+
#include "createMesh.H"
24+
25+
simpleControl simple(mesh);
26+
27+
#include "createFields.H"
28+
29+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30+
31+
Info << "\nCalculating scalar transport\n"
32+
<< endl;
33+
34+
while (simple.loop())
35+
{
36+
Info << "Time = " << runTime.timeName() << nl << endl;
37+
38+
Info << "Recompute phi" << endl;
39+
fvOptions.correct(U);
40+
phi = fvc::flux(U);
41+
#include "CourantNo.H"
42+
43+
while (simple.correctNonOrthogonal())
44+
{
45+
fvScalarMatrix TEqn(
46+
fvm::ddt(T) + fvm::div(phi, T) - fvm::laplacian(DT, T) == fvOptions(T));
47+
48+
TEqn.relax();
49+
fvOptions.constrain(TEqn);
50+
TEqn.solve();
51+
fvOptions.correct(T);
52+
}
53+
54+
runTime.write();
55+
}
56+
57+
Info << "End\n"
58+
<< endl;
59+
60+
return 0;
61+
}
62+
63+
// ************************************************************************* //

0 commit comments

Comments
 (0)