-
Notifications
You must be signed in to change notification settings - Fork 43
Cleanup main model: Clean up templates and variadics #1109
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
Open
nitbharambe
wants to merge
17
commits into
main
Choose a base branch
from
feature/main-model-refactor-clean-templates-experiment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+368
−95
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5a1fba0
experiment with topology
nitbharambe dc02963
uncomment
nitbharambe f717e8c
add more questions
nitbharambe 8d00207
add tests
nitbharambe 4840826
Merge branch 'main' into feature/main-model-refactor-clean-templates-…
mgovers a01f8f3
Merge branch 'main' into feature/main-model-refactor-clean-templates-…
nitbharambe c8d8512
add all MainModelType features
nitbharambe df398f1
change to the generic tuple function
nitbharambe 9f196f5
remove most variadics
nitbharambe 3495fe3
clean up core_utils
nitbharambe 9e54be9
Merge branch 'main' into feature/main-model-refactor-clean-templates-…
nitbharambe c997c1a
add tests
nitbharambe 024be07
change to sv
nitbharambe 746264f
rename
nitbharambe adfd800
move to new file
nitbharambe 63cdfcc
rename test file
nitbharambe 3b1358c
address clang tidy
nitbharambe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
power_grid_model_c/power_grid_model/include/power_grid_model/main_core/main_model_type.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// 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 "state.hpp" | ||
#include "update.hpp" | ||
|
||
#include <array> | ||
#include <vector> | ||
namespace power_grid_model::main_core { | ||
|
||
namespace detail { | ||
|
||
template <typename Tuple> struct tuple_type_identities_to_tuple_types; | ||
|
||
template <typename... Ts> struct tuple_type_identities_to_tuple_types<std::tuple<std::type_identity<Ts>...>> { | ||
using type = std::tuple<Ts...>; | ||
}; | ||
|
||
template <typename Tuple> | ||
using tuple_type_identities_to_tuple_types_t = typename tuple_type_identities_to_tuple_types<Tuple>::type; | ||
|
||
template <typename... Types, typename... SelectTypes> | ||
constexpr auto filter_tuple_types(std::tuple<std::type_identity<Types>...> /*unused*/, | ||
std::tuple<std::type_identity<SelectTypes>...> /*unused*/) { | ||
constexpr auto sub_type_in_type = []<typename T>() { return (std::is_same_v<T, SelectTypes> || ...); }; | ||
|
||
return std::tuple_cat(std::conditional_t<sub_type_in_type.template operator()<Types>(), | ||
std::tuple<std::type_identity<Types>>, std::tuple<>>{}...); | ||
} | ||
|
||
} // namespace detail | ||
|
||
template <class T, class U> struct MainModelType; | ||
|
||
// TODO: discussion on checking dependent types can also be done here. | ||
template <class... ExtraRetrievableType, class... ComponentType> | ||
struct MainModelType<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentList<ComponentType...>> { | ||
|
||
using ComponentContainer = Container<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentType...>; | ||
using MainModelState = main_core::MainModelState<ComponentContainer>; | ||
using ComponentTypesTuple = std::tuple<ComponentType...>; | ||
|
||
static constexpr size_t n_types = sizeof...(ComponentType); | ||
// TODO Should not have to go via container_impl. | ||
template <class CompType> | ||
static constexpr size_t index_of_component = container_impl::get_cls_pos_v<CompType, ComponentType...>; | ||
|
||
private: | ||
static constexpr auto all_types_tuple_v_ = | ||
std::tuple<std::type_identity<ComponentType>..., std::type_identity<ExtraRetrievableType>...>{}; | ||
// TODO: Would making a unique be necessary? We have Node mentioned as a ExtraRetrievableType and ComponentType so | ||
// summing up is possible but maybe not appropriate. Would it be better to handle them both separately? using | ||
|
||
static constexpr auto topology_types_tuple_v_ = | ||
std::tuple<std::type_identity<Node>, std::type_identity<Branch>, std::type_identity<Branch3>, | ||
std::type_identity<Source>, std::type_identity<Shunt>, std::type_identity<GenericLoadGen>, | ||
std::type_identity<GenericVoltageSensor>, std::type_identity<GenericPowerSensor>, | ||
std::type_identity<GenericCurrentSensor>, std::type_identity<Regulator>>{}; | ||
|
||
static constexpr auto topology_connection_types_tuple_v_ = | ||
std::tuple<std::type_identity<Branch>, std::type_identity<Branch3>, std::type_identity<Source>>{}; | ||
|
||
public: | ||
using TopologyTypesTuple = detail::tuple_type_identities_to_tuple_types_t<decltype(detail::filter_tuple_types( | ||
topology_types_tuple_v_, all_types_tuple_v_))>; | ||
using TopologyConnectionTypesTuple = | ||
detail::tuple_type_identities_to_tuple_types_t<decltype(detail::filter_tuple_types( | ||
topology_connection_types_tuple_v_, all_types_tuple_v_))>; | ||
|
||
// Update related types | ||
using OwnedUpdateDataset = std::tuple<std::vector<typename ComponentType::UpdateType>...>; | ||
using SequenceIdxView = std::array<std::span<Idx2D const>, n_types>; | ||
using UpdateIndependence = std::array<main_core::update::independence::UpdateCompProperties, n_types>; | ||
using SequenceIdx = std::array<std::vector<Idx2D>, n_types>; | ||
using SequenceIdxRefWrappers = std::array<std::reference_wrapper<std::vector<Idx2D> const>, n_types>; | ||
using ComponentFlags = std::array<bool, n_types>; | ||
|
||
// Clean these 2. They are unused | ||
static constexpr auto branch_param_in_seq_map = | ||
std::array{index_of_component<Line>, index_of_component<Link>, index_of_component<Transformer>}; | ||
static constexpr auto shunt_param_in_seq_map = std::array{index_of_component<Shunt>}; | ||
|
||
template <class Functor> static constexpr void run_functor_with_all_component_types_return_void(Functor functor) { | ||
(functor.template operator()<ComponentType>(), ...); | ||
} | ||
template <class Functor> static constexpr auto run_functor_with_all_component_types_return_array(Functor functor) { | ||
return std::array { functor.template operator()<ComponentType>()... }; | ||
} | ||
}; | ||
|
||
} // namespace power_grid_model::main_core |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of these utils with
ComponentTypes...
is for now (and mostly in future) limited only to ComponentTypes. So nice to just move them inside.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These would be removed in final stage after all usages are cleared. which would be after #1119