Skip to content
Open
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 @@ -111,6 +111,10 @@ class MainModel {
impl().check_no_experimental_features_used(options, batch_dataset);
}

void check_no_future_deprecations(Options const& options, ConstDataset const* batch_dataset) const {
impl().check_no_future_deprecations(options, batch_dataset);
}

private:
Impl& impl() {
assert(impl_ != nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,18 @@ class MainModelImpl {
}
}

void check_no_future_deprecations(Options const& /*options*/, ConstDataset const* /*batch_dataset*/) const {
ModelType::run_functor_with_all_component_types_return_void([this]<typename CT>() {
if constexpr (requires(CT c) { c.get_terminal_type(); }) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I didn't realize how would this check distinguish flow sensors from voltage sensors and realized that get_terminal_type is only part of the former. Can you add a short comment for easy pinpoint?

if (std::ranges::any_of(state_.components.template citer<CT>(), [](auto const& sensor) {
return sensor.get_terminal_type() == MeasuredTerminalType::node;
})) {
throw InvalidMeasuredTerminalType{MeasuredTerminalType::node, CT::name};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's abusing the notation, but would it make sense to do something like

Suggested change
throw InvalidMeasuredTerminalType{MeasuredTerminalType::node, CT::name};
throw InvalidMeasuredTerminalType{std::format("Deprecation error: {}", MeasuredTerminalType::node), CT::name};

Just to further distinguish it a bit more without introducing anything else? Like a small convention for these rare deprecation errors.

}
}
});
}

private:
template <solver_output_type SolverOutputType>
void output_result(MathOutput<std::vector<SolverOutputType>> const& math_output, MutableDataset const& result_data,
Expand Down
5 changes: 4 additions & 1 deletion power_grid_model_c/power_grid_model_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ file(

target_link_libraries(power_grid_model_c PRIVATE power_grid_model)

target_compile_definitions(power_grid_model_c PRIVATE PGM_VERSION="${PGM_VERSION}")
target_compile_definitions(
power_grid_model_c
PRIVATE PGM_VERSION="${PGM_VERSION}"
)

target_sources(
power_grid_model_c
Expand Down
26 changes: 23 additions & 3 deletions power_grid_model_c/power_grid_model_c/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ void check_no_experimental_features_used(MainModel const& model, MainModel::Opti
model.check_no_experimental_features_used(opt, batch_dataset);
}

void check_no_future_deprecations(MainModel const& model, MainModel::Options const& opt,
ConstDataset const* batch_dataset) {
// optionally add deprecation checks here
using namespace std::string_literals;

model.check_no_future_deprecations(opt, batch_dataset);
}

void check_experimental_support(Idx experimental_features, MainModel const& model, MainModel::Options const& opt,
ConstDataset const* batch_dataset) {
switch (experimental_features) {
case PGM_experimental_features_disabled:
check_no_experimental_features_used(model, opt, batch_dataset);
break;
case PGM_experimental_features_enabled:
check_no_future_deprecations(model, opt, batch_dataset);
break;
default:
throw MissingCaseForEnumError{"calculate_impl", experimental_features};
}
}

void check_calculate_valid_options(PGM_Options const& opt) {
if (opt.tap_changing_strategy != PGM_tap_changing_strategy_disabled && opt.calculation_type != PGM_power_flow) {
// illegal combination of options
Expand Down Expand Up @@ -315,9 +337,7 @@ void calculate_impl(MainModel& model, PGM_Options const& options, MutableDataset
check_calculate_valid_options(options);
auto const extracted_options = extract_calculation_options(options);

if (options.experimental_features == PGM_experimental_features_disabled) {
check_no_experimental_features_used(model, extracted_options, batch_dataset);
}
check_experimental_support(options.experimental_features, model, extracted_options, batch_dataset);

calculate_multi_dimensional_impl(model, extracted_options, output_dataset, batch_dataset);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"version": "1.0",
"type": "input",
"is_batch": false,
"attributes": {},
"data": {
"node": [
{
"id": 1,
"u_rated": 100.0
},
{
"id": 2,
"u_rated": 100.0
}
],
"line": [
{
"id": 4,
"from_node": 1,
"to_node": 2,
"from_status": 1,
"to_status": 1,
"r1": 0.1,
"x1": 0.0,
"c1": 0.0,
"tan1": 0.0,
"i_n": 1000.0
}
],
"source": [
{
"id": 6,
"node": 1,
"status": 1,
"u_ref": 1.0
}
],
"sym_voltage_sensor": [
{
"id": 101,
"measured_object": 1,
"u_measured": 100.0,
"u_sigma": 1.0
}
],
"sym_power_sensor": [
{
"id": 401,
"measured_object": 2,
"measured_terminal_type": 9,
"p_measured": 100e3,
"q_measured": 100e3,
"power_sigma": 1e3
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"calculation_method": ["iterative_linear", "newton_raphson"],
"rtol": 1e-8,
"atol": 1e-8,
"experimental_features": "enabled",
"raises": {
"raises": "InvalidMeasuredObject",
"reason": "Node injection sensors are no longer supported starting with version 2.0."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "1.0",
"type": "sym_output",
"is_batch": false,
"attributes": {},
"data": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>

SPDX-License-Identifier: MPL-2.0
Loading