|
| 1 | +/*! |
| 2 | + * \file MGIS/Function/CoalescedMemoryAccessFunctionViewBase.ixx |
| 3 | + * \brief |
| 4 | + * \author Thomas Helfer |
| 5 | + * \date 26/10/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 | +#ifndef LIB_MGIS_FUNCTION_COALESCEDMEMORYACCESSFUNCTIONVIEWBASE_IXX |
| 16 | +#define LIB_MGIS_FUNCTION_COALESCEDMEMORYACCESSFUNCTIONVIEWBASE_IXX |
| 17 | + |
| 18 | +namespace mgis::function { |
| 19 | + |
| 20 | + template <FunctionalSpaceConcept Space, size_type N, bool is_mutable> |
| 21 | + requires(N > 0) // |
| 22 | + constexpr bool CoalescedMemoryAccessFunctionViewBase<Space, |
| 23 | + N, |
| 24 | + is_mutable>:: |
| 25 | + checkPreconditions( |
| 26 | + AbstractErrorHandler& eh, |
| 27 | + const std::array<ScalarComponentFunctionView, N>& components) { |
| 28 | + for (int i = 1; i != N; ++i) { |
| 29 | + if (!areEquivalent(getSpace(components[0]), getSpace(components[1]))) { |
| 30 | + return eh.registerErrorMessage("unmatched spaces"); |
| 31 | + } |
| 32 | + } |
| 33 | + for (const auto& c : components) { |
| 34 | + if (!check(eh, c)) { |
| 35 | + return false; |
| 36 | + } |
| 37 | + } |
| 38 | + return true; |
| 39 | + } // end of checkPreconditions |
| 40 | + |
| 41 | + template <FunctionalSpaceConcept Space, size_type N, bool is_mutable> |
| 42 | + requires(N > 0) // |
| 43 | + constexpr CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 44 | + CoalescedMemoryAccessFunctionViewBase( |
| 45 | + const std::array<ScalarComponentFunctionView, N>& components) |
| 46 | + : CoalescedMemoryAccessFunctionViewBase(preconditions_check, components) { |
| 47 | + } // end of CoalescedMemoryAccessFunctionViewBase |
| 48 | + |
| 49 | + template <FunctionalSpaceConcept Space, size_type N, bool is_mutable> |
| 50 | + requires(N > 0) // |
| 51 | + template <bool doPreconditionsCheck> |
| 52 | + constexpr CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 53 | + CoalescedMemoryAccessFunctionViewBase( |
| 54 | + const PreconditionsCheck<doPreconditionsCheck>& pcheck, |
| 55 | + const std::array<ScalarComponentFunctionView, N>& components) |
| 56 | + : PreconditionsChecker<CoalescedMemoryAccessFunctionViewBase>(pcheck, |
| 57 | + components), |
| 58 | + function_components(components) { |
| 59 | + } // end of CoalescedMemoryAccessFunctionViewBase |
| 60 | + |
| 61 | + template <FunctionalSpaceConcept Space, size_type N, bool is_mutable> |
| 62 | + requires(N > 0) // |
| 63 | + constexpr |
| 64 | + typename CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 65 | + MutableValues |
| 66 | + CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 67 | + getValuesPointers(const size_type i) requires( |
| 68 | + is_mutable&& LinearElementSpaceConcept<Space> && |
| 69 | + (!hasElementWorkspace<Space>)) { |
| 70 | + return [ this, i ]<std::size_t... Is>(std::index_sequence<Is...>) |
| 71 | + ->std::array<real*, N> { |
| 72 | + return {&this->function_components[Is](i)...}; |
| 73 | + } |
| 74 | + (std::make_index_sequence<N>()); |
| 75 | + } // end of getValuesPointers |
| 76 | + |
| 77 | + template <FunctionalSpaceConcept Space, size_type N, bool is_mutable> |
| 78 | + requires(N > 0) // |
| 79 | + constexpr |
| 80 | + typename CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 81 | + MutableValues |
| 82 | + CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 83 | + getValuesPointers(const size_type e, |
| 84 | + const size_type q) // |
| 85 | + requires(is_mutable&& LinearQuadratureSpaceConcept<Space> && |
| 86 | + (!hasCellWorkspace<Space>)) { |
| 87 | + return [ this, e, q ]<std::size_t... Is>(std::index_sequence<Is...>) |
| 88 | + ->std::array<real*, N> { |
| 89 | + return {&this->function_components[Is](e, q)...}; |
| 90 | + } |
| 91 | + (std::make_index_sequence<N>()); |
| 92 | + } // end of getValuesPointers |
| 93 | + |
| 94 | + template <FunctionalSpaceConcept Space, size_type N, bool is_mutable> |
| 95 | + requires(N > 0) // |
| 96 | + constexpr |
| 97 | + typename CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 98 | + ConstValues |
| 99 | + CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 100 | + getValuesPointers(const size_type i) const // |
| 101 | + requires(LinearElementSpaceConcept<Space> && |
| 102 | + (!hasElementWorkspace<Space>)) { |
| 103 | + return [ this, i ]<std::size_t... Is>(std::index_sequence<Is...>) |
| 104 | + ->std::array<const real*, N> { |
| 105 | + return {&this->function_components[Is](i)...}; |
| 106 | + } |
| 107 | + (std::make_index_sequence<N>()); |
| 108 | + } // end of getValuesPointers |
| 109 | + |
| 110 | + template <FunctionalSpaceConcept Space, size_type N, bool is_mutable> |
| 111 | + requires(N > 0) // |
| 112 | + constexpr |
| 113 | + typename CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 114 | + ConstValues |
| 115 | + CoalescedMemoryAccessFunctionViewBase<Space, N, is_mutable>:: |
| 116 | + getValuesPointers(const size_type e, const size_type q) const // |
| 117 | + requires(LinearQuadratureSpaceConcept<Space> && |
| 118 | + (!hasCellWorkspace<Space>)) { |
| 119 | + return [ this, e, q ]<std::size_t... Is>(std::index_sequence<Is...>) |
| 120 | + ->std::array<real*, N> { |
| 121 | + return {&this->function_components[Is](e, q)...}; |
| 122 | + } |
| 123 | + (std::make_index_sequence<N>()); |
| 124 | + } // end of getValuesPointers |
| 125 | + |
| 126 | +} // end of namespace mgis::function |
| 127 | + |
| 128 | +#endif /* LIB_MGIS_FUNCTION_COALESCEDMEMORYACCESSFUNCTIONVIEWBASE_IXX */ |
0 commit comments