Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of feature 720 asym_line #762

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
49 changes: 49 additions & 0 deletions code_generation/data/attribute_classes/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,55 @@
}
]
},
{
"name": "AsymLineInput",
"base": "BranchInput",
"attributes": [
{
"data_type": "double",
"names": [
"r_aa",
"r_ba",
"r_bb",
"r_ca",
"r_cb",
"r_cc",
TonyXiang8787 marked this conversation as resolved.
Show resolved Hide resolved
"r_na",
"r_nb",
"r_nc",
"r_nn",
"x_aa",
"x_ba",
"x_bb",
"x_ca",
"x_cb",
"x_cc",
"x_na",
"x_nb",
"x_nc",
"x_nn",
"c_aa",
"c_ba",
"c_bb",
"c_ca",
"c_cb",
"c_cc",
"c_na",
"c_nb",
"c_nc",
"c_nn",
"c0",
"c1"
],
"description": "Lower triangle matrix values for R, X and C matrices"
},
{
"data_type": "double",
"names": "i_n",
"description": "rated current"
}
]
},
{
"name": "GenericBranchInput",
"base": "BranchInput",
Expand Down
12 changes: 10 additions & 2 deletions code_generation/data/dataset_class_maps/dataset_definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"names": ["line"],
"class_name": "LineInput"
},
{
"names": ["asym_line"],
"class_name": "AsymLineInput"
},
{
"names": ["link"],
"class_name": "LinkInput"
Expand Down Expand Up @@ -67,7 +71,7 @@
"class_name": "NodeOutput"
},
{
"names": ["line", "link", "transformer", "generic_branch"],
"names": ["line", "link", "transformer", "generic_branch", "asym_line"],
"class_name": "BranchOutput"
},
{
Expand Down Expand Up @@ -108,6 +112,10 @@
"names": ["line"],
"class_name": "BranchUpdate"
},
{
"names": ["asym_line"],
"class_name": "BranchUpdate"
},
{
"names": ["link"],
"class_name": "BranchUpdate"
Expand Down Expand Up @@ -159,7 +167,7 @@
"class_name": "NodeShortCircuitOutput"
},
{
"names": ["line", "link", "transformer"],
"names": ["line", "link", "transformer", "asym_line"],
"class_name": "BranchShortCircuitOutput"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "component/fault.hpp"
#include "component/generic_branch.hpp"
#include "component/line.hpp"
#include "component/asym_line.hpp"
#include "component/link.hpp"
#include "component/load_gen.hpp"
#include "component/node.hpp"
Expand All @@ -27,7 +28,7 @@
namespace power_grid_model {

using AllComponents =
ComponentList<Node, Line, Link, GenericBranch, Transformer, ThreeWindingTransformer, Shunt, Source, SymGenerator,
ComponentList<Node, Line, AsymLine, Link, GenericBranch, Transformer, ThreeWindingTransformer, Shunt, Source, SymGenerator,
AsymGenerator, SymLoad, AsymLoad, SymPowerSensor, AsymPowerSensor, SymVoltageSensor,
AsymVoltageSensor, Fault, TransformerTapRegulator>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,55 @@ struct LineInput {
operator BranchInput const&() const { return reinterpret_cast<BranchInput const&>(*this); }
};

struct AsymLineInput {
ID id{na_IntID}; // ID of the object
ID from_node{na_IntID}; // node IDs to which this branch is connected at both sides
ID to_node{na_IntID}; // node IDs to which this branch is connected at both sides
IntS from_status{na_IntS}; // whether the branch is connected at each side
IntS to_status{na_IntS}; // whether the branch is connected at each side
double r_aa{nan}; // Lower triangle matrix values for R, X and C matrices
double r_ba{nan}; // Lower triangle matrix values for R, X and C matrices
double r_bb{nan}; // Lower triangle matrix values for R, X and C matrices
double r_ca{nan}; // Lower triangle matrix values for R, X and C matrices
double r_cb{nan}; // Lower triangle matrix values for R, X and C matrices
double r_cc{nan}; // Lower triangle matrix values for R, X and C matrices
double r_na{nan}; // Lower triangle matrix values for R, X and C matrices
double r_nb{nan}; // Lower triangle matrix values for R, X and C matrices
double r_nc{nan}; // Lower triangle matrix values for R, X and C matrices
double r_nn{nan}; // Lower triangle matrix values for R, X and C matrices
double x_aa{nan}; // Lower triangle matrix values for R, X and C matrices
double x_ba{nan}; // Lower triangle matrix values for R, X and C matrices
double x_bb{nan}; // Lower triangle matrix values for R, X and C matrices
double x_ca{nan}; // Lower triangle matrix values for R, X and C matrices
double x_cb{nan}; // Lower triangle matrix values for R, X and C matrices
double x_cc{nan}; // Lower triangle matrix values for R, X and C matrices
double x_na{nan}; // Lower triangle matrix values for R, X and C matrices
double x_nb{nan}; // Lower triangle matrix values for R, X and C matrices
double x_nc{nan}; // Lower triangle matrix values for R, X and C matrices
double x_nn{nan}; // Lower triangle matrix values for R, X and C matrices
double c_aa{nan}; // Lower triangle matrix values for R, X and C matrices
double c_ba{nan}; // Lower triangle matrix values for R, X and C matrices
double c_bb{nan}; // Lower triangle matrix values for R, X and C matrices
double c_ca{nan}; // Lower triangle matrix values for R, X and C matrices
double c_cb{nan}; // Lower triangle matrix values for R, X and C matrices
double c_cc{nan}; // Lower triangle matrix values for R, X and C matrices
double c_na{nan}; // Lower triangle matrix values for R, X and C matrices
double c_nb{nan}; // Lower triangle matrix values for R, X and C matrices
double c_nc{nan}; // Lower triangle matrix values for R, X and C matrices
double c_nn{nan}; // Lower triangle matrix values for R, X and C matrices
double c0{nan}; // Lower triangle matrix values for R, X and C matrices
double c1{nan}; // Lower triangle matrix values for R, X and C matrices
double i_n{nan}; // rated current

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

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

struct GenericBranchInput {
ID id{na_IntID}; // ID of the object
ID from_node{na_IntID}; // node IDs to which this branch is connected at both sides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,52 @@ struct get_attributes_list<LineInput> {
};
};

template<>
struct get_attributes_list<AsymLineInput> {
static constexpr std::array<MetaAttribute, 38> value{
// all attributes including base class

meta_data_gen::get_meta_attribute<&AsymLineInput::id>(offsetof(AsymLineInput, id), "id"),
meta_data_gen::get_meta_attribute<&AsymLineInput::from_node>(offsetof(AsymLineInput, from_node), "from_node"),
meta_data_gen::get_meta_attribute<&AsymLineInput::to_node>(offsetof(AsymLineInput, to_node), "to_node"),
meta_data_gen::get_meta_attribute<&AsymLineInput::from_status>(offsetof(AsymLineInput, from_status), "from_status"),
meta_data_gen::get_meta_attribute<&AsymLineInput::to_status>(offsetof(AsymLineInput, to_status), "to_status"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_aa>(offsetof(AsymLineInput, r_aa), "r_aa"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_ba>(offsetof(AsymLineInput, r_ba), "r_ba"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_bb>(offsetof(AsymLineInput, r_bb), "r_bb"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_ca>(offsetof(AsymLineInput, r_ca), "r_ca"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_cb>(offsetof(AsymLineInput, r_cb), "r_cb"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_cc>(offsetof(AsymLineInput, r_cc), "r_cc"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_na>(offsetof(AsymLineInput, r_na), "r_na"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_nb>(offsetof(AsymLineInput, r_nb), "r_nb"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_nc>(offsetof(AsymLineInput, r_nc), "r_nc"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_nn>(offsetof(AsymLineInput, r_nn), "r_nn"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_aa>(offsetof(AsymLineInput, x_aa), "x_aa"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_ba>(offsetof(AsymLineInput, x_ba), "x_ba"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_bb>(offsetof(AsymLineInput, x_bb), "x_bb"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_ca>(offsetof(AsymLineInput, x_ca), "x_ca"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_cb>(offsetof(AsymLineInput, x_cb), "x_cb"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_cc>(offsetof(AsymLineInput, x_cc), "x_cc"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_na>(offsetof(AsymLineInput, x_na), "x_na"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_nb>(offsetof(AsymLineInput, x_nb), "x_nb"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_nc>(offsetof(AsymLineInput, x_nc), "x_nc"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_nn>(offsetof(AsymLineInput, x_nn), "x_nn"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_aa>(offsetof(AsymLineInput, c_aa), "c_aa"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_ba>(offsetof(AsymLineInput, c_ba), "c_ba"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_bb>(offsetof(AsymLineInput, c_bb), "c_bb"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_ca>(offsetof(AsymLineInput, c_ca), "c_ca"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_cb>(offsetof(AsymLineInput, c_cb), "c_cb"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_cc>(offsetof(AsymLineInput, c_cc), "c_cc"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_na>(offsetof(AsymLineInput, c_na), "c_na"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_nb>(offsetof(AsymLineInput, c_nb), "c_nb"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_nc>(offsetof(AsymLineInput, c_nc), "c_nc"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c_nn>(offsetof(AsymLineInput, c_nn), "c_nn"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c0>(offsetof(AsymLineInput, c0), "c0"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c1>(offsetof(AsymLineInput, c1), "c1"),
meta_data_gen::get_meta_attribute<&AsymLineInput::i_n>(offsetof(AsymLineInput, i_n), "i_n"),
};
};

template<>
struct get_attributes_list<GenericBranchInput> {
static constexpr std::array<MetaAttribute, 12> value{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ static_assert(offsetof(LineInput, to_node) == offsetof(BranchInput, to_node));
static_assert(offsetof(LineInput, from_status) == offsetof(BranchInput, from_status));
static_assert(offsetof(LineInput, to_status) == offsetof(BranchInput, to_status));

// static asserts for AsymLineInput
static_assert(std::is_standard_layout_v<AsymLineInput>);
// static asserts for conversion of AsymLineInput to BaseInput
static_assert(std::alignment_of_v<AsymLineInput> >= std::alignment_of_v<BranchInput>);
static_assert(std::same_as<decltype(AsymLineInput::id), decltype(BaseInput::id)>);
static_assert(offsetof(AsymLineInput, id) == offsetof(BaseInput, id));
// static asserts for conversion of AsymLineInput to BranchInput
static_assert(std::alignment_of_v<AsymLineInput> >= std::alignment_of_v<BranchInput>);
static_assert(std::same_as<decltype(AsymLineInput::id), decltype(BranchInput::id)>);
static_assert(std::same_as<decltype(AsymLineInput::from_node), decltype(BranchInput::from_node)>);
static_assert(std::same_as<decltype(AsymLineInput::to_node), decltype(BranchInput::to_node)>);
static_assert(std::same_as<decltype(AsymLineInput::from_status), decltype(BranchInput::from_status)>);
static_assert(std::same_as<decltype(AsymLineInput::to_status), decltype(BranchInput::to_status)>);
static_assert(offsetof(AsymLineInput, id) == offsetof(BranchInput, id));
static_assert(offsetof(AsymLineInput, from_node) == offsetof(BranchInput, from_node));
static_assert(offsetof(AsymLineInput, to_node) == offsetof(BranchInput, to_node));
static_assert(offsetof(AsymLineInput, from_status) == offsetof(BranchInput, from_status));
static_assert(offsetof(AsymLineInput, to_status) == offsetof(BranchInput, to_status));

// static asserts for GenericBranchInput
static_assert(std::is_standard_layout_v<GenericBranchInput>);
// static asserts for conversion of GenericBranchInput to BaseInput
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>

#pragma once

#include "three_phase_tensor.hpp"

namespace power_grid_model {

inline DoubleComplex average_of_diagonal_of_matrix(const ComplexTensor<asymmetric_t> &matrix) {
return (matrix(0,0) + matrix(1,1) + matrix(2,2)) / 3.0;
}

inline DoubleComplex average_of_off_diagonal_of_matrix(const ComplexTensor<asymmetric_t> &matrix) {
return (matrix(0,1) + matrix(1,2) + matrix(1,0) + matrix(1,2) + matrix(2,0) + matrix(2,1)) / 6.0;
}

} // namespace power_grid_model
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace three_phase_tensor {

template <class T> using Eigen3Vector = Eigen::Array<T, 3, 1>;
template <class T> using Eigen3Tensor = Eigen::Array<T, 3, 3, Eigen::ColMajor>;
template <class T> using Eigen4Tensor = Eigen::Array<T, 4, 4, Eigen::ColMajor>;
template <class T> using Eigen3DiagonalTensor = Eigen::DiagonalMatrix<T, 3>;

template <scalar_value T> class Vector : public Eigen3Vector<T> {
Expand Down Expand Up @@ -61,6 +62,7 @@ template <scalar_value T> class Tensor : public Eigen3Tensor<T> {
// additional constructors
explicit Tensor(T const& x) { (*this) << x, 0.0, 0.0, 0.0, x, 0.0, 0.0, 0.0, x; }
explicit Tensor(T const& s, T const& m) { (*this) << s, m, m, m, s, m, m, m, s; }
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; }
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); }
// eigen expression
template <typename OtherDerived> Tensor(Eigen::ArrayBase<OtherDerived> const& other) : Eigen3Tensor<T>{other} {}
Expand All @@ -70,6 +72,22 @@ template <scalar_value T> class Tensor : public Eigen3Tensor<T> {
}
};

template <scalar_value T> class Tensor4 : public Eigen4Tensor<T> {
public:
Tensor4() { (*this) = Eigen4Tensor<T>::Zero(); }
// additional constructors
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; }
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; }
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; }
explicit Tensor4(Vector<T> const& v) { (*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); }
// eigen expression
template <typename OtherDerived> Tensor4(Eigen::ArrayBase<OtherDerived> const& other) : Eigen4Tensor<T>{other} {}
template <typename OtherDerived> Tensor4& operator=(Eigen::ArrayBase<OtherDerived> const& other) {
this->Eigen4Tensor<T>::operator=(other);
return *this;
}
};

template <scalar_value T> class DiagonalTensor : public Eigen3DiagonalTensor<T> {
public:
DiagonalTensor() { (*this).setZero(); }
Expand All @@ -92,6 +110,7 @@ template <symmetry_tag sym>
using RealTensor = std::conditional_t<is_symmetric_v<sym>, double, three_phase_tensor::Tensor<double>>;
template <symmetry_tag sym>
using ComplexTensor = std::conditional_t<is_symmetric_v<sym>, DoubleComplex, three_phase_tensor::Tensor<DoubleComplex>>;
using ComplexTensor4 = three_phase_tensor::Tensor4<DoubleComplex>;

template <symmetry_tag sym>
using RealDiagonalTensor = std::conditional_t<is_symmetric_v<sym>, double, three_phase_tensor::DiagonalTensor<double>>;
Expand Down
Loading