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
4 changes: 2 additions & 2 deletions bindings/julia/src/Integrate.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static int integrateBehaviourData1(mgis::behaviour::BehaviourData& d,
} // end of integrateBehaviourData1

static int integrateDebugBehaviourData1(mgis::behaviour::BehaviourData& d,
const mgis::behaviour::Behaviour& b) {
const mgis::behaviour::Behaviour& b) {
auto v = mgis::behaviour::make_view(d);
const auto s = mgis::behaviour::integrate_debug(v, b);
return s;
Expand Down Expand Up @@ -73,7 +73,7 @@ void declareIntegrate(jlcxx::Module& m) {
const mgis::behaviour::Behaviour&) =
mgis::behaviour::integrate;
int (*integrate_debug_ptr1)(mgis::behaviour::BehaviourDataView&,
const mgis::behaviour::Behaviour&) =
const mgis::behaviour::Behaviour&) =
mgis::behaviour::integrate_debug;
// int (*integrate_ptr2)(mgis::behaviour::MaterialDataManager&,
// const IntegrationType, const mgis::real,
Expand Down
13 changes: 10 additions & 3 deletions bindings/python/mgis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
add_subdirectory(fenics)

install(FILES __init__.py
DESTINATION ${MGIS_PYTHON_MODULES_INSTALL_DIRECTORY}
COMPONENT python_bindings)
if(MGIS_HAVE_TFEL AND TFEL_PYTHON_BINDINGS)
install(FILES __init__-have-tfel.py
DESTINATION ${MGIS_PYTHON_MODULES_INSTALL_DIRECTORY}
COMPONENT python_bindings
RENAME __init__.py)
else()
install(FILES __init__.py
DESTINATION ${MGIS_PYTHON_MODULES_INSTALL_DIRECTORY}
COMPONENT python_bindings)
endif()
7 changes: 7 additions & 0 deletions bindings/python/mgis/__init__-have-tfel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
try:
import mfront.database
except:
print("loading mfront.database model failed")
pass

from ._mgis import *
12 changes: 12 additions & 0 deletions bindings/python/src/Behaviour.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,16 @@ Behaviour_getPostProcessingOutputs(const mgis::behaviour::Behaviour &b,
return p->second.outputs;
} // end of Behaviour_getPostProcessingOutputs

static mgis::behaviour::Behaviour Behaviour_loadFromDatabase(
const std::string &n,
const mgis::behaviour::Hypothesis h,
const std::optional<std::string> &m) {
return mgis::behaviour::loadFromDatabase(
{.name = n, .hypothesis = h, .material = m});
} // end of Behaviour_loadFromDatabase

