Skip to content

Commit 2779442

Browse files
author
Henry Weller
committed
functionObjects::fluidMaxDeltaT: New functionObject to set the maximum Courant number and time-step
at Function1s of time. Underlying this new functionObject is a generalisation of the handling of the maximum time-step in the modular solvers to allow complex user-specification of the maximum time-step used in a simulation, not just the time-dependency provided by fluidMaxDeltaT but functions of anything in the simulation by creating a specialised functionObject in which the maxDeltaT function is defined. The chemical and combustion time-scale functionObjects adjustTimeStepToChemistry and adjustTimeStepToCombustion have been updated and simplified using the above mechanism.
1 parent 634b8d1 commit 2779442

File tree

20 files changed

+428
-107
lines changed

20 files changed

+428
-107
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
fluidSolver.C
2+
functionObjects/fluidMaxDeltaT/fluidMaxDeltaT.C
23

34
LIB = $(FOAM_LIBBIN)/libfluidSolver

applications/modules/fluidSolver/fluidSolver.C

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,20 @@ namespace solvers
4444

4545
void Foam::solvers::fluidSolver::readControls()
4646
{
47-
maxCo =
48-
runTime.controlDict().lookupOrDefault<scalar>("maxCo", 1.0);
49-
50-
maxDeltaT_ =
51-
runTime.controlDict().lookupOrDefault<scalar>("maxDeltaT", vGreat);
52-
53-
correctPhi = pimple.dict().lookupOrDefault
54-
(
55-
"correctPhi",
56-
mesh.dynamic()
57-
);
47+
if (mesh.solution().modified())
48+
{
49+
correctPhi = pimple.dict().lookupOrDefault
50+
(
51+
"correctPhi",
52+
mesh.dynamic()
53+
);
5854

59-
checkMeshCourantNo = pimple.dict().lookupOrDefault
60-
(
61-
"checkMeshCourantNo",
62-
false
63-
);
55+
checkMeshCourantNo = pimple.dict().lookupOrDefault
56+
(
57+
"checkMeshCourantNo",
58+
false
59+
);
60+
}
6461
}
6562

6663

@@ -101,7 +98,7 @@ void Foam::solvers::fluidSolver::correctCoNum
10198
fvc::surfaceSum(mag(phi))().primitiveField()/rho.primitiveField()
10299
);
103100

104-
CoNum = 0.5*gMax(sumPhi/mesh.V().field())*runTime.deltaTValue();
101+
CoNum_ = 0.5*gMax(sumPhi/mesh.V().field())*runTime.deltaTValue();
105102

