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 "cuttingPatchFringe.H"
#include "oversetMesh.H" #include "oversetMesh.H"
#include "oversetRegion.H" #include "oversetRegion.H"
#include "faceCellsFringe.H"
#include "oversetRegion.H"
#include "polyPatchID.H" #include "polyPatchID.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "syncTools.H" #include "syncTools.H"
@ -48,80 +46,6 @@ namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * 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 void Foam::cuttingPatchFringe::calcAddressing() const
{ {
// Make sure that either acceptorsPtr is unnalocated or if it is allocated, // Make sure that either acceptorsPtr is unnalocated or if it is allocated,
@ -135,89 +59,41 @@ void Foam::cuttingPatchFringe::calcAddressing() const
<< abort(FatalError); << abort(FatalError);
} }
if (!isInitialized_) // Get polyMesh
{
// 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
const polyMesh& mesh = this->mesh(); const polyMesh& mesh = this->mesh();
labelHashSet allAcceptors(0.02*mesh.nCells());
labelHashSet allFringeHoles(0.02*mesh.nCells());
if (debug) // Collect all cutting patches
{ labelHashSet patchIDs(cuttingPatchNames_.size());
Info<< "All dependent fringes are ready."
<< " Starting face cells cut patch fringe assembly..." << endl;
}
// Loop through connected regions forAll (cuttingPatchNames_, nameI)
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)
{ {
// Get polyPatchID and check if valid // Get polyPatchID and check if valid
const polyPatchID fringePatch const polyPatchID cutPatch
( (
fcPatchNames[nameI], cuttingPatchNames_[nameI],
mesh.boundaryMesh() mesh.boundaryMesh()
); );
if (!fringePatch.active()) if (!cutPatch.active())
{ {
FatalErrorIn FatalErrorIn
( (
"void cuttingPatchFringe::calcAddressing const" "void cuttingPatchFringe::calcAddressing const"
) << "Fringe patch " << fcPatchNames[nameI] ) << "Cutting patch " << cuttingPatchNames_[nameI]
<< " for region " << allRegions[regionID].name()
<< " cannot be found." << " cannot be found."
<< abort(FatalError); << abort(FatalError);
} }
// Store patch ID in the set // 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 // refactoring. VV, 20/May/2019
// Make and invert local triSurface // Make and invert local triSurface
@ -240,7 +116,7 @@ void Foam::cuttingPatchFringe::calcAddressing() const
forAll (ts, tsI) 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. // the correct direction already. VV, 20/May/2019.
triFaces[tsI] = ts[tsI]; triFaces[tsI] = ts[tsI];
} }
@ -342,8 +218,7 @@ void Foam::cuttingPatchFringe::calcAddressing() const
( (
word word
( (
"patchTriSurface_region" + myRegion.name() + "patchTriSurface_region" + myRegion.name() + ".vtk"
"_connectedRegion" + allRegions[regionID].name() + ".vtk"
) )
); );
} }
@ -378,6 +253,15 @@ void Foam::cuttingPatchFringe::calcAddressing() const
insideMask[myRegionCells[i]] = myRegionInsideMask[i]; 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) // Get necessary mesh data (from polyMesh/primitiveMesh)
const cellList& meshCells = mesh.cells(); const cellList& meshCells = mesh.cells();
const unallocLabelList& owner = mesh.faceOwner(); const unallocLabelList& owner = mesh.faceOwner();
@ -398,7 +282,7 @@ void Foam::cuttingPatchFringe::calcAddressing() const
forAll (cFaces, i) forAll (cFaces, i)
{ {
// Set the mark for this global face and break out // Set the mark for this global face
hasUnmarkedCell[cFaces[i]] = true; hasUnmarkedCell[cFaces[i]] = true;
} }
} }
@ -409,8 +293,8 @@ void Foam::cuttingPatchFringe::calcAddressing() const
( (
mesh, mesh,
hasUnmarkedCell, hasUnmarkedCell,
orOp<bool>(), orEqOp<bool>(),
false true
); );
// Mark-up for all inside faces // Mark-up for all inside faces
@ -443,27 +327,20 @@ void Foam::cuttingPatchFringe::calcAddressing() const
acceptors.insert(cellI); acceptors.insert(cellI);
// This cell is no longer "inside cell" // This cell is no longer "inside cell"
insideMask[cellI] = false;; insideMask[cellI] = false;
// Break out since there's nothing to do for this cell
break;
} }
} else
// If this is still inside cell, collect it and mark its faces
if (insideMask[cellI])
{ {
// Loop through cell faces and mark them // This is an "inside" face, mark it
const cell& cFaces = meshCells[cellI]; insideFaceMask[faceI] = true;
forAll (cFaces, i)
{
insideFaceMask[cFaces[i]] = true;
}
} }
} // End for all faces
} // End if cell is inside } // End if cell is inside
} // End for all cells } // 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) // Hash set containing new acceptors (for successive iterations)
labelHashSet newAcceptors(acceptors.size()); labelHashSet newAcceptors(acceptors.size());
@ -503,11 +380,11 @@ void Foam::cuttingPatchFringe::calcAddressing() const
( (
mesh, mesh,
propagateFace, propagateFace,
orOp<bool>(), orEqOp<bool>(),
false false
); );
// Loop through all faces and append acceptors // Loop through all internal faces and append acceptors
for (label faceI = 0; faceI < mesh.nInternalFaces(); ++faceI) for (label faceI = 0; faceI < mesh.nInternalFaces(); ++faceI)
{ {
if (propagateFace[faceI]) if (propagateFace[faceI])
@ -575,28 +452,20 @@ void Foam::cuttingPatchFringe::calcAddressing() const
} // End for specified number of layers } // End for specified number of layers
// At this point, we have the final set of acceptors and we marked // 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 // all cells that should be holes. Collect them into the list
// optimized by using dynamic lists) dynamicLabelList fringeHoles(myRegionCells.size()/10);
labelHashSet fringeHoles(myRegionCells.size()/10);
forAll (insideMask, cellI) forAll (insideMask, cellI)
{ {
if (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 // Set acceptors and holes from the data for all regions
acceptorsPtr_ = new labelList(allAcceptors.sortedToc()); acceptorsPtr_ = new labelList(acceptors.sortedToc());
fringeHolesPtr_ = new labelList(allFringeHoles.sortedToc()); fringeHolesPtr_ = new labelList(fringeHoles.xfer());
if (debug) if (debug)
{ {
@ -626,13 +495,11 @@ Foam::cuttingPatchFringe::cuttingPatchFringe
) )
: :
oversetFringe(mesh, region, dict), oversetFringe(mesh, region, dict),
connectedRegionNames_(dict.lookup("connectedRegions")), cuttingPatchNames_(dict.lookup("cuttingPatches")),
connectedRegionIDs_(),
nLayers_(readLabel(dict.lookup("nLayers"))), nLayers_(readLabel(dict.lookup("nLayers"))),
fringeHolesPtr_(nullptr), fringeHolesPtr_(nullptr),
acceptorsPtr_(nullptr), acceptorsPtr_(nullptr),
finalDonorAcceptorsPtr_(nullptr), finalDonorAcceptorsPtr_(nullptr)
isInitialized_(false)
{ {
// Sanity check number of layers: must be greater than 0 // Sanity check number of layers: must be greater than 0
if (nLayers_ < 1) if (nLayers_ < 1)
@ -650,7 +517,7 @@ Foam::cuttingPatchFringe::cuttingPatchFringe
) << "Invalid number of layers specified, nLayers = " << nLayers_ ) << "Invalid number of layers specified, nLayers = " << nLayers_
<< nl << nl
<< "The number should be greater than 0." << "The number should be greater than 0."
<< abort(FatalError); << exit(FatalError);
} }
// Preferably, the number of layers should be at least 2 // Preferably, the number of layers should be at least 2

View file

@ -58,14 +58,8 @@ class cuttingPatchFringe
{ {
// Private data // Private data
//- Names of connected regions. Looked up on construction //- Names of the cuttingPatches
wordList connectedRegionNames_; wordList cuttingPatchNames_;
//- 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_;
//- How many layers to move away from connected region donors to define //- How many layers to move away from connected region donors to define
// acceptor (and holes) // acceptor (and holes)
@ -80,15 +74,9 @@ class cuttingPatchFringe
//- Final donor/acceptor pairs for this region (fringe) //- Final donor/acceptor pairs for this region (fringe)
mutable donorAcceptorList* finalDonorAcceptorsPtr_; mutable donorAcceptorList* finalDonorAcceptorsPtr_;
//- Initialization helper
mutable bool isInitialized_;
// Private Member Functions // Private Member Functions
//- Initialization
void init() const;
//- Calculate hole and acceptor addressing //- Calculate hole and acceptor addressing
void calcAddressing() const; void calcAddressing() const;