Skip to content

Commit

Permalink
current sensor input
Browse files Browse the repository at this point in the history
Signed-off-by: petersalemink95 <[email protected]>
  • Loading branch information
petersalemink95 committed Dec 24, 2024
1 parent 66ce29b commit 411f160
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 0 deletions.
34 changes: 34 additions & 0 deletions code_generation/data/attribute_classes/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -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<sym>",
"names": [
"i_measured",
"i_angle_measured"
],
"description": "measured current and current angle"
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,50 @@ struct TransformerTapRegulatorInput {
operator RegulatorInput const&() const { return reinterpret_cast<RegulatorInput const&>(*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<AngleMeasurementType>(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<BaseInput&>(*this); }
operator BaseInput const&() const { return reinterpret_cast<BaseInput const&>(*this); }

// implicit conversions to SensorInput
operator SensorInput&() { return reinterpret_cast<SensorInput&>(*this); }
operator SensorInput const&() const { return reinterpret_cast<SensorInput const&>(*this); }
};

template <symmetry_tag sym_type>
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<AngleMeasurementType>(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<sym> i_measured{nan}; // measured current and current angle
RealValue<sym> i_angle_measured{nan}; // measured current and current angle

// implicit conversions to BaseInput
operator BaseInput&() { return reinterpret_cast<BaseInput&>(*this); }
operator BaseInput const&() const { return reinterpret_cast<BaseInput const&>(*this); }

// implicit conversions to SensorInput
operator SensorInput&() { return reinterpret_cast<SensorInput&>(*this); }
operator SensorInput const&() const { return reinterpret_cast<SensorInput const&>(*this); }

// implicit conversions to GenericCurrentSensorInput
operator GenericCurrentSensorInput&() { return reinterpret_cast<GenericCurrentSensorInput&>(*this); }
operator GenericCurrentSensorInput const&() const { return reinterpret_cast<GenericCurrentSensorInput const&>(*this); }
};

using SymCurrentSensorInput = CurrentSensorInput<symmetric_t>;
using AsymCurrentSensorInput = CurrentSensorInput<asymmetric_t>;



} // namespace power_grid_model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,36 @@ struct get_attributes_list<TransformerTapRegulatorInput> {
};
};

template<>
struct get_attributes_list<GenericCurrentSensorInput> {
static constexpr std::array<MetaAttribute, 5> 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 <symmetry_tag sym_type>
struct get_attributes_list<CurrentSensorInput<sym_type>> {
using sym = sym_type;

static constexpr std::array<MetaAttribute, 7> value{
// all attributes including base class

meta_data_gen::get_meta_attribute<&CurrentSensorInput<sym>::id>(offsetof(CurrentSensorInput<sym>, id), "id"),
meta_data_gen::get_meta_attribute<&CurrentSensorInput<sym>::measured_object>(offsetof(CurrentSensorInput<sym>, measured_object), "measured_object"),
meta_data_gen::get_meta_attribute<&CurrentSensorInput<sym>::angle_measurement_type>(offsetof(CurrentSensorInput<sym>, angle_measurement_type), "angle_measurement_type"),
meta_data_gen::get_meta_attribute<&CurrentSensorInput<sym>::i_sigma>(offsetof(CurrentSensorInput<sym>, i_sigma), "i_sigma"),
meta_data_gen::get_meta_attribute<&CurrentSensorInput<sym>::i_angle_sigma>(offsetof(CurrentSensorInput<sym>, i_angle_sigma), "i_angle_sigma"),
meta_data_gen::get_meta_attribute<&CurrentSensorInput<sym>::i_measured>(offsetof(CurrentSensorInput<sym>, i_measured), "i_measured"),
meta_data_gen::get_meta_attribute<&CurrentSensorInput<sym>::i_angle_measured>(offsetof(CurrentSensorInput<sym>, i_angle_measured), "i_angle_measured"),
};
};




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenericCurrentSensorInput>);
// static asserts for conversion of GenericCurrentSensorInput to BaseInput
static_assert(std::alignment_of_v<GenericCurrentSensorInput> >= std::alignment_of_v<SensorInput>);
static_assert(std::same_as<decltype(GenericCurrentSensorInput::id), decltype(BaseInput::id)>);
static_assert(offsetof(GenericCurrentSensorInput, id) == offsetof(BaseInput, id));
// static asserts for conversion of GenericCurrentSensorInput to SensorInput
static_assert(std::alignment_of_v<GenericCurrentSensorInput> >= std::alignment_of_v<SensorInput>);
static_assert(std::same_as<decltype(GenericCurrentSensorInput::id), decltype(SensorInput::id)>);
static_assert(std::same_as<decltype(GenericCurrentSensorInput::measured_object), decltype(SensorInput::measured_object)>);
static_assert(offsetof(GenericCurrentSensorInput, id) == offsetof(SensorInput, id));
static_assert(offsetof(GenericCurrentSensorInput, measured_object) == offsetof(SensorInput, measured_object));

