From 32be464010fbea21b7f21ac25e710c8bd1040403 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Fri, 18 Mar 2022 17:21:39 +0000 Subject: [PATCH] fixedValueConstraint, fixedTemperatureConstraint: Permit applying only a fraction of the constraint An optional Function1 can now be supplied to a fixedValueConstraint which controls what proportion of the constraint is applied. This can be used to ramp, pulse, or limit the duration of the constraint. For example, ramping up of the constraint could be specified as follows: scalarSource { type fixedValueConstraint; selectionMode points; points ((0 0.1 0)); fieldValues { s 1; } fraction { type ramp; duration 0.1; } } --- .../multiphaseReactions/Make/options | 1 + .../solidDisplacementThermo/Make/options | 3 +- .../epsilonWallFunctionFvPatchScalarField.C | 4 +- .../omegaWallFunctionFvPatchScalarField.C | 4 +- .../fixedInternalValueFvPatchField.C | 4 +- src/finiteVolume/finiteVolume/fvm/fvmD2dt2.H | 5 +- src/finiteVolume/finiteVolume/fvm/fvmDdt.H | 5 +- src/finiteVolume/finiteVolume/fvm/fvmDiv.H | 5 +- .../finiteVolume/fvm/fvmLaplacian.H | 5 +- src/finiteVolume/finiteVolume/fvm/fvmSup.H | 5 +- .../fvMatrices/fvMatrix/fvMatrix.C | 210 ++++++++++++------ .../fvMatrices/fvMatrix/fvMatrix.H | 31 ++- .../fixedTemperatureConstraint.C | 46 +++- .../fixedTemperatureConstraint.H | 7 +- .../fixedValueConstraint.C | 26 ++- .../fixedValueConstraint.H | 5 + 16 files changed, 261 insertions(+), 105 deletions(-) diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseReactions/Make/options b/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseReactions/Make/options index 5b74862cbf..0e45b89ad9 100644 --- a/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseReactions/Make/options +++ b/applications/solvers/multiphase/multiphaseEulerFoam/multiphaseReactions/Make/options @@ -5,6 +5,7 @@ EXE_INC = \ -I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/chemistryModel/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ -I../phaseSystems/lnInclude LIB_LIBS = \ diff --git a/applications/solvers/stressAnalysis/solidDisplacementFoam/solidDisplacementThermo/Make/options b/applications/solvers/stressAnalysis/solidDisplacementFoam/solidDisplacementThermo/Make/options index 77fec2248a..39c0e03f4b 100644 --- a/applications/solvers/stressAnalysis/solidDisplacementFoam/solidDisplacementThermo/Make/options +++ b/applications/solvers/stressAnalysis/solidDisplacementFoam/solidDisplacementThermo/Make/options @@ -2,7 +2,8 @@ EXE_INC = \ -I$(LIB_SRC)/physicalProperties/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/solidThermo/lnInclude \ - -I$(LIB_SRC)/finiteVolume/lnInclude + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude LIB_LIBS = \ -lfiniteVolume \ diff --git a/src/MomentumTransportModels/momentumTransportModels/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C b/src/MomentumTransportModels/momentumTransportModels/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C index 0b3038d855..beae11d27f 100644 --- a/src/MomentumTransportModels/momentumTransportModels/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C +++ b/src/MomentumTransportModels/momentumTransportModels/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.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-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -461,7 +461,7 @@ void Foam::epsilonWallFunctionFvPatchScalarField::manipulateMatrix return; } - matrix.setValues(patch().faceCells(), patchInternalField()); + matrix.setValues(patch().faceCells(), patchInternalField()()); fvPatchField::manipulateMatrix(matrix); } diff --git a/src/MomentumTransportModels/momentumTransportModels/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C b/src/MomentumTransportModels/momentumTransportModels/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C index 7566dd7e54..cda7d30f26 100644 --- a/src/MomentumTransportModels/momentumTransportModels/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C +++ b/src/MomentumTransportModels/momentumTransportModels/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.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-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -500,7 +500,7 @@ void omegaWallFunctionFvPatchScalarField::manipulateMatrix return; } - matrix.setValues(patch().faceCells(), patchInternalField()); + matrix.setValues(patch().faceCells(), patchInternalField()()); fvPatchField::manipulateMatrix(matrix); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedInternalValue/fixedInternalValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedInternalValue/fixedInternalValueFvPatchField.C index 7806e8ec0b..54eb50386d 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedInternalValue/fixedInternalValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedInternalValue/fixedInternalValueFvPatchField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -85,7 +85,7 @@ void Foam::fixedInternalValueFvPatchField::manipulateMatrix ) { // Apply the patch internal field as a constraint in the matrix - matrix.setValues(this->patch().faceCells(), this->patchInternalField()); + matrix.setValues(this->patch().faceCells(), this->patchInternalField()()); } diff --git a/src/finiteVolume/finiteVolume/fvm/fvmD2dt2.H b/src/finiteVolume/finiteVolume/fvm/fvmD2dt2.H index f764518082..9f0f8a941b 100644 --- a/src/finiteVolume/finiteVolume/fvm/fvmD2dt2.H +++ b/src/finiteVolume/finiteVolume/fvm/fvmD2dt2.H @@ -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-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,13 +36,14 @@ SourceFiles #define fvmD2dt2_H #include "volFieldsFwd.H" -#include "fvMatrix.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +template class fvMatrix; + /*---------------------------------------------------------------------------*\ Namespace fvm functions Declaration \*---------------------------------------------------------------------------*/ diff --git a/src/finiteVolume/finiteVolume/fvm/fvmDdt.H b/src/finiteVolume/finiteVolume/fvm/fvmDdt.H index 97f01646a2..bb401726be 100644 --- a/src/finiteVolume/finiteVolume/fvm/fvmDdt.H +++ b/src/finiteVolume/finiteVolume/fvm/fvmDdt.H @@ -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-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,7 +36,6 @@ SourceFiles #define fvmDdt_H #include "volFieldsFwd.H" -#include "fvMatrix.H" #include "one.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -44,6 +43,8 @@ SourceFiles namespace Foam { +template class fvMatrix; + /*---------------------------------------------------------------------------*\ Namespace fvm functions Declaration \*---------------------------------------------------------------------------*/ diff --git a/src/finiteVolume/finiteVolume/fvm/fvmDiv.H b/src/finiteVolume/finiteVolume/fvm/fvmDiv.H index a00edcec88..ff0a099c21 100644 --- a/src/finiteVolume/finiteVolume/fvm/fvmDiv.H +++ b/src/finiteVolume/finiteVolume/fvm/fvmDiv.H @@ -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-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -38,13 +38,14 @@ SourceFiles #include "volFieldsFwd.H" #include "surfaceFieldsFwd.H" #include "surfaceInterpolationScheme.H" -#include "fvMatrix.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +template class fvMatrix; + /*---------------------------------------------------------------------------*\ Namespace fvm functions Declaration \*---------------------------------------------------------------------------*/ diff --git a/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.H b/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.H index 9dc573d7ba..e5652a7f4b 100644 --- a/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.H +++ b/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.H @@ -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-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -37,7 +37,6 @@ SourceFiles #include "volFieldsFwd.H" #include "surfaceFieldsFwd.H" -#include "fvMatrix.H" #include "zero.H" #include "one.H" @@ -46,6 +45,8 @@ SourceFiles namespace Foam { +template class fvMatrix; + /*---------------------------------------------------------------------------*\ Namespace fvm functions Declaration \*---------------------------------------------------------------------------*/ diff --git a/src/finiteVolume/finiteVolume/fvm/fvmSup.H b/src/finiteVolume/finiteVolume/fvm/fvmSup.H index 4086143bf4..02a6dabd15 100644 --- a/src/finiteVolume/finiteVolume/fvm/fvmSup.H +++ b/src/finiteVolume/finiteVolume/fvm/fvmSup.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,7 +36,6 @@ SourceFiles #define fvmSup_H #include "volFieldsFwd.H" -#include "fvMatrix.H" #include "zeroField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -44,6 +43,8 @@ SourceFiles namespace Foam { +template class fvMatrix; + /*---------------------------------------------------------------------------*\ Namespace fvm functions Declaration \*---------------------------------------------------------------------------*/ diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C index 18f09edb59..bac3e8517b 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.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-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,6 +29,7 @@ License #include "extrapolatedCalculatedFvPatchFields.H" #include "coupledFvPatchFields.H" #include "UIndirectList.H" +#include "fvmDdt.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -173,11 +174,10 @@ void Foam::fvMatrix::addBoundarySource template -template class ListType> -void Foam::fvMatrix::setValuesFromList +void Foam::fvMatrix::setValue ( - const labelUList& cellLabels, - const ListType& values + const label celli, + const Type& value ) { const fvMesh& mesh = psi_.mesh(); @@ -187,73 +187,66 @@ void Foam::fvMatrix::setValuesFromList const labelUList& nei = mesh.neighbour(); scalarField& Diag = diag(); + Field& psi = - const_cast - < - GeometricField& - >(psi_).primitiveFieldRef(); + const_cast&>(psi_) + .primitiveFieldRef(); - forAll(cellLabels, i) + psi[celli] = value; + source_[celli] = value*Diag[celli]; + + if (symmetric() || asymmetric()) { - const label celli = cellLabels[i]; - const Type& value = values[i]; + const cell& c = cells[celli]; - psi[celli] = value; - source_[celli] = value*Diag[celli]; - - if (symmetric() || asymmetric()) + forAll(c, j) { - const cell& c = cells[celli]; + const label facei = c[j]; - forAll(c, j) + if (mesh.isInternalFace(facei)) { - const label facei = c[j]; - - if (mesh.isInternalFace(facei)) + if (symmetric()) { - if (symmetric()) + if (celli == own[facei]) { - if (celli == own[facei]) - { - source_[nei[facei]] -= upper()[facei]*value; - } - else - { - source_[own[facei]] -= upper()[facei]*value; - } - - upper()[facei] = 0.0; + source_[nei[facei]] -= upper()[facei]*value; } else { - if (celli == own[facei]) - { - source_[nei[facei]] -= lower()[facei]*value; - } - else - { - source_[own[facei]] -= upper()[facei]*value; - } - - upper()[facei] = 0.0; - lower()[facei] = 0.0; + source_[own[facei]] -= upper()[facei]*value; } + + upper()[facei] = 0.0; } else { - label patchi = mesh.boundaryMesh().whichPatch(facei); - - if (internalCoeffs_[patchi].size()) + if (celli == own[facei]) { - label patchFacei = - mesh.boundaryMesh()[patchi].whichFace(facei); - - internalCoeffs_[patchi][patchFacei] = - Zero; - - boundaryCoeffs_[patchi][patchFacei] = - Zero; + source_[nei[facei]] -= lower()[facei]*value; } + else + { + source_[own[facei]] -= upper()[facei]*value; + } + + upper()[facei] = 0.0; + lower()[facei] = 0.0; + } + } + else + { + label patchi = mesh.boundaryMesh().whichPatch(facei); + + if (internalCoeffs_[patchi].size()) + { + label patchFacei = + mesh.boundaryMesh()[patchi].whichFace(facei); + + internalCoeffs_[patchi][patchFacei] = + Zero; + + boundaryCoeffs_[patchi][patchFacei] = + Zero; } } } @@ -261,6 +254,30 @@ void Foam::fvMatrix::setValuesFromList } +template +void Foam::fvMatrix::setValue +( + const label celli, + const Type& value, + const scalar fraction, + const scalarField& ddtDiag +) +{ + Field& psi = + const_cast&>(psi_) + .primitiveFieldRef(); + + psi[celli] = (1 - fraction)*psi[celli] + fraction*value; + + const scalar coeff = + fraction/(1 - fraction) + *(diag()[celli] - ddtDiag[celli]); + + diag()[celli] += coeff; + source()[celli] += coeff*value; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -480,24 +497,64 @@ Foam::fvMatrix::~fvMatrix() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template +template class ListType> void Foam::fvMatrix::setValues ( const labelUList& cellLabels, - const UList& values + const ListType& values ) { - this->setValuesFromList(cellLabels, values); + // Fix the values + forAll(cellLabels, i) + { + setValue(cellLabels[i], values[i]); + } } template +template class ListType> void Foam::fvMatrix::setValues ( const labelUList& cellLabels, - const UIndirectList& values + const ListType& values, + const scalarList& fractions, + const bool hasDdt ) { - this->setValuesFromList(cellLabels, values); + // Get the proportion of the diagonal associated with iterative update + scalarField ddtDiag(diag().size(), 0); + const scalar alpha = relaxationFactor(); + if (alpha > 0) + { + ddtDiag += (1 - alpha)*diag(); + } + if (hasDdt) + { + const fvMatrix ddtEqn(fvm::ddt(psi_)); + if (ddtEqn.hasDiag()) + { + ddtDiag += ddtEqn.diag(); + } + } + + forAll(cellLabels, i) + { + if (- rootSmall < fractions[i] && fractions[i] < rootSmall) + { + // Do nothing + } + else if (1 - rootSmall < fractions[i] && fractions[i] < 1 + rootSmall) + { + // Fix the values + setValue(cellLabels[i], values[i]); + } + else + { + // Fractionally fix the values + setValue(cellLabels[i], values[i], fractions[i], ddtDiag); + } + } } @@ -517,6 +574,29 @@ void Foam::fvMatrix::setReference } +template +Foam::scalar Foam::fvMatrix::relaxationFactor() const +{ + if + ( + psi_.mesh().data::template lookupOrDefault + ("finalIteration", false) + && psi_.mesh().relaxEquation(psi_.name() + "Final") + ) + { + return psi_.mesh().equationRelaxationFactor(psi_.name() + "Final"); + } + else if (psi_.mesh().relaxEquation(psi_.name())) + { + return psi_.mesh().equationRelaxationFactor(psi_.name()); + } + else + { + return 0; + } +} + + template void Foam::fvMatrix::relax(const scalar alpha) { @@ -671,19 +751,7 @@ void Foam::fvMatrix::relax(const scalar alpha) template void Foam::fvMatrix::relax() { - if - ( - psi_.mesh().data::template lookupOrDefault - ("finalIteration", false) - && psi_.mesh().relaxEquation(psi_.name() + "Final") - ) - { - relax(psi_.mesh().equationRelaxationFactor(psi_.name() + "Final")); - } - else if (psi_.mesh().relaxEquation(psi_.name())) - { - relax(psi_.mesh().equationRelaxationFactor(psi_.name())); - } + relax(relaxationFactor()); } diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H index 50042df0f5..824962d230 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H @@ -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-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -203,12 +203,20 @@ protected: // Matrix manipulation functionality - //- Set solution in given cells to the specified values - template class ListType> - void setValuesFromList + //- Set solution in the given cell to the specified value + void setValue ( - const labelUList& cells, - const ListType& values + const label celli, + const Type& value + ); + + //- Set solution in the given cell to the specified value + void setValue + ( + const label celli, + const Type& value, + const scalar fraction, + const scalarField& ddtDiag ); @@ -330,18 +338,22 @@ public: //- Set solution in given cells to the specified values // and eliminate the corresponding equations from the matrix. + template class ListType> void setValues ( const labelUList& cells, - const UList& values + const ListType& values ); //- Set solution in given cells to the specified values // and eliminate the corresponding equations from the matrix. + template class ListType> void setValues ( const labelUList& cells, - const UIndirectList& values + const ListType& values, + const scalarList& fractions, + const bool hasDdt = true ); //- Set reference level for solution @@ -362,6 +374,9 @@ public: const scalar value ); + //- Return the relaxation factor for this equation + scalar relaxationFactor() const; + //- Relax matrix (for steady-state solution). // alpha = 1 : diagonally equal // alpha < 1 : diagonally dominant diff --git a/src/fvConstraints/fixedTemperatureConstraint/fixedTemperatureConstraint.C b/src/fvConstraints/fixedTemperatureConstraint/fixedTemperatureConstraint.C index 70e33b6469..e8c3055fe5 100644 --- a/src/fvConstraints/fixedTemperatureConstraint/fixedTemperatureConstraint.C +++ b/src/fvConstraints/fixedTemperatureConstraint/fixedTemperatureConstraint.C @@ -81,6 +81,11 @@ void Foam::fv::fixedTemperatureConstraint::readCoeffs() } phaseName_ = coeffs().lookupOrDefault("phase", word::null); + + fraction_ = + coeffs().found("fraction") + ? Function1::New("fraction", coeffs()) + : autoPtr>(); } @@ -133,21 +138,52 @@ bool Foam::fv::fixedTemperatureConstraint::constrain IOobject::groupName(physicalProperties::typeName, phaseName_) ); + const scalar t = mesh().time().userTimeValue(); + switch (mode_) { case temperatureMode::uniform: { - const scalar t = mesh().time().userTimeValue(); - scalarField Tuni(cells.size(), TValue_->value(t)); - eqn.setValues(cells, thermo.he(Tuni, cells)); + const scalarField Tuni(cells.size(), TValue_->value(t)); + const scalarField heuni(thermo.he(Tuni, cells)); + + if (fraction_.valid()) + { + eqn.setValues + ( + cells, + heuni, + scalarList(cells.size(), fraction_->value(t)) + ); + } + else + { + eqn.setValues(cells, heuni); + } + break; } case temperatureMode::lookup: { const volScalarField& T = mesh().lookupObject(TName_); - scalarField Tlkp(T, cells); - eqn.setValues(cells, thermo.he(Tlkp, cells)); + const scalarField Tlkp(T, cells); + const scalarField helkp(thermo.he(Tlkp, cells)); + + if (fraction_.valid()) + { + eqn.setValues + ( + cells, + helkp, + scalarList(cells.size(), fraction_->value(t)) + ); + } + else + { + eqn.setValues(cells, helkp); + } + break; } } diff --git a/src/fvConstraints/fixedTemperatureConstraint/fixedTemperatureConstraint.H b/src/fvConstraints/fixedTemperatureConstraint/fixedTemperatureConstraint.H index 11a8f3d195..aebd1ebec1 100644 --- a/src/fvConstraints/fixedTemperatureConstraint/fixedTemperatureConstraint.H +++ b/src/fvConstraints/fixedTemperatureConstraint/fixedTemperatureConstraint.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -110,6 +110,11 @@ private: //- Optional phase name word phaseName_; + //- Fraction of the constraint to apply. Facilitates ramping, or + // pulsing, or deactivation after a time. Should take a value between + // 0 and 1. Defaults to 1 (i.e., apply all of the constraint). + autoPtr> fraction_; + // Private Member Functions diff --git a/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.C b/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.C index 6d2abacadc..1cd8e110a5 100644 --- a/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.C +++ b/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.C @@ -26,6 +26,7 @@ License #include "fixedValueConstraint.H" #include "fvMesh.H" #include "fvMatrices.H" +#include "fvcSurfaceIntegrate.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -63,6 +64,11 @@ void Foam::fv::fixedValueConstraint::readCoeffs() ) ); } + + fraction_ = + coeffs().found("fraction") + ? Function1::New("fraction", coeffs()) + : autoPtr>(); } @@ -75,12 +81,26 @@ bool Foam::fv::fixedValueConstraint::constrainType { const scalar t = mesh().time().userTimeValue(); - eqn.setValues + const List values ( - set_.cells(), - List(set_.cells().size(), fieldValues_[fieldName]->value(t)) + set_.cells().size(), + fieldValues_[fieldName]->value(t) ); + if (fraction_.valid()) + { + eqn.setValues + ( + set_.cells(), + values, + scalarList(set_.cells().size(), fraction_->value(t)) + ); + } + else + { + eqn.setValues(set_.cells(), values); + } + return set_.cells().size(); } diff --git a/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.H b/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.H index 999b748c47..2f0a700310 100644 --- a/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.H +++ b/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.H @@ -81,6 +81,11 @@ class fixedValueConstraint //- Field values HashPtrTable fieldValues_; + //- Fraction of the constraint to apply. Facilitates ramping, or + // pulsing, or deactivation after a time. Should take a value between + // 0 and 1. Defaults to 1 (i.e., apply all of the constraint). + autoPtr> fraction_; + // Private Member Functions