Refactorization of cuttingPatchFringe

This commit is contained in:
Vuko Vukcevic 2019-05-22 12:08:44 +02:00
parent 7631b1d9db
commit 8051a31239
2 changed files with 342 additions and 488 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"
) )
); );
} }
@ -587,16 +462,9 @@ void Foam::cuttingPatchFringe::calcAddressing() const
} }
} }
// 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.sortedToc());
if (debug) if (debug)
{ {
@ -626,13 +494,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)

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;