Beispiel #1
0
        /// <summary>
        /// Returns the reduction in kg/s
        /// </summary>
        /// <param name="c"></param>
        /// <param name="CurrentMass"></param>
        /// <param name="CurrentTime"></param>
        /// <returns></returns>
        public double GetReduction(Catchment c, double CurrentMass, DateTime CurrentTime)
        {
            double red = 0;

            if (c.BigLake != null && c.BigLake.Start <= CurrentTime && c.BigLake.End >= CurrentTime)
            {
                double Reducer;
                if (c.BigLake.RetentionTime > 1)
                {
                    Reducer = (Par1 * MO5[CurrentTime.Month] - c.Temperature.GetValue(CurrentTime, InterpolationMethods.DeleteValue)) / 100.0;
                }
                else
                {
                    //Get the lake temperature
                    double T = LakeTemperatureFromAir(c.Temperature.GetValue(CurrentTime, InterpolationMethods.DeleteValue), c.Temperature.GetValue(CurrentTime.AddMonths(-1), InterpolationMethods.DeleteValue), CurrentTime);
                    c.BigLake.Temperature.Items.Add(new TimeStampValue(CurrentTime, T));

                    Reducer = Alpha * Math.Pow(Beta, T - 20.0);
                }

                c.BigLake.CurrentNMass += CurrentMass;
                double removedN = Reducer * c.BigLake.CurrentNMass;
                //From m3/s to m3
                double mflow = c.M11Flow.GetTs(TimeStepUnit.Month).GetValue(CurrentTime) * DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400;

                if (mflow > 0)
                {
                    double NOut = (c.BigLake.CurrentNMass - removedN) / (c.BigLake.Volume + mflow) * mflow;
                    //        NOut = Math.Max(0,Math.Min(c.BigLake.CurrentNMass - removedN, NOut));

                    c.BigLake.CurrentNMass = c.BigLake.CurrentNMass - removedN - NOut;

                    //Store some results
                    c.BigLake.NitrateReduction.Items.Add(new TimeStampValue(CurrentTime, removedN));
                    c.BigLake.NitrateConcentration.Items.Add(new TimeStampValue(CurrentTime, c.BigLake.CurrentNMass / c.BigLake.Volume));
                    c.BigLake.FlushingRatio.Items.Add(new TimeStampValue(CurrentTime, mflow / c.BigLake.Volume));

                    red = (CurrentMass - NOut) / (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0);
                }
            }
            red = red * MultiplicationPar + AdditionPar;

            if (MultiplicationFactors != null)
            {
                if (MultiplicationFactors.ContainsKey(c.ID))
                {
                    red *= MultiplicationFactors[c.ID];
                }
            }

            if (AdditionFactors != null)
            {
                if (AdditionFactors.ContainsKey(c.ID))
                {
                    red += AdditionFactors[c.ID];
                }
            }

            return(red);
        }
    public double GetReduction(Catchment c, double CurrentMass, DateTime CurrentTime)
    {
      double red = 0;
      double rate;
      if (Reduction.TryGetValue(c.ID, out rate) & c.M11Flow != null)
      {
        double NormalizedMonthlyFlow = 0;
        double yearlyinflow = c.NetInflow.GetTs(TimeStepUnit.Year).GetValue(CurrentTime, InterpolationMethods.DeleteValue);
        double monthlyflow=c.NetInflow.GetTs(TimeStepUnit.Month).GetValue(CurrentTime, InterpolationMethods.DeleteValue);
        if (yearlyinflow>0 & monthlyflow>0)
          NormalizedMonthlyFlow =  monthlyflow/yearlyinflow;
        red = Math.Min(rate * NormalizedMonthlyFlow * YearFactors[CurrentTime.Year], CurrentMass) / (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0);
        red = Math.Max(0, red);

      }
      red = red * MultiplicationPar + AdditionPar;

      if (MultiplicationFactors != null)
        if (MultiplicationFactors.ContainsKey(c.ID))
          red *= MultiplicationFactors[c.ID];

      if (AdditionFactors != null)
        if (AdditionFactors.ContainsKey(c.ID))
          red += AdditionFactors[c.ID];

      return red;
    }
        /// <summary>
        /// Returns the source rate to the catchment in kg/s at the current time
        /// </summary>
        /// <param name="c"></param>
        /// <param name="CurrentTime"></param>
        /// <returns></returns>
        public double GetValue(Catchment c, DateTime CurrentTime)
        {
            double value = 0;

            if (GWInput.ContainsKey(c.ID))
            {
                value = GWInput[c.ID][(CurrentTime.Year - Start.Year) * 12 + CurrentTime.Month - Start.Month];
            }

            value = value * MultiplicationPar + AdditionPar;

            if (MultiplicationFactors != null)
            {
                if (MultiplicationFactors.ContainsKey(c.ID))
                {
                    value *= MultiplicationFactors[c.ID];
                }
            }

            if (AdditionFactors != null)
            {
                if (AdditionFactors.ContainsKey(c.ID))
                {
                    value += AdditionFactors[c.ID];
                }
            }

            return(value);
        }
Beispiel #4
0
        public double GetReduction(Catchment c, double CurrentInflowRate, DateTime CurrentTime)
        {
            double red = 0;

            CurrentInflowRate /= DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0;
            if (CurrentTime.Month >= FirstSummerMonth & CurrentTime.Month <= LastSummerMonth)
            {
                red = ReductionFactors[c.ID].Item1 * CurrentInflowRate; //Summer
            }
            else
            {
                red = ReductionFactors[c.ID].Item2 * CurrentInflowRate; //Winter
            }
            red = red * MultiplicationPar + AdditionPar;

            if (MultiplicationFactors != null)
            {
                if (MultiplicationFactors.ContainsKey(c.ID))
                {
                    red *= MultiplicationFactors[c.ID];
                }
            }

            if (AdditionFactors != null)
            {
                if (AdditionFactors.ContainsKey(c.ID))
                {
                    red += AdditionFactors[c.ID];
                }
            }

            return(red);
        }
Beispiel #5
0
        private void AddToUpStream1(Catchment c)
        {
            var row = ReductionVariables.Rows.Find(new object[] { c.ID });

            double UpstreamInput = 0;

            foreach (var opc in c.UpstreamConnections)
            {
                AddToUpStream1(opc);
                UpstreamInput += (double)ReductionVariables.Rows.Find(new object[] { opc.ID })["DownStreamOutput"];
            }

            double GWSource            = (double)row["GWSources"];
            double GWReduction         = (double)row["GWReductions"];
            double source              = (double)row["Sources"];
            double ConceptualReduction = (double)row["ConcepReductions"];
            double internalred         = (double)row["Internalreductions"];
            double mainred             = (double)row["MainReductions"];


            row["DownStreamOutput"] = source + GWSource - mainred - internalred - ConceptualReduction - GWReduction + UpstreamInput;
            row["UpstreamInput"]    = UpstreamInput;

            row["MainDischarge"] = 1.0 - mainred / (source + GWSource - internalred - ConceptualReduction - GWReduction + UpstreamInput);
        }
    public double GetReduction(Catchment c, double CurrentMass, DateTime CurrentTime)
    {
      double sourcevalue;
      if(string.IsNullOrEmpty(SourceModelName))
        sourcevalue = CurrentMass;
      else
      {
        sourcevalue = (double)c.StateVariables.Rows.Find(new object[] { c.ID, CurrentTime })[SourceModelName];
      }
      sourcevalue /= (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0);

      double red = 0;
      if (Reduction.ContainsKey(c.ID))
        red = (Reduction[c.ID] * sourcevalue);

      red = red * MultiplicationPar + AdditionPar;

      if (MultiplicationFactors != null)
        if (MultiplicationFactors.ContainsKey(c.ID))
          red *= MultiplicationFactors[c.ID];

      if (AdditionFactors != null)
        if (AdditionFactors.ContainsKey(c.ID))
          red += AdditionFactors[c.ID];

      return red;
    }
Beispiel #7
0
        private double AccumulateUpstream(string Column, Catchment c, DateTime Time, bool WithBias)
        {
            double Value    = 0;
            var    staterow = StateVariables.Rows.Find(new object[] { c.ID, Time });

            if (!staterow.IsNull(Column))
            {
                double BiasFactor = 1;

                if (WithBias)
                {
                    var row = GetReductionRow(c.ID);
                    if (!row.IsNull("BiasFactor"))
                    {
                        BiasFactor = (double)row["BiasFactor"];
                    }
                }
                Value += (double)staterow[Column] * BiasFactor;
            }
            foreach (var upc in c.UpstreamConnections)
            {
                Value += AccumulateUpstream(Column, upc, Time, WithBias);
            }
            return(Value);
        }
