예제 #1
0
파일: CFlow.cs 프로젝트: oseledets/ApsimX
 private void OnSimulationCommencing(object sender, EventArgs e)
 {
     foreach (string destinationName in destinationNames)
     {
         NutrientPool destination = Apsim.Find(this, destinationName) as NutrientPool;
         if (destination == null)
         {
             throw new Exception("Cannot find destination pool with name: " + destinationName);
         }
         destinations.Add(destination);
     }
 }
예제 #2
0
파일: CFlow.cs 프로젝트: cla473/ApsimX
        private void OnSimulationCommencing(object sender, EventArgs e)
        {
            source = Apsim.Find(this, sourceName) as NutrientPool;
            if (source == null)
            {
                throw new Exception("Cannot find source pool with name: " + sourceName);
            }

            destination = Apsim.Find(this, destinationName) as NutrientPool;
            if (destination == null)
            {
                throw new Exception("Cannot find destination pool with name: " + destinationName);
            }
        }
예제 #3
0
파일: CFlow.cs 프로젝트: oseledets/ApsimX
        private void OnDoSoilOrganicMatter(object sender, EventArgs e)
        {
            NutrientPool source = Parent as NutrientPool;

            double[] NH4 = solutes.GetSolute("NH4");
            double[] NO3 = solutes.GetSolute("NO3");

            for (int i = 0; i < source.C.Length; i++)
            {
                double carbonFlowFromSource   = Rate.Value(i) * source.C[i];
                double nitrogenFlowFromSource = MathUtilities.Divide(carbonFlowFromSource, source.CNRatio[i], 0);

                double[] carbonFlowToDestination   = new double[destinations.Count];
                double[] nitrogenFlowToDestination = new double[destinations.Count];

                for (int j = 0; j < destinations.Count; j++)
                {
                    carbonFlowToDestination[j]   = carbonFlowFromSource * CO2Efficiency.Value(i) * destinationFraction[j];
                    nitrogenFlowToDestination[j] = MathUtilities.Divide(carbonFlowToDestination[j], destinations[j].CNRatio[i], 0.0);
                }

                double TotalNitrogenFlowToDestinations = MathUtilities.Sum(nitrogenFlowToDestination);
                double NSupply = nitrogenFlowFromSource + NO3[i] + NH4[i];

                if (MathUtilities.Sum(nitrogenFlowToDestination) > NSupply)
                {
                    double NSupplyFactor = MathUtilities.Bound(MathUtilities.Divide(NO3[i] + NH4[i], TotalNitrogenFlowToDestinations - nitrogenFlowFromSource, 1.0), 0.0, 1.0);

                    for (int j = 0; j < destinations.Count; j++)
                    {
                        carbonFlowToDestination[j]   *= NSupplyFactor;
                        nitrogenFlowToDestination[j] *= NSupplyFactor;
                        if (nitrogenFlowToDestination[j] > 0.5)
                        {
                        }
                    }
                    TotalNitrogenFlowToDestinations *= NSupplyFactor;

                    carbonFlowFromSource   *= NSupplyFactor;
                    nitrogenFlowFromSource *= NSupplyFactor;
                }

                source.C[i] -= carbonFlowFromSource;
                source.N[i] -= nitrogenFlowFromSource;
                for (int j = 0; j < destinations.Count; j++)
                {
                    destinations[j].C[i] += carbonFlowToDestination[j];
                    destinations[j].N[i] += nitrogenFlowToDestination[j];
                }


                if (TotalNitrogenFlowToDestinations <= nitrogenFlowFromSource)
                {
                    NH4[i] += nitrogenFlowFromSource - TotalNitrogenFlowToDestinations;
                }
                else
                {
                    double NDeficit          = TotalNitrogenFlowToDestinations - nitrogenFlowFromSource;
                    double NH4Immobilisation = Math.Min(NH4[i], NDeficit);
                    NH4[i]   -= NH4Immobilisation;
                    NDeficit -= NH4Immobilisation;

                    double NO3Immobilisation = Math.Min(NO3[i], NDeficit);
                    NO3[i]   -= NO3Immobilisation;
                    NDeficit -= NO3Immobilisation;

                    if (MathUtilities.IsGreaterThan(NDeficit, 0.0))
                    {
                        throw new Exception("Insufficient mineral N for immobilisation demand for C flow " + Name);
                    }
                }
            }
            solutes.SetSolute("NH4", NH4);
            solutes.SetSolute("NO3", NO3);
        }