Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional ID structural refactor #828

Merged
merged 38 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9810322
Removed hardoded -1s
figueroa1395 Nov 11, 2024
56534a8
Nipick renaming
figueroa1395 Nov 11, 2024
e7e734c
refactor check_components_independence
figueroa1395 Nov 11, 2024
1bc81f6
Merge branch 'feature/refactor-optional-id' into feature/optional-id-…
figueroa1395 Nov 11, 2024
4640a90
make MSVC happy
figueroa1395 Nov 11, 2024
9cdb0d6
minor update_component refactor
figueroa1395 Nov 12, 2024
a118af8
main model utils introduced
figueroa1395 Nov 12, 2024
ba0a0b8
moved check_id_na
figueroa1395 Nov 12, 2024
7688198
moved UpdateCompProperties and process_buffer_span
figueroa1395 Nov 12, 2024
15a62c9
moved check_component_independence
figueroa1395 Nov 12, 2024
e01c16e
Merge branch 'feature/refactor-optional-id' into feature/optional-id-…
figueroa1395 Nov 12, 2024
954e933
clang tidy
figueroa1395 Nov 13, 2024
104c9fe
moved validate_update_independence and corrected namespace name
figueroa1395 Nov 13, 2024
e6fddf2
Merge branch 'feature/refactor-optional-id' into feature/optional-id-…
figueroa1395 Nov 13, 2024
5f94b0c
actually solve merge conflicts
figueroa1395 Nov 13, 2024
c509044
refactored is_update_independent
figueroa1395 Nov 13, 2024
366b424
removed string lookup
figueroa1395 Nov 13, 2024
44b4233
moved get_component_sequence
figueroa1395 Nov 14, 2024
e4bf1a3
move get_sequence_idx_map
figueroa1395 Nov 14, 2024
c4eb684
Fix tests
figueroa1395 Nov 15, 2024
2143cba
fixed bug - finally
figueroa1395 Nov 15, 2024
cc76897
re-organize
figueroa1395 Nov 15, 2024
1a89659
Merge branch 'main' into feature/optional-id-refactor-part2
figueroa1395 Nov 15, 2024
e474644
address comments
figueroa1395 Nov 18, 2024
67929c5
addressed comments
figueroa1395 Nov 18, 2024
5767a9a
Merge branch 'main' into feature/optional-id-refactor-part2
figueroa1395 Nov 18, 2024
f7c64c9
minor
figueroa1395 Nov 19, 2024
297d2d7
rename get_comp_seq in state_queries
figueroa1395 Nov 19, 2024
8cabc92
Merge pull request #836 from PowerGridModel/get_component_sequence-re…
Jerry-Jinfeng-Guo Nov 19, 2024
4022bac
addess comments
figueroa1395 Nov 20, 2024
b6c4f4d
minor
figueroa1395 Nov 20, 2024
acf5c96
address comments
figueroa1395 Nov 21, 2024
979b9f8
address comments
figueroa1395 Nov 22, 2024
f5134f9
Merge branch 'main' into feature/optional-id-refactor-part2
figueroa1395 Nov 22, 2024
2a9bc41
removed redundant usings
figueroa1395 Nov 22, 2024
c56adb2
final refactor attempt
figueroa1395 Nov 22, 2024
520c174
Revert "final refactor attempt"
figueroa1395 Nov 25, 2024
1f5bb5f
Merge branch 'main' into feature/optional-id-refactor-part2
mgovers Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
figueroa1395 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
//
// SPDX-License-Identifier: MPL-2.0

#pragma once

#include "../all_components.hpp"
#include "../container.hpp"

#include <array>
#include <vector>

