00001
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include <errno.h>
00013 #include <math.h>
00014
00015 #include "generators.h"
00016 #include "power_electronics.h"
00017 #include "rectifier.h"
00018
00019 #define DEFAULT 1.0;
00020
00021
00022 CLASS *rectifier::oclass = NULL;
00023 rectifier *rectifier::defaults = NULL;
00024
00025 static PASSCONFIG passconfig = PC_BOTTOMUP|PC_POSTTOPDOWN;
00026 static PASSCONFIG clockpass = PC_BOTTOMUP;
00027
00028
00029 rectifier::rectifier(MODULE *module)
00030 {
00031 if (oclass==NULL)
00032 {
00033 oclass = gl_register_class(module,"rectifier",sizeof(rectifier),PC_PRETOPDOWN|PC_BOTTOMUP|PC_POSTTOPDOWN);
00034 if (oclass==NULL)
00035 GL_THROW("unable to register object class implemented by %s", __FILE__);
00036
00037 if (gl_publish_variable(oclass,
00038
00039 PT_enumeration,"rectifier_type",PADDR(rectifier_type_v),
00040 PT_KEYWORD,"ONE_PULSE",ONE_PULSE,
00041 PT_KEYWORD,"TWO_PULSE",TWO_PULSE,
00042 PT_KEYWORD,"THREE_PULSE",THREE_PULSE,
00043 PT_KEYWORD,"SIX_PULSE",SIX_PULSE,
00044 PT_KEYWORD,"TWELVE_PULSE",TWELVE_PULSE,
00045
00046 PT_enumeration,"generator_mode",PADDR(gen_mode_v),
00047 PT_KEYWORD,"UNKNOWN",UNKNOWN,
00048 PT_KEYWORD,"CONSTANT_V",CONSTANT_V,
00049 PT_KEYWORD,"CONSTANT_PQ",CONSTANT_PQ,
00050 PT_KEYWORD,"CONSTANT_PF",CONSTANT_PF,
00051 PT_KEYWORD,"SUPPLY_DRIVEN",SUPPLY_DRIVEN,
00052
00053 PT_complex, "V_Out[V]",PADDR(V_Out),
00054 PT_complex, "I_Out[A]",PADDR(I_Out),
00055 PT_complex, "VA_Out[VA]", PADDR(VA_Out),
00056 PT_double, "P_Out", PADDR(P_Out),
00057 PT_double, "Q_Out", PADDR(Q_Out),
00058 PT_complex, "Vdc[V]", PADDR(Vdc),
00059 PT_complex, "phaseA_V_In[V]", PADDR(phaseA_V_In),
00060 PT_complex, "phaseB_V_In[V]", PADDR(phaseB_V_In),
00061 PT_complex, "phaseC_V_In[V]", PADDR(phaseC_V_In),
00062 PT_complex, "phaseA_I_In[V]", PADDR(phaseA_I_In),
00063 PT_complex, "phaseB_I_In[V]", PADDR(phaseB_I_In),
00064 PT_complex, "phaseC_I_In[V]", PADDR(phaseC_I_In),
00065 PT_complex, "power_A_In[VA]", PADDR(power_A_In),
00066 PT_complex, "power_B_In[VA]", PADDR(power_B_In),
00067 PT_complex, "power_C_In[VA]", PADDR(power_C_In),
00068
00069
00070
00071 PT_set, "phases", PADDR(phases),
00072 PT_KEYWORD, "A",(set)PHASE_A,
00073 PT_KEYWORD, "B",(set)PHASE_B,
00074 PT_KEYWORD, "C",(set)PHASE_C,
00075 PT_KEYWORD, "N",(set)PHASE_N,
00076 PT_KEYWORD, "S",(set)PHASE_S,
00077 NULL)<1) GL_THROW("unable to publish properties in %s",__FILE__);
00078 defaults = this;
00079
00080
00081
00082
00083
00084
00085 memset(this,0,sizeof(rectifier));
00086
00087 }
00088 }
00089
00090
00091
00092
00093
00094 int rectifier::create(void)
00095 {
00096 memcpy(this,defaults,sizeof(*this));
00097
00098 return 1;
00099 }
00100
00101
00102 int rectifier::init(OBJECT *parent)
00103 {
00104
00105
00106
00107
00108
00109 Rated_kW = 1000;
00110 Max_P = 1000;
00111 Min_P = 0;
00112
00113
00114 Rated_kVA = 1500;
00115 Rated_kV = 10;
00116 Rinternal = 0.035;
00117 Rload = 1;
00118 Rtotal = 0.05;
00119
00120
00121
00122 XphaseA = complex(5 * 1,0);
00123 XphaseB = complex(5 * 1,0);
00124 XphaseC = complex(5 * 1,0);
00125 Rground = 0.03;
00126 Rground_storage = 0.05;
00127 Vdc = 480;
00128
00129 Cinternal = 0;
00130 Cground = 0;
00131 Ctotal = 0;
00132 Linternal = 0;
00133 Lground = 0;
00134 Ltotal = 0;
00135 filter_120HZ = false;
00136 filter_180HZ = false;
00137 filter_240HZ = false;
00138 pf_in = 1;
00139 pf_out = 0;
00140 number_of_phases_in = 3;
00141 number_of_phases_out = 0;
00142 phaseAIn = true;
00143 phaseBIn = true;
00144 phaseCIn = true;
00145 phaseAOut = false;
00146 phaseBOut = false;
00147 phaseCOut = false;
00148
00149 V_In_Set_A = complex(480,0);
00150 V_In_Set_B = complex(-240, 415.69);
00151 V_In_Set_C = complex(-240,-415.69);
00152
00153 switch_type_choice = IDEAL_SWITCH;
00154
00155 gen_status_v = ONLINE;
00156 filter_type_v = BAND_PASS;
00157 filter_imp_v = IDEAL_FILTER;
00158 rectifier_type_v = SIX_PULSE;
00159 power_in = AC;
00160 power_out = DC;
00161
00162
00163 P_Out = 500;
00164 Q_Out = 0;
00165
00166
00167
00168 margin = 50;
00169 V_Set = 240;
00170 I_out_prev = 0;
00171 I_step_max = 100;
00172 internal_losses = 0;
00173 C_Storage_Out = 0;
00174 efficiency = 0;
00175 losses = 0;
00176
00177 on_ratio = 0;
00178 input_frequency = 2000;
00179 frequency_losses = 0;
00180
00181
00182 gl_verbose("rectifier init: initialized the variables");
00183
00184 struct {
00185 complex **var;
00186 char *varname;
00187 } map[] = {
00188
00189 {&pCircuit_V, "V_In"},
00190 {&pLine_I, "I_In"},
00191 };
00192
00193
00194
00195
00196 static complex default_line_voltage[1], default_line_current[1];
00197 int i;
00198
00199
00200 if (parent!=NULL && strcmp(parent->oclass->name,"meter")==0)
00201 {
00202 parent_string = "meter";
00203 for (i=0; i<sizeof(map)/sizeof(map[0]); i++)
00204 *(map[i].var) = get_complex(parent,map[i].varname);
00205
00206 gl_verbose("rectifier init: mapped METER objects to internal variables");
00207 }
00208 else if (parent!=NULL && strcmp(parent->oclass->name,"inverter")==0){
00209 gl_verbose("rectifier init: parent WAS found, is an inverter!");
00210 parent_string = "inverter";
00211
00213
00214 for (i=0; i<sizeof(map)/sizeof(map[0]); i++){
00215 *(map[i].var) = get_complex(parent,map[i].varname);
00216 }
00217 gl_verbose("rectifier init: mapped INVERTER objects to internal variables");
00218 }
00219 else if (parent!=NULL && strcmp(parent->oclass->name,"dc_dc_converter")==0){
00220 gl_verbose("rectifier init: parent WAS found, is a dc dc converter!!");
00221 parent_string = "dc_dc_converter";
00222
00224
00225 for (i=0; i<sizeof(map)/sizeof(map[0]); i++){
00226 *(map[i].var) = get_complex(parent,map[i].varname);
00227 }
00228 gl_verbose("rectifier init: mapped DC_DC_CONVERTER objects to internal variables");
00229 }
00230 else if (parent!=NULL && strcmp(parent->oclass->name,"battery")==0){
00231 gl_verbose("rectifier init: parent WAS found, is an battery!");
00232 parent_string = "battery";
00233
00235
00236 for (i=0; i<sizeof(map)/sizeof(map[0]); i++){
00237 *(map[i].var) = get_complex(parent,map[i].varname);
00238 }
00239 gl_verbose("rectifier init: mapped BATTERY objects to internal variables");
00240 }
00241 else{
00242
00243
00245
00246
00247 parent_string = "none";
00248 OBJECT *obj = OBJECTHDR(this);
00249 gl_verbose("rectifier init: no parent meter defined, parent is not a meter");
00250 gl_warning("rectifier:%d %s", obj->id, parent==NULL?"has no parent meter defined":"parent is not a meter");
00251
00252
00253 *(map[0].var) = &default_line_voltage[0];
00254 *(map[1].var) = &default_line_current[0];
00255
00256
00257 default_line_voltage[0] = complex(0,0);
00258 default_line_current[0] = complex(0,0);
00259
00260
00261
00262 }
00263
00264 gl_verbose("rectifier init: finished connecting with meter");
00265
00266
00267
00268
00269
00270
00271
00272 if (gen_mode_v==UNKNOWN)
00273 {
00274 OBJECT *obj = OBJECTHDR(this);
00275 throw("Generator control mode is not specified");
00276 }
00277 if (gen_status_v== rectifier::OFFLINE)
00278 {
00279
00280 throw("Generator is out of service!");
00281 }else
00282 {
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 switch(rectifier_type_v){
00320 case ONE_PULSE:
00321 efficiency = 0.5;
00322 break;
00323 case TWO_PULSE:
00324 efficiency = 0.7;
00325 break;
00326 case THREE_PULSE:
00327 efficiency = 0.7;
00328 break;
00329 case SIX_PULSE:
00330 efficiency = 0.8;
00331 break;
00332 case TWELVE_PULSE:
00333 efficiency = 0.9;
00334 break;
00335 default:
00336 efficiency = 0.8;
00337 break;
00338 }
00339
00340 internal_switch_resistance(switch_type_choice);
00341 filter_circuit_impact(filter_type_v, filter_imp_v);
00342
00343 }
00344 gl_verbose("rectifier init: about to exit");
00345 return 1;
00346 }
00347
00348
00349 complex *rectifier::get_complex(OBJECT *obj, char *name)
00350 {
00351 PROPERTY *p = gl_get_property(obj,name);
00352 if (p==NULL || p->ptype!=PT_complex)
00353 return NULL;
00354 return (complex*)GETADDR(obj,p);
00355 }
00356
00357
00358
00359 void rectifier::iterative_IV(complex VA, char* phase_designation){
00360 complex Vdet = complex(0,0);
00361 complex increment = complex(0,0);
00362 complex Idet = complex(0,0);
00363 complex Vs = complex(0,0);
00364 complex s = complex(0,0);
00365 complex incrementA;
00366 complex incrementB;
00367 complex incrementC;
00368 complex VdetA = V_In_Set_A;
00369 complex VdetB = V_In_Set_B;
00370 complex VdetC = V_In_Set_C;
00371 complex IdetA = complex(0,0);
00372 complex IdetB = complex(0,0);
00373 complex IdetC = complex(0,0);
00374 int i = 0;
00375
00376 if(VA.Re() > 3000){
00377 incrementA = complex(1 * 1,0);
00378 incrementB = complex(1 * -0.5, 1 * 0.866);
00379 incrementC = complex(1 * -0.5, 1 * -0.866);
00380 }else if (VA.Re() > 1000){
00381 incrementA = complex(0.5 * 1,0);
00382 incrementB = complex(0.5 * -0.5, 0.5 * 0.866);
00383 incrementC = complex(0.5 * -0.5, 0.5 * -0.866);
00384 }else{
00385 incrementA = complex(0.25 * 1,0);
00386 incrementB = complex(0.25 * -0.5, 0.25 * 0.866);
00387 incrementC = complex(0.25 * -0.5, 0.25 * -0.866);
00388 }
00389
00390
00391 if(phase_designation == "D"){
00392 while(true){
00393 if((abs(VA.Re() - s.Re()) < margin)){
00394 if(true){
00395 break;
00396 }
00397 }
00398
00399 if(i > 150){
00400 throw("rectifier sync: rectifier failed to converge! The power asked for was too high or too low!");
00401 break;
00402 }
00403 VdetA = VdetA + incrementA;
00404 VdetB = VdetB + incrementB;
00405 VdetC = VdetC + incrementC;
00406 IdetA = (VdetA - V_In_Set_A)/XphaseA;
00407 IdetB = (VdetB - V_In_Set_B)/XphaseB;
00408 IdetC = (VdetC - V_In_Set_C)/XphaseC;
00409 s = ((~IdetA) * VdetA) + ((~IdetB) * VdetB) + ((~IdetC) * VdetC);
00410 i++;
00411 }
00412
00413 phaseA_V_In = VdetA;
00414 phaseA_I_In = IdetA;
00415 power_A_In = (~IdetA) * VdetA;
00416 phaseB_V_In = VdetB;
00417 phaseB_I_In = IdetB;
00418 power_B_In = (~IdetB) * VdetB;
00419 phaseC_V_In = VdetC;
00420 phaseC_I_In = IdetC;
00421 power_C_In = (~IdetC) * VdetC;
00422
00423
00424 gl_verbose("rectifier sync: iterative solver: Total VA delivered is: (%f , %f)", s.Re(), s.Im());
00425
00426 gl_verbose("rectifier sync: iterative solver: power_A_In delivered is: (%f , %f)", power_A_In.Re(), power_A_In.Im());
00427 gl_verbose("rectifier sync: iterative solver: phaseA_V_In is: (%f , %f)", phaseA_V_In.Re(), phaseA_V_In.Im());
00428 gl_verbose("rectifier sync: iterative solver: phaseA_I_In is: (%f , %f)", phaseA_I_In.Re(), phaseA_I_In.Im());
00429
00430 gl_verbose("rectifier sync: iterative solver: power_B_In delivered is: (%f , %f)", power_B_In.Re(), power_B_In.Im());
00431 gl_verbose("rectifier sync: iterative solver: phaseB_V_In is: (%f , %f)", phaseB_V_In.Re(), phaseB_V_In.Im());
00432 gl_verbose("rectifier sync: iterative solver: phaseB_I_In is: (%f , %f)", phaseB_I_In.Re(), phaseB_I_In.Im());
00433
00434 gl_verbose("rectifier sync: iterative solver: power_C_In delivered is: (%f , %f)", power_C_In.Re(), power_C_In.Im());
00435 gl_verbose("rectifier sync: iterative solver: phaseC_V_In is: (%f , %f)", phaseC_V_In.Re(), phaseC_V_In.Im());
00436 gl_verbose("rectifier sync: iterative solver: phaseC_I_In is: (%f , %f)", phaseC_I_In.Re(), phaseC_I_In.Im());
00437
00438 return;
00439 }
00440
00441 complex Xphase = complex(0,0);
00442
00443
00444 if (phase_designation == "A"){
00445 Vdet = V_In_Set_A;
00446 Vs = V_In_Set_A;
00447 increment = complex(0.5 * 1,0);
00448 Xphase = XphaseA;
00449 }
00450 else if(phase_designation == "B"){
00451 Vdet = V_In_Set_B;
00452 Vs = V_In_Set_B;
00453 increment = complex(0.5 * -0.5, 0.5 * 0.866);
00454 Xphase = XphaseB;
00455 }
00456 else if(phase_designation == "C"){
00457 Vdet = V_In_Set_C;
00458 Vs = V_In_Set_C;
00459 increment = complex(0.5 * -0.5, 0.5 * -0.866);
00460 Xphase = XphaseC;
00461 }else{
00462 throw("no phase designated!");
00463 }
00464
00465 Idet = (Vdet - Vs)/Xphase;
00466 s = (~Idet) * Vdet;
00467 if(s.Mag() >= VA.Mag()){
00468 if(phase_designation == "A"){
00469 phaseA_V_In = Vdet;
00470 phaseA_I_In = Idet;
00471 }
00472 else if(phase_designation == "B"){
00473 phaseB_V_In = Vdet;
00474 phaseB_I_In = Idet;
00475 }
00476 else if(phase_designation == "C"){
00477 phaseC_V_In = Vdet;
00478 phaseC_I_In = Idet;
00479 }
00480 return;
00481 }
00482
00483
00484 while(((abs(VA.Re() - s.Re()) > margin) || (abs(VA.Im() - s.Im()) > margin))&& i < 50){
00485 Vdet = Vdet + increment;
00486 Idet = (Vdet - Vs)/Xphase;
00487 s = Vdet * ~ Idet;
00488 i++;
00489 }
00490
00491 if(phase_designation == "A"){
00492 phaseA_V_In = Vdet;
00493 phaseA_I_In = Idet;
00494 gl_verbose("rectifier sync: iterative solver: power_A_In asked for was: (%f , %f)", VA.Re(), VA.Im());
00495 gl_verbose("rectifier sync: iterative solver: power_A_In delivered is: (%f , %f)", s.Re(), s.Im());
00496 gl_verbose("rectifier sync: iterative solver: phaseA_V_In is: (%f , %f)", phaseA_V_In.Re(), phaseA_V_In.Im());
00497 gl_verbose("rectifier sync: iterative solver: phaseA_I_In is: (%f , %f)", phaseA_I_In.Re(), phaseA_I_In.Im());
00498
00499 }
00500 else if(phase_designation == "B"){
00501 phaseB_V_In = Vdet;
00502 phaseB_I_In = Idet;
00503 gl_verbose("rectifier sync: iterative solver: power_B_In asked for was: (%f , %f)", VA.Re(), VA.Im());
00504 gl_verbose("rectifier sync: iterative solver: power_B_In delivered is: (%f , %f)", s.Re(), s.Im());
00505 gl_verbose("rectifier sync: iterative solver: phaseB_V_In is: (%f , %f)", phaseB_V_In.Re(), phaseB_V_In.Im());
00506 gl_verbose("rectifier sync: iterative solver: phaseB_I_In is: (%f , %f)", phaseB_I_In.Re(), phaseB_I_In.Im());
00507 }
00508 else if(phase_designation == "C"){
00509 phaseC_V_In = Vdet;
00510 phaseC_I_In = Idet;
00511 gl_verbose("rectifier sync: iterative solver: power_C_In asked for was: (%f , %f)", VA.Re(), VA.Im());
00512 gl_verbose("rectifier sync: iterative solver: power_C_In delivered is: (%f , %f)", s.Re(), s.Im());
00513 gl_verbose("rectifier sync: iterative solver: phaseC_V_In is: (%f , %f)", phaseC_V_In.Re(), phaseC_V_In.Im());
00514 gl_verbose("rectifier sync: iterative solver: phaseC_I_In is: (%f , %f)", phaseC_I_In.Re(), phaseC_I_In.Im());
00515 }
00516
00517
00518 return;
00519 }
00520
00521
00522
00523
00524 TIMESTAMP rectifier::presync(TIMESTAMP t0, TIMESTAMP t1)
00525 {
00526 I_Out = VA_Out = 0.0;
00527
00528 TIMESTAMP t2 = TS_NEVER;
00529
00530 return t2;
00531 }
00532
00533
00534 TIMESTAMP rectifier::sync(TIMESTAMP t0, TIMESTAMP t1)
00535 {
00536
00537 V_Out = pCircuit_V[0];
00538 I_Out = pLine_I[0];
00539
00540 gl_verbose("rectifier sync: V_Out from parent is: (%f , %f)", V_Out.Re(), V_Out.Im());
00541 gl_verbose("rectifier sync: I_Out from parent is: (%f , %f)", I_Out.Re(), I_Out.Im());
00542
00543 internal_losses = 1 - calculate_loss(Rtotal, Ltotal, Ctotal, DC, AC);
00544 frequency_losses = 1 - calculate_frequency_loss(input_frequency, Rtotal,Ltotal, Ctotal);
00545
00546
00547
00548
00549
00550 switch(gen_mode_v){
00551 case SUPPLY_DRIVEN:
00552 {
00553
00554
00555
00556
00557 gl_verbose("rectifier sync: supply driven rectifier");
00558
00559 power_A_In = phaseA_V_In * phaseA_I_In;
00560 power_B_In = phaseB_V_In * phaseB_I_In;
00561 power_C_In = phaseC_V_In * phaseC_I_In;
00562
00563 VA_In = power_A_In + power_B_In + power_C_In;
00564
00565
00566
00567 VA_Out = VA_In * efficiency * internal_losses * frequency_losses;
00568 losses = VA_Out * Rtotal / (Rtotal + Rload);
00569 VA_Out = VA_Out * Rload / (Rtotal + Rload);
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594 I_Out = VA_Out / V_Out;
00595 I_Out = ~ I_Out;
00596
00597
00598 gl_verbose("rectifier sync: VA_Out is: (%f , %f)", VA_Out.Re(), VA_Out.Im());
00599 gl_verbose("rectifier sync: V_Out is: (%f , %f)", V_Out.Re(), V_Out.Im());
00600 gl_verbose("rectifier sync: I_Out is: (%f , %f)", I_Out.Re(), I_Out.Im());
00601 gl_verbose("rectifier sync: losses is: (%f , %f)", losses.Re(), losses.Im());
00602
00603
00604 gl_verbose("rectifier sync: supply driven about to exit");
00605 return TS_NEVER;
00606 }
00607 break;
00608 case CONSTANT_PQ:
00609 {
00610 gl_verbose("rectifier sync: constant pq rectifier");
00611
00612
00613
00614
00615
00616 if(parent_string == "meter"){
00617 VA_Out = complex(P_Out,Q_Out);
00618 }else{
00619 VA_Out = V_Out * (~I_Out);
00620 }
00621
00622 gl_verbose("rectifier sync: VA_Out calculated from parent is: (%f , %f)", VA_Out.Re(), VA_Out.Im());
00623
00624 VA_In = VA_Out / (efficiency * internal_losses);
00625 losses = VA_Out * (1 - (efficiency * internal_losses));
00626
00627
00628
00629 gl_verbose("rectifier sync: VA_In calculated after losses is: (%f , %f)", VA_In.Re(), VA_In.Im());
00630
00631 if(number_of_phases_in == 3){
00632 iterative_IV(VA_In, "D");
00633 }
00634
00635 if(number_of_phases_in == 1){
00636
00637 VA_In = VA_In / number_of_phases_in;
00638
00639
00640
00641
00642
00643
00644 if(phaseAIn){
00645 power_A_In = VA_In;
00646 iterative_IV(power_A_In,"A");
00647
00648
00649
00650
00651 }
00652
00653 if(phaseBIn){
00654 power_B_In = VA_In;
00655 iterative_IV(power_B_In,"B");
00656
00657
00658
00659 }
00660
00661 if(phaseCIn){
00662 power_C_In = VA_In;
00663 iterative_IV(power_C_In,"C");
00664
00665
00666
00667
00668 }
00669
00670 }
00671
00672
00673 gl_verbose("rectifier sync: VA_In is: (%f , %f)", VA_In.Re(), VA_In.Im());
00674 gl_verbose("rectifier sync: power_A_In is: (%f , %f)", power_A_In.Re(), power_A_In.Im());
00675 gl_verbose("rectifier sync: power_B_In is: (%f , %f)", power_B_In.Re(), power_B_In.Im());
00676 gl_verbose("rectifier sync: power_C_In is: (%f , %f)", power_C_In.Re(), power_C_In.Im());
00677 gl_verbose("rectifier sync: phaseA_V_In is: (%f , %f)", phaseA_V_In.Re(), phaseA_V_In.Im());
00678 gl_verbose("rectifier sync: phaseB_V_In is: (%f , %f)", phaseB_V_In.Re(), phaseB_V_In.Im());
00679 gl_verbose("rectifier sync: phaseC_V_In is: (%f , %f)", phaseC_V_In.Re(), phaseC_V_In.Im());
00680 gl_verbose("rectifier sync: phaseA_I_In is: (%f , %f)", phaseA_I_In.Re(), phaseA_I_In.Im());
00681 gl_verbose("rectifier sync: phaseB_I_In is: (%f , %f)", phaseB_I_In.Re(), phaseB_I_In.Im());
00682 gl_verbose("rectifier sync: phaseC_I_In is: (%f , %f)", phaseC_I_In.Re(), phaseC_I_In.Im());
00683
00684 gl_verbose("rectifier sync: constant pq about to exit");
00685 return TS_NEVER;
00686 }
00687 break;
00688 case CONSTANT_V:
00689 {
00690 gl_verbose("rectifier sync: constant v rectifier");
00691 bool changed = false;
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705 if (V_Out < (V_Set - margin)){
00706 I_Out = I_out_prev + I_step_max / 2;
00707 changed = true;
00708 }else if (V_Out > (V_Set + margin)){
00709 I_Out = I_out_prev - I_step_max / 2;
00710 changed = true;
00711 }else{
00712 changed = false;
00713 }
00714
00715 VA_Out = (~I_Out) * V_Out;
00716
00717 if(VA_Out > Rated_kVA){
00718 VA_Out = Rated_kVA;
00719 I_Out = VA_Out / V_Out;
00720 changed = false;
00721 }
00722
00723 if(VA_Out < 0){
00724 VA_Out = 0;
00725 I_Out = 0;
00726 changed = false;
00727 }
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 gl_verbose("rectifier sync: VA_Out requested from parent is: (%f , %f)", VA_Out.Re(), VA_Out.Im());
00801
00802
00803 VA_In = VA_Out / (efficiency * internal_losses);
00804 losses = VA_Out * (1 - (efficiency * internal_losses));
00805
00806 gl_verbose("rectifier sync: VA_In after losses is: (%f , %f)", VA_In.Re(), VA_In.Im());
00807
00808
00809
00810
00811
00812
00813 if(number_of_phases_in == 3){
00814 iterative_IV(VA_In, "D");
00815 }
00816
00817 if(number_of_phases_in == 1){
00818 VA_In = VA_In / number_of_phases_in;
00819
00820 if(phaseAIn){
00821 power_A_In = VA_In;
00822 iterative_IV(power_A_In,"A");
00823 }
00824
00825 if(phaseBIn){
00826 power_B_In = VA_In;
00827 iterative_IV(power_B_In,"B");
00828 }
00829
00830 if(phaseCIn){
00831 power_C_In = VA_In;
00832 iterative_IV(power_C_In,"C");
00833 }
00834
00835 }
00836
00837
00838
00839 gl_verbose("rectifier sync: VA_In is: (%f , %f)", VA_In.Re(), VA_In.Im());
00840 gl_verbose("rectifier sync: power_A_In is: (%f , %f)", power_A_In.Re(), power_A_In.Im());
00841 gl_verbose("rectifier sync: power_B_In is: (%f , %f)", power_B_In.Re(), power_B_In.Im());
00842 gl_verbose("rectifier sync: power_C_In is: (%f , %f)", power_C_In.Re(), power_C_In.Im());
00843 gl_verbose("rectifier sync: phaseA_V_In is: (%f , %f)", phaseA_V_In.Re(), phaseA_V_In.Im());
00844 gl_verbose("rectifier sync: phaseB_V_In is: (%f , %f)", phaseB_V_In.Re(), phaseB_V_In.Im());
00845 gl_verbose("rectifier sync: phaseC_V_In is: (%f , %f)", phaseC_V_In.Re(), phaseC_V_In.Im());
00846 gl_verbose("rectifier sync: phaseA_I_In is: (%f , %f)", phaseA_I_In.Re(), phaseA_I_In.Im());
00847 gl_verbose("rectifier sync: phaseB_I_In is: (%f , %f)", phaseB_I_In.Re(), phaseB_I_In.Im());
00848 gl_verbose("rectifier sync: phaseC_I_In is: (%f , %f)", phaseC_I_In.Re(), phaseC_I_In.Im());
00849
00850
00851 gl_verbose("rectifier sync: constant v rectifier about to exit");
00852 if(changed){
00853 TIMESTAMP t2 = TS_NEVER;
00854 return t2;
00855 }else{
00856 return TS_NEVER;
00857 }
00858 }
00859 break;
00860 default:
00861 break;
00862
00863 return TS_NEVER;
00864
00865 }
00866 return TS_NEVER;
00867 }
00868
00869
00870
00871
00872
00873
00874
00875
00876
00878
00879
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896 TIMESTAMP rectifier::postsync(TIMESTAMP t0, TIMESTAMP t1)
00897 {
00898 TIMESTAMP t2 = TS_NEVER;
00900 return t2;
00901 }
00902
00904
00906
00907 EXPORT int create_rectifier(OBJECT **obj, OBJECT *parent)
00908 {
00909 try
00910 {
00911 *obj = gl_create_object(rectifier::oclass);
00912 if (*obj!=NULL)
00913 {
00914 rectifier *my = OBJECTDATA(*obj,rectifier);
00915 gl_set_parent(*obj,parent);
00916 return my->create();
00917 }
00918 }
00919 catch (char *msg)
00920 {
00921 gl_error("create_rectifier: %s", msg);
00922 }
00923
00924 return 0;
00925 }
00926
00927 EXPORT int init_rectifier(OBJECT *obj, OBJECT *parent)
00928 {
00929 try
00930 {
00931 if (obj!=NULL)
00932 return OBJECTDATA(obj,rectifier)->init(parent);
00933 }
00934 catch (char *msg)
00935 {
00936 gl_error("init_rectifier(obj=%d;%s): %s", obj->id, obj->name?obj->name:"unnamed", msg);
00937 }
00938
00939 return 0;
00940 }
00941
00942 EXPORT TIMESTAMP sync_rectifier(OBJECT *obj, TIMESTAMP t1, PASSCONFIG pass)
00943 {
00944 TIMESTAMP t2 = TS_NEVER;
00945 rectifier *my = OBJECTDATA(obj,rectifier);
00946 try
00947 {
00948 switch (pass) {
00949 case PC_PRETOPDOWN:
00950 t2 = my->presync(obj->clock,t1);
00951 break;
00952 case PC_BOTTOMUP:
00953 t2 = my->sync(obj->clock,t1);
00954 break;
00955 case PC_POSTTOPDOWN:
00956 t2 = my->postsync(obj->clock,t1);
00957 break;
00958 default:
00959 GL_THROW("invalid pass request (%d)", pass);
00960 break;
00961 }
00962 if (pass==clockpass)
00963 obj->clock = t1;
00964 }
00965 catch (char *msg)
00966 {
00967 gl_error("sync_rectifier(obj=%d;%s): %s", obj->id, obj->name?obj->name:"unnamed", msg);
00968 }
00969 return t2;
00970 }