00001
00018 #include <stdlib.h>
00019 #include <stdio.h>
00020 #include <errno.h>
00021 #include <math.h>
00022 #include <iostream>
00023 using namespace std;
00024
00025 #include "transformer.h"
00026
00027 CLASS* transformer::oclass = NULL;
00028 CLASS* transformer::pclass = NULL;
00029
00030 transformer::transformer(MODULE *mod) : link(mod)
00031 {
00032 if(oclass == NULL)
00033 {
00034 pclass = link::oclass;
00035
00036 oclass = gl_register_class(mod,"transformer",sizeof(transformer),PC_PRETOPDOWN|PC_BOTTOMUP|PC_POSTTOPDOWN|PC_UNSAFE_OVERRIDE_OMIT);
00037 if(oclass == NULL)
00038 GL_THROW("unable to register object class implemented by %s",__FILE__);
00039
00040 if(gl_publish_variable(oclass,
00041 PT_INHERIT, "link",
00042 PT_object, "configuration", PADDR(configuration),
00043 NULL) < 1) GL_THROW("unable to publish properties in %s",__FILE__);
00044 }
00045 }
00046
00047 int transformer::isa(char *classname)
00048 {
00049 return strcmp(classname,"transformer")==0 || link::isa(classname);
00050 }
00051
00052 int transformer::create()
00053 {
00054 int result = link::create();
00055 configuration = NULL;
00056 return result;
00057 }
00058
00059 int transformer::init(OBJECT *parent)
00060 {
00061 if (!configuration)
00062 throw "no transformer configuration specified.";
00063
00064
00065
00066
00067 if (!gl_object_isa(configuration, "transformer_configuration"))
00068 throw "invalid transformer configuration";
00069
00070
00071
00072
00073
00074
00075 double V_base,za_basehi,za_baselo,V_basehi;
00076 double sa_base;
00077 double nt, nt_a, nt_b, nt_c, inv_nt_a, inv_nt_b, inv_nt_c;
00078 complex zt, zt_a, zt_b, zt_c, z0, z1, z2, zc;
00079
00080 transformer_configuration *config = OBJECTDATA(configuration,
00081 transformer_configuration);
00082
00083 if (config->connect_type==3)
00084 SpecialLnk = DELTAGWYE;
00085 else if (config->connect_type==5)
00086 SpecialLnk = SPLITPHASE;
00087
00088 link::init(parent);
00089 OBJECT *obj = OBJECTHDR(this);
00090
00091 V_base = config->V_secondary;
00092 voltage_ratio = nt = config->V_primary / config->V_secondary;
00093 zt = (config->impedance * V_base * V_base) / (config->kVA_rating * 1000.0);
00094 zc = complex(V_base * V_base,0) / (config->kVA_rating * 1000.0) * complex(config->shunt_impedance.Re(),0) * complex(0,config->shunt_impedance.Im()) / complex(config->shunt_impedance.Re(),config->shunt_impedance.Im());
00095
00096 for (int i = 0; i < 3; i++)
00097 {
00098 for (int j = 0; j < 3; j++)
00099 a_mat[i][j] = b_mat[i][j] = c_mat[i][j] = d_mat[i][j] = A_mat[i][j] = B_mat[i][j] = 0.0;
00100 }
00101
00102 switch (config->connect_type) {
00103 case transformer_configuration::WYE_WYE:
00104 case transformer_configuration::SINGLE_PHASE:
00105 if (has_phase(PHASE_A))
00106 {
00107 nt_a = nt;
00108 zt_a = zt * nt_a;
00109 inv_nt_a = 1 / nt_a;
00110 c_mat[0][0] = complex(1,0) / ( complex(nt_a,0) * zc);
00111 }
00112 else
00113 {
00114 nt_a = inv_nt_a = 0.0;
00115 zt_a = complex(0,0);
00116 }
00117
00118 if (has_phase(PHASE_B))
00119 {
00120 nt_b = nt;
00121 zt_b = zt * nt_b;
00122 inv_nt_b = 1 / nt_b;
00123 c_mat[1][1] = complex(1,0) / ( complex(nt_b,0) * zc);
00124 }
00125 else
00126 {
00127 nt_b = inv_nt_b = 0.0;
00128 zt_b = complex(0,0);
00129 }
00130
00131 if (has_phase(PHASE_C))
00132 {
00133 nt_c = nt;
00134 zt_c = zt * nt_c;
00135 inv_nt_c = 1 / nt_c;
00136 c_mat[2][2] = complex(1,0) / ( complex(nt_c,0) * zc);
00137 }
00138 else
00139 {
00140 nt_c = inv_nt_c = 0.0;
00141 zt_c = complex(0,0);
00142 }
00143
00144 if (solver_method==SM_FBS)
00145 {
00146 if (has_phase(PHASE_A))
00147 {
00148 A_mat[0][0] = zc / ((zt + zc) * complex(nt,0));
00149 a_mat[0][0] = complex(nt,0) * (zt + zc)/zc;
00150 b_mat[0][0] = complex(nt_a,0) * zt_a;
00151 d_mat[0][0] = 1/nt;
00152
00153
00154
00155
00156
00157 }
00158
00159 if (has_phase(PHASE_B))
00160 {
00161 A_mat[1][1] = zc / ((zt + zc) * complex(nt,0));
00162 a_mat[1][1] = complex(nt,0) * (zt + zc)/zc;
00163 b_mat[1][1] = complex(nt_b,0) * zt_b;
00164 d_mat[1][1] = 1/nt;
00165
00166
00167
00168
00169 }
00170
00171 if (has_phase(PHASE_C))
00172 {
00173 A_mat[2][2] = zc / ((zt + zc) * complex(nt,0));
00174 a_mat[2][2] = complex(nt,0) * (zt + zc)/zc;
00175 b_mat[2][2] = complex(nt_c,0) * zt_c;
00176 d_mat[2][2] = 1/nt;
00177
00178
00179
00180
00181 }
00182 }
00183 else if ((solver_method==SM_GS) || (solver_method==SM_NR))
00184 {
00185 complex Izt = complex(1,0) / zt;
00186
00187
00188 if (has_phase(PHASE_A))
00189
00190 b_mat[0][0] = complex(1,0) / zt;
00191 if (has_phase(PHASE_B))
00192
00193 b_mat[1][1] = complex(1,0) / zt;
00194 if (has_phase(PHASE_C))
00195
00196 b_mat[2][2] = complex(1,0) / zt;
00197
00198
00199 A_mat[0][1] = A_mat[0][2] = A_mat[1][0] = A_mat[1][2] = A_mat[2][0] = A_mat[2][1] = 0.0;
00200 a_mat[0][1] = a_mat[0][2] = a_mat[1][0] = a_mat[1][2] = a_mat[2][0] = a_mat[2][1] = 0.0;
00201 c_mat[0][1] = c_mat[0][2] = c_mat[1][0] = c_mat[1][2] = c_mat[2][0] = c_mat[2][1] = 0.0;
00202
00203 if (has_phase(PHASE_A))
00204 {
00205
00206 a_mat[0][0] = 0;
00207 d_mat[0][0] = Izt / nt / nt;
00208 A_mat[0][0] = complex(nt,0);
00209 c_mat[0][0] = nt;
00210 }
00211 if (has_phase(PHASE_B))
00212 {
00213
00214 a_mat[1][1] = 0;
00215 d_mat[1][1] = Izt / nt / nt;
00216 A_mat[1][1] = complex(nt,0);
00217 c_mat[1][1] = nt;
00218 }
00219 if (has_phase(PHASE_C))
00220 {
00221
00222 a_mat[2][2] = 0;
00223 d_mat[2][2] = Izt / nt / nt;
00224 A_mat[2][2] = complex(nt,0);
00225 c_mat[2][2] = nt;
00226 }
00227
00228
00229 }
00230 else
00231 {
00232 GL_THROW("Unsupported solver method");
00233
00234
00235
00236
00237
00238 }
00239
00240 B_mat[0][0] = zt*zc/(zt+zc);
00241 B_mat[1][1] = zt*zc/(zt+zc);
00242 B_mat[2][2] = zt*zc/(zt+zc);
00243
00244 break;
00245 case transformer_configuration::DELTA_DELTA:
00246 if (solver_method==SM_FBS)
00247 {
00248 a_mat[0][0] = a_mat[1][1] = a_mat[2][2] = nt * 2.0 / 3.0;
00249 a_mat[0][1] = a_mat[0][2] = a_mat[1][0] = a_mat[1][2] = a_mat[2][0] = a_mat[2][1] = -nt / 3.0;
00250
00251 b_mat[0][0] = b_mat[1][1] = zt * nt;
00252 b_mat[2][0] = b_mat[2][1] = zt * -nt;
00253
00254 d_mat[0][0] = d_mat[1][1] = d_mat[2][2] = complex(1.0) / nt;
00255
00256 A_mat[0][0] = A_mat[1][1] = A_mat[2][2] = complex(2.0) / (nt * 3.0);
00257 A_mat[0][1] = A_mat[0][2] = A_mat[1][0] = A_mat[1][2] = A_mat[2][0] = A_mat[2][1] = complex(-1.0) / (nt * 3.0);
00258
00259 B_mat[0][0] = B_mat[1][1] = zt;
00260 B_mat[2][0] = B_mat[2][1] = -zt;
00261 }
00262 else if ((solver_method==SM_GS) || (solver_method==SM_NR))
00263 {
00264
00265 complex Izt = complex(1,0) / zt;
00266
00267 b_mat[0][0] = b_mat[1][1] = b_mat[2][2] = Izt;
00268
00269
00270
00271
00272
00273 d_mat[0][0] = Izt / nt / nt;
00274 d_mat[1][1] = Izt / nt / nt;
00275 d_mat[2][2] = Izt / nt / nt;
00276
00277
00278 A_mat[0][0] = A_mat[1][1] = A_mat[2][2] = nt;
00279
00280 }
00281 else
00282 {
00283 GL_THROW("Unsupported solver method");
00284
00285 }
00286 break;
00287 case transformer_configuration::DELTA_GWYE:
00288 if (solver_method==SM_FBS)
00289 {
00290 if (nt>1.0)
00291 {
00292 nt *= sqrt(3.0);
00293
00294 a_mat[0][1] = a_mat[1][2] = a_mat[2][0] = -nt * 2.0 / 3.0;
00295 a_mat[0][2] = a_mat[1][0] = a_mat[2][1] = -nt / 3.0;
00296
00297 b_mat[0][1] = b_mat[1][2] = b_mat[2][0] = zt * -nt * 2.0 / 3.0;
00298 b_mat[0][2] = b_mat[1][0] = b_mat[2][1] = zt * -nt / 3.0;
00299
00300 d_mat[0][0] = d_mat[1][1] = d_mat[2][2] = complex(1.0) / nt;
00301 d_mat[0][1] = d_mat[1][2] = d_mat[2][0] = complex(-1.0) / nt;
00302
00303 A_mat[0][0] = A_mat[1][1] = A_mat[2][2] = complex(1.0) / nt;
00304 A_mat[0][2] = A_mat[1][0] = A_mat[2][1] = complex(-1.0) / nt;
00305
00306 B_mat[0][0] = B_mat[1][1] = B_mat[2][2] = zt;
00307 }
00308 else {
00309 nt *= sqrt(3.0);
00310
00311 a_mat[0][0] = a_mat[1][1] = a_mat[2][2] = nt * 2.0 / 3.0;
00312 a_mat[0][1] = a_mat[1][2] = a_mat[2][0] = nt / 3.0;
00313
00314 b_mat[0][0] = b_mat[1][1] = b_mat[2][2] = zt * nt * 2.0 / 3.0;
00315 b_mat[0][1] = b_mat[1][2] = b_mat[2][0] = zt * nt/ 3.0;
00316
00317 d_mat[0][0] = d_mat[1][1] = d_mat[2][2] = complex(1.0) / nt;
00318 d_mat[0][2] = d_mat[1][0] = d_mat[2][1] = complex(-1.0) / nt;
00319
00320 A_mat[0][0] = A_mat[1][1] = A_mat[2][2] = complex(1.0) / nt;
00321 A_mat[0][1] = A_mat[1][2] = A_mat[2][0] = complex(-1.0) / nt;
00322
00323 B_mat[0][0] = B_mat[1][1] = B_mat[2][2] = zt;
00324 }
00325 }
00326 else if ((solver_method==SM_GS) || (solver_method==SM_NR))
00327 {
00328 SpecialLnk = DELTAGWYE;
00329
00330 complex Izt = complex(1.0,0) / zt;
00331
00332 complex alphaval = voltage_ratio * sqrt(3.0);
00333
00334 nt *= sqrt(3.0);
00335
00336 if (voltage_ratio>1.0)
00337 {
00338
00339 c_mat[0][0] = c_mat[1][1] = c_mat[2][2] = complex(1.0) / alphaval;
00340 c_mat[0][2] = c_mat[1][0] = c_mat[2][1] = complex(-1.0) / alphaval;
00341 c_mat[0][1] = c_mat[1][2] = c_mat[2][0] = 0.0;
00342
00343
00344 b_mat[0][0] = b_mat[1][1] = b_mat[2][2] = Izt;
00345 b_mat[0][1] = b_mat[0][2] = b_mat[1][0] = 0.0;
00346 b_mat[1][2] = b_mat[2][0] = b_mat[2][1] = 0.0;
00347
00348
00349 B_mat[0][0] = B_mat[1][1] = B_mat[2][2] = complex(1.0) / alphaval;
00350 B_mat[0][1] = B_mat[1][2] = B_mat[2][0] = complex(-1.0) / alphaval;
00351 B_mat[0][2] = B_mat[1][0] = B_mat[2][1] = 0.0;
00352
00353
00354 equalm(c_mat,a_mat);
00355 equalm(B_mat,d_mat);
00356
00357 A_mat[0][0] = A_mat[1][1] = A_mat[2][2] = complex(1.0) / nt;
00358 A_mat[0][2] = A_mat[1][0] = A_mat[2][1] = complex(-1.0) / nt;
00359 }
00360 else
00361 {
00362
00363 c_mat[0][0] = c_mat[1][1] = c_mat[2][2] = complex(1.0) / alphaval;
00364 c_mat[0][1] = c_mat[1][2] = c_mat[2][0] = complex(-1.0) / alphaval;
00365 c_mat[0][2] = c_mat[1][0] = c_mat[2][1] = 0.0;
00366
00367
00368 b_mat[0][0] = b_mat[1][1] = b_mat[2][2] = Izt;
00369 b_mat[0][1] = b_mat[0][2] = b_mat[1][0] = 0.0;
00370 b_mat[1][2] = b_mat[2][0] = b_mat[2][1] = 0.0;
00371
00372
00373 B_mat[0][0] = B_mat[1][1] = B_mat[2][2] = complex(1.0) / alphaval;
00374 B_mat[0][2] = B_mat[1][0] = B_mat[2][1] = complex(-1.0) / alphaval;
00375 B_mat[0][1] = B_mat[1][2] = B_mat[2][0] = 0.0;
00376
00377
00378 equalm(c_mat,a_mat);
00379 equalm(B_mat,d_mat);
00380
00381 A_mat[0][0] = A_mat[1][1] = A_mat[2][2] = complex(1.0) / nt;
00382 A_mat[0][1] = A_mat[1][2] = A_mat[2][0] = complex(-1.0) / nt;
00383 }
00384 }
00385 else
00386 {
00387 GL_THROW("Unsupported solver method");
00388
00389 }
00390
00391 break;
00392 case transformer_configuration::SINGLE_PHASE_CENTER_TAPPED:
00393 if (solver_method==SM_FBS)
00394 {
00395 if (has_phase(PHASE_A|PHASE_B))
00396 {
00397 throw "delta split tap is not supported yet";
00398 }
00399 else if (has_phase(PHASE_B|PHASE_C))
00400 {
00401 throw "delta split tap is not supported yet";
00402 }
00403 else if (has_phase(PHASE_A|PHASE_C))
00404 {
00405 throw "delta split tap is not supported yet";
00406 }
00407 else if (has_phase(PHASE_A))
00408 {
00409 V_basehi = config->V_primary;
00410 sa_base = config->phaseA_kVA_rating;
00411 if (sa_base==0)
00412 GL_THROW("Split-phase tranformer:%d trying to attach to phase A not defined in the configuration",obj->id);
00413
00414
00415
00416
00417
00418
00419 za_basehi = (V_basehi*V_basehi)/(sa_base*1000);
00420 za_baselo = (V_base * V_base)/(sa_base*1000);
00421
00422 if (config->impedance1.Re() == 0.0 && config->impedance1.Im() == 0.0)
00423 {
00424 z0 = complex(0.5 * config->impedance.Re(),0.8*config->impedance.Im()) * complex(za_basehi,0);
00425 z1 = complex(config->impedance.Re(),0.4 * config->impedance.Im()) * complex(za_baselo,0);
00426 z2 = complex(config->impedance.Re(),0.4 * config->impedance.Im()) * complex(za_baselo,0);
00427 }
00428 else
00429 {
00430 z0 = complex(config->impedance.Re(),config->impedance.Im()) * complex(za_basehi,0);
00431 z1 = complex(config->impedance1.Re(),config->impedance1.Im()) * complex(za_baselo,0);
00432 z2 = complex(config->impedance2.Re(),config->impedance2.Im()) * complex(za_baselo,0);
00433 }
00434
00435 zc = complex(za_basehi,0) * complex(config->shunt_impedance.Re(),0) * complex(0,config->shunt_impedance.Im()) / complex(config->shunt_impedance.Re(),config->shunt_impedance.Im());
00436 zt_b = complex(0,0);
00437 zt_c = complex(0,0);
00438
00439 a_mat[0][0] = a_mat[1][0] = (z0 / zc + complex(1,0))*nt;
00440
00441 c_mat[0][0] = complex(1,0)*nt / zc;
00442
00443 d_mat[0][0] = complex(1,0)/nt + complex(nt,0)*z1 / zc;
00444 d_mat[0][1] = complex(-1,0)/nt;
00445
00446 A_mat[0][0] = A_mat[1][0] = (zc / (zc + z0) ) * complex(1,0)/nt;
00447 }
00448
00449 else if (has_phase(PHASE_B))
00450 {
00451 V_basehi = config->V_primary;
00452 sa_base = config->phaseB_kVA_rating;
00453 if (sa_base==0)
00454 GL_THROW("Split-phase tranformer:%d trying to attach to phase B not defined in the configuration",obj->id);
00455
00456
00457
00458
00459
00460
00461 za_basehi = (V_basehi*V_basehi)/(sa_base*1000);
00462 za_baselo = (V_base * V_base)/(sa_base*1000);
00463
00464 if (config->impedance1.Re() == 0.0 && config->impedance1.Im() == 0.0)
00465 {
00466 z0 = complex(0.5 * config->impedance.Re(),0.8*config->impedance.Im()) * complex(za_basehi,0);
00467 z1 = complex(config->impedance.Re(),0.4 * config->impedance.Im()) * complex(za_baselo,0);
00468 z2 = complex(config->impedance.Re(),0.4 * config->impedance.Im()) * complex(za_baselo,0);
00469 }
00470 else
00471 {
00472 z0 = complex(config->impedance.Re(),config->impedance.Im()) * complex(za_basehi,0);
00473 z1 = complex(config->impedance1.Re(),config->impedance1.Im()) * complex(za_baselo,0);
00474 z2 = complex(config->impedance2.Re(),config->impedance2.Im()) * complex(za_baselo,0);
00475 }
00476
00477 zc = complex(za_basehi,0) * complex(config->shunt_impedance.Re(),0) * complex(0,config->shunt_impedance.Im()) / complex(config->shunt_impedance.Re(),config->shunt_impedance.Im());
00478 zt_b = complex(0,0);
00479 zt_c = complex(0,0);
00480
00481 a_mat[0][1] = a_mat[1][1] = (z0 / zc + complex(1,0))*nt;
00482
00483 c_mat[1][0] = complex(1,0)*nt / zc;
00484
00485 d_mat[1][0] = complex(1,0)/nt + complex(nt,0)*z1 / zc;
00486 d_mat[1][1] = complex(-1,0)/nt;
00487
00488 A_mat[0][1] = A_mat[1][1] = (zc / (zc + z0) ) * complex(1,0)/nt;
00489 }
00490 else if (has_phase(PHASE_C))
00491 {
00492 V_basehi = config->V_primary;
00493 sa_base = config->phaseC_kVA_rating;
00494 if (sa_base==0)
00495 GL_THROW("Split-phase tranformer:%d trying to attach to phase C not defined in the configuration",obj->id);
00496
00497
00498
00499
00500
00501
00502 za_basehi = (V_basehi*V_basehi)/(sa_base*1000);
00503 za_baselo = (V_base * V_base)/(sa_base*1000);
00504
00505 if (config->impedance1.Re() == 0.0 && config->impedance1.Im() == 0.0)
00506 {
00507 z0 = complex(0.5 * config->impedance.Re(),0.8*config->impedance.Im()) * complex(za_basehi,0);
00508 z1 = complex(config->impedance.Re(),0.4 * config->impedance.Im()) * complex(za_baselo,0);
00509 z2 = complex(config->impedance.Re(),0.4 * config->impedance.Im()) * complex(za_baselo,0);
00510 }
00511 else
00512 {
00513 z0 = complex(config->impedance.Re(),config->impedance.Im()) * complex(za_basehi,0);
00514 z1 = complex(config->impedance1.Re(),config->impedance1.Im()) * complex(za_baselo,0);
00515 z2 = complex(config->impedance2.Re(),config->impedance2.Im()) * complex(za_baselo,0);
00516 }
00517
00518 zc = complex(za_basehi,0) * complex(config->shunt_impedance.Re(),0) * complex(0,config->shunt_impedance.Im()) / complex(config->shunt_impedance.Re(),config->shunt_impedance.Im());
00519 zt_b = complex(0,0);
00520 zt_c = complex(0,0);
00521
00522 a_mat[0][2] = a_mat[1][2] = (z0 / zc + complex(1,0))*nt;
00523
00524 c_mat[2][0] = complex(1,0)*nt / zc;
00525
00526 d_mat[2][0] = complex(1,0)/nt + complex(nt,0)*z1 / zc;
00527 d_mat[2][1] = complex(-1,0)/nt;
00528
00529 A_mat[0][2] = A_mat[1][2] = (zc / (zc + z0) ) * complex(1,0)/nt;
00530
00531 }
00532
00533 b_mat[0][0] = (z0 / zc + complex(1,0))*(z1*nt) + z0/nt;
00534 b_mat[0][1] = complex(-1,0) * (z0/nt);
00535 b_mat[0][2] = complex(0,0);
00536 b_mat[1][0] = (z0/nt);
00537 b_mat[1][1] = -(z0 / zc + complex(1,0))*(z2*nt) - z0/nt;
00538 b_mat[1][2] = complex(0,0);
00539 b_mat[2][0] = complex(0,0);
00540 b_mat[2][1] = complex(0,0);
00541 b_mat[2][2] = complex(0,0);
00542
00543 B_mat[0][0] = (z1) + (z0*zc/((zc + z0)*nt*nt));
00544 B_mat[0][1] = -(z0*zc/((zc + z0)*nt*nt));
00545 B_mat[1][0] = (z0*zc/((zc + z0)*nt*nt));
00546 B_mat[1][1] = complex(-1,0) * ((z2) + (z0*zc/((zc + z0)*nt*nt)));
00547 B_mat[1][2] = complex(0,0);
00548 B_mat[2][0] = complex(0,0);
00549 B_mat[2][1] = complex(0,0);
00550 B_mat[2][2] = complex(0,0);
00551 }
00552 else if (solver_method==SM_GS)
00553 {
00554 GL_THROW("Gauss-Seidel Implementation of Split-Phase is not complete");
00555
00556
00557
00558
00559 }
00560 else if (solver_method==SM_NR)
00561 {
00562 SpecialLnk = SPLITPHASE;
00563
00564 V_basehi = config->V_primary;
00565
00566 if (has_phase(PHASE_A))
00567 {
00568 sa_base = config->phaseA_kVA_rating;
00569 if (sa_base==0)
00570 GL_THROW("Split-phase tranformer:%d trying to attach to phase A not defined in the configuration",obj->id);
00571
00572
00573
00574
00575
00576 }
00577 else if (has_phase(PHASE_B))
00578 {
00579 sa_base = config->phaseB_kVA_rating;
00580 if (sa_base==0)
00581 GL_THROW("Split-phase tranformer:%d trying to attach to phase B not defined in the configuration",obj->id);
00582
00583
00584
00585
00586
00587 }
00588 else if (has_phase(PHASE_C))
00589 {
00590 sa_base = config->phaseC_kVA_rating;
00591 if (sa_base==0)
00592 GL_THROW("Split-phase tranformer:%d trying to attach to phase C not defined in the configuration",obj->id);
00593
00594
00595
00596
00597
00598 }
00599
00600 za_basehi = (V_basehi*V_basehi)/(sa_base*1000);
00601 za_baselo = (V_base * V_base)/(sa_base*1000);
00602
00603 if (config->impedance1.Re() == 0.0 && config->impedance1.Im() == 0.0)
00604 {
00605 z0 = complex(0.5 * config->impedance.Re(),0.8*config->impedance.Im()) * complex(za_basehi,0);
00606 z1 = complex(config->impedance.Re(),0.4 * config->impedance.Im()) * complex(za_baselo,0);
00607 z2 = complex(config->impedance.Re(),0.4 * config->impedance.Im()) * complex(za_baselo,0);
00608 }
00609 else
00610 {
00611 z0 = complex(config->impedance.Re(),config->impedance.Im()) * complex(za_basehi,0);
00612 z1 = complex(config->impedance1.Re(),config->impedance1.Im()) * complex(za_baselo,0);
00613 z2 = complex(config->impedance2.Re(),config->impedance2.Im()) * complex(za_baselo,0);
00614 }
00615
00616
00617
00618 zc = complex(za_basehi,0) * complex(config->shunt_impedance.Re(),0) * complex(0,config->shunt_impedance.Im()) / complex(config->shunt_impedance.Re(),config->shunt_impedance.Im());
00619
00620
00621 complex indet;
00622 indet=complex(1.0)/(z1*z2*zc*nt*nt+z0*(z2*zc+z1*zc+z1*z2*nt*nt));
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637 a_mat[0][0] = -(z2*zc*nt*nt+z0*zc+z0*z2*nt*nt);
00638 a_mat[0][1] = z0*zc;
00639 a_mat[1][0] = -z0*zc;
00640 a_mat[1][1] = (z1*zc*nt*nt+z0*zc+z0*z1*nt*nt);
00641
00642
00643 a_mat[0][2] = z2*zc*nt;
00644 a_mat[1][2] = -z1*zc*nt;
00645
00646
00647 a_mat[2][0] = -z2*zc*nt;
00648 a_mat[2][1] = -z1*zc*nt;
00649
00650
00651 a_mat[2][2] = (z2*zc+z1*zc+z1*z2*nt*nt);
00652
00653
00654 for (char xindex=0; xindex<3; xindex++)
00655 {
00656 for (char yindex=0; yindex<3; yindex++)
00657 {
00658 b_mat[xindex][yindex]=a_mat[xindex][yindex]*indet;
00659 a_mat[xindex][yindex]=0.0;
00660 }
00661 }
00662 }
00663 else
00664 {
00665 throw "Unsupported solver method";
00666
00667 }
00668
00669 break;
00670 default:
00671 throw "unknown transformer connect type";
00672
00673
00674
00675
00676
00677 }
00678
00679 #ifdef _TESTING
00680 extern bool show_matrix_values;
00681 if (show_matrix_values)
00682 {
00683 gl_testmsg("transformer:\ta matrix");
00684 print_matrix(a_mat);
00685 gl_testmsg("transformer:\tA matrix");
00686 print_matrix(A_mat);
00687 gl_testmsg("transformer:\tb matrix");
00688 print_matrix(b_mat);
00689 gl_testmsg("transformer:\tB matrix");
00690 print_matrix(B_mat);
00691 gl_testmsg("transformer:\td matrix");
00692 print_matrix(d_mat);
00693 }
00694 #endif
00695
00696 return 1;
00697 }
00698
00700
00702
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727 EXPORT int create_transformer(OBJECT **obj, OBJECT *parent)
00728 {
00729 try
00730 {
00731 *obj = gl_create_object(transformer::oclass);
00732 if (*obj!=NULL)
00733 {
00734 transformer *my = OBJECTDATA(*obj,transformer);
00735 gl_set_parent(*obj,parent);
00736 return my->create();
00737 }
00738 }
00739 catch (const char *msg)
00740 {
00741 gl_error("create_transformer: %s", msg);
00742 }
00743 return 0;
00744 }
00745
00746
00747
00754 EXPORT int init_transformer(OBJECT *obj)
00755 {
00756 transformer *my = OBJECTDATA(obj,transformer);
00757 try {
00758 return my->init(obj->parent);
00759 }
00760 catch (const char *msg)
00761 {
00762 GL_THROW("%s (transformer:%d): %s", my->get_name(), my->get_id(), msg);
00763 return 0;
00764 }
00765 }
00766
00775 EXPORT TIMESTAMP sync_transformer(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass)
00776 {
00777 transformer *pObj = OBJECTDATA(obj,transformer);
00778 try {
00779 TIMESTAMP t1 = TS_NEVER;
00780 switch (pass) {
00781 case PC_PRETOPDOWN:
00782 return pObj->presync(t0);
00783 case PC_BOTTOMUP:
00784 return pObj->sync(t0);
00785 case PC_POSTTOPDOWN:
00786 t1 = pObj->postsync(t0);
00787 obj->clock = t0;
00788 return t1;
00789 default:
00790 throw "invalid pass request";
00791 }
00792 } catch (const char *error) {
00793 GL_THROW("%s (transformer:%d): %s", pObj->get_name(), pObj->get_id(), error);
00794 return 0;
00795 } catch (...) {
00796 GL_THROW("%s (transformer:%d): %s", pObj->get_name(), pObj->get_id(), "unknown exception");
00797 return 0;
00798 }
00799 }
00800
00801 EXPORT int isa_transformer(OBJECT *obj, char *classname)
00802 {
00803 return OBJECTDATA(obj,transformer)->isa(classname);
00804 }
00805