00001
00002
00003
00004 #ifndef _LINK_H
00005 #define _LINK_H
00006
00007 #include "powerflow.h"
00008
00009 EXPORT int isa_link(OBJECT *obj, char *classname);
00010 EXPORT SIMULATIONMODE interupdate_link(OBJECT *obj, unsigned int64 delta_time, unsigned long dt, unsigned int iteration_count_val, bool interupdate_pos);
00011 EXPORT int updatepowercalc_link(OBJECT *obj);
00012 EXPORT int calculate_overlimit_link(OBJECT *obj, double *overload_value, bool *overloaded);
00013
00014 #define impedance(X) (B_mat[X][X])
00015
00016 typedef enum {
00017 NORMAL=0,
00018 REGULATOR=1,
00019 DELTAGWYE=2,
00020 SPLITPHASE=3,
00021 SWITCH=4,
00022 DELTADELTA=5,
00023 WYEWYE=6,
00024 VFD=7
00025 } SPECIAL_LINK;
00026
00027
00028 #define FD_UNKNOWN 0x000
00029 #define FD_A_MASK 0x00f
00030 #define FD_A_NORMAL 0x001
00031 #define FD_A_REVERSE 0x002
00032 #define FD_A_NONE 0x003
00033 #define FD_B_MASK 0x0f0
00034 #define FD_B_NORMAL 0x010
00035 #define FD_B_REVERSE 0x020
00036 #define FD_B_NONE 0x030
00037 #define FD_C_MASK 0xf00
00038 #define FD_C_NORMAL 0x100
00039 #define FD_C_REVERSE 0x200
00040 #define FD_C_NONE 0x300
00041
00042 class link_object : public powerflow_object
00043 {
00044 public:
00045 complex a_mat[3][3];
00046 complex b_mat[3][3];
00047 complex c_mat[3][3];
00048 complex d_mat[3][3];
00049 complex A_mat[3][3];
00050 complex B_mat[3][3];
00051 complex tn[3];
00052 complex base_admittance_mat[3][3];
00053 complex To_Y[3][3];
00054 complex From_Y[3][3];
00055 complex *YSfrom;
00056 complex *YSto;
00057 double voltage_ratio;
00058 int NR_branch_reference;
00059 SPECIAL_LINK SpecialLnk;
00060 set flow_direction;
00061 void calculate_power();
00062 void calculate_power_splitphase();
00063 void set_flow_directions();
00064 int link_fault_on(OBJECT **protect_obj, char *fault_type, int *implemented_fault, TIMESTAMP *repair_time);
00065 int link_fault_off(int *implemented_fault, char *imp_fault_name);
00066 double mean_repair_time;
00067 double *link_limits[2][3];
00068 double link_rating[2][3];
00069 double *get_double(OBJECT *obj, char *name);
00070 public:
00071 enumeration status;
00072 enumeration prev_status;
00073
00074 bool current_accumulated;
00075 bool check_link_limits;
00076 OBJECT *from;
00077 OBJECT *to;
00078 complex current_in[3];
00079 complex current_out[3];
00080 complex read_I_in[3];
00081 complex read_I_out[3];
00082 complex If_in[3];
00083 complex If_out[3];
00084 complex Vf_out[3];
00085 complex power_in;
00086 complex power_out;
00087 complex power_loss;
00088 complex indiv_power_in[3];
00089 complex indiv_power_out[3];
00090 complex indiv_power_loss[3];
00091 int protect_locations[3];
00092 FUNCTIONADDR link_recalc_fxn;
00093
00094 int create(void);
00095 int init(OBJECT *parent);
00096 TIMESTAMP prev_LTime;
00097 TIMESTAMP presync(TIMESTAMP t0);
00098 TIMESTAMP sync(TIMESTAMP t0);
00099 TIMESTAMP postsync(TIMESTAMP t0);
00100 link_object(MODULE *mod);
00101 link_object(CLASS *cl=oclass):powerflow_object(cl){};
00102 static CLASS *oclass;
00103 static CLASS *pclass;
00104 int isa(char *classname);
00105 public:
00106
00107 set affected_phases;
00108 #define IMPEDANCE_CHANGED 1
00109 double resistance;
00110 #define LINE_CONTACT 2
00111 set line_contacted;
00112 #define CONTROL_FAILED 4
00113
00114 class node *get_from(void) const;
00115 class node *get_to(void) const;
00116 set get_flow(class node **from, class node **to) const;
00117
00118 inline enumeration open(void) { enumeration previous=status; status=LS_OPEN; return previous;};
00119 inline enumeration close(void) { enumeration previous=status; status=LS_CLOSED; return previous;};
00120 inline enumeration is_open(void) const { return status==LS_OPEN;};
00121 inline enumeration is_closed(void) const { return status==LS_CLOSED;};
00122 inline enumeration get_status(void) const {return status;};
00123
00124 bool is_frequency_nominal();
00125 bool is_voltage_nominal();
00126
00127 static int kmlinit(int (*stream)(const char*,...));
00128 int kmldump(int (*stream)(const char*,...));
00129
00130 int CurrentCalculation(int nodecall, bool link_fault_mode);
00131
00132 void NR_link_presync_fxn(void);
00133 void BOTH_link_postsync_fxn(void);
00134 void perform_limit_checks(double *over_limit_value, bool *over_limits);
00135 double inrush_tol_value;
00136 INRUSHINTMETHOD inrush_int_method_inductance;
00137 INRUSHINTMETHOD inrush_int_method_capacitance;
00138
00139
00140 void lmatrix_add(complex *matrix_in_A, complex *matrix_in_B, complex *matrix_out, int matsize);
00141 void lmatrix_mult(complex *matrix_in_A, complex *matrix_in_B, complex *matrix_out, int matsize);
00142 void lmatrix_vmult(complex *matrix_in, complex *vector_in, complex *vector_out, int matsize);
00143
00144
00145 void fault_current_calc(complex C[7][7], unsigned int removed_phase, double fault_type);
00146
00147 void mesh_fault_current_calc(complex Zth[3][3],complex CV[3][3],complex CI[3][3],complex *VSth,double fault_type);
00148 SIMULATIONMODE inter_deltaupdate_link(unsigned int64 delta_time, unsigned long dt, unsigned int iteration_count_val, bool interupdate_pos);
00149
00150 private:
00151 bool deltamode_inclusive;
00152 bool inrush_computations_needed;
00153 double inrush_vdiffmag_prev[3];
00154 double deltamode_prev_time;
00155
00156 public:
00157 complex *ahrlstore;
00158 complex *bhrlstore;
00159 complex *ahmstore;
00160 complex *bhmstore;
00161 double *chrcstore;
00162 complex *LinkCapShuntTerm;
00163 complex *LinkHistTermL;
00164 complex *LinkHistTermCf;
00165 complex *LinkHistTermCt;
00166 complex *YBase_Full;
00167 complex *YBase_Pri;
00168 complex *YBase_Sec;
00169
00170
00171
00172 double D_sat;
00173 complex A_phi;
00174 complex B_phi;
00175 complex *hphi;
00176 complex *saturation_calculated_vals;
00177
00178
00179
00180 };
00181
00182
00183 void inverse(complex in[3][3], complex out[3][3]);
00184 void multiply(double a, complex b[3][3], complex c[3][3]);
00185 void multiply(complex a[3][3], complex b[3][3], complex c[3][3]);
00186 void subtract(complex a[3][3], complex b[3][3], complex c[3][3]);
00187 void addition(complex a[3][3], complex b[3][3], complex c[3][3]);
00188 void equalm(complex a[3][3], complex b[3][3]);
00189
00190
00191 void lu_decomp(complex *a, complex *l, complex *u, int size_val);
00192 void forward_sub(complex *l, complex *b, complex *z, int size_val);
00193 void back_sub(complex *u, complex *z, complex *x, int size_val);
00194 void lu_matrix_inverse(complex *input_mat, complex *output_mat, int size_val);
00195 #endif // _LINK_H
00196