Commit e9af7428 authored by mattijs's avatar mattijs
Browse files

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

parent f44e59fb
......@@ -71,7 +71,8 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::fvMeshAdder::add
fvMesh& mesh0,
const fvMesh& mesh1,
const faceCoupleInfo& coupleInfo,
const bool validBoundary
const bool validBoundary,
const bool fullyMapped
)
{
mesh0.clearOut();
......@@ -101,17 +102,20 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::fvMeshAdder::add
// Do the mapping of the stored fields
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fvMeshAdder::MapVolFields<scalar>(map, mesh0, mesh1);
fvMeshAdder::MapVolFields<vector>(map, mesh0, mesh1);
fvMeshAdder::MapVolFields<sphericalTensor>(map, mesh0, mesh1);
fvMeshAdder::MapVolFields<symmTensor>(map, mesh0, mesh1);
fvMeshAdder::MapVolFields<tensor>(map, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<scalar>(map, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<vector>(map, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<sphericalTensor>(map, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<symmTensor>(map, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<tensor>(map, mesh0, mesh1);
fvMeshAdder::MapVolFields<scalar>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapVolFields<vector>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapVolFields<sphericalTensor>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapVolFields<symmTensor>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapVolFields<tensor>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapSurfaceFields<scalar>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapSurfaceFields<vector>(map, mesh0, mesh1, fullyMapped);
fvMeshAdder::MapSurfaceFields<sphericalTensor>
(
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<vector>(map, mesh0, mesh1);
......
......@@ -89,7 +89,8 @@ private:
const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvPatchField, volMesh>& fld,
const GeometricField<Type, fvPatchField, volMesh>& fldToAdd
const GeometricField<Type, fvPatchField, volMesh>& fldToAdd,
const bool fullyMapped
);
//- Update single surfaceField.
......@@ -99,7 +100,8 @@ private:
const mapAddedPolyMesh& meshMap,
GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd
const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd,
const bool fullyMapped
);
//- Update single dimensionedField.
......@@ -126,16 +128,21 @@ public:
fvMesh& mesh0,
const fvMesh& mesh1,
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>
static void MapVolFields
(
const mapAddedPolyMesh&,
const fvMesh& mesh,
const fvMesh& meshToAdd
const fvMesh& meshToAdd,
const bool fullyMapped = false
);
//- Map all surfaceFields of Type
......@@ -144,7 +151,8 @@ public:
(
const mapAddedPolyMesh&,
const fvMesh& mesh,
const fvMesh& meshToAdd
const fvMesh& meshToAdd,
const bool fullyMapped = false
);
//- Map all DimensionedFields of Type
......
......@@ -36,7 +36,8 @@ void Foam::fvMeshAdder::MapVolField
const mapAddedPolyMesh& meshMap,
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();
......@@ -142,6 +143,12 @@ void Foam::fvMeshAdder::MapVolField
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.
// Note:
......@@ -204,6 +211,13 @@ void Foam::fvMeshAdder::MapVolField
directFvPatchFieldMapper patchMapper(newToAdded);
// Override mapping (for use in e.g. fvMeshDistribute where
// it sorts mapping out itself)
if (fullyMapped)
{
patchMapper.hasUnmapped() = false;
}
bfld.set
(
newPatchi,
......@@ -250,7 +264,8 @@ void Foam::fvMeshAdder::MapVolFields
(
const mapAddedPolyMesh& meshMap,
const fvMesh& mesh,
const fvMesh& meshToAdd
const fvMesh& meshToAdd,
const bool fullyMapped
)
{
HashTable<const GeometricField<Type, fvPatchField, volMesh>*> fields
......@@ -312,7 +327,7 @@ void Foam::fvMeshAdder::MapVolFields
<< "MapVolFields : mapping " << fld.name()
<< " and " << fldToAdd.name() << endl;
MapVolField<Type>(meshMap, fld, fldToAdd);
MapVolField<Type>(meshMap, fld, fldToAdd, fullyMapped);
}
else
{
......@@ -331,7 +346,8 @@ void Foam::fvMeshAdder::MapSurfaceField
const mapAddedPolyMesh& meshMap,
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();
......@@ -458,6 +474,13 @@ void Foam::fvMeshAdder::MapSurfaceField
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.
// Note:
// - boundaryField already in new order so access with newPatchi
......@@ -519,6 +542,13 @@ void Foam::fvMeshAdder::MapSurfaceField
directFvPatchFieldMapper patchMapper(newToAdded);
// Override mapping (for use in e.g. fvMeshDistribute where
// it sorts mapping out itself)
if (fullyMapped)
{
patchMapper.hasUnmapped() = false;
}
bfld.set
(
newPatchi,
......@@ -565,7 +595,8 @@ void Foam::fvMeshAdder::MapSurfaceFields
(
const mapAddedPolyMesh& meshMap,
const fvMesh& mesh,
const fvMesh& meshToAdd
const fvMesh& meshToAdd,
const bool fullyMapped
)
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> fldType;
......@@ -619,7 +650,7 @@ void Foam::fvMeshAdder::MapSurfaceFields
<< "MapSurfaceFields : mapping " << fld.name()
<< " and " << fldToAdd.name() << endl;
MapSurfaceField<Type>(meshMap, fld, fldToAdd);
MapSurfaceField<Type>(meshMap, fld, fldToAdd, fullyMapped);
}
else
{
......
......@@ -2606,7 +2606,8 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
mesh_,
domainMesh,
couples,
false // no parallel comms
false, // no parallel comms
true // fake complete mapping
);
// Update mesh data: sourceFace,sourceProc for added
......
......@@ -185,7 +185,19 @@ public:
// Evaluation
//- 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
virtual tmp<Field<Type>> integrate
......
......@@ -63,7 +63,17 @@ Foam::uniformFixedValueFvPatchField<Type>::uniformFixedValueFvPatchField
fixedValueFvPatchField<Type>(p, iF, dict, false),
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
uniformValue_(ptf.uniformValue_.clone(p.patch()))
{
// Evaluate since value not mapped
this->evaluate();
if (mapper.direct() && !mapper.hasUnmapped())
{
// 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),
uniformValue_(ptf.uniformValue_.clone(this->patch().patch()))
{
// Evaluate the profile if defined
if (uniformValue_.valid())
{
this->evaluate();
}
}
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -123,6 +135,12 @@ void Foam::uniformFixedValueFvPatchField<Type>::autoMap
{
fixedValueFvPatchField<Type>::autoMap(mapper);
uniformValue_().autoMap(mapper);
if (uniformValue_().constant())
{
// If mapper is not dependent on time we're ok to evaluate
this->evaluate();
}
}
......
......@@ -93,6 +93,11 @@ public:
return hasUnmapped_;
}
bool& hasUnmapped()
{
return hasUnmapped_;
}
const labelUList& directAddressing() const
{
return directAddressing_;
......
......@@ -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_;
}
}
......
......@@ -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
......
......@@ -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
(
......
......@@ -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
......
......@@ -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
(
......
......@@ -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
......
......@@ -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
......
......@@ -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;