From 73a594cbcee9feeffcb33856ec96b8bc2ae1c15a Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Thu, 30 Apr 2020 14:08:44 +0100 Subject: [PATCH] nonUniformTableThermophysicalFunction: New non-uniform table thermophysicalFunction for liquid properties Description Non-uniform tabulated property function that linearly interpolates between the values. To speed-up the search of the non-uniform table a uniform jump-table is created on construction which is used for fast indirect addressing into the table. Usage \nonUniformTable Property | Description values | List of (temperature property) value pairs \endnonUniformTable Example for the density of water between 280 and 350K \verbatim rho { type nonUniformTable; values ( (280 999.87) (300 995.1) (350 973.7) ); } \endverbatim --- applications/test/nonUniformTable/Make/files | 3 + .../test/nonUniformTable/Make/options | 5 + .../nonUniformTable/Test-nonUniformTable.C | 72 +++++++++ applications/test/nonUniformTable/thermoDict | 13 ++ .../thermophysicalProperties/Make/files | 1 + .../nonUniformTableThermophysicalFunction.C | 140 ++++++++++++++++++ .../nonUniformTableThermophysicalFunction.H | 136 +++++++++++++++++ .../table/tableThermophysicalFunction.H | 6 +- 8 files changed, 372 insertions(+), 4 deletions(-) create mode 100644 applications/test/nonUniformTable/Make/files create mode 100644 applications/test/nonUniformTable/Make/options create mode 100644 applications/test/nonUniformTable/Test-nonUniformTable.C create mode 100644 applications/test/nonUniformTable/thermoDict create mode 100644 src/thermophysicalModels/thermophysicalProperties/thermophysicalFunctions/nonUniformTable/nonUniformTableThermophysicalFunction.C create mode 100644 src/thermophysicalModels/thermophysicalProperties/thermophysicalFunctions/nonUniformTable/nonUniformTableThermophysicalFunction.H diff --git a/applications/test/nonUniformTable/Make/files b/applications/test/nonUniformTable/Make/files new file mode 100644 index 0000000000..f7fd5f713c --- /dev/null +++ b/applications/test/nonUniformTable/Make/files @@ -0,0 +1,3 @@ +Test-nonUniformTable.C + +EXE = $(FOAM_USER_APPBIN)/Test-nonUniformTable diff --git a/applications/test/nonUniformTable/Make/options b/applications/test/nonUniformTable/Make/options new file mode 100644 index 0000000000..3ed9829402 --- /dev/null +++ b/applications/test/nonUniformTable/Make/options @@ -0,0 +1,5 @@ +EXE_INC = \ + -I$(LIB_SRC)/thermophysicalModels/thermophysicalProperties/lnInclude + +EXE_LIBS = \ + -lthermophysicalProperties diff --git a/applications/test/nonUniformTable/Test-nonUniformTable.C b/applications/test/nonUniformTable/Test-nonUniformTable.C new file mode 100644 index 0000000000..81d277c141 --- /dev/null +++ b/applications/test/nonUniformTable/Test-nonUniformTable.C @@ -0,0 +1,72 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 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 . + +Application + Test-nonUniformTable + +Description + Tests the lookup of values of a linear function from and non-uniform + table and reports any error. + +\*---------------------------------------------------------------------------*/ + +#include "nonUniformTableThermophysicalFunction.H" +#include "IFstream.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + dictionary dict(IFstream("thermoDict")()); + + thermophysicalFunctions::nonUniformTable table(dict); + + const label n = 1000; + const scalar T0 = table.values().first().first(); + const scalar Tn = table.values().last().first(); + const scalar deltaT = (Tn - T0)/n; + + for (int i = 0; i small) + { + FatalError<< "failed" << exit(FatalError) << endl; + } + } + + Info<< "\nLookup of a linear function from a non-uniform table is correct\n" + << endl; + + Info<< "\nEnd\n" << endl; + + return 0; +} + + +// ************************************************************************* // diff --git a/applications/test/nonUniformTable/thermoDict b/applications/test/nonUniformTable/thermoDict new file mode 100644 index 0000000000..f38941883b --- /dev/null +++ b/applications/test/nonUniformTable/thermoDict @@ -0,0 +1,13 @@ +values +( + (0 0) + (0.1 0.1) + (0.21 0.21) + (0.33 0.33) + (0.5 0.5) + (0.61 0.61) + (0.73 0.73) + (0.8 0.8) + (0.98 0.98) + (1 1) +); diff --git a/src/thermophysicalModels/thermophysicalProperties/Make/files b/src/thermophysicalModels/thermophysicalProperties/Make/files index 165904dab1..c944116b63 100644 --- a/src/thermophysicalModels/thermophysicalProperties/Make/files +++ b/src/thermophysicalModels/thermophysicalProperties/Make/files @@ -3,6 +3,7 @@ thermophysicalFunctions/thermophysicalFunction/thermophysicalFunction.C thermophysicalFunctions/none/noneThermophysicalFunction.C thermophysicalFunctions/constant/constantThermophysicalFunction.C thermophysicalFunctions/table/tableThermophysicalFunction.C +thermophysicalFunctions/nonUniformTable/nonUniformTableThermophysicalFunction.C thermophysicalFunctions/APIfunctions/APIdiffCoef/APIdiffCoefThermophysicalFunction.C NSRDS = thermophysicalFunctions/NSRDS diff --git a/src/thermophysicalModels/thermophysicalProperties/thermophysicalFunctions/nonUniformTable/nonUniformTableThermophysicalFunction.C b/src/thermophysicalModels/thermophysicalProperties/thermophysicalFunctions/nonUniformTable/nonUniformTableThermophysicalFunction.C new file mode 100644 index 0000000000..591e592132 --- /dev/null +++ b/src/thermophysicalModels/thermophysicalProperties/thermophysicalFunctions/nonUniformTable/nonUniformTableThermophysicalFunction.C @@ -0,0 +1,140 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 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 "nonUniformTableThermophysicalFunction.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace thermophysicalFunctions +{ + defineTypeNameAndDebug(nonUniformTable, 0); + + addToRunTimeSelectionTable + ( + thermophysicalFunction, + nonUniformTable, + dictionary + ); +} +} + +template<> +const char* const Foam::Tuple2::typeName +( + "Tuple2" +); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::thermophysicalFunctions::nonUniformTable::nonUniformTable +( + const dictionary& dict +) +: + dictName_(dict.name()), + Tlow_(great), + Thigh_(-great), + values_(dict.lookup("values")), + deltaT_(great) +{ + if (values_.size() < 2) + { + FatalErrorInFunction + << "Table " << nl + << " " << dictName_ << nl + << " has less than 2 entries." + << exit(FatalError); + } + else + { + Tlow_ = values_.first().first(); + Thigh_ = values_.last().first(); + + for(label i = 1; i values_[i + 1].first()) + { + i++; + } + + jumpTable_[j] = i; + } + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::scalar Foam::thermophysicalFunctions::nonUniformTable::f +( + scalar p, + scalar T +) const +{ + if (T < Tlow_ || T > Thigh_) + { + FatalErrorInFunction + << "Temperature " << T << " out of range " + << Tlow_ << " to " << Thigh_ << nl + << " of nonUniformTable " << dictName_ + << exit(FatalError); + } + + const scalar nd = (T - Tlow_)/deltaT_; + const label j = nd; + const label i = jumpTable_[j]; + + const scalar Ti = values_[i].first(); + const scalar lambda = (T - Ti)/(values_[i + 1].first() - Ti); + + return + values_[i].second() + + lambda*(values_[i + 1].second() - values_[i].second()); +} + + +void Foam::thermophysicalFunctions::nonUniformTable::write(Ostream& os) const +{ + writeEntry(os, "values", values_); +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/thermophysicalProperties/thermophysicalFunctions/nonUniformTable/nonUniformTableThermophysicalFunction.H b/src/thermophysicalModels/thermophysicalProperties/thermophysicalFunctions/nonUniformTable/nonUniformTableThermophysicalFunction.H new file mode 100644 index 0000000000..b229ed215d --- /dev/null +++ b/src/thermophysicalModels/thermophysicalProperties/thermophysicalFunctions/nonUniformTable/nonUniformTableThermophysicalFunction.H @@ -0,0 +1,136 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 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 . + +Class + Foam::thermophysicalFunctions::nonUniformTable + +Description + Non-uniform tabulated property function that linearly interpolates between + the values. + + To speed-up the search of the non-uniform table a uniform jump-table is + created on construction which is used for fast indirect addressing into + the table. + +Usage + \nonUniformTable + Property | Description + values | List of (temperature property) value pairs + \endnonUniformTable + + Example for the density of water between 280 and 350K + \verbatim + rho + { + type nonUniformTable; + + values + ( + (280 999.87) + (300 995.1) + (350 973.7) + ); + } + \endverbatim + +\*---------------------------------------------------------------------------*/ + +#ifndef nonUniformTableThermophysicalFunction_H +#define nonUniformTableThermophysicalFunction_H + +#include "thermophysicalFunction.H" +#include "Tuple2.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace thermophysicalFunctions +{ + +/*---------------------------------------------------------------------------*\ + Class nonUniformTable Declaration +\*---------------------------------------------------------------------------*/ + +class nonUniformTable +: + public thermophysicalFunction +{ + // Private member data + + //- Name of dictionary from which this function is instantiated + fileName dictName_; + + //- Lowest temperature in the nonUniformTable + scalar Tlow_; + + //- Highest temperature in the nonUniformTable + scalar Thigh_; + + //- Table values + List> values_; + + //- Temperature increment derived from Tlow_, Thigh_ and values_.size() + scalar deltaT_; + + List