Skip to content

Commit 4dfbe89

Browse files
authored
Merge pull request #215 from thelfer/160-add-pre-compiled-postprocessings-based-on-mgisfunction
160 add pre compiled postprocessings based on mgisfunction
2 parents 88d2d57 + ea2663f commit 4dfbe89

43 files changed

Lines changed: 879 additions & 173 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ endif(enable-openmp)
3232

3333
# enable mgis-function
3434
option(enable-mgis-function "enable mgis function" ON)
35+
option(enable-mgis-function-precompiled-operations
36+
"enable compilations of some tensorial operations of basic functions. \
37+
This requires mgis-functions to be handled **and** TFEL support" ON)
3538
# enable exceptions usage
3639
option(enable-exceptions "use exceptions to report contract violation and error reporting" OFF)
3740

INSTALL-cmake.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Options
6060
this behaviour.
6161
- `enable-mgis-function`: enable or disable compilation of the `MGIS/Function` library.
6262
By default, compilation of `MGIS/Function` is enabled.
63+
- `enable-mgis-function-precompiled-operations`: enable or disable compilation of
64+
some operations on basic functions. This options is only meaningful if `MGIS/Function`
65+
is enabled and if `TFEL` libraries are available.
6366
- `enable-exceptions`: use exceptions to report contract violation and error reporting.
6467
By default, contract violation leads to abort the program.
6568
- `enable-parallel-stl-algorithms`: by default, STL algorithms are used if available

bindings/python/src/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ mgis_python_module(mgis_model model
6363
model-module.cxx
6464
Model.cxx)
6565

66-
66+
if(enable-mgis-function)
67+
mgis_python_module(mgis_function function
68+
function-module.cxx
69+
Function.cxx)
70+
endif(enable-mgis-function)

bindings/python/src/Function.cxx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*!
2+
* \file bindings/python/src/Function.cxx
3+
* \brief
4+
* \author Thomas Helfer
5+
* \date 18/11/2025
6+
*/
7+
8+
#include <pybind11/pybind11.h>
9+
#include <pybind11/stl.h>
10+
#include "MGIS/Python/NumPySupport.hxx"
11+
#include "MGIS/Function/Function.hxx"
12+
#include "MGIS/Function/BasicLinearSpace.hxx"
13+
14+
mgis::function::FunctionView<mgis::function::BasicLinearSpace,
15+
mgis::function::FunctionDataLayoutDescription{},
16+
false>
17+
mgis_convert_to_span(const pybind11::array_t<double> &o) {
18+
using namespace mgis::function;
19+
const auto i = o.request();
20+
if (i.ndim != 1) {
21+
const auto s = static_cast<mgis::size_type>(i.size);
22+
const auto values = std::span{static_cast<const double *>(i.ptr), s};
23+
return FunctionView<BasicLinearSpace, FunctionDataLayoutDescription{},
24+
false>{BasicLinearSpace{s}, values, 1};
25+
}
26+
mgis::raise("convert_to_span: expected one dimensional array");
27+
} // end of mgis_convert_to_span
28+
29+
void declareFunction(pybind11::module_ &m) {
30+
// FunctionView<BasicLinearSpace, FunctionDataLayoutDescription{}, false
31+
using mgis::real;
32+
//
33+
using BasicFunction =
34+
mgis::function::Function<mgis::function::BasicLinearSpace>;
35+
//
36+
using BasicFunctionView = mgis::function::FunctionView<
37+
mgis::function::BasicLinearSpace,
38+
mgis::function::FunctionDataLayoutDescription{}, true>;
39+
40+
pybind11::class_<BasicFunction>(m, "BasicFunction",
41+
pybind11::buffer_protocol())
42+
.def_buffer([](BasicFunction &f) -> pybind11::buffer_info {
43+
if (f.getNumberOfComponents() == 1) {
44+
return pybind11::buffer_info(
45+
f.data().data(), sizeof(real),
46+
pybind11::format_descriptor<real>::format(), 1,
47+
{getSpaceSize(f.getSpace())}, {sizeof(real)});
48+
}
49+
return pybind11::buffer_info(
50+
f.data().data(), sizeof(real),
51+
pybind11::format_descriptor<real>::format(), 2,
52+
{getSpaceSize(f.getSpace()), f.getNumberOfComponents()},
53+
{sizeof(real) * f.getNumberOfComponents(), sizeof(real)});
54+
});
55+
56+
pybind11::class_<BasicFunctionView>(m, "BasicFunctionView",
57+
pybind11::buffer_protocol())
58+
.def_buffer([](BasicFunctionView &f) -> pybind11::buffer_info {
59+
if (f.getNumberOfComponents() == 1) {
60+
return pybind11::buffer_info(
61+
f.data().data(), sizeof(real),
62+
pybind11::format_descriptor<real>::format(), 1,
63+
{getSpaceSize(f.getSpace())}, {sizeof(real) * f.getDataStride()});
64+
}
65+
return pybind11::buffer_info(
66+
f.data().data(), sizeof(real),
67+
pybind11::format_descriptor<real>::format(), 2,
68+
{getSpaceSize(f.getSpace()), f.getNumberOfComponents()},
69+
{sizeof(real) * f.getDataStride(), sizeof(real)});
70+
});
71+
72+
} // end of declareFunction
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
* \file bindings/python/src/function-module.cxx
3+
* \brief
4+
* \author Thomas Helfer
5+
* \date 18/11/2025
6+
* \copyright (C) Copyright Thomas Helfer 2018.
7+
* Use, modification and distribution are subject
8+
* to one of the following licences:
9+
* - GNU Lesser General Public License (LGPL), Version 3.0. (See accompanying
10+
* file LGPL-3.0.txt)
11+
* - CECILL-C, Version 1.0 (See accompanying files
12+
* CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt).
13+
*/
14+
15+
#include <pybind11/pybind11.h>
16+
17+
// forward declarations
18+
void declareFunction(pybind11::module_&);
19+
20+
PYBIND11_MODULE(function, m) { declareFunction(m); } // end of module function

docs/web/install.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ The simplest way to compile this package is:
5555

5656
## Options
5757

58+
- `disable-tfel`: by default, `MGIS` tries to add support for `TFEL`,
59+
notably if `tfel-config` is found in the `PATH`. This option disables
60+
this behaviour.
61+
- `enable-mgis-function`: enable or disable compilation of the `MGIS/Function` library.
62+
By default, compilation of `MGIS/Function` is enabled.
63+
- `enable-mgis-function-precompiled-operations`: enable or disable compilation of
64+
some operations on basic functions. This options is only meaningful if `MGIS/Function`
65+
is enabled and if `TFEL` libraries are available.
66+
- `enable-exceptions`: use exceptions to report contract violation and error reporting.
67+
By default, contract violation leads to abort the program.
68+
- `enable-parallel-stl-algorithms`: by default, STL algorithms are used if available
5869
- `enable-c-bindings`: compiles the `C` bindings (default=OFF)
5970
- `enable-fortran-bindings`: compiles bindings for the `Fortran2003`
6071
language (default=OFF)

include/CMakeLists.txt

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mgis_header(MGIS/Behaviour BehaviourIntegrationFailureAnalyser.hxx)
4545
mgis_header(MGIS/Behaviour FiniteStrainSupport.hxx)
4646
mgis_header(MGIS/Model Model.hxx)
4747

48+
4849
if(MGIS_HAVE_TFEL)
4950
mgis_header(MGIS Database.hxx)
5051
endif(MGIS_HAVE_TFEL)
@@ -87,25 +88,31 @@ if(enable-mgis-function)
8788
mgis_header(MGIS/Function Algorithms.hxx)
8889
mgis_header(MGIS/Function Algorithms.ixx)
8990
mgis_header(MGIS/Function Buffer.hxx)
90-
mgis_header(MGIS/Function Tensors.hxx)
91-
mgis_header(MGIS/Function Tensors.ixx)
92-
mgis_header(MGIS/Function/Tensors TensorConcept.hxx)
93-
mgis_header(MGIS/Function/Tensors TensorView.hxx)
94-
mgis_header(MGIS/Function/Tensors TensorView.ixx)
95-
mgis_header(MGIS/Function/Tensors TensorModifier.hxx)
96-
mgis_header(MGIS/Function/Tensors TensorModifier.ixx)
97-
mgis_header(MGIS/Function Mechanics.hxx)
98-
mgis_header(MGIS/Function Mechanics.ixx)
9991
mgis_header(MGIS/Function CoalescedMemoryAccessFunctionViewBase.hxx)
10092
mgis_header(MGIS/Function CoalescedMemoryAccessFunctionViewBase.ixx)
101-
mgis_header(MGIS/Function/Tensors CoalescedMemoryAccessTensorView.hxx)
102-
mgis_header(MGIS/Function/Tensors CoalescedMemoryAccessTensorView.ixx)
103-
mgis_header(MGIS/Function/Tensors CoalescedMemoryAccessCompositeTensorsView.hxx)
104-
mgis_header(MGIS/Function/Tensors CoalescedMemoryAccessCompositeTensorsView.ixx)
10593
mgis_header(MGIS/Function StridedCoalescedMemoryAccessFunctionViewBase.hxx)
10694
mgis_header(MGIS/Function StridedCoalescedMemoryAccessFunctionViewBase.ixx)
107-
mgis_header(MGIS/Function/Tensors StridedCoalescedMemoryAccessTensorView.hxx)
108-
mgis_header(MGIS/Function/Tensors StridedCoalescedMemoryAccessTensorView.ixx)
109-
mgis_header(MGIS/Function/Tensors StridedCoalescedMemoryAccessCompositeTensorsView.hxx)
110-
mgis_header(MGIS/Function/Tensors StridedCoalescedMemoryAccessCompositeTensorsView.ixx)
95+
if(MGIS_HAVE_TFEL)
96+
mgis_header(MGIS/Function/TFEL TensorConcept.hxx)
97+
mgis_header(MGIS/Function/TFEL Tensors.hxx)
98+
mgis_header(MGIS/Function/TFEL Tensors.ixx)
99+
mgis_header(MGIS/Function/TFEL TensorView.hxx)
100+
mgis_header(MGIS/Function/TFEL TensorView.ixx)
101+
mgis_header(MGIS/Function/TFEL CoalescedMemoryAccessTensorView.hxx)
102+
mgis_header(MGIS/Function/TFEL CoalescedMemoryAccessTensorView.ixx)
103+
mgis_header(MGIS/Function/TFEL CoalescedMemoryAccessCompositeTensorsView.hxx)
104+
mgis_header(MGIS/Function/TFEL CoalescedMemoryAccessCompositeTensorsView.ixx)
105+
mgis_header(MGIS/Function/TFEL StridedCoalescedMemoryAccessTensorView.hxx)
106+
mgis_header(MGIS/Function/TFEL StridedCoalescedMemoryAccessTensorView.ixx)
107+
mgis_header(MGIS/Function/TFEL StridedCoalescedMemoryAccessCompositeTensorsView.hxx)
108+
mgis_header(MGIS/Function/TFEL StridedCoalescedMemoryAccessCompositeTensorsView.ixx)
109+
mgis_header(MGIS/Function/TFEL TensorModifier.hxx)
110+
mgis_header(MGIS/Function/TFEL TensorModifier.ixx)
111+
mgis_header(MGIS/Function/TFEL Mechanics.hxx)
112+
mgis_header(MGIS/Function/TFEL Mechanics.ixx)
113+
if(enable-mgis-function-precompiled-operations)
114+
mgis_header(MGIS/Function/TFEL TensorOperations.hxx)
115+
mgis_header(MGIS/Function/TFEL MechanicalOperations.hxx)
116+
endif(enable-mgis-function-precompiled-operations)
117+
endif(MGIS_HAVE_TFEL)
111118
endif(enable-mgis-function)

include/MGIS/Function/Function.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ namespace mgis::function {
530530
*/
531531
[[nodiscard]] constexpr bool checkCompatibility(const FunctionView&) const;
532532
//! \return a view to the function values
533+
[[nodiscard]] constexpr std::span<real> data() requires(is_mutable);
534+
//! \return a view to the function values
533535
[[nodiscard]] constexpr std::span<const real> data() const;
534536
//! \brief destructor
535537
constexpr ~FunctionView() = default;
@@ -685,8 +687,6 @@ namespace mgis::function {
685687
view() const;
686688
//
687689
using FunctionView<Space, simple_data_layout_description<N>, true>::data;
688-
//! \return a view to the function values
689-
[[nodiscard]] constexpr std::span<real> data();
690690
/*!
691691
* \brief fill the structure using raw data
692692
*

include/MGIS/Function/Function.ixx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,14 @@ namespace mgis::function {
573573
template <LinearFunctionalSpaceConcept Space,
574574
FunctionDataLayoutDescription layout,
575575
bool is_mutable>
576+
constexpr std::span<real>
577+
FunctionView<Space, layout, is_mutable>::data() requires(is_mutable) {
578+
return this->values;
579+
}
576580

581+
template <LinearFunctionalSpaceConcept Space,
582+
FunctionDataLayoutDescription layout,
583+
bool is_mutable>
577584
constexpr std::span<const real> //
578585
FunctionView<Space, layout, is_mutable>::data() const {
579586
return this->values;
@@ -711,11 +718,6 @@ namespace mgis::function {
711718
}
712719
} // end of view
713720

714-
template <LinearFunctionalSpaceConcept Space, size_type N>
715-
requires(N > 0) constexpr std::span<real> Function<Space, N>::data() {
716-
return this->values;
717-
} // end of data
718-
719721
template <LinearFunctionalSpaceConcept Space, size_type N>
720722
requires(N > 0) constexpr bool Function<Space, N>::fill(
721723
AbstractErrorHandler& eh, std::span<const real> values) noexcept {

include/MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.hxx renamed to include/MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.hxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* \file MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.hxx
2+
* \file MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.hxx
33
* \brief
44
* \author Thomas Helfer
55
* \date 27/10/2025
@@ -16,15 +16,15 @@
1616
#error "TFEL is required to use coalesced memory access tensor views"
1717
#endif /* MGIS_HAVE_TFEL */
1818

19-
#ifndef LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_HXX
20-
#define LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_HXX
19+
#ifndef LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_HXX
20+
#define LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_HXX
2121

2222
#include <tuple>
2323
#include <concepts>
2424
#include <type_traits>
2525
#include "TFEL/Math/Array/CoalescedView.hxx"
2626
#include "MGIS/Function/CoalescedMemoryAccessFunctionViewBase.hxx"
27-
#include "MGIS/Function/Tensors/TensorConcept.hxx"
27+
#include "MGIS/Function/TFEL/TensorConcept.hxx"
2828

2929
namespace mgis::function {
3030

@@ -115,7 +115,7 @@ namespace mgis::function {
115115

116116
} // namespace mgis::function
117117

118-
#include "MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.ixx"
118+
#include "MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.ixx"
119119

120-
#endif /* LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_HXX \
120+
#endif /* LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_HXX \
121121
*/

0 commit comments

Comments
 (0)