Skip to content

Commit

Permalink
add components using dataset
Browse files Browse the repository at this point in the history
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
  • Loading branch information
mgovers committed Jul 2, 2024
1 parent 2e31172 commit d6fafd4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
explicit MainModelImpl(double system_frequency, ConstDataset const& input_data, Idx pos = 0)
: system_frequency_{system_frequency}, meta_data_{&input_data.meta_data()} {
assert(input_data.get_description().dataset->name == std::string_view("input"));
auto const add_func = [this, pos, &input_data]<typename CT>() {
this->add_component<CT>(input_data.get_buffer_span<meta_data::input_getter_s, CT>(pos));
};
run_functor_with_all_types_return_void(add_func);
add_components(input_data, pos);
set_construction_complete();
}

Expand Down Expand Up @@ -158,6 +155,13 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
main_core::add_component<CompType>(state_, begin, end, system_frequency_);
}

void add_components(ConstDataset const& input_data, Idx pos = 0) {
auto const add_func = [this, pos, &input_data]<typename CT>() {
this->add_component<CT>(input_data.get_buffer_span<meta_data::input_getter_s, CT>(pos));
};
run_functor_with_all_types_return_void(add_func);
}

// template to update components
// using forward interators
// different selection based on component type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ class MainModelWrapper {
template <class CompType> void add_component(std::vector<typename CompType::InputType> const& components) {
add_component<CompType>(std::span<typename CompType::InputType const>{components});
}
template <class CompType> void add_component(std::span<typename CompType::InputType const> components);
template <class CompType> void add_component(std::span<typename CompType::InputType const> components) {
ConstDataset dataset{false, 1, "input", meta_data::meta_data_gen::meta_data};
dataset.add_buffer(CompType::name, components.size(), components.size(), nullptr, components.data());
add_components(dataset);
}

template <cache_type_c CacheType> void update_component(ConstDataset const& update_data, Idx pos = 0);

template <symmetry_tag sym> MathOutput<std::vector<SolverOutput<sym>>> calculate_power_flow(Options const& options);
Expand All @@ -70,6 +75,8 @@ class MainModelWrapper {

private:
std::unique_ptr<Impl> impl_;

void add_components(ConstDataset const& input_data, Idx pos = 0);
};

} // namespace power_grid_model::pgm_static
Expand Down
31 changes: 2 additions & 29 deletions tests/power_grid_model_static/src/main_model_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,11 @@ void MainModelWrapper::restore_components(ConstDataset const& update_data) {
impl_->restore_components(impl_->get_sequence_idx_map(update_data));
}

template <class CompType>
void MainModelWrapper::add_component(std::span<typename CompType::InputType const> components) {
void MainModelWrapper::add_components(ConstDataset const& input_data, Idx pos) {
assert(impl_ != nullptr);
impl_->add_component<CompType>(components);
impl_->add_components(input_data, pos);
}

template void MainModelWrapper::add_component<Node>(std::span<typename Node::InputType const> components);
template void MainModelWrapper::add_component<Line>(std::span<typename Line::InputType const> components);
template void MainModelWrapper::add_component<Link>(std::span<typename Link::InputType const> components);
template void MainModelWrapper::add_component<Transformer>(std::span<typename Transformer::InputType const> components);
template void MainModelWrapper::add_component<ThreeWindingTransformer>(
std::span<typename ThreeWindingTransformer::InputType const> components);
template void MainModelWrapper::add_component<Shunt>(std::span<typename Shunt::InputType const> components);
template void MainModelWrapper::add_component<Source>(std::span<typename Source::InputType const> components);
template void
MainModelWrapper::add_component<SymGenerator>(std::span<typename SymGenerator::InputType const> components);
template void
MainModelWrapper::add_component<AsymGenerator>(std::span<typename AsymGenerator::InputType const> components);
template void MainModelWrapper::add_component<SymLoad>(std::span<typename SymLoad::InputType const> components);
template void MainModelWrapper::add_component<AsymLoad>(std::span<typename AsymLoad::InputType const> components);
template void
MainModelWrapper::add_component<SymPowerSensor>(std::span<typename SymPowerSensor::InputType const> components);
template void
MainModelWrapper::add_component<AsymPowerSensor>(std::span<typename AsymPowerSensor::InputType const> components);
template void
MainModelWrapper::add_component<SymVoltageSensor>(std::span<typename SymVoltageSensor::InputType const> components);
template void
MainModelWrapper::add_component<AsymVoltageSensor>(std::span<typename AsymVoltageSensor::InputType const> components);
template void MainModelWrapper::add_component<Fault>(std::span<typename Fault::InputType const> components);
template void MainModelWrapper::add_component<TransformerTapRegulator>(
std::span<typename TransformerTapRegulator::InputType const> components);

template <cache_type_c CacheType> void MainModelWrapper::update_component(ConstDataset const& update_data, Idx pos) {
assert(impl_ != nullptr);
impl_->update_component<CacheType>(update_data, pos);
Expand Down

0 comments on commit d6fafd4

Please sign in to comment.