From 07f5080f2efe5ce0573f236128594a6d075b5712 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Fri, 5 Feb 2021 13:45:59 +0000 Subject: [PATCH] fvOptions: Remove type restrictions and rewrite of field-name handling A number of fvOptions that apply to a user-derined field can now automatically work what primitive type they apply to. These options can apply to any field type, and in some cases even multiple fields of differing type. Example usage of the options to which this change applies are shown below: codedSource1 { type codedSource; name codedSource1; field h; ... } fixedValueConstraint1 { type fixedValueConstraint; fieldValues { R (1 0 0 1 0 1); epsilon 150; } ... } phaseLimitStabilization11 { type phaseLimitStabilization; field sigma.liquid; ... } Previously to apply to a given type, these options had to be selected with the name of the type prepended to the option name (e.g., "type symmTensorPhaseLimitStabilization;") and those that operated on multiple fields were restricted to those fields being of the same type. A number of other options have had improvements made to their handling of user specification of fields. Where possible, the option will now attempt to work out what field the option applies to automatically. The following options, therefore, no longer require "field" or "fields" entries: actuationDiskSource buoyancyEnergy buoyancyForce meanVelocityForce rotorDiskSource volumeFractionSource constantHeatTransfer function2HeatTransfer variableHeatTransfer Non-standard field names can be overridden in the same way as in boundary conditions; e.g., the velocity name can be overridden with a "U ;" entry if it does not have the default name, "U". The name of the energy field is now always determined from the thermodynamics model and should always be correct. Some options that can be applied to an individual phase also support a "phase ;" entry; fvOptions field-name handling has been rewritten to increase its flexibility and to improve warning messages. The flexibility now allows for options that apply to all fields, or all fields of a given phase, rather than being limited to a specific list of field names. Messages warning about options that have not been applied now always print just once per time-step. --- .../compressibleInterFilmFoam/Make/files | 1 - .../VoFSolidificationMeltingSource.C | 59 +++- .../VoFSolidificationMeltingSource.H | 20 +- .../VoFSolidificationMeltingSourceIO.C | 51 ---- .../multiphaseEulerFoam/pEqnComps.H | 2 +- .../phaseSystems/phaseSystem/phaseSystem.C | 2 +- .../dynamicCode/codedFvOptionTemplate.C | 41 +-- .../dynamicCode/codedFvOptionTemplate.H | 20 +- .../objectFunction1/objectFunction1.H | 3 +- .../objectFunction1Templates.C | 5 +- .../cfdTools/general/fvOptions/fvOption.C | 97 ++++--- .../cfdTools/general/fvOptions/fvOption.H | 71 ++--- .../cfdTools/general/fvOptions/fvOptionI.H | 6 - .../cfdTools/general/fvOptions/fvOptionList.C | 94 ++++++- .../cfdTools/general/fvOptions/fvOptionList.H | 27 +- .../general/fvOptions/fvOptionListTemplates.C | 32 +-- .../general/fvOptions/fvOptionTemplates.C | 6 +- .../cfdTools/general/fvOptions/fvOptions.H | 4 +- .../cfdTools/general/fvOptions/makeFvOption.H | 52 ---- src/fvOptions/Make/files | 9 +- src/fvOptions/cellSetOption/cellSetOption.C | 76 ++--- src/fvOptions/cellSetOption/cellSetOption.H | 82 +++--- src/fvOptions/cellSetOption/cellSetOptionI.H | 40 +-- src/fvOptions/cellSetOption/cellSetOptionIO.C | 44 --- .../fixedTemperatureConstraint.C | 113 ++++---- .../fixedTemperatureConstraint.H | 50 ++-- .../FixedValueConstraint.C | 95 ------- .../fixedValueConstraint.C | 177 ++++++++++++ ...lueConstraint.H => fixedValueConstraint.H} | 96 +++++-- .../fixedValueConstraints.C | 37 --- .../limitTemperature/limitTemperature.C | 66 +++-- .../limitTemperature/limitTemperature.H | 25 +- .../corrections/limitVelocity/limitVelocity.C | 47 ++-- .../corrections/limitVelocity/limitVelocity.H | 24 +- .../interRegionOption/interRegionOption.C | 61 +++-- .../interRegionOption/interRegionOption.H | 21 +- .../interRegionOption/interRegionOptionI.H | 13 +- .../interRegionOption/interRegionOptionIO.C | 43 --- .../accelerationSource/accelerationSource.C | 40 ++- .../accelerationSource/accelerationSource.H | 43 ++- .../accelerationSourceTemplates.C | 4 +- .../actuationDiskSource/actuationDiskSource.C | 78 +++--- .../actuationDiskSource/actuationDiskSource.H | 63 ++--- .../derived/buoyancyEnergy/buoyancyEnergy.C | 76 ++++- .../derived/buoyancyEnergy/buoyancyEnergy.H | 38 ++- .../derived/buoyancyEnergy/buoyancyEnergyIO.C | 38 --- .../derived/buoyancyForce/buoyancyForce.C | 65 ++++- .../derived/buoyancyForce/buoyancyForce.H | 42 ++- .../derived/buoyancyForce/buoyancyForceIO.C | 38 --- .../sources/derived/damping/damping/damping.C | 170 ++++++------ .../sources/derived/damping/damping/damping.H | 16 +- .../isotropicDamping/isotropicDamping.C | 33 ++- .../isotropicDamping/isotropicDamping.H | 24 +- .../damping/verticalDamping/verticalDamping.C | 12 +- .../damping/verticalDamping/verticalDamping.H | 9 +- .../effectivenessHeatExchangerSource.C | 89 +++--- .../effectivenessHeatExchangerSource.H | 40 ++- .../explicitPorositySource.C | 72 ++--- .../explicitPorositySource.H | 40 ++- .../meanVelocityForce/meanVelocityForce.C | 100 +++---- .../meanVelocityForce/meanVelocityForce.H | 63 +++-- .../meanVelocityForce/meanVelocityForceIO.C | 38 --- .../patchMeanVelocityForce.C | 75 +++-- .../patchMeanVelocityForce.H | 46 ++-- .../PhaseLimitStabilization.C | 88 ------ .../phaseLimitStabilization.C | 159 ++++++++++- ...bilization.H => phaseLimitStabilization.H} | 109 ++++++-- .../radialActuationDiskSource.C | 20 +- .../radialActuationDiskSource.H | 55 ++-- .../profileModel/profileModelList.H | 4 +- .../derived/rotorDiskSource/rotorDiskSource.C | 145 +++++----- .../derived/rotorDiskSource/rotorDiskSource.H | 70 +++-- .../sixDoFAccelerationSource.C | 60 ++-- .../sixDoFAccelerationSource.H | 29 +- .../sixDoFAccelerationSourceTemplates.C | 6 +- .../solidEquilibriumEnergySource.C | 68 +++-- .../solidEquilibriumEnergySource.H | 50 ++-- .../solidificationMeltingSource.C | 133 +++++---- .../solidificationMeltingSource.H | 27 +- .../solidificationMeltingSourceIO.C | 63 ----- .../volumeFractionSource.C | 215 ++++++++------- .../volumeFractionSource.H | 113 +++++--- .../sources/general/codedSource/CodedSource.C | 251 ----------------- .../sources/general/codedSource/CodedSource.H | 244 ----------------- .../general/codedSource/CodedSourceIO.C | 61 ----- .../sources/general/codedSource/codedSource.C | 259 +++++++++++++++++- .../sources/general/codedSource/codedSource.H | 231 ++++++++++++++++ .../semiImplicitSource/semiImplicitSource.C | 181 ++++++------ .../semiImplicitSource/semiImplicitSource.H | 52 ++-- .../interRegionExplicitPorositySource.C | 136 ++++----- .../interRegionExplicitPorositySource.H | 54 ++-- .../constantHeatTransfer.C | 62 ++--- .../constantHeatTransfer.H | 19 +- .../function2HeatTransfer.C | 86 +++--- .../function2HeatTransfer.H | 29 +- .../interRegionHeatTransferModel.C | 148 +++++----- .../interRegionHeatTransferModel.H | 77 +++--- .../interRegionHeatTransferModelI.H | 53 +--- .../interRegionHeatTransferModelIO.C | 43 --- .../interRegionHeatTransferModelTemplates.C | 6 +- .../variableHeatTransfer.C | 118 ++++---- .../variableHeatTransfer.H | 44 ++- .../fvOptions/radiation/radiation.C | 31 ++- .../fvOptions/radiation/radiation.H | 20 +- .../laminar/blockedChannel/Allclean | 2 +- .../laminar/blockedChannel/Allrun | 2 +- .../laminar/blockedChannel/constant/fvOptions | 15 +- .../blockedChannel/system/blockMeshDict | 14 + .../blockedChannel/system/generateAlphas} | 40 +-- .../blockedChannel/system/scalarTransport | 12 +- .../constant/fvOptions | 5 +- .../heatExchanger/constant/air/fvOptions | 1 - .../heatExchanger/{0 => constant}/porous/AoV | 2 +- .../heatExchanger/constant/porous/fvOptions | 1 - .../{0 => constant}/porous/htcConst | 2 +- .../LES/channel395/constant/fvOptions | 1 - .../laminar/blockedChannel/Allclean | 2 +- .../pimpleFoam/laminar/blockedChannel/Allrun | 2 +- .../laminar/blockedChannel/constant/fvOptions | 5 +- .../blockedChannel/system/generateAlphas} | 31 +-- .../blockedChannel/system/scalarTransport | 5 +- .../simpleFoam/rotorDisk/constant/fvOptions | 1 - .../turbineSiting/constant/fvOptions | 6 +- .../laminar/climbingRod/constant/fvOptions | 2 +- .../damBreakWithObstacle/constant/fvOptions | 2 +- 125 files changed, 3566 insertions(+), 3270 deletions(-) delete mode 100644 applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSourceIO.C delete mode 100644 src/finiteVolume/cfdTools/general/fvOptions/makeFvOption.H delete mode 100644 src/fvOptions/cellSetOption/cellSetOptionIO.C delete mode 100644 src/fvOptions/constraints/fixedValueConstraint/FixedValueConstraint.C create mode 100644 src/fvOptions/constraints/fixedValueConstraint/fixedValueConstraint.C rename src/fvOptions/constraints/fixedValueConstraint/{FixedValueConstraint.H => fixedValueConstraint.H} (56%) delete mode 100644 src/fvOptions/constraints/fixedValueConstraint/fixedValueConstraints.C delete mode 100644 src/fvOptions/interRegionOption/interRegionOptionIO.C delete mode 100644 src/fvOptions/sources/derived/buoyancyEnergy/buoyancyEnergyIO.C delete mode 100644 src/fvOptions/sources/derived/buoyancyForce/buoyancyForceIO.C delete mode 100644 src/fvOptions/sources/derived/meanVelocityForce/meanVelocityForceIO.C delete mode 100644 src/fvOptions/sources/derived/phaseLimitStabilization/PhaseLimitStabilization.C rename src/fvOptions/sources/derived/phaseLimitStabilization/{PhaseLimitStabilization.H => phaseLimitStabilization.H} (59%) delete mode 100644 src/fvOptions/sources/derived/solidificationMeltingSource/solidificationMeltingSourceIO.C delete mode 100644 src/fvOptions/sources/general/codedSource/CodedSource.C delete mode 100644 src/fvOptions/sources/general/codedSource/CodedSource.H delete mode 100644 src/fvOptions/sources/general/codedSource/CodedSourceIO.C create mode 100644 src/fvOptions/sources/general/codedSource/codedSource.H delete mode 100644 src/fvOptions/sources/interRegion/interRegionHeatTransfer/interRegionHeatTransferModel/interRegionHeatTransferModelIO.C rename tutorials/{incompressible/pimpleFoam/laminar/blockedChannel/system/generateAlphaSolid => compressible/rhoPimpleFoam/laminar/blockedChannel/system/generateAlphas} (65%) rename tutorials/heatTransfer/chtMultiRegionFoam/heatExchanger/{0 => constant}/porous/AoV (96%) rename tutorials/heatTransfer/chtMultiRegionFoam/heatExchanger/{0 => constant}/porous/htcConst (96%) rename tutorials/{compressible/rhoPimpleFoam/laminar/blockedChannel/system/generateAlphaSolid => incompressible/pimpleFoam/laminar/blockedChannel/system/generateAlphas} (66%) diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/Make/files b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/Make/files index d24eb3216c..f3e857a2a5 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/Make/files +++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/Make/files @@ -1,6 +1,5 @@ VoFPatchTransfer/VoFPatchTransfer.C VoFSolidificationMeltingSource/VoFSolidificationMeltingSource.C -VoFSolidificationMeltingSource/VoFSolidificationMeltingSourceIO.C compressibleInterFilmFoam.C EXE = $(FOAM_APPBIN)/compressibleInterFilmFoam diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSource.C b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSource.C index 8b59af5317..d972a744d3 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSource.C +++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSource.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,6 +48,16 @@ namespace Foam // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +void Foam::fv::VoFSolidificationMeltingSource::readCoeffs() +{ + alphaSolidT_.reset(Function1::New("alphaSolidT", coeffs_).ptr()); + L_ = dimensionedScalar("L", dimEnergy/dimMass, coeffs_); + relax_ = coeffs_.lookupOrDefault("relax", 0.9); + Cu_ = coeffs_.lookupOrDefault("Cu", 100000); + q_ = coeffs_.lookupOrDefault("q", 0.001); +} + + void Foam::fv::VoFSolidificationMeltingSource::update() const { if (curTimeIndex_ == mesh_.time().timeIndex()) @@ -122,11 +132,11 @@ Foam::fv::VoFSolidificationMeltingSource::VoFSolidificationMeltingSource ) : cellSetOption(sourceName, modelType, dict, mesh), - alphaSolidT_(Function1::New("alphaSolidT", coeffs_)), - L_("L", dimEnergy/dimMass, coeffs_), - relax_(coeffs_.lookupOrDefault("relax", 0.9)), - Cu_(coeffs_.lookupOrDefault("Cu", 100000)), - q_(coeffs_.lookupOrDefault("q", 0.001)), + alphaSolidT_(), + L_("L", dimEnergy/dimMass, NaN), + relax_(NaN), + Cu_(NaN), + q_(NaN), alphaSolid_ ( IOobject @@ -143,19 +153,22 @@ Foam::fv::VoFSolidificationMeltingSource::VoFSolidificationMeltingSource ), curTimeIndex_(-1) { - fieldNames_.setSize(2); - fieldNames_[0] = "U"; - fieldNames_[1] = "T"; - applied_.setSize(fieldNames_.size(), false); + readCoeffs(); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +Foam::wordList Foam::fv::VoFSolidificationMeltingSource::addedToFields() const +{ + return wordList({"U", "T"}); +} + + void Foam::fv::VoFSolidificationMeltingSource::addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const { apply(geometricOneField(), eqn); @@ -166,7 +179,7 @@ void Foam::fv::VoFSolidificationMeltingSource::addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const { apply(rho, eqn); @@ -176,7 +189,7 @@ void Foam::fv::VoFSolidificationMeltingSource::addSup void Foam::fv::VoFSolidificationMeltingSource::addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const { if (debug) @@ -208,11 +221,27 @@ void Foam::fv::VoFSolidificationMeltingSource::addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const { // Momentum source uses a Boussinesq approximation - redirect - addSup(eqn, fieldi); + addSup(eqn, fieldName); +} + + +bool Foam::fv::VoFSolidificationMeltingSource::read(const dictionary& dict) +{ + if (cellSetOption::read(dict)) + { + readCoeffs(); + return true; + } + else + { + return false; + } + + return false; } diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSource.H b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSource.H index a253045162..cab7dbf3ed 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSource.H +++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSource.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -124,6 +124,9 @@ class VoFSolidificationMeltingSource // Private Member Functions + //- Non-virtual read + void readCoeffs(); + //- Return the name of the solid phase fraction word alphaSolidName() const; @@ -161,20 +164,27 @@ public: // Member Functions + // Checks + + //- Return the list of fields for which the option adds source term + // to the transport equation + virtual wordList addedToFields() const; + + // Add explicit and implicit contributions //- Add explicit contribution to enthalpy equation virtual void addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; //- Add implicit contribution to momentum equation virtual void addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; @@ -185,7 +195,7 @@ public: ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; //- Add implicit contribution to compressible momentum equation @@ -193,7 +203,7 @@ public: ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSourceIO.C b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSourceIO.C deleted file mode 100644 index 0c0c1ba373..0000000000 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFSolidificationMeltingSource/VoFSolidificationMeltingSourceIO.C +++ /dev/null @@ -1,51 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2018 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 "VoFSolidificationMeltingSource.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -bool Foam::fv::VoFSolidificationMeltingSource::read(const dictionary& dict) -{ - if (cellSetOption::read(dict)) - { - alphaSolidT_ = Function1::New("alphaSolidT", coeffs_); - coeffs_.lookup("L") >> L_; - coeffs_.readIfPresent("relax", relax_); - coeffs_.readIfPresent("Cu", Cu_); - coeffs_.readIfPresent("q", q_); - - return true; - } - else - { - return false; - } - - return false; -} - - -// ************************************************************************* // diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseEulerFoam/pEqnComps.H b/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseEulerFoam/pEqnComps.H index a3cfe3c6bc..9435ec9cb5 100644 --- a/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseEulerFoam/pEqnComps.H +++ b/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseEulerFoam/pEqnComps.H @@ -61,7 +61,7 @@ PtrList pEqnComps(phases.size()); } // Option sources - if (fvOptions.appliesToField(rho.name())) + if (fvOptions.addsToField(rho.name())) { pEqnComp -= (fvOptions(alpha, rho) & rho)/rho; } diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/phaseSystem/phaseSystem.C b/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/phaseSystem/phaseSystem.C index 5d73a03b71..be86372443 100644 --- a/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/phaseSystem/phaseSystem.C +++ b/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/phaseSystem/phaseSystem.C @@ -764,7 +764,7 @@ void Foam::phaseSystem::correctContinuityError() ) ); - if (fvOptions().appliesToField(rho.name())) + if (fvOptions().addsToField(rho.name())) { source += fvOptions()(alpha, rho)ρ } diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C index 2ca99a8dad..6cff655d5d 100644 --- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C +++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C @@ -124,26 +124,10 @@ ${typeName}FvOption${SourceType}:: // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void ${typeName}FvOption${SourceType}::correct -( - GeometricField<${TemplateType}, fvPatchField, volMesh>& fld -) const -{ - if (${verbose:-false}) - { - Info<<"${typeName}FvOption${SourceType}::correct()\n"; - } - -//{{{ begin code - ${codeCorrect} -//}}} end code -} - - void ${typeName}FvOption${SourceType}::addSup ( fvMatrix<${TemplateType}>& eqn, - const label fieldi + const word& fieldName ) const { if (${verbose:-false}) @@ -161,7 +145,7 @@ void ${typeName}FvOption${SourceType}::addSup ( const volScalarField& rho, fvMatrix<${TemplateType}>& eqn, - const label fieldi + const word& fieldName ) const { if (${verbose:-false}) @@ -180,7 +164,7 @@ void ${typeName}FvOption${SourceType}::addSup const volScalarField& alpha, const volScalarField& rho, fvMatrix<${TemplateType}>& eqn, - const label fieldi + const word& fieldName ) const { if (${verbose:-false}) @@ -194,26 +178,9 @@ void ${typeName}FvOption${SourceType}::addSup } -void ${typeName}FvOption${SourceType}::constrain -( - fvMatrix<${TemplateType}>& eqn, - const label fieldi -) const -{ - if (${verbose:-false}) - { - Info<<"${typeName}FvOption${SourceType}::constrain()\n"; - } - -//{{{ begin code - ${codeSetValue} -//}}} end code -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam - } // End namespace fv + // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H index c05bc39d29..397035ba1e 100644 --- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H +++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H @@ -70,23 +70,20 @@ public: const fvMesh& mesh ); + //- Destructor virtual ~${typeName}FvOption${SourceType}(); // Member Functions - //- Correct field - virtual void correct - ( - GeometricField<${TemplateType}, fvPatchField, volMesh>& - ) const; + // Evaluation //- Explicit and implicit matrix contributions virtual void addSup ( fvMatrix<${TemplateType}>& eqn, - const label fieldi + const word& fieldName ) const; //- Explicit and implicit matrix contributions for compressible @@ -95,7 +92,7 @@ public: ( const volScalarField& rho, fvMatrix<${TemplateType}>& eqn, - const label fieldi + const word& fieldName ) const; //- Explicit and implicit matrix contributions for phase equations @@ -104,14 +101,7 @@ public: const volScalarField& alpha, const volScalarField& rho, fvMatrix<${TemplateType}>& eqn, - const label fieldi - ) const; - - //- Set value - virtual void constrain - ( - fvMatrix<${TemplateType}>& eqn, - const label fieldi + const word& fieldName ) const; }; diff --git a/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1.H b/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1.H index 479e10e02d..7dfc14ce74 100644 --- a/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1.H +++ b/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1.H @@ -86,7 +86,8 @@ public: const word& name, const dictionary& dict, const word& objectName, - const objectRegistry& db + const objectRegistry& db, + const bool error = true ); diff --git a/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1Templates.C b/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1Templates.C index ee67d45f29..ff31099c50 100644 --- a/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1Templates.C +++ b/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1Templates.C @@ -50,7 +50,8 @@ Foam::autoPtr Foam::objectFunction1::New const word& name, const dictionary& dict, const word& objectName, - const objectRegistry& db + const objectRegistry& db, + const bool error ) { autoPtr ptr @@ -68,7 +69,7 @@ Foam::autoPtr Foam::objectFunction1::New : nullptr ); - if (!ptr.valid()) + if (error && !ptr.valid()) { // Spit lookup error db.lookupObject(objectName); diff --git a/src/finiteVolume/cfdTools/general/fvOptions/fvOption.C b/src/finiteVolume/cfdTools/general/fvOptions/fvOption.C index 5cd0a44240..4e2452c2ab 100644 --- a/src/finiteVolume/cfdTools/general/fvOptions/fvOption.C +++ b/src/finiteVolume/cfdTools/general/fvOptions/fvOption.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -52,9 +52,7 @@ Foam::fv::option::option modelType_(modelType), mesh_(mesh), dict_(dict), - coeffs_(dict.optionalSubDict(modelType + "Coeffs")), - fieldNames_(), - applied_() + coeffs_(dict.optionalSubDict(modelType + "Coeffs")) { Info<< incrIndent << indent << "Source: " << name_ << endl << decrIndent; } @@ -103,30 +101,46 @@ Foam::fv::option::~option() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -Foam::label Foam::fv::option::applyToField(const word& fieldName) const +Foam::wordList Foam::fv::option::addedToFields() const { - return findIndex(fieldNames_, fieldName); + return wordList::null(); } -void Foam::fv::option::checkApplied() const +Foam::wordList Foam::fv::option::constrainedFields() const { - forAll(applied_, i) - { - if (!applied_[i]) - { - WarningInFunction - << "Source " << name_ << " defined for field " - << fieldNames_[i] << " but never used" << endl; - } - } + return wordList::null(); +} + + +Foam::wordList Foam::fv::option::correctedFields() const +{ + return wordList::null(); +} + + +bool Foam::fv::option::addsToField(const word& fieldName) const +{ + return findIndex(addedToFields(), fieldName) != -1; +} + + +bool Foam::fv::option::constrainsField(const word& fieldName) const +{ + return findIndex(constrainedFields(), fieldName) != -1; +} + + +bool Foam::fv::option::correctsField(const word& fieldName) const +{ + return findIndex(correctedFields(), fieldName) != -1; } void Foam::fv::option::addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -134,7 +148,7 @@ void Foam::fv::option::addSup void Foam::fv::option::addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -142,7 +156,7 @@ void Foam::fv::option::addSup void Foam::fv::option::addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -150,7 +164,7 @@ void Foam::fv::option::addSup void Foam::fv::option::addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -158,7 +172,7 @@ void Foam::fv::option::addSup void Foam::fv::option::addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -167,7 +181,7 @@ void Foam::fv::option::addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -176,7 +190,7 @@ void Foam::fv::option::addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -185,7 +199,7 @@ void Foam::fv::option::addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -194,7 +208,7 @@ void Foam::fv::option::addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -203,7 +217,7 @@ void Foam::fv::option::addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -213,10 +227,10 @@ void Foam::fv::option::addSup const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const { - addSup(alpha*rho, eqn, fieldi); + addSup(alpha*rho, eqn, fieldName); } @@ -225,10 +239,10 @@ void Foam::fv::option::addSup const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const { - addSup(alpha*rho, eqn, fieldi); + addSup(alpha*rho, eqn, fieldName); } @@ -237,10 +251,10 @@ void Foam::fv::option::addSup const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const { - addSup(alpha*rho, eqn, fieldi); + addSup(alpha*rho, eqn, fieldName); } @@ -249,10 +263,10 @@ void Foam::fv::option::addSup const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const { - addSup(alpha*rho, eqn, fieldi); + addSup(alpha*rho, eqn, fieldName); } @@ -261,17 +275,17 @@ void Foam::fv::option::addSup const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const { - addSup(alpha*rho, eqn, fieldi); + addSup(alpha*rho, eqn, fieldName); } void Foam::fv::option::constrain ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -279,7 +293,7 @@ void Foam::fv::option::constrain void Foam::fv::option::constrain ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -287,7 +301,7 @@ void Foam::fv::option::constrain void Foam::fv::option::constrain ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} @@ -295,14 +309,15 @@ void Foam::fv::option::constrain void Foam::fv::option::constrain ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const {} void Foam::fv::option::constrain ( - fvMatrix& eqn, const label fieldi + fvMatrix& eqn, + const word& fieldName ) const {} diff --git a/src/finiteVolume/cfdTools/general/fvOptions/fvOption.H b/src/finiteVolume/cfdTools/general/fvOptions/fvOption.H index d9d65d5eb6..695aa17d0a 100644 --- a/src/finiteVolume/cfdTools/general/fvOptions/fvOption.H +++ b/src/finiteVolume/cfdTools/general/fvOptions/fvOption.H @@ -85,12 +85,6 @@ protected: //- Dictionary containing source coefficients dictionary coeffs_; - //- Field names to apply source to - populated by derived models - wordList fieldNames_; - - //- Applied flag list - corresponds to each fieldNames_ entry - mutable List applied_; - // Protected Member Functions @@ -235,17 +229,28 @@ public: //- Return dictionary inline const dictionary& coeffs() const; - //- Set the applied flag to true for field index fieldi - inline void setApplied(const label fieldi) const; - // Checks - //- Return index of field name if found in fieldNames list - virtual label applyToField(const word& fieldName) const; + //- Return the list of fields for which the option adds source term + // to the transport equation + virtual wordList addedToFields() const; - //- Check that the source has been applied - virtual void checkApplied() const; + //- Return the list of fields constrained by the option + virtual wordList constrainedFields() const; + + //- Return the list of fields corrected by the option + virtual wordList correctedFields() const; + + //- Return true if the option adds a source term to the given + // field's transport equation + virtual bool addsToField(const word& fieldName) const; + + //- Return true if the option constrains the given field + virtual bool constrainsField(const word& fieldName) const; + + //- Return true if the option corrects the given field + virtual bool correctsField(const word& fieldName) const; // Evaluation @@ -255,31 +260,31 @@ public: virtual void addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; @@ -289,35 +294,35 @@ public: ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup ( const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; @@ -328,7 +333,7 @@ public: const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup @@ -336,7 +341,7 @@ public: const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup @@ -344,7 +349,7 @@ public: const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup @@ -352,7 +357,7 @@ public: const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void addSup @@ -360,7 +365,7 @@ public: const volScalarField& alpha, const volScalarField& rho, fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; @@ -417,31 +422,31 @@ public: virtual void constrain ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void constrain ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void constrain ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void constrain ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; virtual void constrain ( fvMatrix& eqn, - const label fieldi + const word& fieldName ) const; diff --git a/src/finiteVolume/cfdTools/general/fvOptions/fvOptionI.H b/src/finiteVolume/cfdTools/general/fvOptions/fvOptionI.H index 54909787ba..f0431b644f 100644 --- a/src/finiteVolume/cfdTools/general/fvOptions/fvOptionI.H +++ b/src/finiteVolume/cfdTools/general/fvOptions/fvOptionI.H @@ -43,10 +43,4 @@ inline const Foam::dictionary& Foam::fv::option::coeffs() const } -inline void Foam::fv::option::setApplied(const label fieldi) const -{ - applied_[fieldi] = true; -} - - // ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/fvOptions/fvOptionList.C b/src/finiteVolume/cfdTools/general/fvOptions/fvOptionList.C index a76a8181ba..aa066d2ab8 100644 --- a/src/finiteVolume/cfdTools/general/fvOptions/fvOptionList.C +++ b/src/finiteVolume/cfdTools/general/fvOptions/fvOptionList.C @@ -59,7 +59,7 @@ bool Foam::fv::optionList::readOptions(const dictionary& dict) { const dictionary& optionsDict(this->optionsDict(dict)); - checkTimeIndex_ = mesh_.time().timeIndex() + 2; + checkTimeIndex_ = mesh_.time().timeIndex() + 1; bool allOk = true; forAll(*this, i) @@ -74,13 +74,44 @@ bool Foam::fv::optionList::readOptions(const dictionary& dict) void Foam::fv::optionList::checkApplied() const { - if (mesh_.time().timeIndex() == checkTimeIndex_) + if (mesh_.time().timeIndex() > checkTimeIndex_) { forAll(*this, i) { - const option& bs = this->operator[](i); - bs.checkApplied(); + const option& source = this->operator[](i); + + wordHashSet notAddedToFields(source.addedToFields()); + notAddedToFields -= addedToFields_[i]; + + forAllConstIter(wordHashSet, notAddedToFields, iter) + { + WarningInFunction + << "Source " << source.name() << " defined for field " + << iter.key() << " but never used" << endl; + } + + wordHashSet notConstrainedFields(source.constrainedFields()); + notConstrainedFields -= constrainedFields_[i]; + + forAllConstIter(wordHashSet, notConstrainedFields, iter) + { + WarningInFunction + << "Constraint " << source.name() << " defined for field " + << iter.key() << " but never used" << endl; + } + + wordHashSet notCorrectedFields(source.correctedFields()); + notCorrectedFields -= correctedFields_[i]; + + forAllConstIter(wordHashSet, notCorrectedFields, iter) + { + WarningInFunction + << "Correction " << source.name() << " defined for field " + << iter.key() << " but never used" << endl; + } } + + checkTimeIndex_ = mesh_.time().timeIndex(); } } @@ -91,7 +122,10 @@ Foam::fv::optionList::optionList(const fvMesh& mesh, const dictionary& dict) : PtrListDictionary