From 5043a18e8734445e17b1b9111d634646d3c9d0b2 Mon Sep 17 00:00:00 2001 From: dcdemen Date: Tue, 24 Sep 2024 15:42:50 -0600 Subject: [PATCH 1/8] Moved direct kernel calls out of `Step` and into a new function --- src/step/post_step_clean_up.hpp | 49 +++++++++++++++++++++++++++++++++ src/step/step.hpp | 34 ++--------------------- 2 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 src/step/post_step_clean_up.hpp diff --git a/src/step/post_step_clean_up.hpp b/src/step/post_step_clean_up.hpp new file mode 100644 index 00000000..da01c81d --- /dev/null +++ b/src/step/post_step_clean_up.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include "step_parameters.hpp" + +#include "src/beams/beams.hpp" +#include "src/constraints/calculate_constraint_output.hpp" +#include "src/constraints/constraints.hpp" +#include "src/solver/solver.hpp" +#include "src/state/state.hpp" +#include "src/state/update_algorithmic_acceleration.hpp" +#include "src/state/update_global_position.hpp" + +namespace openturbine { + +inline void PostStepCleanUp(StepParameters& parameters, Solver& solver, State& state, Constraints& constraints) { + Kokkos::parallel_for( + "UpdateAlgorithmicAcceleration", solver.num_system_nodes, + UpdateAlgorithmicAcceleration{ + state.a, + state.vd, + parameters.alpha_f, + parameters.alpha_m, + } + ); + + Kokkos::parallel_for( + "UpdateGlobalPosition", solver.num_system_nodes, + UpdateGlobalPosition{ + state.q, + state.x0, + state.x, + } + ); + + Kokkos::parallel_for( + "CalculateConstraintOutput", constraints.num, + CalculateConstraintOutput{ + constraints.type, + constraints.target_node_index, + constraints.axes, + state.x0, + state.q, + state.v, + state.vd, + constraints.output, + } + ); +} +} diff --git a/src/step/step.hpp b/src/step/step.hpp index 80c1f9a2..7d31c9bb 100644 --- a/src/step/step.hpp +++ b/src/step/step.hpp @@ -10,6 +10,7 @@ #include "assemble_system_residual.hpp" #include "assemble_tangent_operator.hpp" #include "calculate_convergence_error.hpp" +#include "post_step_clean_up.hpp" #include "predict_next_state.hpp" #include "reset_constraints.hpp" #include "solve_system.hpp" @@ -74,38 +75,7 @@ inline bool Step( } } - Kokkos::parallel_for( - "UpdateAlgorithmicAcceleration", solver.num_system_nodes, - UpdateAlgorithmicAcceleration{ - state.a, - state.vd, - parameters.alpha_f, - parameters.alpha_m, - } - ); - - Kokkos::parallel_for( - "UpdateGlobalPosition", solver.num_system_nodes, - UpdateGlobalPosition{ - state.q, - state.x0, - state.x, - } - ); - - Kokkos::parallel_for( - "CalculateConstraintOutput", constraints.num, - CalculateConstraintOutput{ - constraints.type, - constraints.target_node_index, - constraints.axes, - state.x0, - state.q, - state.v, - state.vd, - constraints.output, - } - ); + PostStepCleanUp(parameters, solver, state, constraints); return true; } From d623b73b327967ac0715203a0a959884e496f675 Mon Sep 17 00:00:00 2001 From: dcdemen Date: Tue, 24 Sep 2024 16:04:49 -0600 Subject: [PATCH 2/8] Improve const correctness of functions in step --- src/step/assemble_constraints_matrix.hpp | 2 +- src/step/assemble_constraints_residual.hpp | 2 +- src/step/assemble_system_matrix.hpp | 2 +- src/step/assemble_system_residual.hpp | 2 +- src/step/assemble_tangent_operator.hpp | 2 +- src/step/calculate_convergence_error.hpp | 2 +- src/step/post_step_clean_up.hpp | 2 +- src/step/predict_next_state.hpp | 2 +- src/step/reset_constraints.hpp | 2 +- src/step/solve_system.hpp | 2 +- src/step/step.hpp | 3 --- src/step/update_constraint_prediction.hpp | 2 +- src/step/update_constraint_variables.hpp | 2 +- src/step/update_state_prediction.hpp | 2 +- src/step/update_system_variables.hpp | 2 +- src/step/update_tangent_operator.hpp | 2 +- 16 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/step/assemble_constraints_matrix.hpp b/src/step/assemble_constraints_matrix.hpp index 93832da7..4422a542 100644 --- a/src/step/assemble_constraints_matrix.hpp +++ b/src/step/assemble_constraints_matrix.hpp @@ -9,7 +9,7 @@ #include "src/solver/solver.hpp" namespace openturbine { -inline void AssembleConstraintsMatrix(Solver& solver, Constraints& constraints) { +inline void AssembleConstraintsMatrix(Solver& solver, const Constraints& constraints) { auto region = Kokkos::Profiling::ScopedRegion("Assemble Constraints Matrix"); if (constraints.num == 0) { diff --git a/src/step/assemble_constraints_residual.hpp b/src/step/assemble_constraints_residual.hpp index 0f8d4dd3..01579800 100644 --- a/src/step/assemble_constraints_residual.hpp +++ b/src/step/assemble_constraints_residual.hpp @@ -10,7 +10,7 @@ namespace openturbine { -inline void AssembleConstraintsResidual(Solver& solver, Constraints& constraints) { +inline void AssembleConstraintsResidual(const Solver& solver, const Constraints& constraints) { auto resid_region = Kokkos::Profiling::ScopedRegion("Assemble Constraints Residual"); if (constraints.num == 0) { diff --git a/src/step/assemble_system_matrix.hpp b/src/step/assemble_system_matrix.hpp index 6c6f5405..ead5c22b 100644 --- a/src/step/assemble_system_matrix.hpp +++ b/src/step/assemble_system_matrix.hpp @@ -15,7 +15,7 @@ namespace openturbine { -inline void AssembleSystemMatrix(Solver& solver, Beams& beams) { +inline void AssembleSystemMatrix(Solver& solver, const Beams& beams) { auto region = Kokkos::Profiling::ScopedRegion("Assemble System Matrix"); const auto num_rows = solver.num_system_dofs; diff --git a/src/step/assemble_system_residual.hpp b/src/step/assemble_system_residual.hpp index b08045ee..c9097944 100644 --- a/src/step/assemble_system_residual.hpp +++ b/src/step/assemble_system_residual.hpp @@ -9,7 +9,7 @@ namespace openturbine { -inline void AssembleSystemResidual(Solver& solver, Beams& beams) { +inline void AssembleSystemResidual(const Solver& solver, const Beams& beams) { auto region = Kokkos::Profiling::ScopedRegion("Assemble System Residual"); const auto num_rows = solver.num_system_dofs; diff --git a/src/step/assemble_tangent_operator.hpp b/src/step/assemble_tangent_operator.hpp index 7da11531..146af3ba 100644 --- a/src/step/assemble_tangent_operator.hpp +++ b/src/step/assemble_tangent_operator.hpp @@ -10,7 +10,7 @@ namespace openturbine { -inline void AssembleTangentOperator(Solver& solver, State& state) { +inline void AssembleTangentOperator(const Solver& solver, const State& state) { auto region = Kokkos::Profiling::ScopedRegion("Assemble Tangent Operator"); const auto num_rows = solver.num_system_dofs; diff --git a/src/step/calculate_convergence_error.hpp b/src/step/calculate_convergence_error.hpp index fa661b08..5d422e0c 100644 --- a/src/step/calculate_convergence_error.hpp +++ b/src/step/calculate_convergence_error.hpp @@ -9,7 +9,7 @@ namespace openturbine { -inline double CalculateConvergenceError(Solver& solver, State& state) { +inline double CalculateConvergenceError(const Solver& solver, const State& state) { auto region = Kokkos::Profiling::ScopedRegion("Calculate Convergence Error"); const double atol = 1e-7; const double rtol = 1e-5; diff --git a/src/step/post_step_clean_up.hpp b/src/step/post_step_clean_up.hpp index da01c81d..d3cd92fd 100644 --- a/src/step/post_step_clean_up.hpp +++ b/src/step/post_step_clean_up.hpp @@ -12,7 +12,7 @@ namespace openturbine { -inline void PostStepCleanUp(StepParameters& parameters, Solver& solver, State& state, Constraints& constraints) { +inline void PostStepCleanUp(const StepParameters& parameters, const Solver& solver, const State& state, const Constraints& constraints) { Kokkos::parallel_for( "UpdateAlgorithmicAcceleration", solver.num_system_nodes, UpdateAlgorithmicAcceleration{ diff --git a/src/step/predict_next_state.hpp b/src/step/predict_next_state.hpp index 5622f158..689f80d7 100644 --- a/src/step/predict_next_state.hpp +++ b/src/step/predict_next_state.hpp @@ -12,7 +12,7 @@ namespace openturbine { -inline void PredictNextState(StepParameters& parameters, State& state) { +inline void PredictNextState(const StepParameters& parameters, const State& state) { auto region = Kokkos::Profiling::ScopedRegion("Predict Next State"); Kokkos::deep_copy(state.q_prev, state.q); diff --git a/src/step/reset_constraints.hpp b/src/step/reset_constraints.hpp index b037b610..43258b07 100644 --- a/src/step/reset_constraints.hpp +++ b/src/step/reset_constraints.hpp @@ -6,7 +6,7 @@ namespace openturbine { -inline void ResetConstraints(Constraints& constraints) { +inline void ResetConstraints(const Constraints& constraints) { Kokkos::deep_copy(constraints.lambda, 0.); } diff --git a/src/step/solve_system.hpp b/src/step/solve_system.hpp index 3acad809..36296bf4 100644 --- a/src/step/solve_system.hpp +++ b/src/step/solve_system.hpp @@ -10,7 +10,7 @@ namespace openturbine { -inline void SolveSystem(StepParameters& parameters, Solver& solver) { +inline void SolveSystem(const StepParameters& parameters, Solver& solver) { auto region = Kokkos::Profiling::ScopedRegion("Solve System"); { diff --git a/src/step/step.hpp b/src/step/step.hpp index 7d31c9bb..5a3ca418 100644 --- a/src/step/step.hpp +++ b/src/step/step.hpp @@ -22,12 +22,9 @@ #include "update_tangent_operator.hpp" #include "src/beams/beams.hpp" -#include "src/constraints/calculate_constraint_output.hpp" #include "src/constraints/constraints.hpp" #include "src/solver/solver.hpp" #include "src/state/state.hpp" -#include "src/state/update_algorithmic_acceleration.hpp" -#include "src/state/update_global_position.hpp" namespace openturbine { diff --git a/src/step/update_constraint_prediction.hpp b/src/step/update_constraint_prediction.hpp index ca7b8ceb..5f1890e3 100644 --- a/src/step/update_constraint_prediction.hpp +++ b/src/step/update_constraint_prediction.hpp @@ -9,7 +9,7 @@ namespace openturbine { -inline void UpdateConstraintPrediction(Solver& solver, Constraints& constraints) { +inline void UpdateConstraintPrediction(const Solver& solver, const Constraints& constraints) { auto region = Kokkos::Profiling::ScopedRegion("Update Constraint Prediction"); const auto x_lambda = Kokkos::subview(solver.x, Kokkos::make_pair(solver.num_system_dofs, solver.num_dofs)); diff --git a/src/step/update_constraint_variables.hpp b/src/step/update_constraint_variables.hpp index ab582ae1..b4468392 100644 --- a/src/step/update_constraint_variables.hpp +++ b/src/step/update_constraint_variables.hpp @@ -10,7 +10,7 @@ namespace openturbine { -inline void UpdateConstraintVariables(State& state, Constraints& constraints) { +inline void UpdateConstraintVariables(const State& state, Constraints& constraints) { auto region = Kokkos::Profiling::ScopedRegion("Update Constraint Variables"); if (constraints.num == 0) { diff --git a/src/step/update_state_prediction.hpp b/src/step/update_state_prediction.hpp index ea303278..e548fa1f 100644 --- a/src/step/update_state_prediction.hpp +++ b/src/step/update_state_prediction.hpp @@ -13,7 +13,7 @@ namespace openturbine { -inline void UpdateStatePrediction(StepParameters& parameters, const Solver& solver, State& state) { +inline void UpdateStatePrediction(const StepParameters& parameters, const Solver& solver, const State& state) { auto region = Kokkos::Profiling::ScopedRegion("Update State Prediction"); const auto x_system = Kokkos::subview(solver.x, Kokkos::make_pair(size_t{0U}, solver.num_system_dofs)); diff --git a/src/step/update_system_variables.hpp b/src/step/update_system_variables.hpp index 36150ac1..ce8bd17b 100644 --- a/src/step/update_system_variables.hpp +++ b/src/step/update_system_variables.hpp @@ -16,7 +16,7 @@ namespace openturbine { -inline void UpdateSystemVariables(StepParameters& parameters, const Beams& beams, State& state) { +inline void UpdateSystemVariables(const StepParameters& parameters, const Beams& beams, const State& state) { auto region = Kokkos::Profiling::ScopedRegion("Update System Variables"); auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); Kokkos::parallel_for( diff --git a/src/step/update_tangent_operator.hpp b/src/step/update_tangent_operator.hpp index 846e3e0c..61b715ec 100644 --- a/src/step/update_tangent_operator.hpp +++ b/src/step/update_tangent_operator.hpp @@ -10,7 +10,7 @@ namespace openturbine { -inline void UpdateTangentOperator(StepParameters& parameters, State& state) { +inline void UpdateTangentOperator(const StepParameters& parameters, const State& state) { auto region = Kokkos::Profiling::ScopedRegion("Update Tangent Operator"); Kokkos::parallel_for( "CalculateTangentOperator", state.num_system_nodes, From 9c4330ce98e3af59d051d831184126b0cda85381 Mon Sep 17 00:00:00 2001 From: dcdemen Date: Tue, 24 Sep 2024 16:20:25 -0600 Subject: [PATCH 3/8] Moved step implementation into its own .cpp file --- src/constraints/constraints.hpp | 1 + src/step/CMakeLists.txt | 2 +- src/step/step.cpp | 77 ++++++++++++++++++ src/step/step.hpp | 81 ++----------------- .../regression/test_cantilever_beam.cpp | 2 + .../regression/test_rotating_beam.cpp | 2 + tests/unit_tests/regression/test_rotor.cpp | 2 + tests/unit_tests/regression/test_solver.cpp | 1 + 8 files changed, 94 insertions(+), 74 deletions(-) create mode 100644 src/step/step.cpp diff --git a/src/constraints/constraints.hpp b/src/constraints/constraints.hpp index 9a3b26db..16e1c6da 100644 --- a/src/constraints/constraints.hpp +++ b/src/constraints/constraints.hpp @@ -2,6 +2,7 @@ #include #include +#include #include diff --git a/src/step/CMakeLists.txt b/src/step/CMakeLists.txt index 7a0cd862..a8cba23a 100644 --- a/src/step/CMakeLists.txt +++ b/src/step/CMakeLists.txt @@ -1 +1 @@ -target_sources(openturbine_library PRIVATE) +target_sources(openturbine_library PRIVATE step.cpp) diff --git a/src/step/step.cpp b/src/step/step.cpp new file mode 100644 index 00000000..60b06bce --- /dev/null +++ b/src/step/step.cpp @@ -0,0 +1,77 @@ +#include "step.hpp" + +#include + +#include "assemble_constraints_matrix.hpp" +#include "assemble_constraints_residual.hpp" +#include "assemble_system_matrix.hpp" +#include "assemble_system_residual.hpp" +#include "assemble_tangent_operator.hpp" +#include "calculate_convergence_error.hpp" +#include "post_step_clean_up.hpp" +#include "predict_next_state.hpp" +#include "reset_constraints.hpp" +#include "solve_system.hpp" +#include "step_parameters.hpp" +#include "update_constraint_prediction.hpp" +#include "update_constraint_variables.hpp" +#include "update_state_prediction.hpp" +#include "update_system_variables.hpp" +#include "update_tangent_operator.hpp" + +#include "src/beams/beams.hpp" +#include "src/constraints/constraints.hpp" +#include "src/solver/solver.hpp" +#include "src/state/state.hpp" + +namespace openturbine { + +bool Step( + const StepParameters& parameters, Solver& solver, const Beams& beams, const State& state, Constraints& constraints +) { + auto region = Kokkos::Profiling::ScopedRegion("Step"); + PredictNextState(parameters, state); + + ResetConstraints(constraints); + + solver.convergence_err.clear(); + + double err = 1000.0; + + for (auto iter = 0U; err > 1.0; ++iter) { + UpdateSystemVariables(parameters, beams, state); + + UpdateTangentOperator(parameters, state); + + AssembleTangentOperator(solver, state); + + AssembleSystemResidual(solver, beams); + + AssembleSystemMatrix(solver, beams); + + UpdateConstraintVariables(state, constraints); + + AssembleConstraintsMatrix(solver, constraints); + + AssembleConstraintsResidual(solver, constraints); + + SolveSystem(parameters, solver); + + err = CalculateConvergenceError(solver, state); + + solver.convergence_err.push_back(err); + + UpdateStatePrediction(parameters, solver, state); + + UpdateConstraintPrediction(solver, constraints); + + if (iter >= parameters.max_iter) { + return false; + } + } + + PostStepCleanUp(parameters, solver, state, constraints); + + return true; +} +} diff --git a/src/step/step.hpp b/src/step/step.hpp index 5a3ca418..192e26ea 100644 --- a/src/step/step.hpp +++ b/src/step/step.hpp @@ -1,80 +1,15 @@ #pragma once -#include -#include -#include - -#include "assemble_constraints_matrix.hpp" -#include "assemble_constraints_residual.hpp" -#include "assemble_system_matrix.hpp" -#include "assemble_system_residual.hpp" -#include "assemble_tangent_operator.hpp" -#include "calculate_convergence_error.hpp" -#include "post_step_clean_up.hpp" -#include "predict_next_state.hpp" -#include "reset_constraints.hpp" -#include "solve_system.hpp" -#include "step_parameters.hpp" -#include "update_constraint_prediction.hpp" -#include "update_constraint_variables.hpp" -#include "update_state_prediction.hpp" -#include "update_system_variables.hpp" -#include "update_tangent_operator.hpp" - -#include "src/beams/beams.hpp" -#include "src/constraints/constraints.hpp" -#include "src/solver/solver.hpp" -#include "src/state/state.hpp" - namespace openturbine { -inline bool Step( - StepParameters& parameters, Solver& solver, Beams& beams, State& state, Constraints& constraints -) { - auto region = Kokkos::Profiling::ScopedRegion("Step"); - PredictNextState(parameters, state); - - ResetConstraints(constraints); - - solver.convergence_err.clear(); - - double err = 1000.0; - - for (auto iter = 0U; err > 1.0; ++iter) { - UpdateSystemVariables(parameters, beams, state); - - UpdateTangentOperator(parameters, state); - - AssembleTangentOperator(solver, state); - - AssembleSystemResidual(solver, beams); - - AssembleSystemMatrix(solver, beams); - - UpdateConstraintVariables(state, constraints); - - AssembleConstraintsMatrix(solver, constraints); - - AssembleConstraintsResidual(solver, constraints); - - SolveSystem(parameters, solver); - - err = CalculateConvergenceError(solver, state); - - solver.convergence_err.push_back(err); - - UpdateStatePrediction(parameters, solver, state); - - UpdateConstraintPrediction(solver, constraints); - - if (iter >= parameters.max_iter) { - return false; - } - } - - PostStepCleanUp(parameters, solver, state, constraints); +struct StepParameters; +struct Solver; +struct Beams; +struct State; +struct Constraints; - return true; -} +bool Step( + const StepParameters& parameters, Solver& solver, const Beams& beams, const State& state, Constraints& constraints +); } // namespace openturbine diff --git a/tests/unit_tests/regression/test_cantilever_beam.cpp b/tests/unit_tests/regression/test_cantilever_beam.cpp index 694cd4cb..fc01edd8 100644 --- a/tests/unit_tests/regression/test_cantilever_beam.cpp +++ b/tests/unit_tests/regression/test_cantilever_beam.cpp @@ -16,6 +16,8 @@ #include "src/solver/solver.hpp" #include "src/state/state.hpp" #include "src/step/step.hpp" +#include "src/step/step_parameters.hpp" +#include "src/constraints/constraints.hpp" #include "src/types.hpp" namespace openturbine::tests { diff --git a/tests/unit_tests/regression/test_rotating_beam.cpp b/tests/unit_tests/regression/test_rotating_beam.cpp index 369c81e6..602649cf 100644 --- a/tests/unit_tests/regression/test_rotating_beam.cpp +++ b/tests/unit_tests/regression/test_rotating_beam.cpp @@ -20,6 +20,8 @@ #include "src/model/model.hpp" #include "src/solver/solver.hpp" #include "src/state/state.hpp" +#include "src/constraints/constraints.hpp" +#include "src/step/step_parameters.hpp" #include "src/step/step.hpp" #include "src/types.hpp" diff --git a/tests/unit_tests/regression/test_rotor.cpp b/tests/unit_tests/regression/test_rotor.cpp index c4fb5169..fbd55494 100644 --- a/tests/unit_tests/regression/test_rotor.cpp +++ b/tests/unit_tests/regression/test_rotor.cpp @@ -18,6 +18,8 @@ #include "src/solver/solver.hpp" #include "src/state/state.hpp" #include "src/step/step.hpp" +#include "src/step/step_parameters.hpp" +#include "src/constraints/constraints.hpp" #include "src/types.hpp" #include "src/utilities/controllers/discon.hpp" #include "src/utilities/controllers/turbine_controller.hpp" diff --git a/tests/unit_tests/regression/test_solver.cpp b/tests/unit_tests/regression/test_solver.cpp index e616afc1..cbab1f6a 100644 --- a/tests/unit_tests/regression/test_solver.cpp +++ b/tests/unit_tests/regression/test_solver.cpp @@ -20,6 +20,7 @@ #include "src/step/predict_next_state.hpp" #include "src/step/step.hpp" #include "src/step/step_parameters.hpp" +#include "src/step/update_system_variables.hpp" #include "src/step/update_constraint_variables.hpp" #include "src/types.hpp" From a43ccb104b204a84882101f0163a8903fc3256c8 Mon Sep 17 00:00:00 2001 From: dcdemen Date: Wed, 25 Sep 2024 13:11:40 -0600 Subject: [PATCH 4/8] Split functions in the step function into .hpp and .cpp files This change should improve compile times, especially with incremental builds --- src/solver/solver.hpp | 2 +- src/step/CMakeLists.txt | 22 ++++- src/step/assemble_constraints_matrix.cpp | 55 +++++++++++++ src/step/assemble_constraints_matrix.hpp | 55 +------------ src/step/assemble_constraints_residual.cpp | 49 ++++++++++++ src/step/assemble_constraints_residual.hpp | 48 +---------- src/step/assemble_inertia_matrix.cpp | 25 ++++++ src/step/assemble_inertia_matrix.hpp | 23 +----- src/step/assemble_residual_vector.cpp | 30 +++++++ src/step/assemble_residual_vector.hpp | 28 +------ src/step/assemble_stiffness_matrix.cpp | 35 ++++++++ src/step/assemble_stiffness_matrix.hpp | 33 +------- src/step/assemble_system_matrix.cpp | 60 ++++++++++++++ src/step/assemble_system_matrix.hpp | 58 +------------- src/step/assemble_system_residual.cpp | 25 ++++++ src/step/assemble_system_residual.hpp | 24 +----- src/step/assemble_tangent_operator.cpp | 29 +++++++ src/step/assemble_tangent_operator.hpp | 28 +------ src/step/calculate_convergence_error.cpp | 28 +++++++ src/step/calculate_convergence_error.hpp | 27 +------ src/step/post_step_clean_up.cpp | 47 +++++++++++ src/step/post_step_clean_up.hpp | 48 ++--------- src/step/predict_next_state.cpp | 43 ++++++++++ src/step/predict_next_state.hpp | 42 +--------- src/step/reset_constraints.cpp | 11 +++ src/step/reset_constraints.hpp | 9 +-- src/step/solve_system.cpp | 62 ++++++++++++++ src/step/solve_system.hpp | 62 +------------- src/step/step.cpp | 3 - src/step/step_parameters.hpp | 2 + src/step/update_constraint_prediction.cpp | 26 ++++++ src/step/update_constraint_prediction.hpp | 26 +----- src/step/update_constraint_variables.cpp | 36 +++++++++ src/step/update_constraint_variables.hpp | 35 +------- src/step/update_state_prediction.cpp | 55 +++++++++++++ src/step/update_state_prediction.hpp | 55 +------------ src/step/update_system_variables.cpp | 88 ++++++++++++++++++++ src/step/update_system_variables.hpp | 89 +-------------------- src/step/update_tangent_operator.cpp | 23 ++++++ src/step/update_tangent_operator.hpp | 22 +---- tests/unit_tests/regression/test_beams.cpp | 2 + tests/unit_tests/regression/test_solver.cpp | 1 + 42 files changed, 808 insertions(+), 663 deletions(-) create mode 100644 src/step/assemble_constraints_matrix.cpp create mode 100644 src/step/assemble_constraints_residual.cpp create mode 100644 src/step/assemble_inertia_matrix.cpp create mode 100644 src/step/assemble_residual_vector.cpp create mode 100644 src/step/assemble_stiffness_matrix.cpp create mode 100644 src/step/assemble_system_matrix.cpp create mode 100644 src/step/assemble_system_residual.cpp create mode 100644 src/step/assemble_tangent_operator.cpp create mode 100644 src/step/calculate_convergence_error.cpp create mode 100644 src/step/post_step_clean_up.cpp create mode 100644 src/step/predict_next_state.cpp create mode 100644 src/step/reset_constraints.cpp create mode 100644 src/step/solve_system.cpp create mode 100644 src/step/update_constraint_prediction.cpp create mode 100644 src/step/update_constraint_variables.cpp create mode 100644 src/step/update_state_prediction.cpp create mode 100644 src/step/update_system_variables.cpp create mode 100644 src/step/update_tangent_operator.cpp diff --git a/src/solver/solver.hpp b/src/solver/solver.hpp index f61236cc..4dada194 100644 --- a/src/solver/solver.hpp +++ b/src/solver/solver.hpp @@ -88,7 +88,7 @@ struct Solver { const Kokkos::View*>::const_type& constraint_row_range ) : num_system_nodes(node_IDs.extent(0)), - num_system_dofs(num_system_nodes * kLieAlgebraComponents), + num_system_dofs(num_system_nodes * 6U), num_dofs(num_system_dofs + num_constraint_dofs), R("R", num_dofs), x("x", num_dofs) { diff --git a/src/step/CMakeLists.txt b/src/step/CMakeLists.txt index a8cba23a..49c677cb 100644 --- a/src/step/CMakeLists.txt +++ b/src/step/CMakeLists.txt @@ -1 +1,21 @@ -target_sources(openturbine_library PRIVATE step.cpp) +target_sources(openturbine_library PRIVATE + assemble_constraints_matrix.cpp + assemble_constraints_residual.cpp + assemble_inertia_matrix.cpp + assemble_residual_vector.cpp + assemble_stiffness_matrix.cpp + assemble_system_matrix.cpp + assemble_system_residual.cpp + assemble_tangent_operator.cpp + calculate_convergence_error.cpp + post_step_clean_up.cpp + predict_next_state.cpp + reset_constraints.cpp + solve_system.cpp + step.cpp + update_constraint_prediction.cpp + update_constraint_variables.cpp + update_state_prediction.cpp + update_system_variables.cpp + update_tangent_operator.cpp +) diff --git a/src/step/assemble_constraints_matrix.cpp b/src/step/assemble_constraints_matrix.cpp new file mode 100644 index 00000000..b1ebde0e --- /dev/null +++ b/src/step/assemble_constraints_matrix.cpp @@ -0,0 +1,55 @@ +#include +#include + +#include "src/constraints/constraints.hpp" +#include "src/solver/copy_constraints_to_sparse_matrix.hpp" +#include "src/solver/copy_sparse_values_to_transpose.hpp" +#include "src/solver/solver.hpp" + +namespace openturbine { +void AssembleConstraintsMatrix(Solver& solver, const Constraints& constraints) { + auto region = Kokkos::Profiling::ScopedRegion("Assemble Constraints Matrix"); + + if (constraints.num == 0) { + return; + } + + { + auto const_region = Kokkos::Profiling::ScopedRegion("Constraints Matrix"); + auto constraint_policy = + Kokkos::TeamPolicy<>(static_cast(constraints.num), Kokkos::AUTO()); + + Kokkos::parallel_for( + "CopyConstraintsToSparseMatrix", constraint_policy, + CopyConstraintsToSparseMatrix{ + constraints.row_range, constraints.base_node_col_range, + constraints.target_node_col_range, solver.B, constraints.base_gradient_terms, + constraints.target_gradient_terms} + ); + } + + { + auto trans_region = Kokkos::Profiling::ScopedRegion("Transpose Constraints Matrix"); + auto B_num_rows = solver.B.numRows(); + auto constraint_transpose_policy = Kokkos::TeamPolicy<>(B_num_rows, Kokkos::AUTO()); + auto tmp_row_map = Solver::RowPtrType( + Kokkos::view_alloc(Kokkos::WithoutInitializing, "tmp_row_map"), + solver.B_t.graph.row_map.extent(0) + ); + Kokkos::deep_copy(tmp_row_map, solver.B_t.graph.row_map); + Kokkos::parallel_for( + "CopySparseValuesToTranspose", constraint_transpose_policy, + CopySparseValuesToTranspose{solver.B, tmp_row_map, solver.B_t} + ); + KokkosSparse::sort_crs_matrix(solver.B_t); + } + + { + auto mult_region = Kokkos::Profiling::ScopedRegion("Assemble Constraints Matrix"); + KokkosSparse::spgemm_numeric( + solver.constraints_spgemm_handle, solver.B, false, solver.T, false, + solver.constraints_matrix + ); + } +} +} // namespace openturbine diff --git a/src/step/assemble_constraints_matrix.hpp b/src/step/assemble_constraints_matrix.hpp index 4422a542..cfdbad38 100644 --- a/src/step/assemble_constraints_matrix.hpp +++ b/src/step/assemble_constraints_matrix.hpp @@ -1,57 +1,8 @@ #pragma once -#include -#include - -#include "src/constraints/constraints.hpp" -#include "src/solver/copy_constraints_to_sparse_matrix.hpp" -#include "src/solver/copy_sparse_values_to_transpose.hpp" -#include "src/solver/solver.hpp" - namespace openturbine { -inline void AssembleConstraintsMatrix(Solver& solver, const Constraints& constraints) { - auto region = Kokkos::Profiling::ScopedRegion("Assemble Constraints Matrix"); - - if (constraints.num == 0) { - return; - } - - { - auto const_region = Kokkos::Profiling::ScopedRegion("Constraints Matrix"); - auto constraint_policy = - Kokkos::TeamPolicy<>(static_cast(constraints.num), Kokkos::AUTO()); - - Kokkos::parallel_for( - "CopyConstraintsToSparseMatrix", constraint_policy, - CopyConstraintsToSparseMatrix{ - constraints.row_range, constraints.base_node_col_range, - constraints.target_node_col_range, solver.B, constraints.base_gradient_terms, - constraints.target_gradient_terms} - ); - } - - { - auto trans_region = Kokkos::Profiling::ScopedRegion("Transpose Constraints Matrix"); - auto B_num_rows = solver.B.numRows(); - auto constraint_transpose_policy = Kokkos::TeamPolicy<>(B_num_rows, Kokkos::AUTO()); - auto tmp_row_map = Solver::RowPtrType( - Kokkos::view_alloc(Kokkos::WithoutInitializing, "tmp_row_map"), - solver.B_t.graph.row_map.extent(0) - ); - Kokkos::deep_copy(tmp_row_map, solver.B_t.graph.row_map); - Kokkos::parallel_for( - "CopySparseValuesToTranspose", constraint_transpose_policy, - CopySparseValuesToTranspose{solver.B, tmp_row_map, solver.B_t} - ); - KokkosSparse::sort_crs_matrix(solver.B_t); - } +struct Solver; +struct Constraints; - { - auto mult_region = Kokkos::Profiling::ScopedRegion("Assemble Constraints Matrix"); - KokkosSparse::spgemm_numeric( - solver.constraints_spgemm_handle, solver.B, false, solver.T, false, - solver.constraints_matrix - ); - } -} +void AssembleConstraintsMatrix(Solver& solver, const Constraints& constraints); } // namespace openturbine diff --git a/src/step/assemble_constraints_residual.cpp b/src/step/assemble_constraints_residual.cpp new file mode 100644 index 00000000..5dd578ea --- /dev/null +++ b/src/step/assemble_constraints_residual.cpp @@ -0,0 +1,49 @@ +#include +#include + +#include "src/constraints/constraints.hpp" +#include "src/solver/contribute_constraints_system_residual_to_vector.hpp" +#include "src/solver/copy_constraints_residual_to_vector.hpp" +#include "src/solver/solver.hpp" + +namespace openturbine { + +void AssembleConstraintsResidual(const Solver& solver, const Constraints& constraints) { + auto resid_region = Kokkos::Profiling::ScopedRegion("Assemble Constraints Residual"); + + if (constraints.num == 0) { + return; + } + + Kokkos::parallel_for( + "ContributeConstraintsSystemResidualToVector", constraints.num, + ContributeConstraintsSystemResidualToVector{ + constraints.target_node_index, solver.R, constraints.system_residual_terms} + ); + + auto R = Solver::ValuesType( + Kokkos::view_alloc(Kokkos::WithoutInitializing, "R_local"), solver.num_system_dofs + ); + Kokkos::deep_copy( + R, Kokkos::subview(solver.R, Kokkos::make_pair(size_t{0U}, solver.num_system_dofs)) + ); + auto lambda = Solver::ValuesType( + Kokkos::view_alloc(Kokkos::WithoutInitializing, "lambda"), constraints.lambda.extent(0) + ); + Kokkos::deep_copy(lambda, constraints.lambda); + auto spmv_handle = Solver::SpmvHandle(); + KokkosSparse::spmv(&spmv_handle, "T", 1., solver.B, lambda, 1., R); + Kokkos::deep_copy( + Kokkos::subview(solver.R, Kokkos::make_pair(size_t{0U}, solver.num_system_dofs)), R + ); + + Kokkos::parallel_for( + "CopyConstraintsResidualToVector", constraints.num, + CopyConstraintsResidualToVector{ + constraints.row_range, + Kokkos::subview(solver.R, Kokkos::make_pair(solver.num_system_dofs, solver.num_dofs)), + constraints.residual_terms} + ); +} + +} // namespace openturbine diff --git a/src/step/assemble_constraints_residual.hpp b/src/step/assemble_constraints_residual.hpp index 01579800..c9f5b0be 100644 --- a/src/step/assemble_constraints_residual.hpp +++ b/src/step/assemble_constraints_residual.hpp @@ -1,51 +1,9 @@ #pragma once -#include -#include - -#include "src/constraints/constraints.hpp" -#include "src/solver/contribute_constraints_system_residual_to_vector.hpp" -#include "src/solver/copy_constraints_residual_to_vector.hpp" -#include "src/solver/solver.hpp" - namespace openturbine { +struct Solver; +struct Constraints; -inline void AssembleConstraintsResidual(const Solver& solver, const Constraints& constraints) { - auto resid_region = Kokkos::Profiling::ScopedRegion("Assemble Constraints Residual"); - - if (constraints.num == 0) { - return; - } - - Kokkos::parallel_for( - "ContributeConstraintsSystemResidualToVector", constraints.num, - ContributeConstraintsSystemResidualToVector{ - constraints.target_node_index, solver.R, constraints.system_residual_terms} - ); - - auto R = Solver::ValuesType( - Kokkos::view_alloc(Kokkos::WithoutInitializing, "R_local"), solver.num_system_dofs - ); - Kokkos::deep_copy( - R, Kokkos::subview(solver.R, Kokkos::make_pair(size_t{0U}, solver.num_system_dofs)) - ); - auto lambda = Solver::ValuesType( - Kokkos::view_alloc(Kokkos::WithoutInitializing, "lambda"), constraints.lambda.extent(0) - ); - Kokkos::deep_copy(lambda, constraints.lambda); - auto spmv_handle = Solver::SpmvHandle(); - KokkosSparse::spmv(&spmv_handle, "T", 1., solver.B, lambda, 1., R); - Kokkos::deep_copy( - Kokkos::subview(solver.R, Kokkos::make_pair(size_t{0U}, solver.num_system_dofs)), R - ); - - Kokkos::parallel_for( - "CopyConstraintsResidualToVector", constraints.num, - CopyConstraintsResidualToVector{ - constraints.row_range, - Kokkos::subview(solver.R, Kokkos::make_pair(solver.num_system_dofs, solver.num_dofs)), - constraints.residual_terms} - ); -} +void AssembleConstraintsResidual(const Solver& solver, const Constraints& constraints); } // namespace openturbine diff --git a/src/step/assemble_inertia_matrix.cpp b/src/step/assemble_inertia_matrix.cpp new file mode 100644 index 00000000..06d61d77 --- /dev/null +++ b/src/step/assemble_inertia_matrix.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include "src/beams/beams.hpp" +#include "src/system/integrate_inertia_matrix.hpp" + +namespace openturbine { + +void AssembleInertiaMatrix(const Beams& beams, double beta_prime, double gamma_prime) { + auto region = Kokkos::Profiling::ScopedRegion("Assemble Inertia Matrix"); + auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); + auto smem = 2 * Kokkos::View::shmem_size(beams.max_elem_qps) + + 2 * Kokkos::View::shmem_size(beams.max_elem_qps) + + Kokkos::View::shmem_size(beams.max_elem_nodes, beams.max_elem_qps); + range_policy.set_scratch_size(1, Kokkos::PerTeam(smem)); + Kokkos::parallel_for( + "IntegrateInertiaMatrix", range_policy, + IntegrateInertiaMatrix{ + beams.num_nodes_per_element, beams.num_qps_per_element, beams.qp_weight, + beams.qp_jacobian, beams.shape_interp, beams.qp_Muu, beams.qp_Guu, beta_prime, + gamma_prime, beams.inertia_matrix_terms} + ); +} + +} // namespace openturbine diff --git a/src/step/assemble_inertia_matrix.hpp b/src/step/assemble_inertia_matrix.hpp index 0e268cc1..f4f1a141 100644 --- a/src/step/assemble_inertia_matrix.hpp +++ b/src/step/assemble_inertia_matrix.hpp @@ -1,27 +1,8 @@ #pragma once -#include -#include - -#include "src/beams/beams.hpp" -#include "src/system/integrate_inertia_matrix.hpp" - namespace openturbine { +struct Beams; -inline void AssembleInertiaMatrix(const Beams& beams, double beta_prime, double gamma_prime) { - auto region = Kokkos::Profiling::ScopedRegion("Assemble Inertia Matrix"); - auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); - auto smem = 2 * Kokkos::View::shmem_size(beams.max_elem_qps) + - 2 * Kokkos::View::shmem_size(beams.max_elem_qps) + - Kokkos::View::shmem_size(beams.max_elem_nodes, beams.max_elem_qps); - range_policy.set_scratch_size(1, Kokkos::PerTeam(smem)); - Kokkos::parallel_for( - "IntegrateInertiaMatrix", range_policy, - IntegrateInertiaMatrix{ - beams.num_nodes_per_element, beams.num_qps_per_element, beams.qp_weight, - beams.qp_jacobian, beams.shape_interp, beams.qp_Muu, beams.qp_Guu, beta_prime, - gamma_prime, beams.inertia_matrix_terms} - ); -} +void AssembleInertiaMatrix(const Beams& beams, double beta_prime, double gamma_prime); } // namespace openturbine diff --git a/src/step/assemble_residual_vector.cpp b/src/step/assemble_residual_vector.cpp new file mode 100644 index 00000000..faf62e74 --- /dev/null +++ b/src/step/assemble_residual_vector.cpp @@ -0,0 +1,30 @@ +#include +#include + +#include "src/beams/beams.hpp" +#include "src/system/integrate_residual_vector.hpp" + +namespace openturbine { + +void AssembleResidualVector(const Beams& beams) { + auto region = Kokkos::Profiling::ScopedRegion("Assemble Residual"); + auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); + const auto shape_size = + Kokkos::View::shmem_size(beams.max_elem_nodes, beams.max_elem_qps); + const auto weight_size = Kokkos::View::shmem_size(beams.max_elem_qps); + const auto node_variable_size = Kokkos::View::shmem_size(beams.max_elem_nodes); + const auto qp_variable_size = Kokkos::View::shmem_size(beams.max_elem_qps); + range_policy.set_scratch_size( + 1, + Kokkos::PerTeam(2 * shape_size + 2 * weight_size + node_variable_size + 4 * qp_variable_size) + ); + Kokkos::parallel_for( + "IntegrateResidualVector", range_policy, + IntegrateResidualVector{ + beams.num_nodes_per_element, beams.num_qps_per_element, beams.qp_weight, + beams.qp_jacobian, beams.shape_interp, beams.shape_deriv, beams.node_FX, beams.qp_Fc, + beams.qp_Fd, beams.qp_Fi, beams.qp_Fg, beams.residual_vector_terms} + ); +} + +} // namespace openturbine diff --git a/src/step/assemble_residual_vector.hpp b/src/step/assemble_residual_vector.hpp index 4cf1172f..46307ba3 100644 --- a/src/step/assemble_residual_vector.hpp +++ b/src/step/assemble_residual_vector.hpp @@ -1,32 +1,8 @@ #pragma once -#include -#include - -#include "src/beams/beams.hpp" -#include "src/system/integrate_residual_vector.hpp" - namespace openturbine { +struct Beams; -inline void AssembleResidualVector(const Beams& beams) { - auto region = Kokkos::Profiling::ScopedRegion("Assemble Residual"); - auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); - const auto shape_size = - Kokkos::View::shmem_size(beams.max_elem_nodes, beams.max_elem_qps); - const auto weight_size = Kokkos::View::shmem_size(beams.max_elem_qps); - const auto node_variable_size = Kokkos::View::shmem_size(beams.max_elem_nodes); - const auto qp_variable_size = Kokkos::View::shmem_size(beams.max_elem_qps); - range_policy.set_scratch_size( - 1, - Kokkos::PerTeam(2 * shape_size + 2 * weight_size + node_variable_size + 4 * qp_variable_size) - ); - Kokkos::parallel_for( - "IntegrateResidualVector", range_policy, - IntegrateResidualVector{ - beams.num_nodes_per_element, beams.num_qps_per_element, beams.qp_weight, - beams.qp_jacobian, beams.shape_interp, beams.shape_deriv, beams.node_FX, beams.qp_Fc, - beams.qp_Fd, beams.qp_Fi, beams.qp_Fg, beams.residual_vector_terms} - ); -} +void AssembleResidualVector(const Beams& beams); } // namespace openturbine diff --git a/src/step/assemble_stiffness_matrix.cpp b/src/step/assemble_stiffness_matrix.cpp new file mode 100644 index 00000000..080511f3 --- /dev/null +++ b/src/step/assemble_stiffness_matrix.cpp @@ -0,0 +1,35 @@ +#include +#include + +#include "src/beams/beams.hpp" +#include "src/system/integrate_stiffness_matrix.hpp" + +namespace openturbine { + +void AssembleStiffnessMatrix(const Beams& beams) { + auto region = Kokkos::Profiling::ScopedRegion("Assemble Stiffness Matrix"); + auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); + auto smem = 5 * Kokkos::View::shmem_size(beams.max_elem_qps) + + 2 * Kokkos::View::shmem_size(beams.max_elem_qps) + + 2 * Kokkos::View::shmem_size(beams.max_elem_nodes, beams.max_elem_qps); + range_policy.set_scratch_size(1, Kokkos::PerTeam(smem)); + Kokkos::parallel_for( + "IntegrateStiffnessMatrix", range_policy, + IntegrateStiffnessMatrix{ + beams.num_nodes_per_element, + beams.num_qps_per_element, + beams.qp_weight, + beams.qp_jacobian, + beams.shape_interp, + beams.shape_deriv, + beams.qp_Kuu, + beams.qp_Puu, + beams.qp_Cuu, + beams.qp_Ouu, + beams.qp_Quu, + beams.stiffness_matrix_terms, + } + ); +} + +} // namespace openturbine diff --git a/src/step/assemble_stiffness_matrix.hpp b/src/step/assemble_stiffness_matrix.hpp index 0f82e33e..3ce0d88e 100644 --- a/src/step/assemble_stiffness_matrix.hpp +++ b/src/step/assemble_stiffness_matrix.hpp @@ -1,37 +1,8 @@ #pragma once -#include -#include - -#include "src/beams/beams.hpp" -#include "src/system/integrate_stiffness_matrix.hpp" - namespace openturbine { +struct Beams; -inline void AssembleStiffnessMatrix(const Beams& beams) { - auto region = Kokkos::Profiling::ScopedRegion("Assemble Stiffness Matrix"); - auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); - auto smem = 5 * Kokkos::View::shmem_size(beams.max_elem_qps) + - 2 * Kokkos::View::shmem_size(beams.max_elem_qps) + - 2 * Kokkos::View::shmem_size(beams.max_elem_nodes, beams.max_elem_qps); - range_policy.set_scratch_size(1, Kokkos::PerTeam(smem)); - Kokkos::parallel_for( - "IntegrateStiffnessMatrix", range_policy, - IntegrateStiffnessMatrix{ - beams.num_nodes_per_element, - beams.num_qps_per_element, - beams.qp_weight, - beams.qp_jacobian, - beams.shape_interp, - beams.shape_deriv, - beams.qp_Kuu, - beams.qp_Puu, - beams.qp_Cuu, - beams.qp_Ouu, - beams.qp_Quu, - beams.stiffness_matrix_terms, - } - ); -} +void AssembleStiffnessMatrix(const Beams& beams); } // namespace openturbine diff --git a/src/step/assemble_system_matrix.cpp b/src/step/assemble_system_matrix.cpp new file mode 100644 index 00000000..f33846d2 --- /dev/null +++ b/src/step/assemble_system_matrix.cpp @@ -0,0 +1,60 @@ +#include "assemble_system_matrix.hpp" + +#include +#include +#include +#include +#include + +#include "src/beams/beams.hpp" +#include "src/solver/contribute_elements_to_sparse_matrix.hpp" +#include "src/solver/copy_into_sparse_matrix.hpp" +#include "src/solver/populate_sparse_indices.hpp" +#include "src/solver/populate_sparse_row_ptrs.hpp" +#include "src/solver/solver.hpp" + +namespace openturbine { + +void AssembleSystemMatrix(Solver& solver, const Beams& beams) { + auto region = Kokkos::Profiling::ScopedRegion("Assemble System Matrix"); + + const auto num_rows = solver.num_system_dofs; + + const auto max_row_entries = beams.max_elem_nodes * 6U; + const auto row_data_size = Kokkos::View::shmem_size(max_row_entries); + const auto col_idx_size = Kokkos::View::shmem_size(max_row_entries); + auto sparse_matrix_policy = Kokkos::TeamPolicy<>(static_cast(num_rows), Kokkos::AUTO()); + + sparse_matrix_policy.set_scratch_size(1, Kokkos::PerTeam(row_data_size + col_idx_size)); + + Kokkos::parallel_for( + "ContributeElementsToSparseMatrix", sparse_matrix_policy, + ContributeElementsToSparseMatrix{ + solver.K, beams.stiffness_matrix_terms} + ); + + Kokkos::fence(); + { + auto static_region = Kokkos::Profiling::ScopedRegion("Assemble Static System Matrix"); + KokkosSparse::spgemm_numeric( + solver.system_spgemm_handle, solver.K, false, solver.T, false, + solver.static_system_matrix + ); + } + + Kokkos::parallel_for( + "ContributeElementsToSparseMatrix", sparse_matrix_policy, + ContributeElementsToSparseMatrix{solver.K, beams.inertia_matrix_terms} + ); + + Kokkos::fence(); + { + auto system_region = Kokkos::Profiling::ScopedRegion("Assemble System Matrix"); + KokkosSparse::spadd_numeric( + &solver.system_spadd_handle, 1., solver.K, 1., solver.static_system_matrix, + solver.system_matrix + ); + } +} + +} // namespace openturbine diff --git a/src/step/assemble_system_matrix.hpp b/src/step/assemble_system_matrix.hpp index ead5c22b..c631dcd6 100644 --- a/src/step/assemble_system_matrix.hpp +++ b/src/step/assemble_system_matrix.hpp @@ -1,60 +1,8 @@ #pragma once -#include -#include -#include -#include -#include - -#include "src/beams/beams.hpp" -#include "src/solver/contribute_elements_to_sparse_matrix.hpp" -#include "src/solver/copy_into_sparse_matrix.hpp" -#include "src/solver/populate_sparse_indices.hpp" -#include "src/solver/populate_sparse_row_ptrs.hpp" -#include "src/solver/solver.hpp" - namespace openturbine { +struct Solver; +struct Beams; -inline void AssembleSystemMatrix(Solver& solver, const Beams& beams) { - auto region = Kokkos::Profiling::ScopedRegion("Assemble System Matrix"); - - const auto num_rows = solver.num_system_dofs; - - const auto max_row_entries = beams.max_elem_nodes * 6U; - const auto row_data_size = Kokkos::View::shmem_size(max_row_entries); - const auto col_idx_size = Kokkos::View::shmem_size(max_row_entries); - auto sparse_matrix_policy = Kokkos::TeamPolicy<>(static_cast(num_rows), Kokkos::AUTO()); - - sparse_matrix_policy.set_scratch_size(1, Kokkos::PerTeam(row_data_size + col_idx_size)); - - Kokkos::parallel_for( - "ContributeElementsToSparseMatrix", sparse_matrix_policy, - ContributeElementsToSparseMatrix{ - solver.K, beams.stiffness_matrix_terms} - ); - - Kokkos::fence(); - { - auto static_region = Kokkos::Profiling::ScopedRegion("Assemble Static System Matrix"); - KokkosSparse::spgemm_numeric( - solver.system_spgemm_handle, solver.K, false, solver.T, false, - solver.static_system_matrix - ); - } - - Kokkos::parallel_for( - "ContributeElementsToSparseMatrix", sparse_matrix_policy, - ContributeElementsToSparseMatrix{solver.K, beams.inertia_matrix_terms} - ); - - Kokkos::fence(); - { - auto system_region = Kokkos::Profiling::ScopedRegion("Assemble System Matrix"); - KokkosSparse::spadd_numeric( - &solver.system_spadd_handle, 1., solver.K, 1., solver.static_system_matrix, - solver.system_matrix - ); - } -} - +void AssembleSystemMatrix(Solver& solver, const Beams& beams); } // namespace openturbine diff --git a/src/step/assemble_system_residual.cpp b/src/step/assemble_system_residual.cpp new file mode 100644 index 00000000..2aa4391e --- /dev/null +++ b/src/step/assemble_system_residual.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include "src/beams/beams.hpp" +#include "src/solver/contribute_elements_to_vector.hpp" +#include "src/solver/solver.hpp" + +namespace openturbine { + +void AssembleSystemResidual(const Solver& solver, const Beams& beams) { + auto region = Kokkos::Profiling::ScopedRegion("Assemble System Residual"); + + const auto num_rows = solver.num_system_dofs; + + Kokkos::deep_copy(Kokkos::subview(solver.R, Kokkos::make_pair(size_t{0U}, num_rows)), 0.); + auto vector_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); + Kokkos::parallel_for( + "ContributeElementsToVector", vector_policy, + ContributeElementsToVector{ + beams.num_nodes_per_element, beams.node_state_indices, beams.residual_vector_terms, + solver.R} + ); +} + +} // namespace openturbine diff --git a/src/step/assemble_system_residual.hpp b/src/step/assemble_system_residual.hpp index c9097944..0914c92a 100644 --- a/src/step/assemble_system_residual.hpp +++ b/src/step/assemble_system_residual.hpp @@ -1,27 +1,9 @@ #pragma once -#include -#include - -#include "src/beams/beams.hpp" -#include "src/solver/contribute_elements_to_vector.hpp" -#include "src/solver/solver.hpp" - namespace openturbine { +struct Solver; +struct Beams; -inline void AssembleSystemResidual(const Solver& solver, const Beams& beams) { - auto region = Kokkos::Profiling::ScopedRegion("Assemble System Residual"); - - const auto num_rows = solver.num_system_dofs; - - Kokkos::deep_copy(Kokkos::subview(solver.R, Kokkos::make_pair(size_t{0U}, num_rows)), 0.); - auto vector_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); - Kokkos::parallel_for( - "ContributeElementsToVector", vector_policy, - ContributeElementsToVector{ - beams.num_nodes_per_element, beams.node_state_indices, beams.residual_vector_terms, - solver.R} - ); -} +void AssembleSystemResidual(const Solver& solver, const Beams& beams); } // namespace openturbine diff --git a/src/step/assemble_tangent_operator.cpp b/src/step/assemble_tangent_operator.cpp new file mode 100644 index 00000000..9260581c --- /dev/null +++ b/src/step/assemble_tangent_operator.cpp @@ -0,0 +1,29 @@ +#include +#include + +#include "src/solver/copy_tangent_to_sparse_matrix.hpp" +#include "src/solver/solver.hpp" +#include "src/state/state.hpp" +#include "src/system/calculate_tangent_operator.hpp" + +namespace openturbine { + +void AssembleTangentOperator(const Solver& solver, const State& state) { + auto region = Kokkos::Profiling::ScopedRegion("Assemble Tangent Operator"); + + const auto num_rows = solver.num_system_dofs; + + const auto max_row_entries = 6U; + const auto row_data_size = Kokkos::View::shmem_size(max_row_entries); + const auto col_idx_size = Kokkos::View::shmem_size(max_row_entries); + auto sparse_matrix_policy = Kokkos::TeamPolicy<>(static_cast(num_rows), Kokkos::AUTO()); + + sparse_matrix_policy.set_scratch_size(1, Kokkos::PerTeam(row_data_size + col_idx_size)); + + Kokkos::parallel_for( + "CopyTangentIntoSparseMatrix", sparse_matrix_policy, + CopyTangentToSparseMatrix{solver.T, state.tangent} + ); +} + +} // namespace openturbine diff --git a/src/step/assemble_tangent_operator.hpp b/src/step/assemble_tangent_operator.hpp index 146af3ba..66cb2046 100644 --- a/src/step/assemble_tangent_operator.hpp +++ b/src/step/assemble_tangent_operator.hpp @@ -1,31 +1,9 @@ #pragma once -#include -#include - -#include "src/solver/copy_tangent_to_sparse_matrix.hpp" -#include "src/solver/solver.hpp" -#include "src/state/state.hpp" -#include "src/system/calculate_tangent_operator.hpp" - namespace openturbine { +struct Solver; +struct State; -inline void AssembleTangentOperator(const Solver& solver, const State& state) { - auto region = Kokkos::Profiling::ScopedRegion("Assemble Tangent Operator"); - - const auto num_rows = solver.num_system_dofs; - - const auto max_row_entries = 6U; - const auto row_data_size = Kokkos::View::shmem_size(max_row_entries); - const auto col_idx_size = Kokkos::View::shmem_size(max_row_entries); - auto sparse_matrix_policy = Kokkos::TeamPolicy<>(static_cast(num_rows), Kokkos::AUTO()); - - sparse_matrix_policy.set_scratch_size(1, Kokkos::PerTeam(row_data_size + col_idx_size)); - - Kokkos::parallel_for( - "CopyTangentIntoSparseMatrix", sparse_matrix_policy, - CopyTangentToSparseMatrix{solver.T, state.tangent} - ); -} +void AssembleTangentOperator(const Solver& solver, const State& state); } // namespace openturbine diff --git a/src/step/calculate_convergence_error.cpp b/src/step/calculate_convergence_error.cpp new file mode 100644 index 00000000..b9abc998 --- /dev/null +++ b/src/step/calculate_convergence_error.cpp @@ -0,0 +1,28 @@ +#include +#include + +#include "src/solver/calculate_error_sum_squares.hpp" +#include "src/solver/solver.hpp" +#include "src/state/state.hpp" + +namespace openturbine { + +double CalculateConvergenceError(const Solver& solver, const State& state) { + auto region = Kokkos::Profiling::ScopedRegion("Calculate Convergence Error"); + const double atol = 1e-7; + const double rtol = 1e-5; + double sum_error_squared = 0.; + Kokkos::parallel_reduce( + solver.num_system_dofs, + CalculateErrorSumSquares{ + atol, + rtol, + state.q_delta, + solver.x, + }, + sum_error_squared + ); + return std::sqrt(sum_error_squared / static_cast(solver.num_system_dofs)); +} + +} // namespace openturbine diff --git a/src/step/calculate_convergence_error.hpp b/src/step/calculate_convergence_error.hpp index 5d422e0c..7df1bed7 100644 --- a/src/step/calculate_convergence_error.hpp +++ b/src/step/calculate_convergence_error.hpp @@ -1,30 +1,9 @@ #pragma once -#include -#include - -#include "src/solver/calculate_error_sum_squares.hpp" -#include "src/solver/solver.hpp" -#include "src/state/state.hpp" - namespace openturbine { +struct Solver; +struct State; -inline double CalculateConvergenceError(const Solver& solver, const State& state) { - auto region = Kokkos::Profiling::ScopedRegion("Calculate Convergence Error"); - const double atol = 1e-7; - const double rtol = 1e-5; - double sum_error_squared = 0.; - Kokkos::parallel_reduce( - solver.num_system_dofs, - CalculateErrorSumSquares{ - atol, - rtol, - state.q_delta, - solver.x, - }, - sum_error_squared - ); - return std::sqrt(sum_error_squared / static_cast(solver.num_system_dofs)); -} +double CalculateConvergenceError(const Solver& solver, const State& state); } // namespace openturbine diff --git a/src/step/post_step_clean_up.cpp b/src/step/post_step_clean_up.cpp new file mode 100644 index 00000000..ec1b63f6 --- /dev/null +++ b/src/step/post_step_clean_up.cpp @@ -0,0 +1,47 @@ +#include "step_parameters.hpp" + +#include "src/beams/beams.hpp" +#include "src/constraints/calculate_constraint_output.hpp" +#include "src/constraints/constraints.hpp" +#include "src/solver/solver.hpp" +#include "src/state/state.hpp" +#include "src/state/update_algorithmic_acceleration.hpp" +#include "src/state/update_global_position.hpp" + +namespace openturbine { + +void PostStepCleanUp(const StepParameters& parameters, const Solver& solver, const State& state, const Constraints& constraints) { + Kokkos::parallel_for( + "UpdateAlgorithmicAcceleration", solver.num_system_nodes, + UpdateAlgorithmicAcceleration{ + state.a, + state.vd, + parameters.alpha_f, + parameters.alpha_m, + } + ); + + Kokkos::parallel_for( + "UpdateGlobalPosition", solver.num_system_nodes, + UpdateGlobalPosition{ + state.q, + state.x0, + state.x, + } + ); + + Kokkos::parallel_for( + "CalculateConstraintOutput", constraints.num, + CalculateConstraintOutput{ + constraints.type, + constraints.target_node_index, + constraints.axes, + state.x0, + state.q, + state.v, + state.vd, + constraints.output, + } + ); +} +} diff --git a/src/step/post_step_clean_up.hpp b/src/step/post_step_clean_up.hpp index d3cd92fd..20f22fe9 100644 --- a/src/step/post_step_clean_up.hpp +++ b/src/step/post_step_clean_up.hpp @@ -1,49 +1,11 @@ #pragma once -#include "step_parameters.hpp" - -#include "src/beams/beams.hpp" -#include "src/constraints/calculate_constraint_output.hpp" -#include "src/constraints/constraints.hpp" -#include "src/solver/solver.hpp" -#include "src/state/state.hpp" -#include "src/state/update_algorithmic_acceleration.hpp" -#include "src/state/update_global_position.hpp" - namespace openturbine { -inline void PostStepCleanUp(const StepParameters& parameters, const Solver& solver, const State& state, const Constraints& constraints) { - Kokkos::parallel_for( - "UpdateAlgorithmicAcceleration", solver.num_system_nodes, - UpdateAlgorithmicAcceleration{ - state.a, - state.vd, - parameters.alpha_f, - parameters.alpha_m, - } - ); +struct StepParameters; +struct Solver; +struct State; +struct Constraints; - Kokkos::parallel_for( - "UpdateGlobalPosition", solver.num_system_nodes, - UpdateGlobalPosition{ - state.q, - state.x0, - state.x, - } - ); - - Kokkos::parallel_for( - "CalculateConstraintOutput", constraints.num, - CalculateConstraintOutput{ - constraints.type, - constraints.target_node_index, - constraints.axes, - state.x0, - state.q, - state.v, - state.vd, - constraints.output, - } - ); -} +void PostStepCleanUp(const StepParameters& parameters, const Solver& solver, const State& state, const Constraints& constraints); } diff --git a/src/step/predict_next_state.cpp b/src/step/predict_next_state.cpp new file mode 100644 index 00000000..2dfc7e3b --- /dev/null +++ b/src/step/predict_next_state.cpp @@ -0,0 +1,43 @@ +#include +#include + +#include "step_parameters.hpp" + +#include "src/solver/solver.hpp" +#include "src/state/calculate_displacement.hpp" +#include "src/state/calculate_next_state.hpp" +#include "src/state/state.hpp" + +namespace openturbine { + +void PredictNextState(const StepParameters& parameters, const State& state) { + auto region = Kokkos::Profiling::ScopedRegion("Predict Next State"); + Kokkos::deep_copy(state.q_prev, state.q); + + Kokkos::parallel_for( + "CalculateNextState", state.v.extent(0), + CalculateNextState{ + parameters.h, + parameters.alpha_f, + parameters.alpha_m, + parameters.beta, + parameters.gamma, + state.q_delta, + state.v, + state.vd, + state.a, + } + ); + + Kokkos::parallel_for( + "CalculateDisplacement", state.q.extent(0), + CalculateDisplacement{ + parameters.h, + state.q_delta, + state.q_prev, + state.q, + } + ); +} + +} // namespace openturbine diff --git a/src/step/predict_next_state.hpp b/src/step/predict_next_state.hpp index 689f80d7..29bb5ede 100644 --- a/src/step/predict_next_state.hpp +++ b/src/step/predict_next_state.hpp @@ -1,45 +1,9 @@ #pragma once -#include -#include - -#include "step_parameters.hpp" - -#include "src/solver/solver.hpp" -#include "src/state/calculate_displacement.hpp" -#include "src/state/calculate_next_state.hpp" -#include "src/state/state.hpp" - namespace openturbine { +struct StepParameters; +struct State; -inline void PredictNextState(const StepParameters& parameters, const State& state) { - auto region = Kokkos::Profiling::ScopedRegion("Predict Next State"); - Kokkos::deep_copy(state.q_prev, state.q); - - Kokkos::parallel_for( - "CalculateNextState", state.v.extent(0), - CalculateNextState{ - parameters.h, - parameters.alpha_f, - parameters.alpha_m, - parameters.beta, - parameters.gamma, - state.q_delta, - state.v, - state.vd, - state.a, - } - ); - - Kokkos::parallel_for( - "CalculateDisplacement", state.q.extent(0), - CalculateDisplacement{ - parameters.h, - state.q_delta, - state.q_prev, - state.q, - } - ); -} +void PredictNextState(const StepParameters& parameters, const State& state); } // namespace openturbine diff --git a/src/step/reset_constraints.cpp b/src/step/reset_constraints.cpp new file mode 100644 index 00000000..a9434707 --- /dev/null +++ b/src/step/reset_constraints.cpp @@ -0,0 +1,11 @@ +#include + +#include "src/constraints/constraints.hpp" + +namespace openturbine { + +void ResetConstraints(const Constraints& constraints) { + Kokkos::deep_copy(constraints.lambda, 0.); +} + +} // namespace openturbine diff --git a/src/step/reset_constraints.hpp b/src/step/reset_constraints.hpp index 43258b07..ea78e803 100644 --- a/src/step/reset_constraints.hpp +++ b/src/step/reset_constraints.hpp @@ -1,13 +1,8 @@ #pragma once -#include - -#include "src/constraints/constraints.hpp" - namespace openturbine { +struct Constraints; -inline void ResetConstraints(const Constraints& constraints) { - Kokkos::deep_copy(constraints.lambda, 0.); -} +void ResetConstraints(const Constraints& constraints); } // namespace openturbine diff --git a/src/step/solve_system.cpp b/src/step/solve_system.cpp new file mode 100644 index 00000000..a35386f0 --- /dev/null +++ b/src/step/solve_system.cpp @@ -0,0 +1,62 @@ +#include +#include + +#include "step_parameters.hpp" + +#include "src/solver/condition_system.hpp" +#include "src/solver/solver.hpp" + +namespace openturbine { + +void SolveSystem(const StepParameters& parameters, Solver& solver) { + auto region = Kokkos::Profiling::ScopedRegion("Solve System"); + + { + auto assemble_region = Kokkos::Profiling::ScopedRegion("Assemble Full System"); + KokkosSparse::spadd_numeric( + &solver.spc_spadd_handle, parameters.conditioner, solver.system_matrix_full, 1., + solver.constraints_matrix_full, solver.system_plus_constraints + ); + KokkosSparse::spadd_numeric( + &solver.full_system_spadd_handle, 1., solver.system_plus_constraints, 1., + solver.transpose_matrix_full, solver.full_matrix + ); + } + + Kokkos::parallel_for( + "ConditionR", solver.num_system_dofs, + ConditionR{ + solver.R, + parameters.conditioner, + } + ); + + KokkosBlas::axpby( + -1.0, solver.R, 0.0, + Kokkos::subview(solver.b->getLocalViewDevice(Tpetra::Access::OverwriteAll), Kokkos::ALL(), 0) + ); + + Kokkos::deep_copy(solver.A->getLocalMatrixDevice().values, solver.full_matrix.values); + + { + auto solve_region = Kokkos::Profiling::ScopedRegion("Linear Solve"); + solver.amesos_solver->numericFactorization(); + solver.amesos_solver->solve(); + } + + Kokkos::deep_copy( + solver.x, + Kokkos::subview(solver.x_mv->getLocalViewDevice(Tpetra::Access::ReadOnly), Kokkos::ALL(), 0) + ); + + Kokkos::parallel_for( + "UnconditionSolution", solver.num_dofs, + UnconditionSolution{ + solver.num_system_dofs, + parameters.conditioner, + solver.x, + } + ); +} + +} // namespace openturbine diff --git a/src/step/solve_system.hpp b/src/step/solve_system.hpp index 36296bf4..8479cf10 100644 --- a/src/step/solve_system.hpp +++ b/src/step/solve_system.hpp @@ -1,64 +1,8 @@ #pragma once -#include -#include - -#include "step_parameters.hpp" - -#include "src/solver/condition_system.hpp" -#include "src/solver/solver.hpp" - namespace openturbine { +struct StepParameters; +struct Solver; -inline void SolveSystem(const StepParameters& parameters, Solver& solver) { - auto region = Kokkos::Profiling::ScopedRegion("Solve System"); - - { - auto assemble_region = Kokkos::Profiling::ScopedRegion("Assemble Full System"); - KokkosSparse::spadd_numeric( - &solver.spc_spadd_handle, parameters.conditioner, solver.system_matrix_full, 1., - solver.constraints_matrix_full, solver.system_plus_constraints - ); - KokkosSparse::spadd_numeric( - &solver.full_system_spadd_handle, 1., solver.system_plus_constraints, 1., - solver.transpose_matrix_full, solver.full_matrix - ); - } - - Kokkos::parallel_for( - "ConditionR", solver.num_system_dofs, - ConditionR{ - solver.R, - parameters.conditioner, - } - ); - - KokkosBlas::axpby( - -1.0, solver.R, 0.0, - Kokkos::subview(solver.b->getLocalViewDevice(Tpetra::Access::OverwriteAll), Kokkos::ALL(), 0) - ); - - Kokkos::deep_copy(solver.A->getLocalMatrixDevice().values, solver.full_matrix.values); - - { - auto solve_region = Kokkos::Profiling::ScopedRegion("Linear Solve"); - solver.amesos_solver->numericFactorization(); - solver.amesos_solver->solve(); - } - - Kokkos::deep_copy( - solver.x, - Kokkos::subview(solver.x_mv->getLocalViewDevice(Tpetra::Access::ReadOnly), Kokkos::ALL(), 0) - ); - - Kokkos::parallel_for( - "UnconditionSolution", solver.num_dofs, - UnconditionSolution{ - solver.num_system_dofs, - parameters.conditioner, - solver.x, - } - ); -} - +void SolveSystem(const StepParameters& parameters, Solver& solver); } // namespace openturbine diff --git a/src/step/step.cpp b/src/step/step.cpp index 60b06bce..2c61075c 100644 --- a/src/step/step.cpp +++ b/src/step/step.cpp @@ -19,10 +19,7 @@ #include "update_system_variables.hpp" #include "update_tangent_operator.hpp" -#include "src/beams/beams.hpp" -#include "src/constraints/constraints.hpp" #include "src/solver/solver.hpp" -#include "src/state/state.hpp" namespace openturbine { diff --git a/src/step/step_parameters.hpp b/src/step/step_parameters.hpp index c47a3f7a..a710774c 100644 --- a/src/step/step_parameters.hpp +++ b/src/step/step_parameters.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace openturbine { struct StepParameters { diff --git a/src/step/update_constraint_prediction.cpp b/src/step/update_constraint_prediction.cpp new file mode 100644 index 00000000..22118341 --- /dev/null +++ b/src/step/update_constraint_prediction.cpp @@ -0,0 +1,26 @@ +#include +#include + +#include "src/constraints/constraints.hpp" +#include "src/constraints/update_lambda_prediction.hpp" +#include "src/solver/solver.hpp" + +namespace openturbine { + +void UpdateConstraintPrediction(const Solver& solver, const Constraints& constraints) { + auto region = Kokkos::Profiling::ScopedRegion("Update Constraint Prediction"); + const auto x_lambda = + Kokkos::subview(solver.x, Kokkos::make_pair(solver.num_system_dofs, solver.num_dofs)); + + if (constraints.num > 0) { + Kokkos::parallel_for( + "UpdateLambdaPrediction", constraints.num_dofs, + UpdateLambdaPrediction{ + x_lambda, + constraints.lambda, + } + ); + } +} + +} // namespace openturbine diff --git a/src/step/update_constraint_prediction.hpp b/src/step/update_constraint_prediction.hpp index 5f1890e3..8d4b2f13 100644 --- a/src/step/update_constraint_prediction.hpp +++ b/src/step/update_constraint_prediction.hpp @@ -1,28 +1,8 @@ #pragma once -#include -#include - -#include "src/constraints/constraints.hpp" -#include "src/constraints/update_lambda_prediction.hpp" -#include "src/solver/solver.hpp" - namespace openturbine { +struct Solver; +struct Constraints; -inline void UpdateConstraintPrediction(const Solver& solver, const Constraints& constraints) { - auto region = Kokkos::Profiling::ScopedRegion("Update Constraint Prediction"); - const auto x_lambda = - Kokkos::subview(solver.x, Kokkos::make_pair(solver.num_system_dofs, solver.num_dofs)); - - if (constraints.num > 0) { - Kokkos::parallel_for( - "UpdateLambdaPrediction", constraints.num_dofs, - UpdateLambdaPrediction{ - x_lambda, - constraints.lambda, - } - ); - } -} - +void UpdateConstraintPrediction(const Solver& solver, const Constraints& constraints); } // namespace openturbine diff --git a/src/step/update_constraint_variables.cpp b/src/step/update_constraint_variables.cpp new file mode 100644 index 00000000..5b6d9908 --- /dev/null +++ b/src/step/update_constraint_variables.cpp @@ -0,0 +1,36 @@ +#include +#include + +#include "src/constraints/calculate_constraint_force.hpp" +#include "src/constraints/calculate_constraint_residual_gradient.hpp" +#include "src/constraints/constraints.hpp" +#include "src/state/state.hpp" + +namespace openturbine { + +void UpdateConstraintVariables(const State& state, Constraints& constraints) { + auto region = Kokkos::Profiling::ScopedRegion("Update Constraint Variables"); + + if (constraints.num == 0) { + return; + } + + constraints.UpdateViews(); + + Kokkos::parallel_for( + "CalculateConstraintForce", constraints.num, + CalculateConstraintForce{ + constraints.type, constraints.target_node_index, constraints.axes, constraints.input, + state.q, constraints.system_residual_terms} + ); + + Kokkos::parallel_for( + "CalculateConstraintResidualGradient", constraints.num, + CalculateConstraintResidualGradient{ + constraints.type, constraints.base_node_index, constraints.target_node_index, + constraints.X0, constraints.axes, constraints.input, state.q, constraints.residual_terms, + constraints.base_gradient_terms, constraints.target_gradient_terms} + ); +} + +} // namespace openturbine diff --git a/src/step/update_constraint_variables.hpp b/src/step/update_constraint_variables.hpp index b4468392..e8833b81 100644 --- a/src/step/update_constraint_variables.hpp +++ b/src/step/update_constraint_variables.hpp @@ -1,38 +1,9 @@ #pragma once -#include -#include - -#include "src/constraints/calculate_constraint_force.hpp" -#include "src/constraints/calculate_constraint_residual_gradient.hpp" -#include "src/constraints/constraints.hpp" -#include "src/state/state.hpp" - namespace openturbine { +struct State; +struct Constraints; -inline void UpdateConstraintVariables(const State& state, Constraints& constraints) { - auto region = Kokkos::Profiling::ScopedRegion("Update Constraint Variables"); - - if (constraints.num == 0) { - return; - } - - constraints.UpdateViews(); - - Kokkos::parallel_for( - "CalculateConstraintForce", constraints.num, - CalculateConstraintForce{ - constraints.type, constraints.target_node_index, constraints.axes, constraints.input, - state.q, constraints.system_residual_terms} - ); - - Kokkos::parallel_for( - "CalculateConstraintResidualGradient", constraints.num, - CalculateConstraintResidualGradient{ - constraints.type, constraints.base_node_index, constraints.target_node_index, - constraints.X0, constraints.axes, constraints.input, state.q, constraints.residual_terms, - constraints.base_gradient_terms, constraints.target_gradient_terms} - ); -} +void UpdateConstraintVariables(const State& state, Constraints& constraints); } // namespace openturbine diff --git a/src/step/update_state_prediction.cpp b/src/step/update_state_prediction.cpp new file mode 100644 index 00000000..31be7f5b --- /dev/null +++ b/src/step/update_state_prediction.cpp @@ -0,0 +1,55 @@ +#include +#include + +#include "step_parameters.hpp" + +#include "src/solver/solver.hpp" +#include "src/state/calculate_displacement.hpp" +#include "src/state/state.hpp" +#include "src/state/update_dynamic_prediction.hpp" +#include "src/state/update_static_prediction.hpp" + +namespace openturbine { + +void UpdateStatePrediction(const StepParameters& parameters, const Solver& solver, const State& state) { + auto region = Kokkos::Profiling::ScopedRegion("Update State Prediction"); + const auto x_system = + Kokkos::subview(solver.x, Kokkos::make_pair(size_t{0U}, solver.num_system_dofs)); + if (parameters.is_dynamic_solve) { + Kokkos::parallel_for( + "UpdateDynamicPrediction", solver.num_system_nodes, + UpdateDynamicPrediction{ + parameters.h, + parameters.beta_prime, + parameters.gamma_prime, + x_system, + state.q_delta, + state.v, + state.vd, + } + ); + } else { + Kokkos::parallel_for( + "UpdateStaticPrediction", solver.num_system_nodes, + UpdateStaticPrediction{ + parameters.h, + parameters.beta_prime, + parameters.gamma_prime, + x_system, + state.q_delta, + } + ); + } + + Kokkos::parallel_for( + "CalculateDisplacement", solver.num_system_nodes, + CalculateDisplacement{ + parameters.h, + state.q_delta, + state.q_prev, + state.q, + } + ); +} + +} // namespace openturbine diff --git a/src/step/update_state_prediction.hpp b/src/step/update_state_prediction.hpp index e548fa1f..ceee082d 100644 --- a/src/step/update_state_prediction.hpp +++ b/src/step/update_state_prediction.hpp @@ -1,57 +1,10 @@ #pragma once -#include -#include - -#include "step_parameters.hpp" - -#include "src/solver/solver.hpp" -#include "src/state/calculate_displacement.hpp" -#include "src/state/state.hpp" -#include "src/state/update_dynamic_prediction.hpp" -#include "src/state/update_static_prediction.hpp" - namespace openturbine { +struct StepParameters; +struct Solver; +struct State; -inline void UpdateStatePrediction(const StepParameters& parameters, const Solver& solver, const State& state) { - auto region = Kokkos::Profiling::ScopedRegion("Update State Prediction"); - const auto x_system = - Kokkos::subview(solver.x, Kokkos::make_pair(size_t{0U}, solver.num_system_dofs)); - if (parameters.is_dynamic_solve) { - Kokkos::parallel_for( - "UpdateDynamicPrediction", solver.num_system_nodes, - UpdateDynamicPrediction{ - parameters.h, - parameters.beta_prime, - parameters.gamma_prime, - x_system, - state.q_delta, - state.v, - state.vd, - } - ); - } else { - Kokkos::parallel_for( - "UpdateStaticPrediction", solver.num_system_nodes, - UpdateStaticPrediction{ - parameters.h, - parameters.beta_prime, - parameters.gamma_prime, - x_system, - state.q_delta, - } - ); - } - - Kokkos::parallel_for( - "CalculateDisplacement", solver.num_system_nodes, - CalculateDisplacement{ - parameters.h, - state.q_delta, - state.q_prev, - state.q, - } - ); -} +void UpdateStatePrediction(const StepParameters& parameters, const Solver& solver, const State& state); } // namespace openturbine diff --git a/src/step/update_system_variables.cpp b/src/step/update_system_variables.cpp new file mode 100644 index 00000000..d700b251 --- /dev/null +++ b/src/step/update_system_variables.cpp @@ -0,0 +1,88 @@ +#include +#include + +#include "assemble_inertia_matrix.hpp" +#include "assemble_residual_vector.hpp" +#include "assemble_stiffness_matrix.hpp" +#include "step_parameters.hpp" + +#include "src/beams/beams.hpp" +#include "src/beams/interpolate_to_quadrature_points.hpp" +#include "src/state/state.hpp" +#include "src/system/calculate_quadrature_point_values.hpp" +#include "src/system/update_node_state.hpp" + +namespace openturbine { + +void UpdateSystemVariables(const StepParameters& parameters, const Beams& beams, const State& state) { + auto region = Kokkos::Profiling::ScopedRegion("Update System Variables"); + auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); + Kokkos::parallel_for( + "UpdateNodeState", range_policy, + UpdateNodeState{ + beams.num_nodes_per_element, + beams.node_state_indices, + beams.node_u, + beams.node_u_dot, + beams.node_u_ddot, + state.q, + state.v, + state.vd, + } + ); + + Kokkos::parallel_for( + "InterpolateToQuadraturePoints", range_policy, + InterpolateToQuadraturePoints{ + beams.num_nodes_per_element, beams.num_qps_per_element, beams.shape_interp, + beams.shape_deriv, beams.qp_jacobian, beams.node_u, beams.node_u_dot, beams.node_u_ddot, + beams.qp_x0, beams.qp_r0, beams.qp_u, beams.qp_u_prime, beams.qp_r, beams.qp_r_prime, + beams.qp_u_dot, beams.qp_omega, beams.qp_u_ddot, beams.qp_omega_dot, beams.qp_x} + ); + + Kokkos::parallel_for( + "CalculateQuadraturePointValues", range_policy, + CalculateQuadraturePointValues{ + beams.num_qps_per_element, + beams.gravity, + beams.qp_u, + beams.qp_u_prime, + beams.qp_r, + beams.qp_r_prime, + beams.qp_r0, + beams.qp_x0, + beams.qp_x0_prime, + beams.qp_u_ddot, + beams.qp_omega, + beams.qp_omega_dot, + beams.qp_Mstar, + beams.qp_Cstar, + beams.qp_x, + beams.qp_RR0, + beams.qp_strain, + beams.qp_eta, + beams.qp_rho, + beams.qp_eta_tilde, + beams.qp_x0pupss, + beams.qp_M_tilde, + beams.qp_N_tilde, + beams.qp_omega_tilde, + beams.qp_omega_dot_tilde, + beams.qp_Fc, + beams.qp_Fd, + beams.qp_Fi, + beams.qp_Fg, + beams.qp_Muu, + beams.qp_Cuu, + beams.qp_Ouu, + beams.qp_Puu, + beams.qp_Quu, + beams.qp_Guu, + beams.qp_Kuu} + ); + + AssembleResidualVector(beams); + AssembleStiffnessMatrix(beams); + AssembleInertiaMatrix(beams, parameters.beta_prime, parameters.gamma_prime); +} +} diff --git a/src/step/update_system_variables.hpp b/src/step/update_system_variables.hpp index ce8bd17b..6ba218b8 100644 --- a/src/step/update_system_variables.hpp +++ b/src/step/update_system_variables.hpp @@ -1,91 +1,10 @@ #pragma once -#include -#include - -#include "assemble_inertia_matrix.hpp" -#include "assemble_residual_vector.hpp" -#include "assemble_stiffness_matrix.hpp" -#include "step_parameters.hpp" - -#include "src/beams/beams.hpp" -#include "src/beams/interpolate_to_quadrature_points.hpp" -#include "src/state/state.hpp" -#include "src/system/calculate_quadrature_point_values.hpp" -#include "src/system/update_node_state.hpp" - namespace openturbine { +struct StepParameters; +struct Beams; +struct State; -inline void UpdateSystemVariables(const StepParameters& parameters, const Beams& beams, const State& state) { - auto region = Kokkos::Profiling::ScopedRegion("Update System Variables"); - auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); - Kokkos::parallel_for( - "UpdateNodeState", range_policy, - UpdateNodeState{ - beams.num_nodes_per_element, - beams.node_state_indices, - beams.node_u, - beams.node_u_dot, - beams.node_u_ddot, - state.q, - state.v, - state.vd, - } - ); - - Kokkos::parallel_for( - "InterpolateToQuadraturePoints", range_policy, - InterpolateToQuadraturePoints{ - beams.num_nodes_per_element, beams.num_qps_per_element, beams.shape_interp, - beams.shape_deriv, beams.qp_jacobian, beams.node_u, beams.node_u_dot, beams.node_u_ddot, - beams.qp_x0, beams.qp_r0, beams.qp_u, beams.qp_u_prime, beams.qp_r, beams.qp_r_prime, - beams.qp_u_dot, beams.qp_omega, beams.qp_u_ddot, beams.qp_omega_dot, beams.qp_x} - ); - - Kokkos::parallel_for( - "CalculateQuadraturePointValues", range_policy, - CalculateQuadraturePointValues{ - beams.num_qps_per_element, - beams.gravity, - beams.qp_u, - beams.qp_u_prime, - beams.qp_r, - beams.qp_r_prime, - beams.qp_r0, - beams.qp_x0, - beams.qp_x0_prime, - beams.qp_u_ddot, - beams.qp_omega, - beams.qp_omega_dot, - beams.qp_Mstar, - beams.qp_Cstar, - beams.qp_x, - beams.qp_RR0, - beams.qp_strain, - beams.qp_eta, - beams.qp_rho, - beams.qp_eta_tilde, - beams.qp_x0pupss, - beams.qp_M_tilde, - beams.qp_N_tilde, - beams.qp_omega_tilde, - beams.qp_omega_dot_tilde, - beams.qp_Fc, - beams.qp_Fd, - beams.qp_Fi, - beams.qp_Fg, - beams.qp_Muu, - beams.qp_Cuu, - beams.qp_Ouu, - beams.qp_Puu, - beams.qp_Quu, - beams.qp_Guu, - beams.qp_Kuu} - ); - - AssembleResidualVector(beams); - AssembleStiffnessMatrix(beams); - AssembleInertiaMatrix(beams, parameters.beta_prime, parameters.gamma_prime); -} +void UpdateSystemVariables(const StepParameters& parameters, const Beams& beams, const State& state); } // namespace openturbine diff --git a/src/step/update_tangent_operator.cpp b/src/step/update_tangent_operator.cpp new file mode 100644 index 00000000..41583c0b --- /dev/null +++ b/src/step/update_tangent_operator.cpp @@ -0,0 +1,23 @@ +#include +#include + +#include "step_parameters.hpp" + +#include "src/state/state.hpp" +#include "src/system/calculate_tangent_operator.hpp" + +namespace openturbine { + +void UpdateTangentOperator(const StepParameters& parameters, const State& state) { + auto region = Kokkos::Profiling::ScopedRegion("Update Tangent Operator"); + Kokkos::parallel_for( + "CalculateTangentOperator", state.num_system_nodes, + CalculateTangentOperator{ + parameters.h, + state.q_delta, + state.tangent, + } + ); +} + +} // namespace openturbine diff --git a/src/step/update_tangent_operator.hpp b/src/step/update_tangent_operator.hpp index 61b715ec..f4e1a49b 100644 --- a/src/step/update_tangent_operator.hpp +++ b/src/step/update_tangent_operator.hpp @@ -1,25 +1,9 @@ #pragma once -#include -#include - -#include "step_parameters.hpp" - -#include "src/state/state.hpp" -#include "src/system/calculate_tangent_operator.hpp" - namespace openturbine { +struct StepParameters; +struct State; -inline void UpdateTangentOperator(const StepParameters& parameters, const State& state) { - auto region = Kokkos::Profiling::ScopedRegion("Update Tangent Operator"); - Kokkos::parallel_for( - "CalculateTangentOperator", state.num_system_nodes, - CalculateTangentOperator{ - parameters.h, - state.q_delta, - state.tangent, - } - ); -} +void UpdateTangentOperator(const StepParameters& parameters, const State& state); } // namespace openturbine diff --git a/tests/unit_tests/regression/test_beams.cpp b/tests/unit_tests/regression/test_beams.cpp index 1ecede0c..179c1a9d 100644 --- a/tests/unit_tests/regression/test_beams.cpp +++ b/tests/unit_tests/regression/test_beams.cpp @@ -12,6 +12,8 @@ #include "src/beams/create_beams.hpp" #include "src/model/model.hpp" #include "src/state/state.hpp" +#include "src/constraints/constraints.hpp" +#include "src/step/step_parameters.hpp" #include "src/step/assemble_residual_vector.hpp" #include "src/step/update_system_variables.hpp" #include "src/types.hpp" diff --git a/tests/unit_tests/regression/test_solver.cpp b/tests/unit_tests/regression/test_solver.cpp index cbab1f6a..c774c9ee 100644 --- a/tests/unit_tests/regression/test_solver.cpp +++ b/tests/unit_tests/regression/test_solver.cpp @@ -10,6 +10,7 @@ #include "src/beams/beams.hpp" #include "src/beams/beams_input.hpp" #include "src/beams/create_beams.hpp" +#include "src/constraints/constraints.hpp" #include "src/model/model.hpp" #include "src/solver/solver.hpp" #include "src/state/state.hpp" From 9296c20e64009f5e814a309081cce1d5f8936aea Mon Sep 17 00:00:00 2001 From: dcdemen Date: Wed, 25 Sep 2024 13:25:03 -0600 Subject: [PATCH 5/8] clang-format --- src/constraints/constraints.hpp | 2 +- src/step/assemble_residual_vector.hpp | 2 +- src/step/post_step_clean_up.cpp | 7 +++++-- src/step/post_step_clean_up.hpp | 7 +++++-- src/step/step.cpp | 5 +++-- src/step/step.hpp | 3 ++- src/step/update_state_prediction.cpp | 4 +++- src/step/update_state_prediction.hpp | 4 +++- src/step/update_system_variables.cpp | 6 ++++-- tests/unit_tests/regression/test_beams.cpp | 4 ++-- tests/unit_tests/regression/test_cantilever_beam.cpp | 2 +- tests/unit_tests/regression/test_rotating_beam.cpp | 4 ++-- tests/unit_tests/regression/test_rotor.cpp | 2 +- tests/unit_tests/regression/test_solver.cpp | 2 +- 14 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/constraints/constraints.hpp b/src/constraints/constraints.hpp index 16e1c6da..2cd16878 100644 --- a/src/constraints/constraints.hpp +++ b/src/constraints/constraints.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include #include +#include #include diff --git a/src/step/assemble_residual_vector.hpp b/src/step/assemble_residual_vector.hpp index 46307ba3..b747308b 100644 --- a/src/step/assemble_residual_vector.hpp +++ b/src/step/assemble_residual_vector.hpp @@ -3,6 +3,6 @@ namespace openturbine { struct Beams; -void AssembleResidualVector(const Beams& beams); +void AssembleResidualVector(const Beams& beams); } // namespace openturbine diff --git a/src/step/post_step_clean_up.cpp b/src/step/post_step_clean_up.cpp index ec1b63f6..c626124c 100644 --- a/src/step/post_step_clean_up.cpp +++ b/src/step/post_step_clean_up.cpp @@ -10,7 +10,10 @@ namespace openturbine { -void PostStepCleanUp(const StepParameters& parameters, const Solver& solver, const State& state, const Constraints& constraints) { +void PostStepCleanUp( + const StepParameters& parameters, const Solver& solver, const State& state, + const Constraints& constraints +) { Kokkos::parallel_for( "UpdateAlgorithmicAcceleration", solver.num_system_nodes, UpdateAlgorithmicAcceleration{ @@ -44,4 +47,4 @@ void PostStepCleanUp(const StepParameters& parameters, const Solver& solver, con } ); } -} +} // namespace openturbine diff --git a/src/step/post_step_clean_up.hpp b/src/step/post_step_clean_up.hpp index 20f22fe9..bce3f471 100644 --- a/src/step/post_step_clean_up.hpp +++ b/src/step/post_step_clean_up.hpp @@ -7,5 +7,8 @@ struct Solver; struct State; struct Constraints; -void PostStepCleanUp(const StepParameters& parameters, const Solver& solver, const State& state, const Constraints& constraints); -} +void PostStepCleanUp( + const StepParameters& parameters, const Solver& solver, const State& state, + const Constraints& constraints +); +} // namespace openturbine diff --git a/src/step/step.cpp b/src/step/step.cpp index 2c61075c..0581c9f5 100644 --- a/src/step/step.cpp +++ b/src/step/step.cpp @@ -24,7 +24,8 @@ namespace openturbine { bool Step( - const StepParameters& parameters, Solver& solver, const Beams& beams, const State& state, Constraints& constraints + const StepParameters& parameters, Solver& solver, const Beams& beams, const State& state, + Constraints& constraints ) { auto region = Kokkos::Profiling::ScopedRegion("Step"); PredictNextState(parameters, state); @@ -71,4 +72,4 @@ bool Step( return true; } -} +} // namespace openturbine diff --git a/src/step/step.hpp b/src/step/step.hpp index 192e26ea..f456843c 100644 --- a/src/step/step.hpp +++ b/src/step/step.hpp @@ -9,7 +9,8 @@ struct State; struct Constraints; bool Step( - const StepParameters& parameters, Solver& solver, const Beams& beams, const State& state, Constraints& constraints + const StepParameters& parameters, Solver& solver, const Beams& beams, const State& state, + Constraints& constraints ); } // namespace openturbine diff --git a/src/step/update_state_prediction.cpp b/src/step/update_state_prediction.cpp index 31be7f5b..d29353ba 100644 --- a/src/step/update_state_prediction.cpp +++ b/src/step/update_state_prediction.cpp @@ -11,7 +11,9 @@ namespace openturbine { -void UpdateStatePrediction(const StepParameters& parameters, const Solver& solver, const State& state) { +void UpdateStatePrediction( + const StepParameters& parameters, const Solver& solver, const State& state +) { auto region = Kokkos::Profiling::ScopedRegion("Update State Prediction"); const auto x_system = Kokkos::subview(solver.x, Kokkos::make_pair(size_t{0U}, solver.num_system_dofs)); diff --git a/src/step/update_state_prediction.hpp b/src/step/update_state_prediction.hpp index ceee082d..500c433f 100644 --- a/src/step/update_state_prediction.hpp +++ b/src/step/update_state_prediction.hpp @@ -5,6 +5,8 @@ struct StepParameters; struct Solver; struct State; -void UpdateStatePrediction(const StepParameters& parameters, const Solver& solver, const State& state); +void UpdateStatePrediction( + const StepParameters& parameters, const Solver& solver, const State& state +); } // namespace openturbine diff --git a/src/step/update_system_variables.cpp b/src/step/update_system_variables.cpp index d700b251..4329a2f7 100644 --- a/src/step/update_system_variables.cpp +++ b/src/step/update_system_variables.cpp @@ -14,7 +14,9 @@ namespace openturbine { -void UpdateSystemVariables(const StepParameters& parameters, const Beams& beams, const State& state) { +void UpdateSystemVariables( + const StepParameters& parameters, const Beams& beams, const State& state +) { auto region = Kokkos::Profiling::ScopedRegion("Update System Variables"); auto range_policy = Kokkos::TeamPolicy<>(static_cast(beams.num_elems), Kokkos::AUTO()); Kokkos::parallel_for( @@ -85,4 +87,4 @@ void UpdateSystemVariables(const StepParameters& parameters, const Beams& beams, AssembleStiffnessMatrix(beams); AssembleInertiaMatrix(beams, parameters.beta_prime, parameters.gamma_prime); } -} +} // namespace openturbine diff --git a/tests/unit_tests/regression/test_beams.cpp b/tests/unit_tests/regression/test_beams.cpp index 179c1a9d..600616a3 100644 --- a/tests/unit_tests/regression/test_beams.cpp +++ b/tests/unit_tests/regression/test_beams.cpp @@ -10,11 +10,11 @@ #include "src/beams/beams.hpp" #include "src/beams/beams_input.hpp" #include "src/beams/create_beams.hpp" +#include "src/constraints/constraints.hpp" #include "src/model/model.hpp" #include "src/state/state.hpp" -#include "src/constraints/constraints.hpp" -#include "src/step/step_parameters.hpp" #include "src/step/assemble_residual_vector.hpp" +#include "src/step/step_parameters.hpp" #include "src/step/update_system_variables.hpp" #include "src/types.hpp" diff --git a/tests/unit_tests/regression/test_cantilever_beam.cpp b/tests/unit_tests/regression/test_cantilever_beam.cpp index fc01edd8..65492514 100644 --- a/tests/unit_tests/regression/test_cantilever_beam.cpp +++ b/tests/unit_tests/regression/test_cantilever_beam.cpp @@ -12,12 +12,12 @@ #include "src/beams/beams.hpp" #include "src/beams/beams_input.hpp" #include "src/beams/create_beams.hpp" +#include "src/constraints/constraints.hpp" #include "src/model/model.hpp" #include "src/solver/solver.hpp" #include "src/state/state.hpp" #include "src/step/step.hpp" #include "src/step/step_parameters.hpp" -#include "src/constraints/constraints.hpp" #include "src/types.hpp" namespace openturbine::tests { diff --git a/tests/unit_tests/regression/test_rotating_beam.cpp b/tests/unit_tests/regression/test_rotating_beam.cpp index 602649cf..d51927fb 100644 --- a/tests/unit_tests/regression/test_rotating_beam.cpp +++ b/tests/unit_tests/regression/test_rotating_beam.cpp @@ -17,12 +17,12 @@ #include "src/beams/beams.hpp" #include "src/beams/beams_input.hpp" #include "src/beams/create_beams.hpp" +#include "src/constraints/constraints.hpp" #include "src/model/model.hpp" #include "src/solver/solver.hpp" #include "src/state/state.hpp" -#include "src/constraints/constraints.hpp" -#include "src/step/step_parameters.hpp" #include "src/step/step.hpp" +#include "src/step/step_parameters.hpp" #include "src/types.hpp" using Array_7 = std::array; diff --git a/tests/unit_tests/regression/test_rotor.cpp b/tests/unit_tests/regression/test_rotor.cpp index fbd55494..608ec898 100644 --- a/tests/unit_tests/regression/test_rotor.cpp +++ b/tests/unit_tests/regression/test_rotor.cpp @@ -14,12 +14,12 @@ #include "src/beams/beams.hpp" #include "src/beams/beams_input.hpp" #include "src/beams/create_beams.hpp" +#include "src/constraints/constraints.hpp" #include "src/model/model.hpp" #include "src/solver/solver.hpp" #include "src/state/state.hpp" #include "src/step/step.hpp" #include "src/step/step_parameters.hpp" -#include "src/constraints/constraints.hpp" #include "src/types.hpp" #include "src/utilities/controllers/discon.hpp" #include "src/utilities/controllers/turbine_controller.hpp" diff --git a/tests/unit_tests/regression/test_solver.cpp b/tests/unit_tests/regression/test_solver.cpp index c774c9ee..0cc81a78 100644 --- a/tests/unit_tests/regression/test_solver.cpp +++ b/tests/unit_tests/regression/test_solver.cpp @@ -21,8 +21,8 @@ #include "src/step/predict_next_state.hpp" #include "src/step/step.hpp" #include "src/step/step_parameters.hpp" -#include "src/step/update_system_variables.hpp" #include "src/step/update_constraint_variables.hpp" +#include "src/step/update_system_variables.hpp" #include "src/types.hpp" namespace openturbine::tests { From 74435ba5497e71a1e0d122f44670ad4fec4d97c9 Mon Sep 17 00:00:00 2001 From: dcdemen Date: Wed, 25 Sep 2024 13:47:08 -0600 Subject: [PATCH 6/8] Fix CI failures on MacOS --- tests/unit_tests/regression/test_rotating_beam.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_tests/regression/test_rotating_beam.cpp b/tests/unit_tests/regression/test_rotating_beam.cpp index d51927fb..8ff2d260 100644 --- a/tests/unit_tests/regression/test_rotating_beam.cpp +++ b/tests/unit_tests/regression/test_rotating_beam.cpp @@ -23,6 +23,7 @@ #include "src/state/state.hpp" #include "src/step/step.hpp" #include "src/step/step_parameters.hpp" +#include "src/step/update_system_variables.hpp" #include "src/types.hpp" using Array_7 = std::array; From e7b844dd0a5457624daddd7761b692301d1eab30 Mon Sep 17 00:00:00 2001 From: dcdemen Date: Tue, 15 Oct 2024 15:12:30 -0600 Subject: [PATCH 7/8] Added an initial "global include" file for user covenience. We can add more lines to this file depending on how people end up interfacing with the code, but this is a good starting point. --- src/openturbine.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/openturbine.hpp diff --git a/src/openturbine.hpp b/src/openturbine.hpp new file mode 100644 index 00000000..73504864 --- /dev/null +++ b/src/openturbine.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "types.hpp" +#include "beams/beams.hpp" +#include "constraints/constraints.hpp" +#include "solver/solver.hpp" +#include "state/state.hpp" +#include "step/step.hpp" +#include "step/step_parameters.hpp" From 4fb6d8fd49c480bcaf9646eab8d0f3cd18edb802 Mon Sep 17 00:00:00 2001 From: dcdemen Date: Tue, 15 Oct 2024 15:36:10 -0600 Subject: [PATCH 8/8] clang-format --- src/openturbine.hpp | 2 +- src/step/assemble_constraints_matrix.cpp | 3 ++- src/step/assemble_constraints_residual.cpp | 6 ++++-- src/step/assemble_inertia_matrix.cpp | 3 ++- src/step/assemble_residual_vector.cpp | 3 ++- src/step/assemble_system_matrix.cpp | 3 ++- src/step/assemble_system_residual.cpp | 3 ++- src/step/update_constraint_variables.cpp | 6 ++++-- src/step/update_system_variables.cpp | 6 ++++-- 9 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/openturbine.hpp b/src/openturbine.hpp index 73504864..e5479045 100644 --- a/src/openturbine.hpp +++ b/src/openturbine.hpp @@ -1,9 +1,9 @@ #pragma once -#include "types.hpp" #include "beams/beams.hpp" #include "constraints/constraints.hpp" #include "solver/solver.hpp" #include "state/state.hpp" #include "step/step.hpp" #include "step/step_parameters.hpp" +#include "types.hpp" diff --git a/src/step/assemble_constraints_matrix.cpp b/src/step/assemble_constraints_matrix.cpp index b1ebde0e..1e13dd96 100644 --- a/src/step/assemble_constraints_matrix.cpp +++ b/src/step/assemble_constraints_matrix.cpp @@ -24,7 +24,8 @@ void AssembleConstraintsMatrix(Solver& solver, const Constraints& constraints) { CopyConstraintsToSparseMatrix{ constraints.row_range, constraints.base_node_col_range, constraints.target_node_col_range, solver.B, constraints.base_gradient_terms, - constraints.target_gradient_terms} + constraints.target_gradient_terms + } ); } diff --git a/src/step/assemble_constraints_residual.cpp b/src/step/assemble_constraints_residual.cpp index 5dd578ea..54b5f71d 100644 --- a/src/step/assemble_constraints_residual.cpp +++ b/src/step/assemble_constraints_residual.cpp @@ -18,7 +18,8 @@ void AssembleConstraintsResidual(const Solver& solver, const Constraints& constr Kokkos::parallel_for( "ContributeConstraintsSystemResidualToVector", constraints.num, ContributeConstraintsSystemResidualToVector{ - constraints.target_node_index, solver.R, constraints.system_residual_terms} + constraints.target_node_index, solver.R, constraints.system_residual_terms + } ); auto R = Solver::ValuesType( @@ -42,7 +43,8 @@ void AssembleConstraintsResidual(const Solver& solver, const Constraints& constr CopyConstraintsResidualToVector{ constraints.row_range, Kokkos::subview(solver.R, Kokkos::make_pair(solver.num_system_dofs, solver.num_dofs)), - constraints.residual_terms} + constraints.residual_terms + } ); } diff --git a/src/step/assemble_inertia_matrix.cpp b/src/step/assemble_inertia_matrix.cpp index 06d61d77..0a353541 100644 --- a/src/step/assemble_inertia_matrix.cpp +++ b/src/step/assemble_inertia_matrix.cpp @@ -18,7 +18,8 @@ void AssembleInertiaMatrix(const Beams& beams, double beta_prime, double gamma_p IntegrateInertiaMatrix{ beams.num_nodes_per_element, beams.num_qps_per_element, beams.qp_weight, beams.qp_jacobian, beams.shape_interp, beams.qp_Muu, beams.qp_Guu, beta_prime, - gamma_prime, beams.inertia_matrix_terms} + gamma_prime, beams.inertia_matrix_terms + } ); } diff --git a/src/step/assemble_residual_vector.cpp b/src/step/assemble_residual_vector.cpp index f1364a8f..01af88d4 100644 --- a/src/step/assemble_residual_vector.cpp +++ b/src/step/assemble_residual_vector.cpp @@ -23,7 +23,8 @@ void AssembleResidualVector(const Beams& beams) { IntegrateResidualVector{ beams.num_nodes_per_element, beams.num_qps_per_element, beams.qp_weight, beams.qp_jacobian, beams.shape_interp, beams.shape_deriv, beams.node_FX, beams.qp_Fc, - beams.qp_Fd, beams.qp_Fi, beams.qp_Fe, beams.qp_Fg, beams.residual_vector_terms} + beams.qp_Fd, beams.qp_Fi, beams.qp_Fe, beams.qp_Fg, beams.residual_vector_terms + } ); } diff --git a/src/step/assemble_system_matrix.cpp b/src/step/assemble_system_matrix.cpp index f33846d2..c7608845 100644 --- a/src/step/assemble_system_matrix.cpp +++ b/src/step/assemble_system_matrix.cpp @@ -30,7 +30,8 @@ void AssembleSystemMatrix(Solver& solver, const Beams& beams) { Kokkos::parallel_for( "ContributeElementsToSparseMatrix", sparse_matrix_policy, ContributeElementsToSparseMatrix{ - solver.K, beams.stiffness_matrix_terms} + solver.K, beams.stiffness_matrix_terms + } ); Kokkos::fence(); diff --git a/src/step/assemble_system_residual.cpp b/src/step/assemble_system_residual.cpp index 2aa4391e..f4687445 100644 --- a/src/step/assemble_system_residual.cpp +++ b/src/step/assemble_system_residual.cpp @@ -18,7 +18,8 @@ void AssembleSystemResidual(const Solver& solver, const Beams& beams) { "ContributeElementsToVector", vector_policy, ContributeElementsToVector{ beams.num_nodes_per_element, beams.node_state_indices, beams.residual_vector_terms, - solver.R} + solver.R + } ); } diff --git a/src/step/update_constraint_variables.cpp b/src/step/update_constraint_variables.cpp index 5b6d9908..35b062a8 100644 --- a/src/step/update_constraint_variables.cpp +++ b/src/step/update_constraint_variables.cpp @@ -21,7 +21,8 @@ void UpdateConstraintVariables(const State& state, Constraints& constraints) { "CalculateConstraintForce", constraints.num, CalculateConstraintForce{ constraints.type, constraints.target_node_index, constraints.axes, constraints.input, - state.q, constraints.system_residual_terms} + state.q, constraints.system_residual_terms + } ); Kokkos::parallel_for( @@ -29,7 +30,8 @@ void UpdateConstraintVariables(const State& state, Constraints& constraints) { CalculateConstraintResidualGradient{ constraints.type, constraints.base_node_index, constraints.target_node_index, constraints.X0, constraints.axes, constraints.input, state.q, constraints.residual_terms, - constraints.base_gradient_terms, constraints.target_gradient_terms} + constraints.base_gradient_terms, constraints.target_gradient_terms + } ); } diff --git a/src/step/update_system_variables.cpp b/src/step/update_system_variables.cpp index 5953fd52..975bd750 100644 --- a/src/step/update_system_variables.cpp +++ b/src/step/update_system_variables.cpp @@ -39,7 +39,8 @@ void UpdateSystemVariables( beams.num_nodes_per_element, beams.num_qps_per_element, beams.shape_interp, beams.shape_deriv, beams.qp_jacobian, beams.node_u, beams.node_u_dot, beams.node_u_ddot, beams.qp_x0, beams.qp_r0, beams.qp_u, beams.qp_u_prime, beams.qp_r, beams.qp_r_prime, - beams.qp_u_dot, beams.qp_omega, beams.qp_u_ddot, beams.qp_omega_dot, beams.qp_x} + beams.qp_u_dot, beams.qp_omega, beams.qp_u_ddot, beams.qp_omega_dot, beams.qp_x + } ); Kokkos::parallel_for( @@ -81,7 +82,8 @@ void UpdateSystemVariables( beams.qp_Puu, beams.qp_Quu, beams.qp_Guu, - beams.qp_Kuu} + beams.qp_Kuu + } ); AssembleResidualVector(beams);