diff --git a/python/py_contact_mechanics_model.cc b/python/py_contact_mechanics_model.cc index 083444098..0325cc68c 100644 --- a/python/py_contact_mechanics_model.cc +++ b/python/py_contact_mechanics_model.cc @@ -1,96 +1,110 @@ /* -------------------------------------------------------------------------- */ #include "py_aka_array.hh" /* -------------------------------------------------------------------------- */ #include <contact_mechanics_model.hh> -#include <surface_selector.hh> +#include <geometry_utils.hh> #include <non_linear_solver.hh> +#include <surface_selector.hh> /* -------------------------------------------------------------------------- */ #include <pybind11/pybind11.h> /* -------------------------------------------------------------------------- */ namespace py = pybind11; /* -------------------------------------------------------------------------- */ namespace akantu { /* -------------------------------------------------------------------------- */ #define def_deprecated(func_name, mesg) \ def(func_name, [](py::args, py::kwargs) { AKANTU_ERROR(mesg); }) #define def_function_nocopy(func_name) \ - def(#func_name, \ + def( \ + #func_name, \ [](ContactMechanicsModel & self) -> decltype(auto) { \ return self.func_name(); \ }, \ py::return_value_policy::reference) #define def_function(func_name) \ def(#func_name, [](ContactMechanicsModel & self) -> decltype(auto) { \ return self.func_name(); \ }) /* -------------------------------------------------------------------------- */ void register_contact_mechanics_model(py::module & mod) { py::class_<ContactMechanicsModelOptions>(mod, "ContactMechanicsModelOptions") .def(py::init<AnalysisMethod>(), py::arg("analysis_method") = _explicit_contact); py::class_<ContactMechanicsModel, Model>(mod, "ContactMechanicsModel", py::multiple_inheritance()) .def(py::init<Mesh &, UInt, const ID &, const MemoryID &, std::shared_ptr<DOFManager>, const ModelType>(), py::arg("mesh"), py::arg("spatial_dimension") = _all_dimensions, py::arg("id") = "contact_mechanics_model", py::arg("memory_id") = 0, py::arg("dof_manager") = nullptr, py::arg("model_type") = ModelType::_contact_mechanics_model) - .def("initFull", - [](ContactMechanicsModel & self, - const ContactMechanicsModelOptions & options) { - self.initFull(options); - }, - py::arg("_analysis_method") = ContactMechanicsModelOptions()) - .def("initFull", - [](ContactMechanicsModel & self, - const AnalysisMethod & analysis_method) { - self.initFull(_analysis_method = analysis_method); - }, - py::arg("_analysis_method")) + .def( + "initFull", + [](ContactMechanicsModel & self, + const ContactMechanicsModelOptions & options) { + self.initFull(options); + }, + py::arg("_analysis_method") = ContactMechanicsModelOptions()) + .def( + "initFull", + [](ContactMechanicsModel & self, + const AnalysisMethod & analysis_method) { + self.initFull(_analysis_method = analysis_method); + }, + py::arg("_analysis_method")) .def_function(search) .def_function(assembleStiffnessMatrix) .def_function(assembleInternalForces) .def_function_nocopy(getExternalForce) .def_function_nocopy(getNormalForce) .def_function_nocopy(getTangentialForce) .def_function_nocopy(getInternalForce) .def_function_nocopy(getGaps) .def_function_nocopy(getNormals) .def_function_nocopy(getNodalArea) .def("dump", py::overload_cast<>(&ContactMechanicsModel::dump)) .def("dump", py::overload_cast<const std::string &>(&ContactMechanicsModel::dump)) .def("dump", py::overload_cast<const std::string &, UInt>( &ContactMechanicsModel::dump)) .def("dump", py::overload_cast<const std::string &, Real, UInt>( &ContactMechanicsModel::dump)); - - py::class_<ContactElement>(mod, "ContactElement") - .def(py::init<>()); + + py::class_<ContactElement>(mod, "ContactElement").def(py::init<>()); py::class_<GeometryUtils>(mod, "GeometryUtils") - .def_static("normal", &GeometryUtils::normal, py::arg("mesh"), py::arg("positions"), - py::arg("element"), py::arg("normal"), py::arg("outward") = true) - .def_static("covariantBasis", &GeometryUtils::covariantBasis, py::arg("mesh"), - py::arg("positions"), py::arg("element"), py::arg("normal"), - py::arg("natural_projection"), py::arg("basis")) - .def_static("curvature", &GeometryUtils::curvature) - .def_static("contravariantBasis", &GeometryUtils::contravariantBasis, - py::arg("covariant_basis"), py::arg("basis")) - .def_static("realProjection", &GeometryUtils::realProjection, py::arg("mesh"), - py::arg("positions"), py::arg("slave"), py::arg("element"), - py::arg("normal"), py::arg("projection")) - .def_static("naturalProjection", &GeometryUtils::naturalProjection, py::arg("mesh"), - py::arg("positions"), py::arg("element"), py::arg("real_projection"), - py::arg("projection")) - .def_static("isBoundaryElement", &GeometryUtils::isBoundaryElement); - + .def_static( + "normal", + py::overload_cast<const Mesh &, const Array<Real> &, const Element &, + Vector<Real> &, bool>(&GeometryUtils::normal), + py::arg("mesh"), py::arg("positions"), py::arg("element"), + py::arg("normal"), py::arg("outward") = true) + .def_static( + "covariantBasis", + py::overload_cast<const Mesh &, const Array<Real> &, const Element &, + const Vector<Real> &, Vector<Real> &, + Matrix<Real> &>(&GeometryUtils::covariantBasis), + py::arg("mesh"), py::arg("positions"), py::arg("element"), + py::arg("normal"), py::arg("natural_projection"), py::arg("basis")) + .def_static("curvature", &GeometryUtils::curvature) + .def_static("contravariantBasis", &GeometryUtils::contravariantBasis, + py::arg("covariant_basis"), py::arg("basis")) + .def_static("realProjection", + py::overload_cast<const Mesh &, const Array<Real> &, + const Vector<Real> &, const Element &, + const Vector<Real> &, Vector<Real> &>( + &GeometryUtils::realProjection), + py::arg("mesh"), py::arg("positions"), py::arg("slave"), + py::arg("element"), py::arg("normal"), py::arg("projection")) + // .def_static("naturalProjection", &GeometryUtils::naturalProjection, + // py::arg("mesh"), py::arg("positions"), py::arg("element"), + // py::arg("real_projection"), py::arg("projection")) + .def_static("isBoundaryElement", &GeometryUtils::isBoundaryElement); } } // namespace akantu diff --git a/python/py_contact_mechanics_model.hh b/python/py_contact_mechanics_model.hh index 72dbbcf88..cec86c46a 100644 --- a/python/py_contact_mechanics_model.hh +++ b/python/py_contact_mechanics_model.hh @@ -1,13 +1,10 @@ +#include <pybind11/pybind11.h> + #ifndef __AKANTU_PY_CONTACT_MECHANICS_MODEL_HH__ #define __AKANTU_PY_CONTACT_MECHANICS_MODEL_HH__ -namespace pybind11 { -struct module; -} - namespace akantu { - void register_contact_mechanics_model(pybind11::module & mod); } // namespace akantu #endif // __AKANTU_PY_CONTACT_MECHANICS_MODEL_HH__ diff --git a/python/py_fe_engine.cc b/python/py_fe_engine.cc index 269302fb4..12db991e1 100644 --- a/python/py_fe_engine.cc +++ b/python/py_fe_engine.cc @@ -1,111 +1,109 @@ /* -------------------------------------------------------------------------- */ #include "py_aka_array.hh" #include "py_aka_common.hh" /* -------------------------------------------------------------------------- */ #include <fe_engine.hh> #include <integration_point.hh> /* -------------------------------------------------------------------------- */ #include <pybind11/functional.h> #include <pybind11/pybind11.h> #include <pybind11/stl.h> /* -------------------------------------------------------------------------- */ namespace py = pybind11; /* -------------------------------------------------------------------------- */ namespace akantu { -__attribute__((visibility("default"))) void -register_fe_engine(py::module & mod) { - +void register_fe_engine(py::module & mod) { py::class_<Element>(mod, "Element") .def(py::init<ElementType, UInt, GhostType>()); py::class_<FEEngine>(mod, "FEEngine") .def( "getNbIntegrationPoints", [](FEEngine & fem, const ElementType & type, const GhostType & ghost_type) { return fem.getNbIntegrationPoints(type, ghost_type); }, py::arg("type"), py::arg("ghost_type") = _not_ghost) .def( "gradientOnIntegrationPoints", [](FEEngine & fem, const Array<Real> & u, Array<Real> & nablauq, UInt nb_degree_of_freedom, ElementType type, GhostType ghost_type, const Array<UInt> * filter_elements) { if (filter_elements == nullptr) { // This is due to the ArrayProxy that looses the // empty_filter information filter_elements = &empty_filter; } fem.gradientOnIntegrationPoints(u, nablauq, nb_degree_of_freedom, type, ghost_type, *filter_elements); }, py::arg("u"), py::arg("nablauq"), py::arg("nb_degree_of_freedom"), py::arg("type"), py::arg("ghost_type") = _not_ghost, py::arg("filter_elements") = nullptr) .def( "interpolateOnIntegrationPoints", [](FEEngine & self, const Array<Real> & u, Array<Real> & uq, UInt nb_degree_of_freedom, ElementType type, GhostType ghost_type, const Array<UInt> * filter_elements) { if (filter_elements == nullptr) { // This is due to the ArrayProxy that looses the // empty_filter information filter_elements = &empty_filter; } self.interpolateOnIntegrationPoints(u, uq, nb_degree_of_freedom, type, ghost_type, *filter_elements); }, py::arg("u"), py::arg("uq"), py::arg("nb_degree_of_freedom"), py::arg("type"), py::arg("ghost_type") = _not_ghost, py::arg("filter_elements") = nullptr) .def( "interpolateOnIntegrationPoints", [](FEEngine & self, const Array<Real> & u, ElementTypeMapArray<Real> & uq, const ElementTypeMapArray<UInt> * filter_elements) { self.interpolateOnIntegrationPoints(u, uq, filter_elements); }, py::arg("u"), py::arg("uq"), py::arg("filter_elements") = nullptr) .def( "computeIntegrationPointsCoordinates", [](FEEngine & self, ElementTypeMapArray<Real> & coordinates, const ElementTypeMapArray<UInt> * filter_elements) -> decltype(auto) { return self.computeIntegrationPointsCoordinates(coordinates, filter_elements); }, py::arg("coordinates"), py::arg("filter_elements") = nullptr) .def( "assembleFieldLumped", [](FEEngine & fem, const std::function<void(Matrix<Real> &, const Element &)> & field_funct, const ID & matrix_id, const ID & dof_id, DOFManager & dof_manager, ElementType type, GhostType ghost_type) { fem.assembleFieldLumped(field_funct, matrix_id, dof_id, dof_manager, type, ghost_type); }, py::arg("field_funct"), py::arg("matrix_id"), py::arg("dof_id"), py::arg("dof_manager"), py::arg("type"), py::arg("ghost_type") = _not_ghost) .def( "assembleFieldMatrix", [](FEEngine & fem, const std::function<void(Matrix<Real> &, const Element &)> & field_funct, const ID & matrix_id, const ID & dof_id, DOFManager & dof_manager, ElementType type, GhostType ghost_type = _not_ghost) { fem.assembleFieldMatrix(field_funct, matrix_id, dof_id, dof_manager, type, ghost_type); }, py::arg("field_funct"), py::arg("matrix_id"), py::arg("dof_id"), py::arg("dof_manager"), py::arg("type"), py::arg("ghost_type") = _not_ghost); py::class_<IntegrationPoint>(mod, "IntegrationPoint"); } } // namespace akantu diff --git a/python/py_model_couplers.hh b/python/py_model_couplers.hh index 71df41b4d..bb517af36 100644 --- a/python/py_model_couplers.hh +++ b/python/py_model_couplers.hh @@ -1,12 +1,10 @@ +#include <pybind11/pybind11.h> + #ifndef __AKANTU_PY_MODEL_COUPLERS_HH__ #define __AKANTU_PY_MODEL_COUPLERS_HH__ -namespace pybind11 { -struct module; -} // namespace pybind11 - namespace akantu { void register_model_couplers(pybind11::module & mod); } // namespace akantu #endif // __AKANTU_PY_MODEL_COUPLERS_HH__ diff --git a/src/model/contact_mechanics/geometry_utils.hh b/src/model/contact_mechanics/geometry_utils.hh index 935b2157a..8765aec08 100644 --- a/src/model/contact_mechanics/geometry_utils.hh +++ b/src/model/contact_mechanics/geometry_utils.hh @@ -1,152 +1,146 @@ /** * @file geometry_utils.hh * * @author Mohit Pundir <mohit.pundir@epfl.ch> * * @date creation: Mon Sep 30 2019 * @date last modification: Mon Sep 30 2019 * - * @brief class to compute geometry related quantities + * @brief class to compute geometry related quantities * * @section LICENSE * * Copyright (©) 2010-2018 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fe_engine.hh" #include "mesh.hh" /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_GEOMETRY_UTILS_HH__ #define __AKANTU_GEOMETRY_UTILS_HH__ namespace akantu { class GeometryUtils { /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// computes the normal on an element (assuming elements is flat) static void normal(const Mesh & mesh, const Array<Real> & positions, - const Element & element, Vector<Real> & normal, bool outward=true); + const Element & element, Vector<Real> & normal, + bool outward = true); - // computes normal at given covariant basis - static void normal(const Mesh & mesh, const Element & element, Matrix<Real> & covariant_basis, - Vector<Real> & normal, bool outward=true); - + static void normal(const Mesh & mesh, const Element & element, + Matrix<Real> & covariant_basis, Vector<Real> & normal, + bool outward = true); + /// computes the orthogonal projection on a set of elements and /// returns natural projection and normal gap and index of element - static UInt orthogonalProjection(const Mesh & mesh, const Array<Real> & positions, - const Vector<Real> & slave, - const Array<Element> & elements, - Real & gap, Vector<Real> & natural_projection, - Vector<Real> & normal, Real alpha, - UInt max_iterations = 100, - Real tolerance = 1e-10, - Real extension_tolerance = 1e-5); + static UInt + orthogonalProjection(const Mesh & mesh, const Array<Real> & positions, + const Vector<Real> & slave, + const Array<Element> & elements, Real & gap, + Vector<Real> & natural_projection, Vector<Real> & normal, + Real alpha, UInt max_iterations = 100, + Real tolerance = 1e-10, Real extension_tolerance = 1e-5); /// computes the orthogonal projection on a set of elements and /// returns natural projection and normal gap and index of element - static UInt orthogonalProjection(const Mesh & mesh, const Array<Real> & positions, - const Vector<Real> & slave, - const Array<Element> & elements, - Real & gap, Vector<Real> & natural_projection, - Vector<Real> & normal, - Matrix<Real> & tangent, - Real alpha, - UInt max_iterations = 100, - Real tolerance = 1e-10, - Real extension_tolerance = 1e-5); - + static UInt orthogonalProjection( + const Mesh & mesh, const Array<Real> & positions, + const Vector<Real> & slave, const Array<Element> & elements, Real & gap, + Vector<Real> & natural_projection, Vector<Real> & normal, + Matrix<Real> & tangent, Real alpha, UInt max_iterations = 100, + Real tolerance = 1e-10, Real extension_tolerance = 1e-5); /// computes the natural projection on an element - static void naturalProjection(const Mesh & mesh, const Array<Real> & positions, - const Element & element, - const Vector<Real> & slave_coords, - Vector<Real> & master_coords, - Vector<Real> & natural_projection, - UInt max_iterations = 100, - Real tolerance = 1e-10); - + static void + naturalProjection(const Mesh & mesh, const Array<Real> & positions, + const Element & element, const Vector<Real> & slave_coords, + Vector<Real> & master_coords, + Vector<Real> & natural_projection, + UInt max_iterations = 100, Real tolerance = 1e-10); + /// computes the real projection on an element static void realProjection(const Mesh & mesh, const Array<Real> & positions, - const Vector<Real> & slave, const Element & element, - const Vector<Real> & normal, Vector<Real> & projection); + const Vector<Real> & slave, + const Element & element, + const Vector<Real> & normal, + Vector<Real> & projection); /// computes the real projection from a natural coordinate static void realProjection(const Mesh & mesh, const Array<Real> & positions, - const Element & element, const Vector<Real> & natural_coord, - Vector<Real> & projection); - + const Element & element, + const Vector<Real> & natural_coord, + Vector<Real> & projection); + /// computes the covariant basis/ local surface basis/ tangents on projection /// point static void covariantBasis(const Mesh & mesh, const Array<Real> & positions, - const Element & element, Vector<Real> & natural_coord, - Matrix<Real> & basis); + const Element & element, + Vector<Real> & natural_coord, + Matrix<Real> & basis); /// computes the covariant basis/ local surface basis/ tangents on projection /// point static void covariantBasis(const Mesh & mesh, const Array<Real> & positions, - const Element & element, const Vector<Real> & normal, - Vector<Real> & natural_coord, - Matrix<Real> & basis); - + const Element & element, + const Vector<Real> & normal, + Vector<Real> & natural_coord, + Matrix<Real> & basis); + // computes the curvature on projection static void curvature(const Mesh & mesh, const Array<Real> & positions, - const Element & element, const Vector<Real> & natural_coord, - Matrix<Real> & curvature); + const Element & element, + const Vector<Real> & natural_coord, + Matrix<Real> & curvature); - /// computes the contravariant basis on projection point static void contravariantBasis(const Matrix<Real> & covariant, - Matrix<Real> & contravariant); + Matrix<Real> & contravariant); /// computes metric tesnor with covariant components - static Matrix<Real> covariantMetricTensor(const Matrix<Real> & ); + static Matrix<Real> covariantMetricTensor(const Matrix<Real> &); /// computes metric tensor with contravariant components - static Matrix<Real> contravariantMetricTensor(const Matrix<Real> & ); + static Matrix<Real> contravariantMetricTensor(const Matrix<Real> &); // computes curvature tensor with convariant components - static Matrix<Real> covariantCurvatureTensor(const Mesh &, - const Array<Real> &, - const Element &, - const Vector<Real> &, - const Vector<Real> &); - + static Matrix<Real> + covariantCurvatureTensor(const Mesh &, const Array<Real> &, const Element &, + const Vector<Real> &, const Vector<Real> &); + /// checks if the element is truly a boundary element or not - inline static bool isBoundaryElement(const Mesh & mesh, const Element & element); + inline static bool isBoundaryElement(const Mesh & mesh, + const Element & element); /// checks if the natural projection is valid for not - inline static bool isValidProjection(const Vector<Real> & projection, - Real extension_tolerance = 1e-5); - - + inline static bool isValidProjection(const Vector<Real> & projection, + Real extension_tolerance = 1e-5); }; - -} - -#include "geometry_utils_inline_impl.cc" +} // namespace akantu +#include "geometry_utils_inline_impl.cc" #endif /* __AKANTU_GEOMETRY_UTILS_HH__ */