Пример #1
0
    public void TestMethod1()
    {
      Model M = new Model();
      M.Name = "Cook";

      WaterPacket HyporhericWater = new WaterPacket(1);
      HyporhericWater.AddChemical(ChemicalFactory.Instance.GetChemical(ChemicalNames.Radon), 0.6 / HyporhericWater.Volume);

      for (int i = 0; i < 10; i++)
      {
        Lake s1 = new Lake("s" + i, XYPolygon.GetSquare(50 * 2));
        s1.Depth = 0.3;
        StagnantExchangeBoundary seb = new StagnantExchangeBoundary(s1.Volume / 20000);
        seb.WaterSample = HyporhericWater.DeepClone(s1.Area * 0.2 * 0.4);
        seb.Output.LogAllChemicals = true;
        s1.Output.LogAllChemicals = true;
        s1.Sinks.Add(seb);
        s1.Sources.Add(seb);
        if (i > 0)
          M._waterBodies[i - 1].AddDownStreamWaterBody(s1);

        M._waterBodies.Add(s1);
      }

      //Bromide injection
      TimespanSeries ts = new TimespanSeries();
      ts.AddSiValue(DateTime.MinValue, new DateTime(2005, 10, 18, 12, 0, 0), 0);
      ts.AddSiValue(new DateTime(2005, 10, 18, 12, 0, 0), new DateTime(2005, 10, 18, 12, 40, 0), 0.001 * 60);
      ts.AddSiValue(new DateTime(2005, 10, 18, 12, 40, 0), DateTime.MaxValue, 0);
      SinkSourceBoundary Bromide = new SinkSourceBoundary(ts);
      WaterPacket P = new WaterPacket(1);
      P.AddChemical(new Chemical("Bromide", 1), 1.13);
      Bromide.WaterSample = P;

      //SF6 injection
      TimespanSeries ts2 = new TimespanSeries();
      ts2.AddSiValue(DateTime.MinValue, new DateTime(2005, 10, 15, 12, 0, 0), 0);
      ts2.AddSiValue(new DateTime(2005, 10, 15, 12, 0, 0), new DateTime(2005, 10, 19, 12, 0, 0), 1e-6);
      ts2.AddSiValue(new DateTime(2005, 10, 19, 12, 0, 0), DateTime.MaxValue, 0);
      SinkSourceBoundary SF6 = new SinkSourceBoundary(ts2);
      WaterPacket SF6w = new WaterPacket(1);
      SF6w.AddChemical(new Chemical("SF6", 1), 1.13);
      SF6.WaterSample = SF6w;

      M._waterBodies.First().Sources.Add(Bromide);
      M._waterBodies.First().Sources.Add(SF6);
      M._waterBodies.First().Sources.Add(new SinkSourceBoundary(0.2));

      DateTime Start = new DateTime(2005, 10, 13);
      DateTime End = new DateTime(2005, 10, 19);

      M.SetState("Initial", Start, new WaterPacket(1));

      M.MoveInTime(new DateTime(2005, 10, 18, 12, 0, 0), TimeSpan.FromHours(2));
      M.MoveInTime(new DateTime(2005, 10, 18, 13, 0, 0), TimeSpan.FromHours(0.02));
      M.MoveInTime(End, TimeSpan.FromHours(2));
      M.Save(@"..\..\..\TestData\CookEtAl.xml");

      M.RestoreState("Initial");
      TimespanSeries ts3 = new TimespanSeries();
      ts3.AddSiValue(DateTime.MinValue, new DateTime(2005, 10, 16, 12, 0, 0), 0);
      ts3.AddSiValue(new DateTime(2005, 10, 16, 12, 0, 0), new DateTime(2005, 10, 17, 0, 0, 0), 0.4);
      ts3.AddSiValue(new DateTime(2005, 10, 17, 0, 0, 0), DateTime.MaxValue, 0);
      M._waterBodies.First().Sources.Add(new SinkSourceBoundary(ts3));
      M.MoveInTime(new DateTime(2005, 10, 18, 12, 0, 0), TimeSpan.FromHours(2));
      M.MoveInTime(new DateTime(2005, 10, 18, 13, 0, 0), TimeSpan.FromHours(0.02));
      M.MoveInTime(End, TimeSpan.FromHours(2));
      M.Save(@"..\..\..\TestData\CookEtAl2.xml");
    }
        public void Example()
        {
            //The code below demonstrates different ways of using the TimespanSeries class

            // -- Constructing the class (default constructor)--
            TimespanSeries ts = new TimespanSeries();

            // -- Constructing the class (overloaded  constructor) --
            //The timespanSeries below is given the name "My Timeseries, starts at January 1st, 2010 at 00:00:00, has
            //10 time timesteps with length 2 days and value 3
            ts = new TimespanSeries("My Timeseries", new DateTime(2010, 1, 1, 0, 0, 0), 10,  2, TimestepUnit.Days, 3);

            // -- Getting and setting values and time from the timeseries --
            // Direct access:
            double secondValue = ts.Items[1].Value; //The value in the unit as defined by the timeseries
            double secondValueInSI = ts.Unit.ToSiUnit(ts.Items[1].Value); // The value in SI unit
          
            DateTime startTimeforSecondTimestep = ts.Items[1].StartTime;
            DateTime endTimeforSecondTimestep = ts.Items[1].EndTime;
            
            ts.Items[1].Value = 4.5;  // when 4.5 is in the same unit at used by the timeseries
            ts.Items[1].Value = ts.Unit.FromSiToThisUnit(4.5); // when 4.5 is in SI units
            ts.Items[1].Value = ts.Unit.FromUnitToThisUnit(4.5, new Unit("cm/sec", 0.01, 0)); // when 4.5 is in cm pr second

            ts.Items[1].StartTime = new DateTime(2010, 1, 1, 0, 0, 0); //changing the starttime for the second timestep
            //TODO: see if it is possible to check that end time is later than start time.

            // -- Getting values for a given time --
            double x = ts.GetValue(new DateTime(2010, 1, 1, 12, 0, 0));  
            double xINSi = ts.GetSiValue(new DateTime(2010, 1, 1, 12, 0, 0));
            double xInMyUnit = ts.GetValue(new DateTime(2010, 1, 1, 12, 0, 0), new Unit("CM/SEC", 0.01, 0));
           
            // -- Getting values for a give timespan (period) --
            double y = ts.GetValue(new DateTime(2010, 1, 1, 0, 0, 0), new DateTime(2010, 1, 2, 0, 0, 0));
            double yInSi = ts.GetSiValue(new DateTime(2010, 1, 1, 0, 0, 0), new DateTime(2010, 1, 2, 0, 0, 0));
            double yInMyUnit = ts.GetValue(new DateTime(2010, 1, 1, 12, 0, 0), new DateTime(2010,1,2,0,0,0), new Unit("CM/SEC", 0.01, 0));

            // -- Adding values --
            ts.AddValue(new DateTime(2010, 1, 1, 12, 0, 0), new DateTime(2010, 1, 2, 0, 0, 0), 4.5);
            ts.AddSiValue(new DateTime(2010, 1, 1, 12, 0, 0), new DateTime(2010, 1, 2, 0, 0, 0), 4.5);
            
            // -- Append value --
            ts.AppendValue(4.5);  //Appending using the same timestep length as the last time step

            // -- Removing values --
            ts.RemoveAfter(new DateTime(2010, 1, 1, 12, 0, 0));
        }
