diff --git a/include/GooseFEM/Mesh.h b/include/GooseFEM/Mesh.h index a5b5507..0e7f82f 100644 --- a/include/GooseFEM/Mesh.h +++ b/include/GooseFEM/Mesh.h @@ -1,1573 +1,1577 @@ /** Generic mesh operations. \file Mesh.h \copyright Copyright 2017. Tom de Geus. All rights reserved. \license This project is released under the GNU Public License (GPLv3). */ #ifndef GOOSEFEM_MESH_H #define GOOSEFEM_MESH_H #include "config.h" namespace GooseFEM { namespace Mesh { /** Enumerator for element-types */ enum class ElementType { Unknown, ///< Unknown element-type Quad4, ///< Quadrilateral: 4-noded element in 2-d Hex8, ///< Hexahedron: 8-noded element in 3-d Tri3 ///< Triangle: 3-noded element in 2-d }; /** Extract the element type based on the connectivity. \param coor Nodal coordinates. \param conn Connectivity. \return ElementType(). */ inline ElementType defaultElementType( const xt::xtensor& coor, const xt::xtensor& conn); /** Base-class for regular meshes in 2-d. This class does not have a specific element-type in mind, it is used mostly internally to derive from such that common methods do not have to be reimplementation. */ class RegularBase2d { public: RegularBase2d() = default; + virtual ~RegularBase2d() = default; + /** \return Number of elements. */ size_t nelem() const; /** \return Number of nodes. */ size_t nnode() const; /** \return Number of nodes-per-element == 4. */ size_t nne() const; /** \return Number of dimensions == 2. */ size_t ndim() const; /** \return Number of elements in x-direction == width of the mesh in units of #h. */ virtual size_t nelx() const; /** \return Number of elements in y-direction == height of the mesh, in units of #h, */ virtual size_t nely() const; /** \return Linear edge size of one 'block'. */ double h() const; /** \return The ElementType(). */ virtual ElementType getElementType() const; /** \return Nodal coordinates [#nnode, #ndim]. */ virtual xt::xtensor coor() const; /** \return Connectivity [#nelem, #nne]. */ virtual xt::xtensor conn() const; /** \return DOF numbers for each node (numbered sequentially) [#nnode, #ndim]. */ virtual xt::xtensor dofs() const; /** Nodes along the bottom edge (y = 0), in order of increasing x. \return List of node numbers. */ virtual xt::xtensor nodesBottomEdge() const; /** Nodes along the top edge (y = #nely * #h), in order of increasing x. \return List of node numbers. */ virtual xt::xtensor nodesTopEdge() const; /** Nodes along the left edge (x = 0), in order of increasing y. \return List of node numbers. */ virtual xt::xtensor nodesLeftEdge() const; /** Nodes along the right edge (x = #nelx * #h), in order of increasing y. \return List of node numbers. */ virtual xt::xtensor nodesRightEdge() const; /** Nodes along the bottom edge (y = 0), without the corners (at x = 0 and x = #nelx * #h). Same as: nodesBottomEdge()[1: -1]. \return List of node numbers. */ virtual xt::xtensor nodesBottomOpenEdge() const; /** Nodes along the top edge (y = #nely * #h), without the corners (at x = 0 and x = #nelx * #h). Same as: nodesTopEdge()[1: -1]. \return List of node numbers. */ virtual xt::xtensor nodesTopOpenEdge() const; /** Nodes along the left edge (x = 0), without the corners (at y = 0 and y = #nely * #h). Same as: nodesLeftEdge()[1: -1]. \return List of node numbers. */ virtual xt::xtensor nodesLeftOpenEdge() const; /** Nodes along the right edge (x = #nelx * #h), without the corners (at y = 0 and y = #nely * #h). Same as: nodesRightEdge()[1: -1]. \return List of node numbers. */ virtual xt::xtensor nodesRightOpenEdge() const; /** The bottom-left corner node (at x = 0, y = 0). Same as nodesBottomEdge()[0] and nodesLeftEdge()[0]. \return Node number. */ virtual size_t nodesBottomLeftCorner() const; /** The bottom-right corner node (at x = #nelx * #h, y = 0). Same as nodesBottomEdge()[-1] and nodesRightEdge()[0]. \return Node number. */ virtual size_t nodesBottomRightCorner() const; /** The top-left corner node (at x = 0, y = #nely * #h). Same as nodesTopEdge()[0] and nodesRightEdge()[-1]. \return Node number. */ virtual size_t nodesTopLeftCorner() const; /** The top-right corner node (at x = #nelx * #h, y = #nely * #h). Same as nodesTopEdge()[-1] and nodesRightEdge()[-1]. \return Node number. */ virtual size_t nodesTopRightCorner() const; /** \return Alias of nodesBottomLeftCorner(). */ size_t nodesLeftBottomCorner() const; /** \return Alias of nodesTopLeftCorner(). */ size_t nodesLeftTopCorner() const; /** \return Alias of nodesBottomRightCorner(). */ size_t nodesRightBottomCorner() const; /** \return Alias of nodesTopRightCorner(). */ size_t nodesRightTopCorner() const; /** DOF-numbers for the case that the periodicity if fully eliminated. Such that: dofs[nodesRightOpenEdge(), :] = dofs[nodesLeftOpenEdge(), :] dofs[nodesTopOpenEdge(), :] = dofs[nodesBottomOpenEdge(), :] dofs[nodesBottomRightCorner(), :] = dofs[nodesBottomLeftCorner(), :] dofs[nodesTopRightCorner(), :] = dofs[nodesBottomLeftCorner(), :] dofs[nodesTopLeftCorner(), :] = dofs[nodesBottomLeftCorner(), :] \return DOF numbers for each node [#nnode, #ndim]. */ xt::xtensor dofsPeriodic() const; /** Periodic node pairs, in two columns: (independent, dependent). - nodesRightOpenEdge() are tied to nodesLeftOpenEdge(). - nodesTopOpenEdge() are tied to nodesBottomOpenEdge(). - nodesBottomRightCorner() are tied to nodesBottomLeftCorner(). - nodesTopRightCorner() are tied to nodesBottomLeftCorner(). - nodesTopLeftCorner() are tied to nodesBottomLeftCorner(). \return [ntyings, #ndim]. */ xt::xtensor nodesPeriodic() const; /** Reference node to use for periodicity, because all corners are tied to it. \return Alias of nodesBottomLeftCorner(). */ size_t nodesOrigin() const; protected: double m_h; ///< See h() size_t m_nelx; ///< See nelx() size_t m_nely; ///< See nely() size_t m_nelem; ///< See nelem() size_t m_nnode; ///< See nnode() size_t m_nne; ///< See nne() size_t m_ndim; ///< See ndim() }; /** Base-class for regular meshes in 3-d. This class does not have a specific element-type in mind, it is used mostly internally to derive from such that common methods do not have to be reimplementation. */ class RegularBase3d { public: RegularBase3d() = default; + virtual ~RegularBase3d() = default; + /** \return Number of elements. */ size_t nelem() const; /** \return Number of nodes. */ size_t nnode() const; /** \return Number of nodes-per-element == 4. */ size_t nne() const; /** \return Number of dimensions == 2. */ size_t ndim() const; /** \return Number of elements in x-direction == width of the mesh in units of #h. */ virtual size_t nelx() const; /** \return Number of elements in y-direction == height of the mesh, in units of #h, */ virtual size_t nely() const; /** \return Number of elements in y-direction == height of the mesh, in units of #h, */ virtual size_t nelz() const; /** \return Linear edge size of one 'block'. */ double h() const; /** \return The ElementType(). */ virtual ElementType getElementType() const; /** \return Nodal coordinates [#nnode, #ndim]. */ virtual xt::xtensor coor() const; /** \return Connectivity [#nelem, #nne]. */ virtual xt::xtensor conn() const; /** \return DOF numbers for each node (numbered sequentially) [#nnode, #ndim]. */ virtual xt::xtensor dofs() const; /** Nodes along the bottom face (y = 0). \return List of node numbers. */ virtual xt::xtensor nodesBottom() const; /** Nodes along the top face (y = #nely * #h). \return List of node numbers. */ virtual xt::xtensor nodesTop() const; /** Nodes along the left face (x = 0). \return List of node numbers. */ virtual xt::xtensor nodesLeft() const; /** Nodes along the right face (x = #nelx * #h). \return List of node numbers. */ virtual xt::xtensor nodesRight() const; /** Nodes along the front face (z = 0). \return List of node numbers. */ virtual xt::xtensor nodesFront() const; /** Nodes along the back face (z = #nelz * #h). \return List of node numbers. */ virtual xt::xtensor nodesBack() const; /** Nodes along the edge at the intersection of the front and bottom faces (z = 0 and y = 0). \return List of node numbers. */ virtual xt::xtensor nodesFrontBottomEdge() const; /** Nodes along the edge at the intersection of the front and top faces (z = 0 and y = #nely * #h). \return List of node numbers. */ virtual xt::xtensor nodesFrontTopEdge() const; /** Nodes along the edge at the intersection of the front and left faces (z = 0 and x = 0). \return List of node numbers. */ virtual xt::xtensor nodesFrontLeftEdge() const; /** Nodes along the edge at the intersection of the front and right faces (z = 0 and x = #nelx * #h). \return List of node numbers. */ virtual xt::xtensor nodesFrontRightEdge() const; /** Nodes along the edge at the intersection of the back and bottom faces (z = #nelz * #h and y = #nely * #h). \return List of node numbers. */ virtual xt::xtensor nodesBackBottomEdge() const; /** Nodes along the edge at the intersection of the back and top faces (z = #nelz * #h and x = 0). \return List of node numbers. */ virtual xt::xtensor nodesBackTopEdge() const; /** Nodes along the edge at the intersection of the back and left faces (z = #nelz * #h and x = #nelx * #h). \return List of node numbers. */ virtual xt::xtensor nodesBackLeftEdge() const; /** Nodes along the edge at the intersection of the back and right faces (? = #nelz * #h and ? = ?). \return List of node numbers. */ virtual xt::xtensor nodesBackRightEdge() const; /** Nodes along the edge at the intersection of the bottom and left faces (y = 0 and x = 0). \return List of node numbers. */ virtual xt::xtensor nodesBottomLeftEdge() const; /** Nodes along the edge at the intersection of the bottom and right faces (y = 0 and x = #nelx * #h). \return List of node numbers. */ virtual xt::xtensor nodesBottomRightEdge() const; /** Nodes along the edge at the intersection of the top and left faces (y = 0 and x = #nelx * #h). \return List of node numbers. */ virtual xt::xtensor nodesTopLeftEdge() const; /** Nodes along the edge at the intersection of the top and right faces (y = #nely * #h and x = #nelx * #h). \return List of node numbers. */ virtual xt::xtensor nodesTopRightEdge() const; /** \return Alias of nodesFrontBottomEdge() */ xt::xtensor nodesBottomFrontEdge() const; /** \return Alias of nodesBackBottomEdge() */ xt::xtensor nodesBottomBackEdge() const; /** \return Alias of nodesFrontTopEdge() */ xt::xtensor nodesTopFrontEdge() const; /** \return Alias of nodesBackTopEdge() */ xt::xtensor nodesTopBackEdge() const; /** \return Alias of nodesBottomLeftEdge() */ xt::xtensor nodesLeftBottomEdge() const; /** \return Alias of nodesFrontLeftEdge() */ xt::xtensor nodesLeftFrontEdge() const; /** \return Alias of nodesBackLeftEdge() */ xt::xtensor nodesLeftBackEdge() const; /** \return Alias of nodesTopLeftEdge() */ xt::xtensor nodesLeftTopEdge() const; /** \return Alias of nodesBottomRightEdge() */ xt::xtensor nodesRightBottomEdge() const; /** \return Alias of nodesTopRightEdge() */ xt::xtensor nodesRightTopEdge() const; /** \return Alias of nodesFrontRightEdge() */ xt::xtensor nodesRightFrontEdge() const; /** \return Alias of nodesBackRightEdge() */ xt::xtensor nodesRightBackEdge() const; /** Nodes along the front face excluding edges. Same as different between nodesFront() and [nodesFrontBottomEdge(), nodesFrontTopEdge(), nodesFrontLeftEdge(), nodesFrontRightEdge()] \return list of node numbers. */ virtual xt::xtensor nodesFrontFace() const; /** Nodes along the back face excluding edges. Same as different between nodesBack() and [nodesBackBottomEdge(), nodesBackTopEdge(), nodesBackLeftEdge(), nodesBackRightEdge()] \return list of node numbers. */ virtual xt::xtensor nodesBackFace() const; /** Nodes along the left face excluding edges. Same as different between nodesLeft() and [nodesFrontLeftEdge(), nodesBackLeftEdge(), nodesBottomLeftEdge(), nodesTopLeftEdge()] \return list of node numbers. */ virtual xt::xtensor nodesLeftFace() const; /** Nodes along the right face excluding edges. Same as different between nodesRight() and [nodesFrontRightEdge(), nodesBackRightEdge(), nodesBottomRightEdge(), nodesTopRightEdge()] \return list of node numbers. */ virtual xt::xtensor nodesRightFace() const; /** Nodes along the bottom face excluding edges. Same as different between nodesBottom() and [nodesBackBottomEdge(), nodesBackTopEdge(), nodesBackLeftEdge(), nodesBackRightEdge()] \return list of node numbers. */ virtual xt::xtensor nodesBottomFace() const; /** Nodes along the top face excluding edges. Same as different between nodesTop() and [nodesFrontBottomEdge(), nodesFrontTopEdge(), nodesFrontLeftEdge(), nodesFrontRightEdge()] \return list of node numbers. */ virtual xt::xtensor nodesTopFace() const; /** Same as nodesFrontBottomEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesFrontBottomOpenEdge() const; /** Same as nodesFrontTopEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesFrontTopOpenEdge() const; /** Same as nodesFrontLeftEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesFrontLeftOpenEdge() const; /** Same as nodesFrontRightEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesFrontRightOpenEdge() const; /** Same as nodesBackBottomEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesBackBottomOpenEdge() const; /** Same as nodesBackTopEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesBackTopOpenEdge() const; /** Same as nodesBackLeftEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesBackLeftOpenEdge() const; /** Same as nodesBackRightEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesBackRightOpenEdge() const; /** Same as nodesBottomLeftEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesBottomLeftOpenEdge() const; /** Same as nodesBottomRightEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesBottomRightOpenEdge() const; /** Same as nodesTopLeftEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesTopLeftOpenEdge() const; /** Same as nodesTopRightEdge() but without corners. \return List of node numbers. */ virtual xt::xtensor nodesTopRightOpenEdge() const; /** \return Alias of nodesFrontBottomOpenEdge(). */ xt::xtensor nodesBottomFrontOpenEdge() const; /** \return Alias of nodesBackBottomOpenEdge(). */ xt::xtensor nodesBottomBackOpenEdge() const; /** \return Alias of nodesFrontTopOpenEdge(). */ xt::xtensor nodesTopFrontOpenEdge() const; /** \return Alias of nodesBackTopOpenEdge(). */ xt::xtensor nodesTopBackOpenEdge() const; /** \return Alias of nodesBottomLeftOpenEdge(). */ xt::xtensor nodesLeftBottomOpenEdge() const; /** \return Alias of nodesFrontLeftOpenEdge(). */ xt::xtensor nodesLeftFrontOpenEdge() const; /** \return Alias of nodesBackLeftOpenEdge(). */ xt::xtensor nodesLeftBackOpenEdge() const; /** \return Alias of nodesTopLeftOpenEdge(). */ xt::xtensor nodesLeftTopOpenEdge() const; /** \return Alias of nodesBottomRightOpenEdge(). */ xt::xtensor nodesRightBottomOpenEdge() const; /** \return Alias of nodesTopRightOpenEdge(). */ xt::xtensor nodesRightTopOpenEdge() const; /** \return Alias of nodesFrontRightOpenEdge(). */ xt::xtensor nodesRightFrontOpenEdge() const; /** \return Alias of nodesBackRightOpenEdge(). */ xt::xtensor nodesRightBackOpenEdge() const; /** Front-Bottom-Left corner node. \return Node number. */ virtual size_t nodesFrontBottomLeftCorner() const; /** Front-Bottom-Right corner node. \return Node number. */ virtual size_t nodesFrontBottomRightCorner() const; /** Front-Top-Left corner node. \return Node number. */ virtual size_t nodesFrontTopLeftCorner() const; /** Front-Top-Right corner node. \return Node number. */ virtual size_t nodesFrontTopRightCorner() const; /** Back-Bottom-Left corner node. \return Node number. */ virtual size_t nodesBackBottomLeftCorner() const; /** Back-Bottom-Right corner node. \return Node number. */ virtual size_t nodesBackBottomRightCorner() const; /** Back-Top-Left corner node. \return Node number. */ virtual size_t nodesBackTopLeftCorner() const; /** Back-Top-Right corner node. \return Node number. */ virtual size_t nodesBackTopRightCorner() const; /** \return Alias of nodesFrontBottomLeftCorner(). */ size_t nodesFrontLeftBottomCorner() const; /** \return Alias of nodesFrontBottomLeftCorner(). */ size_t nodesBottomFrontLeftCorner() const; /** \return Alias of nodesFrontBottomLeftCorner(). */ size_t nodesBottomLeftFrontCorner() const; /** \return Alias of nodesFrontBottomLeftCorner(). */ size_t nodesLeftFrontBottomCorner() const; /** \return Alias of nodesFrontBottomLeftCorner(). */ size_t nodesLeftBottomFrontCorner() const; /** \return Alias of nodesFrontBottomRightCorner(). */ size_t nodesFrontRightBottomCorner() const; /** \return Alias of nodesFrontBottomRightCorner(). */ size_t nodesBottomFrontRightCorner() const; /** \return Alias of nodesFrontBottomRightCorner(). */ size_t nodesBottomRightFrontCorner() const; /** \return Alias of nodesFrontBottomRightCorner(). */ size_t nodesRightFrontBottomCorner() const; /** \return Alias of nodesFrontBottomRightCorner(). */ size_t nodesRightBottomFrontCorner() const; /** \return Alias of nodesFrontTopLeftCorner(). */ size_t nodesFrontLeftTopCorner() const; /** \return Alias of nodesFrontTopLeftCorner(). */ size_t nodesTopFrontLeftCorner() const; /** \return Alias of nodesFrontTopLeftCorner(). */ size_t nodesTopLeftFrontCorner() const; /** \return Alias of nodesFrontTopLeftCorner(). */ size_t nodesLeftFrontTopCorner() const; /** \return Alias of nodesFrontTopLeftCorner(). */ size_t nodesLeftTopFrontCorner() const; /** \return Alias of nodesFrontTopRightCorner(). */ size_t nodesFrontRightTopCorner() const; /** \return Alias of nodesFrontTopRightCorner(). */ size_t nodesTopFrontRightCorner() const; /** \return Alias of nodesFrontTopRightCorner(). */ size_t nodesTopRightFrontCorner() const; /** \return Alias of nodesFrontTopRightCorner(). */ size_t nodesRightFrontTopCorner() const; /** \return Alias of nodesFrontTopRightCorner(). */ size_t nodesRightTopFrontCorner() const; /** \return Alias of nodesBackBottomLeftCorner(). */ size_t nodesBackLeftBottomCorner() const; /** \return Alias of nodesBackBottomLeftCorner(). */ size_t nodesBottomBackLeftCorner() const; /** \return Alias of nodesBackBottomLeftCorner(). */ size_t nodesBottomLeftBackCorner() const; /** \return Alias of nodesBackBottomLeftCorner(). */ size_t nodesLeftBackBottomCorner() const; /** \return Alias of nodesBackBottomLeftCorner(). */ size_t nodesLeftBottomBackCorner() const; /** \return Alias of nodesBackBottomRightCorner(). */ size_t nodesBackRightBottomCorner() const; /** \return Alias of nodesBackBottomRightCorner(). */ size_t nodesBottomBackRightCorner() const; /** \return Alias of nodesBackBottomRightCorner(). */ size_t nodesBottomRightBackCorner() const; /** \return Alias of nodesBackBottomRightCorner(). */ size_t nodesRightBackBottomCorner() const; /** \return Alias of nodesBackBottomRightCorner(). */ size_t nodesRightBottomBackCorner() const; /** \return Alias of nodesBackTopLeftCorner(). */ size_t nodesBackLeftTopCorner() const; /** \return Alias of nodesBackTopLeftCorner(). */ size_t nodesTopBackLeftCorner() const; /** \return Alias of nodesBackTopLeftCorner(). */ size_t nodesTopLeftBackCorner() const; /** \return Alias of nodesBackTopLeftCorner(). */ size_t nodesLeftBackTopCorner() const; /** \return Alias of nodesBackTopLeftCorner(). */ size_t nodesLeftTopBackCorner() const; /** \return Alias of nodesBackTopRightCorner(). */ size_t nodesBackRightTopCorner() const; /** \return Alias of nodesBackTopRightCorner(). */ size_t nodesTopBackRightCorner() const; /** \return Alias of nodesBackTopRightCorner(). */ size_t nodesTopRightBackCorner() const; /** \return Alias of nodesBackTopRightCorner(). */ size_t nodesRightBackTopCorner() const; /** \return Alias of nodesBackTopRightCorner(). */ size_t nodesRightTopBackCorner() const; /** DOF-numbers for the case that the periodicity if fully eliminated. Such that: dofs[nodesBackFace(), :] = dofs[nodesFrontFace(), :] dofs[nodesRightFace(), :] = dofs[nodesLeftFace(), :] dofs[nodesTopFace(), :] = dofs[nodesBottomFace(), :] dofs[nodesBackBottomOpenEdge(), :] = dofs[nodesFrontBottomOpenEdge(), :] dofs[nodesBackTopOpenEdge(), :] = dofs[nodesFrontBottomOpenEdge(), :] dofs[nodesFrontTopOpenEdge(), :] = dofs[nodesFrontBottomOpenEdge(), :] dofs[nodesBottomRightOpenEdge(), :] = dofs[nodesBottomLeftOpenEdge(), :] dofs[nodesTopRightOpenEdge(), :] = dofs[nodesBottomLeftOpenEdge(), :] dofs[nodesTopLeftOpenEdge(), :] = dofs[nodesBottomLeftOpenEdge(), :] dofs[nodesFrontRightOpenEdge(), :] = dofs[nodesFrontLeftOpenEdge(), :] dofs[nodesBackRightOpenEdge(), :] = dofs[nodesFrontLeftOpenEdge(), :] dofs[nodesBackLeftOpenEdge(), :] = dofs[nodesFrontLeftOpenEdge(), :] dofs[nodesFrontBottomRightCorner(), :] = dofs[nodesFrontBottomLeftCorner(), :] dofs[nodesBackBottomRightCorner(), :] = dofs[nodesFrontBottomLeftCorner(), :] dofs[nodesBackBottomLeftCorner(), :] = dofs[nodesFrontBottomLeftCorner(), :] dofs[nodesFrontTopLeftCorner(), :] = dofs[nodesFrontBottomLeftCorner(), :] dofs[nodesFrontTopRightCorner(), :] = dofs[nodesFrontBottomLeftCorner(), :] dofs[nodesBackTopRightCorner(), :] = dofs[nodesFrontBottomLeftCorner(), :] dofs[nodesBackTopLeftCorner(), :] = dofs[nodesFrontBottomLeftCorner(), :] \return DOF numbers for each node [#nnode, #ndim]. */ xt::xtensor dofsPeriodic() const; /** Periodic node pairs, in two columns: (independent, dependent). - nodesBackFace() are tied to nodesFrontFace(). - nodesRightFace() are tied to nodesLeftFace(). - nodesTopFace() are tied to nodesBottomFace(). - nodesBackBottomOpenEdge() are tied to nodesFrontBottomOpenEdge(). - nodesBackTopOpenEdge() are tied to nodesFrontBottomOpenEdge(). - nodesFrontTopOpenEdge() are tied to nodesFrontBottomOpenEdge(). - nodesBottomRightOpenEdge() are tied to nodesBottomLeftOpenEdge(). - nodesTopRightOpenEdge() are tied to nodesBottomLeftOpenEdge(). - nodesTopLeftOpenEdge() are tied to nodesBottomLeftOpenEdge(). - nodesFrontRightOpenEdge() are tied to nodesFrontLeftOpenEdge(). - nodesBackRightOpenEdge() are tied to nodesFrontLeftOpenEdge(). - nodesBackLeftOpenEdge() are tied to nodesFrontLeftOpenEdge(). - nodesFrontBottomRightCorner() are tied to nodesFrontBottomLeftCorner(). - nodesBackBottomRightCorner() are tied to nodesFrontBottomLeftCorner(). - nodesBackBottomLeftCorner() are tied to nodesFrontBottomLeftCorner(). - nodesFrontTopLeftCorner() are tied to nodesFrontBottomLeftCorner(). - nodesFrontTopRightCorner() are tied to nodesFrontBottomLeftCorner(). - nodesBackTopRightCorner() are tied to nodesFrontBottomLeftCorner(). - nodesBackTopLeftCorner() are tied to nodesFrontBottomLeftCorner(). \return [ntyings, #ndim]. */ xt::xtensor nodesPeriodic() const; /** Reference node to use for periodicity, because all corners are tied to it. \return Alias of nodesFrontBottomLeftCorner(). */ size_t nodesOrigin() const; protected: double m_h; ///< See h() size_t m_nelx; ///< See nelx() size_t m_nely; ///< See nely() size_t m_nelz; ///< See nely() size_t m_nelem; ///< See nelem() size_t m_nnode; ///< See nnode() size_t m_nne; ///< See nne() size_t m_ndim; ///< See ndim() }; /** Find overlapping nodes. The output has the following structure: [[nodes_from_mesh_a], [nodes_from_mesh_b]] \param coor_a Nodal coordinates of mesh "a". \param coor_b Nodal coordinates of mesh "b". \param rtol Relative tolerance for position match. \param atol Absolute tolerance for position match. \return Overlapping nodes. */ inline xt::xtensor overlapping( const xt::xtensor& coor_a, const xt::xtensor& coor_b, double rtol = 1e-5, double atol = 1e-8); /** Stitch two mesh objects, specifying overlapping nodes by hand. */ class ManualStitch { public: ManualStitch() = default; /** \param coor_a Nodal coordinates of mesh "a". \param conn_a Connectivity of mesh "a". \param overlapping_nodes_a Node-numbers of mesh "a" that overlap with mesh "b". \param coor_b Nodal coordinates of mesh "b". \param conn_b Connectivity of mesh "b". \param overlapping_nodes_b Node-numbers of mesh "b" that overlap with mesh "a". \param check_position If ``true`` the nodes are checked for position overlap. \param rtol Relative tolerance for check on position overlap. \param atol Absolute tolerance for check on position overlap. */ ManualStitch( const xt::xtensor& coor_a, const xt::xtensor& conn_a, const xt::xtensor& overlapping_nodes_a, const xt::xtensor& coor_b, const xt::xtensor& conn_b, const xt::xtensor& overlapping_nodes_b, bool check_position = true, double rtol = 1e-5, double atol = 1e-8); /** \return Number of sub meshes == 2. */ size_t nmesh() const; /** \return Number of elements. */ size_t nelem() const; /** \return Number of nodes. */ size_t nnode() const; /** \return Number of nodes-per-element. */ size_t nne() const; /** \return Number of dimensions. */ size_t ndim() const; /** \return Nodal coordinates [#nnode, #ndim]. */ xt::xtensor coor() const; /** \return Connectivity [#nelem, #nne]. */ xt::xtensor conn() const; /** \return DOF numbers for each node (numbered sequentially) [#nnode, #ndim]. */ xt::xtensor dofs() const; /** \return Node-map per sub-mesh. */ std::vector> nodemap() const; /** \return Element-map per sub-mesh. */ std::vector> elemmap() const; /** \param mesh_index Index of the mesh ("a" = 1, "b" = 1). \return Node-map for a given mesh. */ xt::xtensor nodemap(size_t mesh_index) const; /** \param mesh_index Index of the mesh ("a" = 1, "b" = 1). \return Element-map for a given mesh. */ xt::xtensor elemmap(size_t mesh_index) const; /** Convert set of node numbers for an original mesh to the stitched mesh. \param set List of node numbers. \param mesh_index Index of the mesh ("a" = 1, "b" = 1). \return List of node numbers for the stitched mesh. */ xt::xtensor nodeset(const xt::xtensor& set, size_t mesh_index) const; /** Convert set of element numbers for an original mesh to the stitched mesh. \param set List of element numbers. \param mesh_index Index of the mesh ("a" = 1, "b" = 1). \return List of element numbers for the stitched mesh. */ xt::xtensor elemset(const xt::xtensor& set, size_t mesh_index) const; private: xt::xtensor m_coor; xt::xtensor m_conn; xt::xtensor m_map_b; size_t m_nnd_a; size_t m_nel_a; size_t m_nel_b; }; /** Stitch mesh objects, automatically searching for overlapping nodes. */ class Stitch { public: /** \param rtol Relative tolerance for position match. \param atol Absolute tolerance for position match. */ Stitch(double rtol = 1e-5, double atol = 1e-8); /** Add mesh to be stitched. \param coor Nodal coordinates. \param conn Connectivity. */ void push_back(const xt::xtensor& coor, const xt::xtensor& conn); /** \return Number of sub meshes. */ size_t nmesh() const; /** \return Number of elements. */ size_t nelem() const; /** \return Number of nodes. */ size_t nnode() const; /** \return Number of nodes-per-element. */ size_t nne() const; /** \return Number of dimensions. */ size_t ndim() const; /** \return Nodal coordinates [#nnode, #ndim]. */ xt::xtensor coor() const; /** \return Connectivity [#nelem, #nne]. */ xt::xtensor conn() const; /** \return DOF numbers for each node (numbered sequentially) [#nnode, #ndim]. */ xt::xtensor dofs() const; /** \return Node-map per sub-mesh. */ std::vector> nodemap() const; /** \return Element-map per sub-mesh. */ std::vector> elemmap() const; /** The node numbers in the stitched mesh that are coming from a specific sub-mesh. \param mesh_index Index of the sub-mesh. \return List of node numbers. */ xt::xtensor nodemap(size_t mesh_index) const; /** The element numbers in the stitched mesh that are coming from a specific sub-mesh. \param mesh_index Index of the sub-mesh. \return List of element numbers. */ xt::xtensor elemmap(size_t mesh_index) const; /** Convert set of node-numbers for a sub-mesh to the stitched mesh. \param set List of node numbers. \param mesh_index Index of the sub-mesh. \return List of node numbers for the stitched mesh. */ xt::xtensor nodeset(const xt::xtensor& set, size_t mesh_index) const; /** Convert set of element-numbers for a sub-mesh to the stitched mesh. \param set List of element numbers. \param mesh_index Index of the sub-mesh. \return List of element numbers for the stitched mesh. */ xt::xtensor elemset(const xt::xtensor& set, size_t mesh_index) const; /** Combine set of node numbers for an original to the final mesh (removes duplicates). \param set List of node numbers per mesh. \return List of node numbers for the stitched mesh. */ xt::xtensor nodeset(const std::vector>& set) const; /** Combine set of element numbers for an original to the final mesh. \param set List of element numbers per mesh. \return List of element numbers for the stitched mesh. */ xt::xtensor elemset(const std::vector>& set) const; private: xt::xtensor m_coor; xt::xtensor m_conn; std::vector> m_map; std::vector m_nel; ///< Number of elements per sub-mesh. std::vector m_el_offset; double m_rtol; double m_atol; }; /** \rst Renumber indices to lowest possible index. For example: .. math:: \begin{bmatrix} 0 & 1 \\ 5 & 4 \end{bmatrix} is renumbered to .. math:: \begin{bmatrix} 0 & 1 \\ 3 & 2 \end{bmatrix} Or, in pseudo-code, the result of this function is that: .. code-block:: python dofs = renumber(dofs) sort(unique(dofs[:])) == range(max(dofs+1)) .. tip:: One can use the wrapper function :cpp:func:`GooseFEM::Mesh::renumber`. This class gives more advanced features. \endrst */ class Renumber { public: Renumber() = default; /** \param dofs DOF-numbers. */ template Renumber(const T& dofs); /** Get renumbered DOFs (same as ``Renumber::apply(dofs)``). \param dofs List of (DOF-)numbers. \return Renumbered list of (DOF-)numbers. */ [[deprecated]] xt::xtensor get(const xt::xtensor& dofs) const; /** Apply renumbering to other set. \param list List of (DOF-)numbers. \return Renumbered list of (DOF-)numbers. */ template T apply(const T& list) const; /** Get the list needed to renumber, e.g.: dofs_renumbered(i, j) = index(dofs(i, j)) \return Renumber-index. */ xt::xtensor index() const; private: xt::xtensor m_renum; }; /** Renumber to lowest possible index (see GooseFEM::Mesh::Renumber). \param dofs DOF-numbers. \return Renumbered DOF-numbers. */ inline xt::xtensor renumber(const xt::xtensor& dofs); /** Reorder to lowest possible index, in specific order. For example for ``Reorder({iiu, iip})`` after reordering: iiu = xt::range(nnu); iip = xt::range(nnp) + nnu; */ class Reorder { public: Reorder() = default; /** \param args List of (DOF-)numbers. */ Reorder(const std::initializer_list> args); /** Get reordered DOFs (same as ``Reorder::apply(dofs)``). \param dofs List of (DOF-)numbers. \return Reordered list of (DOF-)numbers. */ [[deprecated]] xt::xtensor get(const xt::xtensor& dofs) const; /** Apply reordering to other set. \param list List of (DOF-)numbers. \return Reordered list of (DOF-)numbers. */ template T apply(const T& list) const; /** Get the list needed to reorder, e.g.: dofs_reordered(i, j) = index(dofs(i, j)) \return Reorder-index. */ xt::xtensor index() const; private: xt::xtensor m_renum; }; /** List with DOF-numbers in sequential order. The output is a sequential list of DOF-numbers for each vector-component of each node. For example for 3 nodes in 2 dimensions the output is \rst .. math:: \begin{bmatrix} 0 & 1 \\ 2 & 3 \\ 4 & 5 \end{bmatrix} \endrst \param nnode Number of nodes. \param ndim Number of dimensions. \return DOF-numbers. */ inline xt::xtensor dofs(size_t nnode, size_t ndim); /** Number of elements connected to each node. \param conn Connectivity. \return Coordination per node. */ inline xt::xtensor coordination(const xt::xtensor& conn); /** Elements connected to each node. \param conn Connectivity. \param sorted If ``true`` the output is sorted. \return Elements per node. */ inline std::vector> elem2node( const xt::xtensor& conn, bool sorted = true); /** Return size of each element edge. \param coor Nodal coordinates. \param conn Connectivity. \param type ElementType. \return Edge-sizes per element. */ inline xt::xtensor edgesize( const xt::xtensor& coor, const xt::xtensor& conn, ElementType type); /** Return size of each element edge. The element-type is automatically determined, see defaultElementType(). \param coor Nodal coordinates. \param conn Connectivity. \return Edge-sizes per element. */ inline xt::xtensor edgesize( const xt::xtensor& coor, const xt::xtensor& conn); /** Coordinates of the center of each element. \param coor Nodal coordinates. \param conn Connectivity. \param type ElementType. \return Center of each element. */ inline xt::xtensor centers( const xt::xtensor& coor, const xt::xtensor& conn, ElementType type); /** Coordinates of the center of each element. The element-type is automatically determined, see defaultElementType(). \param coor Nodal coordinates. \param conn Connectivity. \return Center of each element. */ inline xt::xtensor centers( const xt::xtensor& coor, const xt::xtensor& conn); /** Convert an element-map to a node-map. \param elem_map Element-map such that ``new_elvar = elvar[elem_map]``. \param coor Nodal coordinates. \param conn Connectivity. \param type ElementType. \return Node-map such that ``new_nodevar = nodevar[node_map]`` */ inline xt::xtensor elemmap2nodemap( const xt::xtensor& elem_map, const xt::xtensor& coor, const xt::xtensor& conn, ElementType type); /** Convert an element-map to a node-map. The element-type is automatically determined, see defaultElementType(). \param elem_map Element-map such that ``new_elvar = elvar[elem_map]``. \param coor Nodal coordinates. \param conn Connectivity. \return Node-map such that ``new_nodevar = nodevar[node_map]`` */ inline xt::xtensor elemmap2nodemap( const xt::xtensor& elem_map, const xt::xtensor& coor, const xt::xtensor& conn); } // namespace Mesh } // namespace GooseFEM #include "Mesh.hpp" #endif