diff --git a/applications/modules/fluidSolver/Make/files b/applications/modules/fluidSolver/Make/files index 52fb8ec070..510310752a 100644 --- a/applications/modules/fluidSolver/Make/files +++ b/applications/modules/fluidSolver/Make/files @@ -1,3 +1,4 @@ fluidSolver.C +functionObjects/fluidMaxDeltaT/fluidMaxDeltaT.C LIB = $(FOAM_LIBBIN)/libfluidSolver diff --git a/applications/modules/fluidSolver/fluidSolver.C b/applications/modules/fluidSolver/fluidSolver.C index eec96fc71d..1355dce211 100644 --- a/applications/modules/fluidSolver/fluidSolver.C +++ b/applications/modules/fluidSolver/fluidSolver.C @@ -44,23 +44,20 @@ namespace solvers void Foam::solvers::fluidSolver::readControls() { - maxCo = - runTime.controlDict().lookupOrDefault("maxCo", 1.0); + if (mesh.solution().modified()) + { + correctPhi = pimple.dict().lookupOrDefault + ( + "correctPhi", + mesh.dynamic() + ); - maxDeltaT_ = - runTime.controlDict().lookupOrDefault("maxDeltaT", vGreat); - - correctPhi = pimple.dict().lookupOrDefault - ( - "correctPhi", - mesh.dynamic() - ); - - checkMeshCourantNo = pimple.dict().lookupOrDefault - ( - "checkMeshCourantNo", - false - ); + checkMeshCourantNo = pimple.dict().lookupOrDefault + ( + "checkMeshCourantNo", + false + ); + } } @@ -101,7 +98,7 @@ void Foam::solvers::fluidSolver::correctCoNum fvc::surfaceSum(mag(phi))().primitiveField()/rho.primitiveField() ); - CoNum = 0.5*gMax(sumPhi/mesh.V().field())*runTime.deltaTValue(); + CoNum_ = 0.5*gMax(sumPhi/mesh.V().field())*runTime.deltaTValue(); const scalar meanCoNum = 0.5*(gSum(sumPhi)/gSum(mesh.V().field()))*runTime.deltaTValue(); @@ -192,8 +189,17 @@ void Foam::solvers::fluidSolver::continuityErrors Foam::solvers::fluidSolver::fluidSolver(fvMesh& mesh) : solver(mesh), + maxCo + ( + mesh.time().controlDict().lookupOrDefault("maxCo", vGreat) + ), + maxDeltaT_ + ( + mesh.time().controlDict().lookupOrDefault("maxDeltaT", vGreat) + ), cumulativeContErr(0), - CoNum(0) + CoNum_(0), + CoNum(CoNum_) { // Read the controls readControls(); @@ -212,7 +218,7 @@ Foam::scalar Foam::solvers::fluidSolver::maxDeltaT() const { scalar deltaT = min(fvModels().maxDeltaT(), maxDeltaT_); - if (CoNum > small) + if (maxCo < vGreat && CoNum > small) { deltaT = min(deltaT, maxCo/CoNum*runTime.deltaTValue()); } diff --git a/applications/modules/fluidSolver/fluidSolver.H b/applications/modules/fluidSolver/fluidSolver.H index abb70d9587..61d2764344 100644 --- a/applications/modules/fluidSolver/fluidSolver.H +++ b/applications/modules/fluidSolver/fluidSolver.H @@ -96,7 +96,7 @@ protected: bool correctPhi; //- Current maximum Courant number for time-step control - scalar CoNum; + scalar CoNum_; //- Read controls void readControls(); @@ -129,6 +129,14 @@ protected: ); +public: + + // Public Data + + //- Current maximum Courant number for time-step control + const scalar& CoNum; + + public: //- Runtime type information diff --git a/applications/modules/fluidSolver/functionObjects/fluidMaxDeltaT/fluidMaxDeltaT.C b/applications/modules/fluidSolver/functionObjects/fluidMaxDeltaT/fluidMaxDeltaT.C new file mode 100644 index 0000000000..4cdd923a55 --- /dev/null +++ b/applications/modules/fluidSolver/functionObjects/fluidMaxDeltaT/fluidMaxDeltaT.C @@ -0,0 +1,113 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "fluidMaxDeltaT.H" +#include "fluidSolver.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(fluidMaxDeltaT, 0); + + addToRunTimeSelectionTable + ( + functionObject, + fluidMaxDeltaT, + dictionary + ); +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::fluidMaxDeltaT::fluidMaxDeltaT +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::fluidMaxDeltaT::~fluidMaxDeltaT() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::fluidMaxDeltaT::read(const dictionary& dict) +{ + fvMeshFunctionObject::read(dict); + + maxCoPtr_ = Function1::New("maxCo", dict); + maxDeltaTPtr_ = Function1::New("maxDeltaT", dict); + + return true; +} + + +bool Foam::functionObjects::fluidMaxDeltaT::execute() +{ + return true; +} + + +bool Foam::functionObjects::fluidMaxDeltaT::write() +{ + return true; +} + + +Foam::scalar Foam::functionObjects::fluidMaxDeltaT::maxDeltaT() const +{ + scalar deltaT = + time_.userTimeToTime(maxDeltaTPtr_().value(time_.userTimeValue())); + + const scalar CoNum = + mesh_.lookupObject(solver::typeName).CoNum; + + if (CoNum > small) + { + const scalar maxCo = maxCoPtr_().value(time_.userTimeValue()); + + deltaT = min(deltaT, maxCo/CoNum*time_.deltaTValue()); + } + + return deltaT; +} + + +// ************************************************************************* // diff --git a/applications/modules/fluidSolver/functionObjects/fluidMaxDeltaT/fluidMaxDeltaT.H b/applications/modules/fluidSolver/functionObjects/fluidMaxDeltaT/fluidMaxDeltaT.H new file mode 100644 index 0000000000..3caf533b5d --- /dev/null +++ b/applications/modules/fluidSolver/functionObjects/fluidMaxDeltaT/fluidMaxDeltaT.H @@ -0,0 +1,153 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::functionObjects::fluidMaxDeltaT + +Description + Returns the maximum time-step evaluated from time-dependent + maximum Courant number and maximum time-step specifications. + + The \c maxCo and \c maxDeltaT are provided as \c Function1 of time, + supporting constant, tabulated and functional specifications. + +Usage + Example of a time-dependent maximum Courant number: + \verbatim + fluidMaxDeltaT + { + type fluidMaxDeltaT; + + maxCo table + ( + (0 0.2) + (0.6 0.2) + (0.7 0.1) + ); + + maxDeltaT 1; + } + \endverbatim + +See also + Foam::functionObject + Foam::functionObjects::fvMeshFunctionObject + Foam::Function1 + +SourceFiles + fluidMaxDeltaT.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fluidMaxDeltaT_H +#define fluidMaxDeltaT_H + +#include "fvMeshFunctionObject.H" +#include "Function1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class fluidMaxDeltaT Declaration +\*---------------------------------------------------------------------------*/ + +class fluidMaxDeltaT +: + public fvMeshFunctionObject +{ + // Private Data + + //- Max Courant number function/table + autoPtr> maxCoPtr_; + + //- Max time-step function/table + autoPtr> maxDeltaTPtr_; + + +public: + + //- Runtime type information + TypeName("fluidMaxDeltaT"); + + + // Constructors + + //- Construct from Time and dictionary + fluidMaxDeltaT + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); + + //- Disallow default bitwise copy construction + fluidMaxDeltaT(const fluidMaxDeltaT&) = delete; + + + //- Destructor + virtual ~fluidMaxDeltaT(); + + + // Member Functions + + //- Read the controls + virtual bool read(const dictionary&); + + //- Return the list of fields required + virtual wordList fields() const + { + return wordList::null(); + } + + //- Execute, currently does nothing + virtual bool execute(); + + //- Write the time step value + virtual bool write(); + + //- Return the maximum time-step for stable operation + virtual scalar maxDeltaT() const; + + + // Member Operators + + //- Disallow default bitwise assignment + void operator=(const fluidMaxDeltaT&) = delete; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/modules/multiphaseEuler/multiphaseEuler/multiphaseEuler.C b/applications/modules/multiphaseEuler/multiphaseEuler/multiphaseEuler.C index c75a31b0f7..4316df8725 100644 --- a/applications/modules/multiphaseEuler/multiphaseEuler/multiphaseEuler.C +++ b/applications/modules/multiphaseEuler/multiphaseEuler/multiphaseEuler.C @@ -79,7 +79,7 @@ void Foam::solvers::multiphaseEuler::correctCoNum() ); } - CoNum = 0.5*gMax(sumPhi/mesh.V().field())*runTime.deltaTValue(); + CoNum_ = 0.5*gMax(sumPhi/mesh.V().field())*runTime.deltaTValue(); const scalar meanCoNum = 0.5*(gSum(sumPhi)/gSum(mesh.V().field()))*runTime.deltaTValue(); diff --git a/applications/modules/shockFluid/shockFluid.C b/applications/modules/shockFluid/shockFluid.C index 5f749a513a..5d5718abb3 100644 --- a/applications/modules/shockFluid/shockFluid.C +++ b/applications/modules/shockFluid/shockFluid.C @@ -50,7 +50,7 @@ void Foam::solvers::shockFluid::correctCoNum(const surfaceScalarField& amaxSf) { const scalarField sumAmaxSf(fvc::surfaceSum(amaxSf)().primitiveField()); - CoNum = 0.5*gMax(sumAmaxSf/mesh.V().field())*runTime.deltaTValue(); + CoNum_ = 0.5*gMax(sumAmaxSf/mesh.V().field())*runTime.deltaTValue(); const scalar meanCoNum = 0.5*(gSum(sumAmaxSf)/gSum(mesh.V().field()))*runTime.deltaTValue(); diff --git a/applications/solvers/foamMultiRun/setDeltaT.C b/applications/solvers/foamMultiRun/setDeltaT.C index 89610f1823..c9816cc9c1 100644 --- a/applications/solvers/foamMultiRun/setDeltaT.C +++ b/applications/solvers/foamMultiRun/setDeltaT.C @@ -47,6 +47,11 @@ void Foam::setDeltaT(Time& runTime, const PtrList& solvers) } } + if (transient) + { + deltaT = min(deltaT, runTime.functionObjects().maxDeltaT()); + } + if (transient && deltaT < rootVGreat) { runTime.setDeltaT(min(runTime.deltaTValue(), deltaT)); @@ -72,6 +77,11 @@ void Foam::adjustDeltaT(Time& runTime, const PtrList& solvers) } } + if (transient) + { + deltaT = min(deltaT, runTime.functionObjects().maxDeltaT()); + } + if (transient && deltaT < rootVGreat) { runTime.setDeltaT diff --git a/applications/solvers/foamRun/setDeltaT.C b/applications/solvers/foamRun/setDeltaT.C index 9e7d9a16fb..c55555d620 100644 --- a/applications/solvers/foamRun/setDeltaT.C +++ b/applications/solvers/foamRun/setDeltaT.C @@ -34,10 +34,15 @@ void Foam::setDeltaT(Time& runTime, const solver& solver) runTime.timeIndex() == 0 && runTime.controlDict().lookupOrDefault("adjustTimeStep", false) && solver.transient() - && solver.maxDeltaT() < rootVGreat ) { - runTime.setDeltaT(min(runTime.deltaTValue(), solver.maxDeltaT())); + const scalar deltaT = + min(solver.maxDeltaT(), runTime.functionObjects().maxDeltaT()); + + if (deltaT < rootVGreat) + { + runTime.setDeltaT(min(runTime.deltaTValue(), deltaT)); + } } } @@ -49,18 +54,19 @@ void Foam::adjustDeltaT(Time& runTime, const solver& solver) ( runTime.controlDict().lookupOrDefault("adjustTimeStep", false) && solver.transient() - && solver.maxDeltaT() < rootVGreat ) { - runTime.setDeltaT - ( - min + const scalar deltaT = + min(solver.maxDeltaT(), runTime.functionObjects().maxDeltaT()); + + if (deltaT < rootVGreat) + { + runTime.setDeltaT ( - solver::deltaTFactor*runTime.deltaTValue(), - solver.maxDeltaT() - ) - ); - Info<< "deltaT = " << runTime.deltaTValue() << endl; + min(solver::deltaTFactor*runTime.deltaTValue(), deltaT) + ); + Info<< "deltaT = " << runTime.deltaTValue() << endl; + } } } diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C index 00cf5c8139..c26612943a 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C @@ -163,6 +163,12 @@ Foam::scalar Foam::functionObject::timeToNextAction() } +Foam::scalar Foam::functionObject::maxDeltaT() const +{ + return vGreat; +} + + void Foam::functionObject::movePoints(const polyMesh&) {} diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H index 68672cb29e..a02f911ede 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H @@ -249,6 +249,9 @@ public: // time. Returns the write time, or vGreat. virtual scalar timeToNextAction(); + //- Return the maximum time-step for stable operation + virtual scalar maxDeltaT() const; + //- Update topology using the given map virtual void movePoints(const polyMesh& mesh); diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 8276947705..586168ddcb 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -299,6 +299,19 @@ Foam::scalar Foam::functionObjectList::timeToNextAction() } +Foam::scalar Foam::functionObjectList::maxDeltaT() const +{ + scalar result = vGreat; + + forAll(*this, oi) + { + result = min(result, operator[](oi).maxDeltaT()); + } + + return result; +} + + bool Foam::functionObjectList::read() { bool ok = true; diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index 605d25bbf8..1a039a2261 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -178,6 +178,9 @@ public: //- Return the time to the next write scalar timeToNextAction(); + //- Return the maximum time-step for stable operation + virtual scalar maxDeltaT() const; + //- Update topology using the given map virtual void movePoints(const polyMesh& mesh); diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index dc1baf2ef1..074ce905fe 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -208,6 +208,10 @@ public: template const Type& lookupObject(const word& name) const; + //- Lookup and return the object reference of the given Type + template + Type& lookupObjectRef(const word& name) const; + //- Is the Type in registry // the name is derived from the type name and given group template @@ -218,10 +222,6 @@ public: template const Type& lookupType(const word& group = word::null) const; - //- Lookup and return the object reference of the given Type - template - Type& lookupObjectRef(const word& name) const; - //- Return new event number. label getEvent() const; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index 7dbfbcc544..a91cab1478 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -216,6 +216,13 @@ const Type& Foam::objectRegistry::lookupObject(const word& name) const } +template +Type& Foam::objectRegistry::lookupObjectRef(const word& name) const +{ + return const_cast(lookupObject(name)); +} + + template bool Foam::objectRegistry::foundType(const word& group) const { @@ -230,13 +237,6 @@ const Type& Foam::objectRegistry::lookupType(const word& group) const } -template -Type& Foam::objectRegistry::lookupObjectRef(const word& name) const -{ - return const_cast(lookupObject(name)); -} - - template bool Foam::objectRegistry::cacheTemporaryObject(Object& ob) const { diff --git a/src/combustionModels/functionObjects/adjustTimeStepToCombustion/adjustTimeStepToCombustion.C b/src/combustionModels/functionObjects/adjustTimeStepToCombustion/adjustTimeStepToCombustion.C index de5ffdb5c2..cc3086cfb9 100644 --- a/src/combustionModels/functionObjects/adjustTimeStepToCombustion/adjustTimeStepToCombustion.C +++ b/src/combustionModels/functionObjects/adjustTimeStepToCombustion/adjustTimeStepToCombustion.C @@ -126,10 +126,32 @@ bool Foam::functionObjects::adjustTimeStepToCombustion::read bool Foam::functionObjects::adjustTimeStepToCombustion::execute() +{ + return true; +} + + +bool Foam::functionObjects::adjustTimeStepToCombustion::write() +{ + if (extrapolate_ && obr_.time().writeTime()) + { + timeIOdictionary propsDict(propsDictIo(IOobject::NO_READ)); + + propsDict.add("combustionDeltaT", combustionDeltaT0_); + + propsDict.regIOobject::write(); + } + + return true; +} + + +Foam::scalar +Foam::functionObjects::adjustTimeStepToCombustion::maxDeltaT() const { if (!time_.controlDict().lookupOrDefault("adjustTimeStep", false)) { - return true; + return vGreat; } const combustionModel& combustion = @@ -185,32 +207,7 @@ bool Foam::functionObjects::adjustTimeStepToCombustion::execute() haveCombustionDeltaT0_ = true; combustionDeltaT0_ = combustionDeltaT1; - // The solver has not adjusted the time-step yet. When it does, if it is - // within the physical and specified limits it will increase it by a - // fixed factor. So, we clip it here to the combustion time-step divided by - // that factor. The solver will then increase it to the combustion - // time-step if it can. - const_cast(time_).setDeltaTNoAdjust - ( - min(deltaT/solver::deltaTFactor, time_.deltaTValue()) - ); - - return true; -} - - -bool Foam::functionObjects::adjustTimeStepToCombustion::write() -{ - if (extrapolate_ && obr_.time().writeTime()) - { - timeIOdictionary propsDict(propsDictIo(IOobject::NO_READ)); - - propsDict.add("combustionDeltaT", combustionDeltaT0_); - - propsDict.regIOobject::write(); - } - - return true; + return deltaT; } diff --git a/src/combustionModels/functionObjects/adjustTimeStepToCombustion/adjustTimeStepToCombustion.H b/src/combustionModels/functionObjects/adjustTimeStepToCombustion/adjustTimeStepToCombustion.H index 2defa6d6af..3bb1fb16dd 100644 --- a/src/combustionModels/functionObjects/adjustTimeStepToCombustion/adjustTimeStepToCombustion.H +++ b/src/combustionModels/functionObjects/adjustTimeStepToCombustion/adjustTimeStepToCombustion.H @@ -25,17 +25,18 @@ Class Foam::functionObjects::adjustTimeStepToCombustion Description - Adjusts the time step to match bulk reaction time scales. This allows the - solver to temporally resolve chemical changes, in order to better couple - the chemistry and transport, or to improve the time-accuracy of - post-processing. + Returns the minimum bulk reaction time scale + + This allows the solver to temporally resolve chemical changes, in order to + better couple the chemistry and transport, or to improve the time-accuracy + of post-processing. Note that this function only does anything if time step adjustment is enabled in the controlDict. Example of function object specification: \verbatim - adjustTimeStepToCombustion1 + adjustTimeStepToCombustion { type adjustTimeStepToCombustion; libs ("libcombustionModels.so"); @@ -94,10 +95,10 @@ class adjustTimeStepToCombustion bool extrapolate_; //- Do we have the previous combustion time-step? - bool haveCombustionDeltaT0_; + mutable bool haveCombustionDeltaT0_; //- The previous combustion time-step - scalar combustionDeltaT0_; + mutable scalar combustionDeltaT0_; // Private Member Functions @@ -143,12 +144,15 @@ public: return wordList::null(); } - //- Reset the timeStep from the Function1 of time + //- Do nothing virtual bool execute(); //- Do nothing virtual bool write(); + //- Return the minimum combustion time-scale + virtual scalar maxDeltaT() const; + // Member Operators diff --git a/src/functionObjects/field/turbulenceFields/turbulenceFields.C b/src/functionObjects/field/turbulenceFields/turbulenceFields.C index 038c03d182..61fb24c85a 100644 --- a/src/functionObjects/field/turbulenceFields/turbulenceFields.C +++ b/src/functionObjects/field/turbulenceFields/turbulenceFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2013-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -158,7 +158,7 @@ bool Foam::functionObjects::turbulenceFields::read(const dictionary& dict) bool Foam::functionObjects::turbulenceFields::execute() { - if (obr_.foundObject(phaseName_)) + if (obr_.foundType(phaseName_)) { const fluidThermophysicalTransportModel& ttm = obr_.lookupType(phaseName_); diff --git a/src/thermophysicalModels/chemistryModel/functionObjects/adjustTimeStepToChemistry/adjustTimeStepToChemistry.C b/src/thermophysicalModels/chemistryModel/functionObjects/adjustTimeStepToChemistry/adjustTimeStepToChemistry.C index 293a0e7b44..1b8822f932 100644 --- a/src/thermophysicalModels/chemistryModel/functionObjects/adjustTimeStepToChemistry/adjustTimeStepToChemistry.C +++ b/src/thermophysicalModels/chemistryModel/functionObjects/adjustTimeStepToChemistry/adjustTimeStepToChemistry.C @@ -83,29 +83,6 @@ bool Foam::functionObjects::adjustTimeStepToChemistry::read bool Foam::functionObjects::adjustTimeStepToChemistry::execute() { - if (!time_.controlDict().lookupOrDefault("adjustTimeStep", false)) - { - return true; - } - - const basicChemistryModel& chemistry = - obr_.lookupObject - ( - IOobject::groupName("chemistryProperties", phaseName_) - ); - - const scalar deltaT = gMin(chemistry.deltaTChem()); - - // The solver has not adjusted the time-step yet. When it does, if it is - // within the physical and specified limits it will increase it by a - // fixed factor. So, we clip it here to the chemical time-step divided by - // that factor. The solver will then increase it to the chemical time-step - // if it can. - const_cast(time_).setDeltaTNoAdjust - ( - min(deltaT/solver::deltaTFactor, time_.deltaTValue()) - ); - return true; } @@ -116,4 +93,21 @@ bool Foam::functionObjects::adjustTimeStepToChemistry::write() } +Foam::scalar Foam::functionObjects::adjustTimeStepToChemistry::maxDeltaT() const +{ + if (!time_.controlDict().lookupOrDefault("adjustTimeStep", false)) + { + return vGreat; + } + + const basicChemistryModel& chemistry = + obr_.lookupObject + ( + IOobject::groupName("chemistryProperties", phaseName_) + ); + + return gMin(chemistry.deltaTChem()); +} + + // ************************************************************************* // diff --git a/src/thermophysicalModels/chemistryModel/functionObjects/adjustTimeStepToChemistry/adjustTimeStepToChemistry.H b/src/thermophysicalModels/chemistryModel/functionObjects/adjustTimeStepToChemistry/adjustTimeStepToChemistry.H index 0e6c13215b..51045803d1 100644 --- a/src/thermophysicalModels/chemistryModel/functionObjects/adjustTimeStepToChemistry/adjustTimeStepToChemistry.H +++ b/src/thermophysicalModels/chemistryModel/functionObjects/adjustTimeStepToChemistry/adjustTimeStepToChemistry.H @@ -25,17 +25,18 @@ Class Foam::functionObjects::adjustTimeStepToChemistry Description - Adjusts the time step to match a chemistry model's stored chemical time - step. This allows the solver to temporally resolve chemical changes, in - order to better couple the chemistry and transport, or in order to - accurately post-process the chemical changes. + Returns the minimum chemistry chemical time scale + + This allows the solver to temporally resolve chemical changes, in order to + better couple the chemistry and transport, or in order to accurately + post-process the chemical changes. Note that this function only does anything if time step adjustment is enabled in the controlDict. Example of function object specification: \verbatim - adjustTimeStepToChemistry1 + adjustTimeStepToChemistry { type adjustTimeStepToChemistry; libs ("libchemistryModel.so"); @@ -114,12 +115,15 @@ public: return wordList::null(); } - //- Reset the timeStep from the Function1 of time + //- Do nothing virtual bool execute(); //- Do nothing virtual bool write(); + //- Return the minimum chemistry.deltaTChem() + virtual scalar maxDeltaT() const; + // Member Operators