diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 10e17d989..65c3e3520 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,88 +1,96 @@ #=============================================================================== # @file CMakeLists.txt # # @author Nicolas Richart # # @date creation: Fri Dec 12 2014 # @date last modification: Mon Jan 18 2016 # # @brief CMake file for the python wrapping of akantu # # @section LICENSE # # Copyright (©) 2015 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 . # #=============================================================================== set(PYAKANTU_SRCS py_aka_common.cc py_aka_error.cc py_akantu.cc py_boundary_conditions.cc py_fe_engine.cc py_group_manager.cc py_mesh.cc py_model.cc py_parser.cc ) package_is_activated(iohelper _is_activated) if (_is_activated) list(APPEND PYAKANTU_SRCS py_dumpable.cc ) endif() package_is_activated(solid_mechanics _is_activated) if (_is_activated) list(APPEND PYAKANTU_SRCS py_solid_mechanics_model.cc py_material.cc ) endif() package_is_activated(cohesive_element _is_activated) if (_is_activated) list(APPEND PYAKANTU_SRCS py_solid_mechanics_model_cohesive.cc ) endif() package_is_activated(heat_transfer _is_activated) if (_is_activated) list(APPEND PYAKANTU_SRCS py_heat_transfer_model.cc ) endif() +package_is_activated(phase_field _is_activated) +if (_is_activated) + list(APPEND PYAKANTU_SRCS + py_phase_field_model.cc + ) +endif() + + pybind11_add_module(py11_akantu ${PYAKANTU_SRCS}) target_link_libraries(py11_akantu PRIVATE akantu pybind11) target_include_directories(py11_akantu INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(py11_akantu PROPERTIES DEBUG_POSTFIX "") set(_python_install_dir ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages) install(TARGETS py11_akantu LIBRARY DESTINATION ${_python_install_dir}) install(DIRECTORY akantu DESTINATION ${_python_install_dir} FILES_MATCHING PATTERN "*.py") diff --git a/python/py_akantu.cc b/python/py_akantu.cc index 85045b1cf..4e768b100 100644 --- a/python/py_akantu.cc +++ b/python/py_akantu.cc @@ -1,89 +1,99 @@ /* -------------------------------------------------------------------------- */ #include "aka_config.hh" /* -------------------------------------------------------------------------- */ #include "py_aka_common.hh" #include "py_aka_error.hh" #include "py_boundary_conditions.hh" #include "py_fe_engine.hh" #include "py_group_manager.hh" #include "py_mesh.hh" #include "py_model.hh" #include "py_parser.hh" #if defined(AKANTU_USE_IOHELPER) #include "py_dumpable.hh" #endif #if defined(AKANTU_SOLID_MECHANICS) #include "py_material.hh" #include "py_solid_mechanics_model.hh" #endif #if defined(AKANTU_HEAT_TRANSFER) #include "py_heat_transfer_model.hh" #endif #if defined(AKANTU_COHESIVE_ELEMENT) #include "py_solid_mechanics_model_cohesive.hh" #endif + + +#if defined(AKANTU_PHASE_FIELD) +#include "py_phase_field_model.hh" +#endif + /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ namespace py = pybind11; namespace akantu { void register_all(pybind11::module & mod) { register_initialize(mod); register_enums(mod); register_error(mod); register_functions(mod); register_parser(mod); register_group_manager(mod); #if defined(AKANTU_USE_IOHELPER) register_dumpable(mod); #endif register_mesh(mod); register_fe_engine(mod); register_boundary_conditions(mod); register_model(mod); #if defined(AKANTU_HEAT_TRANSFER) register_heat_transfer_model(mod); #endif #if defined(AKANTU_SOLID_MECHANICS) register_solid_mechanics_model(mod); register_material(mod); #endif #if defined(AKANTU_COHESIVE_ELEMENT) register_solid_mechanics_model_cohesive(mod); #endif + +#if defined(AKANTU_PHASE_FIELD) + register_phase_field_model(mod); +#endif } } // namespace akantu /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ PYBIND11_MODULE(py11_akantu, mod) { mod.doc() = "Akantu python interface"; static py::exception akantu_exception(mod, "Exception"); py::register_exception_translator([](std::exception_ptr p) { try { if (p) std::rethrow_exception(p); } catch (akantu::debug::Exception & e) { if (akantu::debug::debugger.printBacktrace()) akantu::debug::printBacktrace(15); akantu_exception(e.info().c_str()); } }); akantu::register_all(mod); } // Module akantu diff --git a/python/py_phase_field_model.cc b/python/py_phase_field_model.cc new file mode 100644 index 000000000..61cd00ff0 --- /dev/null +++ b/python/py_phase_field_model.cc @@ -0,0 +1,99 @@ +/* -------------------------------------------------------------------------- */ +#include "py_aka_array.hh" +/* -------------------------------------------------------------------------- */ +#include +#include +/* -------------------------------------------------------------------------- */ +#include +/* -------------------------------------------------------------------------- */ +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, \ + [](PhaseFieldModel & self) -> decltype(auto) { \ + return self.func_name(); \ + }, \ + py::return_value_policy::reference) + +#define def_function(func_name) \ + def(#func_name, [](PhaseFieldModel & self) -> decltype(auto) { \ + return self.func_name(); \ + }) +/* -------------------------------------------------------------------------- */ + + +[[gnu::visibility("default")]] void +register_phase_field_model(py::module & mod) { + + py::class_(mod, "PhaseFieldModelOptions") + .def(py::init(), + py::arg("analysis_method") = _static); + + + py::class_(mod, "PhaseFieldModel", + py::multiple_inheritance()) + .def(py::init(), + py::arg("mesh"), py::arg("spatial_dimension") = _all_dimensions, + py::arg("id") = "phase_field_model", py::arg("memory_id") = 0, + py::arg("model_type") = ModelType::_phase_field_model) + .def("initFull", + [](PhaseFieldModel & self, + const PhaseFieldModelOptions & options) { + self.initFull(options); + }, + py::arg("_analysis_method") = PhaseFieldModelOptions()) + .def("initFull", + [](PhaseFieldModel & self, + const AnalysisMethod & analysis_method) { + self.initFull(_analysis_method = analysis_method); + }, + py::arg("_analysis_method")) + .def_deprecated("applyDirichletBC", "Deprecated: use applyBC") + .def("applyBC", + [](PhaseFieldModel & self, + BC::Dirichlet::DirichletFunctor & func, + const std::string & element_group) { + self.applyBC(func, element_group); + }) + .def("applyBC", + [](PhaseFieldModel & self, BC::Neumann::NeumannFunctor & func, + const std::string & element_group) { + self.applyBC(func, element_group); + }) + .def("setTimeStep", &PhaseFieldModel::setTimeStep, + py::arg("time_step"), py::arg("solver_id") = "") + .def_function(assembleStiffnessMatrix) + .def_function(assembleInternalForces) + .def_function_nocopy(getDamage) + .def_function_nocopy(getInternalForce) + .def_function_nocopy(getBlockedDOFs) + .def_function_nocopy(getMesh) + .def("dump", py::overload_cast<>(&PhaseFieldModel::dump)) + .def("dump", + py::overload_cast(&PhaseFieldModel::dump)) + .def("dump", py::overload_cast( + &PhaseFieldModel::dump)) + .def("dump", py::overload_cast( + &PhaseFieldModel::dump)) + .def("getPhaseField", + py::overload_cast(&PhaseFieldModel::getPhaseField), + py::return_value_policy::reference) + .def("getPhaseField", + py::overload_cast( + &PhaseFieldModel::getPhaseField), + py::return_value_policy::reference) + .def("getPhaseFieldIndex", &PhaseFieldModel::getPhaseFieldIndex) + .def("setPhaseFieldSelector", &PhaseFieldModel::setPhaseFieldSelector); + +} + + +} diff --git a/python/py_phase_field_model.hh b/python/py_phase_field_model.hh new file mode 100644 index 000000000..3024da69c --- /dev/null +++ b/python/py_phase_field_model.hh @@ -0,0 +1,12 @@ +#ifndef __AKANTU_PY_PHASE_FIELD_MODEL_HH__ +#define __AKANTU_PY_PHASE_FIELD_MODEL_HH__ + +namespace pybind11 { + struct module; +}//namespace pybind11 + +namespace akantu { + void register_phase_field_model(pybind11::module & mod); +} // namespace akantu + +#endif // __AKANTU_PY_PHASE_FIELD_MODEL_HH__