diff --git a/docs/install.rst b/docs/install.rst index 8353c41..4269129 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -1,171 +1,169 @@ **************** Getting GooseFEM **************** Using conda =========== The easiest is to use *conda* to install *GooseFEM*:: conda install -c conda-forge goosefem This will install all the necessary runtime dependencies as well. .. tip:: The runtime dependencies (for both the C++ and the Python APIs) are also listed in ``environment.yaml``. One could install those dependencies in an activated environment by:: conda env update --file environment.yaml This will install the dependencies to run tests and examples. From source =========== .. tip:: It could be instructive to see how configuration / compilation is done in the continuous integration: :download:`.github/workflows/ci.yml <../.github/workflows/ci.yml>` Download the package:: git checkout https://github.com/tdegeus/GooseFEM.git cd GooseFEM Install headers, *CMake* and *pkg-config* support: .. code-block:: none cmake -Bbuild cd build cmake --install . .. note:: The version is determined from the latest git tag, and possible commits since that tag. Internally Python's ``setuptools_scm`` is used to this end. In case that you are not working from a clone of the repository you have to set the version manually, **before** configuring with CMake: .. code-block:: none export SETUPTOOLS_SCM_PRETEND_VERSION="1.2.3" cmake -Bbuild cd build cmake --install . In Windows replace the first line with .. code-block:: none set SETUPTOOLS_SCM_PRETEND_VERSION="1.2.3" .. tip:: To install in a loaded conda environment use .. code-block:: none cmake -Bbuild -DCMAKE_INSTALL_PREFIX:PATH="${CONDA_PREFIX}" cd build cmake --install . .. _install_python: Python interface ================ .. tip:: It could be instructive to see how configuration / compilation is done in the continuous integration: :download:`.github/workflows/ci.yml <../.github/workflows/ci.yml>` Using conda ^^^^^^^^^^^ The quickest (but not the most efficient!) is to use *conda* to install *GooseFEM*:: conda install -c conda-forge python-goosefem .. warning:: This package does not benefit from *xsimd* optimisation, as it is not compiled on your hardware. You'll have to compile by hand to benefit from *xsimd* optimisation. .. _install_python_source: From source ^^^^^^^^^^^ Start by installing the dependencies, for example using *conda*:: conda install -c conda-forge xtensor-python eigen xsimd Note that *xsimd* is optional, but recommended. Then, download the package:: git checkout https://github.com/tdegeus/GooseFEM.git cd GooseFEM Install the package using:: python setup.py install --build-type Release -vv To use hardware optimisation (using *xsimd*) use instead:: python setup.py install --build-type Release -vv -DUSE_SIMD=1 .. _install_docs: Docs ==== C++ (Doxygen) ^^^^^^^^^^^^^ .. tip:: It could be instructive to see how configuration / compilation is done in the continuous integration: :download:`.github/workflows/gh-pages.yml <../.github/workflows/gh-pages.yml>` To build the docs there are two steps to be made: 1. Extract the code documentation using doxygen: .. code-block:: none cmake -Bbuild -DBUILD_DOCS=1 cd build make docs 2. Build the docs using sphinx: .. code-block:: none cd docs make html General / Python (Sphinx) ^^^^^^^^^^^^^^^^^^^^^^^^^ .. tip:: The dependencies are also listed in ``environment.yaml``. One could install those dependencies in an activated environment by:: conda env update --file environment.yaml Build the docs as follows:: cd docs make html - - diff --git a/include/GooseFEM/MatrixDiagonal.hpp b/include/GooseFEM/MatrixDiagonal.hpp index 27c21fa..7b6a3cd 100644 --- a/include/GooseFEM/MatrixDiagonal.hpp +++ b/include/GooseFEM/MatrixDiagonal.hpp @@ -1,182 +1,179 @@ /** Implementation of MatrixDiagonal.h \file MatrixDiagonal.hpp \copyright Copyright 2017. Tom de Geus. All rights reserved. \license This project is released under the GNU Public License (GPLv3). */ #ifndef GOOSEFEM_MATRIXDIAGONAL_HPP #define GOOSEFEM_MATRIXDIAGONAL_HPP #include "MatrixDiagonal.h" namespace GooseFEM { template -inline MatrixDiagonal::MatrixDiagonal( - const C& conn, - const D& dofs) - : m_conn(conn), m_dofs(dofs) +inline MatrixDiagonal::MatrixDiagonal(const C& conn, const D& dofs) : m_conn(conn), m_dofs(dofs) { m_nelem = m_conn.shape(0); m_nne = m_conn.shape(1); m_nnode = m_dofs.shape(0); m_ndim = m_dofs.shape(1); m_ndof = xt::amax(m_dofs)() + 1; m_A = xt::empty({m_ndof}); m_inv = xt::empty({m_ndof}); GOOSEFEM_ASSERT(xt::amax(m_conn)() + 1 <= m_nnode); GOOSEFEM_ASSERT(m_ndof <= m_nnode * m_ndim); } inline size_t MatrixDiagonal::nelem() const { return m_nelem; } inline size_t MatrixDiagonal::nne() const { return m_nne; } inline size_t MatrixDiagonal::nnode() const { return m_nnode; } inline size_t MatrixDiagonal::ndim() const { return m_ndim; } inline size_t MatrixDiagonal::ndof() const { return m_ndof; } inline xt::xtensor MatrixDiagonal::dofs() const { return m_dofs; } inline void MatrixDiagonal::factorize() { if (!m_changed) { return; } #pragma omp parallel for for (size_t d = 0; d < m_ndof; ++d) { m_inv(d) = 1.0 / m_A(d); } m_changed = false; } inline void MatrixDiagonal::set(const xt::xtensor& A) { GOOSEFEM_ASSERT(A.size() == m_ndof); std::copy(A.begin(), A.end(), m_A.begin()); m_changed = true; } inline void MatrixDiagonal::assemble(const xt::xtensor& elemmat) { GOOSEFEM_ASSERT(xt::has_shape(elemmat, {m_nelem, m_nne * m_ndim, m_nne * m_ndim})); GOOSEFEM_ASSERT(Element::isDiagonal(elemmat)); m_A.fill(0.0); for (size_t e = 0; e < m_nelem; ++e) { for (size_t m = 0; m < m_nne; ++m) { for (size_t i = 0; i < m_ndim; ++i) { m_A(m_dofs(m_conn(e, m), i)) += elemmat(e, m * m_ndim + i, m * m_ndim + i); } } } m_changed = true; } inline void MatrixDiagonal::dot(const xt::xtensor& x, xt::xtensor& b) const { GOOSEFEM_ASSERT(xt::has_shape(x, {m_nnode, m_ndim})); GOOSEFEM_ASSERT(xt::has_shape(b, {m_nnode, m_ndim})); #pragma omp parallel for for (size_t m = 0; m < m_nnode; ++m) { for (size_t i = 0; i < m_ndim; ++i) { b(m, i) = m_A(m_dofs(m, i)) * x(m, i); } } } inline void MatrixDiagonal::dot(const xt::xtensor& x, xt::xtensor& b) const { GOOSEFEM_ASSERT(x.size() == m_ndof); GOOSEFEM_ASSERT(b.size() == m_ndof); xt::noalias(b) = m_A * x; } inline void MatrixDiagonal::solve(const xt::xtensor& b, xt::xtensor& x) { GOOSEFEM_ASSERT(xt::has_shape(b, {m_nnode, m_ndim})); GOOSEFEM_ASSERT(xt::has_shape(x, {m_nnode, m_ndim})); this->factorize(); #pragma omp parallel for for (size_t m = 0; m < m_nnode; ++m) { for (size_t i = 0; i < m_ndim; ++i) { x(m, i) = m_inv(m_dofs(m, i)) * b(m, i); } } } inline void MatrixDiagonal::solve(const xt::xtensor& b, xt::xtensor& x) { GOOSEFEM_ASSERT(b.size() == m_ndof); GOOSEFEM_ASSERT(x.size() == m_ndof); this->factorize(); xt::noalias(x) = m_inv * b; } inline xt::xtensor MatrixDiagonal::Todiagonal() const { return m_A; } inline xt::xtensor MatrixDiagonal::Dot(const xt::xtensor& x) const { xt::xtensor b = xt::empty({m_nnode, m_ndim}); this->dot(x, b); return b; } inline xt::xtensor MatrixDiagonal::Dot(const xt::xtensor& x) const { xt::xtensor b = xt::empty({m_ndof}); this->dot(x, b); return b; } inline xt::xtensor MatrixDiagonal::Solve(const xt::xtensor& b) { xt::xtensor x = xt::empty({m_nnode, m_ndim}); this->solve(b, x); return x; } inline xt::xtensor MatrixDiagonal::Solve(const xt::xtensor& b) { xt::xtensor x = xt::empty({m_ndof}); this->solve(b, x); return x; } } // namespace GooseFEM #endif diff --git a/include/GooseFEM/Mesh.h b/include/GooseFEM/Mesh.h index 3a49073..138a087 100644 --- a/include/GooseFEM/Mesh.h +++ b/include/GooseFEM/Mesh.h @@ -1,1524 +1,1524 @@ /** 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" -#include "Vector.h" #include "MatrixDiagonal.h" +#include "Vector.h" +#include "config.h" namespace GooseFEM { /** Generic mesh operations, and simple mesh definitions. */ 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 [nnode, ndim]. \param conn Connectivity [nelem, nne]. \return ElementType(). */ template inline ElementType defaultElementType(const S& coor, const T& conn); /** CRTP base class for regular meshes. */ template class RegularBase { public: /** Underlying type. */ using derived_type = D; /** Number of elements. \return unsigned int */ auto nelem() const; /** Number of nodes. \return unsigned int */ auto nnode() const; /** Number of nodes-per-element == 4. \return unsigned int */ auto nne() const; /** Number of dimensions == 2. \return unsigned int */ auto ndim() const; /** Number of elements in x-direction == width of the mesh in units of #h. \return unsigned int */ auto nelx() const; /** Number of elements in y-direction == height of the mesh, in units of #h, \return unsigned int */ auto nely() const; /** Linear edge size of one 'block'. \return double */ auto h() const; /** The ElementType(). \return element type */ auto getElementType() const; /** Nodal coordinates [#nnode, #ndim]. \return coordinates per node */ auto coor() const; /** Connectivity [#nelem, #nne]. \return nodes per element */ auto conn() const; /** DOF numbers for each node (numbered sequentially) [#nnode, #ndim]. \return DOFs per node */ auto dofs() const; /** DOF-numbers for the case that the periodicity if fully eliminated. \return DOF numbers for each node [#nnode, #ndim]. */ auto dofsPeriodic() const; /** Periodic node pairs, in two columns: (independent, dependent). \return [ntyings, #ndim]. */ auto nodesPeriodic() const; /** Reference node to use for periodicity, because all corners are tied to it. \return Node number. */ auto nodesOrigin() const; private: auto derived_cast() -> derived_type&; auto derived_cast() const -> const derived_type&; }; /** CRTP base class for regular meshes in 2d. */ template class RegularBase2d : public RegularBase { public: /** Underlying type. */ using derived_type = D; /** Nodes along the bottom edge (y = 0), in order of increasing x. \return List of node numbers. */ auto nodesBottomEdge() const; /** Nodes along the top edge (y = #nely * #h), in order of increasing x. \return List of node numbers. */ auto nodesTopEdge() const; /** Nodes along the left edge (x = 0), in order of increasing y. \return List of node numbers. */ auto nodesLeftEdge() const; /** Nodes along the right edge (x = #nelx * #h), in order of increasing y. \return List of node numbers. */ auto 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. */ auto 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. */ auto 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. */ auto 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. */ auto nodesRightOpenEdge() const; /** The bottom-left corner node (at x = 0, y = 0). Same as nodesBottomEdge()[0] and nodesLeftEdge()[0]. \return Node number. */ auto nodesBottomLeftCorner() const; /** The bottom-right corner node (at x = #nelx * #h, y = 0). Same as nodesBottomEdge()[-1] and nodesRightEdge()[0]. \return Node number. */ auto nodesBottomRightCorner() const; /** The top-left corner node (at x = 0, y = #nely * #h). Same as nodesTopEdge()[0] and nodesRightEdge()[-1]. \return Node number. */ auto nodesTopLeftCorner() const; /** The top-right corner node (at x = #nelx * #h, y = #nely * #h). Same as nodesTopEdge()[-1] and nodesRightEdge()[-1]. \return Node number. */ auto nodesTopRightCorner() const; /** Alias of nodesBottomLeftCorner(). \return Node number. */ auto nodesLeftBottomCorner() const; /** Alias of nodesTopLeftCorner(). \return Node number. */ auto nodesLeftTopCorner() const; /** Alias of nodesBottomRightCorner(). \return Node number. */ auto nodesRightBottomCorner() const; /** Alias of nodesTopRightCorner(). \return Node number. */ auto nodesRightTopCorner() const; private: auto derived_cast() -> derived_type&; auto derived_cast() const -> const derived_type&; friend class RegularBase; xt::xtensor nodesPeriodic_impl() const; auto nodesOrigin_impl() const; }; /** CRTP base class for regular meshes in 3d. */ template class RegularBase3d : public RegularBase { public: /** Underlying type. */ using derived_type = D; /** Number of elements in y-direction == height of the mesh, in units of #h, \return unsigned int */ auto nelz() const; /** Nodes along the bottom face (y = 0). \return List of node numbers. */ auto nodesBottom() const; /** Nodes along the top face (y = #nely * #h). \return List of node numbers. */ auto nodesTop() const; /** Nodes along the left face (x = 0). \return List of node numbers. */ auto nodesLeft() const; /** Nodes along the right face (x = #nelx * #h). \return List of node numbers. */ auto nodesRight() const; /** Nodes along the front face (z = 0). \return List of node numbers. */ auto nodesFront() const; /** Nodes along the back face (z = #nelz * #h). \return List of node numbers. */ auto 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. */ auto 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. */ auto 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. */ auto 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. */ auto 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. */ auto 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. */ auto 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. */ auto nodesBackLeftEdge() const; /** Nodes along the edge at the intersection of the back and right faces (? = #nelz * #h and ? = ?). \return List of node numbers. */ auto 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. */ auto 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. */ auto 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. */ auto 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. */ auto nodesTopRightEdge() const; /** Alias of nodesFrontBottomEdge() \return List of node numbers. */ auto nodesBottomFrontEdge() const; /** Alias of nodesBackBottomEdge() \return List of node numbers. */ auto nodesBottomBackEdge() const; /** Alias of nodesFrontTopEdge() \return List of node numbers. */ auto nodesTopFrontEdge() const; /** Alias of nodesBackTopEdge() \return List of node numbers. */ auto nodesTopBackEdge() const; /** Alias of nodesBottomLeftEdge() \return List of node numbers. */ auto nodesLeftBottomEdge() const; /** Alias of nodesFrontLeftEdge() \return List of node numbers. */ auto nodesLeftFrontEdge() const; /** Alias of nodesBackLeftEdge() \return List of node numbers. */ auto nodesLeftBackEdge() const; /** Alias of nodesTopLeftEdge() \return List of node numbers. */ auto nodesLeftTopEdge() const; /** Alias of nodesBottomRightEdge() \return List of node numbers. */ auto nodesRightBottomEdge() const; /** Alias of nodesTopRightEdge() \return List of node numbers. */ auto nodesRightTopEdge() const; /** Alias of nodesFrontRightEdge() \return List of node numbers. */ auto nodesRightFrontEdge() const; /** Alias of nodesBackRightEdge() \return List of node numbers. */ auto nodesRightBackEdge() const; /** Nodes along the front face excluding edges. Same as different between nodesFront() and [nodesFrontBottomEdge(), nodesFrontTopEdge(), nodesFrontLeftEdge(), nodesFrontRightEdge()] \return list of node numbers. */ auto nodesFrontFace() const; /** Nodes along the back face excluding edges. Same as different between nodesBack() and [nodesBackBottomEdge(), nodesBackTopEdge(), nodesBackLeftEdge(), nodesBackRightEdge()] \return list of node numbers. */ auto nodesBackFace() const; /** Nodes along the left face excluding edges. Same as different between nodesLeft() and [nodesFrontLeftEdge(), nodesBackLeftEdge(), nodesBottomLeftEdge(), nodesTopLeftEdge()] \return list of node numbers. */ auto nodesLeftFace() const; /** Nodes along the right face excluding edges. Same as different between nodesRight() and [nodesFrontRightEdge(), nodesBackRightEdge(), nodesBottomRightEdge(), nodesTopRightEdge()] \return list of node numbers. */ auto nodesRightFace() const; /** Nodes along the bottom face excluding edges. Same as different between nodesBottom() and [nodesBackBottomEdge(), nodesBackTopEdge(), nodesBackLeftEdge(), nodesBackRightEdge()] \return list of node numbers. */ auto nodesBottomFace() const; /** Nodes along the top face excluding edges. Same as different between nodesTop() and [nodesFrontBottomEdge(), nodesFrontTopEdge(), nodesFrontLeftEdge(), nodesFrontRightEdge()] \return list of node numbers. */ auto nodesTopFace() const; /** Same as nodesFrontBottomEdge() but without corners. \return List of node numbers. */ auto nodesFrontBottomOpenEdge() const; /** Same as nodesFrontTopEdge() but without corners. \return List of node numbers. */ auto nodesFrontTopOpenEdge() const; /** Same as nodesFrontLeftEdge() but without corners. \return List of node numbers. */ auto nodesFrontLeftOpenEdge() const; /** Same as nodesFrontRightEdge() but without corners. \return List of node numbers. */ auto nodesFrontRightOpenEdge() const; /** Same as nodesBackBottomEdge() but without corners. \return List of node numbers. */ auto nodesBackBottomOpenEdge() const; /** Same as nodesBackTopEdge() but without corners. \return List of node numbers. */ auto nodesBackTopOpenEdge() const; /** Same as nodesBackLeftEdge() but without corners. \return List of node numbers. */ auto nodesBackLeftOpenEdge() const; /** Same as nodesBackRightEdge() but without corners. \return List of node numbers. */ auto nodesBackRightOpenEdge() const; /** Same as nodesBottomLeftEdge() but without corners. \return List of node numbers. */ auto nodesBottomLeftOpenEdge() const; /** Same as nodesBottomRightEdge() but without corners. \return List of node numbers. */ auto nodesBottomRightOpenEdge() const; /** Same as nodesTopLeftEdge() but without corners. \return List of node numbers. */ auto nodesTopLeftOpenEdge() const; /** Same as nodesTopRightEdge() but without corners. \return List of node numbers. */ auto nodesTopRightOpenEdge() const; /** Alias of nodesFrontBottomOpenEdge(). \return List of node numbers. */ auto nodesBottomFrontOpenEdge() const; /** Alias of nodesBackBottomOpenEdge(). \return List of node numbers. */ auto nodesBottomBackOpenEdge() const; /** Alias of nodesFrontTopOpenEdge(). \return List of node numbers. */ auto nodesTopFrontOpenEdge() const; /** Alias of nodesBackTopOpenEdge(). \return List of node numbers. */ auto nodesTopBackOpenEdge() const; /** Alias of nodesBottomLeftOpenEdge(). \return List of node numbers. */ auto nodesLeftBottomOpenEdge() const; /** Alias of nodesFrontLeftOpenEdge(). \return List of node numbers. */ auto nodesLeftFrontOpenEdge() const; /** Alias of nodesBackLeftOpenEdge(). \return List of node numbers. */ auto nodesLeftBackOpenEdge() const; /** Alias of nodesTopLeftOpenEdge(). \return List of node numbers. */ auto nodesLeftTopOpenEdge() const; /** Alias of nodesBottomRightOpenEdge(). \return List of node numbers. */ auto nodesRightBottomOpenEdge() const; /** Alias of nodesTopRightOpenEdge(). \return List of node numbers. */ auto nodesRightTopOpenEdge() const; /** Alias of nodesFrontRightOpenEdge(). \return List of node numbers. */ auto nodesRightFrontOpenEdge() const; /** Alias of nodesBackRightOpenEdge(). \return List of node numbers. */ auto nodesRightBackOpenEdge() const; /** Front-Bottom-Left corner node. \return Node number. */ auto nodesFrontBottomLeftCorner() const; /** Front-Bottom-Right corner node. \return Node number. */ auto nodesFrontBottomRightCorner() const; /** Front-Top-Left corner node. \return Node number. */ auto nodesFrontTopLeftCorner() const; /** Front-Top-Right corner node. \return Node number. */ auto nodesFrontTopRightCorner() const; /** Back-Bottom-Left corner node. \return Node number. */ auto nodesBackBottomLeftCorner() const; /** Back-Bottom-Right corner node. \return Node number. */ auto nodesBackBottomRightCorner() const; /** Back-Top-Left corner node. \return Node number. */ auto nodesBackTopLeftCorner() const; /** Back-Top-Right corner node. \return Node number. */ auto nodesBackTopRightCorner() const; /** Alias of nodesFrontBottomLeftCorner(). \return Node number. */ auto nodesFrontLeftBottomCorner() const; /** Alias of nodesFrontBottomLeftCorner(). \return Node number. */ auto nodesBottomFrontLeftCorner() const; /** Alias of nodesFrontBottomLeftCorner(). \return Node number. */ auto nodesBottomLeftFrontCorner() const; /** Alias of nodesFrontBottomLeftCorner(). \return Node number. */ auto nodesLeftFrontBottomCorner() const; /** Alias of nodesFrontBottomLeftCorner(). \return Node number. */ auto nodesLeftBottomFrontCorner() const; /** Alias of nodesFrontBottomRightCorner(). \return Node number. */ auto nodesFrontRightBottomCorner() const; /** Alias of nodesFrontBottomRightCorner(). \return Node number. */ auto nodesBottomFrontRightCorner() const; /** Alias of nodesFrontBottomRightCorner(). \return Node number. */ auto nodesBottomRightFrontCorner() const; /** Alias of nodesFrontBottomRightCorner(). \return Node number. */ auto nodesRightFrontBottomCorner() const; /** Alias of nodesFrontBottomRightCorner(). \return Node number. */ auto nodesRightBottomFrontCorner() const; /** Alias of nodesFrontTopLeftCorner(). \return Node number. */ auto nodesFrontLeftTopCorner() const; /** Alias of nodesFrontTopLeftCorner(). \return Node number. */ auto nodesTopFrontLeftCorner() const; /** Alias of nodesFrontTopLeftCorner(). \return Node number. */ auto nodesTopLeftFrontCorner() const; /** Alias of nodesFrontTopLeftCorner(). \return Node number. */ auto nodesLeftFrontTopCorner() const; /** Alias of nodesFrontTopLeftCorner(). \return Node number. */ auto nodesLeftTopFrontCorner() const; /** Alias of nodesFrontTopRightCorner(). \return Node number. */ auto nodesFrontRightTopCorner() const; /** Alias of nodesFrontTopRightCorner(). \return Node number. */ auto nodesTopFrontRightCorner() const; /** Alias of nodesFrontTopRightCorner(). \return Node number. */ auto nodesTopRightFrontCorner() const; /** Alias of nodesFrontTopRightCorner(). \return Node number. */ auto nodesRightFrontTopCorner() const; /** Alias of nodesFrontTopRightCorner(). \return Node number. */ auto nodesRightTopFrontCorner() const; /** Alias of nodesBackBottomLeftCorner(). \return Node number. */ auto nodesBackLeftBottomCorner() const; /** Alias of nodesBackBottomLeftCorner(). \return Node number. */ auto nodesBottomBackLeftCorner() const; /** Alias of nodesBackBottomLeftCorner(). \return Node number. */ auto nodesBottomLeftBackCorner() const; /** Alias of nodesBackBottomLeftCorner(). \return Node number. */ auto nodesLeftBackBottomCorner() const; /** Alias of nodesBackBottomLeftCorner(). \return Node number. */ auto nodesLeftBottomBackCorner() const; /** Alias of nodesBackBottomRightCorner(). \return Node number. */ auto nodesBackRightBottomCorner() const; /** Alias of nodesBackBottomRightCorner(). \return Node number. */ auto nodesBottomBackRightCorner() const; /** Alias of nodesBackBottomRightCorner(). \return Node number. */ auto nodesBottomRightBackCorner() const; /** Alias of nodesBackBottomRightCorner(). \return Node number. */ auto nodesRightBackBottomCorner() const; /** Alias of nodesBackBottomRightCorner(). \return Node number. */ auto nodesRightBottomBackCorner() const; /** Alias of nodesBackTopLeftCorner(). \return Node number. */ auto nodesBackLeftTopCorner() const; /** Alias of nodesBackTopLeftCorner(). \return Node number. */ auto nodesTopBackLeftCorner() const; /** Alias of nodesBackTopLeftCorner(). \return Node number. */ auto nodesTopLeftBackCorner() const; /** Alias of nodesBackTopLeftCorner(). \return Node number. */ auto nodesLeftBackTopCorner() const; /** Alias of nodesBackTopLeftCorner(). \return Node number. */ auto nodesLeftTopBackCorner() const; /** Alias of nodesBackTopRightCorner(). \return Node number. */ auto nodesBackRightTopCorner() const; /** Alias of nodesBackTopRightCorner(). \return Node number. */ auto nodesTopBackRightCorner() const; /** Alias of nodesBackTopRightCorner(). \return Node number. */ auto nodesTopRightBackCorner() const; /** Alias of nodesBackTopRightCorner(). \return Node number. */ auto nodesRightBackTopCorner() const; /** Alias of nodesBackTopRightCorner(). \return Node number. */ auto nodesRightTopBackCorner() const; private: auto derived_cast() -> derived_type&; auto derived_cast() const -> const derived_type&; friend class RegularBase; xt::xtensor nodesPeriodic_impl() const; auto nodesOrigin_impl() const; }; /** 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" [nnode, ndim]. \param coor_b Nodal coordinates of mesh "b" [nnode, ndim]. \param rtol Relative tolerance for position match. \param atol Absolute tolerance for position match. \return Overlapping nodes. */ template inline xt::xtensor overlapping(const S& coor_a, const T& 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" [nnode, ndim]. \param conn_a Connectivity of mesh "a" [nelem, nne]. \param overlapping_nodes_a Node-numbers of mesh "a" that overlap with mesh "b" [n]. \param coor_b Nodal coordinates of mesh "b" [nnode, ndim]. \param conn_b Connectivity of mesh "b" [nelem, nne]. \param overlapping_nodes_b Node-numbers of mesh "b" that overlap with mesh "a" [n]. \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. */ template ManualStitch( const CA& coor_a, const EA& conn_a, const NA& overlapping_nodes_a, const CB& coor_b, const EB& conn_b, const NB& overlapping_nodes_b, bool check_position = true, double rtol = 1e-5, double atol = 1e-8); /** Number of sub meshes == 2. \return unsigned int */ size_t nmesh() const; /** 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 [#nnode, #ndim]. \return coordinates per node */ xt::xtensor coor() const; /** Connectivity [#nelem, #nne]. \return nodes per element */ xt::xtensor conn() const; /** DOF numbers for each node (numbered sequentially) [#nnode, #ndim]. \return DOFs per node */ xt::xtensor dofs() const; /** Node-map per sub-mesh. \return nodes per mesh */ std::vector> nodemap() const; /** Element-map per sub-mesh. \return elements per 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. */ template T nodeset(const T& 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. */ template T elemset(const T& 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 [nnode, ndim]. \param conn Connectivity [nelem, nne]. */ template void push_back(const C& coor, const E& conn); /** Number of sub meshes. \return unsigned int */ size_t nmesh() const; /** 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 [#nnode, #ndim]. \return coordinates per node */ xt::xtensor coor() const; /** Connectivity [#nelem, #nne]. \return nodes per element */ xt::xtensor conn() const; /** DOF numbers for each node (numbered sequentially) [#nnode, #ndim]. \return DOFs per node */ xt::xtensor dofs() const; /** Node-map per sub-mesh. \return nodes per mesh */ std::vector> nodemap() const; /** Element-map per sub-mesh. \return elements per 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. */ template T nodeset(const T& 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. */ template T elemset(const T& 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. */ template T nodeset(const std::vector& set) const; /** \copydoc nodeset(const std::vector&) const */ template T nodeset(std::initializer_list 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. */ template T elemset(const std::vector& set) const; /** \copydoc elemset(const std::vector&) const */ template T elemset(std::initializer_list set) const; protected: xt::xtensor m_coor; ///< Nodal coordinates [#nnode, #ndim] xt::xtensor m_conn; ///< Connectivity [#nelem, #nne] std::vector> m_map; ///< See nodemap(size_t) std::vector m_nel; ///< Number of elements per sub-mesh. std::vector m_el_offset; ///< First element of every sub-mesh. double m_rtol; ///< Relative tolerance to find overlapping nodes. double m_atol; ///< Absolute tolerance to find overlapping nodes. }; /** Vertically stack meshes. */ class Vstack : public Stitch { public: /** \param check_overlap Check if nodes are overlapping when adding a mesh. \param rtol Relative tolerance for position match. \param atol Absolute tolerance for position match. */ Vstack(bool check_overlap = true, double rtol = 1e-5, double atol = 1e-8); /** Add a mesh to the top of the current stack. Each time the current `nodes_bottom` are stitched with the then highest `nodes_top`. \param coor Nodal coordinates [nnode, ndim]. \param conn Connectivity [nelem, nne]. \param nodes_bottom Nodes along the bottom edge [n]. \param nodes_top Nodes along the top edge [n]. */ template void push_back(const C& coor, const E& conn, const N& nodes_bottom, const N& nodes_top); private: std::vector> m_nodes_bot; ///< Bottom nodes of each mesh (renumbered). std::vector> m_nodes_top; ///< Top nodes of each mesh (renumbered). bool m_check_overlap; ///< Check if nodes are overlapping when adding a mesh. }; /** Renumber indices to lowest possible index. For example: \f$ \begin{bmatrix} 0 & 1 \\ 5 & 4 \end{bmatrix} \f$ is renumbered to \f$ \begin{bmatrix} 0 & 1 \\ 3 & 2 \end{bmatrix} \f$ Or, in pseudo-code, the result of this function is that: dofs = renumber(dofs) sort(unique(dofs[:])) == range(max(dofs+1)) \note One can use the wrapper function renumber(). This class gives more advanced features. */ class Renumber { public: Renumber() = default; /** \param dofs DOF-numbers. */ template Renumber(const T& dofs); /** 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 [nnode, ndim]. \return Renumbered DOF-numbers. */ template inline T renumber(const T& 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. */ template Reorder(const std::initializer_list args); /** 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 \f$ \begin{bmatrix} 0 & 1 \\ 2 & 3 \\ 4 & 5 \end{bmatrix} \f$ \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 [nelem, nne]. \return Coordination per node. */ template inline xt::xtensor coordination(const E& conn); /** Elements connected to each node. \param conn Connectivity. \param sorted If ``true`` the output is sorted. \return Elements per node. */ template inline std::vector> elem2node(const E& 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. */ template inline xt::xtensor edgesize(const C& coor, const E& 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. */ template inline xt::xtensor edgesize(const C& coor, const E& conn); /** Coordinates of the center of each element. \param coor Nodal coordinates. \param conn Connectivity. \param type ElementType. \return Center of each element. */ template inline xt::xtensor centers(const C& coor, const E& 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. */ template inline xt::xtensor centers(const C& coor, const E& 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]`` */ template inline xt::xtensor elemmap2nodemap(const T& elem_map, const C& coor, const E& 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]`` */ template inline xt::xtensor elemmap2nodemap(const T& elem_map, const C& coor, const E& conn); /** Compute the center of gravity of a mesh. \tparam C e.g. `xt::xtensor` \tparam E e.g. `xt::xtensor` \param coor Nodal coordinates `[nnode, ndim]`. \param conn Connectivity `[nelem, nne]`. \param type ElementType. \return Center of gravity `[ndim]`. */ template inline xt::xtensor center_of_gravity(const C& coor, const E& conn, ElementType type); /** Compute the center of gravity of a mesh. \tparam C e.g. `xt::xtensor` \tparam E e.g. `xt::xtensor` \param coor Nodal coordinates `[nnode, ndim]`. \param conn Connectivity `[nelem, nne]`. \return Center of gravity `[ndim]`. */ template inline xt::xtensor center_of_gravity(const C& coor, const E& conn); } // namespace Mesh } // namespace GooseFEM #include "Mesh.hpp" #endif diff --git a/python/Mesh.hpp b/python/Mesh.hpp index 9ad500f..eae765e 100644 --- a/python/Mesh.hpp +++ b/python/Mesh.hpp @@ -1,683 +1,679 @@ /** \file \copyright Copyright 2017. Tom de Geus. All rights reserved. \license This project is released under the GNU Public License (GPLv3). */ #ifndef PYGOOSEFEM_MESH_H #define PYGOOSEFEM_MESH_H #include #include #include #include #include namespace py = pybind11; template void register_Element_RegularBase(P& cls) { cls.def("nelem", &C::nelem); cls.def("nnode", &C::nnode); cls.def("nne", &C::nne); cls.def("ndim", &C::ndim); cls.def("nelx", &C::nelx); cls.def("nely", &C::nely); cls.def("h", &C::h); cls.def("getElementType", &C::getElementType); cls.def("coor", &C::coor); cls.def("conn", &C::conn); cls.def("dofs", &C::dofs); cls.def("dofsPeriodic", &C::dofsPeriodic); cls.def("nodesPeriodic", &C::nodesPeriodic); cls.def("nodesOrigin", &C::nodesOrigin); } template void register_Element_RegularBase2d(P& cls) { cls.def("nodesBottomEdge", &C::nodesBottomEdge); cls.def("nodesTopEdge", &C::nodesTopEdge); cls.def("nodesLeftEdge", &C::nodesLeftEdge); cls.def("nodesRightEdge", &C::nodesRightEdge); cls.def("nodesBottomOpenEdge", &C::nodesBottomOpenEdge); cls.def("nodesTopOpenEdge", &C::nodesTopOpenEdge); cls.def("nodesLeftOpenEdge", &C::nodesLeftOpenEdge); cls.def("nodesRightOpenEdge", &C::nodesRightOpenEdge); cls.def("nodesBottomLeftCorner", &C::nodesBottomLeftCorner); cls.def("nodesBottomRightCorner", &C::nodesBottomRightCorner); cls.def("nodesTopLeftCorner", &C::nodesTopLeftCorner); cls.def("nodesTopRightCorner", &C::nodesTopRightCorner); cls.def("nodesLeftBottomCorner", &C::nodesLeftBottomCorner); cls.def("nodesLeftTopCorner", &C::nodesLeftTopCorner); cls.def("nodesRightBottomCorner", &C::nodesRightBottomCorner); cls.def("nodesRightTopCorner", &C::nodesRightTopCorner); } template void register_Element_RegularBase3d(P& cls) { cls.def("nodesFront", &C::nodesFront); cls.def("nodesBack", &C::nodesBack); cls.def("nodesLeft", &C::nodesLeft); cls.def("nodesRight", &C::nodesRight); cls.def("nodesBottom", &C::nodesBottom); cls.def("nodesTop", &C::nodesTop); cls.def("nodesFrontFace", &C::nodesFrontFace); cls.def("nodesBackFace", &C::nodesBackFace); cls.def("nodesLeftFace", &C::nodesLeftFace); cls.def("nodesRightFace", &C::nodesRightFace); cls.def("nodesBottomFace", &C::nodesBottomFace); cls.def("nodesTopFace", &C::nodesTopFace); cls.def("nodesFrontBottomEdge", &C::nodesFrontBottomEdge); cls.def("nodesFrontTopEdge", &C::nodesFrontTopEdge); cls.def("nodesFrontLeftEdge", &C::nodesFrontLeftEdge); cls.def("nodesFrontRightEdge", &C::nodesFrontRightEdge); cls.def("nodesBackBottomEdge", &C::nodesBackBottomEdge); cls.def("nodesBackTopEdge", &C::nodesBackTopEdge); cls.def("nodesBackLeftEdge", &C::nodesBackLeftEdge); cls.def("nodesBackRightEdge", &C::nodesBackRightEdge); cls.def("nodesBottomLeftEdge", &C::nodesBottomLeftEdge); cls.def("nodesBottomRightEdge", &C::nodesBottomRightEdge); cls.def("nodesTopLeftEdge", &C::nodesTopLeftEdge); cls.def("nodesTopRightEdge", &C::nodesTopRightEdge); cls.def("nodesBottomFrontEdge", &C::nodesBottomFrontEdge); cls.def("nodesBottomBackEdge", &C::nodesBottomBackEdge); cls.def("nodesTopFrontEdge", &C::nodesTopFrontEdge); cls.def("nodesTopBackEdge", &C::nodesTopBackEdge); cls.def("nodesLeftBottomEdge", &C::nodesLeftBottomEdge); cls.def("nodesLeftFrontEdge", &C::nodesLeftFrontEdge); cls.def("nodesLeftBackEdge", &C::nodesLeftBackEdge); cls.def("nodesLeftTopEdge", &C::nodesLeftTopEdge); cls.def("nodesRightBottomEdge", &C::nodesRightBottomEdge); cls.def("nodesRightTopEdge", &C::nodesRightTopEdge); cls.def("nodesRightFrontEdge", &C::nodesRightFrontEdge); cls.def("nodesRightBackEdge", &C::nodesRightBackEdge); cls.def("nodesFrontBottomOpenEdge", &C::nodesFrontBottomOpenEdge); cls.def("nodesFrontTopOpenEdge", &C::nodesFrontTopOpenEdge); cls.def("nodesFrontLeftOpenEdge", &C::nodesFrontLeftOpenEdge); cls.def("nodesFrontRightOpenEdge", &C::nodesFrontRightOpenEdge); cls.def("nodesBackBottomOpenEdge", &C::nodesBackBottomOpenEdge); cls.def("nodesBackTopOpenEdge", &C::nodesBackTopOpenEdge); cls.def("nodesBackLeftOpenEdge", &C::nodesBackLeftOpenEdge); cls.def("nodesBackRightOpenEdge", &C::nodesBackRightOpenEdge); cls.def("nodesBottomLeftOpenEdge", &C::nodesBottomLeftOpenEdge); cls.def("nodesBottomRightOpenEdge", &C::nodesBottomRightOpenEdge); cls.def("nodesTopLeftOpenEdge", &C::nodesTopLeftOpenEdge); cls.def("nodesTopRightOpenEdge", &C::nodesTopRightOpenEdge); cls.def("nodesBottomFrontOpenEdge", &C::nodesBottomFrontOpenEdge); cls.def("nodesBottomBackOpenEdge", &C::nodesBottomBackOpenEdge); cls.def("nodesTopFrontOpenEdge", &C::nodesTopFrontOpenEdge); cls.def("nodesTopBackOpenEdge", &C::nodesTopBackOpenEdge); cls.def("nodesLeftBottomOpenEdge", &C::nodesLeftBottomOpenEdge); cls.def("nodesLeftFrontOpenEdge", &C::nodesLeftFrontOpenEdge); cls.def("nodesLeftBackOpenEdge", &C::nodesLeftBackOpenEdge); cls.def("nodesLeftTopOpenEdge", &C::nodesLeftTopOpenEdge); cls.def("nodesRightBottomOpenEdge", &C::nodesRightBottomOpenEdge); cls.def("nodesRightTopOpenEdge", &C::nodesRightTopOpenEdge); cls.def("nodesRightFrontOpenEdge", &C::nodesRightFrontOpenEdge); cls.def("nodesRightBackOpenEdge", &C::nodesRightBackOpenEdge); cls.def("nodesFrontBottomLeftCorner", &C::nodesFrontBottomLeftCorner); cls.def("nodesFrontBottomRightCorner", &C::nodesFrontBottomRightCorner); cls.def("nodesFrontTopLeftCorner", &C::nodesFrontTopLeftCorner); cls.def("nodesFrontTopRightCorner", &C::nodesFrontTopRightCorner); cls.def("nodesBackBottomLeftCorner", &C::nodesBackBottomLeftCorner); cls.def("nodesBackBottomRightCorner", &C::nodesBackBottomRightCorner); cls.def("nodesBackTopLeftCorner", &C::nodesBackTopLeftCorner); cls.def("nodesBackTopRightCorner", &C::nodesBackTopRightCorner); cls.def("nodesFrontLeftBottomCorner", &C::nodesFrontLeftBottomCorner); cls.def("nodesBottomFrontLeftCorner", &C::nodesBottomFrontLeftCorner); cls.def("nodesBottomLeftFrontCorner", &C::nodesBottomLeftFrontCorner); cls.def("nodesLeftFrontBottomCorner", &C::nodesLeftFrontBottomCorner); cls.def("nodesLeftBottomFrontCorner", &C::nodesLeftBottomFrontCorner); cls.def("nodesFrontRightBottomCorner", &C::nodesFrontRightBottomCorner); cls.def("nodesBottomFrontRightCorner", &C::nodesBottomFrontRightCorner); cls.def("nodesBottomRightFrontCorner", &C::nodesBottomRightFrontCorner); cls.def("nodesRightFrontBottomCorner", &C::nodesRightFrontBottomCorner); cls.def("nodesRightBottomFrontCorner", &C::nodesRightBottomFrontCorner); cls.def("nodesFrontLeftTopCorner", &C::nodesFrontLeftTopCorner); cls.def("nodesTopFrontLeftCorner", &C::nodesTopFrontLeftCorner); cls.def("nodesTopLeftFrontCorner", &C::nodesTopLeftFrontCorner); cls.def("nodesLeftFrontTopCorner", &C::nodesLeftFrontTopCorner); cls.def("nodesLeftTopFrontCorner", &C::nodesLeftTopFrontCorner); cls.def("nodesFrontRightTopCorner", &C::nodesFrontRightTopCorner); cls.def("nodesTopFrontRightCorner", &C::nodesTopFrontRightCorner); cls.def("nodesTopRightFrontCorner", &C::nodesTopRightFrontCorner); cls.def("nodesRightFrontTopCorner", &C::nodesRightFrontTopCorner); cls.def("nodesRightTopFrontCorner", &C::nodesRightTopFrontCorner); cls.def("nodesBackLeftBottomCorner", &C::nodesBackLeftBottomCorner); cls.def("nodesBottomBackLeftCorner", &C::nodesBottomBackLeftCorner); cls.def("nodesBottomLeftBackCorner", &C::nodesBottomLeftBackCorner); cls.def("nodesLeftBackBottomCorner", &C::nodesLeftBackBottomCorner); cls.def("nodesLeftBottomBackCorner", &C::nodesLeftBottomBackCorner); cls.def("nodesBackRightBottomCorner", &C::nodesBackRightBottomCorner); cls.def("nodesBottomBackRightCorner", &C::nodesBottomBackRightCorner); cls.def("nodesBottomRightBackCorner", &C::nodesBottomRightBackCorner); cls.def("nodesRightBackBottomCorner", &C::nodesRightBackBottomCorner); cls.def("nodesRightBottomBackCorner", &C::nodesRightBottomBackCorner); cls.def("nodesBackLeftTopCorner", &C::nodesBackLeftTopCorner); cls.def("nodesTopBackLeftCorner", &C::nodesTopBackLeftCorner); cls.def("nodesTopLeftBackCorner", &C::nodesTopLeftBackCorner); cls.def("nodesLeftBackTopCorner", &C::nodesLeftBackTopCorner); cls.def("nodesLeftTopBackCorner", &C::nodesLeftTopBackCorner); cls.def("nodesBackRightTopCorner", &C::nodesBackRightTopCorner); cls.def("nodesTopBackRightCorner", &C::nodesTopBackRightCorner); cls.def("nodesTopRightBackCorner", &C::nodesTopRightBackCorner); cls.def("nodesRightBackTopCorner", &C::nodesRightBackTopCorner); cls.def("nodesRightTopBackCorner", &C::nodesRightTopBackCorner); } void init_Mesh(py::module& mod) { py::enum_( mod, "ElementType", "ElementType." "See :cpp:enum:`GooseFEM::Mesh::ElementType`.") .value("Unknown", GooseFEM::Mesh::ElementType::Unknown) .value("Tri3", GooseFEM::Mesh::ElementType::Tri3) .value("Quad4", GooseFEM::Mesh::ElementType::Quad4) .value("Hex8", GooseFEM::Mesh::ElementType::Hex8) .export_values(); mod.def( "overlapping", &GooseFEM::Mesh::overlapping, xt::pytensor>, "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_(mod, "ManualStitch") .def( py::init< const xt::pytensor&, const xt::pytensor&, const xt::pytensor&, const xt::pytensor&, const xt::pytensor&, const xt::pytensor&, 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( "nmesh", &GooseFEM::Mesh::ManualStitch::nmesh, "Number of sub meshes." "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nmesh`.") .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", py::overload_cast<>(&GooseFEM::Mesh::ManualStitch::nodemap, py::const_), "Node-map for givall sub-meshes." "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nodemap`.") .def( "elemmap", py::overload_cast<>(&GooseFEM::Mesh::ManualStitch::elemmap, py::const_), "Element-map for all sub-meshes." "See :cpp:func:`GooseFEM::Mesh::ManualStitch::elemmap`.") .def( "nodemap", py::overload_cast(&GooseFEM::Mesh::ManualStitch::nodemap, py::const_), "Node-map for given sub-mesh." "See :cpp:func:`GooseFEM::Mesh::ManualStitch::nodemap`.", py::arg("mesh_index")) .def( "elemmap", py::overload_cast(&GooseFEM::Mesh::ManualStitch::elemmap, py::const_), "Element-map for given sub-mesh." "See :cpp:func:`GooseFEM::Mesh::ManualStitch::elemmap`.", py::arg("mesh_index")) .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_(mod, "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, xt::pytensor>, "Add mesh to be stitched." "See :cpp:func:`GooseFEM::Mesh::Stitch::push_back`.", py::arg("coor"), py::arg("conn")) .def( "nmesh", &GooseFEM::Mesh::Stitch::nmesh, "Number of sub meshes." "See :cpp:func:`GooseFEM::Mesh::Stitch::nmesh`.") .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", py::overload_cast<>(&GooseFEM::Mesh::Stitch::nodemap, py::const_), "Node-map for givall sub-meshes." "See :cpp:func:`GooseFEM::Mesh::Stitch::nodemap`.") .def( "elemmap", py::overload_cast<>(&GooseFEM::Mesh::Stitch::elemmap, py::const_), "Element-map for all sub-meshes." "See :cpp:func:`GooseFEM::Mesh::Stitch::elemmap`.") .def( "nodemap", py::overload_cast(&GooseFEM::Mesh::Stitch::nodemap, py::const_), "Node-map for given sub-mesh." "See :cpp:func:`GooseFEM::Mesh::Stitch::nodemap`.", py::arg("mesh_index")) .def( "elemmap", py::overload_cast(&GooseFEM::Mesh::Stitch::elemmap, py::const_), "Element-map for given sub-mesh." "See :cpp:func:`GooseFEM::Mesh::Stitch::elemmap`.", py::arg("mesh_index")) .def( "nodeset", static_cast (GooseFEM::Mesh::Stitch::*)( const xt::pytensor&, size_t) const>(&GooseFEM::Mesh::Stitch::nodeset), "Convert node-set to the stitched mesh." "See :cpp:func:`GooseFEM::Mesh::Stitch::nodeset`.", py::arg("set"), py::arg("mesh_index")) .def( "elemset", static_cast (GooseFEM::Mesh::Stitch::*)( const xt::pytensor&, size_t) const>(&GooseFEM::Mesh::Stitch::elemset), "Convert element-set to the stitched mesh." "See :cpp:func:`GooseFEM::Mesh::Stitch::elemset`.", py::arg("set"), py::arg("mesh_index")) .def( "nodeset", static_cast (GooseFEM::Mesh::Stitch::*)( const std::vector>&) const>( &GooseFEM::Mesh::Stitch::nodeset), "Convert node-set to the stitched mesh." "See :cpp:func:`GooseFEM::Mesh::Stitch::nodeset`.", py::arg("set")) .def( "elemset", static_cast (GooseFEM::Mesh::Stitch::*)( const std::vector>&) const>( &GooseFEM::Mesh::Stitch::elemset), "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_(mod, "Vstack") .def( py::init(), "Vstack meshes." "See :cpp:class:`GooseFEM::Mesh::Vstack`.", py::arg("check_overlap") = true, py::arg("rtol") = 1e-5, py::arg("atol") = 1e-8) .def( "push_back", &GooseFEM::Mesh::Vstack::push_back< xt::pytensor, xt::pytensor, xt::pytensor>, "Add mesh to be stitched." "See :cpp:func:`GooseFEM::Mesh::Vstack::push_back`.", py::arg("coor"), py::arg("conn"), py::arg("nodes_bottom"), py::arg("nodes_top")) .def("__repr__", [](const GooseFEM::Mesh::Vstack&) { return ""; }); py::class_(mod, "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_(mod, "Reorder") .def( py::init([](xt::pytensor& a) { return new GooseFEM::Mesh::Reorder({a}); }), "Reorder to lowest possible index." "See :cpp:class:`GooseFEM::Mesh::Reorder`.") .def( py::init([](xt::pytensor& a, xt::pytensor& b) { return new GooseFEM::Mesh::Reorder({a, b}); }), "Reorder to lowest possible index." "See :cpp:class:`GooseFEM::Mesh::Reorder`.") .def( py::init([](xt::pytensor& a, xt::pytensor& b, xt::pytensor& c) { return new GooseFEM::Mesh::Reorder({a, b, c}); }), "Reorder to lowest possible index." "See :cpp:class:`GooseFEM::Mesh::Reorder`.") .def( py::init([](xt::pytensor& a, xt::pytensor& b, xt::pytensor& c, xt::pytensor& 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 ""; }); mod.def( "dofs", &GooseFEM::Mesh::dofs, "List with DOF-numbers in sequential order." "See :cpp:func:`GooseFEM::Mesh::dofs`.", py::arg("nnode"), py::arg("ndim")); mod.def( "renumber", &GooseFEM::Mesh::renumber>, "Renumber to lowest possible indices." "See :cpp:func:`GooseFEM::Mesh::renumber`.", py::arg("dofs")); mod.def( "coordination", &GooseFEM::Mesh::coordination>, "Coordination number of each node." "See :cpp:func:`GooseFEM::Mesh::coordination`.", py::arg("conn")); mod.def( "elem2node", &GooseFEM::Mesh::elem2node>, "Element-numbers connected to each node." "See :cpp:func:`GooseFEM::Mesh::elem2node`.", py::arg("conn"), py::arg("sorted") = true); mod.def( "edgesize", py::overload_cast&, const xt::pytensor&>( &GooseFEM::Mesh::edgesize, xt::pytensor>), "Get the edge size of all elements." "See :cpp:func:`GooseFEM::Mesh::edgesize`.", py::arg("coor"), py::arg("conn")); mod.def( "edgesize", py::overload_cast< const xt::pytensor&, const xt::pytensor&, GooseFEM::Mesh::ElementType>( &GooseFEM::Mesh::edgesize, xt::pytensor>), "Get the edge size of all elements." "See :cpp:func:`GooseFEM::Mesh::edgesize`.", py::arg("coor"), py::arg("conn"), py::arg("type")); mod.def( "centers", py::overload_cast&, const xt::pytensor&>( &GooseFEM::Mesh::centers, xt::pytensor>), "Coordinates of the center of each element." "See :cpp:func:`GooseFEM::Mesh::centers`.", py::arg("coor"), py::arg("conn")); mod.def( "centers", py::overload_cast< const xt::pytensor&, const xt::pytensor&, GooseFEM::Mesh::ElementType>( &GooseFEM::Mesh::centers, xt::pytensor>), "Coordinates of the center of each element." "See :cpp:func:`GooseFEM::Mesh::centers`.", py::arg("coor"), py::arg("conn"), py::arg("type")); mod.def( "elemmap2nodemap", py::overload_cast< const xt::pytensor&, const xt::pytensor&, const xt::pytensor&>(&GooseFEM::Mesh::elemmap2nodemap< xt::pytensor, xt::pytensor, xt::pytensor>), "Convert an element-map to a node-map." "See :cpp:func:`GooseFEM::Mesh::elemmap2nodemap`.", py::arg("elem_map"), py::arg("coor"), py::arg("conn")); mod.def( "elemmap2nodemap", py::overload_cast< const xt::pytensor&, const xt::pytensor&, const xt::pytensor&, GooseFEM::Mesh::ElementType>(&GooseFEM::Mesh::elemmap2nodemap< xt::pytensor, xt::pytensor, xt::pytensor>), "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")); mod.def( "center_of_gravity", - py::overload_cast< - const xt::pytensor&, - const xt::pytensor&>(&GooseFEM::Mesh::center_of_gravity< - xt::pytensor, - xt::pytensor>), + py::overload_cast&, const xt::pytensor&>( + &GooseFEM::Mesh::center_of_gravity, xt::pytensor>), "Compute center of gravity of a mesh." "See :cpp:func:`GooseFEM::Mesh::center_of_gravity`.", py::arg("coor"), py::arg("conn")); mod.def( "center_of_gravity", py::overload_cast< const xt::pytensor&, const xt::pytensor&, - GooseFEM::Mesh::ElementType>(&GooseFEM::Mesh::center_of_gravity< - xt::pytensor, - xt::pytensor>), + GooseFEM::Mesh::ElementType>( + &GooseFEM::Mesh::center_of_gravity, xt::pytensor>), "Compute center of gravity of a mesh." "See :cpp:func:`GooseFEM::Mesh::center_of_gravity`.", py::arg("coor"), py::arg("conn"), py::arg("type")); } #endif