Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ if(enable-julia-bindings)
set(CMAKE_CXX_STANDARD "${_CMAKE_CXX_STANDARD}")
endif(enable-julia-bindings)

# HDF5 support (optional)

option(enable-hdf5-support "enable HDF5 support" OFF)
option(enable-hdf5-automatic-support "if set, try to support HDF5, even if not explicitly requested by enable-hdf5-support" ON)
if(enable-hdf5-support)
find_package(HDF5 REQUIRED COMPONENTS CXX)
else(enable-hdf5-support)
if(enable-hdf5-automatic-support)
find_package(HDF5 COMPONENTS CXX)
endif(enable-hdf5-automatic-support)
endif(enable-hdf5-support)
if(HDF5_FOUND)
set(MGIS_HDF5_SUPPORT ON)
MESSAGE(STATUS "hdf5 headers : " ${HDF5_INCLUDE_DIRS})
MESSAGE(STATUS "hdf5 librairies : " ${HDF5_LIBRARIES})
MESSAGE(STATUS "hdf5 definitions : " ${HDF5_DEFINITIONS})
else(HDF5_FOUND)
set(MGIS_HDF5_SUPPORT OFF)
endif(HDF5_FOUND)

# summary

if(enable-c-bindings)
Expand All @@ -129,6 +149,10 @@ if(enable-fenics-bindings)
message(STATUS "FEniCS bindings support enabled")
endif(enable-fenics-bindings)

if(MGIS_HDF5_SUPPORT)
message(STATUS "HDF5 support enabled")
endif(MGIS_HDF5_SUPPORT)

find_package(Threads)
# if(MINGW)
# file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/thread-mingw.cxx"
Expand Down
7 changes: 7 additions & 0 deletions INSTALL-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ Options
- `enable-exceptions`: use exceptions to report contract violation and error reporting.
By default, contract violation leads to abort the program.
- `enable-parallel-stl-algorithms`: by default, STL algorithms are used if available
- `enable-hdf5-support`: enable HDF5 support for save/restore
operations. Note that if this support is not explicitely requested,
`MGIS` still tries by default to support `HDF5` but configuration will
not fail if the `HDF5` library is not found. See
`enable-hdf5-automatic-support` for details.
- `enable-hdf5-automatic-support`: if set, `MGIS` tries by default to
support `HDF5` even if enable-hdf5-support` is not set.

`cmake` usefull variables
=======================
Expand Down
5 changes: 4 additions & 1 deletion bindings/python/src/Variable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ void declareVariable(pybind11::module_& m) {
// free functions
m.def("getVariable", getVariableByString,
pybind11::return_value_policy::reference);
m.def("getVariableSize", &mgis::behaviour::getVariableSize);
m.def("getVariableSize",
pybind11::overload_cast<const Variable&,
const mgis::behaviour::Hypothesis>(
&mgis::behaviour::getVariableSize));
m.def("getVariableSize", getVariableSizeByString);
m.def("getArraySize", &mgis::behaviour::getArraySize);
m.def("getVariableOffset", getVariableOffsetByString);
Expand Down
39 changes: 38 additions & 1 deletion docs/web/release-notes-3.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,28 @@ This version is meant to be used with `TFEL` Version 5.2.

# Documentation

## New `cmake` options

### HDF5 support

The following options control the support of the `HDF5` library:

- `enable-hdf5-support`: enable HDF5 support for save/restore
operations. Note that if this support is not explicitely requested,
`MGIS` still tries by default to support `HDF5` but configuration will
not fail if the `HDF5` library is not found. See
`enable-hdf5-automatic-support` for details.
- `enable-hdf5-automatic-support`: if set, `MGIS` tries by default to
support `HDF5` even if enable-hdf5-support` is not set.

## `Doxygen` documentation

The doxygen documentation is now online:
<https://thelfer.github.io/mgis/doxygen/index.html>.

# New features

## Scripts to define environment variables for `mGIS` to work properly
## Scripts to define environment variables for `MGIS` to work properly

Depending on the system and compilation options, some of following
variables shall be set for `MGIS` to work properly: `MGISHOME`, `PATH`,
Expand Down Expand Up @@ -72,6 +86,25 @@ directory (refered to `<install_prefix>` in the following):

# New features of the `MGIS/Behaviour` library

## Save/restore operations in `MaterialStateManager` and `MaterialDataManager`

If `HDF5` support is enabled, two functions `save` and `restore` are
available:

