00001
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include <errno.h>
00013 #include <math.h>
00014 #include "residential.h"
00015 #include "residential_enduse.h"
00016
00018
00020 CLASS* residential_enduse::oclass = NULL;
00021
00022
00023 residential_enduse::residential_enduse(MODULE *mod)
00024 {
00025
00026 if (oclass==NULL)
00027 {
00028
00029 oclass = gld_class::create(mod,"residential_enduse",sizeof(residential_enduse),PC_BOTTOMUP|PC_AUTOLOCK);
00030 if (oclass==NULL)
00031 GL_THROW("unable to register object class implemented by %s",__FILE__);
00032
00033
00034
00035
00036
00037
00038
00039 if (gl_publish_variable(oclass,
00040 PT_loadshape,"shape",PADDR(shape),
00041 PT_enduse,"",PADDR(load),
00042 PT_enumeration,"override",PADDR(re_override),
00043 PT_KEYWORD,"NORMAL",(enumeration)OV_NORMAL,
00044 PT_KEYWORD,"ON",(enumeration)OV_ON,
00045 PT_KEYWORD,"OFF",(enumeration)OV_OFF,
00046 PT_enumeration, "power_state", PADDR(power_state),
00047 PT_KEYWORD, "OFF", (enumeration)PS_OFF,
00048 PT_KEYWORD, "ON", (enumeration)PS_ON,
00049 PT_KEYWORD, "UNKNOWN", (enumeration)PS_UNKNOWN,
00050 NULL)<1) GL_THROW("unable to publish properties in %s",__FILE__);
00051
00052
00053
00054
00055
00056 }
00057 }
00058
00059
00060 int residential_enduse::create(bool connect_shape)
00061 {
00062
00063 load.end_obj = my();
00064 if (connect_shape) load.shape = &shape;
00065 load.breaker_amps = 20;
00066 load.config = 0;
00067 load.heatgain_fraction = 1.0;
00068 re_override = OV_NORMAL;
00069 power_state = PS_UNKNOWN;
00070 return 1;
00071 }
00072
00073 int residential_enduse::init(OBJECT *parent)
00074 {
00075 set_flags(get_flags()|OF_SKIPSAFE);
00076 gld_object *pParent = OBJECTDATA(parent,gld_object);
00077
00078
00079 if ( pParent!=NULL && pParent->is_valid() )
00080 {
00081 ATTACHFUNCTION attach = (ATTACHFUNCTION)pParent->get_function("attach_enduse");
00082 if ( attach )
00083 pCircuit = (*attach)(parent, &load, load.breaker_amps, (load.config&EUC_IS220)!=0);
00084 else
00085 gl_warning("%s (%s:%d) parent %s (%s:%d) does not export attach_enduse function so voltage response cannot be modeled", get_name(), get_oclass()->get_name(), get_id(), pParent->get_name(), pParent->get_oclass()->get_name(), pParent->get_id());
00086
00087
00088
00089
00090
00091 }
00092
00093 if (load.shape!=NULL) {
00094 if (load.shape->schedule==NULL)
00095 {
00096 gl_verbose("%s (%s:%d) schedule is not specified so the load may be inactive", get_name(), get_oclass()->get_name(), get_id());
00097
00098
00099
00100
00101
00102 }
00103 }
00104
00105 return 1;
00106 }
00107
00108 int residential_enduse::isa(char *classname){
00109 return strcmp(classname,"residential_enduse")==0;
00110 }
00111
00112 TIMESTAMP residential_enduse::sync(TIMESTAMP t0, TIMESTAMP t1)
00113 {
00114 gl_debug("%s shape load = %8g", get_name(), gl_get_loadshape_value(&shape));
00115 if (load.voltage_factor>1.2 || load.voltage_factor<0.8)
00116 gl_verbose("%s voltage is out of normal +/- 20%% range of nominal (vf=%.2f)", get_name(), load.voltage_factor);
00117
00118
00119
00120
00121
00122 return shape.t2>t1 ? shape.t2 : TS_NEVER;
00123 }
00124
00126
00128
00129 EXPORT int create_residential_enduse(OBJECT **obj, OBJECT *parent)
00130 {
00131 try {
00132 *obj = gl_create_object(residential_enduse::oclass);
00133 if (*obj!=NULL)
00134 {
00135 residential_enduse *my = OBJECTDATA(*obj,residential_enduse);
00136 gl_set_parent(*obj,parent);
00137 return my->create();
00138 }
00139 else
00140 return 0;
00141 }
00142 CREATE_CATCHALL(residential_enduse);
00143 }
00144
00145 EXPORT int init_residential_enduse(OBJECT *obj)
00146 {
00147 try {
00148 residential_enduse *my = OBJECTDATA(obj,residential_enduse);
00149 return my->init(obj->parent);
00150 }
00151 INIT_CATCHALL(residential_enduse);
00152 }
00153
00154 EXPORT int isa_residential_enduse(OBJECT *obj, char *classname)
00155 {
00156 if(obj != 0 && classname != 0){
00157 return OBJECTDATA(obj,residential_enduse)->isa(classname);
00158 } else {
00159 return 0;
00160 }
00161 }
00162
00163 EXPORT TIMESTAMP sync_residential_enduse(OBJECT *obj, TIMESTAMP t1)
00164 {
00165 residential_enduse *my = OBJECTDATA(obj,residential_enduse);
00166 try {
00167 TIMESTAMP t2 = my->sync(obj->clock, t1);
00168 obj->clock = t1;
00169 return t2;
00170 }
00171 SYNC_CATCHALL(residential_enduse);
00172 }
00173