ENH: cellShape::reset() - simplifies modification of existing shapes

This commit is contained in:
Mark Olesen
2021-05-28 20:18:04 +02:00
parent 5ec49a3898
commit f2d634c49f
23 changed files with 85 additions and 71 deletions

View File

@ -401,7 +401,7 @@ int main(int argc, char *argv[])
labelsTet[2] = pointMap[labels[2]]; labelsTet[2] = pointMap[labels[2]];
labelsTet[3] = pointMap[labels[4]]; labelsTet[3] = pointMap[labels[4]];
cellShapes[nCells++] = cellShape(tet, labelsTet); cellShapes[nCells++].reset(tet, labelsTet);
} }
else if // Square-based pyramid else if // Square-based pyramid
@ -417,7 +417,7 @@ int main(int argc, char *argv[])
labelsPyramid[3] = pointMap[labels[3]]; labelsPyramid[3] = pointMap[labels[3]];
labelsPyramid[4] = pointMap[labels[4]]; labelsPyramid[4] = pointMap[labels[4]];
cellShapes[nCells++] = cellShape(pyr, labelsPyramid); cellShapes[nCells++].reset(pyr, labelsPyramid);
} }
else if // Triangular prism else if // Triangular prism
@ -433,7 +433,7 @@ int main(int argc, char *argv[])
labelsPrism[4] = pointMap[labels[5]]; labelsPrism[4] = pointMap[labels[5]];
labelsPrism[5] = pointMap[labels[6]]; labelsPrism[5] = pointMap[labels[6]];
cellShapes[nCells++] = cellShape(prism, labelsPrism); cellShapes[nCells++].reset(prism, labelsPrism);
} }
else // Hex else // Hex
@ -447,7 +447,7 @@ int main(int argc, char *argv[])
labelsHex[6] = pointMap[labels[6]]; labelsHex[6] = pointMap[labels[6]];
labelsHex[7] = pointMap[labels[7]]; labelsHex[7] = pointMap[labels[7]];
cellShapes[nCells++] = cellShape(hex, labelsHex); cellShapes[nCells++].reset(hex, labelsHex);
} }
} }

View File

@ -574,7 +574,7 @@ int main(int argc, char *argv[])
]; ];
} }
cellShapes[nCreatedCells] = cellShape(hex, cellPoints); cellShapes[nCreatedCells].reset(hex, cellPoints);
nCreatedCells++; nCreatedCells++;
} }

View File

@ -238,15 +238,14 @@ cellShape extrudedQuadCellShape
return cellShape(hex, cellShapeLabels); return cellShape(hex, cellShapeLabels);
} }
else
{
FatalErrorInFunction FatalErrorInFunction
<< "Problem with edge matching. Edges: " << localFaces << "Problem with edge matching. Edges: " << localFaces
<< abort(FatalError); << abort(FatalError);
}
// Return added to keep compiler happy // Return added to keep compiler happy
return cellShape(hex, labelList(0)); return cellShape(hex, labelList());
} }

View File

@ -178,15 +178,14 @@ cellShape extrudedTriangleCellShape
return cellShape(prism, cellShapeLabels); return cellShape(prism, cellShapeLabels);
} }
else
{
FatalErrorInFunction FatalErrorInFunction
<< "Problem with edge matching. Edges: " << localFaces << "Problem with edge matching. Edges: " << localFaces
<< abort(FatalError); << abort(FatalError);
}
// Return added to keep compiler happy // Return added to keep compiler happy
return cellShape(prism, labelList(0)); return cellShape(prism, labelList());
} }

View File

