ENH: Extended equationInitialResidualCondition to use field components

This commit is contained in:
Andrew Heather
2019-01-21 11:42:49 +00:00
parent 2a386064e2
commit d11a5091a4
3 changed files with 130 additions and 18 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,6 +27,10 @@ License
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "Time.H" #include "Time.H"
#include "volFields.H"
#define SetResidual(Type) \
setResidual<Type>(mesh, solverDict, fieldName, component, canSet, residual);
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -76,12 +80,14 @@ equationInitialResidualCondition
) )
: :
runTimeCondition(name, obr, dict, state), runTimeCondition(name, obr, dict, state),
fieldNames_(dict.get<wordList>("fields")), fieldSelection_(obr, true),
value_(dict.get<scalar>("value")), value_(dict.get<scalar>("value")),
timeStart_(dict.lookupOrDefault("timeStart", -GREAT)), timeStart_(dict.lookupOrDefault("timeStart", -GREAT)),
mode_(operatingModeNames.get("mode", dict)) mode_(operatingModeNames.get("mode", dict))
{ {
if (fieldNames_.size()) fieldSelection_.read(dict);
if (fieldSelection_.size())
{ {
timeStart_ = obr.time().userTimeToTime(timeStart_); timeStart_ = obr.time().userTimeToTime(timeStart_);
} }
@ -97,9 +103,11 @@ equationInitialResidualCondition
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::runTimeControls::equationInitialResidualCondition:: bool Foam::functionObjects::runTimeControls::
apply() equationInitialResidualCondition::apply()
{ {
fieldSelection_.updateSelection();
bool satisfied = false; bool satisfied = false;
if (!active_) if (!active_)
@ -116,16 +124,26 @@ apply()
const fvMesh& mesh = refCast<const fvMesh>(obr_); const fvMesh& mesh = refCast<const fvMesh>(obr_);
const dictionary& solverDict = mesh.solverPerformanceDict(); const dictionary& solverDict = mesh.solverPerformanceDict();
List<scalar> result(fieldNames_.size(), -VGREAT); const auto& selection = fieldSelection_.selection();
List<scalar> result(selection.size(), -VGREAT);
forAll(fieldNames_, fieldi) forAll(selection, fieldi)
{ {
const word& fieldName = fieldNames_[fieldi]; const auto& fieldInfo = selection[fieldi];
const word& fieldName = fieldInfo.name();
if (solverDict.found(fieldName)) if (solverDict.found(fieldName))
{ {
const List<solverPerformance> sp(solverDict.lookup(fieldName)); label component = fieldInfo.component();
const scalar residual = sp.first().initialResidual(); scalar residual = VGREAT;
bool canSet = true;
SetResidual(scalar);
SetResidual(vector);
SetResidual(symmTensor);
SetResidual(sphericalTensor);
SetResidual(tensor);
result[fieldi] = residual; result[fieldi] = residual;
switch (mode_) switch (mode_)
@ -164,7 +182,9 @@ apply()
{ {
WarningInFunction WarningInFunction
<< "Initial residual data not found for field " << "Initial residual data not found for field "
<< fieldNames_[i] << endl; << selection[i].name()
<< ". Solver dictionary contains " << solverDict.sortedToc()
<< endl;
} }
else else
{ {
@ -190,7 +210,7 @@ apply()
{ {
if (result[resulti] > 0) if (result[resulti] > 0)
{ {
Log << " field: " << fieldNames_[resulti] Log << " field: " << selection[resulti].name()
<< ", residual: " << result[resulti] << nl; << ", residual: " << result[resulti] << nl;
} }
} }
@ -201,8 +221,8 @@ apply()
} }
void Foam::functionObjects::runTimeControls::equationInitialResidualCondition:: void Foam::functionObjects::runTimeControls::
write() equationInitialResidualCondition::write()
{ {
// do nothing // do nothing
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,12 +37,15 @@ SourceFiles
#define functionObjects_runTimeControls_equationInitialResidualCondition_H #define functionObjects_runTimeControls_equationInitialResidualCondition_H
#include "runTimeCondition.H" #include "runTimeCondition.H"
#include "Enum.H" #include "solverFieldSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
class fvMesh;
namespace functionObjects namespace functionObjects
{ {
namespace runTimeControls namespace runTimeControls
@ -71,8 +74,8 @@ protected:
// Protected data // Protected data
//- Field name //- Field names
const wordList fieldNames_; solverFieldSelection fieldSelection_;
//- Value to compare //- Value to compare
const scalar value_; const scalar value_;
@ -84,6 +87,21 @@ protected:
operatingMode mode_; operatingMode mode_;
// Protected Member Functions
//- Set the residual (scalar) value
template<class Type>
void setResidual
(
const fvMesh& mesh,
const dictionary& dict,
const word& fieldName,
const label componenti,
bool& canSet,
scalar& residual
) const;
public: public:
//- Runtime type information //- Runtime type information
@ -120,6 +138,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "equationInitialResidualConditionTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,68 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fvMesh.H"
template<class Type>
void Foam::functionObjects::runTimeControls::
equationInitialResidualCondition::setResidual
(
const fvMesh& mesh,
const dictionary& dict,
const word& fieldName,
const label componenti,
bool& canSet,
scalar& residual
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
if (canSet && mesh.foundObject<volFieldType>(fieldName))
{
const List<SolverPerformance<Type>> sp(dict.lookup(fieldName));
const Type& allComponents = sp.first().initialResidual();
if (componenti != -1)
{
if (componenti > pTraits<Type>::nComponents - 1)
{
FatalErrorInFunction
<< "Requested component [" << componenti
<< "] for field " << fieldName
<< " is out of range 0.."
<< pTraits<Type>::nComponents - 1
<< exit(FatalError);
}
residual = component(allComponents, componenti);
}
else
{
residual = cmptMax(allComponents);
}
canSet = false;
}
}