ENH: add construct ConstantField with uniform value

This commit is contained in:
Mark Olesen
2020-09-25 13:41:20 +02:00
parent 97be8fc767
commit bb3660b9a5
12 changed files with 96 additions and 96 deletions

View File

@ -52,7 +52,7 @@ Foam::Function1Types::Constant<Type>::Constant
Function1<Type>(entryName),
value_(Zero)
{
Istream& is(dict.lookup(entryName));
Istream& is = dict.lookup(entryName);
word entryType(is);
is >> value_;
}
@ -78,13 +78,6 @@ Foam::Function1Types::Constant<Type>::Constant(const Constant<Type>& cnst)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::Constant<Type>::~Constant()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>

View File

@ -103,7 +103,7 @@ public:
//- Destructor
virtual ~Constant();
virtual ~Constant() = default;
// Member Functions

View File

@ -103,6 +103,7 @@ protected:
//- Name of entry
const word name_;
// Protected Member Functions
//- No copy assignment

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,10 +28,11 @@ License
#include "Constant.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
Foam::autoPtr<Foam::Function1<Type>>
Foam::Function1<Type>::New
(
const word& entryName,
const dictionary& dict,
@ -86,10 +87,14 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
if (!firstToken.isWord())
{
// Backwards-compatibility for reading straight fields
is.putBack(firstToken);
const Type constValue = pTraits<Type>(is);
return autoPtr<Function1<Type>>
(
new Function1Types::Constant<Type>(entryName, is)
new Function1Types::Constant<Type>(entryName, constValue)
);
}