@ -731,7 +731,7 @@ int main(int argc, char *argv[])
labelsTet[2] = pointLookup[curCellLabels[3] ]; labelsTet[2] = pointLookup[curCellLabels[3] ];
labelsTet[3] = pointLookup[curCellLabels[1] ]; labelsTet[3] = pointLookup[curCellLabels[1] ];
cells[celli] = cellShape(tet, labelsTet); cells[celli].reset(tet, labelsTet);
} }
// Square-based pyramid // Square-based pyramid
@ -743,7 +743,7 @@ int main(int argc, char *argv[])
labelsPyramid[3] = pointLookup[curCellLabels[2] ]; labelsPyramid[3] = pointLookup[curCellLabels[2] ];
labelsPyramid[4] = pointLookup[curCellLabels[4] ]; labelsPyramid[4] = pointLookup[curCellLabels[4] ];
cells[celli] = cellShape(pyr, labelsPyramid); cells[celli].reset(pyr, labelsPyramid);
} }
// Triangular prism // Triangular prism
@ -756,7 +756,7 @@ int main(int argc, char *argv[])
labelsPrism[4] = pointLookup[curCellLabels[4] ]; labelsPrism[4] = pointLookup[curCellLabels[4] ];
labelsPrism[5] = pointLookup[curCellLabels[5] ]; labelsPrism[5] = pointLookup[curCellLabels[5] ];
cells[celli] = cellShape(prism, labelsPrism); cells[celli].reset(prism, labelsPrism);
} }
// Hex // Hex
@ -771,7 +771,7 @@ int main(int argc, char *argv[])
labelsHex[6] = pointLookup[curCellLabels[7] ]; labelsHex[6] = pointLookup[curCellLabels[7] ];
labelsHex[7] = pointLookup[curCellLabels[6] ]; labelsHex[7] = pointLookup[curCellLabels[6] ];
cells[celli] = cellShape(hex, labelsHex); cells[celli].reset(hex, labelsHex);
} }
} }

View File

@ -664,7 +664,7 @@ void readCellsLegacy
renumber(mshToFoam, tetPoints); renumber(mshToFoam, tetPoints);
cells[celli++] = cellShape(tet, tetPoints); cells[celli++].reset(tet, tetPoints);
nTet++; nTet++;
} }
@ -685,7 +685,7 @@ void readCellsLegacy
renumber(mshToFoam, pyrPoints); renumber(mshToFoam, pyrPoints);
cells[celli++] = cellShape(pyr, pyrPoints); cells[celli++].reset(pyr, pyrPoints);
nPyr++; nPyr++;
} }
@ -706,7 +706,7 @@ void readCellsLegacy
renumber(mshToFoam, prismPoints); renumber(mshToFoam, prismPoints);
cells[celli] = cellShape(prism, prismPoints); cells[celli].reset(prism, prismPoints);
const cellShape& cell = cells[celli]; const cellShape& cell = cells[celli];
@ -721,7 +721,7 @@ void readCellsLegacy
prismPoints[4] = cell[4]; prismPoints[4] = cell[4];
prismPoints[5] = cell[5]; prismPoints[5] = cell[5];
cells[celli] = cellShape(prism, prismPoints); cells[celli].reset(prism, prismPoints);
} }
celli++; celli++;
@ -747,7 +747,7 @@ void readCellsLegacy
renumber(mshToFoam, hexPoints); renumber(mshToFoam, hexPoints);
cells[celli] = cellShape(hex, hexPoints); cells[celli].reset(hex, hexPoints);
const cellShape& cell = cells[celli]; const cellShape& cell = cells[celli];
@ -764,7 +764,7 @@ void readCellsLegacy
hexPoints[6] = cell[2]; hexPoints[6] = cell[2];
hexPoints[7] = cell[3]; hexPoints[7] = cell[3];
cells[celli] = cellShape(hex, hexPoints); cells[celli].reset(hex, hexPoints);
} }
celli++; celli++;
@ -1019,7 +1019,7 @@ void readCells
renumber(mshToFoam, tetPoints); renumber(mshToFoam, tetPoints);
cells[celli++] = cellShape(tet, tetPoints); cells[celli++].reset(tet, tetPoints);
} }
} }
else if (elmType == MSHPYR) else if (elmType == MSHPYR)
@ -1046,7 +1046,7 @@ void readCells
renumber(mshToFoam, pyrPoints); renumber(mshToFoam, pyrPoints);
cells[celli++] = cellShape(pyr, pyrPoints); cells[celli++].reset(pyr, pyrPoints);
} }
} }
else if (elmType == MSHPRISM) else if (elmType == MSHPRISM)
@ -1073,7 +1073,7 @@ void readCells
renumber(mshToFoam, prismPoints); renumber(mshToFoam, prismPoints);
cells[celli] = cellShape(prism, prismPoints); cells[celli].reset(prism, prismPoints);
const cellShape& cell = cells[celli]; const cellShape& cell = cells[celli];
@ -1088,7 +1088,7 @@ void readCells
prismPoints[4] = cell[4]; prismPoints[4] = cell[4];
prismPoints[5] = cell[5]; prismPoints[5] = cell[5];
cells[celli] = cellShape(prism, prismPoints); cells[celli].reset(prism, prismPoints);
} }
celli++; celli++;
@ -1120,7 +1120,7 @@ void readCells
renumber(mshToFoam, hexPoints); renumber(mshToFoam, hexPoints);
cells[celli] = cellShape(hex, hexPoints); cells[celli].reset(hex, hexPoints);
const cellShape& cell = cells[celli]; const cellShape& cell = cells[celli];
@ -1137,7 +1137,7 @@ void readCells
hexPoints[6] = cell[2]; hexPoints[6] = cell[2];
hexPoints[7] = cell[3]; hexPoints[7] = cell[3];
cells[celli] = cellShape(hex, hexPoints); cells[celli].reset(hex, hexPoints);
} }
celli++; celli++;

