ComplexDiagonalModalOperator.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include "DataStructures/ComplexModalVector.hpp"
7 #include "DataStructures/DataVector.hpp" // IWYU pragma: keep
8 #include "DataStructures/DiagonalModalOperator.hpp"
9 #include "DataStructures/VectorImpl.hpp"
10 #include "Utilities/PointerVector.hpp" // IWYU pragma: keep
11 #include "Utilities/TMPL.hpp"
12 
13 /// \cond
15 class ModalVector;
16 /// \endcond
17 
18 // IWYU pragma: no_include <blaze/math/expressions/DVecMapExpr.h>
19 // IWYU pragma: no_include <blaze/math/typetraits/IsVector.h>
20 
21 /*!
22  * \ingroup DataStructuresGroup
23  * \brief A class for an element-wise complex multiplier of modal coefficients.
24  *
25  * \details A `ComplexDiagonalModalOperator` holds an array of factors to
26  * multiply by spectral coefficients, and can be either owning (the array is
27  * deleted when the `ComplexDiagonalModalOperator` goes out of scope) or
28  * non-owning, meaning it just has a pointer to an array.
29  *
30  * `ComplexDiagonalModalOperator`s are intended to represent a diagonal matrix
31  * that can operate (via the `*` operator) on spectral coefficients represented
32  * by `ComplexModalVector`s easily. Only basic mathematical operations are
33  * supported with `ComplexDiagonalModalOperator`s.
34  * `ComplexDiagonalModalOperator`s may be added, subtracted, multiplied, or
35  * divided, and all arithmetic operations are similarly supported between
36  * `ComplexDiagonalModalOperator`s and `DiagonalModalOperator`s. In addition,
37  * the following operations with modal data structures are supported:
38  * - multiplication of a `ComplexDiagonalModalOperator` and a
39  * `ComplexModalVector` resulting in a `ComplexModalVector`
40  * - multiplication of a `ComplexDiagonalModalOperator` and a `ModalVector`
41  * resulting in a `ComplexModalVector`
42  * - multiplication of a `DiagonalModalOperator` and a `ComplexModalVector`
43  * resulting in a `ComplexModalVector`
44  * All of these multiplication operations are commutative, supporting the
45  * interpretation of the modal data structure as either a 'row' or a 'column'
46  * vector.
47  *
48  * The following unary operations are supported with
49  * `ComplexDiagonalModalOperator`s:
50  * - conj
51  * - imag (results in a `DiagonalModalOperator`)
52  * - real (results in a `DiagonalModalOperator`)
53  *
54  * Also, addition, subtraction, multiplication and division of
55  * `DiagonalModalOperator`s with `std::complex<double>`s or `double`s is
56  * supported.
57  */
59  : public VectorImpl<std::complex<double>, ComplexDiagonalModalOperator> {
60  public:
62  operator=;
65 };
66 
67 namespace blaze {
69 
71  DiagonalModalOperator, AddTrait);
73  DiagonalModalOperator, DivTrait);
76  MultTrait);
78  DiagonalModalOperator, SubTrait);
79 
81  double, AddTrait);
83  double, DivTrait);
85  double, MultTrait);
87  double, SubTrait);
88 
91  MultTrait);
94  MultTrait);
95 template <>
97  using Type = ComplexModalVector;
98 };
99 template <>
101  using Type = ComplexModalVector;
102 };
103 
104 #if ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3))
105 template <typename Operator>
106 struct UnaryMapTrait<ComplexDiagonalModalOperator, Operator> {
107  // Selectively allow unary operations for spectral coefficient operators
108  static_assert(
109  tmpl::list_contains_v<
110  tmpl::list<
111  blaze::Conj,
112  // these traits are required for operators acting with doubles
123  Operator>,
124  "This unary operation is not permitted on a "
125  "ComplexDiagonalModalOperator");
126  using Type = ComplexDiagonalModalOperator;
127 };
128 template <>
129 struct UnaryMapTrait<ComplexDiagonalModalOperator, blaze::Imag> {
130  using Type = DiagonalModalOperator;
131 };
132 template <>
133 struct UnaryMapTrait<ComplexDiagonalModalOperator, blaze::Real> {
134  using Type = DiagonalModalOperator;
135 };
136 template <>
137 struct UnaryMapTrait<DiagonalModalOperator, blaze::Imag> {
138  using Type = DiagonalModalOperator;
139 };
140 template <>
141 struct UnaryMapTrait<DiagonalModalOperator, blaze::Real> {
142  using Type = DiagonalModalOperator;
143 };
144 
145 template <typename Operator>
146 struct BinaryMapTrait<ComplexDiagonalModalOperator,
147  ComplexDiagonalModalOperator, Operator> {
148  // Forbid math operations in this specialization of BinaryMap traits for
149  // ComplexDiagonalModalOperator that are unlikely to be used on spectral
150  // coefficients. Currently no non-arithmetic binary operations are supported.
151  static_assert(tmpl::list_contains_v<tmpl::list<>, Operator>,
152  "This binary operation is not permitted on a "
153  "ComplexDiagonalModalOperator.");
154  using Type = ComplexDiagonalModalOperator;
155 };
156 #else
157 template <typename Operator>
158 struct MapTrait<ComplexDiagonalModalOperator, Operator> {
159  // Selectively allow unary operations for spectral coefficient operators
160  static_assert(
161  tmpl::list_contains_v<
162  tmpl::list<
163  blaze::Conj,
164  // these traits are required for operators acting with doubles
175  Operator>,
176  "This unary operation is not permitted on a "
177  "ComplexDiagonalModalOperator");
178  using Type = ComplexDiagonalModalOperator;
179 };
180 template <>
181 struct MapTrait<ComplexDiagonalModalOperator, blaze::Imag> {
182  using Type = DiagonalModalOperator;
183 };
184 template <>
185 struct MapTrait<ComplexDiagonalModalOperator, blaze::Real> {
186  using Type = DiagonalModalOperator;
187 };
188 template <>
189 struct MapTrait<DiagonalModalOperator, blaze::Imag> {
190  using Type = DiagonalModalOperator;
191 };
192 template <>
193 struct MapTrait<DiagonalModalOperator, blaze::Real> {
194  using Type = DiagonalModalOperator;
195 };
196 
197 template <typename Operator>
198 struct MapTrait<ComplexDiagonalModalOperator, ComplexDiagonalModalOperator,
199  Operator> {
200  // Forbid math operations in this specialization of BinaryMap traits for
201  // ComplexDiagonalModalOperator that are unlikely to be used on spectral
202  // coefficients. Currently no non-arithmetic binary operations are supported.
203  static_assert(tmpl::list_contains_v<tmpl::list<>, Operator>,
204  "This binary operation is not permitted on a "
205  "ComplexDiagonalModalOperator.");
206  using Type = ComplexDiagonalModalOperator;
207 };
208 #endif // ((BLAZE_MAJOR_VERSION == 3) && (BLAZE_MINOR_VERSION <= 3))
209 } // namespace blaze
210 
212 
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
Defines class PointerVector.
Definition: PointerVector.hpp:349
A class for an element-wise multiplier of modal coefficients.
Definition: DiagonalModalOperator.hpp:39
Definition: ComplexDataVector.hpp:56
A class for an element-wise complex multiplier of modal coefficients.
Definition: ComplexDiagonalModalOperator.hpp:58
#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
Definition: PointerVector.hpp:317
Wraps the template metaprogramming library used (brigand)
#define MAKE_STD_ARRAY_VECTOR_BINOPS(VECTOR_TYPE)
Defines the set of binary operations often supported for std::array<VECTOR_TYPE, size>, for arbitrary size.
Definition: VectorImpl.hpp:504
#define VECTOR_BLAZE_TRAIT_SPECIALIZE_ARITHMETIC_TRAITS(VECTOR_TYPE)
Instructs Blaze to provide the appropriate vector result type of arithmetic operations for VECTOR_TYP...
Definition: VectorImpl.hpp:450