ENH: Function1 and PatchFunction1 improvements (#1917)

- easier support for non-mandatory functions.

  In some boundary conditions it can be desirable to support
  additional functions, but not necessarily require them. Make this
  easier to support with a Function1, PatchFunction1 NewIfPresent()
  selector.

- support for compatibility lookups

- harmonize branching logic and error handling between Function1 and
  PatchFunction1.

ENH: refactor a base class for Function1, PatchFunction1

- includes base characteristics, patch or scalar information

ENH: additional creation macros

- makeConcreteFunction1, makeConcretePatchFunction1Type for adding a
  non-templated function into the correct templated selection table.
  makeScalarPatchFunction1 for similarity with makeScalarFunction1
This commit is contained in:
Mark Olesen
2020-11-12 10:16:06 +01:00
parent 4b964f676e
commit 2f2dcdcf6f
58 changed files with 1295 additions and 648 deletions

View File

@ -90,7 +90,7 @@ ${typeName}PatchFunction1${FieldType}::
${typeName}PatchFunction1${FieldType} ${typeName}PatchFunction1${FieldType}
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues const bool faceValues

View File

@ -75,7 +75,7 @@ public:
${typeName}PatchFunction1${FieldType} ${typeName}PatchFunction1${FieldType}
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues = true const bool faceValues = true
@ -84,13 +84,13 @@ public:
//- Copy construct //- Copy construct
${typeName}PatchFunction1${FieldType} ${typeName}PatchFunction1${FieldType}
( (
const ${typeName}PatchFunction1${FieldType}& const ${typeName}PatchFunction1${FieldType}& rhs
); );
//- Copy construct, resetting patch //- Copy construct, resetting patch
${typeName}PatchFunction1${FieldType} ${typeName}PatchFunction1${FieldType}
( (
const ${typeName}PatchFunction1${FieldType}&, const ${typeName}PatchFunction1${FieldType}& rhs,
const polyPatch& pp const polyPatch& pp
); );

View File

@ -106,6 +106,7 @@ primitives/septernion/septernion.C
primitives/triad/triad.C primitives/triad/triad.C
/* Run-time selectable functions */ /* Run-time selectable functions */
primitives/functions/Function1/Function1/function1Base.C
primitives/functions/Function1/makeFunction1s.C primitives/functions/Function1/makeFunction1s.C
primitives/functions/Function1/ramp/ramp.C primitives/functions/Function1/ramp/ramp.C
primitives/functions/Function1/step/stepFunction.C primitives/functions/Function1/step/stepFunction.C

View File

@ -36,7 +36,7 @@ Foam::Function1Types::Function1Expression<Type>::Function1Expression
const dictionary& dict const dictionary& dict
) )
: :
Function1<Type>(entryName), Function1<Type>(entryName, dict),
dict_(dict), dict_(dict),
valueExpr_(), valueExpr_(),
driver_(1, dict_) driver_(1, dict_)

View File

@ -99,27 +99,22 @@ class Function1Expression
mutable expressions::fieldExprDriver driver_; mutable expressions::fieldExprDriver driver_;
// Private Member Functions
//- No copy assignment
void operator=(const Function1Expression<Type>&) = delete;
public: public:
//- Runtime type information //- Runtime type information
TypeName("expression"); TypeName("expression");
// Generated Methods
//- No copy assignment
void operator=(const Function1Expression<Type>&) = delete;
// Constructors // Constructors
//- Construct from patch, entry name and dictionary //- Construct from entry name and dictionary
// The patch must correspond to an fvPatch! Function1Expression(const word& entryName, const dictionary& dict);
Function1Expression
(
const word& entryName,
const dictionary& dict
);
//- Copy construct //- Copy construct
explicit Function1Expression(const Function1Expression<Type>& rhs); explicit Function1Expression(const Function1Expression<Type>& rhs);

View File

@ -250,13 +250,8 @@ const Foam::fileName& Foam::Function1Types::CSV<Type>::fName() const
template<class Type> template<class Type>
void Foam::Function1Types::CSV<Type>::writeData(Ostream& os) const void Foam::Function1Types::CSV<Type>::writeEntries(Ostream& os) const
{ {
Function1<Type>::writeData(os);
os.endEntry();
os.beginBlock(word(this->name() + "Coeffs"));
// Note: for TableBase write the dictionary entries it needs but not // Note: for TableBase write the dictionary entries it needs but not
// the values themselves // the values themselves
TableBase<Type>::writeEntries(os); TableBase<Type>::writeEntries(os);
@ -273,7 +268,17 @@ void Foam::Function1Types::CSV<Type>::writeData(Ostream& os) const
os.writeEntry("separator", string(separator_)); os.writeEntry("separator", string(separator_));
os.writeEntry("mergeSeparators", mergeSeparators_); os.writeEntry("mergeSeparators", mergeSeparators_);
os.writeEntry("file", fName_); os.writeEntry("file", fName_);
}
template<class Type>
void Foam::Function1Types::CSV<Type>::writeData(Ostream& os) const
{
Function1<Type>::writeData(os);
os.endEntry();
os.beginBlock(word(this->name() + "Coeffs"));
writeEntries(os);
os.endBlock(); os.endBlock();
} }

View File

