Rev 1113 | Rev 1118 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1113 | Rev 1115 | ||
---|---|---|---|
Line 120... | Line 120... | ||
120 | 120 | ||
121 | void Saplings::saplingGrowth(const ResourceUnit *ru) |
121 | void Saplings::saplingGrowth(const ResourceUnit *ru) |
122 | {
|
122 | {
|
123 | HeightGrid *height_grid = GlobalSettings::instance()->model()->heightGrid(); |
123 | HeightGrid *height_grid = GlobalSettings::instance()->model()->heightGrid(); |
124 | FloatGrid *lif_grid = GlobalSettings::instance()->model()->grid(); |
124 | FloatGrid *lif_grid = GlobalSettings::instance()->model()->grid(); |
- | 125 | ||
- | 126 | for (QList<ResourceUnitSpecies*>::const_iterator i=ru->ruSpecies().constBegin(); i!=ru->ruSpecies().constEnd(); ++i) |
|
- | 127 | (*i)->saplingStat().clearStatistics(); |
|
125 | 128 | ||
126 | QPoint imap = mGrid.indexAt(ru->boundingBox().topLeft()); |
129 | QPoint imap = mGrid.indexAt(ru->boundingBox().topLeft()); |
- | 130 | bool need_check=false; |
|
127 | for (int iy=0; iy<cPxPerRU; ++iy) { |
131 | for (int iy=0; iy<cPxPerRU; ++iy) { |
128 | SaplingCell *s = mGrid.ptr(imap.x(), imap.y()+iy); // ptr to the row |
132 | SaplingCell *s = mGrid.ptr(imap.x(), imap.y()+iy); // ptr to the row |
129 | int isc = mGrid.index(imap.x(), imap.y()+iy); |
133 | int isc = mGrid.index(imap.x(), imap.y()+iy); |
130 | 134 | ||
131 | for (int ix=0;ix<cPxPerRU; ++ix, ++s, ++isc) { |
135 | for (int ix=0;ix<cPxPerRU; ++ix, ++s, ++isc) { |
132 | if (s->state != SaplingCell::CellInvalid) { |
136 | if (s->state != SaplingCell::CellInvalid) { |
- | 137 | need_check=false; |
|
133 | for (int i=0;i<NSAPCELLS;++i) { |
138 | for (int i=0;i<NSAPCELLS;++i) { |
134 | if (s->saplings[i].is_occupied()) { |
139 | if (s->saplings[i].is_occupied()) { |
135 | // growth of this sapling tree
|
140 | // growth of this sapling tree
|
136 | const HeightGridValue &hgv = (*height_grid)[height_grid->index5(isc)]; |
141 | const HeightGridValue &hgv = (*height_grid)[height_grid->index5(isc)]; |
137 | float lif_value = (*lif_grid)[isc]; |
142 | float lif_value = (*lif_grid)[isc]; |
138 | 143 | ||
139 | growSapling(ru, s->saplings[i], isc, hgv.height, lif_value); |
- | |
- | 144 | need_check |= growSapling(ru, s->saplings[i], isc, hgv.height, lif_value); |
|
140 | }
|
145 | }
|
141 | }
|
146 | }
|
- | 147 | if (need_check) |
|
- | 148 | s->checkState(); |
|
142 | }
|
149 | }
|
143 | }
|
150 | }
|
144 | }
|
151 | }
|
145 | 152 | ||
146 | }
|
153 | }
|
Line 151... | Line 158... | ||
151 | Saplings::mBrowsingPressure = GlobalSettings::instance()->settings().valueDouble("model.settings.browsing.browsingPressure"); |
158 | Saplings::mBrowsingPressure = GlobalSettings::instance()->settings().valueDouble("model.settings.browsing.browsingPressure"); |
152 | else
|
159 | else
|
153 | Saplings::mBrowsingPressure = 0.; |
160 | Saplings::mBrowsingPressure = 0.; |
154 | }
|
161 | }
|
155 | 162 | ||
156 | void Saplings::growSapling(const ResourceUnit *ru, SaplingTree &tree, int isc, float dom_height, float lif_value) |
- | |
- | 163 | bool Saplings::growSapling(const ResourceUnit *ru, SaplingTree &tree, int isc, float dom_height, float lif_value) |
|
157 | {
|
164 | {
|
158 | ResourceUnitSpecies *rus = const_cast<ResourceUnitSpecies*>(ru->ruSpecies()[tree.species_index]); |
165 | ResourceUnitSpecies *rus = const_cast<ResourceUnitSpecies*>(ru->ruSpecies()[tree.species_index]); |
159 | const Species *species = rus->species(); |
166 | const Species *species = rus->species(); |
160 | 167 | ||
161 | // (1) calculate height growth potential for the tree (uses linerization of expressions...)
|
168 | // (1) calculate height growth potential for the tree (uses linerization of expressions...)
|
Line 192... | Line 199... | ||
192 | if (delta_h_factor < species->saplingGrowthParameters().stressThreshold) { |
199 | if (delta_h_factor < species->saplingGrowthParameters().stressThreshold) { |
193 | tree.stress_years++; |
200 | tree.stress_years++; |
194 | if (tree.stress_years > species->saplingGrowthParameters().maxStressYears) { |
201 | if (tree.stress_years > species->saplingGrowthParameters().maxStressYears) { |
195 | // sapling dies...
|
202 | // sapling dies...
|
196 | tree.clear(); |
203 | tree.clear(); |
197 | rus->saplingStat().addCarbonOfDeadSapling( tree.height / species->saplingGrowthParameters().hdSapling * 100. ); |
- | |
198 | return; |
- | |
- | 204 | rus->saplingStat().addCarbonOfDeadSapling( tree.height / species->saplingGrowthParameters().hdSapling * 100.f ); |
|
- | 205 | return true; // need cleanup |
|
199 | }
|
206 | }
|
200 | } else { |
207 | } else { |
201 | tree.stress_years=0; // reset stress counter |
208 | tree.stress_years=0; // reset stress counter |
202 | }
|
209 | }
|
203 | DBG_IF(delta_h_pot*delta_h_factor < 0.f || delta_h_pot*delta_h_factor > 2., "Sapling::growSapling", "inplausible height growth."); |
210 | DBG_IF(delta_h_pot*delta_h_factor < 0.f || delta_h_pot*delta_h_factor > 2., "Sapling::growSapling", "inplausible height growth."); |
Line 243... | Line 250... | ||
243 | // add carbon to the ground
|
250 | // add carbon to the ground
|
244 | rus->saplingStat().addCarbonOfDeadSapling( s.saplings[i].height / species->saplingGrowthParameters().hdSapling * 100.f ); |
251 | rus->saplingStat().addCarbonOfDeadSapling( s.saplings[i].height / species->saplingGrowthParameters().hdSapling * 100.f ); |
245 | s.saplings[i].clear(); |
252 | s.saplings[i].clear(); |
246 | }
|
253 | }
|
247 | }
|
254 | }
|
248 | return; |
- | |
- | 255 | return true; // need cleanup |
|
249 | }
|
256 | }
|
250 | // book keeping (only for survivors) for the sapling of the resource unit / species
|
257 | // book keeping (only for survivors) for the sapling of the resource unit / species
|
251 | SaplingStat &ss = rus->saplingStat(); |
258 | SaplingStat &ss = rus->saplingStat(); |
252 | ss.mLiving++; |
259 | ss.mLiving++; |
253 | ss.mAvgHeight+=tree.height; |
260 | ss.mAvgHeight+=tree.height; |
254 | ss.mAvgAge+=tree.age; |
261 | ss.mAvgAge+=tree.age; |
255 | ss.mAvgDeltaHPot+=delta_h_pot; |
262 | ss.mAvgDeltaHPot+=delta_h_pot; |
256 | ss.mAvgHRealized += delta_h_pot * delta_h_factor; |
263 | ss.mAvgHRealized += delta_h_pot * delta_h_factor; |
257 | - | ||
- | 264 | return false; |
|
258 | }
|
265 | }
|
259 | 266 | ||
260 | void SaplingStat::clearStatistics() |
267 | void SaplingStat::clearStatistics() |
261 | {
|
268 | {
|
262 | mRecruited=mDied=mLiving=0; |
269 | mRecruited=mDied=mLiving=0; |