00001
00012 #include <stdlib.h>
00013 #include <stdio.h>
00014 #include <errno.h>
00015 #include <math.h>
00016
00017 #include "switch_object.h"
00018 #include "node.h"
00019
00020 EXPORT int64 switch_close(OBJECT *obj)
00021 {
00022 if (!gl_object_isa(obj,"switch"))
00023 {
00024 GL_THROW("powerflow.switch_close(): %s object (%s:%d) is not a switch", obj->name?obj->name:"anonymous", obj->oclass->name,obj->id);
00025 return 0;
00026 }
00027 switch_object *pSwitch = OBJECTDATA(obj,switch_object);
00028 return (int64)pSwitch->close();
00029 }
00030
00031 EXPORT int64 switch_open(OBJECT *obj)
00032 {
00033 if (!gl_object_isa(obj,"switch"))
00034 {
00035 GL_THROW("powerflow::switch_open(): %s object (%s:%d) is not a switch", obj->name?obj->name:"anonymous", obj->oclass->name,obj->id);
00036 return 0;
00037 }
00038 switch_object *pSwitch = OBJECTDATA(obj,switch_object);
00039 return (int64)pSwitch->open();
00040 }
00041
00042 EXPORT int64 switch_status(OBJECT *obj)
00043 {
00044 if (!gl_object_isa(obj,"switch"))
00045 {
00046 GL_THROW("powerflow::switch_open(): %s object (%s:%d) is not a switch", obj->name?obj->name:"anonymous", obj->oclass->name,obj->id);
00047 return 0;
00048 }
00049 switch_object *pSwitch = OBJECTDATA(obj,switch_object);
00050 return (int64)pSwitch->get_status();
00051 }
00052
00054
00056 CLASS* switch_object::oclass = NULL;
00057 CLASS* switch_object::pclass = NULL;
00058
00059 switch_object::switch_object(MODULE *mod) : link(mod)
00060 {
00061 if(oclass == NULL)
00062 {
00063 pclass = link::oclass;
00064
00065 oclass = gl_register_class(mod,"switch",sizeof(switch_object),PC_PRETOPDOWN|PC_BOTTOMUP|PC_POSTTOPDOWN|PC_UNSAFE_OVERRIDE_OMIT);
00066 if(oclass == NULL)
00067 GL_THROW("unable to register object class implemented by %s",__FILE__);
00068
00069 if(gl_publish_variable(oclass,
00070 PT_INHERIT, "link",
00071 PT_enumeration, "phase_A_state", PADDR(phase_A_state),
00072 PT_KEYWORD, "OPEN", OPEN,
00073 PT_KEYWORD, "CLOSED", CLOSED,
00074 PT_enumeration, "phase_B_state", PADDR(phase_B_state),
00075 PT_KEYWORD, "OPEN", OPEN,
00076 PT_KEYWORD, "CLOSED", CLOSED,
00077 PT_enumeration, "phase_C_state", PADDR(phase_C_state),
00078 PT_KEYWORD, "OPEN", OPEN,
00079 PT_KEYWORD, "CLOSED", CLOSED,
00080 PT_enumeration, "operating_mode", PADDR(switch_banked_mode),
00081 PT_KEYWORD, "INDIVIDUAL", INDIVIDUAL_SW,
00082 PT_KEYWORD, "BANKED", BANKED_SW,
00083 NULL) < 1) GL_THROW("unable to publish properties in %s",__FILE__);
00084
00085 if (gl_publish_function(oclass,"close",(FUNCTIONADDR)switch_close)==NULL)
00086 GL_THROW("unable to publish switch close function");
00087 if (gl_publish_function(oclass,"open",(FUNCTIONADDR)switch_open)==NULL)
00088 GL_THROW("unable to publish switch open function");
00089 if (gl_publish_function(oclass,"status",(FUNCTIONADDR)switch_status)==NULL)
00090 GL_THROW("unable to publish switch open function");
00091 }
00092 }
00093
00094 int switch_object::isa(char *classname)
00095 {
00096 return strcmp(classname,"switch")==0 || link::isa(classname);
00097 }
00098
00099 int switch_object::create()
00100 {
00101 int result = link::create();
00102
00103 prev_full_status = 0x00;
00104 switch_banked_mode = BANKED_SW;
00105 phase_A_state = CLOSED;
00106 phase_B_state = CLOSED;
00107 phase_C_state = CLOSED;
00108
00109 prev_SW_time = 0;
00110 return result;
00111 }
00112
00113 int switch_object::init(OBJECT *parent)
00114 {
00115 double phase_total, switch_total;
00116
00117
00118 SpecialLnk = SWITCH;
00119
00120 int result = link::init(parent);
00121
00122 a_mat[0][0] = d_mat[0][0] = A_mat[0][0] = (is_closed() && has_phase(PHASE_A) ? 1.0 : 0.0);
00123 a_mat[1][1] = d_mat[1][1] = A_mat[1][1] = (is_closed() && has_phase(PHASE_B) ? 1.0 : 0.0);
00124 a_mat[2][2] = d_mat[2][2] = A_mat[2][2] = (is_closed() && has_phase(PHASE_C) ? 1.0 : 0.0);
00125
00126 if (solver_method==SM_FBS)
00127 {
00128 b_mat[0][0] = c_mat[0][0] = B_mat[0][0] = 0.0;
00129 b_mat[1][1] = c_mat[1][1] = B_mat[1][1] = 0.0;
00130 b_mat[2][2] = c_mat[2][2] = B_mat[2][2] = 0.0;
00131 }
00132 else
00133 {
00134
00135
00136
00137 From_Y[0][1] = From_Y[0][2] = From_Y[1][0] = 0.0;
00138 From_Y[1][2] = From_Y[2][0] = From_Y[2][1] = 0.0;
00139
00140 if (switch_banked_mode == BANKED_SW)
00141 {
00142
00143 phase_total = (double)(has_phase(PHASE_A) + has_phase(PHASE_B) + has_phase(PHASE_C));
00144
00145 switch_total = 0.0;
00146 if (has_phase(PHASE_A) && (phase_A_state == CLOSED))
00147 switch_total += 1.0;
00148
00149 if (has_phase(PHASE_B) && (phase_B_state == CLOSED))
00150 switch_total += 1.0;
00151
00152 if (has_phase(PHASE_C) && (phase_C_state == CLOSED))
00153 switch_total += 1.0;
00154
00155 switch_total /= phase_total;
00156
00157 if (switch_total > 0.5)
00158 {
00159
00160 if (status == LS_OPEN)
00161 {
00162 phase_A_state = phase_B_state = phase_C_state = CLOSED;
00163 }
00164 else
00165 {
00166 phase_A_state = phase_B_state = phase_C_state = CLOSED;
00167 }
00168 }
00169 else
00170 {
00171 if (switch_total == 0.5)
00172 {
00173 if (status == LS_OPEN)
00174 {
00175 phase_A_state = phase_B_state = phase_C_state = OPEN;
00176 }
00177 else
00178 {
00179 phase_A_state = phase_B_state = phase_C_state = CLOSED;
00180 }
00181 }
00182 else
00183 {
00184 status = LS_OPEN;
00185 phase_A_state = phase_B_state = phase_C_state = OPEN;
00186 }
00187 }
00188
00189 if (status==LS_OPEN)
00190 {
00191 From_Y[0][0] = complex(0.0,0.0);
00192 From_Y[1][1] = complex(0.0,0.0);
00193 From_Y[2][2] = complex(0.0,0.0);
00194
00195 phase_A_state = phase_B_state = phase_C_state = OPEN;
00196 prev_full_status = 0x00;
00197 }
00198 else
00199 {
00200 if (has_phase(PHASE_A))
00201 {
00202 From_Y[0][0] = complex(1e4,1e4);
00203 phase_A_state = CLOSED;
00204 prev_full_status |= 0x04;
00205 }
00206
00207 if (has_phase(PHASE_B))
00208 {
00209 From_Y[1][1] = complex(1e4,1e4);
00210 phase_B_state = CLOSED;
00211 prev_full_status |= 0x02;
00212 }
00213
00214 if (has_phase(PHASE_C))
00215 {
00216 From_Y[2][2] = complex(1e4,1e4);
00217 phase_C_state = CLOSED;
00218 prev_full_status |= 0x01;
00219 }
00220 }
00221 }
00222 else
00223 {
00224 if (status==LS_OPEN)
00225 {
00226 From_Y[0][0] = complex(0.0,0.0);
00227 From_Y[1][1] = complex(0.0,0.0);
00228 From_Y[2][2] = complex(0.0,0.0);
00229
00230 phase_A_state = phase_B_state = phase_C_state = OPEN;
00231 prev_full_status = 0x00;
00232 }
00233 else
00234 {
00235 if (has_phase(PHASE_A))
00236 {
00237 if (phase_A_state == CLOSED)
00238 {
00239 From_Y[0][0] = complex(1e4,1e4);
00240 prev_full_status |= 0x04;
00241 }
00242 else
00243 {
00244 From_Y[0][0] = complex(0.0,0.0);
00245 prev_full_status &=0xFB;
00246 }
00247 }
00248
00249 if (has_phase(PHASE_B))
00250 {
00251 if (phase_B_state == CLOSED)
00252 {
00253 From_Y[1][1] = complex(1e4,1e4);
00254 prev_full_status |= 0x02;
00255 }
00256 else
00257 {
00258 From_Y[1][1] = complex(0.0,0.0);
00259 prev_full_status &=0xFD;
00260 }
00261 }
00262
00263 if (has_phase(PHASE_C))
00264 {
00265 if (phase_C_state == CLOSED)
00266 {
00267 From_Y[2][2] = complex(1e4,1e4);
00268 prev_full_status |= 0x01;
00269 }
00270 else
00271 {
00272 From_Y[2][2] = complex(0.0,0.0);
00273 prev_full_status &=0xFE;
00274 }
00275 }
00276 }
00277 }
00278 }
00279
00280 return result;
00281 }
00282
00283 TIMESTAMP switch_object::sync(TIMESTAMP t0)
00284 {
00285 TIMESTAMP t1 = TS_NEVER;
00286 node *tnode = OBJECTDATA(to,node);
00287 unsigned char pres_status;
00288 double phase_total, switch_total;
00289
00290 if (solver_method==SM_NR)
00291 {
00292 pres_status = 0x00;
00293
00294 if (switch_banked_mode == BANKED_SW)
00295 {
00296 if (status == prev_status)
00297 {
00298
00299 phase_total = (double)(has_phase(PHASE_A) + has_phase(PHASE_B) + has_phase(PHASE_C));
00300
00301 switch_total = 0.0;
00302 if (has_phase(PHASE_A) && (phase_A_state == CLOSED))
00303 switch_total += 1.0;
00304
00305 if (has_phase(PHASE_B) && (phase_B_state == CLOSED))
00306 switch_total += 1.0;
00307
00308 if (has_phase(PHASE_C) && (phase_C_state == CLOSED))
00309 switch_total += 1.0;
00310
00311 switch_total /= phase_total;
00312
00313 if (switch_total > 0.5)
00314 {
00315 status = LS_CLOSED;
00316 phase_A_state = phase_B_state = phase_C_state = CLOSED;
00317 }
00318 else
00319 {
00320 if (switch_total == 0.5)
00321 {
00322 if (status == LS_OPEN)
00323 {
00324 phase_A_state = phase_B_state = phase_C_state = OPEN;
00325 }
00326 else
00327 {
00328 phase_A_state = phase_B_state = phase_C_state = CLOSED;
00329 }
00330 }
00331 else
00332 {
00333 status = LS_OPEN;
00334 phase_A_state = phase_B_state = phase_C_state = OPEN;
00335 }
00336 }
00337 }
00338 else
00339 {
00340 if (status==LS_OPEN)
00341 phase_A_state = phase_B_state = phase_C_state = OPEN;
00342 else
00343 phase_A_state = phase_B_state = phase_C_state = CLOSED;
00344 }
00345
00346 if (status==LS_OPEN)
00347 {
00348 if (has_phase(PHASE_A))
00349 {
00350 From_Y[0][0] = complex(0.0,0.0);
00351 a_mat[0][0] = 0.0;
00352 NR_branchdata[NR_branch_reference].phases &= 0xFB;
00353 }
00354
00355 if (has_phase(PHASE_B))
00356 {
00357 From_Y[1][1] = complex(0.0,0.0);
00358 a_mat[1][1] = 0.0;
00359 NR_branchdata[NR_branch_reference].phases &= 0xFD;
00360 }
00361
00362 if (has_phase(PHASE_C))
00363 {
00364 From_Y[2][2] = complex(0.0,0.0);
00365 a_mat[2][2] = 0.0;
00366 NR_branchdata[NR_branch_reference].phases &= 0xFE;
00367 }
00368 }
00369 else
00370 {
00371 if (has_phase(PHASE_A))
00372 {
00373 From_Y[0][0] = complex(1e4,1e4);
00374 a_mat[0][0] = 1.0;
00375 pres_status |= 0x04;
00376 NR_branchdata[NR_branch_reference].phases |= 0x04;
00377 }
00378
00379 if (has_phase(PHASE_B))
00380 {
00381 From_Y[1][1] = complex(1e4,1e4);
00382 a_mat[1][1] = 1.0;
00383 pres_status |= 0x02;
00384 NR_branchdata[NR_branch_reference].phases |= 0x02;
00385 }
00386
00387 if (has_phase(PHASE_C))
00388 {
00389 From_Y[2][2] = complex(1e4,1e4);
00390 a_mat[2][2] = 1.0;
00391 pres_status |= 0x01;
00392 NR_branchdata[NR_branch_reference].phases |= 0x01;
00393 }
00394 }
00395 }
00396 else
00397 {
00398 if (status == LS_OPEN)
00399 {
00400 From_Y[0][0] = complex(0.0,0.0);
00401 From_Y[1][1] = complex(0.0,0.0);
00402 From_Y[2][2] = complex(0.0,0.0);
00403
00404 phase_A_state = phase_B_state = phase_C_state = OPEN;
00405 NR_branchdata[NR_branch_reference].phases &= 0xF0;
00406 }
00407 else
00408 {
00409 if (has_phase(PHASE_A))
00410 {
00411 if (phase_A_state == CLOSED)
00412 {
00413 From_Y[0][0] = complex(1e4,1e4);
00414 pres_status |= 0x04;
00415 NR_branchdata[NR_branch_reference].phases |= 0x04;
00416 }
00417 else
00418 {
00419 From_Y[0][0] = complex(0.0,0.0);
00420 NR_branchdata[NR_branch_reference].phases &= 0xFB;
00421 }
00422 }
00423
00424 if (has_phase(PHASE_B))
00425 {
00426 if (phase_B_state == CLOSED)
00427 {
00428 From_Y[1][1] = complex(1e4,1e4);
00429 pres_status |= 0x02;
00430 NR_branchdata[NR_branch_reference].phases |= 0x02;
00431 }
00432 else
00433 {
00434 From_Y[1][1] = complex(0.0,0.0);
00435 NR_branchdata[NR_branch_reference].phases &= 0xFD;
00436 }
00437 }
00438
00439 if (has_phase(PHASE_C))
00440 {
00441 if (phase_C_state == CLOSED)
00442 {
00443 From_Y[2][2] = complex(1e4,1e4);
00444 pres_status |= 0x01;
00445 NR_branchdata[NR_branch_reference].phases |= 0x01;
00446 }
00447 else
00448 {
00449 From_Y[2][2] = complex(0.0,0.0);
00450 NR_branchdata[NR_branch_reference].phases &= 0xFE;
00451 }
00452 }
00453 }
00454 }
00455
00456
00457 if ((status != prev_status) || (pres_status != prev_full_status))
00458 NR_admit_change = true;
00459
00460 prev_full_status = pres_status;
00461 }
00462 #ifdef SUPPORT_OUTAGES
00463 set trip = (f->is_contact_any() || t->is_contact_any());
00464
00465
00466 if (status==LS_CLOSED && trip)
00467 {
00468 status = LS_OPEN;
00469 t1 = TS_NEVER;
00470 }
00471 else if (status==LS_OPEN)
00472 {
00473 if (trip)
00474 {
00475 {
00476 t1 = t0+(TIMESTAMP)(gl_random_exponential(3600)*TS_SECOND);
00477 }
00478 }
00479
00480
00481 }
00482 #endif
00483
00484 if (prev_SW_time!=t0)
00485 prev_SW_time=t0;
00486
00487 TIMESTAMP t2=link::sync(t0);
00488
00489 return t1<t2?t1:t2;
00490 }
00491
00492
00493
00494 void switch_object::set_switch(bool desired_status)
00495 {
00496 status = desired_status;
00497
00498 if (solver_method == SM_NR)
00499 {
00500 if (status != prev_status)
00501 {
00502
00503 if (status==LS_OPEN)
00504 {
00505 if (has_phase(PHASE_A))
00506 {
00507 From_Y[0][0] = complex(0.0,0.0);
00508 a_mat[0][0] = 0.0;
00509 NR_branchdata[NR_branch_reference].phases &= 0xFB;
00510 phase_A_state = OPEN;
00511 }
00512
00513 if (has_phase(PHASE_B))
00514 {
00515 From_Y[1][1] = complex(0.0,0.0);
00516 a_mat[1][1] = 0.0;
00517 NR_branchdata[NR_branch_reference].phases &= 0xFD;
00518 phase_B_state = OPEN;
00519 }
00520
00521 if (has_phase(PHASE_C))
00522 {
00523 From_Y[2][2] = complex(0.0,0.0);
00524 a_mat[2][2] = 0.0;
00525 NR_branchdata[NR_branch_reference].phases &= 0xFE;
00526 phase_C_state = OPEN;
00527 }
00528 }
00529 else
00530 {
00531 if (has_phase(PHASE_A))
00532 {
00533 From_Y[0][0] = complex(1e4,1e4);
00534 a_mat[0][0] = 1.0;
00535 NR_branchdata[NR_branch_reference].phases |= 0x04;
00536 phase_A_state = CLOSED;
00537 }
00538
00539 if (has_phase(PHASE_B))
00540 {
00541 From_Y[1][1] = complex(1e4,1e4);
00542 a_mat[1][1] = 1.0;
00543 NR_branchdata[NR_branch_reference].phases |= 0x02;
00544 phase_B_state = CLOSED;
00545 }
00546
00547 if (has_phase(PHASE_C))
00548 {
00549 From_Y[2][2] = complex(1e4,1e4);
00550 a_mat[2][2] = 1.0;
00551 NR_branchdata[NR_branch_reference].phases |= 0x01;
00552 phase_C_state = CLOSED;
00553 }
00554 }
00555
00556
00557 NR_admit_change = true;
00558
00559
00560 prev_status = status;
00561 }
00562
00563 }
00564 else
00565 {
00566 gl_warning("Switch status updated, but no other changes made.");
00567
00568
00569
00570
00571
00572 }
00573 }
00574
00575
00576
00577
00578 void switch_object::set_switch_full(char desired_status_A, char desired_status_B, char desired_status_C)
00579 {
00580 double phase_total, switch_total;
00581 unsigned char pres_status;
00582
00583 if (desired_status_A == 0)
00584 phase_A_state = OPEN;
00585 else if (desired_status_A == 1)
00586 phase_A_state = CLOSED;
00587
00588
00589 if (desired_status_B == 0)
00590 phase_B_state = OPEN;
00591 else if (desired_status_B == 1)
00592 phase_B_state = CLOSED;
00593
00594
00595 if (desired_status_C == 0)
00596 phase_C_state = OPEN;
00597 else if (desired_status_C == 1)
00598 phase_C_state = CLOSED;
00599
00600
00601
00602 if (solver_method==SM_NR)
00603 {
00604 pres_status = 0x00;
00605
00606 if (switch_banked_mode == BANKED_SW)
00607 {
00608 if (status == prev_status)
00609 {
00610
00611 phase_total = (double)(has_phase(PHASE_A) + has_phase(PHASE_B) + has_phase(PHASE_C));
00612
00613 switch_total = 0.0;
00614 if (has_phase(PHASE_A) && (phase_A_state == CLOSED))
00615 switch_total += 1.0;
00616
00617 if (has_phase(PHASE_B) && (phase_B_state == CLOSED))
00618 switch_total += 1.0;
00619
00620 if (has_phase(PHASE_C) && (phase_C_state == CLOSED))
00621 switch_total += 1.0;
00622
00623 switch_total /= phase_total;
00624
00625 if (switch_total > 0.5)
00626 {
00627 status = LS_CLOSED;
00628 phase_A_state = phase_B_state = phase_C_state = CLOSED;
00629 }
00630 else
00631 {
00632 if (switch_total == 0.5)
00633 {
00634 if (status == LS_OPEN)
00635 {
00636 phase_A_state = phase_B_state = phase_C_state = OPEN;
00637 }
00638 else
00639 {
00640 phase_A_state = phase_B_state = phase_C_state = CLOSED;
00641 }
00642 }
00643 else
00644 {
00645 status = LS_OPEN;
00646 phase_A_state = phase_B_state = phase_C_state = OPEN;
00647 }
00648 }
00649 }
00650 else
00651 {
00652 if (status==LS_OPEN)
00653 phase_A_state = phase_B_state = phase_C_state = OPEN;
00654 else
00655 phase_A_state = phase_B_state = phase_C_state = CLOSED;
00656 }
00657
00658 if (status==LS_OPEN)
00659 {
00660 if (has_phase(PHASE_A))
00661 {
00662 From_Y[0][0] = complex(0.0,0.0);
00663 a_mat[0][0] = 0.0;
00664 NR_branchdata[NR_branch_reference].phases &= 0xFB;
00665 }
00666
00667 if (has_phase(PHASE_B))
00668 {
00669 From_Y[1][1] = complex(0.0,0.0);
00670 a_mat[1][1] = 0.0;
00671 NR_branchdata[NR_branch_reference].phases &= 0xFD;
00672 }
00673
00674 if (has_phase(PHASE_C))
00675 {
00676 From_Y[2][2] = complex(0.0,0.0);
00677 a_mat[2][2] = 0.0;
00678 NR_branchdata[NR_branch_reference].phases &= 0xFE;
00679 }
00680 }
00681 else
00682 {
00683 if (has_phase(PHASE_A))
00684 {
00685 From_Y[0][0] = complex(1e4,1e4);
00686 a_mat[0][0] = 1.0;
00687 pres_status |= 0x04;
00688 NR_branchdata[NR_branch_reference].phases |= 0x04;
00689 }
00690
00691 if (has_phase(PHASE_B))
00692 {
00693 From_Y[1][1] = complex(1e4,1e4);
00694 a_mat[1][1] = 1.0;
00695 pres_status |= 0x02;
00696 NR_branchdata[NR_branch_reference].phases |= 0x02;
00697 }
00698
00699 if (has_phase(PHASE_C))
00700 {
00701 From_Y[2][2] = complex(1e4,1e4);
00702 a_mat[2][2] = 1.0;
00703 pres_status |= 0x01;
00704 NR_branchdata[NR_branch_reference].phases |= 0x01;
00705 }
00706 }
00707 }
00708 else
00709 {
00710 if (status == LS_OPEN)
00711 {
00712 From_Y[0][0] = complex(0.0,0.0);
00713 From_Y[1][1] = complex(0.0,0.0);
00714 From_Y[2][2] = complex(0.0,0.0);
00715
00716 phase_A_state = phase_B_state = phase_C_state = OPEN;
00717 NR_branchdata[NR_branch_reference].phases &= 0xF0;
00718 }
00719 else
00720 {
00721 if (has_phase(PHASE_A))
00722 {
00723 if (phase_A_state == CLOSED)
00724 {
00725 From_Y[0][0] = complex(1e4,1e4);
00726 pres_status |= 0x04;
00727 NR_branchdata[NR_branch_reference].phases |= 0x04;
00728 }
00729 else
00730 {
00731 From_Y[0][0] = complex(0.0,0.0);
00732 NR_branchdata[NR_branch_reference].phases &= 0xFB;
00733 }
00734 }
00735
00736 if (has_phase(PHASE_B))
00737 {
00738 if (phase_B_state == CLOSED)
00739 {
00740 From_Y[1][1] = complex(1e4,1e4);
00741 pres_status |= 0x02;
00742 NR_branchdata[NR_branch_reference].phases |= 0x02;
00743 }
00744 else
00745 {
00746 From_Y[1][1] = complex(0.0,0.0);
00747 NR_branchdata[NR_branch_reference].phases &= 0xFD;
00748 }
00749 }
00750
00751 if (has_phase(PHASE_C))
00752 {
00753 if (phase_C_state == CLOSED)
00754 {
00755 From_Y[2][2] = complex(1e4,1e4);
00756 pres_status |= 0x01;
00757 NR_branchdata[NR_branch_reference].phases |= 0x01;
00758 }
00759 else
00760 {
00761 From_Y[2][2] = complex(0.0,0.0);
00762 NR_branchdata[NR_branch_reference].phases &= 0xFE;
00763 }
00764 }
00765 }
00766 }
00767
00768
00769 NR_admit_change = true;
00770
00771
00772 prev_status = status;
00773
00774
00775 prev_full_status = pres_status;
00776
00777 }
00778
00779 }
00780
00782
00784
00792 EXPORT int commit_switch_object(OBJECT *obj)
00793 {
00794 if (solver_method==SM_FBS)
00795 {
00796 switch_object *plink = OBJECTDATA(obj,switch_object);
00797 plink->calculate_power();
00798 }
00799 return 1;
00800 }
00801 EXPORT int create_switch(OBJECT **obj, OBJECT *parent)
00802 {
00803 try
00804 {
00805 *obj = gl_create_object(switch_object::oclass);
00806 if (*obj!=NULL)
00807 {
00808 switch_object *my = OBJECTDATA(*obj,switch_object);
00809 gl_set_parent(*obj,parent);
00810 return my->create();
00811 }
00812 }
00813 catch (const char *msg)
00814 {
00815 gl_error("create_switch: %s", msg);
00816 }
00817 return 0;
00818 }
00819
00826 EXPORT int init_switch(OBJECT *obj)
00827 {
00828 switch_object *my = OBJECTDATA(obj,switch_object);
00829 try {
00830 return my->init(obj->parent);
00831 }
00832 catch (const char *msg)
00833 {
00834 GL_THROW("%s (switch:%d): %s", my->get_name(), my->get_id(), msg);
00835 return 0;
00836 }
00837 }
00838
00847 EXPORT TIMESTAMP sync_switch(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass)
00848 {
00849 switch_object *pObj = OBJECTDATA(obj,switch_object);
00850 try {
00851 TIMESTAMP t1 = TS_NEVER;
00852 switch (pass) {
00853 case PC_PRETOPDOWN:
00854 return pObj->presync(t0);
00855 case PC_BOTTOMUP:
00856 return pObj->sync(t0);
00857 case PC_POSTTOPDOWN:
00858 t1 = pObj->postsync(t0);
00859 obj->clock = t0;
00860 return t1;
00861 default:
00862 throw "invalid pass request";
00863 }
00864 } catch (const char *error) {
00865 GL_THROW("%s (switch:%d): %s", pObj->get_name(), pObj->get_id(), error);
00866 return 0;
00867 } catch (...) {
00868 GL_THROW("%s (switch:%d): %s", pObj->get_name(), pObj->get_id(), "unknown exception");
00869 return 0;
00870 }
00871 }
00872
00873 EXPORT int isa_switch(OBJECT *obj, char *classname)
00874 {
00875 return OBJECTDATA(obj,switch_object)->isa(classname);
00876 }
00877