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

Feature / Add columnar data support in main model #712

Merged
merged 12 commits into from
Sep 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ template <typename T, dataset_type_tag dataset_type> class ColumnarAttributeRang
ctype_func_selector(
meta_attribute.ctype, [&value, &attribute_buffer, &meta_attribute, this]<typename AttributeType> {
AttributeType* buffer_ptr = reinterpret_cast<AttributeType*>(attribute_buffer.data) + idx_;
AttributeType const& attribute_ref = meta_attribute.template get_attribute<AttributeType const>(
auto const& attribute_ref = meta_attribute.template get_attribute<AttributeType const>(
reinterpret_cast<RawDataConstPtr>(&value));
*buffer_ptr = attribute_ref;
});
Expand All @@ -95,7 +95,7 @@ template <typename T, dataset_type_tag dataset_type> class ColumnarAttributeRang
meta_attribute.ctype, [&result, &attribute_buffer, &meta_attribute, this]<typename AttributeType> {
AttributeType const* buffer_ptr =
reinterpret_cast<AttributeType const*>(attribute_buffer.data) + idx_;
AttributeType& attribute_ref =
auto& attribute_ref =
meta_attribute.template get_attribute<AttributeType>(reinterpret_cast<RawDataPtr>(&result));
attribute_ref = *buffer_ptr;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ constexpr std::array<Branch3Side, 3> const branch3_sides = {Branch3Side::side_1,
// template to construct components
// using forward interators
// different selection based on component type
template <std::derived_from<Base> Component, class ComponentContainer, std::forward_iterator ForwardIterator>
template <std::derived_from<Base> Component, class ComponentContainer, typename ForwardIterator>
mgovers marked this conversation as resolved.
Show resolved Hide resolved
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline void add_component(MainModelState<ComponentContainer>& state, ForwardIterator begin, ForwardIterator end,
double system_frequency) {
using ComponentView = std::conditional_t<std::same_as<decltype(*begin), typename Component::InputType const&>,
typename Component::InputType const&, typename Component::InputType>;

reserve_component<Component>(state, std::distance(begin, end));
// do sanity check on the transformer tap regulator
std::vector<Idx2D> regulated_objects;
// loop to add component
for (auto it = begin; it != end; ++it) {
auto const& input = *it;
ComponentView const input = *it;
ID const id = input.id;
// construct based on type of component
if constexpr (std::derived_from<Component, Node>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace power_grid_model::main_core {

namespace detail {

template <typename T, typename U>
concept assignable_to = std::assignable_from<U, T>;
figueroa1395 marked this conversation as resolved.
Show resolved Hide resolved

template <std::same_as<Node> Component, class ComponentContainer>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
constexpr auto comp_base_sequence_cbegin(MainModelState<ComponentContainer> const& state) {
Expand Down Expand Up @@ -75,12 +78,11 @@ constexpr auto comp_base_sequence_cbegin(MainModelState<ComponentContainer> cons
return state.comp_topo->regulated_object_idx.cbegin() + get_component_sequence_offset<Regulator, Component>(state);
}

template <typename Component, typename IndexType, class ComponentContainer, std::forward_iterator ResIt,
typename ResFunc>
template <typename Component, typename IndexType, class ComponentContainer, typename ResIt, typename ResFunc>
figueroa1395 marked this conversation as resolved.
Show resolved Hide resolved
requires model_component_state_c<MainModelState, ComponentContainer, Component> &&
std::invocable<std::remove_cvref_t<ResFunc>, Component const&, IndexType> &&
std::convertible_to<std::invoke_result_t<ResFunc, Component const&, IndexType>,
std::iter_value_t<ResIt>> &&
assignable_to<std::invoke_result_t<ResFunc, Component const&, IndexType>,
std::add_lvalue_reference_t<std::iter_value_t<ResIt>>> &&
std::convertible_to<IndexType,
decltype(*comp_base_sequence_cbegin<Component>(MainModelState<ComponentContainer>{}))>
constexpr ResIt produce_output(MainModelState<ComponentContainer> const& state, ResIt res_it, ResFunc&& func) {
Expand Down Expand Up @@ -359,12 +361,12 @@ output_result(Component const& transformer_tap_regulator, MainModelState<Compone

// output base component
template <std::derived_from<Base> Component, class ComponentContainer, solver_output_type SolverOutputType,
std::forward_iterator ResIt>
typename ResIt>
requires model_component_state_c<MainModelState, ComponentContainer, Component> &&
requires(Component const& component, std::vector<SolverOutputType> const& solver_output, Idx2D math_id) {
{
output_result<Component>(component, solver_output, math_id)
} -> std::convertible_to<std::iter_value_t<ResIt>>;
} -> detail::assignable_to<std::add_lvalue_reference_t<std::iter_value_t<ResIt>>>;
}
constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
MathOutput<std::vector<SolverOutputType>> const& math_output, ResIt res_it) {
Expand All @@ -374,13 +376,13 @@ constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
});
}
template <std::derived_from<Base> Component, class ComponentContainer, solver_output_type SolverOutputType,
std::forward_iterator ResIt>
typename ResIt>
requires model_component_state_c<MainModelState, ComponentContainer, Component> &&
requires(Component const& component, MainModelState<ComponentContainer> const& state,
std::vector<SolverOutputType> const& solver_output, Idx2D math_id) {
{
output_result<Component>(component, state, solver_output, math_id)
} -> std::convertible_to<std::iter_value_t<ResIt>>;
} -> detail::assignable_to<std::add_lvalue_reference_t<std::iter_value_t<ResIt>>>;
}
constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
MathOutput<std::vector<SolverOutputType>> const& math_output, ResIt res_it) {
Expand All @@ -390,13 +392,13 @@ constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
});
}
template <std::derived_from<Base> Component, class ComponentContainer, solver_output_type SolverOutputType,
std::forward_iterator ResIt>
typename ResIt>
requires model_component_state_c<MainModelState, ComponentContainer, Component> &&
requires(Component const& component, MainModelState<ComponentContainer> const& state,
std::vector<SolverOutputType> const& solver_output, Idx obj_seq) {
{
output_result<Component>(component, state, solver_output, obj_seq)
} -> std::convertible_to<std::iter_value_t<ResIt>>;
} -> detail::assignable_to<std::add_lvalue_reference_t<std::iter_value_t<ResIt>>>;
}
constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
MathOutput<std::vector<SolverOutputType>> const& math_output, ResIt res_it) {
Expand All @@ -406,13 +408,13 @@ constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
});
}
template <std::derived_from<Base> Component, class ComponentContainer, solver_output_type SolverOutputType,
std::forward_iterator ResIt>
typename ResIt>
requires model_component_state_c<MainModelState, ComponentContainer, Component> &&
requires(Component const& component, std::vector<SolverOutputType> const& solver_output,
Idx2DBranch3 const& math_id) {
{
output_result<Component>(component, solver_output, math_id)
} -> std::convertible_to<std::iter_value_t<ResIt>>;
} -> detail::assignable_to<std::add_lvalue_reference_t<std::iter_value_t<ResIt>>>;
}
constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
MathOutput<std::vector<SolverOutputType>> const& math_output, ResIt res_it) {
Expand All @@ -421,14 +423,13 @@ constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
return output_result<Component>(component, math_output.solver_output, math_id);
});
}
template <std::derived_from<Base> Component, class ComponentContainer, typename SolverOutputType,
std::forward_iterator ResIt>
template <std::derived_from<Base> Component, class ComponentContainer, typename SolverOutputType, typename ResIt>
requires model_component_state_c<MainModelState, ComponentContainer, Component> &&
requires(Component const& component, MainModelState<ComponentContainer> const& state,
MathOutput<SolverOutputType> const& math_output, Idx const obj_seq) {
{
output_result<Component>(component, state, math_output, obj_seq)
} -> std::convertible_to<std::iter_value_t<ResIt>>;
} -> detail::assignable_to<std::add_lvalue_reference_t<std::iter_value_t<ResIt>>>;
figueroa1395 marked this conversation as resolved.
Show resolved Hide resolved
}
constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
MathOutput<SolverOutputType> const& math_output, ResIt res_it) {
Expand All @@ -440,7 +441,7 @@ constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,

// output source, load_gen, shunt individually
template <std::same_as<Appliance> Component, class ComponentContainer, solver_output_type SolverOutputType,
std::forward_iterator ResIt>
typename ResIt>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
constexpr ResIt output_result(MainModelState<ComponentContainer> const& state,
MathOutput<std::vector<SolverOutputType>> const& math_output, ResIt res_it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace power_grid_model::main_core {

namespace detail {
template <component_c Component, std::forward_iterator ForwardIterator, typename Func>
template <component_c Component, typename ForwardIterator, typename Func>
requires std::invocable<std::remove_cvref_t<Func>, typename Component::UpdateType, Idx2D const&>
inline void iterate_component_sequence(Func&& func, ForwardIterator begin, ForwardIterator end,
std::vector<Idx2D> const& sequence_idx) {
Expand All @@ -27,7 +27,7 @@ inline void iterate_component_sequence(Func&& func, ForwardIterator begin, Forwa
}
} // namespace detail

template <component_c Component, class ComponentContainer, std::forward_iterator ForwardIterator,
template <component_c Component, class ComponentContainer, typename ForwardIterator,
std::output_iterator<Idx2D> OutputIterator>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline void get_component_sequence(MainModelState<ComponentContainer> const& state, ForwardIterator begin,
Expand All @@ -38,7 +38,7 @@ inline void get_component_sequence(MainModelState<ComponentContainer> const& sta
[&state](UpdateType const& update) { return get_component_idx_by_id<Component>(state, update.id); });
}

template <component_c Component, class ComponentContainer, std::forward_iterator ForwardIterator>
template <component_c Component, class ComponentContainer, typename ForwardIterator>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline std::vector<Idx2D> get_component_sequence(MainModelState<ComponentContainer> const& state, ForwardIterator begin,
ForwardIterator end) {
Expand All @@ -52,7 +52,7 @@ inline std::vector<Idx2D> get_component_sequence(MainModelState<ComponentContain
// using forward interators
// different selection based on component type
// if sequence_idx is given, it will be used to load the object instead of using IDs via hash map.
template <component_c Component, class ComponentContainer, std::forward_iterator ForwardIterator,
template <component_c Component, class ComponentContainer, typename ForwardIterator,
std::output_iterator<Idx2D> OutputIterator>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline UpdateChange update_component(MainModelState<ComponentContainer>& state, ForwardIterator begin,
Expand All @@ -77,7 +77,7 @@ inline UpdateChange update_component(MainModelState<ComponentContainer>& state,

return state_changed;
}
template <component_c Component, class ComponentContainer, std::forward_iterator ForwardIterator,
template <component_c Component, class ComponentContainer, /*std::forward_iterator*/ typename ForwardIterator,
std::output_iterator<Idx2D> OutputIterator>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline UpdateChange update_component(MainModelState<ComponentContainer>& state, ForwardIterator begin,
Expand All @@ -90,7 +90,7 @@ inline UpdateChange update_component(MainModelState<ComponentContainer>& state,
// using forward interators
// different selection based on component type
// if sequence_idx is given, it will be used to load the object instead of using IDs via hash map.
template <component_c Component, class ComponentContainer, std::forward_iterator ForwardIterator,
template <component_c Component, class ComponentContainer, typename ForwardIterator,
std::output_iterator<typename Component::UpdateType> OutputIterator>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline void update_inverse(MainModelState<ComponentContainer> const& state, ForwardIterator begin, ForwardIterator end,
Expand All @@ -104,7 +104,7 @@ inline void update_inverse(MainModelState<ComponentContainer> const& state, Forw
},
begin, end, sequence_idx);
}
template <component_c Component, class ComponentContainer, std::forward_iterator ForwardIterator,
template <component_c Component, class ComponentContainer, typename ForwardIterator,
std::output_iterator<typename Component::UpdateType> OutputIterator>
requires model_component_state_c<MainModelState, ComponentContainer, Component>
inline void update_inverse(MainModelState<ComponentContainer> const& state, ForwardIterator begin, ForwardIterator end,
Expand Down
Loading