From 95b5ef4458505f0049798d4c0bb809a3f1760bbc Mon Sep 17 00:00:00 2001 From: Jakub Knir Date: Wed, 1 Apr 2020 18:53:09 +0100 Subject: [PATCH] fvOptions::SemiImplicitSource: Added support for Function1 specifications of the explicit and implicit sources This significant improvement is flexibility of SemiImplicitSource required a generalisation of the source specification syntax and all tutorials have been updated accordingly. Description Semi-implicit source, described using an input dictionary. The injection rate coefficients are specified as pairs of Su-Sp coefficients, i.e. \f[ S(x) = S_u + S_p x \f] where \vartable S(x) | net source for field 'x' S_u | explicit source contribution S_p | linearised implicit contribution \endvartable Example tabulated heat source specification for internal energy: \verbatim volumeMode absolute; // specific sources { e { explicit table ((0 0) (1.5 $power)); implicit 0; } } \endverbatim Example coded heat source specification for enthalpy: \verbatim volumeMode absolute; // specific sources { h { explicit { type coded; name heatInjection; code #{ // Power amplitude const scalar powerAmplitude = 1000; // x is the current time return mag(powerAmplitude*sin(x)); #}; } implicit 0; } } \endverbatim --- .../semiImplicitSource/SemiImplicitSource.C | 39 ++++++-- .../semiImplicitSource/SemiImplicitSource.H | 99 +++++++++---------- .../semiImplicitSource/SemiImplicitSourceI.H | 62 ------------ .../semiImplicitSource/SemiImplicitSourceIO.C | 47 --------- .../templates/system/solid/fvOptions | 15 ++- .../heatedDuct/constant/heater/fvOptions | 8 +- .../reverseBurner/constant/gas/fvOptions | 8 +- .../planarPoiseuille/constant/fvOptions | 9 +- .../validation/WatersKing/createFields.H | 5 +- .../planarPoiseuille/validation/createGraph | 4 +- .../filter/constant/fvOptions | 51 +++++----- .../laminar/bed/constant/fvOptions | 9 +- .../laminar/injection/constant/fvOptions | 37 +++---- .../laminar/steamInjection/constant/fvOptions | 37 +++---- .../laminar/injection/constant/fvOptions | 37 +++---- 15 files changed, 203 insertions(+), 264 deletions(-) delete mode 100644 src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSourceI.H delete mode 100644 src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSourceIO.C diff --git a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.C b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.C index ad1b7bfba4..49c7cf3cff 100644 --- a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.C +++ b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -83,8 +83,9 @@ Foam::word Foam::fv::SemiImplicitSource::volumeModeTypeToWord template void Foam::fv::SemiImplicitSource::setFieldData(const dictionary& dict) { - fieldNames_.setSize(dict.toc().size()); - injectionRate_.setSize(fieldNames_.size()); + fieldNames_.setSize(dict.size()); + Su_.setSize(fieldNames_.size()); + Sp_.setSize(fieldNames_.size()); applied_.setSize(fieldNames_.size(), false); @@ -92,7 +93,9 @@ void Foam::fv::SemiImplicitSource::setFieldData(const dictionary& dict) forAllConstIter(dictionary, dict, iter) { fieldNames_[i] = iter().keyword(); - dict.lookup(iter().keyword()) >> injectionRate_[i]; + const dictionary& fieldSubDict(iter().dict()); + Su_.set(i, Function1::New("explicit", fieldSubDict)); + Sp_.set(i, Function1::New("implicit", fieldSubDict)); i++; } @@ -117,8 +120,7 @@ Foam::fv::SemiImplicitSource::SemiImplicitSource : cellSetOption(name, modelType, dict, mesh), volumeMode_(vmAbsolute), - VDash_(1.0), - injectionRate_() + VDash_(1) { read(dict); } @@ -139,6 +141,8 @@ void Foam::fv::SemiImplicitSource::addSup << ">::addSup for source " << name_ << endl; } + const scalar t = mesh_.time().value(); + const GeometricField& psi = eqn.psi(); typename GeometricField::Internal Su @@ -161,7 +165,7 @@ void Foam::fv::SemiImplicitSource::addSup false ); - UIndirectList(Su, cells_) = injectionRate_[fieldi].first()/VDash_; + UIndirectList(Su, cells_) = Su_[fieldi].value(t)/VDash_; volScalarField::Internal Sp ( @@ -178,12 +182,12 @@ void Foam::fv::SemiImplicitSource::addSup ( "zero", Su.dimensions()/psi.dimensions(), - 0.0 + 0 ), false ); - UIndirectList(Sp, cells_) = injectionRate_[fieldi].second()/VDash_; + UIndirectList(Sp, cells_) = Sp_[fieldi].value(t)/VDash_; eqn += Su + fvm::SuSp(Sp, psi); } @@ -207,4 +211,21 @@ void Foam::fv::SemiImplicitSource::addSup } +template +bool Foam::fv::SemiImplicitSource::read(const dictionary& dict) +{ + if (cellSetOption::read(dict)) + { + volumeMode_ = wordToVolumeModeType(coeffs_.lookup("volumeMode")); + setFieldData(coeffs_.subDict("sources")); + + return true; + } + else + { + return false; + } +} + + // ************************************************************************* // diff --git a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.H b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.H index beb4b2221a..e02a505052 100644 --- a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.H +++ b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,14 +39,41 @@ Description S_p | linearised implicit contribution \endvartable - Example of the source specification: - + Example tabulated heat source specification for internal energy: \verbatim volumeMode absolute; // specific - injectionRateSuSp + sources { - k (30.7 0); - epsilon (1.5 0); + e + { + explicit table ((0 0) (1.5 $power)); + implicit 0; + } + } + \endverbatim + + Example coded heat source specification for enthalpy: + \verbatim + volumeMode absolute; // specific + sources + { + h + { + explicit + { + type coded; + name heatInjection; + code + #{ + // Power amplitude + const scalar powerAmplitude = 1000; + + // x is the current time + return mag(powerAmplitude*sin(x)); + #}; + } + implicit 0; + } } \endverbatim @@ -65,8 +92,8 @@ SourceFiles #ifndef SemiImplicitSource_H #define SemiImplicitSource_H -#include "Tuple2.H" #include "cellSetOption.H" +#include "Function1.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -75,22 +102,6 @@ namespace Foam namespace fv { -// Forward declaration of classes - -template -class SemiImplicitSource; - - -// Forward declaration of friend functions - -template -Ostream& operator<< -( - Ostream&, - const SemiImplicitSource& -); - - /*---------------------------------------------------------------------------*\ Class SemiImplicitSource Declaration \*---------------------------------------------------------------------------*/ @@ -111,25 +122,28 @@ public: vmSpecific }; + +private: + + // Private member data + //- Word list of volume mode type names static const wordList volumeModeTypeNames_; - -protected: - - // Protected data - //- Volume mode volumeModeType volumeMode_; //- Volume normalisation scalar VDash_; - //- Source field values - List> injectionRate_; + //- Explicit source functions for the fields + PtrList> Su_; + + //- Implicit source functions for the fields + PtrList> Sp_; - // Protected functions + // Private member functions //- Helper function to convert from a word to a volumeModeType volumeModeType wordToVolumeModeType(const word& vtName) const; @@ -161,24 +175,6 @@ public: // Member Functions - // Access - - //- Return const access to the volume mode - inline const volumeModeType& volumeMode() const; - - //- Return const access to the source field values - inline const List>& injectionRate() const; - - - // Edit - - //- Return access to the volume mode - inline volumeModeType& volumeMode(); - - //- Return access to the source field values - inline List>& injectionRate(); - - // Evaluation //- Add explicit contribution to equation @@ -213,15 +209,10 @@ public: #ifdef NoRepository #include "SemiImplicitSource.C" - #include "SemiImplicitSourceIO.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "SemiImplicitSourceI.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSourceI.H b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSourceI.H deleted file mode 100644 index 611274aaee..0000000000 --- a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSourceI.H +++ /dev/null @@ -1,62 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-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 "SemiImplicitSource.H" - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -inline const typename Foam::fv::SemiImplicitSource::volumeModeType& -Foam::fv::SemiImplicitSource::volumeMode() const -{ - return volumeMode_; -} - - -template -inline const Foam::List>& -Foam::fv::SemiImplicitSource::injectionRate() const -{ - return injectionRate_; -} - - -template -inline typename Foam::fv::SemiImplicitSource::volumeModeType& -Foam::fv::SemiImplicitSource::volumeMode() -{ - return volumeMode_; -} - - -template -inline Foam::List>& Foam::fv::SemiImplicitSource::injectionRate() -{ - return injectionRate_; -} - - -// ************************************************************************* // diff --git a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSourceIO.C b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSourceIO.C deleted file mode 100644 index 9e0e9ad684..0000000000 --- a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSourceIO.C +++ /dev/null @@ -1,47 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-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 "SemiImplicitSource.H" - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -bool Foam::fv::SemiImplicitSource::read(const dictionary& dict) -{ - if (cellSetOption::read(dict)) - { - volumeMode_ = wordToVolumeModeType(coeffs_.lookup("volumeMode")); - setFieldData(coeffs_.subDict("injectionRateSuSp")); - - return true; - } - else - { - return false; - } -} - - -// ************************************************************************* // diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/coolingSphere/templates/system/solid/fvOptions b/tutorials/heatTransfer/chtMultiRegionFoam/coolingSphere/templates/system/solid/fvOptions index 94e9ae6528..542f61bda7 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/coolingSphere/templates/system/solid/fvOptions +++ b/tutorials/heatTransfer/chtMultiRegionFoam/coolingSphere/templates/system/solid/fvOptions @@ -35,10 +35,19 @@ fixedPower power 100; // Set power (W) - injectionRateSuSp + sources { - e ($power 0); - h ($power 0); + e + { + explicit $power; + implicit 0; + } + + h + { + explicit $power; + implicit 0; + } } } diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/heatedDuct/constant/heater/fvOptions b/tutorials/heatTransfer/chtMultiRegionFoam/heatedDuct/constant/heater/fvOptions index 54a54bce37..104f6b1d82 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/heatedDuct/constant/heater/fvOptions +++ b/tutorials/heatTransfer/chtMultiRegionFoam/heatedDuct/constant/heater/fvOptions @@ -26,9 +26,13 @@ options selectionMode all; volumeMode specific; - injectionRateSuSp + sources { - h (1e7 0); // W/m^3 == kg/m/s^3 + h + { + explicit 1e7; // W/m^3 == kg/m/s^3 + implicit 0; + } } } } diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/reverseBurner/constant/gas/fvOptions b/tutorials/heatTransfer/chtMultiRegionFoam/reverseBurner/constant/gas/fvOptions index f7431bd34c..d331546156 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/reverseBurner/constant/gas/fvOptions +++ b/tutorials/heatTransfer/chtMultiRegionFoam/reverseBurner/constant/gas/fvOptions @@ -27,9 +27,13 @@ options cellSet ignition; volumeMode specific; - injectionRateSuSp + sources { - e (5e7 0); // kg/m/s^3 + e + { + explicit 5e7; // kg/m/s^3 + implicit 0; + } } } } diff --git a/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/constant/fvOptions b/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/constant/fvOptions index 75b3a20b62..892c7636f5 100644 --- a/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/constant/fvOptions +++ b/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/constant/fvOptions @@ -24,9 +24,14 @@ momentumSource selectionMode all; volumeMode specific; - injectionRateSuSp + + sources { - U ((5 0 0) 0); + U + { + explicit (5 0 0); + implicit 0; + } } } diff --git a/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/validation/WatersKing/createFields.H b/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/validation/WatersKing/createFields.H index a78ef93926..0bdc85c920 100644 --- a/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/validation/WatersKing/createFields.H +++ b/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/validation/WatersKing/createFields.H @@ -50,9 +50,8 @@ IOdictionary fvOptions ) ); const dictionary& gradPDict = - fvOptions.subDict("momentumSource").subDict("injectionRateSuSp"); -const scalar K = - Tuple2(gradPDict.lookup("U")).first().x(); + fvOptions.subDict("momentumSource").subDict("sources"); +const scalar K(vector(gradPDict.subDict("U").lookup("explicit")).x()); dictionary probes(IFstream(runTime.system()/"probes")()); const point location = pointField(probes.lookup("probeLocations"))[0]; diff --git a/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/validation/createGraph b/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/validation/createGraph index a30402600e..53fee36479 100755 --- a/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/validation/createGraph +++ b/tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille/validation/createGraph @@ -1,7 +1,7 @@ #!/bin/sh tail -n +4 ../postProcessing/probes/0/U | \ - tr -s " " | tr -d '(' | cut -d " " -f2-3 > ../Numerical.dat + tr -s " " | tr -d '(' | cut -d " " -f1-2 > ../Numerical.dat if ! which gnuplot > /dev/null 2>&1 then @@ -24,4 +24,4 @@ gnuplot<