00001
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <errno.h>
00027 #include <math.h>
00028 #include <iostream>
00029 using namespace std;
00030
00031 #include "transformer.h"
00032
00034
00036 CLASS* transformer_configuration::oclass = NULL;
00037 CLASS* transformer_configuration::pclass = NULL;
00038
00039 transformer_configuration::transformer_configuration(MODULE *mod) : powerflow_library(mod)
00040 {
00041 if(oclass == NULL)
00042 {
00043 oclass = gl_register_class(mod,"transformer_configuration",sizeof(transformer_configuration),PC_BOTTOMUP|PC_POSTTOPDOWN);
00044 if(oclass == NULL)
00045 GL_THROW("unable to register object class implemented by %s",__FILE__);
00046
00047 if(gl_publish_variable(oclass,
00048 PT_enumeration,"connect_type",PADDR(connect_type),
00049 PT_KEYWORD,"UNKNOWN",UNKNOWN,
00050 PT_KEYWORD,"WYE_WYE",WYE_WYE,
00051 PT_KEYWORD,"DELTA_DELTA",DELTA_DELTA,
00052 PT_KEYWORD,"DELTA_GWYE",DELTA_GWYE,
00053 PT_KEYWORD,"SINGLE_PHASE",SINGLE_PHASE,
00054 PT_KEYWORD,"SINGLE_PHASE_CENTER_TAPPED",SINGLE_PHASE_CENTER_TAPPED,
00055 PT_enumeration,"install_type",PADDR(install_type),
00056 PT_KEYWORD,"UNKNOWN",UNKNOWN,
00057 PT_KEYWORD,"POLETOP",POLETOP,
00058 PT_KEYWORD,"PADMOUNT",PADMOUNT,
00059 PT_KEYWORD,"VAULT",VAULT,
00060
00061 PT_double, "primary_voltage[V]", PADDR(V_primary),
00062 PT_double, "secondary_voltage[V]",PADDR(V_secondary),
00063 PT_double, "power_rating[kVA]",PADDR(kVA_rating),
00064 PT_double, "powerA_rating[kVA]",PADDR(phaseA_kVA_rating),
00065 PT_double, "powerB_rating[kVA]",PADDR(phaseB_kVA_rating),
00066 PT_double, "powerC_rating[kVA]",PADDR(phaseC_kVA_rating),
00067 PT_double, "resistance[pu.Ohm]",PADDR(impedance.Re()),
00068 PT_double, "reactance[pu.Ohm]",PADDR(impedance.Im()),
00069 PT_complex, "impedance[pu.Ohm]",PADDR(impedance),
00070 PT_double, "resistance1[pu.Ohm]",PADDR(impedance1.Re()),
00071 PT_double, "reactance1[pu.Ohm]",PADDR(impedance1.Im()),
00072 PT_complex, "impedance1[pu.Ohm]",PADDR(impedance1),
00073 PT_double, "resistance2[pu.Ohm]",PADDR(impedance2.Re()),
00074 PT_double, "reactance2[pu.Ohm]",PADDR(impedance2.Im()),
00075 PT_complex, "impedance2[pu.Ohm]",PADDR(impedance2),
00076 PT_double, "shunt_resistance[pu.Ohm]",PADDR(shunt_impedance.Re()),
00077 PT_double, "shunt_reactance[pu.Ohm]",PADDR(shunt_impedance.Im()),
00078 PT_complex, "shunt_impedance[pu.Ohm]",PADDR(shunt_impedance),
00079
00080 NULL) < 1) GL_THROW("unable to publish properties in %s",__FILE__);
00081 }
00082 }
00083
00084 int transformer_configuration::isa(char *classname)
00085 {
00086 return strcmp(classname,"transformer_configuration")==0;
00087 }
00088
00089 int transformer_configuration::create(void)
00090 {
00091 int result = powerflow_library::create();
00092 memset(&connect_type,0,sizeof(connect_type));
00093 memset(&install_type,0,sizeof(install_type));
00094 V_primary = 0.0;
00095 V_secondary = 0.0;
00096 phaseA_kVA_rating = 0.0;
00097 phaseB_kVA_rating = 0.0;
00098 phaseC_kVA_rating = 0.0;
00099 kVA_rating = 0;
00100 impedance = impedance1 = impedance2 = complex(0.0,0.0);
00101 shunt_impedance = complex(999999999,999999999);
00102 no_load_loss = full_load_loss = 0.0;
00103 return result;
00104 }
00105
00106 int transformer_configuration::init(OBJECT *parent)
00107 {
00108
00109 OBJECT *obj = OBJECTHDR(this);
00110
00111
00112 if (kVA_rating==0)
00113
00114
00115 kVA_rating = phaseA_kVA_rating+phaseB_kVA_rating+phaseC_kVA_rating;
00116
00117
00118 if (phaseA_kVA_rating+phaseB_kVA_rating+phaseC_kVA_rating==0 && kVA_rating>0)
00119 phaseA_kVA_rating = phaseB_kVA_rating = phaseC_kVA_rating = kVA_rating/3;
00120
00121
00122 if (connect_type==UNKNOWN)
00123 throw "connection type not specified";
00124
00125
00126 if (install_type==UNKNOWN)
00127 gl_warning("installation type not specified");
00128
00129
00130 if (V_secondary==0)
00131 throw "V_secondary must be positive";
00132
00133
00134
00135
00136
00137 if (kVA_rating<=0)
00138 throw "kVA_rating(s) must be positive";
00139 if (fabs((kVA_rating-phaseA_kVA_rating-phaseB_kVA_rating-phaseC_kVA_rating)/kVA_rating)>0.01)
00140 throw "kVA rating mismatch across phases exceeds 1%";
00141
00142
00143 if (connect_type!=SINGLE_PHASE_CENTER_TAPPED)
00144 {
00145 if ((impedance1.Re() != 0.0 && impedance1.Im() != 0.0) || (impedance2.Re() != 0.0 && impedance2.Im() != 0.0))
00146 gl_warning("This connection type on transformer:%d (%s) does not support impedance (impedance1 or impedance2) of secondaries at this time.",obj->id,obj->name);
00147
00148
00149
00150
00151 if (connect_type!=WYE_WYE)
00152 {
00153 if (shunt_impedance.Re() != 999999999 || shunt_impedance.Im() != 999999999)
00154 gl_warning("This connection type on transformer:%d (%s) does not support shunt_impedance at this time.",obj->id,obj->name);
00155
00156
00157
00158
00159 }
00160 if (no_load_loss != 0.0 || full_load_loss != 0.0)
00161 gl_warning("This connection type on transformer:%d (%s) does not support shunt_impedance at this time.",obj->id,obj->name);
00162
00163
00164
00165
00166 }
00167 else
00168 {
00169 if ((impedance1.Re() == 0.0 && impedance1.Im() == 0.0) && (impedance2.Re() != 0.0 && impedance2.Im() != 0.0))
00170 {
00171 impedance1 = impedance2;
00172 gl_warning("impedance2 was defined, but impedance1 was not -- assuming they are equal");
00173 }
00174 else if ((impedance1.Re() != 0.0 && impedance1.Im() != 0.0) && (impedance2.Re() == 0.0 && impedance2.Im() == 0.0))
00175 {
00176 impedance2 = impedance1;
00177 gl_warning("impedance1 was defined, but impedance2 was not -- assuming they are equal");
00178 }
00179
00180 }
00181
00182 if (impedance.Re()<0 || impedance1.Re()<0 || impedance2.Re()<0)
00183 throw "resistance must be non-negative";
00184 if (impedance.Im()<0 || impedance1.Im()<0 || impedance2.Im()<0)
00185 throw "reactance must be non-negative";
00186 if (shunt_impedance.Re()<0)
00187 throw "shunt_resistance must be non-negative";
00188 if (shunt_impedance.Im()<0)
00189 throw "shunt_reactance must be non-negative";
00190 return 1;
00191 }
00192
00194
00196
00204 EXPORT int create_transformer_configuration(OBJECT **obj, OBJECT *parent)
00205 {
00206 try
00207 {
00208 *obj = gl_create_object(transformer_configuration::oclass);
00209 if (*obj!=NULL)
00210 {
00211 transformer_configuration *my = OBJECTDATA(*obj,transformer_configuration);
00212 gl_set_parent(*obj,parent);
00213 return my->create();
00214 }
00215 }
00216 catch (const char *msg)
00217 {
00218 gl_error("%s %s (id=%d): %s", (*obj)->name?(*obj)->name:"unnamed", (*obj)->oclass->name, (*obj)->id, msg);
00219 return 0;
00220 }
00221 return 1;
00222 }
00223
00224 EXPORT int init_transformer_configuration(OBJECT *obj, OBJECT *parent)
00225 {
00226 try {
00227 return OBJECTDATA(obj,transformer_configuration)->init(parent);
00228 }
00229 catch (const char *msg)
00230 {
00231 gl_error("%s %s (id=%d): %s", obj->name?obj->name:"unnamed", obj->oclass->name, obj->id, msg);
00232 return 0;
00233 }
00234 return 1;
00235 }
00236
00237 EXPORT TIMESTAMP sync_transformer_configuration(OBJECT *obj, TIMESTAMP t1, PASSCONFIG pass)
00238 {
00239 return TS_NEVER;
00240 }
00241
00242 EXPORT int isa_transformer_configuration(OBJECT *obj, char *classname)
00243 {
00244 return OBJECTDATA(obj,transformer_configuration)->isa(classname);
00245 }
00246