residential/clotheswasher.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 "clotheswasher.h"
00019 
00021 // clotheswasher CLASS FUNCTIONS
00023 CLASS* clotheswasher::oclass = NULL;
00024 clotheswasher *clotheswasher::defaults = NULL;
00025 
00026 clotheswasher::clotheswasher(MODULE *module) 
00027 {
00028     // first time init
00029     if (oclass==NULL)
00030     {
00031         // register the class definition
00032         oclass = gl_register_class(module,"clotheswasher",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         internal_heat = 0.0;
00054         heat_fraction = 0.50;  //Assuming 50% of power is transformed to internal heat
00055         power_kw = 0.0;
00056         power_factor = 0.95;
00057         kwh_meter = 0.0;
00058     }
00059 }
00060 
00061 clotheswasher::~clotheswasher()
00062 {
00063 }
00064 
00065 int clotheswasher::create() 
00066 {
00067     // copy the defaults
00068     memcpy(this,defaults,sizeof(*this));
00069 
00070     // default properties
00071     installed_power = gl_random_uniform(500,750);       // clotheswasher size [W]
00072     return 1;
00073 }
00074 
00075 int clotheswasher::init(OBJECT *parent)
00076 {
00077     if (parent==NULL)
00078     {
00079         gl_error("clotheswasher must have a parent house");
00080         return 0;
00081     }
00082     house *pHouse = OBJECTDATA(parent,house);
00083 
00084     // attach object to house panel
00085     pVoltage = (pHouse->attach(OBJECTHDR(this),20,false))->pV;
00086 
00087     // initial demand
00088     power_kw = installed_power * demand / 1000;
00089 
00090     return 1;
00091 }
00092 
00093 TIMESTAMP clotheswasher::sync(TIMESTAMP t0, TIMESTAMP t1) 
00094 {
00095     // get demand fraction as an average per hour since the last synch time
00096     // a function  prototype will be 'get_average_demand(t0, t1)' which will be used to set 'demand' 
00097     // by default 'demand' is 1.0, now provided by the tape
00098 //  demand = 1.0;
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 = heat_fraction * energy * BTUPHPKW;
00106     kwh_meter += energy;
00107 
00108     house *pHouse = OBJECTDATA((OBJECTHDR(this))->parent,house);
00109     pHouse->clotheswasher_heat_energy += internal_heat;
00110     pHouse->power_kw += power_kw;
00111 
00112     return TS_NEVER; 
00113 }
00114 
00115 
00117 // IMPLEMENTATION OF CORE LINKAGE
00119 
00120 EXPORT int create_clotheswasher(OBJECT **obj, OBJECT *parent)
00121 {
00122     *obj = gl_create_object(clotheswasher::oclass,sizeof(clotheswasher));
00123     if (*obj!=NULL)
00124     {
00125         clotheswasher *my = OBJECTDATA(*obj,clotheswasher);
00126         gl_set_parent(*obj,parent);
00127         my->create();
00128         return 1;
00129     }
00130     return 0;
00131 }
00132 
00133 EXPORT int init_clotheswasher(OBJECT *obj)
00134 {
00135     clotheswasher *my = OBJECTDATA(obj,clotheswasher);
00136     return my->init(obj->parent);
00137 }
00138 
00139 EXPORT TIMESTAMP sync_clotheswasher(OBJECT *obj, TIMESTAMP t0)
00140 {
00141     clotheswasher *my = OBJECTDATA(obj, clotheswasher);
00142     TIMESTAMP t1 = my->sync(obj->clock, t0);
00143     obj->clock = t0;
00144     return t1;
00145 }
00146 

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