ENH: orientedFields - updated mapping and parallel utils

This commit is contained in:
Andrew Heather
2017-05-04 15:32:51 +01:00
parent 72d39f1707
commit ff132ff5f6
9 changed files with 150 additions and 126 deletions

View File

@ -66,7 +66,7 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeInternalField
IOobject::NO_WRITE IOobject::NO_WRITE
); );
return tmp<DimensionedField<Type, volMesh>> tmp<DimensionedField<Type, volMesh>> tfield
( (
new DimensionedField<Type, volMesh> new DimensionedField<Type, volMesh>
( (
@ -76,6 +76,10 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeInternalField
internalField internalField
) )
); );
tfield.ref().oriented() = fld.oriented();
return tfield;
} }
@ -209,7 +213,7 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeField
IOobject::NO_WRITE IOobject::NO_WRITE
); );
return tmp<GeometricField<Type, fvPatchField, volMesh>> tmp<GeometricField<Type, fvPatchField, volMesh>> tfield
( (
new GeometricField<Type, fvPatchField, volMesh> new GeometricField<Type, fvPatchField, volMesh>
( (
@ -220,6 +224,10 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeField
basePatchFields basePatchFields
) )
); );
tfield.ref().oriented()= fld.oriented();
return tfield;
} }
@ -372,7 +380,7 @@ Foam::parFvFieldReconstructor::reconstructFvSurfaceField
IOobject::NO_WRITE IOobject::NO_WRITE
); );
return tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tfield
( (
new GeometricField<Type, fvsPatchField, surfaceMesh> new GeometricField<Type, fvsPatchField, surfaceMesh>
( (
@ -383,6 +391,10 @@ Foam::parFvFieldReconstructor::reconstructFvSurfaceField
basePatchFields basePatchFields
) )
); );
tfield.ref().oriented() = fld.oriented();
return tfield;
} }

View File

@ -3,7 +3,7 @@
\\ / 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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -51,7 +51,7 @@ public:
void operator() void operator()
( (
Field<Type>& field, DimensionedField<Type, GeoMesh>& field,
const MeshMapper& mapper const MeshMapper& mapper
) const; ) const;
}; };
@ -72,10 +72,12 @@ void MapGeometricFields
const MeshMapper& mapper const MeshMapper& mapper
) )
{ {
HashTable<const GeometricField<Type, PatchField, GeoMesh>*> fields typedef GeometricField<Type, PatchField, GeoMesh> FieldType;
HashTable<const FieldType*> fields
( (
mapper.thisDb().objectRegistry::template mapper.thisDb().objectRegistry::template
lookupClass<GeometricField<Type, PatchField, GeoMesh>>() lookupClass<FieldType>()
); );
// It is necessary to enforce that all old-time fields are stored // It is necessary to enforce that all old-time fields are stored
@ -83,17 +85,9 @@ void MapGeometricFields
// old-time-level field is mapped before the field itself, sizes // old-time-level field is mapped before the field itself, sizes
// will not match. // will not match.
for forAllConstIter(typename HashTable<const FieldType*>, fields, fieldIter)
(
typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{ {
GeometricField<Type, PatchField, GeoMesh>& field = FieldType& field = const_cast<FieldType&>(*fieldIter());
const_cast<GeometricField<Type, PatchField, GeoMesh>&>
(*fieldIter());
//Note: check can be removed once pointFields are actually stored on //Note: check can be removed once pointFields are actually stored on
// the pointMesh instead of now on the polyMesh! // the pointMesh instead of now on the polyMesh!
@ -103,17 +97,9 @@ void MapGeometricFields
} }
} }
for forAllConstIter(typename HashTable<const FieldType*>, fields, fieldIter)
(
typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{ {
GeometricField<Type, PatchField, GeoMesh>& field = FieldType& field = const_cast<FieldType&>(*fieldIter());
const_cast<GeometricField<Type, PatchField, GeoMesh>&>
(*fieldIter());
if (&field.mesh() == &mapper.mesh()) if (&field.mesh() == &mapper.mesh())
{ {
@ -124,15 +110,11 @@ void MapGeometricFields
} }
// Map the internal field // Map the internal field
MapInternalField<Type, MeshMapper, GeoMesh>() MapInternalField<Type, MeshMapper, GeoMesh>()(field.ref(), mapper);
(
field.primitiveFieldRef(),
mapper
);
// Map the patch fields // Map the patch fields
typename GeometricField<Type, PatchField, GeoMesh> typename FieldType::Boundary& bfield = field.boundaryFieldRef();
::Boundary& bfield = field.boundaryFieldRef();
forAll(bfield, patchi) forAll(bfield, patchi)
{ {
// Cannot check sizes for patch fields because of // Cannot check sizes for patch fields because of

View File

@ -102,6 +102,7 @@ tmp<GeometricField<Type, fvPatchField, volMesh>> fvMeshSubset::interpolate
) )
); );
GeometricField<Type, fvPatchField, volMesh>& resF = tresF.ref(); GeometricField<Type, fvPatchField, volMesh>& resF = tresF.ref();
resF.oriented() = vf.oriented();
// 2. Change the fvPatchFields to the correct type using a mapper // 2. Change the fvPatchFields to the correct type using a mapper
@ -183,8 +184,6 @@ tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> fvMeshSubset::interpolate
const labelList& faceMap const labelList& faceMap
) )
{ {
const bool negateIfFlipped = vf.oriented()();
// 1. Create the complete field with dummy patch fields // 1. Create the complete field with dummy patch fields
PtrList<fvsPatchField<Type>> patchFields(patchMap.size()); PtrList<fvsPatchField<Type>> patchFields(patchMap.size());
@ -248,6 +247,7 @@ tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> fvMeshSubset::interpolate
) )
); );
GeometricField<Type, fvsPatchField, surfaceMesh>& resF = tresF.ref(); GeometricField<Type, fvsPatchField, surfaceMesh>& resF = tresF.ref();
resF.oriented() = vf.oriented();
// 2. Change the fvsPatchFields to the correct type using a mapper // 2. Change the fvsPatchFields to the correct type using a mapper
@ -311,7 +311,7 @@ tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> fvMeshSubset::interpolate
{ {
Type val = vf.internalField()[baseFacei]; Type val = vf.internalField()[baseFacei];
if (cellMap[fc[i]] == own[baseFacei] || !negateIfFlipped) if (cellMap[fc[i]] == own[baseFacei] || !vf.oriented()())
{ {
pfld[i] = val; pfld[i] = val;
} }
@ -422,6 +422,7 @@ fvMeshSubset::interpolate
) )
); );
GeometricField<Type, pointPatchField, pointMesh>& resF = tresF.ref(); GeometricField<Type, pointPatchField, pointMesh>& resF = tresF.ref();
resF.oriented() = vf.oriented();
// 2. Change the pointPatchFields to the correct type using a mapper // 2. Change the pointPatchFields to the correct type using a mapper
@ -531,6 +532,8 @@ tmp<DimensionedField<Type, volMesh>> fvMeshSubset::interpolate
) )
); );
tresF.ref().oriented() = df.oriented();
return tresF; return tresF;
} }

