/
building.cpp
1914 lines (1724 loc) · 125 KB
/
building.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "district.h"
#include "building.h"
#include "zone.h"
#include "scene.h"
#include "util.h"
// *** Building class, CitySim *** //
// *** jerome.kaempf@epfl.ch *** //
XmlScene* Building::getScene(){ return getDistrict()->getScene();}
Building::Building(TiXmlHandle hdl, District* pDistrict):pDistrict(pDistrict),logStream(pDistrict->logStream.rdbuf()) {
// default XML pointing element
TiXmlElement* xmlElem = NULL;
// gets the buildings ID (used?)
id = to<unsigned int>(hdl.ToElement()->Attribute("id"));
if (hdl.ToElement()->Attribute("key")) key = hdl.ToElement()->Attribute("key");
logStream << "Building: " << id << "\twith key: " << key << endl << flush;
// gets the fmu file to simulate this building
if (hdl.ToElement()->Attribute("fmu")) fmuFile = hdl.ToElement()->Attribute("fmu");
if (hdl.ToElement()->Attribute("tmp")) tmpPath = hdl.ToElement()->Attribute("tmp");
// load the building's characteristics
//float Vi = 0.f; // temporary building's volume for one zone creation
//if (hdl.ToElement()->Attribute("Vi")) Vi=to<float>(hdl.ToElement()->Attribute("Vi"));
if (hdl.ToElement()->Attribute("BlindsLambda")) blindsLambda = to<float>(hdl.ToElement()->Attribute("BlindsLambda"));
if (hdl.ToElement()->Attribute("BlindsIrradianceCutOff")) blindsIrradianceCutOff = to<float>(hdl.ToElement()->Attribute("BlindsIrradianceCutOff"));
if (hdl.ToElement()->Attribute("Simulate")) simulateEP = (hdl.ToElement()->Attribute("Simulate") == string("ep"));
// load the MRT specifications
if (hdl.ToElement()->Attribute("mrt")) mrt = (hdl.ToElement()->Attribute("mrt") == string("true"));
if (hdl.ToElement()->Attribute("mrtEpsilon")) mrtEpsilon = to<float>(hdl.ToElement()->Attribute("mrtEpsilon"));
// load the parameters for the HVAC system
if (hdl.ChildElement("HVAC", 0).ToElement()) {
HVACpresence = true;
coileff = to<float>(hdl.ChildElement("HVAC", 0).ToElement()->Attribute("coilEfficiency"));
TminSupply = to<float>(hdl.ChildElement("HVAC", 0).ToElement()->Attribute("TminSupply"));
TmaxSupply = to<float>(hdl.ChildElement("HVAC", 0).ToElement()->Attribute("TmaxSupply"));
deltaT = to<float>(hdl.ChildElement("HVAC", 0).ToElement()->Attribute("deltaT"));
evaporativeCooling = (hdl.ChildElement("HVAC", 0).ToElement()->Attribute("evaporativeCooling") == string("true"));
coilHTWeff = to<float>(hdl.ChildElement("HVAC", 0).ToElement()->Attribute("hydroThermalWheel"));
}
else HVACpresence = false;
// loading and creating the tanks
if(hdl.ChildElement("HeatTank", 0).ToElement())
heatStock = new Tank(hdl.ChildElement("HeatTank", 0));
if(hdl.ChildElement("DHWTank", 0).ToElement())
dhwStock = new Tank(hdl.ChildElement("DHWTank", 0));
if(hdl.ChildElement("CoolTank", 0).ToElement())
coldStock = new Tank(hdl.ChildElement("CoolTank", 0));
// Cognet: Start of added code.
heatingNeeds = 1.0; coolingNeeds = 1.0;
HS_needs = 1.0; DHW_needs = 1.0; CS_needs = 1.0;
HS_SolPp = 1.0; DHW_SolPp = 1.0; CS_SolPp = 1.0;
SolTherFracLeft = 1.0;
HS_Pp = 1.0; DHW_Pp = 1.0; CS_Pp = 1.0;
VdotUsed = 0.01;
// Cognet: End of added code.
// loading the heating properties
if(hdl.FirstChildElement("HeatSource").ToElement()) {
TiXmlHandle heatSource = hdl.FirstChildElement("HeatSource");
// gets the working period of the heatSource
unsigned int beginDay, endDay;
if ( heatSource.ToElement()->Attribute("beginDay") == NULL ) beginDay = 1;
else beginDay = to<unsigned int>(heatSource.ToElement()->Attribute("beginDay"));
if ( heatSource.ToElement()->Attribute("endDay") == NULL ) endDay = 365;
else endDay = to<unsigned int>(heatSource.ToElement()->Attribute("endDay"));
bool heatSourceFound = false; // Cognet: Added this, to detect error if multiple heatsources present in xml.
string errorMsg = "Error in the XML file: a Building has multiple units in HeatSource, there must be only one."; // Cognet: Added this
// Load source of heat
if (heatSource.FirstChildElement("Boiler").ToElement()) {
if ( heatSourceFound ) { throw errorMsg; } heatSourceFound = true; // Cognet: Added this.
heatingUnit = new Boiler(heatSource.FirstChildElement("Boiler"),beginDay,endDay,&(this->logStream));
}
if (heatSource.FirstChildElement("HeatPump").ToElement()) { // Cognet: Added this, to detect possible errors in xml.
if ( heatSourceFound ) { throw errorMsg; } heatSourceFound = true; // Cognet: Added this.
heatingUnit = new HeatPump(heatSource.FirstChildElement("HeatPump"),beginDay,endDay,&(this->logStream));
}
if (heatSource.FirstChildElement("CHP").ToElement()) { // Cognet: Added this, to detect possible errors in xml.
if ( heatSourceFound ) { throw errorMsg; } heatSourceFound = true; // Cognet: Added this.
heatingUnit = new CoGeneration(heatSource.FirstChildElement("CHP"),beginDay,endDay,&(this->logStream));
}
if (heatSource.FirstChildElement("CHP-HP").ToElement()) { // Cognet: Added this, to detect possible errors in xml.
if ( heatSourceFound ) { throw errorMsg; } heatSourceFound = true; // Cognet: Added this.
heatingUnit = new CoGenerationHeatPump(heatSource.FirstChildElement("CHP-HP"),beginDay,endDay,&(this->logStream));
}
//beginning of contents added by Dapeng // Cognet: Made modifications.
if(heatSource.FirstChildElement("Substation").ToElement() ){
if ( heatSourceFound ) { throw errorMsg; } heatSourceFound = true;
heatingUnit = Substation::createNewSubstation(heatSource.FirstChildElement("Substation"), this, beginDay, endDay, &(this->logStream));
}
if(heatSource.FirstChildElement("SubstationHP").ToElement() ){
if ( heatSourceFound ) { throw errorMsg; } heatSourceFound = true;
heatingUnit = new SubstationHeatPump(heatSource.FirstChildElement("SubstationHP"), this, beginDay, endDay, &(this->logStream));
}
if(heatSource.FirstChildElement("SubstationHP2stages").ToElement() ){
if ( heatSourceFound ) { throw errorMsg; } heatSourceFound = true;
heatingUnit = new SubstationHeatPump2stages(heatSource.FirstChildElement("SubstationHP2stages"), this, beginDay, endDay, &(this->logStream));
}
//end of contents added by Dapeng, later changed by Cognet
if ( not heatSourceFound ) { throw string("Error in the XML file: a Building has a HeatSource containing no units, there must be exactly one."); } // Cognet: Added this.
}
// loading the cooling properties
//beginning of contents added by Dapeng
if(hdl.FirstChildElement("CoolSource").ToElement()) {
TiXmlHandle coolSource = hdl.FirstChildElement("CoolSource");
// gets the working period of the coolSource
unsigned int beginDay, endDay;
if ( hdl.FirstChildElement("CoolSource").ToElement()->Attribute("beginDay") == NULL ) beginDay = 1;
else beginDay = to<unsigned int>(hdl.FirstChildElement("CoolSource").ToElement()->Attribute("beginDay"));
if ( hdl.FirstChildElement("CoolSource").ToElement()->Attribute("endDay") == NULL ) endDay = 365;
else endDay = to<unsigned int>(hdl.FirstChildElement("CoolSource").ToElement()->Attribute("endDay"));
bool coolSourceFound = false; // Cognet: Added this, to detect error if multiple coolsources present in xml.
string errorMsg = "Error in the XML file: a Building has multiple units in CoolSource, there must be only one."; // Cognet: Added this
if (coolSource.FirstChildElement("HeatPump").ToElement()) {
// the air conditioning system
if ( coolSourceFound ) { throw errorMsg; } coolSourceFound = true; // Cognet: Added this.
coolingUnit = new HeatPump(coolSource.FirstChildElement("HeatPump"),beginDay,endDay,&(this->logStream));
}
//beginning of contents added by Dapeng // Cognet: Made modifications.
if(coolSource.FirstChildElement("Substation").ToElement() ){ // Cognet: Added this, to detect possible errors in xml.
if ( coolSourceFound ) { throw errorMsg; } coolSourceFound = true; // Cognet: Added this.
coolingUnit = Substation::createNewSubstation(coolSource.FirstChildElement("Substation"), this, beginDay, endDay, &(this->logStream));
// DP: simplified compared to previous version; one could check the "supplemental source" is a heat pump (i.e. not a possible cold producing system)
}
//end of contents added by Dapeng
if ( not coolSourceFound ) { throw string("Error in the XML file: a Building has a CoolSource containing no units, there must be exactly one."); } // Cognet: Added this.
}
// Cognet: Start added content to impose the heat demanded to the heating unit.
if(hdl.FirstChildElement("ImposedHeatDemand").ToElement()) {
TiXmlAttribute* attrib = hdl.FirstChildElement("ImposedHeatDemand").ToElement()->FirstAttribute();
while ( attrib!=NULL ) {
string dayHour = attrib->Name();
double demand;
if ( attrib->QueryDoubleValue(&demand) ) { throw string("Error in the XML file: a Building has ImposedHeatDemand with attribute"+dayHour+" that isn't a double."); }
if (imposedHeatDemand.count(dayHour) != 0) {
throw string("Error in the XML file: a Building has on ImposedHeatDemand multiple times the attribute "+dayHour+", there must be at most one.");
} else {
imposedHeatDemand[dayHour] = demand;
}
attrib = attrib->Next();
}
}
// Cognet: End added content to impose the heat demanded to the heating unit.
/* DP : Previous version of EnergyConversionSystem reading
// loading the heating properties
if(hdl.FirstChildElement("HeatSource").ToElement()) {
TiXmlHandle heatSource = hdl.FirstChildElement("HeatSource");
// gets the working period of the heatSource
unsigned int beginDay, endDay;
if ( heatSource.ToElement()->Attribute("beginDay") == NULL ) beginDay = 1;
else beginDay = to<unsigned int>(heatSource.ToElement()->Attribute("beginDay"));
if ( heatSource.ToElement()->Attribute("endDay") == NULL ) endDay = 365;
else endDay = to<unsigned int>(heatSource.ToElement()->Attribute("endDay"));
// different sources of heat
if (heatSource.FirstChildElement("Boiler").ToElement()) {
heatingUnit = new Boiler(to<double>(heatSource.FirstChildElement("Boiler").ToElement()->Attribute("Pmax")),
to<double>(heatSource.FirstChildElement("Boiler").ToElement()->Attribute("eta_th")),
beginDay,endDay);
}
if (heatSource.FirstChildElement("HeatPump").ToElement()) {
logStream << "Heat Pump." << endl << flush;
heatingUnit = new HeatPump(to<double>(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("Pmax")),
to<double>(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("eta_tech")),
to<double>(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("Ttarget")),
beginDay,endDay);
if (string(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("Tsource"))==string("ground")) {
logStream << "Ground source." << endl << flush;
if (heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("z1")) {
// vertical pipes in the ground
heatingUnit->setGround(to<double>(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("depth")),
to<double>(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("z1")),
to<double>(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("alpha")));
}
else {
// horizontal pipes in the ground
heatingUnit->setGround(to<double>(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("depth")),
to<double>(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("depth")),
to<double>(heatSource.FirstChildElement("HeatPump").ToElement()->Attribute("alpha")));
}
}
else logStream << "Air source." << endl << flush;
}
if (heatSource.FirstChildElement("CHP").ToElement()) {
logStream << "Cogen." << endl << flush;
heatingUnit = new CoGeneration(to<double>(heatSource.FirstChildElement("CHP").ToElement()->Attribute("Pmax")),
to<double>(heatSource.FirstChildElement("CHP").ToElement()->Attribute("eta_el")),
to<double>(heatSource.FirstChildElement("CHP").ToElement()->Attribute("eta_th")),
to<double>(heatSource.FirstChildElement("CHP").ToElement()->Attribute("minPartLoadCoeff")),
beginDay,endDay);
}
if (heatSource.FirstChildElement("CHP-HP").ToElement()) {
logStream << "Cogen + HP." << endl << flush;
heatingUnit = new CoGenerationHeatPump(to<double>(heatSource.FirstChildElement("CHP-HP").ToElement()->Attribute("Pmax")),
to<double>(heatSource.FirstChildElement("CHP-HP").ToElement()->Attribute("eta_el")),
to<double>(heatSource.FirstChildElement("CHP-HP").ToElement()->Attribute("eta_th")),
to<double>(heatSource.FirstChildElement("CHP-HP").ToElement()->Attribute("minPartLoadCoeff")),
to<double>(heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("eta_tech")),
to<double>(heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("Ttarget")),
beginDay,endDay);
if (string(heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("Tsource"))==string("ground")) {
logStream << "Ground source." << endl << flush;
if (heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("z1")) {
// vertical pipes in the ground
heatingUnit->setGround(to<double>(heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("depth")),
to<double>(heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("z1")),
to<double>(heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("alpha")));
}
else {
// horizontal pipes in the ground
heatingUnit->setGround(to<double>(heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("depth")),
to<double>(heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("depth")),
to<double>(heatSource.FirstChildElement("CHP-HP").FirstChildElement("HeatPump").ToElement()->Attribute("alpha")));
}
}
else logStream << "Air source." << endl << flush;
}
//beginning of contents added by Dapeng
if(heatSource.FirstChildElement("substation").ToElement() ){
logStream <<"heating substation" <<endl << flush;
linkedDEC_ForHeat = to<int>(heatSource.FirstChildElement("substation").ToElement()->Attribute("linked"));
config = "HX";
TiXmlHandle supplementalUnit = heatSource.FirstChildElement("substation");
if(supplementalUnit.FirstChildElement("HeatPump").ToElement()) {
heatPumpElectricPower = to<double>(supplementalUnit.FirstChildElement("HeatPump").ToElement()->Attribute("Pmax") );
heatPumpEtaTech = to<double>(supplementalUnit.FirstChildElement("HeatPump").ToElement()->Attribute("eta_tech") );
targetTemp = to<double>(supplementalUnit.FirstChildElement("HeatPump").ToElement()->Attribute("Ttarget") );
config = "HX+HeatPump";
}
else {
heatPumpElectricPower = 0;
heatPumpEtaTech = 0;
targetTemp = 0;
}
// logStream <<"test output: " <<heatPumpElectricPower<<" "<<heatPumpEtaTech<<" "<<targetTemp<<endl << flush;
if(supplementalUnit.FirstChildElement("Boiler").ToElement() ) {
boilerThermalPower = to<double>(supplementalUnit.FirstChildElement("Boiler").ToElement()->Attribute("Pmax") );
boilerThermalEfficiency = to<double>(supplementalUnit.FirstChildElement("Boiler").ToElement()->Attribute("eta_th") );
config = "HX+Boiler";
}
else {
boilerThermalPower = 0;
boilerThermalEfficiency = 0;
}
if(heatSource.FirstChildElement("substation").ToElement()->Attribute("epsilon")==NULL) {
epsilon=0.0;
config = "HeatPump";
}
else epsilon = to<double>(heatSource.FirstChildElement("substation").ToElement()->Attribute("epsilon"));
heatDesignThermalPower = to<double>(heatSource.FirstChildElement("substation").ToElement()->Attribute("designThermalPower"));
heatDesignTempDifference = to<double>(heatSource.FirstChildElement("substation").ToElement()->Attribute("designTempDifference"));
heatingUnit = new Substation(heatDesignThermalPower, heatDesignTempDifference,
config, epsilon,
boilerThermalPower, boilerThermalEfficiency,
heatPumpElectricPower, heatPumpEtaTech, targetTemp,
beginDay, endDay);
}
//end of contents added by Dapeng
}
// loading the cooling properties
//beginning of contents added by Dapeng
if(hdl.FirstChildElement("CoolSource").ToElement()) {
TiXmlHandle coolSource = hdl.FirstChildElement("CoolSource");
// gets the working period of the coolSource
unsigned int beginDay, endDay;
if ( hdl.FirstChildElement("CoolSource").ToElement()->Attribute("beginDay") == NULL ) beginDay = 1;
else beginDay = to<unsigned int>(hdl.FirstChildElement("CoolSource").ToElement()->Attribute("beginDay"));
if ( hdl.FirstChildElement("CoolSource").ToElement()->Attribute("endDay") == NULL ) endDay = 365;
else endDay = to<unsigned int>(hdl.FirstChildElement("CoolSource").ToElement()->Attribute("endDay"));
if(coolSource.FirstChildElement("HeatPump").ToElement() ) {
// the air conditioning system
logStream << "AC." << endl << flush;
coolingUnit = new HeatPump(to<double>(coolSource.FirstChildElement("HeatPump").ToElement()->Attribute("Pmax")),
to<double>(coolSource.FirstChildElement("HeatPump").ToElement()->Attribute("eta_tech")),
to<double>(coolSource.FirstChildElement("HeatPump").ToElement()->Attribute("Ttarget")),
beginDay,endDay);
}
if(coolSource.FirstChildElement("substation").ToElement() ) {
logStream <<"cooling substation" <<endl << flush;
linkedDEC_ForCool = to<int>(coolSource.FirstChildElement("substation").ToElement()->Attribute("linked"));
config = "HX";
TiXmlHandle supplementalUnit = coolSource.FirstChildElement("substation");
if(supplementalUnit.FirstChildElement("HeatPump").ToElement() ) {
heatPumpElectricPower = to<double>(supplementalUnit.FirstChildElement("HeatPump").ToElement()->Attribute("Pmax") );
heatPumpEtaTech = to<double>(supplementalUnit.FirstChildElement("HeatPump").ToElement()->Attribute("eta_tech") );
targetTemp = to<double>(supplementalUnit.FirstChildElement("HeatPump").ToElement()->Attribute("Ttarget") );
config = "HX+HeatPump";
}
else {
heatPumpElectricPower = 0;
heatPumpEtaTech = 0;
targetTemp = 0;
}
if(coolSource.FirstChildElement("substation").ToElement()->Attribute("epsilon")==NULL) {
epsilon=0.0;
config = "HeatPump";
}
else epsilon = to<double>(coolSource.FirstChildElement("substation").ToElement()->Attribute("epsilon"));
coolDesignThermalPower = to<double>(coolSource.FirstChildElement("substation").ToElement()->Attribute("designThermalPower")),
coolDesignTempDifference = to<double>(coolSource.FirstChildElement("substation").ToElement()->Attribute("designTempDifference")),
coolingUnit = new Substation(coolDesignThermalPower, coolDesignTempDifference,
config, epsilon,
heatPumpElectricPower, heatPumpEtaTech, targetTemp,
beginDay, endDay);
}
}
*/
// THERMAL MODEL
// creates thermal zone(s)
if ( hdl.FirstChildElement("Zone").ToElement() ) {
// zoning exists
unsigned int zoneIndex = 0;
while ( hdl.ChildElement("Zone",zoneIndex).ToElement() ) {
// check if only one zone per building is defined for the E+ simulation
if (simulateEP && (zoneIndex > 0)) throw(string("Only one Thermal Zone per building allowed when co-simulating with EnergyPlus."));
// get some details about zone
if (!hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("id"))
throw (string("No id attribute in the Zone."));
unsigned int zoneId = to<unsigned int>(hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("id"));
if (!hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("volume"))
throw (string("Zone id ")+toString(zoneId)+string(": no volume attribute."));
float zoneVolume = to<float>(hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("volume"));
// sets if the ground floor is there
bool groundFloor = false;
if (hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("groundFloor"))
groundFloor = ( hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("groundFloor") == string("true") );
// containers of the elements
vector<Wall*> zoneWalls;
vector<Roof*> zoneRoofs;
vector<Surface*> zoneSurfaces;
vector<Floor*> zoneFloors;
// read the walls
unsigned int wallIndex = 0;
while ( hdl.ChildElement("Zone",zoneIndex).ChildElement("Wall", wallIndex).ToElement() ) {
// add a new wall to the zoneWalls vector
zoneWalls.push_back(new Wall(hdl.ChildElement("Zone",zoneIndex).ChildElement("Wall", wallIndex), this, &logStream));
/*TiXmlElement *wallElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Wall", wallIndex).ToElement();
// read the openableRatio or if not defined, leave it to 0
float glazingOpenableRatio = 0.f;
if (wallElem->Attribute("OpenableRatio"))
glazingOpenableRatio = to<float>(wallElem->Attribute("OpenableRatio"));
// creation of the pointer to the WallType defined for this wall
Composite* pWallType;
if (wallElem->Attribute("type")) {
// gets the type according to the value in "type"
pWallType = pDistrict->getComposite(wallElem->Attribute("type"));
}
else if (wallElem->Attribute("Uvalue")) {
// gets or creates a new WallType in the building for this special wall
pWallType = pDistrict->getUvalueComposite(to<float>(wallElem->Attribute("Uvalue")));
}
else throw(string("In Wall id: ")+wallElem->Attribute("id")+", no type or Uvalue given.");
// add a new wall to the zoneWalls vector
zoneWalls.push_back(new Wall(to<unsigned int>(wallElem->Attribute("id")),pWallType, to<float>(wallElem->Attribute("ShortWaveReflectance")) ,to<float>(wallElem->Attribute("GlazingRatio")),to<float>(wallElem->Attribute("GlazingGValue")),to<float>(wallElem->Attribute("GlazingUValue")),glazingOpenableRatio,&logStream));
TiXmlElement* pvElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Wall", wallIndex).FirstChildElement("PV").ToElement();
if (pvElem) {
PhotoVoltaic* pv = new PhotoVoltaic(hdl.ChildElement("Zone",zoneIndex).ChildElement("Wall", wallIndex).FirstChildElement("PV"));
zoneWalls.back() -> setPVPanel(to<float>(pvElem->Attribute("pvRatio")),pv);
}
TiXmlElement* pvThermalElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Wall", wallIndex).FirstChildElement("SolarHeater").ToElement();
if(pvThermalElem){// Add Solar thermal
SolarHeater* sh = new SolarHeater(hdl.ChildElement("Zone",zoneIndex).ChildElement("Wall", wallIndex).FirstChildElement("SolarHeater"));
zoneWalls.back() -> setSolarThermalPanel(to<float>(pvThermalElem->Attribute("solarHeaterRatio")), sh);
}
// add the emissivity of present
if (wallElem->Attribute("LongWaveEmissivity"))
zoneWalls.back()->setLongWaveEmissivity(to<float>(wallElem->Attribute("LongWaveEmissivity")));
// add the ep_id
if (wallElem->Attribute("ep_id"))
zoneWalls.back()->setEp_id(wallElem->Attribute("ep_id"));
// add the vertices
wallElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Wall", wallIndex).FirstChildElement("V0").ToElement();
unsigned int vertexIndex = 0;
while(wallElem) {
// check the presence of coordinates in the vertex tag
if (wallElem->Attribute("x")==NULL || wallElem->Attribute("y")==NULL || wallElem->Attribute("z")==NULL) break;
zoneWalls.back()->pushVertex(to<float>(wallElem->Attribute("x")),to<float>(wallElem->Attribute("y")),to<float>(wallElem->Attribute("z")));
string vertexj = "V" + toString(++vertexIndex);
wallElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Wall", wallIndex).FirstChildElement(vertexj.c_str()).ToElement();
}
if (vertexIndex<3) throw(string("Wall id=" + toString(zoneWalls.back()->getId()) + " has only " + toString(vertexIndex) + " vertices"));
zoneWalls.back()->computeNormalAndArea();
*/
if ((zoneWalls.back()->getArea() > 0.f) && (zoneWalls.back()->getRadius() > 0.f)) {
//logStream << "Wall surface loaded";
// computes for this wall the eco-indicators and add them to the whole building's values
nre += zoneWalls.back()->getNRE();
gwp += zoneWalls.back()->getGWP();
ubp += zoneWalls.back()->getUBP();
// outputs of the calculation
//logStream << "Wall id: " << zoneWalls.back()->getId() << "\tNRE: " << zoneWalls.back()->getNRE() << endl << flush;
}
else {
logStream << "(Warning) Wall id=" << zoneWalls.back()->getId() << " has a too small surface area or radius, removing it" << endl << flush;
delete zoneWalls.back();
zoneWalls.pop_back();
}
// increment the wall index
++wallIndex;
}
// read the roofs
unsigned int roofIndex = 0; bool roofUvalueOnly = false;
while ( hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).ToElement() ) {
// add a new roof to the zoneRoofs vector
zoneRoofs.push_back(new Roof(hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex), this, &logStream));
// test if the composite is fully described with layers
if (pDistrict->getComposite(hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).ToElement()->Attribute("type"))->getnLayers()==0) roofUvalueOnly = true;
/*TiXmlElement* roofElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).ToElement();
// takes care of the glazing openable ratio
float glazingOpenableRatio = 0.f;
if (roofElem->Attribute("OpenableRatio"))
glazingOpenableRatio = to<float>(roofElem->Attribute("OpenableRatio"));
// takes care of the type of Roof
if (!roofElem->Attribute("type"))
throw(string("No type given for Roof id=")+roofElem->Attribute("id"));
// add a new roof to the zoneRoofs vector
zoneRoofs.push_back(new Roof(to<unsigned int>(roofElem->Attribute("id")), pDistrict->getComposite(roofElem->Attribute("type")), to<float>(roofElem->Attribute("ShortWaveReflectance")), to<float>(roofElem->Attribute("GlazingRatio")),to<float>(roofElem->Attribute("GlazingGValue")),to<float>(roofElem->Attribute("GlazingUValue")),glazingOpenableRatio,&logStream));
// look for PV element
TiXmlElement* pvElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).FirstChildElement("PV").ToElement();
if (pvElem) {
PhotoVoltaic* pv = new PhotoVoltaic(hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).FirstChildElement("PV"));
zoneRoofs.back() -> setPVPanel(to<float>(pvElem->Attribute("pvRatio")),pv);
}
TiXmlElement* pvThermalElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).FirstChildElement("SolarHeater").ToElement();
if(pvThermalElem){// Add Solar thermal
SolarHeater* sh = new SolarHeater(hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).FirstChildElement("SolarHeater"));
logStream << "New SolarHeater built !" << endl << flush;
zoneRoofs.back() -> setSolarThermalPanel(to<float>(pvThermalElem->Attribute("solarHeaterRatio")), sh);
}
// add the emissivity
if (roofElem->Attribute("LongWaveEmissivity"))
zoneRoofs.back()->setLongWaveEmissivity(to<float>(roofElem->Attribute("LongWaveEmissivity")));
// add the ep_id
if (roofElem->Attribute("ep_id"))
zoneRoofs.back()->setEp_id(roofElem->Attribute("ep_id"));
// add the vertices
roofElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).FirstChildElement("V0").ToElement();
unsigned int vertexIndex = 0;
while (roofElem) {
// check the presence of coordinates in the vertex tag
if (roofElem->Attribute("x")==NULL || roofElem->Attribute("y")==NULL || roofElem->Attribute("z")==NULL) break;
zoneRoofs.back()->pushVertex(to<float>(roofElem->Attribute("x")),to<float>(roofElem->Attribute("y")),to<float>(roofElem->Attribute("z")));
string vertexj = "V" + toString(++vertexIndex);
roofElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).FirstChildElement(vertexj.c_str()).ToElement();
}
if (vertexIndex<3) throw(string("Roof id=" + toString(zoneRoofs.back()->getId()) + " has only " + toString(vertexIndex) + " vertices"));
zoneRoofs.back()->computeNormalAndArea();
*/
if ((zoneRoofs.back()->getArea() > 0.f) && (zoneRoofs.back()->getRadius() > 0.f)) {
// computes for this wall the eco-indicators and add them to the whole building's values
if (hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).ToElement()->Attribute("type") != NULL) {
nre += zoneRoofs.back()->getArea()*(1.f-zoneRoofs.back()->getGlazingRatio())*pDistrict->getComposite(hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).ToElement()->Attribute("type"))->getNRE();
gwp += zoneRoofs.back()->getArea()*(1.f-zoneRoofs.back()->getGlazingRatio())*pDistrict->getComposite(hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).ToElement()->Attribute("type"))->getGWP();
ubp += zoneRoofs.back()->getArea()*(1.f-zoneRoofs.back()->getGlazingRatio())*pDistrict->getComposite(hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).ToElement()->Attribute("type"))->getUBP();
//logStream << "Roof id: " << zoneRoofs.back()->getId() << "\tNRE: " << zoneRoofs.back()->getArea()*(1.f-zoneRoofs.back()->getGlazingRatio())*pDistrict->getType(hdl.ChildElement("Zone",zoneIndex).ChildElement("Roof", roofIndex).ToElement()->Attribute("type"))->getNRE() << endl << flush;
}
}
else {
logStream << "(Warning) Roof id=" << zoneRoofs.back()->getId() << " has a too small surface area or radius, removing it" << endl << flush;
delete zoneRoofs.back();
zoneRoofs.pop_back();
}
++roofIndex;
}
// read the surfaces
unsigned int surfaceIndex = 0;
while (hdl.ChildElement("Zone",zoneIndex).ChildElement("Surface", surfaceIndex).ToElement()) {
// add a new surface to the zoneSurfaces vector
zoneSurfaces.push_back(new Surface(hdl.ChildElement("Zone",zoneIndex).ChildElement("Surface", surfaceIndex), this, &logStream));
/* TiXmlElement* surfaceElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Surface", surfaceIndex).ToElement();
zoneSurfaces.push_back(new Surface(to<unsigned int>(surfaceElem->Attribute("id")),to<float>(surfaceElem->Attribute("ShortWaveReflectance")),0.f,0.f,0.f,0.f,&logStream));
TiXmlElement* pvElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Surface", surfaceIndex).FirstChildElement("PV").ToElement();
if (pvElem) {
PhotoVoltaic* pv = new PhotoVoltaic(hdl.ChildElement("Zone",zoneIndex).ChildElement("Surface", surfaceIndex).FirstChildElement("PV"));
zoneSurfaces.back() -> setPVPanel(to<float>(pvElem->Attribute("pvRatio")),pv);
}
TiXmlElement* pvThermalElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Surface", surfaceIndex).FirstChildElement("SolarHeater").ToElement();
if(pvThermalElem){// Add Solar thermal
SolarHeater* sh = new SolarHeater(hdl.ChildElement("Zone",zoneIndex).ChildElement("Surface", surfaceIndex).FirstChildElement("SolarHeater"));
zoneSurfaces.back() -> setSolarThermalPanel(to<float>(pvThermalElem->Attribute("solarHeaterRatio")), sh);
}
// add the emissivity
if (surfaceElem->Attribute("LongWaveEmissivity"))
zoneSurfaces.back()->setLongWaveEmissivity(to<float>(surfaceElem->Attribute("LongWaveEmissivity")));
// add the vertices
surfaceElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Surface", surfaceIndex).FirstChildElement("V0").ToElement();
unsigned int vertexIndex = 0;
while(surfaceElem) {
// check the presence of coordinates in the vertex tag
if (surfaceElem->Attribute("x")==NULL || surfaceElem->Attribute("y")==NULL || surfaceElem->Attribute("z")==NULL) break;
zoneSurfaces.back()->pushVertex(to<float>(surfaceElem->Attribute("x")),to<float>(surfaceElem->Attribute("y")),to<float>(surfaceElem->Attribute("z")));
string vertexj = "V" + toString(++vertexIndex);
surfaceElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Surface", surfaceIndex).FirstChildElement(vertexj.c_str()).ToElement();
}
if (vertexIndex<3) throw(string("Surface id=" + toString(zoneSurfaces.back()->getId()) + " has only " + toString(vertexIndex) + " vertices"));
zoneSurfaces.back()->computeNormalAndArea();
*/
if ((zoneSurfaces.back()->getArea() > 0.f) && (zoneSurfaces.back()->getRadius() > 0.f)) {
// that's OK
}
else {
logStream << "(Warning) Surface id=" << zoneSurfaces.back()->getId() << " has a too small surface area or radius, removing it" << endl << flush;
delete zoneSurfaces.back();
zoneSurfaces.pop_back();
}
++surfaceIndex;
}
// reads the floor area and conductance
unsigned int floorIndex = 0; bool floorUvalueOnly = false;
while (hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).ToElement()) {
// add a new floor to the zoneFloors vector
zoneFloors.push_back(new Floor(hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex), this, &logStream));
// test is the floor is fully described
if (pDistrict->getComposite(hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).ToElement()->Attribute("type"))->getnLayers()==0) floorUvalueOnly = true;
/*
TiXmlElement *floorElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).ToElement();
// add a new floor element
zoneFloors.push_back(new Floor(to<unsigned int>(floorElem->Attribute("id")),pDistrict->getComposite(floorElem->Attribute("type")),&logStream));
floorElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).FirstChildElement("V0").ToElement();
unsigned int vertexIndex = 0;
while(floorElem){
// check the presence of coordinates in the vertex tag
if (floorElem->Attribute("x")==NULL || floorElem->Attribute("y")==NULL || floorElem->Attribute("z")==NULL) break;
zoneFloors.back()->pushVertex(to<float>(floorElem->Attribute("x")),to<float>(floorElem->Attribute("y")),to<float>(floorElem->Attribute("z")));
string vertexj = "V" + toString(++vertexIndex);
floorElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).FirstChildElement(vertexj.c_str()).ToElement();
}
if (vertexIndex<3) throw(string("Floor id=" + toString(zoneFloors.back()->getId()) + " has only " + toString(vertexIndex) + " vertices"));
zoneFloors.back()->computeNormalAndArea();
*/
if ((zoneFloors.back()->getArea() > 0.f) && (zoneFloors.back()->getRadius() > 0.f)) {
// computes for this wall the eco-indicators and add them to the whole building's values
if (hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).ToElement()->Attribute("type") != NULL) {
nre += zoneFloors.back()->getArea()*pDistrict->getComposite(hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).ToElement()->Attribute("type"))->getNRE();
gwp += zoneFloors.back()->getArea()*pDistrict->getComposite(hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).ToElement()->Attribute("type"))->getGWP();
ubp += zoneFloors.back()->getArea()*pDistrict->getComposite(hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).ToElement()->Attribute("type"))->getUBP();
//logStream << "Floor id: " << zoneFloors.back()->getId() << "\tNRE: " << zoneFloors.back()->getArea()*pDistrict->getType(hdl.ChildElement("Zone",zoneIndex).ChildElement("Floor",floorIndex).ToElement()->Attribute("type"))->getNRE() << endl << flush;
}
}
else {
logStream << "(Warning) Floor id=" << zoneFloors.back()->getId() << " has a too small surface area or radius, removing it" << endl << flush;
delete zoneFloors.back();
zoneFloors.pop_back();
}
// increments the floor index
++floorIndex;
}
// some outputs for verification
logStream << "Zone: " << zoneIndex << "\tWalls: " << wallIndex << "\tRoofs: " << roofIndex << "\tSurfaces: " << surfaceIndex << "\tFloors: " << floorIndex << endl << flush;
// updates the link matrix in a sparse format
// a variable to know which one is the first one of the row
linksAi.push_back( linksAn.size() );
unsigned int zoneSurfaceIndex = 0;
while ( hdl.ChildElement("Zone",zoneIndex).ChildElement("ZoneSurface", zoneSurfaceIndex).ToElement() ) {
TiXmlElement* zoneSurfaceElem = hdl.ChildElement("Zone",zoneIndex).ChildElement("ZoneSurface", zoneSurfaceIndex).ToElement();
float Swall = to<float>( zoneSurfaceElem->Attribute("Area") );
float Kwall;
if ( zoneSurfaceElem->Attribute("Vertical") == string("true") ) {
Kwall = Swall/(1.f/pDistrict->getComposite(zoneSurfaceElem->Attribute("type"))->getConductance()
+ 1.f/3.f + 1.f/3.f );
}
else { // by default a horizontal surface (buoyant 4.3 and stratified 1.5)
Kwall = Swall/(1.f/pDistrict->getComposite(zoneSurfaceElem->Attribute("type"))->getConductance()
+ 1.f/1.5f + 1.f/4.3f );
}
float Cwall = Swall*pDistrict->getComposite(zoneSurfaceElem->Attribute("type"))->getCapacitance();
// reading the area and the connected zone
linksAn.push_back( pair<float,float>(Kwall,Cwall) );
linksAj.push_back( to<unsigned int>( zoneSurfaceElem->Attribute("LinkZone") ) );
// putting back the eco-indicators for the intermediary walls, half for each zone
nre += Swall*pDistrict->getComposite(zoneSurfaceElem->Attribute("type"))->getNRE()/2.f;
gwp += Swall*pDistrict->getComposite(zoneSurfaceElem->Attribute("type"))->getGWP()/2.f;
ubp += Swall*pDistrict->getComposite(zoneSurfaceElem->Attribute("type"))->getUBP()/2.f;
logStream << "Slab: " << zoneSurfaceIndex << "\tNRE: " << Swall*pDistrict->getComposite(zoneSurfaceElem->Attribute("type"))->getNRE()/2.f << endl;
// increment the zoneSurfaceIndex
++zoneSurfaceIndex;
}
// creates the OCCUPANTS for the Zone
Occupants *occupants;
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()) {
float occupantsNumber = to<float>(hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("n"));
logStream << "Occupants defined: " << occupantsNumber << endl << flush;
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").FirstChildElement("Stochastic").ToElement()) {
// stochastic profile
Model::setThermalExplicit(true); // chooses to use the thermal explicit
// loads the different arguments for the stochastic model
string windowModel = hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").FirstChildElement("Models").ToElement()->Attribute("Windows");
// start off with the stochastic presence profile
vector<float> pMon, pTue, pWed, pThu, pFri, pSat, pSun;
TiXmlElement* buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Mon").ToElement();
TiXmlAttribute* attrib = buildingElem->FirstAttribute();
do {
pMon.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Tue").ToElement();
attrib = buildingElem->FirstAttribute();
do {
pTue.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Wed").ToElement();
attrib = buildingElem->FirstAttribute();
do {
pWed.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Thu").ToElement();
attrib = buildingElem->FirstAttribute();
do {
pThu.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Fri").ToElement();
attrib = buildingElem->FirstAttribute();
do {
pFri.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Sat").ToElement();
attrib = buildingElem->FirstAttribute();
do {
pSat.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Sun").ToElement();
attrib = buildingElem->FirstAttribute();
do {
pSun.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
// start off with P01arr
vector<float> P01arr, P10arr, P01int, P10int, P01dep, P10dep, duropen;
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("P01arr").ToElement();
attrib = buildingElem->FirstAttribute();
do {
P01arr.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("P10arr").ToElement();
attrib = buildingElem->FirstAttribute();
do {
P10arr.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("P01int").ToElement();
attrib = buildingElem->FirstAttribute();
do {
P01int.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("P10int").ToElement();
attrib = buildingElem->FirstAttribute();
do {
P10int.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("P01dep").ToElement();
attrib = buildingElem->FirstAttribute();
do {
P01dep.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
// P10dep
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("P10dep").ToElement();
attrib = buildingElem->FirstAttribute();
do {
P10dep.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
// duropen
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("duropen").ToElement();
attrib = buildingElem->FirstAttribute();
do {
duropen.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
// loads the different arguments for the stochastic blinds model
vector<float> Plowerarr_UB, Praisearr_UB, Plowerint_UB, Praiseint_UB, Pfulllower_UB, Pfullraise_UB;
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Plowerarr_UB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Plowerarr_UB .push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Praisearr_UB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Praisearr_UB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Plowerint_UB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Plowerint_UB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Praiseint_UB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Praiseint_UB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Pfulllower_UB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Pfulllower_UB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Pfullraise_UB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Pfullraise_UB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
vector<float> Plowerarr_LB, Praisearr_LB, Plowerint_LB, Praiseint_LB, Pfulllower_LB, Pfullraise_LB, DistFrac_LB;
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Plowerarr_LB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Plowerarr_LB .push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Praisearr_LB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Praisearr_LB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Plowerint_LB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Plowerint_LB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Praiseint_LB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Praiseint_LB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Pfulllower_LB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Pfulllower_LB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Pfullraise_LB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Pfullraise_LB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("DistFrac_LB").ToElement();
attrib = buildingElem->FirstAttribute();
do {
DistFrac_LB.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
// loads the different arguments for the stochastic lights model
vector<float> Ponarr, Ponint;
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Ponarr").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Ponarr.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
buildingElem = hdl.FirstChildElement("Occupants").FirstChildElement("Stochastic").FirstChildElement("Ponint").ToElement();
attrib = buildingElem->FirstAttribute();
do {
Ponint.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
// creates the classes that contains the parameters
StochasticPresenceParameters *presParam = new StochasticPresenceParameters(pMon,pTue,pWed,pThu,pFri,pSat,pSun);
StochasticWindowParameters *winParam = new StochasticWindowParameters(windowModel, P01arr, P10arr, P01int, P10int, P01dep, P10dep, duropen);
StochasticBlindsParameters *blindsParam = new StochasticBlindsParameters(Plowerarr_UB, Praisearr_UB, Plowerint_UB, Praiseint_UB, Pfulllower_UB, Pfullraise_UB, Plowerarr_LB, Praisearr_LB, Plowerint_LB, Praiseint_LB, Pfulllower_LB, Pfullraise_LB, DistFrac_LB);
StochasticLightsParameters *lightsParam = new StochasticLightsParameters(Ponarr, Ponint);
// creates the occupants
occupants = new StochasticOccupantsPresence(occupantsNumber,presParam,winParam,blindsParam,lightsParam);
}
else {
vector<float> occupantsWeekday, occupantsSaturday, occupantsSunday;
TiXmlElement* buildingElem = hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").FirstChildElement("Weekday").ToElement();
if (buildingElem) {
logStream << "Day type=Weekday ";
TiXmlAttribute* attrib = buildingElem->FirstAttribute();
do {
logStream << attrib->DoubleValue() << " ";
occupantsWeekday.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
logStream << endl << flush;
}
buildingElem = hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").FirstChildElement("Saturday").ToElement();
if (buildingElem) {
logStream << "Day type=Saturday ";
TiXmlAttribute* attrib = buildingElem->FirstAttribute();
do {
logStream << attrib->DoubleValue() << " ";
occupantsSaturday.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
logStream << endl << flush;
}
buildingElem = hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").FirstChildElement("Sunday").ToElement();
if (buildingElem) {
logStream << "Day type=Sunday ";
TiXmlAttribute* attrib = buildingElem->FirstAttribute();
do {
logStream << attrib->DoubleValue() << " ";
occupantsSunday.push_back(attrib->DoubleValue());
} while ( (attrib = attrib->Next()) );
logStream << endl << flush;
}
// create the occupants deterministically
occupants = new DeterministicOccupantsPresence(occupantsNumber, occupantsWeekday, occupantsSaturday, occupantsSunday);
}
}
else { // no occupants defined, empty
occupants = new Occupants(0.f);
}
try {
// need to check the consistency of this zone, to define its type (1N, 2N, 3N or even 4N)
if (hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("detailedSimulation")
&& hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("detailedSimulation")==string("true"))
zones.push_back(new ZoneN(zoneId,this,groundFloor,zoneVolume,zoneWalls,zoneRoofs,zoneSurfaces,zoneFloors,occupants));
else if ((roofUvalueOnly && floorUvalueOnly)||(zoneRoofs.empty() && zoneFloors.empty()))
zones.push_back(new Zone2N(zoneId,this,groundFloor,zoneVolume,zoneWalls,zoneRoofs,zoneSurfaces,zoneFloors,occupants));
else if ((roofUvalueOnly)||zoneRoofs.empty())
zones.push_back(new Zone3N_floor(zoneId,this,groundFloor,zoneVolume,zoneWalls,zoneRoofs,zoneSurfaces,zoneFloors,occupants));
else if ((floorUvalueOnly)||zoneFloors.empty())
zones.push_back(new Zone3N(zoneId,this,groundFloor,zoneVolume,zoneWalls,zoneRoofs,zoneSurfaces,zoneFloors,occupants));
else
zones.push_back(new Zone4N(zoneId,this,groundFloor,zoneVolume,zoneWalls,zoneRoofs,zoneSurfaces,zoneFloors,occupants));
}
catch(string msg) { throw(msg); }
// adds the thermal bridges to the zone if they exist
if (hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("psi")) {
zones.back()->setKpsi(to<float>(hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("psi")));
}
// adds the Tmin and Tmax to the zone if they exist in the Tag Zone or take it from the building itself
if (hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("Tmin")) {
zones.back()->setTmin(to<float>(hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("Tmin")));
}
else if (hdl.ToElement()->Attribute("Tmin")) {
zones.back()->setTmin(to<float>(hdl.ToElement()->Attribute("Tmin")));
}
if (hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("Tmax")) {
zones.back()->setTmax(to<float>(hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("Tmax")));
}
else if (hdl.ToElement()->Attribute("Tmax")) {
zones.back()->setTmax(to<float>(hdl.ToElement()->Attribute("Tmax")));
}
// adds the Temperature Profile (if it exists)
if (hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("temperatureProfile")) {
zones.back()->setTprofile(to<unsigned int>(hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("temperatureProfile")));
}
// adds the night ventilation
if (hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("nightVentilationBegin")) {
zones.back()->setNightVentilationBegin(to<unsigned int>(hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("nightVentilationBegin")));
}
if (hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("nightVentilationEnd")) {
zones.back()->setNightVentilationEnd(to<unsigned int>(hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("nightVentilationEnd")));
}
// adds the ep_id if it exists
if (hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("ep_id")) {
zones.back()->setEp_id(hdl.ChildElement("Zone",zoneIndex).ToElement()->Attribute("ep_id"));
}
else zones.back()->setEp_id("SINGLE_ZONE");
// setting of the occupants
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()) {
logStream << "Zone occupants" << endl;
// *** stochastic ***
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("stochastic"))
zones.back()->setOccupantsStochastic(hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("stochastic") == string("true"));
// *** number ***
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("n"))
zones.back()->setOccupantsNumber(to<float>(hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("n")));
// *** sensible heat ***
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("sensibleHeat"))
zones.back()->setOccupantsSensibleHeat(to<float>(hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("sensibleHeat")));
// *** sensible heat radiant fraction ***
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("sensibleHeatRadiantFraction"))
zones.back()->setOccupantsSensibleHeatRadiantFraction(to<float>(hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("sensibleHeatRadiantFraction")));
// *** latent heat ***
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("latentHeat"))
zones.back()->setOccupantsLatentHeat(to<float>(hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("latentHeat")));
// *** activity type ***
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("activityType"))
zones.back()->setActivityType(to<unsigned int>(hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("activityType")));
// *** year profile ID ***
if (hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("type")) {
unsigned int occupantsYearId = to<unsigned int>(hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").ToElement()->Attribute("type"));
if (pDistrict->getOccupancyProfiles()->getYearProfileFromXmlId(occupantsYearId) == nullptr)
throw("Occupants' Year Profile type=" + toString(occupantsYearId) + " not found in Zone id=" + toString(zones.back()->getId()));
else
zones.back()->setOccupantsYearProfile(pDistrict->getOccupancyProfiles()->getYearProfileFromXmlId(occupantsYearId));
}
else {
logStream << "Old occupants definition\t";
// add the day profiles
vector<float> dayProfile;
DayProfile* weekday=NULL;
DayProfile* saturday=NULL;
DayProfile* sunday=NULL;
// weekday
if ( (xmlElem = hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").FirstChildElement("Weekday").ToElement()) ) {
logStream << "Day zoneId= " << zoneId*10+1 << ": ";
unsigned int hourIndex=1;
do {
string attrib = *(xmlElem->Attribute("p"+toString(hourIndex)));
logStream << attrib << " ";
dayProfile.push_back(to<float>(attrib));
} while ( xmlElem->Attribute("p"+toString(++hourIndex)) );
logStream << endl << flush;
weekday = new DayProfile(zoneId*10+1,"Day profile weekday "+toString(zoneId*10+1),dayProfile);
pDistrict->getOccupancyProfiles()->addDayProfile(weekday);
//pDistrict->getOccupancyProfiles()->addDayProfileOld(weekday->getId(),*weekday);
}
dayProfile.clear();
// saturday
if ( (xmlElem = hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").FirstChildElement("Saturday").ToElement()) ) {
logStream << "Day zoneId= " << zoneId*10+2 << ": ";
unsigned int hourIndex=1;
do {
string attrib = *(xmlElem->Attribute("p"+toString(hourIndex)));
logStream << attrib << " ";
dayProfile.push_back(to<float>(attrib));
} while ( xmlElem->Attribute("p"+toString(++hourIndex)) );
logStream << endl << flush;
saturday = new DayProfile(zoneId*10+2,"Day profile saturday "+toString(zoneId*10+2),dayProfile);
pDistrict->getOccupancyProfiles()->addDayProfile(saturday);
//pDistrict->getOccupancyProfiles()->addDayProfileOld(saturday->getId(),*saturday);
}
dayProfile.clear();
// sunday
if ( (xmlElem = hdl.ChildElement("Zone",zoneIndex).FirstChildElement("Occupants").FirstChildElement("Sunday").ToElement()) ) {