residential/dishwasher.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 "dishwasher.h"
00019 
00021 // dishwasher CLASS FUNCTIONS
00023 CLASS* dishwasher::oclass = NULL;
00024 dishwasher *dishwasher::defaults = NULL;
00025 
00026 dishwasher::dishwasher(MODULE *module) 
00027 {
00028     // first time init
00029     if (oclass==NULL)
00030     {
00031         // register the class definition
00032         oclass = gl_register_class(module,"dishwasher",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         // derived properties and other initial conditions
00052         demand = 0.0;
00053         heat_fraction = 0.50;  //Assuming 50% of the power is transformed to internal heat
00054         internal_heat = 0.0;
00055         power_kw = 0.0;
00056         power_factor = 0.95;
00057         kwh_meter = 0.0;
00058     }
00059 }
00060 
00061 dishwasher::~dishwasher()
00062 {
00063 }
00064 
00065 int dishwasher::init(OBJECT *parent)
00066 {
00067     if (parent==NULL)
00068     {
00069         gl_error("dishwasher must have a parent house");
00070         return 0;
00071     }
00072     house *pHouse = OBJECTDATA(parent,house);
00073 
00074     // attach object to house panel
00075     pVoltage = (pHouse->attach(OBJECTHDR(this),20,false))->pV;
00076 
00077     // initial demand
00078     power_kw = installed_power * demand / 1000;
00079 
00080     return 1;
00081 }
00082 
00083 int dishwasher::create() 
00084 {
00085     // copy the defaults
00086     memcpy(this,defaults,sizeof(*this));
00087 
00088     // default properties
00089     installed_power = gl_random_uniform(1000,3000);     // dishwasher size [W]
00090     return 1;
00091 }
00092 
00093 
00094 TIMESTAMP dishwasher::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 
00099     if (t0 <= 0)
00100         return TS_NEVER;
00101 
00102     power_kw.SetPolar(installed_power * demand / 1000.0, acos(power_factor), J);
00103     double energy = power_kw.Mag() * (gl_tohours(t1)-gl_tohours(t0));
00104     internal_heat = heat_fraction * energy * BTUPHPKW;
00105     kwh_meter += energy;
00106 
00107     house *pHouse = OBJECTDATA((OBJECTHDR(this))->parent,house);
00108     pHouse->dishwasher_heat_energy += internal_heat;
00109     pHouse->power_kw += power_kw;
00110 
00111     return TS_NEVER; 
00112 }
00113 
00114 
00116 // IMPLEMENTATION OF CORE LINKAGE: dishwasher
00118 
00119 EXPORT int create_dishwasher(OBJECT **obj, OBJECT *parent)
00120 {
00121     *obj = gl_create_object(dishwasher::oclass,sizeof(dishwasher));
00122     if (*obj!=NULL)
00123     {
00124         dishwasher *my = OBJECTDATA(*obj,dishwasher);
00125         gl_set_parent(*obj,parent);
00126         my->create();
00127         return 1;
00128     }
00129     return 0;
00130 }
00131 
00132 EXPORT int init_dishwasher(OBJECT *obj)
00133 {
00134     dishwasher *my = OBJECTDATA(obj,dishwasher);
00135     return my->init(obj->parent);
00136 }
00137 
00138 EXPORT TIMESTAMP sync_dishwasher(OBJECT *obj, TIMESTAMP t0)
00139 {
00140     dishwasher *my = OBJECTDATA(obj, dishwasher);
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