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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ endif(enable-openmp)

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

Expand Down
3 changes: 3 additions & 0 deletions INSTALL-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ Options
this behaviour.
- `enable-mgis-function`: enable or disable compilation of the `MGIS/Function` library.
By default, compilation of `MGIS/Function` is enabled.
- `enable-mgis-function-precompiled-operations`: enable or disable compilation of
some operations on basic functions. This options is only meaningful if `MGIS/Function`
is enabled and if `TFEL` libraries are available.
- `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
Expand Down
6 changes: 5 additions & 1 deletion bindings/python/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ mgis_python_module(mgis_model model
model-module.cxx
Model.cxx)


if(enable-mgis-function)
mgis_python_module(mgis_function function
function-module.cxx
Function.cxx)
endif(enable-mgis-function)
72 changes: 72 additions & 0 deletions bindings/python/src/Function.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*!
* \file bindings/python/src/Function.cxx
* \brief
* \author Thomas Helfer
* \date 18/11/2025
*/

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "MGIS/Python/NumPySupport.hxx"
#include "MGIS/Function/Function.hxx"
#include "MGIS/Function/BasicLinearSpace.hxx"

mgis::function::FunctionView<mgis::function::BasicLinearSpace,
mgis::function::FunctionDataLayoutDescription{},
false>
mgis_convert_to_span(const pybind11::array_t<double> &o) {
using namespace mgis::function;
const auto i = o.request();
if (i.ndim != 1) {
const auto s = static_cast<mgis::size_type>(i.size);
const auto values = std::span{static_cast<const double *>(i.ptr), s};
return FunctionView<BasicLinearSpace, FunctionDataLayoutDescription{},
false>{BasicLinearSpace{s}, values, 1};
}
mgis::raise("convert_to_span: expected one dimensional array");
} // end of mgis_convert_to_span

void declareFunction(pybind11::module_ &m) {
// FunctionView<BasicLinearSpace, FunctionDataLayoutDescription{}, false
using mgis::real;
//
using BasicFunction =
mgis::function::Function<mgis::function::BasicLinearSpace>;
//
using BasicFunctionView = mgis::function::FunctionView<
mgis::function::BasicLinearSpace,
mgis::function::FunctionDataLayoutDescription{}, true>;

pybind11::class_<BasicFunction>(m, "BasicFunction",
pybind11::buffer_protocol())
.def_buffer([](BasicFunction &f) -> pybind11::buffer_info {
if (f.getNumberOfComponents() == 1) {
return pybind11::buffer_info(
f.data().data(), sizeof(real),
pybind11::format_descriptor<real>::format(), 1,
{getSpaceSize(f.getSpace())}, {sizeof(real)});
}
return pybind11::buffer_info(
f.data().data(), sizeof(real),
pybind11::format_descriptor<real>::format(), 2,
{getSpaceSize(f.getSpace()), f.getNumberOfComponents()},
{sizeof(real) * f.getNumberOfComponents(), sizeof(real)});
});

pybind11::class_<BasicFunctionView>(m, "BasicFunctionView",
pybind11::buffer_protocol())
.def_buffer([](BasicFunctionView &f) -> pybind11::buffer_info {
if (f.getNumberOfComponents() == 1) {
return pybind11::buffer_info(
f.data().data(), sizeof(real),
pybind11::format_descriptor<real>::format(), 1,
{getSpaceSize(f.getSpace())}, {sizeof(real) * f.getDataStride()});
}
return pybind11::buffer_info(
f.data().data(), sizeof(real),
pybind11::format_descriptor<real>::format(), 2,
{getSpaceSize(f.getSpace()), f.getNumberOfComponents()},
{sizeof(real) * f.getDataStride(), sizeof(real)});
});

} // end of declareFunction
20 changes: 20 additions & 0 deletions bindings/python/src/function-module.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*!
* \file bindings/python/src/function-module.cxx
* \brief
* \author Thomas Helfer
* \date 18/11/2025
* \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>

// forward declarations
void declareFunction(pybind11::module_&);

PYBIND11_MODULE(function, m) { declareFunction(m); } // end of module function
11 changes: 11 additions & 0 deletions docs/web/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ The simplest way to compile this package is:

## Options

- `disable-tfel`: by default, `MGIS` tries to add support for `TFEL`,
notably if `tfel-config` is found in the `PATH`. This option disables
this behaviour.
- `enable-mgis-function`: enable or disable compilation of the `MGIS/Function` library.
By default, compilation of `MGIS/Function` is enabled.
- `enable-mgis-function-precompiled-operations`: enable or disable compilation of
some operations on basic functions. This options is only meaningful if `MGIS/Function`
is enabled and if `TFEL` libraries are available.
- `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-c-bindings`: compiles the `C` bindings (default=OFF)
- `enable-fortran-bindings`: compiles bindings for the `Fortran2003`
language (default=OFF)
Expand Down
41 changes: 24 additions & 17 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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)
Expand Down Expand Up @@ -87,25 +88,31 @@ if(enable-mgis-function)
mgis_header(MGIS/Function Algorithms.hxx)
mgis_header(MGIS/Function Algorithms.ixx)
mgis_header(MGIS/Function Buffer.hxx)
mgis_header(MGIS/Function Tensors.hxx)
mgis_header(MGIS/Function Tensors.ixx)
mgis_header(MGIS/Function/Tensors TensorConcept.hxx)
mgis_header(MGIS/Function/Tensors TensorView.hxx)
mgis_header(MGIS/Function/Tensors TensorView.ixx)
mgis_header(MGIS/Function/Tensors TensorModifier.hxx)
mgis_header(MGIS/Function/Tensors TensorModifier.ixx)
mgis_header(MGIS/Function Mechanics.hxx)
mgis_header(MGIS/Function Mechanics.ixx)
mgis_header(MGIS/Function CoalescedMemoryAccessFunctionViewBase.hxx)
mgis_header(MGIS/Function CoalescedMemoryAccessFunctionViewBase.ixx)
mgis_header(MGIS/Function/Tensors CoalescedMemoryAccessTensorView.hxx)
mgis_header(MGIS/Function/Tensors CoalescedMemoryAccessTensorView.ixx)
mgis_header(MGIS/Function/Tensors CoalescedMemoryAccessCompositeTensorsView.hxx)
mgis_header(MGIS/Function/Tensors CoalescedMemoryAccessCompositeTensorsView.ixx)
mgis_header(MGIS/Function StridedCoalescedMemoryAccessFunctionViewBase.hxx)
mgis_header(MGIS/Function StridedCoalescedMemoryAccessFunctionViewBase.ixx)
mgis_header(MGIS/Function/Tensors StridedCoalescedMemoryAccessTensorView.hxx)
mgis_header(MGIS/Function/Tensors StridedCoalescedMemoryAccessTensorView.ixx)
mgis_header(MGIS/Function/Tensors StridedCoalescedMemoryAccessCompositeTensorsView.hxx)
mgis_header(MGIS/Function/Tensors StridedCoalescedMemoryAccessCompositeTensorsView.ixx)
if(MGIS_HAVE_TFEL)
mgis_header(MGIS/Function/TFEL TensorConcept.hxx)
mgis_header(MGIS/Function/TFEL Tensors.hxx)
mgis_header(MGIS/Function/TFEL Tensors.ixx)
mgis_header(MGIS/Function/TFEL TensorView.hxx)
mgis_header(MGIS/Function/TFEL TensorView.ixx)
mgis_header(MGIS/Function/TFEL CoalescedMemoryAccessTensorView.hxx)
mgis_header(MGIS/Function/TFEL CoalescedMemoryAccessTensorView.ixx)
mgis_header(MGIS/Function/TFEL CoalescedMemoryAccessCompositeTensorsView.hxx)
mgis_header(MGIS/Function/TFEL CoalescedMemoryAccessCompositeTensorsView.ixx)
mgis_header(MGIS/Function/TFEL StridedCoalescedMemoryAccessTensorView.hxx)
mgis_header(MGIS/Function/TFEL StridedCoalescedMemoryAccessTensorView.ixx)
mgis_header(MGIS/Function/TFEL StridedCoalescedMemoryAccessCompositeTensorsView.hxx)
mgis_header(MGIS/Function/TFEL StridedCoalescedMemoryAccessCompositeTensorsView.ixx)
mgis_header(MGIS/Function/TFEL TensorModifier.hxx)
mgis_header(MGIS/Function/TFEL TensorModifier.ixx)
mgis_header(MGIS/Function/TFEL Mechanics.hxx)
mgis_header(MGIS/Function/TFEL Mechanics.ixx)
if(enable-mgis-function-precompiled-operations)
mgis_header(MGIS/Function/TFEL TensorOperations.hxx)
mgis_header(MGIS/Function/TFEL MechanicalOperations.hxx)
endif(enable-mgis-function-precompiled-operations)
endif(MGIS_HAVE_TFEL)
endif(enable-mgis-function)
4 changes: 2 additions & 2 deletions include/MGIS/Function/Function.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ namespace mgis::function {
*/
[[nodiscard]] constexpr bool checkCompatibility(const FunctionView&) const;
//! \return a view to the function values
[[nodiscard]] constexpr std::span<real> data() requires(is_mutable);
//! \return a view to the function values
[[nodiscard]] constexpr std::span<const real> data() const;
//! \brief destructor
constexpr ~FunctionView() = default;
Expand Down Expand Up @@ -685,8 +687,6 @@ namespace mgis::function {
view() const;
//
using FunctionView<Space, simple_data_layout_description<N>, true>::data;
//! \return a view to the function values
[[nodiscard]] constexpr std::span<real> data();
/*!
* \brief fill the structure using raw data
*
Expand Down
12 changes: 7 additions & 5 deletions include/MGIS/Function/Function.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,14 @@ namespace mgis::function {
template <LinearFunctionalSpaceConcept Space,
FunctionDataLayoutDescription layout,
bool is_mutable>
constexpr std::span<real>
FunctionView<Space, layout, is_mutable>::data() requires(is_mutable) {
return this->values;
}

template <LinearFunctionalSpaceConcept Space,
FunctionDataLayoutDescription layout,
bool is_mutable>
constexpr std::span<const real> //
FunctionView<Space, layout, is_mutable>::data() const {
return this->values;
Expand Down Expand Up @@ -711,11 +718,6 @@ namespace mgis::function {
}
} // end of view

template <LinearFunctionalSpaceConcept Space, size_type N>
requires(N > 0) constexpr std::span<real> Function<Space, N>::data() {
return this->values;
} // end of data

template <LinearFunctionalSpaceConcept Space, size_type N>
requires(N > 0) constexpr bool Function<Space, N>::fill(
AbstractErrorHandler& eh, std::span<const real> values) noexcept {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* \file MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.hxx
* \file MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.hxx
* \brief
* \author Thomas Helfer
* \date 27/10/2025
Expand All @@ -16,15 +16,15 @@
#error "TFEL is required to use coalesced memory access tensor views"
#endif /* MGIS_HAVE_TFEL */

#ifndef LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_HXX
#define LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_HXX
#ifndef LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_HXX
#define LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_HXX

#include <tuple>
#include <concepts>
#include <type_traits>
#include "TFEL/Math/Array/CoalescedView.hxx"
#include "MGIS/Function/CoalescedMemoryAccessFunctionViewBase.hxx"
#include "MGIS/Function/Tensors/TensorConcept.hxx"
#include "MGIS/Function/TFEL/TensorConcept.hxx"

namespace mgis::function {

Expand Down Expand Up @@ -115,7 +115,7 @@ namespace mgis::function {

} // namespace mgis::function

#include "MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.ixx"
#include "MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.ixx"

#endif /* LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_HXX \
#endif /* LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_HXX \
*/
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* \file MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.ixx
* \file MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.ixx
* \brief
* \author Thomas Helfer
* \date 27/10/2025
Expand All @@ -12,8 +12,8 @@
* CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt).
*/

#ifndef LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX
#define LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX
#ifndef LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_IXX
#define LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_IXX

namespace mgis::function {

Expand Down Expand Up @@ -105,5 +105,5 @@ namespace mgis::function {

} // namespace mgis::function

#endif /* LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX \
#endif /* LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_IXX \
*/
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* \file MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.hxx
* \file MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.hxx
* \brief
* \author Thomas Helfer
* \date 27/10/2025
Expand All @@ -16,12 +16,12 @@
#error "TFEL is required to use coalesced memory access tensor views"
#endif /* MGIS_HAVE_TFEL */

#ifndef LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSTENSORVIEW_HXX
#define LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSTENSORVIEW_HXX
#ifndef LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSTENSORVIEW_HXX
#define LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSTENSORVIEW_HXX

#include "TFEL/Math/Array/CoalescedView.hxx"
#include "MGIS/Function/CoalescedMemoryAccessFunctionViewBase.hxx"
#include "MGIS/Function/Tensors/TensorConcept.hxx"
#include "MGIS/Function/TFEL/TensorConcept.hxx"

namespace mgis::function {

Expand Down Expand Up @@ -87,6 +87,6 @@ namespace mgis::function {

} // namespace mgis::function

#include "MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.ixx"
#include "MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.ixx"

#endif /* LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSTENSORVIEW_HXX */
#endif /* LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSTENSORVIEW_HXX */
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* \file MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.ixx
* \file MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.ixx
* \brief
* \author Thomas Helfer
* \date 27/10/2025
Expand All @@ -12,8 +12,8 @@
* CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt).
*/

#ifndef LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSTENSORVIEW_IXX
#define LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSTENSORVIEW_IXX
#ifndef LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSTENSORVIEW_IXX
#define LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSTENSORVIEW_IXX

namespace mgis::function {

Expand Down Expand Up @@ -74,4 +74,4 @@ namespace mgis::function {

} // namespace mgis::function

#endif /* LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSTENSORVIEW_IXX */
#endif /* LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSTENSORVIEW_IXX */
Loading