From c8bfaa5ca5680b317f30ce7c128b978af59042e6 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Wed, 22 Oct 2025 10:11:18 +0200 Subject: [PATCH 01/10] minor cleanup Signed-off-by: Santiago Figueroa Manrique --- .../include/power_grid_model/main_model_impl.hpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp index 6599f69c8..ccbe46dc6 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp @@ -57,6 +57,7 @@ template <> struct output_type_getter> { using type = meta_data::asym_output_getter_s; }; +// down struct power_flow_t {}; struct state_estimation_t {}; struct short_circuit_t {}; @@ -115,14 +116,13 @@ decltype(auto) calculation_type_symmetry_func_selector(CalculationType calculati }, calculation_symmetry, std::forward(f), std::forward(args)...); } - +// up template requires(main_core::is_main_model_type_v) class MainModelImpl { private: // internal type traits - using ComponentContainer = typename ModelType::ComponentContainer; using MainModelState = typename ModelType::MainModelState; using SequenceIdx = typename ModelType::SequenceIdx; @@ -131,10 +131,6 @@ class MainModelImpl { using OwnedUpdateDataset = typename ModelType::OwnedUpdateDataset; using ComponentFlags = typename ModelType::ComponentFlags; - static constexpr Idx isolated_component{main_core::isolated_component}; - static constexpr Idx not_connected{main_core::not_connected}; - static constexpr Idx sequential{main_core::utils::sequential}; - public: using ImplType = ModelType; using Options = MainModelOptions; From ff6b631e80ec2cf987dec0ea1e1da288baf50f9f Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Wed, 22 Oct 2025 17:17:29 +0200 Subject: [PATCH 02/10] reset solvers moved out Signed-off-by: Santiago Figueroa Manrique --- .../power_grid_model/main_model_impl.hpp | 33 ++++++------ .../power_grid_model/prepare_solvers.hpp | 50 +++++++++++++++++++ 2 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp index ccbe46dc6..021bf458c 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp @@ -11,6 +11,7 @@ #include "calculation_parameters.hpp" #include "container.hpp" #include "main_model_fwd.hpp" +#include "prepare_solvers.hpp" #include "topology.hpp" // common @@ -57,7 +58,7 @@ template <> struct output_type_getter> { using type = meta_data::asym_output_getter_s; }; -// down +//////////////// down struct power_flow_t {}; struct state_estimation_t {}; struct short_circuit_t {}; @@ -116,7 +117,8 @@ decltype(auto) calculation_type_symmetry_func_selector(CalculationType calculati }, calculation_symmetry, std::forward(f), std::forward(args)...); } -// up +//////////////// up + template requires(main_core::is_main_model_type_v) class MainModelImpl { @@ -262,18 +264,6 @@ class MainModelImpl { std::make_shared(main_core::construct_topology(state_.components)); } - void reset_solvers() { - assert(construction_complete_); - is_topology_up_to_date_ = false; - is_sym_parameter_up_to_date_ = false; - is_asym_parameter_up_to_date_ = false; - n_math_solvers_ = 0; - main_core::clear(math_state_); - state_.math_topology.clear(); - state_.topo_comp_coup.reset(); - state_.comp_coup = {}; - } - public: /* the the sequence indexer given an input array of ID's for a given component type @@ -345,6 +335,7 @@ class MainModelImpl { }); } + //////////////// down template requires std::invocable, Idx /*n_math_solvers*/> && @@ -484,6 +475,7 @@ class MainModelImpl { }, *this, options, result_data, logger); } + //////////////// up public: static auto calculator(Options const& options, MainModelImpl& model, MutableDataset const& target_data, @@ -569,7 +561,18 @@ class MainModelImpl { void rebuild_topology() { assert(construction_complete_); // clear old solvers - reset_solvers(); + SolverPreparationContext solver_preparation_context{ + .state = state_, + .math_state = math_state_, + .n_math_solvers = n_math_solvers_, + .is_topology_up_to_date = is_topology_up_to_date_, + .is_sym_parameter_up_to_date = is_sym_parameter_up_to_date_, + .is_asym_parameter_up_to_date = is_asym_parameter_up_to_date_, + .last_updated_calculation_symmetry_mode = last_updated_calculation_symmetry_mode_, + .parameter_changed_components = parameter_changed_components_, + .math_solver_dispatcher = *math_solver_dispatcher_}; + detail::reset_solvers(solver_preparation_context); + ComponentConnections const comp_conn = main_core::construct_components_connections(state_.components); // re build diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp new file mode 100644 index 000000000..ebe1ffaf7 --- /dev/null +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: Contributors to the Power Grid Model project +// +// SPDX-License-Identifier: MPL-2.0 + +#pragma once + +#include "common/common.hpp" + +#include "math_solver/math_solver_dispatch.hpp" + +#include "main_core/main_model_type.hpp" +#include "main_core/math_state.hpp" + +namespace power_grid_model { +template + requires(main_core::is_main_model_type_v) +struct SolverPreparationContext { + typename ModelType::MainModelState& state; + main_core::MathState& math_state; + Idx& n_math_solvers; + bool& is_topology_up_to_date; + bool& is_sym_parameter_up_to_date; + bool& is_asym_parameter_up_to_date; + bool& last_updated_calculation_symmetry_mode; + typename ModelType::SequenceIdx& parameter_changed_components; + MathSolverDispatcher const& math_solver_dispatcher; + + template bool& is_parameter_up_to_date() { + if constexpr (is_symmetric_v) { + return is_sym_parameter_up_to_date; + } else { + return is_asym_parameter_up_to_date; + } + } +}; + +namespace detail { +template void reset_solvers(SolverPreparationContext& context) { + // assert(construction_complete_); + context.is_topology_up_to_date = false; + context.is_sym_parameter_up_to_date = false; + context.is_asym_parameter_up_to_date = false; + context.n_math_solvers = 0; + main_core::clear(context.math_state); + context.state.math_topology.clear(); + context.state.topo_comp_coup.reset(); + context.state.comp_coup = {}; +} +} // namespace detail +} // namespace power_grid_model From 5d985b7cc843379428b8346965cd0c82723a0095 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Wed, 22 Oct 2025 17:37:22 +0200 Subject: [PATCH 03/10] moved out rebuild_topology Signed-off-by: Santiago Figueroa Manrique --- .../power_grid_model/main_model_impl.hpp | 38 ++++++------------- .../power_grid_model/prepare_solvers.hpp | 18 +++++++++ 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp index 021bf458c..2a2000447 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp @@ -558,37 +558,21 @@ class MainModelImpl { } } - void rebuild_topology() { - assert(construction_complete_); - // clear old solvers - SolverPreparationContext solver_preparation_context{ - .state = state_, - .math_state = math_state_, - .n_math_solvers = n_math_solvers_, - .is_topology_up_to_date = is_topology_up_to_date_, - .is_sym_parameter_up_to_date = is_sym_parameter_up_to_date_, - .is_asym_parameter_up_to_date = is_asym_parameter_up_to_date_, - .last_updated_calculation_symmetry_mode = last_updated_calculation_symmetry_mode_, - .parameter_changed_components = parameter_changed_components_, - .math_solver_dispatcher = *math_solver_dispatcher_}; - detail::reset_solvers(solver_preparation_context); - - ComponentConnections const comp_conn = - main_core::construct_components_connections(state_.components); - // re build - Topology topology{*state_.comp_topo, comp_conn}; - std::tie(state_.math_topology, state_.topo_comp_coup) = topology.build_topology(); - n_math_solvers_ = static_cast(state_.math_topology.size()); - is_topology_up_to_date_ = true; - is_sym_parameter_up_to_date_ = false; - is_asym_parameter_up_to_date_ = false; - } - template void prepare_solvers() { std::vector>& solvers = main_core::get_solvers(math_state_); // rebuild topology if needed if (!is_topology_up_to_date_) { - rebuild_topology(); + SolverPreparationContext solver_preparation_context{ + .state = state_, + .math_state = math_state_, + .n_math_solvers = n_math_solvers_, + .is_topology_up_to_date = is_topology_up_to_date_, + .is_sym_parameter_up_to_date = is_sym_parameter_up_to_date_, + .is_asym_parameter_up_to_date = is_asym_parameter_up_to_date_, + .last_updated_calculation_symmetry_mode = last_updated_calculation_symmetry_mode_, + .parameter_changed_components = parameter_changed_components_, + .math_solver_dispatcher = *math_solver_dispatcher_}; + detail::rebuild_topology(solver_preparation_context); } main_core::prepare_y_bus(state_, n_math_solvers_, math_state_); diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp index ebe1ffaf7..ae6846962 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp @@ -4,12 +4,15 @@ #pragma once +#include "topology.hpp" + #include "common/common.hpp" #include "math_solver/math_solver_dispatch.hpp" #include "main_core/main_model_type.hpp" #include "main_core/math_state.hpp" +#include "main_core/topology.hpp" namespace power_grid_model { template @@ -46,5 +49,20 @@ template void reset_solvers(SolverPreparationContext void rebuild_topology(SolverPreparationContext& context) { + // assert(construction_complete_); + // clear old solvers + reset_solvers(context); + ComponentConnections const comp_conn = + main_core::construct_components_connections(context.state.components); + // re build + Topology topology{*context.state.comp_topo, comp_conn}; + std::tie(context.state.math_topology, context.state.topo_comp_coup) = topology.build_topology(); + context.n_math_solvers = static_cast(context.state.math_topology.size()); + context.is_topology_up_to_date = true; + context.is_sym_parameter_up_to_date = false; + context.is_asym_parameter_up_to_date = false; +} } // namespace detail } // namespace power_grid_model From 0ef04c655e4841d90dbe2d2ee57e1b3a9377c449 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Fri, 24 Oct 2025 08:49:39 +0200 Subject: [PATCH 04/10] migration done Signed-off-by: Santiago Figueroa Manrique --- .../calculation_input_preparation.hpp | 1 - .../power_grid_model/main_core/y_bus.hpp | 1 + .../power_grid_model/main_model_impl.hpp | 122 +++++------------- .../power_grid_model/prepare_solvers.hpp | 68 ---------- 4 files changed, 35 insertions(+), 157 deletions(-) delete mode 100644 power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/calculation_input_preparation.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/calculation_input_preparation.hpp index f752f20e5..acadf9e14 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/calculation_input_preparation.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/calculation_input_preparation.hpp @@ -12,7 +12,6 @@ #include namespace power_grid_model::main_core { -constexpr Idx isolated_component{-1}; constexpr Idx not_connected{-1}; namespace detail { diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/y_bus.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/y_bus.hpp index 9f6a8b0cb..183abcfd9 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/y_bus.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/y_bus.hpp @@ -7,6 +7,7 @@ #include "../common/common.hpp" namespace power_grid_model::main_core { +constexpr Idx isolated_component{-1}; namespace detail { template ComponentType, typename ComponentContainer> diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp index 2a2000447..9d6f309d8 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp @@ -11,7 +11,7 @@ #include "calculation_parameters.hpp" #include "container.hpp" #include "main_model_fwd.hpp" -#include "prepare_solvers.hpp" +#include "prepare_calculate.hpp" #include "topology.hpp" // common @@ -41,6 +41,7 @@ #include "main_core/y_bus.hpp" // stl library +#include #include #include @@ -58,7 +59,6 @@ template <> struct output_type_getter> { using type = meta_data::asym_output_getter_s; }; -//////////////// down struct power_flow_t {}; struct state_estimation_t {}; struct short_circuit_t {}; @@ -117,7 +117,6 @@ decltype(auto) calculation_type_symmetry_func_selector(CalculationType calculati }, calculation_symmetry, std::forward(f), std::forward(args)...); } -//////////////// up template requires(main_core::is_main_model_type_v) @@ -144,7 +143,7 @@ class MainModelImpl { MathSolverDispatcher const& math_solver_dispatcher, Idx pos = 0) : system_frequency_{system_frequency}, meta_data_{&input_data.meta_data()}, - math_solver_dispatcher_{&math_solver_dispatcher} { + solver_preparation_context_{.math_solver_dispatcher = &math_solver_dispatcher} { assert(input_data.get_description().dataset->name == std::string_view("input")); add_components(input_data, pos); set_construction_complete(); @@ -155,7 +154,7 @@ class MainModelImpl { MathSolverDispatcher const& math_solver_dispatcher) : system_frequency_{system_frequency}, meta_data_{&meta_data}, - math_solver_dispatcher_{&math_solver_dispatcher} {} + solver_preparation_context_{.math_solver_dispatcher = &math_solver_dispatcher} {} // helper function to get what components are present in the update data ComponentFlags get_components_to_update(ConstDataset const& update_data) const { @@ -204,7 +203,7 @@ class MainModelImpl { UpdateChange const changed = main_core::update::update_component( state_.components, std::forward(updates), - std::back_inserter(std::get(parameter_changed_components_)), sequence_idx); + std::back_inserter(std::get(state_status_context_.parameter_changed_components)), sequence_idx); // update, get changed variable update_state(changed); @@ -293,9 +292,11 @@ class MainModelImpl { void update_state(UpdateChange const& changes) { // if topology changed, everything is not up to date // if only param changed, set param to not up to date - is_topology_up_to_date_ = is_topology_up_to_date_ && !changes.topo; - is_sym_parameter_up_to_date_ = is_sym_parameter_up_to_date_ && !changes.topo && !changes.param; - is_asym_parameter_up_to_date_ = is_asym_parameter_up_to_date_ && !changes.topo && !changes.param; + state_status_context_.is_topology_up_to_date = state_status_context_.is_topology_up_to_date && !changes.topo; + state_status_context_.is_parameter_up_to_date.sym = + state_status_context_.is_parameter_up_to_date.sym && !changes.topo && !changes.param; + state_status_context_.is_parameter_up_to_date.asym = + state_status_context_.is_parameter_up_to_date.asym && !changes.topo && !changes.param; } template void restore_component(SequenceIdxView const& sequence_idx) { @@ -335,7 +336,6 @@ class MainModelImpl { }); } - //////////////// down template requires std::invocable, Idx /*n_math_solvers*/> && @@ -350,18 +350,19 @@ class MainModelImpl { // prepare auto const& input = [this, &logger, prepare_input_ = std::forward(prepare_input)] { Timer const timer{logger, LogEvent::prepare}; - prepare_solvers(); - assert(is_topology_up_to_date_ && is_parameter_up_to_date()); - return prepare_input_(n_math_solvers_); + prepare_solvers(state_, solver_preparation_context_, state_status_context_); + assert((state_status_context_.is_topology_up_to_date && + is_parameter_up_to_date(state_status_context_.is_parameter_up_to_date))); + return prepare_input_(solver_preparation_context_.n_math_solvers); }(); // calculate return [this, &logger, &input, solve_ = std::forward(solve)] { Timer const timer{logger, LogEvent::math_calculation}; - auto& solvers = main_core::get_solvers(math_state_); - auto& y_bus_vec = main_core::get_y_bus(math_state_); + auto& solvers = main_core::get_solvers(solver_preparation_context_.math_state); + auto& y_bus_vec = main_core::get_y_bus(solver_preparation_context_.math_state); std::vector solver_output; - solver_output.reserve(n_math_solvers_); - for (Idx i = 0; i != n_math_solvers_; ++i) { + solver_output.reserve(solver_preparation_context_.n_math_solvers); + for (Idx i = 0; i != solver_preparation_context_.n_math_solvers; ++i) { solver_output.emplace_back(solve_(solvers[i], y_bus_vec[i], input[i])); } return solver_output; @@ -411,7 +412,8 @@ class MainModelImpl { return calculate_, MathSolverProxy, YBus, ShortCircuitInput>( [this, voltage_scaling](Idx n_math_solvers) { - assert(is_topology_up_to_date_ && is_parameter_up_to_date()); + assert((state_status_context_.is_topology_up_to_date && + is_parameter_up_to_date(state_status_context_.is_parameter_up_to_date))); return main_core::prepare_short_circuit_input(state_, state_.comp_coup, n_math_solvers, voltage_scaling); }, @@ -475,7 +477,6 @@ class MainModelImpl { }, *this, options, result_data, logger); } - //////////////// up public: static auto calculator(Options const& options, MainModelImpl& model, MutableDataset const& target_data, @@ -530,84 +531,29 @@ class MainModelImpl { double system_frequency_; MetaData const* meta_data_; - MathSolverDispatcher const* math_solver_dispatcher_; MainModelState state_; - // math model - MathState math_state_; - Idx n_math_solvers_{0}; - bool is_topology_up_to_date_{false}; - bool is_sym_parameter_up_to_date_{false}; - bool is_asym_parameter_up_to_date_{false}; - bool is_accumulated_component_updated_{true}; - bool last_updated_calculation_symmetry_mode_{false}; + + SolverPreparationContext solver_preparation_context_; + // math_state + // n_math_solvers + // math_solver_dispatcher + + StatusCheckingContext state_status_context_{}; + // is_topology_up_to_date + // is_sym_parameter_up_to_date + // is_asym_parameter_up_to_date + // last_updated_calculation_symmetry_mode + // parameter_changed_components + + bool is_accumulated_component_updated_{true}; // may be deleted OwnedUpdateDataset cached_inverse_update_{}; UpdateChange cached_state_changes_{}; - SequenceIdx parameter_changed_components_{}; #ifndef NDEBUG // construction_complete is used for debug assertions only bool construction_complete_{false}; #endif // !NDEBUG - - template bool& is_parameter_up_to_date() { - if constexpr (is_symmetric_v) { - return is_sym_parameter_up_to_date_; - } else { - return is_asym_parameter_up_to_date_; - } - } - - template void prepare_solvers() { - std::vector>& solvers = main_core::get_solvers(math_state_); - // rebuild topology if needed - if (!is_topology_up_to_date_) { - SolverPreparationContext solver_preparation_context{ - .state = state_, - .math_state = math_state_, - .n_math_solvers = n_math_solvers_, - .is_topology_up_to_date = is_topology_up_to_date_, - .is_sym_parameter_up_to_date = is_sym_parameter_up_to_date_, - .is_asym_parameter_up_to_date = is_asym_parameter_up_to_date_, - .last_updated_calculation_symmetry_mode = last_updated_calculation_symmetry_mode_, - .parameter_changed_components = parameter_changed_components_, - .math_solver_dispatcher = *math_solver_dispatcher_}; - detail::rebuild_topology(solver_preparation_context); - } - main_core::prepare_y_bus(state_, n_math_solvers_, math_state_); - - if (n_math_solvers_ != static_cast(solvers.size())) { - assert(solvers.empty()); - assert(n_math_solvers_ == static_cast(state_.math_topology.size())); - assert(n_math_solvers_ == static_cast(main_core::get_y_bus(math_state_).size())); - - solvers.clear(); - solvers.reserve(n_math_solvers_); - std::ranges::transform(state_.math_topology, std::back_inserter(solvers), [this](auto const& math_topo) { - return MathSolverProxy{math_solver_dispatcher_, math_topo}; - }); - for (Idx idx = 0; idx < n_math_solvers_; ++idx) { - main_core::get_y_bus(math_state_)[idx].register_parameters_changed_callback( - [solver = std::ref(solvers[idx])](bool changed) { - solver.get().get().parameters_changed(changed); - }); - } - } else if (!is_parameter_up_to_date()) { - std::vector> const math_params = - main_core::get_math_param(state_, n_math_solvers_); - std::vector const math_param_increments = - main_core::get_math_param_increment(state_, n_math_solvers_, parameter_changed_components_); - if (last_updated_calculation_symmetry_mode_ == is_symmetric_v) { - main_core::update_y_bus(math_state_, math_params, math_param_increments); - } else { - main_core::update_y_bus(math_state_, math_params); - } - } - // else do nothing, set everything up to date - is_parameter_up_to_date() = true; - std::ranges::for_each(parameter_changed_components_, [](auto& comps) { comps.clear(); }); - last_updated_calculation_symmetry_mode_ = is_symmetric_v; - } }; } // namespace power_grid_model diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp deleted file mode 100644 index ae6846962..000000000 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_solvers.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-FileCopyrightText: Contributors to the Power Grid Model project -// -// SPDX-License-Identifier: MPL-2.0 - -#pragma once - -#include "topology.hpp" - -#include "common/common.hpp" - -#include "math_solver/math_solver_dispatch.hpp" - -#include "main_core/main_model_type.hpp" -#include "main_core/math_state.hpp" -#include "main_core/topology.hpp" - -namespace power_grid_model { -template - requires(main_core::is_main_model_type_v) -struct SolverPreparationContext { - typename ModelType::MainModelState& state; - main_core::MathState& math_state; - Idx& n_math_solvers; - bool& is_topology_up_to_date; - bool& is_sym_parameter_up_to_date; - bool& is_asym_parameter_up_to_date; - bool& last_updated_calculation_symmetry_mode; - typename ModelType::SequenceIdx& parameter_changed_components; - MathSolverDispatcher const& math_solver_dispatcher; - - template bool& is_parameter_up_to_date() { - if constexpr (is_symmetric_v) { - return is_sym_parameter_up_to_date; - } else { - return is_asym_parameter_up_to_date; - } - } -}; - -namespace detail { -template void reset_solvers(SolverPreparationContext& context) { - // assert(construction_complete_); - context.is_topology_up_to_date = false; - context.is_sym_parameter_up_to_date = false; - context.is_asym_parameter_up_to_date = false; - context.n_math_solvers = 0; - main_core::clear(context.math_state); - context.state.math_topology.clear(); - context.state.topo_comp_coup.reset(); - context.state.comp_coup = {}; -} - -template void rebuild_topology(SolverPreparationContext& context) { - // assert(construction_complete_); - // clear old solvers - reset_solvers(context); - ComponentConnections const comp_conn = - main_core::construct_components_connections(context.state.components); - // re build - Topology topology{*context.state.comp_topo, comp_conn}; - std::tie(context.state.math_topology, context.state.topo_comp_coup) = topology.build_topology(); - context.n_math_solvers = static_cast(context.state.math_topology.size()); - context.is_topology_up_to_date = true; - context.is_sym_parameter_up_to_date = false; - context.is_asym_parameter_up_to_date = false; -} -} // namespace detail -} // namespace power_grid_model From 7ce6e95d3a2c5ed057a47ac56c0e3b905a0d21d0 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Fri, 24 Oct 2025 09:06:37 +0200 Subject: [PATCH 05/10] minor cleanup Signed-off-by: Santiago Figueroa Manrique --- .../include/power_grid_model/main_model_impl.hpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp index 9d6f309d8..ad89a89fd 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp @@ -34,14 +34,11 @@ #include "main_core/calculation_input_preparation.hpp" #include "main_core/input.hpp" #include "main_core/main_model_type.hpp" -#include "main_core/math_state.hpp" #include "main_core/output.hpp" #include "main_core/topology.hpp" #include "main_core/update.hpp" -#include "main_core/y_bus.hpp" // stl library -#include #include #include @@ -135,7 +132,6 @@ class MainModelImpl { public: using ImplType = ModelType; using Options = MainModelOptions; - using MathState = main_core::MathState; using MetaData = meta_data::MetaData; // constructor with data @@ -350,6 +346,7 @@ class MainModelImpl { // prepare auto const& input = [this, &logger, prepare_input_ = std::forward(prepare_input)] { Timer const timer{logger, LogEvent::prepare}; + assert(construction_complete_); prepare_solvers(state_, solver_preparation_context_, state_status_context_); assert((state_status_context_.is_topology_up_to_date && is_parameter_up_to_date(state_status_context_.is_parameter_up_to_date))); @@ -546,8 +543,6 @@ class MainModelImpl { // last_updated_calculation_symmetry_mode // parameter_changed_components - bool is_accumulated_component_updated_{true}; // may be deleted - OwnedUpdateDataset cached_inverse_update_{}; UpdateChange cached_state_changes_{}; #ifndef NDEBUG From a9ae3356e4169e5b731dff45b5611c4a372f63b3 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Fri, 24 Oct 2025 09:15:04 +0200 Subject: [PATCH 06/10] oops, forgot to add the new file Signed-off-by: Santiago Figueroa Manrique --- .../power_grid_model/prepare_calculate.hpp | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp new file mode 100644 index 000000000..e6de51154 --- /dev/null +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp @@ -0,0 +1,120 @@ +// SPDX-FileCopyrightText: Contributors to the Power Grid Model project +// +// SPDX-License-Identifier: MPL-2.0 + +#pragma once + +#include "topology.hpp" + +#include "common/common.hpp" + +#include "math_solver/math_solver_dispatch.hpp" + +#include "main_core/main_model_type.hpp" +#include "main_core/math_state.hpp" +#include "main_core/topology.hpp" +#include "main_core/y_bus.hpp" + +namespace power_grid_model { +struct SolverPreparationContext { + main_core::MathState math_state; + Idx n_math_solvers{0}; + MathSolverDispatcher const* math_solver_dispatcher; +}; + +template + requires(main_core::is_main_model_type_v) +struct StatusCheckingContext { + bool is_topology_up_to_date{false}; + bool last_updated_calculation_symmetry_mode{false}; + typename ModelType::SequenceIdx parameter_changed_components{}; + struct IsParameterUpToDateHelper { + bool sym{false}; + bool asym{false}; + } is_parameter_up_to_date{}; +}; + +namespace detail { +template +void reset_solvers(typename ModelType::MainModelState& state, SolverPreparationContext& solver_context, + StatusCheckingContext& status_context) { + status_context.is_topology_up_to_date = false; + status_context.is_parameter_up_to_date.sym = false; + status_context.is_parameter_up_to_date.asym = false; + solver_context.n_math_solvers = 0; + main_core::clear(solver_context.math_state); + state.math_topology.clear(); + state.topo_comp_coup.reset(); + state.comp_coup = {}; +} + +template +void rebuild_topology(typename ModelType::MainModelState& state, SolverPreparationContext& solver_context, + StatusCheckingContext& status_context) { + // clear old solvers + reset_solvers(state, solver_context, status_context); + ComponentConnections const comp_conn = main_core::construct_components_connections(state.components); + // re build + Topology topology{*state.comp_topo, comp_conn}; + std::tie(state.math_topology, state.topo_comp_coup) = topology.build_topology(); + solver_context.n_math_solvers = static_cast(state.math_topology.size()); + status_context.is_topology_up_to_date = true; + status_context.is_parameter_up_to_date.sym = false; + status_context.is_parameter_up_to_date.asym = false; +} +} // namespace detail + +template +bool& is_parameter_up_to_date( + typename StatusCheckingContext::IsParameterUpToDateHelper& is_parameter_up_to_date) { + if constexpr (is_symmetric_v) { + return is_parameter_up_to_date.sym; + } else { + return is_parameter_up_to_date.asym; + } +} + +template +void prepare_solvers(typename ModelType::MainModelState& state, SolverPreparationContext& solver_context, + StatusCheckingContext& status_context) { + std::vector>& solvers = main_core::get_solvers(solver_context.math_state); + // rebuild topology if needed + if (!status_context.is_topology_up_to_date) { + detail::rebuild_topology(state, solver_context, status_context); + } + main_core::prepare_y_bus(state, solver_context.n_math_solvers, solver_context.math_state); + + if (solver_context.n_math_solvers != static_cast(solvers.size())) { + assert(solvers.empty()); + assert(solver_context.n_math_solvers == static_cast(state.math_topology.size())); + assert(solver_context.n_math_solvers == + static_cast(main_core::get_y_bus(solver_context.math_state).size())); + + solvers.clear(); + solvers.reserve(solver_context.n_math_solvers); + std::ranges::transform(state.math_topology, std::back_inserter(solvers), + [&solver_context](auto const& math_topo) { + return MathSolverProxy{solver_context.math_solver_dispatcher, math_topo}; + }); + for (Idx idx = 0; idx < solver_context.n_math_solvers; ++idx) { + main_core::get_y_bus(solver_context.math_state)[idx].register_parameters_changed_callback( + [solver = std::ref(solvers[idx])](bool changed) { solver.get().get().parameters_changed(changed); }); + } + } else if (!is_parameter_up_to_date(status_context.is_parameter_up_to_date)) { + std::vector> const math_params = + main_core::get_math_param(state, solver_context.n_math_solvers); + std::vector const math_param_increments = + main_core::get_math_param_increment(state, solver_context.n_math_solvers, + status_context.parameter_changed_components); + if (status_context.last_updated_calculation_symmetry_mode == is_symmetric_v) { + main_core::update_y_bus(solver_context.math_state, math_params, math_param_increments); + } else { + main_core::update_y_bus(solver_context.math_state, math_params); + } + } + // else do nothing, set everything up to date + is_parameter_up_to_date(status_context.is_parameter_up_to_date) = true; + std::ranges::for_each(status_context.parameter_changed_components, [](auto& comps) { comps.clear(); }); + status_context.last_updated_calculation_symmetry_mode = is_symmetric_v; +} +} // namespace power_grid_model From 4f0d5898788b196742a060e233b7a29545a01834 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Mon, 27 Oct 2025 17:26:01 +0100 Subject: [PATCH 07/10] address comments part 1 Signed-off-by: Santiago Figueroa Manrique --- .../power_grid_model/main_model_impl.hpp | 19 +++++--------- .../power_grid_model/prepare_calculate.hpp | 26 +++++++++---------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp index ad89a89fd..248c3a638 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp @@ -12,6 +12,7 @@ #include "container.hpp" #include "main_model_fwd.hpp" #include "prepare_calculate.hpp" +#include "prepare_calculate.hpp" // Include the header where n_math_solvers is defined #include "topology.hpp" // common @@ -139,7 +140,7 @@ class MainModelImpl { MathSolverDispatcher const& math_solver_dispatcher, Idx pos = 0) : system_frequency_{system_frequency}, meta_data_{&input_data.meta_data()}, - solver_preparation_context_{.math_solver_dispatcher = &math_solver_dispatcher} { + solver_preparation_context_{.math_state = {}, .math_solver_dispatcher = &math_solver_dispatcher} { assert(input_data.get_description().dataset->name == std::string_view("input")); add_components(input_data, pos); set_construction_complete(); @@ -150,7 +151,7 @@ class MainModelImpl { MathSolverDispatcher const& math_solver_dispatcher) : system_frequency_{system_frequency}, meta_data_{&meta_data}, - solver_preparation_context_{.math_solver_dispatcher = &math_solver_dispatcher} {} + solver_preparation_context_{.math_state = {}, .math_solver_dispatcher = &math_solver_dispatcher} {} // helper function to get what components are present in the update data ComponentFlags get_components_to_update(ConstDataset const& update_data) const { @@ -350,7 +351,7 @@ class MainModelImpl { prepare_solvers(state_, solver_preparation_context_, state_status_context_); assert((state_status_context_.is_topology_up_to_date && is_parameter_up_to_date(state_status_context_.is_parameter_up_to_date))); - return prepare_input_(solver_preparation_context_.n_math_solvers); + return prepare_input_(get_n_math_solvers(state_)); }(); // calculate return [this, &logger, &input, solve_ = std::forward(solve)] { @@ -358,8 +359,8 @@ class MainModelImpl { auto& solvers = main_core::get_solvers(solver_preparation_context_.math_state); auto& y_bus_vec = main_core::get_y_bus(solver_preparation_context_.math_state); std::vector solver_output; - solver_output.reserve(solver_preparation_context_.n_math_solvers); - for (Idx i = 0; i != solver_preparation_context_.n_math_solvers; ++i) { + solver_output.reserve(get_n_math_solvers(state_)); + for (Idx i = 0; i != get_n_math_solvers(state_); ++i) { solver_output.emplace_back(solve_(solvers[i], y_bus_vec[i], input[i])); } return solver_output; @@ -532,16 +533,8 @@ class MainModelImpl { MainModelState state_; SolverPreparationContext solver_preparation_context_; - // math_state - // n_math_solvers - // math_solver_dispatcher StatusCheckingContext state_status_context_{}; - // is_topology_up_to_date - // is_sym_parameter_up_to_date - // is_asym_parameter_up_to_date - // last_updated_calculation_symmetry_mode - // parameter_changed_components OwnedUpdateDataset cached_inverse_update_{}; UpdateChange cached_state_changes_{}; diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp index e6de51154..95ea9c000 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp @@ -18,7 +18,6 @@ namespace power_grid_model { struct SolverPreparationContext { main_core::MathState math_state; - Idx n_math_solvers{0}; MathSolverDispatcher const* math_solver_dispatcher; }; @@ -41,7 +40,6 @@ void reset_solvers(typename ModelType::MainModelState& state, SolverPreparationC status_context.is_topology_up_to_date = false; status_context.is_parameter_up_to_date.sym = false; status_context.is_parameter_up_to_date.asym = false; - solver_context.n_math_solvers = 0; main_core::clear(solver_context.math_state); state.math_topology.clear(); state.topo_comp_coup.reset(); @@ -57,7 +55,6 @@ void rebuild_topology(typename ModelType::MainModelState& state, SolverPreparati // re build Topology topology{*state.comp_topo, comp_conn}; std::tie(state.math_topology, state.topo_comp_coup) = topology.build_topology(); - solver_context.n_math_solvers = static_cast(state.math_topology.size()); status_context.is_topology_up_to_date = true; status_context.is_parameter_up_to_date.sym = false; status_context.is_parameter_up_to_date.asym = false; @@ -74,6 +71,10 @@ bool& is_parameter_up_to_date( } } +template Idx get_n_math_solvers(typename ModelType::MainModelState const& state) { + return static_cast(state.math_topology.size()); +} + template void prepare_solvers(typename ModelType::MainModelState& state, SolverPreparationContext& solver_context, StatusCheckingContext& status_context) { @@ -82,29 +83,26 @@ void prepare_solvers(typename ModelType::MainModelState& state, SolverPreparatio if (!status_context.is_topology_up_to_date) { detail::rebuild_topology(state, solver_context, status_context); } - main_core::prepare_y_bus(state, solver_context.n_math_solvers, solver_context.math_state); - - if (solver_context.n_math_solvers != static_cast(solvers.size())) { + Idx n_math_solvers = get_n_math_solvers(state); + main_core::prepare_y_bus(state, n_math_solvers, solver_context.math_state); + if (n_math_solvers != static_cast(solvers.size())) { assert(solvers.empty()); - assert(solver_context.n_math_solvers == static_cast(state.math_topology.size())); - assert(solver_context.n_math_solvers == - static_cast(main_core::get_y_bus(solver_context.math_state).size())); + assert(n_math_solvers == static_cast(main_core::get_y_bus(solver_context.math_state).size())); solvers.clear(); - solvers.reserve(solver_context.n_math_solvers); + solvers.reserve(n_math_solvers); std::ranges::transform(state.math_topology, std::back_inserter(solvers), [&solver_context](auto const& math_topo) { return MathSolverProxy{solver_context.math_solver_dispatcher, math_topo}; }); - for (Idx idx = 0; idx < solver_context.n_math_solvers; ++idx) { + for (Idx idx = 0; idx < n_math_solvers; ++idx) { main_core::get_y_bus(solver_context.math_state)[idx].register_parameters_changed_callback( [solver = std::ref(solvers[idx])](bool changed) { solver.get().get().parameters_changed(changed); }); } } else if (!is_parameter_up_to_date(status_context.is_parameter_up_to_date)) { - std::vector> const math_params = - main_core::get_math_param(state, solver_context.n_math_solvers); + std::vector> const math_params = main_core::get_math_param(state, n_math_solvers); std::vector const math_param_increments = - main_core::get_math_param_increment(state, solver_context.n_math_solvers, + main_core::get_math_param_increment(state, n_math_solvers, status_context.parameter_changed_components); if (status_context.last_updated_calculation_symmetry_mode == is_symmetric_v) { main_core::update_y_bus(solver_context.math_state, math_params, math_param_increments); From 66e5449fc348e4a39428bf439f603f06677632ed Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Mon, 27 Oct 2025 17:52:07 +0100 Subject: [PATCH 08/10] address comments part 2 Signed-off-by: Santiago Figueroa Manrique --- .../include/power_grid_model/main_model.hpp | 10 ++++++++-- .../include/power_grid_model/main_model_impl.hpp | 9 ++++----- .../include/power_grid_model/prepare_calculate.hpp | 3 ++- tests/cpp_unit_tests/test_main_model_type.cpp | 11 ++++++----- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp index b7cac93a1..64749df29 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp @@ -10,6 +10,8 @@ #include "common/calculation_info.hpp" +#include "prepare_calculate.hpp" + #include namespace power_grid_model { @@ -25,10 +27,14 @@ class MainModel { explicit MainModel(double system_frequency, ConstDataset const& input_data, MathSolverDispatcher const& math_solver_dispatcher, Idx pos = 0) - : impl_{std::make_unique(system_frequency, input_data, math_solver_dispatcher, pos)} {} + : impl_{std::make_unique( + system_frequency, input_data, + SolverPreparationContext{.math_state = {}, .math_solver_dispatcher = &math_solver_dispatcher}, pos)} {} explicit MainModel(double system_frequency, meta_data::MetaData const& meta_data, MathSolverDispatcher const& math_solver_dispatcher) - : impl_{std::make_unique(system_frequency, meta_data, math_solver_dispatcher)} {}; + : impl_{std::make_unique( + system_frequency, meta_data, + SolverPreparationContext{.math_state = {}, .math_solver_dispatcher = &math_solver_dispatcher})} {}; // deep copy MainModel(MainModel const& other) { diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp index 248c3a638..ccfb562e3 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp @@ -12,7 +12,6 @@ #include "container.hpp" #include "main_model_fwd.hpp" #include "prepare_calculate.hpp" -#include "prepare_calculate.hpp" // Include the header where n_math_solvers is defined #include "topology.hpp" // common @@ -137,10 +136,10 @@ class MainModelImpl { // constructor with data explicit MainModelImpl(double system_frequency, ConstDataset const& input_data, - MathSolverDispatcher const& math_solver_dispatcher, Idx pos = 0) + SolverPreparationContext solver_preparation_context, Idx pos = 0) : system_frequency_{system_frequency}, meta_data_{&input_data.meta_data()}, - solver_preparation_context_{.math_state = {}, .math_solver_dispatcher = &math_solver_dispatcher} { + solver_preparation_context_{solver_preparation_context} { assert(input_data.get_description().dataset->name == std::string_view("input")); add_components(input_data, pos); set_construction_complete(); @@ -148,10 +147,10 @@ class MainModelImpl { // constructor with only frequency explicit MainModelImpl(double system_frequency, meta_data::MetaData const& meta_data, - MathSolverDispatcher const& math_solver_dispatcher) + SolverPreparationContext solver_preparation_context) : system_frequency_{system_frequency}, meta_data_{&meta_data}, - solver_preparation_context_{.math_state = {}, .math_solver_dispatcher = &math_solver_dispatcher} {} + solver_preparation_context_{solver_preparation_context} {} // helper function to get what components are present in the update data ComponentFlags get_components_to_update(ConstDataset const& update_data) const { diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp index 95ea9c000..a5985baef 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp @@ -30,7 +30,8 @@ struct StatusCheckingContext { struct IsParameterUpToDateHelper { bool sym{false}; bool asym{false}; - } is_parameter_up_to_date{}; + }; + IsParameterUpToDateHelper is_parameter_up_to_date{}; }; namespace detail { diff --git a/tests/cpp_unit_tests/test_main_model_type.cpp b/tests/cpp_unit_tests/test_main_model_type.cpp index 59533a9b3..26366c44c 100644 --- a/tests/cpp_unit_tests/test_main_model_type.cpp +++ b/tests/cpp_unit_tests/test_main_model_type.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -30,7 +31,7 @@ static_assert(!is_main_model_type_v> static_assert(!is_main_model_type_v>); static_assert(std::constructible_from>, double, - meta_data::MetaData const&, MathSolverDispatcher const&>); + meta_data::MetaData const&, SolverPreparationContext>); static_assert(detail::validate_component_types_c); @@ -57,7 +58,7 @@ TEST_CASE("MainModelType") { static_assert(ModelType::n_types == 2); static_assert(is_main_model_type_v); static_assert(std::constructible_from, double, meta_data::MetaData const&, - MathSolverDispatcher const&>); + SolverPreparationContext>); CHECK(ModelType::run_functor_with_all_component_types_return_array([]() { return std::string_view(CompType::name); @@ -89,7 +90,7 @@ TEST_CASE("MainModelType") { static_assert(ModelType::n_types == 3); static_assert(is_main_model_type_v); static_assert(std::constructible_from, double, meta_data::MetaData const&, - MathSolverDispatcher const&>); + SolverPreparationContext>); CHECK(ModelType::run_functor_with_all_component_types_return_array([]() { return std::string_view(CompType::name); @@ -122,7 +123,7 @@ TEST_CASE("MainModelType") { static_assert(is_main_model_type_v); static_assert(std::constructible_from, double, meta_data::MetaData const&, - MathSolverDispatcher const&>); + SolverPreparationContext>); CHECK(ModelType::run_functor_with_all_component_types_return_array([]() { return std::string_view(CompType::name); @@ -155,7 +156,7 @@ TEST_CASE("MainModelType") { static_assert(ModelType::n_types == 3); static_assert(is_main_model_type_v); static_assert(std::constructible_from, double, meta_data::MetaData const&, - MathSolverDispatcher const&>); + SolverPreparationContext>); CHECK(ModelType::run_functor_with_all_component_types_return_array([]() { return std::string_view(CompType::name); From 7c1cab56315292539edb3d4abb7a879525911a3a Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Tue, 28 Oct 2025 10:54:17 +0100 Subject: [PATCH 09/10] clang tidy Signed-off-by: Santiago Figueroa Manrique --- .../include/power_grid_model/main_model_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp index ccfb562e3..62b95873c 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp @@ -139,7 +139,7 @@ class MainModelImpl { SolverPreparationContext solver_preparation_context, Idx pos = 0) : system_frequency_{system_frequency}, meta_data_{&input_data.meta_data()}, - solver_preparation_context_{solver_preparation_context} { + solver_preparation_context_{std::move(solver_preparation_context)} { assert(input_data.get_description().dataset->name == std::string_view("input")); add_components(input_data, pos); set_construction_complete(); @@ -150,7 +150,7 @@ class MainModelImpl { SolverPreparationContext solver_preparation_context) : system_frequency_{system_frequency}, meta_data_{&meta_data}, - solver_preparation_context_{solver_preparation_context} {} + solver_preparation_context_{std::move(solver_preparation_context)} {} // helper function to get what components are present in the update data ComponentFlags get_components_to_update(ConstDataset const& update_data) const { From cf50d5109def70003b424d1778b3048846614cf7 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Manrique Date: Wed, 29 Oct 2025 09:59:06 +0100 Subject: [PATCH 10/10] clang tidy 2 Signed-off-by: Santiago Figueroa Manrique --- .../include/power_grid_model/prepare_calculate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp index a5985baef..48d8de866 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/prepare_calculate.hpp @@ -84,7 +84,7 @@ void prepare_solvers(typename ModelType::MainModelState& state, SolverPreparatio if (!status_context.is_topology_up_to_date) { detail::rebuild_topology(state, solver_context, status_context); } - Idx n_math_solvers = get_n_math_solvers(state); + Idx const n_math_solvers = get_n_math_solvers(state); main_core::prepare_y_bus(state, n_math_solvers, solver_context.math_state); if (n_math_solvers != static_cast(solvers.size())) { assert(solvers.empty());