Skip to content
Permalink
Browse files

snappyHexMesh: Per-patch face merging options

Face merging in the layer addition phase can now be controlled at a
per-patch level. By default, faces that are connected to the same cell
and patch, and which do not differ in orientation by more than the
planar angle, are merged if the patch they belong to is associated with
meshed geometry. This has not changed, but it can now be overridden with
a new "mergeFaces" keyword. This can be set in addLayersControls to
control the default behaviour on all patches, and it can be overridden
in the layer settings associated with each patch. For example:

addLayersControls
{
    mergeFaces true; // <-- Merge faces on all patches, not just those
                     // associated with geometry

    layers
    {
        wall1
        {
            nSurfaceLayers 2;
        }
        wall2
        {
            nSurfaceLayers 2;
            mergeFaces false; // <-- Do not merge faces on this patch
        }
    }
}

In addition, the patch-association has been fixed so that faces are no
longer merged on patches which are set not to merge, but are
cell-connected to patches which are.

This change makes it possible to guarantee that the surface mesh retains
the same geometry before and after layer addition, and therefore add
layers to coupled interfaces.
  • Loading branch information...
Will Bainbridge
Will Bainbridge committed Jan 29, 2019
1 parent 82356c7 commit 0497d2a17073f632c550fbddfdc2d75980212a63
@@ -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
@@ -127,6 +127,7 @@ bool Foam::combineFaces::validFace
void Foam::combineFaces::regioniseFaces
(
const scalar minCos,
const labelHashSet& patchIDs,
const label celli,
const labelList& cEdges,
Map<label>& faceRegion
@@ -145,9 +146,15 @@ void Foam::combineFaces::regioniseFaces
label p1 = patches.whichPatch(f1);

// Face can be merged if
// - same non-coupled patch
// - same non-coupled patch in list
// - small angle
if (p0 != -1 && p0 == p1 && !patches[p0].coupled())
if
(
p0 != -1
&& p0 == p1
&& !patches[p0].coupled()
&& patchIDs.found(p0)
)
{
vector f0Normal = mesh_.faceAreas()[f0];
f0Normal /= mag(f0Normal);
@@ -298,6 +305,7 @@ Foam::labelListList Foam::combineFaces::getMergeSets
(
const scalar featureCos,
const scalar minConcaveCos,
const labelHashSet& patchIDs,
const labelHashSet& boundaryCells
) const
{
@@ -317,7 +325,7 @@ Foam::labelListList Foam::combineFaces::getMergeSets

// Region per face
Map<label> faceRegion(cFaces.size());
regioniseFaces(featureCos, celli, cEdges, faceRegion);
regioniseFaces(featureCos, patchIDs, celli, cEdges, faceRegion);

// Now we have in faceRegion for every face the region with planar
// face sharing the same region. We now check whether the resulting
@@ -381,17 +389,18 @@ Foam::labelListList Foam::combineFaces::getMergeSets
Foam::labelListList Foam::combineFaces::getMergeSets
(
const scalar featureCos,
const scalar minConcaveCos
const scalar minConcaveCos,
const labelHashSet& patchIDs
) const
{
const polyBoundaryMesh& patches = mesh_.boundaryMesh();

// Pick up all cells on boundary
labelHashSet boundaryCells(mesh_.nFaces()-mesh_.nInternalFaces());

forAll(patches, patchi)
forAllConstIter(labelHashSet, patchIDs, iter)
{
const polyPatch& patch = patches[patchi];
const polyPatch& patch = patches[iter.key()];

if (!patch.coupled())
{
@@ -402,7 +411,20 @@ Foam::labelListList Foam::combineFaces::getMergeSets
}
}

return getMergeSets(featureCos, minConcaveCos, boundaryCells);
return getMergeSets(featureCos, minConcaveCos, patchIDs, boundaryCells);
}



Foam::labelListList Foam::combineFaces::getMergeSets
(
const scalar featureCos,
const scalar minConcaveCos
) const
{
const labelHashSet patchIDs(identity(mesh_.boundaryMesh().size()));

return getMergeSets(featureCos, minConcaveCos, patchIDs);
}


@@ -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
@@ -101,6 +101,7 @@ class combineFaces
void regioniseFaces
(
const scalar minCos,
const labelHashSet& patchIDs,
const label celli,
const labelList& cEdges,
Map<label>& faceRegion
@@ -153,14 +154,24 @@ public:
// Helper functions

//- Extract lists of all (non-coupled) boundary faces on selected
// cells that can be merged. Uses getFaceRegions.
// patches and cells that can be merged. Uses getFaceRegions.
labelListList getMergeSets
(
const scalar featureCos,
const scalar minConcaveCos,
const labelHashSet& patchIDs,
const labelHashSet& boundaryCells
) const;

//- Extract lists of all (non-coupled) boundary faces on selected
// patches that can be merged. Uses getFaceRegions.
labelListList getMergeSets
(
const scalar featureCos,
const scalar minConcaveCos,
const labelHashSet& patchIDs
) const;

//- Extract lists of all (non-coupled) boundary faces that can
// be merged. Uses getFaceRegions.
labelListList getMergeSets
@@ -997,7 +997,7 @@ public:
(
const scalar minCos,
const scalar concaveCos,
const labelList& patchIDs,
const labelHashSet& patchIDs,
const dictionary& motionDict,
const labelList& preserveFaces
);
@@ -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
@@ -248,49 +248,22 @@ Foam::label Foam::meshRefinement::mergePatchFacesUndo
(
const scalar minCos,
const scalar concaveCos,
const labelList& patchIDs,
const labelHashSet& patchIDs,
const dictionary& motionDict,
const labelList& preserveFaces
)
{
// Patch face merging engine
combineFaces faceCombiner(mesh_, true);

// Pick up all candidate cells on boundary
labelHashSet boundaryCells(mesh_.nFaces()-mesh_.nInternalFaces());

{
const polyBoundaryMesh& patches = mesh_.boundaryMesh();

forAll(patchIDs, i)
{
label patchi = patchIDs[i];

const polyPatch& patch = patches[patchi];

if (!patch.coupled())
{
forAll(patch, i)
{
boundaryCells.insert(mesh_.faceOwner()[patch.start()+i]);
}
}
}
}

// Get all sets of faces that can be merged. Since only faces on the same
// patch get merged there is no risk of e.g. patchID faces getting merged
// with original patches (or even processor patches). There is a risk
// though of original patch faces getting merged if they make a small
// angle. Would be pretty weird starting mesh though.
labelListList allFaceSets
(
faceCombiner.getMergeSets
(
minCos,
concaveCos,
boundaryCells
)
faceCombiner.getMergeSets(minCos, concaveCos, patchIDs)
);

// Filter out any set that contains any preserveFace
@@ -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
@@ -114,6 +114,17 @@ Foam::layerParameters::layerParameters
boundaryMesh.size(),
readScalar(dict.lookup("minThickness"))
),
mergeFaces_
(
boundaryMesh.size(),
dict.found("mergeFaces")
? (
dict.lookupType<bool>("mergeFaces")
? mergeFace::yes
: mergeFace::no
)
: mergeFace::ifOnMeshedPatch
),
featureAngle_(readScalar(dict.lookup("featureAngle"))),
concaveAngle_
(
@@ -361,6 +372,14 @@ Foam::layerParameters::layerParameters
"minThickness",
minThickness_[patchi]
);

if (layerDict.found("mergeFaces"))
{
mergeFaces_[patchi] =
layerDict.lookupType<bool>("mergeFaces")
? mergeFace::yes
: mergeFace::no;
}
}
}
}
@@ -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
@@ -76,6 +76,16 @@ public:
TOTAL_AND_EXPANSION
};