106103
const scalar meanCoNum =
107104
0.5*(gSum(sumPhi)/gSum(mesh.V().field()))*runTime.deltaTValue();
@@ -192,8 +189,17 @@ void Foam::solvers::fluidSolver::continuityErrors
192189
Foam::solvers::fluidSolver::fluidSolver(fvMesh& mesh)
193190
:
194191
solver(mesh),
192+
maxCo
193+
(
194+
mesh.time().controlDict().lookupOrDefault<scalar>("maxCo", vGreat)
195+
),
196+
maxDeltaT_
197+
(
198+
mesh.time().controlDict().lookupOrDefault<scalar>("maxDeltaT", vGreat)
199+
),
195200
cumulativeContErr(0),
196-
CoNum(0)
201+
CoNum_(0),
202+
CoNum(CoNum_)
197203
{
198204
// Read the controls
199205
readControls();
@@ -212,7 +218,7 @@ Foam::scalar Foam::solvers::fluidSolver::maxDeltaT() const
212218
{
213219
scalar deltaT = min(fvModels().maxDeltaT(), maxDeltaT_);
214220

215-
if (CoNum > small)
221+
if (maxCo < vGreat && CoNum > small)
216222
{
217223
deltaT = min(deltaT, maxCo/CoNum*runTime.deltaTValue());
218224
}

applications/modules/fluidSolver/fluidSolver.H

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected:
9696
bool correctPhi;
9797

9898
//- Current maximum Courant number for time-step control
99-
scalar CoNum;
99+
scalar CoNum_;
100100

101101
//- Read controls
102102
void readControls();
@@ -129,6 +129,14 @@ protected:
129129
);
130130

131131

132+
public:
133+
134+
// Public Data
135+
136+
//- Current maximum Courant number for time-step control
137+
const scalar& CoNum;
138+
139+
132140
public:
133141

134142
//- Runtime type information
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*---------------------------------------------------------------------------*\
2+
========= |
3+
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4+
\\ / O peration | Website: https://openfoam.org
5+
\\ / A nd | Copyright (C) 2023 OpenFOAM Foundation
6+
\\/ M anipulation |
7+
-------------------------------------------------------------------------------
8+
License
9+
This file is part of OpenFOAM.
10+
11+
OpenFOAM is free software: you can redistribute it and/or modify it
12+
under the terms of the GNU General Public License as published by
13+
the Free Software Foundation, either version 3 of the License, or
14+
(at your option) any later version.
15+
16+
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19+
for more details.
20+
21+
You should have received a copy of the GNU General Public License
22+
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23+
24+
\*---------------------------------------------------------------------------*/
25+
26+
#include "fluidMaxDeltaT.H"
27+
#include "fluidSolver.H"
28+
#include "addToRunTimeSelectionTable.H"
29+
30+
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31+
32+
namespace Foam
33+
{
34+
namespace functionObjects
35+
{
36+
defineTypeNameAndDebug(fluidMaxDeltaT, 0);
37+
38+
addToRunTimeSelectionTable
39+
(
40+
functionObject,
41+
fluidMaxDeltaT,
42+
dictionary
43+
);
44+
}
45+
}
46+
47+
48+
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49+
50+
Foam::functionObjects::fluidMaxDeltaT::fluidMaxDeltaT
51+
(
52+
const word& name,
53+
const Time& runTime,
54+
const dictionary& dict
55+
)
56+
:
57+
fvMeshFunctionObject(name, runTime, dict)
58+
{
59+
read(dict);
60+
}
61+
62+
63+
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64+
65+
Foam::functionObjects::fluidMaxDeltaT::~fluidMaxDeltaT()
66+
{}
67+
68+
69+
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70+
71+
bool Foam::functionObjects::fluidMaxDeltaT::read(const dictionary& dict)
72+
{
73+
fvMeshFunctionObject::read(dict);
74+
75+
maxCoPtr_ = Function1<scalar>::New("maxCo", dict);
76+
maxDeltaTPtr_ = Function1<scalar>::New("maxDeltaT", dict);
77+
78+
return true;
79+
}
80+
81+
82+
bool Foam::functionObjects::fluidMaxDeltaT::execute()
83+
{
84+
return true;
85+
}
86+
87+
88+
bool Foam::functionObjects::fluidMaxDeltaT::write()
89+
{
90+
return true;
91+
}
92+
93+
94+
Foam::scalar Foam::functionObjects::fluidMaxDeltaT::maxDeltaT() const
95+
{
96+
scalar deltaT =
97+
time_.userTimeToTime(maxDeltaTPtr_().value(time_.userTimeValue()));
98+
99+
const scalar CoNum =
100+
mesh_.lookupObject<solvers::fluidSolver>(solver::typeName).CoNum;
101+
102+
if (CoNum > small)
103+
{
104+
const scalar maxCo = maxCoPtr_().value(time_.userTimeValue());
105+
106+
deltaT = min(deltaT, maxCo/CoNum*time_.deltaTValue());
107+
}
108+
109+
return deltaT;
110+
}
111+
112+
113+
// ************************************************************************* //
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*---------------------------------------------------------------------------*\
2+
========= |
3+
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4+
\\ / O peration | Website: https://openfoam.org
5+
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
6+
\\/ M anipulation |
7+
-------------------------------------------------------------------------------
8+
License
9+
This file is part of OpenFOAM.
10+
11+
OpenFOAM is free software: you can redistribute it and/or modify it
12+
under the terms of the GNU General Public License as published by
13+
the Free Software Foundation, either version 3 of the License, or
14+
(at your option) any later version.
15+
16+
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19+
for more details.
20+
21+
You should have received a copy of the GNU General Public License
22+
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23+
24+
Class
25+
Foam::functionObjects::fluidMaxDeltaT
26+
27+
Description
28+
Returns the maximum time-step evaluated from time-dependent
29+
maximum Courant number and maximum time-step specifications.
30+
31+
The \c maxCo and \c maxDeltaT are provided as \c Function1 of time,
32+
supporting constant, tabulated and functional specifications.
33+
34+
Usage
35+
Example of a time-dependent maximum Courant number:
36+
\verbatim
37+
fluidMaxDeltaT
38+
{
39+
type fluidMaxDeltaT;
40+
41+
maxCo table
42+
(
43+
(0 0.2)
44+
(0.6 0.2)
45+
(0.7 0.1)
46+
);
47+
48+
maxDeltaT 1;
49+
}
50+
\endverbatim
51+
52+
See also
53+
Foam::functionObject
54+
Foam::functionObjects::fvMeshFunctionObject
55+
Foam::Function1
56+
57+
SourceFiles
58+
fluidMaxDeltaT.C
59+
60+
\*---------------------------------------------------------------------------*/
61+
62+
#ifndef fluidMaxDeltaT_H
63+
#define fluidMaxDeltaT_H
64+
65+
#include "fvMeshFunctionObject.H"
66+
#include "Function1.H"
67+
68+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69+
70+
namespace Foam
71+
{
72+
namespace functionObjects
73+
{
74+
75+
/*---------------------------------------------------------------------------*\
76+
Class fluidMaxDeltaT Declaration
77+
\*---------------------------------------------------------------------------*/
78+
79+
class fluidMaxDeltaT
80+
:
81+
public fvMeshFunctionObject
82+
{
83+
// Private Data
84+
85+
//- Max Courant number function/table
86+
autoPtr<Function1<scalar>> maxCoPtr_;
87+
88+
//- Max time-step function/table
89+
autoPtr<Function1<scalar>> maxDeltaTPtr_;
90+
91+
92+
public:
93+
94+
//- Runtime type information
95+
TypeName("fluidMaxDeltaT");
96+
97+
98+
// Constructors
99+
100+
//- Construct from Time and dictionary
101+
fluidMaxDeltaT
102+
(
103+
const word& name,
104+
const Time& runTime,
105+
const dictionary& dict
106+
);
107+
108+
//- Disallow default bitwise copy construction
109+
fluidMaxDeltaT(const fluidMaxDeltaT&) = delete;
110+
111+
112+
//- Destructor
113+
virtual ~fluidMaxDeltaT();
114+
115+
116+
// Member Functions
117+
118+
//- Read the controls
119+
virtual bool read(const dictionary&);
120+
121+
//- Return the list of fields required
122+
virtual wordList fields() const
123+
{
124+
return wordList::null();
125+
}
126+
127+
//- Execute, currently does nothing
128+
virtual bool execute();
129+
130+
//- Write the time step value
131+
virtual bool write();
132+
133+
//- Return the maximum time-step for stable operation
134+
virtual scalar maxDeltaT() const;
135+
136+
137+
// Member Operators
138+
139+
//- Disallow default bitwise assignment
140+
void operator=(const fluidMaxDeltaT&) = delete;
141+
};
142+
143+
144+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145+
146+
} // End namespace functionObjects
147+
} // End namespace Foam
148+
149+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150+
151+
#endif
152+
153+
// ************************************************************************* //

applications/modules/multiphaseEuler/multiphaseEuler/multiphaseEuler.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void Foam::solvers::multiphaseEuler::correctCoNum()
7979
);
8080
}
8181

82-
CoNum = 0.5*gMax(sumPhi/mesh.V().field())*runTime.deltaTValue();
82+
CoNum_ = 0.5*gMax(sumPhi/mesh.V().field())*runTime.deltaTValue();
8383

8484
const scalar meanCoNum =
8585
0.5*(gSum(sumPhi)/gSum(mesh.V().field()))*runTime.deltaTValue();

applications/modules/shockFluid/shockFluid.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void Foam::solvers::shockFluid::correctCoNum(const surfaceScalarField& amaxSf)
5050
{
5151
const scalarField sumAmaxSf(fvc::surfaceSum(amaxSf)().primitiveField());
5252

53-
CoNum = 0.5*gMax(sumAmaxSf/mesh.V().field())*runTime.deltaTValue();
53+
CoNum_ = 0.5*gMax(sumAmaxSf/mesh.V().field())*runTime.deltaTValue();
5454

5555
const scalar meanCoNum =
5656
0.5*(gSum(sumAmaxSf)/gSum(mesh.V().field()))*runTime.deltaTValue();

0 commit comments

Comments
 (0)