Exemplo n.º 1
0
 public DCAPSTModel(
     ISolarGeometry solar,
     ISolarRadiation radiation,
     ITemperature temperature,
     IPathwayParameters pathway,
     ICanopyAttributes canopy,
     Transpiration trans
     )
 {
     Solar         = solar;
     Radiation     = radiation;
     Temperature   = temperature;
     this.pathway  = pathway;
     Canopy        = canopy;
     transpiration = trans;
 }
 public double GetAnnualAvgTranspiration()
 {
     return(Transpiration.Sum() / ((float)Counts.Sum() / 365.25));
 }
 public List <double> GetMonthlyAvgTranspiration()
 {
     return(Transpiration.Select(x => x / (((double)Counts[Transpiration.IndexOf(x)]) / 365.25 * 12.0)).ToList());
 }
 public double GetTotalTranspiration()
 {
     return(Transpiration.Sum());
 }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="CP"></param>
        /// <param name="PP"></param>
        /// <param name="DOY"></param>
        /// <param name="latitude"></param>
        /// <param name="maxT"></param>
        /// <param name="minT"></param>
        /// <param name="radn"></param>
        /// <param name="rpar"></param>
        /// <returns></returns>
        public static DCAPSTModel SetUpModel(
            ICanopyParameters CP,
            IPathwayParameters PP,
            int DOY,
            double latitude,
            double maxT,
            double minT,
            double radn,
            double rpar)
        {
            // Model the solar geometry
            var SG = new SolarGeometry
            {
                Latitude  = latitude.ToRadians(),
                DayOfYear = DOY
            };

            // Model the solar radiation
            var SR = new SolarRadiation(SG)
            {
                Daily = radn,
                RPAR  = rpar
            };

            // Model the environmental temperature
            var TM = new Temperature(SG)
            {
                MaxTemperature      = maxT,
                MinTemperature      = minT,
                AtmosphericPressure = 1.01325
            };

            // Model the pathways
            var SunlitAc1 = new AssimilationPathway(CP, PP);
            var SunlitAc2 = new AssimilationPathway(CP, PP);
            var SunlitAj  = new AssimilationPathway(CP, PP);

            var ShadedAc1 = new AssimilationPathway(CP, PP);
            var ShadedAc2 = new AssimilationPathway(CP, PP);
            var ShadedAj  = new AssimilationPathway(CP, PP);

            // Model the canopy
            IAssimilation A;

            if (CP.Type == CanopyType.C3)
            {
                A = new AssimilationC3(CP, PP);
            }
            else if (CP.Type == CanopyType.C4)
            {
                A = new AssimilationC4(CP, PP);
            }
            else
            {
                A = new AssimilationCCM(CP, PP);
            }

            var sunlit = new AssimilationArea(SunlitAc1, SunlitAc2, SunlitAj, A);
            var shaded = new AssimilationArea(ShadedAc1, ShadedAc2, ShadedAj, A);
            var CA     = new CanopyAttributes(CP, PP, sunlit, shaded);

            // Model the transpiration
            var WI = new WaterInteraction(TM);
            var TR = new TemperatureResponse(CP, PP);
            var TS = new Transpiration(CP, PP, WI, TR);

            // Model the photosynthesis
            var DM = new DCAPSTModel(SG, SR, TM, PP, CA, TS)
            {
                B = 0.409
            };

            return(DM);
        }
