residential/occupantload.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 "occupantload.h"
00019 
00020 
00022 // occupantload CLASS FUNCTIONS
00024 CLASS* occupantload::oclass = NULL;
00025 occupantload *occupantload::defaults = NULL;
00026 
00027 occupantload::occupantload(MODULE *module) 
00028 {
00029     // first time init
00030     if (oclass==NULL)
00031     {
00032         // register the class definition
00033         oclass = gl_register_class(module,"occupantload",PC_BOTTOMUP);
00034         if (oclass==NULL)
00035             GL_THROW("unable to register object class implemented by %s",__FILE__);
00036 
00037         // publish the class properties
00038         if (gl_publish_variable(oclass,
00039             PT_int32,"number_of_occupants",PADDR(number_of_occupants),
00040             PT_double,"occupancy_fraction",PADDR(occupancy_fraction),
00041             PT_double,"heatgain_per_person",PADDR(heatgain_per_person),
00042             PT_double,"total_occupant_load",PADDR(total_occupant_load),
00043             NULL)<1) 
00044             GL_THROW("unable to publish properties in %s",__FILE__);
00045 
00046         // setup the default values
00047         defaults = this;
00048 
00049         number_of_occupants = 4;        // defaulted to 4, but define it based on house size??
00050         occupancy_fraction = 0.0;       // default assumption is unoccupied
00051         heatgain_per_person = 400.0;    // Based on DOE-2, includes latent and sensible heatgain
00052         total_occupant_load = 0.0;
00053     }
00054 }
00055 
00056 occupantload::~occupantload()
00057 {
00058 }
00059 
00060 int occupantload::create() 
00061 {
00062     // copy the defaults
00063     memcpy(this,defaults,sizeof(*this));
00064     return 1;
00065 }
00066 
00067 TIMESTAMP occupantload::sync(TIMESTAMP t0, TIMESTAMP t1) 
00068 {
00069     if (t0 <= 0)
00070         return TS_NEVER;
00071 
00072     total_occupant_load = number_of_occupants * occupancy_fraction * heatgain_per_person;
00073 
00074     house *pHouse = OBJECTDATA((OBJECTHDR(this))->parent,house);
00075     pHouse->occupantload_heat_energy += total_occupant_load;
00076 
00077     return TS_NEVER; 
00078 }
00079 
00081 // IMPLEMENTATION OF CORE LINKAGE
00083 
00084 EXPORT int create_occupantload(OBJECT **obj, OBJECT *parent)
00085 {
00086     *obj = gl_create_object(occupantload::oclass,sizeof(occupantload));
00087     if (*obj!=NULL)
00088     {
00089         occupantload *my = OBJECTDATA(*obj,occupantload);;
00090         gl_set_parent(*obj,parent);
00091         my->create();
00092         return 1;
00093     }
00094     return 0;
00095 }
00096 
00097 EXPORT TIMESTAMP sync_occupantload(OBJECT *obj, TIMESTAMP t0)
00098 {
00099     occupantload *my = OBJECTDATA(obj, occupantload);
00100     TIMESTAMP t1 = my->sync(obj->clock, t0);
00101     obj->clock = t0;
00102     return t1;
00103 }
00104 

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