00001
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 #include <errno.h>
00008 #include <math.h>
00009 #include <string.h>
00010
00011 #include <iostream>
00012 #include <fstream>
00013 #include <cstring>
00014 #include <json/json.h>
00015 using namespace std;
00016
00017 #include "jsondump.h"
00018
00020
00022
00023 CLASS* jsondump::oclass = NULL;
00024
00025
00026 jsondump::jsondump(MODULE *mod)
00027 {
00028 if (oclass==NULL)
00029 {
00030
00031 oclass = gl_register_class(mod,"jsondump",sizeof(jsondump),PC_AUTOLOCK);
00032 if (oclass==NULL)
00033 GL_THROW("unable to register object class implemented by %s",__FILE__);
00034
00035
00036 if (gl_publish_variable(oclass,
00037 PT_char32,"group",PADDR(group),PT_DESCRIPTION,"the group ID to output data for (all objects if empty)",
00038 PT_char256,"filename_dump_system",PADDR(filename_dump_system),PT_DESCRIPTION,"the file to dump the current data into",
00039 PT_char256,"filename_dump_reliability",PADDR(filename_dump_reliability),PT_DESCRIPTION,"the file to dump the current data into",
00040 PT_timestamp,"runtime",PADDR(runtime),PT_DESCRIPTION,"the time to check voltage data",
00041 PT_int32,"runcount",PADDR(runcount),PT_ACCESS,PA_REFERENCE,PT_DESCRIPTION,"the number of times the file has been written to",
00042 PT_bool,"write_system_info",PADDR(write_system),PT_DESCRIPTION,"Flag indicating whether system information will be written into JSON file or not",
00043 PT_bool,"write_reliability",PADDR(write_reliability),PT_DESCRIPTION,"Flag indicating whether reliabililty information will be written into JSON file or not",
00044 PT_bool,"write_per_unit",PADDR(write_per_unit),PT_DESCRIPTION,"Output the quantities as per-unit values",
00045 PT_double,"system_base[VA]",PADDR(system_VA_base),PT_DESCRIPTION,"System base power rating for per-unit calculations",
00046 PT_double,"min_node_voltage[pu]",PADDR(min_volt_value),PT_DESCRIPTION,"Per-unit minimum voltage level allowed for nodes",
00047 PT_double,"max_node_voltage[pu]",PADDR(max_volt_value),PT_DESCRIPTION,"Per-unit maximum voltage level allowed for nodes",
00048
00049 NULL)<1) GL_THROW("unable to publish properties in %s",__FILE__);
00050 }
00051 }
00052
00053 int jsondump::create(void)
00054 {
00055
00056 write_system = false;
00057 write_reliability = false;
00058 write_per_unit = false;
00059 system_VA_base = -1.0;
00060
00061 group.erase();
00062 runcount = 0;
00063
00064 min_volt_value = 0.8;
00065 max_volt_value = 1.2;
00066
00067 return 1;
00068 }
00069
00070 int jsondump::init(OBJECT *parent)
00071 {
00072 OBJECT *hdr = OBJECTHDR(this);
00073
00074
00075 if ((filename_dump_system[0] == '\0') && (write_system == true)){
00076 filename_dump_system = "JSON_dump_line.json";
00077 }
00078
00079
00080 if ((filename_dump_reliability[0] == '\0') && (write_reliability == true)){
00081 filename_dump_reliability = "JSON_dump_reliability.json";
00082 }
00083
00084
00085 if ((filename_dump_system[0] != '\0') && (write_system == true) && (write_per_unit == true))
00086 {
00087
00088 if (system_VA_base <= 0.0)
00089 {
00090 gl_warning("jsondump:%d-%s -- If per-unit impedance is desired, a valid system_base must be specified - defaulting to 100 MVA",hdr->id,(hdr->name ? hdr->name : "Unnamed"));
00091
00092
00093
00094
00095
00096
00097 system_VA_base = 100.0e6;
00098 }
00099 }
00100
00101 return 1;
00102 }
00103
00104 STATUS jsondump::dump_system(void)
00105 {
00106
00107
00108 FINDLIST *ohlines, *tplines, *uglines, *switches, *regulators, *regConfs, *lineConfs, *tpLineConfs, *TransformerList, *TransConfsList, *nodes, *meters, *loads, *inverters, *diesels, *fuses;
00109 FINDLIST *reclosers, *sectionalizers;
00110 OBJECT *objhdr = OBJECTHDR(this);
00111 OBJECT *obj = NULL;
00112 OBJECT *obj_lineConf = NULL;
00113 OBJECT *obj_tplineConf = NULL;
00114 char buffer[1024];
00115 FILE *fn = NULL;
00116 int index = 0;
00117 int phaseCount;
00118 double per_unit_base, temp_impedance_base, temp_voltage_base, temp_de_pu_base;
00119 complex temp_complex_voltage_value[3];
00120 complex temp_complex_power_value[3];
00121 double temp_voltage_output_value;
00122 int indexA, indexB, indexC;
00123 complex *b_mat_pu;
00124 bool *b_mat_defined;
00125 complex *b_mat_tp_pu;
00126 bool *b_mat_tp_defined;
00127 complex *b_mat_trans_pu;
00128 bool *b_mat_trans_defined;
00129 int *trans_phase_count;
00130 complex *b_mat_reg_pu;
00131 bool *b_mat_reg_defined;
00132 int *reg_phase_count;
00133 complex b_mat_switch_pu[9];
00134 bool b_mat_switch_defined;
00135 int switch_phase_count;
00136 complex b_mat_fuse_pu[9];
00137 bool b_mat_fuse_defined;
00138 int fuse_phase_count;
00139 set temp_set_value;
00140 enumeration temp_enum_value;
00141 bool found_match_config;
00142
00143
00144 Json::Value metrics_lines;
00145 Json::Value node_object;
00146 Json::Value load_object;
00147 Json::Value line_object;
00148 Json::Value line_configuration_object;
00149 Json::Value jsonArray;
00150 Json::Value jsonSecondArray;
00151 Json::Value jsonArray1;
00152 Json::Value jsonArray2;
00153
00154 Json::StyledWriter writer;
00155
00156 ofstream out_file;
00157
00158
00159 if(group[0] == '\0'){
00160 ohlines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"overhead_line",AND,FT_MODULE,SAME,"powerflow",FT_END);
00161 tplines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"triplex_line",AND,FT_MODULE,SAME,"powerflow",FT_END);
00162 uglines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"underground_line",AND,FT_MODULE,SAME,"powerflow",FT_END);
00163 switches = gl_find_objects(FL_NEW,FT_CLASS,SAME,"switch",AND,FT_MODULE,SAME,"powerflow",FT_END);
00164 sectionalizers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"sectionalizer",AND,FT_MODULE,SAME,"powerflow",FT_END);
00165 reclosers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"recloser",AND,FT_MODULE,SAME,"powerflow",FT_END);
00166 fuses = gl_find_objects(FL_NEW,FT_CLASS,SAME,"fuse",AND,FT_MODULE,SAME,"powerflow",FT_END);
00167 regulators = gl_find_objects(FL_NEW,FT_CLASS,SAME,"regulator",AND,FT_MODULE,SAME,"powerflow",FT_END);
00168 regConfs = gl_find_objects(FL_NEW,FT_CLASS,SAME,"regulator_configuration",AND,FT_MODULE,SAME,"powerflow",FT_END);
00169 lineConfs = gl_find_objects(FL_NEW,FT_CLASS,SAME,"line_configuration",AND,FT_MODULE,SAME,"powerflow",FT_END);
00170 tpLineConfs = gl_find_objects(FL_NEW,FT_CLASS,SAME,"triplex_line_configuration",AND,FT_MODULE,SAME,"powerflow",FT_END);
00171 TransConfsList = gl_find_objects(FL_NEW,FT_CLASS,SAME,"transformer_configuration",AND,FT_MODULE,SAME,"powerflow",FT_END);
00172 TransformerList = gl_find_objects(FL_NEW,FT_CLASS,SAME,"transformer",AND,FT_MODULE,SAME,"powerflow",FT_END);
00173 nodes = gl_find_objects(FL_NEW,FT_CLASS,SAME,"node",AND,FT_MODULE,SAME,"powerflow",FT_END);
00174 meters = gl_find_objects(FL_NEW,FT_CLASS,SAME,"meter",AND,FT_MODULE,SAME,"powerflow",FT_END);
00175 loads = gl_find_objects(FL_NEW,FT_CLASS,SAME,"load",AND,FT_MODULE,SAME,"powerflow",FT_END);
00176
00177 inverters = gl_find_objects(FL_NEW,FT_CLASS,SAME,"inverter",AND,FT_MODULE,SAME,"generators",FT_END);
00178 diesels = gl_find_objects(FL_NEW,FT_CLASS,SAME,"diesel_dg",AND,FT_MODULE,SAME,"generators",FT_END);
00179 } else {
00180 ohlines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"overhead_line",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00181 tplines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"triplex_line",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00182 uglines = gl_find_objects(FL_NEW,FT_CLASS,SAME,"underground_line",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00183 switches = gl_find_objects(FL_NEW,FT_CLASS,SAME,"switch",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00184 sectionalizers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"sectionalizer",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00185 reclosers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"recloser",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00186 fuses = gl_find_objects(FL_NEW,FT_CLASS,SAME,"fuse",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00187 regulators = gl_find_objects(FL_NEW,FT_CLASS,SAME,"regulator",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00188 regConfs = gl_find_objects(FL_NEW,FT_CLASS,SAME,"regulator_configuration",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00189 lineConfs = gl_find_objects(FL_NEW,FT_CLASS,SAME,"line_configuration",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00190 tpLineConfs = gl_find_objects(FL_NEW,FT_CLASS,SAME,"triplex_line_configuration",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00191 TransConfsList = gl_find_objects(FL_NEW,FT_CLASS,SAME,"transformer_configuration",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00192 TransformerList = gl_find_objects(FL_NEW,FT_CLASS,SAME,"transformer",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00193 nodes = gl_find_objects(FL_NEW,FT_CLASS,SAME,"node",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00194 meters = gl_find_objects(FL_NEW,FT_CLASS,SAME,"meter",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00195 loads = gl_find_objects(FL_NEW,FT_CLASS,SAME,"load",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"powerflow",FT_END);
00196
00197 inverters = gl_find_objects(FL_NEW,FT_CLASS,SAME,"inverter",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"generators",FT_END);
00198 diesels = gl_find_objects(FL_NEW,FT_CLASS,SAME,"diesel_dg",AND,FT_GROUPID,SAME,group.get_string(),AND,FT_MODULE,SAME,"generators",FT_END);
00199 }
00200
00201 if ((ohlines->hit_count==0) && (tplines->hit_count==0) && (uglines->hit_count==0) && (nodes->hit_count==0) && (meters->hit_count==0) && (loads->hit_count==0))
00202 {
00203 gl_error("No line or bus objects were found.");
00204
00205
00206
00207
00208 return FAILED;
00209 }
00210
00211
00212 metrics_lines["$schema"] = "http://json-schema.org/draft-04/schema#";
00213 metrics_lines["description"] = "This file describes the system topology information (bus and lines) and line configuration data";
00214
00215
00216 if (lineConfs->hit_count > 0)
00217 {
00218
00219 pLineConf = (OBJECT **)gl_malloc((lineConfs->hit_count)*sizeof(OBJECT*));
00220
00221
00222 if (pLineConf == NULL)
00223 {
00224 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00225
00226
00227
00228
00229
00230 }
00231
00232
00233 b_mat_pu = (complex *)gl_malloc((lineConfs->hit_count)*9*sizeof(complex));
00234
00235
00236 if (b_mat_pu == NULL)
00237 {
00238 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00239
00240 }
00241
00242
00243 b_mat_defined = (bool *)gl_malloc((lineConfs->hit_count)*sizeof(bool));
00244
00245
00246 if (b_mat_defined == NULL)
00247 {
00248 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00249
00250 }
00251
00252
00253 for (indexA=0; indexA < (lineConfs->hit_count); indexA++)
00254 {
00255 pLineConf[indexA] = NULL;
00256 b_mat_defined[indexA] = false;
00257
00258 for (indexB=0; indexB<9; indexB++)
00259 {
00260 b_mat_pu[indexA*9+indexB] = complex(0.0,0.0);
00261 }
00262 }
00263
00264
00265 obj_lineConf = gl_find_next(lineConfs,NULL);
00266
00267
00268 index = 0;
00269
00270
00271 while (obj_lineConf != NULL)
00272 {
00273 pLineConf[index] = obj_lineConf;
00274
00275
00276 index++;
00277
00278
00279 obj_lineConf = gl_find_next(lineConfs,obj_lineConf);
00280 }
00281 }
00282 else
00283 {
00284 pLineConf = NULL;
00285 b_mat_defined = NULL;
00286 b_mat_pu = NULL;
00287 }
00288
00289
00290 if (tpLineConfs->hit_count > 0)
00291 {
00292 pTpLineConf = (OBJECT **)gl_malloc((tpLineConfs->hit_count)*sizeof(OBJECT*));
00293
00294
00295 if (pTpLineConf == NULL)
00296 {
00297 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00298
00299 }
00300
00301
00302 b_mat_tp_pu = (complex *)gl_malloc((tpLineConfs->hit_count)*9*sizeof(complex));
00303
00304
00305 if (b_mat_tp_pu == NULL)
00306 {
00307 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00308
00309 }
00310
00311
00312 b_mat_tp_defined = (bool *)gl_malloc((tpLineConfs->hit_count)*sizeof(bool));
00313
00314
00315 if (b_mat_tp_defined == NULL)
00316 {
00317 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00318
00319 }
00320
00321
00322
00323 for (indexA=0; indexA < (tpLineConfs->hit_count); indexA++)
00324 {
00325 pTpLineConf[indexA] = NULL;
00326 b_mat_tp_defined[indexA] = false;
00327
00328 for (indexB=0; indexB<9; indexB++)
00329 {
00330 b_mat_tp_pu[indexA*9+indexB] = complex(0.0,0.0);
00331 }
00332 }
00333
00334
00335 obj_lineConf = gl_find_next(tpLineConfs,NULL);
00336
00337
00338 index = 0;
00339
00340
00341 while (obj_lineConf != NULL)
00342 {
00343 pTpLineConf[index] = obj_lineConf;
00344
00345
00346 index++;
00347
00348
00349 obj_lineConf = gl_find_next(tpLineConfs,obj_lineConf);
00350 }
00351 }
00352 else
00353 {
00354 pTpLineConf = NULL;
00355 b_mat_tp_defined = NULL;
00356 b_mat_tp_pu = NULL;
00357 }
00358
00359
00360 if (TransConfsList->hit_count > 0)
00361 {
00362
00363
00364 pTransConf = (OBJECT **)gl_malloc((TransConfsList->hit_count)*sizeof(OBJECT*));
00365
00366
00367 if (pTransConf == NULL)
00368 {
00369 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00370
00371 }
00372
00373
00374 b_mat_trans_pu = (complex *)gl_malloc((TransConfsList->hit_count)*9*sizeof(complex));
00375
00376
00377 if (b_mat_trans_pu == NULL)
00378 {
00379 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00380
00381 }
00382
00383
00384 for (indexA=0; indexA < (TransConfsList->hit_count*9); indexA++)
00385 {
00386 b_mat_trans_pu[indexA] = complex(0.0,0.0);
00387 }
00388
00389
00390 b_mat_trans_defined = (bool *)gl_malloc((TransConfsList->hit_count)*sizeof(bool));
00391
00392
00393 if (b_mat_trans_defined == NULL)
00394 {
00395 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00396
00397 }
00398
00399
00400 for (indexA=0; indexA < (TransConfsList->hit_count); indexA++)
00401 {
00402 b_mat_trans_defined[indexA] = false;
00403 }
00404
00405
00406 trans_phase_count = (int *)gl_malloc((TransConfsList->hit_count)*sizeof(int));
00407
00408
00409 if (trans_phase_count == NULL)
00410 {
00411 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00412
00413 }
00414
00415
00416 for (indexA=0; indexA < (TransConfsList->hit_count); indexA++)
00417 {
00418 trans_phase_count[indexA] = 0;
00419 }
00420
00421
00422 obj_lineConf = gl_find_next(TransConfsList,NULL);
00423
00424 index=0;
00425 while(obj_lineConf != NULL)
00426 {
00427 pTransConf[index] = obj_lineConf;
00428 index++;
00429
00430
00431 obj_lineConf = gl_find_next(TransConfsList,obj_lineConf);
00432 }
00433 }
00434 else
00435 {
00436 pTransConf = NULL;
00437 b_mat_trans_pu = NULL;
00438 b_mat_trans_defined = NULL;
00439 trans_phase_count = NULL;
00440 }
00441
00442
00443 if (regConfs->hit_count > 0)
00444 {
00445
00446
00447 pRegConf = (OBJECT **)gl_malloc((regConfs->hit_count)*sizeof(OBJECT*));
00448
00449
00450 if (pRegConf == NULL)
00451 {
00452 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00453
00454 }
00455
00456
00457 b_mat_reg_pu = (complex *)gl_malloc((regConfs->hit_count)*9*sizeof(complex));
00458
00459
00460 if (b_mat_reg_pu == NULL)
00461 {
00462 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00463
00464 }
00465
00466
00467 for (indexA=0; indexA < (regConfs->hit_count*9); indexA++)
00468 {
00469 b_mat_reg_pu[indexA] = complex(0.0,0.0);
00470 }
00471
00472
00473 b_mat_reg_defined = (bool *)gl_malloc((regConfs->hit_count)*sizeof(bool));
00474
00475
00476 if (b_mat_reg_defined == NULL)
00477 {
00478 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00479
00480 }
00481
00482
00483 for (indexA=0; indexA < (regConfs->hit_count); indexA++)
00484 {
00485 b_mat_reg_defined[indexA] = false;
00486 }
00487
00488
00489 reg_phase_count = (int *)gl_malloc((regConfs->hit_count)*sizeof(int));
00490
00491
00492 if (reg_phase_count == NULL)
00493 {
00494 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
00495
00496 }
00497
00498
00499 for (indexA=0; indexA < (regConfs->hit_count); indexA++)
00500 {
00501 reg_phase_count[indexA] = 0;
00502 }
00503
00504
00505 obj_lineConf = gl_find_next(regConfs,NULL);
00506
00507 index=0;
00508 while(obj_lineConf != NULL)
00509 {
00510 pRegConf[index] = obj_lineConf;
00511 index++;
00512
00513
00514 obj_lineConf = gl_find_next(regConfs,obj_lineConf);
00515 }
00516 }
00517 else
00518 {
00519 pRegConf = NULL;
00520 b_mat_reg_pu = NULL;
00521 b_mat_reg_defined = NULL;
00522 reg_phase_count = NULL;
00523 }
00524
00525
00526 jsonArray.clear();
00527
00528
00529 node_object.clear();
00530
00531
00532 if (inverters->hit_count > 0)
00533 {
00534
00535 obj = gl_find_next(inverters,NULL);
00536
00537
00538 while (obj != NULL)
00539 {
00540
00541 if (obj->name != NULL)
00542 {
00543 node_object["id"] = obj->name;
00544 }
00545 else
00546 {
00547
00548 sprintf(buffer,"inverter:%d",obj->id);
00549 node_object["id"] = buffer;
00550 }
00551
00552
00553 if (obj->parent->name != NULL)
00554 {
00555 node_object["node_id"] = obj->parent->name;
00556 }
00557 else
00558 {
00559
00560 sprintf(buffer,"%s:%d",obj->parent->oclass->name,obj->parent->id);
00561 node_object["node_id"] = buffer;
00562 }
00563
00564
00565 temp_set_value = get_set_value(obj,"phases");
00566
00567
00568 jsonArray2.clear();
00569
00570
00571
00572 if ((temp_set_value & PHASE_A) == PHASE_A)
00573 {
00574 jsonArray2.append(true);
00575 }
00576 else
00577 {
00578 jsonArray2.append(false);
00579 }
00580
00581
00582 if ((temp_set_value & PHASE_B) == PHASE_B)
00583 {
00584 jsonArray2.append(true);
00585 }
00586 else
00587 {
00588 jsonArray2.append(false);
00589 }
00590
00591
00592 if ((temp_set_value & PHASE_C) == PHASE_C)
00593 {
00594 jsonArray2.append(true);
00595 }
00596 else
00597 {
00598 jsonArray2.append(false);
00599 }
00600
00601
00602 node_object["has_phase"] = jsonArray2;
00603 jsonArray2.clear();
00604
00605
00606 temp_complex_power_value[0] = get_complex_value(obj,"power_A");
00607 temp_complex_power_value[1] = get_complex_value(obj,"power_B");
00608 temp_complex_power_value[2] = get_complex_value(obj,"power_C");
00609
00610
00611 if (write_per_unit == true)
00612 {
00613 temp_complex_power_value[0] /= (system_VA_base / 3.0);
00614 temp_complex_power_value[1] /= (system_VA_base / 3.0);
00615 temp_complex_power_value[2] /= (system_VA_base / 3.0);
00616 }
00617
00618
00619 jsonArray2.append(temp_complex_power_value[0].Re());
00620 jsonArray2.append(temp_complex_power_value[1].Re());
00621 jsonArray2.append(temp_complex_power_value[2].Re());
00622
00623
00624 node_object["max_real_phase"] = jsonArray2;
00625
00626
00627 jsonArray2.clear();
00628
00629
00630
00631 jsonArray2.append(temp_complex_power_value[0].Im());
00632 jsonArray2.append(temp_complex_power_value[1].Im());
00633 jsonArray2.append(temp_complex_power_value[2].Im());
00634
00635
00636 node_object["max_reactive_phase"] = jsonArray2;
00637
00638
00639 jsonArray2.clear();
00640
00641
00642 node_object["microgrid_cost"] = 1.0e30;
00643 node_object["microgrid_fixed_cost"] = 0.0;
00644 node_object["max_microgrid"] = 0.0;
00645 node_object["is_new"] = false;
00646
00647
00648 jsonArray.append(node_object);
00649
00650
00651 node_object.clear();
00652
00653
00654 obj = gl_find_next(inverters,obj);
00655 }
00656 }
00657
00658
00659 if (diesels->hit_count > 0)
00660 {
00661
00662 obj = gl_find_next(diesels,NULL);
00663
00664
00665 while (obj != NULL)
00666 {
00667
00668 if (obj->name != NULL)
00669 {
00670 node_object["id"] = obj->name;
00671 }
00672 else
00673 {
00674
00675 sprintf(buffer,"diesel_dg:%d",obj->id);
00676 node_object["id"] = buffer;
00677 }
00678
00679
00680 if (obj->parent->name != NULL)
00681 {
00682 node_object["node_id"] = obj->parent->name;
00683 }
00684 else
00685 {
00686
00687 sprintf(buffer,"%s:%d",obj->parent->oclass->name,obj->parent->id);
00688 node_object["node_id"] = buffer;
00689 }
00690
00691
00692 temp_set_value = get_set_value(obj,"phases");
00693
00694
00695 jsonArray2.clear();
00696
00697
00698
00699 if ((temp_set_value & PHASE_A) == PHASE_A)
00700 {
00701 jsonArray2.append(true);
00702 }
00703 else
00704 {
00705 jsonArray2.append(false);
00706 }
00707
00708
00709 if ((temp_set_value & PHASE_B) == PHASE_B)
00710 {
00711 jsonArray2.append(true);
00712 }
00713 else
00714 {
00715 jsonArray2.append(false);
00716 }
00717
00718
00719 if ((temp_set_value & PHASE_C) == PHASE_C)
00720 {
00721 jsonArray2.append(true);
00722 }
00723 else
00724 {
00725 jsonArray2.append(false);
00726 }
00727
00728
00729 node_object["has_phase"] = jsonArray2;
00730 jsonArray2.clear();
00731
00732
00733 temp_complex_power_value[0] = get_complex_value(obj,"power_out_A");
00734 temp_complex_power_value[1] = get_complex_value(obj,"power_out_B");
00735 temp_complex_power_value[2] = get_complex_value(obj,"power_out_C");
00736
00737
00738 if (write_per_unit == true)
00739 {
00740 temp_complex_power_value[0] /= (system_VA_base / 3.0);
00741 temp_complex_power_value[1] /= (system_VA_base / 3.0);
00742 temp_complex_power_value[2] /= (system_VA_base / 3.0);
00743 }
00744
00745
00746 jsonArray2.append(temp_complex_power_value[0].Re());
00747 jsonArray2.append(temp_complex_power_value[1].Re());
00748 jsonArray2.append(temp_complex_power_value[2].Re());
00749
00750
00751 node_object["max_real_phase"] = jsonArray2;
00752
00753
00754 jsonArray2.clear();
00755
00756
00757
00758 jsonArray2.append(temp_complex_power_value[0].Im());
00759 jsonArray2.append(temp_complex_power_value[1].Im());
00760 jsonArray2.append(temp_complex_power_value[2].Im());
00761
00762
00763 node_object["max_reactive_phase"] = jsonArray2;
00764
00765
00766 jsonArray2.clear();
00767
00768
00769 node_object["microgrid_cost"] = 1.0e30;
00770 node_object["microgrid_fixed_cost"] = 0.0;
00771 node_object["max_microgrid"] = 0.0;
00772 node_object["is_new"] = false;
00773
00774
00775 jsonArray.append(node_object);
00776
00777
00778 node_object.clear();
00779
00780
00781 obj = gl_find_next(diesels,obj);
00782 }
00783 }
00784
00785
00786 metrics_lines["properties"]["generators"] = jsonArray;
00787
00788
00789 node_object.clear();
00790 jsonArray.clear();
00791
00792
00793 if (nodes->hit_count > 0)
00794 {
00795
00796 obj = gl_find_next(nodes,NULL);
00797
00798
00799 while (obj != NULL)
00800 {
00801
00802 if (write_per_unit == true)
00803 {
00804 temp_voltage_base = get_double_value(obj,"nominal_voltage");
00805 temp_de_pu_base = 1.0;
00806 }
00807 else
00808 {
00809 temp_voltage_base = 1.0;
00810 temp_de_pu_base = get_double_value(obj,"nominal_voltage");
00811 }
00812
00813
00814 if (obj->name != NULL)
00815 {
00816 node_object["id"] = obj->name;
00817 }
00818 else
00819 {
00820
00821 sprintf(buffer,"node:%d",obj->id);
00822 node_object["id"] = buffer;
00823 }
00824
00825
00826 node_object["min_voltage"] = min_volt_value * temp_de_pu_base;
00827 node_object["max_voltage"] = max_volt_value * temp_de_pu_base;
00828
00829
00830 temp_complex_voltage_value[0] = get_complex_value(obj,"voltage_A");
00831 temp_complex_voltage_value[1] = get_complex_value(obj,"voltage_B");
00832 temp_complex_voltage_value[2] = get_complex_value(obj,"voltage_C");
00833
00834
00835 jsonArray2.clear();
00836
00837 for (indexA=0; indexA<3; indexA++)
00838 {
00839
00840 temp_voltage_output_value = temp_complex_voltage_value[indexA].Mag() / temp_voltage_base;
00841
00842
00843 jsonArray2.append(temp_voltage_output_value);
00844 }
00845
00846
00847 node_object["ref_voltage"] = jsonArray2;
00848 jsonArray2.clear();
00849
00850
00851 temp_set_value = get_set_value(obj,"phases");
00852
00853
00854 jsonArray2.clear();
00855
00856
00857
00858 if ((temp_set_value & PHASE_A) == PHASE_A)
00859 {
00860 jsonArray2.append(true);
00861 }
00862 else
00863 {
00864 jsonArray2.append(false);
00865 }
00866
00867
00868 if ((temp_set_value & PHASE_B) == PHASE_B)
00869 {
00870 jsonArray2.append(true);
00871 }
00872 else
00873 {
00874 jsonArray2.append(false);
00875 }
00876
00877
00878 if ((temp_set_value & PHASE_C) == PHASE_C)
00879 {
00880 jsonArray2.append(true);
00881 }
00882 else
00883 {
00884 jsonArray2.append(false);
00885 }
00886
00887
00888 node_object["has_phase"] = jsonArray2;
00889 jsonArray2.clear();
00890
00891
00892 jsonArray.append(node_object);
00893
00894
00895 node_object.clear();
00896
00897
00898 obj = gl_find_next(nodes,obj);
00899
00900 }
00901 }
00902
00903
00904 if (meters->hit_count > 0)
00905 {
00906
00907 obj = gl_find_next(meters,NULL);
00908
00909
00910 while (obj != NULL)
00911 {
00912
00913 if (write_per_unit == true)
00914 {
00915 temp_voltage_base = get_double_value(obj,"nominal_voltage");
00916 temp_de_pu_base = 1.0;
00917 }
00918 else
00919 {
00920 temp_voltage_base = 1.0;
00921 temp_de_pu_base = get_double_value(obj,"nominal_voltage");
00922 }
00923
00924
00925 if (obj->name != NULL)
00926 {
00927 node_object["id"] = obj->name;
00928 }
00929 else
00930 {
00931
00932 sprintf(buffer,"meter:%d",obj->id);
00933 node_object["id"] = buffer;
00934 }
00935
00936
00937 node_object["min_voltage"] = min_volt_value * temp_de_pu_base;
00938 node_object["max_voltage"] = max_volt_value * temp_de_pu_base;
00939
00940
00941 temp_complex_voltage_value[0] = get_complex_value(obj,"voltage_A");
00942 temp_complex_voltage_value[1] = get_complex_value(obj,"voltage_B");
00943 temp_complex_voltage_value[2] = get_complex_value(obj,"voltage_C");
00944
00945
00946 jsonArray2.clear();
00947
00948 for (indexA=0; indexA<3; indexA++)
00949 {
00950
00951 temp_voltage_output_value = temp_complex_voltage_value[indexA].Mag() / temp_voltage_base;
00952
00953
00954 jsonArray2.append(temp_voltage_output_value);
00955 }
00956
00957
00958 node_object["ref_voltage"] = jsonArray2;
00959 jsonArray2.clear();
00960
00961
00962 temp_set_value = get_set_value(obj,"phases");
00963
00964
00965 jsonArray2.clear();
00966
00967
00968
00969 if ((temp_set_value & PHASE_A) == PHASE_A)
00970 {
00971 jsonArray2.append(true);
00972 }
00973 else
00974 {
00975 jsonArray2.append(false);
00976 }
00977
00978
00979 if ((temp_set_value & PHASE_B) == PHASE_B)
00980 {
00981 jsonArray2.append(true);
00982 }
00983 else
00984 {
00985 jsonArray2.append(false);
00986 }
00987
00988
00989 if ((temp_set_value & PHASE_C) == PHASE_C)
00990 {
00991 jsonArray2.append(true);
00992 }
00993 else
00994 {
00995 jsonArray2.append(false);
00996 }
00997
00998
00999 node_object["has_phase"] = jsonArray2;
01000 jsonArray2.clear();
01001
01002
01003 jsonArray.append(node_object);
01004
01005
01006 node_object.clear();
01007
01008
01009 obj = gl_find_next(meters,obj);
01010
01011 }
01012 }
01013
01014
01015 load_object.clear();
01016 jsonSecondArray.clear();
01017
01018
01019 if (loads->hit_count > 0)
01020 {
01021
01022 obj = gl_find_next(loads,NULL);
01023
01024
01025 while (obj != NULL)
01026 {
01027
01028 if (write_per_unit == true)
01029 {
01030 temp_voltage_base = get_double_value(obj,"nominal_voltage");
01031 temp_de_pu_base = 1.0;
01032 }
01033 else
01034 {
01035 temp_voltage_base = 1.0;
01036 temp_de_pu_base = get_double_value(obj,"nominal_voltage");
01037 }
01038
01039
01040 if (obj->name != NULL)
01041 {
01042 node_object["id"] = obj->name;
01043
01044
01045 load_object["node_id"] = obj->name;
01046
01047 sprintf(buffer,"load_%s",obj->name);
01048 load_object["id"] = buffer;
01049 }
01050 else
01051 {
01052
01053 sprintf(buffer,"load:%d",obj->id);
01054 node_object["id"] = buffer;
01055
01056
01057 load_object["node_id"] = buffer;
01058
01059 sprintf(buffer,"load_object_%d",obj->id);
01060 load_object["id"] = buffer;
01061 }
01062
01063
01064 temp_enum_value = get_enum_value(obj,"load_priority");
01065
01066
01067 if (temp_enum_value == 2)
01068 {
01069 load_object["is_critical"] = true;
01070 }
01071 else
01072 {
01073 load_object["is_critical"] = false;
01074 }
01075
01076
01077 node_object["min_voltage"] = min_volt_value * temp_de_pu_base;
01078 node_object["max_voltage"] = max_volt_value * temp_de_pu_base;
01079
01080
01081 temp_complex_voltage_value[0] = get_complex_value(obj,"voltage_A");
01082 temp_complex_voltage_value[1] = get_complex_value(obj,"voltage_B");
01083 temp_complex_voltage_value[2] = get_complex_value(obj,"voltage_C");
01084
01085
01086 jsonArray2.clear();
01087
01088 for (indexA=0; indexA<3; indexA++)
01089 {
01090
01091 temp_voltage_output_value = temp_complex_voltage_value[indexA].Mag() / temp_voltage_base;
01092
01093
01094 jsonArray2.append(temp_voltage_output_value);
01095 }
01096
01097
01098 node_object["ref_voltage"] = jsonArray2;
01099 jsonArray2.clear();
01100
01101
01102 temp_set_value = get_set_value(obj,"phases");
01103
01104
01105 jsonArray2.clear();
01106
01107
01108
01109 if ((temp_set_value & PHASE_A) == PHASE_A)
01110 {
01111 jsonArray2.append(true);
01112 }
01113 else
01114 {
01115 jsonArray2.append(false);
01116 }
01117
01118
01119 if ((temp_set_value & PHASE_B) == PHASE_B)
01120 {
01121 jsonArray2.append(true);
01122 }
01123 else
01124 {
01125 jsonArray2.append(false);
01126 }
01127
01128
01129 if ((temp_set_value & PHASE_C) == PHASE_C)
01130 {
01131 jsonArray2.append(true);
01132 }
01133 else
01134 {
01135 jsonArray2.append(false);
01136 }
01137
01138
01139 node_object["has_phase"] = jsonArray2;
01140 load_object["has_phase"] = jsonArray2;
01141 jsonArray2.clear();
01142
01143
01144 temp_complex_power_value[0] = get_complex_value(obj,"constant_power_A");
01145 temp_complex_power_value[1] = get_complex_value(obj,"constant_power_B");
01146 temp_complex_power_value[2] = get_complex_value(obj,"constant_power_C");
01147
01148
01149 if (write_per_unit == true)
01150 {
01151 temp_complex_power_value[0] /= (system_VA_base / 3.0);
01152 temp_complex_power_value[1] /= (system_VA_base / 3.0);
01153 temp_complex_power_value[2] /= (system_VA_base / 3.0);
01154 }
01155
01156
01157 jsonArray2.append(temp_complex_power_value[0].Re());
01158 jsonArray2.append(temp_complex_power_value[1].Re());
01159 jsonArray2.append(temp_complex_power_value[2].Re());
01160
01161
01162 load_object["max_real_phase"] = jsonArray2;
01163
01164
01165 jsonArray2.clear();
01166
01167
01168
01169 jsonArray2.append(temp_complex_power_value[0].Im());
01170 jsonArray2.append(temp_complex_power_value[1].Im());
01171 jsonArray2.append(temp_complex_power_value[2].Im());
01172
01173
01174 load_object["max_reactive_phase"] = jsonArray2;
01175
01176
01177 jsonArray2.clear();
01178
01179
01180 jsonArray.append(node_object);
01181
01182
01183 node_object.clear();
01184
01185
01186 jsonSecondArray.append(load_object);
01187
01188
01189 load_object.clear();
01190
01191
01192 obj = gl_find_next(loads,obj);
01193
01194 }
01195 }
01196
01197
01198 metrics_lines["properties"]["buses"] = jsonArray;
01199
01200
01201 jsonArray.clear();
01202
01203
01204
01205
01206 metrics_lines["properties"]["loads"] = jsonSecondArray;
01207
01208
01209 jsonSecondArray.clear();
01210
01211
01212 index = 0;
01213 line_object.clear();
01214
01215 if(TransformerList->hit_count > 0)
01216 {
01217
01218 pTransformer = (transformer **)gl_malloc(TransformerList->hit_count*sizeof(transformer*));
01219
01220
01221 if (pTransformer == NULL)
01222 {
01223 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
01224
01225 }
01226
01227
01228 obj = gl_find_next(TransformerList,NULL);
01229
01230
01231 index = 0;
01232
01233 while(obj != NULL)
01234 {
01235 if(index >= TransformerList->hit_count){
01236 break;
01237 }
01238
01239 pTransformer[index] = OBJECTDATA(obj,transformer);
01240 if(pTransformer[index] == NULL){
01241 gl_error("Unable to map object as transformer object.");
01242 return FAILED;
01243 }
01244
01245
01246
01247 if (obj->name != NULL)
01248 {
01249 line_object["id"] = obj->name;
01250 }
01251 else
01252 {
01253
01254 sprintf(buffer,"transformer:%d",obj->id);
01255 line_object["id"] = buffer;
01256 }
01257
01258
01259 if (pTransformer[index]->from->name != NULL)
01260 {
01261 line_object["node1_id"] = pTransformer[index]->from->name;
01262 }
01263 else
01264 {
01265
01266 sprintf(buffer,"%s:%d",pTransformer[index]->from->oclass->name,pTransformer[index]->from->id);
01267 line_object["node1_id"] = buffer;
01268 }
01269
01270
01271 if (pTransformer[index]->to->name != NULL)
01272 {
01273 line_object["node2_id"] = pTransformer[index]->to->name;
01274 }
01275 else
01276 {
01277
01278 sprintf(buffer,"%s:%d",pTransformer[index]->to->oclass->name,pTransformer[index]->to->id);
01279 line_object["node2_id"] = buffer;
01280 }
01281
01282
01283 temp_set_value = get_set_value(obj,"phases");
01284
01285
01286 jsonArray2.clear();
01287
01288
01289
01290 phaseCount = 0;
01291
01292 if ((temp_set_value & PHASE_A) == PHASE_A)
01293 {
01294 jsonArray2.append(true);
01295 phaseCount++;
01296 }
01297 else
01298 {
01299 jsonArray2.append(false);
01300 }
01301
01302
01303 if ((temp_set_value & PHASE_B) == PHASE_B)
01304 {
01305 jsonArray2.append(true);
01306 phaseCount++;
01307 }
01308 else
01309 {
01310 jsonArray2.append(false);
01311 }
01312
01313
01314 if ((temp_set_value & PHASE_C) == PHASE_C)
01315 {
01316 jsonArray2.append(true);
01317 phaseCount++;
01318 }
01319 else
01320 {
01321 jsonArray2.append(false);
01322 }
01323
01324
01325 line_object["has_phase"] = jsonArray2;
01326 jsonArray2.clear();
01327
01328
01329 line_object["capacity"] = 1e30;
01330
01331
01332 line_object["length"] = 1.0;
01333
01334
01335 line_object["num_phases"] = phaseCount;
01336
01337
01338 line_object["is_transformer"] = true;
01339
01340
01341 if (write_per_unit == true)
01342 {
01343
01344 per_unit_base = get_double_value(pTransformer[index]->to,"nominal_voltage");
01345
01346
01347 temp_impedance_base = (per_unit_base * per_unit_base) / (system_VA_base / 3.0);
01348 }
01349 else
01350 {
01351 temp_impedance_base = 1.0;
01352 }
01353
01354
01355 found_match_config = false;
01356 for (indexA=0; indexA<TransConfsList->hit_count; indexA++)
01357 {
01358
01359 if (pTransformer[index]->configuration == pTransConf[indexA])
01360 {
01361 found_match_config = true;
01362 break;
01363 }
01364 }
01365
01366
01367 if (found_match_config == true)
01368 {
01369 if (b_mat_trans_defined[indexA] != true)
01370 {
01371 for (indexB = 0; indexB < 3; indexB++)
01372 {
01373 for (indexC = 0; indexC < 3; indexC++)
01374 {
01375 b_mat_trans_pu[indexA*9+indexB*3+indexC] = pTransformer[index]->b_mat[indexB][indexC]/temp_impedance_base;
01376 }
01377 }
01378 trans_phase_count[indexA] = phaseCount;
01379 b_mat_trans_defined[indexA] = true;
01380 }
01381 }
01382
01383
01384 if (pTransformer[index]->configuration->name == NULL)
01385 {
01386 sprintf(buffer,"trans_config:%d",pTransformer[index]->configuration->id);
01387 line_object["line_code"] = buffer;
01388 }
01389 else
01390 {
01391 line_object["line_code"] = pTransformer[index]->configuration->name;
01392 }
01393
01394
01395 line_object["construction_cost"] = 1e30;
01396
01397 line_object["harden_cost"] = 1e30;
01398
01399 line_object["switch_cost"] = 1e30;
01400
01401 line_object["is_new"] = false;
01402
01403 line_object["can_harden"] = false;
01404
01405 line_object["can_add_switch"] = false;
01406
01407 line_object["has_switch"] = false;
01408
01409
01410
01411 jsonArray.append(line_object);
01412
01413
01414 line_object.clear();
01415
01416
01417 obj = gl_find_next(TransformerList,obj);
01418
01419 index++;
01420 }
01421 }
01422
01423
01424 if(regulators->hit_count > 0)
01425 {
01426
01427 pRegulator = (regulator **)gl_malloc(regulators->hit_count*sizeof(regulator*));
01428
01429
01430 if (pRegulator == NULL)
01431 {
01432 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
01433
01434 }
01435
01436
01437 obj = gl_find_next(regulators,NULL);
01438
01439
01440 index = 0;
01441
01442 while(obj != NULL)
01443 {
01444 if(index >= regulators->hit_count){
01445 break;
01446 }
01447
01448 pRegulator[index] = OBJECTDATA(obj,regulator);
01449 if(pRegulator[index] == NULL){
01450 gl_error("Unable to map object as regulator object.");
01451 return FAILED;
01452 }
01453
01454
01455
01456 if (obj->name != NULL)
01457 {
01458 line_object["id"] = obj->name;
01459 }
01460 else
01461 {
01462
01463 sprintf(buffer,"regulator:%d",obj->id);
01464 line_object["id"] = buffer;
01465 }
01466
01467
01468 if (pRegulator[index]->from->name != NULL)
01469 {
01470 line_object["node1_id"] = pRegulator[index]->from->name;
01471 }
01472 else
01473 {
01474
01475 sprintf(buffer,"%s:%d",pRegulator[index]->from->oclass->name,pRegulator[index]->from->id);
01476 line_object["node1_id"] = buffer;
01477 }
01478
01479
01480 if (pRegulator[index]->to->name != NULL)
01481 {
01482 line_object["node2_id"] = pRegulator[index]->to->name;
01483 }
01484 else
01485 {
01486
01487 sprintf(buffer,"%s:%d",pRegulator[index]->to->oclass->name,pRegulator[index]->to->id);
01488 line_object["node2_id"] = buffer;
01489 }
01490
01491
01492 temp_set_value = get_set_value(obj,"phases");
01493
01494
01495 jsonArray2.clear();
01496
01497
01498
01499 phaseCount = 0;
01500
01501 if ((temp_set_value & PHASE_A) == PHASE_A)
01502 {
01503 jsonArray2.append(true);
01504 phaseCount++;
01505 }
01506 else
01507 {
01508 jsonArray2.append(false);
01509 }
01510
01511
01512 if ((temp_set_value & PHASE_B) == PHASE_B)
01513 {
01514 jsonArray2.append(true);
01515 phaseCount++;
01516 }
01517 else
01518 {
01519 jsonArray2.append(false);
01520 }
01521
01522
01523 if ((temp_set_value & PHASE_C) == PHASE_C)
01524 {
01525 jsonArray2.append(true);
01526 phaseCount++;
01527 }
01528 else
01529 {
01530 jsonArray2.append(false);
01531 }
01532
01533
01534 line_object["has_phase"] = jsonArray2;
01535 jsonArray2.clear();
01536
01537
01538 line_object["capacity"] = 1e30;
01539
01540
01541 line_object["length"] = 1.0;
01542
01543
01544 line_object["num_phases"] = phaseCount;
01545
01546
01547 line_object["is_transformer"] = true;
01548
01549
01550 if (write_per_unit == true)
01551 {
01552
01553 per_unit_base = get_double_value(pRegulator[index]->to,"nominal_voltage");
01554
01555
01556 temp_impedance_base = (per_unit_base * per_unit_base) / (system_VA_base / 3.0);
01557 }
01558 else
01559 {
01560 temp_impedance_base = 1.0;
01561 }
01562
01563
01564 found_match_config = false;
01565 for (indexA=0; indexA<regConfs->hit_count; indexA++)
01566 {
01567
01568 if (pRegulator[index]->configuration == pRegConf[indexA])
01569 {
01570 found_match_config = true;
01571 break;
01572 }
01573 }
01574
01575
01576 if (found_match_config == true)
01577 {
01578 if (b_mat_reg_defined[indexA] != true)
01579 {
01580 for (indexB = 0; indexB < 3; indexB++)
01581 {
01582 for (indexC = 0; indexC < 3; indexC++)
01583 {
01584 b_mat_reg_pu[indexA*9+indexB*3+indexC] = pRegulator[index]->b_mat[indexB][indexC]/temp_impedance_base;
01585 }
01586 }
01587 reg_phase_count[indexA] = phaseCount;
01588 b_mat_reg_defined[indexA] = true;
01589 }
01590 }
01591
01592
01593 if (pRegulator[index]->configuration->name == NULL)
01594 {
01595 sprintf(buffer,"reg_config:%d",pRegulator[index]->configuration->id);
01596 line_object["line_code"] = buffer;
01597 }
01598 else
01599 {
01600 line_object["line_code"] = pRegulator[index]->configuration->name;
01601 }
01602
01603
01604 line_object["construction_cost"] = 1e30;
01605
01606 line_object["harden_cost"] = 1e30;
01607
01608 line_object["switch_cost"] = 1e30;
01609
01610 line_object["is_new"] = false;
01611
01612 line_object["can_harden"] = false;
01613
01614 line_object["can_add_switch"] = false;
01615
01616 line_object["has_switch"] = false;
01617
01618
01619
01620 jsonArray.append(line_object);
01621
01622
01623 line_object.clear();
01624
01625
01626 obj = gl_find_next(regulators,obj);
01627
01628 index++;
01629 }
01630 }
01631
01632
01633 if(ohlines->hit_count > 0)
01634 {
01635 pOhLine = (line **)gl_malloc(ohlines->hit_count*sizeof(line*));
01636
01637
01638 if (pOhLine == NULL)
01639 {
01640 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
01641
01642 }
01643
01644
01645 obj = gl_find_next(ohlines,NULL);
01646
01647
01648 index = 0;
01649
01650 while(obj != NULL)
01651 {
01652 if(index >= ohlines->hit_count){
01653 break;
01654 }
01655
01656 pOhLine[index] = OBJECTDATA(obj,line);
01657 if(pOhLine[index] == NULL){
01658 gl_error("Unable to map object as overhead_line object.");
01659 return FAILED;
01660 }
01661
01662
01663
01664 if (obj->name != NULL)
01665 {
01666 line_object["id"] = obj->name;
01667 }
01668 else
01669 {
01670
01671 sprintf(buffer,"overhead_line:%d",obj->id);
01672 line_object["id"] = buffer;
01673 }
01674
01675
01676 if (pOhLine[index]->from->name != NULL)
01677 {
01678 line_object["node1_id"] = pOhLine[index]->from->name;
01679 }
01680 else
01681 {
01682
01683 sprintf(buffer,"%s:%d",pOhLine[index]->from->oclass->name,pOhLine[index]->from->id);
01684 line_object["node1_id"] = buffer;
01685 }
01686
01687
01688 if (pOhLine[index]->to->name != NULL)
01689 {
01690 line_object["node2_id"] = pOhLine[index]->to->name;
01691 }
01692 else
01693 {
01694
01695 sprintf(buffer,"%s:%d",pOhLine[index]->to->oclass->name,pOhLine[index]->to->id);
01696 line_object["node2_id"] = buffer;
01697 }
01698
01699
01700 temp_set_value = get_set_value(obj,"phases");
01701
01702
01703 jsonArray2.clear();
01704
01705
01706
01707 phaseCount = 0;
01708
01709 if ((temp_set_value & PHASE_A) == PHASE_A)
01710 {
01711 jsonArray2.append(true);
01712 phaseCount++;
01713 }
01714 else
01715 {
01716 jsonArray2.append(false);
01717 }
01718
01719
01720 if ((temp_set_value & PHASE_B) == PHASE_B)
01721 {
01722 jsonArray2.append(true);
01723 phaseCount++;
01724 }
01725 else
01726 {
01727 jsonArray2.append(false);
01728 }
01729
01730
01731 if ((temp_set_value & PHASE_C) == PHASE_C)
01732 {
01733 jsonArray2.append(true);
01734 phaseCount++;
01735 }
01736 else
01737 {
01738 jsonArray2.append(false);
01739 }
01740
01741
01742 line_object["has_phase"] = jsonArray2;
01743 jsonArray2.clear();
01744
01745
01746 line_object["capacity"] = 1e30;
01747
01748
01749 line_object["length"] = pOhLine[index]->length;
01750
01751
01752 line_object["num_phases"] = phaseCount;
01753
01754
01755 line_object["is_transformer"] = false;
01756
01757
01758 if (write_per_unit == true)
01759 {
01760
01761 per_unit_base = get_double_value(pOhLine[index]->to,"nominal_voltage");
01762
01763
01764 temp_impedance_base = (per_unit_base * per_unit_base) / (system_VA_base / 3.0);
01765 }
01766 else
01767 {
01768 temp_impedance_base = 1.0;
01769 }
01770
01771
01772 found_match_config = false;
01773 for (indexA=0; indexA<lineConfs->hit_count; indexA++)
01774 {
01775
01776 if (pOhLine[index]->configuration == pLineConf[indexA])
01777 {
01778 found_match_config = true;
01779 break;
01780 }
01781 }
01782
01783
01784 if (found_match_config == true)
01785 {
01786 if (b_mat_defined[indexA] != true)
01787 {
01788 for (indexB = 0; indexB < 3; indexB++)
01789 {
01790 for (indexC = 0; indexC < 3; indexC++)
01791 {
01792 b_mat_pu[indexA*9+indexB*3+indexC] = (pOhLine[index]->b_mat[indexB][indexC])/(((pOhLine[index]->length)/5280.0)/temp_impedance_base);
01793 }
01794 }
01795 b_mat_defined[indexA] = true;
01796 }
01797 }
01798
01799
01800 if (pOhLine[index]->configuration->name == NULL)
01801 {
01802 sprintf(buffer,"line_config:%d",pOhLine[index]->configuration->id);
01803 line_object["line_code"] = buffer;
01804 }
01805 else
01806 {
01807 line_object["line_code"] = pOhLine[index]->configuration->name;
01808 }
01809
01810
01811 line_object["construction_cost"] = 1e30;
01812
01813 line_object["harden_cost"] = 1e30;
01814
01815 line_object["switch_cost"] = 1e30;
01816
01817 line_object["is_new"] = false;
01818
01819 line_object["can_harden"] = false;
01820
01821 line_object["can_add_switch"] = false;
01822
01823 line_object["has_switch"] = false;
01824
01825
01826
01827 jsonArray.append(line_object);
01828
01829
01830 line_object.clear();
01831
01832
01833 obj = gl_find_next(ohlines,obj);
01834
01835 index++;
01836 }
01837 }
01838
01839
01840 if(uglines->hit_count > 0)
01841 {
01842 pUgLine = (line **)gl_malloc(uglines->hit_count*sizeof(line*));
01843
01844
01845 if (pUgLine == NULL)
01846 {
01847 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
01848
01849 }
01850
01851
01852 obj = gl_find_next(uglines,NULL);
01853
01854
01855 index = 0;
01856
01857 while(obj != NULL)
01858 {
01859 if(index >= uglines->hit_count){
01860 break;
01861 }
01862
01863 pUgLine[index] = OBJECTDATA(obj,line);
01864 if(pUgLine[index] == NULL){
01865 gl_error("Unable to map object as underground_line object.");
01866 return FAILED;
01867 }
01868
01869
01870
01871 if (obj->name != NULL)
01872 {
01873 line_object["id"] = obj->name;
01874 }
01875 else
01876 {
01877
01878 sprintf(buffer,"underground_line:%d",obj->id);
01879 line_object["id"] = buffer;
01880 }
01881
01882
01883 if (pUgLine[index]->from->name != NULL)
01884 {
01885 line_object["node1_id"] = pUgLine[index]->from->name;
01886 }
01887 else
01888 {
01889
01890 sprintf(buffer,"%s:%d",pUgLine[index]->from->oclass->name,pUgLine[index]->from->id);
01891 line_object["node1_id"] = buffer;
01892 }
01893
01894
01895 if (pUgLine[index]->to->name != NULL)
01896 {
01897 line_object["node2_id"] = pUgLine[index]->to->name;
01898 }
01899 else
01900 {
01901
01902 sprintf(buffer,"%s:%d",pUgLine[index]->to->oclass->name,pUgLine[index]->to->id);
01903 line_object["node2_id"] = buffer;
01904 }
01905
01906
01907 temp_set_value = get_set_value(obj,"phases");
01908
01909
01910 jsonArray2.clear();
01911
01912
01913
01914 phaseCount = 0;
01915
01916 if ((temp_set_value & PHASE_A) == PHASE_A)
01917 {
01918 jsonArray2.append(true);
01919 phaseCount++;
01920 }
01921 else
01922 {
01923 jsonArray2.append(false);
01924 }
01925
01926
01927 if ((temp_set_value & PHASE_B) == PHASE_B)
01928 {
01929 jsonArray2.append(true);
01930 phaseCount++;
01931 }
01932 else
01933 {
01934 jsonArray2.append(false);
01935 }
01936
01937
01938 if ((temp_set_value & PHASE_C) == PHASE_C)
01939 {
01940 jsonArray2.append(true);
01941 phaseCount++;
01942 }
01943 else
01944 {
01945 jsonArray2.append(false);
01946 }
01947
01948
01949 line_object["has_phase"] = jsonArray2;
01950 jsonArray2.clear();
01951
01952
01953 line_object["capacity"] = 1e30;
01954
01955
01956 line_object["length"] = pUgLine[index]->length;
01957
01958
01959 line_object["num_phases"] = phaseCount;
01960
01961
01962 line_object["is_transformer"] = false;
01963
01964
01965 if (write_per_unit == true)
01966 {
01967
01968 per_unit_base = get_double_value(pUgLine[index]->to,"nominal_voltage");
01969
01970
01971 temp_impedance_base = (per_unit_base * per_unit_base) / (system_VA_base / 3.0);
01972 }
01973 else
01974 {
01975 temp_impedance_base = 1.0;
01976 }
01977
01978
01979 found_match_config = false;
01980 for (indexA=0; indexA<lineConfs->hit_count; indexA++)
01981 {
01982
01983 if (pUgLine[index]->configuration == pLineConf[indexA])
01984 {
01985 found_match_config = true;
01986 break;
01987 }
01988 }
01989
01990
01991 if (found_match_config == true)
01992 {
01993 if (b_mat_defined[indexA] != true)
01994 {
01995 for (indexB = 0; indexB < 3; indexB++)
01996 {
01997 for (indexC = 0; indexC < 3; indexC++)
01998 {
01999 b_mat_pu[indexA*9+indexB*3+indexC] = (pUgLine[index]->b_mat[indexB][indexC])/(((pUgLine[index]->length)/5280.0)/temp_impedance_base);
02000 }
02001 }
02002 b_mat_defined[indexA] = true;
02003 }
02004 }
02005
02006
02007 if (pUgLine[index]->configuration->name == NULL)
02008 {
02009 sprintf(buffer,"line_config:%d",pUgLine[index]->configuration->id);
02010 line_object["line_code"] = buffer;
02011 }
02012 else
02013 {
02014 line_object["line_code"] = pUgLine[index]->configuration->name;
02015 }
02016
02017
02018 line_object["construction_cost"] = 1e30;
02019
02020 line_object["harden_cost"] = 1e30;
02021
02022 line_object["switch_cost"] = 1e30;
02023
02024 line_object["is_new"] = false;
02025
02026 line_object["can_harden"] = false;
02027
02028 line_object["can_add_switch"] = false;
02029
02030 line_object["has_switch"] = false;
02031
02032
02033
02034 jsonArray.append(line_object);
02035
02036
02037 line_object.clear();
02038
02039
02040 obj = gl_find_next(uglines,obj);
02041
02042 index++;
02043 }
02044 }
02045
02046
02047 if(tplines->hit_count > 0)
02048 {
02049 pTpLine = (line **)gl_malloc(tplines->hit_count*sizeof(line*));
02050
02051
02052 if (pTpLine == NULL)
02053 {
02054 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
02055
02056 }
02057
02058
02059 obj = gl_find_next(tplines,NULL);
02060
02061
02062 index = 0;
02063
02064 while(obj != NULL)
02065 {
02066 if(index >= tplines->hit_count){
02067 break;
02068 }
02069
02070 pTpLine[index] = OBJECTDATA(obj,line);
02071 if(pTpLine[index] == NULL){
02072 gl_error("Unable to map object as triplex_line object.");
02073 return FAILED;
02074 }
02075
02076
02077
02078 if (obj->name != NULL)
02079 {
02080 line_object["id"] = obj->name;
02081 }
02082 else
02083 {
02084
02085 sprintf(buffer,"triplex_line:%d",obj->id);
02086 line_object["id"] = buffer;
02087 }
02088
02089
02090 if (pTpLine[index]->from->name != NULL)
02091 {
02092 line_object["node1_id"] = pTpLine[index]->from->name;
02093 }
02094 else
02095 {
02096
02097 sprintf(buffer,"%s:%d",pTpLine[index]->from->oclass->name,pTpLine[index]->from->id);
02098 line_object["node1_id"] = buffer;
02099 }
02100
02101
02102 if (pTpLine[index]->to->name != NULL)
02103 {
02104 line_object["node2_id"] = pTpLine[index]->to->name;
02105 }
02106 else
02107 {
02108
02109 sprintf(buffer,"%s:%d",pTpLine[index]->to->oclass->name,pTpLine[index]->to->id);
02110 line_object["node2_id"] = buffer;
02111 }
02112
02113
02114 temp_set_value = get_set_value(obj,"phases");
02115
02116
02117 jsonArray2.clear();
02118
02119
02120
02121 phaseCount = 0;
02122
02123 if ((temp_set_value & PHASE_A) == PHASE_A)
02124 {
02125 jsonArray2.append(true);
02126 phaseCount++;
02127 }
02128 else
02129 {
02130 jsonArray2.append(false);
02131 }
02132
02133
02134 if ((temp_set_value & PHASE_B) == PHASE_B)
02135 {
02136 jsonArray2.append(true);
02137 phaseCount++;
02138 }
02139 else
02140 {
02141 jsonArray2.append(false);
02142 }
02143
02144
02145 if ((temp_set_value & PHASE_C) == PHASE_C)
02146 {
02147 jsonArray2.append(true);
02148 phaseCount++;
02149 }
02150 else
02151 {
02152 jsonArray2.append(false);
02153 }
02154
02155
02156 line_object["has_phase"] = jsonArray2;
02157 jsonArray2.clear();
02158
02159
02160 line_object["capacity"] = 1e30;
02161
02162
02163 line_object["length"] = pTpLine[index]->length;
02164
02165
02166 line_object["num_phases"] = phaseCount;
02167
02168
02169 line_object["is_transformer"] = false;
02170
02171
02172 if (write_per_unit == true)
02173 {
02174
02175 per_unit_base = get_double_value(pTpLine[index]->to,"nominal_voltage");
02176
02177
02178 temp_impedance_base = (per_unit_base * per_unit_base) / (system_VA_base / 3.0);
02179 }
02180 else
02181 {
02182 temp_impedance_base = 1.0;
02183 }
02184
02185
02186 found_match_config = false;
02187 for (indexA=0; indexA<lineConfs->hit_count; indexA++)
02188 {
02189
02190 if (pTpLine[index]->configuration == pTpLineConf[indexA])
02191 {
02192 found_match_config = true;
02193 break;
02194 }
02195 }
02196
02197
02198 if (found_match_config == true)
02199 {
02200 if (b_mat_tp_defined[indexA] != true)
02201 {
02202 for (indexB = 0; indexB < 3; indexB++)
02203 {
02204 for (indexC = 0; indexC < 3; indexC++)
02205 {
02206 b_mat_tp_pu[indexA*9+indexB*3+indexC] = (pTpLine[index]->b_mat[indexB][indexC])/(((pTpLine[index]->length)/5280.0)/temp_impedance_base);
02207 }
02208 }
02209 b_mat_tp_defined[indexA] = true;
02210 }
02211 }
02212
02213
02214 if (pTpLine[index]->configuration->name == NULL)
02215 {
02216 sprintf(buffer,"line_config:%d",pTpLine[index]->configuration->id);
02217 line_object["line_code"] = buffer;
02218 }
02219 else
02220 {
02221 line_object["line_code"] = pTpLine[index]->configuration->name;
02222 }
02223
02224
02225 line_object["construction_cost"] = 1e30;
02226
02227 line_object["harden_cost"] = 1e30;
02228
02229 line_object["switch_cost"] = 1e30;
02230
02231 line_object["is_new"] = false;
02232
02233 line_object["can_harden"] = false;
02234
02235 line_object["can_add_switch"] = false;
02236
02237 line_object["has_switch"] = false;
02238
02239
02240
02241 jsonArray.append(line_object);
02242
02243
02244 line_object.clear();
02245
02246
02247 obj = gl_find_next(tplines,obj);
02248
02249 index++;
02250 }
02251 }
02252
02253
02254 b_mat_switch_defined = false;
02255
02256
02257 if(switches->hit_count > 0)
02258 {
02259
02260
02261 pSwitch = (switch_object **)gl_malloc(switches->hit_count*sizeof(switch_object*));
02262
02263
02264 if (pSwitch == NULL)
02265 {
02266 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
02267
02268 }
02269
02270
02271 obj = gl_find_next(switches,NULL);
02272
02273
02274 index = 0;
02275
02276 while(obj != NULL)
02277 {
02278 if(index >= switches->hit_count){
02279 break;
02280 }
02281
02282 pSwitch[index] = OBJECTDATA(obj,switch_object);
02283 if(pSwitch[index] == NULL){
02284 gl_error("Unable to map object as switch object.");
02285 return FAILED;
02286 }
02287
02288
02289
02290 if (obj->name != NULL)
02291 {
02292 line_object["id"] = obj->name;
02293 }
02294 else
02295 {
02296
02297 sprintf(buffer,"switch:%d",obj->id);
02298 line_object["id"] = buffer;
02299 }
02300
02301
02302 if (pSwitch[index]->from->name != NULL)
02303 {
02304 line_object["node1_id"] = pSwitch[index]->from->name;
02305 }
02306 else
02307 {
02308
02309 sprintf(buffer,"%s:%d",pSwitch[index]->from->oclass->name,pSwitch[index]->from->id);
02310 line_object["node1_id"] = buffer;
02311 }
02312
02313
02314 if (pSwitch[index]->to->name != NULL)
02315 {
02316 line_object["node2_id"] = pSwitch[index]->to->name;
02317 }
02318 else
02319 {
02320
02321 sprintf(buffer,"%s:%d",pSwitch[index]->to->oclass->name,pSwitch[index]->to->id);
02322 line_object["node2_id"] = buffer;
02323 }
02324
02325
02326 temp_set_value = get_set_value(obj,"phases");
02327
02328
02329 jsonArray2.clear();
02330
02331
02332
02333 phaseCount = 0;
02334
02335 if ((temp_set_value & PHASE_A) == PHASE_A)
02336 {
02337 jsonArray2.append(true);
02338 phaseCount++;
02339 }
02340 else
02341 {
02342 jsonArray2.append(false);
02343 }
02344
02345
02346 if ((temp_set_value & PHASE_B) == PHASE_B)
02347 {
02348 jsonArray2.append(true);
02349 phaseCount++;
02350 }
02351 else
02352 {
02353 jsonArray2.append(false);
02354 }
02355
02356
02357 if ((temp_set_value & PHASE_C) == PHASE_C)
02358 {
02359 jsonArray2.append(true);
02360 phaseCount++;
02361 }
02362 else
02363 {
02364 jsonArray2.append(false);
02365 }
02366
02367
02368 line_object["has_phase"] = jsonArray2;
02369 jsonArray2.clear();
02370
02371
02372 line_object["capacity"] = 1e30;
02373
02374
02375 line_object["length"] = 1.0;
02376
02377
02378 line_object["num_phases"] = phaseCount;
02379
02380
02381 line_object["is_transformer"] = false;
02382
02383
02384 if (write_per_unit == true)
02385 {
02386
02387 per_unit_base = get_double_value(pSwitch[index]->to,"nominal_voltage");
02388
02389
02390 temp_impedance_base = (per_unit_base * per_unit_base) / (system_VA_base / 3.0);
02391 }
02392 else
02393 {
02394 temp_impedance_base = 1.0;
02395 }
02396
02397
02398 if (b_mat_switch_defined==false)
02399 {
02400 for (indexB = 0; indexB < 3; indexB++)
02401 {
02402 for (indexC = 0; indexC < 3; indexC++)
02403 {
02404 b_mat_switch_pu[indexB*3+indexC] = pSwitch[index]->b_mat[indexB][indexC]/temp_impedance_base;
02405 }
02406 }
02407 b_mat_switch_defined = true;
02408 switch_phase_count = phaseCount;
02409 }
02410
02411
02412 line_object["line_code"] = "switch_config";
02413
02414
02415 line_object["construction_cost"] = 1e30;
02416
02417 line_object["harden_cost"] = 1e30;
02418
02419 line_object["switch_cost"] = 1e30;
02420
02421 line_object["is_new"] = false;
02422
02423 line_object["can_harden"] = false;
02424
02425 line_object["can_add_switch"] = false;
02426
02427 line_object["has_switch"] = true;
02428
02429
02430
02431 jsonArray.append(line_object);
02432
02433
02434 line_object.clear();
02435
02436
02437 obj = gl_find_next(switches,obj);
02438
02439 index++;
02440 }
02441 }
02442
02443
02444 if(sectionalizers->hit_count > 0)
02445 {
02446
02447 pSectionalizer = (sectionalizer **)gl_malloc(sectionalizers->hit_count*sizeof(sectionalizer*));
02448
02449
02450 if (pSectionalizer == NULL)
02451 {
02452 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
02453
02454 }
02455
02456
02457 obj = gl_find_next(sectionalizers,NULL);
02458
02459
02460 index = 0;
02461
02462 while(obj != NULL)
02463 {
02464 if(index >= sectionalizers->hit_count){
02465 break;
02466 }
02467
02468 pSectionalizer[index] = OBJECTDATA(obj,sectionalizer);
02469 if(pSectionalizer[index] == NULL){
02470 gl_error("Unable to map object as sectionalizer object.");
02471 return FAILED;
02472 }
02473
02474
02475
02476 if (obj->name != NULL)
02477 {
02478 line_object["id"] = obj->name;
02479 }
02480 else
02481 {
02482
02483 sprintf(buffer,"sectionalizer:%d",obj->id);
02484 line_object["id"] = buffer;
02485 }
02486
02487
02488 if (pSectionalizer[index]->from->name != NULL)
02489 {
02490 line_object["node1_id"] = pSectionalizer[index]->from->name;
02491 }
02492 else
02493 {
02494
02495 sprintf(buffer,"%s:%d",pSectionalizer[index]->from->oclass->name,pSectionalizer[index]->from->id);
02496 line_object["node1_id"] = buffer;
02497 }
02498
02499
02500 if (pSectionalizer[index]->to->name != NULL)
02501 {
02502 line_object["node2_id"] = pSectionalizer[index]->to->name;
02503 }
02504 else
02505 {
02506
02507 sprintf(buffer,"%s:%d",pSectionalizer[index]->to->oclass->name,pSectionalizer[index]->to->id);
02508 line_object["node2_id"] = buffer;
02509 }
02510
02511
02512 temp_set_value = get_set_value(obj,"phases");
02513
02514
02515 jsonArray2.clear();
02516
02517
02518
02519 phaseCount = 0;
02520
02521 if ((temp_set_value & PHASE_A) == PHASE_A)
02522 {
02523 jsonArray2.append(true);
02524 phaseCount++;
02525 }
02526 else
02527 {
02528 jsonArray2.append(false);
02529 }
02530
02531
02532 if ((temp_set_value & PHASE_B) == PHASE_B)
02533 {
02534 jsonArray2.append(true);
02535 phaseCount++;
02536 }
02537 else
02538 {
02539 jsonArray2.append(false);
02540 }
02541
02542
02543 if ((temp_set_value & PHASE_C) == PHASE_C)
02544 {
02545 jsonArray2.append(true);
02546 phaseCount++;
02547 }
02548 else
02549 {
02550 jsonArray2.append(false);
02551 }
02552
02553
02554 line_object["has_phase"] = jsonArray2;
02555 jsonArray2.clear();
02556
02557
02558 line_object["capacity"] = 1e30;
02559
02560
02561 line_object["length"] = 1.0;
02562
02563
02564 line_object["num_phases"] = phaseCount;
02565
02566
02567 line_object["is_transformer"] = false;
02568
02569
02570 if (write_per_unit == true)
02571 {
02572
02573 per_unit_base = get_double_value(pSectionalizer[index]->to,"nominal_voltage");
02574
02575
02576 temp_impedance_base = (per_unit_base * per_unit_base) / (system_VA_base / 3.0);
02577 }
02578 else
02579 {
02580 temp_impedance_base = 1.0;
02581 }
02582
02583
02584 if (b_mat_switch_defined==false)
02585 {
02586 for (indexB = 0; indexB < 3; indexB++)
02587 {
02588 for (indexC = 0; indexC < 3; indexC++)
02589 {
02590 b_mat_switch_pu[indexB*3+indexC] = pSectionalizer[index]->b_mat[indexB][indexC]/temp_impedance_base;
02591 }
02592 }
02593 b_mat_switch_defined = true;
02594 switch_phase_count = phaseCount;
02595 }
02596
02597
02598 line_object["line_code"] = "switch_config";
02599
02600
02601 line_object["construction_cost"] = 1e30;
02602
02603 line_object["harden_cost"] = 1e30;
02604
02605 line_object["switch_cost"] = 1e30;
02606
02607 line_object["is_new"] = false;
02608
02609 line_object["can_harden"] = false;
02610
02611 line_object["can_add_switch"] = false;
02612
02613 line_object["has_switch"] = true;
02614
02615
02616
02617 jsonArray.append(line_object);
02618
02619
02620 line_object.clear();
02621
02622
02623 obj = gl_find_next(sectionalizers,obj);
02624
02625 index++;
02626 }
02627 }
02628
02629
02630 if(reclosers->hit_count > 0)
02631 {
02632
02633
02634 pRecloser = (recloser **)gl_malloc(reclosers->hit_count*sizeof(recloser*));
02635
02636
02637 if (pRecloser == NULL)
02638 {
02639 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
02640
02641 }
02642
02643
02644 obj = gl_find_next(reclosers,NULL);
02645
02646
02647 index = 0;
02648
02649 while(obj != NULL)
02650 {
02651 if(index >= reclosers->hit_count){
02652 break;
02653 }
02654
02655 pRecloser[index] = OBJECTDATA(obj,recloser);
02656 if(pRecloser[index] == NULL){
02657 gl_error("Unable to map object as recloser object.");
02658 return FAILED;
02659 }
02660
02661
02662
02663 if (obj->name != NULL)
02664 {
02665 line_object["id"] = obj->name;
02666 }
02667 else
02668 {
02669
02670 sprintf(buffer,"recloser:%d",obj->id);
02671 line_object["id"] = buffer;
02672 }
02673
02674
02675 if (pRecloser[index]->from->name != NULL)
02676 {
02677 line_object["node1_id"] = pRecloser[index]->from->name;
02678 }
02679 else
02680 {
02681
02682 sprintf(buffer,"%s:%d",pRecloser[index]->from->oclass->name,pRecloser[index]->from->id);
02683 line_object["node1_id"] = buffer;
02684 }
02685
02686
02687 if (pRecloser[index]->to->name != NULL)
02688 {
02689 line_object["node2_id"] = pRecloser[index]->to->name;
02690 }
02691 else
02692 {
02693
02694 sprintf(buffer,"%s:%d",pRecloser[index]->to->oclass->name,pRecloser[index]->to->id);
02695 line_object["node2_id"] = buffer;
02696 }
02697
02698
02699 temp_set_value = get_set_value(obj,"phases");
02700
02701
02702 jsonArray2.clear();
02703
02704
02705
02706 phaseCount = 0;
02707
02708 if ((temp_set_value & PHASE_A) == PHASE_A)
02709 {
02710 jsonArray2.append(true);
02711 phaseCount++;
02712 }
02713 else
02714 {
02715 jsonArray2.append(false);
02716 }
02717
02718
02719 if ((temp_set_value & PHASE_B) == PHASE_B)
02720 {
02721 jsonArray2.append(true);
02722 phaseCount++;
02723 }
02724 else
02725 {
02726 jsonArray2.append(false);
02727 }
02728
02729
02730 if ((temp_set_value & PHASE_C) == PHASE_C)
02731 {
02732 jsonArray2.append(true);
02733 phaseCount++;
02734 }
02735 else
02736 {
02737 jsonArray2.append(false);
02738 }
02739
02740
02741 line_object["has_phase"] = jsonArray2;
02742 jsonArray2.clear();
02743
02744
02745 line_object["capacity"] = 1e30;
02746
02747
02748 line_object["length"] = 1.0;
02749
02750
02751 line_object["num_phases"] = phaseCount;
02752
02753
02754 line_object["is_transformer"] = false;
02755
02756
02757 if (write_per_unit == true)
02758 {
02759
02760 per_unit_base = get_double_value(pRecloser[index]->to,"nominal_voltage");
02761
02762
02763 temp_impedance_base = (per_unit_base * per_unit_base) / (system_VA_base / 3.0);
02764 }
02765 else
02766 {
02767 temp_impedance_base = 1.0;
02768 }
02769
02770
02771 if (b_mat_switch_defined==false)
02772 {
02773 for (indexB = 0; indexB < 3; indexB++)
02774 {
02775 for (indexC = 0; indexC < 3; indexC++)
02776 {
02777 b_mat_switch_pu[indexB*3+indexC] = pRecloser[index]->b_mat[indexB][indexC]/temp_impedance_base;
02778 }
02779 }
02780 b_mat_switch_defined = true;
02781 switch_phase_count = phaseCount;
02782 }
02783
02784
02785 line_object["line_code"] = "switch_config";
02786
02787
02788 line_object["construction_cost"] = 1e30;
02789
02790 line_object["harden_cost"] = 1e30;
02791
02792 line_object["switch_cost"] = 1e30;
02793
02794 line_object["is_new"] = false;
02795
02796 line_object["can_harden"] = false;
02797
02798 line_object["can_add_switch"] = false;
02799
02800 line_object["has_switch"] = true;
02801
02802
02803
02804 jsonArray.append(line_object);
02805
02806
02807 line_object.clear();
02808
02809
02810 obj = gl_find_next(reclosers,obj);
02811
02812 index++;
02813 }
02814 }
02815
02816
02817 b_mat_fuse_defined = false;
02818
02819
02820 if(fuses->hit_count > 0)
02821 {
02822
02823
02824 pFuse = (fuse **)gl_malloc(fuses->hit_count*sizeof(fuse*));
02825
02826
02827 if (pFuse == NULL)
02828 {
02829 GL_THROW("jsdondump:%d %s - Unable to allocate memory",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"));
02830
02831 }
02832
02833
02834 obj = gl_find_next(fuses,NULL);
02835
02836
02837 index = 0;
02838
02839 while(obj != NULL)
02840 {
02841 if(index >= fuses->hit_count){
02842 break;
02843 }
02844
02845 pFuse[index] = OBJECTDATA(obj,fuse);
02846 if(pFuse[index] == NULL){
02847 gl_error("Unable to map object as fuse object.");
02848 return FAILED;
02849 }
02850
02851
02852
02853 if (obj->name != NULL)
02854 {
02855 line_object["id"] = obj->name;
02856 }
02857 else
02858 {
02859
02860 sprintf(buffer,"fuse:%d",obj->id);
02861 line_object["id"] = buffer;
02862 }
02863
02864
02865 if (pFuse[index]->from->name != NULL)
02866 {
02867 line_object["node1_id"] = pFuse[index]->from->name;
02868 }
02869 else
02870 {
02871
02872 sprintf(buffer,"%s:%d",pFuse[index]->from->oclass->name,pFuse[index]->from->id);
02873 line_object["node1_id"] = buffer;
02874 }
02875
02876
02877 if (pFuse[index]->to->name != NULL)
02878 {
02879 line_object["node2_id"] = pFuse[index]->to->name;
02880 }
02881 else
02882 {
02883
02884 sprintf(buffer,"%s:%d",pFuse[index]->to->oclass->name,pFuse[index]->to->id);
02885 line_object["node2_id"] = buffer;
02886 }
02887
02888
02889 temp_set_value = get_set_value(obj,"phases");
02890
02891
02892 jsonArray2.clear();
02893
02894
02895
02896 phaseCount = 0;
02897
02898 if ((temp_set_value & PHASE_A) == PHASE_A)
02899 {
02900 jsonArray2.append(true);
02901 phaseCount++;
02902 }
02903 else
02904 {
02905 jsonArray2.append(false);
02906 }
02907
02908
02909 if ((temp_set_value & PHASE_B) == PHASE_B)
02910 {
02911 jsonArray2.append(true);
02912 phaseCount++;
02913 }
02914 else
02915 {
02916 jsonArray2.append(false);
02917 }
02918
02919
02920 if ((temp_set_value & PHASE_C) == PHASE_C)
02921 {
02922 jsonArray2.append(true);
02923 phaseCount++;
02924 }
02925 else
02926 {
02927 jsonArray2.append(false);
02928 }
02929
02930
02931 line_object["has_phase"] = jsonArray2;
02932 jsonArray2.clear();
02933
02934
02935 line_object["capacity"] = 1e30;
02936
02937
02938 line_object["length"] = 1.0;
02939
02940
02941 line_object["num_phases"] = phaseCount;
02942
02943
02944 line_object["is_transformer"] = false;
02945
02946
02947 if (write_per_unit == true)
02948 {
02949
02950 per_unit_base = get_double_value(pFuse[index]->to,"nominal_voltage");
02951
02952
02953 temp_impedance_base = (per_unit_base * per_unit_base) / (system_VA_base / 3.0);
02954 }
02955 else
02956 {
02957 temp_impedance_base = 1.0;
02958 }
02959
02960
02961 if (b_mat_fuse_defined==false)
02962 {
02963 for (indexB = 0; indexB < 3; indexB++)
02964 {
02965 for (indexC = 0; indexC < 3; indexC++)
02966 {
02967 b_mat_fuse_pu[indexB*3+indexC] = pFuse[index]->b_mat[indexB][indexC]/temp_impedance_base;
02968 }
02969 }
02970 b_mat_fuse_defined = true;
02971 fuse_phase_count = phaseCount;
02972 }
02973
02974
02975 line_object["line_code"] = "fuse_config";
02976
02977
02978 line_object["construction_cost"] = 1e30;
02979
02980 line_object["harden_cost"] = 1e30;
02981
02982 line_object["switch_cost"] = 1e30;
02983
02984 line_object["is_new"] = false;
02985
02986 line_object["can_harden"] = false;
02987
02988 line_object["can_add_switch"] = false;
02989
02990 line_object["has_switch"] = true;
02991
02992
02993
02994 jsonArray.append(line_object);
02995
02996
02997 line_object.clear();
02998
02999
03000 obj = gl_find_next(fuses,obj);
03001
03002 index++;
03003 }
03004 }
03005
03006
03007 metrics_lines["properties"]["lines"] = jsonArray;
03008
03009
03010 jsonArray.clear();
03011
03012
03013 if (fuses->hit_count > 0)
03014 {
03015 line_configuration_object["line_code"] = "fuse_config";
03016
03017
03018 line_configuration_object["num_phases"] = fuse_phase_count;
03019
03020
03021 jsonArray1.clear();
03022 jsonArray2.clear();
03023
03024
03025 for (indexA = 0; indexA < 3; indexA++)
03026 {
03027 for (indexB = 0; indexB < 3; indexB++)
03028 {
03029 jsonArray1.append(b_mat_fuse_pu[indexA*3+indexB].Re());
03030 }
03031 jsonArray2.append(jsonArray1);
03032 jsonArray1.clear();
03033 }
03034 line_configuration_object["rmatrix"] = jsonArray2;
03035 jsonArray2.clear();
03036
03037
03038 for (indexA = 0; indexA < 3; indexA++)
03039 {
03040 for (indexB = 0; indexB < 3; indexB++)
03041 {
03042 jsonArray1.append(b_mat_fuse_pu[indexA*3+indexB].Im());
03043 }
03044 jsonArray2.append(jsonArray1);
03045 jsonArray1.clear();
03046 }
03047 line_configuration_object["xmatrix"] = jsonArray2;
03048 jsonArray2.clear();
03049
03050
03051
03052 jsonArray.append(line_configuration_object);
03053
03054
03055 line_configuration_object.clear();
03056 }
03057
03058
03059 if ((switches->hit_count > 0) || (reclosers->hit_count > 0) || (sectionalizers->hit_count > 0))
03060 {
03061 line_configuration_object["line_code"] = "switch_config";
03062
03063
03064 line_configuration_object["num_phases"] = switch_phase_count;
03065
03066
03067 jsonArray1.clear();
03068 jsonArray2.clear();
03069
03070
03071 for (indexA = 0; indexA < 3; indexA++)
03072 {
03073 for (indexB = 0; indexB < 3; indexB++)
03074 {
03075 jsonArray1.append(b_mat_switch_pu[indexA*3+indexB].Re());
03076 }
03077 jsonArray2.append(jsonArray1);
03078 jsonArray1.clear();
03079 }
03080 line_configuration_object["rmatrix"] = jsonArray2;
03081 jsonArray2.clear();
03082
03083
03084 for (indexA = 0; indexA < 3; indexA++)
03085 {
03086 for (indexB = 0; indexB < 3; indexB++)
03087 {
03088 jsonArray1.append(b_mat_switch_pu[indexA*3+indexB].Im());
03089 }
03090 jsonArray2.append(jsonArray1);
03091 jsonArray1.clear();
03092 }
03093 line_configuration_object["xmatrix"] = jsonArray2;
03094 jsonArray2.clear();
03095
03096
03097
03098 jsonArray.append(line_configuration_object);
03099
03100
03101 line_configuration_object.clear();
03102 }
03103
03104
03105
03106 if(lineConfs->hit_count > 0)
03107 {
03108
03109 for (index=0; index<lineConfs->hit_count; index++)
03110 {
03111
03112 if (b_mat_defined[index] == true)
03113 {
03114
03115
03116 if (pLineConf[index]->name == NULL)
03117 {
03118 sprintf(buffer,"line_config:%d",pLineConf[index]->id);
03119 line_configuration_object["line_code"] = buffer;
03120 }
03121 else
03122 {
03123 line_configuration_object["line_code"] = pLineConf[index]->name;
03124 }
03125
03126
03127 phaseCount = 0;
03128
03129 obj = get_object_value(pLineConf[index],"conductor_A");
03130
03131 if (obj != NULL)
03132 {
03133 phaseCount++;
03134 }
03135
03136 obj = get_object_value(pLineConf[index],"conductor_B");
03137
03138 if (obj != NULL)
03139 {
03140 phaseCount++;
03141 }
03142
03143 obj = get_object_value(pLineConf[index],"conductor_C");
03144
03145 if (obj != NULL)
03146 {
03147 phaseCount++;
03148 }
03149
03150 line_configuration_object["num_phases"] = phaseCount;
03151
03152
03153 jsonArray1.clear();
03154 jsonArray2.clear();
03155
03156
03157 for (indexA = 0; indexA < 3; indexA++)
03158 {
03159 for (indexB = 0; indexB < 3; indexB++)
03160 {
03161 jsonArray1.append(b_mat_pu[index*9+indexA*3+indexB].Re());
03162 }
03163 jsonArray2.append(jsonArray1);
03164 jsonArray1.clear();
03165 }
03166 line_configuration_object["rmatrix"] = jsonArray2;
03167 jsonArray2.clear();
03168
03169
03170 for (indexA = 0; indexA < 3; indexA++)
03171 {
03172 for (indexB = 0; indexB < 3; indexB++)
03173 {
03174 jsonArray1.append(b_mat_pu[index*9+indexA*3+indexB].Im());
03175 }
03176 jsonArray2.append(jsonArray1);
03177 jsonArray1.clear();
03178 }
03179 line_configuration_object["xmatrix"] = jsonArray2;
03180 jsonArray2.clear();
03181
03182
03183
03184 jsonArray.append(line_configuration_object);
03185
03186
03187 line_configuration_object.clear();
03188 }
03189 }
03190 }
03191
03192
03193 if(tpLineConfs->hit_count > 0 )
03194 {
03195
03196 for (index=0; index<tpLineConfs->hit_count; index++)
03197 {
03198
03199 if (b_mat_tp_defined[index] == true)
03200 {
03201
03202
03203 if (pTpLineConf[index]->name == NULL)
03204 {
03205 sprintf(buffer,"line_config:%d",pTpLineConf[index]->id);
03206 line_configuration_object["line_code"] = buffer;
03207 }
03208 else
03209 {
03210 line_configuration_object["line_code"] = pTpLineConf[index]->name;
03211 }
03212
03213
03214 phaseCount = 0;
03215
03216 obj = get_object_value(pTpLineConf[index],"conductor_1");
03217
03218 if (obj != NULL)
03219 {
03220 phaseCount++;
03221 }
03222
03223 obj = get_object_value(pTpLineConf[index],"conductor_2");
03224
03225 if (obj != NULL)
03226 {
03227 phaseCount++;
03228 }
03229
03230 line_configuration_object["num_phases"] = phaseCount;
03231
03232
03233 jsonArray1.clear();
03234 jsonArray2.clear();
03235
03236
03237 for (indexA = 0; indexA < 3; indexA++)
03238 {
03239 for (indexB = 0; indexB < 3; indexB++)
03240 {
03241 jsonArray1.append(b_mat_tp_pu[index*9+indexA*3+indexB].Re());
03242 }
03243 jsonArray2.append(jsonArray1);
03244 jsonArray1.clear();
03245 }
03246 line_configuration_object["rmatrix"] = jsonArray2;
03247 jsonArray2.clear();
03248
03249
03250 for (indexA = 0; indexA < 3; indexA++)
03251 {
03252 for (indexB = 0; indexB < 3; indexB++)
03253 {
03254 jsonArray1.append(b_mat_tp_pu[index*9+indexA*3+indexB].Im());
03255 }
03256 jsonArray2.append(jsonArray1);
03257 jsonArray1.clear();
03258 }
03259 line_configuration_object["xmatrix"] = jsonArray2;
03260 jsonArray2.clear();
03261
03262
03263
03264 jsonArray.append(line_configuration_object);
03265
03266
03267 line_configuration_object.clear();
03268 }
03269 }
03270 }
03271
03272
03273 if(TransConfsList->hit_count > 0 )
03274 {
03275
03276 for (index=0; index<TransConfsList->hit_count; index++)
03277 {
03278
03279 if (b_mat_trans_defined[index] == true)
03280 {
03281
03282
03283 if (pTransConf[index]->name == NULL)
03284 {
03285 sprintf(buffer,"trans_config:%d",pTransConf[index]->id);
03286 line_configuration_object["line_code"] = buffer;
03287 }
03288 else
03289 {
03290 line_configuration_object["line_code"] = pTransConf[index]->name;
03291 }
03292
03293
03294 line_configuration_object["num_phases"] = trans_phase_count[index];
03295
03296
03297 jsonArray1.clear();
03298 jsonArray2.clear();
03299
03300
03301 for (indexA = 0; indexA < 3; indexA++)
03302 {
03303 for (indexB = 0; indexB < 3; indexB++)
03304 {
03305 jsonArray1.append(b_mat_trans_pu[index*9+indexA*3+indexB].Re());
03306 }
03307 jsonArray2.append(jsonArray1);
03308 jsonArray1.clear();
03309 }
03310 line_configuration_object["rmatrix"] = jsonArray2;
03311 jsonArray2.clear();
03312
03313
03314 for (indexA = 0; indexA < 3; indexA++)
03315 {
03316 for (indexB = 0; indexB < 3; indexB++)
03317 {
03318 jsonArray1.append(b_mat_trans_pu[index*9+indexA*3+indexB].Im());
03319 }
03320 jsonArray2.append(jsonArray1);
03321 jsonArray1.clear();
03322 }
03323 line_configuration_object["xmatrix"] = jsonArray2;
03324 jsonArray2.clear();
03325
03326
03327
03328 jsonArray.append(line_configuration_object);
03329
03330
03331 line_configuration_object.clear();
03332 }
03333 }
03334 }
03335
03336
03337 if(regConfs->hit_count > 0 )
03338 {
03339
03340 for (index=0; index<regConfs->hit_count; index++)
03341 {
03342
03343 if (b_mat_reg_defined[index] == true)
03344 {
03345
03346
03347 if (pRegConf[index]->name == NULL)
03348 {
03349 sprintf(buffer,"reg_config:%d",pRegConf[index]->id);
03350 line_configuration_object["line_code"] = buffer;
03351 }
03352 else
03353 {
03354 line_configuration_object["line_code"] = pRegConf[index]->name;
03355 }
03356
03357
03358 line_configuration_object["num_phases"] = reg_phase_count[index];
03359
03360
03361 jsonArray1.clear();
03362 jsonArray2.clear();
03363
03364
03365 for (indexA = 0; indexA < 3; indexA++)
03366 {
03367 for (indexB = 0; indexB < 3; indexB++)
03368 {
03369 jsonArray1.append(b_mat_reg_pu[index*9+indexA*3+indexB].Re());
03370 }
03371 jsonArray2.append(jsonArray1);
03372 jsonArray1.clear();
03373 }
03374 line_configuration_object["rmatrix"] = jsonArray2;
03375 jsonArray2.clear();
03376
03377
03378 for (indexA = 0; indexA < 3; indexA++)
03379 {
03380 for (indexB = 0; indexB < 3; indexB++)
03381 {
03382 jsonArray1.append(b_mat_reg_pu[index*9+indexA*3+indexB].Im());
03383 }
03384 jsonArray2.append(jsonArray1);
03385 jsonArray1.clear();
03386 }
03387 line_configuration_object["xmatrix"] = jsonArray2;
03388 jsonArray2.clear();
03389
03390
03391
03392 jsonArray.append(line_configuration_object);
03393
03394
03395 line_configuration_object.clear();
03396 }
03397 }
03398 }
03399
03400
03401 metrics_lines["properties"]["line_codes"] = jsonArray;
03402
03403
03404 jsonArray.clear();
03405
03406
03407 out_file.open (filename_dump_system);
03408 out_file << writer.write(metrics_lines) << endl;
03409 out_file.close();
03410
03411
03412 if (lineConfs->hit_count > 0)
03413 {
03414 gl_free(b_mat_pu);
03415 gl_free(b_mat_defined);
03416 }
03417
03418 if (tpLineConfs->hit_count > 0)
03419 {
03420 gl_free(b_mat_tp_pu);
03421 gl_free(b_mat_tp_defined);
03422 }
03423
03424 if (TransConfsList->hit_count > 0)
03425 {
03426 gl_free(b_mat_trans_pu);
03427 gl_free(b_mat_trans_defined);
03428 gl_free(trans_phase_count);
03429 }
03430
03431 if (regConfs->hit_count > 0)
03432 {
03433 gl_free(b_mat_reg_pu);
03434 gl_free(b_mat_reg_defined);
03435 gl_free(reg_phase_count);
03436 }
03437
03438
03439 gl_free(ohlines);
03440 gl_free(tplines);
03441 gl_free(uglines);
03442 gl_free(switches);
03443 gl_free(regulators);
03444 gl_free(regConfs);
03445 gl_free(lineConfs);
03446 gl_free(tpLineConfs);
03447 gl_free(TransformerList);
03448 gl_free(TransConfsList);
03449 gl_free(nodes);
03450 gl_free(meters);
03451 gl_free(loads);
03452 gl_free(fuses);
03453 gl_free(reclosers);
03454 gl_free(sectionalizers);
03455 gl_free(inverters);
03456 gl_free(diesels);
03457
03458 return SUCCESS;
03459 }
03460
03461 STATUS jsondump::dump_reliability(void)
03462 {
03463 FINDLIST *powermetrics, *fuses, *reclosers, *sectionalizers, *relays, *capacitors, *regulators;
03464 fuse *fuseData;
03465 recloser *reclData;
03466 sectionalizer *secData;
03467 capacitor *capData;
03468 regulator *regData;
03469 char* indices1366[] = {"SAIFI", "SAIDI", "CAIDI", "ASAI", "MAIFI", NULL};
03470 int index1366;
03471 double *temp_double;
03472 enumeration *temp_emu;
03473 OBJECT *obj = NULL;
03474 char buffer[1024];
03475 FILE *fn = NULL;
03476 int index = 0;
03477
03478
03479 Json::Value metrics_reliability;
03480 Json::Value metrics_1366;
03481 Json::Value metrics_protection;
03482 Json::Value metrics_others;
03483 Json::Value protectionArray;
03484 Json::Value protect_obj;
03485 Json::Value otherArray;
03486 Json::Value other_obj;
03487 Json::Value jsonArray;
03488
03489 Json::StyledWriter writer;
03490
03491 ofstream out_file;
03492
03493
03494 powermetrics = gl_find_objects(FL_NEW,FT_CLASS,SAME,"power_metrics",FT_END);
03495 fuses = gl_find_objects(FL_NEW,FT_CLASS,SAME,"fuse",FT_END);
03496 reclosers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"recloser",FT_END);
03497 sectionalizers = gl_find_objects(FL_NEW,FT_CLASS,SAME,"sectionalizer",FT_END);
03498
03499 capacitors = gl_find_objects(FL_NEW,FT_CLASS,SAME,"capacitor",FT_END);
03500 regulators = gl_find_objects(FL_NEW,FT_CLASS,SAME,"regulator",FT_END);
03501
03502
03503 index = 0;
03504 if(powermetrics != NULL){
03505
03506 while(obj = gl_find_next(powermetrics,obj)){
03507
03508
03509 if(index > 1){
03510 gl_error("There are more than 1 power metrics defined");
03511 return FAILED;
03512 }
03513
03514
03515 index1366 = -1;
03516 while (indices1366[++index1366] != NULL) {
03517
03518 temp_double = gl_get_double_by_name(obj, indices1366[index1366]);
03519
03520 if(temp_double == NULL){
03521 gl_error("Unable to to find property for %s: %s is NULL", obj->name, indices1366[index1366]);
03522 return FAILED;
03523 }
03524
03525 metrics_1366[indices1366[index1366]] = *temp_double;
03526
03527 }
03528
03529 index++;
03530 }
03531 }
03532
03533
03534 metrics_reliability["GridLAB-D reliability outputs"] = metrics_1366;
03535
03536
03537
03538 index = 0;
03539 if(fuses != NULL){
03540
03541 while(obj = gl_find_next(fuses,obj)){
03542 if(index >= fuses->hit_count){
03543 break;
03544 }
03545
03546
03547 fuseData = OBJECTDATA(obj,fuse);
03548
03549
03550 protect_obj["Name"] = obj->name;
03551
03552
03553
03554 if ((fuseData->phases & 0x04) == 0x04) {
03555 sprintf(buffer, "%s", ((fuseData->phase_A_state == 1)? true:false));
03556 jsonArray.append(buffer);
03557 }
03558 if ((fuseData->phases & 0x02) == 0x02) {
03559 sprintf(buffer, "%s", ((fuseData->phase_B_state == 1)? true:false));
03560 jsonArray.append(buffer);
03561 }
03562 if ((fuseData->phases & 0x01) == 0x01) {
03563 sprintf(buffer, "%s", ((fuseData->phase_C_state == 1)? true:false));
03564 jsonArray.append(buffer);
03565 }
03566
03567
03568 protect_obj["Device opening status"] = jsonArray;
03569 jsonArray.clear();
03570
03571
03572 protectionArray.append(protect_obj);
03573 protect_obj.clear();
03574
03575 index++;
03576 }
03577
03578
03579 metrics_protection["Fuse"] = protectionArray;
03580 protectionArray.clear();
03581 }
03582
03583
03584 index = 0;
03585 if(reclosers != NULL){
03586
03587 while(obj = gl_find_next(reclosers,obj)){
03588 if(index >= reclosers->hit_count){
03589 break;
03590 }
03591
03592
03593 reclData = OBJECTDATA(obj,recloser);
03594
03595
03596 protect_obj["Name"] = obj->name;
03597
03598
03599
03600 if ((reclData->phases & 0x04) == 0x04) {
03601 sprintf(buffer, "%s", ((reclData->phase_A_state == 1)? true:false));
03602 jsonArray.append(buffer);
03603 }
03604 if ((reclData->phases & 0x02) == 0x02) {
03605 sprintf(buffer, "%s", ((reclData->phase_B_state == 1)? true:false));
03606 jsonArray.append(buffer);
03607 }
03608 if ((reclData->phases & 0x01) == 0x01) {
03609 sprintf(buffer, "%s", ((reclData->phase_C_state == 1)? true:false));
03610 jsonArray.append(buffer);
03611 }
03612
03613
03614 protect_obj["Device opening status"] = jsonArray;
03615 jsonArray.clear();
03616
03617
03618 protectionArray.append(protect_obj);
03619 protect_obj.clear();
03620
03621 index++;
03622 }
03623
03624
03625 metrics_protection["Recloser"] = protectionArray;
03626 protectionArray.clear();
03627 }
03628
03629
03630 index = 0;
03631 if(sectionalizers != NULL){
03632
03633 while(obj = gl_find_next(sectionalizers,obj)){
03634 if(index >= sectionalizers->hit_count){
03635 break;
03636 }
03637
03638
03639 secData = OBJECTDATA(obj,sectionalizer);
03640
03641
03642 protect_obj["Name"] = obj->name;
03643
03644
03645
03646 if ((secData->phases & 0x04) == 0x04) {
03647 sprintf(buffer, "%s", ((secData->phase_A_state == 1)? true:false));
03648 jsonArray.append(buffer);
03649 }
03650 if ((secData->phases & 0x02) == 0x02) {
03651 sprintf(buffer, "%s", ((secData->phase_B_state == 1)? true:false));
03652 jsonArray.append(buffer);
03653 }
03654 if ((secData->phases & 0x01) == 0x01) {
03655 sprintf(buffer, "%s", ((secData->phase_C_state == 1)? true:false));
03656 jsonArray.append(buffer);
03657 }
03658
03659
03660 protect_obj["Device opening status"] = jsonArray;
03661 jsonArray.clear();
03662
03663
03664 protectionArray.append(protect_obj);
03665 protect_obj.clear();
03666
03667 index++;
03668 }
03669
03670
03671 metrics_protection["Sectionalizer"] = protectionArray;
03672 protectionArray.clear();
03673 }
03674
03675
03676 metrics_reliability["Protective devices"] = metrics_protection;
03677
03678
03679 metrics_protection.clear();
03680
03681
03682
03683 index = 0;
03684 if(capacitors != NULL){
03685
03686 while(obj = gl_find_next(capacitors,obj)){
03687 if(index >= capacitors->hit_count){
03688 break;
03689 }
03690
03691
03692 capData = OBJECTDATA(obj,capacitor);
03693
03694
03695 other_obj["Name"] = obj->name;
03696
03697
03698
03699 if ((capData->pt_phase & 0x04) == 0x04) {
03700 sprintf(buffer, "%s", ((capData->switchA_state == 1)? true:false));
03701 jsonArray.append(buffer);
03702 }
03703 if ((capData->pt_phase & 0x02) == 0x02) {
03704 sprintf(buffer, "%s", ((capData->switchB_state == 1)? true:false));
03705 jsonArray.append(buffer);
03706 }
03707 if ((capData->pt_phase & 0x01) == 0x01) {
03708 sprintf(buffer, "%s", ((capData->switchC_state == 1)? true:false));
03709 jsonArray.append(buffer);
03710 }
03711
03712
03713 other_obj["Device opening status"] = jsonArray;
03714 jsonArray.clear();
03715
03716
03717 otherArray.append(other_obj);
03718 other_obj.clear();
03719
03720 index++;
03721 }
03722
03723
03724 metrics_others["Capacitor"] = otherArray;
03725 otherArray.clear();
03726 }
03727
03728
03729 index = 0;
03730 if(regulators != NULL){
03731
03732 while(obj = gl_find_next(regulators,obj)){
03733 if(index >= regulators->hit_count){
03734 break;
03735 }
03736
03737
03738 regData = OBJECTDATA(obj,regulator);
03739
03740
03741 other_obj["Name"] = obj->name;
03742
03743
03744
03745 if ((regData->phases & 0x04) == 0x04) {
03746 jsonArray.append(regData->tap[0]);
03747 }
03748 if ((regData->phases & 0x02) == 0x02) {
03749 jsonArray.append(regData->tap[1]);
03750 }
03751 if ((regData->phases & 0x01) == 0x01) {
03752 jsonArray.append(regData->tap[2]);
03753 }
03754
03755
03756 other_obj["Tap position"] = jsonArray;
03757 jsonArray.clear();
03758
03759
03760 otherArray.append(other_obj);
03761 other_obj.clear();
03762
03763 index++;
03764 }
03765
03766
03767 metrics_others["Regulator"] = otherArray;
03768 otherArray.clear();
03769 }
03770
03771
03772 metrics_reliability["Other devices"] = metrics_others;
03773
03774
03775 metrics_others.clear();
03776
03777
03778 out_file.open (filename_dump_reliability);
03779 out_file << writer.write(metrics_reliability) << endl;
03780 out_file.close();
03781
03782
03783 gl_free(powermetrics);
03784 gl_free(fuses);
03785 gl_free(reclosers);
03786 gl_free(sectionalizers);
03787 gl_free(relays);
03788 gl_free(capacitors);
03789 gl_free(regulators);
03790
03791 return SUCCESS;
03792
03793 }
03794
03795 TIMESTAMP jsondump::commit(TIMESTAMP t){
03796 STATUS rv;
03797
03798 if(runtime == 0){
03799 runtime = t;
03800 }
03801 if((write_system == true) && ((t == runtime) || (runtime == TS_NEVER)) && (runcount < 1)){
03802
03803 rv = dump_system();
03804 ++runcount;
03805 if(rv == FAILED){
03806 return TS_INVALID;
03807 }
03808 return TS_NEVER;
03809 } else {
03810 if(t < runtime){
03811 return runtime;
03812 } else {
03813 return TS_NEVER;
03814 }
03815 }
03816 }
03817
03818 STATUS jsondump::finalize(){
03819 STATUS rv;
03820
03821 if (write_reliability == true) {
03822
03823 rv = dump_reliability();
03824
03825 if(rv != SUCCESS){
03826 return FAILED;
03827 }
03828
03829 }
03830
03831 return SUCCESS;
03832 }
03833
03834
03835 int jsondump::isa(char *classname)
03836 {
03837 return strcmp(classname,"jsondump")==0;
03838 }
03839
03840
03841
03842 double jsondump::get_double_value(OBJECT *obj, char *name)
03843 {
03844 gld_property *pQuantity;
03845 double output_value;
03846 OBJECT *objhdr = OBJECTHDR(this);
03847
03848
03849 pQuantity = new gld_property(obj,name);
03850
03851
03852 if ((pQuantity->is_valid() != true) || (pQuantity->is_double() != true))
03853 {
03854 GL_THROW("jsdondump:%d %s - Unable to map property %s from object:%d %s",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"),name,obj->id,(obj->name ? obj->name : "Unnamed"));
03855
03856
03857
03858
03859 }
03860
03861
03862 output_value = pQuantity->get_double();
03863
03864
03865 delete pQuantity;
03866
03867
03868 return output_value;
03869 }
03870
03871
03872 complex jsondump::get_complex_value(OBJECT *obj, char *name)
03873 {
03874 gld_property *pQuantity;
03875 complex output_value;
03876 OBJECT *objhdr = OBJECTHDR(this);
03877
03878
03879 pQuantity = new gld_property(obj,name);
03880
03881
03882 if ((pQuantity->is_valid() != true) || (pQuantity->is_complex() != true))
03883 {
03884 GL_THROW("jsdondump:%d %s - Unable to map property %s from object:%d %s",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"),name,obj->id,(obj->name ? obj->name : "Unnamed"));
03885
03886 }
03887
03888
03889 output_value = pQuantity->get_complex();
03890
03891
03892 delete pQuantity;
03893
03894
03895 return output_value;
03896 }
03897
03898
03899 set jsondump::get_set_value(OBJECT *obj, char *name)
03900 {
03901 gld_property *pQuantity;
03902 set output_value;
03903 OBJECT *objhdr = OBJECTHDR(this);
03904
03905
03906 pQuantity = new gld_property(obj,name);
03907
03908
03909 if ((pQuantity->is_valid() != true) || (pQuantity->is_set() != true))
03910 {
03911 GL_THROW("jsdondump:%d %s - Unable to map property %s from object:%d %s",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"),name,obj->id,(obj->name ? obj->name : "Unnamed"));
03912
03913 }
03914
03915
03916 output_value = pQuantity->get_set();
03917
03918
03919 delete pQuantity;
03920
03921
03922 return output_value;
03923 }
03924
03925
03926 enumeration jsondump::get_enum_value(OBJECT *obj, char *name)
03927 {
03928 gld_property *pQuantity;
03929 enumeration output_value;
03930 OBJECT *objhdr = OBJECTHDR(this);
03931
03932
03933 pQuantity = new gld_property(obj,name);
03934
03935
03936 if ((pQuantity->is_valid() != true) || (pQuantity->is_enumeration() != true))
03937 {
03938 GL_THROW("jsdondump:%d %s - Unable to map property %s from object:%d %s",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"),name,obj->id,(obj->name ? obj->name : "Unnamed"));
03939
03940 }
03941
03942
03943 output_value = pQuantity->get_enumeration();
03944
03945
03946 delete pQuantity;
03947
03948
03949 return output_value;
03950 }
03951
03952
03953 OBJECT *jsondump::get_object_value(OBJECT *obj,char *name)
03954 {
03955 gld_property *pQuantity;
03956 gld_rlock *test_rlock;
03957 OBJECT *output_value;
03958 OBJECT *objhdr = OBJECTHDR(this);
03959
03960
03961 pQuantity = new gld_property(obj,name);
03962
03963
03964 if ((pQuantity->is_valid() != true) || (pQuantity->is_objectref() != true))
03965 {
03966 GL_THROW("jsdondump:%d %s - Unable to map property %s from object:%d %s",objhdr->id,(objhdr->name ? objhdr->name : "Unnamed"),name,obj->id,(obj->name ? obj->name : "Unnamed"));
03967
03968 }
03969
03970
03971 pQuantity->getp<OBJECT*>(output_value,*test_rlock);
03972
03973
03974 delete pQuantity;
03975
03976
03977 return output_value;
03978 }
03979
03980
03982
03984
03992 EXPORT int create_jsondump(OBJECT **obj, OBJECT *parent)
03993 {
03994 try
03995 {
03996 *obj = gl_create_object(jsondump::oclass);
03997 if (*obj!=NULL)
03998 {
03999 jsondump *my = OBJECTDATA(*obj,jsondump);
04000 gl_set_parent(*obj,parent);
04001 return my->create();
04002 }
04003 }
04004 catch (const char *msg)
04005 {
04006 gl_error("create_jsondump: %s", msg);
04007 }
04008 return 0;
04009 }
04010
04011 EXPORT int init_jsondump(OBJECT *obj)
04012 {
04013 jsondump *my = OBJECTDATA(obj,jsondump);
04014 try {
04015 return my->init(obj->parent);
04016 }
04017 catch (const char *msg)
04018 {
04019 gl_error("%s (jsondump:%d): %s", obj->name, obj->id, msg);
04020 return 0;
04021 }
04022 }
04023
04024 EXPORT TIMESTAMP sync_jsondump(OBJECT *obj, TIMESTAMP t1, PASSCONFIG pass)
04025 {
04026 try
04027 {
04028 jsondump *my = OBJECTDATA(obj,jsondump);
04029 TIMESTAMP rv;
04030 obj->clock = t1;
04031 rv = my->runtime > t1 ? my->runtime : TS_NEVER;
04032 return rv;
04033 }
04034 SYNC_CATCHALL(jsondump);
04035 }
04036
04037 EXPORT TIMESTAMP commit_jsondump(OBJECT *obj, TIMESTAMP t1, TIMESTAMP t2){
04038 try {
04039 jsondump *my = OBJECTDATA(obj,jsondump);
04040 return my->commit(t1);
04041 }
04042 I_CATCHALL(commit,jsondump);
04043 }
04044
04045 EXPORT STATUS finalize_jsondump(OBJECT *obj)
04046 {
04047
04048 jsondump *my = OBJECTDATA(obj,jsondump);
04049
04050 try {
04051 return obj!=NULL ? my->finalize() : FAILED;
04052 }
04053 catch (char *msg) {
04054 gl_error("finalize_jsondump" "(obj=%d;%s): %s", obj->id, obj->name?obj->name:"unnamed", msg);
04055 return FAILED;
04056 }
04057 catch (const char *msg) {
04058 gl_error("finalize_jsondump" "(obj=%d;%s): %s", obj->id, obj->name?obj->name:"unnamed", msg);
04059 return FAILED;
04060 }
04061 catch (...) {
04062 gl_error("finalize_jsondump" "(obj=%d;%s): unhandled exception", obj->id, obj->name?obj->name:"unnamed");
04063 return FAILED;
04064 }
04065 }
04066
04067 EXPORT int isa_jsondump(OBJECT *obj, char *classname)
04068 {
04069 return OBJECTDATA(obj,jsondump)->isa(classname);
04070 }
04071