residential/microwave.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 "microwave.h"
00019 
00021 // microwave CLASS FUNCTIONS
00023 CLASS* microwave::oclass = NULL;
00024 microwave *microwave::defaults = NULL;
00025 
00026 microwave::microwave(MODULE *module) 
00027 {
00028     // first time init
00029     if (oclass==NULL)
00030     {
00031         // register the class definition
00032         oclass = gl_register_class(module,"microwave",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 microwave::~microwave()
00060 {
00061 }
00062 
00063 int microwave::create() 
00064 {
00065     // copy the defaults
00066     memcpy(this,defaults,sizeof(*this));
00067 
00068     // defult properties
00069     installed_power = gl_random_uniform(700,1200);  // microwave size [W]
00070     demand = gl_random_uniform(0, 0.1);  // assuming a default maximum 10% of the sync time 
00071     heat_fraction = 0.25;  // assuming default 25% of power is transferred as heat
00072     return 1;
00073 }
00074 
00075 int microwave::init(OBJECT *parent)
00076 {
00077     if (parent==NULL)
00078     {
00079         gl_error("microwave 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 microwave::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     
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 = energy * heat_fraction * BTUPHPKW;
00105     kwh_meter += energy;
00106 
00107     house *pHouse = OBJECTDATA((OBJECTHDR(this))->parent,house);
00108     pHouse->microwave_heat_energy += internal_heat;
00109     pHouse->power_kw += power_kw;
00110 
00111     return TS_NEVER; 
00112 }
00113 
00115 // IMPLEMENTATION OF CORE LINKAGE
00117 
00118 EXPORT int create_microwave(OBJECT **obj, OBJECT *parent)
00119 {
00120     *obj = gl_create_object(microwave::oclass,sizeof(microwave));
00121     if (*obj!=NULL)
00122     {
00123         microwave *my = OBJECTDATA(*obj,microwave);;
00124         gl_set_parent(*obj,parent);
00125         my->create();
00126         return 1;
00127     }
00128     return 0;
00129 }
00130 
00131 EXPORT int init_microwave(OBJECT *obj)
00132 {
00133     microwave *my = OBJECTDATA(obj,microwave);
00134     return my->init(obj->parent);
00135 }
00136 
00137 EXPORT TIMESTAMP sync_microwave(OBJECT *obj, TIMESTAMP t0)
00138 {
00139     microwave *my = OBJECTDATA(obj, microwave);
00140     TIMESTAMP t1 = my->sync(obj->clock, t0);
00141     obj->clock = t0;
00142     return t1;
00143 }
00144 

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