/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/discretization/data/hdf5.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/discretization/data/hdf5.hh Source File
DiFfRG
hdf5.hh
Go to the documentation of this file.
1#pragma once
2
3// DiFfRG
6
7#include <autodiff/forward/real/real.hpp>
8
9#include <hdf5lib/hdf5.hh>
10
11namespace DiFfRG::hdf5
12{
13 template <typename T> struct TypeTrait<DiFfRG::complex<T>> {
14 static Datatype get()
15 {
16 auto t = Datatype::compound(2 * sizeof(T));
17 t.insert("real", 0, type_of<T>());
18 t.insert("imag", sizeof(T), type_of<T>());
19 return t;
20 }
21 };
22
23 template <std::size_t N, typename T> struct TypeTrait<autodiff::Real<N, T>> {
24 static Datatype get()
25 {
26 auto t = Datatype::compound((N + 1) * sizeof(T));
27 t.insert("val", 0, type_of<T>());
28 for (std::size_t i = 1; i <= N; ++i)
29 t.insert("d_" + std::to_string(i), i * sizeof(T), type_of<T>());
30 return t;
31 }
32 };
33
34 template <typename T, std::size_t N> struct TypeTrait<std::array<T, N>> {
35 static Datatype get()
36 {
37 auto t = Datatype::compound(N * sizeof(T));
38 for (std::size_t i = 0; i < N; ++i)
39 t.insert("component " + std::to_string(i), i * sizeof(T), type_of<T>());
40 return t;
41 }
42 };
43
44 template <typename T, std::size_t N>
45 requires(!std::is_same_v<std::array<T, N>, DiFfRG::device::array<T, N>>)
47 static Datatype get()
48 {
49 auto t = Datatype::compound(N * sizeof(T));
50 for (std::size_t i = 0; i < N; ++i)
51 t.insert("component " + std::to_string(i), i * sizeof(T), type_of<T>());
52 return t;
53 }
54 };
55} // namespace DiFfRG::hdf5
Definition datatype.hh:12
static Datatype compound(std::size_t size)
Build a compound datatype with the given total size (in bytes).
Definition datatype.hh:32
std::array< T, N > array
Definition kokkos.hh:133
Definition hdf5.hh:12
Datatype type_of()
Convenience factory — type_of<T>() returns the HDF5 datatype for T.
Definition datatype.hh:56
Definition complex_math.hh:10
Definition complex_math.hh:19
static Datatype get()
Definition hdf5.hh:14
static Datatype get()
Definition hdf5.hh:47
static Datatype get()
Definition hdf5.hh:24
static Datatype get()
Definition hdf5.hh:35
Definition datatype.hh:53