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

@ -71,7 +71,8 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::fvMeshAdder::add
fvMesh& mesh0, fvMesh& mesh0,
const fvMesh& mesh1, const fvMesh& mesh1,
const faceCoupleInfo& coupleInfo, const faceCoupleInfo& coupleInfo,
const bool validBoundary const bool validBoundary,
const bool fullyMapped
) )
{ {
mesh0.clearOut(); mesh0.clearOut();
@ -101,17 +102,20 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::fvMeshAdder::add
// Do the mapping of the stored fields // Do the mapping of the stored fields
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fvMeshAdder::MapVolFields<scalar>(map, mesh0, mesh1); fvMeshAdder::MapVolFields<scalar>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapVolFields<vector>(map, mesh0, mesh1); fvMeshAdder::MapVolFields<vector>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapVolFields<sphericalTensor>(map, mesh0, mesh1); fvMeshAdder::MapVolFields<sphericalTensor>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapVolFields<symmTensor>(map, mesh0, mesh1); fvMeshAdder::MapVolFields<symmTensor>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapVolFields<tensor>(map, mesh0, mesh1); fvMeshAdder::MapVolFields<tensor>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapSurfaceFields<scalar>(map, mesh0, mesh1); fvMeshAdder::MapSurfaceFields<scalar>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapSurfaceFields<vector>(map, mesh0, mesh1); fvMeshAdder::MapSurfaceFields<vector>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapSurfaceFields<sphericalTensor>(map, mesh0, mesh1); fvMeshAdder::MapSurfaceFields<sphericalTensor>
fvMeshAdder::MapSurfaceFields<symmTensor>(map, mesh0, mesh1); (
fvMeshAdder::MapSurfaceFields<tensor>(map, mesh0, mesh1); map, mesh0, mesh1, fullyMapped
);
fvMeshAdder::MapSurfaceFields<symmTensor>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapSurfaceFields<tensor>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapDimFields<scalar>(map, mesh0, mesh1); fvMeshAdder::MapDimFields<scalar>(map, mesh0, mesh1);
fvMeshAdder::MapDimFields<vector>(map, mesh0, mesh1); fvMeshAdder::MapDimFields<vector>(map, mesh0, mesh1);

View File

@ -89,7 +89,8 @@ private:
const mapAddedPolyMesh& meshMap, const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvPatchField, volMesh>& fld, GeometricField<Type, fvPatchField, volMesh>& fld,
const GeometricField<Type, fvPatchField, volMesh>& fldToAdd const GeometricField<Type, fvPatchField, volMesh>& fldToAdd,
const bool fullyMapped
); );
//- Update single surfaceField. //- Update single surfaceField.
@ -99,7 +100,8 @@ private:
const mapAddedPolyMesh& meshMap, const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvsPatchField, surfaceMesh>& fld, GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd,
const bool fullyMapped
); );
//- Update single dimensionedField. //- Update single dimensionedField.
@ -126,16 +128,21 @@ public:
fvMesh& mesh0, fvMesh& mesh0,
const fvMesh& mesh1, const fvMesh& mesh1,
const faceCoupleInfo& coupleInfo, const faceCoupleInfo& coupleInfo,
const bool validBoundary = true const bool validBoundary = true,
const bool fullyMapped = false
); );
//- Map all volFields of Type //- Map all volFields of Type.
// Optionally override mapping detection
// of unmapped values (e.g. used in fvMeshDistribute since it fixes
// up mapping itself)
template<class Type> template<class Type>
static void MapVolFields static void MapVolFields
( (
const mapAddedPolyMesh&, const mapAddedPolyMesh&,
const fvMesh& mesh, const fvMesh& mesh,
const fvMesh& meshToAdd const fvMesh& meshToAdd,
const bool fullyMapped = false
); );
//- Map all surfaceFields of Type //- Map all surfaceFields of Type
@ -144,7 +151,8 @@ public:
( (
const mapAddedPolyMesh&, const mapAddedPolyMesh&,
const fvMesh& mesh, const fvMesh& mesh,
const fvMesh& meshToAdd const fvMesh& meshToAdd,
const bool fullyMapped = false
); );
//- Map all DimensionedFields of Type //- Map all DimensionedFields of Type

View File

