Commit 2e2bfd23 authored by Henry Weller's avatar Henry Weller
Browse files

Function1: Rationalized construction to support the simpler sub-dictionary format

e.g.
    ramp
    {
        type     quadratic;
        start    200;
        duration 1.6;
    }

but the old format is supported for backward compatibility:

    ramp linear;
    rampCoeffs
    {
        start    200;
        duration 1.6;
    }
parent b1199f65
......@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
#include "createFields.H"
Info<< "Reading data file" << endl;
Function1Types::CSV<scalar> pData("pressure", dict, "Data");
Function1Types::CSV<scalar> pData("pressure", dict.subDict("pressureData"));
// time history data
const scalarField t(pData.x());
......
......@@ -203,18 +203,16 @@ template<class Type>
Foam::Function1Types::CSV<Type>::CSV
(
const word& entryName,
const dictionary& dict,
const word& ext
const dictionary& dict
)
:
TableBase<Type>(entryName, dict.subDict(entryName + ext)),
coeffs_(dict.subDict(entryName + ext)),
nHeaderLine_(readLabel(coeffs_.lookup("nHeaderLine"))),
refColumn_(readLabel(coeffs_.lookup("refColumn"))),
componentColumns_(coeffs_.lookup("componentColumns")),
separator_(coeffs_.lookupOrDefault<string>("separator", string(","))[0]),
mergeSeparators_(readBool(coeffs_.lookup("mergeSeparators"))),
fName_(coeffs_.lookup("file"))
TableBase<Type>(entryName, dict),
nHeaderLine_(readLabel(dict.lookup("nHeaderLine"))),
refColumn_(readLabel(dict.lookup("refColumn"))),
componentColumns_(dict.lookup("componentColumns")),
separator_(dict.lookupOrDefault<string>("separator", string(","))[0]),
mergeSeparators_(readBool(dict.lookup("mergeSeparators"))),
fName_(dict.lookup("file"))
{
if (componentColumns_.size() != pTraits<Type>::nComponents)
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,9 +25,11 @@ Class
Foam::Function1Types::CSV
Description
Templated CSV container data entry. Reference column is always a scalar,
e.g. time
Templated CSV function.
Reference column is always a scalar, e.g. time.
Usage:
\verbatim
<entryName> csvFile;
<entryName>Coeffs
......@@ -75,9 +77,6 @@ class CSV
{
// Private data
//- Coefficients dictionary (for convenience on reading)
dictionary coeffs_;
//- Number header lines
label nHeaderLine_;
......@@ -121,8 +120,7 @@ public:
CSV
(
const word& entryName,
const dictionary& dict,
const word& ext = "Coeffs"
const dictionary& dict
);
//- Copy constructor
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,9 +25,9 @@ Class
Foam::Function1Types::Constant
Description
Templated basic entry that holds a constant value.
Templated function that returns a constant value.
Usage - for entry \<entryName\> having the value <value>:
Usage - for entry \<entryName\> returning the value <value>:
\verbatim
<entryName> constant <value>
\endverbatim
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -195,6 +195,14 @@ public:
add##SS##Type##ConstructorToTable_;
#define makeScalarFunction1(SS) \
\
defineTypeNameAndDebug(SS, 0); \
\
Function1<scalar>::adddictionaryConstructorToTable<SS> \
add##SS##ConstructorToTable_;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -34,39 +34,70 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
const dictionary& dict
)
{
Istream& is(dict.lookup(entryName, false));
if (dict.isDict(entryName))
{
const dictionary& coeffsDict(dict.subDict(entryName));
token firstToken(is);
word Function1Type;
const word Function1Type(coeffsDict.lookup("type"));
if (!firstToken.isWord())
{
is.putBack(firstToken);
return autoPtr<Function1<Type>>
(
new Function1Types::Constant<Type>(entryName, is)
);
typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(Function1Type);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown Function1 type "
<< Function1Type << " for Function1 "
<< entryName << nl << nl
<< "Valid Function1 types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalError);
}
return cstrIter()(entryName, coeffsDict);
}
else
{
Function1Type = firstToken.wordToken();
}
Istream& is(dict.lookup(entryName, false));
typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(Function1Type);
token firstToken(is);
word Function1Type;
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown Function1 type "
<< Function1Type << " for Function1 "
<< entryName << nl << nl
<< "Valid Function1 types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalError);
}
if (!firstToken.isWord())
{
is.putBack(firstToken);
return autoPtr<Function1<Type>>
(
new Function1Types::Constant<Type>(entryName, is)
);
}
else
{
Function1Type = firstToken.wordToken();
}
typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(Function1Type);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown Function1 type "
<< Function1Type << " for Function1 "
<< entryName << nl << nl
<< "Valid Function1 types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalError);
}
return cstrIter()(entryName, dict);
return cstrIter()
(
entryName,
dict.found(entryName + "Coeffs")
? dict.subDict(entryName + "Coeffs")
: dict
);
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -43,13 +43,12 @@ template<class Type>
Foam::Function1Types::Sine<Type>::Sine
(
const word& entryName,
const dictionary& dict,
const word& ext
const dictionary& dict
)
:
Function1<Type>(entryName)
{
read(dict.subDict(entryName + ext));
read(dict);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -132,8 +132,7 @@ public:
Sine
(
const word& entryName,
const dictionary& dict,
const word& ext = "Coeffs"
const dictionary& dict
);
//- Copy constructor
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -43,13 +43,12 @@ template<class Type>
Foam::Function1Types::Square<Type>::Square
(
const word& entryName,
const dictionary& dict,
const word& ext
const dictionary& dict
)
:
Function1<Type>(entryName)
{
read(dict.subDict(entryName + ext));
read(dict);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -139,8 +139,7 @@ public:
Square
(
const word& entryName,
const dictionary& dict,
const word& ext = "Coeffs"
const dictionary& dict
);
//- Copy constructor
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,10 +25,12 @@ Class
Foam::Function1Types::Table
Description
Templated table container data entry. Items are stored in a list of
Tuple2's. First column is always stored as scalar entries. Data is read
in Tuple2 form, e.g. for an entry \<entryName\> that is (scalar, vector):
Templated table container function.
Items are stored in a list of Tuple2's. First column is always stored as
scalar entries. Data is read in Tuple2 form.
Usage:
\verbatim
<entryName> table
(
......
......@@ -34,11 +34,10 @@ Foam::Function1Types::TableFile<Type>::TableFile
const dictionary& dict
)
:
TableBase<Type>(entryName, dict.subDict(entryName + "Coeffs")),
TableBase<Type>(entryName, dict),
fName_("none")
{
const dictionary coeffs(dict.subDict(entryName + "Coeffs"));
coeffs.lookup("file") >> fName_;
dict.lookup("file") >> fName_;
fileName expandedFile(fName_);
IFstream is(expandedFile.expand());
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,8 +25,9 @@ Class
Foam::Function1Types::TableFile
Description
Templated table container data entry where data is read from file.
Templated table container function where data is read from file.
Usage:
\verbatim
<entryName> tableFile;
<entryName>Coeffs
......@@ -37,7 +38,7 @@ Description
}
\endverbatim
Items are stored in a list of Tuple2's. First column is always stored as
Data is stored as a list of Tuple2's. First column is always stored as
scalar entries. Data is read in the form, e.g. for an entry \<entryName\>
that is (scalar, vector):
\verbatim
......@@ -47,7 +48,6 @@ Description
);
\endverbatim
SourceFiles
TableFile.C
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -24,6 +24,8 @@ License
\*---------------------------------------------------------------------------*/
#include "Constant.H"
#include "ZeroConstant.H"
#include "OneConstant.H"
#include "PolynomialEntry.H"
#include "Sine.H"
#include "Square.H"
......@@ -38,6 +40,8 @@ License
#define makeFunction1s(Type) \
makeFunction1(Type); \
makeFunction1Type(Constant, Type); \
makeFunction1Type(ZeroConstant, Type); \
makeFunction1Type(OneConstant, Type); \
makeFunction1Type(Polynomial, Type); \
makeFunction1Type(Sine, Type); \
makeFunction1Type(Square, Type); \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment