/home/runner/work/kynema/kynema/kynema/src/model/copy_nodes_to_state.hpp Source File

Kynema API: /home/runner/work/kynema/kynema/kynema/src/model/copy_nodes_to_state.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
copy_nodes_to_state.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ranges>
4#include <span>
5#include <vector>
6
7#include "node.hpp"
8#include "state/state.hpp"
10
11namespace kynema::model {
12
13template <typename DeviceType>
14inline void CopyNodesToState(State<DeviceType>& state, std::span<const Node> nodes) {
15 using Kokkos::create_mirror_view;
16 using Kokkos::deep_copy;
17 using Kokkos::WithoutInitializing;
18 using RangePolicy = Kokkos::RangePolicy<typename DeviceType::execution_space>;
19
20 auto host_id = create_mirror_view(WithoutInitializing, state.ID);
21 auto host_x0 = create_mirror_view(WithoutInitializing, state.x0);
22 auto host_q = create_mirror_view(WithoutInitializing, state.q);
23 auto host_v = create_mirror_view(WithoutInitializing, state.v);
24 auto host_vd = create_mirror_view(WithoutInitializing, state.vd);
25
26 for (auto node_index : std::views::iota(0U, nodes.size())) {
27 const auto& node = nodes[node_index];
28 for (auto component : std::views::iota(0U, 7U)) {
29 host_x0(node_index, component) = node.x0[component];
30 host_q(node_index, component) = node.u[component];
31 }
32 for (auto component : std::views::iota(0U, 6U)) {
33 host_v(node_index, component) = node.v[component];
34 host_vd(node_index, component) = node.vd[component];
35 }
36 host_id(node_index) = node.id;
37 }
38
39 // Copy data to host
40 deep_copy(state.ID, host_id);
41 deep_copy(state.x0, host_x0);
42 deep_copy(state.q, host_q);
43 deep_copy(state.v, host_v);
44 deep_copy(state.vd, host_vd);
45 deep_copy(state.a, state.vd); // initialize algorithmic acceleration to acceleration
46 deep_copy(state.f, 0.);
47
48 // Set previous state to current state
49 deep_copy(state.q_prev, state.q);
50
51 // Calculate current global position from initial position and displacement
52 Kokkos::parallel_for(
53 "UpdateGlobalPosition", RangePolicy(0UL, state.num_system_nodes),
55 state.q,
56 state.x0,
57 state.x,
58 }
59 );
60}
61
62} // namespace kynema::model
Definition copy_nodes_to_state.hpp:11
void CopyNodesToState(State< DeviceType > &state, std::span< const Node > nodes)
Definition copy_nodes_to_state.hpp:14
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]> q
Definition state.hpp:33
View< double *[6]> vd
Definition state.hpp:35
View< size_t * > ID
Definition state.hpp:24
size_t num_system_nodes
Definition state.hpp:23
View< double *[6]> f
Definition state.hpp:37
A Kernel to update the absolute position of each node based on the solver's current state and the ini...
Definition update_global_position.hpp:14