Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ template <symmetry_tag sym_type> struct BranchCalcParam {
ComplexTensor<sym> const& ytt() const { return value[3]; }
};

template <symmetry_tag sym_type> struct BranchMathOutput {
template <symmetry_tag sym_type> struct BranchSolverOutput {
using sym = sym_type;

ComplexValue<sym> s_f{};
Expand All @@ -44,7 +44,7 @@ template <symmetry_tag sym_type> struct BranchMathOutput {
ComplexValue<sym> i_t{};
};

template <symmetry_tag sym_type> struct BranchShortCircuitMathOutput {
template <symmetry_tag sym_type> struct BranchShortCircuitSolverOutput {
using sym = sym_type;

ComplexValue<sym> i_f{};
Expand All @@ -58,21 +58,21 @@ struct FaultCalcParam {
FaultPhase fault_phase{};
};

template <symmetry_tag sym_type> struct FaultShortCircuitMathOutput {
template <symmetry_tag sym_type> struct FaultShortCircuitSolverOutput {
using sym = sym_type;

ComplexValue<sym> i_fault{};
};

// appliance math output, always injection direction
// s > 0, energy appliance -> node
template <symmetry_tag sym_type> struct ApplianceMathOutput {
template <symmetry_tag sym_type> struct ApplianceSolverOutput {
using sym = sym_type;

ComplexValue<sym> s{};
ComplexValue<sym> i{};
};
template <symmetry_tag sym_type> struct ApplianceShortCircuitMathOutput {
template <symmetry_tag sym_type> struct ApplianceShortCircuitSolverOutput {
using sym = sym_type;

ComplexValue<sym> i{};
Expand Down Expand Up @@ -125,7 +125,7 @@ struct TransformerTapRegulatorCalcParam {
DoubleComplex z_compensation{};
IntS status{};
};
template <symmetry_tag sym_type> struct TransformerTapRegulatorMathOutput {
template <symmetry_tag sym_type> struct TransformerTapRegulatorOptimizerOutput {
using sym = sym_type;

IntS tap_pos{na_IntS};
Expand Down Expand Up @@ -258,72 +258,72 @@ static_assert(calculation_input_type<PowerFlowInput<asymmetric_t>>);
static_assert(calculation_input_type<StateEstimationInput<asymmetric_t>>);
static_assert(calculation_input_type<ShortCircuitInput>);

struct math_output_t {};
struct solver_output_t {};

template <symmetry_tag sym_type> struct MathOutput {
using type = math_output_t;
template <symmetry_tag sym_type> struct SolverOutput {
using type = solver_output_t;
using sym = sym_type;

std::vector<ComplexValue<sym>> u;
std::vector<ComplexValue<sym>> bus_injection;
std::vector<BranchMathOutput<sym>> branch;
std::vector<ApplianceMathOutput<sym>> source;
std::vector<ApplianceMathOutput<sym>> shunt;
std::vector<ApplianceMathOutput<sym>> load_gen;
std::vector<TransformerTapRegulatorMathOutput<sym>> transformer_tap_regulator;
std::vector<BranchSolverOutput<sym>> branch;
std::vector<ApplianceSolverOutput<sym>> source;
std::vector<ApplianceSolverOutput<sym>> shunt;
std::vector<ApplianceSolverOutput<sym>> load_gen;
std::vector<TransformerTapRegulatorOptimizerOutput<sym>> transformer_tap_regulator;
};

template <symmetry_tag sym_type> struct ShortCircuitMathOutput {
using type = math_output_t;
template <symmetry_tag sym_type> struct ShortCircuitSolverOutput {
using type = solver_output_t;
using sym = sym_type;

std::vector<ComplexValue<sym>> u_bus;
std::vector<FaultShortCircuitMathOutput<sym>> fault;
std::vector<BranchShortCircuitMathOutput<sym>> branch;
std::vector<ApplianceShortCircuitMathOutput<sym>> source;
std::vector<ApplianceShortCircuitMathOutput<sym>> shunt;
std::vector<FaultShortCircuitSolverOutput<sym>> fault;
std::vector<BranchShortCircuitSolverOutput<sym>> branch;
std::vector<ApplianceShortCircuitSolverOutput<sym>> source;
std::vector<ApplianceShortCircuitSolverOutput<sym>> shunt;
};

template <typename T>
concept math_output_type = std::derived_from<typename T::type, math_output_t>;
concept solver_output_type = std::derived_from<typename T::type, solver_output_t>;

static_assert(math_output_type<MathOutput<symmetric_t>>);
static_assert(math_output_type<MathOutput<asymmetric_t>>);
static_assert(math_output_type<ShortCircuitMathOutput<symmetric_t>>);
static_assert(math_output_type<ShortCircuitMathOutput<asymmetric_t>>);
static_assert(solver_output_type<SolverOutput<symmetric_t>>);
static_assert(solver_output_type<SolverOutput<asymmetric_t>>);
static_assert(solver_output_type<ShortCircuitSolverOutput<symmetric_t>>);
static_assert(solver_output_type<ShortCircuitSolverOutput<asymmetric_t>>);

template <typename T>
concept symmetric_math_output_type = math_output_type<T> && is_symmetric_v<typename T::sym>;
concept symmetric_solver_output_type = solver_output_type<T> && is_symmetric_v<typename T::sym>;

static_assert(symmetric_math_output_type<MathOutput<symmetric_t>>);
static_assert(!symmetric_math_output_type<MathOutput<asymmetric_t>>);
static_assert(symmetric_math_output_type<ShortCircuitMathOutput<symmetric_t>>);
static_assert(!symmetric_math_output_type<ShortCircuitMathOutput<asymmetric_t>>);
static_assert(symmetric_solver_output_type<SolverOutput<symmetric_t>>);
static_assert(!symmetric_solver_output_type<SolverOutput<asymmetric_t>>);
static_assert(symmetric_solver_output_type<ShortCircuitSolverOutput<symmetric_t>>);
static_assert(!symmetric_solver_output_type<ShortCircuitSolverOutput<asymmetric_t>>);

template <typename T>
concept asymmetric_math_output_type = math_output_type<T> && is_asymmetric_v<typename T::sym>;
concept asymmetric_solver_output_type = solver_output_type<T> && is_asymmetric_v<typename T::sym>;

static_assert(!asymmetric_math_output_type<MathOutput<symmetric_t>>);
static_assert(asymmetric_math_output_type<MathOutput<asymmetric_t>>);
static_assert(!asymmetric_math_output_type<ShortCircuitMathOutput<symmetric_t>>);
static_assert(asymmetric_math_output_type<ShortCircuitMathOutput<asymmetric_t>>);
static_assert(!asymmetric_solver_output_type<SolverOutput<symmetric_t>>);
static_assert(asymmetric_solver_output_type<SolverOutput<asymmetric_t>>);
static_assert(!asymmetric_solver_output_type<ShortCircuitSolverOutput<symmetric_t>>);
static_assert(asymmetric_solver_output_type<ShortCircuitSolverOutput<asymmetric_t>>);

template <typename T>
concept steady_state_math_output_type = math_output_type<T> && std::derived_from<T, MathOutput<typename T::sym>>;
concept steady_state_solver_output_type = solver_output_type<T> && std::derived_from<T, SolverOutput<typename T::sym>>;

static_assert(steady_state_math_output_type<MathOutput<symmetric_t>>);
static_assert(steady_state_math_output_type<MathOutput<asymmetric_t>>);
static_assert(!steady_state_math_output_type<ShortCircuitMathOutput<symmetric_t>>);
static_assert(!steady_state_math_output_type<ShortCircuitMathOutput<asymmetric_t>>);
static_assert(steady_state_solver_output_type<SolverOutput<symmetric_t>>);
static_assert(steady_state_solver_output_type<SolverOutput<asymmetric_t>>);
static_assert(!steady_state_solver_output_type<ShortCircuitSolverOutput<symmetric_t>>);
static_assert(!steady_state_solver_output_type<ShortCircuitSolverOutput<asymmetric_t>>);

template <typename T>
concept short_circuit_math_output_type =
math_output_type<T> && std::derived_from<T, ShortCircuitMathOutput<typename T::sym>>;
concept short_circuit_solver_output_type =
solver_output_type<T> && std::derived_from<T, ShortCircuitSolverOutput<typename T::sym>>;

static_assert(!short_circuit_math_output_type<MathOutput<symmetric_t>>);
static_assert(!short_circuit_math_output_type<MathOutput<asymmetric_t>>);
static_assert(short_circuit_math_output_type<ShortCircuitMathOutput<symmetric_t>>);
static_assert(short_circuit_math_output_type<ShortCircuitMathOutput<asymmetric_t>>);
static_assert(!short_circuit_solver_output_type<SolverOutput<symmetric_t>>);
static_assert(!short_circuit_solver_output_type<SolverOutput<asymmetric_t>>);
static_assert(short_circuit_solver_output_type<ShortCircuitSolverOutput<symmetric_t>>);
static_assert(short_circuit_solver_output_type<ShortCircuitSolverOutput<asymmetric_t>>);

// component indices at physical model side
// from, to node indices for branches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ class Appliance : public Base {
}

template <symmetry_tag sym>
ApplianceOutput<sym> get_output(ApplianceMathOutput<sym> const& appliance_math_output) const {
ApplianceOutput<sym> get_output(ApplianceSolverOutput<sym> const& appliance_solver_output) const {
ApplianceOutput<sym> output{};
static_cast<BaseOutput&>(output) = base_output(energized(true));
output.p = base_power<sym> * real(appliance_math_output.s) * injection_direction();
output.q = base_power<sym> * imag(appliance_math_output.s) * injection_direction();
output.s = base_power<sym> * cabs(appliance_math_output.s);
output.i = base_i_ * cabs(appliance_math_output.i);
output.p = base_power<sym> * real(appliance_solver_output.s) * injection_direction();
output.q = base_power<sym> * imag(appliance_solver_output.s) * injection_direction();
output.s = base_power<sym> * cabs(appliance_solver_output.s);
output.i = base_i_ * cabs(appliance_solver_output.i);
// pf
if constexpr (is_symmetric_v<sym>) {
if (output.s < numerical_tolerance) {
Expand Down Expand Up @@ -104,8 +104,9 @@ class Appliance : public Base {
}
}
template <symmetry_tag sym>
ApplianceShortCircuitOutput get_sc_output(ApplianceShortCircuitMathOutput<sym> const& appliance_math_output) const {
return get_sc_output(appliance_math_output.i);
ApplianceShortCircuitOutput
get_sc_output(ApplianceShortCircuitSolverOutput<sym> const& appliance_solver_output) const {
return get_sc_output(appliance_solver_output.i);
}

private:
Expand All @@ -114,8 +115,8 @@ class Appliance : public Base {
double base_i_;

// pure virtual functions for translate from u to s/i
virtual ApplianceMathOutput<symmetric_t> sym_u2si(ComplexValue<symmetric_t> const& u) const = 0;
virtual ApplianceMathOutput<asymmetric_t> asym_u2si(ComplexValue<asymmetric_t> const& u) const = 0;
virtual ApplianceSolverOutput<symmetric_t> sym_u2si(ComplexValue<symmetric_t> const& u) const = 0;
virtual ApplianceSolverOutput<asymmetric_t> asym_u2si(ComplexValue<asymmetric_t> const& u) const = 0;

virtual double injection_direction() const = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,29 @@ class Branch : public Base {
BranchOutput<sym> get_output(ComplexValue<sym> const& u_f, ComplexValue<sym> const& u_t) const {
// calculate flow
BranchCalcParam<sym> const param = calc_param<sym>();
BranchMathOutput<sym> branch_math_output{};
branch_math_output.i_f = dot(param.yff(), u_f) + dot(param.yft(), u_t);
branch_math_output.i_t = dot(param.ytf(), u_f) + dot(param.ytt(), u_t);
branch_math_output.s_f = u_f * conj(branch_math_output.i_f);
branch_math_output.s_t = u_t * conj(branch_math_output.i_t);
BranchSolverOutput<sym> branch_solver_output{};
branch_solver_output.i_f = dot(param.yff(), u_f) + dot(param.yft(), u_t);
branch_solver_output.i_t = dot(param.ytf(), u_f) + dot(param.ytt(), u_t);
branch_solver_output.s_f = u_f * conj(branch_solver_output.i_f);
branch_solver_output.s_t = u_t * conj(branch_solver_output.i_t);
// calculate result
return get_output<sym>(branch_math_output);
return get_output<sym>(branch_solver_output);
}

template <symmetry_tag sym> BranchOutput<sym> get_output(BranchMathOutput<sym> const& branch_math_output) const {
template <symmetry_tag sym>
BranchOutput<sym> get_output(BranchSolverOutput<sym> const& branch_solver_output) const {
// result object
BranchOutput<sym> output{};
static_cast<BaseOutput&>(output) = base_output(true);
// calculate result
output.p_from = base_power<sym> * real(branch_math_output.s_f);
output.q_from = base_power<sym> * imag(branch_math_output.s_f);
output.i_from = base_i_from() * cabs(branch_math_output.i_f);
output.s_from = base_power<sym> * cabs(branch_math_output.s_f);
output.p_to = base_power<sym> * real(branch_math_output.s_t);
output.q_to = base_power<sym> * imag(branch_math_output.s_t);
output.i_to = base_i_to() * cabs(branch_math_output.i_t);
output.s_to = base_power<sym> * cabs(branch_math_output.s_t);
output.p_from = base_power<sym> * real(branch_solver_output.s_f);
output.q_from = base_power<sym> * imag(branch_solver_output.s_f);
output.i_from = base_i_from() * cabs(branch_solver_output.i_f);
output.s_from = base_power<sym> * cabs(branch_solver_output.s_f);
output.p_to = base_power<sym> * real(branch_solver_output.s_t);
output.q_to = base_power<sym> * imag(branch_solver_output.s_t);
output.i_to = base_i_to() * cabs(branch_solver_output.i_t);
output.s_to = base_power<sym> * cabs(branch_solver_output.s_t);
double const max_s = std::max(sum_val(output.s_from), sum_val(output.s_to));
double const max_i = std::max(max_val(output.i_from), max_val(output.i_to));
output.loading = loading(max_s, max_i);
Expand All @@ -119,28 +120,30 @@ class Branch : public Base {

BranchShortCircuitOutput get_sc_output(ComplexValue<symmetric_t> const& i_f,
ComplexValue<symmetric_t> const& i_t) const {
return get_sc_output(BranchShortCircuitMathOutput<symmetric_t>{.i_f = i_f, .i_t = i_t});
return get_sc_output(BranchShortCircuitSolverOutput<symmetric_t>{.i_f = i_f, .i_t = i_t});
}
BranchShortCircuitOutput get_sc_output(ComplexValue<asymmetric_t> const& i_f,
ComplexValue<asymmetric_t> const& i_t) const {
return get_sc_output(BranchShortCircuitMathOutput<asymmetric_t>{.i_f = i_f, .i_t = i_t});
return get_sc_output(BranchShortCircuitSolverOutput<asymmetric_t>{.i_f = i_f, .i_t = i_t});
}

BranchShortCircuitOutput get_sc_output(BranchShortCircuitMathOutput<asymmetric_t> const& branch_math_output) const {
BranchShortCircuitOutput
get_sc_output(BranchShortCircuitSolverOutput<asymmetric_t> const& branch_solver_output) const {
BranchShortCircuitOutput output{};
static_cast<BaseOutput&>(output) = base_output(true);
// calculate result
output.i_from = base_i_from() * cabs(branch_math_output.i_f);
output.i_to = base_i_to() * cabs(branch_math_output.i_t);
output.i_from_angle = arg(branch_math_output.i_f);
output.i_to_angle = arg(branch_math_output.i_t);
output.i_from = base_i_from() * cabs(branch_solver_output.i_f);
output.i_to = base_i_to() * cabs(branch_solver_output.i_t);
output.i_from_angle = arg(branch_solver_output.i_f);
output.i_to_angle = arg(branch_solver_output.i_t);
return output;
}

BranchShortCircuitOutput get_sc_output(BranchShortCircuitMathOutput<symmetric_t> const& branch_math_output) const {
BranchShortCircuitOutput
get_sc_output(BranchShortCircuitSolverOutput<symmetric_t> const& branch_solver_output) const {
return get_sc_output(
BranchShortCircuitMathOutput<asymmetric_t>{.i_f = ComplexValue<asymmetric_t>{branch_math_output.i_f},
.i_t = ComplexValue<asymmetric_t>{branch_math_output.i_t}});
BranchShortCircuitSolverOutput<asymmetric_t>{.i_f = ComplexValue<asymmetric_t>{branch_solver_output.i_f},
.i_t = ComplexValue<asymmetric_t>{branch_solver_output.i_t}});
}

template <symmetry_tag sym> BranchOutput<sym> get_null_output() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,27 @@ class Branch3 : public Base {
}

template <symmetry_tag sym>
Branch3Output<sym> get_output(BranchMathOutput<sym> const& branch_math_output1,
BranchMathOutput<sym> const& branch_math_output2,
BranchMathOutput<sym> const& branch_math_output3) const {
Branch3Output<sym> get_output(BranchSolverOutput<sym> const& branch_solver_output1,
BranchSolverOutput<sym> const& branch_solver_output2,
BranchSolverOutput<sym> const& branch_solver_output3) const {
// result object
Branch3Output<sym> output{};
static_cast<BaseOutput&>(output) = base_output(true);
// calculate result
output.p_1 = base_power<sym> * real(branch_math_output1.s_f);
output.q_1 = base_power<sym> * imag(branch_math_output1.s_f);
output.i_1 = base_i_1() * cabs(branch_math_output1.i_f);
output.s_1 = base_power<sym> * cabs(branch_math_output1.s_f);
output.p_1 = base_power<sym> * real(branch_solver_output1.s_f);
output.q_1 = base_power<sym> * imag(branch_solver_output1.s_f);
output.i_1 = base_i_1() * cabs(branch_solver_output1.i_f);
output.s_1 = base_power<sym> * cabs(branch_solver_output1.s_f);

output.p_2 = base_power<sym> * real(branch_math_output2.s_f);
output.q_2 = base_power<sym> * imag(branch_math_output2.s_f);
output.i_2 = base_i_2() * cabs(branch_math_output2.i_f);
output.s_2 = base_power<sym> * cabs(branch_math_output2.s_f);
output.p_2 = base_power<sym> * real(branch_solver_output2.s_f);
output.q_2 = base_power<sym> * imag(branch_solver_output2.s_f);
output.i_2 = base_i_2() * cabs(branch_solver_output2.i_f);
output.s_2 = base_power<sym> * cabs(branch_solver_output2.s_f);

output.p_3 = base_power<sym> * real(branch_math_output3.s_f);
output.q_3 = base_power<sym> * imag(branch_math_output3.s_f);
output.i_3 = base_i_3() * cabs(branch_math_output3.i_f);
output.s_3 = base_power<sym> * cabs(branch_math_output3.s_f);
output.p_3 = base_power<sym> * real(branch_solver_output3.s_f);
output.q_3 = base_power<sym> * imag(branch_solver_output3.s_f);
output.i_3 = base_i_3() * cabs(branch_solver_output3.i_f);
output.s_3 = base_power<sym> * cabs(branch_solver_output3.s_f);

output.loading = loading(sum_val(output.s_1), sum_val(output.s_2), sum_val(output.s_3));

Expand Down Expand Up @@ -150,10 +150,10 @@ class Branch3 : public Base {
return get_sc_output(iabc_1, iabc_2, iabc_3);
}
template <symmetry_tag sym>
Branch3ShortCircuitOutput get_sc_output(BranchShortCircuitMathOutput<sym> const& branch_math_output1,
BranchShortCircuitMathOutput<sym> const& branch_math_output2,
BranchShortCircuitMathOutput<sym> const& branch_math_output3) const {
return get_sc_output(branch_math_output1.i_f, branch_math_output2.i_f, branch_math_output3.i_f);
Branch3ShortCircuitOutput get_sc_output(BranchShortCircuitSolverOutput<sym> const& branch_solver_output1,
BranchShortCircuitSolverOutput<sym> const& branch_solver_output2,
BranchShortCircuitSolverOutput<sym> const& branch_solver_output3) const {
return get_sc_output(branch_solver_output1.i_f, branch_solver_output2.i_f, branch_solver_output3.i_f);
}

template <symmetry_tag sym> Branch3Output<sym> get_null_output() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class Fault final : public Base {
}

template <symmetry_tag sym>
FaultShortCircuitOutput get_sc_output(FaultShortCircuitMathOutput<sym> const& math_output,
FaultShortCircuitOutput get_sc_output(FaultShortCircuitSolverOutput<sym> const& solver_output,
double const u_rated) const {
return get_sc_output(math_output.i_fault, u_rated);
return get_sc_output(solver_output.i_fault, u_rated);
}

// update faulted object
Expand Down
Loading