Rev 477 | Rev 521 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
468 | werner | 2 | #ifndef SNAG_H |
3 | #define SNAG_H |
||
475 | werner | 4 | #include <QList> |
5 | #include <QVariant> |
||
468 | werner | 6 | class Tree; // forward |
490 | werner | 7 | class ResourceUnit; // forward |
468 | werner | 8 | |
476 | werner | 9 | /** CNPool stores a duple of carbon and nitrogen (kg/ha) |
10 | use addBiomass(biomass, cnratio) to add biomass; use operators (+, +=, *, *=) for simple operations. |
||
11 | */ |
||
468 | werner | 12 | struct CNPool |
13 | { |
||
14 | CNPool(): C(0.), N(0.) {} |
||
476 | werner | 15 | static void setCFraction(const double fraction) { biomassCFraction = fraction; } |
468 | werner | 16 | CNPool(const double c, const double n) {C=c; N=n; } |
476 | werner | 17 | bool isEmpty() const { return C==0.; } ///< returns true if pool is empty |
468 | werner | 18 | double C; // carbon pool (kg C/ha) |
19 | double N; // nitrogen pool (kg N/ha) |
||
20 | double CN() { return N>0?C/N:0.; } ///< current CN ratio |
||
21 | void clear() {C=0.; N=0.; } |
||
476 | werner | 22 | /// add biomass to the pool (kg dry mass/ha); CNratio is used to calculate the N-Content, the global C-Fraction of biomass is used to |
23 | /// calculate the amount of carbon of 'biomass'. |
||
468 | werner | 24 | void addBiomass(const double biomass, const double CNratio) { C+=biomass*biomassCFraction; N+=biomass*biomassCFraction/CNratio; } |
25 | // some simple operators |
||
26 | void operator+=(const CNPool &s) { C+=s.C; N+=s.N; } ///< add contents of a pool |
||
27 | void operator*=(const double factor) { C*=factor; N*=factor; } ///< Multiply pool with 'factor' |
||
476 | werner | 28 | const CNPool operator+(const CNPool &p2) const { return CNPool(C+p2.C, N+p2.N); } ///< return the sum of two pools |
29 | const CNPool operator*(const double factor) const { return CNPool(C*factor, N*factor); } ///< return the pool multiplied with 'factor' |
||
468 | werner | 30 | private: |
31 | static double biomassCFraction; |
||
32 | }; |
||
33 | |||
34 | class Snag |
||
35 | { |
||
36 | public: |
||
37 | Snag(); |
||
490 | werner | 38 | void setup( const ResourceUnit *ru); ///< initial setup routine. |
468 | werner | 39 | void newYear(); ///< to be executed at the beginning of a simulation year. This cleans up the transfer pools. |
40 | void processYear(); ///< to be called at the end of the year (after tree growth, harvesting). Calculates flow to the soil. |
||
41 | // access |
||
477 | werner | 42 | bool isStateEmpty() const { return mTotalSnagCarbon == 0.; } |
43 | bool isEmpty() const { return mLabileFlux.isEmpty() && mRefractoryFlux.isEmpty() && isStateEmpty(); } |
||
476 | werner | 44 | CNPool fluxToSoil() const { return mLabileFlux + mRefractoryFlux; } |
468 | werner | 45 | // actions |
46 | /// add for a tree with diameter |
||
47 | void addTurnoverLitter(const Tree *tree, const double litter_foliage, const double litter_fineroot); |
||
48 | /// adds the 'tree' to the appropriate Snag pools. |
||
49 | void addMortality(const Tree* tree); |
||
50 | /// add residual biomass of 'tree' after harvesting. |
||
51 | /// remove_(stem, branch, foliage)_pct: percentage of biomass compartment that is removed by the harvest operation. |
||
52 | /// the harvested biomass is collected. |
||
53 | void addHarvest(const Tree* tree, const double remove_stem_pct, const double remove_branch_pct, const double remove_foliage_pct ); |
||
475 | werner | 54 | QList<QVariant> debugList(); ///< return a debug output |
468 | werner | 55 | private: |
490 | werner | 56 | double calculateClimateFactors(); ///< calculate climate factor 're' for the current year |
57 | double mClimateFactor; ///< current mean climate factor (influenced by temperature and soil water content) |
||
58 | const ResourceUnit *mRU; ///< link to resource unit |
||
468 | werner | 59 | /// access SWDPool as function of diameter (cm) |
60 | int poolIndex(const float dbh) { if (dbh<mDBHLower) return 0; if (dbh>mDBHHigher) return 2; return 1;} |
||
61 | CNPool mSWD[3]; ///< standing woody debris pool (0: smallest dimater class, e.g. <10cm, 1: medium, 2: largest class (e.g. >30cm)) kg/ha |
||
62 | double mNumberOfSnags[3]; ///< number of snags in diameter class |
||
63 | double mTimeSinceDeath[3]; ///< time since death: mass-weighted age of the content of the snag pool |
||
64 | CNPool mToSWD[3]; ///< transfer pool; input of the year is collected here (by size class) |
||
65 | CNPool mLabileFlux; ///< flux to labile soil pools (kg/ha) |
||
66 | CNPool mRefractoryFlux; ///< flux to teh refractory soil pool (kg/ha) |
||
67 | CNPool mBranches[5]; ///< pool for branch biomass |
||
68 | int mBranchCounter; ///< index which of the branch pools should be emptied |
||
475 | werner | 69 | double mTotalSnagCarbon; ///< sum of carbon content in all snag compartments (kg/ha) |
476 | werner | 70 | CNPool mTotalIn; ///< total input to the snag state (i.e. mortality/harvest and litter) |
477 | werner | 71 | CNPool mSWDtoSoil; ///< total flux from standing dead wood -> soil (kg/ha) |
476 | werner | 72 | CNPool mTotalToAtm; ///< flux to atmosphere (kg/ha) |
73 | CNPool mTotalToExtern; ///< total flux of masses removed from the site (i.e. harvesting) kg/ha |
||
468 | werner | 74 | static double mDBHLower, mDBHHigher; ///< thresholds used to classify to SWD-Pools |
75 | }; |
||
76 | |||
77 | #endif // SNAG_H |