diff --git a/python/py_material.cc b/python/py_material.cc index 6d9d4ec5d..ccf7e5e0d 100644 --- a/python/py_material.cc +++ b/python/py_material.cc @@ -1,235 +1,231 @@ /* -------------------------------------------------------------------------- */ #include "py_aka_array.hh" /* -------------------------------------------------------------------------- */ #include #if defined(AKANTU_COHESIVE_ELEMENT) #include #endif /* -------------------------------------------------------------------------- */ -#define AKANTU_WARNING_IGNORE_VARIADIC_MACRO_ARGUMENTS -#include "aka_warning.hh" -/* -------------------------------------------------------------------------- */ #include #include #include /* -------------------------------------------------------------------------- */ namespace py = pybind11; /* -------------------------------------------------------------------------- */ #if not defined(PYBIND11_OVERRIDE) #define PYBIND11_OVERRIDE PYBIND11_OVERLOAD #define PYBIND11_OVERRIDE_PURE PYBIND11_OVERLOAD_PURE #endif namespace akantu { template class PyMaterial : public _Material { public: /* Inherit the constructors */ using _Material::_Material; ~PyMaterial() override = default; void initMaterial() override { - PYBIND11_OVERRIDE(void, _Material, initMaterial); // NOLINT + PYBIND11_OVERRIDE(void, _Material, initMaterial, ); // NOLINT }; void computeStress(ElementType el_type, GhostType ghost_type = _not_ghost) override { PYBIND11_OVERRIDE_PURE(void, _Material, computeStress, el_type, ghost_type); } void computeTangentModuli(ElementType el_type, Array & tangent_matrix, GhostType ghost_type = _not_ghost) override { PYBIND11_OVERRIDE(void, _Material, computeTangentModuli, el_type, tangent_matrix, ghost_type); } void computePotentialEnergy(ElementType el_type) override { PYBIND11_OVERRIDE(void, _Material, computePotentialEnergy, el_type); } Real getPushWaveSpeed(const Element & element) const override { PYBIND11_OVERRIDE(Real, _Material, getPushWaveSpeed, element); } Real getShearWaveSpeed(const Element & element) const override { PYBIND11_OVERRIDE(Real, _Material, getShearWaveSpeed, element); } void registerInternal(const std::string & name, UInt nb_component) { this->internals[name] = std::make_shared>(name, *this); AKANTU_DEBUG_INFO("alloc internal " << name << " " << &this->internals[name]); this->internals[name]->initialize(nb_component); } auto & getInternals() { return this->internals; } protected: std::map>> internals; }; /* -------------------------------------------------------------------------- */ template void register_element_type_map_array(py::module & mod, const std::string & name) { py::class_, std::shared_ptr>>( mod, ("ElementTypeMapArray" + name).c_str()) .def( "__call__", [](ElementTypeMapArray & self, ElementType type, GhostType ghost_type) -> decltype(auto) { return self(type, ghost_type); }, py::arg("type"), py::arg("ghost_type") = _not_ghost, py::return_value_policy::reference) .def( "elementTypes", [](ElementTypeMapArray & self, UInt _dim, GhostType _ghost_type, ElementKind _kind) -> decltype(auto) { auto types = self.elementTypes(_dim, _ghost_type, _kind); std::vector _types; for (auto && t : types) { _types.push_back(t); } return _types; }, py::arg("dim") = _all_dimensions, py::arg("ghost_type") = _not_ghost, py::arg("kind") = _ek_regular); py::class_, ElementTypeMapArray, std::shared_ptr>>( mod, ("InternalField" + name).c_str()); } /* -------------------------------------------------------------------------- */ template void define_material(py::module & mod, const std::string & name) { py::class_<_Material, PyMaterial<_Material>, Parsable>( mod, name.c_str(), py::multiple_inheritance()) .def(py::init()) .def( "getGradU", [](Material & self, ElementType el_type, GhostType ghost_type = _not_ghost) -> decltype(auto) { return self.getGradU(el_type, ghost_type); }, py::arg("el_type"), py::arg("ghost_type") = _not_ghost, py::return_value_policy::reference) .def( "getStress", [](Material & self, ElementType el_type, GhostType ghost_type = _not_ghost) -> decltype(auto) { return self.getStress(el_type, ghost_type); }, py::arg("el_type"), py::arg("ghost_type") = _not_ghost, py::return_value_policy::reference) .def( "getPotentialEnergy", [](Material & self, ElementType el_type) -> decltype(auto) { return self.getPotentialEnergy(el_type); }, py::return_value_policy::reference) .def("initMaterial", &Material::initMaterial) .def("getModel", &Material::getModel) .def("registerInternal", [](Material & self, const std::string & name, UInt nb_component) { return dynamic_cast &>(self).registerInternal( name, nb_component); }) .def( "getInternalFieldReal", [](Material & self, const ID & id, const ElementType & type, const GhostType & ghost_type) -> Array & { return self.getArray(id, type, ghost_type); }, py::arg("id"), py::arg("type"), py::arg("ghost_type") = _not_ghost) .def( "getInternalFieldUInt", [](Material & self, const ID & id, const ElementType & type, const GhostType & ghost_type) -> Array & { return self.getArray(id, type, ghost_type); }, py::arg("id"), py::arg("type"), py::arg("ghost_type") = _not_ghost) .def( "getElementFilter", [](Material & self, const ElementType & type, const GhostType & ghost_type) -> const Array & { return self.getElementFilter()(type, ghost_type); }, py::arg("type"), py::arg("ghost_type") = _not_ghost); } /* -------------------------------------------------------------------------- */ void register_material(py::module & mod) { py::class_(mod, "MaterialFactory") .def_static( "getInstance", []() -> MaterialFactory & { return Material::getFactory(); }, py::return_value_policy::reference) .def("registerAllocator", [](MaterialFactory & self, const std::string id, py::function func) { self.registerAllocator( id, [func, id](UInt dim, const ID & /*unused*/, SolidMechanicsModel & model, const ID & option) -> std::unique_ptr { py::object obj = func(dim, id, model, option); auto & ptr = py::cast(obj); obj.release(); return std::unique_ptr(&ptr); }); }); register_element_type_map_array(mod, "Real"); register_element_type_map_array(mod, "UInt"); define_material(mod, "Material"); py::class_>( mod, "MaterialSelector") .def("setFallback", [](MaterialSelector & self, UInt f) { self.setFallback(f); }) .def("setFallback", [](MaterialSelector & self, const std::shared_ptr & fallback_selector) { self.setFallback(fallback_selector); }) .def("setFallback", [](MaterialSelector & self, MaterialSelector & fallback_selector) { self.setFallback(fallback_selector); }); py::class_, MaterialSelector, std::shared_ptr>>( mod, "MeshDataMaterialSelectorString") .def(py::init(), py::arg("name"), py::arg("model"), py::arg("first_index") = 1); #if defined(AKANTU_COHESIVE_ELEMENT) py::class_>( mod, "DefaultMaterialCohesiveSelector") .def(py::init()); py::class_>( mod, "MeshDataMaterialCohesiveSelector") .def(py::init()); py::class_>( mod, "MaterialCohesiveRulesSelector") .def(py::init(), py::arg("model"), py::arg("rules"), py::arg("mesh_data_id") = "physical_names"); #endif } } // namespace akantu -#include "aka_warning_restore.hh" diff --git a/src/common/aka_warning.hh b/src/common/aka_warning.hh index f4dbe00ad..a8b6cd264 100644 --- a/src/common/aka_warning.hh +++ b/src/common/aka_warning.hh @@ -1,66 +1,67 @@ /** * @file aka_warning.hh * * @author Nicolas Richart * * @date creation: Mon Nov 14 2016 * @date last modification: Fri Dec 02 2016 * * @brief file to include to remove some warnings * * * Copyright (©) 2016-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 . * */ /** AKANTU_WARNING_IGNORE_UNUSED_PARAMETER AKANTU_WARNING_IGNORE_VARIADIC_MACRO_ARGUMENTS **/ // --- Intel warnings ---------------------------------------------------------- #if defined(__INTEL_COMPILER) # if defined(AKANTU_WARNING_IGNORE_UNUSED_PARAMETER) # endif // --- Clang Warnings ---------------------------------------------------------- #elif defined(__clang__) // test clang to be sure that when we test for gnu it // is only gnu # pragma clang diagnostic push # if defined(AKANTU_WARNING_IGNORE_UNUSED_PARAMETER) # pragma clang diagnostic ignored "-Wunused-parameter" # endif # if defined(AKANTU_WARNING_IGNORE_VARIADIC_MACRO_ARGUMENTS) # pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" # endif // --- GCC warnings ------------------------------------------------------------ #elif (defined(__GNUC__) || defined(__GNUG__)) # define GCC_VERSION \ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) # if GCC_VERSION > 40600 # pragma GCC diagnostic push # endif # if defined(AKANTU_WARNING_IGNORE_UNUSED_PARAMETER) # pragma GCC diagnostic ignored "-Wunused-parameter" # endif # if defined(AKANTU_WARNING_IGNORE_VARIADIC_MACRO_ARGUMENTS) +# pragma GCC diagnostic ignored "-Wvariadic-macros" # pragma GCC diagnostic ignored "-Wpedantic" # endif #endif