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

Kynema API: /home/runner/work/kynema/kynema/kynema/src/solver/contribute_beams_to_sparse_matrix.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
contribute_beams_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 = 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{};
31 CrsMatrixType sparse;
32
35 const auto element = member.league_rank();
36 const auto num_nodes = static_cast<int>(num_nodes_per_element(element));
37 constexpr auto is_sorted = true;
38 constexpr auto force_atomic =
39 !std::is_same_v<typename DeviceType::execution_space, Kokkos::Serial>;
40 Kokkos::parallel_for(
41 Kokkos::TeamVectorRange(member, num_nodes * num_nodes),
42 [&](int node_12) {
43 const auto node_1 = node_12 % num_nodes;
44 const auto node_2 = node_12 / num_nodes;
45 constexpr auto num_dofs = 6;
46 const auto hint =
47 static_cast<typename CrsMatrixType::ordinal_type>(node_2 * num_dofs);
48
49 const auto first_column = static_cast<typename CrsMatrixType::ordinal_type>(
50 element_freedom_table(element, node_2, 0)
51 );
52 const auto local_dense =
53 Kokkos::subview(dense, element, node_1, node_2, Kokkos::ALL, Kokkos::ALL);
54 for (auto component_1 = 0; component_1 < num_dofs; ++component_1) {
55 const auto row_num =
56 static_cast<int>(element_freedom_table(element, node_1, component_1));
57 auto row = sparse.row(row_num);
58 auto offset = KokkosSparse::findRelOffset(
59 &(row.colidx(0)), row.length, first_column, hint, is_sorted
60 );
61 for (auto component_2 = 0; component_2 < num_dofs; ++component_2, ++offset) {
62 const auto contribution =
64 if constexpr (force_atomic) {
65 Kokkos::atomic_add(&(row.value(offset)), contribution);
66 } else {
67 row.value(offset) += contribution;
68 }
69 }
70 }
71 }
72 );
73 }
74};
75
76} // namespace kynema::solver
Definition calculate_error_sum_squares.hpp:5
A Kernel which sums the system matrix contributions computed at each node in a beam into the correct ...
Definition contribute_beams_to_sparse_matrix.hpp:15
CrsMatrixType sparse
Definition contribute_beams_to_sparse_matrix.hpp:31
typename TeamPolicy::member_type member_type
Definition contribute_beams_to_sparse_matrix.hpp:20
ConstView< size_t **[6]> element_freedom_table
Definition contribute_beams_to_sparse_matrix.hpp:29
double conditioner
Definition contribute_beams_to_sparse_matrix.hpp:26
ConstView< double ***[6][6]> dense
Definition contribute_beams_to_sparse_matrix.hpp:30
ConstView< dof::FreedomSignature ** > element_freedom_signature
Definition contribute_beams_to_sparse_matrix.hpp:28
KOKKOS_FUNCTION void operator()(member_type member) const
Definition contribute_beams_to_sparse_matrix.hpp:34
typename CrsMatrixType::staticcrsgraph_type::entries_type::non_const_type ColIdxType
Definition contribute_beams_to_sparse_matrix.hpp:18
Kokkos::View< ValueType, DeviceType > View
Definition contribute_beams_to_sparse_matrix.hpp:22
ConstView< size_t * > num_nodes_per_element
Definition contribute_beams_to_sparse_matrix.hpp:27
typename CrsMatrixType::device_type DeviceType
Definition contribute_beams_to_sparse_matrix.hpp:16
Kokkos::TeamPolicy< typename DeviceType::execution_space > TeamPolicy
Definition contribute_beams_to_sparse_matrix.hpp:19
typename CrsMatrixType::values_type::non_const_type RowDataType
Definition contribute_beams_to_sparse_matrix.hpp:17
typename View< ValueType >::const_type ConstView
Definition contribute_beams_to_sparse_matrix.hpp:24