residential/plugload.cpp

Go to the documentation of this file.
00001 
00012 #include <stdlib.h>
00013 #include <stdio.h>
00014 #include <errno.h>
00015 #include <math.h>
00016 
00017 #include "house.h"
00018 #include "plugload.h"
00019 
00021 // plugload CLASS FUNCTIONS
00023 CLASS* plugload::oclass = NULL;
00024 plugload *plugload::defaults = NULL;
00025 
00026 plugload::plugload(MODULE *module) 
00027 {
00028     // first time init
00029     if (oclass==NULL)
00030     {
00031         // register the class definition
00032         oclass = gl_register_class(module,"plugload",PC_BOTTOMUP);
00033         if (oclass==NULL)
00034             GL_THROW("unable to register object class implemented by %s",__FILE__);
00035 
00036         // publish the class properties
00037         if (gl_publish_variable(oclass,
00038             PT_double,"installed_power[W]",PADDR(installed_power),
00039             PT_double,"circuit_split",PADDR(circuit_split),
00040             PT_double,"demand[%]",PADDR(demand),
00041             PT_complex,"power[kW]",PADDR(power_kw),
00042             PT_double,"internal_heat",PADDR(internal_heat),
00043             PT_double,"heat_fraction",PADDR(heat_fraction),
00044             PT_complex,"meter[kWh]",PADDR(kwh_meter),
00045             NULL)<1) 
00046             GL_THROW("unable to publish properties in %s",__FILE__);
00047 
00048         // setup the default values
00049         defaults = this;
00050 
00051         // other derived properties
00052         power_kw =0;
00053         power_factor = 0.95;
00054         kwh_meter = 0;
00055         internal_heat = 0;
00056     }
00057 }
00058 
00059 plugload::~plugload()
00060 {
00061 }
00062 
00063 int plugload::create() 
00064 {
00065     // copy the defaults
00066     memcpy(this,defaults,sizeof(*this));
00067 
00068     // defult properties
00069     installed_power = gl_random_uniform(700,2000);  // plugload size [W]
00070     demand = gl_random_uniform(0, 0.1);  // assuming a default maximum 10% of the sync time 
00071     heat_fraction = 0.90;  // assuming default 90% of power is transferred as heat
00072     return 1;
00073     
00074 }
00075 
00076 int plugload::init(OBJECT *parent)
00077 {
00078     if (parent==NULL)
00079     {
00080         gl_error("plugload must have a parent house");
00081         return 0;
00082     }
00083     house *pHouse = OBJECTDATA(parent,house);
00084 
00085     // attach object to house panel
00086     pVoltage = (pHouse->attach(OBJECTHDR(this),20,false))->pV;
00087 
00088     // initial demand
00089     power_kw = installed_power * demand / 1000;
00090 
00091     return 1;
00092 }
00093 
00094 TIMESTAMP plugload::sync(TIMESTAMP t0, TIMESTAMP t1) 
00095 {
00096     // get demand fraction as an average per hour since the last synch time
00097     // a function  prototype will be 'get_average_demand(t0, t1)' which will be used to set 'demand' 
00098     // by default 'demand' is 1.0, now provided by the tape
00099     
00100         if (t0 <= 0)
00101         return TS_NEVER;
00102 
00103     power_kw.SetPolar(installed_power * demand / 1000.0, acos(power_factor), J);
00104     double energy = power_kw.Mag() * (gl_tohours(t1)-gl_tohours(t0));
00105     internal_heat = energy * heat_fraction * BTUPHPKW;
00106     kwh_meter += energy;
00107 
00108     house *pHouse = OBJECTDATA((OBJECTHDR(this))->parent,house);
00109     pHouse->plugload_heat_energy += internal_heat;
00110     pHouse->power_kw += power_kw;
00111 
00112     return TS_NEVER; 
00113 }
00114 
00116 // IMPLEMENTATION OF CORE LINKAGE
00118 
00119 EXPORT int create_plugload(OBJECT **obj, OBJECT *parent)
00120 {
00121     *obj = gl_create_object(plugload::oclass,sizeof(plugload));
00122     if (*obj!=NULL)
00123     {
00124         plugload *my = OBJECTDATA(*obj,plugload);;
00125         gl_set_parent(*obj,parent);
00126         my->create();
00127         return 1;
00128     }
00129     return 0;
00130 }
00131 
00132 EXPORT int init_plugload(OBJECT *obj)
00133 {
00134     plugload *my = OBJECTDATA(obj,plugload);
00135     return my->init(obj->parent);
00136 }
00137 
00138 EXPORT TIMESTAMP sync_plugload(OBJECT *obj, TIMESTAMP t0)
00139 {
00140     plugload *my = OBJECTDATA(obj, plugload);
00141     TIMESTAMP t1 = my->sync(obj->clock, t0);
00142     obj->clock = t0;
00143     return t1;
00144 }
00145 

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