Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,17 @@ enum class CType : IntS { c_int32 = 0, c_int8 = 1, c_double = 2, c_double3 = 3 }

enum class SerializationFormat : IntS { json = 0, msgpack = 1 };

enum class OptimizerType : IntS {
no_optimization = 0, // do nothing
automatic_tap_adjustment = 1, // power flow with automatic tap adjustment
};

enum class OptimizerStrategy : IntS { // Conventions for optimization strategies
any = 0, // any = Any{f(x) \in Range} for x \in Domain
global_minimum = 1, // global_minimum = argmin{f(x) \in Range} for x in Domain
global_maximum = 2, // global_maximum = argmax{f(x) \in Range} for x in Domain
local_minimum = 3, // local_minimum = Any{argmin{f(x) \in Range}} for x in Domain
local_maximum = 4, // local_maximum = Any{argmax{f(x) \in Range}} for x in Domain
};

} // namespace power_grid_model
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace power_grid_model::main_core {
// using forward interators
// different selection based on component type
template <std::derived_from<Base> Component, class ComponentContainer, std::forward_iterator ForwardIterator>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline void add_component(MainModelState<ComponentContainer>& state, ForwardIterator begin, ForwardIterator end,
double system_frequency) {
size_t const size = std::distance(begin, end);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,27 @@ template <class CompContainer> struct MainModelState {
ComponentToMathCoupling comp_coup;
};

template <class StateType>
concept main_model_state_c = std::same_as<StateType, MainModelState<typename StateType::ComponentContainer>>;

template <typename ContainerType, typename ComponentType>
concept component_container = requires(ContainerType const& c, ID id) {
{ c.template citer<ComponentType>().begin() } -> std::forward_iterator;
{ c.template citer<ComponentType>().end() } -> std::forward_iterator;
{
*(c.template citer<ComponentType>().begin())
} -> std::same_as<ComponentType const&>;
{ *(c.template citer<ComponentType>().end()) } -> std::same_as<ComponentType const&>;
{
c.template get_item<ComponentType>(id)
} -> std::convertible_to<ComponentType const&>;
};
concept component_container_c = requires(ContainerType const& c, ID id) {
{ c.template citer<ComponentType>().begin() } -> std::forward_iterator;
{ c.template citer<ComponentType>().end() } -> std::forward_iterator;
{
*(c.template citer<ComponentType>().begin())
} -> std::same_as<ComponentType const&>;
{
*(c.template citer<ComponentType>().end())
} -> std::same_as<ComponentType const&>;
{
c.template get_item<ComponentType>(id)
} -> std::convertible_to<ComponentType const&>;
};

template <template <typename T> class StateType, typename ContainerType, typename ComponentType>
concept model_component_state =
component_container<typename StateType<ContainerType>::ComponentContainer, ComponentType> &&
concept model_component_state_c =
component_container_c<typename StateType<ContainerType>::ComponentContainer, ComponentType> &&
std::same_as<StateType<ContainerType>, MainModelState<ContainerType>>;

} // namespace power_grid_model::main_core
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace power_grid_model::main_core {
namespace detail {

template <typename Component, class ComponentContainer, typename ResType, typename ResFunc>
requires model_component_state<MainModelState, ComponentContainer, Component> &&
requires model_component_state_c<MainModelState, ComponentContainer, Component> &&
std::invocable<std::remove_cvref_t<ResFunc>, Component const&> &&
std::convertible_to<std::invoke_result_t<ResFunc, Component const&>, ResType>
constexpr void register_topo_components(MainModelState<ComponentContainer> const& state, std::vector<ResType>& target,
Expand All @@ -26,22 +26,22 @@ constexpr void register_topo_components(MainModelState<ComponentContainer> const
}

template <typename Component, class ComponentContainer>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
constexpr auto get_seq(MainModelState<ComponentContainer> const& state, ID id) {
return state.components.template get_seq<Component>(id);
}

} // namespace detail

template <std::same_as<Node> Component, class ComponentContainer>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
constexpr void register_topology_components(MainModelState<ComponentContainer> const& state,
ComponentTopology& comp_topo) {
comp_topo.n_node = state.components.template size<Node>();
}

template <std::same_as<Branch> Component, class ComponentContainer>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
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) {
Expand All @@ -51,7 +51,7 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
}

template <std::same_as<Branch3> Component, class ComponentContainer>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
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) {
Expand All @@ -62,7 +62,7 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
}

template <std::same_as<Source> Component, class ComponentContainer>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
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) {
Expand All @@ -71,7 +71,7 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
}

