00001
00013 #include <stdlib.h>
00014 #include <stdio.h>
00015 #include <errno.h>
00016 #include <math.h>
00017
00018 #include "occupantload.h"
00019
00020
00022
00024 CLASS* occupantload::oclass = NULL;
00025 CLASS* occupantload::pclass = NULL;
00026
00027 occupantload::occupantload(MODULE *module) : residential_enduse(module)
00028 {
00029
00030 if (oclass==NULL)
00031 {
00032
00033 oclass = gl_register_class(module,"occupantload",sizeof(occupantload),PC_BOTTOMUP|PC_AUTOLOCK);
00034 if (oclass==NULL)
00035 throw "unable to register class occupantload";
00036 else
00037 oclass->trl = TRL_QUALIFIED;
00038
00039
00040 if (gl_publish_variable(oclass,
00041 PT_INHERIT, "residential_enduse",
00042 PT_int32,"number_of_occupants",PADDR(number_of_occupants),
00043 PT_double,"occupancy_fraction[unit]",PADDR(occupancy_fraction),
00044 PT_double,"heatgain_per_person[Btu/h]",PADDR(heatgain_per_person),
00045 NULL)<1)
00046 GL_THROW("unable to publish properties in %s",__FILE__);
00047 }
00048 }
00049
00050 occupantload::~occupantload()
00051 {
00052 }
00053
00054 int occupantload::create()
00055 {
00056 int res = residential_enduse::create();
00057
00058
00059 load.name = oclass->name;
00060 load.power = load.admittance = load.current = load.total = complex(0,0,J);
00061 load.config = EUC_HEATLOAD;
00062 load.config |= EUC_IS220;
00063 return res;
00064 }
00065
00066 int occupantload::init(OBJECT *parent)
00067 {
00068 if(parent != NULL){
00069 if((parent->flags & OF_INIT) != OF_INIT){
00070 char objname[256];
00071 gl_verbose("occupantload::init(): deferring initialization on %s", gl_name(parent, objname, 255));
00072 return 2;
00073 }
00074 }
00075 if (number_of_occupants==0) number_of_occupants = 4;
00076 if (heatgain_per_person==0) heatgain_per_person = 400.0;
00077
00078 OBJECT *hdr = OBJECTHDR(this);
00079 hdr->flags |= OF_SKIPSAFE;
00080
00081 if (parent==NULL || (!gl_object_isa(parent,"house") && !gl_object_isa(parent,"house_e")))
00082 {
00083 gl_error("occupantload must have a parent house");
00084
00085
00086
00087
00088
00089 return 0;
00090 }
00091
00092
00093 FUNCTIONADDR attach = 0;
00094 load.end_obj = hdr;
00095 attach = (gl_get_function(parent, "attach_enduse"));
00096 if(attach == NULL){
00097 gl_error("occupantload parent must publish attach_enduse()");
00098
00099
00100
00101
00102 return 0;
00103 }
00104
00105
00106 ((CIRCUIT *(*)(OBJECT *, enduse *, double, int))(*attach))(hdr->parent, &(this->load), 20, true);
00107
00108 load.heatgain = number_of_occupants * occupancy_fraction * heatgain_per_person;
00109
00110 if(shape.type != MT_UNKNOWN && shape.type != MT_ANALOG){
00111 char outname[64];
00112 if(hdr->name){
00113
00114 } else {
00115 sprintf(outname, "occupancy_load:%i", hdr->id);
00116 }
00117 gl_warning("occupancy_load \'%s\' may not work properly with a non-analog load shape.", hdr->name ? hdr->name : outname);
00118 }
00119 return 1;
00120 }
00121
00122 int occupantload::isa(char *classname)
00123 {
00124 return (strcmp(classname,"occupantload")==0 || residential_enduse::isa(classname));
00125 }
00126
00127 TIMESTAMP occupantload::sync(TIMESTAMP t0, TIMESTAMP t1)
00128 {
00129
00130 if(heatgain_per_person < 0){
00131 gl_error("negative heatgain per person, reseting to 400 BTU/hr");
00132 heatgain_per_person = 400.0;
00133 }
00134 if(heatgain_per_person > 1600){
00135
00136 gl_error("heatgain per person above 1600 Btu/hr (470W), reseting to 400 Btu/hr");
00137 heatgain_per_person = 400.0;
00138 }
00139
00140
00141 if(shape.type == MT_UNKNOWN){
00142 if(number_of_occupants < 0){
00143 gl_error("negative number of occupants, reseting to zero");
00144 number_of_occupants = 0;
00145 }
00146 if(occupancy_fraction < 0.0){
00147 gl_error("negative occupancy_fraction, reseting to zero");
00148 occupancy_fraction = 0.0;
00149 }
00150 if(occupancy_fraction > 1.0){
00151 ;
00152 }
00153 if(occupancy_fraction * number_of_occupants > 300.0){
00154 gl_error("attempting to fit 300 warm bodies into a house, reseting to zero");
00155
00156
00157
00158 occupancy_fraction = 0;
00159 }
00160
00161 load.heatgain = number_of_occupants * occupancy_fraction * heatgain_per_person;
00162 }
00163
00164 return TS_NEVER;
00165 }
00166
00168
00170
00171 EXPORT int create_occupantload(OBJECT **obj, OBJECT *parent)
00172 {
00173 try
00174 {
00175 *obj = gl_create_object(occupantload::oclass);
00176 if (*obj!=NULL)
00177 {
00178 occupantload *my = OBJECTDATA(*obj,occupantload);;
00179 gl_set_parent(*obj,parent);
00180 my->create();
00181 return 1;
00182 }
00183 else
00184 return 0;
00185 }
00186 CREATE_CATCHALL(occupantload);
00187 }
00188
00189 EXPORT int init_occupantload(OBJECT *obj)
00190 {
00191 try
00192 {
00193 occupantload *my = OBJECTDATA(obj,occupantload);
00194 return my->init(obj->parent);
00195 }
00196 INIT_CATCHALL(occupantload);
00197 }
00198
00199 EXPORT int isa_occupantload(OBJECT *obj, char *classname)
00200 {
00201 if(obj != 0 && classname != 0){
00202 return OBJECTDATA(obj,occupantload)->isa(classname);
00203 } else {
00204 return 0;
00205 }
00206 }
00207
00208 EXPORT TIMESTAMP sync_occupantload(OBJECT *obj, TIMESTAMP t0)
00209 {
00210 try
00211 {
00212 occupantload *my = OBJECTDATA(obj, occupantload);
00213 TIMESTAMP t1 = my->sync(obj->clock, t0);
00214 obj->clock = t0;
00215 return t1;
00216 }
00217 SYNC_CATCHALL(occupantload);
00218 }
00219