diff --git a/CMakeLists.txt b/CMakeLists.txt index fec764c5b..8f2b21ed2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/INSTALL-cmake.md b/INSTALL-cmake.md index 189b1e04d..d411c6d4b 100644 --- a/INSTALL-cmake.md +++ b/INSTALL-cmake.md @@ -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 diff --git a/bindings/python/src/CMakeLists.txt b/bindings/python/src/CMakeLists.txt index 223af232c..a1ab67496 100644 --- a/bindings/python/src/CMakeLists.txt +++ b/bindings/python/src/CMakeLists.txt @@ -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) diff --git a/bindings/python/src/Function.cxx b/bindings/python/src/Function.cxx new file mode 100644 index 000000000..a69b33384 --- /dev/null +++ b/bindings/python/src/Function.cxx @@ -0,0 +1,72 @@ +/*! + * \file bindings/python/src/Function.cxx + * \brief + * \author Thomas Helfer + * \date 18/11/2025 + */ + +#include +#include +#include "MGIS/Python/NumPySupport.hxx" +#include "MGIS/Function/Function.hxx" +#include "MGIS/Function/BasicLinearSpace.hxx" + +mgis::function::FunctionView +mgis_convert_to_span(const pybind11::array_t &o) { + using namespace mgis::function; + const auto i = o.request(); + if (i.ndim != 1) { + const auto s = static_cast(i.size); + const auto values = std::span{static_cast(i.ptr), s}; + return FunctionView{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; + // + using BasicFunctionView = mgis::function::FunctionView< + mgis::function::BasicLinearSpace, + mgis::function::FunctionDataLayoutDescription{}, true>; + + pybind11::class_(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::format(), 1, + {getSpaceSize(f.getSpace())}, {sizeof(real)}); + } + return pybind11::buffer_info( + f.data().data(), sizeof(real), + pybind11::format_descriptor::format(), 2, + {getSpaceSize(f.getSpace()), f.getNumberOfComponents()}, + {sizeof(real) * f.getNumberOfComponents(), sizeof(real)}); + }); + + pybind11::class_(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::format(), 1, + {getSpaceSize(f.getSpace())}, {sizeof(real) * f.getDataStride()}); + } + return pybind11::buffer_info( + f.data().data(), sizeof(real), + pybind11::format_descriptor::format(), 2, + {getSpaceSize(f.getSpace()), f.getNumberOfComponents()}, + {sizeof(real) * f.getDataStride(), sizeof(real)}); + }); + +} // end of declareFunction diff --git a/bindings/python/src/function-module.cxx b/bindings/python/src/function-module.cxx new file mode 100644 index 000000000..ba31f1440 --- /dev/null +++ b/bindings/python/src/function-module.cxx @@ -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 + +// forward declarations +void declareFunction(pybind11::module_&); + +PYBIND11_MODULE(function, m) { declareFunction(m); } // end of module function diff --git a/docs/web/install.md b/docs/web/install.md index 72833cb3d..09136ee6d 100644 --- a/docs/web/install.md +++ b/docs/web/install.md @@ -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) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 539424fa0..0cecc999b 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -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) @@ -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) diff --git a/include/MGIS/Function/Function.hxx b/include/MGIS/Function/Function.hxx index a0c60fbb8..f3c686b22 100644 --- a/include/MGIS/Function/Function.hxx +++ b/include/MGIS/Function/Function.hxx @@ -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 data() requires(is_mutable); + //! \return a view to the function values [[nodiscard]] constexpr std::span data() const; //! \brief destructor constexpr ~FunctionView() = default; @@ -685,8 +687,6 @@ namespace mgis::function { view() const; // using FunctionView, true>::data; - //! \return a view to the function values - [[nodiscard]] constexpr std::span data(); /*! * \brief fill the structure using raw data * diff --git a/include/MGIS/Function/Function.ixx b/include/MGIS/Function/Function.ixx index 9d46b4db3..ce9e53b52 100644 --- a/include/MGIS/Function/Function.ixx +++ b/include/MGIS/Function/Function.ixx @@ -573,7 +573,14 @@ namespace mgis::function { template + constexpr std::span + FunctionView::data() requires(is_mutable) { + return this->values; + } + template constexpr std::span // FunctionView::data() const { return this->values; @@ -711,11 +718,6 @@ namespace mgis::function { } } // end of view - template - requires(N > 0) constexpr std::span Function::data() { - return this->values; - } // end of data - template requires(N > 0) constexpr bool Function::fill( AbstractErrorHandler& eh, std::span values) noexcept { diff --git a/include/MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.hxx b/include/MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.hxx similarity index 90% rename from include/MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.hxx rename to include/MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.hxx index 9f8ceaa6e..09ebb7223 100644 --- a/include/MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.hxx +++ b/include/MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.hxx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.hxx + * \file MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.hxx * \brief * \author Thomas Helfer * \date 27/10/2025 @@ -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 #include #include #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 { @@ -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 \ */ diff --git a/include/MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.ixx b/include/MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.ixx similarity index 93% rename from include/MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.ixx rename to include/MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.ixx index a861f5cf8..36063fefc 100644 --- a/include/MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.ixx +++ b/include/MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.ixx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.ixx + * \file MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.ixx * \brief * \author Thomas Helfer * \date 27/10/2025 @@ -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 { @@ -105,5 +105,5 @@ namespace mgis::function { } // namespace mgis::function -#endif /* LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX \ +#endif /* LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_IXX \ */ diff --git a/include/MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.hxx b/include/MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.hxx similarity index 88% rename from include/MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.hxx rename to include/MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.hxx index 366886563..9e25ddb2b 100644 --- a/include/MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.hxx +++ b/include/MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.hxx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.hxx + * \file MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.hxx * \brief * \author Thomas Helfer * \date 27/10/2025 @@ -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 { @@ -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 */ diff --git a/include/MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.ixx b/include/MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.ixx similarity index 91% rename from include/MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.ixx rename to include/MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.ixx index b89c9e249..45b90a28f 100644 --- a/include/MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.ixx +++ b/include/MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.ixx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.ixx + * \file MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.ixx * \brief * \author Thomas Helfer * \date 27/10/2025 @@ -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 { @@ -74,4 +74,4 @@ namespace mgis::function { } // namespace mgis::function -#endif /* LIB_MGIS_FUNCTION_TENSORS_COALESCEDMEMORYACCESSTENSORVIEW_IXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_COALESCEDMEMORYACCESSTENSORVIEW_IXX */ diff --git a/include/MGIS/Function/TFEL/MechanicalOperations.hxx b/include/MGIS/Function/TFEL/MechanicalOperations.hxx new file mode 100644 index 000000000..fb433bc05 --- /dev/null +++ b/include/MGIS/Function/TFEL/MechanicalOperations.hxx @@ -0,0 +1,71 @@ +/*! + * \file MGIS/Function/TFEL/MechanicalOperations.hxx + * \brief + * \author Thomas Helfer + * \date 15/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). + */ + +#ifndef MGIS_HAVE_TFEL +#error "TFEL is required to use tensor evaluators" +#endif /* MGIS_HAVE_TFEL */ + +#ifndef LIB_MGIS_FUNCTION_TFEL_MECHANICALOPERATIONS_HXX +#define LIB_MGIS_FUNCTION_TFEL_MECHANICALOPERATIONS_HXX + +#include +#include "MGIS/Config.hxx" +#include "MGIS/Function/BasicLinearSpace.hxx" +#include "MGIS/Function/Function.hxx" + +namespace mgis::function { + + using BasicImmutableFunctionView = + FunctionView; + + MGIS_EXPORT std::optional> computeTrace( + Context&, const BasicImmutableFunctionView&) noexcept; + + MGIS_EXPORT std::optional> computeVonMisesStress( + Context&, const BasicImmutableFunctionView&) noexcept; + + MGIS_EXPORT std::optional> + computeHydrostraticPressure(Context&, + const BasicImmutableFunctionView&) noexcept; + + MGIS_EXPORT std::optional> computeEigenValues( + Context&, const BasicImmutableFunctionView&) noexcept; + + MGIS_EXPORT std::optional> + computeCauchyStressFromFirstPiolaKirchhoffStress( + Context&, + const BasicImmutableFunctionView&, + const BasicImmutableFunctionView&) noexcept; + + MGIS_EXPORT std::optional> + computeCauchyStressHydrostraticPressureFromFirstPiolaKirchhoffStress( + Context&, + const BasicImmutableFunctionView&, + const BasicImmutableFunctionView&) noexcept; + + MGIS_EXPORT std::optional> + computeCauchyStressVonMisesStressFromFirstPiolaKirchhoffStress( + Context&, + const BasicImmutableFunctionView&, + const BasicImmutableFunctionView&) noexcept; + + MGIS_EXPORT std::optional> + computeCauchyStressEigenValuesFromFirstPiolaKirchhoffStress( + Context&, + const BasicImmutableFunctionView&, + const BasicImmutableFunctionView&) noexcept; + +} // namespace mgis::function + +#endif /* LIB_MGIS_FUNCTION_TFEL_MECHANICALOPERATIONS_HXX */ diff --git a/include/MGIS/Function/Mechanics.hxx b/include/MGIS/Function/TFEL/Mechanics.hxx similarity index 88% rename from include/MGIS/Function/Mechanics.hxx rename to include/MGIS/Function/TFEL/Mechanics.hxx index 389d1e9a0..36163648d 100644 --- a/include/MGIS/Function/Mechanics.hxx +++ b/include/MGIS/Function/TFEL/Mechanics.hxx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Mechanics.hxx + * \file MGIS/Function/TFEL/Mechanics.hxx * \brief * \author Thomas Helfer * \date 02/05/2025 @@ -12,18 +12,17 @@ * CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt). */ -#ifndef LIB_MGIS_FUNCTION_MECHANICS_HXX -#define LIB_MGIS_FUNCTION_MECHANICS_HXX +#ifndef MGIS_HAVE_TFEL +#error "TFEL is required to use this header" +#endif /* MGIS_HAVE_TFEL */ + +#ifndef LIB_MGIS_FUNCTION_TFEL_MECHANICS_HXX +#define LIB_MGIS_FUNCTION_TFEL_MECHANICS_HXX #include -#ifdef MGIS_HAVE_TFEL #include "TFEL/Material/FiniteStrainBehaviourTangentOperator.hxx" -#endif /* MGIS_HAVE_TFEL */ - #include "MGIS/Function/Evaluator.hxx" -#include "MGIS/Function/Tensors.hxx" - -#ifdef MGIS_HAVE_TFEL +#include "MGIS/Function/TFEL/Tensors.hxx" namespace mgis::function { @@ -68,8 +67,6 @@ namespace mgis::function { } // end of namespace mgis::function -#endif /* MGIS_HAVE_TFEL */ - -#include "MGIS/Function/Mechanics.ixx" +#include "MGIS/Function/TFEL/Mechanics.ixx" #endif /* LIB_MGIS_FUNCTION_MECHANICS_HXX */ diff --git a/include/MGIS/Function/Mechanics.ixx b/include/MGIS/Function/TFEL/Mechanics.ixx similarity index 98% rename from include/MGIS/Function/Mechanics.ixx rename to include/MGIS/Function/TFEL/Mechanics.ixx index b88627e19..112108a4d 100644 --- a/include/MGIS/Function/Mechanics.ixx +++ b/include/MGIS/Function/TFEL/Mechanics.ixx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Mechanics.ixx + * \file MGIS/Function/TFEL/Mechanics.ixx * \brief * \author Thomas Helfer * \date 02/05/2025 @@ -12,10 +12,8 @@ * CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt). */ -#ifndef LIB_MGIS_FUNCTION_MECHANICS_IXX -#define LIB_MGIS_FUNCTION_MECHANICS_IXX - -#ifdef MGIS_HAVE_TFEL +#ifndef LIB_MGIS_FUNCTION_TFEL_MECHANICS_IXX +#define LIB_MGIS_FUNCTION_TFEL_MECHANICS_IXX namespace mgis::function::internals { @@ -286,6 +284,4 @@ namespace mgis::function { } // end of namespace mgis::function -#endif /* MGIS_HAVE_TFEL */ - -#endif /* LIB_MGIS_FUNCTION_MECHANICS_IXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_MECHANICS_IXX */ diff --git a/include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.hxx b/include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.hxx similarity index 90% rename from include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.hxx rename to include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.hxx index afaf7f8c5..7b4243572 100644 --- a/include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.hxx +++ b/include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.hxx @@ -1,6 +1,6 @@ /*! * \file - * MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.hxx + * MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.hxx * \brief * \author Thomas Helfer * \date 27/10/2025 @@ -17,15 +17,15 @@ #error "TFEL is required to use strided coalesced memory access tensor views" #endif /* MGIS_HAVE_TFEL */ -#ifndef LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_HXX -#define LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_HXX +#ifndef LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_HXX +#define LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_HXX #include #include #include #include "TFEL/Math/Array/StridedCoalescedView.hxx" #include "MGIS/Function/StridedCoalescedMemoryAccessFunctionViewBase.hxx" -#include "MGIS/Function/Tensors/TensorConcept.hxx" +#include "MGIS/Function/TFEL/TensorConcept.hxx" namespace mgis::function { @@ -116,7 +116,7 @@ namespace mgis::function { } // namespace mgis::function -#include "MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.ixx" +#include "MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.ixx" -#endif /* LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_HXX \ +#endif /* LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORVIEW_HXX \ */ diff --git a/include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.ixx b/include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.ixx similarity index 92% rename from include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.ixx rename to include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.ixx index 0a1733fa5..67a2e409b 100644 --- a/include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.ixx +++ b/include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.ixx @@ -1,6 +1,6 @@ /*! * \file - * MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.ixx + * MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.ixx * \brief * \author Thomas Helfer * \date 27/10/2025 @@ -13,8 +13,8 @@ * CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt). */ -#ifndef LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX -#define LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX +#ifndef LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX +#define LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX namespace mgis::function { @@ -108,5 +108,5 @@ namespace mgis::function { } // namespace mgis::function -#endif /* LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX \ +#endif /* LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSCOMPOSITETENSORSVIEW_IXX \ */ diff --git a/include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.hxx b/include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.hxx similarity index 87% rename from include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.hxx rename to include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.hxx index f420f2da1..0ce5849b1 100644 --- a/include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.hxx +++ b/include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.hxx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.hxx + * \file MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.hxx * \brief * \author Thomas Helfer * \date 27/10/2025 @@ -16,12 +16,12 @@ #error "TFEL is required to use coalesced memory access tensor views" #endif /* MGIS_HAVE_TFEL */ -#ifndef LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_HXX -#define LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_HXX +#ifndef LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_HXX +#define LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_HXX #include "TFEL/Math/Array/StridedCoalescedView.hxx" #include "MGIS/Function/StridedCoalescedMemoryAccessFunctionViewBase.hxx" -#include "MGIS/Function/Tensors/TensorConcept.hxx" +#include "MGIS/Function/TFEL/TensorConcept.hxx" namespace mgis::function { @@ -83,7 +83,7 @@ namespace mgis::function { } // namespace mgis::function -#include "MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.ixx" +#include "MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.ixx" -#endif /* LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_HXX \ +#endif /* LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_HXX \ */ diff --git a/include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.ixx b/include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.ixx similarity index 91% rename from include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.ixx rename to include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.ixx index 7c233a41e..5db0503d3 100644 --- a/include/MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.ixx +++ b/include/MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.ixx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.ixx + * \file MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.ixx * \brief * \author Thomas Helfer * \date 17/01/2026 @@ -12,8 +12,8 @@ * CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt). */ -#ifndef LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_IXX -#define LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_IXX +#ifndef LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_IXX +#define LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_IXX namespace mgis::function { @@ -82,5 +82,5 @@ namespace mgis::function { } // namespace mgis::function -#endif /* LIB_MGIS_FUNCTION_TENSORS_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_IXX \ +#endif /* LIB_MGIS_FUNCTION_TFEL_STRIDEDCOALESCEDMEMORYACCESSTENSORVIEW_IXX \ */ diff --git a/include/MGIS/Function/Tensors/TensorConcept.hxx b/include/MGIS/Function/TFEL/TensorConcept.hxx similarity index 90% rename from include/MGIS/Function/Tensors/TensorConcept.hxx rename to include/MGIS/Function/TFEL/TensorConcept.hxx index e1cc9a950..9a7dc6d01 100644 --- a/include/MGIS/Function/Tensors/TensorConcept.hxx +++ b/include/MGIS/Function/TFEL/TensorConcept.hxx @@ -1,16 +1,23 @@ /*! - * \file MGIS/Function/Tensors/TensorConcept.hxx + * \file MGIS/Function/TFEL/TensorConcept.hxx * \brief * \author Thomas Helfer * \date 10/05/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). */ #ifndef MGIS_HAVE_TFEL #error "TFEL is required to use tensor evaluators" #endif /* MGIS_HAVE_TFEL */ -#ifndef LIB_MGIS_FUNCTION_TENSORCONCEPT_HXX -#define LIB_MGIS_FUNCTION_TENSORCONCEPT_HXX +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSORCONCEPT_HXX +#define LIB_MGIS_FUNCTION_TFEL_TENSORCONCEPT_HXX #include #include "TFEL/Math/fsarray.hxx" @@ -154,4 +161,4 @@ namespace mgis::function { } // end of namespace mgis::function -#endif /* LIB_MGIS_FUNCTION_TENSORCONCEPT_HXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSORCONCEPT_HXX */ diff --git a/include/MGIS/Function/Tensors/TensorModifier.hxx b/include/MGIS/Function/TFEL/TensorModifier.hxx similarity index 72% rename from include/MGIS/Function/Tensors/TensorModifier.hxx rename to include/MGIS/Function/TFEL/TensorModifier.hxx index 6c0bd028a..2cf2bf249 100644 --- a/include/MGIS/Function/Tensors/TensorModifier.hxx +++ b/include/MGIS/Function/TFEL/TensorModifier.hxx @@ -1,16 +1,27 @@ /*! - * \file MGIS/Function/Tensors/TensorModifier.hxx + * \file MGIS/Function/TFEL/TensorModifier.hxx * \brief * \author Thomas Helfer * \date 13/05/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). */ -#ifndef LIB_MGIS_FUNCTION_TENSORMODIFIER_HXX -#define LIB_MGIS_FUNCTION_TENSORMODIFIER_HXX +#ifndef MGIS_HAVE_TFEL +#error "TFEL is required to use this header" +#endif /* MGIS_HAVE_TFEL */ + +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSORMODIFIER_HXX +#define LIB_MGIS_FUNCTION_TFEL_TENSORMODIFIER_HXX #include "MGIS/Function/Evaluator.hxx" #include "MGIS/Function/EvaluatorModifierBase.hxx" -#include "MGIS/Function/Tensors/TensorConcept.hxx" +#include "MGIS/Function/TFEL/TensorConcept.hxx" namespace mgis::function { @@ -58,6 +69,6 @@ namespace mgis::function { } // end of namespace mgis::function -#include "MGIS/Function/Tensors/TensorModifier.ixx" +#include "MGIS/Function/TFEL/TensorModifier.ixx" -#endif /* LIB_MGIS_FUNCTION_TENSORMODIFIER_HXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSORMODIFIER_HXX */ diff --git a/include/MGIS/Function/Tensors/TensorModifier.ixx b/include/MGIS/Function/TFEL/TensorModifier.ixx similarity index 68% rename from include/MGIS/Function/Tensors/TensorModifier.ixx rename to include/MGIS/Function/TFEL/TensorModifier.ixx index fedfb2865..1a5d376ab 100644 --- a/include/MGIS/Function/Tensors/TensorModifier.ixx +++ b/include/MGIS/Function/TFEL/TensorModifier.ixx @@ -1,12 +1,19 @@ /*! - * \file MGIS/Function/TensorModifier.ixx + * \file MGIS/Function/TFEL/TensorModifier.ixx * \brief * \author Thomas Helfer * \date 13/05/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). */ -#ifndef LIB_MGIS_FUNCTION_TENSORMODIFIER_IXX -#define LIB_MGIS_FUNCTION_TENSORMODIFIER_IXX +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSORMODIFIER_IXX +#define LIB_MGIS_FUNCTION_TFEL_TENSORMODIFIER_IXX namespace mgis::function { @@ -35,4 +42,4 @@ namespace mgis::function { } // end of namespace mgis::function -#endif /* LIB_MGIS_FUNCTION_TENSORMODIFIER_IXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSORMODIFIER_IXX */ diff --git a/include/MGIS/Function/TFEL/TensorOperations.hxx b/include/MGIS/Function/TFEL/TensorOperations.hxx new file mode 100644 index 000000000..e33b64a4e --- /dev/null +++ b/include/MGIS/Function/TFEL/TensorOperations.hxx @@ -0,0 +1,106 @@ +/*! + * \file MGIS/Function/TFEL/TensorOperations.hxx + * \brief + * \author Thomas Helfer + * \date 15/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). + */ + +#ifndef MGIS_HAVE_TFEL +#error "TFEL is required to use tensor evaluators" +#endif /* MGIS_HAVE_TFEL */ + +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSOROPERATIONS_HXX +#define LIB_MGIS_FUNCTION_TFEL_TENSOROPERATIONS_HXX + +#include +#include +#include "MGIS/Config.hxx" +#include "MGIS/Function/BasicLinearSpace.hxx" +#include "MGIS/Function/Function.hxx" + +namespace mgis::function { + + /*! + * \brief a simple alias to shorten the declaration of the functions + */ + using BasicImmutableFunctionView = + FunctionView; + + /*! + * \brief type of tensor that are supported + */ + enum struct TensorType { STENSOR, TENSOR, ST2TOST2 }; + /*! + * \brief supported rotation operations + * + * - If the rotation operation is `FORWARD`, the given rotation matrix is used + * directly. + * - If the rotation operation is `BACKWARD`, the transposed of the rotation + * matrix is used. + */ + enum struct RotationOperation { FORWARD, BACKWARD }; + + MGIS_EXPORT std::optional> computeRotatedTensor( + Context&, + const BasicImmutableFunctionView&, + const BasicImmutableFunctionView&, + const TensorType = TensorType::STENSOR, + const RotationOperation = RotationOperation::FORWARD) noexcept; + + MGIS_EXPORT std::optional> computeRotatedTensor( + Context&, + const BasicImmutableFunctionView&, + const std::span&, + const TensorType = TensorType::STENSOR, + const RotationOperation = RotationOperation::FORWARD) noexcept; + + MGIS_EXPORT std::optional> + computeRotatedSymmetricTensor( + Context&, + const BasicImmutableFunctionView&, + const BasicImmutableFunctionView&, + const RotationOperation = RotationOperation::FORWARD) noexcept; + + MGIS_EXPORT std::optional> + computeRotatedSymmetricTensor( + Context&, + const BasicImmutableFunctionView&, + const std::span&, + const RotationOperation = RotationOperation::FORWARD) noexcept; + + MGIS_EXPORT std::optional> + computeRotatedUnsymmetricTensor( + Context&, + const BasicImmutableFunctionView&, + const BasicImmutableFunctionView&, + const RotationOperation = RotationOperation::FORWARD) noexcept; + + MGIS_EXPORT std::optional> + computeRotatedUnsymmetricTensor( + Context&, + const BasicImmutableFunctionView&, + const std::span&, + const RotationOperation = RotationOperation::FORWARD) noexcept; + + MGIS_EXPORT std::optional> computeRotatedST2toST2( + Context&, + const BasicImmutableFunctionView&, + const BasicImmutableFunctionView&, + const RotationOperation = RotationOperation::FORWARD) noexcept; + + MGIS_EXPORT std::optional> computeRotatedST2toST2( + Context&, + const BasicImmutableFunctionView&, + const std::span&, + const RotationOperation = RotationOperation::FORWARD) noexcept; + +} // namespace mgis::function + +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSOROPERATIONS_HXX */ diff --git a/include/MGIS/Function/Tensors/TensorView.hxx b/include/MGIS/Function/TFEL/TensorView.hxx similarity index 89% rename from include/MGIS/Function/Tensors/TensorView.hxx rename to include/MGIS/Function/TFEL/TensorView.hxx index 08ed815b9..0e953a89f 100644 --- a/include/MGIS/Function/Tensors/TensorView.hxx +++ b/include/MGIS/Function/TFEL/TensorView.hxx @@ -1,19 +1,30 @@ /*! - * \file MGIS/Function/TensorView.hxx + * \file MGIS/Function/TFEL/TensorView.hxx * \brief This file declares the TensorView class and the * transform function, as well as the as_fsarray, as_tvector, * as_tmatrix, as_stensor and as_tensor modifiers. * \author Thomas Helfer * \date 09/05/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). */ -#ifndef LIB_MGIS_FUNCTION_TENSORVIEW_HXX -#define LIB_MGIS_FUNCTION_TENSORVIEW_HXX +#ifndef MGIS_HAVE_TFEL +#error "TFEL is required to use this header" +#endif /* MGIS_HAVE_TFEL */ + +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSORVIEW_HXX +#define LIB_MGIS_FUNCTION_TFEL_TENSORVIEW_HXX #include #include "MGIS/Contract.hxx" #include "MGIS/Function/Function.hxx" -#include "MGIS/Function/Tensors/TensorConcept.hxx" +#include "MGIS/Function/TFEL/TensorConcept.hxx" namespace mgis::function { @@ -152,6 +163,6 @@ namespace mgis::function { } // end of namespace mgis::function -#include "MGIS/Function/Tensors/TensorView.ixx" +#include "MGIS/Function/TFEL/TensorView.ixx" -#endif /* LIB_MGIS_FUNCTION_TENSORVIEW_HXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSORVIEW_HXX */ diff --git a/include/MGIS/Function/Tensors/TensorView.ixx b/include/MGIS/Function/TFEL/TensorView.ixx similarity index 94% rename from include/MGIS/Function/Tensors/TensorView.ixx rename to include/MGIS/Function/TFEL/TensorView.ixx index 795e1e833..29f1a0734 100644 --- a/include/MGIS/Function/Tensors/TensorView.ixx +++ b/include/MGIS/Function/TFEL/TensorView.ixx @@ -1,12 +1,20 @@ + /*! - * \file MGIS/Function/TensorView.ixx + * \file MGIS/Function/TFEL/TensorView.ixx * \brief * \author Thomas Helfer * \date 10/05/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). */ -#ifndef LIB_MGIS_FUNCTION_TENSORVIEW_IXX -#define LIB_MGIS_FUNCTION_TENSORVIEW_IXX +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSORVIEW_IXX +#define LIB_MGIS_FUNCTION_TFEL_TENSORVIEW_IXX #include @@ -221,4 +229,4 @@ namespace mgis::function { } // end of namespace mgis::function -#endif /* LIB_MGIS_FUNCTION_TENSORVIEW_IXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSORVIEW_IXX */ diff --git a/include/MGIS/Function/TensorialFunction.hxx b/include/MGIS/Function/TFEL/TensorialFunction.hxx similarity index 93% rename from include/MGIS/Function/TensorialFunction.hxx rename to include/MGIS/Function/TFEL/TensorialFunction.hxx index 578d6f7f6..1b6fccb95 100644 --- a/include/MGIS/Function/TensorialFunction.hxx +++ b/include/MGIS/Function/TFEL/TensorialFunction.hxx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/TensorialFunction.hxx + * \file MGIS/Function/TFEL/TensorialFunction.hxx * \brief * \author Thomas Helfer * \date 28/08/2025 @@ -12,13 +12,15 @@ * CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt). */ -#ifndef LIB_MGIS_FUNCTION_TENSORIALFUNCTION_HXX -#define LIB_MGIS_FUNCTION_TENSORIALFUNCTION_HXX +#ifndef MGIS_HAVE_TFEL +#error "TFEL is required to use this header" +#endif /* MGIS_HAVE_TFEL */ -#include "MGIS/Function/Function.hxx" -#include "MGIS/Function/Tensors.hxx" +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSORIALFUNCTION_HXX +#define LIB_MGIS_FUNCTION_TFEL_TENSORIALFUNCTION_HXX -#ifdef MGIS_HAVE_TFEL +#include "MGIS/Function/Function.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" namespace mgis::function { @@ -150,8 +152,6 @@ namespace mgis::function { } // end of namespace mgis::function -#endif /* MGIS_HAVE_TFEL */ - -#include "MGIS/Function/TensorialFunction.ixx" +#include "MGIS/Function/TFEL/TensorialFunction.ixx" -#endif /* LIB_MGIS_FUNCTION_TENSORIALFUNCTION_HXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSORIALFUNCTION_HXX */ diff --git a/include/MGIS/Function/TensorialFunction.ixx b/include/MGIS/Function/TFEL/TensorialFunction.ixx similarity index 94% rename from include/MGIS/Function/TensorialFunction.ixx rename to include/MGIS/Function/TFEL/TensorialFunction.ixx index b8c3b3e8c..e008dd73e 100644 --- a/include/MGIS/Function/TensorialFunction.ixx +++ b/include/MGIS/Function/TFEL/TensorialFunction.ixx @@ -1,5 +1,6 @@ + /*! - * \file MGIS/Function/TensorialFunction.ixx + * \file MGIS/Function/TFEL/TensorialFunction.ixx * \brief * \author Thomas Helfer * \date 28/08/2025 @@ -12,10 +13,8 @@ * CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt). */ -#ifndef LIB_MGIS_FUNCTION_TENSORIALFUNCTION_IXX -#define LIB_MGIS_FUNCTION_TENSORIALFUNCTION_IXX - -#ifdef MGIS_HAVE_TFEL +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSORIALFUNCTION_IXX +#define LIB_MGIS_FUNCTION_TFEL_TENSORIALFUNCTION_IXX namespace mgis::function { @@ -105,6 +104,4 @@ namespace mgis::function { } // end of namespace mgis::function -#endif /* MGIS_HAVE_TFEL */ - -#endif /* LIB_MGIS_FUNCTION_TENSORIALFUNCTION_HXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSORIALFUNCTION_IXX */ diff --git a/include/MGIS/Function/Tensors.hxx b/include/MGIS/Function/TFEL/Tensors.hxx similarity index 92% rename from include/MGIS/Function/Tensors.hxx rename to include/MGIS/Function/TFEL/Tensors.hxx index 67edd201b..f2b672ba8 100644 --- a/include/MGIS/Function/Tensors.hxx +++ b/include/MGIS/Function/TFEL/Tensors.hxx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Tensors.hxx + * \file MGIS/Function/TFEL/Tensors.hxx * \brief * \author Thomas Helfer * \date 11/05/2025 @@ -12,21 +12,22 @@ * CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt). */ -#ifndef LIB_MGIS_FUNCTION_TENSORS_HXX -#define LIB_MGIS_FUNCTION_TENSORS_HXX +#ifndef MGIS_HAVE_TFEL +#error "TFEL is required to use this header" +#endif /* MGIS_HAVE_TFEL */ + +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSORS_HXX +#define LIB_MGIS_FUNCTION_TFEL_TENSORS_HXX #include "MGIS/Function/FunctionConcept.hxx" #include "MGIS/Function/EvaluatorConcept.hxx" - -#ifdef MGIS_HAVE_TFEL - -#include "MGIS/Function/Tensors/TensorConcept.hxx" -#include "MGIS/Function/Tensors/TensorView.hxx" -#include "MGIS/Function/Tensors/TensorModifier.hxx" -#include "MGIS/Function/Tensors/CoalescedMemoryAccessTensorView.hxx" -#include "MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.hxx" -#include "MGIS/Function/Tensors/StridedCoalescedMemoryAccessTensorView.hxx" -#include "MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.hxx" +#include "MGIS/Function/TFEL/TensorConcept.hxx" +#include "MGIS/Function/TFEL/TensorView.hxx" +#include "MGIS/Function/TFEL/TensorModifier.hxx" +#include "MGIS/Function/TFEL/CoalescedMemoryAccessTensorView.hxx" +#include "MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.hxx" +#include "MGIS/Function/TFEL/StridedCoalescedMemoryAccessTensorView.hxx" +#include "MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.hxx" namespace mgis::function::internals { @@ -67,14 +68,16 @@ namespace mgis::function::internals { [](const TensorType& t, const tfel::math::tmatrix<3, 3, real>& R) // requires((tfel::math::TensorConcept) || - (tfel::math::StensorConcept)) { + (tfel::math::StensorConcept) || + (tfel::math::ST2toST2Concept)) { return tfel::math::change_basis(t, R); }); constexpr auto operator()(const tfel::math::tmatrix<3, 3, real>& R) const { auto c = [R](const TensorType& t) // requires((tfel::math::TensorConcept) || - (tfel::math::StensorConcept)) { + (tfel::math::StensorConcept) || + (tfel::math::ST2toST2Concept)) { return tfel::math::change_basis(t, R); }; return internals::unary_operation_modifier(c); @@ -111,7 +114,8 @@ namespace mgis::function::internals { [](const TensorType& t, const tfel::math::tmatrix<3, 3, real>& R) // requires((tfel::math::TensorConcept) || - (tfel::math::StensorConcept)) { + (tfel::math::StensorConcept) || + (tfel::math::ST2toST2Concept)) { return tfel::math::change_basis(t, tfel::math::transpose(R)); }); @@ -119,7 +123,8 @@ namespace mgis::function::internals { auto c = [Rb = tfel::math::transpose(R)]( const TensorType& t) // requires((tfel::math::TensorConcept) || - (tfel::math::StensorConcept)) { + (tfel::math::StensorConcept) || + (tfel::math::ST2toST2Concept)) { return tfel::math::change_basis(t, Rb); }; return internals::unary_operation_modifier(c); @@ -377,8 +382,6 @@ namespace mgis::function { } // end of namespace mgis::function -#endif /* MGIS_HAVE_TFEL */ - -#include "MGIS/Function/Tensors.ixx" +#include "MGIS/Function/TFEL/Tensors.ixx" -#endif /* LIB_MGIS_FUNCTION_TENSORS_HXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSORS_HXX */ diff --git a/include/MGIS/Function/Tensors.ixx b/include/MGIS/Function/TFEL/Tensors.ixx similarity index 95% rename from include/MGIS/Function/Tensors.ixx rename to include/MGIS/Function/TFEL/Tensors.ixx index 084676e8e..1f54669dc 100644 --- a/include/MGIS/Function/Tensors.ixx +++ b/include/MGIS/Function/TFEL/Tensors.ixx @@ -1,5 +1,5 @@ /*! - * \file MGIS/Function/Tensors.ixx + * \file MGIS/Function/TFEL/Tensors.ixx * \brief * \author Thomas Helfer * \date 13/05/2025 @@ -12,8 +12,8 @@ * CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt). */ -#ifndef LIB_MGIS_FUNCTION_TENSORS_IXX -#define LIB_MGIS_FUNCTION_TENSORS_IXX +#ifndef LIB_MGIS_FUNCTION_TFEL_TENSORS_IXX +#define LIB_MGIS_FUNCTION_TFEL_TENSORS_IXX namespace mgis::function::customization_points { @@ -108,4 +108,4 @@ namespace mgis::function { } // end of namespace mgis::function -#endif /* LIB_MGIS_FUNCTION_TENSORS_IXX */ +#endif /* LIB_MGIS_FUNCTION_TFEL_TENSORS_IXX */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 76e4b4371..685aba8d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,6 +46,11 @@ if(enable-mgis-function) list(APPEND MFrontGenericInterface_SOURCES TensorView.cxx TensorModifier.cxx) + if(enable-mgis-function-precompiled-operations) + list(APPEND MFrontGenericInterface_SOURCES + TensorOperations.cxx + MechanicalOperations.cxx) + endif(enable-mgis-function-precompiled-operations) endif(MGIS_HAVE_TFEL) endif(enable-mgis-function) diff --git a/src/CoalescedMemoryAccessFunctionView.cxx b/src/CoalescedMemoryAccessFunctionView.cxx index 640a98ba6..975f88cc2 100644 --- a/src/CoalescedMemoryAccessFunctionView.cxx +++ b/src/CoalescedMemoryAccessFunctionView.cxx @@ -14,5 +14,5 @@ #include "MGIS/Function/CoalescedMemoryAccessFunctionViewBase.hxx" #ifdef MGIS_HAVE_TFEL -#include "MGIS/Function/Tensors/CoalescedMemoryAccessCompositeTensorsView.hxx" +#include "MGIS/Function/TFEL/CoalescedMemoryAccessCompositeTensorsView.hxx" #endif /* MGIS_HAVE_TFEL */ diff --git a/src/MechanicalOperations.cxx b/src/MechanicalOperations.cxx new file mode 100644 index 000000000..8db8f942b --- /dev/null +++ b/src/MechanicalOperations.cxx @@ -0,0 +1,146 @@ +/*! + * \file src/MechanicalOperations.cxx + * \brief + * \author Thomas Helfer + * \date 01/09/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 +#include "MGIS/Context.hxx" +#include "MGIS/Behaviour/Hypothesis.hxx" +#include "MGIS/Function/BasicLinearSpace.hxx" +#include "MGIS/Function/Algorithms.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" +#include "MGIS/Function/TFEL/Mechanics.hxx" +#include "MGIS/Function/TFEL/MechanicalOperations.hxx" + +namespace mgis::function::internals { + + template + static std::optional> evaluate( + Context& ctx, const EvaluatorType& e) noexcept { + const auto& s = getSpace(e); + const auto nc = getNumberOfComponents(e); + if (!Function::checkPreconditions(ctx, s, nc)) { + return {}; + } + auto r = Function{s, nc}; + if (!assign(ctx, r, e)) { + return {}; + } + return r; + } // end of evaluate + + static std::optional> + evaluateUnaryOperationOnSymmetricTensor( + Context& ctx, + const BasicImmutableFunctionView& f, + const EvaluatorModifierConcept auto& op) noexcept { + if (getNumberOfComponents(f) == 3) { + return internals::evaluate(ctx, f | as_stensor<1> | op); + } else if (getNumberOfComponents(f) == 4) { + return internals::evaluate(ctx, f | as_stensor<2> | op); + } else if (getNumberOfComponents(f) == 6) { + return internals::evaluate(ctx, f | as_stensor<3> | op); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of evaluateUnaryOperationOnSymmetricTensor + + static std::optional> + evaluateUnaryOperationOnCauchyStressComputedFromPK1( + Context& ctx, + const BasicImmutableFunctionView& pk1, + const BasicImmutableFunctionView& F, + const EvaluatorModifierConcept auto& op) noexcept { + if (getNumberOfComponents(pk1) == 3) { + return internals::evaluate( + ctx, pk1 | as_tensor<1> | from_pk1_to_cauchy(F | as_tensor<1>) | op); + } else if (getNumberOfComponents(pk1) == 5) { + return internals::evaluate( + ctx, pk1 | as_tensor<2> | from_pk1_to_cauchy(F | as_tensor<2>) | op); + } else if (getNumberOfComponents(pk1) == 9) { + return internals::evaluate( + ctx, pk1 | as_tensor<3> | from_pk1_to_cauchy(F | as_tensor<3>) | op); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of evaluateUnaryOperationOnUnsymmetricTensor + +} // namespace mgis::function::internals + +namespace mgis::function { + + std::optional> computeTrace( + Context& ctx, const BasicImmutableFunctionView& f) noexcept { + return internals::evaluateUnaryOperationOnSymmetricTensor(ctx, f, trace); + } // end of computeTrace + + std::optional> computeVonMisesStress( + Context& ctx, const BasicImmutableFunctionView& f) noexcept { + return internals::evaluateUnaryOperationOnSymmetricTensor(ctx, f, vmis); + } // end of computeMisesStress + + std::optional> computeHydrostraticPressure( + Context& ctx, const BasicImmutableFunctionView& f) noexcept { + return internals::evaluateUnaryOperationOnSymmetricTensor( + ctx, f, hydrostatic_stress); + } // end of computeHydrostraticPressure + + std::optional> computeEigenValues( + Context& ctx, const BasicImmutableFunctionView& f) noexcept { + return internals::evaluateUnaryOperationOnSymmetricTensor(ctx, f, + eigen_values<>); + } // end of computeHydrostraticPressure + + std::optional> + computeCauchyStressFromFirstPiolaKirchhoffStress( + Context& ctx, + const BasicImmutableFunctionView& pk1, + const BasicImmutableFunctionView& F) noexcept { + if (getNumberOfComponents(pk1) == 3) { + return internals::evaluate( + ctx, pk1 | as_tensor<1> | from_pk1_to_cauchy(F | as_tensor<1>)); + } else if (getNumberOfComponents(pk1) == 5) { + return internals::evaluate( + ctx, pk1 | as_tensor<2> | from_pk1_to_cauchy(F | as_tensor<2>)); + } else if (getNumberOfComponents(pk1) == 9) { + return internals::evaluate( + ctx, pk1 | as_tensor<3> | from_pk1_to_cauchy(F | as_tensor<3>)); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of computeCauchyStressFromFirstPiolaKirchhoffStress + + std::optional> + computeCauchyStressHydrostraticPressureFromFirstPiolaKirchhoffStress( + Context& ctx, + const BasicImmutableFunctionView& pk1, + const BasicImmutableFunctionView& F) noexcept { + return internals::evaluateUnaryOperationOnCauchyStressComputedFromPK1( + ctx, pk1, F, vmis); + } + + std::optional> + computeCauchyStressVonMisesStressFromFirstPiolaKirchhoffStress( + Context& ctx, + const BasicImmutableFunctionView& pk1, + const BasicImmutableFunctionView& F) noexcept { + return internals::evaluateUnaryOperationOnCauchyStressComputedFromPK1( + ctx, pk1, F, vmis); + } // end of computeCauchyStressVonMisesStressFromFirstPiolaKirchhoffStress + + std::optional> + computeCauchyStressEigenValuesFromFirstPiolaKirchhoffStress( + Context& ctx, + const BasicImmutableFunctionView& pk1, + const BasicImmutableFunctionView& F) noexcept { + return internals::evaluateUnaryOperationOnCauchyStressComputedFromPK1( + ctx, pk1, F, eigen_values<>); + } // end of computeStressCauchyEigenValuesFromFirstPiolaKirchhoffStress + +} // end of namespace mgis::function diff --git a/src/StridedCoalescedMemoryAccessFunctionView.cxx b/src/StridedCoalescedMemoryAccessFunctionView.cxx index cebe1670a..a394a550a 100644 --- a/src/StridedCoalescedMemoryAccessFunctionView.cxx +++ b/src/StridedCoalescedMemoryAccessFunctionView.cxx @@ -14,5 +14,5 @@ #include "MGIS/Function/StridedCoalescedMemoryAccessFunctionViewBase.hxx" #ifdef MGIS_HAVE_TFEL -#include "MGIS/Function/Tensors/StridedCoalescedMemoryAccessCompositeTensorsView.hxx" +#include "MGIS/Function/TFEL/StridedCoalescedMemoryAccessCompositeTensorsView.hxx" #endif /* MGIS_HAVE_TFEL */ diff --git a/src/TensorModifier.cxx b/src/TensorModifier.cxx index 463216ad5..ce3256e6b 100644 --- a/src/TensorModifier.cxx +++ b/src/TensorModifier.cxx @@ -3,14 +3,19 @@ * \brief * \author Thomas Helfer * \date 01/09/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). */ -#ifdef MGIS_HAVE_TFEL - #include "MGIS/Function/BasicLinearSpace.hxx" #include "MGIS/Function/Function.hxx" -#include "MGIS/Function/Tensors.hxx" -#include "MGIS/Function/Tensors/TensorModifier.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" +#include "MGIS/Function/TFEL/TensorModifier.hxx" namespace mgis::function { @@ -27,5 +32,3 @@ namespace mgis::function { 6); } // end of namespace mgis::function - -#endif /* MGIS_HAVE_TFEL */ diff --git a/src/TensorOperations.cxx b/src/TensorOperations.cxx new file mode 100644 index 000000000..cdc9b6ef0 --- /dev/null +++ b/src/TensorOperations.cxx @@ -0,0 +1,213 @@ +/*! + * \file src/TensorOperations.cxx + * \brief + * \author Thomas Helfer + * \date 01/09/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 +#include "MGIS/Context.hxx" +#include "MGIS/Behaviour/Hypothesis.hxx" +#include "MGIS/Function/BasicLinearSpace.hxx" +#include "MGIS/Function/Algorithms.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" +#include "MGIS/Function/TFEL/TensorOperations.hxx" + +namespace mgis::function::internals { + + template + static std::optional> evaluate( + Context& ctx, const EvaluatorType& e) noexcept { + const auto& s = getSpace(e); + const auto nc = getNumberOfComponents(e); + if (!Function::checkPreconditions(ctx, s, nc)) { + return {}; + } + auto r = Function{s, nc}; + if (!assign(ctx, r, e)) { + return {}; + } + return r; + } // end of evaluate + + template + std::optional> computeRotatedTensor( + Context& ctx, + const TensorFunctionView& t, + const BasicImmutableFunctionView& r, + const RotationOperation ro) noexcept { + const auto rm = r | as_tmatrix<3, 3>; + if (ro == RotationOperation::FORWARD) { + return internals::evaluate(ctx, t | rotate(rm)); + } else { + return internals::evaluate(ctx, t | rotate_backwards(rm)); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of computeRotatedSymmetricTensor + + template + std::optional> computeRotatedTensor( + Context& ctx, + const TensorFunctionView& t, + const std::span& r, + const RotationOperation ro) noexcept { + const auto rm = tfel::math::tmatrix<3u, 3u, real>{r.data()}; + if (ro == RotationOperation::FORWARD) { + return internals::evaluate(ctx, t | rotate(rm)); + } else { + return internals::evaluate(ctx, t | rotate_backwards(rm)); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of computeRotatedSymmetricTensor + +} // end of namespace mgis::function::internals + +namespace mgis::function { + + std::optional> computeRotatedTensor( + Context& ctx, + const BasicImmutableFunctionView& t, + const BasicImmutableFunctionView& r, + const TensorType type, + const RotationOperation ro) noexcept { + if (type == TensorType::STENSOR) { + return computeRotatedSymmetricTensor(ctx, t, r, ro); + } else if (type == TensorType::TENSOR) { + return computeRotatedUnsymmetricTensor(ctx, t, r, ro); + } else if (type == TensorType::ST2TOST2) { + return computeRotatedST2toST2(ctx, t, r, ro); + } + return ctx.registerErrorMessage( + "computeRotatedTensor: unsupported tensor type"); + } + + std::optional> computeRotatedTensor( + Context& ctx, + const BasicImmutableFunctionView& t, + const std::span& r, + const TensorType type, + const RotationOperation ro) noexcept { + if (type == TensorType::STENSOR) { + return computeRotatedSymmetricTensor(ctx, t, r, ro); + } else if (type == TensorType::TENSOR) { + return computeRotatedUnsymmetricTensor(ctx, t, r, ro); + } else if (type == TensorType::ST2TOST2) { + return computeRotatedST2toST2(ctx, t, r, ro); + } + return ctx.registerErrorMessage( + "computeRotatedTensor: unsupported tensor type"); + } // end of computeRotatedTensor + + std::optional> computeRotatedSymmetricTensor( + Context& ctx, + const BasicImmutableFunctionView& s, + const BasicImmutableFunctionView& r, + const RotationOperation ro) noexcept { + if (getNumberOfComponents(s) == 3) { + return internals::evaluate(ctx, s); + } else if (getNumberOfComponents(s) == 4) { + return internals::computeRotatedTensor(ctx, s | as_stensor<2>, r, ro); + } else if (getNumberOfComponents(s) == 6) { + return internals::computeRotatedTensor(ctx, s | as_stensor<3>, r, ro); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of computeRotatedSymmetricTensor + + std::optional> computeRotatedSymmetricTensor( + Context& ctx, + const BasicImmutableFunctionView& s, + const std::span& r, + const RotationOperation ro) noexcept { + if (r.size() != 9u) { + return ctx.registerErrorMessage( + "computeRotatedSymmetricTensor: invalid number of values for the " + "rotation matrix"); + } + if (getNumberOfComponents(s) == 3) { + return internals::evaluate(ctx, s); + } else if (getNumberOfComponents(s) == 4) { + return internals::computeRotatedTensor(ctx, s | as_stensor<2>, r, ro); + } else if (getNumberOfComponents(s) == 6) { + return internals::computeRotatedTensor(ctx, s | as_stensor<3>, r, ro); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of computeRotatedSymmetricTensor + + std::optional> computeRotatedUnsymmetricTensor( + Context& ctx, + const BasicImmutableFunctionView& s, + const BasicImmutableFunctionView& r, + const RotationOperation ro) noexcept { + if (getNumberOfComponents(s) == 3) { + return internals::evaluate(ctx, s); + } else if (getNumberOfComponents(s) == 5) { + return internals::computeRotatedTensor(ctx, s | as_tensor<2>, r, ro); + } else if (getNumberOfComponents(s) == 9) { + return internals::computeRotatedTensor(ctx, s | as_tensor<3>, r, ro); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of computeRotatedUnsymmetricTensor + + std::optional> computeRotatedUnsymmetricTensor( + Context& ctx, + const BasicImmutableFunctionView& s, + const std::span& r, + const RotationOperation ro) noexcept { + if (r.size() != 9u) { + return ctx.registerErrorMessage( + "computeRotatedUnsymmetricTensor: invalid number of values for the " + "rotation matrix"); + } + if (getNumberOfComponents(s) == 3) { + return internals::evaluate(ctx, s); + } else if (getNumberOfComponents(s) == 5) { + return internals::computeRotatedTensor(ctx, s | as_tensor<2>, r, ro); + } else if (getNumberOfComponents(s) == 9) { + return internals::computeRotatedTensor(ctx, s | as_tensor<3>, r, ro); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of computeRotatedUnsymmetricTensor + + std::optional> computeRotatedST2toST2( + Context& ctx, + const BasicImmutableFunctionView& s, + const BasicImmutableFunctionView& r, + const RotationOperation ro) noexcept { + if (getNumberOfComponents(s) == 9) { + return internals::evaluate(ctx, s); + } else if (getNumberOfComponents(s) == 16) { + return internals::computeRotatedTensor(ctx, s | as_st2tost2<2>, r, ro); + } else if (getNumberOfComponents(s) == 36) { + return internals::computeRotatedTensor(ctx, s | as_st2tost2<3>, r, ro); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of computeRotatedST2toST2 + + std::optional> computeRotatedST2toST2( + Context& ctx, + const BasicImmutableFunctionView& s, + const std::span& r, + const RotationOperation ro) noexcept { + if (r.size() != 9u) { + return ctx.registerErrorMessage( + "computeRotatedST2toST2: invalid number of values for the " + "rotation matrix"); + } + if (getNumberOfComponents(s) == 9) { + return internals::evaluate(ctx, s); + } else if (getNumberOfComponents(s) == 16) { + return internals::computeRotatedTensor(ctx, s | as_st2tost2<2>, r, ro); + } else if (getNumberOfComponents(s) == 36) { + return internals::computeRotatedTensor(ctx, s | as_st2tost2<3>, r, ro); + } + return ctx.registerErrorMessage("invalid number of components"); + } // end of computeRotatedST2toST2 + +} // end of namespace mgis::function diff --git a/src/TensorView.cxx b/src/TensorView.cxx index c328deab3..0565d1965 100644 --- a/src/TensorView.cxx +++ b/src/TensorView.cxx @@ -3,14 +3,19 @@ * \brief * \author Thomas Helfer * \date 01/09/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). */ -#ifdef MGIS_HAVE_TFEL - #include "MGIS/Function/BasicLinearSpace.hxx" #include "MGIS/Function/Function.hxx" -#include "MGIS/Function/Tensors.hxx" -#include "MGIS/Function/Tensors/TensorView.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" +#include "MGIS/Function/TFEL/TensorView.hxx" namespace mgis::function { @@ -27,5 +32,3 @@ namespace mgis::function { 6); } // end of namespace mgis::function - -#endif /* MGIS_HAVE_TFEL */ diff --git a/tests/CoalescedMemoryAccessFunctionViewTest.cxx b/tests/CoalescedMemoryAccessFunctionViewTest.cxx index eb1177628..70952bae3 100644 --- a/tests/CoalescedMemoryAccessFunctionViewTest.cxx +++ b/tests/CoalescedMemoryAccessFunctionViewTest.cxx @@ -17,7 +17,7 @@ #include "MGIS/Function/BasicLinearSpace.hxx" #include "MGIS/Function/BasicLinearQuadratureSpace.hxx" #include "MGIS/Function/CoalescedMemoryAccessFunctionViewBase.hxx" -#include "MGIS/Function/Tensors.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" namespace mgis::function {} // end of namespace mgis::function diff --git a/tests/EvaluatorsTest.cxx b/tests/EvaluatorsTest.cxx index f01455b40..f1bc71f74 100644 --- a/tests/EvaluatorsTest.cxx +++ b/tests/EvaluatorsTest.cxx @@ -24,7 +24,7 @@ #include "MGIS/Function/Evaluator.hxx" #include "MGIS/Function/FixedSizeView.hxx" #include "MGIS/Function/FixedSizeModifier.hxx" -#include "MGIS/Function/Tensors.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" struct EvaluatorsTest final : public tfel::tests::TestCase { EvaluatorsTest() diff --git a/tests/MechanicalEvaluatorsTest.cxx b/tests/MechanicalEvaluatorsTest.cxx index 0e6e91b40..87400b0ce 100644 --- a/tests/MechanicalEvaluatorsTest.cxx +++ b/tests/MechanicalEvaluatorsTest.cxx @@ -21,7 +21,7 @@ #include "MGIS/Function/Function.hxx" #include "MGIS/Function/FixedSizeView.hxx" #include "MGIS/Function/FixedSizeModifier.hxx" -#include "MGIS/Function/Mechanics.hxx" +#include "MGIS/Function/TFEL/Mechanics.hxx" struct MechanicalEvaluatorsTest final : public tfel::tests::TestCase { MechanicalEvaluatorsTest() diff --git a/tests/StridedCoalescedMemoryAccessFunctionViewTest.cxx b/tests/StridedCoalescedMemoryAccessFunctionViewTest.cxx index a3eb9e367..d21c170ff 100644 --- a/tests/StridedCoalescedMemoryAccessFunctionViewTest.cxx +++ b/tests/StridedCoalescedMemoryAccessFunctionViewTest.cxx @@ -17,7 +17,7 @@ #include "MGIS/Function/BasicLinearSpace.hxx" #include "MGIS/Function/BasicLinearQuadratureSpace.hxx" #include "MGIS/Function/StridedCoalescedMemoryAccessFunctionViewBase.hxx" -#include "MGIS/Function/Tensors.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" namespace mgis::function {} // end of namespace mgis::function diff --git a/tests/TensorialFunctionTest.cxx b/tests/TensorialFunctionTest.cxx index 46747c30b..0f468e43b 100644 --- a/tests/TensorialFunctionTest.cxx +++ b/tests/TensorialFunctionTest.cxx @@ -25,8 +25,8 @@ #include "MGIS/Function/Evaluator.hxx" #include "MGIS/Function/FixedSizeView.hxx" #include "MGIS/Function/FixedSizeModifier.hxx" -#include "MGIS/Function/Tensors.hxx" -#include "MGIS/Function/TensorialFunction.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" +#include "MGIS/Function/TFEL/TensorialFunction.hxx" struct TensorialFunctionsTest final : public tfel::tests::TestCase { TensorialFunctionsTest() diff --git a/tests/UniformEvaluatorsTest.cxx b/tests/UniformEvaluatorsTest.cxx index e74d8873f..cb22009c1 100644 --- a/tests/UniformEvaluatorsTest.cxx +++ b/tests/UniformEvaluatorsTest.cxx @@ -20,7 +20,7 @@ #include "TFEL/Tests/TestManager.hxx" #include "MGIS/Function/BasicLinearSpace.hxx" #include "MGIS/Function/UniformEvaluator.hxx" -#include "MGIS/Function/Tensors.hxx" +#include "MGIS/Function/TFEL/Tensors.hxx" struct UniformEvaluatorsTest final : public tfel::tests::TestCase { UniformEvaluatorsTest()