Beispiel #8
0
        /// <summary>
        /// Gets the value in kg/s
        /// </summary>
        /// <param name="c"></param>
        /// <param name="CurrentTime"></param>
        /// <returns></returns>
        public double GetValue(Catchment c, DateTime CurrentTime)
        {
            double        value = 0;
            List <double> data;

            if (deposition.TryGetValue(c.ID, out data))
            {
                value = Math.Max(0, data[CurrentTime.Year - FirstYear] * (c.NetInflow.GetTs(TimeStepUnit.Month).GetValue(CurrentTime)));
            }
            value = value * MultiplicationPar + AdditionPar;

            if (MultiplicationFactors != null)
            {
                if (MultiplicationFactors.ContainsKey(c.ID))
                {
                    value *= MultiplicationFactors[c.ID];
                }
            }

            if (AdditionFactors != null)
            {
                if (AdditionFactors.ContainsKey(c.ID))
                {
                    value += AdditionFactors[c.ID];
                }
            }

            return(value);
        }
    /// <summary>
    /// Loads the catchments and connects them
    /// First data column must be ID
    /// Second column must be ID of downstream catchment
    /// </summary>
    /// <param name="ShapeFileName"></param>
    public void LoadCatchments(string ShapeFileName)
    {
      using (ShapeReader sr = new ShapeReader(ShapeFileName))
      {
        if (AllCatchments == null)
          AllCatchments = new Dictionary<int, Catchment>();

        var data = sr.GeoData.ToList();
        foreach (var c in data)
        {
          Catchment ca = new Catchment((int)c.Data[0]);
          if (!AllCatchments.ContainsKey(ca.ID))
            AllCatchments.Add(ca.ID, ca);

          ca.Geometry = (IXYPolygon)c.Geometry;
        }

        //now loop again to do the connections
        foreach (var c in data)
        {
          int catcid = ((int)c.Data[0]);
          int downid = ((int)c.Data[1]);
          Catchment DownStreamCatchment;
          if (AllCatchments.TryGetValue(downid, out DownStreamCatchment))
          {
            if (DownStreamCatchment != AllCatchments[catcid]) //Do not allow reference to self
            {
              AllCatchments[catcid].DownstreamConnection = DownStreamCatchment;
              DownStreamCatchment.UpstreamConnections.Add(AllCatchments[catcid]);
            }
          }
        }
      }
    }
Beispiel #10
0
        /// <summary>
        /// Returns the source rate to the catchment in kg/s at the current time
        /// </summary>
        /// <param name="c"></param>
        /// <param name="CurrentTime"></param>
        /// <returns></returns>
        public double GetValue(Catchment c, DateTime CurrentTime)
        {
            double value = 0;
            Dictionary <int, double> timevalues;

            if (YearlyData.TryGetValue(c.ID, out timevalues))
            {
                timevalues.TryGetValue(CurrentTime.Year, out value);
            }
            value = value * MultiplicationPar + AdditionPar;

            if (MultiplicationFactors != null)
            {
                if (MultiplicationFactors.ContainsKey(c.ID))
                {
                    value *= MultiplicationFactors[c.ID];
                }
            }

            if (AdditionFactors != null)
            {
                if (AdditionFactors.ContainsKey(c.ID))
                {
                    value += AdditionFactors[c.ID];
                }
            }

            return(value);
        }
Beispiel #11
0
 private void GetCatchmentsWithObs(Catchment c, List <Catchment> Upstreams)
 {
     foreach (var upc in c.UpstreamConnections)
     {
         GetCatchmentsWithObs(upc, Upstreams);
     }
     if (c.Measurements != null)
     {
         Upstreams.Add(c);
     }
 }
Beispiel #12
0
        private void AddToUpStream(double d, Catchment c)
        {
            var    row         = GetReductionRow(c.ID);
            double accumulated = (double)row["MainDischarge"] * d;

            row["AccDischarge"] = accumulated;
            foreach (var opc in c.UpstreamConnections)
            {
                AddToUpStream(accumulated, opc);
            }
        }
    /// <summary>
    /// Returns all catchments upstream the catchment c. Also adds c to the list
    /// </summary>
    /// <param name="c"></param>
    /// <returns></returns>
    public List<Catchment> GetUpstreamCatchments(Catchment c)
    {

      List<Catchment> ToReturn = new List<Catchment>();
      ToReturn.Add(c);
      foreach (var item in c.UpstreamConnections)
      {
        ToReturn.AddRange(GetUpstreamCatchments(item));
      }
      return ToReturn;
    }
 /// <summary>
 /// Returns the leaching from the catchment in kg/s at the current time
 /// </summary>
 /// <param name="c"></param>
 /// <param name="CurrentTime"></param>
 /// <returns></returns>
 public double GetValue(Catchment c, DateTime CurrentTime)
 {
     if (CatchLeach.ContainsKey(c.ID))
     {
         return(CatchLeach[c.ID][(CurrentTime.Year - Start.Year) * 12 + CurrentTime.Month - Start.Month]);
     }
     else
     {
         return(0);
     }
 }
