Merge branch 'feature/donorBasedOverlapFringe' of ssh://git.code.sf.net/u/vvukcevic/foam-extend-4.0-vv into feature/donorBasedOverlapFringe

This commit is contained in:
Vuko Vukcevic 2019-07-11 14:36:18 +02:00
commit 4203848450
2 changed files with 337 additions and 482 deletions

View file

@ -26,8 +26,6 @@ License
#include "cuttingPatchFringe.H"
#include "oversetMesh.H"
#include "oversetRegion.H"
#include "faceCellsFringe.H"
#include "oversetRegion.H"
#include "polyPatchID.H"
#include "addToRunTimeSelectionTable.H"
#include "syncTools.H"
@ -48,80 +46,6 @@ namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::cuttingPatchFringe::init() const
{
// Set size of the list containing IDs
connectedRegionIDs_.setSize(connectedRegionNames_.size());
// Get list of all overset regions
const PtrList<oversetRegion>& allRegions =
this->region().overset().regions();
// Create list of all region names for easy lookup
wordList allRegionNames(allRegions.size());
forAll (allRegionNames, arI)
{
allRegionNames[arI] = allRegions[arI].name();
}
// Loop through all regions, collect region IDs and do sanity checks
forAll (connectedRegionNames_, crI)
{
// Get name of this connected region
const word& crName = connectedRegionNames_[crI];
// Find this region in the list of all regions
const label regionID = findIndex(allRegionNames, crName);
if (regionID == -1)
{
FatalErrorIn("void cuttingPatchFringe::init() const")
<< "Region " << crName << " not found in list of regions."
<< "List of overset regions: " << allRegionNames
<< abort(FatalError);
}
// Check whether the region is already present in the list
if (findIndex(connectedRegionIDs_, regionID) != -1)
{
// Duplicate found. Issue an error
FatalErrorIn("void cuttingPatchFringe::init() const")
<< "Region " << crName << " found in the list of regions"
<< " more than once." << nl
<< " This is not allowed." << nl
<< "Make sure that you don't have duplicate entries."
<< abort(FatalError);
}
// Collect the region index in the list
connectedRegionIDs_[crI] = regionID;
// Sanity check: if the specified connected donor region has more than 1
// donor regions, this fringe algorithm is attempted to be used for
// something that's not intended. Issue an error
if (allRegions[regionID].donorRegions().size() != 1)
{
FatalErrorIn("void cuttingPatchFringe::init() const")
<< "Region " << crName << " specified as connected region, but"
<< " that region has "
<< allRegions[regionID].donorRegions().size()
<< " donor regions."
<< abort(FatalError);
}
// Sanity check whether the donor region of connected region is actually
// this region
if (allRegions[regionID].donorRegions()[0] != this->region().index())
{
FatalErrorIn("void cuttingPatchFringe::init() const")
<< "The donor region of region " << crName
<< " should be only region " << this->region().name()
<< abort(FatalError);
}
}
}
void Foam::cuttingPatchFringe::calcAddressing() const
{
// Make sure that either acceptorsPtr is unnalocated or if it is allocated,
@ -135,89 +59,41 @@ void Foam::cuttingPatchFringe::calcAddressing() const
<< abort(FatalError);
}
if (!isInitialized_)
{
// This is the first call, initialize the data and set flag to true
init();
isInitialized_ = true;
}
// Get list of all overset regions
const PtrList<oversetRegion>& allRegions =
this->region().overset().regions();
// Sets containing all acceptors and all holes for all connected regions
// Get polyMesh
const polyMesh& mesh = this->mesh();
labelHashSet allAcceptors(0.02*mesh.nCells());
labelHashSet allFringeHoles(0.02*mesh.nCells());
if (debug)
{
Info<< "All dependent fringes are ready."
<< " Starting face cells cut patch fringe assembly..." << endl;
}
// Collect all cutting patches
labelHashSet patchIDs(cuttingPatchNames_.size());
// Loop through connected regions
forAll (connectedRegionIDs_, crI)
{
// Get ID of this region
const label& regionID = connectedRegionIDs_[crI];
// Get fringe of the connected region
const oversetFringe& fringe = allRegions[regionID].fringe();
// If this is not faceCells fringe, issue an Error. This fringe
// selection algorithm is intended to work only with faceCells fringe on
// the other side. VV, 9/Apr/2019
if (!isA<faceCellsFringe>(fringe))
{
FatalErrorIn
(
"void Foam::cuttingPatchFringe::"
"updateIteration(donorAcceptorList&) const"
) << "cuttingPatch fringe is designed to work"
<< " with faceCells fringe as a connected region fringe."
<< nl
<< "Connected overset region " << allRegions[regionID].name()
<< " has " << fringe.type() << " fringe type. "
<< nl
<< "Proceed with care!"
<< abort(FatalError);
}
const faceCellsFringe& fcFringe =
refCast<const faceCellsFringe>(fringe);
// Get patch names from faceCells fringe
const wordList& fcPatchNames = fcFringe.patchNames();
// Find the patches
labelHashSet patchIDs;
forAll (fcPatchNames, nameI)
forAll (cuttingPatchNames_, nameI)
{
// Get polyPatchID and check if valid
const polyPatchID fringePatch
const polyPatchID cutPatch
(
fcPatchNames[nameI],
cuttingPatchNames_[nameI],
mesh.boundaryMesh()
);
if (!fringePatch.active())
if (!cutPatch.active())
{
FatalErrorIn
(
"void cuttingPatchFringe::calcAddressing const"
) << "Fringe patch " << fcPatchNames[nameI]
<< " for region " << allRegions[regionID].name()
) << "Cutting patch " << cuttingPatchNames_[nameI]
<< " cannot be found."
<< abort(FatalError);
}
// Store patch ID in the set
patchIDs.insert(fringePatch.index());
patchIDs.insert(cutPatch.index());
}
// Note: same code as in oversetRegion::calcHoleTriMesh. Consider
if (debug)
{
Info<< "Starting cutting patch fringe assembly..." << endl;
}
// Note: similar code as in oversetRegion::calcHoleTriMesh. Consider
// refactoring. VV, 20/May/2019
// Make and invert local triSurface
@ -240,7 +116,7 @@ void Foam::cuttingPatchFringe::calcAddressing() const
forAll (ts, tsI)
{
// Bugfix: no need to reverse face because the normals point in
// Bugfix: no need to reverse the face because the normals point in
// the correct direction already. VV, 20/May/2019.
triFaces[tsI] = ts[tsI];
}
@ -342,8 +218,7 @@ void Foam::cuttingPatchFringe::calcAddressing() const
(
word
(
"patchTriSurface_region" + myRegion.name() +
"_connectedRegion" + allRegions[regionID].name() + ".vtk"
"patchTriSurface_region" + myRegion.name() + ".vtk"
)
);
}
@ -378,6 +253,15 @@ void Foam::cuttingPatchFringe::calcAddressing() const
insideMask[myRegionCells[i]] = myRegionInsideMask[i];
}
// Make sure that the cut holes for this region are also properly marked as
// "inside". This may not be the case automatically for e.g. simulations
// with appendages
const labelList& cutRegionHoles = myRegion.cutHoles();
forAll (cutRegionHoles, i)
{
insideMask[cutRegionHoles[i]] = true;
}
// Get necessary mesh data (from polyMesh/primitiveMesh)
const cellList& meshCells = mesh.cells();
const unallocLabelList& owner = mesh.faceOwner();
@ -398,7 +282,7 @@ void Foam::cuttingPatchFringe::calcAddressing() const
forAll (cFaces, i)
{
// Set the mark for this global face and break out
// Set the mark for this global face
hasUnmarkedCell[cFaces[i]] = true;
}
}
@ -409,8 +293,8 @@ void Foam::cuttingPatchFringe::calcAddressing() const
(
mesh,
hasUnmarkedCell,
orOp<bool>(),
false
orEqOp<bool>(),
true
);
// Mark-up for all inside faces
@ -443,27 +327,20 @@ void Foam::cuttingPatchFringe::calcAddressing() const
acceptors.insert(cellI);
// This cell is no longer "inside cell"
insideMask[cellI] = false;;
// Break out since there's nothing to do for this cell
break;
insideMask[cellI] = false;
}
}
// If this is still inside cell, collect it and mark its faces
if (insideMask[cellI])
else
{
// Loop through cell faces and mark them
const cell& cFaces = meshCells[cellI];
forAll (cFaces, i)
{
insideFaceMask[cFaces[i]] = true;
}
// This is an "inside" face, mark it
insideFaceMask[faceI] = true;
}
} // End for all faces
} // End if cell is inside
} // End for all cells
// Note: insideFaceMask already synced across processors because it relies
// on hasUnmarkedCell list, which has been synced just above
// Hash set containing new acceptors (for successive iterations)
labelHashSet newAcceptors(acceptors.size());
@ -503,11 +380,11 @@ void Foam::cuttingPatchFringe::calcAddressing() const
(
mesh,
propagateFace,
orOp<bool>(),
orEqOp<bool>(),
false
);
// Loop through all faces and append acceptors
// Loop through all internal faces and append acceptors
for (label faceI = 0; faceI < mesh.nInternalFaces(); ++faceI)
{
if (propagateFace[faceI])
@ -575,28 +452,20 @@ void Foam::cuttingPatchFringe::calcAddressing() const
} // End for specified number of layers
// At this point, we have the final set of acceptors and we marked
// all cells that should be holes. Collect holes into hash set (could be
// optimized by using dynamic lists)
labelHashSet fringeHoles(myRegionCells.size()/10);
// all cells that should be holes. Collect them into the list
dynamicLabelList fringeHoles(myRegionCells.size()/10);
forAll (insideMask, cellI)
{
if (insideMask[cellI])
{
fringeHoles.insert(cellI);
fringeHoles.append(cellI);
}
}
// Finally, we have fringe holes and acceptors and we need to add them
// to the list containing all acceptors and holes (for all connected
// regions)
allAcceptors += acceptors;
allFringeHoles += fringeHoles;
}
// Set acceptors and holes from the data for all regions
acceptorsPtr_ = new labelList(allAcceptors.sortedToc());
fringeHolesPtr_ = new labelList(allFringeHoles.sortedToc());
acceptorsPtr_ = new labelList(acceptors.sortedToc());
fringeHolesPtr_ = new labelList(fringeHoles.xfer());
if (debug)
{
@ -626,13 +495,11 @@ Foam::cuttingPatchFringe::cuttingPatchFringe
)
:
oversetFringe(mesh, region, dict),
connectedRegionNames_(dict.lookup("connectedRegions")),
connectedRegionIDs_(),
cuttingPatchNames_(dict.lookup("cuttingPatches")),
nLayers_(readLabel(dict.lookup("nLayers"))),
fringeHolesPtr_(nullptr),
acceptorsPtr_(nullptr),
finalDonorAcceptorsPtr_(nullptr),
isInitialized_(false)
finalDonorAcceptorsPtr_(nullptr)
{
// Sanity check number of layers: must be greater than 0
if (nLayers_ < 1)
@ -650,7 +517,7 @@ Foam::cuttingPatchFringe::cuttingPatchFringe
) << "Invalid number of layers specified, nLayers = " << nLayers_
<< nl
<< "The number should be greater than 0."
<< abort(FatalError);
<< exit(FatalError);
}
// Preferably, the number of layers should be at least 2

View file

@ -58,14 +58,8 @@ class cuttingPatchFringe
{
// Private data
//- Names of connected regions. Looked up on construction
wordList connectedRegionNames_;
//- Regions IDs from which the donors will be collected as a starting
// point. Note: initialized in init private member function because we
// cannot initialize it in constructor. This is because certain overset
// regions (and their fringes) may not be initialized at this point.
mutable labelList connectedRegionIDs_;
//- Names of the cuttingPatches
wordList cuttingPatchNames_;
//- How many layers to move away from connected region donors to define
// acceptor (and holes)
@ -80,15 +74,9 @@ class cuttingPatchFringe
//- Final donor/acceptor pairs for this region (fringe)
mutable donorAcceptorList* finalDonorAcceptorsPtr_;
//- Initialization helper
mutable bool isInitialized_;
// Private Member Functions
//- Initialization
void init() const;
//- Calculate hole and acceptor addressing
void calcAddressing() const;