DenseVector.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 /// \file
5 /// Defines class DenseVector.
6 
7 #pragma once
8 
9 #include <pup.h> // IWYU pragma: keep
10 
11 #include "Options/Options.hpp"
12 #include "Utilities/Blaze.hpp"
13 #include "Utilities/Gsl.hpp"
15 #include "Utilities/TypeTraits.hpp"
16 
17 #include <blaze/math/DynamicVector.h>
18 #include <blaze/system/Version.h>
19 
20 /*!
21  * \ingroup DataStructuresGroup
22  * \brief A dynamically sized vector of arbitrary type.
23  *
24  * \details Use this vector type to represent a generic collection of numbers
25  * without assigning any particular meaning to them. It supports all common
26  * vector operations such as elementwise arithmetic, dot-products between
27  * vectors and multiplication by a DenseMatrix.
28  *
29  * \note This is a thin wrapper around `blaze::DynamicVector`. Please refer to
30  * the [Blaze documentation](https://bitbucket.org/blaze-lib/blaze/wiki/Home)
31  * for information on how to use it.
32  *
33  * Refer to the \ref DataStructuresGroup documentation for a list of other
34  * available vector and matrix types. In particular, to represent the values of
35  * a function on the computational domain use DataVector instead.
36  */
37 template <typename T, bool TF = blaze::defaultTransposeFlag>
38 class DenseVector : public blaze::DynamicVector<T, TF> {
39  public:
40  // Inherit constructors
41  using blaze::DynamicVector<T, TF>::DynamicVector;
42 
43  /// Charm++ serialization
44  // clang-tidy: runtime-references
45  void pup(PUP::er& p) noexcept { // NOLINT
46  auto size = blaze::DynamicVector<T, TF>::size();
47  p | size;
48  if (p.isUnpacking()) {
49  blaze::DynamicVector<T, TF>::resize(size);
50  }
51  if (cpp17::is_fundamental_v<T>) {
52  PUParray(p, blaze::DynamicVector<T, TF>::data(), size);
53  } else {
54  for (auto& element : *this) {
55  p | element;
56  }
57  }
58  }
59 };
60 
61 namespace MakeWithValueImpls {
62 template <bool TFOut, typename TIn, bool TFIn>
63 struct MakeWithValueImpl<DenseVector<double, TFOut>, DenseVector<TIn, TFIn>> {
64  /// \brief Returns a `DenseVector` the same size as `input`, with each element
65  /// equal to `value`.
66  static SPECTRE_ALWAYS_INLINE DenseVector<double, TFOut> apply(
67  const DenseVector<TIn, TFIn>& input, const double value) noexcept {
68  return DenseVector<double, TFOut>(input.size(), value);
69  }
70 };
71 } // namespace MakeWithValueImpls
72 
73 template <typename T, bool TF>
74 struct create_from_yaml<DenseVector<T, TF>> {
75  static DenseVector<T, TF> create(const Option& options) {
76  const auto data = options.parse_as<std::vector<T>>();
77  DenseVector<T, TF> result(data.size());
78  std::copy(std::begin(data), std::end(data), result.begin());
79  return result;
80  }
81 };
Implementations of make_with_value.
Definition: DenseVector.hpp:61
The type that options are passed around as. Contains YAML node data and an OptionContext.
Definition: Options.hpp:103
T parse_as() const
Convert to an object of type T.
Definition: ParseOptions.hpp:69
Includes Blaze library with specific configs.
static DenseVector< double, TFOut > apply(const DenseVector< TIn, TFIn > &input, const double value) noexcept
Returns a DenseVector the same size as input, with each element equal to value.
Definition: DenseVector.hpp:66
Used by the parser to create an object. The default action is to parse options using T::options...
Definition: Options.hpp:143
Defines classes and functions for making classes creatable from input files.
constexpr auto create(Args &&... args)
Create a new DataBox.
Definition: DataBox.hpp:1259
Definition: MakeWithValue.hpp:20
void pup(PUP::er &p) noexcept
Charm++ serialization.
Definition: DenseVector.hpp:45
#define SPECTRE_ALWAYS_INLINE
Always inline a function. Only use this if you benchmarked the code.
Definition: ForceInline.hpp:20
Defines functions and classes from the GSL.
Defines type traits, some of which are future STL type_traits header.
Defines make_with_value.