/home/runner/work/kynema/kynema/kynema/src/solver/compute_system_col_inds.hpp Source File

Kynema API: /home/runner/work/kynema/kynema/kynema/src/solver/compute_system_col_inds.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
compute_system_col_inds.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Kokkos_Core.hpp>
4
5namespace kynema::solver {
6
11template <typename RowPtrType, typename IndicesType>
13 using RowPtrValueType = typename RowPtrType::value_type;
14 using IndicesValueType = typename IndicesType::value_type;
15 using DeviceType = typename RowPtrType::device_type;
16 template <typename ValueType>
17 using View = Kokkos::View<ValueType, DeviceType>;
18 template <typename ValueType>
20
31 typename RowPtrType::const_type row_ptrs;
33
35 bool ElementContainsNode(size_t element, size_t node) const {
36 const auto num_nodes = num_nodes_per_element(element);
37 for (auto node_idx = 0U; node_idx < num_nodes; ++node_idx) {
38 if (node_state_indices(element, node_idx) == node) {
39 return true;
40 }
41 }
42 return false;
43 }
44
46 bool BaseContainsNode(size_t constraint, size_t dof_index) const {
47 return dof_index == base_node_freedom_table(constraint, 0) &&
48 base_active_dofs(constraint) != 0UL;
49 }
50
52 bool TargetContainsNode(size_t constraint, size_t dof_index) const {
53 return dof_index == target_node_freedom_table(constraint, 0) &&
54 target_active_dofs(constraint) != 0UL;
55 }
56
58 bool ConstraintContainsNode(size_t constraint, size_t dof_index) const {
59 return BaseContainsNode(constraint, dof_index) || TargetContainsNode(constraint, dof_index);
60 }
61
63 RowPtrValueType ComputeColIndsInElement(size_t element, size_t node, RowPtrValueType index)
64 const {
65 for (auto node_index = 0U; node_index < num_nodes_per_element(element); ++node_index) {
66 const auto node_state_index = node_state_indices(element, node_index);
67 if (node_state_index != node) {
70 for (auto component = 0U; component < num_dof; ++component, ++index) {
71 const auto col_index = dof_index + component;
72 col_inds(index) = static_cast<IndicesValueType>(col_index);
73 }
74 }
75 }
76 return index;
77 }
78
81 const auto first_row = row_range(constraint).first;
82 const auto end_row = row_range(constraint).second;
83 for (auto k = first_row; k < end_row; ++k, ++index) {
84 const auto col_index = num_system_dofs + k;
85 col_inds(index) = static_cast<IndicesValueType>(col_index);
86 }
87 return index;
88 }
89
91 void operator()(size_t node) const {
92 const auto num_dof = active_dofs(node);
93 const auto dof_index = node_freedom_map_table(node);
94
95 const auto num_elements = num_nodes_per_element.extent(0);
96 const auto num_constraints = row_range.extent(0);
97
98 auto current_col = Kokkos::Array<RowPtrValueType, 6>{};
99
100 for (auto component_1 = 0U; component_1 < num_dof; ++component_1) {
101 auto index = row_ptrs(dof_index + component_1);
102
103 for (auto component_2 = 0U; component_2 < num_dof; ++component_2, ++index) {
104 col_inds(index) = static_cast<IndicesValueType>(dof_index) +
105 static_cast<IndicesValueType>(component_2);
106 }
108 }
109
110 for (auto element = 0U; element < num_elements; ++element) {
111 if (!ElementContainsNode(element, node)) {
112 continue;
113 }
114 for (auto component = 0U; component < num_dof; ++component) {
115 const auto index = row_ptrs(dof_index + component) + current_col[component];
116 const auto new_index = ComputeColIndsInElement(element, node, index);
117 current_col[component] += new_index - index;
118 }
119 }
120
121 for (auto constraint = 0U; constraint < num_constraints; ++constraint) {
122 if (!ConstraintContainsNode(constraint, dof_index)) {
123 continue;
124 }
125 for (auto component = 0U; component < num_dof; ++component) {
126 const auto index = row_ptrs(dof_index + component) + current_col[component];
127 const auto new_index = ComputeColIndsInConstraint(constraint, index);
128 current_col[component] += new_index - index;
129 }
130 }
131 }
132};
133
134} // namespace kynema::solver
Definition calculate_error_sum_squares.hpp:5
A Kernel for computing the system elements' contribution to the column indicies for the CRS matrix to...
Definition compute_system_col_inds.hpp:12
ConstView< size_t *[6]> base_node_freedom_table
Definition compute_system_col_inds.hpp:28
Kokkos::View< ValueType, DeviceType > View
Definition compute_system_col_inds.hpp:17
ConstView< size_t * > base_active_dofs
Definition compute_system_col_inds.hpp:26
typename RowPtrType::device_type DeviceType
Definition compute_system_col_inds.hpp:15
KOKKOS_FUNCTION RowPtrValueType ComputeColIndsInConstraint(size_t constraint, RowPtrValueType index) const
Definition compute_system_col_inds.hpp:80
ConstView< Kokkos::pair< size_t, size_t > * > row_range
Definition compute_system_col_inds.hpp:30
ConstView< size_t * > num_nodes_per_element
Definition compute_system_col_inds.hpp:24
KOKKOS_FUNCTION bool BaseContainsNode(size_t constraint, size_t dof_index) const
Definition compute_system_col_inds.hpp:46
ConstView< size_t * > node_freedom_map_table
Definition compute_system_col_inds.hpp:23
KOKKOS_FUNCTION bool ConstraintContainsNode(size_t constraint, size_t dof_index) const
Definition compute_system_col_inds.hpp:58
IndicesType col_inds
Definition compute_system_col_inds.hpp:32
typename View< ValueType >::const_type ConstView
Definition compute_system_col_inds.hpp:19
ConstView< size_t *[6]> target_node_freedom_table
Definition compute_system_col_inds.hpp:29
size_t num_system_dofs
Definition compute_system_col_inds.hpp:21
typename RowPtrType::value_type RowPtrValueType
Definition compute_system_col_inds.hpp:13
typename IndicesType::value_type IndicesValueType
Definition compute_system_col_inds.hpp:14
KOKKOS_FUNCTION bool TargetContainsNode(size_t constraint, size_t dof_index) const
Definition compute_system_col_inds.hpp:52
ConstView< size_t ** > node_state_indices
Definition compute_system_col_inds.hpp:25
ConstView< size_t * > active_dofs
Definition compute_system_col_inds.hpp:22
KOKKOS_FUNCTION void operator()(size_t node) const
Definition compute_system_col_inds.hpp:91
ConstView< size_t * > target_active_dofs
Definition compute_system_col_inds.hpp:27
RowPtrType::const_type row_ptrs
Definition compute_system_col_inds.hpp:31
KOKKOS_FUNCTION bool ElementContainsNode(size_t element, size_t node) const
Definition compute_system_col_inds.hpp:35
KOKKOS_FUNCTION RowPtrValueType ComputeColIndsInElement(size_t element, size_t node, RowPtrValueType index) const
Definition compute_system_col_inds.hpp:63