Rev 490 | Rev 513 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
111 | Werner | 2 | #include "global.h" |
189 | iland | 3 | #include "resourceunitspecies.h" |
111 | Werner | 4 | |
5 | #include "species.h" |
||
189 | iland | 6 | #include "resourceunit.h" |
468 | werner | 7 | #include "model.h" |
8 | #include "snag.h" |
||
496 | werner | 9 | #include "watercycle.h" |
376 | werner | 10 | |
458 | werner | 11 | /** @class ResourceUnitSpecies |
12 | The class contains data available at ResourceUnit x Species scale. |
||
13 | Data stored is either statistical (i.e. number of trees per species) or used |
||
468 | werner | 14 | within the model (e.g. fraction of utilizable Radiation). |
15 | Important submodules are: |
||
16 | * 3PG production (Production3PG) |
||
17 | * Establishment |
||
18 | * Growth and Recruitment of Saplings |
||
19 | * Snag dynamics |
||
458 | werner | 20 | */ |
468 | werner | 21 | ResourceUnitSpecies::~ResourceUnitSpecies() |
22 | { |
||
23 | if (mSnag) |
||
24 | delete mSnag; |
||
25 | mSnag = 0; |
||
26 | } |
||
440 | werner | 27 | |
376 | werner | 28 | double ResourceUnitSpecies::leafArea() const |
29 | { |
||
30 | // Leaf area of the species: |
||
31 | // total leaf area on the RU * fraction of leafarea |
||
32 | return mLAIfactor * ru()->leafAreaIndex(); |
||
33 | } |
||
34 | |||
235 | werner | 35 | void ResourceUnitSpecies::setup(Species *species, ResourceUnit *ru) |
36 | { |
||
37 | mSpecies = species; |
||
38 | mRU = ru; |
||
39 | mResponse.setup(this); |
||
40 | m3PG.setResponse(&mResponse); |
||
440 | werner | 41 | mEstablishment.setup(ru->climate(), this); |
452 | werner | 42 | mSapling.setup(this); |
235 | werner | 43 | mStatistics.setResourceUnitSpecies(this); |
277 | werner | 44 | mStatisticsDead.setResourceUnitSpecies(this); |
278 | werner | 45 | mStatisticsMgmt.setResourceUnitSpecies(this); |
468 | werner | 46 | if (mSnag) |
47 | delete mSnag; |
||
48 | mSnag=0; |
||
49 | if (Model::settings().carbonCycleEnabled) { |
||
50 | mSnag = new Snag; |
||
490 | werner | 51 | mSnag->setup(mRU); |
468 | werner | 52 | } |
440 | werner | 53 | |
277 | werner | 54 | mRemovedGrowth = 0.; |
438 | werner | 55 | mLastYear = -1; |
468 | werner | 56 | |
235 | werner | 57 | } |
111 | Werner | 58 | |
59 | |||
440 | werner | 60 | void ResourceUnitSpecies::calculate(const bool fromEstablishment) |
226 | werner | 61 | { |
438 | werner | 62 | if (mLastYear == GlobalSettings::instance()->currentYear()) |
63 | return; |
||
64 | mLastYear = GlobalSettings::instance()->currentYear(); |
||
65 | |||
66 | statistics().clear(); |
||
440 | werner | 67 | if (mLAIfactor>0 || fromEstablishment==true) { |
496 | werner | 68 | // execute the water calculation... |
69 | if (fromEstablishment) |
||
70 | const_cast<WaterCycle*>(mRU->waterCycle())->run(); // run the water sub model (only if this has not be done already) |
||
71 | mResponse.calculate();// calculate environmental responses per species (vpd, temperature, ...) |
||
72 | m3PG.calculate();// production of NPP |
||
369 | werner | 73 | } else { |
74 | // if no LAI is present, then just clear the respones. |
||
376 | werner | 75 | // note: subject to change when regeneration is added... |
369 | werner | 76 | mResponse.clear(); |
77 | m3PG.clear(); |
||
78 | } |
||
226 | werner | 79 | } |
277 | werner | 80 | |
81 | |||
82 | void ResourceUnitSpecies::updateGWL() |
||
83 | { |
||
84 | // removed growth is the running sum of all removed |
||
85 | // tree volume. the current "GWL" therefore is current volume (standing) + mRemovedGrowth. |
||
278 | werner | 86 | mRemovedGrowth+=statisticsDead().volume() + statisticsMgmt().volume(); |
277 | werner | 87 | } |
440 | werner | 88 | |
89 | void ResourceUnitSpecies::calclulateEstablishment() |
||
90 | { |
||
91 | mEstablishment.calculate(); |
||
442 | werner | 92 | //DBGMODE( |
93 | if (GlobalSettings::instance()->isDebugEnabled(GlobalSettings::dEstablishment)) { |
||
94 | DebugList &out = GlobalSettings::instance()->debugList(ru()->index(), GlobalSettings::dEstablishment); |
||
95 | // establishment details |
||
96 | out << mSpecies->id() << ru()->index(); |
||
97 | out << mEstablishment.avgSeedDensity(); |
||
98 | out << mEstablishment.TACAminTemp() << mEstablishment.TACAchill() << mEstablishment.TACAfrostFree() << mEstablishment.TACgdd(); |
||
99 | out << mEstablishment.TACAfrostDaysAfterBudBirst() << mEstablishment.abioticEnvironment(); |
||
100 | out << m3PG.fEnvYear() << mEstablishment.avgLIFValue() << mEstablishment.numberEstablished(); |
||
466 | werner | 101 | out << mSapling.livingSaplings() << mSapling.averageHeight() << mSapling.averageAge() << mSapling.averageDeltaHPot() << mSapling.averageDeltaHRealized(); |
471 | werner | 102 | out << mSapling.newSaplings() << mSapling.diedSaplings() << mSapling.recruitedSaplings() << mSpecies->saplingGrowthParameters().referenceRatio; |
442 | werner | 103 | } |
104 | //); // DBGMODE() |
||
440 | werner | 105 | |
442 | werner | 106 | |
440 | werner | 107 | if ( logLevelDebug() ) |
108 | qDebug() << "establishment of RU" << mRU->index() << "species" << species()->id() |
||
109 | << "seeds density:" << mEstablishment.avgSeedDensity() |
||
110 | << "abiotic environment:" << mEstablishment.abioticEnvironment() |
||
111 | << "f_env,yr:" << m3PG.fEnvYear() |
||
112 | << "N(established):" << mEstablishment.numberEstablished(); |
||
113 | |||
114 | } |
||
450 | werner | 115 | |
116 | void ResourceUnitSpecies::calclulateSaplingGrowth() |
||
117 | { |
||
118 | mSapling.calculateGrowth(); |
||
119 | } |
||
453 | werner | 120 | |
121 | void ResourceUnitSpecies::visualGrid(Grid<float> &grid) const |
||
122 | { |
||
123 | mSapling.fillHeightGrid(grid); |
||
124 | } |
||
462 | werner | 125 | |
475 | werner | 126 | void ResourceUnitSpecies::calculateSnagDynamics() |
127 | { |
||
128 | if (!snag()) |
||
129 | return; |
||
130 | |||
131 | snag()->processYear(); |
||
477 | werner | 132 | if (GlobalSettings::instance()->isDebugEnabled(GlobalSettings::dSnagDynamics) && !snag()->isEmpty()) { |
475 | werner | 133 | DebugList &out = GlobalSettings::instance()->debugList(ru()->index(), GlobalSettings::dSnagDynamics); |
477 | werner | 134 | out << mSpecies->id() << ru()->index() << snag()->debugList(); // use private variables... |
475 | werner | 135 | } |
136 | |||
137 | } |