@ -154,6 +154,9 @@ public:
//- Write in dictionary format //- Write in dictionary format
virtual void writeData(Ostream& os) const; virtual void writeData(Ostream& os) const;
//- Write coefficient entries in dictionary format
void writeEntries(Ostream& os) const;
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015 OpenCFD Ltd. Copyright (C) 2015-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -49,7 +49,7 @@ Foam::Function1Types::Constant<Type>::Constant
const dictionary& dict const dictionary& dict
) )
: :
Function1<Type>(entryName), Function1<Type>(entryName, dict),
value_(Zero) value_(Zero)
{ {
Istream& is = dict.lookup(entryName); Istream& is = dict.lookup(entryName);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015 OpenCFD Ltd. Copyright (C) 2015-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -61,24 +61,25 @@ class Constant
: :
public Function1<Type> public Function1<Type>
{ {
// Private data // Private Data
//- Constant value //- Constant value
Type value_; Type value_;
// Private Member Functions
//- No copy assignment
void operator=(const Constant<Type>&) = delete;
public: public:
// Runtime type information // Runtime type information
TypeName("constant"); TypeName("constant");
// Generated Methods
//- No copy assignment
void operator=(const Constant<Type>&) = delete;
// Constructors // Constructors
//- Construct from components //- Construct from components

View File

@ -36,32 +36,26 @@ License
template<class Type> template<class Type>
Foam::Function1<Type>::Function1(const word& entryName) Foam::Function1<Type>::Function1(const word& entryName)
: :
name_(entryName) function1Base(entryName)
{}
template<class Type>
Foam::Function1<Type>::Function1(const word& entryName, const dictionary& dict)
:
function1Base(entryName, dict)
{} {}
template<class Type> template<class Type>
Foam::Function1<Type>::Function1(const Function1<Type>& rhs) Foam::Function1<Type>::Function1(const Function1<Type>& rhs)
: :
refCount(), function1Base(rhs)
name_(rhs.name_)
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const Foam::word& Foam::Function1<Type>::name() const
{
return name_;
}
template<class Type>
void Foam::Function1<Type>::convertTimeBase(const Time&)
{}
template<class Type> template<class Type>
Type Foam::Function1<Type>::value(const scalar x) const Type Foam::Function1<Type>::value(const scalar x) const
{ {
@ -71,7 +65,8 @@ Type Foam::Function1<Type>::value(const scalar x) const
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::value Foam::tmp<Foam::Field<Type>>
Foam::Function1<Type>::value
( (
const scalarField& x const scalarField& x
) const ) const
@ -90,7 +85,8 @@ Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::integrate Foam::tmp<Foam::Field<Type>>
Foam::Function1<Type>::integrate
( (
const scalarField& x1, const scalarField& x1,
const scalarField& x2 const scalarField& x2
@ -161,6 +157,11 @@ Foam::FieldFunction1<Function1Type>::integrate
} }
template<class Type>
void Foam::Function1<Type>::writeEntries(Ostream& os) const
{}
template<class Type> template<class Type>
void Foam::Function1<Type>::writeData(Ostream& os) const void Foam::Function1<Type>::writeData(Ostream& os) const
{ {
@ -179,7 +180,7 @@ Foam::Ostream& Foam::operator<<
{ {
os.check(FUNCTION_NAME); os.check(FUNCTION_NAME);
os << rhs.name_; os << rhs.name();
rhs.writeData(os); rhs.writeData(os);
return os; return os;

View File

@ -74,7 +74,7 @@ SourceFiles
#ifndef Function1_H #ifndef Function1_H
#define Function1_H #define Function1_H
#include "dictionary.H" #include "function1Base.H"
#include "Field.H" #include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -94,16 +94,23 @@ template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&);
template<class Type> template<class Type>
class Function1 class Function1
: :
public refCount public function1Base
{ {
// Private Member Functions
//- Selector, with alternative entry, fallback redirection, etc
static autoPtr<Function1<Type>> New
(
const word& entryName, // Entry name for function
const entry* eptr, // Eg, dict.findEntry(entryName)
const dictionary& dict,
const word& redirectType,
const bool mandatory
);
protected: protected:
// Protected Data
//- Name of entry
const word name_;
// Protected Member Functions // Protected Member Functions
//- No copy assignment //- No copy assignment
@ -136,20 +143,52 @@ public:
//- Construct from entry name //- Construct from entry name
explicit Function1(const word& entryName); explicit Function1(const word& entryName);
//- Copy constructor //- Construct from entry name and dictionary
Function1(const word& entryName, const dictionary& dict);
//- Copy construct
explicit Function1(const Function1<Type>& rhs); explicit Function1(const Function1<Type>& rhs);
//- Construct and return a clone //- Construct and return a clone
virtual tmp<Function1<Type>> clone() const = 0; virtual tmp<Function1<Type>> clone() const = 0;
//- Selector // Selectors
static autoPtr<Function1<Type>> New
( //- Selector, with fallback redirection
const word& entryName, static autoPtr<Function1<Type>> New
const dictionary& dict, (
const word& redirectType = word::null const word& entryName,
); const dictionary& dict,
const word& redirectType,
const bool mandatory = true
);
//- Compatibility selector, with fallback redirection
static autoPtr<Function1<Type>> NewCompat
(
const word& entryName,
std::initializer_list<std::pair<const char*,int>> compat,
const dictionary& dict,
const word& redirectType = word::null,
const bool mandatory = true
);
//- Selector, without fallback redirection
static autoPtr<Function1<Type>> New
(
const word& entryName,
const dictionary& dict,
const bool mandatory = true
);
//- An optional selector
static autoPtr<Function1<Type>> NewIfPresent
(
const word& entryName,
const dictionary& dict,
const word& redirectType = word::null
);
//- Destructor //- Destructor
@ -158,18 +197,6 @@ public:
// Member Functions // Member Functions
// Access
//- Return the name of the entry
const word& name() const;
// Manipulation
//- Convert time
virtual void convertTimeBase(const Time& t);
// Evaluation // Evaluation
//- Return value as a function of (scalar) independent variable //- Return value as a function of (scalar) independent variable
@ -189,17 +216,22 @@ public:
) const; ) const;
// I/O // I/O
//- Ostream Operator //- Ostream Operator
friend Ostream& operator<< <Type> friend Ostream& operator<< <Type>
( (
Ostream& os, Ostream& os,
const Function1<Type>& func const Function1<Type>& func
); );
//- Write in dictionary format
virtual void writeData(Ostream& os) const; //- Write in dictionary format.
// \note The base output is \em without an END_STATEMENT
virtual void writeData(Ostream& os) const;
//- Write coefficient entries in dictionary format
void writeEntries(Ostream& os) const;
}; };
@ -212,7 +244,6 @@ class FieldFunction1
: :
public Function1Type public Function1Type
{ {
public: public:
typedef typename Function1Type::returnType Type; typedef typename Function1Type::returnType Type;
@ -256,6 +287,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Define Function1 run-time selection
#define makeFunction1(Type) \ #define makeFunction1(Type) \
\ \
defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \ defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
@ -267,6 +299,7 @@ public:
); );
// Define (templated) Function1, add to (templated) run-time selection
#define makeFunction1Type(SS, Type) \ #define makeFunction1Type(SS, Type) \
\ \
defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \ defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \
@ -276,12 +309,20 @@ public:
add##SS##Type##ConstructorToTable_; add##SS##Type##ConstructorToTable_;
#define makeScalarFunction1(SS) \ // Define a non-templated Function1 and add to (templated) run-time selection
#define makeConcreteFunction1(SS, Type) \
\ \
defineTypeNameAndDebug(SS, 0); \ defineTypeNameAndDebug(SS, 0); \
\ \
Function1<scalar>::adddictionaryConstructorToTable<FieldFunction1<SS>> \ Function1<Type>::adddictionaryConstructorToTable \
add##SS##ConstructorToTable_; <FieldFunction1<SS>> \
add##SS##Type##ConstructorToTable_;
// Define scalar Function1 and add to (templated) run-time selection
#define makeScalarFunction1(SS) \
\
makeConcreteFunction1(SS, scalar);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -35,59 +35,43 @@ Foam::autoPtr<Foam::Function1<Type>>
Foam::Function1<Type>::New Foam::Function1<Type>::New
( (
const word& entryName, const word& entryName,
const entry* eptr,
const dictionary& dict, const dictionary& dict,
const word& redirectType const word& redirectType,
const bool mandatory
) )
{ {
word modelType(redirectType); word modelType(redirectType);
const entry* eptr = dict.findEntry(entryName, keyType::LITERAL); const dictionary* coeffs = (eptr ? eptr->dictPtr() : nullptr);
if (!eptr) if (coeffs)
{ {
if (modelType.empty()) // Dictionary entry
{
FatalIOErrorInFunction(dict)
<< "No Function1 dictionary entry: "
<< entryName << nl << nl
<< exit(FatalIOError);
}
}
else if (eptr->isDict())
{
const dictionary& coeffsDict = eptr->dict();
coeffsDict.readEntry coeffs->readEntry
( (
"type", "type",
modelType, modelType,
keyType::LITERAL, keyType::LITERAL,
redirectType.empty() // mandatory when redirectType is empty modelType.empty() // "type" entry is mandatory if no 'redirect'
); );
auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType); // Fallthrough
if (!cstrIter.found())
{
FatalIOErrorInFunction(dict)
<< "Unknown Function1 type "
<< modelType << " for " << entryName
<< "\n\nValid Function1 types :\n"
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalIOError);
}
return cstrIter()(entryName, coeffsDict);
} }
else else if (eptr)
{ {
// Primitive entry
// - non-word : value for constant function
// - word : the modelType
Istream& is = eptr->stream(); Istream& is = eptr->stream();
token firstToken(is); token firstToken(is);
if (!firstToken.isWord()) if (!firstToken.isWord())
{ {
// Backwards-compatibility for reading straight fields // A value
is.putBack(firstToken); is.putBack(firstToken);
const Type constValue = pTraits<Type>(is); const Type constValue = pTraits<Type>(is);
@ -97,8 +81,40 @@ Foam::Function1<Type>::New
new Function1Types::Constant<Type>(entryName, constValue) new Function1Types::Constant<Type>(entryName, constValue)
); );
} }
else
{
modelType = firstToken.wordToken();
}
modelType = firstToken.wordToken(); // Fallthrough
}
if (modelType.empty())
{
// Entry missing
if (mandatory)
{
FatalIOErrorInFunction(dict)
<< "Missing or invalid Function1 entry: "
<< entryName << nl
<< exit(FatalIOError);
}
return nullptr;
}
else if (!coeffs)
{
// Primitive entry. Coeffs dictionary is optional.
// Use keyword() - not entryName - for compatibility lookup!
coeffs =
&dict.optionalSubDict
(
eptr->keyword() + "Coeffs",
keyType::LITERAL
);
} }
@ -114,12 +130,78 @@ Foam::Function1<Type>::New
<< exit(FatalIOError); << exit(FatalIOError);
} }
return cstrIter() return cstrIter()(entryName, *coeffs);
}
template<class Type>
Foam::autoPtr<Foam::Function1<Type>>
Foam::Function1<Type>::New
(
const word& entryName,
const dictionary& dict,
const word& redirectType,
const bool mandatory
)
{
return Function1<Type>::New
( (
entryName, entryName,
dict.optionalSubDict(entryName + "Coeffs") dict.findEntry(entryName, keyType::LITERAL),
dict,
redirectType,
mandatory
); );
} }
template<class Type>
Foam::autoPtr<Foam::Function1<Type>>
Foam::Function1<Type>::NewCompat
(
const word& entryName,
std::initializer_list<std::pair<const char*,int>> compat,
const dictionary& dict,
const word& redirectType,
const bool mandatory
)
{
return Function1<Type>::New
(
entryName,
dict.findCompat(entryName, compat, keyType::LITERAL),
dict,
redirectType,
mandatory
);
}
template<class Type>
Foam::autoPtr<Foam::Function1<Type>>
Foam::Function1<Type>::New
(
const word& entryName,
const dictionary& dict,
const bool mandatory
)
{
return Function1<Type>::New(entryName, dict, word::null, mandatory);
}
template<class Type>
Foam::autoPtr<Foam::Function1<Type>>
Foam::Function1<Type>::NewIfPresent
(
const word& entryName,
const dictionary& dict,
const word& redirectType
)
{
// mandatory = false
return Function1<Type>::New(entryName, dict, redirectType, false);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "function1Base.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
Foam::function1Base::function1Base(const word& entryName)
:
refCount(),
name_(entryName)
{}
Foam::function1Base::function1Base
(
const word& entryName,
const dictionary& dict
)
:
refCount(),
name_(entryName)
{}
Foam::function1Base::function1Base(const function1Base& rhs)
:
refCount(),
name_(rhs.name_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::function1Base::convertTimeBase(const Time& t)
{}
// ************************************************************************* //

View File

@ -0,0 +1,121 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::function1Base
Description
Top level data entry class for use in dictionaries. Provides a mechanism
to specify a variable as a certain type, e.g. constant or time varying, and
provide functions to return the (interpolated) value, and integral between
limits.
Extends the Function1 class by adding autoMap and rMap functions
SourceFiles
function1Base.C
\*---------------------------------------------------------------------------*/
#ifndef function1Base_H
#define function1Base_H
#include "dictionary.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class Time;
/*---------------------------------------------------------------------------*\
Class function1Base Declaration
\*---------------------------------------------------------------------------*/
class function1Base
:
public refCount
{
protected:
// Protected Data
//- Name of entry
const word name_;
// Protected Member Functions
//- No copy assignment
void operator=(const function1Base&) = delete;
public:
// Constructors
//- Construct from entry name
explicit function1Base(const word& entryName);
//- Construct from entry name and dictionary
function1Base(const word& entryName, const dictionary& dict);
//- Copy construct
explicit function1Base(const function1Base& rhs);
//- Destructor
virtual ~function1Base() = default;
// Member Functions
// Access
//- The name of the entry
const word& name() const
{
return name_;
}
// Manipulation
//- Convert time
virtual void convertTimeBase(const Time& t);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -43,7 +43,7 @@ Foam::Function1Types::OneConstant<Type>::OneConstant
const dictionary& dict const dictionary& dict
) )
: :
Function1<Type>(entryName) Function1<Type>(entryName, dict)
{} {}

View File

@ -61,18 +61,18 @@ class OneConstant
: :
public Function1<Type> public Function1<Type>
{ {
// Private Member Functions
//- No copy assignment
void operator=(const OneConstant<Type>&) = delete;
public: public:
//- Runtime type information //- Runtime type information
TypeName("one"); TypeName("one");
// Generated Methods
//- No copy assignment
void operator=(const OneConstant<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name //- Construct from entry name

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,7 +37,7 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
const dictionary& dict const dictionary& dict
) )
: :
Function1<Type>(entryName), Function1<Type>(entryName, dict),
coeffs_(), coeffs_(),
canIntegrate_(true) canIntegrate_(true)
{ {
@ -48,8 +49,9 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
if (!coeffs_.size()) if (!coeffs_.size())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Polynomial coefficients for entry " << this->name_ << "Invalid (empty) polynomial coefficients for "
<< " are invalid (empty)" << nl << exit(FatalError); << this->name() << nl
<< exit(FatalError);
} }
forAll(coeffs_, i) forAll(coeffs_, i)
@ -66,7 +68,7 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
if (!canIntegrate_) if (!canIntegrate_)
{ {
WarningInFunction WarningInFunction
<< "Polynomial " << this->name_ << " cannot be integrated" << "Polynomial " << this->name() << " cannot be integrated"
<< endl; << endl;
} }
} }
@ -87,8 +89,9 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
if (!coeffs_.size()) if (!coeffs_.size())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Polynomial coefficients for entry " << this->name_ << "Invalid (empty) polynomial coefficients for "
<< " are invalid (empty)" << nl << exit(FatalError); << this->name() << nl
<< exit(FatalError);
} }
forAll(coeffs_, i) forAll(coeffs_, i)
@ -105,7 +108,7 @@ Foam::Function1Types::Polynomial<Type>::Polynomial
if (!canIntegrate_) if (!canIntegrate_)
{ {
WarningInFunction WarningInFunction
<< "Polynomial " << this->name_ << " cannot be integrated" << "Polynomial " << this->name() << " cannot be integrated"
<< endl; << endl;
} }
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -61,6 +62,14 @@ Foam::Function1Types::Scale<Type>::Scale(const Scale<Type>& rhs)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::Function1Types::Scale<Type>::writeEntries(Ostream& os) const
{
scale_->writeData(os);
value_->writeData(os);
}
template<class Type> template<class Type>
void Foam::Function1Types::Scale<Type>::writeData(Ostream& os) const void Foam::Function1Types::Scale<Type>::writeData(Ostream& os) const
{ {
@ -68,10 +77,7 @@ void Foam::Function1Types::Scale<Type>::writeData(Ostream& os) const
os << token::END_STATEMENT << nl; os << token::END_STATEMENT << nl;
os.beginBlock(word(this->name() + "Coeffs")); os.beginBlock(word(this->name() + "Coeffs"));
writeEntries(os);
scale_->writeData(os);
value_->writeData(os);
os.endBlock(); os.endBlock();
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -106,9 +107,6 @@ class Scale
//- Read the coefficients from the given dictionary //- Read the coefficients from the given dictionary
void read(const dictionary& coeffs); void read(const dictionary& coeffs);
//- No copy assignment
void operator=(const Scale<Type>&) = delete;
public: public:
@ -116,6 +114,12 @@ public:
TypeName("scale"); TypeName("scale");
// Generated Methods
//- No copy assignment
void operator=(const Scale<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
@ -140,6 +144,9 @@ public:
//- Write in dictionary format //- Write in dictionary format
virtual void writeData(Ostream& os) const; virtual void writeData(Ostream& os) const;
//- Write coefficient entries in dictionary format
void writeEntries(Ostream& os) const;
}; };

View File

@ -48,7 +48,7 @@ Foam::Function1Types::Sine<Type>::Sine
const dictionary& dict const dictionary& dict
) )
: :
Function1<Type>(entryName) Function1<Type>(entryName, dict)
{ {
read(dict); read(dict);
} }
@ -68,6 +68,17 @@ Foam::Function1Types::Sine<Type>::Sine(const Sine<Type>& se)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::Function1Types::Sine<Type>::writeEntries(Ostream& os) const
{
os.writeEntry("t0", t0_);
amplitude_->writeData(os);
frequency_->writeData(os);
scale_->writeData(os);
level_->writeData(os);
}
template<class Type> template<class Type>
void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const
{ {
@ -75,13 +86,7 @@ void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const
os.endEntry(); os.endEntry();
os.beginBlock(word(this->name() + "Coeffs")); os.beginBlock(word(this->name() + "Coeffs"));
writeEntries(os);
os.writeEntry("t0", t0_);
amplitude_->writeData(os);
frequency_->writeData(os);
scale_->writeData(os);
level_->writeData(os);
os.endBlock(); os.endBlock();
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -118,16 +119,18 @@ class Sine
//- Read the coefficients from the given dictionary //- Read the coefficients from the given dictionary
void read(const dictionary& coeffs); void read(const dictionary& coeffs);
//- No copy assignment
void operator=(const Sine<Type>&) = delete;
public: public:
// Runtime type information // Runtime type information
TypeName("sine"); TypeName("sine");
// Generated Methods
//- No copy assignment
void operator=(const Sine<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
@ -152,6 +155,9 @@ public:
//- Write in dictionary format //- Write in dictionary format
virtual void writeData(Ostream& os) const; virtual void writeData(Ostream& os) const;
//- Write coefficient entries in dictionary format
void writeEntries(Ostream& os) const;
}; };

View File

@ -49,7 +49,7 @@ Foam::Function1Types::Square<Type>::Square
const dictionary& dict const dictionary& dict
) )
: :
Function1<Type>(entryName) Function1<Type>(entryName, dict)
{ {
read(dict); read(dict);
} }
@ -71,20 +71,25 @@ Foam::Function1Types::Square<Type>::Square(const Square<Type>& se)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
void Foam::Function1Types::Square<Type>::writeData(Ostream& os) const void Foam::Function1Types::Square<Type>::writeEntries(Ostream& os) const
{ {
Function1<Type>::writeData(os);
os.endEntry();
os.beginBlock(word(this->name() + "Coeffs"));
os.writeEntry("t0", t0_); os.writeEntry("t0", t0_);
os.writeEntry("markSpace", markSpace_); os.writeEntry("markSpace", markSpace_);
amplitude_->writeData(os); amplitude_->writeData(os);
frequency_->writeData(os); frequency_->writeData(os);
scale_->writeData(os); scale_->writeData(os);
level_->writeData(os); level_->writeData(os);
}
template<class Type>
void Foam::Function1Types::Square<Type>::writeData(Ostream& os) const
{
Function1<Type>::writeData(os);
os.endEntry();
os.beginBlock(word(this->name() + "Coeffs"));
writeEntries(os);
os.endBlock(); os.endBlock();
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -125,9 +126,6 @@ class Square
//- Read the coefficients from the given dictionary //- Read the coefficients from the given dictionary
void read(const dictionary& coeffs); void read(const dictionary& coeffs);
//- No copy assignment
void operator=(const Square<Type>&) = delete;
public: public:
@ -135,6 +133,12 @@ public:
TypeName("square"); TypeName("square");
// Generated Methods
//- No copy assignment
void operator=(const Square<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
@ -159,6 +163,9 @@ public:
//- Write in dictionary format //- Write in dictionary format
virtual void writeData(Ostream& os) const; virtual void writeData(Ostream& os) const;
//- Write coefficient entries in dictionary format
void writeEntries(Ostream& os) const;
}; };

View File

@ -65,8 +65,7 @@ Foam::Function1Types::TableBase<Type>::TableBase
const dictionary& dict const dictionary& dict
) )
: :
Function1<Type>(name), Function1<Type>(name, dict),
name_(name),
bounding_ bounding_
( (
bounds::repeatableBoundingNames.getOrDefault bounds::repeatableBoundingNames.getOrDefault
@ -91,7 +90,6 @@ template<class Type>
Foam::Function1Types::TableBase<Type>::TableBase(const TableBase<Type>& tbl) Foam::Function1Types::TableBase<Type>::TableBase(const TableBase<Type>& tbl)
: :
Function1<Type>(tbl), Function1<Type>(tbl),
name_(tbl.name_),
bounding_(tbl.bounding_), bounding_(tbl.bounding_),
interpolationScheme_(tbl.interpolationScheme_), interpolationScheme_(tbl.interpolationScheme_),
table_(tbl.table_), table_(tbl.table_),
@ -115,7 +113,7 @@ void Foam::Function1Types::TableBase<Type>::check() const
if (!table_.size()) if (!table_.size())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Table for entry " << this->name_ << " is invalid (empty)" << "Table for entry " << this->name() << " is invalid (empty)"
<< nl << exit(FatalError); << nl << exit(FatalError);
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -65,9 +66,6 @@ protected:
// Protected Data // Protected Data
//- Table name
const word name_;
//- Handling for out-of-bound values //- Handling for out-of-bound values
const bounds::repeatableBounding bounding_; const bounds::repeatableBounding bounding_;

View File

@ -59,9 +59,7 @@ SourceFiles
#ifndef TableFile_H #ifndef TableFile_H
#define TableFile_H #define TableFile_H
#include "Function1.H"
#include "TableBase.H" #include "TableBase.H"
#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -44,7 +44,7 @@ Foam::Function1Types::ZeroConstant<Type>::ZeroConstant
const dictionary& dict const dictionary& dict
) )
: :
Function1<Type>(entryName) Function1<Type>(entryName, dict)
{} {}

