Skip to content

Commit 1ab7ee8

Browse files
committed
homogenize registration
Signed-off-by: Nitish Bharambe <[email protected]>
1 parent fbbaa5e commit 1ab7ee8

File tree

1 file changed

+31
-24
lines changed
  • power_grid_model_c/power_grid_model/include/power_grid_model/main_core

1 file changed

+31
-24
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/topology.hpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,34 @@ constexpr void register_topology_components(ComponentContainer const& components
184184
[](Regulator const& regulator) { return regulator.regulated_object_type(); });
185185
}
186186

187+
// TODO Rename register_topo_components if this is combined
188+
template <std::same_as<Branch> Component, class ComponentContainer>
189+
requires component_container_c<ComponentContainer, Component>
190+
constexpr void register_connections_components(ComponentContainer components, ComponentConnections& comp_conn) {
191+
detail::register_topo_components<Component>(components, comp_conn.branch_connected, [](Branch const& branch) {
192+
return BranchConnected{static_cast<IntS>(branch.from_status()), static_cast<IntS>(branch.to_status())};
193+
});
194+
detail::register_topo_components<Component>(components, comp_conn.branch_phase_shift,
195+
[](Branch const& branch) { return branch.phase_shift(); });
196+
}
197+
template <std::same_as<Branch3> Component, class ComponentContainer>
198+
requires component_container_c<ComponentContainer, Component>
199+
constexpr void register_connections_components(ComponentContainer components, ComponentConnections& comp_conn) {
200+
detail::register_topo_components<Component>(components, comp_conn.branch3_connected, [](Branch3 const& branch3) {
201+
return Branch3Connected{static_cast<IntS>(branch3.status_1()), static_cast<IntS>(branch3.status_2()),
202+
static_cast<IntS>(branch3.status_3())};
203+
});
204+
detail::register_topo_components<Component>(components, comp_conn.branch3_phase_shift,
205+
[](Branch3 const& branch3) { return branch3.phase_shift(); });
206+
}
207+
208+
template <std::same_as<Source> Component, class ComponentContainer>
209+
requires component_container_c<ComponentContainer, Component>
210+
constexpr void register_connections_components(ComponentContainer components, ComponentConnections& comp_conn) {
211+
detail::register_topo_components<Component>(components, comp_conn.source_connected,
212+
[](Source const& source) { return source.status(); });
213+
}
214+
187215
template <typename ComponentContainer>
188216
requires multi_extended_component_container_c<ComponentContainer, Branch, Branch3, Source, Shunt, GenericLoadGen,
189217
GenericVoltageSensor, GenericPowerSensor, GenericCurrentSensor,
@@ -207,30 +235,9 @@ template <typename ComponentContainer>
207235
requires multi_extended_component_container_c<ComponentContainer, Branch, Branch3, Source>
208236
ComponentConnections construct_components_connections(ComponentContainer const& components) {
209237
ComponentConnections comp_conn;
210-
comp_conn.branch_connected.resize(get_component_size<Branch>(components));
211-
comp_conn.branch_phase_shift.resize(get_component_size<Branch>(components));
212-
comp_conn.branch3_connected.resize(get_component_size<Branch3>(components));
213-
comp_conn.branch3_phase_shift.resize(get_component_size<Branch3>(components));
214-
comp_conn.source_connected.resize(get_component_size<Source>(components));
215-
std::ranges::transform(
216-
components.template citer<Branch>(), comp_conn.branch_connected.begin(), [](Branch const& branch) {
217-
return BranchConnected{static_cast<IntS>(branch.from_status()), static_cast<IntS>(branch.to_status())};
218-
});
219-
220-
std::ranges::transform(components.template citer<Branch>(), comp_conn.branch_phase_shift.begin(),
221-
[](Branch const& branch) { return branch.phase_shift(); });
222-
223-
std::ranges::transform(
224-
components.template citer<Branch3>(), comp_conn.branch3_connected.begin(), [](Branch3 const& branch3) {
225-
return Branch3Connected{static_cast<IntS>(branch3.status_1()), static_cast<IntS>(branch3.status_2()),
226-
static_cast<IntS>(branch3.status_3())};
227-
});
228-
229-
std::ranges::transform(components.template citer<Branch3>(), comp_conn.branch3_phase_shift.begin(),
230-
[](Branch3 const& branch3) { return branch3.phase_shift(); });
231-
232-
std::ranges::transform(components.template citer<Source>(), comp_conn.source_connected.begin(),
233-
[](Source const& source) { return source.status(); });
238+
register_connections_components<Branch>(components, comp_conn);
239+
register_connections_components<Branch3>(components, comp_conn);
240+
register_connections_components<Source>(components, comp_conn);
234241
return comp_conn;
235242
}
236243

0 commit comments

Comments
 (0)