00001
00012 #include <stdlib.h>
00013 #include <stdio.h>
00014 #include <errno.h>
00015 #include <math.h>
00016
00017 #include "load.h"
00018
00019 CLASS* load::oclass = NULL;
00020 CLASS* load::pclass = NULL;
00021
00022 load::load(MODULE *mod) : node(mod)
00023 {
00024 if(oclass == NULL)
00025 {
00026 pclass = node::oclass;
00027
00028 oclass = gl_register_class(mod,"load",sizeof(load),PC_PRETOPDOWN|PC_BOTTOMUP|PC_POSTTOPDOWN|PC_UNSAFE_OVERRIDE_OMIT|PC_AUTOLOCK);
00029 if (oclass==NULL)
00030 throw "unable to register class load";
00031 else
00032 oclass->trl = TRL_PROVEN;
00033
00034 if(gl_publish_variable(oclass,
00035 PT_INHERIT, "node",
00036 PT_enumeration, "load_class", PADDR(load_class),PT_DESCRIPTION,"Flag to track load type, not currently used for anything except sorting",
00037 PT_KEYWORD, "U", (enumeration)LC_UNKNOWN,
00038 PT_KEYWORD, "R", (enumeration)LC_RESIDENTIAL,
00039 PT_KEYWORD, "C", (enumeration)LC_COMMERCIAL,
00040 PT_KEYWORD, "I", (enumeration)LC_INDUSTRIAL,
00041 PT_KEYWORD, "A", (enumeration)LC_AGRICULTURAL,
00042 PT_enumeration, "load_priority", PADDR(load_priority),PT_DESCRIPTION,"Load classification based on priority",
00043 PT_KEYWORD, "DISCRETIONARY", (enumeration)DISCRETIONARY,
00044 PT_KEYWORD, "PRIORITY", (enumeration)PRIORITY,
00045 PT_KEYWORD, "CRITICAL", (enumeration)CRITICAL,
00046 PT_complex, "constant_power_A[VA]", PADDR(constant_power[0]),PT_DESCRIPTION,"constant power load on phase A, specified as VA",
00047 PT_complex, "constant_power_B[VA]", PADDR(constant_power[1]),PT_DESCRIPTION,"constant power load on phase B, specified as VA",
00048 PT_complex, "constant_power_C[VA]", PADDR(constant_power[2]),PT_DESCRIPTION,"constant power load on phase C, specified as VA",
00049 PT_double, "constant_power_A_real[W]", PADDR(constant_power[0].Re()),PT_DESCRIPTION,"constant power load on phase A, real only, specified as W",
00050 PT_double, "constant_power_B_real[W]", PADDR(constant_power[1].Re()),PT_DESCRIPTION,"constant power load on phase B, real only, specified as W",
00051 PT_double, "constant_power_C_real[W]", PADDR(constant_power[2].Re()),PT_DESCRIPTION,"constant power load on phase C, real only, specified as W",
00052 PT_double, "constant_power_A_reac[VAr]", PADDR(constant_power[0].Im()),PT_DESCRIPTION,"constant power load on phase A, imaginary only, specified as VAr",
00053 PT_double, "constant_power_B_reac[VAr]", PADDR(constant_power[1].Im()),PT_DESCRIPTION,"constant power load on phase B, imaginary only, specified as VAr",
00054 PT_double, "constant_power_C_reac[VAr]", PADDR(constant_power[2].Im()),PT_DESCRIPTION,"constant power load on phase C, imaginary only, specified as VAr",
00055 PT_complex, "constant_current_A[A]", PADDR(constant_current[0]),PT_DESCRIPTION,"constant current load on phase A, specified as Amps",
00056 PT_complex, "constant_current_B[A]", PADDR(constant_current[1]),PT_DESCRIPTION,"constant current load on phase B, specified as Amps",
00057 PT_complex, "constant_current_C[A]", PADDR(constant_current[2]),PT_DESCRIPTION,"constant current load on phase C, specified as Amps",
00058 PT_double, "constant_current_A_real[A]", PADDR(constant_current[0].Re()),PT_DESCRIPTION,"constant current load on phase A, real only, specified as Amps",
00059 PT_double, "constant_current_B_real[A]", PADDR(constant_current[1].Re()),PT_DESCRIPTION,"constant current load on phase B, real only, specified as Amps",
00060 PT_double, "constant_current_C_real[A]", PADDR(constant_current[2].Re()),PT_DESCRIPTION,"constant current load on phase C, real only, specified as Amps",
00061 PT_double, "constant_current_A_reac[A]", PADDR(constant_current[0].Im()),PT_DESCRIPTION,"constant current load on phase A, imaginary only, specified as Amps",
00062 PT_double, "constant_current_B_reac[A]", PADDR(constant_current[1].Im()),PT_DESCRIPTION,"constant current load on phase B, imaginary only, specified as Amps",
00063 PT_double, "constant_current_C_reac[A]", PADDR(constant_current[2].Im()),PT_DESCRIPTION,"constant current load on phase C, imaginary only, specified as Amps",
00064 PT_complex, "constant_impedance_A[Ohm]", PADDR(constant_impedance[0]),PT_DESCRIPTION,"constant impedance load on phase A, specified as Ohms",
00065 PT_complex, "constant_impedance_B[Ohm]", PADDR(constant_impedance[1]),PT_DESCRIPTION,"constant impedance load on phase B, specified as Ohms",
00066 PT_complex, "constant_impedance_C[Ohm]", PADDR(constant_impedance[2]),PT_DESCRIPTION,"constant impedance load on phase C, specified as Ohms",
00067 PT_double, "constant_impedance_A_real[Ohm]", PADDR(constant_impedance[0].Re()),PT_DESCRIPTION,"constant impedance load on phase A, real only, specified as Ohms",
00068 PT_double, "constant_impedance_B_real[Ohm]", PADDR(constant_impedance[1].Re()),PT_DESCRIPTION,"constant impedance load on phase B, real only, specified as Ohms",
00069 PT_double, "constant_impedance_C_real[Ohm]", PADDR(constant_impedance[2].Re()),PT_DESCRIPTION,"constant impedance load on phase C, real only, specified as Ohms",
00070 PT_double, "constant_impedance_A_reac[Ohm]", PADDR(constant_impedance[0].Im()),PT_DESCRIPTION,"constant impedance load on phase A, imaginary only, specified as Ohms",
00071 PT_double, "constant_impedance_B_reac[Ohm]", PADDR(constant_impedance[1].Im()),PT_DESCRIPTION,"constant impedance load on phase B, imaginary only, specified as Ohms",
00072 PT_double, "constant_impedance_C_reac[Ohm]", PADDR(constant_impedance[2].Im()),PT_DESCRIPTION,"constant impedance load on phase C, imaginary only, specified as Ohms",
00073
00074 PT_complex, "constant_power_AN[VA]", PADDR(constant_power_dy[3]),PT_DESCRIPTION,"constant power wye-connected load on phase A, specified as VA",
00075 PT_complex, "constant_power_BN[VA]", PADDR(constant_power_dy[4]),PT_DESCRIPTION,"constant power wye-connected load on phase B, specified as VA",
00076 PT_complex, "constant_power_CN[VA]", PADDR(constant_power_dy[5]),PT_DESCRIPTION,"constant power wye-connected load on phase C, specified as VA",
00077 PT_double, "constant_power_AN_real[W]", PADDR(constant_power_dy[3].Re()),PT_DESCRIPTION,"constant power wye-connected load on phase A, real only, specified as W",
00078 PT_double, "constant_power_BN_real[W]", PADDR(constant_power_dy[4].Re()),PT_DESCRIPTION,"constant power wye-connected load on phase B, real only, specified as W",
00079 PT_double, "constant_power_CN_real[W]", PADDR(constant_power_dy[5].Re()),PT_DESCRIPTION,"constant power wye-connected load on phase C, real only, specified as W",
00080 PT_double, "constant_power_AN_reac[VAr]", PADDR(constant_power_dy[3].Im()),PT_DESCRIPTION,"constant power wye-connected load on phase A, imaginary only, specified as VAr",
00081 PT_double, "constant_power_BN_reac[VAr]", PADDR(constant_power_dy[4].Im()),PT_DESCRIPTION,"constant power wye-connected load on phase B, imaginary only, specified as VAr",
00082 PT_double, "constant_power_CN_reac[VAr]", PADDR(constant_power_dy[5].Im()),PT_DESCRIPTION,"constant power wye-connected load on phase C, imaginary only, specified as VAr",
00083 PT_complex, "constant_current_AN[A]", PADDR(constant_current_dy[3]),PT_DESCRIPTION,"constant current wye-connected load on phase A, specified as Amps",
00084 PT_complex, "constant_current_BN[A]", PADDR(constant_current_dy[4]),PT_DESCRIPTION,"constant current wye-connected load on phase B, specified as Amps",
00085 PT_complex, "constant_current_CN[A]", PADDR(constant_current_dy[5]),PT_DESCRIPTION,"constant current wye-connected load on phase C, specified as Amps",
00086 PT_double, "constant_current_AN_real[A]", PADDR(constant_current_dy[3].Re()),PT_DESCRIPTION,"constant current wye-connected load on phase A, real only, specified as Amps",
00087 PT_double, "constant_current_BN_real[A]", PADDR(constant_current_dy[4].Re()),PT_DESCRIPTION,"constant current wye-connected load on phase B, real only, specified as Amps",
00088 PT_double, "constant_current_CN_real[A]", PADDR(constant_current_dy[5].Re()),PT_DESCRIPTION,"constant current wye-connected load on phase C, real only, specified as Amps",
00089 PT_double, "constant_current_AN_reac[A]", PADDR(constant_current_dy[3].Im()),PT_DESCRIPTION,"constant current wye-connected load on phase A, imaginary only, specified as Amps",
00090 PT_double, "constant_current_BN_reac[A]", PADDR(constant_current_dy[4].Im()),PT_DESCRIPTION,"constant current wye-connected load on phase B, imaginary only, specified as Amps",
00091 PT_double, "constant_current_CN_reac[A]", PADDR(constant_current_dy[5].Im()),PT_DESCRIPTION,"constant current wye-connected load on phase C, imaginary only, specified as Amps",
00092 PT_complex, "constant_impedance_AN[Ohm]", PADDR(constant_impedance_dy[3]),PT_DESCRIPTION,"constant impedance wye-connected load on phase A, specified as Ohms",
00093 PT_complex, "constant_impedance_BN[Ohm]", PADDR(constant_impedance_dy[4]),PT_DESCRIPTION,"constant impedance wye-connected load on phase B, specified as Ohms",
00094 PT_complex, "constant_impedance_CN[Ohm]", PADDR(constant_impedance_dy[5]),PT_DESCRIPTION,"constant impedance wye-connected load on phase C, specified as Ohms",
00095 PT_double, "constant_impedance_AN_real[Ohm]", PADDR(constant_impedance_dy[3].Re()),PT_DESCRIPTION,"constant impedance wye-connected load on phase A, real only, specified as Ohms",
00096 PT_double, "constant_impedance_BN_real[Ohm]", PADDR(constant_impedance_dy[4].Re()),PT_DESCRIPTION,"constant impedance wye-connected load on phase B, real only, specified as Ohms",
00097 PT_double, "constant_impedance_CN_real[Ohm]", PADDR(constant_impedance_dy[5].Re()),PT_DESCRIPTION,"constant impedance wye-connected load on phase C, real only, specified as Ohms",
00098 PT_double, "constant_impedance_AN_reac[Ohm]", PADDR(constant_impedance_dy[3].Im()),PT_DESCRIPTION,"constant impedance wye-connected load on phase A, imaginary only, specified as Ohms",
00099 PT_double, "constant_impedance_BN_reac[Ohm]", PADDR(constant_impedance_dy[4].Im()),PT_DESCRIPTION,"constant impedance wye-connected load on phase B, imaginary only, specified as Ohms",
00100 PT_double, "constant_impedance_CN_reac[Ohm]", PADDR(constant_impedance_dy[5].Im()),PT_DESCRIPTION,"constant impedance wye-connected load on phase C, imaginary only, specified as Ohms",
00101
00102 PT_complex, "constant_power_AB[VA]", PADDR(constant_power_dy[0]),PT_DESCRIPTION,"constant power delta-connected load on phase A, specified as VA",
00103 PT_complex, "constant_power_BC[VA]", PADDR(constant_power_dy[1]),PT_DESCRIPTION,"constant power delta-connected load on phase B, specified as VA",
00104 PT_complex, "constant_power_CA[VA]", PADDR(constant_power_dy[2]),PT_DESCRIPTION,"constant power delta-connected load on phase C, specified as VA",
00105 PT_double, "constant_power_AB_real[W]", PADDR(constant_power_dy[0].Re()),PT_DESCRIPTION,"constant power delta-connected load on phase A, real only, specified as W",
00106 PT_double, "constant_power_BC_real[W]", PADDR(constant_power_dy[1].Re()),PT_DESCRIPTION,"constant power delta-connected load on phase B, real only, specified as W",
00107 PT_double, "constant_power_CA_real[W]", PADDR(constant_power_dy[2].Re()),PT_DESCRIPTION,"constant power delta-connected load on phase C, real only, specified as W",
00108 PT_double, "constant_power_AB_reac[VAr]", PADDR(constant_power_dy[0].Im()),PT_DESCRIPTION,"constant power delta-connected load on phase A, imaginary only, specified as VAr",
00109 PT_double, "constant_power_BC_reac[VAr]", PADDR(constant_power_dy[1].Im()),PT_DESCRIPTION,"constant power delta-connected load on phase B, imaginary only, specified as VAr",
00110 PT_double, "constant_power_CA_reac[VAr]", PADDR(constant_power_dy[2].Im()),PT_DESCRIPTION,"constant power delta-connected load on phase C, imaginary only, specified as VAr",
00111 PT_complex, "constant_current_AB[A]", PADDR(constant_current_dy[0]),PT_DESCRIPTION,"constant current delta-connected load on phase A, specified as Amps",
00112 PT_complex, "constant_current_BC[A]", PADDR(constant_current_dy[1]),PT_DESCRIPTION,"constant current delta-connected load on phase B, specified as Amps",
00113 PT_complex, "constant_current_CA[A]", PADDR(constant_current_dy[2]),PT_DESCRIPTION,"constant current delta-connected load on phase C, specified as Amps",
00114 PT_double, "constant_current_AB_real[A]", PADDR(constant_current_dy[0].Re()),PT_DESCRIPTION,"constant current delta-connected load on phase A, real only, specified as Amps",
00115 PT_double, "constant_current_BC_real[A]", PADDR(constant_current_dy[1].Re()),PT_DESCRIPTION,"constant current delta-connected load on phase B, real only, specified as Amps",
00116 PT_double, "constant_current_CA_real[A]", PADDR(constant_current_dy[2].Re()),PT_DESCRIPTION,"constant current delta-connected load on phase C, real only, specified as Amps",
00117 PT_double, "constant_current_AB_reac[A]", PADDR(constant_current_dy[0].Im()),PT_DESCRIPTION,"constant current delta-connected load on phase A, imaginary only, specified as Amps",
00118 PT_double, "constant_current_BC_reac[A]", PADDR(constant_current_dy[1].Im()),PT_DESCRIPTION,"constant current delta-connected load on phase B, imaginary only, specified as Amps",
00119 PT_double, "constant_current_CA_reac[A]", PADDR(constant_current_dy[2].Im()),PT_DESCRIPTION,"constant current delta-connected load on phase C, imaginary only, specified as Amps",
00120 PT_complex, "constant_impedance_AB[Ohm]", PADDR(constant_impedance_dy[0]),PT_DESCRIPTION,"constant impedance delta-connected load on phase A, specified as Ohms",
00121 PT_complex, "constant_impedance_BC[Ohm]", PADDR(constant_impedance_dy[1]),PT_DESCRIPTION,"constant impedance delta-connected load on phase B, specified as Ohms",
00122 PT_complex, "constant_impedance_CA[Ohm]", PADDR(constant_impedance_dy[2]),PT_DESCRIPTION,"constant impedance delta-connected load on phase C, specified as Ohms",
00123 PT_double, "constant_impedance_AB_real[Ohm]", PADDR(constant_impedance_dy[0].Re()),PT_DESCRIPTION,"constant impedance delta-connected load on phase A, real only, specified as Ohms",
00124 PT_double, "constant_impedance_BC_real[Ohm]", PADDR(constant_impedance_dy[1].Re()),PT_DESCRIPTION,"constant impedance delta-connected load on phase B, real only, specified as Ohms",
00125 PT_double, "constant_impedance_CA_real[Ohm]", PADDR(constant_impedance_dy[2].Re()),PT_DESCRIPTION,"constant impedance delta-connected load on phase C, real only, specified as Ohms",
00126 PT_double, "constant_impedance_AB_reac[Ohm]", PADDR(constant_impedance_dy[0].Im()),PT_DESCRIPTION,"constant impedance delta-connected load on phase A, imaginary only, specified as Ohms",
00127 PT_double, "constant_impedance_BC_reac[Ohm]", PADDR(constant_impedance_dy[1].Im()),PT_DESCRIPTION,"constant impedance delta-connected load on phase B, imaginary only, specified as Ohms",
00128 PT_double, "constant_impedance_CA_reac[Ohm]", PADDR(constant_impedance_dy[2].Im()),PT_DESCRIPTION,"constant impedance delta-connected load on phase C, imaginary only, specified as Ohms",
00129
00130 PT_complex, "measured_voltage_A",PADDR(measured_voltage_A),PT_DESCRIPTION,"current measured voltage on phase A",
00131 PT_complex, "measured_voltage_B",PADDR(measured_voltage_B),PT_DESCRIPTION,"current measured voltage on phase B",
00132 PT_complex, "measured_voltage_C",PADDR(measured_voltage_C),PT_DESCRIPTION,"current measured voltage on phase C",
00133 PT_complex, "measured_voltage_AB",PADDR(measured_voltage_AB),PT_DESCRIPTION,"current measured voltage on phases AB",
00134 PT_complex, "measured_voltage_BC",PADDR(measured_voltage_BC),PT_DESCRIPTION,"current measured voltage on phases BC",
00135 PT_complex, "measured_voltage_CA",PADDR(measured_voltage_CA),PT_DESCRIPTION,"current measured voltage on phases CA",
00136 PT_bool, "phase_loss_protection", PADDR(three_phase_protect), PT_DESCRIPTION, "Trip all three phases of the load if a fault occurs",
00137
00138
00139
00140
00141 PT_double, "base_power_A[VA]",PADDR(base_power[0]),PT_DESCRIPTION,"in similar format as ZIPload, this represents the nominal power on phase A before applying ZIP fractions",
00142 PT_double, "base_power_B[VA]",PADDR(base_power[1]),PT_DESCRIPTION,"in similar format as ZIPload, this represents the nominal power on phase B before applying ZIP fractions",
00143 PT_double, "base_power_C[VA]",PADDR(base_power[2]),PT_DESCRIPTION,"in similar format as ZIPload, this represents the nominal power on phase C before applying ZIP fractions",
00144 PT_double, "power_pf_A[pu]",PADDR(power_pf[0]),PT_DESCRIPTION,"in similar format as ZIPload, this is the power factor of the phase A constant power portion of load",
00145 PT_double, "current_pf_A[pu]",PADDR(current_pf[0]),PT_DESCRIPTION,"in similar format as ZIPload, this is the power factor of the phase A constant current portion of load",
00146 PT_double, "impedance_pf_A[pu]",PADDR(impedance_pf[0]),PT_DESCRIPTION,"in similar format as ZIPload, this is the power factor of the phase A constant impedance portion of load",
00147 PT_double, "power_pf_B[pu]",PADDR(power_pf[1]),PT_DESCRIPTION,"in similar format as ZIPload, this is the power factor of the phase B constant power portion of load",
00148 PT_double, "current_pf_B[pu]",PADDR(current_pf[1]),PT_DESCRIPTION,"in similar format as ZIPload, this is the power factor of the phase B constant current portion of load",
00149 PT_double, "impedance_pf_B[pu]",PADDR(impedance_pf[1]),PT_DESCRIPTION,"in similar format as ZIPload, this is the power factor of the phase B constant impedance portion of load",
00150 PT_double, "power_pf_C[pu]",PADDR(power_pf[2]),PT_DESCRIPTION,"in similar format as ZIPload, this is the power factor of the phase C constant power portion of load",
00151 PT_double, "current_pf_C[pu]",PADDR(current_pf[2]),PT_DESCRIPTION,"in similar format as ZIPload, this is the power factor of the phase C constant current portion of load",
00152 PT_double, "impedance_pf_C[pu]",PADDR(impedance_pf[2]),PT_DESCRIPTION,"in similar format as ZIPload, this is the power factor of the phase C constant impedance portion of load",
00153 PT_double, "power_fraction_A[pu]",PADDR(power_fraction[0]),PT_DESCRIPTION,"this is the constant power fraction of base power on phase A",
00154 PT_double, "current_fraction_A[pu]",PADDR(current_fraction[0]),PT_DESCRIPTION,"this is the constant current fraction of base power on phase A",
00155 PT_double, "impedance_fraction_A[pu]",PADDR(impedance_fraction[0]),PT_DESCRIPTION,"this is the constant impedance fraction of base power on phase A",
00156 PT_double, "power_fraction_B[pu]",PADDR(power_fraction[1]),PT_DESCRIPTION,"this is the constant power fraction of base power on phase B",
00157 PT_double, "current_fraction_B[pu]",PADDR(current_fraction[1]),PT_DESCRIPTION,"this is the constant current fraction of base power on phase B",
00158 PT_double, "impedance_fraction_B[pu]",PADDR(impedance_fraction[1]),PT_DESCRIPTION,"this is the constant impedance fraction of base power on phase B",
00159 PT_double, "power_fraction_C[pu]",PADDR(power_fraction[2]),PT_DESCRIPTION,"this is the constant power fraction of base power on phase C",
00160 PT_double, "current_fraction_C[pu]",PADDR(current_fraction[2]),PT_DESCRIPTION,"this is the constant current fraction of base power on phase C",
00161 PT_double, "impedance_fraction_C[pu]",PADDR(impedance_fraction[2]),PT_DESCRIPTION,"this is the constant impedance fraction of base power on phase C",
00162
00163 PT_enumeration, "inrush_integration_method_capacitance",PADDR(inrush_int_method_capacitance),PT_DESCRIPTION,"Selected integration method to use for capacitive elements of the load",
00164 PT_KEYWORD,"NONE",(enumeration)IRM_NONE,
00165 PT_KEYWORD,"UNDEFINED",(enumeration)IRM_UNDEFINED,
00166 PT_KEYWORD,"TRAPEZOIDAL",(enumeration)IRM_TRAPEZOIDAL,
00167 PT_KEYWORD,"BACKWARD_EULER",(enumeration)IRM_BACKEULER,
00168
00169 PT_enumeration, "inrush_integration_method_inductance",PADDR(inrush_int_method_inductance),PT_DESCRIPTION,"Selected integration method to use for inductive elements of the load",
00170 PT_KEYWORD,"NONE",(enumeration)IRM_NONE,
00171 PT_KEYWORD,"UNDEFINED",(enumeration)IRM_UNDEFINED,
00172 PT_KEYWORD,"TRAPEZOIDAL",(enumeration)IRM_TRAPEZOIDAL,
00173 PT_KEYWORD,"BACKWARD_EULER",(enumeration)IRM_BACKEULER,
00174
00175 NULL) < 1) GL_THROW("unable to publish properties in %s",__FILE__);
00176
00177
00178 if (gl_publish_function(oclass, "interupdate_pwr_object", (FUNCTIONADDR)interupdate_load)==NULL)
00179 GL_THROW("Unable to publish load deltamode function");
00180 if (gl_publish_function(oclass, "pwr_object_swing_swapper", (FUNCTIONADDR)swap_node_swing_status)==NULL)
00181 GL_THROW("Unable to publish load swing-swapping function");
00182 if (gl_publish_function(oclass, "pwr_current_injection_update_map", (FUNCTIONADDR)node_map_current_update_function)==NULL)
00183 GL_THROW("Unable to publish load current injection update mapping function");
00184 if (gl_publish_function(oclass, "attach_vfd_to_pwr_object", (FUNCTIONADDR)attach_vfd_to_node)==NULL)
00185 GL_THROW("Unable to publish load VFD attachment function");
00186 if (gl_publish_function(oclass, "pwr_object_reset_disabled_status", (FUNCTIONADDR)node_reset_disabled_status) == NULL)
00187 GL_THROW("Unable to publish load island-status-reset function");
00188 }
00189 }
00190
00191 int load::isa(char *classname)
00192 {
00193 return strcmp(classname,"load")==0 || node::isa(classname);
00194 }
00195
00196 int load::create(void)
00197 {
00198 int res = node::create();
00199
00200 maximum_voltage_error = 0;
00201 base_power[0] = base_power[1] = base_power[2] = 0;
00202 power_fraction[0] = power_fraction[1] = power_fraction[2] = 0;
00203 current_fraction[0] = current_fraction[1] = current_fraction[2] = 0;
00204 impedance_fraction[0] = impedance_fraction[1] = impedance_fraction[2] = 0;
00205 power_pf[0] = power_pf[1] = power_pf[2] = 1;
00206 current_pf[0] = current_pf[1] = current_pf[2] = 1;
00207 impedance_pf[0] = impedance_pf[1] = impedance_pf[2] = 1;
00208 load_class = LC_UNKNOWN;
00209 three_phase_protect = false;
00210
00211
00212 constant_power[0] = constant_power[1] = constant_power[2] = 0.0;
00213 constant_current[0] = constant_current[1] = constant_current[2] = 0.0;
00214 constant_impedance[0] = constant_impedance[1] = constant_impedance[2] = 0.0;
00215
00216 constant_power_dy[0] = constant_power_dy[1] = constant_power_dy[2] = 0.0;
00217 constant_current_dy[0] = constant_current_dy[1] = constant_current_dy[2] = 0.0;
00218 constant_impedance_dy[0] = constant_impedance_dy[1] = constant_impedance_dy[2] = 0.0;
00219
00220 constant_power_dy[3] = constant_power_dy[4] = constant_power_dy[5] = 0.0;
00221 constant_current_dy[3] = constant_current_dy[4] = constant_current_dy[5] = 0.0;
00222 constant_impedance_dy[3] = constant_impedance_dy[4] = constant_impedance_dy[5] = 0.0;
00223
00224
00225 node_type = LOAD_NODE;
00226
00227
00228 prev_shunt[0] = prev_shunt[1] = prev_shunt[2] = complex(0.0,0.0);
00229
00230
00231 base_load_val_was_nonzero[0] = base_load_val_was_nonzero[1] = base_load_val_was_nonzero[2] = false;
00232
00233
00234 inrush_int_method_inductance = IRM_UNDEFINED;
00235 inrush_int_method_capacitance = IRM_UNDEFINED;
00236
00237 return res;
00238 }
00239
00240
00241 int load::init(OBJECT *parent)
00242 {
00243 char temp_buff[128];
00244 OBJECT *obj = OBJECTHDR(this);
00245 int ret_value;
00246
00247 if (has_phase(PHASE_S))
00248 {
00249 GL_THROW("Load objects do not support triplex connections at this time!");
00250
00251
00252
00253
00254 }
00255
00256
00257
00258 gl_global_getvar("multirun_mode",temp_buff,sizeof(temp_buff));
00259
00260
00261 if (strcmp(temp_buff,"STANDALONE"))
00262 {
00263 if (solver_method == SM_NR)
00264 {
00265
00266 prev_power_value = (complex *)gl_malloc(3*sizeof(complex));
00267
00268
00269 if (prev_power_value==NULL)
00270 {
00271 GL_THROW("Failure to allocate memory for power tracking array");
00272
00273
00274
00275
00276
00277
00278 }
00279
00280
00281 prev_power_value[0] = complex(0.0,0.0);
00282 prev_power_value[1] = complex(0.0,0.0);
00283 prev_power_value[2] = complex(0.0,0.0);
00284 }
00285 }
00286
00287
00288 ret_value = node::init(parent);
00289
00290 if ((obj->flags & OF_DELTAMODE) == OF_DELTAMODE)
00291 {
00292 if ((constant_current[0] != 0.0) || (constant_current[1] != 0.0) || (constant_current[2] != 0.0))
00293 {
00294 gl_warning("load:%s - constant_current loads in deltamode are handled slightly different", obj->name ? obj->name : "unnamed");
00295
00296
00297
00298
00299
00300 }
00301
00302
00303 if ((constant_current_dy[0] != 0.0) || (constant_current_dy[1] != 0.0) || (constant_current_dy[2] != 0.0) || (constant_current_dy[3] != 0.0) || (constant_current_dy[4] != 0.0) || (constant_current_dy[5] != 0.0))
00304 {
00305 gl_warning("load:%s - constant_current loads in deltamode are handled slightly different", obj->name ? obj->name : "unnamed");
00306
00307 }
00308
00309
00310 if (enable_inrush_calculations==true)
00311 {
00312
00313 if (inrush_int_method_inductance == IRM_UNDEFINED)
00314 {
00315
00316 inrush_int_method_inductance = inrush_integration_method;
00317 }
00318
00319
00320 if (inrush_int_method_capacitance == IRM_UNDEFINED)
00321 {
00322
00323 inrush_int_method_capacitance = inrush_integration_method;
00324 }
00325
00326
00327
00328 ahrlloadstore = (complex *)gl_malloc(3*sizeof(complex));
00329
00330
00331 if (ahrlloadstore == NULL)
00332 {
00333 GL_THROW("load:%d-%s - failed to allocate memory for in-rush calculations",obj->id, obj->name ? obj->name : "unnamed");
00334
00335
00336
00337
00338 }
00339
00340
00341 bhrlloadstore = (complex *)gl_malloc(3*sizeof(complex));
00342
00343
00344 if (bhrlloadstore == NULL)
00345 {
00346 GL_THROW("load:%d-%s - failed to allocate memory for in-rush calculations",obj->id, obj->name ? obj->name : "unnamed");
00347
00348 }
00349
00350
00351 chrcloadstore = (complex *)gl_malloc(3*sizeof(complex));
00352
00353
00354 if (chrcloadstore == NULL)
00355 {
00356 GL_THROW("load:%d-%s - failed to allocate memory for in-rush calculations",obj->id, obj->name ? obj->name : "unnamed");
00357
00358 }
00359
00360
00361 LoadHistTermL = (complex *)gl_malloc(6*sizeof(complex));
00362
00363
00364 if (LoadHistTermL == NULL)
00365 {
00366 GL_THROW("load:%d-%s - failed to allocate memory for in-rush calculations",obj->id, obj->name ? obj->name : "unnamed");
00367
00368 }
00369
00370
00371 LoadHistTermC = (complex *)gl_malloc(6*sizeof(complex));
00372
00373
00374 if (LoadHistTermC == NULL)
00375 {
00376 GL_THROW("load:%d-%s - failed to allocate memory for in-rush calculations",obj->id, obj->name ? obj->name : "unnamed");
00377
00378 }
00379
00380
00381 full_Y_load = (complex *)gl_malloc(3*sizeof(complex));
00382
00383
00384 if (full_Y_load == NULL)
00385 {
00386 GL_THROW("load:%d-%s - failed to allocate memory for in-rush calculations",obj->id, obj->name ? obj->name : "unnamed");
00387
00388 }
00389
00390
00391 ahrlloadstore[0] = ahrlloadstore[1] = ahrlloadstore[2] = complex(0.0,0.0);
00392 bhrlloadstore[0] = bhrlloadstore[1] = bhrlloadstore[2] = complex(0.0,0.0);
00393 chrcloadstore[0] = chrcloadstore[1] = chrcloadstore[2] = complex(0.0,0.0);
00394
00395 LoadHistTermL[0] = LoadHistTermL[1] = LoadHistTermL[2] = complex(0.0,0.0);
00396 LoadHistTermL[3] = LoadHistTermL[4] = LoadHistTermL[5] = complex(0.0,0.0);
00397
00398 LoadHistTermC[0] = LoadHistTermC[1] = LoadHistTermC[2] = complex(0.0,0.0);
00399 LoadHistTermC[3] = LoadHistTermC[4] = LoadHistTermC[5] = complex(0.0,0.0);
00400
00401 full_Y_load[0] = full_Y_load[1] = full_Y_load[2] = complex(0.0,0.0);
00402
00403
00404 }
00405
00406 }
00407
00408 return ret_value;
00409 }
00410
00411 TIMESTAMP load::presync(TIMESTAMP t0)
00412 {
00413 if ((solver_method!=SM_FBS) && ((SubNode==PARENT) || (SubNode==DIFF_PARENT)))
00414 {
00415 if (SubNode == PARENT)
00416 {
00417 shunt[0] = shunt[1] = shunt[2] = 0.0;
00418 power[0] = power[1] = power[2] = 0.0;
00419 current[0] = current[1] = current[2] = 0.0;
00420 }
00421
00422
00423 shunt_dy[0] = shunt_dy[1] = shunt_dy[2] = 0.0;
00424 shunt_dy[3] = shunt_dy[4] = shunt_dy[5] = 0.0;
00425 power_dy[0] = power_dy[1] = power_dy[2] = 0.0;
00426 power_dy[3] = power_dy[4] = power_dy[5] = 0.0;
00427 current_dy[0] = current_dy[1] = current_dy[2] = 0.0;
00428 current_dy[3] = current_dy[4] = current_dy[5] = 0.0;
00429 }
00430
00431
00432 TIMESTAMP result = node::presync(t0);
00433
00434 return result;
00435 }
00436
00437 TIMESTAMP load::sync(TIMESTAMP t0)
00438 {
00439
00440 bool fault_mode;
00441 TIMESTAMP tresults_val, result;
00442
00443
00444 tresults_val = TS_NEVER;
00445
00446
00447 if (fault_check_object == NULL)
00448 fault_mode = false;
00449 else
00450 fault_mode = true;
00451
00452
00453 if (GFA_enable == true)
00454 {
00455
00456 if (GFA_status == true)
00457 {
00458
00459 load_update_fxn(fault_mode);
00460 }
00461 else
00462 {
00463
00464 load_delete_update_fxn();
00465 }
00466 }
00467 else
00468 {
00469
00470 load_update_fxn(fault_mode);
00471 }
00472
00473
00474 result = node::sync(t0);
00475
00476 return result;
00477 }
00478
00479 TIMESTAMP load::postsync(TIMESTAMP t0)
00480 {
00481
00482 TIMESTAMP t1 = node::postsync(t0);
00483
00484
00485 measured_voltage_A.SetPolar(voltageA.Mag(),voltageA.Arg());
00486 measured_voltage_B.SetPolar(voltageB.Mag(),voltageB.Arg());
00487 measured_voltage_C.SetPolar(voltageC.Mag(),voltageC.Arg());
00488 measured_voltage_AB = measured_voltage_A-measured_voltage_B;
00489 measured_voltage_BC = measured_voltage_B-measured_voltage_C;
00490 measured_voltage_CA = measured_voltage_C-measured_voltage_A;
00491
00492 return t1;
00493 }
00494
00495
00496
00497 void load::load_update_fxn(bool fault_mode)
00498 {
00499 bool all_three_phases, transf_from_stdy_state;
00500 complex intermed_impedance[3];
00501 complex intermed_impedance_dy[6];
00502 int index_var;
00503 bool volt_below_thresh;
00504 double voltage_base_val;
00505 double voltage_pu_vals[3];
00506 complex nominal_voltage_value;
00507 int node_reference_value;
00508 double curr_delta_time;
00509 bool require_inrush_update;
00510 complex working_impedance_value, working_data_value, working_admittance_value;
00511 double workingvalue;
00512 OBJECT *obj;
00513 double baseangles[3];
00514 node *temp_par_node = NULL;
00515
00516
00517
00518
00519
00520
00521 baseangles[0] = 0.0;
00522 baseangles[1] = -2.0*PI/3.0;
00523 baseangles[2] = 2.0*PI/3.0;
00524
00525 for (int index=0; index<3; index++)
00526 {
00527 if (base_power[index] != 0.0)
00528 {
00529
00530 base_load_val_was_nonzero[index] = true;
00531
00532 if (power_fraction[index] + current_fraction[index] + impedance_fraction[index] != 1.0)
00533 {
00534 power_fraction[index] = 1 - current_fraction[index] - impedance_fraction[index];
00535
00536 char temp[3] = {'A','B','C'};
00537
00538 OBJECT *obj = OBJECTHDR(this);
00539
00540 gl_warning("load:%s - ZIP components on phase %c did not sum to 1. Setting power_fraction to %.2f", obj->name ? obj->name : "unnamed", temp[index], power_fraction[index]);
00541
00542
00543
00544
00545 }
00546
00547
00548 if (power_fraction[index] != 0.0)
00549 {
00550 double real_power,imag_power;
00551
00552 if (power_pf[index] == 0.0)
00553 {
00554 real_power = 0.0;
00555 imag_power = base_power[index] * power_fraction[index];
00556 }
00557 else
00558 {
00559 real_power = base_power[index] * power_fraction[index] * fabs(power_pf[index]);
00560 imag_power = real_power * sqrt(1.0/(power_pf[index] * power_pf[index]) - 1.0);
00561 }
00562
00563 if (power_pf[index] < 0)
00564 {
00565 imag_power *= -1.0;
00566 }
00567 constant_power[index] = complex(real_power,imag_power);
00568 }
00569 else
00570 {
00571 constant_power[index] = complex(0,0);
00572 }
00573
00574
00575 if (current_fraction[index] != 0.0)
00576 {
00577 double real_power,imag_power,temp_angle;
00578 complex temp_curr;
00579
00580 if (current_pf[index] == 0.0)
00581 {
00582 real_power = 0.0;
00583 imag_power = base_power[index] * current_fraction[index];
00584 }
00585 else
00586 {
00587 real_power = base_power[index] * current_fraction[index] * fabs(current_pf[index]);
00588 imag_power = real_power * sqrt(1.0/(current_pf[index] * current_pf[index]) - 1.0);
00589 }
00590
00591 if (current_pf[index] < 0)
00592 {
00593 imag_power *= -1.0;
00594 }
00595
00596
00597 temp_curr = ~complex(real_power,imag_power) / complex(nominal_voltage,0);
00598
00599
00600
00601 temp_angle = temp_curr.Arg() + baseangles[index];
00602 temp_curr.SetPolar(temp_curr.Mag(),temp_angle);
00603
00604 constant_current[index] = temp_curr;
00605 }
00606 else
00607 {
00608 constant_current[index] = complex(0,0);
00609 }
00610
00611
00612 if (impedance_fraction[index] != 0.0)
00613 {
00614 double real_power,imag_power;
00615
00616 if (impedance_pf[index] == 0.0)
00617 {
00618 real_power = 0.0;
00619 imag_power = base_power[index] * impedance_fraction[index];
00620 }
00621 else
00622 {
00623 real_power = base_power[index] * impedance_fraction[index] * fabs(impedance_pf[index]);
00624 imag_power = real_power * sqrt(1.0/(impedance_pf[index] * impedance_pf[index]) - 1.0);
00625 }
00626
00627 if (impedance_pf[index] < 0)
00628 {
00629 imag_power *= -1.0;
00630 }
00631
00632 constant_impedance[index] = ~( complex(nominal_voltage * nominal_voltage, 0) / complex(real_power,imag_power) );
00633
00634 }
00635 else
00636 {
00637 constant_impedance[index] = complex(0,0);
00638 }
00639 }
00640 else if (base_load_val_was_nonzero[index] == true)
00641 {
00642
00643 constant_power[index] = complex(0.0,0.0);
00644 constant_current[index] = complex(0.0,0.0);
00645 constant_impedance[index] = complex(0.0,0.0);
00646
00647
00648 base_load_val_was_nonzero[index] = false;
00649 }
00650 }
00651
00652
00653 if (enable_frequency_dependence == true)
00654 {
00655
00656 for (index_var=0; index_var<3; index_var++)
00657 {
00658 if ((constant_impedance[index_var].IsZero()) == false)
00659 {
00660
00661 intermed_impedance[index_var].SetReal(constant_impedance[index_var].Re());
00662
00663
00664 if (constant_impedance[index_var].Im()<0)
00665 {
00666 intermed_impedance[index_var].SetImag(constant_impedance[index_var].Im()/current_frequency*nominal_frequency);
00667 }
00668 else
00669 {
00670 intermed_impedance[index_var].SetImag(constant_impedance[index_var].Im()/nominal_frequency*current_frequency);
00671 }
00672 }
00673 else
00674 {
00675 intermed_impedance[index_var] = 0.0;
00676 }
00677 }
00678
00679
00680 for (index_var=0; index_var<6; index_var++)
00681 {
00682 if ((constant_impedance_dy[index_var].IsZero()) == false)
00683 {
00684
00685 intermed_impedance_dy[index_var].SetReal(constant_impedance_dy[index_var].Re());
00686
00687
00688 if (constant_impedance_dy[index_var].Im()<0)
00689 {
00690 intermed_impedance_dy[index_var].SetImag(constant_impedance_dy[index_var].Im()/current_frequency*nominal_frequency);
00691 }
00692 else
00693 {
00694 intermed_impedance_dy[index_var].SetImag(constant_impedance_dy[index_var].Im()/nominal_frequency*current_frequency);
00695 }
00696 }
00697 else
00698 {
00699 intermed_impedance_dy[index_var] = 0.0;
00700 }
00701 }
00702 }
00703 else
00704 {
00705 intermed_impedance[0] = constant_impedance[0];
00706 intermed_impedance[1] = constant_impedance[1];
00707 intermed_impedance[2] = constant_impedance[2];
00708
00709
00710 for (index_var=0; index_var<6; index_var++)
00711 {
00712 intermed_impedance_dy[index_var] = constant_impedance_dy[index_var];
00713 }
00714 }
00715
00716 if (fault_mode == false)
00717 {
00718 if ((solver_method!=SM_FBS) && ((SubNode==PARENT) || (SubNode==DIFF_PARENT)))
00719 {
00720 if (SubNode == PARENT)
00721 {
00722 if (!(intermed_impedance[0].IsZero()))
00723 shunt[0] += complex(1.0)/intermed_impedance[0];
00724
00725 if (!(intermed_impedance[1].IsZero()))
00726 shunt[1] += complex(1.0)/intermed_impedance[1];
00727
00728 if (!(intermed_impedance[2].IsZero()))
00729 shunt[2] += complex(1.0)/intermed_impedance[2];
00730
00731 power[0] += constant_power[0];
00732 power[1] += constant_power[1];
00733 power[2] += constant_power[2];
00734
00735 current[0] += constant_current[0];
00736 current[1] += constant_current[1];
00737 current[2] += constant_current[2];
00738 }
00739 else
00740 {
00741 if(intermed_impedance[0].IsZero())
00742 shunt[0] = 0.0;
00743 else
00744 shunt[0] = complex(1.0)/intermed_impedance[0];
00745
00746 if(intermed_impedance[1].IsZero())
00747 shunt[1] = 0.0;
00748 else
00749 shunt[1] = complex(1.0)/intermed_impedance[1];
00750
00751 if(intermed_impedance[2].IsZero())
00752 shunt[2] = 0.0;
00753 else
00754 shunt[2] = complex(1.0)/intermed_impedance[2];
00755
00756 power[0] = constant_power[0];
00757 power[1] = constant_power[1];
00758 power[2] = constant_power[2];
00759 current[0] = constant_current[0];
00760 current[1] = constant_current[1];
00761 current[2] = constant_current[2];
00762 }
00763
00764
00765 for (index_var=0; index_var<6; index_var++)
00766 {
00767 if (!(intermed_impedance_dy[index_var].IsZero()))
00768 shunt_dy[index_var] += complex(1.0)/intermed_impedance_dy[index_var];
00769
00770 power_dy[index_var] += constant_power_dy[index_var];
00771
00772 current_dy[index_var] += constant_current_dy[index_var];
00773 }
00774 }
00775 else
00776 {
00777 if(intermed_impedance[0].IsZero())
00778 shunt[0] = 0.0;
00779 else
00780 shunt[0] = complex(1.0)/intermed_impedance[0];
00781
00782 if(intermed_impedance[1].IsZero())
00783 shunt[1] = 0.0;
00784 else
00785 shunt[1] = complex(1.0)/intermed_impedance[1];
00786
00787 if(intermed_impedance[2].IsZero())
00788 shunt[2] = 0.0;
00789 else
00790 shunt[2] = complex(1.0)/intermed_impedance[2];
00791
00792 power[0] = constant_power[0];
00793 power[1] = constant_power[1];
00794 power[2] = constant_power[2];
00795
00796 current[0] = constant_current[0];
00797 current[1] = constant_current[1];
00798 current[2] = constant_current[2];
00799
00800
00801 for (index_var=0; index_var<6; index_var++)
00802 {
00803 if (intermed_impedance_dy[index_var].IsZero())
00804 shunt_dy[index_var] = 0.0;
00805 else
00806 shunt_dy[index_var] = complex(1.0)/intermed_impedance_dy[index_var];
00807
00808 power_dy[index_var] = constant_power_dy[index_var];
00809
00810 current_dy[index_var] = constant_current_dy[index_var];
00811 }
00812 }
00813 }
00814 else
00815 {
00816 all_three_phases = true;
00817
00818
00819 if (three_phase_protect == true)
00820 {
00821 if ((SubNode!=CHILD) && (SubNode!=DIFF_CHILD))
00822 {
00823
00824 if ((NR_busdata[NR_node_reference].origphases & NR_busdata[NR_node_reference].phases) != NR_busdata[NR_node_reference].origphases)
00825 {
00826
00827 all_three_phases = false;
00828 }
00829 }
00830 else
00831 {
00832
00833 if ((NR_busdata[*NR_subnode_reference].origphases & NR_busdata[*NR_subnode_reference].phases) != NR_busdata[*NR_subnode_reference].origphases)
00834 {
00835
00836 all_three_phases = false;
00837 }
00838 }
00839 }
00840
00841 if (all_three_phases == true)
00842 {
00843 if ((solver_method!=SM_FBS) && ((SubNode==PARENT) || (SubNode==DIFF_PARENT)))
00844 {
00845 if (SubNode == PARENT)
00846 {
00847
00848 if (enable_inrush_calculations == true)
00849 {
00850
00851 volt_below_thresh = false;
00852
00853
00854 if (has_phase(PHASE_D))
00855 {
00856 voltage_base_val = nominal_voltage * sqrt(3.0);
00857
00858
00859 voltage_pu_vals[0] = voltaged[0].Mag()/voltage_base_val;
00860 voltage_pu_vals[1] = voltaged[1].Mag()/voltage_base_val;
00861 voltage_pu_vals[2] = voltaged[2].Mag()/voltage_base_val;
00862
00863
00864 if (((NR_busdata[NR_node_reference].phases & 0x06) == 0x06) && (voltage_pu_vals[0] < impedance_conversion_low_pu))
00865 {
00866 volt_below_thresh = true;
00867 }
00868
00869
00870 if (((NR_busdata[NR_node_reference].phases & 0x03) == 0x03) && (voltage_pu_vals[1] < impedance_conversion_low_pu))
00871 {
00872 volt_below_thresh = true;
00873 }
00874
00875
00876 if (((NR_busdata[NR_node_reference].phases & 0x05) == 0x05) && (voltage_pu_vals[2] < impedance_conversion_low_pu))
00877 {
00878 volt_below_thresh = true;
00879 }
00880 }
00881 else
00882 {
00883
00884 voltage_base_val = nominal_voltage;
00885
00886
00887 voltage_pu_vals[0] = voltage[0].Mag()/voltage_base_val;
00888 voltage_pu_vals[1] = voltage[1].Mag()/voltage_base_val;
00889 voltage_pu_vals[2] = voltage[2].Mag()/voltage_base_val;
00890
00891
00892 if (((NR_busdata[NR_node_reference].phases & 0x04) == 0x04) && (voltage_pu_vals[0] < impedance_conversion_low_pu))
00893 {
00894 volt_below_thresh = true;
00895 }
00896
00897
00898 if (((NR_busdata[NR_node_reference].phases & 0x02) == 0x01) && (voltage_pu_vals[1] < impedance_conversion_low_pu))
00899 {
00900 volt_below_thresh = true;
00901 }
00902
00903
00904 if (((NR_busdata[NR_node_reference].phases & 0x01) == 0x01) && (voltage_pu_vals[2] < impedance_conversion_low_pu))
00905 {
00906 volt_below_thresh = true;
00907 }
00908 }
00909
00910
00911 if (volt_below_thresh == true)
00912 {
00913
00914 if (has_phase(PHASE_D))
00915 {
00916
00917 voltage_base_val = nominal_voltage * sqrt(3.0);
00918
00919
00920 if ((NR_busdata[NR_node_reference].phases & 0x06) == 0x06)
00921 {
00922
00923 if (!(constant_power[0].IsZero()))
00924 {
00925
00926 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
00927
00928
00929 intermed_impedance[0] += ~(nominal_voltage_value/constant_power[0]);
00930 }
00931
00932
00933 if (!(constant_current[0].IsZero()))
00934 {
00935
00936 nominal_voltage_value.SetPolar(voltage_base_val,PI/6);
00937
00938
00939 intermed_impedance[0] += nominal_voltage_value/constant_current[0];
00940 }
00941 }
00942
00943
00944 if ((NR_busdata[NR_node_reference].phases & 0x03) == 0x03)
00945 {
00946
00947 if (!(constant_power[1].IsZero()))
00948 {
00949
00950 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
00951
00952
00953 intermed_impedance[1] += ~(nominal_voltage_value/constant_power[1]);
00954 }
00955
00956
00957 if (!(constant_current[1].IsZero()))
00958 {
00959
00960 nominal_voltage_value.SetPolar(voltage_base_val,-1.0*PI/2.0);
00961
00962
00963 intermed_impedance[1] += nominal_voltage_value/constant_current[1];
00964 }
00965 }
00966
00967
00968 if ((NR_busdata[NR_node_reference].phases & 0x05) == 0x05)
00969 {
00970
00971 if (!(constant_power[2].IsZero()))
00972 {
00973
00974 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
00975
00976
00977 intermed_impedance[2] += ~(nominal_voltage_value/constant_power[2]);
00978 }
00979
00980
00981 if (!(constant_current[2].IsZero()))
00982 {
00983
00984 nominal_voltage_value.SetPolar(voltage_base_val,5.0*PI/6.0);
00985
00986
00987 intermed_impedance[2] += nominal_voltage_value/constant_current[2];
00988 }
00989 }
00990 }
00991 else
00992 {
00993
00994 voltage_base_val = nominal_voltage;
00995
00996
00997 if ((NR_busdata[NR_node_reference].phases & 0x04) == 0x04)
00998 {
00999
01000 if (!(constant_power[0].IsZero()))
01001 {
01002
01003 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01004
01005
01006 intermed_impedance[0] += ~(nominal_voltage_value/constant_power[0]);
01007 }
01008
01009
01010 if (!(constant_current[0].IsZero()))
01011 {
01012
01013 nominal_voltage_value = complex(voltage_base_val,0.0);
01014
01015
01016 intermed_impedance[0] += nominal_voltage_value/constant_current[0];
01017 }
01018 }
01019
01020
01021 if ((NR_busdata[NR_node_reference].phases & 0x02) == 0x02)
01022 {
01023
01024 if (!(constant_power[1].IsZero()))
01025 {
01026
01027 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01028
01029
01030 intermed_impedance[1] += ~(nominal_voltage_value/constant_power[1]);
01031 }
01032
01033
01034 if (!(constant_current[1].IsZero()))
01035 {
01036
01037 nominal_voltage_value.SetPolar(voltage_base_val,-2.0*PI/3.0);
01038
01039
01040 intermed_impedance[1] += nominal_voltage_value/constant_current[1];
01041 }
01042 }
01043
01044
01045 if ((NR_busdata[NR_node_reference].phases & 0x01) == 0x01)
01046 {
01047
01048 if (!(constant_power[2].IsZero()))
01049 {
01050
01051 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01052
01053
01054 intermed_impedance[2] += ~(nominal_voltage_value/constant_power[2]);
01055 }
01056
01057
01058 if (!(constant_current[2].IsZero()))
01059 {
01060
01061 nominal_voltage_value.SetPolar(voltage_base_val,2.0*PI/3.0);
01062
01063
01064 intermed_impedance[2] += nominal_voltage_value/constant_current[2];
01065 }
01066 }
01067 }
01068
01069
01070 if (!(intermed_impedance[0].IsZero()))
01071 shunt[0] += complex(1.0)/intermed_impedance[0];
01072
01073 if (!(intermed_impedance[1].IsZero()))
01074 shunt[1] += complex(1.0)/intermed_impedance[1];
01075
01076 if (!(intermed_impedance[2].IsZero()))
01077 shunt[2] += complex(1.0)/intermed_impedance[2];
01078
01079
01080
01081
01082
01083
01084
01085 voltage_base_val = nominal_voltage * sqrt(3.0);
01086
01087
01088 if ((NR_busdata[NR_node_reference].phases & 0x06) == 0x06)
01089 {
01090
01091 if (!(constant_power_dy[0].IsZero()))
01092 {
01093
01094 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01095
01096
01097 intermed_impedance_dy[0] += ~(nominal_voltage_value/constant_power_dy[0]);
01098 }
01099
01100
01101 if (!(constant_current_dy[0].IsZero()))
01102 {
01103
01104 nominal_voltage_value.SetPolar(voltage_base_val,PI/6);
01105
01106
01107 intermed_impedance_dy[0] += nominal_voltage_value/constant_current_dy[0];
01108 }
01109 }
01110
01111
01112 if ((NR_busdata[NR_node_reference].phases & 0x03) == 0x03)
01113 {
01114
01115 if (!(constant_power_dy[1].IsZero()))
01116 {
01117
01118 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01119
01120
01121 intermed_impedance_dy[1] += ~(nominal_voltage_value/constant_power_dy[1]);
01122 }
01123
01124
01125 if (!(constant_current_dy[1].IsZero()))
01126 {
01127
01128 nominal_voltage_value.SetPolar(voltage_base_val,-1.0*PI/2.0);
01129
01130
01131 intermed_impedance_dy[1] += nominal_voltage_value/constant_current_dy[1];
01132 }
01133 }
01134
01135
01136 if ((NR_busdata[NR_node_reference].phases & 0x05) == 0x05)
01137 {
01138
01139 if (!(constant_power_dy[2].IsZero()))
01140 {
01141
01142 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01143
01144
01145 intermed_impedance_dy[2] += ~(nominal_voltage_value/constant_power_dy[2]);
01146 }
01147
01148
01149 if (!(constant_current_dy[2].IsZero()))
01150 {
01151
01152 nominal_voltage_value.SetPolar(voltage_base_val,5.0*PI/6.0);
01153
01154
01155 intermed_impedance_dy[2] += nominal_voltage_value/constant_current_dy[2];
01156 }
01157 }
01158
01159
01160
01161 voltage_base_val = nominal_voltage;
01162
01163
01164 if ((NR_busdata[NR_node_reference].phases & 0x04) == 0x04)
01165 {
01166
01167 if (!(constant_power_dy[3].IsZero()))
01168 {
01169
01170 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01171
01172
01173 intermed_impedance_dy[3] += ~(nominal_voltage_value/constant_power_dy[3]);
01174 }
01175
01176
01177 if (!(constant_current_dy[3].IsZero()))
01178 {
01179
01180 nominal_voltage_value = complex(voltage_base_val,0.0);
01181
01182
01183 intermed_impedance_dy[3] += nominal_voltage_value/constant_current_dy[3];
01184 }
01185 }
01186
01187
01188 if ((NR_busdata[NR_node_reference].phases & 0x02) == 0x02)
01189 {
01190
01191 if (!(constant_power_dy[4].IsZero()))
01192 {
01193
01194 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01195
01196
01197 intermed_impedance_dy[4] += ~(nominal_voltage_value/constant_power_dy[4]);
01198 }
01199
01200
01201 if (!(constant_current_dy[4].IsZero()))
01202 {
01203
01204 nominal_voltage_value.SetPolar(voltage_base_val,-2.0*PI/3.0);
01205
01206
01207 intermed_impedance_dy[4] += nominal_voltage_value/constant_current_dy[4];
01208 }
01209 }
01210
01211
01212 if ((NR_busdata[NR_node_reference].phases & 0x01) == 0x01)
01213 {
01214
01215 if (!(constant_power_dy[5].IsZero()))
01216 {
01217
01218 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01219
01220
01221 intermed_impedance_dy[5] += ~(nominal_voltage_value/constant_power_dy[5]);
01222 }
01223
01224
01225 if (!(constant_current_dy[5].IsZero()))
01226 {
01227
01228 nominal_voltage_value.SetPolar(voltage_base_val,2.0*PI/3.0);
01229
01230
01231 intermed_impedance_dy[5] += nominal_voltage_value/constant_current_dy[5];
01232 }
01233 }
01234
01235
01236 for (index_var=0; index_var<6; index_var++)
01237 {
01238 if (!(intermed_impedance_dy[index_var].IsZero()))
01239 shunt_dy[index_var] += complex(1.0)/intermed_impedance_dy[index_var];
01240 }
01241 }
01242 else
01243 {
01244 if (!(intermed_impedance[0].IsZero()))
01245 shunt[0] += complex(1.0)/intermed_impedance[0];
01246
01247 if (!(intermed_impedance[1].IsZero()))
01248 shunt[1] += complex(1.0)/intermed_impedance[1];
01249
01250 if (!(intermed_impedance[2].IsZero()))
01251 shunt[2] += complex(1.0)/intermed_impedance[2];
01252
01253 power[0] += constant_power[0];
01254 power[1] += constant_power[1];
01255 power[2] += constant_power[2];
01256
01257 current[0] += constant_current[0];
01258 current[1] += constant_current[1];
01259 current[2] += constant_current[2];
01260
01261
01262
01263 for (index_var=0; index_var<6; index_var++)
01264 {
01265 if (!(intermed_impedance_dy[index_var].IsZero()))
01266 shunt_dy[index_var] += complex(1.0)/intermed_impedance_dy[index_var];
01267
01268 power_dy[index_var] += constant_power_dy[index_var];
01269
01270 current_dy[index_var] += constant_current_dy[index_var];
01271 }
01272 }
01273 }
01274 else
01275 {
01276 if (!(intermed_impedance[0].IsZero()))
01277 shunt[0] += complex(1.0)/intermed_impedance[0];
01278
01279 if (!(intermed_impedance[1].IsZero()))
01280 shunt[1] += complex(1.0)/intermed_impedance[1];
01281
01282 if (!(intermed_impedance[2].IsZero()))
01283 shunt[2] += complex(1.0)/intermed_impedance[2];
01284
01285 power[0] += constant_power[0];
01286 power[1] += constant_power[1];
01287 power[2] += constant_power[2];
01288
01289 current[0] += constant_current[0];
01290 current[1] += constant_current[1];
01291 current[2] += constant_current[2];
01292
01293
01294
01295 for (index_var=0; index_var<6; index_var++)
01296 {
01297 if (!(intermed_impedance_dy[index_var].IsZero()))
01298 shunt_dy[index_var] += complex(1.0)/intermed_impedance_dy[index_var];
01299
01300 power_dy[index_var] += constant_power_dy[index_var];
01301
01302 current_dy[index_var] += constant_current_dy[index_var];
01303 }
01304 }
01305 }
01306 else
01307 {
01308
01309 if (enable_inrush_calculations == true)
01310 {
01311
01312 volt_below_thresh = false;
01313
01314
01315 if (has_phase(PHASE_D))
01316 {
01317 voltage_base_val = nominal_voltage * sqrt(3.0);
01318
01319
01320 voltage_pu_vals[0] = voltaged[0].Mag()/voltage_base_val;
01321 voltage_pu_vals[1] = voltaged[1].Mag()/voltage_base_val;
01322 voltage_pu_vals[2] = voltaged[2].Mag()/voltage_base_val;
01323
01324
01325 if (((NR_busdata[NR_node_reference].phases & 0x06) == 0x06) && (voltage_pu_vals[0] < impedance_conversion_low_pu))
01326 {
01327 volt_below_thresh = true;
01328 }
01329
01330
01331 if (((NR_busdata[NR_node_reference].phases & 0x03) == 0x03) && (voltage_pu_vals[1] < impedance_conversion_low_pu))
01332 {
01333 volt_below_thresh = true;
01334 }
01335
01336
01337 if (((NR_busdata[NR_node_reference].phases & 0x05) == 0x05) && (voltage_pu_vals[2] < impedance_conversion_low_pu))
01338 {
01339 volt_below_thresh = true;
01340 }
01341 }
01342 else
01343 {
01344
01345 voltage_base_val = nominal_voltage;
01346
01347
01348 voltage_pu_vals[0] = voltage[0].Mag()/voltage_base_val;
01349 voltage_pu_vals[1] = voltage[1].Mag()/voltage_base_val;
01350 voltage_pu_vals[2] = voltage[2].Mag()/voltage_base_val;
01351
01352
01353 if (((NR_busdata[NR_node_reference].phases & 0x04) == 0x04) && (voltage_pu_vals[0] < impedance_conversion_low_pu))
01354 {
01355 volt_below_thresh = true;
01356 }
01357
01358
01359 if (((NR_busdata[NR_node_reference].phases & 0x02) == 0x01) && (voltage_pu_vals[1] < impedance_conversion_low_pu))
01360 {
01361 volt_below_thresh = true;
01362 }
01363
01364
01365 if (((NR_busdata[NR_node_reference].phases & 0x01) == 0x01) && (voltage_pu_vals[2] < impedance_conversion_low_pu))
01366 {
01367 volt_below_thresh = true;
01368 }
01369 }
01370
01371
01372 if (volt_below_thresh == true)
01373 {
01374
01375 if (has_phase(PHASE_D))
01376 {
01377
01378 voltage_base_val = nominal_voltage * sqrt(3.0);
01379
01380
01381 if ((NR_busdata[NR_node_reference].phases & 0x06) == 0x06)
01382 {
01383
01384 if (!(constant_power[0].IsZero()))
01385 {
01386
01387 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01388
01389
01390 intermed_impedance[0] += ~(nominal_voltage_value/constant_power[0]);
01391 }
01392
01393
01394 if (!(constant_current[0].IsZero()))
01395 {
01396
01397 nominal_voltage_value.SetPolar(voltage_base_val,PI/6);
01398
01399
01400 intermed_impedance[0] += nominal_voltage_value/constant_current[0];
01401 }
01402 }
01403
01404
01405 if ((NR_busdata[NR_node_reference].phases & 0x03) == 0x03)
01406 {
01407
01408 if (!(constant_power[1].IsZero()))
01409 {
01410
01411 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01412
01413
01414 intermed_impedance[1] += ~(nominal_voltage_value/constant_power[1]);
01415 }
01416
01417
01418 if (!(constant_current[1].IsZero()))
01419 {
01420
01421 nominal_voltage_value.SetPolar(voltage_base_val,-1.0*PI/2.0);
01422
01423
01424 intermed_impedance[1] += nominal_voltage_value/constant_current[1];
01425 }
01426 }
01427
01428
01429 if ((NR_busdata[NR_node_reference].phases & 0x05) == 0x05)
01430 {
01431
01432 if (!(constant_power[2].IsZero()))
01433 {
01434
01435 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01436
01437
01438 intermed_impedance[2] += ~(nominal_voltage_value/constant_power[2]);
01439 }
01440
01441
01442 if (!(constant_current[2].IsZero()))
01443 {
01444
01445 nominal_voltage_value.SetPolar(voltage_base_val,5.0*PI/6.0);
01446
01447
01448 intermed_impedance[2] += nominal_voltage_value/constant_current[2];
01449 }
01450 }
01451 }
01452 else
01453 {
01454
01455 voltage_base_val = nominal_voltage;
01456
01457
01458 if ((NR_busdata[NR_node_reference].phases & 0x04) == 0x04)
01459 {
01460
01461 if (!(constant_power[0].IsZero()))
01462 {
01463
01464 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01465
01466
01467 intermed_impedance[0] += ~(nominal_voltage_value/constant_power[0]);
01468 }
01469
01470
01471 if (!(constant_current[0].IsZero()))
01472 {
01473
01474 nominal_voltage_value = complex(voltage_base_val,0.0);
01475
01476
01477 intermed_impedance[0] += nominal_voltage_value/constant_current[0];
01478 }
01479 }
01480
01481
01482 if ((NR_busdata[NR_node_reference].phases & 0x02) == 0x02)
01483 {
01484
01485 if (!(constant_power[1].IsZero()))
01486 {
01487
01488 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01489
01490
01491 intermed_impedance[1] += ~(nominal_voltage_value/constant_power[1]);
01492 }
01493
01494
01495 if (!(constant_current[1].IsZero()))
01496 {
01497
01498 nominal_voltage_value.SetPolar(voltage_base_val,-2.0*PI/3.0);
01499
01500
01501 intermed_impedance[1] += nominal_voltage_value/constant_current[1];
01502 }
01503 }
01504
01505
01506 if ((NR_busdata[NR_node_reference].phases & 0x01) == 0x01)
01507 {
01508
01509 if (!(constant_power[2].IsZero()))
01510 {
01511
01512 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01513
01514
01515 intermed_impedance[2] += ~(nominal_voltage_value/constant_power[2]);
01516 }
01517
01518
01519 if (!(constant_current[2].IsZero()))
01520 {
01521
01522 nominal_voltage_value.SetPolar(voltage_base_val,2.0*PI/3.0);
01523
01524
01525 intermed_impedance[2] += nominal_voltage_value/constant_current[2];
01526 }
01527 }
01528 }
01529
01530
01531 if (!(intermed_impedance[0].IsZero()))
01532 shunt[0] = complex(1.0)/intermed_impedance[0];
01533 else
01534 shunt[0] = complex(0.0,0.0);
01535
01536 if (!(intermed_impedance[1].IsZero()))
01537 shunt[1] = complex(1.0)/intermed_impedance[1];
01538 else
01539 shunt[1] = complex(0.0,0.0);
01540
01541 if (!(intermed_impedance[2].IsZero()))
01542 shunt[2] = complex(1.0)/intermed_impedance[2];
01543 else
01544 shunt[2] = complex(0.0,0.0);
01545
01546
01547
01548
01549
01550
01551
01552 voltage_base_val = nominal_voltage * sqrt(3.0);
01553
01554
01555 if ((NR_busdata[NR_node_reference].phases & 0x06) == 0x06)
01556 {
01557
01558 if (!(constant_power_dy[0].IsZero()))
01559 {
01560
01561 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01562
01563
01564 intermed_impedance_dy[0] += ~(nominal_voltage_value/constant_power_dy[0]);
01565 }
01566
01567
01568 if (!(constant_current_dy[0].IsZero()))
01569 {
01570
01571 nominal_voltage_value.SetPolar(voltage_base_val,PI/6);
01572
01573
01574 intermed_impedance_dy[0] += nominal_voltage_value/constant_current_dy[0];
01575 }
01576 }
01577
01578
01579 if ((NR_busdata[NR_node_reference].phases & 0x03) == 0x03)
01580 {
01581
01582 if (!(constant_power_dy[1].IsZero()))
01583 {
01584
01585 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01586
01587
01588 intermed_impedance_dy[1] += ~(nominal_voltage_value/constant_power_dy[1]);
01589 }
01590
01591
01592 if (!(constant_current_dy[1].IsZero()))
01593 {
01594
01595 nominal_voltage_value.SetPolar(voltage_base_val,-1.0*PI/2.0);
01596
01597
01598 intermed_impedance_dy[1] += nominal_voltage_value/constant_current_dy[1];
01599 }
01600 }
01601
01602
01603 if ((NR_busdata[NR_node_reference].phases & 0x05) == 0x05)
01604 {
01605
01606 if (!(constant_power_dy[2].IsZero()))
01607 {
01608
01609 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01610
01611
01612 intermed_impedance_dy[2] += ~(nominal_voltage_value/constant_power_dy[2]);
01613 }
01614
01615
01616 if (!(constant_current_dy[2].IsZero()))
01617 {
01618
01619 nominal_voltage_value.SetPolar(voltage_base_val,5.0*PI/6.0);
01620
01621
01622 intermed_impedance_dy[2] += nominal_voltage_value/constant_current_dy[2];
01623 }
01624 }
01625
01626
01627
01628 voltage_base_val = nominal_voltage;
01629
01630
01631 if ((NR_busdata[NR_node_reference].phases & 0x04) == 0x04)
01632 {
01633
01634 if (!(constant_power_dy[3].IsZero()))
01635 {
01636
01637 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01638
01639
01640 intermed_impedance_dy[3] += ~(nominal_voltage_value/constant_power_dy[3]);
01641 }
01642
01643
01644 if (!(constant_current_dy[3].IsZero()))
01645 {
01646
01647 nominal_voltage_value = complex(voltage_base_val,0.0);
01648
01649
01650 intermed_impedance_dy[3] += nominal_voltage_value/constant_current_dy[3];
01651 }
01652 }
01653
01654
01655 if ((NR_busdata[NR_node_reference].phases & 0x02) == 0x02)
01656 {
01657
01658 if (!(constant_power_dy[4].IsZero()))
01659 {
01660
01661 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01662
01663
01664 intermed_impedance_dy[4] += ~(nominal_voltage_value/constant_power_dy[4]);
01665 }
01666
01667
01668 if (!(constant_current_dy[4].IsZero()))
01669 {
01670
01671 nominal_voltage_value.SetPolar(voltage_base_val,-2.0*PI/3.0);
01672
01673
01674 intermed_impedance_dy[4] += nominal_voltage_value/constant_current_dy[4];
01675 }
01676 }
01677
01678
01679 if ((NR_busdata[NR_node_reference].phases & 0x01) == 0x01)
01680 {
01681
01682 if (!(constant_power_dy[5].IsZero()))
01683 {
01684
01685 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01686
01687
01688 intermed_impedance_dy[5] += ~(nominal_voltage_value/constant_power_dy[5]);
01689 }
01690
01691
01692 if (!(constant_current_dy[5].IsZero()))
01693 {
01694
01695 nominal_voltage_value.SetPolar(voltage_base_val,2.0*PI/3.0);
01696
01697
01698 intermed_impedance_dy[5] += nominal_voltage_value/constant_current_dy[5];
01699 }
01700 }
01701
01702
01703 for (index_var=0; index_var<6; index_var++)
01704 {
01705 if (!(intermed_impedance_dy[index_var].IsZero()))
01706 shunt_dy[index_var] += complex(1.0)/intermed_impedance_dy[index_var];
01707 }
01708 }
01709 else
01710 {
01711 if(intermed_impedance[0].IsZero())
01712 shunt[0] = 0.0;
01713 else
01714 shunt[0] = complex(1.0)/intermed_impedance[0];
01715
01716 if(intermed_impedance[1].IsZero())
01717 shunt[1] = 0.0;
01718 else
01719 shunt[1] = complex(1.0)/intermed_impedance[1];
01720
01721 if(intermed_impedance[2].IsZero())
01722 shunt[2] = 0.0;
01723 else
01724 shunt[2] = complex(1.0)/intermed_impedance[2];
01725
01726 power[0] = constant_power[0];
01727 power[1] = constant_power[1];
01728 power[2] = constant_power[2];
01729 current[0] = constant_current[0];
01730 current[1] = constant_current[1];
01731 current[2] = constant_current[2];
01732
01733
01734
01735 for (index_var=0; index_var<6; index_var++)
01736 {
01737 if (!(intermed_impedance_dy[index_var].IsZero()))
01738 shunt_dy[index_var] += complex(1.0)/intermed_impedance_dy[index_var];
01739
01740 power_dy[index_var] += constant_power_dy[index_var];
01741
01742 current_dy[index_var] += constant_current_dy[index_var];
01743 }
01744 }
01745 }
01746 else
01747 {
01748 if(intermed_impedance[0].IsZero())
01749 shunt[0] = 0.0;
01750 else
01751 shunt[0] = complex(1.0)/intermed_impedance[0];
01752
01753 if(intermed_impedance[1].IsZero())
01754 shunt[1] = 0.0;
01755 else
01756 shunt[1] = complex(1.0)/intermed_impedance[1];
01757
01758 if(intermed_impedance[2].IsZero())
01759 shunt[2] = 0.0;
01760 else
01761 shunt[2] = complex(1.0)/intermed_impedance[2];
01762
01763 power[0] = constant_power[0];
01764 power[1] = constant_power[1];
01765 power[2] = constant_power[2];
01766 current[0] = constant_current[0];
01767 current[1] = constant_current[1];
01768 current[2] = constant_current[2];
01769
01770
01771
01772 for (index_var=0; index_var<6; index_var++)
01773 {
01774 if (!(intermed_impedance_dy[index_var].IsZero()))
01775 shunt_dy[index_var] += complex(1.0)/intermed_impedance_dy[index_var];
01776
01777 power_dy[index_var] += constant_power_dy[index_var];
01778
01779 current_dy[index_var] += constant_current_dy[index_var];
01780 }
01781 }
01782 }
01783 }
01784 else
01785 {
01786
01787 if (NR_node_reference == -99)
01788 {
01789 node_reference_value = *NR_subnode_reference;
01790
01791
01792 if (node_reference_value < 0)
01793 {
01794
01795 obj = OBJECTHDR(this);
01796
01797 GL_THROW("node:%s -- %s tried to perform an impedance conversion with an uninitialzed child node!",obj->id, obj->name?obj->name:"unnamed");
01798
01799
01800
01801
01802 }
01803
01804 }
01805 else
01806 {
01807 node_reference_value = NR_node_reference;
01808 }
01809
01810
01811 if (enable_inrush_calculations == true)
01812 {
01813
01814 volt_below_thresh = false;
01815
01816
01817 if (has_phase(PHASE_D))
01818 {
01819 voltage_base_val = nominal_voltage * sqrt(3.0);
01820
01821
01822 voltage_pu_vals[0] = voltaged[0].Mag()/voltage_base_val;
01823 voltage_pu_vals[1] = voltaged[1].Mag()/voltage_base_val;
01824 voltage_pu_vals[2] = voltaged[2].Mag()/voltage_base_val;
01825
01826
01827 if (((NR_busdata[node_reference_value].phases & 0x06) == 0x06) && (voltage_pu_vals[0] < impedance_conversion_low_pu))
01828 {
01829 volt_below_thresh = true;
01830 }
01831
01832
01833 if (((NR_busdata[node_reference_value].phases & 0x03) == 0x03) && (voltage_pu_vals[1] < impedance_conversion_low_pu))
01834 {
01835 volt_below_thresh = true;
01836 }
01837
01838
01839 if (((NR_busdata[node_reference_value].phases & 0x05) == 0x05) && (voltage_pu_vals[2] < impedance_conversion_low_pu))
01840 {
01841 volt_below_thresh = true;
01842 }
01843 }
01844 else
01845 {
01846
01847 voltage_base_val = nominal_voltage;
01848
01849
01850 voltage_pu_vals[0] = voltage[0].Mag()/voltage_base_val;
01851 voltage_pu_vals[1] = voltage[1].Mag()/voltage_base_val;
01852 voltage_pu_vals[2] = voltage[2].Mag()/voltage_base_val;
01853
01854
01855 if (((NR_busdata[node_reference_value].phases & 0x04) == 0x04) && (voltage_pu_vals[0] < impedance_conversion_low_pu))
01856 {
01857 volt_below_thresh = true;
01858 }
01859
01860
01861 if (((NR_busdata[node_reference_value].phases & 0x02) == 0x01) && (voltage_pu_vals[1] < impedance_conversion_low_pu))
01862 {
01863 volt_below_thresh = true;
01864 }
01865
01866
01867 if (((NR_busdata[node_reference_value].phases & 0x01) == 0x01) && (voltage_pu_vals[2] < impedance_conversion_low_pu))
01868 {
01869 volt_below_thresh = true;
01870 }
01871 }
01872
01873
01874 if (volt_below_thresh == true)
01875 {
01876
01877 power[0] = 0.0;
01878 power[1] = 0.0;
01879 power[2] = 0.0;
01880 current[0] = 0.0;
01881 current[1] = 0.0;
01882 current[2] = 0.0;
01883
01884
01885 power_dy[0] = power_dy[1] = power_dy[2] = 0.0;
01886 power_dy[3] = power_dy[4] = power_dy[5] = 0.0;
01887 current_dy[0] = current_dy[1] = current_dy[2] = 0.0;
01888 current_dy[3] = current_dy[4] = current_dy[5] = 0.0;
01889
01890
01891 if (has_phase(PHASE_D))
01892 {
01893
01894 voltage_base_val = nominal_voltage * sqrt(3.0);
01895
01896
01897 if ((NR_busdata[node_reference_value].phases & 0x06) == 0x06)
01898 {
01899
01900 if (!(constant_power[0].IsZero()))
01901 {
01902
01903 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01904
01905
01906 intermed_impedance[0] += ~(nominal_voltage_value/constant_power[0]);
01907 }
01908
01909
01910 if (!(constant_current[0].IsZero()))
01911 {
01912
01913 nominal_voltage_value.SetPolar(voltage_base_val,PI/6);
01914
01915
01916 intermed_impedance[0] += nominal_voltage_value/constant_current[0];
01917 }
01918 }
01919
01920
01921 if ((NR_busdata[node_reference_value].phases & 0x03) == 0x03)
01922 {
01923
01924 if (!(constant_power[1].IsZero()))
01925 {
01926
01927 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01928
01929
01930 intermed_impedance[1] += ~(nominal_voltage_value/constant_power[1]);
01931 }
01932
01933
01934 if (!(constant_current[1].IsZero()))
01935 {
01936
01937 nominal_voltage_value.SetPolar(voltage_base_val,-1.0*PI/2.0);
01938
01939
01940 intermed_impedance[1] += nominal_voltage_value/constant_current[1];
01941 }
01942 }
01943
01944
01945 if ((NR_busdata[node_reference_value].phases & 0x05) == 0x05)
01946 {
01947
01948 if (!(constant_power[2].IsZero()))
01949 {
01950
01951 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01952
01953
01954 intermed_impedance[2] += ~(nominal_voltage_value/constant_power[2]);
01955 }
01956
01957
01958 if (!(constant_current[2].IsZero()))
01959 {
01960
01961 nominal_voltage_value.SetPolar(voltage_base_val,5.0*PI/6.0);
01962
01963
01964 intermed_impedance[2] += nominal_voltage_value/constant_current[2];
01965 }
01966 }
01967 }
01968 else
01969 {
01970
01971 voltage_base_val = nominal_voltage;
01972
01973
01974 if ((NR_busdata[node_reference_value].phases & 0x04) == 0x04)
01975 {
01976
01977 if (!(constant_power[0].IsZero()))
01978 {
01979
01980 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
01981
01982
01983 intermed_impedance[0] += ~(nominal_voltage_value/constant_power[0]);
01984 }
01985
01986
01987 if (!(constant_current[0].IsZero()))
01988 {
01989
01990 nominal_voltage_value = complex(voltage_base_val,0.0);
01991
01992
01993 intermed_impedance[0] += nominal_voltage_value/constant_current[0];
01994 }
01995 }
01996
01997
01998 if ((NR_busdata[node_reference_value].phases & 0x02) == 0x02)
01999 {
02000
02001 if (!(constant_power[1].IsZero()))
02002 {
02003
02004 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
02005
02006
02007 intermed_impedance[1] += ~(nominal_voltage_value/constant_power[1]);
02008 }
02009
02010
02011 if (!(constant_current[1].IsZero()))
02012 {
02013
02014 nominal_voltage_value.SetPolar(voltage_base_val,-2.0*PI/3.0);
02015
02016
02017 intermed_impedance[1] += nominal_voltage_value/constant_current[1];
02018 }
02019 }
02020
02021
02022 if ((NR_busdata[node_reference_value].phases & 0x01) == 0x01)
02023 {
02024
02025 if (!(constant_power[2].IsZero()))
02026 {
02027
02028 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
02029
02030
02031 intermed_impedance[2] += ~(nominal_voltage_value/constant_power[2]);
02032 }
02033
02034
02035 if (!(constant_current[2].IsZero()))
02036 {
02037
02038 nominal_voltage_value.SetPolar(voltage_base_val,2.0*PI/3.0);
02039
02040
02041 intermed_impedance[2] += nominal_voltage_value/constant_current[2];
02042 }
02043 }
02044 }
02045
02046
02047 if (!(intermed_impedance[0].IsZero()))
02048 shunt[0] = complex(1.0)/intermed_impedance[0];
02049 else
02050 shunt[0] = complex(0.0,0.0);
02051
02052 if (!(intermed_impedance[1].IsZero()))
02053 shunt[1] = complex(1.0)/intermed_impedance[1];
02054 else
02055 shunt[1] = complex(0.0,0.0);
02056
02057 if (!(intermed_impedance[2].IsZero()))
02058 shunt[2] = complex(1.0)/intermed_impedance[2];
02059 else
02060 shunt[2] = complex(0.0,0.0);
02061
02062
02063
02064
02065
02066
02067
02068 voltage_base_val = nominal_voltage * sqrt(3.0);
02069
02070
02071 if ((NR_busdata[node_reference_value].phases & 0x06) == 0x06)
02072 {
02073
02074 if (!(constant_power_dy[0].IsZero()))
02075 {
02076
02077 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
02078
02079
02080 intermed_impedance_dy[0] += ~(nominal_voltage_value/constant_power_dy[0]);
02081 }
02082
02083
02084 if (!(constant_current_dy[0].IsZero()))
02085 {
02086
02087 nominal_voltage_value.SetPolar(voltage_base_val,PI/6);
02088
02089
02090 intermed_impedance_dy[0] += nominal_voltage_value/constant_current_dy[0];
02091 }
02092 }
02093
02094
02095 if ((NR_busdata[node_reference_value].phases & 0x03) == 0x03)
02096 {
02097
02098 if (!(constant_power_dy[1].IsZero()))
02099 {
02100
02101 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
02102
02103
02104 intermed_impedance_dy[1] += ~(nominal_voltage_value/constant_power_dy[1]);
02105 }
02106
02107
02108 if (!(constant_current_dy[1].IsZero()))
02109 {
02110
02111 nominal_voltage_value.SetPolar(voltage_base_val,-1.0*PI/2.0);
02112
02113
02114 intermed_impedance_dy[1] += nominal_voltage_value/constant_current_dy[1];
02115 }
02116 }
02117
02118
02119 if ((NR_busdata[node_reference_value].phases & 0x05) == 0x05)
02120 {
02121
02122 if (!(constant_power_dy[2].IsZero()))
02123 {
02124
02125 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
02126
02127
02128 intermed_impedance_dy[2] += ~(nominal_voltage_value/constant_power_dy[2]);
02129 }
02130
02131
02132 if (!(constant_current_dy[2].IsZero()))
02133 {
02134
02135 nominal_voltage_value.SetPolar(voltage_base_val,5.0*PI/6.0);
02136
02137
02138 intermed_impedance_dy[2] += nominal_voltage_value/constant_current_dy[2];
02139 }
02140 }
02141
02142
02143
02144 voltage_base_val = nominal_voltage;
02145
02146
02147 if ((NR_busdata[node_reference_value].phases & 0x04) == 0x04)
02148 {
02149
02150 if (!(constant_power_dy[3].IsZero()))
02151 {
02152
02153 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
02154
02155
02156 intermed_impedance_dy[3] += ~(nominal_voltage_value/constant_power_dy[3]);
02157 }
02158
02159
02160 if (!(constant_current_dy[3].IsZero()))
02161 {
02162
02163 nominal_voltage_value = complex(voltage_base_val,0.0);
02164
02165
02166 intermed_impedance_dy[3] += nominal_voltage_value/constant_current_dy[3];
02167 }
02168 }
02169
02170
02171 if ((NR_busdata[node_reference_value].phases & 0x02) == 0x02)
02172 {
02173
02174 if (!(constant_power_dy[4].IsZero()))
02175 {
02176
02177 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
02178
02179
02180 intermed_impedance_dy[4] += ~(nominal_voltage_value/constant_power_dy[4]);
02181 }
02182
02183
02184 if (!(constant_current_dy[4].IsZero()))
02185 {
02186
02187 nominal_voltage_value.SetPolar(voltage_base_val,-2.0*PI/3.0);
02188
02189
02190 intermed_impedance_dy[4] += nominal_voltage_value/constant_current_dy[4];
02191 }
02192 }
02193
02194
02195 if ((NR_busdata[node_reference_value].phases & 0x01) == 0x01)
02196 {
02197
02198 if (!(constant_power_dy[5].IsZero()))
02199 {
02200
02201 nominal_voltage_value = complex(voltage_base_val*voltage_base_val,0);
02202
02203
02204 intermed_impedance_dy[5] += ~(nominal_voltage_value/constant_power_dy[5]);
02205 }
02206
02207
02208 if (!(constant_current_dy[5].IsZero()))
02209 {
02210
02211 nominal_voltage_value.SetPolar(voltage_base_val,2.0*PI/3.0);
02212
02213
02214 intermed_impedance_dy[5] += nominal_voltage_value/constant_current_dy[5];
02215 }
02216 }
02217
02218
02219 for (index_var=0; index_var<6; index_var++)
02220 {
02221 if (!(intermed_impedance_dy[index_var].IsZero()))
02222 shunt_dy[index_var] = complex(1.0)/intermed_impedance_dy[index_var];
02223 }
02224 }
02225 else
02226 {
02227 if(intermed_impedance[0].IsZero())
02228 shunt[0] = 0.0;
02229 else
02230 shunt[0] = complex(1)/intermed_impedance[0];
02231
02232 if(intermed_impedance[1].IsZero())
02233 shunt[1] = 0.0;
02234 else
02235 shunt[1] = complex(1)/intermed_impedance[1];
02236
02237 if(intermed_impedance[2].IsZero())
02238 shunt[2] = 0.0;
02239 else
02240 shunt[2] = complex(1)/intermed_impedance[2];
02241
02242 power[0] = constant_power[0];
02243 power[1] = constant_power[1];
02244 power[2] = constant_power[2];
02245
02246 current[0] = constant_current[0];
02247 current[1] = constant_current[1];
02248 current[2] = constant_current[2];
02249
02250
02251 for (index_var=0; index_var<6; index_var++)
02252 {
02253 if (intermed_impedance_dy[index_var].IsZero())
02254 shunt_dy[index_var] = 0.0;
02255 else
02256 shunt_dy[index_var] = complex(1.0)/intermed_impedance_dy[index_var];
02257
02258 power_dy[index_var] = constant_power_dy[index_var];
02259
02260 current_dy[index_var] = constant_current_dy[index_var];
02261 }
02262 }
02263 }
02264 else
02265 {
02266 if(intermed_impedance[0].IsZero())
02267 shunt[0] = 0.0;
02268 else
02269 shunt[0] = complex(1)/intermed_impedance[0];
02270
02271 if(intermed_impedance[1].IsZero())
02272 shunt[1] = 0.0;
02273 else
02274 shunt[1] = complex(1)/intermed_impedance[1];
02275
02276 if(intermed_impedance[2].IsZero())
02277 shunt[2] = 0.0;
02278 else
02279 shunt[2] = complex(1)/intermed_impedance[2];
02280
02281 power[0] = constant_power[0];
02282 power[1] = constant_power[1];
02283 power[2] = constant_power[2];
02284
02285 current[0] = constant_current[0];
02286 current[1] = constant_current[1];
02287 current[2] = constant_current[2];
02288
02289
02290 for (index_var=0; index_var<6; index_var++)
02291 {
02292 if (intermed_impedance_dy[index_var].IsZero())
02293 shunt_dy[index_var] = 0.0;
02294 else
02295 shunt_dy[index_var] = complex(1.0)/intermed_impedance_dy[index_var];
02296
02297 power_dy[index_var] = constant_power_dy[index_var];
02298
02299 current_dy[index_var] = constant_current_dy[index_var];
02300 }
02301 }
02302 }
02303 }
02304 else
02305 {
02306 power[0] = 0.0;
02307 power[1] = 0.0;
02308 power[2] = 0.0;
02309 shunt[0] = 0.0;
02310 shunt[1] = 0.0;
02311 shunt[2] = 0.0;
02312 current[0] = 0.0;
02313 current[1] = 0.0;
02314 current[2] = 0.0;
02315
02316
02317
02318 for (index_var=0; index_var<6; index_var++)
02319 {
02320 shunt_dy[index_var] = complex(0.0,0.0);
02321 power_dy[index_var] = complex(0.0,0.0);
02322 current_dy[index_var] = complex(0.0,0.0);
02323 }
02324 }
02325 }
02326
02327
02328 if (enable_inrush_calculations == true)
02329 {
02330
02331 if ((SubNode == CHILD) || (SubNode == DIFF_CHILD))
02332 {
02333
02334 if (NR_busdata[*NR_subnode_reference].full_Y_load == NULL)
02335 {
02336
02337 temp_par_node = OBJECTDATA(SubNodeParent,node);
02338
02339
02340 if (temp_par_node == NULL)
02341 {
02342
02343 obj = OBJECTHDR(this);
02344
02345 GL_THROW("load:%s - failed to map parent object for childed node",obj->name ? obj->name : "unnamed");
02346
02347
02348
02349
02350 }
02351
02352
02353 if (temp_par_node->full_Y_load == NULL)
02354 {
02355
02356 LOCK_OBJECT(SubNodeParent);
02357
02358
02359 temp_par_node->full_Y_load = (complex *)gl_malloc(3*sizeof(complex));
02360
02361
02362 if (temp_par_node->full_Y_load==NULL)
02363 {
02364 GL_THROW("Node:%s failed to allocate space for the a deltamode variable",SubNodeParent->name);
02365
02366
02367
02368
02369
02370 }
02371
02372
02373 temp_par_node->full_Y_load[0] = temp_par_node->full_Y_load[1] = temp_par_node->full_Y_load[2] = complex(0.0,0.0);
02374
02375
02376
02377
02378 UNLOCK_OBJECT(SubNodeParent);
02379
02380
02381 NR_busdata[*NR_subnode_reference].full_Y_load = temp_par_node->full_Y_load;
02382 }
02383 }
02384 }
02385
02386 }
02387
02388
02389
02390
02391
02392 if (enable_inrush_calculations == true)
02393 {
02394 if (deltatimestep_running > 0)
02395 {
02396
02397 curr_delta_time = gl_globaldeltaclock;
02398
02399
02400 require_inrush_update = true;
02401
02402
02403 if (curr_delta_time != prev_delta_time)
02404 {
02405
02406 for (index_var=0; index_var<3; index_var++)
02407 {
02408
02409 transf_from_stdy_state = false;
02410
02411
02412 if (prev_delta_time < 0)
02413 {
02414
02415
02416 if ((SubNode != CHILD) && (SubNode != DIFF_CHILD))
02417 {
02418 if (NR_busdata[NR_node_reference].V[index_var].Mag() > 0.0)
02419 {
02420 transf_from_stdy_state = true;
02421 }
02422
02423 }
02424 else
02425 {
02426 if (NR_busdata[*NR_subnode_reference].V[index_var].Mag() > 0.0)
02427 {
02428 transf_from_stdy_state = true;
02429 }
02430
02431 }
02432 }
02433
02434
02435
02436 if (transf_from_stdy_state == true)
02437 {
02438
02439 if (shunt[index_var].Im()>0.0)
02440 {
02441
02442 LoadHistTermL[index_var] = complex(0.0,0.0);
02443 LoadHistTermL[index_var+3] = complex(0.0,0.0);
02444
02445
02446 ahrlloadstore[index_var] = complex(0.0,0.0);
02447 bhrlloadstore[index_var] = complex(0.0,0.0);
02448
02449
02450 LoadHistTermC[index_var+3] = LoadHistTermC[index_var];
02451
02452
02453 if (inrush_int_method_capacitance == IRM_TRAPEZOIDAL)
02454 {
02455
02456 workingvalue = shunt[index_var].Im() / (PI * current_frequency * deltatimestep_running);
02457
02458
02459 chrcloadstore[index_var] = 2.0 * workingvalue;
02460
02461
02462
02463 if ((SubNode != CHILD) && (SubNode != DIFF_CHILD))
02464 {
02465 LoadHistTermC[index_var] = NR_busdata[NR_node_reference].V[index_var] * chrcloadstore[index_var] / complex(2.0,0.0);
02466 }
02467 else
02468 {
02469 LoadHistTermC[index_var] = NR_busdata[*NR_subnode_reference].V[index_var] * chrcloadstore[index_var] / complex(2.0,0.0);
02470 }
02471 }
02472 else if (inrush_int_method_capacitance == IRM_BACKEULER)
02473 {
02474
02475 workingvalue = shunt[index_var].Im() / (2.0 * PI * current_frequency * deltatimestep_running);
02476
02477
02478 chrcloadstore[index_var] = workingvalue;
02479
02480
02481
02482 if ((SubNode != CHILD) && (SubNode != DIFF_CHILD))
02483 {
02484 LoadHistTermC[index_var] = NR_busdata[NR_node_reference].V[index_var] * chrcloadstore[index_var];
02485 }
02486 else
02487 {
02488 LoadHistTermC[index_var] = NR_busdata[*NR_subnode_reference].V[index_var] * chrcloadstore[index_var];
02489 }
02490 }
02491
02492
02493
02494
02495 }
02496 else if (shunt[index_var].Im()<0.0)
02497 {
02498
02499 LoadHistTermC[index_var] = complex(0.0,0.0);
02500 LoadHistTermC[index_var+3] = complex(0.0,0.0);
02501
02502
02503 chrcloadstore[index_var] = complex(0.0,0.0);
02504
02505
02506 LoadHistTermL[index_var+3] = LoadHistTermL[index_var];
02507
02508
02509
02510 working_impedance_value = complex(1.0,0.0) / shunt[index_var];
02511
02512 if (inrush_int_method_inductance == IRM_TRAPEZOIDAL)
02513 {
02514
02515 workingvalue = working_impedance_value.Im() / (PI * current_frequency * deltatimestep_running);
02516
02517
02518 working_data_value = working_impedance_value - complex(workingvalue,0.0);
02519 }
02520 else if (inrush_int_method_inductance == IRM_BACKEULER)
02521 {
02522
02523 workingvalue = working_impedance_value.Im() / (2.0 * PI * current_frequency * deltatimestep_running);
02524
02525
02526 working_data_value = complex(-1.0 * workingvalue,0.0);
02527 }
02528
02529
02530
02531 working_impedance_value += complex(workingvalue,0.0);
02532
02533
02534 if (working_impedance_value.IsZero() != true)
02535 {
02536 working_admittance_value = complex(1.0,0.0) / working_impedance_value;
02537 }
02538 else
02539 {
02540 working_admittance_value = complex(0.0,0.0);
02541 }
02542
02543
02544 bhrlloadstore[index_var] = working_admittance_value * working_data_value;
02545
02546 if (inrush_int_method_inductance == IRM_TRAPEZOIDAL)
02547 {
02548
02549 ahrlloadstore[index_var] = working_admittance_value*(working_data_value * working_admittance_value - complex(1.0,0.0));
02550 }
02551 else if (inrush_int_method_inductance == IRM_BACKEULER)
02552 {
02553
02554 ahrlloadstore[index_var] = working_admittance_value * working_data_value * working_admittance_value;
02555 }
02556
02557
02558
02559
02560
02561
02562
02563 if ((SubNode != CHILD) && (SubNode != DIFF_CHILD))
02564 {
02565 LoadHistTermL[index_var] = NR_busdata[NR_node_reference].V[index_var] * ahrlloadstore[index_var] /
02566 (complex(1.0,0.0) + bhrlloadstore[index_var]);
02567 }
02568 else
02569 {
02570 LoadHistTermL[index_var] = NR_busdata[*NR_subnode_reference].V[index_var] * ahrlloadstore[index_var] /
02571 (complex(1.0,0.0) + bhrlloadstore[index_var]);
02572 }
02573 }
02574 else
02575 {
02576
02577 ahrlloadstore[index_var] = complex(0.0,0.0);
02578 bhrlloadstore[index_var] = complex(0.0,0.0);
02579
02580 chrcloadstore[index_var] = complex(0.0,0.0);
02581
02582
02583 LoadHistTermL[index_var] = complex(0.0,0.0);
02584 LoadHistTermL[index_var+3] = complex(0.0,0.0);
02585
02586 LoadHistTermC[index_var] = complex(0.0,0.0);
02587 LoadHistTermC[index_var+3] = complex(0.0,0.0);
02588 }
02589 }
02590 else
02591 {
02592
02593 if (shunt[index_var].Im()>0.0)
02594 {
02595
02596 LoadHistTermL[index_var] = complex(0.0,0.0);
02597 LoadHistTermL[index_var+3] = complex(0.0,0.0);
02598
02599
02600 LoadHistTermC[index_var+3] = LoadHistTermC[index_var];
02601
02602
02603 if (inrush_int_method_capacitance == IRM_TRAPEZOIDAL)
02604 {
02605
02606
02607 if ((SubNode != CHILD) && (SubNode != DIFF_CHILD))
02608 {
02609 LoadHistTermC[index_var] = NR_busdata[NR_node_reference].V[index_var] * chrcloadstore[index_var] -
02610 LoadHistTermC[index_var+3];
02611 }
02612 else
02613 {
02614 LoadHistTermC[index_var] = NR_busdata[*NR_subnode_reference].V[index_var] * chrcloadstore[index_var] -
02615 LoadHistTermC[index_var+3];
02616 }
02617 }
02618 else if (inrush_int_method_capacitance == IRM_BACKEULER)
02619 {
02620
02621
02622 if ((SubNode != CHILD) && (SubNode != DIFF_CHILD))
02623 {
02624 LoadHistTermC[index_var] = NR_busdata[NR_node_reference].V[index_var] * chrcloadstore[index_var];
02625 }
02626 else
02627 {
02628 LoadHistTermC[index_var] = NR_busdata[*NR_subnode_reference].V[index_var] * chrcloadstore[index_var];
02629 }
02630 }
02631
02632 }
02633 else if (shunt[index_var].Im()<0.0)
02634 {
02635
02636 LoadHistTermC[index_var] = complex(0.0,0.0);
02637 LoadHistTermC[index_var+3] = complex(0.0,0.0);
02638
02639
02640 LoadHistTermL[index_var+3] = LoadHistTermL[index_var];
02641
02642
02643
02644
02645 if ((SubNode != CHILD) && (SubNode != DIFF_CHILD))
02646 {
02647 LoadHistTermL[index_var] = NR_busdata[NR_node_reference].V[index_var] * ahrlloadstore[index_var] -
02648 bhrlloadstore[index_var] * LoadHistTermL[index_var+3];
02649 }
02650 else
02651 {
02652 LoadHistTermL[index_var] = NR_busdata[*NR_subnode_reference].V[index_var] * ahrlloadstore[index_var] -
02653 bhrlloadstore[index_var] * LoadHistTermL[index_var+3];
02654 }
02655 }
02656 else
02657 {
02658
02659 LoadHistTermL[index_var] = complex(0.0,0.0);
02660 LoadHistTermL[index_var+3] = complex(0.0,0.0);
02661
02662 LoadHistTermC[index_var] = complex(0.0,0.0);
02663 LoadHistTermC[index_var+3] = complex(0.0,0.0);
02664 }
02665 }
02666
02667
02668 if ((SubNode!=CHILD) && (SubNode!=DIFF_CHILD))
02669 {
02670
02671 NR_busdata[NR_node_reference].BusHistTerm[index_var] += LoadHistTermL[index_var] + LoadHistTermC[index_var];
02672 }
02673 else
02674 {
02675
02676 NR_busdata[*NR_subnode_reference].BusHistTerm[index_var] += LoadHistTermL[index_var] + LoadHistTermC[index_var];
02677 }
02678 }
02679 }
02680
02681 }
02682 else
02683 {
02684
02685
02686 require_inrush_update = false;
02687
02688
02689 LoadHistTermL[0] = complex(0.0,0.0);
02690 LoadHistTermL[1] = complex(0.0,0.0);
02691 LoadHistTermL[2] = complex(0.0,0.0);
02692 LoadHistTermL[3] = complex(0.0,0.0);
02693 LoadHistTermL[4] = complex(0.0,0.0);
02694 LoadHistTermL[5] = complex(0.0,0.0);
02695
02696 LoadHistTermC[0] = complex(0.0,0.0);
02697 LoadHistTermC[1] = complex(0.0,0.0);
02698 LoadHistTermC[2] = complex(0.0,0.0);
02699 LoadHistTermC[3] = complex(0.0,0.0);
02700 LoadHistTermC[4] = complex(0.0,0.0);
02701 LoadHistTermC[5] = complex(0.0,0.0);
02702
02703
02704
02705 if ((SubNode!=CHILD) && (SubNode!=DIFF_CHILD))
02706 {
02707
02708 NR_busdata[NR_node_reference].BusHistTerm[0] = complex(0.0,0.0);
02709 NR_busdata[NR_node_reference].BusHistTerm[1] = complex(0.0,0.0);
02710 NR_busdata[NR_node_reference].BusHistTerm[2] = complex(0.0,0.0);
02711
02712
02713 NR_busdata[NR_node_reference].full_Y_load[0] = complex(0.0,0.0);
02714 NR_busdata[NR_node_reference].full_Y_load[1] = complex(0.0,0.0);
02715 NR_busdata[NR_node_reference].full_Y_load[2] = complex(0.0,0.0);
02716 }
02717 else
02718 {
02719
02720 NR_busdata[*NR_subnode_reference].BusHistTerm[0] = complex(0.0,0.0);
02721 NR_busdata[*NR_subnode_reference].BusHistTerm[1] = complex(0.0,0.0);
02722 NR_busdata[*NR_subnode_reference].BusHistTerm[2] = complex(0.0,0.0);
02723
02724 NR_busdata[*NR_subnode_reference].full_Y_load[0] = complex(0.0,0.0);
02725 NR_busdata[*NR_subnode_reference].full_Y_load[1] = complex(0.0,0.0);
02726 NR_busdata[*NR_subnode_reference].full_Y_load[2] = complex(0.0,0.0);
02727 }
02728
02729
02730 prev_shunt[0] = complex(0.0,0.0);
02731 prev_shunt[1] = complex(0.0,0.0);
02732 prev_shunt[2] = complex(0.0,0.0);
02733 }
02734 }
02735 else
02736 {
02737 require_inrush_update = false;
02738 }
02739
02740
02741 if (require_inrush_update==true)
02742 {
02743
02744 for (index_var=0; index_var<3; index_var++)
02745 {
02746
02747 if (shunt[index_var].Im()>0.0)
02748 {
02749
02750 ahrlloadstore[index_var] = complex(0.0,0.0);
02751 bhrlloadstore[index_var] = complex(0.0,0.0);
02752
02753 if (inrush_int_method_capacitance == IRM_TRAPEZOIDAL)
02754 {
02755
02756 workingvalue = shunt[index_var].Im() / (PI * current_frequency * deltatimestep_running);
02757
02758
02759 chrcloadstore[index_var] = 2.0 * workingvalue;
02760 }
02761 else if (inrush_int_method_capacitance == IRM_BACKEULER)
02762 {
02763
02764 workingvalue = shunt[index_var].Im() / (2.0 * PI * current_frequency * deltatimestep_running);
02765
02766
02767 chrcloadstore[index_var] = workingvalue;
02768 }
02769
02770
02771
02772 shunt[index_var] += complex(workingvalue,0.0);
02773
02774 }
02775 else if (shunt[index_var].Im()<0.0)
02776 {
02777
02778 chrcloadstore[index_var] = complex(0.0,0.0);
02779
02780
02781 working_impedance_value = complex(1.0,0.0) / shunt[index_var];
02782
02783 if (inrush_int_method_inductance == IRM_TRAPEZOIDAL)
02784 {
02785
02786 workingvalue = working_impedance_value.Im() / (PI * current_frequency * deltatimestep_running);
02787
02788
02789 working_data_value = working_impedance_value - complex(workingvalue,0.0);
02790 }
02791 else if (inrush_int_method_inductance == IRM_BACKEULER)
02792 {
02793
02794 workingvalue = working_impedance_value.Im() / (2.0 * PI * current_frequency * deltatimestep_running);
02795
02796
02797 working_data_value = complex(-1.0 * workingvalue,0.0);
02798 }
02799
02800
02801
02802 working_impedance_value += complex(workingvalue,0.0);
02803
02804
02805 if (working_impedance_value.IsZero() != true)
02806 {
02807 working_admittance_value = complex(1.0,0.0) / working_impedance_value;
02808 }
02809 else
02810 {
02811 working_admittance_value = complex(0.0,0.0);
02812 }
02813
02814
02815 bhrlloadstore[index_var] = working_admittance_value * working_data_value;
02816
02817 if (inrush_int_method_inductance == IRM_TRAPEZOIDAL)
02818 {
02819
02820 ahrlloadstore[index_var] = working_admittance_value*(working_data_value * working_admittance_value - complex(1.0,0.0));
02821 }
02822 else if (inrush_int_method_inductance == IRM_BACKEULER)
02823 {
02824
02825 ahrlloadstore[index_var] = working_admittance_value * working_data_value * working_admittance_value;
02826 }
02827
02828
02829
02830 shunt[index_var] = working_admittance_value;
02831 }
02832 else
02833 {
02834
02835 ahrlloadstore[index_var] = complex(0.0,0.0);
02836 bhrlloadstore[index_var] = complex(0.0,0.0);
02837
02838 chrcloadstore[index_var] = complex(0.0,0.0);
02839 }
02840
02841
02842 if ((SubNode!=CHILD) && (SubNode!=DIFF_CHILD))
02843 {
02844
02845 NR_busdata[NR_node_reference].full_Y_load[index_var] += shunt[index_var]-prev_shunt[index_var];
02846 }
02847 else
02848 {
02849
02850 NR_busdata[*NR_subnode_reference].full_Y_load[index_var] += shunt[index_var]-prev_shunt[index_var];
02851 }
02852
02853
02854 prev_shunt[index_var] = shunt[index_var];
02855
02856
02857 shunt[index_var] = complex(0.0,0.0);
02858 }
02859
02860
02861
02862
02863
02864
02865 }
02866
02867 }
02868
02869
02870 void load::load_delete_update_fxn(void)
02871 {
02872 int index_var;
02873
02874 if ((solver_method!=SM_FBS) && ((SubNode==PARENT) || (SubNode==DIFF_PARENT)))
02875 {
02876 if (SubNode != PARENT)
02877 {
02878
02879 for (index_var=0; index_var<3; index_var++)
02880 {
02881 shunt[index_var] = complex(0.0,0.0);
02882 power[index_var] = complex(0.0,0.0);
02883 current[index_var] = complex(0.0,0.0);
02884 }
02885 }
02886 }
02887 else
02888 {
02889
02890 for (index_var=0; index_var<3; index_var++)
02891 {
02892 shunt[index_var] = complex(0.0,0.0);
02893 power[index_var] = complex(0.0,0.0);
02894 current[index_var] = complex(0.0,0.0);
02895 }
02896
02897
02898 for (index_var=0; index_var<6; index_var++)
02899 {
02900 shunt_dy[index_var] = complex(0.0,0.0);
02901 power_dy[index_var] = complex(0.0,0.0);
02902 current_dy[index_var] = complex(0.0,0.0);
02903 }
02904 }
02905 }
02906
02907
02908
02909
02910
02911 int load::notify(int update_mode, PROPERTY *prop, char *value)
02912 {
02913 complex diff_val;
02914 double power_tolerance;
02915
02916 if (solver_method == SM_NR)
02917 {
02918
02919 if (prev_power_value != NULL)
02920 {
02921
02922 if (strcmp(prop->name,"constant_power_A")==0)
02923 {
02924 if (update_mode==NM_PREUPDATE)
02925 {
02926
02927 prev_power_value[0] = constant_power[0];
02928 }
02929 else if (update_mode==NM_POSTUPDATE)
02930 {
02931
02932 power_tolerance = constant_power[0].Mag() * default_maximum_power_error;
02933
02934
02935 diff_val = constant_power[0] - prev_power_value[0];
02936
02937 if (diff_val.Mag() >= power_tolerance)
02938 {
02939 NR_retval = gl_globalclock;
02940 }
02941 }
02942 }
02943
02944
02945 if (strcmp(prop->name,"constant_power_B")==0)
02946 {
02947 if (update_mode==NM_PREUPDATE)
02948 {
02949
02950 prev_power_value[1] = constant_power[1];
02951 }
02952 else if (update_mode==NM_POSTUPDATE)
02953 {
02954
02955 power_tolerance = constant_power[1].Mag() * default_maximum_power_error;
02956
02957
02958 diff_val = constant_power[1] - prev_power_value[1];
02959
02960 if (diff_val.Mag() >= power_tolerance)
02961 {
02962 NR_retval = gl_globalclock;
02963 }
02964 }
02965 }
02966
02967
02968 if (strcmp(prop->name,"constant_power_C")==0)
02969 {
02970 if (update_mode==NM_PREUPDATE)
02971 {
02972
02973 prev_power_value[2] = constant_power[2];
02974 }
02975 else if (update_mode==NM_POSTUPDATE)
02976 {
02977
02978 power_tolerance = constant_power[2].Mag() * default_maximum_power_error;
02979
02980
02981 diff_val = constant_power[2] - prev_power_value[2];
02982
02983 if (diff_val.Mag() >= power_tolerance)
02984 {
02985 NR_retval = gl_globalclock;
02986 }
02987 }
02988 }
02989 }
02990 }
02991
02992
02993 return 1;
02994 }
02995
02996
02998
03000
03001 SIMULATIONMODE load::inter_deltaupdate_load(unsigned int64 delta_time, unsigned long dt, unsigned int iteration_count_val,bool interupdate_pos)
03002 {
03003 OBJECT *hdr = OBJECTHDR(this);
03004 bool fault_mode;
03005 double deltat, deltatimedbl;
03006 STATUS return_status_val;
03007
03008
03009 deltat = (double)dt/(double)DT_SECOND;
03010
03011
03012 if ((iteration_count_val==0) && (interupdate_pos == false))
03013 {
03014
03015 deltatimedbl = (double)delta_time/(double)DT_SECOND;
03016
03017
03018 prev_time_dbl = (double)gl_globalclock + deltatimedbl;
03019
03020
03021 if (fmeas_type != FM_NONE)
03022 {
03023
03024 memcpy(&prev_freq_state,&curr_freq_state,sizeof(FREQM_STATES));
03025 }
03026 }
03027
03028
03029 if ((delta_time==0) && (iteration_count_val==0) && (interupdate_pos == false) && (fmeas_type != FM_NONE))
03030 {
03031
03032 init_freq_dynamics();
03033 }
03034
03035
03036 if ((GFA_enable == true) && (iteration_count_val == 0) && (interupdate_pos == false))
03037 {
03038
03039 GFA_Update_time = perform_GFA_checks(deltat);
03040 }
03041
03042 if (interupdate_pos == false)
03043 {
03044
03045 if (SubNode==PARENT)
03046 {
03047 shunt[0] = shunt[1] = shunt[2] = 0.0;
03048 power[0] = power[1] = power[2] = 0.0;
03049 current[0] = current[1] = current[2] = 0.0;
03050 }
03051
03052
03053 NR_node_presync_fxn(0);
03054
03055
03056 if (fault_check_object == NULL)
03057 fault_mode = false;
03058 else
03059 fault_mode = true;
03060
03061
03062 if (GFA_enable == true)
03063 {
03064
03065 if (GFA_status == true)
03066 {
03067
03068 load_update_fxn(fault_mode);
03069 }
03070 else
03071 {
03072
03073 load_delete_update_fxn();
03074 }
03075 }
03076 else
03077 {
03078
03079 load_update_fxn(fault_mode);
03080 }
03081
03082
03083 NR_node_sync_fxn(hdr);
03084
03085 return SM_DELTA;
03086
03087 }
03088 else
03089 {
03090
03091 BOTH_node_postsync_fxn(hdr);
03092
03093
03094 if (fmeas_type != FM_NONE)
03095 {
03096 return_status_val = calc_freq_dynamics(deltat);
03097
03098
03099 if (return_status_val == FAILED)
03100 {
03101 return SM_ERROR;
03102 }
03103 }
03104
03105
03106
03107 measured_voltage_A.SetPolar(voltageA.Mag(),voltageA.Arg());
03108 measured_voltage_B.SetPolar(voltageB.Mag(),voltageB.Arg());
03109 measured_voltage_C.SetPolar(voltageC.Mag(),voltageC.Arg());
03110 measured_voltage_AB = measured_voltage_A-measured_voltage_B;
03111 measured_voltage_BC = measured_voltage_B-measured_voltage_C;
03112 measured_voltage_CA = measured_voltage_C-measured_voltage_A;
03113
03114
03115 if (GFA_enable == true)
03116 {
03117
03118 if ((GFA_Update_time > 0.0) && (GFA_Update_time < 1.7))
03119 {
03120
03121 return SM_DELTA;
03122 }
03123 else
03124 {
03125 return SM_EVENT;
03126 }
03127 }
03128 else
03129 {
03130 return SM_EVENT;
03131 }
03132 }
03133 }
03134
03135
03137
03139
03147 EXPORT int create_load(OBJECT **obj, OBJECT *parent)
03148 {
03149 try
03150 {
03151 *obj = gl_create_object(load::oclass);
03152 if (*obj!=NULL)
03153 {
03154 load *my = OBJECTDATA(*obj,load);
03155 gl_set_parent(*obj,parent);
03156 return my->create();
03157 }
03158 else
03159 return 0;
03160 }
03161 CREATE_CATCHALL(load);
03162 }
03163
03170 EXPORT int init_load(OBJECT *obj)
03171 {
03172 try {
03173 load *my = OBJECTDATA(obj,load);
03174 return my->init(obj->parent);
03175 }
03176 INIT_CATCHALL(load);
03177 }
03178
03187 EXPORT TIMESTAMP sync_load(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass)
03188 {
03189 try {
03190 load *pObj = OBJECTDATA(obj,load);
03191 TIMESTAMP t1 = TS_NEVER;
03192 switch (pass) {
03193 case PC_PRETOPDOWN:
03194 return pObj->presync(t0);
03195 case PC_BOTTOMUP:
03196 return pObj->sync(t0);
03197 case PC_POSTTOPDOWN:
03198 t1 = pObj->postsync(t0);
03199 obj->clock = t0;
03200 return t1;
03201 default:
03202 throw "invalid pass request";
03203 }
03204 }
03205 SYNC_CATCHALL(load);
03206 }
03207
03208 EXPORT int isa_load(OBJECT *obj, char *classname)
03209 {
03210 return OBJECTDATA(obj,load)->isa(classname);
03211 }
03212
03213 EXPORT int notify_load(OBJECT *obj, int update_mode, PROPERTY *prop, char *value){
03214 load *n = OBJECTDATA(obj, load);
03215 int rv = 1;
03216
03217 rv = n->notify(update_mode, prop, value);
03218
03219 return rv;
03220 }
03221
03222
03223 EXPORT SIMULATIONMODE interupdate_load(OBJECT *obj, unsigned int64 delta_time, unsigned long dt, unsigned int iteration_count_val, bool interupdate_pos)
03224 {
03225 load *my = OBJECTDATA(obj,load);
03226 SIMULATIONMODE status = SM_ERROR;
03227 try
03228 {
03229 status = my->inter_deltaupdate_load(delta_time,dt,iteration_count_val,interupdate_pos);
03230 return status;
03231 }
03232 catch (char *msg)
03233 {
03234 gl_error("interupdate_load(obj=%d;%s): %s", obj->id, obj->name?obj->name:"unnamed", msg);
03235 return status;
03236 }
03237 }
03238
03239 int load::kmldata(int (*stream)(const char*,...))
03240 {
03241 int phase[3] = {has_phase(PHASE_A),has_phase(PHASE_B),has_phase(PHASE_C)};
03242
03243
03244 stream("<TR><TH ALIGN=LEFT>Z</TH>");
03245 for ( int i = 0 ; i<sizeof(phase)/sizeof(phase[0]) ; i++ )
03246 {
03247 if ( phase[i] )
03248 stream("<TD ALIGN=RIGHT STYLE=\"font-family:courier;\"><NOBR>%.3f</NOBR></TD><TD ALIGN=LEFT>kVA</TD>", constant_impedance[i].Mag()/1000);
03249 else
03250 stream("<TD ALIGN=RIGHT STYLE=\"font-family:courier;\">—</TD><TD> </TD>");
03251 }
03252 stream("</TR>\n");
03253
03254
03255 stream("<TR><TH ALIGN=LEFT>I</TH>");
03256 for ( int i = 0 ; i<sizeof(phase)/sizeof(phase[0]) ; i++ )
03257 {
03258 if ( phase[i] )
03259 stream("<TD ALIGN=RIGHT STYLE=\"font-family:courier;\"><NOBR>%.3f</NOBR></TD><TD ALIGN=LEFT>kVA</TD>", constant_current[i].Mag()/1000);
03260 else
03261 stream("<TD ALIGN=RIGHT STYLE=\"font-family:courier;\">—</TD><TD> </TD>");
03262 }
03263 stream("</TR>\n");
03264
03265
03266 stream("<TR><TH ALIGN=LEFT>P</TH>");
03267 for ( int i = 0 ; i<sizeof(phase)/sizeof(phase[0]) ; i++ )
03268 {
03269 if ( phase[i] )
03270 stream("<TD ALIGN=RIGHT STYLE=\"font-family:courier;\"><NOBR>%.3f</NOBR></TD><TD ALIGN=LEFT>kVA</TD>", constant_power[i].Mag()/1000);
03271 else
03272 stream("<TD ALIGN=RIGHT STYLE=\"font-family:courier;\">—</TD><TD> </TD>");
03273 }
03274 stream("</TR>\n");
03275
03276 return 0;
03277 }
03278