network/regulator.cpp

00001 
00009 #include <stdlib.h>
00010 #include <stdio.h>
00011 #include <errno.h>
00012 #include <math.h>
00013 #include "network.h"
00014 
00015 
00016 
00018 // regulator CLASS FUNCTIONS
00020 CLASS* regulator::oclass = NULL;
00021 CLASS* regulator::pclass = NULL;
00022 regulator *regulator::defaults = NULL;
00023 
00024 regulator::regulator(MODULE *mod) : link(mod)
00025 {
00026     // first time init
00027     if (oclass==NULL)
00028     {
00029         // register the class definition
00030         regulator_class = oclass = gl_register_class(mod,"regulator",PC_BOTTOMUP);
00031         if (oclass==NULL)
00032             GL_THROW("unable to register object class implemented by %s",__FILE__);
00033 
00034         // publish the class properties
00035         if (gl_publish_variable(oclass,
00036             PT_enumeration,"Type",PADDR(Type),
00037                 PT_KEYWORD,"RT_LTC",RT_LTC,
00038                 PT_KEYWORD,"RT_VR",RT_VR,
00039             PT_double, "Vmax", PADDR(Vmax),
00040             PT_double, "Vmin", PADDR(Vmin),
00041             PT_double, "Vstep", PADDR(Vstep),
00042             PT_object, "CTlink", PADDR(CTlink),
00043             PT_object, "PTbus", PADDR(PTbus),
00044             PT_double, "TimeDelay", PADDR(TimeDelay),
00045             NULL)<1) GL_THROW("unable to publish properties in %s",__FILE__);
00046 
00047         // setup the default values
00048         defaults = this;
00049     }
00050 
00051 }
00052 
00053 int regulator::create() 
00054 {
00055     int result = link::create();
00056     memcpy(this,defaults,sizeof(*this));
00057     return result;
00058 }
00059 
00060 TIMESTAMP regulator::sync(TIMESTAMP t0) 
00061 {
00062     node *f = OBJECTDATA(from,node);
00063     node *t = OBJECTDATA(to,node);
00064     if (f==NULL || t==NULL)
00065         return TS_NEVER;
00066     // TODO: update regulator state
00067     return link::sync(t0);
00068 }
00070 // IMPLEMENTATION OF CORE LINKAGE: regulator
00072 
00073 EXPORT int create_regulator(OBJECT **obj, OBJECT *parent)
00074 {
00075     *obj = gl_create_object(regulator_class,sizeof(regulator));
00076     if (*obj!=NULL)
00077     {
00078         regulator *my = OBJECTDATA(*obj,regulator);
00079         gl_set_parent(*obj,parent);
00080         my->create();
00081         return 1;
00082     }
00083     return 0;
00084 }
00085 
00086 EXPORT TIMESTAMP sync_regulator(OBJECT *obj, TIMESTAMP t0)
00087 {
00088     TIMESTAMP t1 = OBJECTDATA(obj,regulator)->sync(t0);
00089     obj->clock = t0;
00090     return t1;
00091 }
00092 
00093 

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