View File

@ -128,7 +128,7 @@ for (label i=0; i<nPoints; i++)
hexLabels[6] = i3tab[i1tab[i8tab[i]]]; hexLabels[6] = i3tab[i1tab[i8tab[i]]];
hexLabels[7] = i3tab[i8tab[i]]; hexLabels[7] = i3tab[i8tab[i]];
cellShapes[activeCells] = cellShape(hex, hexLabels); cellShapes[activeCells].reset(hex, hexLabels);
edgeList edges = cellShapes[activeCells].edges(); edgeList edges = cellShapes[activeCells].edges();

View File

@ -108,7 +108,7 @@ int main(int argc, char *argv[])
{ {
mshStream >> hexPoints[cp]; mshStream >> hexPoints[cp];
} }
cells[celli] = cellShape(hex, hexPoints); cells[celli].reset(hex, hexPoints);
} }
} }
else else
@ -119,7 +119,7 @@ int main(int argc, char *argv[])
{ {
mshStream >> tetPoints[cp]; mshStream >> tetPoints[cp];
} }
cells[celli] = cellShape(tet, tetPoints); cells[celli].reset(tet, tetPoints);
} }
} }

View File

@ -154,7 +154,7 @@ int main(int argc, char *argv[])
tetPoints[2] = readLabel(str) - 1; tetPoints[2] = readLabel(str) - 1;
tetPoints[3] = readLabel(str) - 1; tetPoints[3] = readLabel(str) - 1;
cells[celli] = cellShape(tet, tetPoints); cells[celli].reset(tet, tetPoints);
} }

View File

@ -231,7 +231,7 @@ int main(int argc, char *argv[])
} }
// Do automatic collapse from hex. // Do automatic collapse from hex.
cellShapes[nCreatedCells] = cellShape(hex, cellPoints, true); cellShapes[nCreatedCells].reset(hex, cellPoints, true);
nCreatedCells++; nCreatedCells++;
} }

View File

@ -309,7 +309,7 @@ int main(int argc, char *argv[])
tetPoints[i] = nodeToPoint[nodeI]; tetPoints[i] = nodeToPoint[nodeI];
} }
cells[celli++] = cellShape(tet, tetPoints); cells[celli++].reset(tet, tetPoints);
// Skip attributes // Skip attributes
for (label i = 0; i < nElemAttr; i++) for (label i = 0; i < nElemAttr; i++)

View File

@ -273,7 +273,7 @@ autoPtr<polyMesh> generateHexMesh
hexPoints[5] = vtxLabel(nCells, i+1, j, k+1); hexPoints[5] = vtxLabel(nCells, i+1, j, k+1);
hexPoints[6] = vtxLabel(nCells, i+1, j+1, k+1); hexPoints[6] = vtxLabel(nCells, i+1, j+1, k+1);
hexPoints[7] = vtxLabel(nCells, i, j+1, k+1); hexPoints[7] = vtxLabel(nCells, i, j+1, k+1);
cellShapes[celli++] = cellShape(hex, hexPoints); cellShapes[celli++].reset(hex, hexPoints);
} }
} }
} }

View File