Пример #3
0
    public static void AddMonthlyValues(TimespanSeries TS, int year, double[] values)
    {
      double conversion1 = 1.0 / 1000 / 86400 / 31;
      double conversion2 = 1.0 / 1000 / 86400 / 28;
      double conversion3 = 1.0 / 1000 / 86400 / 30;
      TS.AddSiValue(new DateTime(year, 1, 1),new DateTime(year, 2, 1), values[0] * conversion1);
      TS.AddSiValue(new DateTime(year, 2, 1), new DateTime(year, 3, 1), values[1] * conversion2);
      TS.AddSiValue(new DateTime(year, 3, 1), new DateTime(year, 4, 1), values[2] * conversion1);
      TS.AddSiValue(new DateTime(year, 4, 1), new DateTime(year, 5, 1), values[3] * conversion3);
      TS.AddSiValue(new DateTime(year, 5, 1), new DateTime(year, 6, 1), values[4] * conversion1);
      TS.AddSiValue(new DateTime(year, 6, 1), new DateTime(year, 7, 1), values[5] * conversion3);
      TS.AddSiValue(new DateTime(year, 7, 1), new DateTime(year, 8, 1), values[6] * conversion1);
      TS.AddSiValue(new DateTime(year, 8, 1), new DateTime(year, 9, 1), values[7] * conversion3);
      TS.AddSiValue(new DateTime(year, 9, 1), new DateTime(year, 10, 1), values[8] * conversion1);
      TS.AddSiValue(new DateTime(year, 10, 1), new DateTime(year,11, 1), values[9] * conversion3);
      TS.AddSiValue(new DateTime(year, 11, 1), new DateTime(year, 12, 1), values[10] * conversion1);
      TS.AddSiValue(new DateTime(year, 12, 1), new DateTime(year + 1, 1, 1), values[11] * conversion3);

    }