View File

@ -61,18 +61,18 @@ class ZeroConstant
: :
public Function1<Type> public Function1<Type>
{ {
// Private Member Functions
//- No copy assignment
void operator=(const ZeroConstant<Type>&) = delete;
public: public:
//- Runtime type information //- Runtime type information
TypeName("zero"); TypeName("zero");
// Generated Methods
//- No copy assignment
void operator=(const ZeroConstant<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name //- Construct from entry name

View File

@ -29,7 +29,7 @@ Class
Description Description
Quadratic ramp function starting from 0 and increasing quadratically Quadratic ramp function starting from 0 and increasing quadratically
to 1 from \c t_0 over the \c duration and remaining at 1 thereafter. to 1 from \c start over the \c duration and remaining at 1 thereafter.
See also See also
Foam::Function1Types::ramp Foam::Function1Types::ramp

View File

@ -43,7 +43,7 @@ Foam::Function1Types::ramp::ramp
const dictionary& dict const dictionary& dict
) )
: :
Function1<scalar>(entryName) Function1<scalar>(entryName, dict)
{ {
read(dict); read(dict);
} }
@ -51,16 +51,20 @@ Foam::Function1Types::ramp::ramp
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::Function1Types::ramp::writeEntries(Ostream& os) const
{
os.writeEntry("start", start_);
os.writeEntry("duration", duration_);
}
void Foam::Function1Types::ramp::writeData(Ostream& os) const void Foam::Function1Types::ramp::writeData(Ostream& os) const
{ {
Function1<scalar>::writeData(os); Function1<scalar>::writeData(os);
os << token::END_STATEMENT << nl; os << token::END_STATEMENT << nl;
os.beginBlock(word(this->name() + "Coeffs")); os.beginBlock(word(this->name() + "Coeffs"));
writeEntries(os);
os.writeEntry("start", start_);
os.writeEntry("duration", duration_);
os.endBlock(); os.endBlock();
} }

View File

@ -138,6 +138,9 @@ public:
//- Write in dictionary format //- Write in dictionary format
virtual void writeData(Ostream& os) const; virtual void writeData(Ostream& os) const;
//- Write coefficient entries in dictionary format
void writeEntries(Ostream& os) const;
}; };

View File

@ -34,7 +34,7 @@ template<class Type>
Foam::PatchFunction1Types::PatchExprField<Type>::PatchExprField Foam::PatchFunction1Types::PatchExprField<Type>::PatchExprField
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues const bool faceValues
@ -72,10 +72,7 @@ Foam::PatchFunction1Types::PatchExprField<Type>::PatchExprField
const PatchExprField<Type>& rhs const PatchExprField<Type>& rhs
) )
: :
PatchFunction1<Type>(rhs), PatchExprField<Type>(rhs, rhs.patch())
dict_(rhs.dict_),
valueExpr_(rhs.valueExpr_),
driver_(fvPatch::lookupPatch(this->patch()), rhs.driver_)
{} {}
@ -156,7 +153,7 @@ void Foam::PatchFunction1Types::PatchExprField<Type>::writeData
Ostream& os Ostream& os
) const ) const
{ {
// PatchFunction1-from-subdict so out dictionary contains // PatchFunction1-from-subdict so output dictionary contains
// only the relevant entries. // only the relevant entries.
dict_.writeEntry(this->name(), os); dict_.writeEntry(this->name(), os);
} }

View File

@ -97,18 +97,18 @@ class PatchExprField
mutable expressions::patchExpr::parseDriver driver_; mutable expressions::patchExpr::parseDriver driver_;
// Private Member Functions
//- No copy assignment
void operator=(const PatchExprField<Type>&) = delete;
public: public:
//- Runtime type information //- Runtime type information
TypeName("expression"); TypeName("expression");
// Generated Methods
//- No copy assignment
void operator=(const PatchExprField<Type>&) = delete;
// Constructors // Constructors
//- Construct from patch, entry name and dictionary //- Construct from patch, entry name and dictionary
@ -116,7 +116,7 @@ public:
PatchExprField PatchExprField
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues = true const bool faceValues = true

View File

@ -53,7 +53,7 @@ template<class Type>
Foam::PatchFunction1Types::Sampled<Type>::Sampled Foam::PatchFunction1Types::Sampled<Type>::Sampled
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues const bool faceValues
@ -76,31 +76,26 @@ Foam::PatchFunction1Types::Sampled<Type>::Sampled
template<class Type> template<class Type>
Foam::PatchFunction1Types::Sampled<Type>::Sampled Foam::PatchFunction1Types::Sampled<Type>::Sampled
( (
const Sampled<Type>& ut const Sampled<Type>& rhs
) )
: :
PatchFunction1<Type>(ut), Sampled<Type>(rhs, rhs.patch())
mappedPatchBase(ut),
fieldName_(ut.fieldName_),
setAverage_(ut.setAverage_),
average_(ut.average_),
interpolationScheme_(ut.interpolationScheme_)
{} {}
template<class Type> template<class Type>
Foam::PatchFunction1Types::Sampled<Type>::Sampled Foam::PatchFunction1Types::Sampled<Type>::Sampled
( (
const Sampled<Type>& ut, const Sampled<Type>& rhs,
const polyPatch& pp const polyPatch& pp
) )
: :
PatchFunction1<Type>(ut, pp), PatchFunction1<Type>(rhs, pp),
mappedPatchBase(pp, ut), mappedPatchBase(pp, rhs),
fieldName_(ut.fieldName_), fieldName_(rhs.fieldName_),
setAverage_(ut.setAverage_), setAverage_(rhs.setAverage_),
average_(ut.average_), average_(rhs.average_),
interpolationScheme_(ut.interpolationScheme_) interpolationScheme_(rhs.interpolationScheme_)
{} {}
@ -286,7 +281,7 @@ Foam::PatchFunction1Types::Sampled<Type>::value
if (setAverage_ && returnReduce(newValues.size(), sumOp<label>())) if (setAverage_ && returnReduce(newValues.size(), sumOp<label>()))
{ {
Type averagePsi; Type averagePsi;
if (this->faceValues_) if (this->faceValues())
{ {
const scalarField magSf const scalarField magSf
( (

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -86,7 +86,7 @@ namespace PatchFunction1Types
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class Sampled Declaration Class Sampled Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type> template<class Type>
@ -124,9 +124,6 @@ protected:
//- Field to sample. Either on my or nbr mesh //- Field to sample. Either on my or nbr mesh
bool haveSampleField() const; bool haveSampleField() const;
//- No copy assignment
void operator=(const Sampled<Type>&) = delete;
public: public:
@ -134,25 +131,31 @@ public:
TypeName("sampled"); TypeName("sampled");
// Generated Methods
//- No copy assignment
void operator=(const Sampled<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
Sampled Sampled
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues = true const bool faceValues = true
); );
//- Copy constructor //- Copy construct
explicit Sampled(const Sampled<Type>& ut); explicit Sampled(const Sampled<Type>& rhs);
//- Copy constructor setting patch //- Copy construct setting patch
explicit Sampled explicit Sampled
( (
const Sampled<Type>& ut, const Sampled<Type>& rhs,
const polyPatch& pp const polyPatch& pp
); );

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -56,13 +56,8 @@ surfaceNormalFixedValueFvPatchVectorField
: :
fixedValueFvPatchVectorField(p, iF, dict, false), fixedValueFvPatchVectorField(p, iF, dict, false),
refValue_("refValue", dict, p.size()), refValue_("refValue", dict, p.size()),
ramp_(nullptr) ramp_(Function1<scalar>::NewIfPresent("ramp", dict))
{ {
if (dict.found("ramp"))
{
ramp_ = Function1<scalar>::New("ramp", dict);
}
tmp<vectorField> tvalues(refValue_*patch().nf()); tmp<vectorField> tvalues(refValue_*patch().nf());
if (ramp_) if (ramp_)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -55,13 +55,8 @@ uniformNormalFixedValueFvPatchVectorField
: :
fixedValueFvPatchVectorField(p, iF, dict, false), fixedValueFvPatchVectorField(p, iF, dict, false),
uniformValue_(PatchFunction1<scalar>::New(p.patch(), "uniformValue", dict)), uniformValue_(PatchFunction1<scalar>::New(p.patch(), "uniformValue", dict)),
ramp_(nullptr) ramp_(Function1<scalar>::NewIfPresent("ramp", dict))
{ {
if (dict.found("ramp"))
{
ramp_ = Function1<scalar>::New("ramp", dict);
}
if (dict.found("value")) if (dict.found("value"))
{ {
fvPatchVectorField::operator= fvPatchVectorField::operator=

View File

@ -85,13 +85,8 @@ timeVaryingMappedFixedValuePointPatchField
endSampleTime_(-1), endSampleTime_(-1),
endSampledValues_(0), endSampledValues_(0),
endAverage_(Zero), endAverage_(Zero),
offset_() offset_(Function1<Type>::NewIfPresent("offset", dict))
{ {
if (dict.found("offset"))
{
offset_ = Function1<Type>::New("offset", dict);
}
if if
( (
mapMethod_ != "planarInterpolation" mapMethod_ != "planarInterpolation"

View File

@ -305,8 +305,10 @@ mappedPatches/mappedPointPatch/mappedWallPointPatch.C
polyTopoChange/topoAction/topoActions.C polyTopoChange/topoAction/topoActions.C
polyTopoChange/polyTopoChange.C polyTopoChange/polyTopoChange.C
/* Run-time selectable functions */
PatchFunction1/PatchFunction1/patchFunction1Base.C
PatchFunction1/makePatchFunction1s.C PatchFunction1/makePatchFunction1s.C
PatchFunction1/coordinateLabelScaling.C PatchFunction1/coordinateScaling/coordinateScalings.C
PatchFunction1/CodedField/makeCodedFields.C PatchFunction1/CodedField/makeCodedFields.C
PatchFunction1/MappedFile/rawIOFields.C PatchFunction1/MappedFile/rawIOFields.C

View File

@ -135,7 +135,7 @@ template<class Type>
Foam::PatchFunction1Types::CodedField<Type>::CodedField Foam::PatchFunction1Types::CodedField<Type>::CodedField
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues const bool faceValues
@ -156,10 +156,7 @@ Foam::PatchFunction1Types::CodedField<Type>::CodedField
const CodedField<Type>& rhs const CodedField<Type>& rhs
) )
: :
PatchFunction1<Type>(rhs), CodedField<Type>(rhs, rhs.patch())
codedBase(),
dict_(rhs.dict_),
name_(rhs.name_)
{} {}
@ -202,7 +199,7 @@ Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const
this->patch(), this->patch(),
name_, name_,
dict, dict,
this->faceValues_ this->faceValues()
) )
); );
} }

View File

@ -135,10 +135,6 @@ protected:
// Get the dictionary to initialize the codeContext // Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const; virtual const dictionary& codeDict() const;
//- No copy assignment
void operator=(const CodedField<Type>&) = delete;
public: public:
// Static Data Members // Static Data Members
@ -156,13 +152,19 @@ public:
TypeName("coded"); TypeName("coded");
// Generated Methods
//- No copy assignment
void operator=(const CodedField<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
CodedField CodedField
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues = true const bool faceValues = true

View File

@ -42,7 +42,7 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
PatchFunction1<Type>(pp, entryName, dict, faceValues), PatchFunction1<Type>(pp, entryName, dict, faceValues),
isUniform_(true), isUniform_(true),
uniformValue_(uniformValue), uniformValue_(uniformValue),
value_((faceValues ? pp.size() : pp.nPoints()), uniformValue_) value_(this->size(), uniformValue_)
{} {}
@ -63,24 +63,23 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
uniformValue_(uniformValue), uniformValue_(uniformValue),
value_(fieldValues) value_(fieldValues)
{ {
const label len = (faceValues ? pp.size() : pp.nPoints()); if (fieldValues.size() != this->size())
if (fieldValues.size() != len)
{ {
FatalIOErrorInFunction(dict) FatalIOErrorInFunction(dict)
<< "Supplied field size " << fieldValues.size() << "Supplied field size " << fieldValues.size()
<< " is not equal to the number of " << " is not equal to the number of "
<< (faceValues ? "faces" : "points") << ' ' << (faceValues ? "faces" : "points") << ' '
<< len << " of patch " << pp.name() << nl << this->size() << " of patch " << pp.name() << nl
<< exit(FatalIOError); << exit(FatalIOError);
} }
} }
template<class Type> template<class Type>
Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue Foam::Field<Type>
Foam::PatchFunction1Types::ConstantField<Type>::getValue
( (
const word& keyword, const entry* eptr,
const dictionary& dict, const dictionary& dict,
const label len, const label len,
bool& isUniform, bool& isUniform,
@ -94,7 +93,13 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
if (len) if (len)
{ {
ITstream& is = dict.lookup(keyword); if (!eptr || !eptr->isStream())
{
FatalIOErrorInFunction(dict)
<< "Null or invalid entry" << nl
<< exit(FatalIOError);
}
ITstream& is = eptr->stream();
// Read first token // Read first token
token firstToken(is); token firstToken(is);
@ -172,20 +177,22 @@ template<class Type>
Foam::PatchFunction1Types::ConstantField<Type>::ConstantField Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues const bool faceValues
) )
: :
PatchFunction1<Type>(pp, entryName, dict, faceValues), PatchFunction1<Type>(pp, entryName, dict, faceValues),
isUniform_(true), // overwritten by getValue()
uniformValue_(Zero), // overwritten by getValue()
value_ value_
( (
getValue getValue
( (
entryName, dict.findEntry(entryName, keyType::LITERAL),
dict, dict,
(faceValues ? pp.size() : pp.nPoints()), this->size(),
isUniform_, isUniform_,
uniformValue_ uniformValue_
) )
@ -196,34 +203,54 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
template<class Type> template<class Type>
Foam::PatchFunction1Types::ConstantField<Type>::ConstantField Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
( (
const ConstantField<Type>& cnst const polyPatch& pp,
const entry* eptr,
const word& entryName,
const dictionary& dict,
const bool faceValues
) )
: :
PatchFunction1<Type>(cnst), PatchFunction1<Type>(pp, entryName, dict, faceValues),
isUniform_(cnst.isUniform_), isUniform_(true), // overwritten by getValue()
uniformValue_(cnst.uniformValue_), uniformValue_(Zero), // overwritten by getValue()
value_(cnst.value_) value_
(
getValue
(
eptr,
dict,
this->size(),
isUniform_,
uniformValue_
)
)
{} {}
template<class Type> template<class Type>
Foam::PatchFunction1Types::ConstantField<Type>::ConstantField Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
( (
const ConstantField<Type>& cnst, const ConstantField<Type>& rhs
)
:
ConstantField<Type>(rhs, rhs.patch())
{}
template<class Type>
Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
(
const ConstantField<Type>& rhs,
const polyPatch& pp const polyPatch& pp
) )
: :
PatchFunction1<Type>(cnst, pp), PatchFunction1<Type>(rhs, pp),
isUniform_(cnst.isUniform_), isUniform_(rhs.isUniform_),
uniformValue_(cnst.uniformValue_), uniformValue_(rhs.uniformValue_),
value_(cnst.value_) value_(rhs.value_)
{ {
// If sizes are different... // If sizes are different...
value_.resize value_.resize(this->size(), Zero);
(
(this->faceValues_ ? this->patch_.size() : this->patch_.nPoints()),
Zero
);
if (isUniform_) if (isUniform_)
{ {
@ -272,13 +299,13 @@ void Foam::PatchFunction1Types::ConstantField<Type>::writeData
if (isUniform_) if (isUniform_)
{ {
os.writeKeyword(this->name_) os.writeKeyword(this->name())
<< word("constant") << token::SPACE << uniformValue_ << word("constant") << token::SPACE << uniformValue_
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
else else
{ {
value_.writeEntry(this->name_, os); value_.writeEntry(this->name(), os);
} }
} }

View File

@ -74,11 +74,11 @@ class ConstantField
// Private Member Functions // Private Member Functions
//- Helper to read value from dictionary //- Helper to read value from dictionary entry
static Field<Type> getValue static Field<Type> getValue
( (
const word& keyword, const entry* eptr, // primitiveEntry
const dictionary& dict, const dictionary& dict, // For error context
const label len, const label len,
bool& isUniform, bool& isUniform,
Type& uniformValue Type& uniformValue
@ -122,19 +122,29 @@ public:
ConstantField ConstantField
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName,
const dictionary& dict,
const bool faceValues = true
);
//- Construct from primitive entry, entry name and dictionary
ConstantField
(
const polyPatch& pp,
const entry* eptr,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues = true const bool faceValues = true
); );
//- Copy construct //- Copy construct
explicit ConstantField(const ConstantField<Type>& cnst); explicit ConstantField(const ConstantField<Type>& rhs);
//- Copy constructor setting patch //- Copy construct setting patch
explicit ConstantField explicit ConstantField
( (
const ConstantField<Type>& cnst, const ConstantField<Type>& rhs,
const polyPatch& pp const polyPatch& pp
); );

View File

@ -34,7 +34,7 @@ template<class Type>
Foam::PatchFunction1Types::MappedFile<Type>::MappedFile Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues const bool faceValues
@ -42,8 +42,8 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
: :
PatchFunction1<Type>(pp, entryName, dict, faceValues), PatchFunction1<Type>(pp, entryName, dict, faceValues),
dictConstructed_(true), dictConstructed_(true),
fieldTableName_(entryName),
setAverage_(dict.getOrDefault("setAverage", false)), setAverage_(dict.getOrDefault("setAverage", false)),
fieldTableName_(entryName),
perturb_(dict.getOrDefault<scalar>("perturb", 1e-5)), perturb_(dict.getOrDefault<scalar>("perturb", 1e-5)),
pointsName_(dict.getOrDefault<word>("points", "points")), pointsName_(dict.getOrDefault<word>("points", "points")),
mapMethod_ mapMethod_
@ -62,13 +62,8 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
endSampleTime_(-1), endSampleTime_(-1),
endSampledValues_(0), endSampledValues_(0),
endAverage_(Zero), endAverage_(Zero),
offset_(nullptr) offset_(Function1<Type>::NewIfPresent("offset", dict))
{ {
if (dict.found("offset"))
{
offset_ = Function1<Type>::New("offset", dict);
}
if if
( (
mapMethod_ != "planarInterpolation" mapMethod_ != "planarInterpolation"
@ -96,8 +91,8 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
: :
PatchFunction1<Type>(pp, entryName, dict, faceValues), PatchFunction1<Type>(pp, entryName, dict, faceValues),
dictConstructed_(false), dictConstructed_(false),
fieldTableName_(fieldTableName),
setAverage_(dict.getOrDefault("setAverage", false)), setAverage_(dict.getOrDefault("setAverage", false)),
fieldTableName_(fieldTableName),
perturb_(dict.getOrDefault<scalar>("perturb", 1e-5)), perturb_(dict.getOrDefault<scalar>("perturb", 1e-5)),
pointsName_(dict.getOrDefault<word>("points", "points")), pointsName_(dict.getOrDefault<word>("points", "points")),
mapMethod_ mapMethod_
@ -116,13 +111,8 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
endSampleTime_(-1), endSampleTime_(-1),
endSampledValues_(0), endSampledValues_(0),
endAverage_(Zero), endAverage_(Zero),
offset_(nullptr) offset_(Function1<Type>::NewIfPresent("offset", dict))
{ {
if (dict.found("offset"))
{
offset_ = Function1<Type>::New("offset", dict);
}
if if
( (
mapMethod_ != "planarInterpolation" mapMethod_ != "planarInterpolation"
@ -139,51 +129,36 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
template<class Type> template<class Type>
Foam::PatchFunction1Types::MappedFile<Type>::MappedFile Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
( (
const MappedFile<Type>& ut const MappedFile<Type>& rhs
) )
: :
PatchFunction1<Type>(ut), MappedFile<Type>(rhs, rhs.patch())
dictConstructed_(ut.dictConstructed_),
fieldTableName_(ut.fieldTableName_),
setAverage_(ut.setAverage_),
perturb_(ut.perturb_),
pointsName_(ut.pointsName_),
mapMethod_(ut.mapMethod_),
mapperPtr_(ut.mapperPtr_.clone()),
sampleTimes_(ut.sampleTimes_),
startSampleTime_(ut.startSampleTime_),
startSampledValues_(ut.startSampledValues_),
startAverage_(ut.startAverage_),
endSampleTime_(ut.endSampleTime_),
endSampledValues_(ut.endSampledValues_),
endAverage_(ut.endAverage_),
offset_(ut.offset_.clone())
{} {}
template<class Type> template<class Type>
Foam::PatchFunction1Types::MappedFile<Type>::MappedFile Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
( (
const MappedFile<Type>& ut, const MappedFile<Type>& rhs,
const polyPatch& pp const polyPatch& pp
) )
: :
PatchFunction1<Type>(ut, pp), PatchFunction1<Type>(rhs, pp),
dictConstructed_(ut.dictConstructed_), dictConstructed_(rhs.dictConstructed_),
fieldTableName_(ut.fieldTableName_), setAverage_(rhs.setAverage_),
setAverage_(ut.setAverage_), fieldTableName_(rhs.fieldTableName_),
perturb_(ut.perturb_), perturb_(rhs.perturb_),
pointsName_(ut.pointsName_), pointsName_(rhs.pointsName_),
mapMethod_(ut.mapMethod_), mapMethod_(rhs.mapMethod_),
mapperPtr_(ut.mapperPtr_.clone()), mapperPtr_(rhs.mapperPtr_.clone()),
sampleTimes_(ut.sampleTimes_), sampleTimes_(rhs.sampleTimes_),
startSampleTime_(ut.startSampleTime_), startSampleTime_(rhs.startSampleTime_),
startSampledValues_(ut.startSampledValues_), startSampledValues_(rhs.startSampledValues_),
startAverage_(ut.startAverage_), startAverage_(rhs.startAverage_),
endSampleTime_(ut.endSampleTime_), endSampleTime_(rhs.endSampleTime_),
endSampledValues_(ut.endSampledValues_), endSampledValues_(rhs.endSampledValues_),
endAverage_(ut.endAverage_), endAverage_(rhs.endAverage_),
offset_(ut.offset_.clone()) offset_(rhs.offset_.clone())
{} {}
@ -279,7 +254,7 @@ void Foam::PatchFunction1Types::MappedFile<Type>::checkTable
); );
// Allocate the interpolator // Allocate the interpolator
if (this->faceValues_) if (this->faceValues())
{ {
mapperPtr_.reset mapperPtr_.reset
( (
@ -536,7 +511,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::value
if (setAverage_) if (setAverage_)
{ {
Type averagePsi; Type averagePsi;
if (this->faceValues_) if (this->faceValues())
{ {
const scalarField magSf(mag(this->patch_.faceAreas())); const scalarField magSf(mag(this->patch_.faceAreas()));
averagePsi = gSum(magSf*fld)/gSum(magSf); averagePsi = gSum(magSf*fld)/gSum(magSf);

View File

@ -73,12 +73,12 @@ class MappedFile
//- Whether constructed from dictionary //- Whether constructed from dictionary
const bool dictConstructed_; const bool dictConstructed_;
//- Name of the field data table, defaults to the name of the field
word fieldTableName_;
//- If true adjust the mapped field to maintain average value //- If true adjust the mapped field to maintain average value
bool setAverage_; bool setAverage_;
//- Name of the field data table, defaults to the name of the field
word fieldTableName_;
//- Fraction of perturbation (fraction of bounding box) to add //- Fraction of perturbation (fraction of bounding box) to add
scalar perturb_; scalar perturb_;
@ -120,23 +120,25 @@ class MappedFile
void checkTable(const scalar t) const; void checkTable(const scalar t) const;
//- No copy assignment
void operator=(const MappedFile<Type>&) = delete;
public: public:
//- Runtime type information //- Runtime type information
TypeName("mappedFile"); TypeName("mappedFile");
// Generated Methods
//- No copy assignment
void operator=(const MappedFile<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
MappedFile MappedFile
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues = true const bool faceValues = true
@ -152,13 +154,13 @@ public:
const bool faceValues const bool faceValues
); );
//- Copy constructor //- Copy construct
explicit MappedFile(const MappedFile<Type>& ut); explicit MappedFile(const MappedFile<Type>& rhs);
//- Copy constructor setting patch //- Copy construct setting patch
explicit MappedFile explicit MappedFile
( (
const MappedFile<Type>& ut, const MappedFile<Type>& rhs,
const polyPatch& pp const polyPatch& pp
); );

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -39,10 +39,7 @@ Foam::PatchFunction1<Type>::PatchFunction1
const bool faceValues const bool faceValues
) )
: :
refCount(), patchFunction1Base(pp, entryName, faceValues),
name_(entryName),
patch_(pp),
faceValues_(faceValues),
coordSys_() coordSys_()
{} {}
@ -56,68 +53,32 @@ Foam::PatchFunction1<Type>::PatchFunction1
const bool faceValues const bool faceValues
) )
: :
refCount(), patchFunction1Base(pp, entryName, dict, faceValues),
name_(entryName),
patch_(pp),
faceValues_(faceValues),
coordSys_(pp.boundaryMesh().mesh().thisDb(), dict) coordSys_(pp.boundaryMesh().mesh().thisDb(), dict)
{} {}
template<class Type> template<class Type>
Foam::PatchFunction1<Type>::PatchFunction1(const PatchFunction1<Type>& pf1) Foam::PatchFunction1<Type>::PatchFunction1(const PatchFunction1<Type>& rhs)
: :
refCount(), PatchFunction1<Type>(rhs, rhs.patch())
name_(pf1.name_),
patch_(pf1.patch_),
faceValues_(pf1.faceValues_),
coordSys_(pf1.coordSys_)
{} {}
template<class Type> template<class Type>
Foam::PatchFunction1<Type>::PatchFunction1 Foam::PatchFunction1<Type>::PatchFunction1
( (
const PatchFunction1<Type>& pf1, const PatchFunction1<Type>& rhs,
const polyPatch& pp const polyPatch& pp
) )
: :
refCount(), patchFunction1Base(pp, rhs.name(), rhs.faceValues()),
name_(pf1.name_), coordSys_(rhs.coordSys_)
patch_(pp),
faceValues_(pf1.faceValues_),
coordSys_(pf1.coordSys_)
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const Foam::word& Foam::PatchFunction1<Type>::name() const
{
return name_;
}
template<class Type>
const Foam::polyPatch& Foam::PatchFunction1<Type>::patch() const
{
return patch_;
}
template<class Type>
bool Foam::PatchFunction1<Type>::faceValues() const
{
return faceValues_;
}
template<class Type>
void Foam::PatchFunction1<Type>::convertTimeBase(const Time&)
{}
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::value Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::value
( (
@ -125,8 +86,7 @@ Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::value
) const ) const
{ {
NotImplemented; NotImplemented;
return nullptr;
return Field<Type>();
} }
template<class Type> template<class Type>
@ -144,8 +104,7 @@ Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::integrate
) const ) const
{ {
NotImplemented; NotImplemented;
return nullptr;
return Field<Type>();
} }
@ -175,7 +134,7 @@ Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::transform
tmp<Field<Type>> tresult = tmp<Field<Type>> tresult =
( (
faceValues_ this->faceValues()
? this->coordSys_.transform(this->patch_.faceCentres(), tfld()) ? this->coordSys_.transform(this->patch_.faceCentres(), tfld())
: this->coordSys_.transform(this->patch_.localPoints(), tfld()) : this->coordSys_.transform(this->patch_.localPoints(), tfld())
); );
@ -196,7 +155,7 @@ Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::transform
return fld; return fld;
} }
if (faceValues_) if (this->faceValues())
{ {
return this->coordSys_.transform(this->patch_.faceCentres(), fld); return this->coordSys_.transform(this->patch_.faceCentres(), fld);
} }
@ -215,7 +174,7 @@ void Foam::PatchFunction1<Type>::autoMap(const FieldMapper& mapper)
template<class Type> template<class Type>
void Foam::PatchFunction1<Type>::rmap void Foam::PatchFunction1<Type>::rmap
( (
const PatchFunction1<Type>& pf1, const PatchFunction1<Type>& rhs,
const labelList& addr const labelList& addr
) )
{} {}
@ -228,7 +187,7 @@ void Foam::PatchFunction1<Type>::writeData(Ostream& os) const
// Leave type() output up to derived type. This is so 'Constant'&Uniform // Leave type() output up to derived type. This is so 'Constant'&Uniform
// can do backwards compatibility. // can do backwards compatibility.
//os.writeKeyword(name_) << type(); //os.writeKeyword(this->name()) << this->type();
} }
@ -243,7 +202,7 @@ Foam::Ostream& Foam::operator<<
{ {
os.check(FUNCTION_NAME); os.check(FUNCTION_NAME);
os << rhs.name_; os << rhs.name();
rhs.writeData(os); rhs.writeData(os);
return os; return os;

View File

@ -46,10 +46,9 @@ SeeAlso
#ifndef PatchFunction1_H #ifndef PatchFunction1_H
#define PatchFunction1_H #define PatchFunction1_H
#include "dictionary.H" #include "patchFunction1Base.H"
#include "Field.H"
#include "polyPatch.H"
#include "coordinateScaling.H" #include "coordinateScaling.H"
#include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -70,21 +69,26 @@ Ostream& operator<<(Ostream&, const PatchFunction1<Type>&);
template<class Type> template<class Type>
class PatchFunction1 class PatchFunction1
: :
public refCount public patchFunction1Base
{ {
// Private Member Functions
//- Selector, with alternative entry etc
static autoPtr<PatchFunction1<Type>> New
(
const polyPatch& pp,
const word& entryName,
const entry* eptr,
const dictionary& dict,
const bool faceValues,
const bool mandatory
);
protected: protected:
// Protected Data // Protected Data
//- Name of entry
const word name_;
//- Reference to the patch
const polyPatch& patch_;
//- Whether to generate face or point values on patch
const bool faceValues_;
//- Optional local co-ordinate system and scaling //- Optional local co-ordinate system and scaling
coordinateScaling<Type> coordSys_; coordinateScaling<Type> coordSys_;
@ -138,31 +142,54 @@ public:
const bool faceValues = true const bool faceValues = true
); );
//- Copy constructor //- Copy construct
explicit PatchFunction1(const PatchFunction1<Type>& pf1); explicit PatchFunction1(const PatchFunction1<Type>& rhs);
//- Copy constructor setting patch //- Copy construct setting patch
explicit PatchFunction1 explicit PatchFunction1
( (
const PatchFunction1<Type>& pf1, const PatchFunction1<Type>& rhs,
const polyPatch& pp const polyPatch& pp
); );
//- Construct and return a clone //- Return a clone
virtual tmp<PatchFunction1<Type>> clone() const = 0; virtual tmp<PatchFunction1<Type>> clone() const = 0;
//- Construct and return a clone setting patch //- Return a clone, setting patch
virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const = 0; virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const = 0;
//- Selector // Selectors
static autoPtr<PatchFunction1<Type>> New
( //- Selector
const polyPatch& pp, static autoPtr<PatchFunction1<Type>> New
const word& entryName, (
const dictionary& dict, const polyPatch& pp,
const bool faceValues = true const word& entryName,
); const dictionary& dict,
const bool faceValues = true,
const bool mandatory = true
);
//- Compatibility selector
static autoPtr<PatchFunction1<Type>> NewCompat
(
const polyPatch& pp,
const word& entryName,
std::initializer_list<std::pair<const char*,int>> compat,
const dictionary& dict,
const bool faceValues = true,
const bool mandatory = true
);
//- An optional selector
static autoPtr<PatchFunction1<Type>> NewIfPresent
(
const polyPatch& pp,
const word& entryName,
const dictionary& dict,
const bool faceValues = true
);
//- Destructor //- Destructor
@ -171,24 +198,6 @@ public:
// Member Functions // Member Functions
// Access
//- Return the name of the entry
const word& name() const;
//- Reference to the patch
const polyPatch& patch() const;
//- Whether to generate face or point values on patch
bool faceValues() const;
// Manipulation
//- Convert time
virtual void convertTimeBase(const Time& t);
// Evaluation // Evaluation
//- Return value as a function of (scalar) independent variable //- Return value as a function of (scalar) independent variable
@ -231,7 +240,7 @@ public:
//- Reverse map the given PatchFunction1 onto this PatchFunction1 //- Reverse map the given PatchFunction1 onto this PatchFunction1
virtual void rmap virtual void rmap
( (
const PatchFunction1<Type>& pf1, const PatchFunction1<Type>& rhs,
const labelList& addr const labelList& addr
); );
@ -256,6 +265,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Define PatchFunction1 run-time selection
#define makePatchFunction1(Type) \ #define makePatchFunction1(Type) \
\ \
defineNamedTemplateTypeNameAndDebug(PatchFunction1<Type>, 0); \ defineNamedTemplateTypeNameAndDebug(PatchFunction1<Type>, 0); \
@ -266,6 +276,8 @@ public:
dictionary \ dictionary \
); );
// Define (templated) PatchFunction1, add to (templated) run-time selection
#define makePatchFunction1Type(SS, Type) \ #define makePatchFunction1Type(SS, Type) \
\ \
defineNamedTemplateTypeNameAndDebug(PatchFunction1Types::SS<Type>, 0); \ defineNamedTemplateTypeNameAndDebug(PatchFunction1Types::SS<Type>, 0); \
@ -274,6 +286,23 @@ public:
<PatchFunction1Types::SS<Type>> \ <PatchFunction1Types::SS<Type>> \
add##SS##Type##ConstructorToTable_; add##SS##Type##ConstructorToTable_;
// Define (non-templated) PatchFunction1, add to (templated) run-time selection
#define makeConcretePatchFunction1Type(SS, Type) \
\
defineTypeNameAndDebug(SS, 0); \
\
PatchFunction1<Type>::adddictionaryConstructorToTable \
<PatchFunction1Types::SS> \
add##SS##Type##ConstructorToTable_;
// Define scalar PatchFunction1 and add to (templated) run-time selection
#define makeScalarPatchFunction1(SS) \
\
makeConcretePatchFunction1Type(SS, scalar);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository

View File

@ -0,0 +1,219 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "ConstantField.H"
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::PatchFunction1<Type>>
Foam::PatchFunction1<Type>::New
(
const polyPatch& pp,
const word& entryName,
const entry* eptr,
const dictionary& dict,
const bool faceValues,
const bool mandatory
)
{
word modelType;
const dictionary* coeffs = (eptr ? eptr->dictPtr() : nullptr);
if (coeffs)
{
// Dictionary entry
coeffs->readEntry
(
"type",
modelType,
keyType::LITERAL
// "type" entry is mandatory, there is no 'redirect'
);
}
else if (eptr)
{
// Primitive entry
// - non-word : value for constant (uniform) function
// - word : the modelType, or uniform/nonuniform
ITstream& is = eptr->stream();
token firstToken(is);
// Compatibility for reading straight fields
if (!firstToken.isWord())
{
// A value
is.putBack(firstToken);
const Type constValue = pTraits<Type>(is);
return autoPtr<PatchFunction1<Type>>
(
new PatchFunction1Types::ConstantField<Type>
(
pp,
entryName,
constValue,
dict,
faceValues
)
);
}
modelType = firstToken.wordToken();
// Looks like a normal field entry?
if (modelType == "uniform" || modelType == "nonuniform")
{
return autoPtr<PatchFunction1<Type>>
(
new PatchFunction1Types::ConstantField<Type>
(
pp,
eptr,
entryName,
dict,
faceValues
)
);
}
// Fallthrough
}
if (modelType.empty())
{
// Entry missing
if (mandatory)
{
FatalIOErrorInFunction(dict)
<< "Missing or invalid PatchFunction1 entry: "
<< entryName << nl
<< exit(FatalIOError);
}
return nullptr;
}
else if (!coeffs)
{
// Primitive entry. Coeffs dictionary is optional.
// Use keyword() - not entryName - for compatibility lookup!
coeffs =
&dict.optionalSubDict
(
eptr->keyword() + "Coeffs",
keyType::LITERAL
);
}
auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
if (!cstrIter.found())
{
FatalIOErrorInFunction(dict)
<< "Unknown PatchFunction1 type "
<< modelType << " for " << entryName
<< "\n\nValid PatchFunction1 types :\n"
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalIOError);
}
return cstrIter()(pp, modelType, entryName, *coeffs, faceValues);
}
template<class Type>
Foam::autoPtr<Foam::PatchFunction1<Type>>
Foam::PatchFunction1<Type>::New
(
const polyPatch& pp,
const word& entryName,
const dictionary& dict,
const bool faceValues,
const bool mandatory
)
{
return PatchFunction1<Type>::New
(
pp,
entryName,
dict.findEntry(entryName, keyType::LITERAL),
dict,
faceValues,
mandatory
);
}
template<class Type>
Foam::autoPtr<Foam::PatchFunction1<Type>>
Foam::PatchFunction1<Type>::NewCompat
(
const polyPatch& pp,
const word& entryName,
std::initializer_list<std::pair<const char*,int>> compat,
const dictionary& dict,
const bool faceValues,
const bool mandatory
)
{
return PatchFunction1<Type>::New
(
pp,
entryName,
dict.findCompat(entryName, compat, keyType::LITERAL),
dict,
faceValues,
mandatory
);
}
template<class Type>
Foam::autoPtr<Foam::PatchFunction1<Type>>
Foam::PatchFunction1<Type>::NewIfPresent
(
const polyPatch& pp,
const word& entryName,
const dictionary& dict,
const bool faceValues
)
{
// mandatory = false
return PatchFunction1<Type>::New(pp, entryName, dict, faceValues, false);
}
// ************************************************************************* //

View File

@ -0,0 +1,88 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "patchFunction1Base.H"
#include "polyPatch.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
Foam::patchFunction1Base::patchFunction1Base
(
const polyPatch& pp,
const word& entryName,
const bool faceValues
)
:
refCount(),
name_(entryName),
patch_(pp),
faceValues_(faceValues)
{}
Foam::patchFunction1Base::patchFunction1Base
(
const polyPatch& pp,
const word& entryName,
const dictionary& dict,
const bool faceValues
)
:
refCount(),
name_(entryName),
patch_(pp),
faceValues_(faceValues)
{}
Foam::patchFunction1Base::patchFunction1Base(const patchFunction1Base& rhs)
:
patchFunction1Base(rhs, rhs.patch())
{}
Foam::patchFunction1Base::patchFunction1Base
(
const patchFunction1Base& rhs,
const polyPatch& pp
)
:
refCount(),
name_(rhs.name_),
patch_(pp),
faceValues_(rhs.faceValues_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::patchFunction1Base::convertTimeBase(const Time&)
{}
// ************************************************************************* //

View File

@ -0,0 +1,164 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::patchFunction1Base
Description
Top level data entry class for use in dictionaries. Provides a mechanism
to specify a variable as a certain type, e.g. constant or time varying, and
provide functions to return the (interpolated) value, and integral between
limits.
Extends the Function1 class by adding autoMap and rMap functions
SourceFiles
patchFunction1Base.C
\*---------------------------------------------------------------------------*/
#ifndef patchFunction1Base_H
#define patchFunction1Base_H
#include "dictionary.H"
#include "polyPatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class Time;
/*---------------------------------------------------------------------------*\
Class patchFunction1Base Declaration
\*---------------------------------------------------------------------------*/
class patchFunction1Base
:
public refCount
{
protected:
// Protected Data
//- Name of entry
const word name_;
//- Reference to the patch
const polyPatch& patch_;
//- Generate face or point values on patch
const bool faceValues_;
// Protected Member Functions
//- No copy assignment
void operator=(const patchFunction1Base&) = delete;
public:
// Constructors
//- Construct from polyPatch and entry name
patchFunction1Base
(
const polyPatch& pp,
const word& entryName,
const bool faceValues = true
);
//- Construct from polyPatch, dictionary and entry name
patchFunction1Base
(
const polyPatch& pp,
const word& entryName,
const dictionary& dict,
const bool faceValues = true
);
//- Copy construct
explicit patchFunction1Base(const patchFunction1Base& rhs);
//- Copy construct setting patch
explicit patchFunction1Base
(
const patchFunction1Base& rhs,
const polyPatch& pp
);
//- Destructor
virtual ~patchFunction1Base() = default;
// Member Functions
// Access
//- The name of the entry
const word& name() const
{
return name_;
}
//- Reference to the patch
const polyPatch& patch() const
{
return patch_;
}
//- Generate face or point values on patch?
bool faceValues() const
{
return faceValues_;
}
//- Number of faces or points on the patch
label size() const
{
return (faceValues_ ? patch_.size() : patch_.nPoints());
}
// Manipulation
//- Convert time
virtual void convertTimeBase(const Time&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,143 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "ConstantField.H"
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::PatchFunction1<Type>>
Foam::PatchFunction1<Type>::New
(
const polyPatch& pp,
const word& entryName,
const dictionary& dict,
const bool faceValues
)
{
const entry* eptr = dict.findEntry(entryName, keyType::LITERAL);
if (!eptr)
{
FatalIOErrorInFunction(dict)
<< "No PatchFunction1 dictionary entry: "
<< entryName << nl << nl
<< exit(FatalIOError);
// Failed
return nullptr;
}
else if (eptr->isDict())
{
const dictionary& coeffsDict = eptr->dict();
const word modelType(coeffsDict.getWord("type", keyType::LITERAL));
auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
if (!cstrIter.found())
{
FatalIOErrorInFunction(coeffsDict)
<< "Unknown PatchFunction1 type "
<< modelType << " for " << entryName
<< "\n\nValid PatchFunction1 types :\n"
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalIOError);
}
return cstrIter()(pp, modelType, entryName, coeffsDict, faceValues);
}
else
{
ITstream& is = eptr->stream();
token firstToken(is);
if (!firstToken.isWord())
{
// Backwards-compatibility for reading straight fields
is.putBack(firstToken);
const Type uniformValue = pTraits<Type>(is);
return autoPtr<PatchFunction1<Type>>
(
new PatchFunction1Types::ConstantField<Type>
(
pp,
entryName,
uniformValue,
dict,
faceValues
)
);
}
const word modelType = firstToken.wordToken();
// Check to see if this looks like a normal field entry
if (modelType == "uniform" || modelType == "nonuniform")
{
return autoPtr<PatchFunction1<Type>>
(
new PatchFunction1Types::ConstantField<Type>
(
pp,
PatchFunction1Types::ConstantField<Type>::typeName,
entryName,
dict,
faceValues
)
);
}
auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
if (!cstrIter.found())
{
FatalIOErrorInFunction(dict)
<< "Unknown PatchFunction1 type "
<< modelType << " for " << entryName
<< "\n\nValid PatchFunction1 types :\n"
<< dictionaryConstructorTablePtr_->sortedToc() << nl
<< exit(FatalIOError);
}
return cstrIter()
(
pp,
modelType,
entryName,
dict.optionalSubDict(entryName + "Coeffs"),
faceValues
);
}
}
// ************************************************************************* //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -34,7 +34,7 @@ template<class Type>
Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues const bool faceValues
@ -47,7 +47,7 @@ Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField
( (
entryName, entryName,
dict, dict,
type redirectType
) )
) )
{} {}
@ -56,23 +56,22 @@ Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField
template<class Type> template<class Type>
Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField
( (
const UniformValueField<Type>& ut const UniformValueField<Type>& rhs
) )
: :
PatchFunction1<Type>(ut), UniformValueField<Type>(rhs, rhs.patch())
uniformValuePtr_(ut.uniformValuePtr_.clone())
{} {}
template<class Type> template<class Type>
Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField
( (
const UniformValueField<Type>& ut, const UniformValueField<Type>& rhs,
const polyPatch& pp const polyPatch& pp
) )
: :
PatchFunction1<Type>(ut, pp), PatchFunction1<Type>(rhs, pp),
uniformValuePtr_(ut.uniformValuePtr_.clone()) uniformValuePtr_(rhs.uniformValuePtr_.clone())
{} {}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -67,38 +67,37 @@ class UniformValueField
//- Source of uniform values (in local coordinate system) //- Source of uniform values (in local coordinate system)
autoPtr<Foam::Function1<Type>> uniformValuePtr_; autoPtr<Foam::Function1<Type>> uniformValuePtr_;
// Private Member Functions
//- No copy assignment
void operator=(const UniformValueField<Type>&) = delete;
public: public:
// Runtime type information // Runtime type information
TypeName("uniformValue"); TypeName("uniformValue");
// Generated Methods
//- No copy assignment
void operator=(const UniformValueField<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary
UniformValueField UniformValueField
( (
const polyPatch& pp, const polyPatch& pp,
const word& type, const word& redirectType,
const word& entryName, const word& entryName,
const dictionary& dict, const dictionary& dict,
const bool faceValues = true const bool faceValues = true
); );
//- Copy constructor //- Copy construct
explicit UniformValueField(const UniformValueField<Type>& ut); explicit UniformValueField(const UniformValueField<Type>& rhs);
//- Copy constructor setting patch //- Copy construct setting patch
explicit UniformValueField explicit UniformValueField
( (
const UniformValueField<Type>& ut, const UniformValueField<Type>& rhs,
const polyPatch& pp const polyPatch& pp
); );

View File

@ -46,13 +46,10 @@ Foam::PatchFunction1Types::UniformValueField<Type>::value
const scalar x const scalar x
) const ) const
{ {
const label len =
(this->faceValues_ ? this->patch_.size() : this->patch_.nPoints());
auto tfld = auto tfld =
tmp<Field<Type>>::New tmp<Field<Type>>::New
( (
len, this->size(),
uniformValuePtr_->value(x) uniformValuePtr_->value(x)
); );
@ -68,13 +65,10 @@ Foam::PatchFunction1Types::UniformValueField<Type>::integrate
const scalar x2 const scalar x2
) const ) const
{ {
const label len =
(this->faceValues_ ? this->patch_.size() : this->patch_.nPoints());
auto tfld = auto tfld =
tmp<Field<Type>>::New tmp<Field<Type>>::New
( (
len, this->size(),
uniformValuePtr_->integrate(x1, x2) uniformValuePtr_->integrate(x1, x2)
); );

View File

@ -33,7 +33,6 @@ License
#include "pointConstraints.H" #include "pointConstraints.H"
#include "uniformDimensionedFields.H" #include "uniformDimensionedFields.H"
#include "forces.H" #include "forces.H"
#include "OneConstant.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -120,7 +119,7 @@ Foam::rigidBodyMeshMotion::rigidBodyMeshMotion
test_(coeffDict().getOrDefault("test", false)), test_(coeffDict().getOrDefault("test", false)),
rhoInf_(1.0), rhoInf_(1.0),
rhoName_(coeffDict().getOrDefault<word>("rho", "rho")), rhoName_(coeffDict().getOrDefault<word>("rho", "rho")),
ramp_(nullptr), ramp_(Function1<scalar>::NewIfPresent("ramp", coeffDict())),
curTimeIndex_(-1) curTimeIndex_(-1)
{ {
if (rhoName_ == "rhoInf") if (rhoName_ == "rhoInf")
@ -128,15 +127,6 @@ Foam::rigidBodyMeshMotion::rigidBodyMeshMotion
readEntry("rhoInf", rhoInf_); readEntry("rhoInf", rhoInf_);
} }
if (coeffDict().found("ramp"))
{
ramp_ = Function1<scalar>::New("ramp", coeffDict());
}
else
{
ramp_.reset(new Function1Types::OneConstant<scalar>("ramp"));
}
const dictionary& bodiesDict = coeffDict().subDict("bodies"); const dictionary& bodiesDict = coeffDict().subDict("bodies");
for (const entry& dEntry : bodiesDict) for (const entry& dEntry : bodiesDict)
@ -242,7 +232,7 @@ void Foam::rigidBodyMeshMotion::solve()
curTimeIndex_ = this->db().time().timeIndex(); curTimeIndex_ = this->db().time().timeIndex();
} }
const scalar ramp = ramp_->value(t.value()); const scalar ramp = (ramp_ ? ramp_->value(t.value()) : 1.0);
if (t.foundObject<uniformDimensionedVectorField>("g")) if (t.foundObject<uniformDimensionedVectorField>("g"))
{ {