residential/washer.cpp

00001 /* washer.cpp
00002  *
00003  */
00004 
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 #include <errno.h>
00008 #include <math.h>
00009 
00010 #include "washer.h"
00011 
00012 washer::washer() 
00013 {
00014     memset(this, 0, sizeof(washer));
00015 }
00016 
00017 washer::~washer()
00018 {
00019 }
00020 
00021 void washer::create() 
00022 {
00023     // default properties
00024     installed_power = gl_random_uniform(500,750);       // washer size [W]
00025 
00026     // derived properties and other initial conditions
00027     demand = 0.0;
00028     heat_loss = 0.0;
00029     power_demand = 0.0;
00030     kwh_meter = 0.0;
00031 }
00032 
00033 
00034 TIMESTAMP washer::sync(TIMESTAMP t0, TIMESTAMP t1) 
00035 {
00036     // get demand fraction as an average per hour since the last synch time
00037     // a function  prototype will be 'get_average_demand(t0, t1)' which will be used to set 'demand' 
00038     // by default 'demand' is 1.0, now provided by the tape
00039 //  demand = 1.0;
00040 
00041     if (t0 <= 0)
00042         return TS_NEVER;
00043 
00044     power_demand.SetPolar(installed_power * demand / 1000.0, acos(1.0), J);
00045     double energy = power_demand.Mag() * (t1-t0);
00046     heat_loss = energy;
00047     kwh_meter += energy;
00048 
00049     return TS_NEVER; 
00050 }
00051 
00052 
00054 // IMPLEMENTATION OF CORE LINKAGE
00056 CDECL CLASS *washer_class = NULL;
00057 CDECL OBJECT *last_washer = NULL;
00058 
00059 EXPORT int create_washer(OBJECT **obj, OBJECT *parent)
00060 {
00061     *obj = gl_create_object(washer_class,sizeof(washer));
00062     if (*obj!=NULL)
00063     {
00064         last_washer = *obj;
00065         washer *my = OBJECTDATA(*obj,washer);
00066         gl_set_parent(*obj,parent);
00067         my->create();
00068         return 1;
00069     }
00070     return 0;
00071 }
00072 
00073 EXPORT TIMESTAMP sync_washer(OBJECT *obj, TIMESTAMP t0)
00074 {
00075     washer *my = OBJECTDATA(obj, washer);
00076     TIMESTAMP t1 = my->sync(obj->clock, t0);
00077     obj->clock = t0;
00078     return t1;
00079 }

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