Пример #4
0
    public void TestMethod1()
    {
      Lake Gjeller = LakeFactory.GetLake("Gjeller Sø");
      Gjeller.Depth = 1.2;
      Gjeller.WaterLevel = 0.4;

      WaterPacket GjellerWater = new WaterPacket(1, 1);
      GjellerWater.AddChemical(ChemicalFactory.Instance.GetChemical(ChemicalNames.Cl), 1);

      TimeSeriesGroup climate = TimeSeriesGroupFactory.Create("climate.xts");

      foreach (var I in climate.Items)
      {
        I.ExtrapolationMethod = ExtrapolationMethods.RecycleYear;
        I.AllowExtrapolation = true;
      }

      EvaporationRateBoundary evap = new EvaporationRateBoundary((TimespanSeries)climate.Items[1]);
      evap.ContactGeometry = Gjeller.Geometry;
      Gjeller.EvaporationBoundaries.Add(evap);

      SinkSourceBoundary precip = new SinkSourceBoundary(climate.Items[0]);
      precip.ContactGeometry = Gjeller.Geometry;
      Gjeller.Precipitation.Add(precip);
      precip.ID = 2;
      precip.WaterSample = GjellerWater.DeepClone();
      precip.WaterSample.IDForComposition = precip.ID; ;

      GroundWaterBoundary GWIN = new GroundWaterBoundary(Gjeller, 1e-5, 2, 0.45, XYPolygon.GetSquare(Gjeller.Area / 2));
      GWIN.WaterSample = GjellerWater.DeepClone();
      GWIN.ID = 3;
      GWIN.WaterSample.IDForComposition = GWIN.ID;
      GWIN.Name = "Inflow";
      Gjeller.GroundwaterBoundaries.Add(GWIN);

      GroundWaterBoundary GWout = new GroundWaterBoundary(Gjeller, 1e-5, 2, 0.35, XYPolygon.GetSquare(Gjeller.Area / 2));
      GWout.Name = "Outflow";
      Gjeller.GroundwaterBoundaries.Add(GWout);


      TimespanSeries pumping = new TimespanSeries();
      pumping.AddSiValue(new DateTime(1990, 01, 01), new DateTime(2010, 01, 01), 0);
      pumping.AddSiValue(new DateTime(2010, 01, 01), new DateTime(2010, 05, 01), 0.05);
      pumping.AddSiValue(new DateTime(2010, 05, 01), DateTime.Now, 0);


      SinkSourceBoundary DrainageWater = new SinkSourceBoundary(pumping);
      DrainageWater.ID = 4;
      DrainageWater.WaterSample = GjellerWater.DeepClone();
      DrainageWater.WaterSample.IDForComposition = DrainageWater.ID;
      DrainageWater.Name = "Indpumpet Drænvand";
      Gjeller.Sources.Add(DrainageWater);


      var tsg = TimeSeriesGroupFactory.Create(@"..\..\..\TestData\GjellerObservations.xts");

      foreach (var ts in tsg.Items)
      {
        Chemical c = new Chemical(ts.Name, 1);
        Gjeller.RealData.AddChemicalTimeSeries(c);
        Gjeller.RealData.ChemicalConcentrations[c] = (TimestampSeries) ts;


      }

      Model M = new Model();
      M._waterBodies.Add(Gjeller);
      Gjeller.Output.LogAllChemicals = true;
      Gjeller.Output.LogComposition = true;

      M.SetState("Initial", new DateTime(1995, 1, 1), GjellerWater);


      M.MoveInTime(DateTime.Now, TimeSpan.FromDays(10));
      M.Save(@"..\..\..\TestData\Gjeller.xml");

    }