/home/runner/work/kynema/kynema/kynema/src/state/write_state_to_file.hpp Source File

Kynema API: /home/runner/work/kynema/kynema/kynema/src/state/write_state_to_file.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
write_state_to_file.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ostream>
4
5#include <Kokkos_Core.hpp>
6
7#include "state.hpp"
8
9namespace kynema {
10
19template <typename DeviceType>
20inline void WriteStateToFile(std::ostream& output, const State<DeviceType>& state) {
21 auto num_system_nodes = state.num_system_nodes;
22 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
23 output.write(reinterpret_cast<char*>(&num_system_nodes), sizeof(size_t));
24
25 const auto mirror_7 = Kokkos::View<double* [7]>::HostMirror("mirror_7", num_system_nodes);
26 const auto out_7 = Kokkos::View<double* [7], Kokkos::HostSpace>("out_7", num_system_nodes);
27
28 const auto mirror_6 = Kokkos::View<double* [6]>::HostMirror("mirror_6", num_system_nodes);
29 const auto out_6 = Kokkos::View<double* [6], Kokkos::HostSpace>("out_6", num_system_nodes);
30
31 const auto write_7 = [&](const Kokkos::View<double* [7]>& data) {
32 Kokkos::deep_copy(mirror_7, data);
33 Kokkos::deep_copy(out_7, mirror_7);
34
35 const auto stream_size = static_cast<long>(7U * num_system_nodes * sizeof(double));
36 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
37 output.write(reinterpret_cast<char*>(out_7.data()), stream_size);
38 };
39
40 const auto write_6 = [&](const Kokkos::View<double* [6]>& data) {
41 Kokkos::deep_copy(mirror_6, data);
42 Kokkos::deep_copy(out_6, mirror_6);
43
44 const auto stream_size = static_cast<long>(6U * num_system_nodes * sizeof(double));
45 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
46 output.write(reinterpret_cast<char*>(out_6.data()), stream_size);
47 };
48
49 write_7(state.x0);
50 write_7(state.x);
51 write_6(state.q_delta);
52 write_7(state.q_prev);
53 write_7(state.q);
54 write_6(state.v);
55 write_6(state.vd);
56 write_6(state.a);
57 write_6(state.f);
58}
59
60} // namespace kynema
Definition calculate_constraint_output.hpp:8
void WriteStateToFile(std::ostream &output, const State< DeviceType > &state)
Writes State data into a minimal restart file.
Definition write_state_to_file.hpp:20
Container for storing the complete system state of the simulation at a given time increment.
Definition state.hpp:18
View< double *[7]> x0
Definition state.hpp:29
View< double *[6]> v
Definition state.hpp:34
View< double *[6]> a
Definition state.hpp:36
View< double *[7]> q_prev
Definition state.hpp:32
View< double *[7]> x
Definition state.hpp:30
View< double *[6]> q_delta
Definition state.hpp:31
View< double *[7]> q
Definition state.hpp:33
View< double *[6]> vd
Definition state.hpp:35
size_t num_system_nodes
Definition state.hpp:23
View< double *[6]> f
Definition state.hpp:37