Skip to content

Commit 764a43f

Browse files
committed
Added implementation for asym_line input
1 parent d6ca3d7 commit 764a43f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1731
-7
lines changed

code_generation/data/attribute_classes/input.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,51 @@
127127
}
128128
]
129129
},
130+
{
131+
"name": "AsymLineInput",
132+
"base": "BranchInput",
133+
"attributes": [
134+
{
135+
"data_type": "double",
136+
"names": [
137+
"r_aa",
138+
"r_ba",
139+
"r_bb",
140+
"r_ca",
141+
"r_cb",
142+
"r_cc",
143+
"r_na",
144+
"r_nb",
145+
"r_nc",
146+
"r_nn",
147+
"x_aa",
148+
"x_ba",
149+
"x_bb",
150+
"x_ca",
151+
"x_cb",
152+
"x_cc",
153+
"x_na",
154+
"x_nb",
155+
"x_nc",
156+
"x_nn",
157+
"c_aa",
158+
"c_ba",
159+
"c_bb",
160+
"c_ca",
161+
"c_cb",
162+
"c_cc",
163+
"c0",
164+
"c1"
165+
],
166+
"description": "Lower triangle matrix values for R, X and C matrices"
167+
},
168+
{
169+
"data_type": "double",
170+
"names": "i_n",
171+
"description": "rated current"
172+
}
173+
]
174+
},
130175
{
131176
"name": "GenericBranchInput",
132177
"base": "BranchInput",

code_generation/data/dataset_class_maps/dataset_definitions.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"names": ["line"],
1313
"class_name": "LineInput"
1414
},
15+
{
16+
"names": ["asym_line"],
17+
"class_name": "AsymLineInput"
18+
},
1519
{
1620
"names": ["link"],
1721
"class_name": "LinkInput"
@@ -71,7 +75,7 @@
7175
"class_name": "NodeOutput"
7276
},
7377
{
74-
"names": ["line", "link", "transformer", "generic_branch"],
78+
"names": ["line", "link", "transformer", "generic_branch", "asym_line"],
7579
"class_name": "BranchOutput"
7680
},
7781
{
@@ -116,6 +120,10 @@
116120
"names": ["line"],
117121
"class_name": "BranchUpdate"
118122
},
123+
{
124+
"names": ["asym_line"],
125+
"class_name": "BranchUpdate"
126+
},
119127
{
120128
"names": ["link"],
121129
"class_name": "BranchUpdate"
@@ -171,7 +179,7 @@
171179
"class_name": "NodeShortCircuitOutput"
172180
},
173181
{
174-
"names": ["line", "link", "transformer"],
182+
"names": ["line", "link", "transformer", "asym_line"],
175183
"class_name": "BranchShortCircuitOutput"
176184
},
177185
{

power_grid_model_c/power_grid_model/include/power_grid_model/all_components.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "component/fault.hpp"
1414
#include "component/generic_branch.hpp"
1515
#include "component/line.hpp"
16+
#include "component/asym_line.hpp"
1617
#include "component/link.hpp"
1718
#include "component/load_gen.hpp"
1819
#include "component/node.hpp"
@@ -28,7 +29,7 @@
2829
namespace power_grid_model {
2930

3031
using AllComponents =
31-
ComponentList<Node, Line, Link, GenericBranch, Transformer, ThreeWindingTransformer, Shunt, Source, SymGenerator,
32+
ComponentList<Node, Line, AsymLine, Link, GenericBranch, Transformer, ThreeWindingTransformer, Shunt, Source, SymGenerator,
3233
AsymGenerator, SymLoad, AsymLoad, SymPowerSensor, AsymPowerSensor, SymVoltageSensor,
3334
AsymVoltageSensor, SymCurrentSensor, AsymCurrentSensor, Fault, TransformerTapRegulator>;
3435

power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/input.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,51 @@ struct LineInput {
9898
operator BranchInput const&() const { return reinterpret_cast<BranchInput const&>(*this); }
9999
};
100100

101+
struct AsymLineInput {
102+
ID id{na_IntID}; // ID of the object
103+
ID from_node{na_IntID}; // node IDs to which this branch is connected at both sides
104+
ID to_node{na_IntID}; // node IDs to which this branch is connected at both sides
105+
IntS from_status{na_IntS}; // whether the branch is connected at each side
106+
IntS to_status{na_IntS}; // whether the branch is connected at each side
107+
double r_aa{nan}; // Lower triangle matrix values for R, X and C matrices
108+
double r_ba{nan}; // Lower triangle matrix values for R, X and C matrices
109+
double r_bb{nan}; // Lower triangle matrix values for R, X and C matrices
110+
double r_ca{nan}; // Lower triangle matrix values for R, X and C matrices
111+
double r_cb{nan}; // Lower triangle matrix values for R, X and C matrices
112+
double r_cc{nan}; // Lower triangle matrix values for R, X and C matrices
113+
double r_na{nan}; // Lower triangle matrix values for R, X and C matrices
114+
double r_nb{nan}; // Lower triangle matrix values for R, X and C matrices
115+
double r_nc{nan}; // Lower triangle matrix values for R, X and C matrices
116+
double r_nn{nan}; // Lower triangle matrix values for R, X and C matrices
117+
double x_aa{nan}; // Lower triangle matrix values for R, X and C matrices
118+
double x_ba{nan}; // Lower triangle matrix values for R, X and C matrices
119+
double x_bb{nan}; // Lower triangle matrix values for R, X and C matrices
120+
double x_ca{nan}; // Lower triangle matrix values for R, X and C matrices
121+
double x_cb{nan}; // Lower triangle matrix values for R, X and C matrices
122+
double x_cc{nan}; // Lower triangle matrix values for R, X and C matrices
123+
double x_na{nan}; // Lower triangle matrix values for R, X and C matrices
124+
double x_nb{nan}; // Lower triangle matrix values for R, X and C matrices
125+
double x_nc{nan}; // Lower triangle matrix values for R, X and C matrices
126+
double x_nn{nan}; // Lower triangle matrix values for R, X and C matrices
127+
double c_aa{nan}; // Lower triangle matrix values for R, X and C matrices
128+
double c_ba{nan}; // Lower triangle matrix values for R, X and C matrices
129+
double c_bb{nan}; // Lower triangle matrix values for R, X and C matrices
130+
double c_ca{nan}; // Lower triangle matrix values for R, X and C matrices
131+
double c_cb{nan}; // Lower triangle matrix values for R, X and C matrices
132+
double c_cc{nan}; // Lower triangle matrix values for R, X and C matrices
133+
double c0{nan}; // Lower triangle matrix values for R, X and C matrices
134+
double c1{nan}; // Lower triangle matrix values for R, X and C matrices
135+
double i_n{nan}; // rated current
136+
137+
// implicit conversions to BaseInput
138+
operator BaseInput&() { return reinterpret_cast<BaseInput&>(*this); }
139+
operator BaseInput const&() const { return reinterpret_cast<BaseInput const&>(*this); }
140+
141+
// implicit conversions to BranchInput
142+
operator BranchInput&() { return reinterpret_cast<BranchInput&>(*this); }
143+
operator BranchInput const&() const { return reinterpret_cast<BranchInput const&>(*this); }
144+
};
145+
101146
struct GenericBranchInput {
102147
ID id{na_IntID}; // ID of the object
103148
ID from_node{na_IntID}; // node IDs to which this branch is connected at both sides

power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/meta_gen/input.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,48 @@ struct get_attributes_list<LineInput> {
111111
};
112112
};
113113

114+
template<>
115+
struct get_attributes_list<AsymLineInput> {
116+
static constexpr std::array<MetaAttribute, 34> value{
117+
// all attributes including base class
118+
119+
meta_data_gen::get_meta_attribute<&AsymLineInput::id>(offsetof(AsymLineInput, id), "id"),
120+
meta_data_gen::get_meta_attribute<&AsymLineInput::from_node>(offsetof(AsymLineInput, from_node), "from_node"),
121+
meta_data_gen::get_meta_attribute<&AsymLineInput::to_node>(offsetof(AsymLineInput, to_node), "to_node"),
122+
meta_data_gen::get_meta_attribute<&AsymLineInput::from_status>(offsetof(AsymLineInput, from_status), "from_status"),
123+
meta_data_gen::get_meta_attribute<&AsymLineInput::to_status>(offsetof(AsymLineInput, to_status), "to_status"),
124+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_aa>(offsetof(AsymLineInput, r_aa), "r_aa"),
125+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_ba>(offsetof(AsymLineInput, r_ba), "r_ba"),
126+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_bb>(offsetof(AsymLineInput, r_bb), "r_bb"),
127+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_ca>(offsetof(AsymLineInput, r_ca), "r_ca"),
128+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_cb>(offsetof(AsymLineInput, r_cb), "r_cb"),
129+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_cc>(offsetof(AsymLineInput, r_cc), "r_cc"),
130+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_na>(offsetof(AsymLineInput, r_na), "r_na"),
131+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_nb>(offsetof(AsymLineInput, r_nb), "r_nb"),
132+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_nc>(offsetof(AsymLineInput, r_nc), "r_nc"),
133+
meta_data_gen::get_meta_attribute<&AsymLineInput::r_nn>(offsetof(AsymLineInput, r_nn), "r_nn"),
134+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_aa>(offsetof(AsymLineInput, x_aa), "x_aa"),
135+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_ba>(offsetof(AsymLineInput, x_ba), "x_ba"),
136+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_bb>(offsetof(AsymLineInput, x_bb), "x_bb"),
137+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_ca>(offsetof(AsymLineInput, x_ca), "x_ca"),
138+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_cb>(offsetof(AsymLineInput, x_cb), "x_cb"),
139+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_cc>(offsetof(AsymLineInput, x_cc), "x_cc"),
140+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_na>(offsetof(AsymLineInput, x_na), "x_na"),
141+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_nb>(offsetof(AsymLineInput, x_nb), "x_nb"),
142+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_nc>(offsetof(AsymLineInput, x_nc), "x_nc"),
143+
meta_data_gen::get_meta_attribute<&AsymLineInput::x_nn>(offsetof(AsymLineInput, x_nn), "x_nn"),
144+
meta_data_gen::get_meta_attribute<&AsymLineInput::c_aa>(offsetof(AsymLineInput, c_aa), "c_aa"),
145+
meta_data_gen::get_meta_attribute<&AsymLineInput::c_ba>(offsetof(AsymLineInput, c_ba), "c_ba"),
146+
meta_data_gen::get_meta_attribute<&AsymLineInput::c_bb>(offsetof(AsymLineInput, c_bb), "c_bb"),
147+
meta_data_gen::get_meta_attribute<&AsymLineInput::c_ca>(offsetof(AsymLineInput, c_ca), "c_ca"),
148+
meta_data_gen::get_meta_attribute<&AsymLineInput::c_cb>(offsetof(AsymLineInput, c_cb), "c_cb"),
149+
meta_data_gen::get_meta_attribute<&AsymLineInput::c_cc>(offsetof(AsymLineInput, c_cc), "c_cc"),
150+
meta_data_gen::get_meta_attribute<&AsymLineInput::c0>(offsetof(AsymLineInput, c0), "c0"),
151+
meta_data_gen::get_meta_attribute<&AsymLineInput::c1>(offsetof(AsymLineInput, c1), "c1"),
152+
meta_data_gen::get_meta_attribute<&AsymLineInput::i_n>(offsetof(AsymLineInput, i_n), "i_n"),
153+
};
154+
};
155+
114156
template<>
115157
struct get_attributes_list<GenericBranchInput> {
116158
static constexpr std::array<MetaAttribute, 12> value{

power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/static_asserts/input.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ static_assert(offsetof(LineInput, to_node) == offsetof(BranchInput, to_node));
7070
static_assert(offsetof(LineInput, from_status) == offsetof(BranchInput, from_status));
7171
static_assert(offsetof(LineInput, to_status) == offsetof(BranchInput, to_status));
7272

73+
// static asserts for AsymLineInput
74+
static_assert(std::is_standard_layout_v<AsymLineInput>);
75+
// static asserts for conversion of AsymLineInput to BaseInput
76+
static_assert(std::alignment_of_v<AsymLineInput> >= std::alignment_of_v<BranchInput>);
77+
static_assert(std::same_as<decltype(AsymLineInput::id), decltype(BaseInput::id)>);
78+
static_assert(offsetof(AsymLineInput, id) == offsetof(BaseInput, id));
79+
// static asserts for conversion of AsymLineInput to BranchInput
80+
static_assert(std::alignment_of_v<AsymLineInput> >= std::alignment_of_v<BranchInput>);
81+
static_assert(std::same_as<decltype(AsymLineInput::id), decltype(BranchInput::id)>);
82+
static_assert(std::same_as<decltype(AsymLineInput::from_node), decltype(BranchInput::from_node)>);
83+
static_assert(std::same_as<decltype(AsymLineInput::to_node), decltype(BranchInput::to_node)>);
84+
static_assert(std::same_as<decltype(AsymLineInput::from_status), decltype(BranchInput::from_status)>);
85+
static_assert(std::same_as<decltype(AsymLineInput::to_status), decltype(BranchInput::to_status)>);
86+
static_assert(offsetof(AsymLineInput, id) == offsetof(BranchInput, id));
87+
static_assert(offsetof(AsymLineInput, from_node) == offsetof(BranchInput, from_node));
88+
static_assert(offsetof(AsymLineInput, to_node) == offsetof(BranchInput, to_node));
89+
static_assert(offsetof(AsymLineInput, from_status) == offsetof(BranchInput, from_status));
90+
static_assert(offsetof(AsymLineInput, to_status) == offsetof(BranchInput, to_status));
91+
7392
// static asserts for GenericBranchInput
7493
static_assert(std::is_standard_layout_v<GenericBranchInput>);
7594
// static asserts for conversion of GenericBranchInput to BaseInput
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2+
3+
#pragma once
4+
5+
#include "three_phase_tensor.hpp"
6+
7+
namespace power_grid_model {
8+
9+
inline DoubleComplex average_of_diagonal_of_matrix(const ComplexTensor<asymmetric_t> &matrix) {
10+
return (matrix(0,0) + matrix(1,1) + matrix(2,2)) / 3.0;
11+
}
12+
13+
inline DoubleComplex average_of_off_diagonal_of_matrix(const ComplexTensor<asymmetric_t> &matrix) {
14+
return (matrix(0,1) + matrix(1,2) + matrix(1,0) + matrix(1,2) + matrix(2,0) + matrix(2,1)) / 6.0;
15+
}
16+
17+
} // namespace power_grid_model

power_grid_model_c/power_grid_model/include/power_grid_model/common/three_phase_tensor.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace three_phase_tensor {
2222

2323
template <class T> using Eigen3Vector = Eigen::Array<T, 3, 1>;
2424
template <class T> using Eigen3Tensor = Eigen::Array<T, 3, 3, Eigen::ColMajor>;
25+
template <class T> using Eigen4Tensor = Eigen::Array<T, 4, 4, Eigen::ColMajor>;
2526
template <class T> using Eigen3DiagonalTensor = Eigen::DiagonalMatrix<T, 3>;
2627

2728
template <scalar_value T> class Vector : public Eigen3Vector<T> {
@@ -61,7 +62,8 @@ template <scalar_value T> class Tensor : public Eigen3Tensor<T> {
6162
// additional constructors
6263
explicit Tensor(T const& x) { (*this) << x, 0.0, 0.0, 0.0, x, 0.0, 0.0, 0.0, x; }
6364
explicit Tensor(T const& s, T const& m) { (*this) << s, m, m, m, s, m, m, m, s; }
64-
explicit Tensor(Vector<T> const& v) { (*this) << v(0), 0.0, 0.0, 0.0, v(1), 0.0, 0.0, 0.0, v(2); }
65+
explicit Tensor(T const& s1, T const& s2, T const& s3, T const& m12, T const& m13, T const& m23) { (*this) << s1, m12, m13, m12, s2, m23, m13, m23, s3; }
66+
explicit Tensor(Vector<T> const& v) { assert(v.size() == 3); (*this) << v(0), 0.0, 0.0, 0.0, v(1), 0.0, 0.0, 0.0, v(2); }
6567
// eigen expression
6668
template <typename OtherDerived> Tensor(Eigen::ArrayBase<OtherDerived> const& other) : Eigen3Tensor<T>{other} {}
6769
template <typename OtherDerived> Tensor& operator=(Eigen::ArrayBase<OtherDerived> const& other) {
@@ -70,6 +72,22 @@ template <scalar_value T> class Tensor : public Eigen3Tensor<T> {
7072
}
7173
};
7274

75+
template <scalar_value T> class Tensor4 : public Eigen4Tensor<T> {
76+
public:
77+
Tensor4() { (*this) = Eigen4Tensor<T>::Zero(); }
78+
// additional constructors
79+
explicit Tensor4(T const& x) { (*this) << x, 0.0, 0.0, 0.0, 0.0, x, 0.0, 0.0, 0.0, 0.0, x, 0.0, 0.0, 0.0, 0.0, x; }
80+
explicit Tensor4(T const& s, T const& m) { (*this) << s, m, m, m, m, s, m, m, m, m, s, m, m, m, m, s; }
81+
explicit Tensor4(T const& s1, T const& s2, T const& s3, T const& s4, T const& m12, T const& m13, T const& m14, T const& m23, T const& m24, T const& m34) { (*this) << s1, m12, m13, m14, m12, s2, m23, m24, m13, m23, s3, m34, m14, m24, m34, s4; }
82+
explicit Tensor4(Vector<T> const& v) { assert(v.size() == 4); (*this) << v(0), 0.0, 0.0, 0.0, 0.0, v(1), 0.0, 0.0, 0.0, 0.0, v(2), 0.0, 0.0, 0.0, 0.0, v(3); }
83+
// eigen expression
84+
template <typename OtherDerived> Tensor4(Eigen::ArrayBase<OtherDerived> const& other) : Eigen4Tensor<T>{other} {}
85+
template <typename OtherDerived> Tensor4& operator=(Eigen::ArrayBase<OtherDerived> const& other) {
86+
this->Eigen4Tensor<T>::operator=(other);
87+
return *this;
88+
}
89+
};
90+
7391
template <scalar_value T> class DiagonalTensor : public Eigen3DiagonalTensor<T> {
7492
public:
7593
DiagonalTensor() { (*this).setZero(); }
@@ -92,6 +110,7 @@ template <symmetry_tag sym>
92110
using RealTensor = std::conditional_t<is_symmetric_v<sym>, double, three_phase_tensor::Tensor<double>>;
93111
template <symmetry_tag sym>
94112
using ComplexTensor = std::conditional_t<is_symmetric_v<sym>, DoubleComplex, three_phase_tensor::Tensor<DoubleComplex>>;
113+
using ComplexTensor4 = three_phase_tensor::Tensor4<DoubleComplex>;
95114

96115
template <symmetry_tag sym>
97116
using RealDiagonalTensor = std::conditional_t<is_symmetric_v<sym>, double, three_phase_tensor::DiagonalTensor<double>>;

0 commit comments

Comments
 (0)