void declareBehaviour(pybind11::module_ &m) {
using namespace pybind11::literals;
using mgis::behaviour::Behaviour;
using mgis::behaviour::BehaviourDescription;
using mgis::behaviour::FiniteStrainBehaviourOptions;
Expand Down Expand Up @@ -250,6 +259,9 @@ void declareBehaviour(pybind11::module_ &m) {

m.def("load", load_ptr);
m.def("load", load_ptr2);
m.def("loadFromDatabase", Behaviour_loadFromDatabase, "name"_a,
"hypothesis"_a, "material"_a = std::optional<std::string>{});

m.def("setParameter", setParameter1);
m.def("setIntegerParameter", setParameter2);
m.def("setUnsignedShortParameter", setParameter3);
Expand Down
8 changes: 7 additions & 1 deletion bindings/python/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ function(mgis_python_module fullname name)
COMPONENT python_bindings)
endfunction(mgis_python_module)

mgis_python_module(mgis _mgis
set(MGIS_MODULE_SOURCES)
list(APPEND MGIS_MODULE_SOURCES
mgis-module.cxx
ThreadPool.cxx)
if(MGIS_HAVE_TFEL)
list(APPEND MGIS_MODULE_SOURCES
Database.cxx)
endif(MGIS_HAVE_TFEL)
mgis_python_module(mgis _mgis ${MGIS_MODULE_SOURCES})

mgis_python_module(mgis_material_property material_property
material_property-module.cxx
Expand Down
23 changes: 23 additions & 0 deletions bindings/python/src/Database.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*!
* \file bindings/python/src/Database.cxx
* \brief
* \author Thomas Helfer
* \date 31/10/2018
* \copyright (C) Copyright Thomas Helfer 2018.
* Use, modification and distribution are subject
* to one of the following licences:
* - GNU Lesser General Public License (LGPL), Version 3.0. (See accompanying
* file LGPL-3.0.txt)
* - CECILL-C, Version 1.0 (See accompanying files
* CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt).
*/

#include <pybind11/pybind11.h>
#include "MGIS/Database.hxx"

void declareDatabase(pybind11::module_&);

void declareDatabase(pybind11::module_& m) {
m.def("getDatabase", mgis::getDatabase,
pybind11::return_value_policy::reference);
} // end of declareDatabase
12 changes: 7 additions & 5 deletions bindings/python/src/Integrate.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static int integrateBehaviourData1(mgis::behaviour::BehaviourData& d,
} // end of integrateBehaviourData

static int integrateDebugBehaviourData1(mgis::behaviour::BehaviourData& d,
const mgis::behaviour::Behaviour& b) {
const mgis::behaviour::Behaviour& b) {
auto v = mgis::behaviour::make_view(d);
const auto s = mgis::behaviour::integrate_debug(v, b);
return s;
Expand Down Expand Up @@ -246,12 +246,14 @@ void declareIntegrate(pybind11::module_& m) {
MultiThreadedBehaviourIntegrationResult (*integrate_ptr5)(
mgis::ThreadPool&, MaterialDataManager&,
const BehaviourIntegrationOptions&, const mgis::real) = integrate;
int (*integrate_debug_ptr1)(BehaviourDataView&, const Behaviour&) = integrate_debug;
int (*integrate_debug_ptr1)(BehaviourDataView&, const Behaviour&) =
integrate_debug;
int (*integrate_debug_ptr2)(MaterialDataManager&, const IntegrationType,
const mgis::real, const mgis::size_type,
const mgis::size_type) = integrate_debug;
const mgis::real, const mgis::size_type,
const mgis::size_type) = integrate_debug;
int (*integrate_debug_ptr3)(mgis::ThreadPool&, MaterialDataManager&,
const IntegrationType, const mgis::real) = integrate_debug;
const IntegrationType, const mgis::real) =
integrate_debug;
BehaviourIntegrationResult (*integrate_debug_ptr4)(
MaterialDataManager&, const BehaviourIntegrationOptions&,
const mgis::real, const mgis::size_type, const mgis::size_type) =
Expand Down
17 changes: 16 additions & 1 deletion bindings/python/src/Model.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@
*/

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "MGIS/Model/Model.hxx"

// forward declaration
void declareModel(pybind11::module_& m);

static mgis::model::Model Model_loadFromDatabase(
const std::string& n,
const mgis::behaviour::Hypothesis h,
const std::optional<std::string>& m) {
return mgis::model::loadFromDatabase(
{.name = n, .hypothesis = h, .material = m});
} // end of Behaviour_loadFromDatabase

void declareModel(pybind11::module_& m) {
using namespace pybind11::literals;
// wrapping free functions
m.def("load", mgis::model::load);
m.def("load", pybind11::overload_cast<const std::string&, const std::string&,
const mgis::behaviour::Hypothesis>(
mgis::model::load));
m.def("loadFromDatabase", Model_loadFromDatabase, "name"_a, "hypothesis"_a,
"material"_a = std::optional<std::string>{});

} // end of declareModel
2 changes: 1 addition & 1 deletion bindings/python/src/NumPySupport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace mgis::python {
return pybind11::array_t<double>(
{v.size() / nc, nc}, /* Buffer dimensions */
{nc * sizeof(double), sizeof(double)}, v.data(), pybind11::none());
} // end of wrapInNumPyArray
} // end of wrapInNumPyArray

pybind11::array_t<double> wrapInNumPyArray(std::vector<double>& v,
const size_type nc) {
Expand Down
10 changes: 9 additions & 1 deletion bindings/python/src/mgis-module.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
#include <pybind11/pybind11.h>

void declareThreadPool(pybind11::module_&);
#ifdef MGIS_HAVE_TFEL
void declareDatabase(pybind11::module_&);
#endif /* MGIS_HAVE_TFEL */

PYBIND11_MODULE(_mgis, m) { declareThreadPool(m); } // end of module behaviour
PYBIND11_MODULE(_mgis, m) {
declareThreadPool(m);
#ifdef MGIS_HAVE_TFEL
declareDatabase(m);
#endif /* MGIS_HAVE_TFEL */
} // end of module behaviour
1 change: 1 addition & 0 deletions cmake/modules/FindTFEL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(tfel_libs
TFELMaterial
TFELMath
MTestFileGenerator
TFELMFrontDatabase
)

if(DEFINED TFEL_DIR)
Expand Down
29 changes: 26 additions & 3 deletions docs/web/install.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
% Installation Guide
% Thomas Helfer
% 20/01/2020
---
title: Installation guide
author: Thomas Helfer
date: 2025
lang: en-EN
numbersections: true
documentclass: article
from: markdown+tex_math_single_backslash
geometry:
- margin=2cm
papersize: a4
link-citations: true
colorlinks: true
figPrefixTemplate: "$$i$$"
tabPrefixTemplate: "$$i$$"
secPrefixTemplate: "$$i$$"
eqnPrefixTemplate: "($$i$$)"
bibliography: bibliography.bib
---

# Installing from source

Expand Down Expand Up @@ -56,6 +72,13 @@ The simplest way to compile this package is:
- `enable-doxygen-doc`: enable the generation of the API documentation
using with `Doxygen`.

By default, the library tries to autodetect the TFEL libraries and
expects that a working version of TFEL is available in the
environnement. The `disable-tfel` option can be used to disable this
feature. The `TFEL_DIR` variable can be passed to `cmake` to help the
detection of the `TFEL` libraries: it must points to the `cmake` files
generated by the `TFEL` project.

## `cmake` usefull variables

- `CMAKE_BUILD_TYPE` : two values are supported `Release` and `Debug`
Expand Down
101 changes: 99 additions & 2 deletions docs/web/release-notes-3.1.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: MFrontGenericInterfaceSupport Version 3.1
author: Thomas Helfer
date: 2024
date: 2025
lang: en-EN
numbersections: true
documentclass: article
Expand All @@ -18,7 +18,104 @@ eqnPrefixTemplate: "($$i$$)"
bibliography: bibliography.bib
---

This version is meant to be used with `TFEL` Version 5.1.
This version is meant to be used with `TFEL` Version 5.1. This version
is the first that can optionnaly use directly the `TFEL` libraries.

# The `MGIS/Function` library

The main new feature of `MGIS` is the `MGIS/Function`[^functions]
library, which has been introduced to provide standard mechanical
post-processings based on the `TFEL/Math` and `TFEL/Material` libraries.
`MGIS/Function` allows reusing the large amount of documented and
verified functionalities provided by those libraries at the structural
scale, including: rotation from/to material frame, conversion between
stress measures, Hencky and Green-Lagrange strains, Tresca, von Mises,
Hosford, Hill, Barlat equivalent stresses, principal values, Lode's
angle, etc.

[^functions] A function denote a set of values associated with the
elements (nodes, quadrature points, cells) of a discretized space.
Functions are often called `fields` in many solvers.

The following snippet computes the Cauchy stress in the global frame
from the first Piola-Kirchhoff stress known in the material frame.

~~~~{.cxx}
const auto evaluator = pk1_function | as_tensor<3> |
from_pk1_to_cauchy (F_function | as_tensor<3>) |
rotate_backwards (R_function | as_matrix<3,3>);
const auto ok = assign(ctx, sig | as_stensor<3>, evaluator);
~~~~

The library is developed in `C++-20` with high-quality requirements and
strives to be `constexpr` friendly, memory-safe, thread-safe,
exception-safe, and `GPU-friendly`.

The data structures of the functions depend on the targeted solver, as
well as the implementation of the `assign`, which depends on the
programming model chosen by the targeted solver (`OpenMP`, `CUDA`,
`SYCL`, `Kokkos`, etc.).

For standard data structures, such as the one used by `Numpy`'s array,
so-called `views` are provided allowing direct usage of the library. In
this case, an implementation of the `assign` algorithm is provided by
the parallel version of the Standard library. Depending on the compiler
and implementation of the standard library, various parallel programming
models are used (multithreading and GPU-offloading).

The `MGIS/Function` library is described on [this page](functions.html).

# Improvements

## `getDatabase` and `loadFromDatabase`

> **Note**
>
> This feature requires `MGIS` to be compiled againt the `TFEL` libraries.

The `mgis::getDatabase` function returns a global instance of an
`MFrontDatabase` object. See [this
page](https://thelfer.github.iotfel/web/tfel-mfront-database.html) for
more details. This instance can be populated using a library, a
directory or a list of directories specified in an environment variable.

The function `mgis::behaviour::loadFromDatabase` relies on the previous
database to load a behaviour matching the given criteria:

- the name (required) of the behaviour of the loaded,
- the material (optional)

### Example of usage

The following example registers all the material knownledge available in
the shared libraries found in directories listed in an environment
variable and lists all the behaviours compiled with the `generic`
interface:

~~~~{.python}
import mgis
db = mgis.getDatabase()
db.analyseDirectoriesListedInEnvironmentVariable('MFRONT_GALLERY_LIBRARIES',
ignore_errors = True)
for e in db.getEntryPoints(type = 'behaviour',
interface = 'generic',
material = 'concrete'):
print(f"- {e.library}: {e.name}")
~~~~

The following snippet populates the database using all the libraries of
a given directory and loads a behaviour whose name of which contains
`Elasticity` and which is associated with the material wood.

~~~~{.python}
import mgis
import mgis.behaviour as mgis_bv
db = mgis.getDatabase()
db.analyseDirectory('/home/th202608/codes/MFrontGallery/master/install/lib/',
ignore_errors = True)
b = mgis_bv.loadFromDatabase(name='\\w+Elasticity\\w+', material='Wood',
hypothesis = mgis.behaviour.Hypothesis.Tridimensional)
~~~~

# Python bindings

Expand Down
4 changes: 4 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ mgis_header(MGIS/Behaviour BehaviourIntegrationFailureAnalyser.hxx)
mgis_header(MGIS/Behaviour FiniteStrainSupport.hxx)
mgis_header(MGIS/Model Model.hxx)

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

if(enable-mgis-function)
mgis_header(MGIS/Function CompileTimeSize.hxx)
mgis_header(MGIS/Function SpaceConcept.hxx)
Expand Down
Loading