View File

@ -48,7 +48,7 @@ public:
void operator() void operator()
( (
Field<Type>& field, DimensionedField<Type, surfaceMesh>& field,
const MeshMapper& mapper const MeshMapper& mapper
) const; ) const;
}; };
@ -57,7 +57,7 @@ public:
template<class Type, class MeshMapper> template<class Type, class MeshMapper>
void MapInternalField<Type, MeshMapper, surfaceMesh>::operator() void MapInternalField<Type, MeshMapper, surfaceMesh>::operator()
( (
Field<Type>& field, DimensionedField<Type, surfaceMesh>& field,
const MeshMapper& mapper const MeshMapper& mapper
) const ) const
{ {
@ -69,16 +69,22 @@ void MapInternalField<Type, MeshMapper, surfaceMesh>::operator()
<< abort(FatalError); << abort(FatalError);
} }
field.autoMap(mapper.surfaceMap()); // Passing in oriented flag so that oriented fields (e.g. phi) are negated
// if flipped. Un-oriented fields, e.g U interpolated to faces (Uf) are not
// touched
field.autoMap(mapper.surfaceMap(), field.oriented().oriented());
// Flip the flux if (field.oriented().oriented())
const labelList flipFaces = mapper.surfaceMap().flipFaceFlux().toc();
forAll(flipFaces, i)
{ {
if (flipFaces[i] < field.size()) // Flip the flux
const labelList flipFaces = mapper.surfaceMap().flipFaceFlux().toc();
forAll(flipFaces, i)
{ {
field[flipFaces[i]] *= -1.0; if (flipFaces[i] < field.size())
{
field[flipFaces[i]] *= -1.0;
}
} }
} }
} }

View File