Exemplo n.º 6
0
            /*!
             * Executes the crop sequence calculation.
             *
             * \author  Hunstock
             * \date    06.04.2017
             *
             * \param   start                       The start Date/Time for calculation.
             * \param   end                         The end Date/Time for calculation.
             * \param [in,out]  etArgs              The arguments for evaporation, transpiration and irrigation calculation.
             * \param [in,out]  irrigationAmount    The irrigation amounts. Here can be a modified CropSequenceResult passed.
             * \param   dryRun                      true to dry run and calculate the irrgation demand, false to real irrigate.
             *
             * \return  A CropSequenceResult, the irrigation demand, formatted for use in MIKE-Basin by DHI-WASY.
             */

            public CropSequenceResult runCropSequence(DateTime start, DateTime end, ref ETArgs etArgs, ref CropSequenceResult irrigationAmount, bool dryRun = false)
            {
                //measure calculation duration
                Stopwatch stopWatch = new Stopwatch();

                stopWatch.Start();

                CropSequenceResult localMbResult = new CropSequenceResult();

                if (irrigationAmount == null)
                {
                    irrigationAmount = new CropSequenceResult();
                }

                IList <CropSequenceValues> csPart = getCropSequence(start);

                foreach (CropSequenceValues cs in csPart)
                {
                    String _csIndex = csIndex(cs);

                    ETArgs tmpArgs = MergeArgs(ref etArgs, cs);
                    tmpArgs.start = start;
                    tmpArgs.end   = end;
                    if (tmpArgs.plant == null)
                    {
                        Debug.WriteLine("no plant for cropSequence: " + _csIndex + " skipping sequence " + start.ToString());
                        continue;
                    }

                    ETResult tmpResult = null;
                    if (_results.ContainsKey(_csIndex))
                    {
                        tmpResult = _results[_csIndex];
                    }

                    if (dryRun)
                    {
                        if (tmpResult != null)
                        {
                            tmpResult = new ETResult(tmpResult);
                            tmpResult.autoIrrigation      = 0;
                            tmpResult.autoNetIrrigation   = 0;
                            tmpResult.interceptionAutoIrr = 0;
                        }
                        Transpiration.ETCalc(ref tmpArgs, ref tmpResult, dryRun);
                    }
                    else
                    {
                        if (irrigationAmount.networkIdIrrigationDemand.ContainsKey(_csIndex))
                        {
                            //Debug.WriteLine("found irrigation: " + csIndex + ": " + mbResult.networkIdIrrigationDemand[csIndex].ToString());
                            //FIXME: convert irrigation to schedule and add to tmpArgs
                            DateTime startMin       = new DateTime(Math.Max(tmpArgs.seedDate.Ticks, tmpArgs.start != null ? ((DateTime)tmpArgs.start).Ticks : 0));
                            DateTime endMax         = new DateTime(Math.Min(tmpArgs.harvestDate.Ticks, tmpArgs.end != null ? ((DateTime)tmpArgs.end).Ticks : 0));
                            TimeSpan scheduleLength = endMax.Subtract(startMin);
                            DateTime scheduleMid    = startMin.AddMinutes(scheduleLength.TotalMinutes / 2);
                            if (tmpArgs.irrigationSchedule == null)
                            {
                                if (cs.irrigationType == null)
                                {
                                    tmpArgs.irrigationSchedule = new IrrigationSchedule(cs.autoIrrigation.type);
                                    tmpArgs.autoIrr.type       = cs.autoIrrigation.type;
                                }
                                else
                                {
                                    tmpArgs.irrigationSchedule = new IrrigationSchedule(cs.irrigationType);
                                }
                                tmpArgs.irrigationSchedule.schedule.Add(scheduleMid, irrigationAmount.networkIdIrrigationDemand[_csIndex].irrigationDemand.amount);
                            }
                        }
                        Transpiration.ETCalc(ref tmpArgs, ref tmpResult, dryRun);
                        _results[_csIndex] = tmpResult;
                    }

                    if (localMbResult.networkIdIrrigationDemand.ContainsKey(_csIndex))
                    {
                        localMbResult.networkIdIrrigationDemand[_csIndex].irrigationDemand.surfaceWater.amount += tmpResult.autoNetIrrigation;
                    }
                    else
                    {
                        localMbResult.networkIdIrrigationDemand[_csIndex]                  = new CropSequenceFieldResult();
                        localMbResult.networkIdIrrigationDemand[_csIndex].area             = cs.area;
                        localMbResult.networkIdIrrigationDemand[_csIndex].fieldId          = cs.fieldId;
                        localMbResult.networkIdIrrigationDemand[_csIndex].networkId        = cs.networkId;
                        localMbResult.networkIdIrrigationDemand[_csIndex].waterRights      = cs.waterRights;
                        localMbResult.networkIdIrrigationDemand[_csIndex].irrigationDemand = new IrrigationAmount(surfaceWaterAmount: tmpResult.autoNetIrrigation);
                    }

                    localMbResult.error += tmpResult.error;
                }
                stopWatch.Stop();
                TimeSpan ts = stopWatch.Elapsed;

                // Format and display the TimeSpan value.
                String elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
                                                   ts.Hours, ts.Minutes, ts.Seconds,
                                                   ts.Milliseconds);

                Debug.WriteLine("runCropSequence took " + elapsedTime + " start: " + start.ToString("yyyy-MM-dd") + " end: " + end.ToString("yyyy-MM-dd"));
                localMbResult.runtimeMs = stopWatch.ElapsedMilliseconds;

                return(localMbResult);
            }