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

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,7 +51,7 @@ public:
void operator()
(
Field<Type>& field,
DimensionedField<Type, GeoMesh>& field,
const MeshMapper& mapper
) const;
};
@ -72,10 +72,12 @@ void MapGeometricFields
const MeshMapper& mapper
)
{
HashTable<const GeometricField<Type, PatchField, GeoMesh>*> fields
typedef GeometricField<Type, PatchField, GeoMesh> FieldType;
HashTable<const FieldType*> fields
(
mapper.thisDb().objectRegistry::template
lookupClass<GeometricField<Type, PatchField, GeoMesh>>()
lookupClass<FieldType>()
);
// 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
// will not match.
for
(
typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
forAllConstIter(typename HashTable<const FieldType*>, fields, fieldIter)
{
GeometricField<Type, PatchField, GeoMesh>& field =
const_cast<GeometricField<Type, PatchField, GeoMesh>&>
(*fieldIter());
FieldType& field = const_cast<FieldType&>(*fieldIter());
//Note: check can be removed once pointFields are actually stored on
// the pointMesh instead of now on the polyMesh!
@ -103,17 +97,9 @@ void MapGeometricFields
}
}
for
(
typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
forAllConstIter(typename HashTable<const FieldType*>, fields, fieldIter)
{
GeometricField<Type, PatchField, GeoMesh>& field =
const_cast<GeometricField<Type, PatchField, GeoMesh>&>
(*fieldIter());
FieldType& field = const_cast<FieldType&>(*fieldIter());
if (&field.mesh() == &mapper.mesh())
{
@ -124,15 +110,11 @@ void MapGeometricFields
}
// Map the internal field
MapInternalField<Type, MeshMapper, GeoMesh>()
(
field.primitiveFieldRef(),
mapper
);
MapInternalField<Type, MeshMapper, GeoMesh>()(field.ref(), mapper);
// Map the patch fields
typename GeometricField<Type, PatchField, GeoMesh>
::Boundary& bfield = field.boundaryFieldRef();
typename FieldType::Boundary& bfield = field.boundaryFieldRef();
forAll(bfield, patchi)
{
// 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();
resF.oriented() = vf.oriented();
// 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 bool negateIfFlipped = vf.oriented()();
// 1. Create the complete field with dummy patch fields
PtrList<fvsPatchField<Type>> patchFields(patchMap.size());
@ -248,6 +247,7 @@ tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> fvMeshSubset::interpolate
)
);
GeometricField<Type, fvsPatchField, surfaceMesh>& resF = tresF.ref();
resF.oriented() = vf.oriented();
// 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];
if (cellMap[fc[i]] == own[baseFacei] || !negateIfFlipped)
if (cellMap[fc[i]] == own[baseFacei] || !vf.oriented()())
{
pfld[i] = val;
}
@ -422,6 +422,7 @@ fvMeshSubset::interpolate
)
);
GeometricField<Type, pointPatchField, pointMesh>& resF = tresF.ref();
resF.oriented() = vf.oriented();
// 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;
}

View File

@ -48,7 +48,7 @@ public:
void operator()
(
Field<Type>& field,
DimensionedField<Type, surfaceMesh>& field,
const MeshMapper& mapper
) const;
};
@ -57,7 +57,7 @@ public:
template<class Type, class MeshMapper>
void MapInternalField<Type, MeshMapper, surfaceMesh>::operator()
(
Field<Type>& field,
DimensionedField<Type, surfaceMesh>& field,
const MeshMapper& mapper
) const
{
@ -69,16 +69,22 @@ void MapInternalField<Type, MeshMapper, surfaceMesh>::operator()
<< 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
const labelList flipFaces = mapper.surfaceMap().flipFaceFlux().toc();
forAll(flipFaces, i)
if (field.oriented().oriented())
{
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()
(
Field<Type>& field,
DimensionedField<Type, volMesh>& field,
const MeshMapper& mapper
) const;
};
@ -57,7 +57,7 @@ public:
template<class Type, class MeshMapper>
void MapInternalField<Type, MeshMapper, volMesh>::operator()
(
Field<Type>& field,
DimensionedField<Type, volMesh>& field,
const MeshMapper& mapper
) const
{

View File

@ -107,7 +107,7 @@ processorSurfacePatchFieldDecomposer
weights_[i].setSize(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),
cellAddressing_(cellAddressing),
boundaryAddressing_(boundaryAddressing),
patchFieldDecomposerPtrs_
(
procMesh_.boundary().size(),
static_cast<patchFieldDecomposer*>(nullptr)
),
processorVolPatchFieldDecomposerPtrs_
(
procMesh_.boundary().size(),
static_cast<processorVolPatchFieldDecomposer*>(nullptr)
),
processorSurfacePatchFieldDecomposerPtrs_
(
procMesh_.boundary().size(),
static_cast<processorSurfacePatchFieldDecomposer*>(nullptr)
)
patchFieldDecomposerPtrs_(procMesh_.boundary().size()),
processorVolPatchFieldDecomposerPtrs_(procMesh_.boundary().size()),
processorSurfacePatchFieldDecomposerPtrs_(procMesh_.boundary().size()),
faceSign_(procMesh_.boundary().size())
{
forAll(boundaryAddressing_, patchi)
{
const fvPatch& fvp = procMesh_.boundary()[patchi];
if
(
boundaryAddressing_[patchi] >= 0
&& !isA<processorLduInterface>(procMesh.boundary()[patchi])
)
{
patchFieldDecomposerPtrs_[patchi] = new patchFieldDecomposer
patchFieldDecomposerPtrs_.set
(
procMesh_.boundary()[patchi].patchSlice(faceAddressing_),
completeMesh_.boundaryMesh()
[
boundaryAddressing_[patchi]
].start()
patchi,
new patchFieldDecomposer
(
fvp.patchSlice(faceAddressing_),
completeMesh_.boundaryMesh()
[
boundaryAddressing_[patchi]
].start()
)
);
}
else
{
processorVolPatchFieldDecomposerPtrs_[patchi] =
processorVolPatchFieldDecomposerPtrs_.set
(
patchi,
new processorVolPatchFieldDecomposer
(
completeMesh_,
procMesh_.boundary()[patchi].patchSlice(faceAddressing_)
);
fvp.patchSlice(faceAddressing_)
)
);
processorSurfacePatchFieldDecomposerPtrs_[patchi] =
processorSurfacePatchFieldDecomposerPtrs_.set
(
patchi,
new processorSurfacePatchFieldDecomposer
(
static_cast<const labelUList&>
(
procMesh_.boundary()[patchi].patchSlice
fvp.patchSlice
(
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 * * * * * * * * * * * * * * * //
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_;
//- List of patch field decomposers
List<patchFieldDecomposer*> patchFieldDecomposerPtrs_;
PtrList<patchFieldDecomposer> patchFieldDecomposerPtrs_;
List<processorVolPatchFieldDecomposer*>
PtrList<processorVolPatchFieldDecomposer>
processorVolPatchFieldDecomposerPtrs_;
List<processorSurfacePatchFieldDecomposer*>
PtrList<processorSurfacePatchFieldDecomposer>
processorSurfacePatchFieldDecomposerPtrs_;
PtrList<scalarField> faceSign_;
// Private Member Functions
//- Disallow default bitwise copy construct

View File

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

View File

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