Beispiel #15
0
        public double GetReduction(Catchment c, double CurrentMass, DateTime CurrentTime)
        {
            double red = 0;

            var CurrentWetLands = c.Wetlands.Where(w => w.StartTime <= CurrentTime).ToList();

            if (CurrentWetLands.Count > 0)
            {
                if (CurrentTime > new DateTime(2010, 1, 1))
                {
                    int k = 0;
                }



                var precip = c.Precipitation.GetTs(TimeStepUnit.Month).GetValue(CurrentTime);

                double accurain = c.Precipitation.GetTs(TimeStepUnit.Month).Average;
                double afs      = Math.Abs((precip - accurain) / accurain * Par1 + Par2);

                foreach (var w in CurrentWetLands)
                {
                    red += SoilEquations[w.SoilString].GetReduction(CurrentTime, afs) * XYGeometryTools.CalculateSharedArea(c.Geometry, w.Geometry) / 10000.0;
                }

                //Make sure we do not reduce more than what is available
                red  = Math.Max(0, Math.Min(CurrentMass, red));
                red /= (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0);
            }
            red = red * MultiplicationPar + AdditionPar;

            if (MultiplicationFactors != null)
            {
                if (MultiplicationFactors.ContainsKey(c.ID))
                {
                    red *= MultiplicationFactors[c.ID];
                }
            }

            if (AdditionFactors != null)
            {
                if (AdditionFactors.ContainsKey(c.ID))
                {
                    red += AdditionFactors[c.ID];
                }
            }

            return(red);
        }
Beispiel #16
0
        private double AccumulateUpstream(string Column, Catchment c, DateTime Time)
        {
            double Value    = 0;
            var    staterow = MW.StateVariables.Rows.Find(new object[] { c.ID, Time });

            if (!staterow.IsNull(Column))
            {
                Value += (double)staterow[Column];
            }
            foreach (var upc in c.UpstreamConnections)
            {
                Value += AccumulateUpstream(Column, upc, Time);
            }
            return(Value);
        }
Beispiel #17
0
        private double AccumulateGWSourceUpstream(string Column, Catchment c, DateTime Time)
        {
            double Value    = 0;
            var    staterow = StateVariables.Rows.Find(new object[] { c.ID, Time });
            var    row      = GetReductionRow(c.ID);

            if (!staterow.IsNull(Column))
            {
                Value += (double)staterow[Column] / (double)row["GWDischarge"];
            }
            foreach (var upc in c.UpstreamConnections)
            {
                Value += AccumulateGWSourceUpstream(Column, upc, Time);
            }
            return(Value);
        }
Beispiel #18
0
        private void SendReducUpstream(Catchment c, Dictionary <int, double> Reduction, double MultiFactor, string PlaceString, bool Reset)
        {
            foreach (var item in c.UpstreamConnections.Where(cc => cc.Measurements == null))
            {
                SendReducUpstream(item, Reduction, MultiFactor, PlaceString, Reset);
            }
            var row = dt.Rows.Find(c.ID);

            if (Reset)
            {
                Reduction[c.ID] = 0;
            }
            else
            {
                Reduction[c.ID] += MultiFactor * Math.Abs((double)row[PlaceString]);
            }
        }
