From 411f160a9b30ec7e506b9fed0113f72bf99dff33 Mon Sep 17 00:00:00 2001 From: petersalemink95 Date: Tue, 24 Dec 2024 14:54:04 +0100 Subject: [PATCH] current sensor input Signed-off-by: petersalemink95 --- .../data/attribute_classes/input.json | 34 ++++++ .../power_grid_model/auxiliary/input.hpp | 44 +++++++ .../auxiliary/meta_gen/input.hpp | 30 +++++ .../auxiliary/static_asserts/input.hpp | 110 ++++++++++++++++++ 4 files changed, 218 insertions(+) diff --git a/code_generation/data/attribute_classes/input.json b/code_generation/data/attribute_classes/input.json index dea1c0fdd..141115ddb 100644 --- a/code_generation/data/attribute_classes/input.json +++ b/code_generation/data/attribute_classes/input.json @@ -494,6 +494,40 @@ "description": "line drop compensation reactance" } ] + }, + { + "name": "GenericCurrentSensorInput", + "base": "SensorInput", + "attributes": [ + { + "data_type": "AngleMeasurementType", + "names": "angle_measurement_type", + "description": "type of angle measurement" + }, + { + "data_type": "double", + "names": [ + "i_sigma", + "i_angle_sigma" + ], + "description": "sigma of error margin of apparent power measurement" + } + ] + }, + { + "name": "CurrentSensorInput", + "base": "GenericCurrentSensorInput", + "is_template": true, + "attributes": [ + { + "data_type": "RealValue", + "names": [ + "i_measured", + "i_angle_measured" + ], + "description": "measured current and current angle" + } + ] } ] } \ No newline at end of file diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/input.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/input.hpp index ec9eaed24..87c7a7d4e 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/input.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/input.hpp @@ -444,6 +444,50 @@ struct TransformerTapRegulatorInput { operator RegulatorInput const&() const { return reinterpret_cast(*this); } }; +struct GenericCurrentSensorInput { + ID id{na_IntID}; // ID of the object + ID measured_object{na_IntID}; // ID of the measured object + AngleMeasurementType angle_measurement_type{static_cast(na_IntS)}; // type of angle measurement + double i_sigma{nan}; // sigma of error margin of apparent power measurement + double i_angle_sigma{nan}; // sigma of error margin of apparent power measurement + + // implicit conversions to BaseInput + operator BaseInput&() { return reinterpret_cast(*this); } + operator BaseInput const&() const { return reinterpret_cast(*this); } + + // implicit conversions to SensorInput + operator SensorInput&() { return reinterpret_cast(*this); } + operator SensorInput const&() const { return reinterpret_cast(*this); } +}; + +template +struct CurrentSensorInput { + using sym = sym_type; + + ID id{na_IntID}; // ID of the object + ID measured_object{na_IntID}; // ID of the measured object + AngleMeasurementType angle_measurement_type{static_cast(na_IntS)}; // type of angle measurement + double i_sigma{nan}; // sigma of error margin of apparent power measurement + double i_angle_sigma{nan}; // sigma of error margin of apparent power measurement + RealValue i_measured{nan}; // measured current and current angle + RealValue i_angle_measured{nan}; // measured current and current angle + + // implicit conversions to BaseInput + operator BaseInput&() { return reinterpret_cast(*this); } + operator BaseInput const&() const { return reinterpret_cast(*this); } + + // implicit conversions to SensorInput + operator SensorInput&() { return reinterpret_cast(*this); } + operator SensorInput const&() const { return reinterpret_cast(*this); } + + // implicit conversions to GenericCurrentSensorInput + operator GenericCurrentSensorInput&() { return reinterpret_cast(*this); } + operator GenericCurrentSensorInput const&() const { return reinterpret_cast(*this); } +}; + +using SymCurrentSensorInput = CurrentSensorInput; +using AsymCurrentSensorInput = CurrentSensorInput; + } // namespace power_grid_model diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/meta_gen/input.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/meta_gen/input.hpp index 7cca2754f..f20333f27 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/meta_gen/input.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/meta_gen/input.hpp @@ -396,6 +396,36 @@ struct get_attributes_list { }; }; +template<> +struct get_attributes_list { + static constexpr std::array value{ + // all attributes including base class + + meta_data_gen::get_meta_attribute<&GenericCurrentSensorInput::id>(offsetof(GenericCurrentSensorInput, id), "id"), + meta_data_gen::get_meta_attribute<&GenericCurrentSensorInput::measured_object>(offsetof(GenericCurrentSensorInput, measured_object), "measured_object"), + meta_data_gen::get_meta_attribute<&GenericCurrentSensorInput::angle_measurement_type>(offsetof(GenericCurrentSensorInput, angle_measurement_type), "angle_measurement_type"), + meta_data_gen::get_meta_attribute<&GenericCurrentSensorInput::i_sigma>(offsetof(GenericCurrentSensorInput, i_sigma), "i_sigma"), + meta_data_gen::get_meta_attribute<&GenericCurrentSensorInput::i_angle_sigma>(offsetof(GenericCurrentSensorInput, i_angle_sigma), "i_angle_sigma"), + }; +}; + +template +struct get_attributes_list> { + using sym = sym_type; + + static constexpr std::array value{ + // all attributes including base class + + meta_data_gen::get_meta_attribute<&CurrentSensorInput::id>(offsetof(CurrentSensorInput, id), "id"), + meta_data_gen::get_meta_attribute<&CurrentSensorInput::measured_object>(offsetof(CurrentSensorInput, measured_object), "measured_object"), + meta_data_gen::get_meta_attribute<&CurrentSensorInput::angle_measurement_type>(offsetof(CurrentSensorInput, angle_measurement_type), "angle_measurement_type"), + meta_data_gen::get_meta_attribute<&CurrentSensorInput::i_sigma>(offsetof(CurrentSensorInput, i_sigma), "i_sigma"), + meta_data_gen::get_meta_attribute<&CurrentSensorInput::i_angle_sigma>(offsetof(CurrentSensorInput, i_angle_sigma), "i_angle_sigma"), + meta_data_gen::get_meta_attribute<&CurrentSensorInput::i_measured>(offsetof(CurrentSensorInput, i_measured), "i_measured"), + meta_data_gen::get_meta_attribute<&CurrentSensorInput::i_angle_measured>(offsetof(CurrentSensorInput, i_angle_measured), "i_angle_measured"), + }; +}; + diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/static_asserts/input.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/static_asserts/input.hpp index ee2288a36..5c2334794 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/static_asserts/input.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/static_asserts/input.hpp @@ -517,6 +517,116 @@ static_assert(offsetof(TransformerTapRegulatorInput, id) == offsetof(RegulatorIn static_assert(offsetof(TransformerTapRegulatorInput, regulated_object) == offsetof(RegulatorInput, regulated_object)); static_assert(offsetof(TransformerTapRegulatorInput, status) == offsetof(RegulatorInput, status)); +// static asserts for GenericCurrentSensorInput +static_assert(std::is_standard_layout_v); +// static asserts for conversion of GenericCurrentSensorInput to BaseInput +static_assert(std::alignment_of_v >= std::alignment_of_v); +static_assert(std::same_as); +static_assert(offsetof(GenericCurrentSensorInput, id) == offsetof(BaseInput, id)); +// static asserts for conversion of GenericCurrentSensorInput to SensorInput +static_assert(std::alignment_of_v >= std::alignment_of_v); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(offsetof(GenericCurrentSensorInput, id) == offsetof(SensorInput, id)); +static_assert(offsetof(GenericCurrentSensorInput, measured_object) == offsetof(SensorInput, measured_object)); + +// static asserts for CurrentSensorInput +static_assert(std::is_standard_layout_v>); +// static asserts for conversion of CurrentSensorInput to BaseInput +static_assert(std::alignment_of_v> >= std::alignment_of_v); +static_assert(std::same_as::id), decltype(BaseInput::id)>); +static_assert(offsetof(CurrentSensorInput, id) == offsetof(BaseInput, id)); +// static asserts for conversion of CurrentSensorInput to SensorInput +static_assert(std::alignment_of_v> >= std::alignment_of_v); +static_assert(std::same_as::id), decltype(SensorInput::id)>); +static_assert(std::same_as::measured_object), decltype(SensorInput::measured_object)>); +static_assert(offsetof(CurrentSensorInput, id) == offsetof(SensorInput, id)); +static_assert(offsetof(CurrentSensorInput, measured_object) == offsetof(SensorInput, measured_object)); +// static asserts for conversion of CurrentSensorInput to GenericCurrentSensorInput +static_assert(std::alignment_of_v> >= std::alignment_of_v); +static_assert(std::same_as::id), decltype(GenericCurrentSensorInput::id)>); +static_assert(std::same_as::measured_object), decltype(GenericCurrentSensorInput::measured_object)>); +static_assert(std::same_as::angle_measurement_type), decltype(GenericCurrentSensorInput::angle_measurement_type)>); +static_assert(std::same_as::i_sigma), decltype(GenericCurrentSensorInput::i_sigma)>); +static_assert(std::same_as::i_angle_sigma), decltype(GenericCurrentSensorInput::i_angle_sigma)>); +static_assert(offsetof(CurrentSensorInput, id) == offsetof(GenericCurrentSensorInput, id)); +static_assert(offsetof(CurrentSensorInput, measured_object) == offsetof(GenericCurrentSensorInput, measured_object)); +static_assert(offsetof(CurrentSensorInput, angle_measurement_type) == offsetof(GenericCurrentSensorInput, angle_measurement_type)); +static_assert(offsetof(CurrentSensorInput, i_sigma) == offsetof(GenericCurrentSensorInput, i_sigma)); +static_assert(offsetof(CurrentSensorInput, i_angle_sigma) == offsetof(GenericCurrentSensorInput, i_angle_sigma)); +// static asserts for CurrentSensorInput +static_assert(std::is_standard_layout_v>); +// static asserts for conversion of CurrentSensorInput to BaseInput +static_assert(std::alignment_of_v> >= std::alignment_of_v); +static_assert(std::same_as::id), decltype(BaseInput::id)>); +static_assert(offsetof(CurrentSensorInput, id) == offsetof(BaseInput, id)); +// static asserts for conversion of CurrentSensorInput to SensorInput +static_assert(std::alignment_of_v> >= std::alignment_of_v); +static_assert(std::same_as::id), decltype(SensorInput::id)>); +static_assert(std::same_as::measured_object), decltype(SensorInput::measured_object)>); +static_assert(offsetof(CurrentSensorInput, id) == offsetof(SensorInput, id)); +static_assert(offsetof(CurrentSensorInput, measured_object) == offsetof(SensorInput, measured_object)); +// static asserts for conversion of CurrentSensorInput to GenericCurrentSensorInput +static_assert(std::alignment_of_v> >= std::alignment_of_v); +static_assert(std::same_as::id), decltype(GenericCurrentSensorInput::id)>); +static_assert(std::same_as::measured_object), decltype(GenericCurrentSensorInput::measured_object)>); +static_assert(std::same_as::angle_measurement_type), decltype(GenericCurrentSensorInput::angle_measurement_type)>); +static_assert(std::same_as::i_sigma), decltype(GenericCurrentSensorInput::i_sigma)>); +static_assert(std::same_as::i_angle_sigma), decltype(GenericCurrentSensorInput::i_angle_sigma)>); +static_assert(offsetof(CurrentSensorInput, id) == offsetof(GenericCurrentSensorInput, id)); +static_assert(offsetof(CurrentSensorInput, measured_object) == offsetof(GenericCurrentSensorInput, measured_object)); +static_assert(offsetof(CurrentSensorInput, angle_measurement_type) == offsetof(GenericCurrentSensorInput, angle_measurement_type)); +static_assert(offsetof(CurrentSensorInput, i_sigma) == offsetof(GenericCurrentSensorInput, i_sigma)); +static_assert(offsetof(CurrentSensorInput, i_angle_sigma) == offsetof(GenericCurrentSensorInput, i_angle_sigma)); +// static asserts for SymCurrentSensorInput +static_assert(std::is_standard_layout_v); +// static asserts for conversion of SymCurrentSensorInput to BaseInput +static_assert(std::alignment_of_v >= std::alignment_of_v); +static_assert(std::same_as); +static_assert(offsetof(SymCurrentSensorInput, id) == offsetof(BaseInput, id)); +// static asserts for conversion of SymCurrentSensorInput to SensorInput +static_assert(std::alignment_of_v >= std::alignment_of_v); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(offsetof(SymCurrentSensorInput, id) == offsetof(SensorInput, id)); +static_assert(offsetof(SymCurrentSensorInput, measured_object) == offsetof(SensorInput, measured_object)); +// static asserts for conversion of SymCurrentSensorInput to GenericCurrentSensorInput +static_assert(std::alignment_of_v >= std::alignment_of_v); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(offsetof(SymCurrentSensorInput, id) == offsetof(GenericCurrentSensorInput, id)); +static_assert(offsetof(SymCurrentSensorInput, measured_object) == offsetof(GenericCurrentSensorInput, measured_object)); +static_assert(offsetof(SymCurrentSensorInput, angle_measurement_type) == offsetof(GenericCurrentSensorInput, angle_measurement_type)); +static_assert(offsetof(SymCurrentSensorInput, i_sigma) == offsetof(GenericCurrentSensorInput, i_sigma)); +static_assert(offsetof(SymCurrentSensorInput, i_angle_sigma) == offsetof(GenericCurrentSensorInput, i_angle_sigma)); +// static asserts for AsymCurrentSensorInput +static_assert(std::is_standard_layout_v); +// static asserts for conversion of AsymCurrentSensorInput to BaseInput +static_assert(std::alignment_of_v >= std::alignment_of_v); +static_assert(std::same_as); +static_assert(offsetof(AsymCurrentSensorInput, id) == offsetof(BaseInput, id)); +// static asserts for conversion of AsymCurrentSensorInput to SensorInput +static_assert(std::alignment_of_v >= std::alignment_of_v); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(offsetof(AsymCurrentSensorInput, id) == offsetof(SensorInput, id)); +static_assert(offsetof(AsymCurrentSensorInput, measured_object) == offsetof(SensorInput, measured_object)); +// static asserts for conversion of AsymCurrentSensorInput to GenericCurrentSensorInput +static_assert(std::alignment_of_v >= std::alignment_of_v); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(std::same_as); +static_assert(offsetof(AsymCurrentSensorInput, id) == offsetof(GenericCurrentSensorInput, id)); +static_assert(offsetof(AsymCurrentSensorInput, measured_object) == offsetof(GenericCurrentSensorInput, measured_object)); +static_assert(offsetof(AsymCurrentSensorInput, angle_measurement_type) == offsetof(GenericCurrentSensorInput, angle_measurement_type)); +static_assert(offsetof(AsymCurrentSensorInput, i_sigma) == offsetof(GenericCurrentSensorInput, i_sigma)); +static_assert(offsetof(AsymCurrentSensorInput, i_angle_sigma) == offsetof(GenericCurrentSensorInput, i_angle_sigma)); + } // namespace power_grid_model::test