-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTestBasalAreaLight.cpp
1746 lines (1538 loc) · 71.2 KB
/
TestBasalAreaLight.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
//---------------------------------------------------------------------------
// TestBasalAreaLight.cpp
//---------------------------------------------------------------------------
#include "TestBasalAreaLight.h"
#include <gtest/gtest.h>
#include "Grid.h"
#include "SimManager.h"
#include "BehaviorBase.h"
#include "TreePopulation.h"
#include "BasalAreaLight.h"
#include <math.h>
#include <fstream>
////////////////////////////////////////////////////////////////////////////
// TestErrorProcessing()
////////////////////////////////////////////////////////////////////////////
TEST(BasalAreaLight, TestErrorProcessing)
{
clSimManager * p_oSimManager = new clSimManager( 7, 1, "" );
try
{
p_oSimManager->ReadFile( WriteBasalAreaLightXMLErrorFile1() );
FAIL() << "TestBasalAreaLight error processing didn't catch error for WriteBasalAreaLightXMLErrorFile1.";
}
catch ( modelErr& err )
{
if ( err.sFunction.compare("clBasalAreaLight::DoShellSetup" ) != 0 )
{
FAIL() << "TestBasalAreaLight error processing caught wrong error for WriteBasalAreaLightXMLErrorFile1.";
}
;
}
try
{
p_oSimManager->ReadFile( WriteBasalAreaLightXMLErrorFile2() );
FAIL() << "TestBasalAreaLight error processing didn't catch error for WriteBasalAreaLightXMLErrorFile2.";
}
catch ( modelErr& err )
{
if ( err.sFunction.compare("clBasalAreaLight::DoShellSetup" ) != 0 )
{
FAIL() << "TestBasalAreaLight error processing caught wrong error for WriteBasalAreaLightXMLErrorFile2.";
}
;
}
try
{
p_oSimManager->ReadFile( WriteBasalAreaLightXMLErrorFile3() );
FAIL() << "TestBasalAreaLight error processing didn't catch error for WriteBasalAreaLightXMLErrorFile3.";
}
catch ( modelErr& err )
{
if ( err.sFunction.compare("clBasalAreaLight::DoShellSetup" ) != 0 )
{
FAIL() << "TestBasalAreaLight error processing caught wrong error for WriteBasalAreaLightXMLErrorFile3.";
}
;
}
try
{
p_oSimManager->ReadFile( WriteBasalAreaLightXMLErrorFile4() );
FAIL() << "TestBasalAreaLight error processing didn't catch error for WriteBasalAreaLightXMLErrorFile4.";
}
catch ( modelErr& err )
{
if ( err.sFunction.compare("clBasalAreaLight::DoShellSetup" ) != 0 )
{
FAIL() << "TestBasalAreaLight error processing caught wrong error for WriteBasalAreaLightXMLErrorFile4.";
}
;
}
try
{
p_oSimManager->ReadFile( WriteBasalAreaLightXMLErrorFile5() );
FAIL() << "TestBasalAreaLight error processing didn't catch error for WriteBasalAreaLightXMLErrorFile5.";
}
catch ( modelErr& err )
{
if ( err.sFunction.compare("clBasalAreaLight::DoShellSetup" ) != 0 )
{
FAIL() << "TestBasalAreaLight error processing caught wrong error for WriteBasalAreaLightXMLErrorFile5.";
}
;
}
delete p_oSimManager;
}
/////////////////////////////////////////////////////////////////////////////
// NormalProcessingRun1()
// Tests normal processing - run 1. This checks the calculation of mean GLI
// and verifies that new light level calculations are triggered correctly.
// WriteBasalAreaLightXMLFile1() does setup.
/////////////////////////////////////////////////////////////////////////////
TEST(BasalAreaLight, NormalProcessingRun1)
{
clSimManager * p_oSimManager = new clSimManager( 7, 1, "" );
try {
clTreePopulation *p_oPop;
clBehaviorBase *p_oTemp;
clBasalAreaLight *p_oLightBeh;
clGrid *p_oLightGrid;
clTree *p_oTree1, *p_oTree2, *p_oTree3, *p_oTree4, *p_oTree5, *p_oTree6,
*p_oTree7, *p_oTree8, *p_oTree9, *p_oTree10, *p_oTree11, *p_oTree12,
*p_oTree13, *p_oTree14, *p_oTree15, *p_oTree16, *p_oTree17,
*p_oTree18, *p_oTree19, *p_oTree20, *p_oTree21, *p_oTree22,
*p_oTree23, *p_oTree24, *p_oTree25, *p_oTree26, *p_oTree27,
*p_oTree28, *p_oTree29, *p_oTree30, *p_oTree31, *p_oTree32;
float fActualLight, //Light level calculated by SORTIE
fExpectedLight, //Light level we're expecting
fExpConBA, //Conifer basal area we're expecting
fExpAngBA, //Angiosperm basal area we're expecting
fActualConBA, //Conifer basal area calculated by SORTIE
fActualAngBA, //Angiosperm basal area calculated by SORTIE
fDiam, fX, fY, //For creating trees
//For stashing light levels between timesteps
fLight1, fLight2, fLight3, fLight4, fLight5, fLight6, fLight7;
int iLightCode, iConBACode, iAngBACode, iX, iY, iNumXCells, iSpecies,
iNumYCells;
//Feed our file to the sim manager
p_oSimManager->ReadFile(WriteBasalAreaLightXMLFile1());
p_oPop = (clTreePopulation*) p_oSimManager->GetPopulationObject("treepopulation");
//Add trees to three grid cells
//Grid Cell 0,1: 1 conifer
fX = 4; fY = 12;
iSpecies = 2; fDiam = 50;
p_oTree1 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
//Grid cell 0,2: 1 angiosperm.
fX = 4; fY = 20;
iSpecies = 1; fDiam = 45;
p_oTree2 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
//Grid cell 0,3: 3 conifers, plus more too small
fX = 4; fY = 28;
iSpecies = 0; fDiam = 45;
p_oTree3 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 2; fDiam = 24;
p_oTree4 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 2; fDiam = 70;
p_oTree5 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 0; fDiam = 8;
p_oTree6 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
iSpecies = 2; fDiam = 9;
p_oTree7 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
//Grid cell 0,4: 5 angiosperms, plus more too small.
fX = 4; fY = 36;
iSpecies = 3; fDiam = 45;
p_oTree8 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 1; fDiam = 24;
p_oTree9 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 1; fDiam = 70;
p_oTree10 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 3; fDiam = 18;
p_oTree11 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 1; fDiam = 31;
p_oTree12 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 3; fDiam = 6;
p_oTree13 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
iSpecies = 1; fDiam = 4;
p_oTree14 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
//Grid cell 0,5: 6 trees, mixed conifer and angiosperm, plus more too small,
//and snags
fX = 4; fY = 44;
iSpecies = 3; fDiam = 45;
p_oTree15 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 1; fDiam = 24;
p_oTree16 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 1; fDiam = 70;
p_oTree17 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 3; fDiam = 18;
p_oTree18 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 1; fDiam = 31;
p_oTree19 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 3; fDiam = 6;
p_oTree20 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
iSpecies = 1; fDiam = 4;
p_oTree21 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
iSpecies = 0; fDiam = 45;
p_oTree22 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 2; fDiam = 24;
p_oTree23 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 1; fDiam = 70;
p_oTree24 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 0; fDiam = 8;
p_oTree25 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
iSpecies = 2; fDiam = 9;
p_oTree26 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
iSpecies = 0; fDiam = 100;
p_oTree27 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::snag, fDiam );
//Grid cell 0,6: Several trees, all too small.
fX = 4; fY = 52;
iSpecies = 3; fDiam = 3;
p_oTree28 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
iSpecies = 0; fDiam = 6;
p_oTree29 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
iSpecies = 2; fDiam = 3;
p_oTree30 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
iSpecies = 1; fDiam = 9;
p_oTree31 = p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
//Check the mean GLI calculations directly for several values
p_oTemp = p_oSimManager->GetBehaviorObject("basalarealightshell");
p_oLightBeh = dynamic_cast<clBasalAreaLight*>(p_oTemp);
fExpectedLight = 12.4;
fActualConBA = 0;
fActualAngBA = 0;
fActualLight = p_oLightBeh->GetMeanGLI(fActualConBA, fActualAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
fExpectedLight = 12.22827861;
fActualConBA = 0.196349541;
fActualAngBA = 0;
fActualLight = p_oLightBeh->GetMeanGLI(fActualConBA, fActualAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
fExpectedLight = 12.3998466;
fActualConBA = 0;
fActualAngBA = 0.159043128;
fActualLight = p_oLightBeh->GetMeanGLI(fActualConBA, fActualAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
fExpectedLight = 11.25757809;
fActualConBA = 0.589127162;
fActualAngBA = 0;
fActualLight = p_oLightBeh->GetMeanGLI(fActualConBA, fActualAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
fExpectedLight = 12.35778669;
fActualConBA = 0;
fActualAngBA = 0.690050826;
fActualLight = p_oLightBeh->GetMeanGLI(fActualConBA, fActualAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
fExpectedLight = 11.99536365;
fActualConBA = 0.204282062;
fActualAngBA = 1.074895926;
fActualLight = p_oLightBeh->GetMeanGLI(fActualConBA, fActualAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
//Run one timestep
p_oSimManager->RunSim(1);
p_oLightGrid = p_oSimManager->GetGridObject("Basal Area Light");
iLightCode = p_oLightGrid->GetFloatDataCode("Light");
EXPECT_LT(-1, iLightCode);
iConBACode = p_oLightGrid->GetFloatDataCode("Con BA");
EXPECT_LT(-1, iConBACode);
iAngBACode = p_oLightGrid->GetFloatDataCode("Ang BA");
EXPECT_LT(-1, iAngBACode);
//Check to make sure the basal area totals are correct
//Grid 0, 0
fExpConBA = 0;
fExpAngBA = 0;
p_oLightGrid->GetValueOfCell(0, 0, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 0, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 1
fExpConBA = 0.196349541;
fExpAngBA = 0;
p_oLightGrid->GetValueOfCell(0, 1, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 1, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 2
fExpConBA = 0;
fExpAngBA = 0.159043128;
p_oLightGrid->GetValueOfCell(0, 2, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 2, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 3
fExpConBA = 0.589127162;
fExpAngBA = 0;
p_oLightGrid->GetValueOfCell(0, 3, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 3, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 4
fExpConBA = 0;
fExpAngBA = 0.690050826;
p_oLightGrid->GetValueOfCell(0, 4, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 4, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 5
fExpConBA = 0.204282062;
fExpAngBA = 1.074895926;
p_oLightGrid->GetValueOfCell(0, 5, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 5, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 6
fExpConBA = 0;
fExpAngBA = 0;
p_oLightGrid->GetValueOfCell(0, 6, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 6, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Make sure that all cells got a light level
iNumXCells = p_oLightGrid->GetNumberXCells();
iNumYCells = p_oLightGrid->GetNumberYCells();
for (iX = 0; iX < iNumXCells; iX++) {
for (iY = 0; iY < iNumYCells; iY++) {
p_oLightGrid->GetValueOfCell(iX, iY, iLightCode, &fActualLight);
EXPECT_GT(fActualLight, 0);
}
}
//Save the light values for the seven grid cells to check for density changes
p_oLightGrid->GetValueOfCell(0, 0, iLightCode, &fLight1);
p_oLightGrid->GetValueOfCell(0, 1, iLightCode, &fLight2);
p_oLightGrid->GetValueOfCell(0, 2, iLightCode, &fLight3);
p_oLightGrid->GetValueOfCell(0, 3, iLightCode, &fLight4);
p_oLightGrid->GetValueOfCell(0, 4, iLightCode, &fLight5);
p_oLightGrid->GetValueOfCell(0, 5, iLightCode, &fLight6);
p_oLightGrid->GetValueOfCell(0, 6, iLightCode, &fLight7);
//Make sure that the species two trees got light values matching their
//grids, and nobody else
//Grid 0,1 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree1->GetSpecies(), p_oTree1->GetType()), -1);
//Grid 0,2 trees
p_oTree2->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree2->GetSpecies(), p_oTree2->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight3);
//Grid 0,3 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree3->GetSpecies(), p_oTree3->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree4->GetSpecies(), p_oTree4->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree5->GetSpecies(), p_oTree5->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree6->GetSpecies(), p_oTree6->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree7->GetSpecies(), p_oTree7->GetType()), -1);
//Grid 0,4 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree8->GetSpecies(), p_oTree8->GetType()), -1);
p_oTree9->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree9->GetSpecies(), p_oTree9->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight5);
p_oTree10->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree10->GetSpecies(), p_oTree10->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight5);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree11->GetSpecies(), p_oTree11->GetType()), -1);
p_oTree12->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree12->GetSpecies(), p_oTree12->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight5);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree13->GetSpecies(), p_oTree13->GetType()), -1);
p_oTree14->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree14->GetSpecies(), p_oTree14->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight5);
//Grid 0,5 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree15->GetSpecies(), p_oTree15->GetType()), -1);
p_oTree16->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree16->GetSpecies(), p_oTree16->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight6);
p_oTree17->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree17->GetSpecies(), p_oTree17->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight6);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree18->GetSpecies(), p_oTree18->GetType()), -1);
p_oTree19->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree19->GetSpecies(), p_oTree19->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight6);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree20->GetSpecies(), p_oTree20->GetType()), -1);
p_oTree21->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree21->GetSpecies(), p_oTree21->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight6);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree22->GetSpecies(), p_oTree22->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree23->GetSpecies(), p_oTree23->GetType()), -1);
p_oTree24->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree24->GetSpecies(), p_oTree24->GetType()), &fActualLight);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree25->GetSpecies(), p_oTree25->GetType()), -1);
EXPECT_EQ(fActualLight, fLight6);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree26->GetSpecies(), p_oTree26->GetType()), -1);
//Snag - has light but doesn't match
p_oTree27->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree27->GetSpecies(), p_oTree27->GetType()), &fActualLight);
ASSERT_TRUE(fActualLight != fLight6);
//Grid 0,6 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree28->GetSpecies(), p_oTree28->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree29->GetSpecies(), p_oTree29->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree30->GetSpecies(), p_oTree30->GetType()), -1);
p_oTree31->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree31->GetSpecies(), p_oTree31->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight7);
//Change the number of trees to trigger basal area changes
//Grid cell 0, 0 - Add one tree of DBH 25 (total BA 0.049)
p_oTree32 = p_oPop->CreateTree( 4, 4, 1, clTreePopulation::adult, 25 );
//Grid cell 0, 1 - Do nothing
//Grid cell 0, 2 - Add two trees of DBH 25, one each conifer and
//angiosperm (total BA 0.098)
fX = 4; fY = 20; fDiam = 25;
iSpecies = 1;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
iSpecies = 2;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
//Grid cell 0, 3 - Subtract the tree with DBH 45 (total BA 0.15)
p_oPop->KillTree(p_oTree3, natural);
//Grid cell 0, 4 - Add three trees too small
fX = 4; fY = 36;
iSpecies = 3; fDiam = 6;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::sapling, fDiam );
//Grid cell 0, 5 - Subtract 2 trees too small
p_oPop->KillTree(p_oTree25, natural);
p_oPop->KillTree(p_oTree26, natural);
//Grid cell 0, 6 - Do nothing
//Run another timestep
p_oSimManager->RunSim(1);
//Check to make sure that the basal areas are correct
//Grid 0, 0
fExpConBA = 0;
fExpAngBA = 0;
p_oLightGrid->GetValueOfCell(0, 0, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 0, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 1
fExpConBA = 0.196349541;
fExpAngBA = 0;
p_oLightGrid->GetValueOfCell(0, 1, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 1, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 2
fExpConBA = 0.049087385;
fExpAngBA = 0.208130513;
p_oLightGrid->GetValueOfCell(0, 2, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 2, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 3
fExpConBA = 0.43008403;
fExpAngBA = 0;
p_oLightGrid->GetValueOfCell(0, 3, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 3, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 4
fExpConBA = 0;
fExpAngBA = 0.690050826;
p_oLightGrid->GetValueOfCell(0, 4, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 4, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 5
fExpConBA = 0.204282062;
fExpAngBA = 1.074895926;
p_oLightGrid->GetValueOfCell(0, 5, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 5, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 0, 6
fExpConBA = 0;
fExpAngBA = 0;
p_oLightGrid->GetValueOfCell(0, 6, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(0, 6, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Make sure that the light levels for the third and fourth cells
//change and the rest stay the same
p_oLightGrid->GetValueOfCell(0, 0, iLightCode, &fActualLight);
EXPECT_LT(fabs(fActualLight - fLight1), 0.00001);
p_oLightGrid->GetValueOfCell(0, 1, iLightCode, &fActualLight);
EXPECT_LT(fabs(fActualLight - fLight2), 0.00001);
p_oLightGrid->GetValueOfCell(0, 2, iLightCode, &fActualLight);
EXPECT_GT(fabs(fActualLight - fLight3), 0.1);
p_oLightGrid->GetValueOfCell(0, 3, iLightCode, &fActualLight);
EXPECT_GT(fabs(fActualLight - fLight4), 0.1);
p_oLightGrid->GetValueOfCell(0, 4, iLightCode, &fActualLight);
EXPECT_LT(fabs(fActualLight - fLight5), 0.00001);
p_oLightGrid->GetValueOfCell(0, 5, iLightCode, &fActualLight);
EXPECT_LT(fabs(fActualLight - fLight6), 0.00001);
p_oLightGrid->GetValueOfCell(0, 6, iLightCode, &fActualLight);
EXPECT_LT(fabs(fActualLight - fLight7), 0.00001);
//Check tree values
p_oLightGrid->GetValueOfCell(0, 0, iLightCode, &fLight1);
p_oLightGrid->GetValueOfCell(0, 1, iLightCode, &fLight2);
p_oLightGrid->GetValueOfCell(0, 2, iLightCode, &fLight3);
p_oLightGrid->GetValueOfCell(0, 3, iLightCode, &fLight4);
p_oLightGrid->GetValueOfCell(0, 4, iLightCode, &fLight5);
p_oLightGrid->GetValueOfCell(0, 5, iLightCode, &fLight6);
p_oLightGrid->GetValueOfCell(0, 6, iLightCode, &fLight7);
//Make sure that the species two trees got light values matching their
//grids, and nobody else
//Grid 0,0 trees
p_oTree32->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree32->GetSpecies(), p_oTree32->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight1);
//Grid 0,1 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree1->GetSpecies(), p_oTree1->GetType()), -1);
//Grid 0,2 trees
p_oTree2->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree2->GetSpecies(), p_oTree2->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight3);
//Grid 0,3 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree4->GetSpecies(), p_oTree4->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree5->GetSpecies(), p_oTree5->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree6->GetSpecies(), p_oTree6->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree7->GetSpecies(), p_oTree7->GetType()), -1);
//Grid 0,4 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree8->GetSpecies(), p_oTree8->GetType()), -1);
p_oTree9->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree9->GetSpecies(), p_oTree9->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight5);
p_oTree10->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree10->GetSpecies(), p_oTree10->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight5);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree11->GetSpecies(), p_oTree11->GetType()), -1);
p_oTree12->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree12->GetSpecies(), p_oTree12->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight5);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree13->GetSpecies(), p_oTree13->GetType()), -1);
p_oTree14->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree14->GetSpecies(), p_oTree14->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight5);
//Grid 0,5 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree15->GetSpecies(), p_oTree15->GetType()), -1);
p_oTree16->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree16->GetSpecies(), p_oTree16->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight6);
p_oTree17->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree17->GetSpecies(), p_oTree17->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight6);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree18->GetSpecies(), p_oTree18->GetType()), -1);
p_oTree19->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree19->GetSpecies(), p_oTree19->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight6);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree20->GetSpecies(), p_oTree20->GetType()), -1);
p_oTree21->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree21->GetSpecies(), p_oTree21->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight6);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree22->GetSpecies(), p_oTree22->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree23->GetSpecies(), p_oTree23->GetType()), -1);
p_oTree24->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree24->GetSpecies(), p_oTree24->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight6);
//Snag - has light but doesn't match
p_oTree27->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree27->GetSpecies(), p_oTree27->GetType()), &fActualLight);
ASSERT_TRUE(fActualLight != fLight6);
//Grid 0,6 trees
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree28->GetSpecies(), p_oTree28->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree29->GetSpecies(), p_oTree29->GetType()), -1);
EXPECT_EQ(p_oPop->GetFloatDataCode("Light", p_oTree30->GetSpecies(), p_oTree30->GetType()), -1);
p_oTree31->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree31->GetSpecies(), p_oTree31->GetType()), &fActualLight);
EXPECT_EQ(fActualLight, fLight7);
delete p_oSimManager;
} catch (modelErr &e) {
delete p_oSimManager;
FAIL() << "Testing failed in function: " << e.sFunction << " with message: " << e.sMoreInfo;
}
}
/////////////////////////////////////////////////////////////////////////////
// NormalProcessingRun2()
// Tests normal processing - run 2. This ensures that the calculation of mean
// GLI is bounded between 0 and 100. WriteBasalAreaLightXMLFile2() does setup.
/////////////////////////////////////////////////////////////////////////////
TEST(BasalAreaLight, NormalProcessingRun2)
{
clSimManager * p_oSimManager = new clSimManager( 7, 1, "" );
try {
clBehaviorBase *p_oTemp;
clBasalAreaLight *p_oLightBeh;
float fActualLight, fExpectedLight, fConBA, fAngBA;
//Feed our file to the sim manager
p_oSimManager->ReadFile(WriteBasalAreaLightXMLFile2());
//Check the mean GLI calculations directly for 4 values
p_oTemp = p_oSimManager->GetBehaviorObject("basalarealightshell");
p_oLightBeh = dynamic_cast<clBasalAreaLight*>(p_oTemp);
fExpectedLight = 12.4;
fConBA = 0;
fAngBA = 0;
fActualLight = p_oLightBeh->GetMeanGLI(fConBA, fAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
fExpectedLight = 4.677703256;
fConBA = 1;
fAngBA = 6;
fActualLight = p_oLightBeh->GetMeanGLI(fConBA, fAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
fExpectedLight = 100;
fConBA = 5;
fAngBA = 0;
fActualLight = p_oLightBeh->GetMeanGLI(fConBA, fAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
fExpectedLight = 0;
fConBA = 6;
fAngBA = 0;
fActualLight = p_oLightBeh->GetMeanGLI(fConBA, fAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
fExpectedLight = 0;
fConBA = 100;
fAngBA = 0;
fActualLight = p_oLightBeh->GetMeanGLI(fConBA, fAngBA);
EXPECT_LT(fabs(fExpectedLight - fActualLight), 0.0001);
delete p_oSimManager;
} catch (modelErr &e) {
delete p_oSimManager;
FAIL() << "Testing failed in function: " << e.sFunction << " with message: " << e.sMoreInfo;
}
}
/////////////////////////////////////////////////////////////////////////////
// NormalProcessingRun3()
// Tests normal processing - run 3. This checks to make sure grid cell sizes
// are honored and allows checking of the light level distribution.
// WriteBasalAreaLightXMLFile3() does setup. This produces an output file called "Density
// Light Distribution.txt".
/////////////////////////////////////////////////////////////////////////////
TEST(BasalAreaLight, NormalProcessingRun3)
{
clSimManager * p_oSimManager = new clSimManager( 7, 1, "" );
try {
using namespace std;
//clTreePopulation *p_oPop;
//clTreeSearch *p_oAllTrees;
//clTree *p_oTree;
clGrid *p_oLightGrid;
//int p_iCount[101];
//float fLight;
int iLightCode; //iX, iY
//Feed our file to the sim manager
p_oSimManager->ReadFile(WriteBasalAreaLightXMLFile3());
//Verify the grid cell size
p_oLightGrid = p_oSimManager->GetGridObject("Basal Area Light");
iLightCode = p_oLightGrid->GetFloatDataCode("Light");
EXPECT_LT(-1, iLightCode);
EXPECT_EQ(10, p_oLightGrid->GetLengthXCells());
EXPECT_EQ(10, p_oLightGrid->GetLengthYCells());
//Put 3 trees in each grid cell
/* p_oPop = (clTreePopulation*) p_oSimManager->GetPopulationObject("treepopulation");
for (iX = 0; iX < p_oLightGrid->GetNumberXCells(); iX++) {
for (iY = 0; iY < p_oLightGrid->GetNumberYCells(); iY++) {
p_oPop->CreateTree( (iX * 10) + 5, (iY * 10) + 5, 0, clTreePopulation::adult, 45 );
p_oPop->CreateTree( (iX * 10) + 5, (iY * 10) + 5, 1, clTreePopulation::adult, 24 );
p_oPop->CreateTree( (iX * 10) + 5, (iY * 10) + 5, 2, clTreePopulation::adult, 70 );
}
}
//Run one timestep
p_oSimManager->RunSim(1);
//Count up the light levels and put them in buckets
for (iX = 0; iX < 101; iX++)
p_iCount[iX] = 0;
for (iX = 0; iX < p_oLightGrid->GetNumberXCells(); iX++) {
for (iY = 0; iY < p_oLightGrid->GetNumberYCells(); iY++) {
p_oLightGrid->GetValueOfCell(iX, iY, iLightCode, &fLight);
p_iCount[(int)fLight]++;
}
}
//Write out the results
std::fstream oOut;
oOut.open( "Basal Area Light Distribution.txt", ios::out | ios::trunc );
oOut << "Basal Area Light Distribution\n";
oOut << "Number of grid values falling into each GLI bucket (BA = 0.59):\n";
oOut << "0";
for (iX = 1; iX < 101; iX++)
oOut << "\t" << iX;
oOut << "\n" << p_iCount[0];
for (iX = 1; iX < 101; iX++)
oOut << "\t" << p_iCount[iX];
oOut << "\n";
//Count up the tree values and write that distribution as well
for (iX = 0; iX < 101; iX++)
p_iCount[iX] = 0;
p_oAllTrees = p_oPop->Find("all");
p_oTree = p_oAllTrees->NextTree();
while (p_oTree) {
p_oTree->GetValue(p_oPop->GetFloatDataCode("Light", p_oTree->GetSpecies(), p_oTree->GetType()), &fLight);
p_iCount[(int)fLight]++;
p_oTree = p_oAllTrees->NextTree();
}
oOut << "Number of tree values falling into each GLI bucket (BA = 0.59):\n";
oOut << "0";
for (iX = 1; iX < 101; iX++)
oOut << "\t" << iX;
oOut << "\n" << p_iCount[0];
for (iX = 1; iX < 101; iX++)
oOut << "\t" << p_iCount[iX];
oOut << "\n";
oOut.close(); */
delete p_oSimManager;
} catch (modelErr &e) {
delete p_oSimManager;
FAIL() << "Testing failed in function: " << e.sFunction << " with message: " << e.sMoreInfo;
}
}
/////////////////////////////////////////////////////////////////////////////
// NormalProcessingRun4()
// Tests normal processing - run 4. This double-checks grid map reading.
// WriteBasalAreaLightXMLFile4() does setup.
/////////////////////////////////////////////////////////////////////////////
TEST(BasalAreaLight, NormalProcessingRun4)
{
clSimManager * p_oSimManager = new clSimManager( 7, 1, "" );
try {
clGrid *p_oLightGrid;
float fActualLight, fExpectedLight = 95, fExpConBA = 0.03, fExpAngBA = 0,
fActualConBA, fActualAngBA;
int iLightCode, iConBACode, iAngBACode, iX, iY,
iNumXCells, iNumYCells;
//Feed our file to the sim manager
p_oSimManager->ReadFile(WriteBasalAreaLightXMLFile4());
//Run one timestep
p_oSimManager->RunSim(1);
p_oLightGrid = p_oSimManager->GetGridObject("Basal Area Light");
iLightCode = p_oLightGrid->GetFloatDataCode("Light");
EXPECT_LT(-1, iLightCode);
iConBACode = p_oLightGrid->GetFloatDataCode("Con BA");
EXPECT_LT(-1, iConBACode);
iAngBACode = p_oLightGrid->GetFloatDataCode("Ang BA");
EXPECT_LT(-1, iAngBACode);
//Make sure that all cells got a light level
iNumXCells = p_oLightGrid->GetNumberXCells();
iNumYCells = p_oLightGrid->GetNumberYCells();
for (iX = 0; iX < iNumXCells; iX++) {
for (iY = 0; iY < iNumYCells; iY++) {
p_oLightGrid->GetValueOfCell(iX, iY, iLightCode, &fActualLight);
p_oLightGrid->GetValueOfCell(iX, iY, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(iX, iY, iAngBACode, &fActualAngBA);
EXPECT_EQ(fExpectedLight, fActualLight);
EXPECT_EQ(fExpConBA, fActualConBA);
EXPECT_EQ(fExpAngBA, fActualAngBA);
}
}
delete p_oSimManager;
} catch (modelErr &e) {
delete p_oSimManager;
FAIL() << "Testing failed in function: " << e.sFunction << " with message: " << e.sMoreInfo;
}
}
/////////////////////////////////////////////////////////////////////////////
// NormalProcessingRun5()
// Tests normal processing - run 5. This double-checks radius.
// WriteBasalAreaLightXMLFile5() does setup.
/////////////////////////////////////////////////////////////////////////////
TEST(BasalAreaLight, NormalProcessingRun5)
{
clSimManager * p_oSimManager = new clSimManager( 7, 1, "" );
try {
clTreePopulation *p_oPop;
clGrid *p_oLightGrid;
float fExpConBA, //Conifer basal area we're expecting
fExpAngBA, //Angiosperm basal area we're expecting
fActualConBA, //Conifer basal area calculated by SORTIE
fActualAngBA, //Angiosperm basal area calculated by SORTIE
fDiam, fX, fY; //For creating trees
//For stashing light levels between timesteps
int iLightCode, iConBACode, iAngBACode, iSpecies;
//Feed our file to the sim manager
p_oSimManager->ReadFile(WriteBasalAreaLightXMLFile5());
p_oPop = (clTreePopulation*) p_oSimManager->GetPopulationObject("treepopulation");
//Add trees
fX = 29.38; fY = 34.87; iSpecies = 0; fDiam = 74.50;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 23.44; fY = 35.27; iSpecies = 2; fDiam = 95.05;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 30.70; fY = 28.31; iSpecies = 1; fDiam = 78.92;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 25.69; fY = 27.20; iSpecies = 3; fDiam = 69.95;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 25.34; fY = 38.52; iSpecies = 0; fDiam = 74.06;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 30.11; fY = 38.41; iSpecies = 3; fDiam = 93.52;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 24.55; fY = 25.90; iSpecies = 1; fDiam = 67.81;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 20.73; fY = 36.66; iSpecies = 2; fDiam = 40.47;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 19.64; fY = 31.49; iSpecies = 3; fDiam = 92.60;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 24.82; fY = 25.12; iSpecies = 0; fDiam = 35.49;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 35.63; fY = 33.87; iSpecies = 1; fDiam = 71.42;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 27.03; fY = 24.10; iSpecies = 3; fDiam = 63.52;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 36.08; fY = 31.00; iSpecies = 3; fDiam = 59.44;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 20.41; fY = 27.57; iSpecies = 2; fDiam = 51.39;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 20.83; fY = 25.51; iSpecies = 2; fDiam = 95.57;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 38.26; fY = 32.18; iSpecies = 0; fDiam = 34.70;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 38.56; fY = 35.23; iSpecies = 3; fDiam = 60.03;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 35.73; fY = 24.74; iSpecies = 2; fDiam = 62.12;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 38.55; fY = 29.70; iSpecies = 0; fDiam = 31.72;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 38.71; fY = 29.89; iSpecies = 2; fDiam = 78.87;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 37.34; fY = 38.96; iSpecies = 3; fDiam = 83.99;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 36.84; fY = 23.88; iSpecies = 0; fDiam = 52.87;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 35.42; fY = 22.05; iSpecies = 1; fDiam = 31.12;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 38.84; fY = 24.81; iSpecies = 0; fDiam = 41.15;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 23.09; fY = 18.10; iSpecies = 1; fDiam = 49.68;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 29.13; fY = 17.01; iSpecies = 3; fDiam = 18.39;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 25.42; fY = 15.83; iSpecies = 2; fDiam = 96.25;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 27.92; fY = 15.67; iSpecies = 0; fDiam = 40.37;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 25.23; fY = 15.28; iSpecies = 1; fDiam = 24.07;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 34.72; fY = 16.18; iSpecies = 1; fDiam = 44.42;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 36.12; fY = 16.65; iSpecies = 2; fDiam = 99.04;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
fX = 39.98; fY = 15.98; iSpecies = 1; fDiam = 45.91;
p_oPop->CreateTree( fX, fY, iSpecies, clTreePopulation::adult, fDiam );
//Run one timestep
p_oSimManager->RunSim(1);
p_oLightGrid = p_oSimManager->GetGridObject("Basal Area Light");
iLightCode = p_oLightGrid->GetFloatDataCode("Light");
EXPECT_LT(-1, iLightCode);
iConBACode = p_oLightGrid->GetFloatDataCode("Con BA");
EXPECT_LT(-1, iConBACode);
iAngBACode = p_oLightGrid->GetFloatDataCode("Ang BA");
EXPECT_LT(-1, iAngBACode);
//Check to make sure the basal area totals are correct
//Grid 5, 5
fExpConBA = 1.459611208;
fExpAngBA = 1.551503445;
p_oLightGrid->GetValueOfCell(5, 5, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(5, 5, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 5, 6
fExpConBA = 1.803823734;
fExpAngBA = 3.31248918;
p_oLightGrid->GetValueOfCell(5, 6, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(5, 6, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
//Grid 6, 5
fExpConBA = 1.852594769;
fExpAngBA = 2.305672952;
p_oLightGrid->GetValueOfCell(6, 5, iConBACode, &fActualConBA);
p_oLightGrid->GetValueOfCell(6, 5, iAngBACode, &fActualAngBA);
EXPECT_LT(fabs(fExpConBA - fActualConBA), 0.001);
EXPECT_LT(fabs(fExpAngBA - fActualAngBA), 0.001);
delete p_oSimManager;
} catch (modelErr &e) {
delete p_oSimManager;
FAIL() << "Testing failed in function: " << e.sFunction << " with message: " << e.sMoreInfo;
}
}
/////////////////////////////////////////////////////////////////////////////
// WriteBasalAreaLightXMLFile1()
/////////////////////////////////////////////////////////////////////////////
const char* WriteBasalAreaLightXMLFile1()
{
using namespace std;
const char *cFileString = "TestFile1.xml";
//Open file to write to
std::fstream oOut;
oOut.open( cFileString, ios::out | ios::trunc );
oOut << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"
<< "<paramFile fileCode=\"06010101\">"
<< "<plot>"
<< "<timesteps>3</timesteps>"
<< "<yearsPerTimestep>1</yearsPerTimestep>"
<< "<randomSeed>1</randomSeed>"
<< "<plot_lenX>96</plot_lenX>"
<< "<plot_lenY>96</plot_lenY>"
<< "<plot_latitude>55.37</plot_latitude>"
<< "<plot_precip_mm_yr>1150.645781</plot_precip_mm_yr>"
<< "<plot_temp_C>12.88171785</plot_temp_C>"
<< "</plot>";
WriteBasalAreaLightCommonStuff(oOut);
oOut << "<behaviorList>"
<< "<behavior>"
<< "<behaviorName>BasalAreaLight</behaviorName>"
<< "<applyTo species=\"Species_2\" type=\"Adult\" />"
<< "<applyTo species=\"Species_2\" type=\"Sapling\" />"
<< "<version>1</version>"
<< "<listPosition>1</listPosition>"
<< "</behavior>"
<< "<behavior>"
<< "<behaviorName>ConstantGLI</behaviorName>"
<< "<version>1</version>"
<< "<listPosition>2</listPosition>"
<< "<applyTo species=\"Species_1\" type=\"Snag\"/>"
<< "</behavior>"
<< "</behaviorList>"
<< "<ConstantGLI2>"
<< "<li_constGLI>100</li_constGLI>"
<< "</ConstantGLI2>"
<< "<BasalAreaLight1>"
<< "<li_baLightA>12.4</li_baLightA>"
<< "<li_baConiferLightB>1.8</li_baConiferLightB>"
<< "<li_baConiferLightC>2.1</li_baConiferLightC>"
<< "<li_baAngiospermLightB>3.83</li_baAngiospermLightB>"
<< "<li_baAngiospermLightC>3.04</li_baAngiospermLightC>"
<< "<li_baLightSigma>0.82</li_baLightSigma>"
<< "<li_baLightChangeThreshold>0.05</li_baLightChangeThreshold>"