diff --git a/include/GooseFEM/Mesh.h b/include/GooseFEM/Mesh.h index 262cf26..5d57c54 100644 --- a/include/GooseFEM/Mesh.h +++ b/include/GooseFEM/Mesh.h @@ -1,474 +1,556 @@ /** 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 { 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); /** 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 Nodal coordinates of stitched mesh. + Number of elements. + + \return unsigned int. + */ + size_t nelem() const; + + /** + Number of nodes. + + \return unsigned int. + */ + size_t nnode() const; + + /** + Number of nodes-per-element. + + \return unsigned int. + */ + size_t nne() const; + + /** + Number of dimensions. + + \return unsigned int. + */ + size_t ndim() const; + + /** + Nodal coordinates. + + \return [#nnode, #ndim]. */ xt::xtensor coor() const; /** - \return Connectivity of stitched mesh. + Connectivity. + + \return [#nelem, #nne]. */ xt::xtensor conn() const; + /** + DOF numbers for each node (numbered sequentially). + + \return [#nnode, #ndim]. + */ + xt::xtensor dofs() 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. + Convert set of node numbers for an original mesh to the stitched mesh. - \param set Set of node-numbers. + \param set List of node numbers. \param mesh_index Index of the mesh ("a" = 1, "b" = 1). - \return Set of node-number for the stitched 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 an original mesh to the stitched mesh. + Convert set of element numbers for an original mesh to the stitched mesh. - \param set Set of element-numbers. + \param set List of element numbers. \param mesh_index Index of the mesh ("a" = 1, "b" = 1). - \return Set of element-number for the stitched mesh. + \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 Nodal coordinates. + Number of elements. + + \return unsigned int. + */ + size_t nelem() const; + + /** + Number of nodes. + + \return unsigned int. + */ + size_t nnode() const; + + /** + Number of nodes-per-element. + + \return unsigned int. + */ + size_t nne() const; + + /** + Number of dimensions. + + \return unsigned int. + */ + size_t ndim() const; + + /** + Nodal coordinates. + + \return [#nnode, #ndim]. */ xt::xtensor coor() const; /** - \return Connectivity. + Connectivity. + + \return [#nelem, #nne]. */ xt::xtensor conn() const; /** - \param mesh_index Index of the mesh. - \return Node-map for a given mesh. + DOF numbers for each node (numbered sequentially). + + \return [#nnode, #ndim]. + */ + xt::xtensor dofs() 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; /** - \param mesh_index Index of the mesh. - \return Element-map for a given mesh. + 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 an original mesh to the stitched mesh. + Convert set of node-numbers for a sub-mesh to the stitched mesh. - \param set Set of node-numbers. - \param mesh_index Index of the mesh. - \return Set of node-number for 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 an original mesh to the stitched mesh. + Convert set of element-numbers for a sub-mesh to the stitched mesh. - \param set Set of element-numbers. - \param mesh_index Index of the mesh. - \return Set of element-number for 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). + Combine set of node numbers for an original to the final mesh (removes duplicates). - \param set List of node-sets per mesh. - \return Combined node-set on the stitched mesh. + \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. + Combine set of element numbers for an original to the final mesh. - \param set List of element-sets per mesh. - \return Combined element-set on the stitched 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; + 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 diff --git a/include/GooseFEM/Mesh.hpp b/include/GooseFEM/Mesh.hpp index b04dbc4..771d7e7 100644 --- a/include/GooseFEM/Mesh.hpp +++ b/include/GooseFEM/Mesh.hpp @@ -1,556 +1,610 @@ /** Implementation of Mesh.h \file Mesh.hpp \copyright Copyright 2017. Tom de Geus. All rights reserved. \license This project is released under the GNU Public License (GPLv3). */ #ifndef GOOSEFEM_MESH_HPP #define GOOSEFEM_MESH_HPP #include "Mesh.h" namespace GooseFEM { namespace Mesh { inline ElementType defaultElementType( const xt::xtensor& coor, const xt::xtensor& conn) { if (coor.shape(1) == 2ul && conn.shape(1) == 3ul) { return ElementType::Tri3; } if (coor.shape(1) == 2ul && conn.shape(1) == 4ul) { return ElementType::Quad4; } if (coor.shape(1) == 3ul && conn.shape(1) == 8ul) { return ElementType::Hex8; } throw std::runtime_error("Element-type not implemented"); } namespace detail { template inline T renum(const T& arg, const R& mapping) { T ret = T::from_shape(arg.shape()); auto jt = ret.begin(); for (auto it = arg.begin(); it != arg.end(); ++it, ++jt) { *jt = mapping(*it); } return ret; } } // namespace detail inline xt::xtensor overlapping( const xt::xtensor& coor_a, const xt::xtensor& coor_b, double rtol, double atol) { GOOSEFEM_ASSERT(coor_a.shape(1) == coor_b.shape(1)); std::vector ret_a; std::vector ret_b; for (size_t i = 0; i < coor_a.shape(0); ++i) { auto idx = xt::flatten_indices(xt::argwhere(xt::prod(xt::isclose( coor_b, xt::view(coor_a, i, xt::all()), rtol, atol), 1))); for (auto& j : idx) { ret_a.push_back(i); ret_b.push_back(j); } } xt::xtensor ret = xt::empty({size_t(2), ret_a.size()}); for (size_t i = 0; i < ret_a.size(); ++i) { ret(0, i) = ret_a[i]; ret(1, i) = ret_b[i]; } return ret; } inline ManualStitch::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, double rtol, double atol) { UNUSED(rtol); UNUSED(atol); GOOSEFEM_ASSERT(xt::has_shape(overlapping_nodes_a, overlapping_nodes_b.shape())); GOOSEFEM_ASSERT(coor_a.shape(1) == coor_b.shape(1)); GOOSEFEM_ASSERT(conn_a.shape(1) == conn_b.shape(1)); if (check_position) { GOOSEFEM_ASSERT(xt::allclose( xt::view(coor_a, xt::keep(overlapping_nodes_a), xt::all()), xt::view(coor_b, xt::keep(overlapping_nodes_b), xt::all()), rtol, atol)); } size_t nnda = coor_a.shape(0); size_t nndb = coor_b.shape(0); size_t ndim = coor_a.shape(1); size_t nelim = overlapping_nodes_a.size(); size_t nela = conn_a.shape(0); size_t nelb = conn_b.shape(0); size_t nne = conn_a.shape(1); m_nel_a = nela; m_nel_b = nelb; m_nnd_a = nnda; xt::xtensor keep_b = xt::setdiff1d(xt::arange(nndb), overlapping_nodes_b); m_map_b = xt::empty({nndb}); xt::view(m_map_b, xt::keep(overlapping_nodes_b)) = overlapping_nodes_a; xt::view(m_map_b, xt::keep(keep_b)) = xt::arange(keep_b.size()) + nnda; m_conn = xt::empty({nela + nelb, nne}); xt::view(m_conn, xt::range(0, nela), xt::all()) = conn_a; xt::view(m_conn, xt::range(nela, nela + nelb), xt::all()) = detail::renum(conn_b, m_map_b); m_coor = xt::empty({nnda + nndb - nelim, ndim}); xt::view(m_coor, xt::range(0, nnda), xt::all()) = coor_a; xt::view(m_coor, xt::range(nnda, nnda + nndb - nelim), xt::all()) = xt::view(coor_b, xt::keep(keep_b), xt::all()); } inline xt::xtensor ManualStitch::coor() const { return m_coor; } inline xt::xtensor ManualStitch::conn() const { return m_conn; } +inline size_t ManualStitch::nelem() const +{ + return m_conn.shape(0); +} + +inline size_t ManualStitch::nnode() const +{ + return m_coor.shape(0); +} + +inline size_t ManualStitch::nne() const +{ + return m_conn.shape(1); +} + +inline size_t ManualStitch::ndim() const +{ + return m_coor.shape(1); +} + +inline xt::xtensor ManualStitch::dofs() const +{ + size_t nnode = this->nnode(); + size_t ndim = this->ndim(); + return xt::reshape_view(xt::arange(nnode * ndim), {nnode, ndim}); +} + inline xt::xtensor ManualStitch::nodemap(size_t mesh_index) const { GOOSEFEM_ASSERT(mesh_index <= 1); if (mesh_index == 0) { return xt::arange(m_nnd_a); } return m_map_b; } inline xt::xtensor ManualStitch::elemmap(size_t mesh_index) const { GOOSEFEM_ASSERT(mesh_index <= 1); if (mesh_index == 0) { return xt::arange(m_nel_a); } return xt::arange(m_nel_b) + m_nel_a; } inline xt::xtensor ManualStitch::nodeset(const xt::xtensor& set, size_t mesh_index) const { GOOSEFEM_ASSERT(mesh_index <= 1); if (mesh_index == 0) { GOOSEFEM_ASSERT(xt::amax(set)() < m_nnd_a); return set; } GOOSEFEM_ASSERT(xt::amax(set)() < m_map_b.size()); return detail::renum(set, m_map_b); } inline xt::xtensor ManualStitch::elemset(const xt::xtensor& set, size_t mesh_index) const { GOOSEFEM_ASSERT(mesh_index <= 1); if (mesh_index == 0) { GOOSEFEM_ASSERT(xt::amax(set)() < m_nel_a); return set; } GOOSEFEM_ASSERT(xt::amax(set)() < m_nel_b); return set + m_nel_a; } inline Stitch::Stitch(double rtol, double atol) { m_rtol = rtol; m_atol = atol; } inline void Stitch::push_back( const xt::xtensor& coor, const xt::xtensor& conn) { if (m_map.size() == 0) { m_coor = coor; m_conn = conn; m_map.push_back(xt::eval(xt::arange(coor.shape(0)))); m_nel.push_back(conn.shape(0)); m_el_offset.push_back(0); return; } auto overlap = overlapping(m_coor, coor, m_rtol, m_atol); size_t index = m_map.size(); ManualStitch stich( m_coor, m_conn, xt::view(overlap, 0, xt::all()), coor, conn, xt::view(overlap, 1, xt::all()), false); m_coor = stich.coor(); m_conn = stich.conn(); m_map.push_back(stich.nodemap(1)); m_nel.push_back(conn.shape(0)); m_el_offset.push_back(m_el_offset[index - 1] + m_nel[index - 1]); } inline xt::xtensor Stitch::coor() const { return m_coor; } inline xt::xtensor Stitch::conn() const { return m_conn; } +inline size_t Stitch::nelem() const +{ + return m_conn.shape(0); +} + +inline size_t Stitch::nnode() const +{ + return m_coor.shape(0); +} + +inline size_t Stitch::nne() const +{ + return m_conn.shape(1); +} + +inline size_t Stitch::ndim() const +{ + return m_coor.shape(1); +} + +inline xt::xtensor Stitch::dofs() const +{ + size_t nnode = this->nnode(); + size_t ndim = this->ndim(); + return xt::reshape_view(xt::arange(nnode * ndim), {nnode, ndim}); +} + inline xt::xtensor Stitch::nodemap(size_t mesh_index) const { GOOSEFEM_ASSERT(mesh_index < m_map.size()); return m_map[mesh_index]; } inline xt::xtensor Stitch::elemmap(size_t mesh_index) const { GOOSEFEM_ASSERT(mesh_index < m_map.size()); return xt::arange(m_nel[mesh_index]) + m_el_offset[mesh_index]; } inline xt::xtensor Stitch::nodeset(const xt::xtensor& set, size_t mesh_index) const { GOOSEFEM_ASSERT(mesh_index < m_map.size()); GOOSEFEM_ASSERT(xt::amax(set)() < m_map[mesh_index].size()); return detail::renum(set, m_map[mesh_index]); } inline xt::xtensor Stitch::elemset(const xt::xtensor& set, size_t mesh_index) const { GOOSEFEM_ASSERT(mesh_index < m_map.size()); GOOSEFEM_ASSERT(xt::amax(set)() < m_nel[mesh_index]); return set + m_el_offset[mesh_index]; } inline xt::xtensor Stitch::nodeset(const std::vector>& set) const { GOOSEFEM_ASSERT(set.size() == m_map.size()); size_t n = 0; for (size_t i = 0; i < set.size(); ++i) { n += set[i].size(); } xt::xtensor ret = xt::empty({n}); n = 0; for (size_t i = 0; i < set.size(); ++i) { xt::view(ret, xt::range(n, n + set[i].size())) = this->nodeset(set[i], i); n += set[i].size(); } return xt::unique(ret); } inline xt::xtensor Stitch::elemset(const std::vector>& set) const { GOOSEFEM_ASSERT(set.size() == m_map.size()); size_t n = 0; for (size_t i = 0; i < set.size(); ++i) { n += set[i].size(); } xt::xtensor ret = xt::empty({n}); n = 0; for (size_t i = 0; i < set.size(); ++i) { xt::view(ret, xt::range(n, n + set[i].size())) = this->elemset(set[i], i); n += set[i].size(); } return ret; } template inline Renumber::Renumber(const T& dofs) { size_t n = xt::amax(dofs)() + 1; size_t i = 0; xt::xtensor unique = xt::unique(dofs); m_renum = xt::empty({n}); for (auto& j : unique) { m_renum(j) = i; ++i; } } inline xt::xtensor Renumber::get(const xt::xtensor& dofs) const { GOOSEFEM_WARNING("Renumber::get is deprecated, use Renumber::apply"); return this->apply(dofs); } template inline T Renumber::apply(const T& list) const { return detail::renum(list, m_renum); } inline xt::xtensor Renumber::index() const { return m_renum; } inline xt::xtensor renumber(const xt::xtensor& dofs) { return Renumber(dofs).apply(dofs); } inline Reorder::Reorder(const std::initializer_list> args) { size_t n = 0; size_t i = 0; for (auto& arg : args) { if (arg.size() == 0) { continue; } n = std::max(n, xt::amax(arg)() + 1); } #ifdef GOOSEFEM_ENABLE_ASSERT for (auto& arg : args) { GOOSEFEM_ASSERT(xt::unique(arg) == xt::sort(arg)); } #endif m_renum = xt::empty({n}); for (auto& arg : args) { for (auto& j : arg) { m_renum(j) = i; ++i; } } } inline xt::xtensor Reorder::get(const xt::xtensor& dofs) const { GOOSEFEM_WARNING("Reorder::get is deprecated, use Reorder::apply"); return this->apply(dofs); } template inline T Reorder::apply(const T& list) const { T ret = T::from_shape(list.shape()); auto jt = ret.begin(); for (auto it = list.begin(); it != list.end(); ++it, ++jt) { *jt = m_renum(*it); } return ret; } inline xt::xtensor Reorder::index() const { return m_renum; } inline xt::xtensor dofs(size_t nnode, size_t ndim) { return xt::reshape_view(xt::arange(nnode * ndim), {nnode, ndim}); } inline xt::xtensor coordination(const xt::xtensor& conn) { size_t nnode = xt::amax(conn)() + 1; xt::xtensor N = xt::zeros({nnode}); for (auto it = conn.begin(); it != conn.end(); ++it) { N(*it) += 1; } return N; } inline std::vector> elem2node(const xt::xtensor& conn, bool sorted) { auto N = coordination(conn); auto nnode = N.size(); std::vector> ret(nnode); for (size_t i = 0; i < nnode; ++i) { ret[i].reserve(N(i)); } for (size_t e = 0; e < conn.shape(0); ++e) { for (size_t m = 0; m < conn.shape(1); ++m) { ret[conn(e, m)].push_back(e); } } if (sorted) { for (auto& row : ret) { std::sort(row.begin(), row.end()); } } return ret; } inline xt::xtensor edgesize( const xt::xtensor& coor, const xt::xtensor& conn, ElementType type) { GOOSEFEM_ASSERT(xt::amax(conn)() < coor.shape(0)); if (type == ElementType::Quad4) { GOOSEFEM_ASSERT(coor.shape(1) == 2ul); GOOSEFEM_ASSERT(conn.shape(1) == 4ul); xt::xtensor n0 = xt::view(conn, xt::all(), 0); xt::xtensor n1 = xt::view(conn, xt::all(), 1); xt::xtensor n2 = xt::view(conn, xt::all(), 2); xt::xtensor n3 = xt::view(conn, xt::all(), 3); xt::xtensor x0 = xt::view(coor, xt::keep(n0), 0); xt::xtensor x1 = xt::view(coor, xt::keep(n1), 0); xt::xtensor x2 = xt::view(coor, xt::keep(n2), 0); xt::xtensor x3 = xt::view(coor, xt::keep(n3), 0); xt::xtensor y0 = xt::view(coor, xt::keep(n0), 1); xt::xtensor y1 = xt::view(coor, xt::keep(n1), 1); xt::xtensor y2 = xt::view(coor, xt::keep(n2), 1); xt::xtensor y3 = xt::view(coor, xt::keep(n3), 1); xt::xtensor ret = xt::empty(conn.shape()); xt::view(ret, xt::all(), 0) = xt::sqrt(xt::pow(x1 - x0, 2.0) + xt::pow(y1 - y0, 2.0)); xt::view(ret, xt::all(), 1) = xt::sqrt(xt::pow(x2 - x1, 2.0) + xt::pow(y2 - y1, 2.0)); xt::view(ret, xt::all(), 2) = xt::sqrt(xt::pow(x3 - x2, 2.0) + xt::pow(y3 - y2, 2.0)); xt::view(ret, xt::all(), 3) = xt::sqrt(xt::pow(x0 - x3, 2.0) + xt::pow(y0 - y3, 2.0)); return ret; } throw std::runtime_error("Element-type not implemented"); } inline xt::xtensor edgesize( const xt::xtensor& coor, const xt::xtensor& conn) { return edgesize(coor, conn, defaultElementType(coor, conn)); } inline xt::xtensor centers( const xt::xtensor& coor, const xt::xtensor& conn, ElementType type) { GOOSEFEM_ASSERT(xt::amax(conn)() < coor.shape(0)); xt::xtensor ret = xt::zeros({conn.shape(0), coor.shape(1)}); if (type == ElementType::Quad4) { GOOSEFEM_ASSERT(coor.shape(1) == 2); GOOSEFEM_ASSERT(conn.shape(1) == 4); for (size_t i = 0; i < 4; ++i) { auto n = xt::view(conn, xt::all(), i); ret += xt::view(coor, xt::keep(n), xt::all()); } ret /= 4.0; return ret; } throw std::runtime_error("Element-type not implemented"); } inline xt::xtensor centers( const xt::xtensor& coor, const xt::xtensor& conn) { return centers(coor, conn, defaultElementType(coor, conn)); } inline xt::xtensor elemmap2nodemap( const xt::xtensor& elem_map, const xt::xtensor& coor, const xt::xtensor& conn, ElementType type) { GOOSEFEM_ASSERT(xt::amax(conn)() < coor.shape(0)); GOOSEFEM_ASSERT(elem_map.size() == conn.shape(0)); size_t N = coor.shape(0); xt::xtensor ret = N * xt::ones({N}); if (type == ElementType::Quad4) { GOOSEFEM_ASSERT(coor.shape(1) == 2); GOOSEFEM_ASSERT(conn.shape(1) == 4); for (size_t i = 0; i < 4; ++i) { xt::xtensor t = N * xt::ones({N}); auto old_nd = xt::view(conn, xt::all(), i); auto new_nd = xt::view(conn, xt::keep(elem_map), i); xt::view(t, xt::keep(old_nd)) = new_nd; ret = xt::where(xt::equal(ret, N), t, ret); } return ret; } throw std::runtime_error("Element-type not implemented"); } inline xt::xtensor elemmap2nodemap( const xt::xtensor& elem_map, const xt::xtensor& coor, const xt::xtensor& conn) { return elemmap2nodemap(elem_map, coor, conn, defaultElementType(coor, conn)); } } // namespace Mesh } // namespace GooseFEM #endif diff --git a/include/GooseFEM/MeshQuad4.h b/include/GooseFEM/MeshQuad4.h index 3c4e2c7..7c5421d 100644 --- a/include/GooseFEM/MeshQuad4.h +++ b/include/GooseFEM/MeshQuad4.h @@ -1,582 +1,626 @@ /** Generate simple meshes of 4-noded quadrilateral elements in 2d (GooseFEM::Mesh::ElementType::Quad4). \file MeshQuad4.h \copyright Copyright 2017. Tom de Geus. All rights reserved. \license This project is released under the GNU Public License (GPLv3). */ #ifndef GOOSEFEM_MESHQUAD4_H #define GOOSEFEM_MESHQUAD4_H #include "config.h" namespace GooseFEM { namespace Mesh { namespace Quad4 { // pre-allocation namespace Map { class FineLayer2Regular; } /** Regular mesh: equi-sized elements. */ class Regular { public: Regular() = default; /** Constructor. \param nelx Number of elements in horizontal (x) direction. \param nely Number of elements in vertical (y) direction. \param h Edge size (width == height). */ Regular(size_t nelx, size_t nely, double h = 1.0); /** Number of elements. \return unsigned int. */ size_t nelem() const; /** Number of nodes. \return unsigned int. */ size_t nnode() const; /** Number of nodes-per-element. \return unsigned int. */ size_t nne() const; /** Number of dimensions. \return unsigned int. */ size_t ndim() const; /** Number of elements in x-direction == width of the mesh in units of #h. \return unsigned int. */ size_t nelx() const; /** Number of elements in y-direction == height of the mesh, in units of #h, \return unsigned int. */ size_t nely() const; /** Edge size of one element. \return double. */ double h() const; /** Element type. \return GooseFEM::Mesh::ElementType(). */ ElementType getElementType() const; /** Nodal coordinates. \return [#nnode, #ndim]. */ xt::xtensor coor() const; /** Connectivity. \return [#nelem, #nne]. */ xt::xtensor conn() const; - // boundary nodes: edges + /** + Nodes along the bottom edge (y = 0). + + \return List of node numbers. + */ xt::xtensor nodesBottomEdge() const; + + /** + Nodes along the top edge (y = #nely * #h). + + \return List of node numbers. + */ xt::xtensor nodesTopEdge() const; + + /** + Nodes along the left edge (x = 0). + + \return List of node numbers. + */ xt::xtensor nodesLeftEdge() const; + + /** + Nodes along the right edge (x = #nelx * #h). + + \return List of node numbers. + */ xt::xtensor nodesRightEdge() const; - // boundary nodes: edges, without corners + /** + Nodes along the bottom edge (y = 0), with the corners (at x = 0 and x = #nelx * #h). + + \return List of node numbers. + */ xt::xtensor nodesBottomOpenEdge() const; + + /** + Nodes along the top edge (y = #nely * #h), with the corners (at x = 0 and x = #nelx * #h). + + \return List of node numbers. + */ xt::xtensor nodesTopOpenEdge() const; + + /** + Nodes along the left edge (x = 0), with the corners (at y = 0 and y = #nely * #h). + + \return List of node numbers. + */ xt::xtensor nodesLeftOpenEdge() const; + + /** + Nodes along the right edge (x = #nelx * #h), with the corners (at y = 0 and y = #nely * #h). + + \return List of node numbers. + */ xt::xtensor nodesRightOpenEdge() const; // boundary nodes: corners (including aliases) size_t nodesBottomLeftCorner() const; size_t nodesBottomRightCorner() const; size_t nodesTopLeftCorner() const; size_t nodesTopRightCorner() const; size_t nodesLeftBottomCorner() const; size_t nodesLeftTopCorner() const; size_t nodesRightBottomCorner() const; size_t nodesRightTopCorner() const; // DOF-numbers for each component of each node (sequential) xt::xtensor dofs() const; // DOF-numbers for the case that the periodicity if fully eliminated xt::xtensor dofsPeriodic() const; // periodic node pairs [:,2]: (independent, dependent) xt::xtensor nodesPeriodic() const; // front-bottom-left node, used as reference for periodicity size_t nodesOrigin() const; // element numbers as matrix xt::xtensor elementgrid() const; private: double m_h; // elementary element edge-size (in all directions) size_t m_nelx; // number of elements in x-direction (length == "m_nelx * m_h") size_t m_nely; // number of elements in y-direction (length == "m_nely * m_h") size_t m_nelem; // number of elements size_t m_nnode; // number of nodes static const size_t m_nne = 4; // number of nodes-per-element static const size_t m_ndim = 2; // number of dimensions }; // Mesh with fine middle layer, and coarser elements towards the top and bottom class FineLayer { public: FineLayer() = default; FineLayer(size_t nelx, size_t nely, double h = 1.0, size_t nfine = 1); /** Reconstruct class for given coordinates / connectivity. \param coor Nodal coordinates ``[nnode, ndim]`` with ``ndim == 2``. \param conn Connectivity ``[nne, nne]`` with ``nne == 4``. \throw GOOSEFEM_CHECK() */ FineLayer(const xt::xtensor& coor, const xt::xtensor& conn); /** Number of elements. \return unsigned int. */ size_t nelem() const; /** Number of nodes. \return unsigned int. */ size_t nnode() const; /** Number of nodes-per-element. \return unsigned int. */ size_t nne() const; /** Number of dimensions. \return unsigned int. */ size_t ndim() const; /** Number of elements in x-direction along the middle layer. By definition equal to the width of the mesh in units of #h. \return unsigned int. */ size_t nelx() const; /** Height of the mesh, in units of #h. \return unsigned int. */ size_t nely() const; /** Edge size of the smallest elements (along the middle layer). \return double. */ double h() const; /** Edge size in x-direction of a block, in units of #h, per row of blocks. Note that a block is equal to an element except in refinement layers where it contains three elements. \returns List of size equal to the number of rows of blocks. */ xt::xtensor elemrow_nhx() const; /** Edge size in y-direction of a block, in units of #h, per row of blocks. Note that a block is equal to an element except in refinement layers where it contains three elements. \returns List of size equal to the number of rows of blocks. */ xt::xtensor elemrow_nhy() const; /** Number of elements per row of blocks. Note that a block is equal to an element except in refinement layers where it contains three elements. \returns List of size equal to the number of rows of blocks. */ xt::xtensor elemrow_nelem() const; /** Element type. \return GooseFEM::Mesh::ElementType(). */ ElementType getElementType() const; /** Nodal coordinates. \return ``[nnode, ndim]``. */ xt::xtensor coor() const; /** Connectivity. \return ``[nelem, nne]``. */ xt::xtensor conn() const; // elements in the middle (fine) layer xt::xtensor elementsMiddleLayer() const; // extract elements along a layer xt::xtensor elementsLayer(size_t layer) const; // select region of elements from 'matrix' of element numbers xt::xtensor elementgrid_ravel( std::vector rows_start_stop, std::vector cols_start_stop) const; /** Select region of elements from 'matrix' of element numbers around an element: square box with edge-size ``(2 * size + 1) * h``, around ``element``. \param element The element around which to select elements. \param size Edge size of the square box encapsulating the selected element. \param periodic Assume the mesh periodic. \returns List of elements. */ xt::xtensor elementgrid_around_ravel( size_t element, size_t size, bool periodic = true); /** Select region of elements from 'matrix' of element numbers around an element: left/right from ``element`` (on the same layer). \param element The element around which to select elements. \param left Number of elements to select to the left. \param right Number of elements to select to the right. \param periodic Assume the mesh periodic. \returns List of elements. */ // - xt::xtensor elementgrid_leftright( size_t element, size_t left, size_t right, bool periodic = true); // boundary nodes: edges xt::xtensor nodesBottomEdge() const; xt::xtensor nodesTopEdge() const; xt::xtensor nodesLeftEdge() const; xt::xtensor nodesRightEdge() const; // boundary nodes: edges, without corners xt::xtensor nodesBottomOpenEdge() const; xt::xtensor nodesTopOpenEdge() const; xt::xtensor nodesLeftOpenEdge() const; xt::xtensor nodesRightOpenEdge() const; // boundary nodes: corners (including aliases) size_t nodesBottomLeftCorner() const; size_t nodesBottomRightCorner() const; size_t nodesTopLeftCorner() const; size_t nodesTopRightCorner() const; size_t nodesLeftBottomCorner() const; size_t nodesLeftTopCorner() const; size_t nodesRightBottomCorner() const; size_t nodesRightTopCorner() const; // DOF-numbers for each component of each node (sequential) xt::xtensor dofs() const; // DOF-numbers for the case that the periodicity if fully eliminated xt::xtensor dofsPeriodic() const; // periodic node pairs [:,2]: (independent, dependent) xt::xtensor nodesPeriodic() const; // front-bottom-left node, used as reference for periodicity size_t nodesOrigin() const; // mapping to 'roll' periodically in the x-direction, // returns element mapping, such that: new_elemvar = elemvar[elem_map] xt::xtensor roll(size_t n); private: double m_h; // elementary element edge-size (in all directions) double m_Lx; // mesh size in "x" size_t m_nelem; // number of elements size_t m_nnode; // number of nodes static const size_t m_nne = 4; // number of nodes-per-element static const size_t m_ndim = 2; // number of dimensions xt::xtensor m_nelx; ///< See elemrow_nelem(). xt::xtensor m_nhx; ///< See elemrow_nhx(). xt::xtensor m_nhy; ///< See elemrow_nhy(). xt::xtensor m_nnd; // total number of nodes in the main node layer (**) xt::xtensor m_refine; // refine direction (-1:no refine, 0:"x" (*) xt::xtensor m_startElem; // start element (*) xt::xtensor m_startNode; // start node (**) // (*) per element layer in "y" // (**) per node layer in "y" void init(size_t nelx, size_t nely, double h, size_t nfine = 1); void map(const xt::xtensor& coor, const xt::xtensor& conn); friend class GooseFEM::Mesh::Quad4::Map::FineLayer2Regular; }; // Mesh mappings namespace Map { // Return "FineLayer"-class responsible for generating a connectivity // Throws if conversion is not possible [[ deprecated ]] GooseFEM::Mesh::Quad4::FineLayer FineLayer( const xt::xtensor& coor, const xt::xtensor& conn); /** Refine a Regular mesh: subdivide elements in several smaller elements. */ class RefineRegular { public: RefineRegular() = default; /** Constructor. \param mesh the coarse mesh. \param nx for each coarse element: number of fine elements in x-direction. \param ny for each coarse element: number of fine elements in y-direction. */ RefineRegular(const GooseFEM::Mesh::Quad4::Regular& mesh, size_t nx, size_t ny); /** For each coarse element: number of fine elements in x-direction. \return unsigned int (same as used in constructor) */ size_t nx() const; /** For each coarse element: number of fine elements in y-direction. \return unsigned int (same as used in constructor) */ size_t ny() const; /** Obtain the coarse mesh (copy of the mesh passed to the constructor). \return mesh */ GooseFEM::Mesh::Quad4::Regular getCoarseMesh() const; /** Obtain the fine mesh. \return mesh */ GooseFEM::Mesh::Quad4::Regular getFineMesh() const; /** Get element-mapping: elements of the fine mesh per element of the coarse mesh. \return [nelem_coarse, nx() * ny()] */ xt::xtensor getMap() const; // map field [[ deprecated ]] xt::xtensor mapToCoarse(const xt::xtensor& data) const; // scalar per el [[ deprecated ]] xt::xtensor mapToCoarse(const xt::xtensor& data) const; // scalar per intpnt [[ deprecated ]] xt::xtensor mapToCoarse(const xt::xtensor& data) const; // tensor per intpnt /** Compute the mean of the quantity define on the fine mesh when mapped on the coarse mesh. \tparam T type of the data (e.g. ``double``). \tparam rank rank of the data. \param data the data [nelem_fine, ...] \return the average data of the coarse mesh [nelem_coarse, ...] */ template xt::xtensor meanToCoarse(const xt::xtensor& data) const; /** Compute the average of the quantity define on the fine mesh when mapped on the coarse mesh. \tparam T type of the data (e.g. ``double``). \tparam rank rank of the data. \tparam S type of the weights (e.g. ``double``). \param data the data [nelem_fine, ...] \param weights the weights [nelem_fine, ...] \return the average data of the coarse mesh [nelem_coarse, ...] */ template xt::xtensor averageToCoarse( const xt::xtensor& data, const xt::xtensor& weights) const; /** Map element quantities to the fine mesh. The mapping is a bit simplistic: no interpolation is involved. The mapping is such that:: ret[e_fine, ...] <- data[e_coarse, ...] \tparam T type of the data (e.g. ``double``). \tparam rank rank of the data. \param data the data. \return mapped data. */ template xt::xtensor mapToFine(const xt::xtensor& data) const; private: GooseFEM::Mesh::Quad4::Regular m_coarse; ///< the coarse mesh GooseFEM::Mesh::Quad4::Regular m_fine; ///< the fine mesh size_t m_nx; ///< see nx() size_t m_ny; ///< see ny() xt::xtensor m_coarse2fine; ///< see getMap() }; /** Map a FineLayer mesh to a Regular mesh. The element size of the Regular corresponds to the smallest elements of the FineLayer mesh (along the middle layer). */ class FineLayer2Regular { public: FineLayer2Regular() = default; /** Constructors. \param mesh The FineLayer mesh. */ FineLayer2Regular(const GooseFEM::Mesh::Quad4::FineLayer& mesh); /** Obtain the Regular mesh. \return mesh. */ GooseFEM::Mesh::Quad4::Regular getRegularMesh() const; /** Obtain the FineLayer mesh (copy of the mesh passed to the constructor). \return mesh. */ GooseFEM::Mesh::Quad4::FineLayer getFineLayerMesh() const; // elements of the Regular mesh per element of the FineLayer mesh // and the fraction by which the overlap is /** Get element-mapping: elements of the Regular mesh per element of the FineLayer mesh. The number of Regular elements varies between elements of the FineLayer mesh. \return [nelem_finelayer, ?] */ std::vector> getMap() const; /** To overlap fraction for each item in the mapping in getMap(). \return [nelem_finelayer, ?] */ std::vector> getMapFraction() const; /** Map element quantities to Regular. The mapping is a bit simplistic: no interpolation is involved, the function just accounts the fraction of overlap between the FineLayer element and the Regular element. The mapping is such that:: ret[e_regular, ...] <- arg[e_finelayer, ...] \tparam T type of the data (e.g. ``double``). \tparam rank rank of the data. \param arg data. \return mapped data. */ template xt::xtensor mapToRegular(const xt::xtensor& arg) const; private: GooseFEM::Mesh::Quad4::FineLayer m_finelayer; ///< the FineLayer mesh to map GooseFEM::Mesh::Quad4::Regular m_regular; ///< the new Regular mesh to which to map std::vector> m_elem_regular; ///< see getMap() std::vector> m_frac_regular; ///< see getMapFraction() }; } // namespace Map } // namespace Quad4 } // namespace Mesh } // namespace GooseFEM #include "MeshQuad4.hpp" #endif diff --git a/python/Mesh.hpp b/python/Mesh.hpp index ef98be0..b693f5d 100644 --- a/python/Mesh.hpp +++ b/python/Mesh.hpp @@ -1,363 +1,394 @@ /* ================================================================================================= (c - GPLv3) T.W.J. de Geus (Tom) | tom@geus.me | www.geus.me | github.com/tdegeus/GooseFEM ================================================================================================= */ #include #include #include namespace py = pybind11; void init_Mesh(py::module& m) { py::enum_(m, "ElementType", "ElementType." "See :cpp:enum:`GooseFEM::Mesh::ElementType`.") .value("Tri3", GooseFEM::Mesh::ElementType::Tri3) .value("Quad4", GooseFEM::Mesh::ElementType::Quad4) .value("Hex8", GooseFEM::Mesh::ElementType::Hex8) .export_values(); m.def( "overlapping", &GooseFEM::Mesh::overlapping, "Find overlapping nodes." "See :cpp:func:`GooseFEM::Mesh::overlapping`.", py::arg("coor_a"), py::arg("coor_b"), py::arg("rtol") = 1e-5, py::arg("atol") = 1e-8); py::class_(m, "ManualStitch") - .def( - py::init< + .def(py::init< const xt::xtensor&, const xt::xtensor&, const xt::xtensor&, const xt::xtensor&, const xt::xtensor&, const xt::xtensor&, bool, double, double>(), - "Manually stitch meshes." - "See :cpp:class:`GooseFEM::Mesh::ManualStitch`.", - py::arg("coor_a"), - py::arg("conn_a"), - py::arg("overlapping_nodes_a"), - py::arg("coor_b"), - py::arg("conn_b"), - py::arg("overlapping_nodes_b"), - py::arg("check_position") = true, - py::arg("rtol") = 1e-5, - py::arg("atol") = 1e-8) - - .def( - "coor", - &GooseFEM::Mesh::ManualStitch::coor, - "Coordinates of stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::ManualStitch::coor`.") - - .def( - "conn", - &GooseFEM::Mesh::ManualStitch::conn, - "Connectivity of stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::ManualStitch::conn`.") - - .def( - "nodemap", - &GooseFEM::Mesh::ManualStitch::nodemap, - "Map to new node-numbers." - "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nodemap`.") - - .def( - "elemmap", - &GooseFEM::Mesh::ManualStitch::elemmap, - "Map to new element-numbers." - "See :cpp:func:`GooseFEM::Mesh::ManualStitch::elemmap`.") - - .def( - "nodeset", - &GooseFEM::Mesh::ManualStitch::nodeset, - "Convert node-set to the stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nodeset`.", - py::arg("set"), - py::arg("mesh_index")) - - .def( - "elemset", - &GooseFEM::Mesh::ManualStitch::elemset, - "Convert element-set to the stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::ManualStitch::elemset`.", - py::arg("set"), - py::arg("mesh_index")) - - .def( - "__repr__", [](const GooseFEM::Mesh::ManualStitch&) { - return ""; }); + "Manually stitch meshes." + "See :cpp:class:`GooseFEM::Mesh::ManualStitch`.", + py::arg("coor_a"), + py::arg("conn_a"), + py::arg("overlapping_nodes_a"), + py::arg("coor_b"), + py::arg("conn_b"), + py::arg("overlapping_nodes_b"), + py::arg("check_position") = true, + py::arg("rtol") = 1e-5, + py::arg("atol") = 1e-8) + + .def("nnode", + &GooseFEM::Mesh::ManualStitch::nnode, + "Number of nodes of stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nnode`.") + + .def("nelem", + &GooseFEM::Mesh::ManualStitch::nelem, + "Number of elements of stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nelem`.") + + .def("ndim", + &GooseFEM::Mesh::ManualStitch::ndim, + "Number of dimensions (of stitched mesh)." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::ndim`.") + + .def("nne", + &GooseFEM::Mesh::ManualStitch::nne, + "Number of nodes per element (of stitched mesh)." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nne`.") + + .def("coor", + &GooseFEM::Mesh::ManualStitch::coor, + "Coordinates of stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::coor`.") + + .def("conn", + &GooseFEM::Mesh::ManualStitch::conn, + "Connectivity of stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::conn`.") + + .def("dofs", + &GooseFEM::Mesh::ManualStitch::dofs, + "DOF numbers per node." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::dofs`.") + + .def("nodemap", + &GooseFEM::Mesh::ManualStitch::nodemap, + "Map to new node-numbers." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nodemap`.") + + .def("elemmap", + &GooseFEM::Mesh::ManualStitch::elemmap, + "Map to new element-numbers." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::elemmap`.") + + .def("nodeset", + &GooseFEM::Mesh::ManualStitch::nodeset, + "Convert node-set to the stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nodeset`.", + py::arg("set"), + py::arg("mesh_index")) + + .def("elemset", + &GooseFEM::Mesh::ManualStitch::elemset, + "Convert element-set to the stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::ManualStitch::elemset`.", + py::arg("set"), + py::arg("mesh_index")) + + .def("__repr__", + [](const GooseFEM::Mesh::ManualStitch&) { return ""; }); py::class_(m, "Stitch") - .def( - py::init(), - "Stitch meshes." - "See :cpp:class:`GooseFEM::Mesh::Stitch`.", - py::arg("rtol") = 1e-5, - py::arg("atol") = 1e-8) - - .def( - "push_back", - &GooseFEM::Mesh::Stitch::push_back, - "Add mesh to be stitched." - "See :cpp:func:`GooseFEM::Mesh::Stitch::push_back`.", - py::arg("coor"), - py::arg("conn")) - - .def( - "coor", - &GooseFEM::Mesh::Stitch::coor, - "Coordinates of stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::Stitch::coor`.") - - .def( - "conn", - &GooseFEM::Mesh::Stitch::conn, - "Connectivity of stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::Stitch::coor`.") - - .def( - "nodemap", - &GooseFEM::Mesh::Stitch::nodemap, - "Node-map for given mesh." - "See :cpp:func:`GooseFEM::Mesh::Stitch::nodemap`.", - py::arg("mesh_index")) - - .def( - "elemmap", - &GooseFEM::Mesh::Stitch::elemmap, - "Element-map for given mesh." - "See :cpp:func:`GooseFEM::Mesh::Stitch::elemmap`.", - py::arg("mesh_index")) - - .def( - "nodeset", - py::overload_cast&, size_t>( - &GooseFEM::Mesh::Stitch::nodeset, py::const_), - "Convert node-set to the stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::Stitch::nodeset`.", - py::arg("set"), - py::arg("mesh_index")) - - .def( - "elemset", - py::overload_cast&, size_t>( - &GooseFEM::Mesh::Stitch::elemset, py::const_), - "Convert element-set to the stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::Stitch::elemset`.", - py::arg("set"), - py::arg("mesh_index")) - - .def( - "nodeset", - py::overload_cast>&>( - &GooseFEM::Mesh::Stitch::nodeset, py::const_), - "Convert node-set to the stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::Stitch::nodeset`.", - py::arg("set")) - - .def( - "elemset", - py::overload_cast>&>( - &GooseFEM::Mesh::Stitch::elemset, py::const_), - "Convert element-set to the stitched mesh." - "See :cpp:func:`GooseFEM::Mesh::Stitch::elemset`.", - py::arg("set")) - - .def( - "__repr__", [](const GooseFEM::Mesh::Stitch&) { return ""; }); + .def(py::init(), + "Stitch meshes." + "See :cpp:class:`GooseFEM::Mesh::Stitch`.", + py::arg("rtol") = 1e-5, + py::arg("atol") = 1e-8) + + .def("push_back", + &GooseFEM::Mesh::Stitch::push_back, + "Add mesh to be stitched." + "See :cpp:func:`GooseFEM::Mesh::Stitch::push_back`.", + py::arg("coor"), + py::arg("conn")) + + .def("nnode", + &GooseFEM::Mesh::Stitch::nnode, + "Number of nodes of stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::nnode`.") + + .def("nelem", + &GooseFEM::Mesh::Stitch::nelem, + "Number of elements of stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::nelem`.") + + .def("ndim", + &GooseFEM::Mesh::Stitch::ndim, + "Number of dimensions (of stitched mesh)." + "See :cpp:func:`GooseFEM::Mesh::Stitch::ndim`.") + + .def("nne", + &GooseFEM::Mesh::Stitch::nne, + "Number of nodes per element (of stitched mesh)." + "See :cpp:func:`GooseFEM::Mesh::Stitch::nne`.") + + .def("coor", + &GooseFEM::Mesh::Stitch::coor, + "Coordinates of stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::coor`.") + + .def("conn", + &GooseFEM::Mesh::Stitch::conn, + "Connectivity of stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::conn`.") + + .def("dofs", + &GooseFEM::Mesh::Stitch::dofs, + "DOF numbers per node." + "See :cpp:func:`GooseFEM::Mesh::Stitch::dofs`.") + + .def("nodemap", + &GooseFEM::Mesh::Stitch::nodemap, + "Node-map for given mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::nodemap`.", + py::arg("mesh_index")) + + .def("elemmap", + &GooseFEM::Mesh::Stitch::elemmap, + "Element-map for given mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::elemmap`.", + py::arg("mesh_index")) + + .def("nodeset", + py::overload_cast&, size_t>( + &GooseFEM::Mesh::Stitch::nodeset, py::const_), + "Convert node-set to the stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::nodeset`.", + py::arg("set"), + py::arg("mesh_index")) + + .def("elemset", + py::overload_cast&, size_t>( + &GooseFEM::Mesh::Stitch::elemset, py::const_), + "Convert element-set to the stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::elemset`.", + py::arg("set"), + py::arg("mesh_index")) + + .def("nodeset", + py::overload_cast>&>( + &GooseFEM::Mesh::Stitch::nodeset, py::const_), + "Convert node-set to the stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::nodeset`.", + py::arg("set")) + + .def("elemset", + py::overload_cast>&>( + &GooseFEM::Mesh::Stitch::elemset, py::const_), + "Convert element-set to the stitched mesh." + "See :cpp:func:`GooseFEM::Mesh::Stitch::elemset`.", + py::arg("set")) + + .def("__repr__", [](const GooseFEM::Mesh::Stitch&) { return ""; }); py::class_(m, "Renumber") .def( py::init&>(), "Renumber to lowest possible index." "See :cpp:class:`GooseFEM::Mesh::Renumber`.", py::arg("dofs")) .def( "get", &GooseFEM::Mesh::Renumber::apply>, "Get renumbered DOFs." "See :cpp:func:`GooseFEM::Mesh::Renumber::get`.") .def( "apply", &GooseFEM::Mesh::Renumber::apply>, "Get renumbered list." "See :cpp:func:`GooseFEM::Mesh::Renumber::apply`.") .def( "index", &GooseFEM::Mesh::Renumber::index, "Get index list to apply renumbering. Apply renumbering using ``index[dofs]``." "See :cpp:func:`GooseFEM::Mesh::Renumber::index`.") .def( "__repr__", [](const GooseFEM::Mesh::Renumber&) { return ""; }); py::class_(m, "Reorder") .def( py::init([](xt::xtensor& a) { return new GooseFEM::Mesh::Reorder({a}); }), "Reorder to lowest possible index." "See :cpp:class:`GooseFEM::Mesh::Reorder`.") .def( py::init([](xt::xtensor& a, xt::xtensor& b) { return new GooseFEM::Mesh::Reorder({a, b}); }), "Reorder to lowest possible index." "See :cpp:class:`GooseFEM::Mesh::Reorder`.") .def( py::init( [](xt::xtensor& a, xt::xtensor& b, xt::xtensor& c) { return new GooseFEM::Mesh::Reorder({a, b, c}); }), "Reorder to lowest possible index." "See :cpp:class:`GooseFEM::Mesh::Reorder`.") .def( py::init([](xt::xtensor& a, xt::xtensor& b, xt::xtensor& c, xt::xtensor& d) { return new GooseFEM::Mesh::Reorder({a, b, c, d}); }), "Reorder to lowest possible index." "See :cpp:class:`GooseFEM::Mesh::Reorder`.") .def( "get", &GooseFEM::Mesh::Reorder::apply>, "Reorder matrix (e.g. ``dofs``)." "See :cpp:func:`GooseFEM::Mesh::Reorder::get`.", py::arg("dofs")) .def( "apply", &GooseFEM::Mesh::Reorder::apply>, "Get reordered list." "See :cpp:func:`GooseFEM::Mesh::Reorder::apply`.") .def( "index", &GooseFEM::Mesh::Reorder::index, "Get index list to apply renumbering. Apply renumbering using ``index[dofs]``." "See :cpp:func:`GooseFEM::Mesh::Reorder::index`.") .def("__repr__", [](const GooseFEM::Mesh::Reorder&) { return ""; }); m.def( "dofs", &GooseFEM::Mesh::dofs, "List with DOF-numbers in sequential order." "See :cpp:func:`GooseFEM::Mesh::dofs`.", py::arg("nnode"), py::arg("ndim")); m.def( "renumber", &GooseFEM::Mesh::renumber, "Renumber to lowest possible indices." "See :cpp:func:`GooseFEM::Mesh::renumber`.", py::arg("dofs")); m.def( "coordination", &GooseFEM::Mesh::coordination, "Coordination number of each node." "See :cpp:func:`GooseFEM::Mesh::coordination`.", py::arg("conn")); m.def( "elem2node", &GooseFEM::Mesh::elem2node, "Element-numbers connected to each node." "See :cpp:func:`GooseFEM::Mesh::elem2node`.", py::arg("conn"), py::arg("sorted") = true); m.def( "edgesize", py::overload_cast&, const xt::xtensor&>( &GooseFEM::Mesh::edgesize), "Get the edge size of all elements." "See :cpp:func:`GooseFEM::Mesh::edgesize`.", py::arg("coor"), py::arg("conn")); m.def( "edgesize", py::overload_cast< const xt::xtensor&, const xt::xtensor&, GooseFEM::Mesh::ElementType>(&GooseFEM::Mesh::edgesize), "Get the edge size of all elements." "See :cpp:func:`GooseFEM::Mesh::edgesize`.", py::arg("coor"), py::arg("conn"), py::arg("type")); m.def( "centers", py::overload_cast&, const xt::xtensor&>( &GooseFEM::Mesh::centers), "Coordinates of the center of each element." "See :cpp:func:`GooseFEM::Mesh::centers`.", py::arg("coor"), py::arg("conn")); m.def( "centers", py::overload_cast< const xt::xtensor&, const xt::xtensor&, GooseFEM::Mesh::ElementType>(&GooseFEM::Mesh::centers), "Coordinates of the center of each element." "See :cpp:func:`GooseFEM::Mesh::centers`.", py::arg("coor"), py::arg("conn"), py::arg("type")); m.def( "elemmap2nodemap", py::overload_cast< const xt::xtensor&, const xt::xtensor&, const xt::xtensor&>(&GooseFEM::Mesh::elemmap2nodemap), "Convert an element-map to a node-map." "See :cpp:func:`GooseFEM::Mesh::elemmap2nodemap`.", py::arg("elem_map"), py::arg("coor"), py::arg("conn")); m.def( "elemmap2nodemap", py::overload_cast< const xt::xtensor&, const xt::xtensor&, const xt::xtensor&, GooseFEM::Mesh::ElementType>(&GooseFEM::Mesh::elemmap2nodemap), "Convert an element-map to a node-map." "See :cpp:func:`GooseFEM::Mesh::elemmap2nodemap`.", py::arg("elem_map"), py::arg("coor"), py::arg("conn"), py::arg("type")); }