Skip to content

Commit

Permalink
boilerplate code for asym_line
Browse files Browse the repository at this point in the history
  • Loading branch information
leovsch committed Oct 4, 2024
1 parent 9983d3c commit 62b8999
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 35 deletions.
52 changes: 30 additions & 22 deletions code_generation/data/attribute_classes/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,37 @@
{
"data_type": "double",
"names": [
"c1"
"r_aa",
"r_ba",
"r_bb",
"r_ca",
"r_cb",
"r_cc",
"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_ba",
"c_bb",
"c_ca",
"c_cb",
"c_cc",
"c_na",
"c_nb",
"c_nc",
"c_nn"
],
"description": "positive sequence parameters"
},
{
"data_type": "std::array<std::array<double, 3>, 3>",
"names": [
"r_matrix",
"x_matrix"
],
"description": "3 x 3 matrix"
},
{
"data_type": "double",
"names": [
"c0"
],
"description": "zero sequence parameters"
},
{
"data_type": "double",
"names": "i_n",
"description": "rated current"
"description": "Lower triangle matrix values for R, X and C matrices"
}
]
},
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 @@ -63,7 +67,7 @@
"class_name": "NodeOutput"
},
{
"names": ["line", "link", "transformer"],
"names": ["line", "link", "transformer", "asym_line"],
"class_name": "BranchOutput"
},
{
Expand Down Expand Up @@ -104,6 +108,10 @@
"names": ["line"],
"class_name": "BranchUpdate"
},
{
"names": ["asym_line"],
"class_name": "BranchUpdate"
},
{
"names": ["link"],
"class_name": "BranchUpdate"
Expand Down Expand Up @@ -155,7 +163,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 @@ -104,11 +104,35 @@ struct AsymLineInput {
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 c1{nan}; // positive sequence parameters
std::array<std::array<double, 3>, 3> r_matrix{static_cast<std::array<std::array<double, 3>, 3>>(na_IntS)}; // 3 x 3 matrix
std::array<std::array<double, 3>, 3> x_matrix{static_cast<std::array<std::array<double, 3>, 3>>(na_IntS)}; // 3 x 3 matrix
double c0{nan}; // zero sequence parameters
double i_n{nan}; // rated current
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_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

// implicit conversions to BaseInput
operator BaseInput&() { return reinterpret_cast<BaseInput&>(*this); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,43 @@ struct get_attributes_list<LineInput> {

template<>
struct get_attributes_list<AsymLineInput> {
static constexpr std::array<MetaAttribute, 10> value{
static constexpr std::array<MetaAttribute, 34> 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::c1>(offsetof(AsymLineInput, c1), "c1"),
meta_data_gen::get_meta_attribute<&AsymLineInput::r_matrix>(offsetof(AsymLineInput, r_matrix), "r_matrix"),
meta_data_gen::get_meta_attribute<&AsymLineInput::x_matrix>(offsetof(AsymLineInput, x_matrix), "x_matrix"),
meta_data_gen::get_meta_attribute<&AsymLineInput::c0>(offsetof(AsymLineInput, c0), "c0"),
meta_data_gen::get_meta_attribute<&AsymLineInput::i_n>(offsetof(AsymLineInput, i_n), "i_n"),
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_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"),
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include "branch.hpp"

#include "../auxiliary/input.hpp"
#include "../auxiliary/output.hpp"
#include "../auxiliary/update.hpp"
#include "../calculation_parameters.hpp"
#include "../common/common.hpp"
#include "../common/three_phase_tensor.hpp"

namespace power_grid_model {

class AsymLine : public Branch {
public:
using InputType = AsymLineInput;
using UpdateType = BranchUpdate;
static constexpr char const* name = "asym_line";

explicit AsymLine(AsymLineInput const& asym_line_input, double system_frequency, double u1, double u2)
: Branch{asym_line_input}, i_n_{asym_line_input.i_n}, base_i_{base_power_3p / u1 / sqrt3} {
if (cabs(u1 - u2) > numerical_tolerance) {
throw ConflictVoltage{id(), from_node(), to_node(), u1, u2};
}
double const base_y = base_i_ / (u1 / sqrt3);

}

// override getter
double base_i_from() const override { return base_i_; }
double base_i_to() const override { return base_i_; }
double loading(double /* max_s */, double max_i) const override { return max_i / i_n_; };
double phase_shift() const override { return 0.0; }
bool is_param_mutable() const override { return false; }

private:
double i_n_;
double base_i_;
DoubleComplex y1_series_;
DoubleComplex y1_shunt_;
DoubleComplex y0_series_;
DoubleComplex y0_shunt_;

BranchCalcParam<symmetric_t> sym_calc_param() const override {
return calc_param_y_sym(y1_series_, y1_shunt_, 1.0);
}
BranchCalcParam<asymmetric_t> asym_calc_param() const override {
return calc_param_y_asym(y1_series_, y1_shunt_, y0_series_, y0_shunt_, 1.0);
}
}
Loading

0 comments on commit 62b8999

Please sign in to comment.