Skip to content
Permalink
Browse files

decomposePar: Apply face-flipping to surfaceScalarFields only

Flux fields (surfaceScalarFields) are flipped as before but this process is no
longer applied to surfaceVectorFields (Uf etc.) for which it is not appropriate.
decomposePar is now consistent with reconstructPar with respect to
surfaceVectorFields.

Patch contributed by Mattijs Janssens.
  • Loading branch information...
Henry Weller
Henry Weller committed Apr 29, 2019
1 parent af45bd6 commit 3395a5ba358766bd9d6b9c70a3e89aab0aa8e72c
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -92,26 +92,6 @@ processorVolPatchFieldDecomposer
}


Foam::fvFieldDecomposer::processorSurfacePatchFieldDecomposer::
processorSurfacePatchFieldDecomposer
(
const labelUList& addressingSlice
)
:
addressing_(addressingSlice.size()),
weights_(addressingSlice.size())
{
forAll(addressing_, i)
{
addressing_[i].setSize(1);
weights_[i].setSize(1);

addressing_[i][0] = mag(addressingSlice[i]) - 1;
weights_[i][0] = sign(addressingSlice[i]);
}
}


Foam::fvFieldDecomposer::fvFieldDecomposer
(
const fvMesh& completeMesh,
@@ -135,11 +115,6 @@ Foam::fvFieldDecomposer::fvFieldDecomposer
(
procMesh_.boundary().size(),
static_cast<processorVolPatchFieldDecomposer*>(nullptr)
),
processorSurfacePatchFieldDecomposerPtrs_
(
procMesh_.boundary().size(),
static_cast<processorSurfacePatchFieldDecomposer*>(nullptr)
)
{
forAll(boundaryAddressing_, patchi)
@@ -167,18 +142,6 @@ Foam::fvFieldDecomposer::fvFieldDecomposer
completeMesh_,
procMesh_.boundary()[patchi].patchSlice(faceAddressing_)
);

processorSurfacePatchFieldDecomposerPtrs_[patchi] =
new processorSurfacePatchFieldDecomposer
(
static_cast<const labelUList&>
(
procMesh_.boundary()[patchi].patchSlice
(
faceAddressing_
)
)
);
}
}
}
@@ -203,14 +166,6 @@ Foam::fvFieldDecomposer::~fvFieldDecomposer()
delete processorVolPatchFieldDecomposerPtrs_[patchi];
}
}

forAll(processorSurfacePatchFieldDecomposerPtrs_, patchi)
{
if (processorSurfacePatchFieldDecomposerPtrs_[patchi])
{
delete processorSurfacePatchFieldDecomposerPtrs_[patchi];
}
}
}

// ************************************************************************* //
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -220,12 +220,18 @@ private:
List<processorVolPatchFieldDecomposer*>
processorVolPatchFieldDecomposerPtrs_;

List<processorSurfacePatchFieldDecomposer*>
processorSurfacePatchFieldDecomposerPtrs_;


// Private Member Functions

//- Helper: map & optionally flip a (face) field
template<class Type>
static tmp<Field<Type>> mapField
(
const Field<Type>& field,
const labelUList& mapAndSign,
const bool applyFlip
);

//- Disallow default bitwise copy construct
fvFieldDecomposer(const fvFieldDecomposer&);

@@ -32,6 +32,40 @@ License

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::fvFieldDecomposer::mapField
(
const Field<Type>& field,
const labelUList& mapAndSign,
const bool applyFlip
)
{
tmp<Field<Type>> tfld(new Field<Type>(mapAndSign.size()));
Field<Type>& fld = tfld.ref();

if (applyFlip)
{
forAll(mapAndSign, i)
{
if (mapAndSign[i] < 0)
{
fld[i] = -field[-mapAndSign[i] - 1];
}
else
{
fld[i] = field[mapAndSign[i] - 1];
}
}
}
else
{
// Ignore face flipping
fld.map(field, mag(mapAndSign) - 1);
}
return tfld;
}


template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::fvFieldDecomposer::decomposeField
@@ -87,6 +121,8 @@ Foam::fvFieldDecomposer::decomposeField

