00001
00047 #include <stdlib.h>
00048 #include <stdio.h>
00049 #include <errno.h>
00050 #include <math.h>
00051
00052 #include "powerflow.h"
00053 #include "node.h"
00054 #include "link.h"
00055
00057
00059 CLASS* powerflow_object::oclass = NULL;
00060 CLASS* powerflow_object::pclass = NULL;
00061 powerflow_object *powerflow_object::defaults = NULL;
00062
00063 powerflow_object::powerflow_object(MODULE *mod)
00064 {
00065 if (oclass==NULL)
00066 {
00067 oclass = gl_register_class(mod,"powerflow_object",0x00);
00068 if (oclass==NULL)
00069 GL_THROW("unable to register object class implemented by %s",__FILE__);
00070 }
00071
00072 memset(this,0,sizeof(powerflow_object));
00073 defaults = this;
00074 phases = NO_PHASE;
00075 condition = OC_NORMAL;
00076 solution = PS_NORMAL;
00077 }
00078
00079 int powerflow_object::isa(char *classname)
00080 {
00081 return strcmp(classname,"powerflow_object")==0;
00082 }
00083
00084 int powerflow_object::create(void)
00085 {
00086 memcpy(this,defaults,sizeof(powerflow_object));
00087 return 1;
00088 }
00089
00090 int powerflow_object::init(void)
00091 {
00092
00093 if (has_phase(PHASE_S) && !(has_phase(PHASE_A) || has_phase(PHASE_B) || has_phase(PHASE_C)))
00094 throw "split connection is missing A,B, or C phase connection";
00095
00096
00097 if (has_phase(PHASE_S) && (
00098 (has_phase(PHASE_A) && has_phase(PHASE_B)) ||
00099 (has_phase(PHASE_B) && has_phase(PHASE_C)) ||
00100 (has_phase(PHASE_C) && has_phase(PHASE_A))))
00101 throw "split connection is connected to two phases simultaneously";
00102
00103
00104 if (has_phase(PHASE_S) && has_phase(PHASE_D))
00105 throw "split and delta connection cannot occur simultaneously";
00106
00107
00108 if (has_phase(PHASE_N) && has_phase(PHASE_S))
00109 {
00110 gl_warning("neutral phase ignored on split connection.");
00111 phases ^= PHASE_N;
00112 }
00113
00114 return 1;
00115 }
00116
00117 TIMESTAMP powerflow_object::sync(TIMESTAMP t0)
00118 {
00119 return TS_NEVER;
00120 }
00121
00122 TIMESTAMP powerflow_object::postsync(TIMESTAMP t0)
00123 {
00124 return TS_NEVER;
00125 }
00126
00128
00130
00138 EXPORT int create_powerflow_object(OBJECT **obj, OBJECT *parent)
00139 {
00140 try
00141 {
00142 *obj = gl_create_object(powerflow_object::oclass,sizeof(powerflow_object));
00143 if (*obj==NULL)
00144 throw "unable to create powerflow_object";
00145 gl_set_parent(*obj,parent);
00146 return OBJECTDATA(*obj,powerflow_object)->create();
00147 }
00148 catch (char *msg)
00149 {
00150 gl_error("create_powerflow_object: %s", msg);
00151 return 0;
00152 }
00153 }
00154
00161 EXPORT int init_powerflow_object(OBJECT *obj)
00162 {
00163 powerflow_object *my = OBJECTDATA(obj,powerflow_object);
00164 try {
00165 return my->init();
00166 }
00167 catch (char *msg)
00168 {
00169 GL_THROW("%s (powerflow_object:%d): %s", my->get_name(), my->get_id(), msg);
00170 return 0;
00171 }
00172 }
00173
00181 EXPORT TIMESTAMP sync_powerflow_object(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass)
00182 {
00183 powerflow_object *pObj = OBJECTDATA(obj,powerflow_object);
00184 try {
00185 if (pass==PC_BOTTOMUP)
00186 return pObj->sync(t0);
00187 else
00188 {
00189 TIMESTAMP t1 = pObj->postsync(t0);
00190 obj->clock = t0;
00191 return t1;
00192 }
00193 } catch (const char *error) {
00194 GL_THROW("%s (%s:%d): %s", pObj->get_name(), pObj->get_id(), error);
00195 return 0;
00196 } catch (...) {
00197 GL_THROW("%s (%s:%d): %s", pObj->get_name(), pObj->get_id(), "unknown exception");
00198 return 0;
00199 }
00200 }
00201
00202 EXPORT int isa_powerflow_object(OBJECT *obj, char *classname)
00203 {
00204 return OBJECTDATA(obj,powerflow_object)->isa(classname);
00205 }
00206