00001
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017 #include <errno.h>
00018 #include <math.h>
00019 #include <iostream>
00020
00021 using namespace std;
00022
00023 #include "emissions.h"
00024
00026
00028 CLASS* emissions::oclass = NULL;
00029 CLASS* emissions::pclass = NULL;
00030
00031 emissions::emissions(MODULE *mod) : powerflow_object(mod)
00032 {
00033 if(oclass == NULL)
00034 {
00035 pclass = powerflow_object::oclass;
00036 oclass = gl_register_class(mod,"emissions",sizeof(emissions),PC_POSTTOPDOWN|PC_AUTOLOCK);
00037 if(oclass == NULL)
00038 GL_THROW("unable to register object class implemented by %s",__FILE__);
00039
00040 if(gl_publish_variable(oclass,
00041
00042 PT_double, "Nuclear_Order", PADDR(Nuclear_Order),
00043 PT_double, "Hydroelectric_Order", PADDR(Hydroelectric_Order),
00044 PT_double, "Solarthermal_Order", PADDR(Solarthermal_Order),
00045 PT_double, "Biomass_Order", PADDR(Biomass_Order),
00046 PT_double, "Wind_Order", PADDR(Wind_Order),
00047 PT_double, "Coal_Order", PADDR(Coal_Order),
00048 PT_double, "Naturalgas_Order", PADDR(Naturalgas_Order),
00049 PT_double, "Geothermal_Order", PADDR(Geothermal_Order),
00050 PT_double, "Petroleum_Order", PADDR(Petroleum_Order),
00051
00052 PT_double, "Naturalgas_Max_Out[kWh]", PADDR(Naturalgas_Max_Out),
00053 PT_double, "Coal_Max_Out[kWh]", PADDR(Coal_Max_Out),
00054 PT_double, "Biomass_Max_Out[kWh]", PADDR(Biomass_Max_Out),
00055 PT_double, "Geothermal_Max_Out[kWh]", PADDR(Geothermal_Max_Out),
00056 PT_double, "Hydroelectric_Max_Out[kWh]", PADDR(Hydroelectric_Max_Out),
00057 PT_double, "Nuclear_Max_Out[kWh]", PADDR(Nuclear_Max_Out),
00058 PT_double, "Wind_Max_Out[kWh]", PADDR(Wind_Max_Out),
00059 PT_double, "Petroleum_Max_Out[kWh]", PADDR(Petroleum_Max_Out),
00060 PT_double, "Solarthermal_Max_Out[kWh]", PADDR(Solarthermal_Max_Out),
00061
00062 PT_double, "Naturalgas_Out[kWh]", PADDR(Naturalgas_Out),
00063 PT_double, "Coal_Out[kWh]", PADDR(Coal_Out),
00064 PT_double, "Biomass_Out[kWh]", PADDR(Biomass_Out),
00065 PT_double, "Geothermal_Out[kWh]", PADDR(Geothermal_Out),
00066 PT_double, "Hydroelectric_Out[kWh]", PADDR(Hydroelectric_Out),
00067 PT_double, "Nuclear_Out[kWh]", PADDR(Nuclear_Out),
00068 PT_double, "Wind_Out[kWh]", PADDR(Wind_Out),
00069 PT_double, "Petroleum_Out[kWh]", PADDR(Petroleum_Out),
00070 PT_double, "Solarthermal_Out[kWh]", PADDR(Solarthermal_Out),
00071
00072 PT_double, "Naturalgas_Conv_Eff[Btu/kWh]", PADDR(Naturalgas_Conv_Eff),
00073 PT_double, "Coal_Conv_Eff[Btu/kWh]", PADDR(Coal_Conv_Eff),
00074 PT_double, "Biomass_Conv_Eff[Btu/kWh]", PADDR(Biomass_Conv_Eff),
00075 PT_double, "Geothermal_Conv_Eff[Btu/kWh]", PADDR(Geothermal_Conv_Eff),
00076 PT_double, "Hydroelectric_Conv_Eff[Btu/kWh]", PADDR(Hydroelectric_Conv_Eff),
00077 PT_double, "Nuclear_Conv_Eff[Btu/kWh]", PADDR(Nuclear_Conv_Eff),
00078 PT_double, "Wind_Conv_Eff[Btu/kWh]", PADDR(Wind_Conv_Eff),
00079 PT_double, "Petroleum_Conv_Eff[Btu/kWh]", PADDR(Petroleum_Conv_Eff),
00080 PT_double, "Solarthermal_Conv_Eff[Btu/kWh]", PADDR(Solarthermal_Conv_Eff),
00081
00082 PT_double, "Naturalgas_CO2[lb/Btu]", PADDR(Naturalgas_CO2),
00083 PT_double, "Coal_CO2[lb/Btu]", PADDR(Coal_CO2),
00084 PT_double, "Biomass_CO2[lb/Btu]", PADDR(Biomass_CO2),
00085 PT_double, "Geothermal_CO2[lb/Btu]", PADDR(Geothermal_CO2),
00086 PT_double, "Hydroelectric_CO2[lb/Btu]", PADDR(Hydroelectric_CO2),
00087 PT_double, "Nuclear_CO2[lb/Btu]", PADDR(Nuclear_CO2),
00088 PT_double, "Wind_CO2[lb/Btu]", PADDR(Wind_CO2),
00089 PT_double, "Petroleum_CO2[lb/Btu]", PADDR(Petroleum_CO2),
00090 PT_double, "Solarthermal_CO2[lb/Btu]", PADDR(Solarthermal_CO2),
00091
00092 PT_double, "Naturalgas_SO2[lb/Btu]", PADDR(Naturalgas_SO2),
00093 PT_double, "Coal_SO2[lb/Btu]", PADDR(Coal_SO2),
00094 PT_double, "Biomass_SO2[lb/Btu]", PADDR(Biomass_SO2),
00095 PT_double, "Geothermal_SO2[lb/Btu]", PADDR(Geothermal_SO2),
00096 PT_double, "Hydroelectric_SO2[lb/Btu]", PADDR(Hydroelectric_SO2),
00097 PT_double, "Nuclear_SO2[lb/Btu]", PADDR(Nuclear_SO2),
00098 PT_double, "Wind_SO2[lb/Btu]", PADDR(Wind_SO2),
00099 PT_double, "Petroleum_SO2[lb/Btu]", PADDR(Petroleum_SO2),
00100 PT_double, "Solarthermal_SO2[lb/Btu]", PADDR(Solarthermal_SO2),
00101
00102 PT_double, "Naturalgas_NOx[lb/Btu]", PADDR(Naturalgas_NOx),
00103 PT_double, "Coal_NOx[lb/Btu]", PADDR(Coal_NOx),
00104 PT_double, "Biomass_NOx[lb/Btu]", PADDR(Biomass_NOx),
00105 PT_double, "Geothermal_NOx[lb/Btu]", PADDR(Geothermal_NOx),
00106 PT_double, "Hydroelectric_NOx[lb/Btu]", PADDR(Hydroelectric_NOx),
00107 PT_double, "Nuclear_NOx[lb/Btu]", PADDR(Nuclear_NOx),
00108 PT_double, "Wind_NOx[lb/Btu]", PADDR(Wind_NOx),
00109 PT_double, "Petroleum_NOx[lb/Btu]", PADDR(Petroleum_NOx),
00110 PT_double, "Solarthermal_NOx[lb/Btu]", PADDR(Solarthermal_NOx),
00111
00112 PT_double, "Naturalgas_emissions_CO2[lb]", PADDR(Naturalgas_emissions_CO2),
00113 PT_double, "Naturalgas_emissions_SO2[lb]", PADDR(Naturalgas_emissions_SO2),
00114 PT_double, "Naturalgas_emissions_NOx[lb]", PADDR(Naturalgas_emissions_NOx),
00115
00116 PT_double, "Coal_emissions_CO2[lb]", PADDR(Coal_emissions_CO2),
00117 PT_double, "Coal_emissions_SO2[lb]", PADDR(Coal_emissions_SO2),
00118 PT_double, "Coal_emissions_NOx[lb]", PADDR(Coal_emissions_NOx),
00119
00120 PT_double, "Biomass_emissions_CO2[lb]", PADDR(Biomass_emissions_CO2),
00121 PT_double, "Biomass_emissions_SO2[lb]", PADDR(Biomass_emissions_SO2),
00122 PT_double, "Biomass_emissions_NOx[lb]", PADDR(Biomass_emissions_NOx),
00123
00124 PT_double, "Geothermal_emissions_CO2[lb]", PADDR(Geothermal_emissions_CO2),
00125 PT_double, "Geothermal_emissions_SO2[lb]", PADDR(Geothermal_emissions_SO2),
00126 PT_double, "Geothermal_emissions_NOx[lb]", PADDR(Geothermal_emissions_NOx),
00127
00128 PT_double, "Hydroelectric_emissions_CO2[lb]", PADDR(Hydroelectric_emissions_CO2),
00129 PT_double, "Hydroelectric_emissions_SO2[lb]", PADDR(Hydroelectric_emissions_SO2),
00130 PT_double, "Hydroelectric_emissions_NOx[lb]", PADDR(Hydroelectric_emissions_NOx),
00131
00132 PT_double, "Nuclear_emissions_CO2[lb]", PADDR(Nuclear_emissions_CO2),
00133 PT_double, "Nuclear_emissions_SO2[lb]", PADDR(Nuclear_emissions_SO2),
00134 PT_double, "Nuclear_emissions_NOx[lb]", PADDR(Nuclear_emissions_NOx),
00135
00136 PT_double, "Wind_emissions_CO2[lb]", PADDR(Wind_emissions_CO2),
00137 PT_double, "Wind_emissions_SO2[lb]", PADDR(Wind_emissions_SO2),
00138 PT_double, "Wind_emissions_NOx[lb]", PADDR(Wind_emissions_NOx),
00139
00140 PT_double, "Petroleum_emissions_CO2[lb]", PADDR(Petroleum_emissions_CO2),
00141 PT_double, "Petroleum_emissions_SO2[lb]", PADDR(Petroleum_emissions_SO2),
00142 PT_double, "Petroleum_emissions_NOx[lb]", PADDR(Petroleum_emissions_NOx),
00143
00144 PT_double, "Solarthermal_emissions_CO2[lb]", PADDR(Solarthermal_emissions_CO2),
00145 PT_double, "Solarthermal_emissions_SO2[lb]", PADDR(Solarthermal_emissions_SO2),
00146 PT_double, "Solarthermal_emissions_NOx[lb]", PADDR(Solarthermal_emissions_NOx),
00147
00148 PT_double, "Total_emissions_CO2[lb]", PADDR(Total_emissions_CO2),
00149 PT_double, "Total_emissions_SO2[lb]", PADDR(Total_emissions_SO2),
00150 PT_double, "Total_emissions_NOx[lb]", PADDR(Total_emissions_NOx),
00151
00152 PT_double, "Total_energy_out[kWh]", PADDR(Total_energy_out),
00153
00154 PT_double, "Region", PADDR(Region),
00155
00156 PT_double,"cycle_interval[s]", PADDR(cycle_interval),
00157 NULL) < 1) GL_THROW("unable to publish properties in %s",__FILE__);
00158 }
00159 }
00160
00161 int emissions::isa(char *classname)
00162 {
00163 return strcmp(classname,"emissions")==0;
00164 }
00165
00166 int emissions::create(void)
00167 {
00168 int rval;
00169
00170 rval = powerflow_object::create();
00171
00172 phases = PHASE_A;
00173
00174 parent_meter_total_power = NULL;
00175
00176
00177 cycle_interval_TS = 0;
00178 time_cycle_interval = 0;
00179 prev_cycle_time = 0;
00180 curr_cycle_time = 0;
00181
00182
00183 accumulated_energy = 0.0;
00184 cycle_power = 0.0;
00185
00186
00187
00188 Nuclear_Order = 1;
00189 Hydroelectric_Order = 2;
00190 Solarthermal_Order = 3;
00191 Biomass_Order = 4;
00192 Wind_Order = 5;
00193 Coal_Order = 6;
00194 Naturalgas_Order= 7;
00195 Geothermal_Order = 8;
00196 Petroleum_Order = 9;
00197
00198 Naturalgas_Out= 0.0;
00199 Coal_Out = 0.0;
00200 Biomass_Out = 0.0;
00201 Geothermal_Out = 0.0;
00202 Hydroelectric_Out = 0.0;
00203 Nuclear_Out = 0.0;
00204 Wind_Out = 0.0;
00205 Petroleum_Out = 0.0;
00206 Solarthermal_Out = 0.0;
00207
00208 Naturalgas_Max_Out= 0.0;
00209 Coal_Max_Out = 0.0;
00210 Biomass_Max_Out = 0.0;
00211 Geothermal_Max_Out = 0.0;
00212 Hydroelectric_Max_Out = 0.0;
00213 Nuclear_Max_Out = 0.0;
00214 Wind_Max_Out = 0.0;
00215 Petroleum_Max_Out = 0.0;
00216 Solarthermal_Max_Out = 0.0;
00217
00218 Naturalgas_Conv_Eff = 0.0;
00219 Coal_Conv_Eff = 0.0;
00220 Biomass_Conv_Eff = 0.0;
00221 Geothermal_Conv_Eff = 0.0;
00222 Hydroelectric_Conv_Eff = 0.0;
00223 Nuclear_Conv_Eff = 0.0;
00224 Wind_Conv_Eff = 0.0;
00225 Petroleum_Conv_Eff = 0.0;
00226 Solarthermal_Conv_Eff = 0.0;
00227 Naturalgas_CO2 = 0.0;
00228 Coal_CO2 = 0.0;
00229 Biomass_CO2 = 0.0;
00230 Geothermal_CO2 = 0.0;
00231 Hydroelectric_CO2 = 0.0;
00232 Nuclear_CO2 = 0.0;
00233 Wind_CO2 = 0.0;
00234 Petroleum_CO2 = 0.0;
00235 Solarthermal_CO2 = 0.0;
00236 Naturalgas_SO2 = 0.0;
00237 Coal_SO2 = 0.0;
00238 Biomass_SO2 = 0.0;
00239 Geothermal_SO2 = 0.0;
00240 Hydroelectric_SO2 = 0.0;
00241 Nuclear_SO2 = 0.0;
00242 Wind_SO2 = 0.0;
00243 Petroleum_SO2 = 0.0;
00244 Solarthermal_SO2 = 0.0;
00245 Naturalgas_NOx = 0.0;
00246 Coal_NOx = 0.0;
00247 Biomass_NOx = 0.0;
00248 Geothermal_NOx = 0.0;
00249 Hydroelectric_NOx = 0.0;
00250 Nuclear_NOx = 0.0;
00251 Wind_NOx = 0.0;
00252 Petroleum_NOx = 0.0;
00253 Solarthermal_NOx = 0.0;
00254
00255 Naturalgas_Out = 0.0;
00256 Coal_Out = 0.0;
00257 Biomass_Out = 0.0;
00258 Geothermal_Out = 0.0;
00259 Hydroelectric_Out = 0.0;
00260 Nuclear_Out = 0.0;
00261 Wind_Out = 0.0;
00262 Petroleum_Out = 0.0;
00263 Solarthermal_Out = 0.0;
00264
00265 Naturalgas_emissions_CO2 = 0.0;
00266 Naturalgas_emissions_SO2 = 0.0;
00267 Naturalgas_emissions_NOx = 0.0;
00268 Coal_emissions_CO2 = 0.0;
00269 Coal_emissions_SO2 = 0.0;
00270 Coal_emissions_NOx = 0.0;
00271 Biomass_emissions_CO2 = 0.0;
00272 Biomass_emissions_SO2 = 0.0;
00273 Biomass_emissions_NOx = 0.0;
00274 Geothermal_emissions_CO2 = 0.0;
00275 Geothermal_emissions_SO2 = 0.0;
00276 Geothermal_emissions_NOx = 0.0;
00277 Hydroelectric_emissions_CO2 = 0.0;
00278 Hydroelectric_emissions_SO2 = 0.0;
00279 Hydroelectric_emissions_NOx = 0.0;
00280 Nuclear_emissions_CO2 = 0.0;
00281 Nuclear_emissions_SO2 = 0.0;
00282 Nuclear_emissions_NOx = 0.0;
00283 Wind_emissions_CO2 = 0.0;
00284 Wind_emissions_SO2 = 0.0;
00285 Wind_emissions_NOx = 0.0;
00286 Petroleum_emissions_CO2 = 0.0;
00287 Petroleum_emissions_SO2 = 0.0;
00288 Petroleum_emissions_NOx = 0.0;
00289 Solarthermal_emissions_CO2 = 0.0;
00290 Solarthermal_emissions_SO2 = 0.0;
00291 Solarthermal_emissions_NOx = 0.0;
00292 Total_emissions_CO2 = 0.0;
00293 Total_emissions_SO2 = 0.0;
00294 Total_emissions_NOx = 0.0;
00295 Total_energy_out = 0.0;
00296
00297 return rval;
00298 }
00299
00300 int emissions::init(OBJECT *parent)
00301 {
00302 int rval;
00303 OBJECT *obj = OBJECTHDR(this);
00304
00305 rval = powerflow_object::init(parent);
00306
00307
00308 if (parent!=NULL)
00309 {
00310
00311 if (gl_object_isa(parent,"meter","powerflow"))
00312 {
00313
00314 parent_meter_total_power = new gld_property(parent,"measured_power");
00315
00316
00317 if ((parent_meter_total_power->is_valid() != true) || (parent_meter_total_power->is_complex() != true))
00318 {
00319 GL_THROW("emissions:%d - %s - Unable to map parent object's power value",obj->id,(obj->name ? obj->name : "Unnamed"));
00320
00321
00322
00323
00324 }
00325 }
00326 else
00327 {
00328 GL_THROW("emissions:%s must be parented to a three-phase meter to work!",obj->name);
00329
00330
00331
00332
00333 }
00334 }
00335 else
00336 {
00337 GL_THROW("emissions:%s must be parented to a three-phase meter to work!",obj->name);
00338
00339 }
00340
00341
00342 if (cycle_interval == 0.0)
00343 cycle_interval = 900.0;
00344
00345
00346 if (cycle_interval <= 0)
00347 {
00348 GL_THROW("emissions:%s must have a positive cycle_interval time",obj->name);
00349
00350
00351
00352
00353 }
00354
00355 if (Nuclear_Order==0)
00356 {
00357 gl_verbose("Emissions:%s has nuclear disabled.",obj->name);
00358
00359
00360
00361
00362 }
00363
00364 if (Hydroelectric_Order==0)
00365 {
00366 gl_verbose("Emissions:%s has hydro disabled.",obj->name);
00367
00368
00369
00370
00371 }
00372
00373 if (Solarthermal_Order==0)
00374 {
00375 gl_verbose("Emissions:%s has solar disabled.",obj->name);
00376
00377
00378
00379
00380 }
00381
00382 if (Biomass_Order==0)
00383 {
00384 gl_verbose("Emissions:%s has biomass disabled.",obj->name);
00385
00386
00387
00388
00389 }
00390
00391 if (Wind_Order==0)
00392 {
00393 gl_verbose("Emissions:%s has wind disabled.",obj->name);
00394
00395
00396
00397
00398 }
00399
00400 if (Coal_Order==0)
00401 {
00402 gl_verbose("Emissions:%s has coal disabled.",obj->name);
00403
00404
00405
00406
00407 }
00408
00409 if (Naturalgas_Order==0)
00410 {
00411 gl_verbose("Emissions:%s has natural gas disabled.",obj->name);
00412
00413
00414
00415
00416 }
00417
00418 if (Geothermal_Order==0)
00419 {
00420 gl_verbose("Emissions:%s has geothermal disabled.",obj->name);
00421
00422
00423
00424
00425 }
00426
00427 if (Petroleum_Order==0)
00428 {
00429 gl_verbose("Emissions:%s has petroleum disabled.",obj->name);
00430
00431
00432
00433
00434 }
00435
00436
00437
00438 cycle_interval_TS = (TIMESTAMP)(cycle_interval);
00439 return rval;
00440 }
00441
00442 TIMESTAMP emissions::postsync(TIMESTAMP t0)
00443 {
00444 double temp_energy, dispatch_order;;
00445 complex temp_power;
00446 complex energy_for_calc;
00447 bool energy_requirement;
00448 OBJECT *obj = OBJECTHDR(this);
00449 TIMESTAMP tret = powerflow_object::postsync(t0);
00450
00451
00452
00453
00454 if ((prev_cycle_time == 0) && (t0 != 0))
00455 {
00456 time_cycle_interval = t0 + cycle_interval_TS;
00457 }
00458
00459 if (prev_cycle_time != t0)
00460 {
00461
00462 curr_cycle_time = t0;
00463
00464
00465 dt_val = (double)(curr_cycle_time - prev_cycle_time);
00466
00467
00468 prev_cycle_time = t0;
00469
00470
00471 temp_energy = cycle_power* dt_val/3600;
00472 accumulated_energy += temp_energy;
00473
00474 Naturalgas_Max_Out = Naturalgas_Max_Out * cycle_interval/3600;
00475 Coal_Max_Out = Coal_Max_Out * cycle_interval/3600;
00476 Biomass_Max_Out = Biomass_Max_Out * cycle_interval/3600;
00477 Geothermal_Max_Out = Geothermal_Max_Out * cycle_interval/3600;
00478 Hydroelectric_Max_Out = Hydroelectric_Max_Out * cycle_interval/3600;
00479 Nuclear_Max_Out = Nuclear_Max_Out * cycle_interval/3600;
00480 Wind_Max_Out = Wind_Max_Out * cycle_interval/3600;
00481 Petroleum_Max_Out = Petroleum_Max_Out * cycle_interval/3600;
00482 Solarthermal_Max_Out = Solarthermal_Max_Out * cycle_interval/3600;
00483 }
00484
00485
00486 if (curr_cycle_time == t0)
00487 {
00488
00489 temp_power = parent_meter_total_power->get_complex();
00490 cycle_power = (temp_power.Re()) / 1000.0;
00491 }
00492
00493
00494
00495
00496 if (curr_cycle_time >= time_cycle_interval)
00497 {
00498
00499 energy_requirement = true;
00500
00501
00502 energy_for_calc = accumulated_energy;
00503
00504
00505
00506
00507
00508 for (dispatch_order = 0; dispatch_order < 10; dispatch_order++)
00509 {
00510
00511
00512
00513
00514 if (dispatch_order == Nuclear_Order)
00515 {
00516 if ((Nuclear_Max_Out < energy_for_calc.Mag() && energy_requirement == true) && (dispatch_order != 0))
00517
00518 {
00519 Nuclear_Out = Nuclear_Max_Out;
00520
00521 Nuclear_emissions_CO2 = Nuclear_Out * Nuclear_Conv_Eff * Nuclear_CO2;
00522 Nuclear_emissions_SO2 = Nuclear_Out * Nuclear_Conv_Eff * Nuclear_SO2;
00523 Nuclear_emissions_NOx = Nuclear_Out * Nuclear_Conv_Eff * Nuclear_NOx;
00524
00525 energy_for_calc = energy_for_calc - Nuclear_Max_Out;
00526 }
00527 else if ((energy_requirement == true) && (dispatch_order != 0))
00528 {
00529 Nuclear_Out = energy_for_calc.Mag();
00530
00531 Nuclear_emissions_CO2 = Nuclear_Out * Nuclear_Conv_Eff * Nuclear_CO2;
00532 Nuclear_emissions_SO2 = Nuclear_Out * Nuclear_Conv_Eff * Nuclear_SO2;
00533 Nuclear_emissions_NOx = Nuclear_Out * Nuclear_Conv_Eff * Nuclear_NOx;
00534
00535 energy_requirement = false;
00536
00537 energy_for_calc = energy_for_calc - Nuclear_Out;
00538
00539 }
00540 else
00541 {
00542 Nuclear_Out = 0.0;
00543
00544
00545 Nuclear_emissions_CO2 = 0.0;
00546 Nuclear_emissions_SO2 = 0.0;
00547 Nuclear_emissions_NOx = 0.0;
00548 }
00549 }
00550
00551 if (dispatch_order == Hydroelectric_Order)
00552 {
00553 if ((Hydroelectric_Max_Out < energy_for_calc.Mag() && energy_requirement == true) && (dispatch_order != 0))
00554 {
00555 Hydroelectric_Out = Hydroelectric_Max_Out;
00556
00557 Hydroelectric_emissions_CO2 = Hydroelectric_Out * Hydroelectric_Conv_Eff * Hydroelectric_CO2;
00558 Hydroelectric_emissions_SO2 = Hydroelectric_Out * Hydroelectric_Conv_Eff * Hydroelectric_SO2;
00559 Hydroelectric_emissions_NOx = Hydroelectric_Out * Hydroelectric_Conv_Eff * Hydroelectric_NOx;
00560
00561 energy_for_calc = energy_for_calc - Hydroelectric_Max_Out;
00562 }
00563 else if ((energy_requirement == true) && (dispatch_order != 0))
00564 {
00565 Hydroelectric_Out = energy_for_calc.Mag();
00566
00567 Hydroelectric_emissions_CO2 = Hydroelectric_Out * Hydroelectric_Conv_Eff * Hydroelectric_CO2;
00568 Hydroelectric_emissions_SO2 = Hydroelectric_Out * Hydroelectric_Conv_Eff * Hydroelectric_SO2;
00569 Hydroelectric_emissions_NOx = Hydroelectric_Out * Hydroelectric_Conv_Eff * Hydroelectric_NOx;
00570
00571 energy_requirement = false;
00572
00573 energy_for_calc = energy_for_calc - Hydroelectric_Out;
00574
00575 }
00576 else
00577 {
00578 Hydroelectric_Out = 0.0;
00579
00580
00581 Hydroelectric_emissions_CO2 = 0.0;
00582 Hydroelectric_emissions_SO2 = 0.0;
00583 Hydroelectric_emissions_NOx = 0.0;
00584 }
00585 }
00586
00587 if (dispatch_order == Solarthermal_Order)
00588 {
00589 if ((Solarthermal_Max_Out < energy_for_calc.Mag() && energy_requirement == true) && (dispatch_order != 0))
00590 {
00591 Solarthermal_Out = Solarthermal_Max_Out;
00592
00593 Solarthermal_emissions_CO2 = Solarthermal_Out * Solarthermal_Conv_Eff * Solarthermal_CO2;
00594 Solarthermal_emissions_SO2 = Solarthermal_Out * Solarthermal_Conv_Eff * Solarthermal_SO2;
00595 Solarthermal_emissions_NOx = Solarthermal_Out * Solarthermal_Conv_Eff * Solarthermal_NOx;
00596
00597 energy_for_calc = energy_for_calc - Solarthermal_Max_Out;
00598 }
00599 else if ((energy_requirement == true) && (dispatch_order != 0))
00600 {
00601 Solarthermal_Out = energy_for_calc.Mag();
00602
00603 Solarthermal_emissions_CO2 = Solarthermal_Out * Solarthermal_Conv_Eff * Solarthermal_CO2;
00604 Solarthermal_emissions_SO2 = Solarthermal_Out * Solarthermal_Conv_Eff * Solarthermal_SO2;
00605 Solarthermal_emissions_NOx = Solarthermal_Out * Solarthermal_Conv_Eff * Solarthermal_NOx;
00606
00607 energy_for_calc = energy_for_calc - Solarthermal_Out;
00608
00609 }
00610 else
00611 {
00612 Solarthermal_Out = 0.0;
00613
00614
00615 Solarthermal_emissions_CO2 = 0.0;
00616 Solarthermal_emissions_SO2 = 0.0;
00617 Solarthermal_emissions_NOx = 0.0;
00618 }
00619 }
00620
00621 if (dispatch_order == Biomass_Order)
00622 {
00623 if ((Biomass_Max_Out < energy_for_calc.Mag() && energy_requirement == true) && (dispatch_order != 0))
00624 {
00625 Biomass_Out = Biomass_Max_Out ;
00626
00627 Biomass_emissions_CO2 = Biomass_Out * Biomass_Conv_Eff * Biomass_CO2;
00628 Biomass_emissions_SO2 = Biomass_Out * Biomass_Conv_Eff * Biomass_SO2;
00629 Biomass_emissions_NOx = Biomass_Out * Biomass_Conv_Eff * Biomass_NOx;
00630
00631 energy_for_calc = energy_for_calc - Biomass_Max_Out;
00632 }
00633 else if ((energy_requirement == true) && (dispatch_order != 0))
00634 {
00635 Biomass_Out = energy_for_calc.Mag();
00636
00637 Biomass_emissions_CO2 = Biomass_Out * Biomass_Conv_Eff * Biomass_CO2;
00638 Biomass_emissions_SO2 = Biomass_Out * Biomass_Conv_Eff * Biomass_SO2;
00639 Biomass_emissions_NOx = Biomass_Out * Biomass_Conv_Eff * Biomass_NOx;
00640
00641 energy_requirement = false;
00642
00643 energy_for_calc = energy_for_calc - Biomass_Out;
00644
00645 }
00646 else
00647 {
00648 Biomass_Out = 0.0;
00649
00650
00651 Biomass_emissions_CO2 = 0.0;
00652 Biomass_emissions_SO2 = 0.0;
00653 Biomass_emissions_NOx = 0.0;
00654 }
00655 }
00656
00657 if (dispatch_order == Wind_Order)
00658 {
00659 if ((Wind_Max_Out < energy_for_calc.Mag() && energy_requirement == true) && (dispatch_order != 0))
00660 {
00661 Wind_Out = Wind_Max_Out;
00662
00663 Wind_emissions_CO2 = Wind_Out * Wind_Conv_Eff * Wind_CO2;
00664 Wind_emissions_SO2 = Wind_Out * Wind_Conv_Eff * Wind_SO2;
00665 Wind_emissions_NOx = Wind_Out * Wind_Conv_Eff * Wind_NOx;
00666
00667 energy_for_calc = energy_for_calc - Wind_Max_Out;
00668 }
00669 else if ((energy_requirement == true) && (dispatch_order != 0))
00670 {
00671 Wind_Out = energy_for_calc.Mag();
00672
00673 Wind_emissions_CO2 = Wind_Out * Wind_Conv_Eff * Wind_CO2;
00674 Wind_emissions_SO2 = Wind_Out * Wind_Conv_Eff * Wind_SO2;
00675 Wind_emissions_NOx = Wind_Out * Wind_Conv_Eff * Wind_NOx;
00676
00677 energy_requirement = false;
00678
00679 energy_for_calc = energy_for_calc - Wind_Out;
00680
00681 }
00682 else
00683 {
00684 Wind_Out = 0.0;
00685
00686
00687 Wind_emissions_CO2 = 0.0;
00688 Wind_emissions_SO2 = 0.0;
00689 Wind_emissions_NOx = 0.0;
00690 }
00691 }
00692
00693 if (dispatch_order == Coal_Order)
00694 {
00695 if ((Coal_Max_Out < energy_for_calc.Mag() && energy_requirement == true) && (dispatch_order != 0))
00696 {
00697 Coal_Out = Coal_Max_Out;
00698
00699 Coal_emissions_CO2 = Coal_Out * Coal_Conv_Eff * Coal_CO2;
00700 Coal_emissions_SO2 = Coal_Out * Coal_Conv_Eff * Coal_SO2;
00701 Coal_emissions_NOx = Coal_Out * Coal_Conv_Eff * Coal_NOx;
00702
00703 energy_for_calc = energy_for_calc - Coal_Max_Out;
00704 }
00705 else if ((energy_requirement == true) && (dispatch_order != 0))
00706 {
00707 Coal_Out = energy_for_calc.Mag();
00708
00709 Coal_emissions_CO2 = Coal_Out * Coal_Conv_Eff * Coal_CO2;
00710 Coal_emissions_SO2 = Coal_Out * Coal_Conv_Eff * Coal_SO2;
00711 Coal_emissions_NOx = Coal_Out * Coal_Conv_Eff * Coal_NOx;
00712
00713 energy_requirement = false;
00714
00715 energy_for_calc = energy_for_calc - Coal_Out;
00716
00717 }
00718 else
00719 {
00720 Coal_Out = 0.0;
00721
00722
00723 Coal_emissions_CO2 = 0.0;
00724 Coal_emissions_SO2 = 0.0;
00725 Coal_emissions_NOx = 0.0;
00726 }
00727 }
00728
00729
00730 if (dispatch_order == Naturalgas_Order)
00731 {
00732 if ((Naturalgas_Max_Out < energy_for_calc.Mag()) && (energy_requirement == true) && (dispatch_order != 0))
00733 {
00734 Naturalgas_Out = Naturalgas_Max_Out;
00735
00736 Naturalgas_emissions_CO2 = Naturalgas_Out * Naturalgas_Conv_Eff * Naturalgas_CO2;
00737 Naturalgas_emissions_SO2 = Naturalgas_Out * Naturalgas_Conv_Eff * Naturalgas_SO2;
00738 Naturalgas_emissions_NOx = Naturalgas_Out * Naturalgas_Conv_Eff * Naturalgas_NOx;
00739
00740 energy_for_calc = energy_for_calc - Naturalgas_Max_Out;
00741 }
00742 else if ((energy_requirement == true) && (dispatch_order != 0))
00743 {
00744 Naturalgas_Out = energy_for_calc.Mag();
00745
00746 Naturalgas_emissions_CO2 = Naturalgas_Out * Naturalgas_Conv_Eff * Naturalgas_CO2;
00747 Naturalgas_emissions_SO2 = Naturalgas_Out * Naturalgas_Conv_Eff * Naturalgas_SO2;
00748 Naturalgas_emissions_NOx = Naturalgas_Out * Naturalgas_Conv_Eff* Naturalgas_NOx;
00749
00750 energy_requirement = false;
00751
00752 energy_for_calc = energy_for_calc - Naturalgas_Out;
00753
00754 }
00755 else
00756 {
00757 Naturalgas_Out = 0.0;
00758
00759
00760 Naturalgas_emissions_CO2 = 0.0;
00761 Naturalgas_emissions_SO2 = 0.0;
00762 Naturalgas_emissions_NOx = 0.0;
00763 }
00764 }
00765
00766 if (dispatch_order == Geothermal_Order)
00767 {
00768 if ((Geothermal_Max_Out < energy_for_calc.Mag() && energy_requirement == true) && (dispatch_order != 0))
00769 {
00770 Geothermal_Out = Geothermal_Max_Out;
00771
00772 Geothermal_emissions_CO2 = Geothermal_Out * Geothermal_Conv_Eff * Geothermal_CO2;
00773 Geothermal_emissions_SO2 = Geothermal_Out * Geothermal_Conv_Eff * Geothermal_SO2;
00774 Geothermal_emissions_NOx = Geothermal_Out * Geothermal_Conv_Eff * Geothermal_NOx;
00775
00776 energy_for_calc = energy_for_calc - Geothermal_Max_Out;
00777 }
00778 else if ((energy_requirement == true) && (dispatch_order != 0))
00779 {
00780 Geothermal_Out = energy_for_calc.Mag();
00781
00782 Geothermal_emissions_CO2 = Geothermal_Out * Geothermal_Conv_Eff * Geothermal_CO2;
00783 Geothermal_emissions_SO2 = Geothermal_Out * Geothermal_Conv_Eff * Geothermal_SO2;
00784 Geothermal_emissions_NOx = Geothermal_Out * Geothermal_Conv_Eff * Geothermal_NOx;
00785
00786 energy_requirement = false;
00787
00788 energy_for_calc = energy_for_calc - Geothermal_Out;
00789
00790 }
00791 else
00792 {
00793 Geothermal_Out = 0.0;
00794
00795
00796 Geothermal_emissions_CO2 = 0.0;
00797 Geothermal_emissions_SO2 = 0.0;
00798 Geothermal_emissions_NOx = 0.0;
00799 }
00800 }
00801
00802 if (dispatch_order == Petroleum_Order)
00803 {
00804 if ((Petroleum_Max_Out < energy_for_calc.Mag() && energy_requirement == true) && (dispatch_order != 0))
00805 {
00806 Petroleum_Out = Petroleum_Max_Out;
00807
00808 Petroleum_emissions_CO2 = Petroleum_Out * Petroleum_Conv_Eff * Petroleum_CO2;
00809 Petroleum_emissions_SO2 = Petroleum_Out * Petroleum_Conv_Eff * Petroleum_SO2;
00810 Petroleum_emissions_NOx = Petroleum_Out * Petroleum_Conv_Eff * Petroleum_NOx;
00811
00812 energy_for_calc = energy_for_calc - Petroleum_Max_Out;
00813 }
00814 else if ((energy_requirement == true) && (dispatch_order != 0))
00815 {
00816 Petroleum_Out = energy_for_calc.Mag();
00817
00818 Petroleum_emissions_CO2 = Petroleum_Out * Petroleum_Conv_Eff * Petroleum_CO2;
00819 Petroleum_emissions_SO2 = Petroleum_Out * Petroleum_Conv_Eff * Petroleum_SO2;
00820 Petroleum_emissions_NOx = Petroleum_Out * Petroleum_Conv_Eff * Petroleum_NOx;
00821
00822 energy_requirement = false;
00823
00824 energy_for_calc = energy_for_calc - Petroleum_Out;
00825
00826 }
00827 else
00828 {
00829 Petroleum_Out = 0.0;
00830
00831
00832 Petroleum_emissions_CO2 = 0.0;
00833 Petroleum_emissions_SO2 = 0.0;
00834 Petroleum_emissions_NOx = 0.0;
00835 }
00836 }
00837 }
00838
00839
00840 if (energy_for_calc.Mag() > 0)
00841 {
00842 Coal_Out = Coal_Out + energy_for_calc.Mag();
00843 }
00844
00845 Total_energy_out = Naturalgas_Out + Coal_Out + Biomass_Out + Geothermal_Out + Hydroelectric_Out + Nuclear_Out + Wind_Out + Petroleum_Out + Solarthermal_Out;
00846
00847 Total_emissions_CO2 = Naturalgas_emissions_CO2 + Coal_emissions_CO2 + Biomass_emissions_CO2 + Geothermal_emissions_CO2 + Hydroelectric_emissions_CO2 + Nuclear_emissions_CO2 + Wind_emissions_CO2 + Petroleum_emissions_CO2 + Solarthermal_emissions_CO2;
00848
00849 Total_emissions_SO2 = Naturalgas_emissions_SO2 + Coal_emissions_SO2 + Biomass_emissions_SO2 + Geothermal_emissions_SO2 + Hydroelectric_emissions_SO2 + Nuclear_emissions_SO2 + Wind_emissions_SO2 + Petroleum_emissions_SO2 + Solarthermal_emissions_SO2;
00850
00851 Total_emissions_NOx = Naturalgas_emissions_NOx + Coal_emissions_NOx + Biomass_emissions_NOx + Geothermal_emissions_NOx + Hydroelectric_emissions_NOx + Nuclear_emissions_NOx + Wind_emissions_NOx + Petroleum_emissions_NOx + Solarthermal_emissions_NOx;
00852
00853
00854 accumulated_energy = 0.0;
00855
00856
00857 time_cycle_interval += cycle_interval_TS;
00858
00859 }
00860
00861
00862 if (tret > time_cycle_interval)
00863 {
00864 tret = time_cycle_interval;
00865 }
00866
00867
00868 if (tret == TS_NEVER)
00869 return TS_NEVER;
00870 else
00871 return -tret;
00872 }
00873
00874
00876
00878
00886 EXPORT int create_emissions(OBJECT **obj, OBJECT *parent)
00887 {
00888 try
00889 {
00890 *obj = gl_create_object(emissions::oclass);
00891 if (*obj!=NULL)
00892 {
00893 emissions *my = OBJECTDATA(*obj,emissions);
00894 gl_set_parent(*obj,parent);
00895 return my->create();
00896 }
00897 }
00898 catch (const char *msg)
00899 {
00900 gl_error("%s %s (id=%d): %s", (*obj)->name?(*obj)->name:"unnamed", (*obj)->oclass->name, (*obj)->id, msg);
00901 return 0;
00902 }
00903 return 1;
00904 }
00905
00906 EXPORT int init_emissions(OBJECT *obj, OBJECT *parent)
00907 {
00908 try {
00909 return OBJECTDATA(obj,emissions)->init(parent);
00910 }
00911 catch (const char *msg)
00912 {
00913 gl_error("%s %s (id=%d): %s", obj->name?obj->name:"unnamed", obj->oclass->name, obj->id, msg);
00914 return 0;
00915 }
00916 return 1;
00917 }
00918
00927 EXPORT TIMESTAMP sync_emissions(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass)
00928 {
00929 emissions *pObj = OBJECTDATA(obj,emissions);
00930 try {
00931 TIMESTAMP t1 = TS_NEVER;
00932 switch (pass) {
00933 case PC_PRETOPDOWN:
00934 return pObj->presync(t0);
00935 case PC_BOTTOMUP:
00936 return pObj->sync(t0);
00937 case PC_POSTTOPDOWN:
00938 t1 = pObj->postsync(t0);
00939 obj->clock = t0;
00940 return t1;
00941 default:
00942 throw "invalid pass request";
00943 }
00944 }
00945 catch (const char *msg)
00946 {
00947 gl_error("emissions %s (%s:%d): %s", obj->name, obj->oclass->name, obj->id, msg);
00948 }
00949 catch (...)
00950 {
00951 gl_error("emissions %s (%s:%d): unknown exception", obj->name, obj->oclass->name, obj->id);
00952 }
00953 return TS_INVALID;
00954 }
00955
00956 EXPORT int isa_emissions(OBJECT *obj, char *classname)
00957 {
00958 return OBJECTDATA(obj,emissions)->isa(classname);
00959 }
00960