- The `save` function allows saving the values stored in a
`MaterialStateManager` or in a `MaterialDataManager` to an `HDF5`
file.
- The `restore` function allows retrieving the values stored in a
`MaterialStateManager` or in a `MaterialDataManager` from an `HDF5`
file.

Those functions have options allowing to precisely select what is saved
or restored.

By default, one expects to restore the maximum amount of information.
The `getGreedyMaterialStateManagerRestoreOptions` function creates
option that can restore everything that has been saved.

## Control on variables updated/reverted in `MaterialStateManager`

By default, material properties, mass density and external state
Expand Down Expand Up @@ -152,6 +185,10 @@ const auto e2 = f.get<0, tfel::math::stensor<2, real>>(1);

For more details, see <https://github.com/thelfer/MFrontGenericInterfaceSupport/issues/210>

## Issue 209: Add basic support for `save`/`restore` operations in `MaterialDataManager`

For more details, see <https://github.com/thelfer/MFrontGenericInterfaceSupport/issues/209>

## Issue 201: Add the ability to update only the state variables of a `MaterialStateManager`

For more details, see <https://github.com/thelfer/MFrontGenericInterfaceSupport/issues/201>
Expand Down
7 changes: 6 additions & 1 deletion include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ mgis_header(MGIS/Behaviour FiniteStrainSupport.hxx)
mgis_header(MGIS/Model Model.hxx)

if(MGIS_HAVE_TFEL)
mgis_header(MGIS Database.hxx)
mgis_header(MGIS Database.hxx)
endif(MGIS_HAVE_TFEL)

if(MGIS_HDF5_SUPPORT)
mgis_header(MGIS/Utilities HDF5Forward.hxx)
mgis_header(MGIS/Utilities HDF5Support.hxx)
endif(MGIS_HDF5_SUPPORT)

if(enable-mgis-function)
mgis_header(MGIS/Function CompileTimeSize.hxx)
mgis_header(MGIS/Function SpaceConcept.hxx)
Expand Down
44 changes: 44 additions & 0 deletions include/MGIS/Behaviour/MaterialDataManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include <thread>
#include <memory>
#include <vector>
#ifdef MGIS_HAVE_HDF5
#include "MGIS/Utilities/HDF5Forward.hxx"
#endif /* MGIS_HAVE_HDF5 */

#include "MGIS/Config.hxx"
#include "MGIS/Behaviour/MaterialStateManager.hxx"

Expand Down Expand Up @@ -280,6 +284,46 @@ namespace mgis::behaviour {
MGIS_EXPORT std::vector<mgis::real> allocatePostProcessingVariables(
const MaterialDataManager&, const std::string_view);

#ifdef MGIS_HAVE_HDF5

/*!
* \brief structure used to customize the saving of a `MaterialDataManager`
*/
struct MaterialDataManagerSavingOptions
: public MaterialStateManagerSavingOptions {};

/*!
* \brief save a `MaterialDataManager` to an HDF5 group
* \param[in] ctx: execution context
* \param[in] g: group
* \param[in] m: material data manager
* \param[in] opts: options
*/
MGIS_EXPORT [[nodiscard]] bool save(
Context&,
H5::Group&,
const MaterialDataManager&,
const MaterialDataManagerSavingOptions& = {}) noexcept;
/*!
* \brief structure used to customize the saving of a `MaterialDataManager`
*/
struct MaterialDataManagerRestoreOptions
: public MaterialStateManagerRestoreOptions {};
/*!
* \brief restore a `MaterialDataManager` from an HDF5 group
* \param[in] ctx: execution context
* \param[in] g: group
* \param[in] m: material data manager
* \param[in] opts: options
*/
MGIS_EXPORT [[nodiscard]] bool restore(
Context&,
MaterialDataManager&,
const H5::Group&,
const MaterialDataManagerRestoreOptions& = {}) noexcept;

#endif /* MGIS_HAVE_HDF5 */

} // end of namespace mgis::behaviour

#endif /* LIB_MGIS_BEHAVIOUR_MATERIALDATAMANAGER_HXX */
122 changes: 122 additions & 0 deletions include/MGIS/Behaviour/MaterialStateManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <variant>
#include <optional>
#include <string_view>
#ifdef MGIS_HAVE_HDF5
#include "MGIS/Utilities/HDF5Forward.hxx"
#endif /* MGIS_HAVE_HDF5 */

#include "MGIS/Config.hxx"
#include "MGIS/StorageMode.hxx"

