/home/runner/work/kynema/kynema/kynema/src/step/step.hpp Source File

Kynema API: /home/runner/work/kynema/kynema/kynema/src/step/step.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
step.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Kokkos_Core.hpp>
4#include <Kokkos_Profiling_ScopedRegion.hpp>
5
13#include "elements/elements.hpp"
15#include "reset_constraints.hpp"
16#include "reset_solver.hpp"
17#include "solve_system.hpp"
18#include "solver/solver.hpp"
19#include "state/clone_state.hpp"
21#include "state/state.hpp"
24#include "step_parameters.hpp"
30
31namespace kynema {
32
44template <typename DeviceType>
45inline bool SolveStep(
46 StepParameters& parameters, Solver<DeviceType>& solver, Elements<DeviceType>& elements,
48) {
49 auto region = Kokkos::Profiling::ScopedRegion("SolveStep");
50
51 step::PredictNextState(parameters, state);
52 step::ResetConstraints(constraints);
53
54 solver.convergence_err.clear();
55 double err{1000.};
56 for (auto iter = 0U; err > 1.; ++iter) {
57 if (iter >= parameters.max_iter) {
58 return false;
59 }
60 step::ResetSolver(solver);
61
62 step::UpdateTangentOperator(parameters, state);
63
64 step::UpdateSystemVariables(parameters, elements, state);
65
66 step::AssembleSystemResidual(solver, elements, state);
67
68 step::AssembleSystemMatrix(parameters, solver, elements);
69
70 step::UpdateConstraintVariables(state, constraints);
71
72 step::AssembleConstraintsMatrix(solver, constraints);
73
74 step::AssembleConstraintsResidual(solver, constraints);
75
76 step::SolveSystem(parameters, solver);
77
78 err = step::CalculateConvergenceError(parameters, solver, state, constraints);
79
80 solver.convergence_err.push_back(err);
81
82 step::UpdateStatePrediction(parameters, solver, state);
83
84 step::UpdateConstraintPrediction(solver, constraints);
85 }
86
87 using RangePolicy = Kokkos::RangePolicy<typename DeviceType::execution_space>;
88
89 auto system_range = RangePolicy(0, solver.num_system_nodes);
90 Kokkos::parallel_for(
91 "UpdateAlgorithmicAcceleration", system_range,
93 state.a,
94 state.vd,
95 parameters.alpha_f,
96 parameters.alpha_m,
97 }
98 );
99
100 Kokkos::parallel_for(
101 "UpdateGlobalPosition", system_range,
103 state.q,
104 state.x0,
105 state.x,
106 }
107 );
108
109 auto constraints_range = RangePolicy(0, constraints.num_constraints);
110 Kokkos::parallel_for(
111 "CalculateConstraintOutput", constraints_range,
113 constraints.type,
114 constraints.target_node_index,
115 constraints.axes,
116 state.x0,
117 state.q,
118 state.v,
119 state.vd,
120 constraints.output,
121 }
122 );
123 Kokkos::deep_copy(constraints.host_output, constraints.output);
124
125 // If the error was NaN, return false
126 return !std::isnan(err);
127}
128
138template <typename DeviceType>
139inline bool Step(
140 StepParameters& parameters, Solver<DeviceType>& solver, Elements<DeviceType>& elements,
141 State<DeviceType>& state, Constraints<DeviceType>& constraints
142) {
143 //--------------------------------------------------------------------------
144 // Dynamic analysis -> just do a single nonlinear increment
145 //--------------------------------------------------------------------------
146 if (parameters.is_dynamic_solve) {
147 return SolveStep(parameters, solver, elements, state, constraints);
148 }
149
150 //--------------------------------------------------------------------------
151 // Static analysis -> load reduction strategy to help with convergence
152 //--------------------------------------------------------------------------
153 const Kokkos::View<double* [6], DeviceType> loads_baseline("loads_baseline", state.f.extent(0));
154 Kokkos::deep_copy(loads_baseline, state.f);
155
156 // Load reduction variables initialization
157 bool solved{false};
158 double load_factor_low{0.}; // lower bound for the load factor
159 double load_factor_current{1.}; // current load factor
160 double load_factor_high{1.}; // upper bound for the load factor
161
162 //-------------------------------
163 // Bisection method
164 //-------------------------------
165 // Load reduction loop to help with convergence
166 auto state_last_converged = CloneState<DeviceType>(state);
167 for (size_t j = 0; j < parameters.static_load_retries; ++j) {
168 // Scale the external loads
169 Kokkos::parallel_for(
170 "ScaleLoads",
171 Kokkos::RangePolicy<typename DeviceType::execution_space>(0, state.f.extent(0)),
172 KOKKOS_LAMBDA(const int i) {
173 for (int k = 0; k < 6; ++k) {
174 state.f(i, k) = loads_baseline(i, k) * load_factor_current;
175 }
176 }
177 );
178
179 // TODO Scale the gravity load as well?
180
181 // Attempt a single nonlinear solve at the current load factor
182 const bool converged = SolveStep(parameters, solver, elements, state, constraints);
183
184 if (converged) {
185 // Record the last converged state - if we're at full load our work is done
186 CopyStateData<DeviceType>(state_last_converged, state);
187 if (std::abs(load_factor_current - 1.) < 1e-10) {
188 solved = true;
189 break;
190 }
191 // We have a successful converged lower bound -> increase lower bound
192 // to current load factor + set current load factor to full load
193 load_factor_low = load_factor_current;
194 load_factor_current = 1.;
195 } else {
196 // Not converged -> shrink load interval by bisection i.e. upper bounds is reduced to
197 // current load factor + new current load factor is set to the average of the bounds i.e.
198 // bisected
199 load_factor_high = load_factor_current;
200 load_factor_current = 0.5 * (load_factor_low + load_factor_high);
201 // Roll back to the last converged state
202 CopyStateData<DeviceType>(state, state_last_converged);
203 }
204 }
205 return solved;
206}
207
208} // namespace kynema
void ResetSolver(Solver< DeviceType > &solver)
Definition reset_solver.hpp:11
void UpdateTangentOperator(StepParameters &parameters, State< DeviceType > &state)
Definition update_tangent_operator.hpp:13
void AssembleSystemMatrix(StepParameters &parameters, Solver< DeviceType > &solver, Elements< DeviceType > &elements)
Definition assemble_system_matrix.hpp:16
void UpdateConstraintVariables(State< DeviceType > &state, Constraints< DeviceType > &constraints)
Definition update_constraint_variables.hpp:13
double CalculateConvergenceError(const StepParameters &parameters, const Solver< DeviceType > &solver, const State< DeviceType > &state, const Constraints< DeviceType > &constraints)
Calculation based on Table 1 of DOI: 10.1115/1.4033441.
Definition calculate_convergence_error.hpp:16
void AssembleConstraintsResidual(Solver< DeviceType > &solver, Constraints< DeviceType > &constraints)
Definition assemble_constraints_residual.hpp:15
void SolveSystem(StepParameters &parameters, Solver< DeviceType > &solver)
Definition solve_system.hpp:15
void ResetConstraints(Constraints< DeviceType > &constraints)
Definition reset_constraints.hpp:11
void AssembleSystemResidual(Solver< DeviceType > &solver, Elements< DeviceType > &elements, State< DeviceType > &state)
Definition assemble_system_residual.hpp:17
void AssembleConstraintsMatrix(Solver< DeviceType > &solver, Constraints< DeviceType > &constraints)
Definition assemble_constraints_matrix.hpp:13
void PredictNextState(StepParameters &parameters, State< DeviceType > &state)
Definition predict_next_state.hpp:14
void UpdateConstraintPrediction(Solver< DeviceType > &solver, Constraints< DeviceType > &constraints)
Definition update_constraint_prediction.hpp:13
void UpdateStatePrediction(StepParameters &parameters, const Solver< DeviceType > &solver, State< DeviceType > &state)
Updates the predicted next state values, based on computed solver solution, solver....
Definition update_state_prediction.hpp:25
void UpdateSystemVariables(StepParameters &parameters, const Elements< DeviceType > &elements, State< DeviceType > &state)
Definition update_system_variables.hpp:15
Definition calculate_constraint_output.hpp:8
bool Step(StepParameters &parameters, Solver< DeviceType > &solver, Elements< DeviceType > &elements, State< DeviceType > &state, Constraints< DeviceType > &constraints)
Advance solution by one time step with bisection-based load reduction for static analysis.
Definition step.hpp:139
bool SolveStep(StepParameters &parameters, Solver< DeviceType > &solver, Elements< DeviceType > &elements, State< DeviceType > &state, Constraints< DeviceType > &constraints)
Attempts to complete a single time step in the dynamic/static FEA simulation.
Definition step.hpp:45
Container class for managing multiple constraints in a simulation.
Definition constraints.hpp:29
View< double *[3]> output
Definition constraints.hpp:59
View< size_t * > target_node_index
Definition constraints.hpp:42
View< double *[3][3]> axes
Definition constraints.hpp:55
size_t num_constraints
Definition constraints.hpp:35
View< constraints::ConstraintType * > type
Definition constraints.hpp:39
View< double *[3]>::HostMirror host_output
Definition constraints.hpp:64
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
size_t num_system_nodes
Definition solver.hpp:73
std::vector< double > convergence_err
Definition solver.hpp:83
Container for storing the complete system state of the simulation at a given time increment.
Definition state.hpp:18
View< double *[7]> x0
Definition state.hpp:29
View< double *[6]> v
Definition state.hpp:34
View< double *[6]> a
Definition state.hpp:36
View< double *[7]> x
Definition state.hpp:30
View< double *[7]> q
Definition state.hpp:33
View< double *[6]> vd
Definition state.hpp:35
View< double *[6]> f
Definition state.hpp:37
A Struct containing the paramters used to control the time stepping process.
Definition step_parameters.hpp:12
size_t static_load_retries
Definition step_parameters.hpp:25
double alpha_m
Definition step_parameters.hpp:16
size_t max_iter
Definition step_parameters.hpp:14
bool is_dynamic_solve
Definition step_parameters.hpp:13
double alpha_f
Definition step_parameters.hpp:17
Kernel that calculates the output for a constraints, for use as feedback to controllers.
Definition calculate_constraint_output.hpp:15
A Kernel to update the algorithmic acceleration based on the acceleration and generalized alpha solve...
Definition update_algorithmic_acceleration.hpp:12
A Kernel to update the absolute position of each node based on the solver's current state and the ini...
Definition update_global_position.hpp:14