Skip to content

Commit

Permalink
Merge pull request #790 from PowerGridModel/bug/fix-feedstock-mac
Browse files Browse the repository at this point in the history
Bug/Fix feedstock mac
  • Loading branch information
nitbharambe authored Oct 16, 2024
2 parents 45c34c3 + 75337c6 commit 813eff1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
61 changes: 61 additions & 0 deletions tests/cpp_integration_tests/test_main_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ struct State {
std::vector<SourceUpdate> source_update{{10, 1, test::u1, nan}};
std::vector<BranchUpdate> link_update{{5, 1, 0}};
std::vector<FaultUpdate> fault_update{{30, 1, FaultType::three_phase, FaultPhase::abc, 1, nan, nan}};

// batch update vector
std::vector<SymLoadGenUpdate> batch_sym_load_update{{7, 1, 1.0e6, nan}, {7}, {7}, {7}, {7}};
std::vector<AsymLoadGenUpdate> batch_asym_load_update{
{8, 0, RealValue<asymmetric_t>{nan}, RealValue<asymmetric_t>{nan}}, {8}, {8}, {8}, {8}};
std::vector<ShuntUpdate> batch_shunt_update{{9, 0, nan, 0.02, nan, 0.02}, {9}, {9}, {9}, {9}};
std::vector<SourceUpdate> batch_source_update{{10, 1, test::u1, nan}, {10}, {10}, {10}, {10}};
std::vector<BranchUpdate> batch_link_update{{5, 1, 0}, {5}, {5}, {5}, {5}};
std::vector<FaultUpdate> batch_fault_update{
{30, 1, FaultType::three_phase, FaultPhase::abc, 1, nan, nan}, {30}, {30}, {30}, {30}};
};

auto default_model(State const& state) -> MainModel {
Expand Down Expand Up @@ -949,6 +959,57 @@ TEST_CASE_TEMPLATE("Test main model - all updates", settings, regular_update, ca
}
}

TEST_CASE_TEMPLATE("Test main model - single permanent update from batch", settings, regular_update, cached_update) {
State state;
auto main_model = default_model(state);

state.batch_sym_load_update[0].p_specified = 2.5e6;
ConstDataset update_data{true, 5, "update", meta_data::meta_data_gen::meta_data};
update_data.add_buffer("sym_load", 1, state.batch_sym_load_update.size(), nullptr,
state.batch_sym_load_update.data());
update_data.add_buffer("asym_load", 1, state.batch_asym_load_update.size(), nullptr,
state.batch_asym_load_update.data());
update_data.add_buffer("shunt", 1, state.batch_shunt_update.size(), nullptr, state.batch_shunt_update.data());
update_data.add_buffer("source", 1, state.batch_source_update.size(), nullptr, state.batch_source_update.data());
update_data.add_buffer("link", 1, state.batch_link_update.size(), nullptr, state.batch_link_update.data());
update_data.add_buffer("fault", 1, state.batch_fault_update.size(), nullptr, state.batch_fault_update.data());

main_model.update_component<typename settings::update_type>(update_data);

SUBCASE("Symmetrical") {
auto const solver_output =
main_model.calculate<power_flow_t, symmetric_t>(get_default_options(symmetric, CalculationMethod::linear));
main_model.output_result<Node>(solver_output, state.sym_node);
main_model.output_result<Branch>(solver_output, state.sym_branch);
main_model.output_result<Appliance>(solver_output, state.sym_appliance);
CHECK(state.sym_node[0].u_pu == doctest::Approx(1.05));
CHECK(state.sym_node[1].u_pu == doctest::Approx(1.05));
CHECK(state.sym_node[2].u_pu == doctest::Approx(test::u1));
CHECK(state.sym_branch[0].i_from == doctest::Approx(0.0).epsilon(1e-6));
CHECK(state.sym_appliance[0].i == doctest::Approx(0.0).epsilon(1e-6));
CHECK(state.sym_appliance[1].i == doctest::Approx(test::i));
CHECK(state.sym_appliance[2].i == doctest::Approx(test::i));
CHECK(state.sym_appliance[3].i == doctest::Approx(0.0));
CHECK(state.sym_appliance[4].i == doctest::Approx(0.0));
}
SUBCASE("Asymmetrical") {
auto const solver_output = main_model.calculate<power_flow_t, asymmetric_t>(
get_default_options(asymmetric, CalculationMethod::linear));
main_model.output_result<Node>(solver_output, state.asym_node);
main_model.output_result<Branch>(solver_output, state.asym_branch);
main_model.output_result<Appliance>(solver_output, state.asym_appliance);
CHECK(state.asym_node[0].u_pu(0) == doctest::Approx(1.05));
CHECK(state.asym_node[1].u_pu(1) == doctest::Approx(1.05));
CHECK(state.asym_node[2].u_pu(2) == doctest::Approx(test::u1));
CHECK(state.asym_branch[0].i_from(0) == doctest::Approx(0.0).epsilon(1e-6));
CHECK(state.asym_appliance[0].i(1) == doctest::Approx(0.0).epsilon(1e-6));
CHECK(state.asym_appliance[1].i(2) == doctest::Approx(test::i));
CHECK(state.asym_appliance[2].i(0) == doctest::Approx(test::i));
CHECK(state.asym_appliance[3].i(1) == doctest::Approx(0.0));
CHECK(state.asym_appliance[4].i(2) == doctest::Approx(0.0));
}
}

TEST_CASE_TEMPLATE("Test main model - restore components", settings, regular_update, cached_update) {
State state;
auto main_model = default_model(state);
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/test_power_grid_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ def test_simple_power_flow(model: PowerGridModel, sym_output):
compare_result(result, sym_output, rtol=0.0, atol=1e-8)


def test_simple_permanent_update(
model: PowerGridModel, update_batch, sym_output_batch
): # error if permanent update is not single scenario
model.update(update_data=update_batch) # single permanent model update
def test_simple_permanent_update(model: PowerGridModel, update_batch, sym_output_batch):
model.update(update_data=get_dataset_scenario(update_batch, 0)) # single permanent model update
result = model.calculate_power_flow()
expected_result = get_dataset_scenario(sym_output_batch, 0)
compare_result(result, expected_result, rtol=0.0, atol=1e-8)
Expand Down

0 comments on commit 813eff1

Please sign in to comment.