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
This commit is contained in:
Henry Weller
2020-04-30 14:08:44 +01:00
parent 62d1bcdb72
commit 73a594cbce
8 changed files with 372 additions and 4 deletions

View File

@ -0,0 +1,3 @@
Test-nonUniformTable.C
EXE = $(FOAM_USER_APPBIN)/Test-nonUniformTable

View File

@ -0,0 +1,5 @@
EXE_INC = \
-I$(LIB_SRC)/thermophysicalModels/thermophysicalProperties/lnInclude
EXE_LIBS = \
-lthermophysicalProperties

View File

@ -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 <http://www.gnu.org/licenses/>.
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<n + 1; i++)
{
const scalar T = T0 + i*deltaT;
const scalar f = table.f(0, T);
if (mag(T - f) > 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;
}
// ************************************************************************* //

View File

@ -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)
);

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "nonUniformTableThermophysicalFunction.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace thermophysicalFunctions
{
defineTypeNameAndDebug(nonUniformTable, 0);
addToRunTimeSelectionTable
(
thermophysicalFunction,
nonUniformTable,
dictionary
);
}
}
template<>
const char* const Foam::Tuple2<Foam::scalar, Foam::scalar>::typeName
(
"Tuple2<scalar,scalar>"
);
// * * * * * * * * * * * * * * * * 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_.size(); i++)
{
deltaT_ = min(deltaT_, values_[i].first() - values_[i - 1].first());
}
deltaT_ *= 0.9;
jumpTable_.setSize((Thigh_ - Tlow_)/deltaT_ + 1);
label i = 0;
forAll(jumpTable_, j)
{
const scalar T = Tlow_ + j*deltaT_;
if (T > 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_);
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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<Tuple2<scalar, scalar>> values_;
//- Temperature increment derived from Tlow_, Thigh_ and values_.size()
scalar deltaT_;
List<label> jumpTable_;
public:
//- Runtime type information
TypeName("nonUniformTable");
// Constructors
//- Construct from dictionary
nonUniformTable(const dictionary& dict);
// Member Functions
//- Return the non-uniform table of values
const List<Tuple2<scalar, scalar>>& values() const
{
return values_;
}
//- Evaluate the function and return the result
scalar f(scalar p, scalar T) const;
//- Write the function coefficients
void write(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace thermophysicalFunctions
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2019-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,7 +25,7 @@ Class
Foam::thermophysicalFunctions::table
Description
Tabulated property function the linearly interpolates between
Tabulated property function that linearly interpolates between
the table values.
Usage
@ -54,8 +54,6 @@ Usage
}
\endverbatim
\*---------------------------------------------------------------------------*/
#ifndef tableThermophysicalFunction_H