ComplexModalVector.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 /// \cond
14 class ModalVector;
15 /// \endcond
16 
17 /*!
18  * \ingroup DataStructuresGroup
19  * \brief A class for storing complex spectral coefficients on a spectral grid.
20  *
21  * \details A ComplexModalVector holds an array of spectral coefficients
22  * represented as `std::complex<double>`s, and can be either owning (the array
23  * is deleted when the ComplexModalVector goes out of scope) or non-owning,
24  * meaning it just has a pointer to an array.
25  *
26  * Only basic mathematical operations are supported with
27  * `ComplexModalVector`s. `ComplexModalVector`s may be added or subtracted and
28  * may be added or subtracted with `ModalVector`s, and the following unary
29  * operations are supported:
30  * - conj
31  * - imag (which returns a `ModalVector`)
32  * - real (which returns a `ModalVector`)
33  *
34  * Also multiplication is supported with `std::complex<double>`s or doubles and
35  * `ComplexModalVector`s, and `ComplexModalVector`s can be divided by
36  * `std::complex<double>`s or `double`s. Multiplication is supported with
37  * `ComplexDiagonalModalOperator`s and `ComplexModalVector`s.
38  */
40  : public VectorImpl<std::complex<double>, ComplexModalVector> {
41  public:
44 
47 };
48 
49 namespace blaze {
50 template <>
51 struct IsVector<ComplexModalVector> : std::true_type {};
52 template <>
53 struct TransposeFlag<ComplexModalVector>
54  : BoolConstant<ComplexModalVector::transpose_flag> {};
55 template <>
56 struct AddTrait<ComplexModalVector, ComplexModalVector> {
57  using Type = ComplexModalVector;
58 };
60  AddTrait);
61 template <>
62 struct SubTrait<ComplexModalVector, ComplexModalVector> {
63  using Type = ComplexModalVector;
64 };
66  SubTrait);
68  std::complex<double>, MultTrait);
69 BLAZE_TRAIT_SPECIALIZE_COMPATIBLE_BINARY_TRAIT(ComplexModalVector, double,
70  MultTrait);
71 template <>
72 struct DivTrait<ComplexModalVector, std::complex<double>> {
73  using Type = ComplexModalVector;
74 };
75 template <>
76 struct DivTrait<ComplexModalVector, double> {
77  using Type = ComplexModalVector;
78 };
79 
80 #if ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3))
81 template <typename Operator>
82 struct UnaryMapTrait<ComplexModalVector, Operator> {
83  // Selectively allow unary operations for spectral coefficients
84  static_assert(
85  tmpl::list_contains_v<
86  tmpl::list<blaze::Conj,
87  // Following 3 reqd. by operator(+,+=), (-,-=),
88  // (-) w/doubles
92  Operator>,
93  "Only unary operations permitted on a ComplexModalVector are:"
94  " conj, imag, and real");
95  using Type = ComplexModalVector;
96 };
97 template <>
98 struct UnaryMapTrait<ComplexModalVector, blaze::Imag> {
99  using Type = ModalVector;
100 };
101 template <>
102 struct UnaryMapTrait<ComplexModalVector, blaze::Real> {
103  using Type = ModalVector;
104 };
105 // for consistency with the std::imag and std::real, these operations should be
106 // supported on real types
107 template <>
108 struct UnaryMapTrait<ModalVector, blaze::Imag> {
109  using Type = ModalVector;
110 };
111 template <>
112 struct UnaryMapTrait<ModalVector, blaze::Real> {
113  using Type = ModalVector;
114 };
115 
116 template <typename Operator>
117 struct BinaryMapTrait<ComplexModalVector, ComplexModalVector, Operator> {
118  // Forbid math operations in this specialization of BinaryMap traits for
119  // ComplexModalVector that are unlikely to be used on spectral coefficients.
120  // Currently no non-arithmetic binary operations are supported.
121  static_assert(
122  tmpl::list_contains_v<tmpl::list<>, Operator>,
123  "This binary operation is not permitted on a ComplexModalVector.");
124  using Type = ComplexModalVector;
125 };
126 #else
127 template <typename Operator>
128 struct MapTrait<ComplexModalVector, Operator> {
129  // Selectively allow unary operations for spectral coefficients
130  static_assert(
131  tmpl::list_contains_v<
132  tmpl::list<blaze::Conj,
133  // Following 3 reqd. by operator(+,+=), (-,-=),
134  // (-) w/doubles
138  Operator>,
139  "Only unary operations permitted on a ComplexModalVector are:"
140  " conj, imag, and real");
141  using Type = ComplexModalVector;
142 };
143 template <>
144 struct MapTrait<ComplexModalVector, blaze::Imag> {
145  using Type = ModalVector;
146 };
147 template <>
148 struct MapTrait<ComplexModalVector, blaze::Real> {
149  using Type = ModalVector;
150 };
151 template <>
152 struct MapTrait<ModalVector, blaze::Imag> {
153  using Type = ModalVector;
154 };
155 template <>
156 struct MapTrait<ModalVector, blaze::Real> {
157  using Type = ModalVector;
158 };
159 
160 template <typename Operator>
161 struct MapTrait<ComplexModalVector, ComplexModalVector, Operator> {
162  // Forbid math operations in this specialization of BinaryMap traits for
163  // ComplexModalVector that are unlikely to be used on spectral coefficients.
164  // Currently no non-arithmetic binary operations are supported.
165  static_assert(
166  tmpl::list_contains_v<tmpl::list<>, Operator>,
167  "This binary operation is not permitted on a ComplexModalVector.");
168  using Type = ComplexModalVector;
169 };
170 #endif // ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3))
171 } // namespace blaze
172 
173 /// \cond
175  ComplexModalVector, operator+, std::plus<>())
177  ComplexModalVector, operator-, std::minus<>())
179  ComplexModalVector, operator+=, std::plus<>())
181  ComplexModalVector, operator-=, std::minus<>())
182 /// \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
A class for storing complex spectral coefficients on a spectral grid.
Definition: ComplexModalVector.hpp:39
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