residential/test.h

00001 
00010 #ifndef _RESIDENTIAL_TEST_H
00011 #define _RESIDENTIAL_TEST_H
00012 
00013 #include "gridlabd.h"
00014 
00015 #include "house.h"
00016 #include "waterheater.h"
00017 #include "lights.h"
00018 #include "clotheswasher.h"
00019 
00020 #include "test_framework.h"
00021 
00022 #include "test_callbacks.h"
00023 // Include any module specific headers needed for testing.
00024 
00029 class residential_test : public test_helper
00030 {
00031     OBJECT *obj;
00032 public:
00033     residential_test(){}
00038     void setup(){}
00039 
00049     OBJECT *house_create(){
00050         CLASS *cl = get_class_by_name("house");
00051         CPPUNIT_ASSERT(cl != NULL);
00052         obj = gl_create_object(cl,sizeof(house));
00053         CPPUNIT_ASSERT(obj != NULL);
00054         return obj;
00055     }
00056 
00057     OBJECT *lights_create() {
00058         CLASS *cl = get_class_by_name("lights");
00059         CPPUNIT_ASSERT(cl != NULL);
00060         obj = gl_create_object(cl,sizeof(lights));
00061         CPPUNIT_ASSERT(obj != NULL);
00062         return obj;
00063     }
00064 
00065     OBJECT *clotheswasher_create() {
00066         CLASS *cl = get_class_by_name("clotheswasher");
00067         CPPUNIT_ASSERT(cl != NULL);
00068         obj = gl_create_object(cl,sizeof(clotheswasher));
00069         CPPUNIT_ASSERT(obj != NULL);
00070         return obj;
00071     }
00072 
00073     void lights_test() {
00074         gl_output("\n\nLights Unit Tests");
00075         gl_output("======================");
00076         OBJECT *house1 = house_create();
00077         OBJECTDATA(house1, house)->create();
00078 
00079         OBJECT *lights1 = lights_create();
00080         OBJECTDATA(lights1, lights)->create();
00081         gl_set_parent(lights1, house1);
00082         CPPUNIT_ASSERT(local_callbacks->init_objects() != FAILED);
00083         CPPUNIT_ASSERT(local_callbacks->setup_test_ranks() != FAILED);
00084         
00085         double curPower = 1500.0, curDemand = 1.0;
00086         OBJECTDATA(lights1, lights)->type = lights::INCANDESCENT;
00087         OBJECTDATA(lights1, lights)->placement = lights::INDOOR;
00088         OBJECTDATA(lights1, lights)->demand = curDemand;
00089         OBJECTDATA(lights1, lights)->installed_power = curPower;
00090 
00091         TIMESTAMP _time = gl_parsetime("2000-08-01 0:0:0 GMT");;
00092         house1->clock = _time;
00093 
00094         double nhours, lasthour;
00095         nhours = gl_tohours(_time);
00096         double toHour = nhours + 24;
00097         lasthour = nhours;
00098         double expectedPower, gridlabPower, expectedHeatgain, gridlabHeatgain;
00099         double demandSchedule[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.20, 0.20, 0.20, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.4, 0.2, 0.2};
00100 
00101         gl_output("\n            Expected      Gridlab       Expected        Gridlab"); 
00102         gl_output(  "   Hour     power_kw      power_kw      heatgain        heatgain"); 
00103 
00104         while (nhours < toHour)
00105         {
00106             curDemand = demandSchedule[(int)(nhours+24-toHour)];
00107             OBJECTDATA(lights1, lights)->demand = curDemand;
00108             
00109             TIMESTAMP nextSyncTime = local_callbacks->myobject_sync(lights1, _time, PC_BOTTOMUP);
00110             if (nextSyncTime == TS_NEVER )
00111                 _time += 3600 * TS_RESOLUTION * TS_SECOND;  //synch every fifteen minutes
00112             else
00113             {
00114                 gl_output("lights:  Unit test failed.  Unexpected synch time encountered.\n");
00115                 return;
00116             }
00117 
00118             expectedPower = curDemand * curPower/1000.0;
00119             gridlabPower = OBJECTDATA(lights1, lights)->power_kw.Mag();
00120             expectedHeatgain =  expectedPower * (nhours-lasthour) * BTUPHPKW;
00121             gridlabHeatgain = OBJECTDATA(lights1, lights)->internal_heat;
00122 
00123             gl_output("%5.1lf   %10.2lf    %10.2lf    %10.2lf    %10.2lf", 
00124                 (nhours+24-toHour), expectedPower, gridlabPower, expectedHeatgain, gridlabHeatgain);
00125             
00126             lasthour = nhours;
00127             nhours = gl_tohours(_time);
00128         }
00129     }
00130 
00131     void clotheswasher_test() {
00132         gl_output("\n\nClotheswasher Unit Tests");
00133         gl_output("======================");
00134         OBJECT *house1 = house_create();
00135         OBJECTDATA(house1, house)->create();
00136 
00137         OBJECT *clotheswasher1 = clotheswasher_create();
00138         OBJECTDATA(clotheswasher1, clotheswasher)->create();
00139         gl_set_parent(clotheswasher1, house1);
00140         CPPUNIT_ASSERT(local_callbacks->init_objects() != FAILED);
00141         CPPUNIT_ASSERT(local_callbacks->setup_test_ranks() != FAILED);
00142         
00143         double curPower = 2000.0, curDemand = 0.0, curHeatFraction = 0.5;
00144         OBJECTDATA(clotheswasher1, clotheswasher)->heat_fraction = curHeatFraction;
00145         OBJECTDATA(clotheswasher1, clotheswasher)->demand = curDemand;
00146         OBJECTDATA(clotheswasher1, clotheswasher)->installed_power = curPower;
00147         double demandSchedule[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.};
00148 
00149         TIMESTAMP _time = gl_parsetime("2000-08-01 0:0:0 GMT");;
00150         house1->clock = _time;
00151 
00152         double nhours, lasthour;
00153         nhours = gl_tohours(_time);
00154         double toHour = nhours + 24;
00155         lasthour = nhours;
00156         double expectedPower, gridlabPower, expectedHeatgain, gridlabHeatgain;
00157 
00158         gl_output("\n            Expected      Gridlab       Expected        Gridlab"); 
00159         gl_output(  "   Hour     power_kw      power_kw      heatgain        heatgain"); 
00160 
00161         while (nhours < toHour)
00162         {
00163             curDemand = demandSchedule[(int)(nhours+24-toHour)];
00164             OBJECTDATA(clotheswasher1, clotheswasher)->demand = curDemand;
00165 
00166             TIMESTAMP nextSyncTime = local_callbacks->myobject_sync(clotheswasher1, _time, PC_BOTTOMUP);
00167             if (nextSyncTime == TS_NEVER )
00168                 _time += 3600 * TS_RESOLUTION * TS_SECOND;  //synch every fifteen minutes
00169             else
00170             {
00171                 gl_output("clotheswasher:  Unit test failed.  Unexpected synch time encountered.\n");
00172                 return;
00173             }
00174 
00175             expectedPower = curDemand * curPower/1000.0;
00176             gridlabPower = OBJECTDATA(clotheswasher1, clotheswasher)->power_kw.Mag();
00177             expectedHeatgain =  expectedPower * curHeatFraction * (nhours-lasthour) * BTUPHPKW;
00178             gridlabHeatgain = OBJECTDATA(clotheswasher1, clotheswasher)->internal_heat;
00179 
00180             gl_output("%5.1lf   %10.2lf    %10.2lf    %10.2lf    %10.2lf", 
00181                 (nhours+24-toHour), expectedPower, gridlabPower, expectedHeatgain, gridlabHeatgain);
00182             
00183             lasthour = nhours;
00184             nhours = gl_tohours(_time);
00185         }
00186     }
00187 
00188     void house_test() {
00189         gl_output("\n\nHouse Unit Tests");
00190         gl_output("======================\n");
00191         OBJECT *house1 = house_create();
00192         OBJECTDATA(house1, house)->create();
00193         house1->latitude = 38.0;
00194 
00195         OBJECTDATA(house1, house)->floor_area = 2500.0;
00196         OBJECTDATA(house1, house)->Tair = 74.0;
00197         OBJECTDATA(house1, house)->airchange_per_hour = 5;
00198         OBJECTDATA(house1, house)->thermostat_deadband = 1.0;
00199         OBJECTDATA(house1, house)->heating_setpoint = 70.0;
00200         OBJECTDATA(house1, house)->cooling_setpoint = 74.0;
00201         OBJECTDATA(house1, house)->envelope_UA = 437.5;
00202 
00203         OBJECTDATA(house1, house)->air_density = 0.0735;
00204         OBJECTDATA(house1, house)->air_mass = 1470.0;
00205         OBJECTDATA(house1, house)->air_heat_capacity = 0.2402;
00206         OBJECTDATA(house1, house)->air_thermal_mass = 353.094;
00207         OBJECTDATA(house1, house)->house_content_heat_transfer_coeff = 1875.0;
00208         OBJECTDATA(house1, house)->COP_coeff = 1.0;
00209         OBJECTDATA(house1, house)->heat_cool_mode = house::OFF;
00210         OBJECTDATA(house1, house)->Tmaterials = 74.0;
00211         OBJECTDATA(house1, house)->design_cooling_capacity = 18.0;
00212         OBJECTDATA(house1, house)->design_heating_capacity = 18.0;
00213         OBJECTDATA(house1, house)->cooling_COP = 3.0;
00214         OBJECTDATA(house1, house)->heating_COP = 1.0;
00215 
00216         // Now we call init on the objects
00217         CPPUNIT_ASSERT(local_callbacks->init_objects() != FAILED);
00218         CPPUNIT_ASSERT(local_callbacks->setup_test_ranks() != FAILED);
00219 
00220         // set climate object variables
00221         static double tout=95.0, rhout=0.75, solar[8] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
00222         OBJECTDATA(house1, house)->pTout = &tout;
00223         OBJECTDATA(house1, house)->pRhout = &rhout;
00224         OBJECTDATA(house1, house)->pSolar = &solar[1];
00225 
00226         // run the tests
00227         TIMESTAMP _time = gl_parsetime("2000-08-01 0:0:0 GMT");;
00228         double Tout_test[24] = {80, 77, 74, 70, 70, 70, 70, 73, 76, 79, 80, 80, 81, 80, 79, 78, 76, 75, 73, 70, 68, 66, 65, 65};
00229 
00230         house1->clock = _time;
00231 
00232         double nhours;
00233         nhours = gl_tohours(_time);
00234         double startTime = nhours;
00235         double toHour = nhours + 24;
00236         FILE *fp = fopen("house_test.csv", "w");
00237         double Tout, Tair, hvac_load;
00238         house::HCMODE unit_status;
00239         fprintf(fp, "Time stamp, Tout, Tair, Hvac_load (Btu/hr), unit_status(0=heat, 1=cool)\n");
00240 
00241         while (nhours <= toHour)
00242         {
00243             OBJECTDATA(house1, house)->thermostat(house1->clock, _time);
00244             OBJECTDATA(house1, house)->pTout = &(Tout_test[(int)(nhours+24-toHour)]);
00245             local_callbacks->myobject_sync(house1, _time, PC_PRETOPDOWN);
00246             TIMESTAMP nextSyncTime = local_callbacks->myobject_sync(house1, _time, PC_BOTTOMUP);
00247             TIMESTAMP simTime = _time + 900 * TS_RESOLUTION * TS_SECOND;  //synch every fifteen minutes
00248             
00249             // step to next hour unless hvac_load_sync needs to synch sooner
00250             if (nextSyncTime == TS_NEVER || nextSyncTime > simTime)
00251                 _time = simTime;
00252             else
00253                 _time = nextSyncTime;
00254 
00255             nhours = gl_tohours(_time);
00256             Tout = *(double *)(OBJECTDATA(house1, house)->pTout);
00257             Tair = OBJECTDATA(house1, house)->Tair;
00258             hvac_load = OBJECTDATA(house1, house)->hvac_kWh_use;
00259             unit_status = OBJECTDATA(house1, house)->heat_cool_mode;
00260             fprintf(fp, "%.2f, %.2lf, %.2lf, %.3lf, %d\n", nhours-startTime, Tout, Tair, hvac_load, (int)unit_status);
00261         }
00262 
00263     }
00264     
00265     void waterheater_test()
00266     {
00267         gl_output("\n\nWaterheater Unit Tests");
00268         gl_output("======================\n");
00269         OBJECT *house1 = house_create();
00270         OBJECTDATA(house1, house)->create();
00271 
00272         OBJECT* waterheater1;
00273         CLASS *cl = get_class_by_name("waterheater");
00274         waterheater1 = gl_create_object(cl,sizeof(waterheater));
00275         CPPUNIT_ASSERT(waterheater1 != NULL);
00276         OBJECTDATA(waterheater1, waterheater)->create();
00277         gl_set_parent(waterheater1, house1);
00278 
00279         // Water tank properties for unit test
00280         //  tank volume = 50 gallons
00281         //  tank diameter = 1.5 ft
00282         //  tank UA = 2.0
00283         //  heating element = 4500 W
00284         //  tank location = inside the house
00285 
00286         OBJECTDATA(waterheater1, waterheater)->tank_volume = 50.0;
00287         OBJECTDATA(waterheater1, waterheater)->tank_diameter = 1.5;
00288         OBJECTDATA(waterheater1, waterheater)->tank_UA = 2;
00289         OBJECTDATA(waterheater1, waterheater)->heating_element_capacity = 4500.0;
00290         OBJECTDATA(waterheater1, waterheater)->location = waterheater::INSIDE;
00291 
00292         CPPUNIT_ASSERT(local_callbacks->init_objects() != FAILED);
00293         CPPUNIT_ASSERT(local_callbacks->setup_test_ranks() != FAILED);
00294 
00295         // call sync to set derived properties and sync the object clock and simulation clock
00296         TIMESTAMP _time = gl_parsetime("2000-08-01 0:0:0 GMT");;
00297         waterheater1->clock = _time;
00298         TIMESTAMP nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00299 
00300         double nhours;
00301 
00302         // Test 1:  Time to decay from 140 degF to 120 F
00303         OBJECTDATA(waterheater1, waterheater)->tank_setpoint = 130.0;
00304         OBJECTDATA(waterheater1, waterheater)->thermostat_deadband = 20.0;
00305         OBJECTDATA(waterheater1, waterheater)->Tw = 140.0;
00306         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00307         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00308         gl_output("\nTest 1:  Time to decay from 140 degF to 120 F");
00309         gl_output("Expected value :  72.641 hours\nGridlabD output:  %.3lf hours\n", nhours);
00310 
00311         // Test 2:  Time to simple recovery from 110 degF to 135 F
00312         OBJECTDATA(waterheater1, waterheater)->tank_setpoint = 130.0;
00313         OBJECTDATA(waterheater1, waterheater)->thermostat_deadband = 10.0;
00314         OBJECTDATA(waterheater1, waterheater)->Tw = 110.0;
00315         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00316         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00317         gl_output("Test 2:  Time to simple recovery from 110 degF to 135 F");
00318         gl_output("Expected value :  0.683 hours\nGridlabD output:  %.3lf hours\n", nhours);
00319 
00320         // Test 3:  Time to simple recovery from 120 degF to 135 F
00321         OBJECTDATA(waterheater1, waterheater)->Tw = 120.0;
00322         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00323         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00324         gl_output("Test 3:  Time to simple recovery from 120 degF to 135 F");
00325         gl_output("Expected value :  0.410 hours\nGridlabD output:  %.3lf hours\n", nhours);
00326 
00327         // Test 4:  Time to simple recovery from 124 degF to 135 F
00328         OBJECTDATA(waterheater1, waterheater)->Tw = 124.0;
00329         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00330         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00331         gl_output("Test 4:  Time to simple recovery from 124 degF to 135 F");
00332         gl_output("Expected value :  0.301 hours\nGridlabD output:  %.3lf hours\n", nhours);
00333 
00334         OBJECTDATA(waterheater1, waterheater)->tank_setpoint = 125.0;
00335         OBJECTDATA(waterheater1, waterheater)->thermostat_deadband = 10.0;
00336         OBJECTDATA(waterheater1, waterheater)->Tw = 130.0;
00337 
00338         // Test 5:  Time to depletion at 2.5 gpm 130 degF to 125 F
00339         OBJECTDATA(waterheater1, waterheater)->water_demand = 2.5;
00340         OBJECTDATA(waterheater1, waterheater)->last_water_demand = 2.5;
00341         OBJECTDATA(waterheater1, waterheater)->h = OBJECTDATA(waterheater1, waterheater)->height;
00342         OBJECTDATA(waterheater1, waterheater)->set_current_model_and_load_state();
00343         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00344         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00345         gl_output("Test 5:  Time to depletion at 2.5 gpm from 130 degF");
00346         gl_output("Expected value :  0.405 hours\nGridlabD output:  %.3lf hours\n", nhours);
00347 
00348         // Test 6:  Time to depletion at 0.4445 gpm 130 degF to 125 F
00349         OBJECTDATA(waterheater1, waterheater)->Tw = 130.0;
00350         OBJECTDATA(waterheater1, waterheater)->water_demand = 0.4445;
00351         OBJECTDATA(waterheater1, waterheater)->last_water_demand = 0.445;
00352         OBJECTDATA(waterheater1, waterheater)->set_current_model_and_load_state();
00353         OBJECTDATA(waterheater1, waterheater)->h = OBJECTDATA(waterheater1, waterheater)->height;
00354         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00355         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00356         gl_output("Test 6:  Time to depletion at 0.445 gpm from 130 degF");
00357         gl_output("Expected value :  263.787 hours\nGridlabD output:  %.3lf hours\n", nhours);
00358 
00359         // Test 7:  Time to depletion at 0.3 gpm 130 degF to 125 F
00360         OBJECTDATA(waterheater1, waterheater)->Tw = 130.0;
00361         OBJECTDATA(waterheater1, waterheater)->water_demand = 0.3;
00362         OBJECTDATA(waterheater1, waterheater)->last_water_demand = 0.3;
00363         OBJECTDATA(waterheater1, waterheater)->h = OBJECTDATA(waterheater1, waterheater)->height;
00364         OBJECTDATA(waterheater1, waterheater)->set_current_model_and_load_state();
00365         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00366         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00367         gl_output("Test 7:  Time to depletion at 0.3 gpm from 130 degF");
00368         gl_output("Expected value :  -5.91 hours\nGridlabD output:  %.3lf hours\n", nhours);
00369 
00370         // Test 8:  Time to recovery at 2.5 gpm to 130 degF
00371         OBJECTDATA(waterheater1, waterheater)->Tw = 130.0;
00372         OBJECTDATA(waterheater1, waterheater)->water_demand = 2.5;
00373         OBJECTDATA(waterheater1, waterheater)->cur_water_demand = 2.5;
00374         OBJECTDATA(waterheater1, waterheater)->last_water_demand = 2.5;
00375         OBJECTDATA(waterheater1, waterheater)->h = 0.0;
00376         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00377         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00378         gl_output("Test 8:  Time to recovery at 2.5 gpm 130 degF to 125 F");
00379         gl_output("Expected value :  -0.404 hours\nGridlabD output:  %.3lf hours\n", nhours);
00380 
00381         // Test 9:  Time to recovery at 0.435 gpm to 130 degF
00382         OBJECTDATA(waterheater1, waterheater)->Tw = 130.0;
00383         OBJECTDATA(waterheater1, waterheater)->water_demand = 0.435;
00384         OBJECTDATA(waterheater1, waterheater)->cur_water_demand = 0.435;
00385         OBJECTDATA(waterheater1, waterheater)->last_water_demand = 0.435;
00386         OBJECTDATA(waterheater1, waterheater)->h = 0.0;
00387         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00388         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00389         gl_output("Test 9:  Time to recovery at 0.435 gpm to  130 degF");
00390         gl_output("Expected value :  146.227 hours\nGridlabD output:  %.3lf hours\n", nhours);
00391 
00392         // Test 10:  Time to recovery at 0.2 gpm to 130 degF
00393         OBJECTDATA(waterheater1, waterheater)->water_demand = 0.2;
00394         OBJECTDATA(waterheater1, waterheater)->cur_water_demand = 0.2;
00395         OBJECTDATA(waterheater1, waterheater)->last_water_demand = 0.2;
00396         OBJECTDATA(waterheater1, waterheater)->h = 0.0;
00397         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00398         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00399         gl_output("Test 10:  Time to recovery at 0.2 gpm 130 degF to 120 F");
00400         gl_output("Expected value :  3.459 hours\nGridlabD output:  %.3lf hours\n", nhours);
00401 
00402         // Test 11:  Time to recovery at 0.0 gpm to 130 degF
00403         OBJECTDATA(waterheater1, waterheater)->Tw = 130.0;
00404         OBJECTDATA(waterheater1, waterheater)->water_demand = 0.0;
00405         OBJECTDATA(waterheater1, waterheater)->cur_water_demand = 0.0;
00406         OBJECTDATA(waterheater1, waterheater)->last_water_demand = 0.0;
00407         OBJECTDATA(waterheater1, waterheater)->h = 0.0;
00408         nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00409         nhours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00410         gl_output("Test 11:  Time to recovery at 0.0 gpm to 130 degF ");
00411         gl_output("Expected value :  1.890 hours\nGridlabD output:  %.3lf hours\n", nhours);
00412 
00413         _time = gl_parsetime("2000-08-01 0:0:0 GMT");;
00414         house1->clock = _time;
00415         double water_demand[24] = {0.0, 0.0, 0.0, 0.0, 0.0, 4.0, 5.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 1.0, 0.0, 0.0, 0.0};
00416         OBJECTDATA(waterheater1, waterheater)->tank_setpoint = 130.0;
00417         OBJECTDATA(waterheater1, waterheater)->thermostat_deadband = 20.0;
00418         OBJECTDATA(waterheater1, waterheater)->Tw = 140.0;
00419         OBJECTDATA(waterheater1, waterheater)->h = OBJECTDATA(waterheater1, waterheater)->height;
00420 
00421         OBJECTDATA(waterheater1, waterheater)->heat_needed = FALSE;  //reset for the full day test
00422         nhours = gl_tohours(_time);
00423         double toHour = nhours + 24;
00424         double lasthour = nhours, nextSynchours = 0.0;
00425         gl_output("Hour      power(kW)   flowrate(gpm)    h(ft)      Tw   next synchtime");
00426 
00427         double waterheaterPower = 0.0;
00428         while (nhours <= toHour)
00429         {
00430             OBJECTDATA(waterheater1, waterheater)->water_demand = water_demand[(int)(nhours-toHour+24)];
00431             nextSyncTime = local_callbacks->myobject_sync(waterheater1, _time, PC_BOTTOMUP);
00432             nextSynchours = gl_tohours(nextSyncTime) - gl_tohours(_time);
00433             
00434             if (nextSyncTime == TS_NEVER || (nextSynchours > 1))
00435                 _time += 3600 * TS_RESOLUTION * TS_SECOND;  //synch every fifteen minutes
00436             else
00437                 _time = nextSyncTime;
00438 
00439             waterheaterPower = OBJECTDATA(waterheater1, waterheater)->power_kw.Mag();
00440 
00441             gl_output("%5.2lf, %10.2lf, %15.2lf, %7.2lf, %8.2lf, %8.2lf hrs", 
00442                 (nhours-toHour+24), waterheaterPower, water_demand[(int)(nhours-toHour+24)], OBJECTDATA(waterheater1, waterheater)->h, OBJECTDATA(waterheater1, waterheater)->Tw, nextSynchours);
00443             lasthour = nhours;
00444             nhours = gl_tohours(_time);
00445         }
00446 }
00447 
00448     /*
00449      * This section creates the suite() method that will be used by the
00450      * CPPUnit testrunner to execute the tests that we have registered.
00451      * This section needs to be in the .h file
00452      */
00453     CPPUNIT_TEST_SUITE(residential_test);
00454     /*
00455      * For each test method defined above, we should have a separate
00456      * CPPUNIT_TEST() line.
00457      */
00458     CPPUNIT_TEST(house_test);
00459     CPPUNIT_TEST(waterheater_test);
00460     CPPUNIT_TEST(lights_test);
00461     CPPUNIT_TEST(clotheswasher_test);
00462 
00463     CPPUNIT_TEST_SUITE_END();
00464 
00465     
00466 };
00467 
00468 /*
00469  * Registers the test suite with the CPPUnit registration factory.  In most
00470  * cases, this is all that is required for it to be included and run by the
00471  * module_test method in test.cpp.
00472  */
00473 CPPUNIT_TEST_SUITE_REGISTRATION(residential_test);
00474 
00475 #endif

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