예제 #1
0
 public VarEcoregionSpecies(string label)
 {
     values = new Library.Biomass.Ecoregions.AuxParm <Library.Biomass.Species.AuxParm <T> >(PlugIn.modelCore.Ecoregions);
     //= new VarEcoregion<Library.Biomass.Species.AuxParm<T>>(label);
     this.label = label;
     foreach (IEcoregion eco in PlugIn.ModelCore.Ecoregions)
     {
         values[eco] = new Library.Biomass.Species.AuxParm <T>(PlugIn.modelCore.Species);
     }
 }
        //---------------------------------------------------------------------

        public InputParameters()
        {
            hassiteoutput            = PlugIn.ModelCore.Landscape.NewSiteVar <bool>();
            canopylayerbiomfractions = new List <float[]>();
            canopylayerages          = new List <int>();
            climatefilename          = new Library.Biomass.Ecoregions.AuxParm <string>(PlugIn.modelCore.Ecoregions);
            slwdel               = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            toroot               = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            towood               = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            folret               = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            tofol                = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            gddfolst             = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            mortCurveShapeParm   = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            growthCurveShapeParm = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            slwmax               = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            cddfolend            = new Landis.Library.Biomass.Species.AuxParm <int>(PlugIn.ModelCore.Species);
            wuecnst              = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            q10                    = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            psntmin                = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            halfsat                = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            estradsensitivity      = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            estmoisturesensitivity = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            psntopt                = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            foln                   = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            bfolresp               = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            follignin              = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            kwdlit                 = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            grmstsens              = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            dvpd2                  = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            dvpd1                  = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            amaxa                  = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            amaxb                  = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            psnagered              = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            k                  = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            dnsc               = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            maintresp          = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            wltpnt             = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            rtstratio          = new Landis.Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
            whc                = new Landis.Library.Biomass.Ecoregions.AuxParm <int>(PlugIn.ModelCore.Ecoregions);
            aet                = new Landis.Library.Biomass.Ecoregions.AuxParm <int>(PlugIn.ModelCore.Ecoregions);
            preciplossfrac     = new Landis.Library.Biomass.Ecoregions.AuxParm <float>(PlugIn.ModelCore.Ecoregions);
            porosity           = new Landis.Library.Biomass.Ecoregions.AuxParm <int>(PlugIn.ModelCore.Ecoregions);
            leakagefrac        = new Landis.Library.Biomass.Ecoregions.AuxParm <float>(PlugIn.ModelCore.Ecoregions);
            canopylayernumbers = new List <int>();
        }
 //---------------------------------------------------------------------
 public InputParameters()
 {
     hassiteoutput = PlugIn.ModelCore.Landscape.NewSiteVar<bool>();
     canopylayerbiomfractions = new List<float[]>();
     canopylayerages = new List<int>();
     climatefilename = new Library.Biomass.Ecoregions.AuxParm<string>(PlugIn.modelCore.Ecoregions);
     slwdel = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     toroot = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     towood = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     folret = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     tofol = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     gddfolst = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     mortCurveShapeParm = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     growthCurveShapeParm = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     slwmax = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     cddfolend = new Landis.Library.Biomass.Species.AuxParm<int>(PlugIn.ModelCore.Species);
     wuecnst = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     q10 = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     psntmin = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     halfsat = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     estradsensitivity = new Landis.Library.Biomass.Species.AuxParm<float >(PlugIn.ModelCore.Species);
     estmoisturesensitivity = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     psntopt = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     foln = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     bfolresp = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     follignin = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     kwdlit = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     grmstsens = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     dvpd2 = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     dvpd1 = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     amaxa = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     amaxb = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     psnagered = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     k = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     dnsc = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     maintresp = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     wltpnt = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     rtstratio = new Landis.Library.Biomass.Species.AuxParm<float>(PlugIn.ModelCore.Species);
     whc = new Landis.Library.Biomass.Ecoregions.AuxParm<int>(PlugIn.ModelCore.Ecoregions);
     aet = new Landis.Library.Biomass.Ecoregions.AuxParm<int>(PlugIn.ModelCore.Ecoregions);
     preciplossfrac = new Landis.Library.Biomass.Ecoregions.AuxParm<float>(PlugIn.ModelCore.Ecoregions);
     porosity  = new Landis.Library.Biomass.Ecoregions.AuxParm<int>(PlugIn.ModelCore.Ecoregions);
     leakagefrac = new Landis.Library.Biomass.Ecoregions.AuxParm<float>(PlugIn.ModelCore.Ecoregions);
     canopylayernumbers = new List<int>();
 }
예제 #4
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");
        }