BUG: uniformFixedValue: do not evaluate upon reading. Fixes #1058.

This commit is contained in:
mattijs
2018-11-12 09:15:09 +00:00
parent f44e59fb55
commit e9af742819
17 changed files with 226 additions and 51 deletions

View File

@ -32,13 +32,17 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
(
const polyPatch& pp,
const word& entryName,
const Field<Type>& value,
const bool isUniform,
const Type& uniformValue,
const Field<Type>& nonUniformValue,
const dictionary& dict,
const bool faceValues
)
:
PatchFunction1<Type>(pp, entryName, dict, faceValues),
value_(value)
isUniform_(isUniform),
uniformValue_(uniformValue),
value_(nonUniformValue)
{}
@ -47,9 +51,14 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
(
const word& keyword,
const dictionary& dict,
const label len
const label len,
bool& isUniform,
Type& uniformValue
)
{
isUniform = true;
uniformValue = Zero;
Field<Type> fld;
if (len)
@ -67,13 +76,16 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
|| firstToken.wordToken() == "constant"
)
{
is >> uniformValue;
fld.setSize(len);
fld = pTraits<Type>(is);
fld = uniformValue;
}
else if (firstToken.wordToken() == "nonuniform")
{
List<Type>& list = fld;
is >> list;
isUniform = false;
label currentSize = fld.size();
if (currentSize != len)
{
@ -105,6 +117,7 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
}
else
{
isUniform = false;
FatalIOErrorInFunction(dict)
<< "Expected keyword 'uniform', 'nonuniform' or 'constant'"
<< ", found " << firstToken.wordToken()
@ -113,10 +126,10 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
}
else
{
fld.setSize(len);
is.putBack(firstToken);
fld = pTraits<Type>(is);
is >> uniformValue;
fld.setSize(len);
fld = uniformValue;
}
}
return fld;
@ -134,7 +147,7 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
)
:
PatchFunction1<Type>(pp, entryName, dict, faceValues),
value_(getValue(entryName, dict, pp.size()))
value_(getValue(entryName, dict, pp.size(), isUniform_, uniformValue_))
{}
@ -145,6 +158,8 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
)
:
PatchFunction1<Type>(cnst),
isUniform_(cnst.isUniform_),
uniformValue_(cnst.uniformValue_),
value_(cnst.value_)
{}
@ -157,8 +172,17 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
)
:
PatchFunction1<Type>(cnst, pp),
isUniform_(cnst.isUniform_),
uniformValue_(cnst.uniformValue_),
value_(cnst.value_)
{}
{
// If different sizes do what?
value_.setSize(this->patch_.size());
if (isUniform_)
{
value_ = uniformValue_;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -170,6 +194,12 @@ void Foam::PatchFunction1Types::ConstantField<Type>::autoMap
)
{
value_.autoMap(mapper);
// If originating from single value override just to make sure
if (isUniform_)
{
value_ = uniformValue_;
}
}

View File

@ -60,6 +60,12 @@ class ConstantField
{
// Private data
//- Is uniform?
bool isUniform_;
//- If uniform the uniformValue
Type uniformValue_;
//- ConstantField value
Field<Type> value_;
@ -71,7 +77,9 @@ class ConstantField
(
const word& keyword,
const dictionary& dict,
const label len
const label len,
bool& isUniform,
Type& uniformValue
);
//- No copy assignment
@ -91,7 +99,9 @@ public:
(
const polyPatch& pp,
const word& entryName,
const Field<Type>& value,
const bool isUniform,
const Type& uniformValue,
const Field<Type>& nonUniformValue,
const dictionary& dict = dictionary::null,
const bool faceValues = true
);
@ -141,7 +151,19 @@ public:
// Evaluation
//- Return constant value
virtual inline tmp<Field<Type>> value(const scalar) const;
virtual inline tmp<Field<Type>> value(const scalar x) const;
//- Is value constant (i.e. independent of x)
virtual inline bool constant() const
{
return true;
}
//- Is value uniform (i.e. independent of coordinate)
virtual inline bool uniform() const
{
return isUniform_ && PatchFunction1<Type>::uniform();
}
//- Integrate between two values
virtual inline tmp<Field<Type>> integrate

View File

@ -178,6 +178,18 @@ public:
//- Return MappedFile value
virtual tmp<Field<Type>> value(const scalar) const;
//- Is value constant (i.e. independent of x)
virtual bool constant() const
{
return sampleTimes_.size() == 1;
}
//- Is value uniform (i.e. independent of coordinate)
virtual bool uniform() const
{
return PatchFunction1<Type>::uniform();
}
//- Integrate between two values
virtual tmp<Field<Type>> integrate
(

View File

@ -113,6 +113,12 @@ Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::value
return Field<Type>();
}
template<class Type>
bool Foam::PatchFunction1<Type>::uniform() const
{
return !coordSys_.active();
}
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::integrate

View File

@ -193,6 +193,12 @@ public:
//- Return value as a function of (scalar) independent variable
virtual tmp<Field<Type>> value(const scalar x) const;
//- Is value constant (i.e. independent of x)
virtual bool constant() const = 0;
//- Is value uniform (i.e. independent of coordinate)
virtual bool uniform() const = 0;
//- Integrate between two (scalar) values
virtual tmp<Field<Type>> integrate
(

View File

@ -67,7 +67,9 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
{
// Backwards-compatibility for reading straight fields
is.putBack(firstToken);
const Field<Type> value(pp.size(), pTraits<Type>(is));
const Type uniformValue = pTraits<Type>(is);
const Field<Type> value(pp.size(), uniformValue);
return autoPtr<PatchFunction1<Type>>
(
@ -75,6 +77,8 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
(
pp,
entryName,
true, // uniform
uniformValue, // uniform value
value, // Supply value
dict,
faceValues

View File

@ -128,7 +128,16 @@ public:
// Evaluation
//- Return UniformValueField value
virtual inline tmp<Field<Type>> value(const scalar) const;
virtual inline tmp<Field<Type>> value(const scalar x) const;
//- Is value constant (i.e. independent of x)
virtual inline bool constant() const;
//- Is value uniform (i.e. independent of coordinate)
virtual inline bool uniform() const
{
return PatchFunction1<Type>::uniform();
}
//- Integrate between two values
virtual inline tmp<Field<Type>> integrate

View File

@ -25,9 +25,18 @@ License
#include "UniformValueField.H"
#include "SubField.H"
#include "Constant.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline bool
Foam::PatchFunction1Types::UniformValueField<Type>::constant() const
{
return uniformValuePtr_->type() == Function1Types::Constant<Type>::typeName;
}
template<class Type>
inline Foam::tmp<Foam::Field<Type>>
Foam::PatchFunction1Types::UniformValueField<Type>::value