@ -48,7 +48,7 @@ public:
void operator() void operator()
( (
Field<Type>& field, DimensionedField<Type, volMesh>& field,
const MeshMapper& mapper const MeshMapper& mapper
) const; ) const;
}; };
@ -57,7 +57,7 @@ public:
template<class Type, class MeshMapper> template<class Type, class MeshMapper>
void MapInternalField<Type, MeshMapper, volMesh>::operator() void MapInternalField<Type, MeshMapper, volMesh>::operator()
( (
Field<Type>& field, DimensionedField<Type, volMesh>& field,
const MeshMapper& mapper const MeshMapper& mapper
) const ) const
{ {

View File

@ -107,7 +107,7 @@ processorSurfacePatchFieldDecomposer
weights_[i].setSize(1); weights_[i].setSize(1);
addressing_[i][0] = mag(addressingSlice[i]) - 1; addressing_[i][0] = mag(addressingSlice[i]) - 1;
weights_[i][0] = sign(addressingSlice[i]); weights_[i][0] = 1;
} }
} }
@ -126,59 +126,75 @@ Foam::fvFieldDecomposer::fvFieldDecomposer
faceAddressing_(faceAddressing), faceAddressing_(faceAddressing),
cellAddressing_(cellAddressing), cellAddressing_(cellAddressing),
boundaryAddressing_(boundaryAddressing), boundaryAddressing_(boundaryAddressing),
patchFieldDecomposerPtrs_ patchFieldDecomposerPtrs_(procMesh_.boundary().size()),
( processorVolPatchFieldDecomposerPtrs_(procMesh_.boundary().size()),
procMesh_.boundary().size(), processorSurfacePatchFieldDecomposerPtrs_(procMesh_.boundary().size()),
static_cast<patchFieldDecomposer*>(nullptr) faceSign_(procMesh_.boundary().size())
),
processorVolPatchFieldDecomposerPtrs_
(
procMesh_.boundary().size(),
static_cast<processorVolPatchFieldDecomposer*>(nullptr)
),
processorSurfacePatchFieldDecomposerPtrs_
(
procMesh_.boundary().size(),
static_cast<processorSurfacePatchFieldDecomposer*>(nullptr)
)
{ {
forAll(boundaryAddressing_, patchi) forAll(boundaryAddressing_, patchi)
{ {
const fvPatch& fvp = procMesh_.boundary()[patchi];
if if
( (
boundaryAddressing_[patchi] >= 0 boundaryAddressing_[patchi] >= 0
&& !isA<processorLduInterface>(procMesh.boundary()[patchi]) && !isA<processorLduInterface>(procMesh.boundary()[patchi])
) )
{ {
patchFieldDecomposerPtrs_[patchi] = new patchFieldDecomposer patchFieldDecomposerPtrs_.set
( (
procMesh_.boundary()[patchi].patchSlice(faceAddressing_), patchi,
completeMesh_.boundaryMesh() new patchFieldDecomposer
[ (
boundaryAddressing_[patchi] fvp.patchSlice(faceAddressing_),
].start() completeMesh_.boundaryMesh()
[
boundaryAddressing_[patchi]
].start()
)
); );
} }
else else
{ {
processorVolPatchFieldDecomposerPtrs_[patchi] = processorVolPatchFieldDecomposerPtrs_.set
(
patchi,
new processorVolPatchFieldDecomposer new processorVolPatchFieldDecomposer
( (
completeMesh_, completeMesh_,
procMesh_.boundary()[patchi].patchSlice(faceAddressing_) fvp.patchSlice(faceAddressing_)
); )
);
processorSurfacePatchFieldDecomposerPtrs_[patchi] = processorSurfacePatchFieldDecomposerPtrs_.set
(
patchi,
new processorSurfacePatchFieldDecomposer new processorSurfacePatchFieldDecomposer
( (
static_cast<const labelUList&> static_cast<const labelUList&>
( (
procMesh_.boundary()[patchi].patchSlice fvp.patchSlice
( (
faceAddressing_ faceAddressing_
) )
) )
); )
);
faceSign_.set
(
patchi,
new scalarField(fvp.patchSlice(faceAddressing_).size())
);
{
const SubList<label> fa = fvp.patchSlice(faceAddressing_);
scalarField& s = faceSign_[patchi];
forAll(s, i)
{
s[i] = sign(fa[i]);
}
}
} }
} }
} }
@ -187,30 +203,7 @@ Foam::fvFieldDecomposer::fvFieldDecomposer
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fvFieldDecomposer::~fvFieldDecomposer() Foam::fvFieldDecomposer::~fvFieldDecomposer()
{ {}
forAll(patchFieldDecomposerPtrs_, patchi)
{
if (patchFieldDecomposerPtrs_[patchi])
{
delete patchFieldDecomposerPtrs_[patchi];
}
}
forAll(processorVolPatchFieldDecomposerPtrs_, patchi)
{
if (processorVolPatchFieldDecomposerPtrs_[patchi])
{
delete processorVolPatchFieldDecomposerPtrs_[patchi];
}
}
forAll(processorSurfacePatchFieldDecomposerPtrs_, patchi)
{
if (processorSurfacePatchFieldDecomposerPtrs_[patchi])
{
delete processorSurfacePatchFieldDecomposerPtrs_[patchi];
}
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -215,15 +215,18 @@ private:
const labelList& boundaryAddressing_; const labelList& boundaryAddressing_;
//- List of patch field decomposers //- List of patch field decomposers
List<patchFieldDecomposer*> patchFieldDecomposerPtrs_; PtrList<patchFieldDecomposer> patchFieldDecomposerPtrs_;
List<processorVolPatchFieldDecomposer*> PtrList<processorVolPatchFieldDecomposer>
processorVolPatchFieldDecomposerPtrs_; processorVolPatchFieldDecomposerPtrs_;
List<processorSurfacePatchFieldDecomposer*> PtrList<processorSurfacePatchFieldDecomposer>
processorSurfacePatchFieldDecomposerPtrs_; processorSurfacePatchFieldDecomposerPtrs_;
PtrList<scalarField> faceSign_;
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct

View File

@ -40,6 +40,8 @@ Foam::fvFieldDecomposer::decomposeField
const bool allowUnknownPatchFields const bool allowUnknownPatchFields
) const ) const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
// 1. Create the complete field with dummy patch fields // 1. Create the complete field with dummy patch fields
PtrList<fvPatchField<Type>> patchFields(boundaryAddressing_.size()); PtrList<fvPatchField<Type>> patchFields(boundaryAddressing_.size());
@ -58,9 +60,9 @@ Foam::fvFieldDecomposer::decomposeField
} }
// Create the field for the processor // Create the field for the processor
tmp<GeometricField<Type, fvPatchField, volMesh>> tresF tmp<VolFieldType> tresF
( (
new GeometricField<Type, fvPatchField, volMesh> new VolFieldType
( (
IOobject IOobject
( (
@ -76,18 +78,18 @@ Foam::fvFieldDecomposer::decomposeField
patchFields patchFields
) )
); );
GeometricField<Type, fvPatchField, volMesh>& resF = tresF.ref(); VolFieldType& resF = tresF.ref();
resF.oriented() = field().oriented();
// 2. Change the fvPatchFields to the correct type using a mapper // 2. Change the fvPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field) // constructor (with reference to the now correct internal field)
typename GeometricField<Type, fvPatchField, volMesh>:: typename VolFieldType::Boundary& bf = resF.boundaryFieldRef();
Boundary& bf = resF.boundaryFieldRef();
forAll(bf, patchi) forAll(bf, patchi)
{ {
if (patchFieldDecomposerPtrs_[patchi]) if (patchFieldDecomposerPtrs_.set(patchi))
{ {
bf.set bf.set
( (
@ -97,7 +99,7 @@ Foam::fvFieldDecomposer::decomposeField
field.boundaryField()[boundaryAddressing_[patchi]], field.boundaryField()[boundaryAddressing_[patchi]],
procMesh_.boundary()[patchi], procMesh_.boundary()[patchi],
resF(), resF(),
*patchFieldDecomposerPtrs_[patchi] patchFieldDecomposerPtrs_[patchi]
) )
); );
} }
@ -113,7 +115,7 @@ Foam::fvFieldDecomposer::decomposeField
Field<Type> Field<Type>
( (
field.primitiveField(), field.primitiveField(),
*processorVolPatchFieldDecomposerPtrs_[patchi] processorVolPatchFieldDecomposerPtrs_[patchi]
) )
) )
); );
@ -130,7 +132,7 @@ Foam::fvFieldDecomposer::decomposeField
Field<Type> Field<Type>
( (
field.primitiveField(), field.primitiveField(),
*processorVolPatchFieldDecomposerPtrs_[patchi] processorVolPatchFieldDecomposerPtrs_[patchi]
) )
) )
); );
@ -166,6 +168,8 @@ Foam::fvFieldDecomposer::decomposeField
const GeometricField<Type, fvsPatchField, surfaceMesh>& field const GeometricField<Type, fvsPatchField, surfaceMesh>& field
) const ) const
{ {
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
labelList mapAddr labelList mapAddr
( (
labelList::subList labelList::subList
@ -200,7 +204,7 @@ Foam::fvFieldDecomposer::decomposeField
forAll(field.boundaryField(), patchi) forAll(field.boundaryField(), patchi)
{ {
const Field<Type> & p = field.boundaryField()[patchi]; const Field<Type>& p = field.boundaryField()[patchi];
const label patchStart = field.mesh().boundaryMesh()[patchi].start(); const label patchStart = field.mesh().boundaryMesh()[patchi].start();
@ -228,9 +232,9 @@ Foam::fvFieldDecomposer::decomposeField
); );
} }
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tresF tmp<SurfaceFieldType> tresF
( (
new GeometricField<Type, fvsPatchField, surfaceMesh> new SurfaceFieldType
( (
IOobject IOobject
( (
@ -246,18 +250,17 @@ Foam::fvFieldDecomposer::decomposeField
patchFields patchFields
) )
); );
GeometricField<Type, fvsPatchField, surfaceMesh>& resF = tresF.ref(); SurfaceFieldType& resF = tresF.ref();
resF.oriented() = field().oriented();
// 2. Change the fvsPatchFields to the correct type using a mapper // 2. Change the fvsPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field) // constructor (with reference to the now correct internal field)
typename GeometricField<Type, fvsPatchField, surfaceMesh>:: typename SurfaceFieldType::Boundary& bf = resF.boundaryFieldRef();
Boundary& bf = resF.boundaryFieldRef();
forAll(boundaryAddressing_, patchi) forAll(boundaryAddressing_, patchi)
{ {
if (patchFieldDecomposerPtrs_[patchi]) if (patchFieldDecomposerPtrs_.set(patchi))
{ {
bf.set bf.set
( (
@ -267,7 +270,7 @@ Foam::fvFieldDecomposer::decomposeField
field.boundaryField()[boundaryAddressing_[patchi]], field.boundaryField()[boundaryAddressing_[patchi]],
procMesh_.boundary()[patchi], procMesh_.boundary()[patchi],
resF(), resF(),
*patchFieldDecomposerPtrs_[patchi] patchFieldDecomposerPtrs_[patchi]
) )
); );
} }
@ -283,10 +286,15 @@ Foam::fvFieldDecomposer::decomposeField
Field<Type> Field<Type>
( (
allFaceField, allFaceField,
*processorSurfacePatchFieldDecomposerPtrs_[patchi] processorSurfacePatchFieldDecomposerPtrs_[patchi]
) )
) )
); );
if (resF.oriented().oriented())
{
bf[patchi] *= faceSign_[patchi];
}
} }
else if (isA<processorFvPatch>(procMesh_.boundary()[patchi])) else if (isA<processorFvPatch>(procMesh_.boundary()[patchi]))
{ {
@ -300,10 +308,15 @@ Foam::fvFieldDecomposer::decomposeField
Field<Type> Field<Type>
( (
allFaceField, allFaceField,
*processorSurfacePatchFieldDecomposerPtrs_[patchi] processorSurfacePatchFieldDecomposerPtrs_[patchi]
) )
) )
); );
if (resF.oriented().oriented())
{
bf[patchi] *= faceSign_[patchi];
}
} }
else else
{ {

View File

@ -56,7 +56,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
); );
} }
return tmp<DimensionedField<Type, volMesh>> tmp<DimensionedField<Type, volMesh>> tfield
( (
new DimensionedField<Type, volMesh> new DimensionedField<Type, volMesh>
( (
@ -66,6 +66,10 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
internalField internalField
) )
); );
tfield.ref().oriented() = procFields[0].oriented();
return tfield;
} }
@ -282,7 +286,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
// Now construct and write the field // Now construct and write the field
// setting the internalField and patchFields // setting the internalField and patchFields
return tmp<GeometricField<Type, fvPatchField, volMesh>> tmp<GeometricField<Type, fvPatchField, volMesh>> tfield
( (
new GeometricField<Type, fvPatchField, volMesh> new GeometricField<Type, fvPatchField, volMesh>
( (
@ -293,6 +297,10 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
patchFields patchFields
) )
); );
tfield.ref().oriented() = procFields[0].oriented();
return tfield;
} }
@ -523,7 +531,7 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
// Now construct and write the field // Now construct and write the field
// setting the internalField and patchFields // setting the internalField and patchFields
return tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tfield
( (
new GeometricField<Type, fvsPatchField, surfaceMesh> new GeometricField<Type, fvsPatchField, surfaceMesh>
( (
@ -534,6 +542,10 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
patchFields patchFields
) )
); );
tfield.ref().oriented() = procFields[0].oriented();
return tfield;
} }