Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include "DataStructures/VectorImpl.hpp"
7 : #include "Utilities/TMPL.hpp"
8 :
9 : /// \cond
10 : class ModalVector;
11 : /// \endcond
12 :
13 : namespace blaze {
14 0 : DECLARE_GENERAL_VECTOR_BLAZE_TRAITS(ModalVector);
15 : } // namespace blaze
16 :
17 : /*!
18 : * \ingroup DataStructuresGroup
19 : * \brief A class for storing spectral coefficients on a spectral grid.
20 : *
21 : * \details A ModalVector holds an array of spectral coefficients, and can be
22 : * either owning (the array is deleted when the ModalVector goes out of scope)
23 : * or non-owning, meaning it just has a pointer to an array.
24 : *
25 : * Only basic mathematical operations are supported with
26 : * ModalVectors. ModalVectors may be added or subtracted, and the following
27 : * unary operations are supported:
28 : * - abs
29 : *
30 : * Also multiplication is supported with doubles and `ModalVector`s, and
31 : * `ModalVector`s can be divided by doubles. Multiplication is supported with
32 : * `DiagonalModalOperator`s and `ModalVector`s.
33 : */
34 1 : class ModalVector : public VectorImpl<double, ModalVector> {
35 : public:
36 0 : ModalVector() = default;
37 0 : ModalVector(const ModalVector&) = default;
38 0 : ModalVector(ModalVector&&) = default;
39 0 : ModalVector& operator=(const ModalVector&) = default;
40 0 : ModalVector& operator=(ModalVector&&) = default;
41 0 : ~ModalVector() = default;
42 :
43 0 : using BaseType = VectorImpl<double, ModalVector>;
44 :
45 : using BaseType::operator=;
46 : using BaseType::VectorImpl;
47 : };
48 :
49 : namespace blaze {
50 : template <>
51 0 : struct TransposeFlag<ModalVector> : BoolConstant<ModalVector::transpose_flag> {
52 : };
53 : template <>
54 0 : struct AddTrait<ModalVector, ModalVector> {
55 0 : using Type = ModalVector;
56 : };
57 : template <>
58 0 : struct SubTrait<ModalVector, ModalVector> {
59 0 : using Type = ModalVector;
60 : };
61 0 : BLAZE_TRAIT_SPECIALIZE_COMPATIBLE_BINARY_TRAIT(ModalVector, double, MultTrait,
62 : ModalVector);
63 : template <>
64 0 : struct DivTrait<ModalVector, double> {
65 0 : using Type = ModalVector;
66 : };
67 :
68 : template <typename Operator>
69 0 : struct MapTrait<ModalVector, Operator> {
70 : // Selectively allow unary operations for spectral coefficients
71 : static_assert(
72 : tmpl::list_contains_v<
73 : tmpl::list<blaze::Abs, blaze::Bind1st<blaze::Add, double>,
74 : blaze::Bind2nd<blaze::Add, double>,
75 : blaze::Bind1st<blaze::Sub, double>,
76 : blaze::Bind2nd<blaze::Sub, double>,
77 : blaze::Bind1st<blaze::Add, std::complex<double>>,
78 : blaze::Bind2nd<blaze::Add, std::complex<double>>,
79 : blaze::Bind1st<blaze::Sub, std::complex<double>>,
80 : blaze::Bind2nd<blaze::Sub, std::complex<double>>>,
81 : Operator>,
82 : "The only unary operation permitted on a ModalVector is:"
83 : " abs.");
84 0 : using Type = ModalVector;
85 : };
86 :
87 : template <typename Operator>
88 0 : struct MapTrait<ModalVector, ModalVector, Operator> {
89 : // Forbid math operations in this specialization of BinaryMap traits for
90 : // ModalVector that are unlikely to be used on spectral coefficients.
91 : // Currently no non-arithmetic binary operations are supported.
92 : static_assert(tmpl::list_contains_v<tmpl::list<>, Operator>,
93 : "This binary operation is not permitted on a ModalVector.");
94 0 : using Type = ModalVector;
95 : };
96 : } // namespace blaze
97 :
98 : /// \cond
99 : DEFINE_STD_ARRAY_BINOP(ModalVector, ModalVector, ModalVector, operator+,
100 : std::plus<>())
101 : DEFINE_STD_ARRAY_BINOP(ModalVector, ModalVector, ModalVector, operator-,
102 : std::minus<>())
103 : DEFINE_STD_ARRAY_INPLACE_BINOP(ModalVector, ModalVector, operator+=,
104 : std::plus<>())
105 : DEFINE_STD_ARRAY_INPLACE_BINOP(ModalVector, ModalVector, operator-=,
106 : std::minus<>())
107 : /// \endcond
108 : MAKE_WITH_VALUE_IMPL_DEFINITION_FOR(ModalVector)
|