@@ -32,31 +32,22 @@ class Source : public Appliance {
3232 explicit Source (SourceInput const & source_input, double u)
3333 : Appliance{source_input, u},
3434 u_ref_{source_input.u_ref },
35- u_ref_angle_{is_nan (source_input.u_ref_angle ) ? 0.0 : source_input.u_ref_angle } {
36- double const sk{is_nan (source_input.sk ) ? default_source_sk : source_input.sk };
37- double const rx_ratio{is_nan (source_input.rx_ratio ) ? default_source_rx_ratio : source_input.rx_ratio };
38- double const z01_ratio{is_nan (source_input.z01_ratio ) ? default_source_z01_ratio : source_input.z01_ratio };
39- calculate_y_ref (sk, rx_ratio, z01_ratio);
40- }
41-
42- // calculate y1 y0 ref
43- void calculate_y_ref (double sk, double rx_ratio, double z01_ratio) {
44- double const z_abs = base_power_3p / sk; // s_pu = s/base_s, z = u^2/s = 1/s = base_s/s_pu
45- double const x1 = z_abs / sqrt (rx_ratio * rx_ratio + 1.0 );
46- double const r1 = x1 * rx_ratio;
47- y1_ref_ = 1.0 / DoubleComplex{r1, x1};
48- y0_ref_ = y1_ref_ / z01_ratio;
49- }
35+ u_ref_angle_{is_nan (source_input.u_ref_angle ) ? 0.0 : source_input.u_ref_angle },
36+ sk_{is_nan (source_input.sk ) ? default_source_sk : source_input.sk },
37+ rx_ratio_{is_nan (source_input.rx_ratio ) ? default_source_rx_ratio : source_input.rx_ratio },
38+ z01_ratio_{is_nan (source_input.z01_ratio ) ? default_source_z01_ratio : source_input.z01_ratio } {}
5039
5140 template <symmetry_tag sym> SourceCalcParam math_param () const {
52- // internal element_admittance
53- SourceCalcParam param;
54- param.y0 = y0_ref_;
55- param.y1 = y1_ref_;
56- return param;
41+ // calculate y1 y0 ref
42+ double const z_abs = base_power_3p / sk_;
43+ double const x1 = z_abs / sqrt (rx_ratio_ * rx_ratio_ + 1.0 );
44+ double const r1 = x1 * rx_ratio_;
45+ DoubleComplex const y1_ref = 1.0 / DoubleComplex{r1, x1};
46+ DoubleComplex const y0_ref = y1_ref / z01_ratio_;
47+ return SourceCalcParam{.y1 = y1_ref, .y0 = y0_ref};
5748 }
5849
59- // setter
50+ // setter for u_ref
6051 bool set_u_ref (double new_u_ref, double new_u_ref_angle) {
6152 bool changed = false ;
6253 if (!is_nan (new_u_ref)) {
@@ -96,10 +87,13 @@ class Source : public Appliance {
9687 UpdateChange update (SourceUpdate const & update_data) {
9788 assert (update_data.id == this ->id () || is_nan (update_data.id ));
9889 bool const topo_changed = set_status (update_data.status );
99- bool const param_changed = set_u_ref (update_data.u_ref , update_data.u_ref_angle );
90+ set_u_ref (update_data.u_ref , update_data.u_ref_angle );
91+ bool const param_changed_impedance =
92+ set_sk_rx_ratio_z01_ratio (update_data.sk , update_data.rx_ratio , update_data.z01_ratio );
10093 // change source connection will change both topo and param
101- // change u ref will change param
102- return {.topo = topo_changed, .param = param_changed || topo_changed};
94+ // change u ref will NOT change param
95+ // change sk/rx_ratio/z01_ratio will change param
96+ return {.topo = topo_changed, .param = param_changed_impedance || topo_changed};
10397 }
10498
10599 SourceUpdate inverse (SourceUpdate update_data) const {
@@ -108,6 +102,9 @@ class Source : public Appliance {
108102 set_if_not_nan (update_data.status , status_to_int (this ->status ()));
109103 set_if_not_nan (update_data.u_ref , u_ref_);
110104 set_if_not_nan (update_data.u_ref_angle , u_ref_angle_);
105+ set_if_not_nan (update_data.sk , sk_);
106+ set_if_not_nan (update_data.rx_ratio , rx_ratio_);
107+ set_if_not_nan (update_data.z01_ratio , z01_ratio_);
111108
112109 return update_data;
113110 }
@@ -117,9 +114,27 @@ class Source : public Appliance {
117114 private:
118115 double u_ref_;
119116 double u_ref_angle_;
120- // positive and zero sequence ref
121- DoubleComplex y1_ref_;
122- DoubleComplex y0_ref_;
117+ // source short circuit power
118+ double sk_;
119+ double rx_ratio_;
120+ double z01_ratio_;
121+
122+ bool set_sk_rx_ratio_z01_ratio (double new_sk, double new_rx_ratio, double new_z01_ratio) {
123+ bool changed = false ;
124+ if (!is_nan (new_sk)) {
125+ sk_ = new_sk;
126+ changed = true ;
127+ }
128+ if (!is_nan (new_rx_ratio)) {
129+ rx_ratio_ = new_rx_ratio;
130+ changed = true ;
131+ }
132+ if (!is_nan (new_z01_ratio)) {
133+ z01_ratio_ = new_z01_ratio;
134+ changed = true ;
135+ }
136+ return changed;
137+ }
123138
124139 double injection_direction () const final { return 1.0 ; }
125140};
0 commit comments