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

Kynema API: /home/runner/work/kynema-fmb/kynema-fmb/kynema-fmb/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_fmb::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), [&](int node_12) {
42 const auto node_1 = node_12 % num_nodes;
43 const auto node_2 = node_12 / num_nodes;
44 constexpr auto num_dofs = 6;
45 const auto hint =
46 static_cast<typename CrsMatrixType::ordinal_type>(node_2 * num_dofs);
47
48 const auto first_column = static_cast<typename CrsMatrixType::ordinal_type>(
49 element_freedom_table(element, node_2, 0)
50 );
51 const auto local_dense =
52 Kokkos::subview(dense, element, node_1, node_2, Kokkos::ALL, Kokkos::ALL);
53 for (auto component_1 = 0; component_1 < num_dofs; ++component_1) {
54 const auto row_num =
55 static_cast<int>(element_freedom_table(element, node_1, component_1));
56 auto row = sparse.row(row_num);
57 auto offset = KokkosSparse::findRelOffset(
58 &(row.colidx(0)), row.length, first_column, hint, is_sorted
59 );
60 for (auto component_2 = 0; component_2 < num_dofs; ++component_2, ++offset) {
61 const auto contribution =
63 if constexpr (force_atomic) {
64 Kokkos::atomic_add(&(row.value(offset)), contribution);
65 } else {
66 row.value(offset) += contribution;
67 }
68 }
69 }
70 }
71 );
72 }
73};
74
75} // namespace kynema_fmb::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
ConstView< size_t * > num_nodes_per_element
Definition contribute_beams_to_sparse_matrix.hpp:27
typename CrsMatrixType::staticcrsgraph_type::entries_type::non_const_type ColIdxType
Definition contribute_beams_to_sparse_matrix.hpp:18
CrsMatrixType sparse
Definition contribute_beams_to_sparse_matrix.hpp:31
Kokkos::TeamPolicy< typename DeviceType::execution_space > TeamPolicy
Definition contribute_beams_to_sparse_matrix.hpp:19
ConstView< double ***[6][6]> dense
Definition contribute_beams_to_sparse_matrix.hpp:30
typename CrsMatrixType::values_type::non_const_type RowDataType
Definition contribute_beams_to_sparse_matrix.hpp:17
Kokkos::View< ValueType, DeviceType > View
Definition contribute_beams_to_sparse_matrix.hpp:22
typename View< ValueType >::const_type ConstView
Definition contribute_beams_to_sparse_matrix.hpp:24
ConstView< size_t **[6]> element_freedom_table
Definition contribute_beams_to_sparse_matrix.hpp:29
typename TeamPolicy::member_type member_type
Definition contribute_beams_to_sparse_matrix.hpp:20
KOKKOS_FUNCTION void operator()(member_type member) const
Definition contribute_beams_to_sparse_matrix.hpp:34
typename CrsMatrixType::device_type DeviceType
Definition contribute_beams_to_sparse_matrix.hpp:16
double conditioner
Definition contribute_beams_to_sparse_matrix.hpp:26
ConstView< dof::FreedomSignature ** > element_freedom_signature
Definition contribute_beams_to_sparse_matrix.hpp:28