ENH: ConstantField: allow 'constant' keyword. See #1046.

This commit is contained in:
mattijs
2018-10-30 13:26:23 +00:00
parent 966eed302e
commit 6f2376a649
2 changed files with 59 additions and 3 deletions

View File

@ -42,6 +42,54 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
{} {}
template<class Type>
Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
(
const word& keyword,
const dictionary& dict,
const label len
)
{
Field<Type> fld;
if (len)
{
ITstream& is = dict.lookup(keyword);
// Read first token
token firstToken(is);
if (firstToken.isWord())
{
if
(
firstToken.wordToken() == "uniform"
|| firstToken.wordToken() == "constant"
)
{
fld.setSize(len);
fld = pTraits<Type>(is);
}
else
{
FatalIOErrorInFunction(dict)
<< "expected keyword 'uniform' or 'constant', found "
<< firstToken.wordToken()
<< exit(FatalIOError);
}
}
else
{
fld.setSize(len);
is.putBack(firstToken);
fld = pTraits<Type>(is);
}
}
return fld;
}
template<class Type> template<class Type>
Foam::PatchFunction1Types::ConstantField<Type>::ConstantField Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
( (
@ -52,7 +100,7 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
) )
: :
PatchFunction1<Type>(pp, entryName, dict, faceValues), PatchFunction1<Type>(pp, entryName, dict, faceValues),
value_(entryName, dict, pp.size()) value_(getValue(entryName, dict, pp.size()))
{} {}

View File

@ -2,8 +2,8 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -66,6 +66,14 @@ class ConstantField
// Private Member Functions // Private Member Functions
//- Helper to read value from dictionary
static Field<Type> getValue
(
const word& keyword,
const dictionary& dict,
const label len
);
//- No copy assignment //- No copy assignment
void operator=(const ConstantField<Type>&) = delete; void operator=(const ConstantField<Type>&) = delete;