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