|
| 1 | +/*! |
| 2 | + * \file MGIS/Function/TensorialFunction.hxx |
| 3 | + * \brief |
| 4 | + * \author Thomas Helfer |
| 5 | + * \date 28/08/2025 |
| 6 | + */ |
| 7 | + |
| 8 | +#ifndef LIB_MGIS_FUNCTION_TENSORIALFUNCTION_HXX |
| 9 | +#define LIB_MGIS_FUNCTION_TENSORIALFUNCTION_HXX |
| 10 | + |
| 11 | +#include "MGIS/Function/Function.hxx" |
| 12 | +#include "MGIS/Function/Tensors.hxx" |
| 13 | + |
| 14 | +#ifdef MGIS_HAVE_TFEL |
| 15 | + |
| 16 | +namespace mgis::function { |
| 17 | + |
| 18 | + /*! |
| 19 | + * \brief default implementation of a function |
| 20 | + * |
| 21 | + * \tparam Space: type of the functional space |
| 22 | + * \tparam TensorType: tensor type |
| 23 | + * |
| 24 | + * \note the data stride is equal to the data size |
| 25 | + */ |
| 26 | + template <FunctionalSpaceConcept Space, TensorConcept TensorType> |
| 27 | + requires(LinearElementSpaceConcept<Space> || |
| 28 | + LinearQuadratureSpaceConcept<Space>) // |
| 29 | + struct TensorialFunction |
| 30 | + : private PreconditionsChecker<TensorialFunction<Space, TensorType>>, |
| 31 | + private Function<Space, |
| 32 | + tfel::math::getUnderlyingArrayMinimalSize< |
| 33 | + typename TensorType::indexing_policy>()>, |
| 34 | + public TensorView<Function<Space, |
| 35 | + tfel::math::getUnderlyingArrayMinimalSize< |
| 36 | + typename TensorType::indexing_policy>()>, |
| 37 | + TensorType> { |
| 38 | + //! \brief a simple alias |
| 39 | + using UnderlyingFunctionType = |
| 40 | + Function<Space, |
| 41 | + tfel::math::getUnderlyingArrayMinimalSize< |
| 42 | + typename TensorType::indexing_policy>()>; |
| 43 | + //! \brief a simple alias |
| 44 | + using UnderlyingTensorView = |
| 45 | + TensorView<Function<Space, |
| 46 | + tfel::math::getUnderlyingArrayMinimalSize< |
| 47 | + typename TensorType::indexing_policy>()>, |
| 48 | + TensorType>; |
| 49 | + /*! |
| 50 | + * \brief constructor from a space and a data size |
| 51 | + * \param[in] eh: error handler |
| 52 | + * \param[in] s: space |
| 53 | + */ |
| 54 | + [[nodiscard]] static constexpr bool checkPreconditions( |
| 55 | + AbstractErrorHandler&, const Space&); |
| 56 | + /*! |
| 57 | + * \brief constructor from a space |
| 58 | + * Vieparam[in] s: space |
| 59 | + */ |
| 60 | + constexpr TensorialFunction(const Space&); |
| 61 | + /*! |
| 62 | + * \brief constructor from a space |
| 63 | + * \param[in] s: space |
| 64 | + */ |
| 65 | + template <bool doPreconditionsCheck> |
| 66 | + constexpr TensorialFunction(const PreconditionsCheck<doPreconditionsCheck>&, |
| 67 | + const Space&); |
| 68 | + //! \brief move constructor |
| 69 | + constexpr TensorialFunction(TensorialFunction&&); |
| 70 | + //! \brief copy constructor |
| 71 | + constexpr TensorialFunction(const TensorialFunction&); |
| 72 | + //! \brief return a view of the function |
| 73 | + constexpr UnderlyingTensorView& view() noexcept; |
| 74 | + //! \brief return a view of the function |
| 75 | + constexpr const UnderlyingTensorView& view() const noexcept; |
| 76 | + // |
| 77 | + using UnderlyingFunctionType::getSpace; |
| 78 | + using UnderlyingFunctionType::getNumberOfComponents; |
| 79 | + using UnderlyingTensorView::operator(); |
| 80 | + using UnderlyingFunctionType::data; |
| 81 | + // /*! |
| 82 | + // * \brief fill the structure using raw data |
| 83 | + // * |
| 84 | + // * \param[in] eh: error handler |
| 85 | + // * \param[in] values: raw data |
| 86 | + // */ |
| 87 | + // constexpr bool fill(AbstractErrorHandler&, std::span<const real>) |
| 88 | + // noexcept; |
| 89 | + // /*! |
| 90 | + // * \brief fill the structure using raw data |
| 91 | + // * |
| 92 | + // * \param[in] eh: error handler |
| 93 | + // * \param[in] values: raw data |
| 94 | + // */ |
| 95 | + // constexpr bool fill(AbstractErrorHandler&, |
| 96 | + // std::initializer_list<real>) noexcept; |
| 97 | + //! \brief destructor |
| 98 | + constexpr ~TensorialFunction(); |
| 99 | + |
| 100 | + protected: |
| 101 | + /* |
| 102 | + * This function is made protected to avoid Function from being treated |
| 103 | + * as an evaluator |
| 104 | + */ |
| 105 | + using TensorView<Function<Space, |
| 106 | + tfel::math::getUnderlyingArrayMinimalSize< |
| 107 | + typename TensorType::indexing_policy>()>, |
| 108 | + TensorType>::check; |
| 109 | + /* |
| 110 | + * This function is made protected to avoid Function from being treated as |
| 111 | + * an evaluator |
| 112 | + */ |
| 113 | + using TensorView<Function<Space, |
| 114 | + tfel::math::getUnderlyingArrayMinimalSize< |
| 115 | + typename TensorType::indexing_policy>()>, |
| 116 | + TensorType>::allocateWorkspace; |
| 117 | + }; |
| 118 | + |
| 119 | + template <FunctionalSpaceConcept Space, TensorConcept TensorType> |
| 120 | + constexpr decltype(auto) |
| 121 | + getSpace(const TensorialFunction<Space, TensorType>&); |
| 122 | + |
| 123 | + template <FunctionalSpaceConcept Space, unsigned short N> |
| 124 | + using StensorFunction = |
| 125 | + TensorialFunction<Space, tfel::math::stensor<N, real>>; |
| 126 | + template <FunctionalSpaceConcept Space, unsigned short N> |
| 127 | + using TensorFunction = TensorialFunction<Space, tfel::math::tensor<N, real>>; |
| 128 | + template <FunctionalSpaceConcept Space, unsigned short N> |
| 129 | + using ST2toST2Function = |
| 130 | + TensorialFunction<Space, tfel::math::st2tost2<N, real>>; |
| 131 | + template <FunctionalSpaceConcept Space, unsigned short N> |
| 132 | + using T2toST2Function = |
| 133 | + TensorialFunction<Space, tfel::math::t2tost2<N, real>>; |
| 134 | + template <FunctionalSpaceConcept Space, unsigned short N> |
| 135 | + using ST2toT2Function = |
| 136 | + TensorialFunction<Space, tfel::math::st2tot2<N, real>>; |
| 137 | + template <FunctionalSpaceConcept Space, unsigned short N> |
| 138 | + using T2toT2Function = |
| 139 | + TensorialFunction<Space, tfel::math::t2tot2<N, real>>; |
| 140 | + |
| 141 | + |
| 142 | + /*! |
| 143 | + * \brief convert a tensorial function to a immutable view |
| 144 | + * \param[in] f: function |
| 145 | + */ |
| 146 | + template <FunctionalSpaceConcept Space, TensorConcept TensorType> |
| 147 | + constexpr auto view(const TensorialFunction<Space, TensorType>&); |
| 148 | + |
| 149 | + // // class template deduction guide |
| 150 | + // template <FunctionalSpaceConcept SpaceType> |
| 151 | + // TensorialFunction(const SpaceType&, const size_type) |
| 152 | + // -> Function<SpaceType, dynamic_extent>; |
| 153 | + |
| 154 | +} // end of namespace mgis::function |
| 155 | + |
| 156 | +#endif /* MGIS_HAVE_TFEL */ |
| 157 | + |
| 158 | +#include "MGIS/Function/TensorialFunction.ixx" |
| 159 | + |
| 160 | +#endif /* LIB_MGIS_FUNCTION_TENSORIALFUNCTION_HXX */ |
0 commit comments