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

Kynema API: /home/runner/work/kynema/kynema/kynema/src/solver/copy_constraints_to_sparse_matrix.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
copy_constraints_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
34 CrsMatrixType sparse;
35
38 const auto constraint = member.league_rank();
39 constexpr auto is_sorted = true;
40 const auto start_row = row_range(constraint).first;
41 const auto end_row = row_range(constraint).second;
42 const auto num_base_dofs = count_active_dofs(base_node_freedom_signature(constraint));
43 const auto num_target_dofs = count_active_dofs(target_node_freedom_signature(constraint));
44 constexpr auto force_atomic =
45 !std::is_same_v<typename DeviceType::execution_space, Kokkos::Serial>;
46
47 Kokkos::parallel_for(Kokkos::TeamVectorRange(member, start_row, end_row), [&](size_t i) {
48 const auto row_number = i - start_row;
49 const auto real_row = num_system_rows + i;
50 constexpr auto hint = static_cast<typename CrsMatrixType::ordinal_type>(0);
51 auto row = sparse.row(static_cast<int>(real_row));
52 auto first_col = static_cast<typename CrsMatrixType::ordinal_type>(
53 base_node_freedom_table(constraint, 0)
54 );
55 auto offset = KokkosSparse::findRelOffset(
56 &(row.colidx(0)), row.length, first_col, hint, is_sorted
57 );
58 for (auto entry = 0U; entry < num_base_dofs; ++entry, ++offset) {
59 if constexpr (force_atomic) {
60 Kokkos::atomic_add(
61 &row.value(offset), base_dense(constraint, row_number, entry)
62 );
63 } else {
64 row.value(offset) = base_dense(constraint, row_number, entry);
65 }
66 }
67
68 first_col = static_cast<typename CrsMatrixType::ordinal_type>(
69 target_node_freedom_table(constraint, 0)
70 );
71 offset = KokkosSparse::findRelOffset(
72 &(row.colidx(0)), row.length, first_col, hint, is_sorted
73 );
74 for (auto entry = 0U; entry < num_target_dofs; ++entry, ++offset) {
75 if constexpr (force_atomic) {
76 Kokkos::atomic_add(
77 &row.value(offset), target_dense(constraint, row_number, entry)
78 );
79 } else {
80 row.value(offset) = target_dense(constraint, row_number, entry);
81 }
82 }
83 });
84 }
85};
86} // namespace kynema::solver
Definition calculate_error_sum_squares.hpp:5
A Kernel which copies the gradient matrix contributions for the base and target node of a constraint ...
Definition copy_constraints_to_sparse_matrix.hpp:15
ConstView< double *[6][6]> base_dense
Definition copy_constraints_to_sparse_matrix.hpp:32
typename CrsMatrixType::staticcrsgraph_type::entries_type::non_const_type ColIdxType
Definition copy_constraints_to_sparse_matrix.hpp:18
CrsMatrixType sparse
Definition copy_constraints_to_sparse_matrix.hpp:34
typename CrsMatrixType::device_type DeviceType
Definition copy_constraints_to_sparse_matrix.hpp:16
ConstView< dof::FreedomSignature * > base_node_freedom_signature
Definition copy_constraints_to_sparse_matrix.hpp:28
size_t num_system_rows
Definition copy_constraints_to_sparse_matrix.hpp:26
typename TeamPolicy::member_type member_type
Definition copy_constraints_to_sparse_matrix.hpp:20
ConstView< Kokkos::pair< size_t, size_t > * > row_range
Definition copy_constraints_to_sparse_matrix.hpp:27
KOKKOS_FUNCTION void operator()(member_type member) const
Definition copy_constraints_to_sparse_matrix.hpp:37
ConstView< double *[6][6]> target_dense
Definition copy_constraints_to_sparse_matrix.hpp:33
Kokkos::View< ValueType, DeviceType > View
Definition copy_constraints_to_sparse_matrix.hpp:22
typename Kokkos::TeamPolicy< typename DeviceType::execution_space > TeamPolicy
Definition copy_constraints_to_sparse_matrix.hpp:19
typename CrsMatrixType::values_type::non_const_type RowDataType
Definition copy_constraints_to_sparse_matrix.hpp:17
ConstView< size_t *[6]> target_node_freedom_table
Definition copy_constraints_to_sparse_matrix.hpp:31
typename View< ValueType >::const_type ConstView
Definition copy_constraints_to_sparse_matrix.hpp:24
ConstView< dof::FreedomSignature * > target_node_freedom_signature
Definition copy_constraints_to_sparse_matrix.hpp:29
ConstView< size_t *[6]> base_node_freedom_table
Definition copy_constraints_to_sparse_matrix.hpp:30