Beispiel #19
0
        private void AddErrorToUpStream(double d, Catchment c)
        {
            var staterow = ReductionVariables.Rows.Find(new object[] { c.ID });

            if (!staterow.IsNull("BiasFactor"))
            {
                d = (double)staterow["BiasFactor"];
            }
            else
            {
                staterow["BiasFactor"] = d;
            }
            foreach (var opc in c.UpstreamConnections)
            {
                AddErrorToUpStream(d, opc);
            }
        }
    /// <summary>
    /// Returns the atmospheric deposition in kg/s
    /// </summary>
    /// <param name="c"></param>
    /// <param name="CurrentTime"></param>
    /// <returns></returns>
    public double GetValue(Catchment c, DateTime CurrentTime)
    {



      double value = deposition[c.ID][CurrentTime.Year - FirstYear];

      value = value * MultiplicationPar + AdditionPar;

      if (MultiplicationFactors != null)
        if (MultiplicationFactors.ContainsKey(c.ID))
          value *= MultiplicationFactors[c.ID];

      if (AdditionFactors != null)
        if (AdditionFactors.ContainsKey(c.ID))
          value += AdditionFactors[c.ID];

      return value;
    }
        public double GetReduction(Catchment c, double CurrentMass, DateTime CurrentTime)
        {
            double sourcevalue;

            if (string.IsNullOrEmpty(SourceModelName))
            {
                sourcevalue = CurrentMass;
            }
            else
            {
                sourcevalue = (double)c.StateVariables.Rows.Find(new object[] { c.ID, CurrentTime })[SourceModelName];
            }
            sourcevalue /= (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0);

            double red = 0;

            if (Reduction.ContainsKey(c.ID))
            {
                red = (Reduction[c.ID] * sourcevalue);
            }

            red = red * MultiplicationPar + AdditionPar;

            if (MultiplicationFactors != null)
            {
                if (MultiplicationFactors.ContainsKey(c.ID))
                {
                    red *= MultiplicationFactors[c.ID];
                }
            }

            if (AdditionFactors != null)
            {
                if (AdditionFactors.ContainsKey(c.ID))
                {
                    red += AdditionFactors[c.ID];
                }
            }

            return(red);
        }
Beispiel #22
0
        public double GetReduction(Catchment c, double CurrentMass, DateTime CurrentTime)
        {
            double red = 0;
            double rate;

            if (Reduction.TryGetValue(c.ID, out rate) & c.M11Flow != null)
            {
                double NormalizedMonthlyFlow = 0;
                double yearlyinflow          = c.NetInflow.GetTs(TimeStepUnit.Year).GetValue(CurrentTime);
                double monthlyflow           = c.NetInflow.GetTs(TimeStepUnit.Month).GetValue(CurrentTime);
                if (yearlyinflow > 0 & monthlyflow > 0)
                {
                    NormalizedMonthlyFlow = monthlyflow / yearlyinflow;
                }
                red = Math.Min(rate * NormalizedMonthlyFlow * YearFactors[CurrentTime.Year], CurrentMass) / (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0);
                red = Math.Max(0, red);
            }
            red = red * MultiplicationPar + AdditionPar;

            if (MultiplicationFactors != null)
            {
                if (MultiplicationFactors.ContainsKey(c.ID))
                {
                    red *= MultiplicationFactors[c.ID];
                }
            }

            if (AdditionFactors != null)
            {
                if (AdditionFactors.ContainsKey(c.ID))
                {
                    red += AdditionFactors[c.ID];
                }
            }

            return(red);
        }
        /// <summary>
        /// Returns the atmospheric deposition in kg/s
        /// </summary>
        /// <param name="c"></param>
        /// <param name="CurrentTime"></param>
        /// <returns></returns>
        public double GetValue(Catchment c, DateTime CurrentTime)
        {
            double value = deposition[c.ID][CurrentTime.Year - FirstYear];

            value = value * MultiplicationPar + AdditionPar;

            if (MultiplicationFactors != null)
            {
                if (MultiplicationFactors.ContainsKey(c.ID))
                {
                    value *= MultiplicationFactors[c.ID];
                }
            }

            if (AdditionFactors != null)
            {
                if (AdditionFactors.ContainsKey(c.ID))
                {
                    value += AdditionFactors[c.ID];
                }
            }

            return(value);
        }
Beispiel #24
0
    private IEnumerable<Catchment> GetUpstreamRecursive(Catchment c)
    {

      List<Catchment> ToReturn = new List<Catchment>();
      ToReturn.Add(c);
      foreach (var item in c.UpstreamConnections)
      {
        ToReturn.AddRange(GetUpstreamRecursive(item));
      }
      return ToReturn;
    }
Beispiel #25
0
    /// <summary>
    /// Gets the value in kg/s
    /// </summary>
    /// <param name="c"></param>
    /// <param name="CurrentTime"></param>
    /// <returns></returns>
    public double GetValue(Catchment c, DateTime CurrentTime)
    {
      double value = 0;
      List<double> data;
      if (deposition.TryGetValue(c.ID, out data) )
      {
        value= Math.Max(0, data[CurrentTime.Year - FirstYear] * (c.NetInflow.GetTs(TimeStepUnit.Month).GetValue(CurrentTime, InterpolationMethods.DeleteValue)));
      }
      value = value * MultiplicationPar + AdditionPar;

      if (MultiplicationFactors != null)
        if (MultiplicationFactors.ContainsKey(c.ID))
          value *= MultiplicationFactors[c.ID];

      if (AdditionFactors != null)
        if (AdditionFactors.ContainsKey(c.ID))
          value += AdditionFactors[c.ID];

      return value;
    }
