diff --git a/packages/core.cmake b/packages/core.cmake index d871e30b8..29c556261 100644 --- a/packages/core.cmake +++ b/packages/core.cmake @@ -1,531 +1,532 @@ #=============================================================================== # @file core.cmake # # @author Guillaume Anciaux # @author Nicolas Richart # # @date creation: Mon Nov 21 2011 # @date last modification: Mon Jan 18 2016 # # @brief package description for core # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 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 . # #=============================================================================== package_declare(core NOT_OPTIONAL DESCRIPTION "core package for Akantu" FEATURES_PUBLIC cxx_strong_enums cxx_defaulted_functions cxx_deleted_functions cxx_auto_type cxx_decltype_auto FEATURES_PRIVATE cxx_lambdas cxx_nullptr cxx_range_for cxx_delegating_constructors DEPENDS INTERFACE akantu_iterators Boost) package_declare_sources(core common/aka_array.cc common/aka_array.hh common/aka_array_tmpl.hh common/aka_array_printer.hh common/aka_bbox.hh common/aka_blas_lapack.hh common/aka_circular_array.hh common/aka_circular_array_inline_impl.hh common/aka_common.cc common/aka_common.hh common/aka_common_inline_impl.hh common/aka_csr.hh common/aka_element_classes_info_inline_impl.hh common/aka_enum_macros.hh common/aka_error.cc common/aka_error.hh common/aka_event_handler_manager.hh common/aka_extern.cc common/aka_factory.hh common/aka_fwd.hh common/aka_grid_dynamic.hh common/aka_math.cc common/aka_math.hh common/aka_math_tmpl.hh common/aka_named_argument.hh common/aka_random_generator.hh common/aka_safe_enum.hh common/aka_typelist.hh common/aka_types.hh common/aka_visitor.hh common/aka_voigthelper.hh common/aka_voigthelper_tmpl.hh common/aka_voigthelper.cc common/aka_warning.hh common/aka_warning_restore.hh fe_engine/element_class.hh fe_engine/element_class_tmpl.hh fe_engine/element_classes/element_class_hexahedron_8_inline_impl.hh fe_engine/element_classes/element_class_hexahedron_20_inline_impl.hh fe_engine/element_classes/element_class_pentahedron_6_inline_impl.hh fe_engine/element_classes/element_class_pentahedron_15_inline_impl.hh fe_engine/element_classes/element_class_point_1_inline_impl.hh fe_engine/element_classes/element_class_quadrangle_4_inline_impl.hh fe_engine/element_classes/element_class_quadrangle_8_inline_impl.hh fe_engine/element_classes/element_class_segment_2_inline_impl.hh fe_engine/element_classes/element_class_segment_3_inline_impl.hh fe_engine/element_classes/element_class_tetrahedron_10_inline_impl.hh fe_engine/element_classes/element_class_tetrahedron_4_inline_impl.hh fe_engine/element_classes/element_class_triangle_3_inline_impl.hh fe_engine/element_classes/element_class_triangle_6_inline_impl.hh fe_engine/element_type_conversion.hh fe_engine/fe_engine.cc fe_engine/fe_engine.hh fe_engine/fe_engine_inline_impl.hh fe_engine/fe_engine_template.hh fe_engine/fe_engine_template_tmpl_field.hh fe_engine/fe_engine_template_tmpl.hh fe_engine/geometrical_element_property.hh fe_engine/geometrical_element_property.cc fe_engine/gauss_integration.cc fe_engine/gauss_integration_tmpl.hh fe_engine/integrator.hh fe_engine/integrator_gauss.hh fe_engine/integrator_gauss_inline_impl.hh fe_engine/interpolation_element_tmpl.hh fe_engine/integration_point.hh fe_engine/shape_functions.hh fe_engine/shape_functions.cc fe_engine/shape_functions_inline_impl.hh fe_engine/shape_lagrange_base.cc fe_engine/shape_lagrange_base.hh fe_engine/shape_lagrange_base_inline_impl.hh fe_engine/shape_lagrange.hh fe_engine/shape_lagrange_inline_impl.hh fe_engine/element.hh io/dumper/dumpable.hh io/dumper/dumpable.cc io/dumper/dumpable_dummy.hh io/dumper/dumpable_inline_impl.hh io/dumper/dumper_field.hh io/dumper/dumper_material_padders.hh io/dumper/dumper_filtered_connectivity.hh io/dumper/dumper_element_partition.hh io/mesh_io.cc io/mesh_io.hh io/mesh_io/mesh_io_diana.cc io/mesh_io/mesh_io_diana.hh io/mesh_io/mesh_io_msh.cc io/mesh_io/mesh_io_msh.hh io/parser/algebraic_parser.hh io/parser/input_file_parser.hh io/parser/parsable.cc io/parser/parsable.hh io/parser/parser.cc io/parser/parser_real.cc io/parser/parser_random.cc io/parser/parser_types.cc io/parser/parser_input_files.cc io/parser/parser.hh io/parser/parser_tmpl.hh io/parser/parser_grammar_tmpl.hh io/parser/cppargparse/cppargparse.hh io/parser/cppargparse/cppargparse.cc io/parser/cppargparse/cppargparse_tmpl.hh io/parser/parameter_registry.cc io/parser/parameter_registry.hh io/parser/parameter_registry_tmpl.hh mesh/element_group.cc mesh/element_group.hh mesh/element_group_inline_impl.hh mesh/element_type_map.cc mesh/element_type_map.hh mesh/element_type_map_tmpl.hh mesh/element_type_map_filter.hh mesh/group_manager.cc mesh/group_manager.hh mesh/group_manager_inline_impl.hh mesh/mesh.cc mesh/mesh.hh mesh/mesh_periodic.cc mesh/mesh_accessor.hh mesh/mesh_events.hh mesh/mesh_filter.hh mesh/mesh_global_data_updater.hh mesh/mesh_data.cc mesh/mesh_data.hh mesh/mesh_data_tmpl.hh mesh/mesh_inline_impl.hh mesh/node_group.cc mesh/node_group.hh mesh/node_group_inline_impl.hh mesh/mesh_iterators.hh mesh_utils/mesh_partition.cc mesh_utils/mesh_partition.hh mesh_utils/mesh_partition/mesh_partition_mesh_data.cc mesh_utils/mesh_partition/mesh_partition_mesh_data.hh mesh_utils/mesh_partition/mesh_partition_scotch.hh mesh_utils/mesh_utils_pbc.cc mesh_utils/mesh_utils.cc mesh_utils/mesh_utils.hh mesh_utils/mesh_utils_distribution.cc mesh_utils/mesh_utils_distribution.hh mesh_utils/mesh_utils.hh mesh_utils/mesh_utils_inline_impl.hh mesh_utils/global_ids_updater.hh mesh_utils/global_ids_updater.cc mesh_utils/global_ids_updater_inline_impl.hh model/common/boundary_condition/boundary_condition.hh model/common/boundary_condition/boundary_condition_functor.hh model/common/boundary_condition/boundary_condition_functor_inline_impl.hh model/common/boundary_condition/boundary_condition_tmpl.hh model/common/constitutive_laws/constitutive_law_non_local_interface.hh model/common/constitutive_laws/constitutive_law_non_local_interface_tmpl.hh model/common/constitutive_laws/constitutive_law.hh + model/common/constitutive_laws/constitutive_law_selector.hh model/common/constitutive_laws/constitutive_law_tmpl.hh model/common/constitutive_laws/constitutive_laws_handler.hh model/common/constitutive_laws/constitutive_laws_handler_tmpl.hh model/common/constitutive_laws/internal_field.hh model/common/constitutive_laws/internal_field_tmpl.hh model/common/constitutive_laws/random_internal_field.hh model/common/constitutive_laws/random_internal_field_tmpl.hh model/common/non_local_toolbox/neighborhood_base.hh model/common/non_local_toolbox/neighborhood_base.cc model/common/non_local_toolbox/neighborhood_base_inline_impl.hh model/common/non_local_toolbox/neighborhoods_criterion_evaluation/neighborhood_max_criterion.hh model/common/non_local_toolbox/neighborhoods_criterion_evaluation/neighborhood_max_criterion.cc model/common/non_local_toolbox/neighborhoods_criterion_evaluation/neighborhood_max_criterion_inline_impl.hh model/common/non_local_toolbox/non_local_manager.hh model/common/non_local_toolbox/non_local_manager.cc model/common/non_local_toolbox/non_local_manager_inline_impl.hh model/common/non_local_toolbox/non_local_manager_callback.hh model/common/non_local_toolbox/non_local_neighborhood_base.hh model/common/non_local_toolbox/non_local_neighborhood_base.cc model/common/non_local_toolbox/non_local_neighborhood.hh model/common/non_local_toolbox/non_local_neighborhood_tmpl.hh model/common/non_local_toolbox/non_local_neighborhood_inline_impl.hh model/common/non_local_toolbox/base_weight_function.hh model/common/non_local_toolbox/base_weight_function_inline_impl.hh model/common/model_solver.cc model/common/model_solver.hh model/common/solver_callback.hh model/common/solver_callback.cc model/common/dof_manager/dof_manager.cc model/common/dof_manager/dof_manager.hh model/common/dof_manager/dof_manager_default.cc model/common/dof_manager/dof_manager_default.hh model/common/dof_manager/dof_manager_default_inline_impl.hh model/common/dof_manager/dof_manager_inline_impl.hh model/common/non_linear_solver/non_linear_solver.cc model/common/non_linear_solver/non_linear_solver.hh model/common/non_linear_solver/non_linear_solver_default.hh model/common/non_linear_solver/non_linear_solver_lumped.cc model/common/non_linear_solver/non_linear_solver_lumped.hh model/common/time_step_solvers/time_step_solver.hh model/common/time_step_solvers/time_step_solver.cc model/common/time_step_solvers/time_step_solver_default.cc model/common/time_step_solvers/time_step_solver_default.hh model/common/time_step_solvers/time_step_solver_default_explicit.hh model/common/integration_scheme/generalized_trapezoidal.cc model/common/integration_scheme/generalized_trapezoidal.hh model/common/integration_scheme/integration_scheme.cc model/common/integration_scheme/integration_scheme.hh model/common/integration_scheme/integration_scheme_1st_order.cc model/common/integration_scheme/integration_scheme_1st_order.hh model/common/integration_scheme/integration_scheme_2nd_order.cc model/common/integration_scheme/integration_scheme_2nd_order.hh model/common/integration_scheme/newmark-beta.cc model/common/integration_scheme/newmark-beta.hh model/common/integration_scheme/pseudo_time.cc model/common/integration_scheme/pseudo_time.hh model/model.cc model/model.hh model/model_inline_impl.hh model/model_options.hh solver/solver_vector.hh solver/solver_vector_default.cc solver/solver_vector_default.hh solver/solver_vector_default_tmpl.hh solver/solver_vector_distributed.cc solver/solver_vector_distributed.hh solver/sparse_matrix.cc solver/sparse_matrix.hh solver/sparse_matrix_aij.cc solver/sparse_matrix_aij.hh solver/sparse_matrix_aij_inline_impl.hh solver/sparse_matrix_inline_impl.hh solver/sparse_solver.cc solver/sparse_solver.hh solver/sparse_solver_inline_impl.hh solver/terms_to_assemble.hh synchronizer/communication_buffer_inline_impl.hh synchronizer/communication_descriptor.hh synchronizer/communication_descriptor_tmpl.hh synchronizer/communication_request.hh synchronizer/communication_tag.hh synchronizer/communications.hh synchronizer/communications_tmpl.hh synchronizer/communicator.cc synchronizer/communicator.hh synchronizer/communicator_dummy_inline_impl.hh synchronizer/communicator_event_handler.hh synchronizer/communicator_inline_impl.hh synchronizer/data_accessor.cc synchronizer/data_accessor.hh synchronizer/dof_synchronizer.cc synchronizer/dof_synchronizer.hh synchronizer/dof_synchronizer_inline_impl.hh synchronizer/element_info_per_processor.cc synchronizer/element_info_per_processor.hh synchronizer/element_info_per_processor_tmpl.hh synchronizer/element_synchronizer.cc synchronizer/element_synchronizer.hh synchronizer/facet_synchronizer.cc synchronizer/facet_synchronizer.hh synchronizer/facet_synchronizer_inline_impl.hh synchronizer/grid_synchronizer.cc synchronizer/grid_synchronizer.hh synchronizer/grid_synchronizer_tmpl.hh synchronizer/master_element_info_per_processor.cc synchronizer/node_info_per_processor.cc synchronizer/node_info_per_processor.hh synchronizer/node_synchronizer.cc synchronizer/node_synchronizer.hh synchronizer/node_synchronizer_inline_impl.hh synchronizer/periodic_node_synchronizer.cc synchronizer/periodic_node_synchronizer.hh synchronizer/slave_element_info_per_processor.cc synchronizer/synchronizer.cc synchronizer/synchronizer.hh synchronizer/synchronizer_impl.hh synchronizer/synchronizer_impl_tmpl.hh synchronizer/synchronizer_registry.cc synchronizer/synchronizer_registry.hh synchronizer/synchronizer_tmpl.hh synchronizer/communication_buffer.hh ) set(AKANTU_SPIRIT_SOURCES io/mesh_io/mesh_io_abaqus.cc io/parser/parser_real.cc io/parser/parser_random.cc io/parser/parser_types.cc io/parser/parser_input_files.cc PARENT_SCOPE ) package_declare_elements(core ELEMENT_TYPES _point_1 _segment_2 _segment_3 _triangle_3 _triangle_6 _quadrangle_4 _quadrangle_8 _tetrahedron_4 _tetrahedron_10 _pentahedron_6 _pentahedron_15 _hexahedron_8 _hexahedron_20 KIND regular GEOMETRICAL_TYPES _gt_point _gt_segment_2 _gt_segment_3 _gt_triangle_3 _gt_triangle_6 _gt_quadrangle_4 _gt_quadrangle_8 _gt_tetrahedron_4 _gt_tetrahedron_10 _gt_hexahedron_8 _gt_hexahedron_20 _gt_pentahedron_6 _gt_pentahedron_15 INTERPOLATION_TYPES _itp_lagrange_point_1 _itp_lagrange_segment_2 _itp_lagrange_segment_3 _itp_lagrange_triangle_3 _itp_lagrange_triangle_6 _itp_lagrange_quadrangle_4 _itp_serendip_quadrangle_8 _itp_lagrange_tetrahedron_4 _itp_lagrange_tetrahedron_10 _itp_lagrange_hexahedron_8 _itp_serendip_hexahedron_20 _itp_lagrange_pentahedron_6 _itp_lagrange_pentahedron_15 GEOMETRICAL_SHAPES _gst_point _gst_triangle _gst_square _gst_prism GAUSS_INTEGRATION_TYPES _git_point _git_segment _git_triangle _git_tetrahedron _git_pentahedron INTERPOLATION_KIND _itk_lagrangian FE_ENGINE_LISTS gradient_on_integration_points interpolate_on_integration_points interpolate compute_normals_on_integration_points inverse_map contains compute_shapes compute_shapes_derivatives get_shapes_derivatives lagrange_base assemble_fields ) package_declare_documentation_files(core manual.sty manual.cls manual.tex manual-macros.sty manual-titlepages.tex manual-authors.tex manual-changelog.tex manual-introduction.tex manual-gettingstarted.tex manual-io.tex manual-feengine.tex manual-elements.tex manual-appendix-elements.tex manual-appendix-packages.tex manual-backmatter.tex manual-bibliography.bib manual-bibliographystyle.bst figures/bc_and_ic_example.pdf figures/boundary.pdf figures/boundary.svg figures/dirichlet.pdf figures/dirichlet.svg # figures/doc_wheel.pdf # figures/doc_wheel.svg figures/hot-point-1.png figures/hot-point-2.png figures/insertion.pdf figures/interpolate.pdf figures/interpolate.svg figures/vectors.pdf figures/vectors.svg figures/elements/hexahedron_8.pdf figures/elements/hexahedron_8.svg figures/elements/quadrangle_4.pdf figures/elements/quadrangle_4.svg figures/elements/quadrangle_8.pdf figures/elements/quadrangle_8.svg figures/elements/segment_2.pdf figures/elements/segment_2.svg figures/elements/segment_3.pdf figures/elements/segment_3.svg figures/elements/tetrahedron_10.pdf figures/elements/tetrahedron_10.svg figures/elements/tetrahedron_4.pdf figures/elements/tetrahedron_4.svg figures/elements/triangle_3.pdf figures/elements/triangle_3.svg figures/elements/triangle_6.pdf figures/elements/triangle_6.svg figures/elements/xtemp.pdf ) package_declare_documentation(core "This package is the core engine of \\akantu. It depends on:" "\\begin{itemize}" "\\item A C++ compiler (\\href{http://gcc.gnu.org/}{GCC} >= 4, or \\href{https://software.intel.com/en-us/intel-compilers}{Intel})." "\\item The cross-platform, open-source \\href{http://www.cmake.org/}{CMake} build system." "\\item The \\href{http://www.boost.org/}{Boost} C++ portable libraries." "\\item The \\href{http://www.zlib.net/}{zlib} compression library." "\\end{itemize}" "" "Under Ubuntu (14.04 LTS) the installation can be performed using the commands:" "\\begin{command}" " > sudo apt-get install cmake libboost-dev zlib1g-dev g++" "\\end{command}" "" "Under Mac OS X the installation requires the following steps:" "\\begin{itemize}" "\\item Install Xcode" "\\item Install the command line tools." "\\item Install the MacPorts project which allows to automatically" "download and install opensource packages." "\\end{itemize}" "Then the following commands should be typed in a terminal:" "\\begin{command}" " > sudo port install cmake gcc48 boost" "\\end{command}" ) find_program(READLINK_COMMAND readlink) find_program(ADDR2LINE_COMMAND addr2line) find_program(PATCH_COMMAND patch) mark_as_advanced(READLINK_COMMAND) mark_as_advanced(ADDR2LINE_COMMAND) package_declare_extra_files_to_package(core SOURCES common/aka_element_classes_info.hh.in common/aka_config.hh.in ) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.9)) package_set_compile_flags(core CXX "-Wno-undefined-var-template") endif() if(DEFINED AKANTU_CXX11_FLAGS) package_declare(core_cxx11 NOT_OPTIONAL DESCRIPTION "C++ 11 additions for Akantu core" COMPILE_FLAGS CXX "${AKANTU_CXX11_FLAGS}") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.6") set(AKANTU_CORE_CXX11 OFF CACHE BOOL "C++ 11 additions for Akantu core - not supported by the selected compiler" FORCE) endif() endif() package_declare_documentation(core_cxx11 "This option activates some features of the C++11 standard. This is usable with GCC>=4.7 or Intel>=13.") else() if(CMAKE_VERSION VERSION_LESS 3.1) message(FATAL_ERROR "Since version 3.0 Akantu requires at least c++11 capable compiler") endif() endif() diff --git a/python/py_material.cc b/python/py_material.cc index a35063a47..dd82b7bd8 100644 --- a/python/py_material.cc +++ b/python/py_material.cc @@ -1,207 +1,204 @@ /* -------------------------------------------------------------------------- */ #include "py_aka_array.hh" /* -------------------------------------------------------------------------- */ #include #if defined(AKANTU_COHESIVE_ELEMENT) #include #endif /* -------------------------------------------------------------------------- */ #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 }; 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); } template void registerInternal(const std::string & name, UInt nb_component) { auto && internal = std::make_shared>(name, *this); - AKANTU_DEBUG_INFO("alloc internal " << name << " " - << &this->internals[name]); + this->registerInternal(internal); + + AKANTU_DEBUG_INFO("Allocate internal " << name << " " + << &this->internals[name]); internal->initialize(nb_component); - this->internals[name] = internal; } - -protected: - std::map> internals; }; /* -------------------------------------------------------------------------- */ template -void register_internal_field(py::module & mod, - const std::string & name) { - py::class_, ElementTypeMapArray, +void register_internal_field(py::module & mod, const std::string & name) { + py::class_, InternalFieldBase, 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("registerInternalReal", [](Material & self, const std::string & name, UInt nb_component) { return dynamic_cast &>(self) .registerInternal(name, nb_component); }) .def("registerInternalUInt", [](Material & self, const std::string & name, UInt nb_component) { return dynamic_cast &>(self) .registerInternal(name, nb_component); }) .def( "getInternalReal", [](Material & self, const ID & id) -> decltype(auto) { return self.getInternal(id); }, py::arg("id"), py::return_value_policy::reference) .def( "getInternalUInt", [](Material & self, const ID & id) -> decltype(auto) { return self.getInternal(id); }, py::arg("id"), py::return_value_policy::reference) .def( "getElementFilter", [](Material & self) -> decltype(auto) { return self.getElementFilter(); }, py::return_value_policy::reference); } /* -------------------------------------------------------------------------- */ 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_internal_field(mod, "Real"); register_internal_field(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 diff --git a/src/model/common/constitutive_laws/constitutive_law.hh b/src/model/common/constitutive_laws/constitutive_law.hh index 61fb1ea44..a07f9c71f 100644 --- a/src/model/common/constitutive_laws/constitutive_law.hh +++ b/src/model/common/constitutive_laws/constitutive_law.hh @@ -1,196 +1,220 @@ /** * @file constitutive_law.hh * * @author Daniel Pino Muñoz * @author Nicolas Richart * @author Marco Vocialta * * @date creation: Fri Jun 18 2010 * @date last modification: Wed Feb 21 2018 * * @brief Mother class for all constitutive laws * * * 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 . * */ /* -------------------------------------------------------------------------- */ #include "data_accessor.hh" #include "mesh_events.hh" #include "parsable.hh" #include "parser.hh" /* -------------------------------------------------------------------------- */ #include "internal_field.hh" #include "random_internal_field.hh" /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_CONSTITUTIVE_LAW_HH__ #define __AKANTU_CONSTITUTIVE_LAW_HH__ /* -------------------------------------------------------------------------- */ namespace akantu { template class ConstitutiveLaw : public DataAccessor, public Parsable { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: using ConstitutiveLawsHandler = ConstitutiveLawsHandler_; ConstitutiveLaw(const ConstitutiveLaw & law) = delete; ConstitutiveLaw & operator=(const ConstitutiveLaw & law) = delete; /// Initialize constitutive law with defaults ConstitutiveLaw(ConstitutiveLawsHandler & handler, const ID & id = "", ElementKind element_kind = _ek_regular); /// Destructor ~ConstitutiveLaw() override; protected: void initialize(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: - template - void registerInternal(InternalField & /*vect*/) { - AKANTU_TO_IMPLEMENT(); - } + template + inline void registerInternal(std::shared_ptr> & vect); - template - void unregisterInternal(InternalField & /*vect*/) { - AKANTU_TO_IMPLEMENT(); - } + inline void unregisterInternal(const ID & id); /// initialize the constitutive law computed parameter virtual void initConstitutiveLaw(); /// save the internals in the previous_state if needed virtual void savePreviousState(); /// restore the internals from previous_state if needed virtual void restorePreviousState(); /// add an element to the local mesh filter inline UInt addElement(ElementType type, UInt element, GhostType ghost_type); inline UInt addElement(const Element & element); /// add many elements at once void addElements(const Array & elements_to_add); /// remove many element at once void removeElements(const Array & elements_to_remove); /// function to print the contain of the class void printself(std::ostream & stream, int indent = 0) const override; protected: /// resize the internals arrrays virtual void resizeInternals(); /// function called to update the internal parameters when the /// modifiable parameters are modified virtual void updateInternalParameters() {} public: virtual void onElementsAdded(const Array & /*unused*/, const NewElementsEvent & /*unused*/); virtual void onElementsRemoved(const Array & element_list, const ElementTypeMapArray & new_numbering, const RemovedElementsEvent & event); public: - template - const InternalField & getInternal(const ID & /*id*/) const { - AKANTU_TO_IMPLEMENT(); - return NULL; + template + const InternalField & getInternal(const ID & id) const { + auto it = internal_vectors.find(getID() + ":" + id); + if (it != internal_vectors.end() and + aka::is_of_type>(*it->second)) { + return aka::as_type>(*it->second); + } + + AKANTU_SILENT_EXCEPTION("The material " << name << "(" << getID() + << ") does not contain an internal " + << id << " (" + << (getID() + ":" + id) << ")"); } - template - InternalField & getInternal(const ID & /*id*/) { - AKANTU_TO_IMPLEMENT(); - return NULL; + template InternalField & getInternal(const ID & id) { + auto it = internal_vectors.find(getID() + ":" + id); + if (it != internal_vectors.end() and + aka::is_of_type>(*it->second)) { + return aka::as_type>(*it->second); + } + + AKANTU_SILENT_EXCEPTION("The material " << name << "(" << getID() + << ") does not contain an internal " + << id << " (" + << (getID() + ":" + id) << ")"); } - template - inline bool isInternal(const ID & /*id*/, - const ElementKind & /*element_kind*/) const { - return false; + template + inline bool isInternal(const ID & id, + const ElementKind & element_kind) const { + auto it = internal_vectors.find(this->getID() + ":" + id); + + return (it != internal_vectors.end() and + aka::is_of_type>(*it->second) and + aka::as_type>(*it->second).getElementKind() != + element_kind); } + template + const Array & getArray(const ID & id, ElementType type, + GhostType ghost_type = _not_ghost) const; + template + Array & getArray(const ID & id, ElementType type, + GhostType ghost_type = _not_ghost); + template inline void setParam(const ID & param, T value); inline const Parameter & getParam(const ID & param) const; template void flattenInternal(const std::string & field_id, ElementTypeMapArray & internal_flat, const GhostType ghost_type = _not_ghost, ElementKind element_kind = _ek_not_defined) const; - /* ------------------------------------------------------------------------ */ - /* Accessors */ - /* ------------------------------------------------------------------------ */ + /* ------------------------------------------------------------------------ + */ + /* Accessors */ + /* ------------------------------------------------------------------------ + */ public: AKANTU_GET_MACRO(Name, name, const std::string &); AKANTU_GET_MACRO(ID, id, const ID &); AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(ElementFilter, element_filter, UInt); template ElementTypeMap getInternalDataPerElem(const ID & id, ElementKind element_kind) const; protected: bool isInit() const { return is_init; } - /* ------------------------------------------------------------------------ */ - /* Class Members */ - /* ------------------------------------------------------------------------ */ + /* ------------------------------------------------------------------------ + */ + /* Class Members */ + /* ------------------------------------------------------------------------ + */ private: /// boolean to know if the constitutive law has been initialized bool is_init{false}; - std::map *> internal_vectors_real; - std::map *> internal_vectors_uint; - std::map *> internal_vectors_bool; + std::map> internal_vectors; protected: ID id; /// constitutive law name std::string name; /// list of element handled by the constitutive law ElementTypeMapArray element_filter; // Constitutive law handler for which this is a constitutive law ConstitutiveLawsHandler & handler; }; } // namespace akantu #include "constitutive_law_tmpl.hh" #endif diff --git a/src/model/common/constitutive_laws/constitutive_law_tmpl.hh b/src/model/common/constitutive_laws/constitutive_law_tmpl.hh index 5ab6e034f..b7a7c5611 100644 --- a/src/model/common/constitutive_laws/constitutive_law_tmpl.hh +++ b/src/model/common/constitutive_laws/constitutive_law_tmpl.hh @@ -1,607 +1,412 @@ /** * @file constitutive_law_tmpl.hh * * @author Guillaume Anciaux * @author Aurelia Isabel Cuba Ramos * @author Daniel Pino Muñoz * @author Nicolas Richart * @author Marco Vocialta * * @date creation: Tue Jul 27 2010 * @date last modification: Wed Feb 21 2018 * * @brief Implementation of the templated part of the constitutive law class * * * 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 . * */ /* -------------------------------------------------------------------------- */ #include "constitutive_law.hh" #include "constitutive_laws_handler.hh" +#include "fe_engine.hh" /* -------------------------------------------------------------------------- */ #ifndef AKANTU_CONSTITUTIVE_LAW_TMPL_HH #define AKANTU_CONSTITUTIVE_LAW_TMPL_HH namespace akantu { template ConstitutiveLaw::ConstitutiveLaw( ConstitutiveLawsHandler_ & handler, const ID & id, ElementKind element_kind) : Parsable(ParserType::_constitutive_law, id), handler(handler), id(id), element_filter("element_filter", id) { /// for each connectivity types allocate the element filer array of the /// constitutive law element_filter.initialize(handler.getMesh(), _spatial_dimension = handler.getSpatialDimension(), _element_kind = element_kind); this->initialize(); } /* -------------------------------------------------------------------------- */ template void ConstitutiveLaw::initialize() { registerParam("name", name, std::string(), _pat_parsable | _pat_readable); } /* -------------------------------------------------------------------------- */ template void ConstitutiveLaw::initConstitutiveLaw() { this->resizeInternals(); this->updateInternalParmaters(); is_init = true; } /* -------------------------------------------------------------------------- */ template void ConstitutiveLaw::savePreviousState() { - for (auto pair : internal_vectors_real) { + for (auto pair : internal_vectors) { if (pair.second->hasHistory()) { pair.second->saveCurrentValues(); } } } /* -------------------------------------------------------------------------- */ template void ConstitutiveLaw::restorePreviousState() { - for (auto pair : internal_vectors_real) { + for (auto pair : internal_vectors) { if (pair.second->hasHistory()) { pair.second->restorePreviousValues(); } } } /* -------------------------------------------------------------------------- */ template void ConstitutiveLaw::resizeInternals() { - for (auto it = internal_vectors_real.begin(); - it != internal_vectors_real.end(); ++it) { - it->second->resize(); - } - - for (auto it = internal_vectors_uint.begin(); - it != internal_vectors_uint.end(); ++it) { - it->second->resize(); - } - - for (auto it = internal_vectors_bool.begin(); - it != internal_vectors_bool.end(); ++it) { - it->second->resize(); + for (auto && pair : internal_vectors) { + pair.second->resize(); } } /* -------------------------------------------------------------------------- */ template void ConstitutiveLaw::addElements( const Array & elements_to_add) { AKANTU_DEBUG_IN(); UInt law_id = handler.getConstitutiveLawIndex(name); for (const auto & element : elements_to_add) { auto index = this->addElement(element); handler.constitutive_law_index(element) = law_id; handler.constitutive_law_local_numbering(element) = index; } this->resizeInternals(); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ template void ConstitutiveLaw::removeElements( const Array & elements_to_remove) { AKANTU_DEBUG_IN(); auto el_begin = elements_to_remove.begin(); auto el_end = elements_to_remove.end(); if (elements_to_remove.empty()) { return; } auto & mesh = handler.getMesh(); ElementTypeMapArray constitutive_law_local_new_numbering( "remove constitutive law filter elem", id); constitutive_law_local_new_numbering.initialize( mesh, _element_filter = &element_filter, _element_kind = _ek_not_defined, _with_nb_element = true); ElementTypeMapArray element_filter_tmp("element_filter_tmp", id); element_filter_tmp.initialize(mesh, _element_filter = &element_filter, _element_kind = _ek_not_defined); ElementTypeMap new_ids, element_ids; for_each_element( mesh, [&](auto && el) { if (not new_ids(el.type, el.ghost_type)) { element_ids(el.type, el.ghost_type) = 0; } auto & element_id = element_ids(el.type, el.ghost_type); auto l_el = Element{el.type, element_id, el.ghost_type}; if (std::find(el_begin, el_end, el) != el_end) { constitutive_law_local_new_numbering(l_el) = UInt(-1); return; } element_filter_tmp(el.type, el.ghost_type).push_back(el.element); if (not new_ids(el.type, el.ghost_type)) { new_ids(el.type, el.ghost_type) = 0; } auto & new_id = new_ids(el.type, el.ghost_type); constitutive_law_local_new_numbering(l_el) = new_id; handler.constitutive_law_local_numbering(el) = new_id; ++new_id; ++element_id; }, _element_filter = &element_filter, _element_kind = _ek_not_defined); for (auto ghost_type : ghost_types) { for (const auto & type : element_filter.elementTypes( _ghost_type = ghost_type, _element_kind = _ek_not_defined)) { element_filter(type, ghost_type) .copy(element_filter_tmp(type, ghost_type)); } } - for (auto it = internal_vectors_real.begin(); - it != internal_vectors_real.end(); ++it) { - it->second->removeIntegrationPoints(constitutive_law_local_new_numbering); - } - - for (auto it = internal_vectors_uint.begin(); - it != internal_vectors_uint.end(); ++it) { - it->second->removeIntegrationPoints(constitutive_law_local_new_numbering); - } - - for (auto it = internal_vectors_bool.begin(); - it != internal_vectors_bool.end(); ++it) { - it->second->removeIntegrationPoints(constitutive_law_local_new_numbering); + for (auto && pair : internal_vectors) { + pair.second->removeIntegrationPoints(constitutive_law_local_new_numbering); } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ template void ConstitutiveLaw::onElementsAdded( const Array & /*unused*/, const NewElementsEvent & /*unused*/) { this->resizeInternals(); } /* -------------------------------------------------------------------------- */ template void ConstitutiveLaw::onElementsRemoved( const Array & element_list, const ElementTypeMapArray & new_numbering, const RemovedElementsEvent & /*event*/) { UInt my_num = handler.getInternalIndexFromID(getID()); ElementTypeMapArray constitutive_law_local_new_numbering( "remove constitutive law filter elem", getID()); auto el_begin = element_list.begin(); auto el_end = element_list.end(); for (auto && gt : ghost_types) { for (auto && type : new_numbering.elementTypes(_all_dimensions, gt, _ek_not_defined)) { if (not element_filter.exists(type, gt) || element_filter(type, gt).empty()) { continue; } auto & elem_filter = element_filter(type, gt); auto & law_indexes = this->handler.constitutive_law_index(type, gt); auto & law_loc_num = this->handler.constitutive_law_local_numbering(type, gt); auto nb_element = this->handler.getMesh().getNbElement(type, gt); // all constitutive laws will resized to the same size... law_indexes.resize(nb_element); law_loc_num.resize(nb_element); if (!constitutive_law_local_new_numbering.exists(type, gt)) { constitutive_law_local_new_numbering.alloc(elem_filter.size(), 1, type, gt); } auto & law_renumbering = constitutive_law_local_new_numbering(type, gt); const auto & renumbering = new_numbering(type, gt); Array elem_filter_tmp; UInt ni = 0; Element el{type, 0, gt}; for (UInt i = 0; i < elem_filter.size(); ++i) { el.element = elem_filter(i); if (std::find(el_begin, el_end, el) == el_end) { UInt new_el = renumbering(el.element); AKANTU_DEBUG_ASSERT(new_el != UInt(-1), "A not removed element as been badly renumbered"); elem_filter_tmp.push_back(new_el); law_renumbering(i) = ni; law_indexes(new_el) = my_num; law_loc_num(new_el) = ni; ++ni; } else { law_renumbering(i) = UInt(-1); } } elem_filter.resize(elem_filter_tmp.size()); elem_filter.copy(elem_filter_tmp); } } - for (auto it = internal_vectors_real.begin(); - it != internal_vectors_real.end(); ++it) { - it->second->removeIntegrationPoints(constitutive_law_local_new_numbering); - } - - for (auto it = internal_vectors_uint.begin(); - it != internal_vectors_uint.end(); ++it) { - it->second->removeIntegrationPoints(constitutive_law_local_new_numbering); - } - - for (auto it = internal_vectors_bool.begin(); - it != internal_vectors_bool.end(); ++it) { - it->second->removeIntegrationPoints(constitutive_law_local_new_numbering); + for (auto pair : internal_vectors) { + pair.second->removeIntegrationPoints(constitutive_law_local_new_numbering); } } /* -------------------------------------------------------------------------- */ template inline UInt ConstitutiveLaw::addElement( ElementType type, UInt element, GhostType ghost_type) { Array & el_filter = this->element_filter(type, ghost_type); el_filter.push_back(element); return el_filter.size() - 1; } /* -------------------------------------------------------------------------- */ template inline UInt ConstitutiveLaw::addElement(const Element & element) { return this->addElement(element.type, element.element, element.ghost_type); } /* -------------------------------------------------------------------------- */ template inline const Parameter & ConstitutiveLaw::getParam(const ID & param) const { try { return get(param); } catch (...) { AKANTU_EXCEPTION("No parameter " << param << " in the constitutive law" << getID()); } } /* -------------------------------------------------------------------------- */ template template inline void ConstitutiveLaw::setParam(const ID & param, T value) { try { set(param, value); } catch (...) { AKANTU_EXCEPTION("No parameter " << param << " in the constitutive law " << getID()); } updateInternalParameters(); } /* -------------------------------------------------------------------------- */ template -template -inline void -ConstitutiveLaw::registerInternal( - InternalField & vect) { - internal_vectors_real[vect.getID()] = &vect; -} - -template -template -inline void -ConstitutiveLaw::registerInternal( - InternalField & vect) { - internal_vectors_uint[vect.getID()] = &vect; -} - -template -template -inline void -ConstitutiveLaw::registerInternal( - InternalField & vect) { - internal_vectors_bool[vect.getID()] = &vect; +template +inline void ConstitutiveLaw::registerInternal( + std::shared_ptr> & vect) { + internal_vectors[vect.getID()] = vect; } /* -------------------------------------------------------------------------- */ template -template -inline void -ConstitutiveLaw::unregisterInternal( - InternalField & vect) { - internal_vectors_real.erase(vect.getID()); -} - -template -template -inline void -ConstitutiveLaw::unregisterInternal( - InternalField & vect) { - internal_vectors_uint.erase(vect.getID()); -} - -template -template inline void -ConstitutiveLaw::unregisterInternal( - InternalField & vect) { - internal_vectors_bool.erase(vect.getID()); -} - -/* -------------------------------------------------------------------------- */ -template -template -const InternalField & -ConstituitveLaw::getInternal( - const ID & int_id) const { - auto it = internal_vectors_real.find(getID() + ":" + int_id); - if (it == internal_vectors_real.end()) { - AKANTU_SILENT_EXCEPTION("The material " << name << "(" << getID() - << ") does not contain an internal " - << int_id << " (" - << (getID() + ":" + int_id) << ")"); - } - return *it->second; -} - -/* -------------------------------------------------------------------------- */ -template -template <> -InternalField & -ConstituitveLaw::getInternal( - const ID & int_id) { - auto it = internal_vectors_real.find(getID() + ":" + int_id); - if (it == internal_vectors_real.end()) { - AKANTU_SILENT_EXCEPTION("The material " << name << "(" << getID() - << ") does not contain an internal " - << int_id << " (" - << (getID() + ":" + int_id) << ")"); - } - return *it->second; -} - -/* -------------------------------------------------------------------------- */ -template -template -const InternalField & -ConstituitveLaw::getInternal( - const ID & int_id) const { - auto it = internal_vectors_uint.find(getID() + ":" + int_id); - if (it == internal_vectors_uint.end()) { - AKANTU_SILENT_EXCEPTION("The material " << name << "(" << getID() - << ") does not contain an internal " - << int_id << " (" - << (getID() + ":" + int_id) << ")"); - } - return *it->second; -} - -/* -------------------------------------------------------------------------- */ -template -template -InternalField & -ConstituitveLaw::getInternal( - const ID & int_id) { - auto it = internal_vectors_uint.find(getID() + ":" + int_id); - if (it == internal_vectors_uint.end()) { - AKANTU_SILENT_EXCEPTION("The material " << name << "(" << getID() - << ") does not contain an internal " - << int_id << " (" - << (getID() + ":" + int_id) << ")"); - } - return *it->second; -} - -/* -------------------------------------------------------------------------- */ -template -template -const InternalField & -ConstituitveLaw::getInternal( - const ID & int_id) const { - auto it = internal_vectors_bool.find(getID() + ":" + int_id); - if (it == internal_vectors_bool.end()) { - AKANTU_SILENT_EXCEPTION("The material " << name << "(" << getID() - << ") does not contain an internal " - << int_id << " (" - << (getID() + ":" + int_id) << ")"); - } - return *it->second; -} - -/* -------------------------------------------------------------------------- */ -template -template -InternalField & -ConstituitveLaw::getInternal( - const ID & int_id) { - auto it = internal_vectors_bool.find(getID() + ":" + int_id); - if (it == internal_vectors_bool.end()) { - AKANTU_SILENT_EXCEPTION("The material " << name << "(" << getID() - << ") does not contain an internal " - << int_id << " (" - << (getID() + ":" + int_id) << ")"); - } - return *it->second; -} - -/* -------------------------------------------------------------------------- */ -template -template -inline bool ConstitutiveLaw::isInternal( - const ID & id, ElementKind element_kind) const { - auto internal_array = internal_vectors_real.find(this->getID() + ":" + id); - - return not(internal_array == internal_vectors_real.end() || - internal_array->second->getElementKind() != element_kind); -} - -/* -------------------------------------------------------------------------- */ -template -template -inline bool ConstitutiveLaw::isInternal( - const ID & id, ElementKind element_kind) const { - auto internal_array = internal_vectors_uint.find(this->getID() + ":" + id); - - return not(internal_array == internal_vectors_uint.end() || - internal_array->second->getElementKind() != element_kind); -} - -/* -------------------------------------------------------------------------- */ -template -template -inline bool ConstitutiveLaw::isInternal( - const ID & id, ElementKind element_kind) const { - auto internal_array = internal_vectors_bool.find(this->getID() + ":" + id); - - return not(internal_array == internal_vectors_bool.end() || - internal_array->second->getElementKind() != element_kind); +ConstitutiveLaw::unregisterInternal(const ID & id) { + internal_vectors.erase(id); } /* -------------------------------------------------------------------------- */ template +template inline ElementTypeMap ConstitutiveLaw::getInternalDataPerElem( const ID & field_id, ElementKind element_kind) const { - if (!this->template isInternal(field_id, element_kind)) { + if (not this->template isInternal(field_id, element_kind)) { AKANTU_EXCEPTION("Cannot find internal field " << id << " in the constitutive law " << this->name); } - const InternalField & internal_field = - this->template getInternal(field_id); + const auto & internal_field = this->template getInternal(field_id); const FEEngine & fe_engine = internal_field.getFEEngine(); UInt nb_data_per_quad = internal_field.getNbComponent(); ElementTypeMap res; for (auto ghost_type : ghost_types) { for (auto & type : internal_field.elementTypes(ghost_type)) { UInt nb_quadrature_points = fe_engine.getNbIntegrationPoints(type, ghost_type); res(type, ghost_type) = nb_data_per_quad * nb_quadrature_points; } } return res; } /* -------------------------------------------------------------------------- */ template +template void ConstitutiveLaw::flattenInternal( const std::string & field_id, ElementTypeMapArray & internal_flat, const GhostType ghost_type, ElementKind element_kind) const { if (!this->template isInternal(field_id, element_kind)) { AKANTU_EXCEPTION("Cannot find internal field " << id << " in the constitutive law " << this->name); } const InternalField & internal_field = this->template getInternal(field_id); const FEEngine & fe_engine = internal_field.getFEEngine(); const Mesh & mesh = fe_engine.getMesh(); for (auto && type : internal_field.filterTypes(ghost_type)) { const Array & src_vect = internal_field(type, ghost_type); const Array & filter = internal_field.getFilter(type, ghost_type); // total number of elements in the corresponding mesh UInt nb_element_dst = mesh.getNbElement(type, ghost_type); // number of element in the internal field UInt nb_element_src = filter.size(); // number of quadrature points per elem UInt nb_quad_per_elem = fe_engine.getNbIntegrationPoints(type); // number of data per quadrature point UInt nb_data_per_quad = internal_field.getNbComponent(); if (!internal_flat.exists(type, ghost_type)) { internal_flat.alloc(nb_element_dst * nb_quad_per_elem, nb_data_per_quad, type, ghost_type); } if (nb_element_src == 0) { continue; } // number of data per element UInt nb_data = nb_quad_per_elem * nb_data_per_quad; Array & dst_vect = internal_flat(type, ghost_type); dst_vect.resize(nb_element_dst * nb_quad_per_elem); auto it_dst = make_view(dst_vect, nb_data).begin(); for (auto && data : zip(filter, make_view(src_vect, nb_data))) { it_dst[std::get<0>(data)] = std::get<1>(data); } } } } // namespace akantu #endif // AKANTU_CONSTITUTIVE_LAW_TMPL_HH diff --git a/src/model/common/constitutive_laws/internal_field.hh b/src/model/common/constitutive_laws/internal_field.hh index 4dbb2895e..659461688 100644 --- a/src/model/common/constitutive_laws/internal_field.hh +++ b/src/model/common/constitutive_laws/internal_field.hh @@ -1,277 +1,266 @@ /** * @file internal_field.hh * * @author Nicolas Richart * * @date creation: Fri Jun 18 2010 * @date last modification: Thu Feb 08 2018 * * @brief Material internal properties * * * 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 . * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "element_type_map.hh" /* -------------------------------------------------------------------------- */ +#include +/* -------------------------------------------------------------------------- */ #ifndef AKANTU_INTERNAL_FIELD_HH_ #define AKANTU_INTERNAL_FIELD_HH_ namespace akantu { class Material; class FEEngine; +class InternalFieldBase + : public std::enable_shared_from_this { +public: + /// activate the history of this field + virtual void initializeHistory() = 0; + + /// resize the arrays and set the new element to 0 + virtual void resize() = 0; + + /// save the current values in the history + virtual void saveCurrentValues() = 0; + + /// restore the previous values from the history + virtual void restorePreviousValues() = 0; + + /// remove the quadrature points corresponding to suppressed elements + virtual void + removeIntegrationPoints(const ElementTypeMapArray & new_numbering) = 0; + + virtual bool hasHistory() const = 0; +}; + /** * class for the internal fields of materials * to store values for each quadrature */ -template class InternalField : public ElementTypeMapArray { +template +class InternalField : public InternalFieldBase, public ElementTypeMapArray { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: InternalField(const ID & id, Material & material); ~InternalField() override; /// This constructor is only here to let cohesive elements compile InternalField(const ID & id, Material & material, FEEngine & fem, const ElementTypeMapArray & element_filter); /// More general constructor InternalField(const ID & id, Material & material, UInt dim, FEEngine & fem, const ElementTypeMapArray & element_filter); InternalField(const ID & id, const InternalField & other); - InternalField operator=(const InternalField &) = delete; /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// function to reset the FEEngine for the internal field virtual void setFEEngine(FEEngine & fe_engine); /// function to reset the element kind for the internal virtual void setElementKind(ElementKind element_kind); /// initialize the field to a given number of component virtual void initialize(UInt nb_component); /// activate the history of this field - virtual void initializeHistory(); + void initializeHistory() override; /// resize the arrays and set the new element to 0 - virtual void resize(); + void resize() override; /// set the field to a given value v virtual void setDefaultValue(const T & v); /// reset all the fields to the default value virtual void reset(); /// save the current values in the history - virtual void saveCurrentValues(); + void saveCurrentValues() override; /// restore the previous values from the history - virtual void restorePreviousValues(); + void restorePreviousValues() override; /// remove the quadrature points corresponding to suppressed elements - virtual void - removeIntegrationPoints(const ElementTypeMapArray & new_numbering); + void removeIntegrationPoints( + const ElementTypeMapArray & new_numbering) override; /// print the content void printself(std::ostream & stream, int /*indent*/ = 0) const override; /// get the default value inline operator T() const; virtual FEEngine & getFEEngine() { return *fem; } virtual const FEEngine & getFEEngine() const { return *fem; } /// AKANTU_GET_MACRO(FEEngine, *fem, FEEngine &); protected: /// initialize the arrays in the ElementTypeMapArray void internalInitialize(UInt nb_component); /// set the values for new internals virtual void setArrayValues(T * begin, T * end); /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: - // using type_iterator = typename ElementTypeMapArray::type_iterator; - // using filter_type_iterator = - // typename ElementTypeMapArray::type_iterator; - - // /// get the type iterator on all types contained in the internal field - // type_iterator firstType(GhostType ghost_type = _not_ghost) const { - // return ElementTypeMapArray::firstType(this->spatial_dimension, - // ghost_type, this->element_kind); - // } - - // /// get the type iterator on the last type contained in the internal field - // type_iterator lastType(GhostType ghost_type = _not_ghost) const { - // return ElementTypeMapArray::lastType(this->spatial_dimension, - // ghost_type, - // this->element_kind); - // } - - // /// get the type iterator on all types contained in the internal field - // filter_type_iterator - // filterFirstType(GhostType ghost_type = _not_ghost) const { - // return this->element_filter.firstType(this->spatial_dimension, - // ghost_type, - // this->element_kind); - // } - - // /// get the type iterator on the last type contained in the internal field - // filter_type_iterator - // filterLastType(GhostType ghost_type = _not_ghost) const { - // return this->element_filter.lastType(this->spatial_dimension, ghost_type, - // this->element_kind); - // } - /// get filter types for range loop decltype(auto) elementTypes(GhostType ghost_type = _not_ghost) const { return ElementTypeMapArray::elementTypes( _spatial_dimension = this->spatial_dimension, _element_kind = this->element_kind, _ghost_type = ghost_type); } /// get filter types for range loop decltype(auto) filterTypes(GhostType ghost_type = _not_ghost) const { return this->element_filter.elementTypes( _spatial_dimension = this->spatial_dimension, _element_kind = this->element_kind, _ghost_type = ghost_type); } /// get the array for a given type of the element_filter - const Array & - getFilter(ElementType type, - GhostType ghost_type = _not_ghost) const { + const Array & getFilter(ElementType type, + GhostType ghost_type = _not_ghost) const { return this->element_filter(type, ghost_type); } /// get the Array corresponding to the type en ghost_type specified virtual Array & operator()(ElementType type, GhostType ghost_type = _not_ghost) { return ElementTypeMapArray::operator()(type, ghost_type); } - virtual const Array & - operator()(ElementType type, - GhostType ghost_type = _not_ghost) const { + virtual const Array & operator()(ElementType type, + GhostType ghost_type = _not_ghost) const { return ElementTypeMapArray::operator()(type, ghost_type); } virtual Array & previous(ElementType type, GhostType ghost_type = _not_ghost) { AKANTU_DEBUG_ASSERT(previous_values != nullptr, "The history of the internal " << this->getID() << " has not been activated"); return this->previous_values->operator()(type, ghost_type); } - virtual const Array & - previous(ElementType type, - GhostType ghost_type = _not_ghost) const { + virtual const Array & previous(ElementType type, + GhostType ghost_type = _not_ghost) const { AKANTU_DEBUG_ASSERT(previous_values != nullptr, "The history of the internal " << this->getID() << " has not been activated"); return this->previous_values->operator()(type, ghost_type); } virtual InternalField & previous() { AKANTU_DEBUG_ASSERT(previous_values != nullptr, "The history of the internal " << this->getID() << " has not been activated"); return *(this->previous_values); } virtual const InternalField & previous() const { AKANTU_DEBUG_ASSERT(previous_values != nullptr, "The history of the internal " << this->getID() << " has not been activated"); return *(this->previous_values); } /// check if the history is used or not - bool hasHistory() const { return (previous_values != nullptr); } + bool hasHistory() const override { return (previous_values != nullptr); } /// get the kind treated by the internal ElementKind getElementKind() const { return element_kind; } /// return the number of components UInt getNbComponent() const { return nb_component; } /// return the spatial dimension corresponding to the internal element type /// loop filter UInt getSpatialDimension() const { return this->spatial_dimension; } /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: /// the material for which this is an internal parameter Material & material; /// the fem containing the mesh and the element informations FEEngine * fem{nullptr}; /// Element filter if needed const ElementTypeMapArray & element_filter; /// default value T default_value{}; /// spatial dimension of the element to consider UInt spatial_dimension{0}; /// ElementKind of the element to consider ElementKind element_kind{_ek_regular}; /// Number of component of the internal field UInt nb_component{0}; /// Is the field initialized bool is_init{false}; /// previous values std::unique_ptr> previous_values; }; /// standard output stream operator template inline std::ostream & operator<<(std::ostream & stream, const InternalField & _this) { _this.printself(stream); return stream; } } // namespace akantu #endif /* AKANTU_INTERNAL_FIELD_HH_ */ diff --git a/src/model/solid_mechanics/material.hh b/src/model/solid_mechanics/material.hh index 339591dba..9f516ee9b 100644 --- a/src/model/solid_mechanics/material.hh +++ b/src/model/solid_mechanics/material.hh @@ -1,621 +1,619 @@ /** * @file material.hh * * @author Daniel Pino Muñoz * @author Nicolas Richart * @author Marco Vocialta * * @date creation: Fri Jun 18 2010 * @date last modification: Wed Feb 21 2018 * * @brief Mother class for all materials * * * 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 . * */ /* -------------------------------------------------------------------------- */ #include "aka_factory.hh" #include "aka_voigthelper.hh" #include "data_accessor.hh" #include "integration_point.hh" #include "parsable.hh" #include "parser.hh" #include "constitutive_law.hh" /* -------------------------------------------------------------------------- */ #include "internal_field.hh" #include "random_internal_field.hh" /* -------------------------------------------------------------------------- */ #include "mesh_events.hh" #include "solid_mechanics_model_event_handler.hh" /* -------------------------------------------------------------------------- */ #ifndef AKANTU_MATERIAL_HH_ #define AKANTU_MATERIAL_HH_ /* -------------------------------------------------------------------------- */ namespace akantu { class Model; class SolidMechanicsModel; class Material; } // namespace akantu namespace akantu { using MaterialFactory = Factory; /** * Interface of all materials * Prerequisites for a new material * - inherit from this class * - implement the following methods: * \code * virtual Real getStableTimeStep(Real h, const Element & element = * ElementNull); * * virtual void computeStress(ElementType el_type, * GhostType ghost_type = _not_ghost); * * virtual void computeTangentStiffness(ElementType el_type, * Array & tangent_matrix, * GhostType ghost_type = _not_ghost); * \endcode * */ -class Material : public ConstitutiveLaw - public DataAccessor, - public Parsable, +class Material : public ConstitutiveLaw, public MeshEventHandler, protected SolidMechanicsModelEventHandler { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: Material(const Material & mat) = delete; Material & operator=(const Material & mat) = delete; /// Initialize material with defaults Material(SolidMechanicsModel & model, const ID & id = ""); /// Initialize material with custom mesh & fe_engine Material(SolidMechanicsModel & model, UInt dim, const Mesh & mesh, FEEngine & fe_engine, const ID & id = ""); /// Destructor ~Material() override; protected: void initialize(); /* ------------------------------------------------------------------------ */ /* Function that materials can/should reimplement */ /* ------------------------------------------------------------------------ */ protected: /// constitutive law virtual void computeStress(ElementType /* el_type */, GhostType /* ghost_type */ = _not_ghost) { AKANTU_TO_IMPLEMENT(); } /// compute the tangent stiffness matrix virtual void computeTangentModuli(ElementType /*el_type*/, Array & /*tangent_matrix*/, GhostType /*ghost_type*/ = _not_ghost) { AKANTU_TO_IMPLEMENT(); } /// compute the potential energy virtual void computePotentialEnergy(ElementType el_type); /// compute the potential energy for an element virtual void computePotentialEnergyByElement(ElementType /*type*/, UInt /*index*/, Vector & /*epot_on_quad_points*/) { AKANTU_TO_IMPLEMENT(); } virtual void updateEnergies(ElementType /*el_type*/) {} virtual void updateEnergiesAfterDamage(ElementType /*el_type*/) {} /// set the material to steady state (to be implemented for materials that /// need it) virtual void setToSteadyState(ElementType /*el_type*/, GhostType /*ghost_type*/ = _not_ghost) {} /// function called to update the internal parameters when the /// modifiable parameters are modified virtual void updateInternalParameters(); public: /// extrapolate internal values virtual void extrapolateInternal(const ID & id, const Element & element, const Matrix & points, Matrix & extrapolated); /// compute the p-wave speed in the material virtual Real getPushWaveSpeed(const Element & /*element*/) const { AKANTU_TO_IMPLEMENT(); } /// compute the s-wave speed in the material virtual Real getShearWaveSpeed(const Element & /*element*/) const { AKANTU_TO_IMPLEMENT(); } /// get a material celerity to compute the stable time step (default: is the /// push wave speed) virtual Real getCelerity(const Element & element) const { return getPushWaveSpeed(element); } /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// initialize the material computed parameter virtual void initMaterial(); /// compute the residual for this material // virtual void updateResidual(GhostType ghost_type = _not_ghost); /// assemble the residual for this material virtual void assembleInternalForces(GhostType ghost_type); /// compute the stresses for this material virtual void computeAllStresses(GhostType ghost_type = _not_ghost); // virtual void // computeAllStressesFromTangentModuli(GhostType ghost_type = _not_ghost); virtual void computeAllCauchyStresses(GhostType ghost_type = _not_ghost); /// set material to steady state void setToSteadyState(GhostType ghost_type = _not_ghost); /// compute the stiffness matrix virtual void assembleStiffnessMatrix(GhostType ghost_type); /// function to print the contain of the class void printself(std::ostream & stream, int indent = 0) const override; /** * interpolate stress on given positions for each element by means * of a geometrical interpolation on quadrature points */ void interpolateStress(ElementTypeMapArray & result, GhostType ghost_type = _not_ghost); /** * interpolate stress on given positions for each element by means * of a geometrical interpolation on quadrature points and store the * results per facet */ void interpolateStressOnFacets(ElementTypeMapArray & result, ElementTypeMapArray & by_elem_result, GhostType ghost_type = _not_ghost); /** * function to initialize the elemental field interpolation * function by inverting the quadrature points' coordinates */ void initElementalFieldInterpolation( const ElementTypeMapArray & interpolation_points_coordinates); /* ------------------------------------------------------------------------ */ /* Common part */ /* ------------------------------------------------------------------------ */ protected: /* ------------------------------------------------------------------------ */ static inline UInt getTangentStiffnessVoigtSize(UInt dim); /// compute the potential energy by element void computePotentialEnergyByElements(); /* ------------------------------------------------------------------------ */ /* Finite deformation functions */ /* This functions area implementing what is described in the paper of Bathe */ /* et al, in IJNME, Finite Element Formulations For Large Deformation */ /* Dynamic Analysis, Vol 9, 353-386, 1975 */ /* ------------------------------------------------------------------------ */ protected: /// assemble the residual template void assembleInternalForces(GhostType ghost_type); template void computeAllStressesFromTangentModuli(ElementType type, GhostType ghost_type); template void assembleStiffnessMatrix(ElementType type, GhostType ghost_type); /// assembling in finite deformation template void assembleStiffnessMatrixNL(ElementType type, GhostType ghost_type); template void assembleStiffnessMatrixL2(ElementType type, GhostType ghost_type); /* ------------------------------------------------------------------------ */ /* Conversion functions */ /* ------------------------------------------------------------------------ */ public: /// Size of the Stress matrix for the case of finite deformation see: Bathe et /// al, IJNME, Vol 9, 353-386, 1975 static inline UInt getCauchyStressMatrixSize(UInt dim); /// Sets the stress matrix according to Bathe et al, IJNME, Vol 9, 353-386, /// 1975 template static inline void setCauchyStressMatrix(const Matrix & S_t, Matrix & sigma); /// write the stress tensor in the Voigt notation. template static inline decltype(auto) stressToVoigt(const Matrix & stress) { return VoigtHelper::matrixToVoigt(stress); } /// write the strain tensor in the Voigt notation. template static inline decltype(auto) strainToVoigt(const Matrix & strain) { return VoigtHelper::matrixToVoigtWithFactors(strain); } /// write a voigt vector to stress template static inline void voigtToStress(const Vector & voigt, Matrix & stress) { VoigtHelper::voigtToMatrix(voigt, stress); } /// Computation of Cauchy stress tensor in the case of finite deformation from /// the 2nd Piola-Kirchhoff for a given element type template void StoCauchy(ElementType el_type, GhostType ghost_type = _not_ghost); /// Computation the Cauchy stress the 2nd Piola-Kirchhoff and the deformation /// gradient template inline void StoCauchy(const Matrix & F, const Matrix & S, Matrix & sigma, const Real & C33 = 1.0) const; template static inline void gradUToF(const Matrix & grad_u, Matrix & F); template static inline decltype(auto) gradUToF(const Matrix & grad_u); static inline void rightCauchy(const Matrix & F, Matrix & C); static inline void leftCauchy(const Matrix & F, Matrix & B); template static inline void gradUToEpsilon(const Matrix & grad_u, Matrix & epsilon); template static inline decltype(auto) gradUToEpsilon(const Matrix & grad_u); template static inline void gradUToE(const Matrix & grad_u, Matrix & epsilon); template static inline decltype(auto) gradUToE(const Matrix & grad_u); static inline Real stressToVonMises(const Matrix & stress); /* ------------------------------------------------------------------------ */ /* DataAccessor inherited members */ /* ------------------------------------------------------------------------ */ public: inline UInt getNbData(const Array & elements, const SynchronizationTag & tag) const override; inline void packData(CommunicationBuffer & buffer, const Array & elements, const SynchronizationTag & tag) const override; inline void unpackData(CommunicationBuffer & buffer, const Array & elements, const SynchronizationTag & tag) override; template inline void packElementDataHelper(const ElementTypeMapArray & data_to_pack, CommunicationBuffer & buffer, const Array & elements, const ID & fem_id = ID()) const; template inline void unpackElementDataHelper(ElementTypeMapArray & data_to_unpack, CommunicationBuffer & buffer, const Array & elements, const ID & fem_id = ID()); /* ------------------------------------------------------------------------ */ /* MeshEventHandler inherited members */ /* ------------------------------------------------------------------------ */ public: /* ------------------------------------------------------------------------ */ void onNodesAdded(const Array & /*unused*/, const NewNodesEvent & /*unused*/) override{}; void onNodesRemoved(const Array & /*unused*/, const Array & /*unused*/, const RemovedNodesEvent & /*unused*/) override{}; void onElementsAdded(const Array & element_list, const NewElementsEvent & event) override; void onElementsRemoved(const Array & element_list, const ElementTypeMapArray & new_numbering, const RemovedElementsEvent & event) override; void onElementsChanged(const Array & /*unused*/, const Array & /*unused*/, const ElementTypeMapArray & /*unused*/, const ChangedElementsEvent & /*unused*/) override{}; /* ------------------------------------------------------------------------ */ /* SolidMechanicsModelEventHandler inherited members */ /* ------------------------------------------------------------------------ */ public: virtual void beforeSolveStep(); virtual void afterSolveStep(bool converged = true); void onDamageIteration() override; void onDamageUpdate() override; void onDump() override; /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: AKANTU_GET_MACRO(Model, model, const SolidMechanicsModel &) AKANTU_GET_MACRO(Rho, rho, Real); AKANTU_SET_MACRO(Rho, rho, Real); AKANTU_GET_MACRO(SpatialDimension, spatial_dimension, UInt); /// return the potential energy for the subset of elements contained by the /// material Real getPotentialEnergy(); /// return the potential energy for the provided element Real getPotentialEnergy(ElementType & type, UInt index); /// return the energy (identified by id) for the subset of elements contained /// by the material virtual Real getEnergy(const std::string & type); /// return the energy (identified by id) for the provided element virtual Real getEnergy(const std::string & energy_id, ElementType type, UInt index); AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(GradU, gradu, Real); AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(Stress, stress, Real); AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(PotentialEnergy, potential_energy, Real); AKANTU_GET_MACRO(GradU, gradu, const ElementTypeMapArray &); AKANTU_GET_MACRO(Stress, stress, const ElementTypeMapArray &); AKANTU_GET_MACRO(ElementFilter, element_filter, const ElementTypeMapArray &); AKANTU_GET_MACRO(FEEngine, fem, FEEngine &); bool isNonLocal() const { return is_non_local; } bool isFiniteDeformation() const { return finite_deformation; } bool isInelasticDeformation() const { return inelastic_deformation; } /// apply a constant eigengrad_u everywhere in the material virtual void applyEigenGradU(const Matrix & prescribed_eigen_grad_u, GhostType /*ghost_type*/ = _not_ghost); bool hasMatrixChanged(const ID & id) { if (id == "K") { return hasStiffnessMatrixChanged() or finite_deformation; } return true; } MatrixType getMatrixType(const ID & id) { if (id == "K") { return getTangentType(); } if (id == "M") { return _symmetric; } return _mt_not_defined; } /// specify if the matrix need to be recomputed for this material virtual bool hasStiffnessMatrixChanged() { return true; } /// specify the type of matrix, if not overloaded the material is not valid /// for static or implicit computations virtual MatrixType getTangentType() { return _mt_not_defined; } /// static method to reteive the material factory static MaterialFactory & getFactory(); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: /// Link to the fem object in the model FEEngine & fem; /// Finite deformation bool finite_deformation{false}; /// Finite deformation bool inelastic_deformation{false}; /// The model to witch the material belong SolidMechanicsModel & model; /// density : rho Real rho{0.}; /// spatial dimension UInt spatial_dimension; /// stresses arrays ordered by element types InternalField stress; /// eigengrad_u arrays ordered by element types InternalField eigengradu; /// grad_u arrays ordered by element types InternalField gradu; /// Green Lagrange strain (Finite deformation) InternalField green_strain; /// Second Piola-Kirchhoff stress tensor arrays ordered by element types /// (Finite deformation) InternalField piola_kirchhoff_2; /// potential energy by element InternalField potential_energy; /// tell if using in non local mode or not bool is_non_local{false}; /// tell if the material need the previous stress state bool use_previous_stress{false}; /// tell if the material need the previous strain state bool use_previous_gradu{false}; /// elemental field interpolation coordinates InternalField interpolation_inverse_coordinates; /// elemental field interpolation points InternalField interpolation_points_matrices; private: /// eigen_grad_u for the parser Matrix eigen_grad_u; }; /// standard output stream operator inline std::ostream & operator<<(std::ostream & stream, const Material & _this) { _this.printself(stream); return stream; } } // namespace akantu #include "material_inline_impl.hh" #include "internal_field_tmpl.hh" #include "random_internal_field_tmpl.hh" /* -------------------------------------------------------------------------- */ /* Auto loop */ /* -------------------------------------------------------------------------- */ /// This can be used to automatically write the loop on quadrature points in /// functions such as computeStress. This macro in addition to write the loop /// provides two tensors (matrices) sigma and grad_u #define MATERIAL_STRESS_QUADRATURE_POINT_LOOP_BEGIN(el_type, ghost_type) \ auto && grad_u_view = \ make_view(this->gradu(el_type, ghost_type), this->spatial_dimension, \ this->spatial_dimension); \ \ auto stress_view = \ make_view(this->stress(el_type, ghost_type), this->spatial_dimension, \ this->spatial_dimension); \ \ if (this->isFiniteDeformation()) { \ stress_view = make_view(this->piola_kirchhoff_2(el_type, ghost_type), \ this->spatial_dimension, this->spatial_dimension); \ } \ \ for (auto && data : zip(grad_u_view, stress_view)) { \ [[gnu::unused]] Matrix & grad_u = std::get<0>(data); \ [[gnu::unused]] Matrix & sigma = std::get<1>(data) #define MATERIAL_STRESS_QUADRATURE_POINT_LOOP_END } /// This can be used to automatically write the loop on quadrature points in /// functions such as computeTangentModuli. This macro in addition to write the /// loop provides two tensors (matrices) sigma_tensor, grad_u, and a matrix /// where the elemental tangent moduli should be stored in Voigt Notation #define MATERIAL_TANGENT_QUADRATURE_POINT_LOOP_BEGIN(tangent_mat) \ auto && grad_u_view = \ make_view(this->gradu(el_type, ghost_type), this->spatial_dimension, \ this->spatial_dimension); \ \ auto && stress_view = \ make_view(this->stress(el_type, ghost_type), this->spatial_dimension, \ this->spatial_dimension); \ \ auto tangent_size = \ this->getTangentStiffnessVoigtSize(this->spatial_dimension); \ \ auto && tangent_view = make_view(tangent_mat, tangent_size, tangent_size); \ \ for (auto && data : zip(grad_u_view, stress_view, tangent_view)) { \ [[gnu::unused]] Matrix & grad_u = std::get<0>(data); \ [[gnu::unused]] Matrix & sigma = std::get<1>(data); \ Matrix & tangent = std::get<2>(data); #define MATERIAL_TANGENT_QUADRATURE_POINT_LOOP_END } /* -------------------------------------------------------------------------- */ #define INSTANTIATE_MATERIAL_ONLY(mat_name) \ template class mat_name<1>; /* NOLINT */ \ template class mat_name<2>; /* NOLINT */ \ template class mat_name<3> /* NOLINT */ #define MATERIAL_DEFAULT_PER_DIM_ALLOCATOR(id, mat_name) \ [](UInt dim, const ID &, SolidMechanicsModel & model, \ const ID & id) /* NOLINT */ \ -> std::unique_ptr< \ Material> { /* NOLINT */ \ switch (dim) { \ case 1: \ return std::make_unique>(/* NOLINT */ \ model, id); \ case 2: \ return std::make_unique>(/* NOLINT */ \ model, id); \ case 3: \ return std::make_unique>(/* NOLINT */ \ model, id); \ default: \ AKANTU_EXCEPTION( \ "The dimension " \ << dim \ << "is not a valid dimension for the material " \ << #id); \ } \ } #define INSTANTIATE_MATERIAL(id, mat_name) \ INSTANTIATE_MATERIAL_ONLY(mat_name); \ static bool material_is_alocated_##id [[gnu::unused]] = \ MaterialFactory::getInstance().registerAllocator( \ #id, MATERIAL_DEFAULT_PER_DIM_ALLOCATOR(id, mat_name)) #endif /* AKANTU_MATERIAL_HH_ */