forAll(bf, patchi)
{
const fvPatch& procPatch = procMesh_.boundary()[patchi];

if (patchFieldDecomposerPtrs_[patchi])
{
bf.set
@@ -95,20 +131,20 @@ Foam::fvFieldDecomposer::decomposeField
fvPatchField<Type>::New
(
field.boundaryField()[boundaryAddressing_[patchi]],
procMesh_.boundary()[patchi],
procPatch,
resF(),
*patchFieldDecomposerPtrs_[patchi]
)
);
}
else if (isA<processorCyclicFvPatch>(procMesh_.boundary()[patchi]))
else if (isA<processorCyclicFvPatch>(procPatch))
{
bf.set
(
patchi,
new processorCyclicFvPatchField<Type>
(
procMesh_.boundary()[patchi],
procPatch,
resF(),
Field<Type>
(
@@ -118,14 +154,14 @@ Foam::fvFieldDecomposer::decomposeField
)
);
}
else if (isA<processorFvPatch>(procMesh_.boundary()[patchi]))
else if (isA<processorFvPatch>(procPatch))
{
bf.set
(
patchi,
new processorFvPatchField<Type>
(
procMesh_.boundary()[patchi],
procPatch,
resF(),
Field<Type>
(
@@ -142,7 +178,7 @@ Foam::fvFieldDecomposer::decomposeField
patchi,
new emptyFvPatchField<Type>
(
procMesh_.boundary()[patchi],
procPatch,
resF()
)
);
@@ -166,41 +202,9 @@ Foam::fvFieldDecomposer::decomposeField
const GeometricField<Type, fvsPatchField, surfaceMesh>& field
) const
{
labelField mapAddr
(
labelList::subList
(
faceAddressing_,
procMesh_.nInternalFaces()
)
);

Field<Type> internalField(procMesh_.nInternalFaces());
// Apply flipping to surfaceScalarFields only
const bool doFlip = (pTraits<Type>::nComponents == 1);

if (pTraits<Type>::nComponents == 1)
{
// Assume all scalar surfaceFields are oriented flux fields
// and flip the sign of the flux if necessary

forAll(mapAddr, i)
{
if (mapAddr[i] < 0)
{
internalField[i] = -field[mag(mapAddr[i]) - 1];
}
else
{
internalField[i] = field[mapAddr[i] - 1];
}
}
}
else
{
// Ignore face flipping
internalField.map(field.primitiveField(), mag(mapAddr) - 1);
}

// internalField.map(field.primitiveField(), mag(mapAddr) - 1);

// Problem with addressing when a processor patch picks up both internal
// faces and faces from cyclic boundaries. This is a bit of a hack, but
@@ -258,7 +262,16 @@ Foam::fvFieldDecomposer::decomposeField
),
procMesh_,
field.dimensions(),
internalField,
mapField
(
field,
labelList::subList
(
faceAddressing_,
procMesh_.nInternalFaces()
),
doFlip
),
patchFields
)
);
@@ -273,6 +286,8 @@ Foam::fvFieldDecomposer::decomposeField

forAll(boundaryAddressing_, patchi)
{
const fvPatch& procPatch = procMesh_.boundary()[patchi];

if (patchFieldDecomposerPtrs_[patchi])
{
bf.set
@@ -281,50 +296,63 @@ Foam::fvFieldDecomposer::decomposeField
fvsPatchField<Type>::New
(
field.boundaryField()[boundaryAddressing_[patchi]],
procMesh_.boundary()[patchi],
procPatch,
resF(),
*patchFieldDecomposerPtrs_[patchi]
)
);
}
else if (isA<processorCyclicFvPatch>(procMesh_.boundary()[patchi]))
else
{
bf.set
(
patchi,
new processorCyclicFvsPatchField<Type>
// Do our own mapping - avoids a lot of mapping complexity

if (isA<processorCyclicFvPatch>(procPatch))
{
bf.set
(
procMesh_.boundary()[patchi],
resF(),
Field<Type>
patchi,
new processorCyclicFvsPatchField<Type>
(
allFaceField,
*processorSurfacePatchFieldDecomposerPtrs_[patchi]
procPatch,
resF(),
mapField
(
allFaceField,
procPatch.patchSlice
(
faceAddressing_
),
doFlip
)
)
)
);
}
else if (isA<processorFvPatch>(procMesh_.boundary()[patchi]))
{
bf.set
(
patchi,
new processorFvsPatchField<Type>
);
}
else if (isA<processorFvPatch>(procPatch))
{
bf.set
(
procMesh_.boundary()[patchi],
resF(),
Field<Type>
patchi,
new processorFvsPatchField<Type>
(
allFaceField,
*processorSurfacePatchFieldDecomposerPtrs_[patchi]
procPatch,
resF(),
mapField
(
allFaceField,
procPatch.patchSlice
(
faceAddressing_
),
doFlip
)
)
)
);
}
else
{
FatalErrorInFunction
<< "Unknown type." << abort(FatalError);
);
}
else
{
FatalErrorInFunction
<< "Unknown type." << abort(FatalError);
}
}
}

0 comments on commit 3395a5b

Please sign in to comment.
You can’t perform that action at this time.