Commit 153323e1 authored by Mattijs Janssens's avatar Mattijs Janssens
Browse files

Merge branch 'feature-regionsplit' into 'develop'

Feature regionsplit

See merge request OpenFOAM-plus!201
parents f3d1e41d ed272274
......@@ -259,9 +259,9 @@ void Foam::medialAxisMeshMover::update(const dictionary& coeffDict)
);
wallDistCalc.iterate(nMedialAxisIter);
label nUnvisit = returnReduce
const label nUnvisit = returnReduce
(
wallDistCalc.getUnsetPoints(),
wallDistCalc.nUnvisitedPoints(),
sumOp<label>()
);
......
......@@ -108,6 +108,16 @@ Foam::meshRefinement::writeType Foam::meshRefinement::writeLevel_;
Foam::meshRefinement::outputType Foam::meshRefinement::outputLevel_;
// Inside/outside test for polyMesh:.findCell()
// 2.4.x : default = polyMesh::FACE_DIAG_TRIS
// 1712 : default = polyMesh::CELL_TETS
//
// - CELL_TETS is better with concave cells, but much slower.
// - use faster method (FACE_DIAG_TRIS) here
static const Foam::polyMesh::cellDecomposition
findCellMode(Foam::polyMesh::FACE_DIAG_TRIS);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -2198,18 +2208,7 @@ Foam::label Foam::meshRefinement::findRegion
// Force calculation of base points (needs to be synchronised)
(void)mesh.tetBasePtIs();
label celli = mesh.findCell(p);
//if (celli != -1)
//{
// Pout<< "findRegion : Found point:" << p << " in cell " << celli
// << " at:" << mesh.cellCentres()[celli] << endl;
//}
//else
//{
// Pout<< "findRegion : Found point:" << p << " in cell " << celli
// << endl;
//}
label celli = mesh.findCell(p, findCellMode);
if (celli != -1)
{
regioni = cellToRegion[celli];
......@@ -2219,7 +2218,7 @@ Foam::label Foam::meshRefinement::findRegion
if (regioni == -1)
{
// See if we can perturb a bit
celli = mesh.findCell(p+perturbVec);
celli = mesh.findCell(p+perturbVec, findCellMode);
if (celli != -1)
{
regioni = cellToRegion[celli];
......@@ -2228,61 +2227,12 @@ Foam::label Foam::meshRefinement::findRegion
}
return regioni;
}
//XXXXXXXX
//Foam::labelList Foam::meshRefinement::findRegion
//(
// const polyMesh& mesh,
// const labelList& cellToRegion,
// const vector& perturbVec,
// const pointField& pts
//)
//{
// labelList regions(pts.size(), -1);
//
// forAll(pts, i)
// {
// label celli = mesh.findCell(pts[i]);
// if (celli != -1)
// {
// regions[i] = cellToRegion[celli];
// }
// reduce(regions[i], maxOp<label>());
//
// if (regions[i] == -1)
// {
// // See if we can perturb a bit
// celli = mesh.findCell(pts[i]+perturbVec);
// if (celli != -1)
// {
// regions[i] = cellToRegion[celli];
// }
// reduce(regions[i], maxOp<label>());
// }
// }
//
// forAll(regions, i)
// {
// if (regions[i] == -1)
// {
// FatalErrorInFunction
// << "Point " << pts[i]
// << " is not inside the mesh." << nl
// << "Bounding box of the mesh:" << mesh.bounds()
// //<< "All points " << pts
// //<< " with corresponding regions " << regions
// << exit(FatalError);
// }
// }
//
// return regions;
//}
//XXXXXXXX
// Modify cellRegion to be consistent with locationsInMesh.
// - all regions not in locationsInMesh are set to -1
// - check that all regions inside locationsOutsideMesh are set to -1
void Foam::meshRefinement::findRegions
Foam::label Foam::meshRefinement::findRegions
(
const polyMesh& mesh,
const vector& perturbVec,
......@@ -2352,14 +2302,23 @@ void Foam::meshRefinement::findRegions
}
label nRemove = 0;
// Now update cellRegion to -1 for unreachable cells
forAll(insideCell, celli)
{
if (!insideCell[celli])
if (!insideCell.test(celli))
{
cellRegion[celli] = -1;
++nRemove;
}
else if (cellRegion[celli] == -1)
{
++nRemove;
}
}
return nRemove;
}
......@@ -2382,7 +2341,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::splitMeshRegions
regionSplit cellRegion(mesh_, blockedFace);
findRegions
label nRemove = findRegions
(
mesh_,
mergeDistance_*vector(1,1,1), // perturbVec
......@@ -2396,7 +2355,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::splitMeshRegions
// ~~~~~~
// Get cells to remove
DynamicList<label> cellsToRemove(mesh_.nCells());
DynamicList<label> cellsToRemove(nRemove);
forAll(cellRegion, celli)
{
if (cellRegion[celli] == -1)
......
......@@ -1226,7 +1226,9 @@ public:
const point& p
);
static void findRegions
//- Find regions points are in.
// \return number of cells to be removed
static label findRegions
(
const polyMesh&,
const vector& perturbVec,
......
......@@ -1570,7 +1570,7 @@ Foam::label Foam::meshRefinement::markSmallFeatureRefinement
);
//- Option 1: use octree nearest searching inside polyMesh
//label cellI = mesh_.findCell(pt);
//label cellI = mesh_.findCell(pt, polyMesh::CELL_TETS);
//- Option 2: use octree 'inside' searching inside polyMesh. Is
// much faster.
......
......@@ -191,7 +191,7 @@ Foam::labelList Foam::refinementParameters::findCells
{
const point& location = locations[i];
label localCellI = mesh.findCell(location);
label localCellI = mesh.findCell(location, polyMesh::FACE_DIAG_TRIS);
label globalCellI = -1;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -57,7 +57,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward declarations
class polyMesh;
class polyPatch;
......@@ -79,16 +79,21 @@ class FaceCellWave
{
// Private Member Functions
//- Disallow default bitwise copy construct
FaceCellWave(const FaceCellWave&);
//- No copy construct
FaceCellWave(const FaceCellWave&) = delete;
//- Disallow default bitwise assignment
void operator=(const FaceCellWave&);
//- No copy assignment
void operator=(const FaceCellWave&) = delete;
protected:
// Protected data
//- Information tagged with a source or destination id.
// With std::pair as lightweight, moveable container.
typedef std::pair<label,Type> taggedInfoType;
// Protected Data
//- Reference to mesh
const polyMesh& mesh_;
......@@ -108,15 +113,18 @@ protected:
//- Has face changed
bitSet changedFace_;
//- List of changed faces
DynamicList<label> changedFaces_;
//- Has cell changed
bitSet changedCell_;
//- List of changed faces
DynamicList<label> changedFaces_;
// Cells that have changed
DynamicList<label> changedCells_;
// Information exchange for explicit baffle connections
// Max capacity = 2x number of explicit connections
DynamicList<taggedInfoType> changedBaffles_;
//- Contains cyclics
const bool hasCyclicPatches_;
......@@ -132,8 +140,10 @@ protected:
label nUnvisitedFaces_;
//- Updates cellInfo with information from neighbour. Updates all
// statistics.
// Protected Member Functions
//- Updates cellInfo with information from neighbour.
// Updates all statistics.
bool updateCell
(
const label celli,
......@@ -143,8 +153,8 @@ protected:
Type& cellInfo
);
//- Updates faceInfo with information from neighbour. Updates all
// statistics.
//- Updates faceInfo with information from neighbour.
// Updates all statistics.
bool updateFace
(
const label facei,
......@@ -154,8 +164,8 @@ protected:
Type& faceInfo
);
//- Updates faceInfo with information from same face. Updates all
// statistics.
//- Updates faceInfo with information from same face.
// Updates all statistics.
bool updateFace
(
const label facei,
......@@ -179,8 +189,8 @@ protected:
(
const polyPatch& patch,
const label nFaces,
const labelList&,
const List<Type>&
const labelUList& changedFaces,
const List<Type>& changedFacesInfo
);
//- Extract info for single patch only
......@@ -198,7 +208,7 @@ protected:
(
const polyPatch& patch,
const label nFaces,
const labelList& faceLabels,
const labelUList& faceLabels,
List<Type>& faceInfo
) const;
......@@ -207,7 +217,7 @@ protected:
(
const polyPatch& patch,
const label nFaces,
const labelList& faceLabels,
const labelUList& faceLabels,
List<Type>& faceInfo
) const;
......@@ -229,16 +239,18 @@ protected:
);
//- Merge data from across processor boundaries
// Transfer changed faces from neighbouring processors.
void handleProcPatches();
//- Merge data from across cyclics
// Transfer changed faces across cyclic halves
void handleCyclicPatches();
//- Merge data from across AMI cyclics
void handleAMICyclicPatches();
//- Merge data across explicitly provided local connections (usually
// baffles)
//- Merge data across explicitly provided local connections
// These are usually baffles
void handleExplicitConnections();
......@@ -271,11 +283,11 @@ public:
// Constructors
// Construct from mesh. Use setFaceInfo and iterate() to do actual
// calculation.
//- Construct from mesh.
//- Use setFaceInfo and iterate() to do actual calculation.
FaceCellWave
(
const polyMesh&,
const polyMesh& mesh,
UList<Type>& allFaceInfo,
UList<Type>& allCellInfo,
TrackingData& td = dummyTrackData_
......@@ -283,11 +295,11 @@ public:
//- Construct from mesh and list of changed faces with the Type
// for these faces. Iterates until nothing changes or maxIter reached.
// (maxIter can be 0)
// (maxIter can be 0 or negative). 0 initializes, -1 does not
FaceCellWave
(
const polyMesh&,
const labelList& initialChangedFaces,
const polyMesh& mesh,
const labelUList& initialChangedFaces,
const List<Type>& changedFacesInfo,
UList<Type>& allFaceInfo,
UList<Type>& allCellInfo,
......@@ -298,13 +310,13 @@ public:
//- Construct from mesh and explicitly connected boundary faces
// and list of changed faces with the Type
// for these faces. Iterates until nothing changes or maxIter reached.
// (maxIter can be 0)
// (maxIter can be 0 or negative). 0 initializes, -1 does not
FaceCellWave
(
const polyMesh&,
const polyMesh& mesh,
const labelPairList& explicitConnections,
const bool handleCyclicAMI,
const labelList& initialChangedFaces,
const labelUList& initialChangedFaces,
const List<Type>& changedFacesInfo,
UList<Type>& allFaceInfo,
UList<Type>& allCellInfo,
......@@ -314,70 +326,75 @@ public:
//- Destructor
virtual ~FaceCellWave()
{}
virtual ~FaceCellWave() = default;
// Member Functions
// Access
// Access
//- Access allFaceInfo
UList<Type>& allFaceInfo()
{
return allFaceInfo_;
}
//- Access allCellInfo
UList<Type>& allCellInfo()
{
return allCellInfo_;
}
//- Access allFaceInfo
UList<Type>& allFaceInfo()
{
return allFaceInfo_;
}
//- Additional data to be passed into container
const TrackingData& data() const
{
return td_;
}
//- Access allCellInfo
UList<Type>& allCellInfo()
{
return allCellInfo_;
}
//- Access mesh
const polyMesh& mesh() const
{
return mesh_;
}
//- Additional data to be passed into container
const TrackingData& data() const
{
return td_;
}
//- Get number of unvisited cells,
//- i.e. cells that were not (yet) reached from walking across mesh.
// This can happen from
// - not enough iterations done
// - a disconnected mesh
// - a mesh without walls in it
label nUnvisitedCells() const;
//- Access mesh
const polyMesh& mesh() const
{
return mesh_;
}
//- Get number of unvisited faces
label nUnvisitedFaces() const;
//- Get number of unvisited cells, i.e. cells that were not (yet)
// reached from walking across mesh. This can happen from
// - not enough iterations done
// - a disconnected mesh
// - a mesh without walls in it
label getUnsetCells() const;
//- Get number of unvisited faces
label getUnsetFaces() const;
// Edit
//- Set single initial changed face.
// This is a noop if the face had already been visited
void setFaceInfo(const label facei, const Type& faceInfo);
// Edit
//- Set initial changed faces
void setFaceInfo
(
const labelUList& changedFaces,
const List<Type>& changedFacesInfo
);
//- Set initial changed faces
void setFaceInfo
(
const labelList& changedFaces,
const List<Type>& changedFacesInfo
);
//- Propagate from face to cell.
// \return total number of cells (over all processors) changed.
virtual label faceToCell();
//- Propagate from face to cell. Returns total number of cells
// (over all processors) changed.
virtual label faceToCell();
//- Propagate from cell to face.
// \return total number of faces (over all processors) changed.
// Note that faces on processor patches are counted twice.
virtual label cellToFace();
//- Propagate from cell to face. Returns total number of faces
// (over all processors) changed. (Faces on processorpatches are
// counted double)
virtual label cellToFace();
//- Iterate until no changes or maxIter reached.
// \return the number of iterations taken.
virtual label iterate(const label maxIter);
//- Iterate until no changes or maxIter reached. Returns actual
// number of iterations.
virtual label iterate(const label maxIter);
};
......
......@@ -141,20 +141,20 @@ public:
return calc_.iterate(maxIter);
}
//- Get number of unvisited cells, i.e. cells that were not (yet)
//- Number of unvisited cells, i.e. cells that were not (yet)
// reached from walking across mesh. This can happen from
// - not enough iterations done
// - a disconnected mesh
// - a mesh without walls in it
label getUnsetCells() const
label nUnvisitedCells() const
{
return calc_.getUnsetCells();
return calc_.nUnvisitedCells();
}
//- Get number of unvisited faces
label getUnsetFaces() const
//- Number of unvisited faces
label nUnvisitedFaces() const
{
return calc_.getUnsetFaces();
return calc_.nUnvisitedFaces();
}
};
......
......@@ -420,7 +420,7 @@ template
class TrackingData
>
Foam::label Foam::PatchEdgeFaceWave<PrimitivePatchType, Type, TrackingData>::
getUnsetEdges() const
nUnvisitedEdges() const
{
return nUnvisitedEdges_;
}
......@@ -433,7 +433,7 @@ template
class TrackingData
>
Foam::label Foam::PatchEdgeFaceWave<PrimitivePatchType, Type, TrackingData>::
getUnsetFaces() const
nUnvisitedFaces() const
{
return nUnvisitedFaces_;
}
......
......@@ -226,14 +226,14 @@ public:
return td_;
}
//- Get number of unvisited faces, i.e. faces that were not (yet)
//- Number of unvisited faces, i.e. faces that were not (yet)
// reached from walking across patch. This can happen from
// - not enough iterations done
// - a disconnected patch
// - a patch without walls in it
label getUnsetFaces() const;
label nUnvisitedFaces() const;
label getUnsetEdges() const;
label nUnvisitedEdges() const;
//- Copy initial data into allEdgeInfo_
void setEdgeInfo
......
......@@ -714,14 +714,14 @@ Foam::PointEdgeWave<Type, TrackingData>::~PointEdgeWave()
template<class Type, class TrackingData>
Foam::label Foam::PointEdgeWave<Type, TrackingData>::getUnsetPoints() const
Foam::label Foam::PointEdgeWave<Type, TrackingData>::nUnvisitedPoints() const
{
return nUnvisitedPoints_;
}
template<class Type, class TrackingData>
Foam::label Foam::PointEdgeWave<Type, TrackingData>::getUnsetEdges() const
Foam::label Foam::PointEdgeWave<Type, TrackingData>::nUnvisitedEdges() const
{
return nUnvisitedEdges_;
}
......@@ -737,9 +737,9 @@ void Foam::PointEdgeWave<Type, TrackingData>::setPointInfo
{
forAll(changedPoints, changedPointi)
{
label pointi = changedPoints[changedPointi];
const label pointi = changedPoints[changedPointi];
bool wasValid = allPointInfo_[pointi].valid(td_);
const bool wasValid = allPointInfo_[pointi].valid(td_);
// Copy info for pointi
allPointInfo_[pointi] = changedPointsInfo[changedPointi];
......
......@@ -287,14 +287,14 @@ public:
return td_;
}
//- Get number of unvisited edges, i.e. edges that were not (yet)
//- Number of unvisited edges, i.e. edges that were not (yet)
// reached from walking across mesh. This can happen from