//- Enumeration defining whether to merge faces on a given patch. Read
// as a boolean (no/yes). Defaults to merging only on patches which
// were meshed/snapped to (ifOnMeshedPatch).
enum class mergeFace
{
no,
ifOnMeshedPatch,
yes
};


private:

@@ -112,6 +122,9 @@ private:
//- Minimum total thickness
scalarField minThickness_;

//- Whether to merge boundary faces of the same layer cell
List<mergeFace> mergeFaces_;


scalar featureAngle_;

@@ -225,6 +238,12 @@ public:
return minThickness_;
}

//- Whether to merge boundary faces of the same layer cell
const List<mergeFace>& mergeFaces() const
{
return mergeFaces_;
}


// Control

@@ -2832,11 +2832,25 @@ void Foam::snappyLayerDriver::mergePatchFacesUndo
duplicateFace[cpl[1]] = cpl[0];
}

// Get a set of which patches are to have faces merged
labelHashSet patchIDs(meshRefiner_.meshedPatches());
forAll(mesh.boundaryMesh(), patchi)
{
if (layerParams.mergeFaces()[patchi] == layerParameters::mergeFace::no)
{
patchIDs.unset(patchi);
}
if (layerParams.mergeFaces()[patchi] == layerParameters::mergeFace::yes)
{
patchIDs.set(patchi);
}
}

label nChanged = meshRefiner_.mergePatchFacesUndo
(
minCos,
concaveCos,
meshRefiner_.meshedPatches(),
patchIDs,
motionDict,
duplicateFace
);

0 comments on commit 0497d2a

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