Esempio n. 1
0
        private void OnIncorpFOMPool(FOMPoolType FOMPoolData)
        {
            if (FOMPoolData.Layer.Length > FOMLignin.C.Length)
            {
                throw new Exception("Incorrect number of soil layers of IncorporatedFOM");
            }

            for (int layer = 0; layer < FOMPoolData.Layer.Length; layer++)
            {
                FOMCarbohydrate.C[layer] += FOMPoolData.Layer[layer].Pool[0].C;
                FOMCarbohydrate.N[layer] += FOMPoolData.Layer[layer].Pool[0].N;

                FOMCellulose.C[layer] += FOMPoolData.Layer[layer].Pool[1].C;
                FOMCellulose.N[layer] += FOMPoolData.Layer[layer].Pool[1].N;

                FOMLignin.C[layer] += FOMPoolData.Layer[layer].Pool[2].C;
                FOMLignin.N[layer] += FOMPoolData.Layer[layer].Pool[2].N;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Calculate surfom incorporation as a result of tillage and update;
        /// residue and N pools.
        /// </summary>
        /// <param name="fIncorp">The f incorp.</param>
        /// <param name="tillageDepth">The tillage depth.</param>
        private void Incorp(double fIncorp, double tillageDepth)
        {
            int    deepestLayer;
            int    nLayers        = soil.Thickness.Length;
            double F_incorp_layer = 0;

            double[] residueIncorpFraction = new double[nLayers];
            double   layerIncorpDepth;

            double[,] CPool      = new double[maxFr, nLayers]; // total C in each Om fraction and layer (from all surfOM"s) incorporated;
            double[,] NPool      = new double[maxFr, nLayers]; // total N in each Om fraction and layer (from all surfOM"s) incorporated;
            double[,] PPool      = new double[maxFr, nLayers]; // total P in each Om fraction and layer (from all surfOM"s) incorporated;
            double[,] AshAlkPool = new double[maxFr, nLayers]; // total AshAlk in each Om fraction and layer (from all surfOM"s) incorporated;
            double[]    no3          = new double[nLayers];    // total no3 to go into each soil layer (from all surfOM"s)
            double[]    nh4          = new double[nLayers];    // total nh4 to go into each soil layer (from all surfOM"s)
            double[]    po4          = new double[nLayers];    // total po4 to go into each soil layer (from all surfOM"s)
            FOMPoolType FPoolProfile = new FOMPoolType();

            fIncorp = MathUtilities.Bound(fIncorp, 0.0, 1.0);

            deepestLayer = Soil.LayerIndexOfDepth(tillageDepth, soil.Thickness);

            double cumDepth = 0.0;

            for (int layer = 0; layer <= deepestLayer; layer++)
            {
                for (int residue = 0; residue < numSurfom; residue++)
                {
                    double depthToGo = tillageDepth - cumDepth;
                    layerIncorpDepth = Math.Min(depthToGo, soil.Thickness[layer]);
                    F_incorp_layer   = MathUtilities.Divide(layerIncorpDepth, tillageDepth, 0.0);
                    for (int i = 0; i < maxFr; i++)
                    {
                        CPool[i, layer] += (SurfOM[residue].Lying[i].C + SurfOM[residue].Standing[i].C) * fIncorp * F_incorp_layer;
                        NPool[i, layer] += (SurfOM[residue].Lying[i].N + SurfOM[residue].Standing[i].N) * fIncorp * F_incorp_layer;
                        PPool[i, layer] += (SurfOM[residue].Lying[i].P + SurfOM[residue].Standing[i].P) * fIncorp * F_incorp_layer;
                    }
                    no3[layer] += SurfOM[residue].no3 * fIncorp * F_incorp_layer;
                    nh4[layer] += SurfOM[residue].nh4 * fIncorp * F_incorp_layer;
                    po4[layer] += SurfOM[residue].po4 * fIncorp * F_incorp_layer;
                }
                cumDepth = cumDepth + soil.Thickness[layer];
                residueIncorpFraction[layer] = F_incorp_layer;
            }

            FPoolProfile.Layer = new FOMPoolLayerType[deepestLayer + 1];

            for (int layer = 0; layer <= deepestLayer; layer++)
            {
                FPoolProfile.Layer[layer] = new FOMPoolLayerType()
                {
                    thickness = soil.Thickness[layer],
                    no3       = no3[layer],
                    nh4       = nh4[layer],
                    po4       = po4[layer],
                    Pool      = new FOMType[maxFr]
                };

                for (int i = 0; i < maxFr; i++)
                {
                    FPoolProfile.Layer[layer].Pool[i] = new FOMType()
                    {
                        C      = CPool[i, layer],
                        N      = NPool[i, layer],
                        P      = PPool[i, layer],
                        AshAlk = AshAlkPool[i, layer]
                    }
                }
                ;
            }
            if (IncorpFOMPool != null)
            {
                IncorpFOMPool.Invoke(FPoolProfile);
            }

            for (int pool = 0; pool < maxFr; pool++)
            {
                for (int i = 0; i < SurfOM.Count; i++)
                {
                    SurfOM[i].Lying[pool].amount    = SurfOM[i].Lying[pool].amount * (1.0 - fIncorp);
                    SurfOM[i].Standing[pool].amount = SurfOM[i].Standing[pool].amount * (1.0 - fIncorp);

                    SurfOM[i].Lying[pool].C    = SurfOM[i].Lying[pool].C * (1.0 - fIncorp);
                    SurfOM[i].Standing[pool].C = SurfOM[i].Standing[pool].C * (1.0 - fIncorp);

                    SurfOM[i].Lying[pool].N    = SurfOM[i].Lying[pool].N * (1.0 - fIncorp);
                    SurfOM[i].Standing[pool].N = SurfOM[i].Standing[pool].N * (1.0 - fIncorp);

                    SurfOM[i].Lying[pool].P    = SurfOM[i].Lying[pool].P * (1.0 - fIncorp);
                    SurfOM[i].Standing[pool].P = SurfOM[i].Standing[pool].P * (1.0 - fIncorp);
                }
            }

            for (int i = 0; i < SurfOM.Count; i++)
            {
                SurfOM[i].no3 *= (1.0 - fIncorp);
                SurfOM[i].nh4 *= (1.0 - fIncorp);
                SurfOM[i].po4 *= (1.0 - fIncorp);
            }
        }