diff --git a/applications/utilities/preProcessing/createBoxTurb/createBlockMesh.H b/applications/utilities/preProcessing/createBoxTurb/createBlockMesh.H index 12690b467e..ef5f151db8 100644 --- a/applications/utilities/preProcessing/createBoxTurb/createBlockMesh.H +++ b/applications/utilities/preProcessing/createBoxTurb/createBlockMesh.H @@ -8,7 +8,7 @@ pointField points; block b ( - cellShape(hex, identity(8), false), + cellShape(hex, identity(8)), pointField ( { @@ -24,18 +24,11 @@ pointField points; ), blockEdgeList(), blockFaceList(), - N, - List(12) + N ); Info<< "Creating cells" << endl; - - List> bCells(b.cells()); - cellShapes.setSize(bCells.size()); - forAll(cellShapes, celli) - { - cellShapes[celli].reset(hex, labelList(bCells[celli]), false); - } + cellShapes = b.shapes(); Info<< "Creating boundary faces" << endl; diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 5f51900130..f37def5122 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -491,6 +491,8 @@ procFacesGAMGProcAgglomeration = $(GAMGProcAgglomerations)/procFacesGAMGProcAggl $(procFacesGAMGProcAgglomeration)/procFacesGAMGProcAgglomeration.C +meshes/ijkMesh/ijkMesh.C + meshes/lduMesh/lduMesh.C meshes/lduMesh/lduPrimitiveMesh.C @@ -525,6 +527,9 @@ $(cell)/cell.C $(cell)/oppositeCellFace.C $(cell)/cellIOList.C +hexCell = $(meshShapes)/hexCell +$(hexCell)/hexCell.C + tetCell = $(meshShapes)/tetCell $(tetCell)/tetCell.C diff --git a/src/OpenFOAM/meshes/ijkMesh/ijkMesh.C b/src/OpenFOAM/meshes/ijkMesh/ijkMesh.C new file mode 100644 index 0000000000..7c6dc5c8a2 --- /dev/null +++ b/src/OpenFOAM/meshes/ijkMesh/ijkMesh.C @@ -0,0 +1,56 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . +\*---------------------------------------------------------------------------*/ + +#include "ijkMesh.H" +#include "hexCell.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::hexCell +Foam::ijkMesh::vertLabels(const label i, const label j, const label k) const +{ + hexCell verts; + + verts[0] = pointLabel(i, j, k); + verts[1] = pointLabel(i+1, j, k); + verts[2] = pointLabel(i+1, j+1, k); + verts[3] = pointLabel(i, j+1, k); + verts[4] = pointLabel(i, j, k+1); + verts[5] = pointLabel(i+1, j, k+1); + verts[6] = pointLabel(i+1, j+1, k+1); + verts[7] = pointLabel(i, j+1, k+1); + + return verts; +} + + +Foam::hexCell Foam::ijkMesh::vertLabels(const labelVector& ijk) const +{ + return vertLabels(ijk.x(), ijk.y(), ijk.z()); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/ijkMesh/ijkMesh.H b/src/OpenFOAM/meshes/ijkMesh/ijkMesh.H index 89fff4f65d..8da2879a20 100644 --- a/src/OpenFOAM/meshes/ijkMesh/ijkMesh.H +++ b/src/OpenFOAM/meshes/ijkMesh/ijkMesh.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,6 +33,7 @@ Description addressing information. SourceFiles + ijkMesh.C ijkMeshI.H \*---------------------------------------------------------------------------*/ @@ -47,6 +48,9 @@ SourceFiles namespace Foam { +// Forward Declarations +class hexCell; + /*---------------------------------------------------------------------------*\ Class ijkMesh Declaration \*---------------------------------------------------------------------------*/ @@ -116,6 +120,15 @@ public: //- The linear point index for an i-j-k position. // Addressable in the range (ni+1, nj+1, nk+1). inline label pointLabel(const labelVector& ijk) const; + + + // Mesh Components + + //- The hex cell vertices for an i-j-k position + hexCell vertLabels(const label i, const label j, const label k) const; + + //- The hex cell vertices for an i-j-k position + hexCell vertLabels(const labelVector& ijk) const; }; diff --git a/src/OpenFOAM/meshes/meshShapes/cellShape/cellShape.H b/src/OpenFOAM/meshes/meshShapes/cellShape/cellShape.H index 0be81406c7..8b9148a4b3 100644 --- a/src/OpenFOAM/meshes/meshShapes/cellShape/cellShape.H +++ b/src/OpenFOAM/meshes/meshShapes/cellShape/cellShape.H @@ -81,7 +81,7 @@ public: // Constructors - //- Default construct + //- Default construct. Empty shape, no cell model. inline constexpr cellShape() noexcept; //- Copy construct from components @@ -109,7 +109,7 @@ public: const bool doCollapse = false ); - //- Copy construct from components, using lookup cellModel by name + //- Copy construct from components, lookup cellModel by name inline cellShape ( const word& modelName, @@ -130,7 +130,7 @@ public: inline const cellModel& model() const; //- Number of points - inline label nPoints() const; + inline label nPoints() const noexcept; //- Number of edges inline label nEdges() const; @@ -184,6 +184,15 @@ public: const bool doCollapse = false ); + //- Reset from components + template + inline void reset + ( + const cellModel& model, + const FixedList& labels, + const bool doCollapse = false + ); + //- Collapse shape to correct one after removing duplicate vertices void collapse(); diff --git a/src/OpenFOAM/meshes/meshShapes/cellShape/cellShapeI.H b/src/OpenFOAM/meshes/meshShapes/cellShape/cellShapeI.H index 2c24a4b804..9795386b7c 100644 --- a/src/OpenFOAM/meshes/meshShapes/cellShape/cellShapeI.H +++ b/src/OpenFOAM/meshes/meshShapes/cellShape/cellShapeI.H @@ -129,9 +129,9 @@ inline const Foam::cellModel& Foam::cellShape::model() const } -inline Foam::label Foam::cellShape::nPoints() const +inline Foam::label Foam::cellShape::nPoints() const noexcept { - return size(); + return labelList::size(); } @@ -313,4 +313,22 @@ inline void Foam::cellShape::reset } +template +inline void Foam::cellShape::reset +( + const cellModel& model, + const FixedList& labels, + const bool doCollapse +) +{ + static_cast(*this) = labels; + m = &model; + + if (doCollapse) + { + collapse(); + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/meshShapes/hexCell/hexCell.C b/src/OpenFOAM/meshes/meshShapes/hexCell/hexCell.C new file mode 100644 index 0000000000..15fd47bf3f --- /dev/null +++ b/src/OpenFOAM/meshes/meshShapes/hexCell/hexCell.C @@ -0,0 +1,166 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "hexCell.H" +#include "cellShape.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +// Warning: +// Ordering of faces needs to be the same for +// a hexahedral cell shape model and a hexCell + +const Foam::label Foam::hexCell::modelFaces_[6][4] = +{ + {0, 4, 7, 3}, // x-min + {1, 2, 6, 5}, // x-max + {0, 1, 5, 4}, // y-min + {3, 7, 6, 2}, // y-max + {0, 3, 2, 1}, // z-min + {4, 5, 6, 7} // z-max +}; + + +// Warning: +// Ordering of edges needs to be the same for +// a hexahedral cell shape model and a hexCell + +const Foam::label Foam::hexCell::modelEdges_[12][2] = +{ + {0, 1}, // x-direction + {3, 2}, + {7, 6}, + {4, 5}, + {0, 3}, // y-direction + {1, 2}, + {5, 6}, + {4, 7}, + {0, 4}, // z-direction + {1, 5}, + {2, 6}, + {3, 7} +}; + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +const Foam::faceList& Foam::hexCell::modelFaces() +{ + static std::unique_ptr ptr(nullptr); + + if (!ptr) + { + ptr.reset(new Foam::faceList(6)); + + for (label facei = 0; facei < 6; ++facei) + { + auto& f = (*ptr)[facei]; + + f.resize(4); + f[0] = modelFaces_[facei][0]; + f[1] = modelFaces_[facei][1]; + f[2] = modelFaces_[facei][2]; + f[3] = modelFaces_[facei][3]; + } + } + + return *ptr; +} + + +const Foam::edgeList& Foam::hexCell::modelEdges() +{ + static std::unique_ptr ptr(nullptr); + + if (!ptr) + { + ptr.reset(new Foam::edgeList(12)); + + for (label edgei = 0; edgei < 12; ++edgei) + { + auto& e = (*ptr)[edgei]; + + e.first() = modelEdges_[edgei][0]; + e.second() = modelEdges_[edgei][1]; + } + } + + return *ptr; +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +/// Foam::faceList Foam::hexCell::faces() const +/// { +/// Foam::faceList result(6); +/// +/// for (label facei = 0; facei < 6; ++facei) +/// { +/// auto& f = result[facei]; +/// +/// f.resize(4); +/// f[0] = (*this)[modelFaces_[facei][0]]; +/// f[1] = (*this)[modelFaces_[facei][1]]; +/// f[2] = (*this)[modelFaces_[facei][2]]; +/// f[3] = (*this)[modelFaces_[facei][3]]; +/// } +/// +/// return result; +/// } +/// +/// +/// Foam::edgeList Foam::hexCell::edges() const +/// { +/// Foam::edgeList result(12); +/// +/// for (label edgei = 0; edgei < 12; ++edgei) +/// { +/// auto& e = result[edgei]; +/// +/// e.first() = (*this)[modelEdges_[edgei][0]], +/// e.second() = (*this)[modelEdges_[edgei][1]] +/// } +/// +/// return result; +/// } + + +Foam::cellShape Foam::hexCell::shape(const bool doCollapse) const +{ + static const cellModel* modelPtr(nullptr); + + if (!modelPtr) + { + modelPtr = cellModel::ptr(cellModel::HEX); + } + + return cellShape(*modelPtr, *this, doCollapse); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/meshShapes/hexCell/hexCell.H b/src/OpenFOAM/meshes/meshShapes/hexCell/hexCell.H new file mode 100644 index 0000000000..fb6b9ddace --- /dev/null +++ b/src/OpenFOAM/meshes/meshShapes/hexCell/hexCell.H @@ -0,0 +1,174 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::hexCell + +Description + A hexahedral cell primitive. + + It is important that the face/edge ordering is identical for + a hexahedral cell shape model and a hexCell + +SourceFiles + hexCell.C + hexCellI.H + +\*---------------------------------------------------------------------------*/ + +#ifndef hexCell_H +#define hexCell_H + +#include "FixedList.H" +#include "faceList.H" +#include "edgeList.H" +#include "pointField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward Declarations +class cellShape; + +/*---------------------------------------------------------------------------*\ + Class hexCell Declaration +\*---------------------------------------------------------------------------*/ + +class hexCell +: + public FixedList +{ + // Static Data Members + + //- The model faces for HEX + static const label modelFaces_[6][4]; + + //- The model edges for HEX + static const label modelEdges_[12][2]; + + +public: + + // Constructors + + //- Default construct, with invalid point labels (-1) + inline hexCell(); + + //- Construct from an initializer list of eight point labels + inline explicit hexCell(std::initializer_list