@ -36,7 +36,8 @@ void Foam::fvMeshAdder::MapVolField
const mapAddedPolyMesh& meshMap, const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvPatchField, volMesh>& fld, GeometricField<Type, fvPatchField, volMesh>& fld,
const GeometricField<Type, fvPatchField, volMesh>& fldToAdd const GeometricField<Type, fvPatchField, volMesh>& fldToAdd,
const bool fullyMapped
) )
{ {
const fvMesh& mesh = fld.mesh(); const fvMesh& mesh = fld.mesh();
@ -142,6 +143,12 @@ void Foam::fvMeshAdder::MapVolField
directFvPatchFieldMapper patchMapper(newToOld); directFvPatchFieldMapper patchMapper(newToOld);
// Override mapping (for use in e.g. fvMeshDistribute where
// it sorts mapping out itself)
if (fullyMapped)
{
patchMapper.hasUnmapped() = false;
}
// Create new patchField with same type as existing one. // Create new patchField with same type as existing one.
// Note: // Note:
@ -204,6 +211,13 @@ void Foam::fvMeshAdder::MapVolField
directFvPatchFieldMapper patchMapper(newToAdded); directFvPatchFieldMapper patchMapper(newToAdded);
// Override mapping (for use in e.g. fvMeshDistribute where
// it sorts mapping out itself)
if (fullyMapped)
{
patchMapper.hasUnmapped() = false;
}
bfld.set bfld.set
( (
newPatchi, newPatchi,
@ -250,7 +264,8 @@ void Foam::fvMeshAdder::MapVolFields
( (
const mapAddedPolyMesh& meshMap, const mapAddedPolyMesh& meshMap,
const fvMesh& mesh, const fvMesh& mesh,
const fvMesh& meshToAdd const fvMesh& meshToAdd,
const bool fullyMapped
) )
{ {
HashTable<const GeometricField<Type, fvPatchField, volMesh>*> fields HashTable<const GeometricField<Type, fvPatchField, volMesh>*> fields
@ -312,7 +327,7 @@ void Foam::fvMeshAdder::MapVolFields
<< "MapVolFields : mapping " << fld.name() << "MapVolFields : mapping " << fld.name()
<< " and " << fldToAdd.name() << endl; << " and " << fldToAdd.name() << endl;
MapVolField<Type>(meshMap, fld, fldToAdd); MapVolField<Type>(meshMap, fld, fldToAdd, fullyMapped);
} }
else else
{ {
@ -331,7 +346,8 @@ void Foam::fvMeshAdder::MapSurfaceField
const mapAddedPolyMesh& meshMap, const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvsPatchField, surfaceMesh>& fld, GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd,
const bool fullyMapped
) )
{ {
const fvMesh& mesh = fld.mesh(); const fvMesh& mesh = fld.mesh();
@ -458,6 +474,13 @@ void Foam::fvMeshAdder::MapSurfaceField
directFvPatchFieldMapper patchMapper(newToOld); directFvPatchFieldMapper patchMapper(newToOld);
// Override mapping (for use in e.g. fvMeshDistribute where
// it sorts mapping out itself)
if (fullyMapped)
{
patchMapper.hasUnmapped() = false;
}
// Create new patchField with same type as existing one. // Create new patchField with same type as existing one.
// Note: // Note:
// - boundaryField already in new order so access with newPatchi // - boundaryField already in new order so access with newPatchi
@ -519,6 +542,13 @@ void Foam::fvMeshAdder::MapSurfaceField
directFvPatchFieldMapper patchMapper(newToAdded); directFvPatchFieldMapper patchMapper(newToAdded);
// Override mapping (for use in e.g. fvMeshDistribute where
// it sorts mapping out itself)
if (fullyMapped)
{
patchMapper.hasUnmapped() = false;
}
bfld.set bfld.set
( (
newPatchi, newPatchi,
@ -565,7 +595,8 @@ void Foam::fvMeshAdder::MapSurfaceFields
( (
const mapAddedPolyMesh& meshMap, const mapAddedPolyMesh& meshMap,
const fvMesh& mesh, const fvMesh& mesh,
const fvMesh& meshToAdd const fvMesh& meshToAdd,
const bool fullyMapped
) )
{ {
typedef GeometricField<Type, fvsPatchField, surfaceMesh> fldType; typedef GeometricField<Type, fvsPatchField, surfaceMesh> fldType;
@ -619,7 +650,7 @@ void Foam::fvMeshAdder::MapSurfaceFields
<< "MapSurfaceFields : mapping " << fld.name() << "MapSurfaceFields : mapping " << fld.name()
<< " and " << fldToAdd.name() << endl; << " and " << fldToAdd.name() << endl;
MapSurfaceField<Type>(meshMap, fld, fldToAdd); MapSurfaceField<Type>(meshMap, fld, fldToAdd, fullyMapped);
} }
else else
{ {

View File

@ -2606,7 +2606,8 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
mesh_, mesh_,
domainMesh, domainMesh,
couples, couples,
false // no parallel comms false, // no parallel comms
true // fake complete mapping
); );
// Update mesh data: sourceFace,sourceProc for added // Update mesh data: sourceFace,sourceProc for added

View File

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

View File

@ -63,7 +63,17 @@ Foam::uniformFixedValueFvPatchField<Type>::uniformFixedValueFvPatchField
fixedValueFvPatchField<Type>(p, iF, dict, false), fixedValueFvPatchField<Type>(p, iF, dict, false),
uniformValue_(PatchFunction1<Type>::New(p.patch(), "uniformValue", dict)) uniformValue_(PatchFunction1<Type>::New(p.patch(), "uniformValue", dict))
{ {
this->evaluate(); if (dict.found("value"))
{
fvPatchField<Type>::operator=
(
Field<Type>("value", dict, p.size())
);
}
else
{
this->evaluate();
}
} }
@ -79,8 +89,16 @@ Foam::uniformFixedValueFvPatchField<Type>::uniformFixedValueFvPatchField
fixedValueFvPatchField<Type>(p, iF), // Don't map fixedValueFvPatchField<Type>(p, iF), // Don't map
uniformValue_(ptf.uniformValue_.clone(p.patch())) uniformValue_(ptf.uniformValue_.clone(p.patch()))
{ {
// Evaluate since value not mapped if (mapper.direct() && !mapper.hasUnmapped())
this->evaluate(); {
// Use mapping instead of re-evaluation
this->map(ptf, mapper);
}
else
{
// Evaluate since value not mapped
this->evaluate();
}
} }
@ -104,13 +122,7 @@ Foam::uniformFixedValueFvPatchField<Type>::uniformFixedValueFvPatchField
: :
fixedValueFvPatchField<Type>(ptf, iF), fixedValueFvPatchField<Type>(ptf, iF),
uniformValue_(ptf.uniformValue_.clone(this->patch().patch())) uniformValue_(ptf.uniformValue_.clone(this->patch().patch()))
{ {}
// Evaluate the profile if defined
if (uniformValue_.valid())
{
this->evaluate();
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -123,6 +135,12 @@ void Foam::uniformFixedValueFvPatchField<Type>::autoMap
{ {
fixedValueFvPatchField<Type>::autoMap(mapper); fixedValueFvPatchField<Type>::autoMap(mapper);
uniformValue_().autoMap(mapper); uniformValue_().autoMap(mapper);
if (uniformValue_().constant())
{
// If mapper is not dependent on time we're ok to evaluate
this->evaluate();
}
} }

View File

@ -93,6 +93,11 @@ public:
return hasUnmapped_; return hasUnmapped_;
} }
bool& hasUnmapped()
{
return hasUnmapped_;
}
const labelUList& directAddressing() const const labelUList& directAddressing() const
{ {
return directAddressing_; return directAddressing_;

View File

@ -32,13 +32,17 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
( (
const polyPatch& pp, const polyPatch& pp,
const word& entryName, const word& entryName,
const Field<Type>& value, const bool isUniform,
const Type& uniformValue,
const Field<Type>& nonUniformValue,
const dictionary& dict, const dictionary& dict,
const bool faceValues const bool faceValues
) )
: :
PatchFunction1<Type>(pp, entryName, dict, 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 word& keyword,
const dictionary& dict, const dictionary& dict,
const label len const label len,
bool& isUniform,
Type& uniformValue
) )
{ {
isUniform = true;
uniformValue = Zero;
Field<Type> fld; Field<Type> fld;
if (len) if (len)
@ -67,13 +76,16 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
|| firstToken.wordToken() == "constant" || firstToken.wordToken() == "constant"
) )
{ {
is >> uniformValue;
fld.setSize(len); fld.setSize(len);
fld = pTraits<Type>(is); fld = uniformValue;
} }
else if (firstToken.wordToken() == "nonuniform") else if (firstToken.wordToken() == "nonuniform")
{ {
List<Type>& list = fld; List<Type>& list = fld;
is >> list; is >> list;
isUniform = false;
label currentSize = fld.size(); label currentSize = fld.size();
if (currentSize != len) if (currentSize != len)
{ {
@ -105,6 +117,7 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
} }
else else
{ {
isUniform = false;
FatalIOErrorInFunction(dict) FatalIOErrorInFunction(dict)
<< "Expected keyword 'uniform', 'nonuniform' or 'constant'" << "Expected keyword 'uniform', 'nonuniform' or 'constant'"
<< ", found " << firstToken.wordToken() << ", found " << firstToken.wordToken()
@ -113,10 +126,10 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
} }
else else
{ {
fld.setSize(len);
is.putBack(firstToken); is.putBack(firstToken);
fld = pTraits<Type>(is); is >> uniformValue;
fld.setSize(len);
fld = uniformValue;
} }
} }
return fld; return fld;
@ -134,7 +147,7 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
) )
: :
PatchFunction1<Type>(pp, entryName, dict, faceValues), 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), PatchFunction1<Type>(cnst),
isUniform_(cnst.isUniform_),
uniformValue_(cnst.uniformValue_),
value_(cnst.value_) value_(cnst.value_)
{} {}
@ -157,8 +172,17 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
) )
: :
PatchFunction1<Type>(cnst, pp), PatchFunction1<Type>(cnst, pp),
isUniform_(cnst.isUniform_),
uniformValue_(cnst.uniformValue_),
value_(cnst.value_) value_(cnst.value_)
{} {
// If different sizes do what?
value_.setSize(this->patch_.size());
if (isUniform_)
{
value_ = uniformValue_;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -170,6 +194,12 @@ void Foam::PatchFunction1Types::ConstantField<Type>::autoMap
) )
{ {
value_.autoMap(mapper); 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 // Private data
//- Is uniform?
bool isUniform_;
//- If uniform the uniformValue
Type uniformValue_;
//- ConstantField value //- ConstantField value
Field<Type> value_; Field<Type> value_;
@ -71,7 +77,9 @@ class ConstantField
( (
const word& keyword, const word& keyword,
const dictionary& dict, const dictionary& dict,
const label len const label len,
bool& isUniform,
Type& uniformValue
); );
//- No copy assignment //- No copy assignment
@ -91,7 +99,9 @@ public:
( (
const polyPatch& pp, const polyPatch& pp,
const word& entryName, const word& entryName,
const Field<Type>& value, const bool isUniform,
const Type& uniformValue,
const Field<Type>& nonUniformValue,
const dictionary& dict = dictionary::null, const dictionary& dict = dictionary::null,
const bool faceValues = true const bool faceValues = true
); );
@ -141,7 +151,19 @@ public:
// Evaluation // Evaluation
//- Return constant value //- 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 //- Integrate between two values
virtual inline tmp<Field<Type>> integrate virtual inline tmp<Field<Type>> integrate

View File

@ -178,6 +178,18 @@ public:
//- Return MappedFile value //- Return MappedFile value
virtual tmp<Field<Type>> value(const scalar) const; 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 //- Integrate between two values
virtual tmp<Field<Type>> integrate virtual tmp<Field<Type>> integrate
( (

View File

@ -113,6 +113,12 @@ Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::value
return Field<Type>(); return Field<Type>();
} }
template<class Type>
bool Foam::PatchFunction1<Type>::uniform() const
{
return !coordSys_.active();
}
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::PatchFunction1<Type>::integrate 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 //- Return value as a function of (scalar) independent variable
virtual tmp<Field<Type>> value(const scalar x) const; 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 //- Integrate between two (scalar) values
virtual tmp<Field<Type>> integrate 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 // Backwards-compatibility for reading straight fields
is.putBack(firstToken); 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>> return autoPtr<PatchFunction1<Type>>
( (
@ -75,6 +77,8 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
( (
pp, pp,
entryName, entryName,
true, // uniform
uniformValue, // uniform value
value, // Supply value value, // Supply value
dict, dict,
faceValues faceValues

View File

@ -128,7 +128,16 @@ public:
// Evaluation // Evaluation
//- Return UniformValueField value //- 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 //- Integrate between two values
virtual inline tmp<Field<Type>> integrate virtual inline tmp<Field<Type>> integrate

View File

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

View File

@ -21,7 +21,6 @@ internalField uniform 0.2;
boundaryField boundaryField
{ {
inlet inlet
{ {
type uniformFixedValue; type uniformFixedValue;

View File

@ -32,7 +32,6 @@ boundaryField
(0.01 (0 -15 0)) (0.01 (0 -15 0))
(100 (0 -15 0)) (100 (0 -15 0))
); );
value $internalField;
} }
outlet outlet