Line data Source code
1 1 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : /// \file
5 : /// `blaze::StaticVector` is a general-purpose fixed size vector type. This file
6 : /// implements interoperability of `blaze::StaticVector` with our data
7 : /// structures.
8 :
9 : #pragma once
10 :
11 : #include <array>
12 : #include <blaze/math/StaticVector.h>
13 : #include <pup.h>
14 : #include <type_traits>
15 :
16 : #include "Options/ParseOptions.hpp"
17 : #include "Utilities/ErrorHandling/Assert.hpp"
18 : #include "Utilities/MakeWithValue.hpp"
19 :
20 : namespace PUP {
21 : /// @{
22 : /// Serialization of blaze::StaticVector
23 : template <typename T, size_t N, bool TF, blaze::AlignmentFlag AF,
24 : blaze::PaddingFlag PF, typename Tag>
25 : void pup(er& p, blaze::StaticVector<T, N, TF, AF, PF, Tag>& t) {
26 : if (std::is_fundamental_v<T>) {
27 : PUParray(p, t.data(), N);
28 : } else {
29 : for (T& element : t) {
30 : p | element;
31 : }
32 : }
33 : }
34 : template <typename T, size_t N, bool TF, blaze::AlignmentFlag AF,
35 : blaze::PaddingFlag PF, typename Tag>
36 : void operator|(er& p, blaze::StaticVector<T, N, TF, AF, PF, Tag>& t) {
37 : pup(p, t);
38 : }
39 : /// @}
40 : } // namespace PUP
41 :
42 : namespace MakeWithValueImpls {
43 : template <typename T, size_t N, bool TF, blaze::AlignmentFlag AF,
44 : blaze::PaddingFlag PF, typename Tag>
45 0 : struct NumberOfPoints<blaze::StaticVector<T, N, TF, AF, PF, Tag>> {
46 0 : static constexpr size_t apply(
47 : const blaze::StaticVector<T, N, TF, AF, PF, Tag>& /*input*/) {
48 : return N;
49 : }
50 : };
51 :
52 : template <typename T, size_t N, bool TF, blaze::AlignmentFlag AF,
53 : blaze::PaddingFlag PF, typename Tag>
54 0 : struct MakeWithSize<blaze::StaticVector<T, N, TF, AF, PF, Tag>> {
55 0 : static SPECTRE_ALWAYS_INLINE blaze::StaticVector<T, N, TF, AF, PF, Tag> apply(
56 : const size_t size, const T& value) {
57 : ASSERT(size == N, "Size mismatch for StaticVector: Expected "
58 : << N << ", got " << size << ".");
59 : return blaze::StaticVector<T, N, TF, AF, PF, Tag>(value);
60 : }
61 : };
62 : } // namespace MakeWithValueImpls
63 :
64 : template <typename T, size_t N, bool TF, blaze::AlignmentFlag AF,
65 : blaze::PaddingFlag PF, typename Tag>
66 0 : struct Options::create_from_yaml<blaze::StaticVector<T, N, TF, AF, PF, Tag>> {
67 : template <typename Metavariables>
68 0 : static blaze::StaticVector<T, N, TF, AF, PF, Tag> create(
69 : const Options::Option& options) {
70 : return {options.parse_as<std::array<T, N>>()};
71 : }
72 : };
|