/home/runner/work/kynema-fmb/kynema-fmb/src/step/extract_system_matrices.hpp Source File

Kynema-FMB API: /home/runner/work/kynema-fmb/kynema-fmb/src/step/extract_system_matrices.hpp Source File
Kynema-FMB API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
extract_system_matrices.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Kokkos_Core.hpp>
4#include <Kokkos_Profiling_ScopedRegion.hpp>
5
10#include "reset_solver.hpp"
11#include "solver/solver.hpp"
12#include "state/state.hpp"
13#include "step_parameters.hpp"
17
18namespace kynema_fmb {
19
20template <typename DeviceType>
23 using ValuesType = typename CrsMatrixType::values_type::non_const_type;
24 using RowMapType = typename CrsMatrixType::staticcrsgraph_type::row_map_type;
25 using EntriesType = typename CrsMatrixType::staticcrsgraph_type::entries_type;
26
27 // CRS graph shared by all assembled matrices
30
35};
36
37namespace step {
38
39template <typename DeviceType>
41 const StepParameters& base_parameters, Solver<DeviceType>& solver,
43) {
44 auto region = Kokkos::Profiling::ScopedRegion("Extract System Matrices");
45
46 using ValuesType = typename SystemMatrices<DeviceType>::ValuesType;
48 const auto num_values = solver.A.values.extent(0);
49
50 // Capture the shared sparsity pattern that is created with the solver.
51 result.row_map = solver.A.graph.row_map;
52 result.col_indices = solver.A.graph.entries;
53
54 // Tangent depends only on state and base parameters — compute once
55 auto params_for_tangent = base_parameters;
56 step::UpdateTangentOperator(params_for_tangent, state);
57
58 // --- Mass pass ---
59 {
60 auto params = base_parameters;
61 params.h = 0.0;
62 params.beta_prime = 1.0;
63 params.gamma_prime = 0.0;
64 params.conditioner = 1.0;
65 params.include_stiffness = false;
66
67 step::ResetSolver(solver);
68 step::UpdateSystemVariables(params, elements, state);
69 step::AssembleSystemMatrix(params, solver, elements);
70
71 result.mass_matrix_values = ValuesType("mass_values", num_values);
72 Kokkos::deep_copy(result.mass_matrix_values, solver.A.values);
73 }
74
75 // --- Stiffness pass ---
76 {
77 auto params = base_parameters;
78 params.h = 0.0;
79 params.beta_prime = 0.0;
80 params.gamma_prime = 0.0;
81 params.conditioner = 1.0;
82 params.include_stiffness = true;
83 params.include_tangent = false;
84
85 step::ResetSolver(solver);
86 step::UpdateSystemVariables(params, elements, state);
87 step::AssembleSystemMatrix(params, solver, elements);
88
89 result.stiffness_matrix_values = ValuesType("stiffness_values", num_values);
90 Kokkos::deep_copy(result.stiffness_matrix_values, solver.A.values);
91 }
92
93 // --- Damping pass ---
94 {
95 auto params = base_parameters;
96 params.h = 0.0;
97 params.beta_prime = 0.0;
98 params.gamma_prime = 1.0;
99 params.conditioner = 1.0;
100 params.include_stiffness = false;
101
102 step::ResetSolver(solver);
103 step::UpdateSystemVariables(params, elements, state);
104 step::AssembleSystemMatrix(params, solver, elements);
105
106 result.damping_matrix_values = ValuesType("damping_values", num_values);
107 Kokkos::deep_copy(result.damping_matrix_values, solver.A.values);
108 }
109
110 // --- Constraint pass ---
111 {
112 bool include_tangent{false}; //< post multiply by tangent operator in system matrix
113
114 step::ResetSolver(solver);
115 step::UpdateConstraintVariables(state, constraints, include_tangent);
116 step::AssembleConstraintsMatrix(solver, constraints);
117
118 result.constraint_matrix_values = ValuesType("constraint_values", num_values);
119 Kokkos::deep_copy(result.constraint_matrix_values, solver.A.values);
120 }
121
122 // --- Restore: re-run with original parameters so element
123 // storage is consistent for the next solve step ---
124 {
125 auto params = base_parameters;
126 step::ResetSolver(solver);
127 step::UpdateSystemVariables(params, elements, state);
128
129 // Likely do not need this, but for consistency in having all
130 // updates again in the reset.
131 step::UpdateTangentOperator(params, state);
132
133 step::AssembleSystemMatrix(params, solver, elements);
134 }
135
136 return result;
137}
138
139} // namespace step
140} // namespace kynema_fmb
void ResetSolver(Solver< DeviceType > &solver)
Definition reset_solver.hpp:11
void UpdateConstraintVariables(State< DeviceType > &state, Constraints< DeviceType > &constraints, bool include_tangent=true)
Definition update_constraint_variables.hpp:13
void AssembleConstraintsMatrix(Solver< DeviceType > &solver, Constraints< DeviceType > &constraints)
Definition assemble_constraints_matrix.hpp:13
SystemMatrices< DeviceType > ExtractSystemMatrices(const StepParameters &base_parameters, Solver< DeviceType > &solver, Elements< DeviceType > &elements, State< DeviceType > &state, Constraints< DeviceType > &constraints)
Definition extract_system_matrices.hpp:40
void UpdateSystemVariables(StepParameters &parameters, const Elements< DeviceType > &elements, State< DeviceType > &state)
Definition update_system_variables.hpp:15
void AssembleSystemMatrix(StepParameters &parameters, Solver< DeviceType > &solver, Elements< DeviceType > &elements)
Definition assemble_system_matrix.hpp:16
void UpdateTangentOperator(StepParameters &parameters, State< DeviceType > &state)
Definition update_tangent_operator.hpp:13
Definition calculate_constraint_output.hpp:8
Container class for managing multiple constraints in a simulation.
Definition constraints.hpp:29
A container providing handle to all structural elements present in the model.
Definition elements.hpp:20
This object manages the assembly and solution of linear system arising from the generalized-alpha bas...
Definition solver.hpp:21
CrsMatrixType A
Definition solver.hpp:77
KokkosSparse::CrsMatrix< ValueType, IndexType, DeviceType, void, IndexType > CrsMatrixType
Definition solver.hpp:65
Container for storing the complete system state of the simulation at a given time increment.
Definition state.hpp:18
A Struct containing the paramters used to control the time stepping process.
Definition step_parameters.hpp:12
double h
Definition step_parameters.hpp:15
Definition extract_system_matrices.hpp:21
ValuesType constraint_matrix_values
Definition extract_system_matrices.hpp:34
EntriesType col_indices
Definition extract_system_matrices.hpp:29
ValuesType stiffness_matrix_values
Definition extract_system_matrices.hpp:32
ValuesType damping_matrix_values
Definition extract_system_matrices.hpp:33
RowMapType row_map
Definition extract_system_matrices.hpp:28
ValuesType mass_matrix_values
Definition extract_system_matrices.hpp:31
typename CrsMatrixType::staticcrsgraph_type::row_map_type RowMapType
Definition extract_system_matrices.hpp:24
typename Solver< DeviceType >::CrsMatrixType CrsMatrixType
Definition extract_system_matrices.hpp:22
typename CrsMatrixType::values_type::non_const_type ValuesType
Definition extract_system_matrices.hpp:23
typename CrsMatrixType::staticcrsgraph_type::entries_type EntriesType
Definition extract_system_matrices.hpp:25