// static asserts for CurrentSensorInput<symmetric_t>
static_assert(std::is_standard_layout_v<CurrentSensorInput<symmetric_t>>);
// static asserts for conversion of CurrentSensorInput<symmetric_t> to BaseInput
static_assert(std::alignment_of_v<CurrentSensorInput<symmetric_t>> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(CurrentSensorInput<symmetric_t>::id), decltype(BaseInput::id)>);
static_assert(offsetof(CurrentSensorInput<symmetric_t>, id) == offsetof(BaseInput, id));
// static asserts for conversion of CurrentSensorInput<symmetric_t> to SensorInput
static_assert(std::alignment_of_v<CurrentSensorInput<symmetric_t>> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(CurrentSensorInput<symmetric_t>::id), decltype(SensorInput::id)>);
static_assert(std::same_as<decltype(CurrentSensorInput<symmetric_t>::measured_object), decltype(SensorInput::measured_object)>);
static_assert(offsetof(CurrentSensorInput<symmetric_t>, id) == offsetof(SensorInput, id));
static_assert(offsetof(CurrentSensorInput<symmetric_t>, measured_object) == offsetof(SensorInput, measured_object));
// static asserts for conversion of CurrentSensorInput<symmetric_t> to GenericCurrentSensorInput
static_assert(std::alignment_of_v<CurrentSensorInput<symmetric_t>> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(CurrentSensorInput<symmetric_t>::id), decltype(GenericCurrentSensorInput::id)>);
static_assert(std::same_as<decltype(CurrentSensorInput<symmetric_t>::measured_object), decltype(GenericCurrentSensorInput::measured_object)>);
static_assert(std::same_as<decltype(CurrentSensorInput<symmetric_t>::angle_measurement_type), decltype(GenericCurrentSensorInput::angle_measurement_type)>);
static_assert(std::same_as<decltype(CurrentSensorInput<symmetric_t>::i_sigma), decltype(GenericCurrentSensorInput::i_sigma)>);
static_assert(std::same_as<decltype(CurrentSensorInput<symmetric_t>::i_angle_sigma), decltype(GenericCurrentSensorInput::i_angle_sigma)>);
static_assert(offsetof(CurrentSensorInput<symmetric_t>, id) == offsetof(GenericCurrentSensorInput, id));
static_assert(offsetof(CurrentSensorInput<symmetric_t>, measured_object) == offsetof(GenericCurrentSensorInput, measured_object));
static_assert(offsetof(CurrentSensorInput<symmetric_t>, angle_measurement_type) == offsetof(GenericCurrentSensorInput, angle_measurement_type));
static_assert(offsetof(CurrentSensorInput<symmetric_t>, i_sigma) == offsetof(GenericCurrentSensorInput, i_sigma));
static_assert(offsetof(CurrentSensorInput<symmetric_t>, i_angle_sigma) == offsetof(GenericCurrentSensorInput, i_angle_sigma));
// static asserts for CurrentSensorInput<asymmetric_t>
static_assert(std::is_standard_layout_v<CurrentSensorInput<asymmetric_t>>);
// static asserts for conversion of CurrentSensorInput<asymmetric_t> to BaseInput
static_assert(std::alignment_of_v<CurrentSensorInput<asymmetric_t>> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(CurrentSensorInput<asymmetric_t>::id), decltype(BaseInput::id)>);
static_assert(offsetof(CurrentSensorInput<asymmetric_t>, id) == offsetof(BaseInput, id));
// static asserts for conversion of CurrentSensorInput<asymmetric_t> to SensorInput
static_assert(std::alignment_of_v<CurrentSensorInput<asymmetric_t>> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(CurrentSensorInput<asymmetric_t>::id), decltype(SensorInput::id)>);
static_assert(std::same_as<decltype(CurrentSensorInput<asymmetric_t>::measured_object), decltype(SensorInput::measured_object)>);
static_assert(offsetof(CurrentSensorInput<asymmetric_t>, id) == offsetof(SensorInput, id));
static_assert(offsetof(CurrentSensorInput<asymmetric_t>, measured_object) == offsetof(SensorInput, measured_object));
// static asserts for conversion of CurrentSensorInput<asymmetric_t> to GenericCurrentSensorInput
static_assert(std::alignment_of_v<CurrentSensorInput<asymmetric_t>> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(CurrentSensorInput<asymmetric_t>::id), decltype(GenericCurrentSensorInput::id)>);
static_assert(std::same_as<decltype(CurrentSensorInput<asymmetric_t>::measured_object), decltype(GenericCurrentSensorInput::measured_object)>);
static_assert(std::same_as<decltype(CurrentSensorInput<asymmetric_t>::angle_measurement_type), decltype(GenericCurrentSensorInput::angle_measurement_type)>);
static_assert(std::same_as<decltype(CurrentSensorInput<asymmetric_t>::i_sigma), decltype(GenericCurrentSensorInput::i_sigma)>);
static_assert(std::same_as<decltype(CurrentSensorInput<asymmetric_t>::i_angle_sigma), decltype(GenericCurrentSensorInput::i_angle_sigma)>);
static_assert(offsetof(CurrentSensorInput<asymmetric_t>, id) == offsetof(GenericCurrentSensorInput, id));
static_assert(offsetof(CurrentSensorInput<asymmetric_t>, measured_object) == offsetof(GenericCurrentSensorInput, measured_object));
static_assert(offsetof(CurrentSensorInput<asymmetric_t>, angle_measurement_type) == offsetof(GenericCurrentSensorInput, angle_measurement_type));
static_assert(offsetof(CurrentSensorInput<asymmetric_t>, i_sigma) == offsetof(GenericCurrentSensorInput, i_sigma));
static_assert(offsetof(CurrentSensorInput<asymmetric_t>, i_angle_sigma) == offsetof(GenericCurrentSensorInput, i_angle_sigma));
// static asserts for SymCurrentSensorInput
static_assert(std::is_standard_layout_v<SymCurrentSensorInput>);
// static asserts for conversion of SymCurrentSensorInput to BaseInput
static_assert(std::alignment_of_v<SymCurrentSensorInput> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(SymCurrentSensorInput::id), decltype(BaseInput::id)>);
static_assert(offsetof(SymCurrentSensorInput, id) == offsetof(BaseInput, id));
// static asserts for conversion of SymCurrentSensorInput to SensorInput
static_assert(std::alignment_of_v<SymCurrentSensorInput> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(SymCurrentSensorInput::id), decltype(SensorInput::id)>);
static_assert(std::same_as<decltype(SymCurrentSensorInput::measured_object), decltype(SensorInput::measured_object)>);
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<SymCurrentSensorInput> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(SymCurrentSensorInput::id), decltype(GenericCurrentSensorInput::id)>);
static_assert(std::same_as<decltype(SymCurrentSensorInput::measured_object), decltype(GenericCurrentSensorInput::measured_object)>);
static_assert(std::same_as<decltype(SymCurrentSensorInput::angle_measurement_type), decltype(GenericCurrentSensorInput::angle_measurement_type)>);
static_assert(std::same_as<decltype(SymCurrentSensorInput::i_sigma), decltype(GenericCurrentSensorInput::i_sigma)>);
static_assert(std::same_as<decltype(SymCurrentSensorInput::i_angle_sigma), decltype(GenericCurrentSensorInput::i_angle_sigma)>);
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<AsymCurrentSensorInput>);
// static asserts for conversion of AsymCurrentSensorInput to BaseInput
static_assert(std::alignment_of_v<AsymCurrentSensorInput> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(AsymCurrentSensorInput::id), decltype(BaseInput::id)>);
static_assert(offsetof(AsymCurrentSensorInput, id) == offsetof(BaseInput, id));
// static asserts for conversion of AsymCurrentSensorInput to SensorInput
static_assert(std::alignment_of_v<AsymCurrentSensorInput> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(AsymCurrentSensorInput::id), decltype(SensorInput::id)>);
static_assert(std::same_as<decltype(AsymCurrentSensorInput::measured_object), decltype(SensorInput::measured_object)>);
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<AsymCurrentSensorInput> >= std::alignment_of_v<GenericCurrentSensorInput>);
static_assert(std::same_as<decltype(AsymCurrentSensorInput::id), decltype(GenericCurrentSensorInput::id)>);
static_assert(std::same_as<decltype(AsymCurrentSensorInput::measured_object), decltype(GenericCurrentSensorInput::measured_object)>);
static_assert(std::same_as<decltype(AsymCurrentSensorInput::angle_measurement_type), decltype(GenericCurrentSensorInput::angle_measurement_type)>);
static_assert(std::same_as<decltype(AsymCurrentSensorInput::i_sigma), decltype(GenericCurrentSensorInput::i_sigma)>);
static_assert(std::same_as<decltype(AsymCurrentSensorInput::i_angle_sigma), decltype(GenericCurrentSensorInput::i_angle_sigma)>);
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
Expand Down

0 comments on commit 411f160

Please sign in to comment.