diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index f95dc85741bbcb8bb740606b61ea57a538c00f11..91781cff7c8659635fb4735ee8c6d91cdaa331a3 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -123,6 +123,7 @@ $(ranges)/labelRange/labelRange.C $(ranges)/labelRange/labelRanges.C $(ranges)/scalarRange/scalarRange.C $(ranges)/scalarRange/scalarRanges.C +$(ranges)/tableBounds/tableBounds.C spatialVectorAlgebra = primitives/spatialVectorAlgebra $(spatialVectorAlgebra)/SpatialVector/spatialVector/spatialVector.C diff --git a/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.C b/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.C index 01c0aaa9590a84ab3aea5dfaa18a27f0a75f7504..d4c4cca0d0b433d6fd937398dcd948c82014073a 100644 --- a/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.C +++ b/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.C @@ -55,7 +55,7 @@ template<class Type> Foam::interpolation2DTable<Type>::interpolation2DTable() : List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>(), - boundsHandling_(interpolation2DTable::WARN), + bounding_(bounds::normalBounding::WARN), fileName_("fileNameIsUndefined"), reader_(nullptr) {} @@ -65,12 +65,12 @@ template<class Type> Foam::interpolation2DTable<Type>::interpolation2DTable ( const List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>& values, - const boundsHandling bounds, + const bounds::normalBounding bounding, const fileName& fName ) : List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>(values), - boundsHandling_(bounds), + bounding_(bounding), fileName_(fName), reader_(nullptr) {} @@ -80,7 +80,7 @@ template<class Type> Foam::interpolation2DTable<Type>::interpolation2DTable(const fileName& fName) : List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>(), - boundsHandling_(interpolation2DTable::WARN), + bounding_(bounds::normalBounding::WARN), fileName_(fName), reader_(new openFoamTableReader<Type>(dictionary())) { @@ -92,7 +92,15 @@ template<class Type> Foam::interpolation2DTable<Type>::interpolation2DTable(const dictionary& dict) : List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>(), - boundsHandling_(wordToBoundsHandling(dict.lookup("outOfBounds"))), + bounding_ + ( + bounds::normalBoundingNames.lookupOrFailsafe + ( + "outOfBounds", + dict, + bounds::normalBounding::WARN + ) + ), fileName_(dict.lookup("file")), reader_(tableReader<Type>::New(dict)) { @@ -107,7 +115,7 @@ Foam::interpolation2DTable<Type>::interpolation2DTable ) : List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>(interpTable), - boundsHandling_(interpTable.boundsHandling_), + bounding_(interpTable.bounding_), fileName_(interpTable.fileName_), reader_(interpTable.reader_) // note: steals reader. Used in write(). {} @@ -130,9 +138,9 @@ Type Foam::interpolation2DTable<Type>::interpolateValue if (lookupValue < minLimit) { - switch (boundsHandling_) + switch (bounding_) { - case interpolation2DTable::ERROR: + case bounds::normalBounding::ERROR: { FatalErrorInFunction << "value (" << lookupValue << ") less than lower " @@ -140,18 +148,18 @@ Type Foam::interpolation2DTable<Type>::interpolateValue << exit(FatalError); break; } - case interpolation2DTable::WARN: + case bounds::normalBounding::WARN: { WarningInFunction << "value (" << lookupValue << ") less than lower " << "bound (" << minLimit << ")" << nl << " Continuing with the first entry" << endl; - // Behaviour as per 'CLAMP' + // Behaviour as per CLAMP return data.first().second(); break; } - case interpolation2DTable::CLAMP: + case bounds::normalBounding::CLAMP: { return data.first().second(); break; @@ -160,9 +168,9 @@ Type Foam::interpolation2DTable<Type>::interpolateValue } else if (lookupValue >= maxLimit) { - switch (boundsHandling_) + switch (bounding_) { - case interpolation2DTable::ERROR: + case bounds::normalBounding::ERROR: { FatalErrorInFunction << "value (" << lookupValue << ") greater than upper " @@ -170,18 +178,18 @@ Type Foam::interpolation2DTable<Type>::interpolateValue << exit(FatalError); break; } - case interpolation2DTable::WARN: + case bounds::normalBounding::WARN: { WarningInFunction << "value (" << lookupValue << ") greater than upper " << "bound (" << maxLimit << ")" << nl << " Continuing with the last entry" << endl; - // Behaviour as per 'CLAMP' + // Behaviour as per CLAMP return data.last().second(); break; } - case interpolation2DTable::CLAMP: + case bounds::normalBounding::CLAMP: { return data.last().second(); break; @@ -241,25 +249,25 @@ Foam::label Foam::interpolation2DTable<Type>::Xi if (bop(valueX, t[limitI].first())) { - switch (boundsHandling_) + switch (bounding_) { - case interpolation2DTable::ERROR: + case bounds::normalBounding::ERROR: { FatalErrorInFunction << "value (" << valueX << ") out of bounds" << exit(FatalError); break; } - case interpolation2DTable::WARN: + case bounds::normalBounding::WARN: { WarningInFunction << "value (" << valueX << ") out of bounds" << endl; - // Behaviour as per 'CLAMP' + // Behaviour as per CLAMP return limitI; break; } - case interpolation2DTable::CLAMP: + case bounds::normalBounding::CLAMP: { return limitI; break; @@ -267,7 +275,7 @@ Foam::label Foam::interpolation2DTable<Type>::Xi default: { FatalErrorInFunction - << "Unhandled enumeration " << boundsHandling_ + << "Unhandled bounding type " << int(bounding_) << abort(FatalError); } } @@ -351,79 +359,6 @@ Type Foam::interpolation2DTable<Type>::operator() } -template<class Type> -Foam::word Foam::interpolation2DTable<Type>::boundsHandlingToWord -( - const boundsHandling& bound -) const -{ - word enumName("warn"); - - switch (bound) - { - case interpolation2DTable::ERROR: - { - enumName = "error"; - break; - } - case interpolation2DTable::WARN: - { - enumName = "warn"; - break; - } - case interpolation2DTable::CLAMP: - { - enumName = "clamp"; - break; - } - } - - return enumName; -} - - -template<class Type> -typename Foam::interpolation2DTable<Type>::boundsHandling -Foam::interpolation2DTable<Type>::wordToBoundsHandling -( - const word& bound -) const -{ - if (bound == "error") - { - return interpolation2DTable::ERROR; - } - else if (bound == "warn") - { - return interpolation2DTable::WARN; - } - else if (bound == "clamp") - { - return interpolation2DTable::CLAMP; - } - else - { - WarningInFunction - << "bad outOfBounds specifier " << bound << " using 'warn'" << endl; - - return interpolation2DTable::WARN; - } -} - - -template<class Type> -typename Foam::interpolation2DTable<Type>::boundsHandling -Foam::interpolation2DTable<Type>::outOfBounds -( - const boundsHandling& bound -) -{ - boundsHandling prev = boundsHandling_; - boundsHandling_ = bound; - return prev; -} - - template<class Type> void Foam::interpolation2DTable<Type>::checkOrder() const { @@ -453,7 +388,7 @@ template<class Type> void Foam::interpolation2DTable<Type>::write(Ostream& os) const { os.writeEntry("file", fileName_); - os.writeEntry("outOfBounds", boundsHandlingToWord(boundsHandling_)); + os.writeEntry("outOfBounds", bounds::normalBoundingNames[bounding_]); os << *this; } diff --git a/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.H b/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.H index e38b0a979a486ea9b26a8ff21c85a3f8af86f8b4..5c4eb31057b1b6f50218ada8eb6293c2a8352298 100644 --- a/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.H +++ b/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.H @@ -38,6 +38,7 @@ SourceFiles #include "List.H" #include "Tuple2.H" +#include "tableBounds.H" #include "tableReader.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -58,14 +59,6 @@ public: // Public data types - //- Enumeration for handling out-of-bound values - enum boundsHandling - { - ERROR, //!< Exit with a FatalError - WARN, //!< Issue warning and clamp value (default) - CLAMP //!< Clamp value to the start/end value - }; - //- Convenience typedef typedef List<Tuple2<scalar, List<Tuple2<scalar, Type>>>> table; @@ -74,8 +67,8 @@ private: // Private data - //- Enumeration for handling out-of-bound values - boundsHandling boundsHandling_; + //- Handling for out-of-bound values + bounds::normalBounding bounding_; //- File name fileName fileName_; @@ -117,14 +110,14 @@ public: interpolation2DTable ( const List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>& values, - const boundsHandling bounds, + const bounds::normalBounding bounding, const fileName& fName ); //- Construct given the name of the file containing the table of data interpolation2DTable(const fileName& fName); - //- Construct by reading the fileName and boundsHandling from dictionary + //- Construct by reading file name and outOfBounds from dictionary interpolation2DTable(const dictionary& dict); //- Construct copy @@ -133,15 +126,6 @@ public: // Member Functions - //- Return the out-of-bounds handling as a word - word boundsHandlingToWord(const boundsHandling& bound) const; - - //- Return the out-of-bounds handling as an enumeration - boundsHandling wordToBoundsHandling(const word& bound) const; - - //- Set the out-of-bounds handling from enum, return previous setting - boundsHandling outOfBounds(const boundsHandling& bound); - //- Check that list is monotonically increasing // Exit with a FatalError if there is a problem void checkOrder() const; @@ -152,7 +136,7 @@ public: // Member Operators - //- Return an element of constant Tuple2<scalar, Type> + //- Return an element of constant List<Tuple2<scalar, Type>> const List<Tuple2<scalar, Type>>& operator[](const label) const; //- Return an interpolated value diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C index 695e13dca46e1d3902e2739610d522057050b8bb..012e47d2fd6b8ad8cdce8acd1361166751f05989 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C +++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C @@ -59,7 +59,7 @@ template<class Type> Foam::interpolationTable<Type>::interpolationTable() : List<Tuple2<scalar, Type>>(), - boundsHandling_(interpolationTable::WARN), + bounding_(bounds::repeatableBounding::WARN), fileName_("fileNameIsUndefined"), reader_(nullptr) {} @@ -69,12 +69,12 @@ template<class Type> Foam::interpolationTable<Type>::interpolationTable ( const List<Tuple2<scalar, Type>>& values, - const boundsHandling bounds, + const bounds::repeatableBounding bounding, const fileName& fName ) : List<Tuple2<scalar, Type>>(values), - boundsHandling_(bounds), + bounding_(bounding), fileName_(fName), reader_(nullptr) {} @@ -84,7 +84,7 @@ template<class Type> Foam::interpolationTable<Type>::interpolationTable(const fileName& fName) : List<Tuple2<scalar, Type>>(), - boundsHandling_(interpolationTable::WARN), + bounding_(bounds::repeatableBounding::WARN), fileName_(fName), reader_(new openFoamTableReader<Type>(dictionary())) { @@ -96,7 +96,15 @@ template<class Type> Foam::interpolationTable<Type>::interpolationTable(const dictionary& dict) : List<Tuple2<scalar, Type>>(), - boundsHandling_(wordToBoundsHandling(dict.lookup("outOfBounds"))), + bounding_ + ( + bounds::repeatableBoundingNames.lookupOrFailsafe + ( + "outOfBounds", + dict, + bounds::repeatableBounding::WARN + ) + ), fileName_(dict.lookup("file")), reader_(tableReader<Type>::New(dict)) { @@ -111,7 +119,7 @@ Foam::interpolationTable<Type>::interpolationTable ) : List<Tuple2<scalar, Type>>(interpTable), - boundsHandling_(interpTable.boundsHandling_), + bounding_(interpTable.bounding_), fileName_(interpTable.fileName_), reader_(interpTable.reader_) // note: steals reader. Used in write(). {} @@ -120,88 +128,6 @@ Foam::interpolationTable<Type>::interpolationTable // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<class Type> -Foam::word Foam::interpolationTable<Type>::boundsHandlingToWord -( - const boundsHandling& bound -) const -{ - word enumName("warn"); - - switch (bound) - { - case interpolationTable::ERROR: - { - enumName = "error"; - break; - } - case interpolationTable::WARN: - { - enumName = "warn"; - break; - } - case interpolationTable::CLAMP: - { - enumName = "clamp"; - break; - } - case interpolationTable::REPEAT: - { - enumName = "repeat"; - break; - } - } - - return enumName; -} - - -template<class Type> -typename Foam::interpolationTable<Type>::boundsHandling -Foam::interpolationTable<Type>::wordToBoundsHandling -( - const word& bound -) const -{ - if (bound == "error") - { - return interpolationTable::ERROR; - } - else if (bound == "warn") - { - return interpolationTable::WARN; - } - else if (bound == "clamp") - { - return interpolationTable::CLAMP; - } - else if (bound == "repeat") - { - return interpolationTable::REPEAT; - } - else - { - WarningInFunction - << "bad outOfBounds specifier " << bound << " using 'warn'" << endl; - - return interpolationTable::WARN; - } -} - - -template<class Type> -typename Foam::interpolationTable<Type>::boundsHandling -Foam::interpolationTable<Type>::outOfBounds -( - const boundsHandling& bound -) -{ - boundsHandling prev = boundsHandling_; - boundsHandling_ = bound; - return prev; -} - - template<class Type> void Foam::interpolationTable<Type>::check() const { @@ -230,7 +156,7 @@ template<class Type> void Foam::interpolationTable<Type>::write(Ostream& os) const { os.writeEntry("file", fileName_); - os.writeEntry("outOfBounds", boundsHandlingToWord(boundsHandling_)); + os.writeEntry("outOfBounds", bounds::repeatableBoundingNames[bounding_]); if (reader_.valid()) { reader_->write(os); @@ -255,33 +181,33 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const if (lookupValue < minLimit) { - switch (boundsHandling_) + switch (bounding_) { - case interpolationTable::ERROR: + case bounds::repeatableBounding::ERROR: { FatalErrorInFunction << "value (" << lookupValue << ") underflow" << nl << exit(FatalError); break; } - case interpolationTable::WARN: + case bounds::repeatableBounding::WARN: { WarningInFunction << "value (" << lookupValue << ") underflow" << nl << " Zero rate of change." << endl; - // behaviour as per 'CLAMP' + // Behaviour as per CLAMP return 0; break; } - case interpolationTable::CLAMP: + case bounds::repeatableBounding::CLAMP: { return 0; break; } - case interpolationTable::REPEAT: + case bounds::repeatableBounding::REPEAT: { - // adjust lookupValue to >= minLimit + // Adjust lookupValue to >= minLimit scalar span = maxLimit-minLimit; lookupValue = fmod(lookupValue-minLimit, span) + minLimit; break; @@ -290,33 +216,33 @@ Type Foam::interpolationTable<Type>::rateOfChange(const scalar value) const } else if (lookupValue >= maxLimit) { - switch (boundsHandling_) + switch (bounding_) { - case interpolationTable::ERROR: + case bounds::repeatableBounding::ERROR: { FatalErrorInFunction << "value (" << lookupValue << ") overflow" << nl << exit(FatalError); break; } - case interpolationTable::WARN: + case bounds::repeatableBounding::WARN: { WarningInFunction << "value (" << lookupValue << ") overflow" << nl << " Zero rate of change." << endl; - // Behaviour as per 'CLAMP' + // Behaviour as per CLAMP return 0; break; } - case interpolationTable::CLAMP: + case bounds::repeatableBounding::CLAMP: { return 0; break; } - case interpolationTable::REPEAT: + case bounds::repeatableBounding::REPEAT: { - // adjust lookupValue <= maxLimit + // Adjust lookupValue <= maxLimit scalar span = maxLimit-minLimit; lookupValue = fmod(lookupValue-minLimit, span) + minLimit; break; @@ -401,16 +327,16 @@ Foam::interpolationTable<Type>::operator[](const label i) const } else if (ii < 0) { - switch (boundsHandling_) + switch (bounding_) { - case interpolationTable::ERROR: + case bounds::repeatableBounding::ERROR: { FatalErrorInFunction << "index (" << ii << ") underflow" << nl << exit(FatalError); break; } - case interpolationTable::WARN: + case bounds::repeatableBounding::WARN: { WarningInFunction << "index (" << ii << ") underflow" << nl @@ -420,12 +346,12 @@ Foam::interpolationTable<Type>::operator[](const label i) const ii = 0; break; } - case interpolationTable::CLAMP: + case bounds::repeatableBounding::CLAMP: { ii = 0; break; } - case interpolationTable::REPEAT: + case bounds::repeatableBounding::REPEAT: { while (ii < 0) { @@ -437,16 +363,16 @@ Foam::interpolationTable<Type>::operator[](const label i) const } else if (ii >= n) { - switch (boundsHandling_) + switch (bounding_) { - case interpolationTable::ERROR: + case bounds::repeatableBounding::ERROR: { FatalErrorInFunction << "index (" << ii << ") overflow" << nl << exit(FatalError); break; } - case interpolationTable::WARN: + case bounds::repeatableBounding::WARN: { WarningInFunction << "index (" << ii << ") overflow" << nl @@ -456,12 +382,12 @@ Foam::interpolationTable<Type>::operator[](const label i) const ii = n - 1; break; } - case interpolationTable::CLAMP: + case bounds::repeatableBounding::CLAMP: { ii = n - 1; break; } - case interpolationTable::REPEAT: + case bounds::repeatableBounding::REPEAT: { while (ii >= n) { @@ -492,31 +418,31 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const if (lookupValue < minLimit) { - switch (boundsHandling_) + switch (bounding_) { - case interpolationTable::ERROR: + case bounds::repeatableBounding::ERROR: { FatalErrorInFunction << "value (" << lookupValue << ") underflow" << nl << exit(FatalError); break; } - case interpolationTable::WARN: + case bounds::repeatableBounding::WARN: { WarningInFunction << "value (" << lookupValue << ") underflow" << nl << " Continuing with the first entry" << endl; - // Behaviour as per 'CLAMP' + // Behaviour as per CLAMP return this->first().second(); break; } - case interpolationTable::CLAMP: + case bounds::repeatableBounding::CLAMP: { return this->first().second(); break; } - case interpolationTable::REPEAT: + case bounds::repeatableBounding::REPEAT: { // adjust lookupValue to >= minLimit const scalar span = maxLimit-minLimit; @@ -527,16 +453,16 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const } else if (lookupValue >= maxLimit) { - switch (boundsHandling_) + switch (bounding_) { - case interpolationTable::ERROR: + case bounds::repeatableBounding::ERROR: { FatalErrorInFunction << "value (" << lookupValue << ") overflow" << nl << exit(FatalError); break; } - case interpolationTable::WARN: + case bounds::repeatableBounding::WARN: { WarningInFunction << "value (" << lookupValue << ") overflow" << nl @@ -546,12 +472,12 @@ Type Foam::interpolationTable<Type>::operator()(const scalar value) const return this->last().second(); break; } - case interpolationTable::CLAMP: + case bounds::repeatableBounding::CLAMP: { return this->last().second(); break; } - case interpolationTable::REPEAT: + case bounds::repeatableBounding::REPEAT: { // adjust lookupValue <= maxLimit const scalar span = maxLimit-minLimit; diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H index 09f2e74442544a312f849e20fb6c59432dd5b329..e75040703e06943138d3c68e796b1ba93d94b47f 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H +++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H @@ -64,6 +64,7 @@ SourceFiles #include "List.H" #include "Tuple2.H" +#include "tableBounds.H" #include "tableReader.H" #include "autoPtr.H" @@ -81,26 +82,10 @@ class interpolationTable : public List<Tuple2<scalar, Type>> { -public: - - // Public data types - - //- Enumeration for handling out-of-bound values - enum boundsHandling - { - ERROR, //!< Exit with a FatalError - WARN, //!< Issue warning and clamp value (default) - CLAMP, //!< Clamp value to the start/end value - REPEAT //!< Treat as a repeating list - }; - - -private: - // Private data - //- Enumeration for handling out-of-bound values - boundsHandling boundsHandling_; + //- Handling for out-of-bound values + bounds::repeatableBounding bounding_; //- File name fileName fileName_; @@ -108,6 +93,7 @@ private: //- The actual reader autoPtr<tableReader<Type>> reader_; + // Private Member Functions //- Read the table of data from file @@ -125,14 +111,14 @@ public: interpolationTable ( const List<Tuple2<scalar, Type>>& values, - const boundsHandling bounds, + const bounds::repeatableBounding bounding, const fileName& fName ); //- Construct given the name of the file containing the table of data interpolationTable(const fileName& fName); - //- Construct by reading the fileName and boundsHandling from dictionary + //- Construct by reading file name and outOfBounds from dictionary // and read the table from that file. // This is a specialised constructor used by patchFields interpolationTable(const dictionary& dict); @@ -143,15 +129,6 @@ public: // Member Functions - //- Return the out-of-bounds handling as a word - word boundsHandlingToWord(const boundsHandling& bound) const; - - //- Return the out-of-bounds handling as an enumeration - boundsHandling wordToBoundsHandling(const word& bound) const; - - //- Set the out-of-bounds handling from enum, return previous setting - boundsHandling outOfBounds(const boundsHandling& bound); - //- Check that list is monotonically increasing // Exit with a FatalError if there is a problem void check() const; diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C index 02d3b186eff9a0984f89f63c3feb5882981a4228..eb3bdbf0def573649d56c2cf03cea7f01f71fb41 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C +++ b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C @@ -64,11 +64,13 @@ Foam::Function1Types::TableBase<Type>::TableBase : Function1<Type>(name), name_(name), - boundsHandling_ + bounding_ ( - wordToBoundsHandling + bounds::repeatableBoundingNames.lookupOrFailsafe ( - dict.lookupOrDefault<word>("outOfBounds", "clamp") + "outOfBounds", + dict, + bounds::repeatableBounding::CLAMP ) ), interpolationScheme_ @@ -84,7 +86,7 @@ Foam::Function1Types::TableBase<Type>::TableBase(const TableBase<Type>& tbl) : Function1<Type>(tbl), name_(tbl.name_), - boundsHandling_(tbl.boundsHandling_), + bounding_(tbl.bounding_), interpolationScheme_(tbl.interpolationScheme_), table_(tbl.table_), tableSamplesPtr_(tbl.tableSamplesPtr_), @@ -101,90 +103,6 @@ Foam::Function1Types::TableBase<Type>::~TableBase() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<class Type> -Foam::word Foam::Function1Types::TableBase<Type>::boundsHandlingToWord -( - const boundsHandling& bound -) const -{ - word enumName("warn"); - - switch (bound) - { - case ERROR: - { - enumName = "error"; - break; - } - case WARN: - { - enumName = "warn"; - break; - } - case CLAMP: - { - enumName = "clamp"; - break; - } - case REPEAT: - { - enumName = "repeat"; - break; - } - } - - return enumName; -} - - -template<class Type> -typename Foam::Function1Types::TableBase<Type>::boundsHandling -Foam::Function1Types::TableBase<Type>::wordToBoundsHandling -( - const word& bound -) const -{ - if (bound == "error") - { - return ERROR; - } - else if (bound == "warn") - { - return WARN; - } - else if (bound == "clamp") - { - return CLAMP; - } - else if (bound == "repeat") - { - return REPEAT; - } - else - { - WarningInFunction - << "bad outOfBounds specifier " << bound << " using 'warn'" - << endl; - - return WARN; - } -} - - -template<class Type> -typename Foam::Function1Types::TableBase<Type>::boundsHandling -Foam::Function1Types::TableBase<Type>::outOfBounds -( - const boundsHandling& bound -) -{ - boundsHandling prev = boundsHandling_; - boundsHandling_ = bound; - - return prev; -} - - template<class Type> void Foam::Function1Types::TableBase<Type>::check() const { @@ -223,33 +141,33 @@ bool Foam::Function1Types::TableBase<Type>::checkMinBounds { if (x < table_.first().first()) { - switch (boundsHandling_) + switch (bounding_) { - case ERROR: + case bounds::repeatableBounding::ERROR: { FatalErrorInFunction << "value (" << x << ") underflow" << exit(FatalError); break; } - case WARN: + case bounds::repeatableBounding::WARN: { WarningInFunction << "value (" << x << ") underflow" << nl << endl; - // Behaviour as per 'CLAMP' + // Behaviour as per CLAMP xDash = table_.first().first(); return true; break; } - case CLAMP: + case bounds::repeatableBounding::CLAMP: { xDash = table_.first().first(); return true; break; } - case REPEAT: + case bounds::repeatableBounding::REPEAT: { // adjust x to >= minX const scalar span = @@ -282,33 +200,33 @@ bool Foam::Function1Types::TableBase<Type>::checkMaxBounds { if (x > table_.last().first()) { - switch (boundsHandling_) + switch (bounding_) { - case ERROR: + case bounds::repeatableBounding::ERROR: { FatalErrorInFunction << "value (" << x << ") overflow" << exit(FatalError); break; } - case WARN: + case bounds::repeatableBounding::WARN: { WarningInFunction << "value (" << x << ") overflow" << nl << endl; - // Behaviour as per 'CLAMP' + // Behaviour as per CLAMP xDash = table_.last().first(); return true; break; } - case CLAMP: + case bounds::repeatableBounding::CLAMP: { xDash = table_.last().first(); return true; break; } - case REPEAT: + case bounds::repeatableBounding::REPEAT: { // adjust x to >= minX const scalar span = @@ -427,9 +345,13 @@ Foam::tmp<Foam::Field<Type>> Foam::Function1Types::TableBase<Type>::y() const template<class Type> void Foam::Function1Types::TableBase<Type>::writeEntries(Ostream& os) const { - if (boundsHandling_ != CLAMP) + if (bounding_ != bounds::repeatableBounding::CLAMP) { - os.writeEntry("outOfBounds", boundsHandlingToWord(boundsHandling_)); + os.writeEntry + ( + "outOfBounds", + bounds::repeatableBoundingNames[bounding_] + ); } if (interpolationScheme_ != "linear") { diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H index 95c610902671d4ced217694f7233c8ddb00c5a18..f2a26907daffc26905eca3d6f4c48a7d8fd75ffa 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H +++ b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H @@ -35,6 +35,7 @@ SourceFiles #ifndef TableBase_H #define TableBase_H +#include "tableBounds.H" #include "Function1.H" #include "Tuple2.H" @@ -57,20 +58,6 @@ class TableBase : public Function1<Type> { -public: - - // Public data types - - //- Enumeration for handling out-of-bound values - enum boundsHandling - { - ERROR, //!< Exit with a FatalError - WARN, //!< Issue warning and clamp value (default) - CLAMP, //!< Clamp value to the start/end value - REPEAT //!< Treat as a repeating list - }; - - protected: // Protected data @@ -78,8 +65,8 @@ protected: //- Table name const word name_; - //- Enumeration for handling out-of-bound values - const boundsHandling boundsHandling_; + //- Handling for out-of-bound values + const bounds::repeatableBounding bounding_; //- Interpolation type const word interpolationScheme_; @@ -108,7 +95,7 @@ protected: private: //- Disallow default bitwise assignment - void operator=(const TableBase<Type>&); + void operator=(const TableBase<Type>&) = delete; public: @@ -128,15 +115,6 @@ public: // Member Functions - //- Return the out-of-bounds handling as a word - word boundsHandlingToWord(const boundsHandling& bound) const; - - //- Return the out-of-bounds handling as an enumeration - boundsHandling wordToBoundsHandling(const word& bound) const; - - //- Set the out-of-bounds handling from enum, return previous setting - boundsHandling outOfBounds(const boundsHandling& bound); - //- Check the table for size and consistency void check() const; @@ -164,8 +142,8 @@ public: //- Write all table data in dictionary format virtual void writeData(Ostream& os) const; - //- Write keywords only in dictionary format. Used for non-inline - // table types + //- Write keywords only in dictionary format. + // Used for non-inline table types virtual void writeEntries(Ostream& os) const; }; diff --git a/src/OpenFOAM/primitives/ranges/tableBounds/tableBounds.C b/src/OpenFOAM/primitives/ranges/tableBounds/tableBounds.C new file mode 100644 index 0000000000000000000000000000000000000000..38c811534326ba85167b44a2e23ab36aed90dcac --- /dev/null +++ b/src/OpenFOAM/primitives/ranges/tableBounds/tableBounds.C @@ -0,0 +1,49 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "tableBounds.H" + +// * * * * * * * * * * * * * * * * Global Data * * * * * * * * * * * * * * * // + +const Foam::Enum<Foam::bounds::normalBounding> +Foam::bounds::normalBoundingNames +{ + { normalBounding::ERROR, "error" }, + { normalBounding::WARN, "warn" }, + { normalBounding::CLAMP, "clamp" }, +}; + + +const Foam::Enum<Foam::bounds::repeatableBounding> +Foam::bounds::repeatableBoundingNames +{ + { repeatableBounding::ERROR, "error" }, + { repeatableBounding::WARN, "warn" }, + { repeatableBounding::CLAMP, "clamp" }, + { repeatableBounding::REPEAT, "repeat" }, +}; + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/ranges/tableBounds/tableBounds.H b/src/OpenFOAM/primitives/ranges/tableBounds/tableBounds.H new file mode 100644 index 0000000000000000000000000000000000000000..ef3e49e78e6d8ee22d759beb87e940a800f27a94 --- /dev/null +++ b/src/OpenFOAM/primitives/ranges/tableBounds/tableBounds.H @@ -0,0 +1,84 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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/>. + +Namespace + Foam::bounds + +Description + Namespace for bounding specifications. + At the moment, mostly for tables. + +SourceFiles + tableBounds.C + +\*---------------------------------------------------------------------------*/ + +#ifndef tableBounds_H +#define tableBounds_H + +#include "Enum.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace bounds +{ + + // Enumerations + + //- Enumeration for handling out-of-bound values + enum class normalBounding + { + ERROR, //!< Exit with a FatalError + WARN, //!< Issue warning and clamp value (this is a good default) + CLAMP //!< Clamp value to the start/end value + }; + + //- Enumeration for handling out-of-bound values that are repeatable + enum class repeatableBounding + { + ERROR, //!< Exit with a FatalError + WARN, //!< Issue warning and clamp value (this is a good default) + CLAMP, //!< Clamp value to the start/end value + REPEAT //!< Treat as a repeating list + }; + + + //- Strings corresponding to the normalBounding + extern const Foam::Enum<normalBounding> normalBoundingNames; + + //- Strings corresponding to the repeatableBounding + extern const Foam::Enum<repeatableBounding> repeatableBoundingNames; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace bounds +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/radiation/radiationModels/fvDOM/blackBodyEmission/blackBodyEmission.C b/src/thermophysicalModels/radiation/radiationModels/fvDOM/blackBodyEmission/blackBodyEmission.C index b2fdb85d1632b48b63af64a36ac1dff199fefc2e..03ba5ca1208a26057d5e9cac9e6033bc9917af74 100644 --- a/src/thermophysicalModels/radiation/radiationModels/fvDOM/blackBodyEmission/blackBodyEmission.C +++ b/src/thermophysicalModels/radiation/radiationModels/fvDOM/blackBodyEmission/blackBodyEmission.C @@ -149,7 +149,7 @@ Foam::radiation::blackBodyEmission::blackBodyEmission table_ ( emissivePowerTable, - interpolationTable<scalar>::CLAMP, + bounds::repeatableBounding::CLAMP, "blackBodyEmissivePower" ), C1_("C1", dimensionSet(1, 4, 3, 0, 0, 0, 0), 3.7419e-16),