Beispiel #26
0
    /// <summary>
    /// Returns the reduction in kg/s
    /// </summary>
    /// <param name="c"></param>
    /// <param name="CurrentMass"></param>
    /// <param name="CurrentTime"></param>
    /// <returns></returns>
    public double GetReduction(Catchment c, double CurrentMass, DateTime CurrentTime)
    {
      double red = 0;
      if (c.BigLake != null && c.BigLake.Start<=CurrentTime && c.BigLake.End>=CurrentTime)
      {
        double Reducer;
        if (c.BigLake.RetentionTime > 1)
        {
          Reducer = (Par1 * MO5[CurrentTime.Month] - c.Temperature.GetValue(CurrentTime, InterpolationMethods.DeleteValue))/100.0;
        }
        else
        {
          //Get the lake temperature
          double T = LakeTemperatureFromAir(c.Temperature.GetValue(CurrentTime, InterpolationMethods.DeleteValue), c.Temperature.GetValue(CurrentTime.AddMonths(-1),InterpolationMethods.DeleteValue), CurrentTime);
          c.BigLake.Temperature.Items.Add(new TimeStampValue(CurrentTime, T));
          
          Reducer = Alpha * Math.Pow(Beta, T - 20.0);
        }

        c.BigLake.CurrentNMass += CurrentMass;
        double removedN = Reducer * c.BigLake.CurrentNMass;
        //From m3/s to m3
        double mflow = c.M11Flow.GetTs(TimeStepUnit.Month).GetValue(CurrentTime) * DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400;

        if (mflow > 0)
        {
          double NOut = (c.BigLake.CurrentNMass - removedN) / (c.BigLake.Volume + mflow) * mflow;
          //        NOut = Math.Max(0,Math.Min(c.BigLake.CurrentNMass - removedN, NOut));

          c.BigLake.CurrentNMass = c.BigLake.CurrentNMass - removedN - NOut;

          //Store some results
          c.BigLake.NitrateReduction.Items.Add(new TimeStampValue(CurrentTime, removedN));
          c.BigLake.NitrateConcentration.Items.Add(new TimeStampValue(CurrentTime, c.BigLake.CurrentNMass / c.BigLake.Volume));
          c.BigLake.FlushingRatio.Items.Add(new TimeStampValue(CurrentTime, mflow/c.BigLake.Volume  ));

          red = (CurrentMass - NOut) / (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0);
        }
      }
      red = red * MultiplicationPar + AdditionPar;

      if (MultiplicationFactors != null)
        if (MultiplicationFactors.ContainsKey(c.ID))
          red *= MultiplicationFactors[c.ID];

      if (AdditionFactors != null)
        if (AdditionFactors.ContainsKey(c.ID))
          red += AdditionFactors[c.ID];

      return red;
    }
    private double AccumulateUpstream(string Column, Catchment c, DateTime Time, bool WithBias)
    {
      double Value = 0;
      var staterow = StateVariables.Rows.Find(new object[] { c.ID, Time });
      if (!staterow.IsNull(Column))
      {
        double BiasFactor=1;

        if (WithBias)
        {
          var row = GetReductionRow(c.ID);
          if(!row.IsNull("BiasFactor"))
            BiasFactor =(double)row["BiasFactor"];
        }
        Value += (double)staterow[Column] * BiasFactor;
      }
      foreach (var upc in c.UpstreamConnections)
      {
        Value += AccumulateUpstream(Column, upc, Time, WithBias);
      }
      return Value;
    }
Beispiel #28
0
    private double AccumulateUpstream(string Column, Catchment c, DateTime Time)
    {

      double Value = 0;
      var staterow = MW.StateVariables.Rows.Find(new object[] { c.ID, Time });
      if (!staterow.IsNull(Column))
      {
        Value += (double)staterow[Column];
      }
      foreach (var upc in c.UpstreamConnections)
      {
        Value += AccumulateUpstream(Column, upc, Time);
      }
      return Value;
    }
    /// <summary>
    /// Returns all catchments downstream the catchment c. Also adds c to the list.
    /// </summary>
    /// <param name="c"></param>
    /// <returns></returns>
    public List<Catchment> GetDownStreamCatchments(Catchment c)
    {
      List<Catchment> ToReturn = new List<Catchment>();
      ToReturn.Add(c);

      if (c.DownstreamConnection != null)
        ToReturn.AddRange(GetDownStreamCatchments(c.DownstreamConnection));

      return ToReturn;
    }
