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

Kynema API: /home/runner/work/kynema/kynema/kynema/src/solver/contribute_springs_to_sparse_matrix.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
contribute_springs_to_sparse_matrix.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <KokkosSparse.hpp>
4#include <Kokkos_Core.hpp>
5
7
8namespace kynema::solver {
9
14template <typename CrsMatrixType>
16 using DeviceType = typename CrsMatrixType::device_type;
17 using RowDataType = typename CrsMatrixType::values_type::non_const_type;
18 using ColIdxType = typename CrsMatrixType::staticcrsgraph_type::entries_type::non_const_type;
19 using TeamPolicy = typename Kokkos::TeamPolicy<typename DeviceType::execution_space>;
20 using member_type = typename TeamPolicy::member_type;
21 template <typename ValueType>
22 using View = Kokkos::View<ValueType, DeviceType>;
23 template <typename ValueType>
25
26 double conditioner{};
29 ConstView<double* [2][2][3][3]> dense; //< Element Stiffness matrices
30 CrsMatrixType sparse; //< Global sparse stiffness matrix
31
34 const auto element = member.league_rank();
35 constexpr auto is_sorted = true;
36 constexpr auto force_atomic =
37 !std::is_same_v<typename DeviceType::execution_space, Kokkos::Serial>;
38
39 constexpr auto num_dofs = 3;
40 constexpr auto num_nodes = 2;
41 constexpr auto hint = static_cast<typename CrsMatrixType::ordinal_type>(0);
42
43 Kokkos::parallel_for(
44 Kokkos::TeamVectorRange(member, num_nodes * num_nodes),
45 [&](int node_12) {
46 const auto node_1 = node_12 / num_nodes;
47 const auto node_2 = node_12 % num_nodes;
48 const auto first_column = static_cast<typename CrsMatrixType::ordinal_type>(
49 element_freedom_table(element, node_2, 0)
50 );
51
52 for (auto component_1 = 0; component_1 < num_dofs; ++component_1) {
53 const auto row_num =
54 static_cast<int>(element_freedom_table(element, node_1, component_1));
55 auto row = sparse.row(row_num);
56 auto offset = KokkosSparse::findRelOffset(
57 &(row.colidx(0)), row.length, first_column, hint, is_sorted
58 );
59 for (auto component_2 = 0; component_2 < num_dofs; ++component_2, ++offset) {
60 const auto contribution =
62 if constexpr (force_atomic) {
63 Kokkos::atomic_add(&(row.value(offset)), contribution);
64 } else {
65 row.value(offset) += contribution;
66 }
67 }
68 }
69 }
70 );
71 };
72};
73
74} // namespace kynema::solver
Definition calculate_error_sum_squares.hpp:5
A Kernel which sums the system matrix contributions computed at each of the nodes in a spring element...
Definition contribute_springs_to_sparse_matrix.hpp:15
Kokkos::View< ValueType, DeviceType > View
Definition contribute_springs_to_sparse_matrix.hpp:22
double conditioner
Definition contribute_springs_to_sparse_matrix.hpp:26
ConstView< dof::FreedomSignature *[2]> element_freedom_signature
Definition contribute_springs_to_sparse_matrix.hpp:27
typename CrsMatrixType::device_type DeviceType
Definition contribute_springs_to_sparse_matrix.hpp:16
typename View< ValueType >::const_type ConstView
Definition contribute_springs_to_sparse_matrix.hpp:24
typename TeamPolicy::member_type member_type
Definition contribute_springs_to_sparse_matrix.hpp:20
ConstView< size_t *[2][3]> element_freedom_table
Definition contribute_springs_to_sparse_matrix.hpp:28
ConstView< double *[2][2][3][3]> dense
Definition contribute_springs_to_sparse_matrix.hpp:29
KOKKOS_FUNCTION void operator()(member_type member) const
Definition contribute_springs_to_sparse_matrix.hpp:33
CrsMatrixType sparse
Definition contribute_springs_to_sparse_matrix.hpp:30
typename CrsMatrixType::staticcrsgraph_type::entries_type::non_const_type ColIdxType
Definition contribute_springs_to_sparse_matrix.hpp:18
typename CrsMatrixType::values_type::non_const_type RowDataType
Definition contribute_springs_to_sparse_matrix.hpp:17
typename Kokkos::TeamPolicy< typename DeviceType::execution_space > TeamPolicy
Definition contribute_springs_to_sparse_matrix.hpp:19