diff --git a/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C b/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C index 050e598434..0d96061784 100644 --- a/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C +++ b/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,6 +27,10 @@ License #include "addToRunTimeSelectionTable.H" #include "fvMesh.H" #include "Time.H" +#include "volFields.H" + +#define SetResidual(Type) \ + setResidual(mesh, solverDict, fieldName, component, canSet, residual); // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -76,12 +80,14 @@ equationInitialResidualCondition ) : runTimeCondition(name, obr, dict, state), - fieldNames_(dict.get("fields")), + fieldSelection_(obr, true), value_(dict.get("value")), timeStart_(dict.lookupOrDefault("timeStart", -GREAT)), mode_(operatingModeNames.get("mode", dict)) { - if (fieldNames_.size()) + fieldSelection_.read(dict); + + if (fieldSelection_.size()) { timeStart_ = obr.time().userTimeToTime(timeStart_); } @@ -97,9 +103,11 @@ equationInitialResidualCondition // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * // -bool Foam::functionObjects::runTimeControls::equationInitialResidualCondition:: -apply() +bool Foam::functionObjects::runTimeControls:: +equationInitialResidualCondition::apply() { + fieldSelection_.updateSelection(); + bool satisfied = false; if (!active_) @@ -116,16 +124,26 @@ apply() const fvMesh& mesh = refCast(obr_); const dictionary& solverDict = mesh.solverPerformanceDict(); - List result(fieldNames_.size(), -VGREAT); + const auto& selection = fieldSelection_.selection(); + List 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)) { - const List sp(solverDict.lookup(fieldName)); - const scalar residual = sp.first().initialResidual(); + label component = fieldInfo.component(); + scalar residual = VGREAT; + bool canSet = true; + SetResidual(scalar); + SetResidual(vector); + SetResidual(symmTensor); + SetResidual(sphericalTensor); + SetResidual(tensor); + result[fieldi] = residual; switch (mode_) @@ -164,7 +182,9 @@ apply() { WarningInFunction << "Initial residual data not found for field " - << fieldNames_[i] << endl; + << selection[i].name() + << ". Solver dictionary contains " << solverDict.sortedToc() + << endl; } else { @@ -190,7 +210,7 @@ apply() { if (result[resulti] > 0) { - Log << " field: " << fieldNames_[resulti] + Log << " field: " << selection[resulti].name() << ", residual: " << result[resulti] << nl; } } @@ -201,8 +221,8 @@ apply() } -void Foam::functionObjects::runTimeControls::equationInitialResidualCondition:: -write() +void Foam::functionObjects::runTimeControls:: +equationInitialResidualCondition::write() { // do nothing } diff --git a/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.H b/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.H index fa0ca263b1..fab51aed76 100644 --- a/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.H +++ b/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,12 +37,15 @@ SourceFiles #define functionObjects_runTimeControls_equationInitialResidualCondition_H #include "runTimeCondition.H" -#include "Enum.H" +#include "solverFieldSelection.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { + +class fvMesh; + namespace functionObjects { namespace runTimeControls @@ -71,8 +74,8 @@ protected: // Protected data - //- Field name - const wordList fieldNames_; + //- Field names + solverFieldSelection fieldSelection_; //- Value to compare const scalar value_; @@ -84,6 +87,21 @@ protected: operatingMode mode_; + // Protected Member Functions + + //- Set the residual (scalar) value + template + void setResidual + ( + const fvMesh& mesh, + const dictionary& dict, + const word& fieldName, + const label componenti, + bool& canSet, + scalar& residual + ) const; + + public: //- Runtime type information @@ -120,6 +138,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "equationInitialResidualConditionTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualConditionTemplates.C b/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualConditionTemplates.C new file mode 100644 index 0000000000..5f24cafad5 --- /dev/null +++ b/src/functionObjects/utilities/runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualConditionTemplates.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "fvMesh.H" + +template +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 volFieldType; + + if (canSet && mesh.foundObject(fieldName)) + { + const List> sp(dict.lookup(fieldName)); + const Type& allComponents = sp.first().initialResidual(); + + if (componenti != -1) + { + if (componenti > pTraits::nComponents - 1) + { + FatalErrorInFunction + << "Requested component [" << componenti + << "] for field " << fieldName + << " is out of range 0.." + << pTraits::nComponents - 1 + << exit(FatalError); + } + + residual = component(allComponents, componenti); + } + else + { + residual = cmptMax(allComponents); + } + + canSet = false; + } +}