namespace power_grid_model::main_core::utils {

template <class... ComponentTypes> constexpr size_t n_types = sizeof...(ComponentTypes);
template <class CompType, class... ComponentTypes>
constexpr size_t index_of_component = container_impl::get_cls_pos_v<CompType, ComponentTypes...>;

template <class... ComponentTypes> using SequenceIdx = std::array<std::vector<Idx2D>, n_types<ComponentTypes...>>;
template <class... ComponentTypes> using ComponentFlags = std::array<bool, n_types<ComponentTypes...>>;

// run functors with all component types
template <class... Types, class Functor> constexpr void run_functor_with_all_types_return_void(Functor functor) {
(functor.template operator()<Types>(), ...);
}
template <class... Types, class Functor> constexpr auto run_functor_with_all_types_return_array(Functor functor) {
return std::array { functor.template operator()<Types>()... };
}

} // namespace power_grid_model::main_core::utils
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constexpr Idx get_component_group_idx(MainModelState<ComponentContainer> const&

template <typename ComponentType, class ComponentContainer>
requires model_component_state_c<MainModelState, ComponentContainer, ComponentType>
inline Idx get_component_sequence(MainModelState<ComponentContainer> const& state, auto const& id_or_index) {
inline Idx get_component_sequence_idx(MainModelState<ComponentContainer> const& state, auto const& id_or_index) {
figueroa1395 marked this conversation as resolved.
Show resolved Hide resolved
return state.components.template get_seq<ComponentType>(id_or_index);
}

Expand Down Expand Up @@ -97,19 +97,19 @@ constexpr auto get_component_citer(MainModelState<ComponentContainer> const& sta
template <std::derived_from<Branch> ComponentType, class ComponentContainer>
requires model_component_state_c<MainModelState, ComponentContainer, ComponentType>
constexpr auto get_topology_index(MainModelState<ComponentContainer> const& state, auto const& id_or_index) {
return get_component_sequence<Branch>(state, id_or_index);
return get_component_sequence_idx<Branch>(state, id_or_index);
}

template <std::derived_from<Branch3> ComponentType, class ComponentContainer>
requires model_component_state_c<MainModelState, ComponentContainer, ComponentType>
constexpr auto get_topology_index(MainModelState<ComponentContainer> const& state, auto const& id_or_index) {
return get_component_sequence<Branch3>(state, id_or_index);
return get_component_sequence_idx<Branch3>(state, id_or_index);
}

template <std::derived_from<Regulator> ComponentType, class ComponentContainer>
requires model_component_state_c<MainModelState, ComponentContainer, ComponentType>
constexpr auto get_topology_index(MainModelState<ComponentContainer> const& state, auto const& id_or_index) {
return get_component_sequence<Regulator>(state, id_or_index);
return get_component_sequence_idx<Regulator>(state, id_or_index);
}

template <std::derived_from<Branch> ComponentType, class ComponentContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ template <std::same_as<Branch> Component, class ComponentContainer>
constexpr void register_topology_components(MainModelState<ComponentContainer> const& state,
ComponentTopology& comp_topo) {
detail::register_topo_components<Component>(state, comp_topo.branch_node_idx, [&state](Branch const& branch) {
return BranchIdx{get_component_sequence<Node>(state, branch.from_node()),
get_component_sequence<Node>(state, branch.to_node())};
return BranchIdx{get_component_sequence_idx<Node>(state, branch.from_node()),
get_component_sequence_idx<Node>(state, branch.to_node())};
});
}

Expand All @@ -50,9 +50,9 @@ template <std::same_as<Branch3> Component, class ComponentContainer>
constexpr void register_topology_components(MainModelState<ComponentContainer> const& state,
ComponentTopology& comp_topo) {
detail::register_topo_components<Component>(state, comp_topo.branch3_node_idx, [&state](Branch3 const& branch3) {
return Branch3Idx{get_component_sequence<Node>(state, branch3.node_1()),
get_component_sequence<Node>(state, branch3.node_2()),
get_component_sequence<Node>(state, branch3.node_3())};
return Branch3Idx{get_component_sequence_idx<Node>(state, branch3.node_1()),
get_component_sequence_idx<Node>(state, branch3.node_2()),
get_component_sequence_idx<Node>(state, branch3.node_3())};
});
}

Expand All @@ -61,7 +61,7 @@ template <std::same_as<Source> Component, class ComponentContainer>
constexpr void register_topology_components(MainModelState<ComponentContainer> const& state,
ComponentTopology& comp_topo) {
detail::register_topo_components<Component>(state, comp_topo.source_node_idx, [&state](Source const& source) {
return get_component_sequence<Node>(state, source.node());
return get_component_sequence_idx<Node>(state, source.node());
});
}

Expand All @@ -70,7 +70,7 @@ template <std::same_as<Shunt> Component, class ComponentContainer>
constexpr void register_topology_components(MainModelState<ComponentContainer> const& state,
ComponentTopology& comp_topo) {
detail::register_topo_components<Component>(state, comp_topo.shunt_node_idx, [&state](Shunt const& shunt) {
return get_component_sequence<Node>(state, shunt.node());
return get_component_sequence_idx<Node>(state, shunt.node());
});
}

Expand All @@ -80,7 +80,7 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
ComponentTopology& comp_topo) {
detail::register_topo_components<Component>(
state, comp_topo.load_gen_node_idx,
[&state](GenericLoadGen const& load_gen) { return get_component_sequence<Node>(state, load_gen.node()); });
[&state](GenericLoadGen const& load_gen) { return get_component_sequence_idx<Node>(state, load_gen.node()); });

detail::register_topo_components<Component>(state, comp_topo.load_gen_type,
[](GenericLoadGen const& load_gen) { return load_gen.type(); });
Expand All @@ -92,7 +92,7 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
ComponentTopology& comp_topo) {
detail::register_topo_components<Component>(
state, comp_topo.voltage_sensor_node_idx, [&state](GenericVoltageSensor const& voltage_sensor) {
return get_component_sequence<Node>(state, voltage_sensor.measured_object());
return get_component_sequence_idx<Node>(state, voltage_sensor.measured_object());
});
}

Expand All @@ -110,21 +110,21 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
case branch_from:
[[fallthrough]];
case branch_to:
return get_component_sequence<Branch>(state, measured_object);
return get_component_sequence_idx<Branch>(state, measured_object);
case source:
return get_component_sequence<Source>(state, measured_object);
return get_component_sequence_idx<Source>(state, measured_object);
case shunt:
return get_component_sequence<Shunt>(state, measured_object);
return get_component_sequence_idx<Shunt>(state, measured_object);
case load:
[[fallthrough]];
case generator:
return get_component_sequence<GenericLoadGen>(state, measured_object);
return get_component_sequence_idx<GenericLoadGen>(state, measured_object);
case branch3_1:
case branch3_2:
case branch3_3:
return get_component_sequence<Branch3>(state, measured_object);
return get_component_sequence_idx<Branch3>(state, measured_object);
case node:
return get_component_sequence<Node>(state, measured_object);
return get_component_sequence_idx<Node>(state, measured_object);
default:
throw MissingCaseForEnumError("Power sensor idx to seq transformation",
power_sensor.get_terminal_type());
Expand All @@ -144,9 +144,9 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
state, comp_topo.regulated_object_idx, [&state](Regulator const& regulator) {
switch (regulator.regulated_object_type()) {
case ComponentType::branch:
return get_component_sequence<Branch>(state, regulator.regulated_object());
return get_component_sequence_idx<Branch>(state, regulator.regulated_object());
case ComponentType::branch3:
return get_component_sequence<Branch3>(state, regulator.regulated_object());
return get_component_sequence_idx<Branch3>(state, regulator.regulated_object());
default:
throw MissingCaseForEnumError("Regulator idx to seq transformation", regulator.regulated_object_type());
}
Expand Down
Loading
Loading