diff --git a/etc/codeTemplates/dynamicCode/Function1Template.C b/etc/codeTemplates/dynamicCode/Function1Template.C index d613a66129..a4f12919b9 100644 --- a/etc/codeTemplates/dynamicCode/Function1Template.C +++ b/etc/codeTemplates/dynamicCode/Function1Template.C @@ -62,6 +62,17 @@ extern "C" } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::Function1s::${typeName}Function1${TemplateType}::writeData +( + Ostream& os +) const +{ + NotImplemented; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::Function1s::${typeName}Function1${TemplateType}:: @@ -127,13 +138,4 @@ Foam::Function1s::${typeName}Function1${TemplateType}::integrate } -void Foam::Function1s::${typeName}Function1${TemplateType}::writeData -( - Ostream& os -) const -{ - NotImplemented; -} - - // ************************************************************************* i/ diff --git a/etc/codeTemplates/dynamicCode/Function1Template.H b/etc/codeTemplates/dynamicCode/Function1Template.H index f7624d7429..69209e9df3 100644 --- a/etc/codeTemplates/dynamicCode/Function1Template.H +++ b/etc/codeTemplates/dynamicCode/Function1Template.H @@ -55,6 +55,11 @@ class ${typeName}Function1${TemplateType} : public FieldFunction1<${TemplateType}, ${typeName}Function1${TemplateType}> { + // Private Member Functions + + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; + public: @@ -108,9 +113,6 @@ public: const scalar x2 ) const; - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C index 488152b237..3b9d7aa747 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C +++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C @@ -88,6 +88,13 @@ Foam::Function1s::Coded::compileNew() } +template +void Foam::Function1s::Coded::writeData(Ostream& os) const +{ + writeCode(os); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -165,13 +172,4 @@ Foam::tmp> Foam::Function1s::Coded::integrate } -template -void Foam::Function1s::Coded::writeData(Ostream& os) const -{ - Function1::writeData(os); - os << token::END_STATEMENT << nl; - writeCode(os); -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H index 31344b0e53..f1fe2e3920 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H +++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H @@ -116,6 +116,9 @@ class Coded //- Compile, link and return the now coded Function1 autoPtr> compileNew(); + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; + public: @@ -161,9 +164,6 @@ public: const scalarField& x2 ) const; - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.C b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.C index 2be8eb08c1..0dddf88059 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.C +++ b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -99,11 +99,10 @@ Foam::Function1s::Constant::~Constant() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void Foam::Function1s::Constant::writeData(Ostream& os) const +void Foam::Function1s::Constant::write(Ostream& os) const { - Function1::writeData(os); - - os << token::SPACE << value_ << token::END_STATEMENT << nl; + this->writeType(os) + << token::SPACE << value_ << token::END_STATEMENT << nl; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H index 435a4381df..589b2d3d8c 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H +++ b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H @@ -106,7 +106,7 @@ public: virtual inline Type integrate(const scalar x1, const scalar x2) const; //- Write in dictionary format - virtual void writeData(Ostream& os) const; + virtual void write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C index bdb0a075f5..4bce92fbd4 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,16 @@ License #include "Function1.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +Foam::Ostream& Foam::Function1::writeType(Ostream& os) const +{ + return writeKeyword(os, name_) << type(); +} + + // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // template @@ -95,9 +105,16 @@ const Foam::word& Foam::Function1::name() const template -void Foam::Function1::writeData(Ostream& os) const +void Foam::Function1::write(Ostream& os) const { - writeKeyword(os, name_) << type(); + writeKeyword(os, name_) + << nl << indent << token::BEGIN_BLOCK << nl << incrIndent; + + writeEntry(os, "type", type()); + + writeData(os); + + os << decrIndent << indent << token::END_BLOCK << endl; } @@ -144,7 +161,7 @@ Foam::FieldFunction1::integrate template void Foam::writeEntry(Ostream& os, const Function1& f1) { - f1.writeData(os); + f1.write(os); } @@ -163,7 +180,7 @@ Foam::Ostream& Foam::operator<< "Ostream& operator<<(Ostream&, const Function1&)" ); - f1.writeData(os); + f1.write(os); return os; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H index 16b91cbf96..b1436311c9 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H @@ -71,6 +71,15 @@ protected: const word name_; + // Protected member functions + + Ostream& writeType(Ostream& os) const; + + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const + {} + + public: typedef Type returnType; @@ -137,8 +146,8 @@ public: const scalarField& x2 ) const = 0; - //- Write in dictionary format - virtual void writeData(Ostream& os) const; + //- Write dictionary to stream + virtual void write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C index 5b349db7f5..dc4cc57327 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 | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -90,13 +90,27 @@ Foam::autoPtr> Foam::Function1::New << exit(FatalError); } - return cstrIter() + autoPtr> funcPtr ( - entryName, - dict.found(entryName + "Coeffs") - ? dict.subDict(entryName + "Coeffs") - : dict + cstrIter() + ( + entryName, + dict.found(entryName + "Coeffs") + ? dict.subDict(entryName + "Coeffs") + : dict + ) ); + + if (dict.found(entryName + "Coeffs")) + { + IOWarningInFunction(dict) + << "Using deprecated " + << (entryName + "Coeffs") << " sub-dictionary."<< nl + << " Please use the simpler form" << endl; + funcPtr->write(Info); + } + + return funcPtr; } } diff --git a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C index 6298893270..910f6010ff 100644 --- a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C +++ b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -55,11 +55,9 @@ Foam::Function1s::OneConstant::~OneConstant() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void Foam::Function1s::OneConstant::writeData(Ostream& os) const +void Foam::Function1s::OneConstant::write(Ostream& os) const { - Function1::writeData(os); - - os << token::END_STATEMENT << nl; + this->writeType(os) << token::END_STATEMENT << nl; } diff --git a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H index ef2654ad7c..ab945f430e 100644 --- a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H +++ b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H @@ -87,7 +87,7 @@ public: virtual inline Type integrate(const scalar x1, const scalar x2) const; //- Write in dictionary format - virtual void writeData(Ostream& os) const; + virtual void write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.C b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.C index 2b41c1c12d..d15700fcd6 100644 --- a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.C +++ b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -184,11 +184,10 @@ Type Foam::Function1s::Polynomial::integrate template -void Foam::Function1s::Polynomial::writeData(Ostream& os) const +void Foam::Function1s::Polynomial::write(Ostream& os) const { - Function1::writeData(os); - - os << nl << indent << coeffs_ << token::END_STATEMENT << nl; + this->writeType(os) + << nl << indent << coeffs_ << token::END_STATEMENT << nl; } diff --git a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H index 34ba210b16..857cd58b0b 100644 --- a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H +++ b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H @@ -111,7 +111,7 @@ public: //- Write in dictionary format - virtual void writeData(Ostream& os) const; + virtual void write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Ramp/Ramp.C b/src/OpenFOAM/primitives/functions/Function1/Ramp/Ramp.C index 13fc5ce055..1e621f9e2f 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Ramp/Ramp.C +++ b/src/OpenFOAM/primitives/functions/Function1/Ramp/Ramp.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,16 @@ License #include "Ramp.H" +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +void Foam::Function1s::Ramp::writeData(Ostream& os) const +{ + writeEntry(os, "start", start_); + writeEntry(os, "duration", duration_); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -55,19 +65,4 @@ Foam::Function1s::Ramp::~Ramp() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::Function1s::Ramp::writeData(Ostream& os) const -{ - Function1::writeData(os); - os << token::END_STATEMENT << nl; - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; - writeEntry(os, "start", start_); - writeEntry(os, "duration", duration_); - os << decrIndent << indent << token::END_BLOCK << endl; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Ramp/Ramp.H b/src/OpenFOAM/primitives/functions/Function1/Ramp/Ramp.H index b7991d409c..c8f15b7b72 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Ramp/Ramp.H +++ b/src/OpenFOAM/primitives/functions/Function1/Ramp/Ramp.H @@ -114,6 +114,9 @@ protected: return 1/duration_; } + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; + private: @@ -144,9 +147,6 @@ public: //- Return value for time t virtual scalar value(const scalar t) const = 0; - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C index eb5685e502..783b94b27f 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C +++ b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,6 +47,15 @@ void Foam::Function1s::Scale::read(const dictionary& coeffs) } +template +void Foam::Function1s::Scale::writeData(Ostream& os) const +{ + scale_->write(os); + xScale_->write(os); + value_->write(os); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -81,20 +90,4 @@ Foam::Function1s::Scale::~Scale() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::Function1s::Scale::writeData(Ostream& os) const -{ - Function1::writeData(os); - os << token::END_STATEMENT << nl; - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; - scale_->writeData(os); - xScale_->writeData(os); - value_->writeData(os); - os << decrIndent << indent << token::END_BLOCK << endl; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H index af2a34a77f..a3abaaa596 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H +++ b/src/OpenFOAM/primitives/functions/Function1/Scale/Scale.H @@ -160,6 +160,9 @@ class Scale //- Read the coefficients from the given dictionary void read(const dictionary& coeffs); + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; + public: @@ -186,9 +189,6 @@ public: // Member Functions - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - //- Return value virtual inline Type value(const scalar x) const; diff --git a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.C index 134736f6f7..93d0a62f5b 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 | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -41,6 +41,16 @@ void Foam::Function1s::Sine::read(const dictionary& coeffs) } +template +void Foam::Function1s::Sine::writeData(Ostream& os) const +{ + amplitude_->write(os); + writeEntry(os, "frequency", frequency_); + writeEntry(os, "start", start_); + level_->write(os); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -75,21 +85,4 @@ Foam::Function1s::Sine::~Sine() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::Function1s::Sine::writeData(Ostream& os) const -{ - Function1::writeData(os); - os << token::END_STATEMENT << nl; - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; - amplitude_->writeData(os); - writeEntry(os, "frequency", frequency_); - writeEntry(os, "start", start_); - level_->writeData(os); - os << decrIndent << indent << token::END_BLOCK << endl; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H index 395d3a9c2f..2357bdad1f 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H +++ b/src/OpenFOAM/primitives/functions/Function1/Sine/Sine.H @@ -114,6 +114,9 @@ class Sine //- Read the coefficients from the given dictionary void read(const dictionary& coeffs); + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; + public: @@ -146,9 +149,6 @@ public: //- Integrate between two values virtual inline Type integrate(const scalar x1, const scalar x2) const; - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Square/Square.C b/src/OpenFOAM/primitives/functions/Function1/Square/Square.C index d8c2d77df8..de0c4a5295 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 | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -42,6 +42,17 @@ void Foam::Function1s::Square::read(const dictionary& coeffs) } +template +void Foam::Function1s::Square::writeData(Ostream& os) const +{ + amplitude_->write(os); + writeEntry(os, "frequency", frequency_); + writeEntry(os, "start", start_); + level_->write(os); + writeEntry(os, "markSpace", markSpace_); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -77,22 +88,4 @@ Foam::Function1s::Square::~Square() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::Function1s::Square::writeData(Ostream& os) const -{ - Function1::writeData(os); - os << token::END_STATEMENT << nl; - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; - amplitude_->writeData(os); - writeEntry(os, "frequency", frequency_); - writeEntry(os, "start", start_); - level_->writeData(os); - writeEntry(os, "markSpace", markSpace_); - os << decrIndent << indent << token::END_BLOCK << endl; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Square/Square.H b/src/OpenFOAM/primitives/functions/Function1/Square/Square.H index 772fe06735..b8e7fac69d 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 | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -125,6 +125,9 @@ class Square //- Read the coefficients from the given dictionary void read(const dictionary& coeffs); + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; + public: @@ -157,9 +160,6 @@ public: //- Integrate between two values virtual inline Type integrate(const scalar x1, const scalar x2) const; - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/Table.C b/src/OpenFOAM/primitives/functions/Function1/Table/Table.C index f59c55b39e..d762c99efb 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/Table.C +++ b/src/OpenFOAM/primitives/functions/Function1/Table/Table.C @@ -130,6 +130,29 @@ Foam::scalar Foam::Function1s::Table::bound } +template +void Foam::Function1s::Table::writeData(Ostream& os) const +{ + writeEntryIfDifferent + ( + os, + "outOfBounds", + tableBase::boundsHandlingNames_[tableBase::boundsHandling::clamp], + tableBase::boundsHandlingNames_[boundsHandling_] + ); + + writeEntryIfDifferent + ( + os, + "interpolationScheme", + linearInterpolationWeights::typeName, + interpolationScheme_ + ); + + reader_->write(os, table_); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -293,38 +316,4 @@ Foam::Function1s::Table::y() const } -template -void Foam::Function1s::Table::writeData -( - Ostream& os -) const -{ - Function1::writeData(os); - os << token::END_STATEMENT << nl; - - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; - - writeEntryIfDifferent - ( - os, - "outOfBounds", - tableBase::boundsHandlingNames_[tableBase::boundsHandling::clamp], - tableBase::boundsHandlingNames_[boundsHandling_] - ); - - writeEntryIfDifferent - ( - os, - "interpolationScheme", - linearInterpolationWeights::typeName, - interpolationScheme_ - ); - - reader_->write(os, table_); - - os << decrIndent << indent << token::END_BLOCK << endl; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/Table.H b/src/OpenFOAM/primitives/functions/Function1/Table/Table.H index 521eaaa5d4..681824ebcc 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/Table.H +++ b/src/OpenFOAM/primitives/functions/Function1/Table/Table.H @@ -39,15 +39,51 @@ Description ); \endverbatim + or in dictionary form which supports the setting of options, e.g. + \verbatim + table; + + values + ( + (0.0 (1 2 3)) + (1.0 (4 5 6)) + ); + + outOfBounds clamp; // optional out-of-bounds handling + interpolationScheme linear; // optional interpolation method + \endverbatim + + or in sub-dictionary form which avoids clashes between table entries and + other entries in the dictionary: + + \verbatim + + { + type table; + + values + ( + (0.0 (1 2 3)) + (1.0 (4 5 6)) + ); + + outOfBounds clamp; // optional out-of-bounds handling + interpolationScheme linear; // optional interpolation method + } + \endverbatim + The data may be read from a separate file in either native or CSV format: Usage: \verbatim - table; - file ""; // Name/path of thedata file - format foam; // data format (optional) - outOfBounds clamp; // optional out-of-bounds handling - interpolationScheme linear; // optional interpolation method + + { + type table; + file ""; // Name/path of thedata file + format foam; // data format (optional) + outOfBounds clamp; // optional out-of-bounds handling + interpolationScheme linear; // optional interpolation method + } \endverbatim SourceFiles @@ -113,7 +149,7 @@ class Table const autoPtr> reader_; - // Protected Member Functions + // Private Member Functions //- Return (demand driven) interpolator const interpolationWeights& interpolator() const; @@ -126,6 +162,9 @@ class Table // as the interpolator already performs that function. scalar bound(const scalar x) const; + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; + public: @@ -169,9 +208,6 @@ public: //- Return the dependent values virtual tmp> y() const; - //- Write all table data in dictionary format - virtual void writeData(Ostream& os) const; - // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C index 93749b3097..d286d2f8ba 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C +++ b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,11 +48,9 @@ Foam::Function1s::ZeroConstant::~ZeroConstant() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void Foam::Function1s::ZeroConstant::writeData(Ostream& os) const +void Foam::Function1s::ZeroConstant::write(Ostream& os) const { - Function1::writeData(os); - - os << token::END_STATEMENT << nl; + this->writeType(os) << token::END_STATEMENT << nl; } diff --git a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H index 5776fc466b..0879c78627 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H +++ b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H @@ -84,7 +84,7 @@ public: virtual inline Type integrate(const scalar x1, const scalar x2) const; //- Write in dictionary format - virtual void writeData(Ostream& os) const; + virtual void write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function1/reverseRamp/reverseRamp.C b/src/OpenFOAM/primitives/functions/Function1/reverseRamp/reverseRamp.C index f9715ac491..3cd539ad53 100644 --- a/src/OpenFOAM/primitives/functions/Function1/reverseRamp/reverseRamp.C +++ b/src/OpenFOAM/primitives/functions/Function1/reverseRamp/reverseRamp.C @@ -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 @@ -36,6 +36,15 @@ namespace Function1s } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::Function1s::reverseRamp::writeData(Ostream& os) const +{ + Ramp::writeData(os); + ramp_->write(os); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::Function1s::reverseRamp::reverseRamp @@ -65,17 +74,4 @@ Foam::Function1s::reverseRamp::~reverseRamp() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void Foam::Function1s::reverseRamp::writeData(Ostream& os) const -{ - Ramp::writeData(os); - os << token::END_STATEMENT << nl; - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; - ramp_->writeData(os); - os << decrIndent << indent << token::END_BLOCK << endl; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/reverseRamp/reverseRamp.H b/src/OpenFOAM/primitives/functions/Function1/reverseRamp/reverseRamp.H index 33447650a7..b32acc02be 100644 --- a/src/OpenFOAM/primitives/functions/Function1/reverseRamp/reverseRamp.H +++ b/src/OpenFOAM/primitives/functions/Function1/reverseRamp/reverseRamp.H @@ -83,8 +83,16 @@ class reverseRamp : public Ramp { - //- Standard ramp function to reverse - autoPtr> ramp_; + // Private Data + + //- Standard ramp function to reverse + autoPtr> ramp_; + + + // Private Member Functions + + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; public: @@ -122,9 +130,6 @@ public: const scalar t2 ) const; - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.C b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.C index 3ce4317a69..ccb72a1b6b 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.C +++ b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.C @@ -88,6 +88,13 @@ Foam::Function2s::Coded::compileNew() } +template +void Foam::Function2s::Coded::writeData(Ostream& os) const +{ + writeCode(os); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -142,13 +149,4 @@ Foam::tmp> Foam::Function2s::Coded::value } -template -void Foam::Function2s::Coded::writeData(Ostream& os) const -{ - Function2::writeData(os); - os << token::END_STATEMENT << nl; - writeCode(os); -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.H b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.H index 0b2c524875..4976173b4a 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.H +++ b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.H @@ -89,6 +89,9 @@ class Coded //- Compile, link and return the now coded Function2 autoPtr> compileNew(); + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; + public: @@ -128,9 +131,6 @@ public: const scalarField& y ) const; - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.C b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.C index 88e37551ae..8ac680103a 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.C +++ b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.C @@ -99,11 +99,10 @@ Foam::Function2s::Constant::~Constant() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void Foam::Function2s::Constant::writeData(Ostream& os) const +void Foam::Function2s::Constant::write(Ostream& os) const { - Function2::writeData(os); - - os << token::SPACE << value_ << token::END_STATEMENT << nl; + this->writeType(os) + << token::SPACE << value_ << token::END_STATEMENT << nl; } diff --git a/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.H b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.H index 33f877d1e2..1b32cecae0 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.H +++ b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.H @@ -116,7 +116,7 @@ public: ) const; //- Write in dictionary format - virtual void writeData(Ostream& os) const; + virtual void write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.C b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.C index a330643d27..60083544c4 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.C +++ b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.C @@ -25,6 +25,15 @@ License #include "Function2.H" +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +Foam::Ostream& Foam::Function2::writeType(Ostream& os) const +{ + return writeKeyword(os, name_) << type(); +} + + // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // template @@ -95,9 +104,16 @@ const Foam::word& Foam::Function2::name() const template -void Foam::Function2::writeData(Ostream& os) const +void Foam::Function2::write(Ostream& os) const { - writeKeyword(os, name_) << type(); + writeKeyword(os, name_) + << nl << indent << token::BEGIN_BLOCK << nl << incrIndent; + + writeEntry(os, "type", type()); + + writeData(os); + + os << decrIndent << indent << token::END_BLOCK << endl; } @@ -125,7 +141,7 @@ Foam::tmp> Foam::FieldFunction2::value template void Foam::writeEntry(Ostream& os, const Function2& f1) { - f1.writeData(os); + f1.write(os); } @@ -144,7 +160,7 @@ Foam::Ostream& Foam::operator<< "Ostream& operator<<(Ostream&, const Function2&)" ); - f1.writeData(os); + f1.write(os); return os; } diff --git a/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.H b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.H index 86ef98a278..02a53d5b7f 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.H +++ b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.H @@ -71,6 +71,15 @@ protected: const word name_; + // Protected member functions + + Ostream& writeType(Ostream& os) const; + + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const + {} + + public: typedef Type returnType; @@ -132,7 +141,7 @@ public: ) const = 0; //- Write in dictionary format - virtual void writeData(Ostream& os) const; + virtual void write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function2/Function2/Function2New.C b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2New.C index 7ce0326d97..7096900c7d 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Function2/Function2New.C +++ b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2New.C @@ -90,13 +90,7 @@ Foam::autoPtr> Foam::Function2::New << exit(FatalError); } - return cstrIter() - ( - entryName, - dict.found(entryName + "Coeffs") - ? dict.subDict(entryName + "Coeffs") - : dict - ); + return cstrIter()(entryName, dict); } } diff --git a/src/OpenFOAM/primitives/functions/Function2/One/OneConstant2.C b/src/OpenFOAM/primitives/functions/Function2/One/OneConstant2.C index e0e90cc320..080ab3a15a 100644 --- a/src/OpenFOAM/primitives/functions/Function2/One/OneConstant2.C +++ b/src/OpenFOAM/primitives/functions/Function2/One/OneConstant2.C @@ -55,11 +55,9 @@ Foam::Function2s::OneConstant::~OneConstant() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void Foam::Function2s::OneConstant::writeData(Ostream& os) const +void Foam::Function2s::OneConstant::write(Ostream& os) const { - Function2::writeData(os); - - os << token::END_STATEMENT << nl; + this->writeType(os) << token::END_STATEMENT << nl; } diff --git a/src/OpenFOAM/primitives/functions/Function2/One/OneConstant2.H b/src/OpenFOAM/primitives/functions/Function2/One/OneConstant2.H index dffcdc43b0..21fd84bef8 100644 --- a/src/OpenFOAM/primitives/functions/Function2/One/OneConstant2.H +++ b/src/OpenFOAM/primitives/functions/Function2/One/OneConstant2.H @@ -91,7 +91,7 @@ public: ) const; //- Write in dictionary format - virtual void writeData(Ostream& os) const; + virtual void write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function2/Scale/Scale2.C b/src/OpenFOAM/primitives/functions/Function2/Scale/Scale2.C index 716660008b..d63ffd0874 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Scale/Scale2.C +++ b/src/OpenFOAM/primitives/functions/Function2/Scale/Scale2.C @@ -49,6 +49,16 @@ void Foam::Function2s::Scale::read(const dictionary& coeffs) } +template +void Foam::Function2s::Scale::writeData(Ostream& os) const +{ + scale_->write(os); + xScale_->write(os); + yScale_->write(os); + value_->write(os); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -82,21 +92,4 @@ Foam::Function2s::Scale::~Scale() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::Function2s::Scale::writeData(Ostream& os) const -{ - Function2::writeData(os); - os << token::END_STATEMENT << nl; - os << indent << word(this->name() + "Coeffs") << nl; - os << indent << token::BEGIN_BLOCK << incrIndent << nl; - scale_->writeData(os); - xScale_->writeData(os); - yScale_->writeData(os); - value_->writeData(os); - os << decrIndent << indent << token::END_BLOCK << endl; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function2/Scale/Scale2.H b/src/OpenFOAM/primitives/functions/Function2/Scale/Scale2.H index 582ac9e0de..3279a53aa0 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Scale/Scale2.H +++ b/src/OpenFOAM/primitives/functions/Function2/Scale/Scale2.H @@ -80,6 +80,9 @@ class Scale //- Read the coefficients from the given dictionary void read(const dictionary& coeffs); + //- Write data to dictionary stream + virtual void writeData(Ostream& os) const; + public: @@ -106,9 +109,6 @@ public: // Member Functions - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - //- Return value virtual inline Type value(const scalar x, const scalar y) const; diff --git a/src/OpenFOAM/primitives/functions/Function2/Zero/ZeroConstant2.C b/src/OpenFOAM/primitives/functions/Function2/Zero/ZeroConstant2.C index 244724d58e..5e287f01d5 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Zero/ZeroConstant2.C +++ b/src/OpenFOAM/primitives/functions/Function2/Zero/ZeroConstant2.C @@ -48,11 +48,9 @@ Foam::Function2s::ZeroConstant::~ZeroConstant() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void Foam::Function2s::ZeroConstant::writeData(Ostream& os) const +void Foam::Function2s::ZeroConstant::write(Ostream& os) const { - Function2::writeData(os); - - os << token::END_STATEMENT << nl; + this->writeType(os) << token::END_STATEMENT << nl; } diff --git a/src/OpenFOAM/primitives/functions/Function2/Zero/ZeroConstant2.H b/src/OpenFOAM/primitives/functions/Function2/Zero/ZeroConstant2.H index 442ac5bd47..fc82966fc5 100644 --- a/src/OpenFOAM/primitives/functions/Function2/Zero/ZeroConstant2.H +++ b/src/OpenFOAM/primitives/functions/Function2/Zero/ZeroConstant2.H @@ -88,7 +88,7 @@ public: ) const; //- Write in dictionary format - virtual void writeData(Ostream& os) const; + virtual void write(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.C b/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.C index 508367f9bc..9eca8f6448 100644 --- a/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.C +++ b/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -120,9 +120,9 @@ Foam::Ostream& Foam::operator<< template -void Foam::TimeFunction1::writeData(Ostream& os) const +void Foam::TimeFunction1::write(Ostream& os) const { - function_->writeData(os); + function_->write(os); } diff --git a/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.H b/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.H index 5de934d64b..6e9c0f4fe2 100644 --- a/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.H +++ b/src/OpenFOAM/primitives/functions/TimeFunction1/TimeFunction1.H @@ -128,7 +128,7 @@ public: ); //- Write in dictionary format - virtual void writeData(Ostream& os) const; + virtual void write(Ostream& os) const; }; diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C index 41e405865b..048381d59e 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -577,7 +577,7 @@ void Foam::MRFZone::writeData(Ostream& os) const writeEntry(os, "cellZone", cellZoneName_); writeEntry(os, "origin", origin_); writeEntry(os, "axis", axis_); - omega_->writeData(os); + omega_->write(os); if (excludedPatchNames_.size()) { diff --git a/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion/restraints/axialAngularSpring/axialAngularSpring.C b/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion/restraints/axialAngularSpring/axialAngularSpring.C index ea5b8c710e..8466d9d9b1 100644 --- a/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion/restraints/axialAngularSpring/axialAngularSpring.C +++ b/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion/restraints/axialAngularSpring/axialAngularSpring.C @@ -209,7 +209,7 @@ void Foam::sixDoFRigidBodyMotionRestraints::axialAngularSpring::write writeEntry(os, "axis", axis_); - moment_->writeData(os); + moment_->write(os); writeKeyword(os, "angleFormat"); diff --git a/tutorials/incompressible/pimpleFoam/RAS/TJunction/0/p b/tutorials/incompressible/pimpleFoam/RAS/TJunction/0/p index d7da6c1a97..3890a0d08a 100644 --- a/tutorials/incompressible/pimpleFoam/RAS/TJunction/0/p +++ b/tutorials/incompressible/pimpleFoam/RAS/TJunction/0/p @@ -23,11 +23,16 @@ boundaryField inlet { type uniformTotalPressure; - p0 table - ( - (0 10) - (1 40) - ); + p0 + { + type table; + + values + ( + (0 10) + (1 40) + ); + } } outlet1