Expand Down Expand Up @@ -240,6 +244,37 @@ namespace mgis::behaviour {
const MaterialStateManager::StorageMode =
MaterialStateManager::LOCAL_STORAGE,
const MaterialStateManager::UpdatePolicy = MaterialStateManager::UPDATE);
/*!
* \brief set the given material property
* \param[out] m: material data manager
* \param[in] n: name
* \param[in] v: value
* \param[in] p: update policy
*/
MGIS_EXPORT [[nodiscard]] bool setMaterialProperty(
Context&,
MaterialStateManager&,
const std::string_view&,
const real,
const MaterialStateManager::UpdatePolicy =
MaterialStateManager::UPDATE) noexcept;
/*!
* \brief set the given material property
* \param[out] m: material data manager
* \param[in] n: name
* \param[in] v: values
* \param[in] s: storage mode
* \param[in] p: update policy
*/
MGIS_EXPORT [[nodiscard]] bool setMaterialProperty(
Context&,
MaterialStateManager&,
const std::string_view&,
const std::span<mgis::real>&,
const MaterialStateManager::StorageMode =
MaterialStateManager::LOCAL_STORAGE,
const MaterialStateManager::UpdatePolicy =
MaterialStateManager::UPDATE) noexcept;
/*!
* \return true if the given external state variable is defined.
* \param[out] m: material data manager
Expand Down Expand Up @@ -354,6 +389,93 @@ namespace mgis::behaviour {
const mgis::behaviour::MaterialStateManager&,
const std::string_view);

#ifdef MGIS_HAVE_HDF5

/*!
* \brief structure used to customize the saving of a `MaterialStateManager`
*/
struct MaterialStateManagerSavingOptions {
const bool allow_overwrite = true;
const bool save_gradients = true;
const bool save_thermodynamic_forces = true;
const bool save_stored_energies = true;
const bool save_dissipated_energies = true;
const bool save_mass_densities = true;
const bool save_material_properties = true;
const bool save_external_state_variables = true;
};

/*!
* \brief save a `MaterialStateManager` to an HDF5 group
* \param[in] ctx: execution context
* \param[in] g: group
* \param[in] s: material state manager
* \param[in] opts: options
*/
MGIS_EXPORT [[nodiscard]] bool save(
Context&,
H5::Group&,
const MaterialStateManager&,
const MaterialStateManagerSavingOptions& = {}) noexcept;

/*!
* \brief structure used to customize how to restore a `MaterialStateManager`
*/
struct MaterialStateManagerRestoreOptions {
const bool restore_gradients = true;
const bool restore_thermodynamic_forces = true;
/*!
* \brief flag stating if the stored energies shall be read
*
* \note this flag is ignored if the behaviour does not compute the
* stored energy
*/
const bool restore_stored_energies = true;
/*!
* \brief flag stating if the dissipated energies shall be read
*
* \note this flag is ignored if the behaviour does not compute the
* dissipated energy
*/
const bool restore_dissipated_energies = true;
const bool restore_internal_state_variables = true;
const bool restore_mass_densities = true;
const bool restore_material_properties = true;
//! \brief list of material properties that shall not be restored
const std::vector<std::string> ignored_material_properties = {};
const bool restore_external_state_variables = true;
//! \brief list of external state variables that shall not be restored
const std::vector<std::string> ignored_external_state_variables = {};
}; // end of MaterialStateManagerRestoreOptions
/*!
* \brief return restore options selecting all that can be read in the given
* group.
*
* \param[in] ctx: execution context
* \param[in] g: group
*/
MGIS_EXPORT [[nodiscard]] std::optional<MaterialStateManagerRestoreOptions>
getGreedyMaterialStateManagerRestoreOptions(Context&,
const H5::Group&) noexcept;
/*!
* \brief restore a `MaterialStateManager` from a HDF5 group
*
* \param[in] ctx: execution context
* \param[in] g: group
* \param[in] s: material state manager
* \param[in] opts: options
*
* \note update policies are set to their values for material properties and
* external state variables created during the restoration
*/
MGIS_EXPORT [[nodiscard]] bool restore(
Context&,
MaterialStateManager&,
const H5::Group&,
const MaterialStateManagerRestoreOptions&) noexcept;

#endif /* MGIS_HAVE_HDF5 */

} // end of namespace mgis::behaviour

#endif /* LIB_MGIS_BEHAVIOUR_MATERIALSTATEMANAGER_HXX */
Loading