00001
00007 #ifndef _NODE_H
00008 #define _NODE_H
00009
00010 #include "powerflow.h"
00011
00012
00013 EXPORT SIMULATIONMODE interupdate_node(OBJECT *obj, unsigned int64 delta_time, unsigned long dt, unsigned int iteration_count_val, bool interupdate_pos);
00014 EXPORT STATUS swap_node_swing_status(OBJECT *obj, bool desired_status);
00015 EXPORT STATUS node_reset_disabled_status(OBJECT *nodeObj);
00016 EXPORT STATUS node_map_current_update_function(OBJECT *nodeObj, OBJECT *callObj);
00017 EXPORT STATUS attach_vfd_to_node(OBJECT *obj,OBJECT *calledVFD);
00018
00019 #define I_INJ(V, S, Z, I) (I_S(S, V) + ((Z.IsFinite()) ? I_Z(Z, V) : complex(0.0)) + I_I(I))
00020 #define I_S(S, V) (~((S) / (V))) // Current injection - constant power load
00021 #define I_Z(Z, V) ((V) / (Z)) // Current injection - constant impedance load
00022 #define I_I(I) (I) // Current injection - constant current load
00023
00024
00025
00026
00027
00028
00029
00030 #define voltageA voltage[0]
00031 #define voltageB voltage[1]
00032 #define voltageC voltage[2]
00033
00034 #define voltageAB voltaged[0]
00035 #define voltageBC voltaged[1]
00036 #define voltageCA voltaged[2]
00037
00038 #define currentA current[0]
00039 #define currentB current[1]
00040 #define currentC current[2]
00041
00042 #define powerA power[0]
00043 #define powerB power[1]
00044 #define powerC power[2]
00045
00046 #define shuntA shunt[0]
00047 #define shuntB shunt[1]
00048 #define shuntC shunt[2]
00049
00050
00051 #define voltage1 voltage[0]
00052 #define voltage2 voltage[1]
00053 #define voltageN voltage[2]
00054
00055 #define voltage12 voltaged[0]
00056 #define voltage2N voltaged[1]
00057 #define voltage1N voltaged[2]
00058
00059 #define current1 current[0]
00060 #define current2 current[1]
00061 #define currentN current[2]
00062
00063 #define power1 power[0]
00064 #define power2 power[1]
00065 #define power12 power[2]
00066
00067 #define shunt1 shunt[0]
00068 #define shunt2 shunt[1]
00069 #define shunt12 shunt[2]
00070
00071 typedef enum {
00072 NONE=0,
00073 CHILD=1,
00074 CHILD_NOINIT=2,
00075 PARENT=3,
00076 DIFF_CHILD=4,
00077 DIFF_PARENT=5
00078 } SUBNODETYPE;
00079
00080 typedef enum {
00081 NORMAL_NODE=0,
00082 LOAD_NODE=1,
00083 METER_NODE=2
00084 } DYN_NODE_TYPE;
00085
00086
00087 typedef struct {
00088 complex voltage_val[3];
00089 double x[3];
00090 double anglemeas[3];
00091 double fmeas[3];
00092 double average_freq;
00093 double sinangmeas[3];
00094 double cosangmeas[3];
00095 } FREQM_STATES;
00096
00097
00098 class node : public powerflow_object
00099 {
00100 private:
00101 complex last_voltage[3];
00102 complex current_inj[3];
00103 TIMESTAMP prev_NTime;
00104 complex last_child_power[4][3];
00105 complex last_child_power_dy[6][3];
00106 complex last_child_current12;
00107 bool deltamode_inclusive;
00108 complex BusHistTerm[3];
00109 double prev_delta_time;
00110 complex *ahrlloadstore;
00111 complex *bhrlloadstore;
00112 complex *chrcloadstore;
00113 complex *LoadHistTermL;
00114 complex *LoadHistTermC;
00115
00116
00117 FREQM_STATES curr_freq_state;
00118 FREQM_STATES prev_freq_state;
00119 double freq_omega_ref;
00120
00121 double freq_violation_time_total;
00122 double volt_violation_time_total;
00123 double out_of_violation_time_total;
00124 double prev_time_dbl;
00125 double GFA_Update_time;
00126 GL_STRUCT(complex_array,full_Y_matrix);
00127 GL_STRUCT(complex_array,full_Y_all_matrix);
00128
00129
00130 bool VFD_attached;
00131 FUNCTIONADDR VFD_updating_function;
00132 OBJECT *VFD_object;
00133
00134 double compute_angle_diff(double angle_B, double angle_A);
00135
00136 public:
00137 double frequency;
00138 object reference_bus;
00139 static unsigned int n;
00140 unsigned short k;
00141 complex *prev_voltage_value;
00142 complex *prev_power_value;
00143
00144 bool reset_island_state;
00145 public:
00146
00147 enum {
00148 PQ=0,
00149 PV=1,
00150 SWING=2,
00151 SWING_PQ=3
00152 };
00153 enumeration bustype;
00154 enum { NOMINAL=1,
00155 UNDERVOLT,
00156 OVERVOLT,
00157 };
00158 enumeration status;
00159 enum {
00160 ND_OUT_OF_SERVICE = 0,
00161 ND_IN_SERVICE = 1,
00162 };
00163 enum {
00164 GFA_NONE=0,
00165 GFA_UF=1,
00166 GFA_OF=2,
00167 GFA_UV=3,
00168 GFA_OV=4
00169 };
00170 enumeration GFA_trip_method;
00171 enumeration service_status;
00172 double service_status_dbl;
00173 TIMESTAMP last_disconnect;
00174 double previous_uptime;
00175 double current_uptime;
00176
00177
00178 enum {FM_NONE=1, FM_SIMPLE=2, FM_PLL=3};
00179 enumeration fmeas_type;
00180
00181 double freq_sfm_Tf;
00182 double freq_pll_Kp;
00183 double freq_pll_Ki;
00184
00185
00186 bool GFA_enable;
00187 double GFA_freq_low_trip;
00188 double GFA_freq_high_trip;
00189 double GFA_voltage_low_trip;
00190 double GFA_voltage_high_trip;
00191 double GFA_reconnect_time;
00192 double GFA_freq_disconnect_time;
00193 double GFA_volt_disconnect_time;
00194 bool GFA_status;
00195
00196 SUBNODETYPE SubNode;
00197 set busflags;
00198 set busphasesIn;
00199 set busphasesOut;
00200 double maximum_voltage_error;
00201
00202
00203 complex voltage[3];
00204 complex voltaged[3];
00205 complex current[3];
00206 complex pre_rotated_current[3];
00207 complex deltamode_dynamic_current[3];
00208 complex deltamode_PGenTotal;
00209 complex power[3];
00210 complex shunt[3];
00211 complex current_dy[6];
00212 complex power_dy[6];
00213 complex shunt_dy[6];
00214 complex *full_Y;
00215 complex *full_Y_load;
00216 complex *full_Y_all;
00217 DYN_NODE_TYPE node_type;
00218 complex current12;
00219 complex nom_res_curr[3];
00220 bool house_present;
00221 bool dynamic_norton;
00222 bool dynamic_generator;
00223 complex *Triplex_Data;
00224 complex *Extra_Data;
00225 unsigned int NR_connected_links[2];
00226 unsigned int NR_number_child_nodes[2];
00227 node **NR_child_nodes;
00228 int *NR_link_table;
00229
00230 double mean_repair_time;
00231
00232 int NR_node_reference;
00233 int *NR_subnode_reference;
00234 unsigned char prev_phases;
00235
00236 inline bool is_split() {return (phases&PHASE_S)!=0;};
00237 public:
00238 static CLASS *oclass;
00239 static CLASS *pclass;
00240 static node *defaults;
00241 public:
00242 node(MODULE *mod);
00243 inline node(CLASS *cl=oclass):powerflow_object(cl){};
00244 int create(void);
00245 int init(OBJECT *parent=NULL);
00246 TIMESTAMP presync(TIMESTAMP t0);
00247 TIMESTAMP sync(TIMESTAMP t0);
00248 TIMESTAMP postsync(TIMESTAMP t0);
00249 int isa(char *classname);
00250 int notify(int update_mode, PROPERTY *prop, char *value);
00251 SIMULATIONMODE inter_deltaupdate_node(unsigned int64 delta_time, unsigned long dt, unsigned int iteration_count_val, bool interupdate_pos);
00252
00253
00254 TIMESTAMP NR_node_presync_fxn(TIMESTAMP t0_val);
00255 void NR_node_sync_fxn(OBJECT *obj);
00256 void BOTH_node_postsync_fxn(OBJECT *obj);
00257 OBJECT *NR_master_swing_search(char *node_type_value,bool main_swing);
00258
00259 void init_freq_dynamics(void);
00260 STATUS calc_freq_dynamics(double deltat);
00261
00262 double perform_GFA_checks(double timestepvalue);
00263
00264 STATUS link_VFD_functions(OBJECT *linkVFD);
00265
00266 bool current_accumulated;
00267
00268 int NR_populate(void);
00269 OBJECT *SubNodeParent;
00270 int NR_current_update(bool parentcall);
00271 object TopologicalParent;
00272
00273
00274 STATUS NR_swap_swing_status(bool desired_status);
00275
00276
00277 STATUS reset_node_island_condition(void);
00278
00279
00280 STATUS NR_map_current_update_function(OBJECT *callObj);
00281
00282 friend class link_object;
00283 friend class meter;
00284 friend class substation;
00285 friend class triplex_node;
00286 friend class triplex_meter;
00287 friend class triplex_load;
00288 friend class load;
00289 friend class capacitor;
00290 friend class fuse;
00291 friend class frequency_gen;
00292 friend class motor;
00293
00294 static int kmlinit(int (*stream)(const char*,...));
00295 int kmldump(int (*stream)(const char*,...));
00296 };
00297
00298 #endif // _NODE_H
00299