Skip to content

Commit

Permalink
create generic_branch
Browse files Browse the repository at this point in the history
Signed-off-by: Eduard Fried <[email protected]>
  • Loading branch information
Eduard Fried committed Sep 30, 2024
1 parent dec5729 commit fb20722
Show file tree
Hide file tree
Showing 17 changed files with 517 additions and 10 deletions.
27 changes: 27 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,33 @@
}
]
},
{
"name": "GenericBranchInput",
"base": "BranchInput",
"attributes": [
{
"data_type": "double",
"names": ["r1","x1","g1","b1"],
"description": "positive sequence parameters"
},
{
"data_type": "double",
"names": "k",
"description": "transformer ratio, default = 1.0"
},
{
"data_type": "double",
"names": "theta",
"description": "angle shift"
},
{
"data_type": "double",
"names": "sn",
"description": "rated power for calculation of loading (obsolete)"
}
]
},

{
"name": "LinkInput",
"base": "BranchInput",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"names": ["link"],
"class_name": "LinkInput"
},
{
"names": ["generic_branch"],
"class_name": "GenericBranchInput"
},
{
"names": ["transformer"],
"class_name": "TransformerInput"
Expand Down Expand Up @@ -63,7 +67,7 @@
"class_name": "NodeOutput"
},
{
"names": ["line", "link", "transformer"],
"names": ["line", "link", "transformer", "generic_branch"],
"class_name": "BranchOutput"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// component include
#include "component/appliance.hpp"
#include "component/fault.hpp"
#include "component/genericbranch.hpp"
#include "component/line.hpp"
#include "component/link.hpp"
#include "component/load_gen.hpp"
Expand All @@ -25,8 +26,9 @@

namespace power_grid_model {

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

} // namespace power_grid_model
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ struct LineInput {
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
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 r1{nan}; // positive sequence parameters
double x1{nan}; // positive sequence parameters
double g1{nan}; // positive sequence parameters
double b1{nan}; // positive sequence parameters
double k{nan}; // transformer ratio, default = 1.0
double theta{nan}; // angle shift
double sn{nan}; // rated power for calculation of loading (obsolete)

// 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 LinkInput {
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,26 @@ struct get_attributes_list<LineInput> {
};
};

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

meta_data_gen::get_meta_attribute<&GenericBranchInput::id>(offsetof(GenericBranchInput, id), "id"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::from_node>(offsetof(GenericBranchInput, from_node), "from_node"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::to_node>(offsetof(GenericBranchInput, to_node), "to_node"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::from_status>(offsetof(GenericBranchInput, from_status), "from_status"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::to_status>(offsetof(GenericBranchInput, to_status), "to_status"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::r1>(offsetof(GenericBranchInput, r1), "r1"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::x1>(offsetof(GenericBranchInput, x1), "x1"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::g1>(offsetof(GenericBranchInput, g1), "g1"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::b1>(offsetof(GenericBranchInput, b1), "b1"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::k>(offsetof(GenericBranchInput, k), "k"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::theta>(offsetof(GenericBranchInput, theta), "theta"),
meta_data_gen::get_meta_attribute<&GenericBranchInput::sn>(offsetof(GenericBranchInput, sn), "sn"),
};
};

template<>
struct get_attributes_list<LinkInput> {
static constexpr std::array<MetaAttribute, 5> 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 GenericBranchInput
static_assert(std::is_standard_layout_v<GenericBranchInput>);
// static asserts for conversion of GenericBranchInput to BaseInput
static_assert(std::alignment_of_v<GenericBranchInput> >= std::alignment_of_v<BranchInput>);
static_assert(std::same_as<decltype(GenericBranchInput::id), decltype(BaseInput::id)>);
static_assert(offsetof(GenericBranchInput, id) == offsetof(BaseInput, id));
// static asserts for conversion of GenericBranchInput to BranchInput
static_assert(std::alignment_of_v<GenericBranchInput> >= std::alignment_of_v<BranchInput>);
static_assert(std::same_as<decltype(GenericBranchInput::id), decltype(BranchInput::id)>);
static_assert(std::same_as<decltype(GenericBranchInput::from_node), decltype(BranchInput::from_node)>);
static_assert(std::same_as<decltype(GenericBranchInput::to_node), decltype(BranchInput::to_node)>);
static_assert(std::same_as<decltype(GenericBranchInput::from_status), decltype(BranchInput::from_status)>);
static_assert(std::same_as<decltype(GenericBranchInput::to_status), decltype(BranchInput::to_status)>);
static_assert(offsetof(GenericBranchInput, id) == offsetof(BranchInput, id));
static_assert(offsetof(GenericBranchInput, from_node) == offsetof(BranchInput, from_node));
static_assert(offsetof(GenericBranchInput, to_node) == offsetof(BranchInput, to_node));
static_assert(offsetof(GenericBranchInput, from_status) == offsetof(BranchInput, from_status));
static_assert(offsetof(GenericBranchInput, to_status) == offsetof(BranchInput, to_status));

// static asserts for LinkInput
static_assert(std::is_standard_layout_v<LinkInput>);
// static asserts for conversion of LinkInput to BaseInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class DuplicativelyRegulatedObject : public PowerGridError {
}
};

class NotImplementedError : public PowerGridError {
public:
NotImplementedError() { append_msg("Function not yet implemented"); }
};

class AutomaticTapCalculationError : public PowerGridError {
public:
AutomaticTapCalculationError(ID id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
//
// SPDX-License-Identifier: MPL-2.0

#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/exception.hpp"
#include "../common/three_phase_tensor.hpp"

/*
generic Branch: either a line N = 1 or a transformoer N = t*e^(j*theta1)
paramaters should be given as r1, x1, ....
-----| |-----------y1_series-------
| | | |
| | y1_shunt y1_shunt
| | | |
| | | |
-----| |--------------------------
N = k * e^(j*theta1)
*/

namespace power_grid_model {

class GenericBranch final : public Branch {
public:
using InputType = GenericBranchInput;
using UpdateType = BranchUpdate;
static constexpr char const* name = "generic_branch";

explicit GenericBranch(GenericBranchInput const& genericbranch_input, double u1_rated, double u2_rated)
: Branch{genericbranch_input},
sn_{genericbranch_input.sn},
r1_{genericbranch_input.r1},
x1_{genericbranch_input.x1},
g1_{genericbranch_input.g1},
b1_{genericbranch_input.b1},
k_{std::isnan(genericbranch_input.k) ? 1.0 : genericbranch_input.k},
theta_{std::isnan(genericbranch_input.theta) ? 0.0 : std::fmod(genericbranch_input.theta, 2 * pi)},
base_i_from_{base_power_3p / u1_rated / sqrt3},
base_i_to_{base_power_3p / u2_rated / sqrt3},
base_y_{base_i_to_ / (u2_rated / sqrt3)} {

y1_series_ = 1.0 / (r1_ + 1.0i * x1_) / base_y_;
y1_shunt_ = (g1_ + 1.0i * b1_) / base_y_;
}

// override getter
double base_i_from() const override { return base_i_from_; }
double base_i_to() const override { return base_i_to_; }
double loading(double max_s, double /*max_i*/) const override { return std::isnan(sn_) ? 0.0 : (max_s / sn_); };
double phase_shift() const override { return theta_; }
bool is_param_mutable() const override { return false; }

private:
double sn_;
double r1_;
double x1_;
double g1_;
double b1_;
double k_;
double theta_;
double base_i_from_;
double base_i_to_;
double base_y_;
DoubleComplex y1_series_;
DoubleComplex y1_shunt_;

BranchCalcParam<symmetric_t> sym_calc_param() const override {
return calc_param_y_sym(y1_series_, y1_shunt_, k_ * std::exp(1.0i * theta_));
}

[[noreturn]] BranchCalcParam<asymmetric_t> asym_calc_param() const override { throw NotImplementedError(); }
};

} // namespace power_grid_model
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ PGM_API extern PGM_MetaAttribute const* const PGM_def_input_link_from_node;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_link_to_node;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_link_from_status;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_link_to_status;
// component generic_branch
PGM_API extern PGM_MetaComponent const* const PGM_def_input_generic_branch;
// attributes of input generic_branch
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_id;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_from_node;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_to_node;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_from_status;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_to_status;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_r1;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_x1;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_g1;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_b1;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_k;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_theta;
PGM_API extern PGM_MetaAttribute const* const PGM_def_input_generic_branch_sn;
// component transformer
PGM_API extern PGM_MetaComponent const* const PGM_def_input_transformer;
// attributes of input transformer
Expand Down Expand Up @@ -311,6 +326,20 @@ PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_transformer_p_t
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_transformer_q_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_transformer_i_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_transformer_s_to;
// component generic_branch
PGM_API extern PGM_MetaComponent const* const PGM_def_sym_output_generic_branch;
// attributes of sym_output generic_branch
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_id;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_energized;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_loading;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_p_from;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_q_from;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_i_from;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_s_from;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_p_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_q_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_i_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_sym_output_generic_branch_s_to;
// component transformer_tap_regulator
PGM_API extern PGM_MetaComponent const* const PGM_def_sym_output_transformer_tap_regulator;
// attributes of sym_output transformer_tap_regulator
Expand Down Expand Up @@ -483,6 +512,20 @@ PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_transformer_p_
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_transformer_q_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_transformer_i_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_transformer_s_to;
// component generic_branch
PGM_API extern PGM_MetaComponent const* const PGM_def_asym_output_generic_branch;
// attributes of asym_output generic_branch
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_id;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_energized;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_loading;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_p_from;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_q_from;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_i_from;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_s_from;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_p_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_q_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_i_to;
PGM_API extern PGM_MetaAttribute const* const PGM_def_asym_output_generic_branch_s_to;
// component transformer_tap_regulator
PGM_API extern PGM_MetaComponent const* const PGM_def_asym_output_transformer_tap_regulator;
// attributes of asym_output transformer_tap_regulator
Expand Down
Loading

0 comments on commit fb20722

Please sign in to comment.