From 01c758b79a9f62bc8bdbe9844664f73278df76eb Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Thu, 16 Mar 2017 20:53:08 +0000 Subject: [PATCH] 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; } --- .../utilities/postProcessing/noise/noise.C | 2 +- .../primitives/functions/Function1/CSV/CSV.C | 18 ++-- .../primitives/functions/Function1/CSV/CSV.H | 14 ++- .../functions/Function1/Constant/Constant.H | 6 +- .../functions/Function1/Function1/Function1.H | 10 ++- .../Function1/Function1/Function1New.C | 89 +++++++++++++------ .../functions/Function1/One/OneConstant.H | 2 +- .../functions/Function1/Sine/Sine.C | 7 +- .../functions/Function1/Sine/Sine.H | 5 +- .../functions/Function1/Square/Square.C | 7 +- .../functions/Function1/Square/Square.H | 5 +- .../functions/Function1/Table/Table.H | 10 ++- .../functions/Function1/TableFile/TableFile.C | 5 +- .../functions/Function1/TableFile/TableFile.H | 8 +- .../functions/Function1/Zero/ZeroConstant.H | 2 +- .../functions/Function1/makeDataEntries.C | 6 +- 16 files changed, 116 insertions(+), 80 deletions(-) diff --git a/applications/utilities/postProcessing/noise/noise.C b/applications/utilities/postProcessing/noise/noise.C index 7230e0cd04..700cb5b249 100644 --- a/applications/utilities/postProcessing/noise/noise.C +++ b/applications/utilities/postProcessing/noise/noise.C @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) #include "createFields.H" Info<< "Reading data file" << endl; - Function1Types::CSV pData("pressure", dict, "Data"); + Function1Types::CSV pData("pressure", dict.subDict("pressureData")); // time history data const scalarField t(pData.x()); diff --git a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C index 258d4aca77..d494090b3c 100644 --- a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C +++ b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C @@ -203,18 +203,16 @@ template Foam::Function1Types::CSV::CSV ( const word& entryName, - const dictionary& dict, - const word& ext + const dictionary& dict ) : - TableBase(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("separator", string(","))[0]), - mergeSeparators_(readBool(coeffs_.lookup("mergeSeparators"))), - fName_(coeffs_.lookup("file")) + TableBase(entryName, dict), + nHeaderLine_(readLabel(dict.lookup("nHeaderLine"))), + refColumn_(readLabel(dict.lookup("refColumn"))), + componentColumns_(dict.lookup("componentColumns")), + separator_(dict.lookupOrDefault("separator", string(","))[0]), + mergeSeparators_(readBool(dict.lookup("mergeSeparators"))), + fName_(dict.lookup("file")) { if (componentColumns_.size() != pTraits::nComponents) { diff --git a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.H b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.H index 97e0047a2b..4790b0be19 100644 --- a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.H +++ b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.H @@ -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 csvFile; 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 diff --git a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H index ddfbcdf84b..3ccbc5224b 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H +++ b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H @@ -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 \ having the value : + Usage - for entry \ returning the value : \verbatim constant \endverbatim diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H index fb71134add..c75f128cec 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H @@ -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::adddictionaryConstructorToTable \ + add##SS##ConstructorToTable_; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C index 81d4565401..604370ff3d 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.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) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -34,39 +34,70 @@ Foam::autoPtr> Foam::Function1::New const dictionary& dict ) { - Istream& is(dict.lookup(entryName, false)); - - token firstToken(is); - word Function1Type; - - if (!firstToken.isWord()) + if (dict.isDict(entryName)) { - is.putBack(firstToken); - return autoPtr> - ( - new Function1Types::Constant(entryName, is) - ); + const dictionary& coeffsDict(dict.subDict(entryName)); + + const word Function1Type(coeffsDict.lookup("type")); + + 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)); + + token firstToken(is); + word Function1Type; + + if (!firstToken.isWord()) + { + is.putBack(firstToken); + return autoPtr> + ( + new Function1Types::Constant(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.found(entryName + "Coeffs") + ? dict.subDict(entryName + "Coeffs") + : dict + ); } - - 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); } diff --git a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H index ba2f796dc3..60ec52c3e4 100644 --- a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H +++ b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C index 6031096643..762492b03b 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C +++ b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C @@ -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 Foam::Function1Types::Sine::Sine ( const word& entryName, - const dictionary& dict, - const word& ext + const dictionary& dict ) : Function1(entryName) { - read(dict.subDict(entryName + ext)); + read(dict); } diff --git a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H index 66c9f11058..d18291862f 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H +++ b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C index 213e768321..2a397260d2 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C +++ b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C @@ -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 Foam::Function1Types::Square::Square ( const word& entryName, - const dictionary& dict, - const word& ext + const dictionary& dict ) : Function1(entryName) { - read(dict.subDict(entryName + ext)); + read(dict); } diff --git a/src/OpenFOAM/primitives/functions/Function1/Square/Square.H b/src/OpenFOAM/primitives/functions/Function1/Square/Square.H index 9ca2079c00..df6ec25deb 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Square/Square.H +++ b/src/OpenFOAM/primitives/functions/Function1/Square/Square.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/Table.H b/src/OpenFOAM/primitives/functions/Function1/Table/Table.H index c11eb621db..5d50acca48 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/Table.H +++ b/src/OpenFOAM/primitives/functions/Function1/Table/Table.H @@ -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 \ 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 table ( diff --git a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C index 3e2645b9c2..aa86056cb3 100644 --- a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C +++ b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.C @@ -34,11 +34,10 @@ Foam::Function1Types::TableFile::TableFile const dictionary& dict ) : - TableBase(entryName, dict.subDict(entryName + "Coeffs")), + TableBase(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()); diff --git a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.H b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.H index a44ba48d7f..d4973639bf 100644 --- a/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.H +++ b/src/OpenFOAM/primitives/functions/Function1/TableFile/TableFile.H @@ -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 tableFile; 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 \ that is (scalar, vector): \verbatim @@ -47,7 +48,6 @@ Description ); \endverbatim - SourceFiles TableFile.C diff --git a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H index 804bd2f00f..7d486150bc 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H +++ b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H @@ -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 diff --git a/src/OpenFOAM/primitives/functions/Function1/makeDataEntries.C b/src/OpenFOAM/primitives/functions/Function1/makeDataEntries.C index babb5bad63..6c8db2ed8a 100644 --- a/src/OpenFOAM/primitives/functions/Function1/makeDataEntries.C +++ b/src/OpenFOAM/primitives/functions/Function1/makeDataEntries.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) 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); \