@ -34,8 +34,7 @@ pointField points;
cellShapes.setSize(bCells.size()); cellShapes.setSize(bCells.size());
forAll(cellShapes, celli) forAll(cellShapes, celli)
{ {
cellShapes[celli] = cellShapes[celli].reset(hex, labelList(bCells[celli]), false);
cellShape(hex, labelList(bCells[celli]), false);
} }
Info<< "Creating boundary faces" << endl; Info<< "Creating boundary faces" << endl;

View File

@ -334,8 +334,7 @@ bool Foam::hexMatcher::matches
) )
) )
{ {
shape = cellShape(model(), vertLabels()); shape.reset(model(), vertLabels());
return true; return true;
} }

View File

@ -371,8 +371,7 @@ bool Foam::prismMatcher::matches
) )
) )
{ {
shape = cellShape(model(), vertLabels()); shape.reset(model(), vertLabels());
return true; return true;
} }

View File

@ -329,8 +329,7 @@ bool Foam::pyrMatcher::matches
) )
) )
{ {
shape = cellShape(model(), vertLabels()); shape.reset(model(), vertLabels());
return true; return true;
} }

View File

@ -274,8 +274,7 @@ bool Foam::tetMatcher::matches
) )
) )
{ {
shape = cellShape(model(), vertLabels()); shape.reset(model(), vertLabels());
return true; return true;
} }

View File

@ -296,8 +296,7 @@ bool Foam::tetWedgeMatcher::matches
) )
) )
{ {
shape = cellShape(model(), vertLabels()); shape.reset(model(), vertLabels());
return true; return true;
} }

View File

@ -396,8 +396,7 @@ bool Foam::wedgeMatcher::matches
) )
) )
{ {
shape = cellShape(model(), vertLabels()); shape.reset(model(), vertLabels());
return true; return true;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -105,7 +105,7 @@ public:
inline cellShape inline cellShape
( (
const cellModel& model, const cellModel& model,
labelUList&& labels, labelList&& labels,
const bool doCollapse = false const bool doCollapse = false
); );
@ -173,18 +173,26 @@ public:
//- Centroid of the cell //- Centroid of the cell
inline point centre(const UList<point>& points) const; inline point centre(const UList<point>& points) const;
//- Scalar magnitude
inline scalar mag(const UList<point>& points) const;
//- Reset from components
inline void reset
(
const cellModel& model,
const labelUList& labels,
const bool doCollapse = false
);
//- Collapse shape to correct one after removing duplicate vertices
void collapse();
//- Return info proxy, to print information to a stream //- Return info proxy, to print information to a stream
Foam::InfoProxy<cellShape> info() const Foam::InfoProxy<cellShape> info() const
{ {
return *this; return *this;
} }
//- Scalar magnitude
inline scalar mag(const UList<point>& points) const;
//- Collapse shape to correct one after removing duplicate vertices
void collapse();
// Friend Operators // Friend Operators

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -78,7 +78,7 @@ inline Foam::cellShape::cellShape
inline Foam::cellShape::cellShape inline Foam::cellShape::cellShape
( (
const cellModel& model, const cellModel& model,
labelUList&& labels, labelList&& labels,
const bool doCollapse const bool doCollapse
) )
: :
@ -296,4 +296,21 @@ inline Foam::scalar Foam::cellShape::mag(const UList<point>& points) const
} }
inline void Foam::cellShape::reset
(
const cellModel& model,
const labelUList& labels,
const bool doCollapse
)
{
static_cast<labelList&>(*this) = labels;
m = &model;
if (doCollapse)
{
collapse();
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -130,8 +130,7 @@ void Foam::blockMesh::createCells() const
} }
// Construct collapsed cell and add to list // Construct collapsed cell and add to list
cells_[celli] = cellShape(hex, cellPoints, true); cells_[celli].reset(hex, cellPoints, true);
++celli; ++celli;
} }
} }

View File

@ -518,8 +518,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::voxelMeshSearch::makeMesh
cellShapes.setSize(bCells.size()); cellShapes.setSize(bCells.size());
forAll(cellShapes, celli) forAll(cellShapes, celli)
{ {
cellShapes[celli] = cellShapes[celli].reset(hex, labelList(bCells[celli]), false);
cellShape(hex, labelList(bCells[celli]), false);
} }
//Info<< "Creating boundary faces" << endl; //Info<< "Creating boundary faces" << endl;