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

Kynema API: /home/runner/work/kynema/kynema/kynema/src/state/read_state_from_file.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
read_state_from_file.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <istream>
4
5#include <Kokkos_Core.hpp>
6
7#include "state.hpp"
8
9namespace kynema {
10
22template <typename DeviceType>
23inline void ReadStateFromFile(std::istream& input, State<DeviceType>& state) {
24 auto num_system_nodes = size_t{};
25 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
26 input.read(reinterpret_cast<char*>(&num_system_nodes), sizeof(size_t));
27
28 if (num_system_nodes != state.num_system_nodes) {
29 throw std::length_error("Number of system nodes in file is not the same as in model");
30 }
31
32 const auto mirror_7 = Kokkos::View<double* [7]>::HostMirror("mirror_7", num_system_nodes);
33 const auto out_7 = Kokkos::View<double* [7], Kokkos::HostSpace>("out_7", num_system_nodes);
34
35 const auto mirror_6 = Kokkos::View<double* [6]>::HostMirror("mirror_6", num_system_nodes);
36 const auto out_6 = Kokkos::View<double* [6], Kokkos::HostSpace>("out_6", num_system_nodes);
37
38 const auto read_7 = [&](const Kokkos::View<double* [7]>& data) {
39 const auto stream_size = static_cast<long>(7U * num_system_nodes * sizeof(double));
40 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
41 input.read(reinterpret_cast<char*>(out_7.data()), stream_size);
42
43 Kokkos::deep_copy(mirror_7, out_7);
44 Kokkos::deep_copy(data, mirror_7);
45 };
46
47 const auto read_6 = [&](const Kokkos::View<double* [6]>& data) {
48 const auto stream_size = static_cast<long>(6U * num_system_nodes * sizeof(double));
49 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
50 input.read(reinterpret_cast<char*>(out_6.data()), stream_size);
51
52 Kokkos::deep_copy(mirror_6, out_6);
53 Kokkos::deep_copy(data, mirror_6);
54 };
55
56 read_7(state.x0);
57 read_7(state.x);
58 read_6(state.q_delta);
59 read_7(state.q_prev);
60 read_7(state.q);
61 read_6(state.v);
62 read_6(state.vd);
63 read_6(state.a);
64 read_6(state.f);
65}
66
67} // namespace kynema
Definition calculate_constraint_output.hpp:8
void ReadStateFromFile(std::istream &input, State< DeviceType > &state)
Reads State data from a provided restart file.
Definition read_state_from_file.hpp:23
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