Skip to content

Commit

Permalink
current sensor output
Browse files Browse the repository at this point in the history
Signed-off-by: petersalemink95 <peter.salemink95@gmail.com>
  • Loading branch information
petersalemink95 committed Dec 24, 2024
1 parent 51c972d commit 8480a5f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
15 changes: 15 additions & 0 deletions code_generation/data/attribute_classes/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,21 @@
"base": "BaseOutput",
"is_template": false,
"attributes": []
},
{
"name": "CurrentSensorOutput",
"base": "BaseOutput",
"is_template": true,
"attributes": [
{
"data_type": "RealValue<sym>",
"names": [
"i_residual",
"i_angle_residual"
],
"description": "deviation between the measured value and calculated value"
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ struct get_attributes_list<RegulatorShortCircuitOutput> {
};
};

template <symmetry_tag sym_type>
struct get_attributes_list<CurrentSensorOutput<sym_type>> {
using sym = sym_type;

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

meta_data_gen::get_meta_attribute<&CurrentSensorOutput<sym>::id>(offsetof(CurrentSensorOutput<sym>, id), "id"),
meta_data_gen::get_meta_attribute<&CurrentSensorOutput<sym>::energized>(offsetof(CurrentSensorOutput<sym>, energized), "energized"),
meta_data_gen::get_meta_attribute<&CurrentSensorOutput<sym>::i_residual>(offsetof(CurrentSensorOutput<sym>, i_residual), "i_residual"),
meta_data_gen::get_meta_attribute<&CurrentSensorOutput<sym>::i_angle_residual>(offsetof(CurrentSensorOutput<sym>, i_angle_residual), "i_angle_residual"),
};
};




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,23 @@ struct RegulatorShortCircuitOutput {
operator BaseOutput const&() const { return reinterpret_cast<BaseOutput const&>(*this); }
};

template <symmetry_tag sym_type>
struct CurrentSensorOutput {
using sym = sym_type;

ID id{na_IntID}; // ID of the object
IntS energized{na_IntS}; // whether the object is energized
RealValue<sym> i_residual{nan}; // deviation between the measured value and calculated value
RealValue<sym> i_angle_residual{nan}; // deviation between the measured value and calculated value

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

using SymCurrentSensorOutput = CurrentSensorOutput<symmetric_t>;
using AsymCurrentSensorOutput = CurrentSensorOutput<asymmetric_t>;



} // namespace power_grid_model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,39 @@ static_assert(std::same_as<decltype(RegulatorShortCircuitOutput::energized), dec
static_assert(offsetof(RegulatorShortCircuitOutput, id) == offsetof(BaseOutput, id));
static_assert(offsetof(RegulatorShortCircuitOutput, energized) == offsetof(BaseOutput, energized));

// static asserts for CurrentSensorOutput<symmetric_t>
static_assert(std::is_standard_layout_v<CurrentSensorOutput<symmetric_t>>);
// static asserts for conversion of CurrentSensorOutput<symmetric_t> to BaseOutput
static_assert(std::alignment_of_v<CurrentSensorOutput<symmetric_t>> >= std::alignment_of_v<BaseOutput>);
static_assert(std::same_as<decltype(CurrentSensorOutput<symmetric_t>::id), decltype(BaseOutput::id)>);
static_assert(std::same_as<decltype(CurrentSensorOutput<symmetric_t>::energized), decltype(BaseOutput::energized)>);
static_assert(offsetof(CurrentSensorOutput<symmetric_t>, id) == offsetof(BaseOutput, id));
static_assert(offsetof(CurrentSensorOutput<symmetric_t>, energized) == offsetof(BaseOutput, energized));
// static asserts for CurrentSensorOutput<asymmetric_t>
static_assert(std::is_standard_layout_v<CurrentSensorOutput<asymmetric_t>>);
// static asserts for conversion of CurrentSensorOutput<asymmetric_t> to BaseOutput
static_assert(std::alignment_of_v<CurrentSensorOutput<asymmetric_t>> >= std::alignment_of_v<BaseOutput>);
static_assert(std::same_as<decltype(CurrentSensorOutput<asymmetric_t>::id), decltype(BaseOutput::id)>);
static_assert(std::same_as<decltype(CurrentSensorOutput<asymmetric_t>::energized), decltype(BaseOutput::energized)>);
static_assert(offsetof(CurrentSensorOutput<asymmetric_t>, id) == offsetof(BaseOutput, id));
static_assert(offsetof(CurrentSensorOutput<asymmetric_t>, energized) == offsetof(BaseOutput, energized));
// static asserts for SymCurrentSensorOutput
static_assert(std::is_standard_layout_v<SymCurrentSensorOutput>);
// static asserts for conversion of SymCurrentSensorOutput to BaseOutput
static_assert(std::alignment_of_v<SymCurrentSensorOutput> >= std::alignment_of_v<BaseOutput>);
static_assert(std::same_as<decltype(SymCurrentSensorOutput::id), decltype(BaseOutput::id)>);
static_assert(std::same_as<decltype(SymCurrentSensorOutput::energized), decltype(BaseOutput::energized)>);
static_assert(offsetof(SymCurrentSensorOutput, id) == offsetof(BaseOutput, id));
static_assert(offsetof(SymCurrentSensorOutput, energized) == offsetof(BaseOutput, energized));
// static asserts for AsymCurrentSensorOutput
static_assert(std::is_standard_layout_v<AsymCurrentSensorOutput>);
// static asserts for conversion of AsymCurrentSensorOutput to BaseOutput
static_assert(std::alignment_of_v<AsymCurrentSensorOutput> >= std::alignment_of_v<BaseOutput>);
static_assert(std::same_as<decltype(AsymCurrentSensorOutput::id), decltype(BaseOutput::id)>);
static_assert(std::same_as<decltype(AsymCurrentSensorOutput::energized), decltype(BaseOutput::energized)>);
static_assert(offsetof(AsymCurrentSensorOutput, id) == offsetof(BaseOutput, id));
static_assert(offsetof(AsymCurrentSensorOutput, energized) == offsetof(BaseOutput, energized));



} // namespace power_grid_model::test
Expand Down

0 comments on commit 8480a5f

Please sign in to comment.