00001
00009 #include <stdlib.h>
00010 #include <stdio.h>
00011 #include <errno.h>
00012 #include <math.h>
00013 #include <iostream>
00014 using namespace std;
00015
00016 #include "line.h"
00017
00018 CLASS* triplex_line::oclass = NULL;
00019 CLASS* triplex_line::pclass = NULL;
00020 triplex_line *triplex_line::defaults = NULL;
00021
00022 triplex_line::triplex_line(MODULE *mod) : line(mod)
00023 {
00024 if(oclass == NULL)
00025 {
00026 pclass = line::oclass;
00027
00028 oclass = gl_register_class(mod,"triplex_line",PC_BOTTOMUP|PC_POSTTOPDOWN);
00029 if(oclass == NULL)
00030 GL_THROW("unable to register object class implemented by %s",__FILE__);
00031
00032 if(gl_publish_variable(oclass,
00033 PT_object, "from",PADDR(from),
00034 PT_object, "to", PADDR(to),
00035 PT_object, "configuration",PADDR(configuration),
00036 PT_double, "length[ft]",PADDR(length),
00037 PT_set, "phases", PADDR(phases),
00038 PT_KEYWORD, "A",PHASE_A,
00039 PT_KEYWORD, "B",PHASE_B,
00040 PT_KEYWORD, "C",PHASE_C,
00041 PT_KEYWORD, "N",PHASE_N,
00042 PT_KEYWORD, "S",PHASE_S,
00043 NULL) < 1) GL_THROW("unable to publish properties in %s",__FILE__);
00044
00045
00046 memset(this,0,sizeof(triplex_line));
00047 defaults = this;
00048 }
00049 }
00050
00051 int triplex_line::create(void)
00052 {
00053 int result = line::create();
00054 memcpy(this,defaults,sizeof(triplex_line));
00055 return result;
00056 }
00057
00058 int triplex_line::isa(char *classname)
00059 {
00060 return strcmp(classname,"triplex_line")==0 || line::isa(classname);
00061 }
00062
00063 int triplex_line::init()
00064 {
00065
00066 double dcond,ins_thick,D12,D13,D23;
00067 double r1,r2,rn,gmr1,gmr2,gmrn;
00068 complex zp11,zp22,zp33,zp12,zp13,zp23;
00069
00070 complex zs[3][3];
00071 complex tn[2];
00072
00073 int result = line::init();
00074
00075
00076 triplex_line_configuration *line_config = OBJECTDATA(configuration,triplex_line_configuration);
00077 dcond = line_config->diameter;
00078 ins_thick = line_config->ins_thickness;
00079
00080 triplex_line_conductor *l1 = OBJECTDATA(line_config->phaseA_conductor,triplex_line_conductor);
00081 triplex_line_conductor *l2 = OBJECTDATA(line_config->phaseB_conductor,triplex_line_conductor);
00082 triplex_line_conductor *lN = OBJECTDATA(line_config->phaseC_conductor,triplex_line_conductor);
00083
00084 r1 = l1->resistance;
00085 r2 = l2->resistance;
00086 rn = lN->resistance;
00087 gmr1 = l1->geometric_mean_radius;
00088 gmr2 = l2->geometric_mean_radius;
00089 gmrn = lN->geometric_mean_radius;
00090
00091
00092 D12 = (dcond + 2 * ins_thick)/12;
00093 D13 = (dcond + ins_thick)/12;
00094 D23 = D13;
00095
00096 zp11 = complex(r1,0) + 0.09530 + complex(0.0,0.12134) * (log(1/gmr1) + 7.93402);
00097 zp22 = complex(r2,0) + 0.09530 + complex(0.0,0.12134) * (log(1/gmr2) + 7.93402);
00098 zp33 = complex(rn,0) + 0.09530 + complex(0.0,0.12134) * (log(1/gmrn) + 7.93402);
00099 zp12 = complex(0.09530,0.0) + complex(0.0,0.12134) * (log(1/D12) + 7.93402);
00100 zp13 = complex(0.09530,0.0) + complex(0.0,0.12134) * (log(1/D13) + 7.93402);
00101 zp23 = complex(0.09530,0.0) + complex(0.0,0.12134) * (log(1/D23) + 7.93402);
00102
00103 zs[0][0] = zp11-((zp13^2)/zp33);
00104 zs[0][1] = zp12-((zp13*zp23)/zp33);
00105 zs[1][0] = zp12-((zp13*zp23)/zp33);
00106 zs[1][1] = zp22-((zp23*zp23)/zp33);
00107 zs[0][2] = complex(0,0);
00108 zs[1][2] = complex(0,0);
00109 zs[2][2] = complex(0,0);
00110 zs[2][1] = complex(0,0);
00111 zs[2][0] = complex(0,0);
00112
00113
00114
00115
00116
00117
00118 a_mat[0][0] = complex(1,0);
00119 a_mat[0][1] = complex(0,0);
00120 a_mat[0][2] = complex(0,0);
00121 a_mat[1][0] = complex(0,0);
00122 a_mat[1][1] = complex(1,0);
00123 a_mat[1][2] = complex(0,0);
00124 a_mat[2][0] = complex(0,0);
00125 a_mat[2][1] = complex(0,0);
00126 a_mat[2][2] = complex(1,0);
00127
00128 c_mat[0][0] = complex(0,0);
00129 c_mat[0][1] = complex(0,0);
00130 c_mat[0][2] = complex(0,0);
00131 c_mat[1][0] = complex(0,0);
00132 c_mat[1][1] = complex(0,0);
00133 c_mat[1][2] = complex(0,0);
00134 c_mat[2][0] = complex(0,0);
00135 c_mat[2][1] = complex(0,0);
00136 c_mat[2][2] = complex(0,0);
00137
00138 d_mat[0][0] = complex(1,0);
00139 d_mat[0][1] = complex(0,0);
00140 d_mat[0][2] = complex(0,0);
00141 d_mat[1][0] = complex(0,0);
00142 d_mat[1][1] = complex(1,0);
00143 d_mat[1][2] = complex(0,0);
00144 d_mat[2][0] = complex(0,0);
00145 d_mat[2][1] = complex(0,0);
00146 d_mat[2][2] = complex(1,0);
00147
00148 A_mat[0][0] = complex(1,0);
00149 A_mat[0][1] = complex(0,0);
00150 A_mat[0][2] = complex(0,0);
00151 A_mat[1][0] = complex(0,0);
00152 A_mat[1][1] = complex(1,0);
00153 A_mat[1][2] = complex(0,0);
00154 A_mat[2][0] = complex(0,0);
00155 A_mat[2][1] = complex(0,0);
00156 A_mat[2][2] = complex(1,0);
00157
00158 multiply(length/5280.0,zs,b_mat);
00159 multiply(length/5280.0,zs,B_mat);
00160
00161
00162 #ifdef _TESTING
00163 if (show_matrix_values)
00164 {
00165 gl_testmsg("triplex_line: a matrix");
00166 print_matrix(a_mat);
00167
00168 gl_testmsg("triplex_line: A matrix");
00169 print_matrix(A_mat);
00170
00171 gl_testmsg("triplex_line: b matrix");
00172 print_matrix(b_mat);
00173
00174 gl_testmsg("triplex_line: B matrix");
00175 print_matrix(B_mat);
00176
00177 gl_testmsg("triplex_line: c matrix");
00178 print_matrix(c_mat);
00179
00180 gl_testmsg("triplex_line: d matrix");
00181 print_matrix(d_mat);
00182 }
00183 #endif
00184 return result;
00185 }
00186
00188
00190
00198 EXPORT int create_triplex_line(OBJECT **obj, OBJECT *parent)
00199 {
00200 try
00201 {
00202 *obj = gl_create_object(triplex_line::oclass,sizeof(triplex_line));
00203 if (*obj!=NULL)
00204 {
00205 triplex_line *my = OBJECTDATA(*obj,triplex_line);
00206 gl_set_parent(*obj,parent);
00207 return my->create();
00208 }
00209 }
00210 catch (char *msg)
00211 {
00212 gl_error("create_triplex_line: %s", msg);
00213 }
00214 return 1;
00215 }
00216
00217 EXPORT TIMESTAMP sync_triplex_line(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass)
00218 {
00219 triplex_line *pObj = OBJECTDATA(obj,triplex_line);
00220 try {
00221 if (pass==PC_BOTTOMUP)
00222 return pObj->sync(t0);
00223 else
00224 {
00225 TIMESTAMP t1 = pObj->postsync(t0);
00226 obj->clock = t0;
00227 return t1;
00228 }
00229 } catch (const char *error) {
00230 GL_THROW("%s (%s:%d): %s", pObj->get_name(), pObj->get_id(), error);
00231 return 0;
00232 } catch (...) {
00233 GL_THROW("%s (%s:%d): %s", pObj->get_name(), pObj->get_id(), "unknown exception");
00234 return 0;
00235 }
00236 }
00237
00238 EXPORT int init_triplex_line(OBJECT *obj)
00239 {
00240 triplex_line *my = OBJECTDATA(obj,triplex_line);
00241 try {
00242 return my->init();
00243 }
00244 catch (char *msg)
00245 {
00246 GL_THROW("%s (triplex_line:%d): %s", my->get_name(), my->get_id(), msg);
00247 return 0;
00248 }
00249 }
00250
00251 EXPORT int isa_triplex_line(OBJECT *obj, char *classname)
00252 {
00253 return OBJECTDATA(obj,triplex_line)->isa(classname);
00254 }
00255