Subversion Repositories public iLand

Rev

Rev 1164 | Rev 1168 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1164 Rev 1165
Line 55... Line 55...
55
55
56
    int species_idx;
56
    int species_idx;
57
    QVector<int>::const_iterator sbegin, send;
57
    QVector<int>::const_iterator sbegin, send;
58
    ru->speciesSet()->randomSpeciesOrder(sbegin, send);
58
    ru->speciesSet()->randomSpeciesOrder(sbegin, send);
59
    for (QVector<int>::const_iterator s_idx=sbegin; s_idx!=send;++s_idx) {
59
    for (QVector<int>::const_iterator s_idx=sbegin; s_idx!=send;++s_idx) {
60
    //for (int s_idx = 0; s_idx<ru->ruSpecies().size(); ++s_idx) {
-
 
61
60
62
        // start from a random species (and cycle through the available species)
61
        // start from a random species (and cycle through the available species)
63
        species_idx = *s_idx;
62
        species_idx = *s_idx;
64
63
65
        ResourceUnitSpecies *rus = ru->ruSpecies()[species_idx];
64
        ResourceUnitSpecies *rus = ru->ruSpecies()[species_idx];
Line 207... Line 206...
207
    GridRunner<float> runner(GlobalSettings::instance()->model()->grid(), rectangle);
206
    GridRunner<float> runner(GlobalSettings::instance()->model()->grid(), rectangle);
208
    ResourceUnit *ru;
207
    ResourceUnit *ru;
209
    while (runner.next()) {
208
    while (runner.next()) {
210
        SaplingCell *s = cell(runner.currentIndex(), true, &ru);
209
        SaplingCell *s = cell(runner.currentIndex(), true, &ru);
211
        if (s) {
210
        if (s) {
-
 
211
            clearSaplings(s, ru, remove_biomass);
-
 
212
        }
212
213
213
            for (int i=0;i<NSAPCELLS;++i)
-
 
214
                if (s->saplings[i].is_occupied()) {
-
 
215
                    if (remove_biomass) {
-
 
216
                        ResourceUnitSpecies *rus = ru->resourceUnitSpecies(s->saplings[i].species_index);
-
 
217
                        if (!rus && !rus->species()) {
-
 
218
                            qDebug() << "Saplings::clearSaplings(): invalid resource unit!!!";
-
 
219
                            return;
-
 
220
                        }
-
 
221
                        rus->saplingStat().addCarbonOfDeadSapling( s->saplings[i].height / rus->species()->saplingGrowthParameters().hdSapling * 100.f );
-
 
-
 
214
    }
-
 
215
}
-
 
216
-
 
217
void Saplings::clearSaplings(SaplingCell *s, ResourceUnit *ru, const bool remove_biomass)
-
 
218
{
-
 
219
    if (s) {
-
 
220
        for (int i=0;i<NSAPCELLS;++i)
-
 
221
            if (s->saplings[i].is_occupied()) {
-
 
222
                if (!remove_biomass) {
-
 
223
                    ResourceUnitSpecies *rus = ru->resourceUnitSpecies(s->saplings[i].species_index);
-
 
224
                    if (!rus && !rus->species()) {
-
 
225
                        qDebug() << "Saplings::clearSaplings(): invalid resource unit!!!";
-
 
226
                        return;
222
                    }
227
                    }
223
                    s->saplings[i].clear();
-
 
-
 
228
                    rus->saplingStat().addCarbonOfDeadSapling( s->saplings[i].height / rus->species()->saplingGrowthParameters().hdSapling * 100.f );
224
                }
229
                }
225
            s->checkState();
-
 
-
 
230
                s->saplings[i].clear();
-
 
231
            }
-
 
232
        s->checkState();
-
 
233
-
 
234
    }
-
 
235
-
 
236
}
-
 
237
-
 
238
int Saplings::addSprout(const Tree *t)
-
 
239
{
-
 
240
    if (t->species()->saplingGrowthParameters().sproutGrowth==0.)
-
 
241
        return 0;
-
 
242
    SaplingCell *sc = cell(t->positionIndex());
-
 
243
    if (!sc)
-
 
244
        return 0;
-
 
245
    clearSaplings(sc, const_cast<ResourceUnit*>(t->ru()), false );
-
 
246
    SaplingTree *st=sc->addSapling(0.05f, 0, t->species()->index());
-
 
247
    if (st)
-
 
248
        st->set_sprout(true);
-
 
249
-
 
250
    // neighboring cells
-
 
251
    double crown_area = t->crownRadius()*t->crownRadius() * M_PI; //m2
-
 
252
    // calculate how many cells on the ground are covered by the crown (this is a rather rough estimate)
-
 
253
    // n_cells: in addition to the original cell
-
 
254
    int n_cells = static_cast<int>(round( crown_area / static_cast<double>(cPxSize*cPxSize) - 1.));
-
 
255
    if (n_cells>0) {
-
 
256
        ResourceUnit *ru;
-
 
257
        static const int offsets_x[8] = {1,1,0,-1,-1,-1,0,1};
-
 
258
        static const int offsets_y[8] = {0,1,1,1,0,-1,-1,-1};
-
 
259
        int s=irandom(0,8);
-
 
260
        while(n_cells) {
-
 
261
            sc = cell(t->positionIndex()+QPoint(offsets_x[s], offsets_y[s]),true,&ru);
-
 
262
            if (sc) {
-
 
263
                clearSaplings(sc, ru, false );
-
 
264
                SaplingTree *st=sc->addSapling(0.05f, 0, t->species()->index());
-
 
265
                if (st)
-
 
266
                    st->set_sprout(true);
-
 
267
            }
226
268
-
 
269
            s = (s+1)%8; --n_cells;
227
        }
270
        }
228
    }
271
    }
-
 
272
    return 1;
229
}
273
}
230
274
231
void Saplings::updateBrowsingPressure()
275
void Saplings::updateBrowsingPressure()
232
{
276
{
233
    if (GlobalSettings::instance()->settings().valueBool("model.settings.browsing.enabled"))
277
    if (GlobalSettings::instance()->settings().valueBool("model.settings.browsing.enabled"))
Line 260... Line 304...
260
304
261
    double delta_h_factor = f_env_yr * lr; // relative growth
305
    double delta_h_factor = f_env_yr * lr; // relative growth
262
306
263
    if (h_pot<0. || delta_h_pot<0. || lif_corrected<0. || lif_corrected>1. || delta_h_factor<0. || delta_h_factor>1. )
307
    if (h_pot<0. || delta_h_pot<0. || lif_corrected<0. || lif_corrected>1. || delta_h_factor<0. || delta_h_factor>1. )
264
        qDebug() << "invalid values in Sapling::growSapling";
308
        qDebug() << "invalid values in Sapling::growSapling";
-
 
309
-
 
310
    // sprouts grow faster. Sprouts therefore are less prone to stress (threshold), and can grow higher than the growth potential.
-
 
311
    if (tree.is_sprout())
-
 
312
        delta_h_factor = delta_h_factor *species->saplingGrowthParameters().sproutGrowth;
265
313
266
    // check browsing
314
    // check browsing
267
    if (mBrowsingPressure>0. && tree.height<=2.f) {
315
    if (mBrowsingPressure>0. && tree.height<=2.f) {
268
        double p = rus->species()->saplingGrowthParameters().browsingProbability;
316
        double p = rus->species()->saplingGrowthParameters().browsingProbability;
269
        // calculate modifed annual browsing probability via odds-ratios
317
        // calculate modifed annual browsing probability via odds-ratios
Line 284... Line 332...
284
            return true; // need cleanup
332
            return true; // need cleanup
285
        }
333
        }
286
    } else {
334
    } else {
287
        tree.stress_years=0; // reset stress counter
335
        tree.stress_years=0; // reset stress counter
288
    }
336
    }
289
    DBG_IF(delta_h_pot*delta_h_factor < 0.f || delta_h_pot*delta_h_factor > 2., "Sapling::growSapling", "inplausible height growth.");
-
 
-
 
337
    DBG_IF(delta_h_pot*delta_h_factor < 0.f || (!tree.is_sprout() && delta_h_pot*delta_h_factor > 2.), "Sapling::growSapling", "inplausible height growth.");
290
338
291
    // grow
339
    // grow
292
    tree.height += delta_h_pot * delta_h_factor;
340
    tree.height += delta_h_pot * delta_h_factor;
293
    tree.age++; // increase age of sapling by 1
341
    tree.age++; // increase age of sapling by 1
294
342