/// <summary> /// Remove mineral N and P from surfom with leaching rainfall and; /// pass to Soil N and Soil P modules. /// </summary> /// <param name="leachRain">The leach rain.</param> private void Leach(double leachRain) { double nh4Incorp; double no3Incorp; double po4Incorp; // Apply leaching fraction to all mineral pools and put all mineral NO3,NH4 and PO4 into top layer; double leaching_fr = MathUtilities.Bound(MathUtilities.Divide(leachRain, totalLeachRain, 0.0), 0.0, 1.0); no3Incorp = SurfOM.Sum <SurfOrganicMatterType>(x => x.no3) * leaching_fr; nh4Incorp = SurfOM.Sum <SurfOrganicMatterType>(x => x.nh4) * leaching_fr; po4Incorp = SurfOM.Sum <SurfOrganicMatterType>(x => x.po4) * leaching_fr; // If neccessary, Send the mineral N & P leached to the Soil N&P modules; if (no3Incorp > 0.0 || nh4Incorp > 0.0 || po4Incorp > 0.0) { solutes.AddToLayer(0, "NH4", SoluteManager.SoluteSetterType.Soil, nh4Incorp); solutes.AddToLayer(0, "NO3", SoluteManager.SoluteSetterType.Soil, no3Incorp); } for (int i = 0; i < numSurfom; i++) { SurfOM[i].no3 = SurfOM[i].no3 * (1.0 - leaching_fr); SurfOM[i].nh4 = SurfOM[i].nh4 * (1.0 - leaching_fr); SurfOM[i].po4 = SurfOM[i].po4 * (1.0 - leaching_fr); } }
private void OnDoSoilOrganicMatter(object sender, EventArgs e) { for (int i = 0; i < source.C.Length; i++) { double carbonFlow = rate.Value(i) * source.C[i]; double nitrogenFlow = MathUtilities.Divide(carbonFlow, source.CNRatio[i], 0); double carbonFlowToDestination = carbonFlow * CO2Efficiency.Value(i); double nitrogenFlowToDestination = carbonFlowToDestination / destination.CNRatio[i]; source.C[i] -= carbonFlow; source.N[i] -= nitrogenFlow; destination.C[i] += carbonFlowToDestination; destination.N[i] += nitrogenFlowToDestination; if (nitrogenFlowToDestination <= nitrogenFlow) { solutes.AddToLayer(i, "NH4", nitrogenFlow - nitrogenFlowToDestination); } else { throw new NotImplementedException(); } } }