00001
00002
00003 #ifndef _VIOLATION_RECORDER_H_
00004 #define _VIOLATION_RECORDER_H_
00005
00006 #include "tape.h"
00007 #include "../powerflow/transformer_configuration.h"
00008 #include "../powerflow/transformer.h"
00009 #include "../powerflow/line.h"
00010 #include <new>
00011
00012 EXPORT void new_violation_recorder(MODULE *);
00013
00014 #ifdef __cplusplus
00015
00016 #define VIOLATION0 0x00
00017 #define VIOLATION1 0x01
00018 #define VIOLATION2 0x02
00019 #define VIOLATION3 0x04
00020 #define VIOLATION4 0x08
00021 #define VIOLATION5 0x10
00022 #define VIOLATION6 0x20
00023 #define VIOLATION7 0x40
00024 #define VIOLATION8 0x80
00025 #define ALLVIOLATIONS 0xFF
00026
00027 #define XFMR 1
00028 #define OHLN 2
00029 #define UGLN 3
00030 #define TPXL 4
00031 #define NODE 5
00032 #define TPXN 6
00033 #define TPXM 7
00034 #define INVT 8
00035 #define CMTR 9
00036
00045 #define NO_PHASE 0x0000
00046
00047 #define PHASE_A 0x0001
00048 #define PHASE_B 0x0002
00049 #define PHASE_C 0x0004
00050 #define PHASE_ABC 0x0007
00051 #define PHASE_N 0x0008
00052 #define PHASE_ABCN 0x000f
00053
00054 #define PHASE_S1 0x0010
00055 #define PHASE_S2 0x0020
00056 #define PHASE_SN 0x0040
00057 #define PHASE_S 0x0070
00058 #define GROUND 0x0080
00060 #define AR 0x002
00061 #define BR 0x020
00062 #define CR 0x200
00063
00064 #define POWER 0x01
00065 #define CURRENT 0x02
00066
00067 #define sign(x) ((x > 0) - (x < 0))
00068 #define l2(x) (log((double) x) / log(2.0))
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 class vobjlist{
00082 public:
00083 vobjlist(){
00084 obj = 0;
00085 next = 0;
00086 ref_obj=0;
00087 for( int i = 0; i < 3; i++ ){
00088 last_v[i] = 0;
00089 last_t[i] = 0;
00090 last_s[i] = 0;
00091 }
00092 }
00093 vobjlist(OBJECT *o){
00094 obj = o;
00095 next = 0;
00096 ref_obj=0;
00097 for( int i = 0; i < 3; i++ ){
00098 last_v[i] = 0;
00099 last_t[i] = 0;
00100 last_s[i] = 0;
00101 }
00102 }
00103 ~vobjlist(){if(next != 0) delete next;}
00104 void tack(OBJECT *o) {
00105 if (obj) {
00106 if(next){
00107 next->tack(o);
00108 } else {
00109
00110 next = (vobjlist *)gl_malloc(sizeof(vobjlist));
00111
00112 if (next == NULL)
00113 {
00114 GL_THROW("violation_recorder - Failed to allocate space for object list to check");
00115
00116
00117
00118
00119 }
00120
00121
00122 new (next) vobjlist(o);
00123 }
00124 } else {
00125 obj = o;
00126 }
00127 }
00128 void add_ref(OBJECT *o) {
00129 ref_obj = o;
00130 }
00131 int length() {
00132 if(next){
00133 return 1+next->length();
00134 }
00135 if (obj) {
00136 return 1;
00137 }
00138 return 0;
00139 }
00140 void update_last(int i, double v, TIMESTAMP t, int s) {
00141 if (i>2 || i<0)
00142 return;
00143 last_v[i] = v;
00144 last_t[i] = t;
00145 last_s[i] = s;
00146 }
00147 OBJECT *obj;
00148 vobjlist *next;
00149 OBJECT *ref_obj;
00150 double last_v[3];
00151 TIMESTAMP last_t[3];
00152 int last_s[3];
00153
00154 };
00155
00156 class uniqueList{
00157 public:
00158 uniqueList(){
00159 name = 0;
00160 next = 0;
00161 }
00162 uniqueList(char *n){
00163 name = n;
00164 next = 0;
00165 }
00166 ~uniqueList(){if(next != 0) delete next;}
00167 void insert(char *n) {
00168 if (name && strcmp(name, n) != 0) {
00169 if(next){
00170 next->insert(n);
00171 } else {
00172
00173 next = (uniqueList *)gl_malloc(sizeof(uniqueList));
00174
00175 if (next == NULL)
00176 {
00177 GL_THROW("violation_recorder - Failed to allocate space for unique list");
00178
00179
00180
00181
00182 }
00183
00184
00185 new (next) uniqueList(n);
00186 }
00187 } else {
00188 name = n;
00189 }
00190 }
00191 int length() {
00192 if(next){
00193 return 1+next->length();
00194 }
00195 if(name) {
00196 return 1;
00197 }
00198 return 0;
00199 }
00200 char *name;
00201 uniqueList *next;
00202 };
00203
00204 class violation_recorder{
00205 public:
00206 static violation_recorder *defaults;
00207 static CLASS *oclass, *pclass;
00208
00209 violation_recorder(MODULE *);
00210 int create();
00211 int init(OBJECT *);
00212 STATUS finalize(OBJECT *obj);
00213 int isa(char *);
00214 TIMESTAMP postsync(TIMESTAMP, TIMESTAMP);
00215
00216 int commit(TIMESTAMP);
00217 public:
00218 double dInterval;
00219 double dFlush_interval;
00220 int32 limit;
00221 char256 filename;
00222 char256 summary;
00223 char256 virtual_substation;
00224 bool strict;
00225 set violation_flag;
00226 bool echo;
00227 double xfrmr_thermal_limit_upper;
00228 double xfrmr_thermal_limit_lower;
00229 double line_thermal_limit_upper;
00230 double line_thermal_limit_lower;
00231 double node_instantaneous_voltage_limit_upper;
00232 double node_instantaneous_voltage_limit_lower;
00233 double node_continuous_voltage_limit_upper;
00234 double node_continuous_voltage_limit_lower;
00235 double node_continuous_voltage_interval;
00236 double secondary_dist_voltage_rise_upper_limit;
00237 double secondary_dist_voltage_rise_lower_limit;
00238 double substation_breaker_A_limit;
00239 double substation_breaker_B_limit;
00240 double substation_breaker_C_limit;
00241 double substation_pf_lower_limit;
00242 int violation_count[8][10];
00243 double inverter_v_chng_per_interval_upper_bound;
00244 double inverter_v_chng_per_interval_lower_bound;
00245 double inverter_v_chng_interval;
00246 TIMESTAMP violation_start_delay;
00247 private:
00248 int write_header();
00249 int flush_line();
00250 int write_footer();
00251 int pass_error_check();
00252 int check_violations(TIMESTAMP);
00253 int check_violation_1(TIMESTAMP);
00254 int check_violation_2(TIMESTAMP);
00255 int check_violation_3(TIMESTAMP);
00256 int check_violation_4(TIMESTAMP);
00257 int check_violation_5(TIMESTAMP);
00258 int check_violation_6(TIMESTAMP);
00259 int check_violation_7(TIMESTAMP);
00260 int check_violation_8(TIMESTAMP);
00261 int check_line_thermal_limit(TIMESTAMP, vobjlist *, uniqueList *, int, double, double);
00262 int check_xfrmr_thermal_limit(TIMESTAMP, vobjlist *, uniqueList *, int, double, double);
00263 int check_reverse_flow_violation(TIMESTAMP, int, double, char*);
00264 int write_to_stream (TIMESTAMP, bool, char *, ...);
00265 double get_observed_double_value(OBJECT *, PROPERTY *);
00266 complex get_observed_complex_value(OBJECT *, PROPERTY *);
00267 int make_object_list(int, char *, vobjlist *);
00268 int assoc_meter_w_xfrmr_node(vobjlist *, vobjlist *, vobjlist *);
00269 int find_substation_node(char256, vobjlist *);
00270 int has_phase(OBJECT *, int);
00271 int fails_static_condition (OBJECT *, char *, double, double, double, double *);
00272 int fails_static_condition (double, double, double, double, double *);
00273 int fails_dynamic_condition (vobjlist *, int, char *, TIMESTAMP, double, double, double, double, double *);
00274 int fails_continuous_condition (vobjlist *, int, char *, TIMESTAMP, double, double, double, double, double *);
00275 int increment_violation (int);
00276 int increment_violation (int, int);
00277 int get_violation_count(int);
00278 int get_violation_count(int, int);
00279 int write_summary();
00280
00281 vobjlist *vobjlist_alloc_fxn(vobjlist *input_list);
00282 uniqueList *uniqueList_alloc_fxn(uniqueList *input_unlist);
00283 private:
00284 FILE *rec_file;
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 vobjlist *xfrmr_obj_list;
00299 vobjlist *ohl_obj_list;
00300 vobjlist *ugl_obj_list;
00301 vobjlist *tplxl_obj_list;
00302 vobjlist *node_obj_list;
00303 vobjlist *tplx_node_obj_list;
00304 vobjlist *tplx_mtr_obj_list;
00305 vobjlist *comm_mtr_obj_list;
00306 vobjlist *inverter_obj_list;
00307 vobjlist *powerflow_obj_list;
00308 OBJECT *link_monitor_obj;
00309 uniqueList *xfrmr_list_v1;
00310 uniqueList *ohl_list_v1;
00311 uniqueList *ugl_list_v1;
00312 uniqueList *tplxl_list_v1;
00313 uniqueList *node_list_v2;
00314 uniqueList *tplx_node_list_v2;
00315 uniqueList *tplx_meter_list_v2;
00316 uniqueList *comm_meter_list_v2;
00317 uniqueList *tplx_node_list_v3;
00318 uniqueList *tplx_meter_list_v3;
00319 uniqueList *comm_meter_list_v3;
00320 uniqueList *inverter_list_v6;
00321 uniqueList *tplx_meter_list_v7;
00322 uniqueList *comm_meter_list_v7;
00323
00324 int write_count;
00325 TIMESTAMP next_write;
00326 TIMESTAMP last_write;
00327 TIMESTAMP last_flush;
00328 TIMESTAMP write_interval;
00329 TIMESTAMP flush_interval;
00330 int32 write_ct;
00331 TAPESTATUS tape_status;
00332 char *prev_line_buffer;
00333 char *line_buffer;
00334 size_t line_size;
00335 bool interval_write;
00336 TIMESTAMP sim_start;
00337 };
00338
00339 #endif // C++
00340
00341 #endif // _VIOLATION_RECORDER_H_
00342
00343