Beispiel #30
0
 private void RecursiveWriter(Catchment c, ShapeWriter sw, DataTable data, string ColumnName, double Factor)
 {
   foreach (var upc in c.UpstreamConnections.Where(cc => cc.Measurements == null))
   {
     GeoRefData gd = new GeoRefData() { Geometry = upc.Geometry };
     gd.Data = data.NewRow();
     gd.Data[0] = upc.ID;
     gd.Data[ColumnName] = Factor;
     sw.Write(gd);
     RecursiveWriter(upc, sw, data,ColumnName, Factor);
   }
 }
Beispiel #31
0
    public double GetReduction(Catchment c, double CurrentInflowRate, DateTime CurrentTime)
    {
      double red = 0;
      CurrentInflowRate /= DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0;
      if (CurrentTime.Month >= FirstSummerMonth & CurrentTime.Month <= LastSummerMonth)
        red= ReductionFactors[c.ID].Item1 * CurrentInflowRate; //Summer
      else
        red= ReductionFactors[c.ID].Item2 * CurrentInflowRate; //Winter

      red= red *MultiplicationPar + AdditionPar;

      if (MultiplicationFactors != null)
        if (MultiplicationFactors.ContainsKey(c.ID))
          red *= MultiplicationFactors[c.ID];

      if (AdditionFactors != null)
        if (AdditionFactors.ContainsKey(c.ID))
          red += AdditionFactors[c.ID];

      return red;
    }
    private double AccumulateGWSourceUpstream(string Column, Catchment c, DateTime Time)
    {
      double Value = 0;
      var staterow = StateVariables.Rows.Find(new object[] { c.ID, Time });
      var row = GetReductionRow(c.ID);

      if (!staterow.IsNull(Column))
        Value += (double)staterow[Column] / (double)row["GWDischarge"];
      foreach (var upc in c.UpstreamConnections)
      {
        Value += AccumulateGWSourceUpstream(Column, upc, Time);
      }
      return Value;
    }
    private void AddToUpStream1(Catchment c)
    {
      var row = ReductionVariables.Rows.Find(new object[] { c.ID });

      double UpstreamInput = 0;
      foreach (var opc in c.UpstreamConnections)
      {
        AddToUpStream1(opc);
        UpstreamInput += (double)ReductionVariables.Rows.Find(new object[] { opc.ID })["DownStreamOutput"];
      }

      double GWSource = (double)row["GWSources"];
      double GWReduction = (double)row["GWReductions"];
      double source = (double)row["Sources"];
      double ConceptualReduction = (double)row["ConcepReductions"];
      double internalred = (double)row["Internalreductions"];
      double mainred = (double)row["MainReductions"];


      row["DownStreamOutput"] = source + GWSource - mainred - internalred - ConceptualReduction - GWReduction + UpstreamInput;
      row["UpstreamInput"] = UpstreamInput;

      row["MainDischarge"] = 1.0 - mainred / (source + GWSource - internalred - ConceptualReduction - GWReduction + UpstreamInput);

    }
    private void AddToUpStream(double d, Catchment c)
    {
      var row = GetReductionRow(c.ID);
      double accumulated = (double)row["MainDischarge"] * d;
      row["AccDischarge"] = accumulated;
      foreach (var opc in c.UpstreamConnections)
      {
        AddToUpStream(accumulated, opc);
      }

    }
 private void AddErrorToUpStream(double d, Catchment c)
 {
   var staterow = ReductionVariables.Rows.Find(new object[] { c.ID });
   if (!staterow.IsNull("BiasFactor"))
     d = (double)staterow["BiasFactor"];
   else
     staterow["BiasFactor"] = d;
   foreach (var opc in c.UpstreamConnections)
     AddErrorToUpStream(d, opc);
 }
Beispiel #36
0
    /// <summary>
    /// Returns the source rate to the catchment in kg/s at the current time
    /// </summary>
    /// <param name="c"></param>
    /// <param name="CurrentTime"></param>
    /// <returns></returns>
    public double GetValue(Catchment c, DateTime CurrentTime)
    {
      double value = 0;
      Dictionary<int, double> timevalues;
      if (YearlyData.TryGetValue(c.ID, out timevalues))
      {
        timevalues.TryGetValue(CurrentTime.Year, out value);
      }
      value = value * MultiplicationPar + AdditionPar;

      if (MultiplicationFactors != null)
        if (MultiplicationFactors.ContainsKey(c.ID))
          value *= MultiplicationFactors[c.ID];

      if (AdditionFactors != null)
        if (AdditionFactors.ContainsKey(c.ID))
          value += AdditionFactors[c.ID];

      return value;
    }