template <std::same_as<Shunt> Component, class ComponentContainer>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
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) {
Expand All @@ -80,7 +80,7 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
}

template <std::same_as<GenericLoadGen> Component, class ComponentContainer>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
constexpr void register_topology_components(MainModelState<ComponentContainer> const& state,
ComponentTopology& comp_topo) {
detail::register_topo_components<Component>(
Expand All @@ -92,7 +92,7 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
}

template <std::same_as<GenericVoltageSensor> Component, class ComponentContainer>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
constexpr void register_topology_components(MainModelState<ComponentContainer> const& state,
ComponentTopology& comp_topo) {
detail::register_topo_components<Component>(
Expand All @@ -102,7 +102,7 @@ constexpr void register_topology_components(MainModelState<ComponentContainer> c
}

template <std::same_as<GenericPowerSensor> Component, class ComponentContainer>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
constexpr void register_topology_components(MainModelState<ComponentContainer> const& state,
ComponentTopology& comp_topo) {
detail::register_topo_components<Component>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace power_grid_model::main_core {

namespace detail {
template <std::derived_from<Base> Component, class ComponentContainer, typename UpdateType>
requires model_component_state<MainModelState, ComponentContainer, Component> &&
requires model_component_state_c<MainModelState, ComponentContainer, Component> &&
std::same_as<std::remove_cvref_t<typename Component::UpdateType>, std::remove_cvref_t<UpdateType>>
inline Idx2D get_idx_by_id(MainModelState<ComponentContainer> const& state, UpdateType const& update) {
return state.components.template get_idx_by_id<Component>(update.id);
Expand All @@ -34,7 +34,7 @@ inline void iterate_component_sequence(Func&& func, ForwardIterator begin, Forwa

template <std::derived_from<Base> Component, class ComponentContainer, std::forward_iterator ForwardIterator,
std::output_iterator<Idx2D> OutputIterator>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline void get_component_sequence(MainModelState<ComponentContainer> const& state, ForwardIterator begin,
ForwardIterator end, OutputIterator destination) {
using UpdateType = typename Component::UpdateType;
Expand All @@ -44,7 +44,7 @@ inline void get_component_sequence(MainModelState<ComponentContainer> const& sta
}

template <std::derived_from<Base> Component, class ComponentContainer, std::forward_iterator ForwardIterator>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline std::vector<Idx2D> get_component_sequence(MainModelState<ComponentContainer> const& state, ForwardIterator begin,
ForwardIterator end) {
std::vector<Idx2D> result;
Expand All @@ -59,7 +59,7 @@ inline std::vector<Idx2D> get_component_sequence(MainModelState<ComponentContain
// if sequence_idx is given, it will be used to load the object instead of using IDs via hash map.
template <std::derived_from<Base> Component, class ComponentContainer, std::forward_iterator ForwardIterator,
std::output_iterator<Idx2D> OutputIterator>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline UpdateChange update_component(MainModelState<ComponentContainer>& state, ForwardIterator begin,
ForwardIterator end, OutputIterator changed_it,
std::vector<Idx2D> const& sequence_idx = {}) {
Expand Down Expand Up @@ -89,7 +89,7 @@ inline UpdateChange update_component(MainModelState<ComponentContainer>& state,
// if sequence_idx is given, it will be used to load the object instead of using IDs via hash map.
template <std::derived_from<Base> Component, class ComponentContainer, std::forward_iterator ForwardIterator,
std::output_iterator<typename Component::UpdateType> OutputIterator>
requires model_component_state<MainModelState, ComponentContainer, Component>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline void update_inverse(MainModelState<ComponentContainer> const& state, ForwardIterator begin, ForwardIterator end,
OutputIterator destination, std::vector<Idx2D> const& sequence_idx = {}) {
using UpdateType = typename Component::UpdateType;
Expand Down
Loading