ModalVector.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include "DataStructures/VectorImpl.hpp"
7 #include "Utilities/PointerVector.hpp" // IWYU pragma: keep
8 #include "Utilities/TMPL.hpp"
9 
10 // IWYU pragma: no_include <blaze/math/expressions/DVecMapExpr.h>
11 // IWYU pragma: no_include <blaze/math/typetraits/IsVector.h>
12 
13 /*!
14  * \ingroup DataStructuresGroup
15  * \brief A class for storing spectral coefficients on a spectral grid.
16  *
17  * \details A ModalVector holds an array of spectral coefficients, and can be
18  * either owning (the array is deleted when the ModalVector goes out of scope)
19  * or non-owning, meaning it just has a pointer to an array.
20  *
21  * Only basic mathematical operations are supported with
22  * ModalVectors. ModalVectors may be added or subtracted, and the following
23  * unary operations are supported:
24  * - abs
25  *
26  * Also multiplication is supported with doubles and `ModalVector`s, and
27  * `ModalVector`s can be divided by doubles. Multiplication is supported with
28  * `DiagonalModalOperator`s and `ModalVector`s.
29  */
30 class ModalVector : public VectorImpl<double, ModalVector> {
31  public:
34 
37 };
38 
39 namespace blaze {
40 template <>
41 struct IsVector<ModalVector> : std::true_type {};
42 template <>
43 struct TransposeFlag<ModalVector> : BoolConstant<ModalVector::transpose_flag> {
44 };
45 template <>
46 struct AddTrait<ModalVector, ModalVector> {
47  using Type = ModalVector;
48 };
49 template <>
50 struct SubTrait<ModalVector, ModalVector> {
51  using Type = ModalVector;
52 };
53 BLAZE_TRAIT_SPECIALIZE_COMPATIBLE_BINARY_TRAIT(ModalVector, double, MultTrait);
54 template <>
55 struct DivTrait<ModalVector, double> {
56  using Type = ModalVector;
57 };
58 
59 #if ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3))
60 template <typename Operator>
61 struct UnaryMapTrait<ModalVector, Operator> {
62  // Selectively allow unary operations for spectral coefficients
63  static_assert(tmpl::list_contains_v<
64  tmpl::list<blaze::Abs,
65  // Following 3 reqd. by operator(+,+=), (-,-=),
66  // (-) w/doubles
70  Operator>,
71  "Only unary operation permitted on a ModalVector are:"
72  " abs");
73  using Type = ModalVector;
74 };
75 
76 template <typename Operator>
77 struct BinaryMapTrait<ModalVector, ModalVector, Operator> {
78  // Forbid math operations in this specialization of BinaryMap traits for
79  // ModalVector that are unlikely to be used on spectral coefficients.
80  // Currently no non-arithmetic binary operations are supported.
81  static_assert(tmpl::list_contains_v<tmpl::list<>, Operator>,
82  "This binary operation is not permitted on a ModalVector.");
83  using Type = ModalVector;
84 };
85 #else
86 template <typename Operator>
87 struct MapTrait<ModalVector, Operator> {
88  // Selectively allow unary operations for spectral coefficients
89  static_assert(tmpl::list_contains_v<
90  tmpl::list<blaze::Abs,
91  // Following 3 reqd. by operator(+,+=), (-,-=),
92  // (-) w/doubles
96  Operator>,
97  "Only unary operation permitted on a ModalVector are:"
98  " abs.");
99  using Type = ModalVector;
100 };
101 
102 template <typename Operator>
103 struct MapTrait<ModalVector, ModalVector, Operator> {
104  // Forbid math operations in this specialization of BinaryMap traits for
105  // ModalVector that are unlikely to be used on spectral coefficients.
106  // Currently no non-arithmetic binary operations are supported.
107  static_assert(tmpl::list_contains_v<tmpl::list<>, Operator>,
108  "This binary operation is not permitted on a ModalVector.");
109  using Type = ModalVector;
110 };
111 #endif // ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3))
112 } // namespace blaze
113 
114 /// \cond
116  std::plus<>())
118  std::minus<>())
120  std::plus<>())
122  std::minus<>())
123 /// \endcond
Definition: PointerVector.hpp:393
Definition: PointerVector.hpp:418
#define BLAZE_TRAIT_SPECIALIZE_COMPATIBLE_BINARY_TRAIT(VECTOR_TYPE, COMPATIBLE, BLAZE_MATH_TRAIT)
Instructs Blaze to provide the appropriate vector result type of an operator between VECTOR_TYPE and ...
Definition: VectorImpl.hpp:426
Base class template for various DataVector and related types.
Definition: VectorImpl.hpp:109
A class for storing spectral coefficients on a spectral grid.
Definition: ModalVector.hpp:30
#define DEFINE_STD_ARRAY_INPLACE_BINOP(LTYPE, RTYPE, OP_FUNCTION_NAME, BINARY_OP)
Declares an in-place binary function on an array, intended for operations such as += ...
Definition: StdArrayHelpers.hpp:242
Defines class PointerVector.
Definition: PointerVector.hpp:349
Definition: ComplexDataVector.hpp:56
#define MAKE_MATH_ASSIGN_EXPRESSION_POINTERVECTOR(OP, TYPE)
Generates the OP assignment operator for the type TYPE
Definition: PointerVector.hpp:1430
#define MAKE_WITH_VALUE_IMPL_DEFINITION_FOR(VECTOR_TYPE)
Defines the MakeWithValueImpl apply specialization.
Definition: VectorImpl.hpp:552
Wraps the template metaprogramming library used (brigand)
#define DEFINE_STD_ARRAY_BINOP(RESULT_TYPE, LTYPE, RTYPE, OP_FUNCTION_NAME, BINARY_OP)
Declares a binary function on an array, intended for binary operators such as +
Definition: StdArrayHelpers.hpp:213