Beispiel #37
0
 private void RecursiveUpstreamAdd(Catchment c)
 {
   CurrentCatchments.Add(c);
   foreach (var ups in c.UpstreamConnections)
     RecursiveUpstreamAdd(ups);
 }
Beispiel #38
0
 private Catchment GetNextDownstream(Catchment c)
 {
   if (c.DownstreamConnection == null)
     return c;
   return GetNextDownstream(c.DownstreamConnection);
 }
Beispiel #39
0
 private void GetCatchmentsWithObs(Catchment c, List<Catchment> Upstreams)
 {
   foreach (var upc in c.UpstreamConnections)
     GetCatchmentsWithObs(upc, Upstreams);
   if (c.Measurements != null)
     Upstreams.Add(c);
 }
    /// <summary>
    /// Returns the source rate to the catchment in kg/s at the current time
    /// </summary>
    /// <param name="c"></param>
    /// <param name="CurrentTime"></param>
    /// <returns></returns>
    public double GetValue(Catchment c, DateTime CurrentTime)
    {
      double value = 0;
      if (GWInput.ContainsKey(c.ID))
        value = GWInput[c.ID][(CurrentTime.Year - Start.Year) * 12 + CurrentTime.Month - Start.Month];

      value = value * MultiplicationPar + AdditionPar;

      if (MultiplicationFactors != null)
        if (MultiplicationFactors.ContainsKey(c.ID))
          value *= MultiplicationFactors[c.ID];

      if (AdditionFactors != null)
        if (AdditionFactors.ContainsKey(c.ID))
          value += AdditionFactors[c.ID];

      return value;
    }
Beispiel #41
0
 private void SendReducUpstream(Catchment c, Dictionary<int, double> Reduction, double MultiFactor, string PlaceString, bool Reset)
 {
   foreach (var item in c.UpstreamConnections.Where(cc => cc.Measurements == null))
   {
     SendReducUpstream(item, Reduction, MultiFactor, PlaceString, Reset);
   }
   var row = dt.Rows.Find(c.ID);
   if (Reset)
     Reduction[c.ID] = 0;
   else
     Reduction[c.ID] += MultiFactor *Math.Abs((double)row[PlaceString]);
 }
 /// <summary>
 /// Returns the leaching from the catchment in kg/s at the current time
 /// </summary>
 /// <param name="c"></param>
 /// <param name="CurrentTime"></param>
 /// <returns></returns>
 public double GetValue(Catchment c, DateTime CurrentTime)
 {
   if (CatchLeach.ContainsKey(c.ID))
     return CatchLeach[c.ID][(CurrentTime.Year - Start.Year) * 12 + CurrentTime.Month - Start.Month];
   else
     return 0;
 }
    public double GetReduction(Catchment c, double CurrentMass, DateTime CurrentTime)
    {
      double red = 0;

      var CurrentWetLands = c.Wetlands.Where(w => w.StartTime <= CurrentTime).ToList();

      if (CurrentWetLands.Count > 0)
      {
        if (CurrentTime > new DateTime(2010, 1, 1))
        {
          int k = 0;
        }



        var precip = c.Precipitation.GetTs(TimeStepUnit.Month).GetValue(CurrentTime, InterpolationMethods.DeleteValue);

        double accurain = c.Precipitation.GetTs(TimeStepUnit.Month).Average;
        double afs = Math.Abs((precip - accurain) / accurain * Par1 + Par2);

        foreach(var w in CurrentWetLands)
        {
          red += SoilEquations[w.SoilString].GetReduction(CurrentTime, afs) * XYGeometryTools.CalculateSharedArea(c.Geometry, w.Geometry) / 10000.0;
        }

        //Make sure we do not reduce more than what is available
        red = Math.Max(0, Math.Min(CurrentMass, red));
        red /= (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0);
      }
      red = red * MultiplicationPar + AdditionPar;

      if (MultiplicationFactors != null)
        if (MultiplicationFactors.ContainsKey(c.ID))
          red *= MultiplicationFactors[c.ID];

      if (AdditionFactors != null)
        if (AdditionFactors.ContainsKey(c.ID))
          red += AdditionFactors[c.ID];

      return red;
    }