generators/diesel_dg.cpp

Go to the documentation of this file.
00001 
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <errno.h>
00011 #include <math.h>
00012 
00013 #include "diesel_dg.h"
00014 
00015 CLASS *diesel_dg::oclass = NULL;
00016 diesel_dg *diesel_dg::defaults = NULL;
00017 
00018 #ifdef OPTIONAL
00019 /* TODO: define this to allow the use of derived classes */
00020 CLASS *PARENTdiesel_dg::pclass = NULL;
00021 #endif
00022 
00023 /* TODO: remove passes that aren't needed */
00024 static PASSCONFIG passconfig = PC_PRETOPDOWN|PC_BOTTOMUP|PC_POSTTOPDOWN;
00025 
00026 /* TODO: specify which pass the clock advances */
00027 static PASSCONFIG clockpass = PC_BOTTOMUP;
00028 
00029 /* Class registration is only called once to register the class with the core */
00030 diesel_dg::diesel_dg(MODULE *module)
00031 #ifdef OPTIONAL
00032 /* TODO: include this if you are deriving this from a superclass */
00033 : SUPERCLASS(module)
00034 #endif
00035 {
00036 #ifdef OPTIONAL
00037     /* TODO: include this if you are deriving this from a superclass */
00038     pclass = SUPERCLASS::oclass;
00039 #endif
00040     if (oclass==NULL)
00041     {
00042         oclass = gl_register_class(module,"diesel_dg",passconfig);
00043         if (oclass==NULL)
00044             GL_THROW("unable to register object class implemented by %s", __FILE__); 
00045 
00046         if (gl_publish_variable(oclass,
00047             /* TODO: add your published properties here */
00048             NULL)<1) GL_THROW("unable to publish properties in %s",__FILE__);
00049         defaults = this;
00050         /* TODO: set the default values of all properties here */
00051     }
00052 }
00053 
00054 /* Object creation is called once for each object that is created by the core */
00055 int diesel_dg::create(void) 
00056 {
00057     memcpy(this,defaults,sizeof(*this));
00058     /* TODO: set the context-free initial value of properties */
00059     return 1; /* return 1 on success, 0 on failure */
00060 }
00061 
00062 /* Object initialization is called once after all object have been created */
00063 int diesel_dg::init(OBJECT *parent)
00064 {
00065     /* TODO: set the context-dependent initial value of properties */
00066     return 1; /* return 1 on success, 0 on failure */
00067 }
00068 
00069 /* Presync is called when the clock needs to advance on the first top-down pass */
00070 TIMESTAMP diesel_dg::presync(TIMESTAMP t0, TIMESTAMP t1)
00071 {
00072     TIMESTAMP t2 = TS_NEVER;
00073     /* TODO: implement pre-topdown behavior */
00074     return t2; /* return t2>t1 on success, t2=t1 for retry, t2<t1 on failure */
00075 }
00076 
00077 /* Sync is called when the clock needs to advance on the bottom-up pass */
00078 TIMESTAMP diesel_dg::sync(TIMESTAMP t0, TIMESTAMP t1) 
00079 {
00080     TIMESTAMP t2 = TS_NEVER;
00081     /* TODO: implement bottom-up behavior */
00082     return t2; /* return t2>t1 on success, t2=t1 for retry, t2<t1 on failure */
00083 }
00084 
00085 /* Postsync is called when the clock needs to advance on the second top-down pass */
00086 TIMESTAMP diesel_dg::postsync(TIMESTAMP t0, TIMESTAMP t1)
00087 {
00088     TIMESTAMP t2 = TS_NEVER;
00089     /* TODO: implement post-topdown behavior */
00090     return t2; /* return t2>t1 on success, t2=t1 for retry, t2<t1 on failure */
00091 }
00092 
00094 // IMPLEMENTATION OF CORE LINKAGE
00096 
00097 EXPORT int create_diesel_dg(OBJECT **obj, OBJECT *parent) 
00098 {
00099     try 
00100     {
00101         *obj = gl_create_object(diesel_dg::oclass,sizeof(diesel_dg));
00102         if (*obj!=NULL)
00103         {
00104             diesel_dg *my = OBJECTDATA(*obj,diesel_dg);
00105             gl_set_parent(*obj,parent);
00106             return my->create();
00107         }
00108     } 
00109     catch (char *msg) 
00110     {
00111         gl_error("create_diesel_dg: %s", msg);
00112     }
00113     return 0;
00114 }
00115 
00116 EXPORT int init_diesel_dg(OBJECT *obj, OBJECT *parent) 
00117 {
00118     try 
00119     {
00120         if (obj!=NULL)
00121             return OBJECTDATA(obj,diesel_dg)->init(parent);
00122     }
00123     catch (char *msg)
00124     {
00125         gl_error("init_diesel_dg(obj=%d;%s): %s", obj->id, obj->name?obj->name:"unnamed", msg);
00126     }
00127     return 0;
00128 }
00129 
00130 EXPORT TIMESTAMP sync_diesel_dg(OBJECT *obj, TIMESTAMP t1, PASSCONFIG pass)
00131 {
00132     TIMESTAMP t2 = TS_NEVER;
00133     diesel_dg *my = OBJECTDATA(obj,diesel_dg);
00134     try
00135     {
00136         switch (pass) {
00137         case PC_PRETOPDOWN:
00138             t2 = my->presync(obj->clock,t1);
00139             break;
00140         case PC_BOTTOMUP:
00141             t2 = my->sync(obj->clock,t1);
00142             break;
00143         case PC_POSTTOPDOWN:
00144             t2 = my->postsync(obj->clock,t1);
00145             break;
00146         default:
00147             GL_THROW("invalid pass request (%d)", pass);
00148             break;
00149         }
00150         if (pass==clockpass)
00151             obj->clock = t1;        
00152     }
00153     catch (char *msg)
00154     {
00155         gl_error("sync_diesel_dg(obj=%d;%s): %s", obj->id, obj->name?obj->name:"unnamed", msg);
00156     }
00157     return t2;
00158 }

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy