public static void Initialize(IInputParameters parameters)
        {
            AET       = parameters.AET;
            FolLignin = parameters.FolLignin;

            KNwdLitter = GetKNwdLitter();
        }
Exemple #2
0
        public VarEcoregionSpeciesDate(string label, DateTime[] DateRange)
        {
            values = new VarEcoregionSpecies <VarDate <T> >(label);

            foreach (ISpecies s in PlugIn.modelCore.Species)
            {
                foreach (IEcoregion eco in PlugIn.ModelCore.Ecoregions)
                {
                    values[eco, s] = new VarDate <T>(label, DateRange);
                }
            }
        }
Exemple #3
0
 private static VarEcoregionSpecies <float> GetWiltingPoint(IInputParameters Parameters)
 {
     wiltingpoint_mm = new VarEcoregionSpecies <float>("wiltingpoint_mm");
     foreach (IEcoregion ecoregion in PlugIn.ModelCore.Ecoregions)
     {
         foreach (ISpecies spc in PlugIn.modelCore.Species)
         {
             wiltingpoint_mm[ecoregion, spc] = Parameters.WltPnt[spc] * Parameters.WHC[ecoregion];
         }
     }
     return(wiltingpoint_mm);
 }
        //---------------------------------------------------------------------
        /// <summary>
        /// Adds some biomass for a species to the LITTER pools at a site.
        /// </summary>
        public static VarEcoregionSpecies <double> GetKNwdLitter()
        {
            KNwdLitter = new VarEcoregionSpecies <double>("KNwdLitter");

            foreach (IEcoregion ecoregion in PlugIn.ModelCore.Ecoregions)
            {
                double siteAET = (double)AET[ecoregion];

                foreach (ISpecies spc in PlugIn.modelCore.Species)
                {
                    //Calculation of decomposition rate for species litter cohort
                    // Decay rate from Meentemeyer 1978.  Ecology 59: 465-472.

                    KNwdLitter[ecoregion, spc] = 1.0 / 12.0 * (-0.5365 + (0.00241 * siteAET)) - (((-0.01586 + (0.000056 * siteAET)) * FolLignin[spc] * 100));
                }
            }
            return(KNwdLitter);
        }
Exemple #5
0
        public static void InitializeStatic(IInputParameters Parameters)
        {
            climateFileName = Parameters.climateFileName;

            DateRange = GetDataRange();

            possibleestmonth   = new VarEcoregionSpeciesDate <bool>("PossibleEstmonth", DateRange);
            newsnow            = new VarEcoregionDate <float>("newsnow", DateRange);
            maxmonthlysnowmelt = new VarEcoregionDate <float>("maxmonthlysnowmelt", DateRange);
            precin             = new VarEcoregionDate <float>("precin", DateRange);
            tmax = new VarEcoregionDate <float>("tmax", DateRange);
            tmin = new VarEcoregionDate <float>("tmin", DateRange);
            tday = new VarEcoregionDate <float>("tday", DateRange);
            par0 = new VarEcoregionDate <float>("par0", DateRange);
            tave = new VarEcoregionDate <float>("tave", DateRange);
            prec = new VarEcoregionDate <float>("prec", DateRange);
            vpd  = new VarEcoregionDate <float>("vpd", DateRange);


            ftemppsn     = new VarEcoregionSpeciesDate <float>("dtemppsn", DateRange);
            refresp      = new VarEcoregionSpeciesDate <float>("refresp", DateRange);
            fTempResp    = new VarEcoregionSpeciesDate <float>("dTempResp", DateRange);
            fTempRespDay = new VarEcoregionSpeciesDate <float>("dTempRespDay", DateRange);
            wue_co2_corr = new VarEcoregionSpeciesDate <float>("wue_co2_corr", DateRange);
            dvpd         = new VarEcoregionSpeciesDate <float>("dvpd", DateRange);
            leaf_on      = new VarEcoregionSpeciesDate <bool>("leaf_on", DateRange);
            gdd          = new VarEcoregionSpeciesDate <float>("gdd", DateRange);
            hdd          = new VarEcoregionSpeciesDate <float>("hdd", DateRange);

            refnetpsn = new VarEcoregionSpeciesDate <float>("refnetpsn", DateRange);

            foreach (IEcoregion ecoregion in PlugIn.ModelCore.Ecoregions)
            {
                if (ecoregion.Active == false)
                {
                    continue;
                }

                if (TryCopyVarsFromOtherEcoRegion(ecoregion))
                {
                    PlugIn.ModelCore.UI.WriteLine("   Copied static climate data for ecoregion " + ecoregion);
                    continue;
                }
                PlugIn.ModelCore.UI.WriteLine("   Initializing static climate data for ecoregion " + ecoregion + " from " + Parameters.climateFileName[ecoregion]);

                string[] Content = ReadContent(climateFileName[ecoregion]);

                SetClimateFileHeaders(Content[0]);

                wiltingpoint_mm = GetWiltingPoint(Parameters);

                DateTime date = DateRange[0];
                while (date.CompareTo(DateRange[1]) <= 0)
                {
                    // GetLine checks if year/month according to the loop is equal to the date read in
                    string[] terms = GetLine(date.Year, date.Month, Content).Split((char[])null, System.StringSplitOptions.RemoveEmptyEntries);
                    if (terms.Count() != ColumnCount)
                    {
                        throw new System.Exception("Unexpected number of columns in " + Parameters.climateFileName + " date = " + date);
                    }

                    if (date.Year < GetYearFrom4charOr9charString(terms[0], FirstLastYear.First) ||
                        date.Year > GetYearFrom4charOr9charString(terms[0], FirstLastYear.Last) ||
                        int.Parse(terms[1]) != date.Month)
                    {
                        throw new System.Exception("Missing month " + date + " in climate file");
                    }

                    try
                    {
                        tmax[ecoregion, date] = CheckInputValue(float.Parse(terms[ColumnNumbers.TMax]), -80, 80, "TMax");
                        tmin[ecoregion, date] = CheckInputValue(float.Parse(terms[ColumnNumbers.TMin]), -80, tmax[ecoregion, date], "TMin");
                        float co2 = CheckInputValue(float.Parse(terms[ColumnNumbers.CO2]), 0, float.MaxValue, "CO2");
                        par0[ecoregion, date] = CheckInputValue(float.Parse(terms[ColumnNumbers.PAR0]), 0, float.MaxValue, "PAR0");
                        prec[ecoregion, date] = CheckInputValue(float.Parse(terms[ColumnNumbers.Prec]), 0, float.MaxValue, "PREC");


                        float hr          = Calculate_hr(date.DayOfYear, Parameters.Latitude);
                        float daylength   = Calculate_DayLength(hr);
                        float nightlength = Calculate_NightLength(hr);
                        int   dayspan     = Calculate_DaySpan(date.Month);
                        tave[ecoregion, date] = (float)0.5 * (tmin[ecoregion, date] + tmax[ecoregion, date]);
                        tday[ecoregion, date] = (float)0.5 * (tmax[ecoregion, date] + tave[ecoregion, date]);
                        vpd[ecoregion, date]  = Calculate_VPD(Tday[ecoregion, date], TMin[ecoregion, date]);

                        float snowfraction = CumputeSnowFraction(tave[ecoregion, date]);
                        newsnow[ecoregion, date]            = snowfraction * prec[ecoregion, date];//mm
                        maxmonthlysnowmelt[ecoregion, date] = 0.15f * Math.Max(1, Tave[ecoregion, date]) * dayspan;
                        PrecIn[ecoregion, date]             = (1 - snowfraction) * prec[ecoregion, date];

                        foreach (ISpecies spc in PlugIn.ModelCore.Species)
                        {
                            float dGDD = Math.Max(0, (Tave[ecoregion, date] - Parameters.PsnTMin[spc]) * dayspan);
                            if (date.Month == 1)
                            {
                                gdd[ecoregion, spc, date] = dGDD;
                            }
                            else
                            {
                                DateTime last_month = date.AddMonths(-1);
                                gdd[ecoregion, spc, date] = gdd[ecoregion, spc, last_month] + dGDD;
                            }

                            float dHDD = Math.Max(0, (Parameters.PsnTOpt[spc] - tmin[ecoregion, date]) * dayspan);
                            if (date.Month <= 8)
                            {
                                hdd[ecoregion, spc, date] = 0;
                            }
                            else
                            {
                                DateTime last_month = date.AddMonths(-1);
                                hdd[ecoregion, spc, date] = hdd[ecoregion, spc, last_month] + dHDD;
                            }

                            if (StaticVariables.GDD[ecoregion, spc, date] < Parameters.GDDFolSt[spc] || StaticVariables.HDD[ecoregion, spc, date] > Parameters.CDDFolEnd[spc])
                            {
                                Leaf_On[ecoregion, spc, date] = false;
                            }
                            else //if (StaticVariables.HDD[ecoregion, spc, date] > Parameters.CDDFolEnd[spc] && Leaf_On[ecoregion, spc, date] == true)
                            {
                                Leaf_On[ecoregion, spc, date] = true;
                            }

                            //ftemppsn[date, spc] = ParabolicPsnTempResponse(tday[ecoregion, date], Parameters.PsnTOpt[spc], Parameters.PsnTMin[spc]);
                            ftemppsn[ecoregion, spc, date] = LinearPsnTempResponse(tday[ecoregion, date], Parameters.PsnTOpt[spc], Parameters.PsnTMin[spc]);

                            dvpd[ecoregion, spc, date] = Math.Max(0, 1 - Parameters.DVPD1[spc] * (float)Math.Pow(vpd[ecoregion, date], Parameters.DVPD2[spc]));

                            float cicaRatio = (-0.075f * Parameters.FolN[spc]) + 0.875f;
                            float ci350     = 350 * cicaRatio;
                            float Arel350   = 1.22f * ((ci350 - 68) / (ci350 + 136));

                            float ciElev   = co2 * cicaRatio;
                            float ArelElev = 1.22f * ((ciElev - 68) / (ciElev + 136));
                            float delamax  = 1 + ((ArelElev - Arel350) / Arel350);


                            // CO2 effect on photosynthesis
                            // Calculate CO2 effect on conductance and set slope and intercept for A-gs relationship
                            float Delgs = delamax / ((co2 - co2 * cicaRatio) / (350.0f - ci350));

                            //wue[ecoregion, spc, date] = (Parameters.WUEcnst[spc] / vpd[ecoregion, date]) * (1 + 1 - Delgs);    //DWUE determined from CO2 effects on conductance
                            float wue = (Parameters.WUEcnst[spc] / vpd[ecoregion, date]) * (1 + 1 - Delgs);    //DWUE determined from CO2 effects on conductance
                            wue_co2_corr[ecoregion, spc, date] = wue / delamax;

                            // NETPSN
                            float amax = delamax * (Parameters.AmaxA[spc] + Parameters.AmaxB[spc] * Parameters.FolN[spc]);

                            //Reference net Psn (lab conditions)
                            RefNetPsn[ecoregion, spc, date] = dayspan * (amax * dvpd[ecoregion, spc, date] * daylength * Constants.MC) / Constants.billion;


                            fTempRespDay[ecoregion, spc, date] = ((float)Math.Pow(Parameters.Q10[spc], (Tday[ecoregion, date] - Parameters.PsnTOpt[spc]) / 10));
                            float fTempRespNight = ((float)Math.Pow(Parameters.Q10[spc], (TMin[ecoregion, date] - Parameters.PsnTOpt[spc]) / 10));

                            fTempResp[ecoregion, spc, date] = (float)Math.Min(1.0, (fTempRespDay[ecoregion, spc, date] * daylength + fTempRespNight * nightlength) / ((float)daylength + (float)nightlength));

                            //  gC/day
                            RefResp[ecoregion, spc, date] = Parameters.BFolResp[spc] * dayspan * (amax * daylength * Constants.MC) / Constants.billion;
                        }
                        date = date.AddMonths(1);
                    }
                    catch (System.Exception e)
                    {
                        throw new System.Exception("Error in climate " + date.ToString("MM/yyyy") + " " + e.Message);
                    }
                }
                SetEstablishmentMonths(Parameters, ecoregion);
            }
            PlugIn.ModelCore.UI.WriteLine("Ready initializing static data");
        }