예제 #1
0
        /// <summary>
        /// Reads in head observations from txt file with this format.
        /// "WellID X Y Z Head  Date  Layer". Separated with tabs. Layer is optional
        /// </summary>
        /// <param name="LSFileName"></param>
        public Dictionary<string, MikeSheWell> ReadFromLSText(string LSFileName)
        {
            Dictionary<string, MikeSheWell> Wells = new Dictionary<string, MikeSheWell>();
              //Sets the output file name for subsequent writing
              string path = Path.GetDirectoryName(LSFileName);
              string FileName = Path.GetFileNameWithoutExtension(LSFileName);
              _baseOutPutFileName = Path.Combine(path, FileName);

              //Now read the input
              using (StreamReader SR = new StreamReader(LSFileName))
              {

            //Reads the HeadLine
            string line = SR.ReadLine();
            string[] s;
            MikeSheWell OW;

            while ((line = SR.ReadLine()) != null)
            {
              s = line.Split('\t');

              //Check that s has correct lengt and does not consist of empty entries
              if (s.Length > 5 & s.Aggregate<string>((a,b)=>a+b)!="")
              {
            try
            {
              //If the well has not already been read in create a new one
              if (!Wells.TryGetValue(s[0], out OW))
              {
                OW = new MikeSheWell(s[0]);
                IIntake I = OW.AddNewIntake(1);
                Wells.Add(OW.ID, OW);
                OW.X = double.Parse(s[1]);
                OW.Y = double.Parse(s[2]);

                //Layer is provided directly. Calculate Z
                if (s.Length >= 7 && s[6] != "")
                {
                  OW.Layer = _numberOfLayers - int.Parse(s[6]);
                }
                //Use the Z-coordinate
                else
                {
                  OW.Depth = double.Parse(s[3]);
                  OW.Layer = -3;
                }
              }
              //Now add the observation
              OW.Intakes.First().Observations.Add(new ObservationEntry(DateTime.Parse(s[5]), double.Parse(s[4])));
            }
            catch (FormatException e)
            {
              MessageBox.Show("Error reading this line:\n\n" + line +"\n\nFrom file: "+ LSFileName + "\n\nLine skipped!", "Format error!");
            }
              }
            }
              } //End of streamreader
              return Wells;
        }
예제 #2
0
        /// <summary>
        /// Reads in the wells defined in detailed timeseries input section
        /// </summary>
        /// <param name="Mshe"></param>
        public static IEnumerable <IWell> ReadInDetailedTimeSeries(Model Mshe)
        {
            MikeSheWell CurrentWell;
            IIntake     CurrentIntake;
            TSObject    _tso = null;

            foreach (var dt in Mshe.Input.MIKESHE_FLOWMODEL.StoringOfResults.DetailedTimeseriesOutput.Item_1s)
            {
                CurrentWell   = new MikeSheWell(dt.Name);
                CurrentWell.X = dt.X;
                CurrentWell.Y = dt.Y;
                CurrentWell.UsedForExtraction = false;
                CurrentIntake = CurrentWell.AddNewIntake(1);
                Screen sc = new Screen(CurrentIntake);
                sc.DepthToTop    = dt.Z;
                sc.DepthToBottom = dt.Z;

                CurrentWell.Row    = Mshe.GridInfo.GetRowIndex(CurrentWell.X);
                CurrentWell.Column = Mshe.GridInfo.GetColumnIndex(CurrentWell.Y);

                CurrentWell.Terrain = Mshe.GridInfo.SurfaceTopography.Data[CurrentWell.Row, CurrentWell.Column];

                //Read in observations if they are included
                if (dt.InclObserved == 1)
                {
                    if (_tso == null || _tso.Connection.FilePath != dt.TIME_SERIES_FILE.FILE_NAME)
                    {
                        _tso = new TSObjectClass();
                        _tso.Connection.FilePath = dt.TIME_SERIES_FILE.FILE_NAME;
                        _tso.Connection.Open();
                    }

                    //Loop the observations and add
                    for (int i = 1; i <= _tso.Time.NrTimeSteps; i++)
                    {
                        CurrentIntake.HeadObservations.Items.Add(new TimestampValue((DateTime)_tso.Time.GetTimeForTimeStepNr(i), (float)_tso.Item(dt.TIME_SERIES_FILE.ITEM_NUMBERS).GetDataForTimeStepNr(i)));
                    }
                }
                yield return(CurrentWell);
            }
        }
예제 #3
0
        /// <summary>
        /// Reads in head observations from txt file with this format.
        /// "WellID X Y Z Head  Date  Layer". Separated with tabs. Layer is optional
        /// </summary>
        /// <param name="LSFileName"></param>
        public Dictionary <string, MikeSheWell> ReadFromLSText(string LSFileName)
        {
            Dictionary <string, MikeSheWell> Wells = new Dictionary <string, MikeSheWell>();
            //Sets the output file name for subsequent writing
            string path     = Path.GetDirectoryName(LSFileName);
            string FileName = Path.GetFileNameWithoutExtension(LSFileName);

            _baseOutPutFileName = Path.Combine(path, FileName);

            //Now read the input
            using (StreamReader SR = new StreamReader(LSFileName))
            {
                //Reads the HeadLine
                string      line = SR.ReadLine();
                string[]    s;
                MikeSheWell OW;

                while ((line = SR.ReadLine()) != null)
                {
                    s = line.Split('\t');

                    //Check that s has correct lengt and does not consist of empty entries
                    if (s.Length > 5 & s.Aggregate <string>((a, b) => a + b) != "")
                    {
                        try
                        {
                            LsIntake I = null;
                            //If the well has not already been read in create a new one
                            if (!Wells.TryGetValue(s[0], out OW))
                            {
                                OW = new MikeSheWell(s[0]);
                                I  = new LsIntake(OW, 1);
                                OW.AddIntake(I);
                                Wells.Add(OW.ID, OW);
                                OW.X = double.Parse(s[1]);
                                OW.Y = double.Parse(s[2]);

                                //Layer is provided directly. Calculate Z
                                if (s.Length >= 7 && s[6] != "")
                                {
                                    OW.Layer = _numberOfLayers - int.Parse(s[6]);
                                }
                                //Use the Z-coordinate
                                else
                                {
                                    OW.Depth = double.Parse(s[3]);
                                    OW.Layer = -3;
                                }
                            }

                            if (I == null)
                            {
                                I = OW.Intakes.First() as LsIntake;
                            }

                            //Now add the observation
                            I.Observations.Add(new Observation(DateTime.ParseExact(s[5], new string[] { "dd-MM-yyyy", "d-MM-yyyy", "d-M-yyyy", "dd-M-yyyy" }, null, System.Globalization.DateTimeStyles.None), double.Parse(s[4]), OW));
                        }
                        catch (FormatException e)
                        {
                            MessageBox.Show("Error reading this line:\n\n" + line + "\n\nFrom file: " + LSFileName + "\n\nLine skipped!", "Format error!");
                        }
                    }
                }
            } //End of streamreader
            return(Wells);
        }
예제 #4
0
 public Observation(DateTime time, double Value, MikeSheWell well)
 {
     this.Time  = time;
     this.Value = Value;
     Well       = well;
 }
예제 #5
0
        /// <summary>
        /// Reads in the wells defined in detailed timeseries input section
        /// </summary>
        /// <param name="Mshe"></param>
        public static IEnumerable<IWell> ReadInDetailedTimeSeries(Model Mshe)
        {
            MikeSheWell CurrentWell;
              IIntake CurrentIntake;
              TSObject _tso = null;

              foreach (MikeSheWrapper.InputFiles.Item_11 dt in Mshe.Input.MIKESHE_FLOWMODEL.StoringOfResults.DetailedTimeseriesOutput.Item_1s)
              {
            CurrentWell = new MikeSheWell(dt.Name);
            CurrentWell.X = dt.X;
            CurrentWell.Y = dt.Y;
            CurrentWell.Depth = dt.Z;
            CurrentWell.UsedForExtraction = false;

            //Read in observations if they are included
            if (dt.InclObserved == 1)
            {
              CurrentIntake = CurrentWell.AddNewIntake(1);

              if (_tso == null || _tso.Connection.FilePath != dt.TIME_SERIES_FILE.FILE_NAME)
              {
            _tso = new TSObjectClass();
            _tso.Connection.FilePath = dt.TIME_SERIES_FILE.FILE_NAME;
            _tso.Connection.Open();
              }

              //Loop the observations and add
              for (int i = 1; i <= _tso.Time.NrTimeSteps; i++)
              {
            CurrentIntake.Observations.Add(new ObservationEntry((DateTime)_tso.Time.GetTimeForTimeStepNr(i), (float)_tso.Item(dt.TIME_SERIES_FILE.ITEM_NUMBERS).GetDataForTimeStepNr(i)));
              }
            }
            yield return CurrentWell;
              }
        }
예제 #6
0
        /// <summary>
        /// 4-point bilinear interpolation is used to get the value in a point.
        /// </summary>
        /// <param name="MSheResults"></param>
        /// <param name="GridInfo"></param>
        public static void GetSimulatedValuesFromGridOutput(Results MSheResults, MikeSheGridInfo GridInfo, MikeSheWell Well)
        {
            foreach(Intake I in Well.Intakes)
            foreach (ObservationEntry TSE in I.Observations)
            {
              if (Well.Layer >= 0)
              {
            Matrix M = MSheResults.PhreaticHead.TimeData(TSE.Time)[Well.Layer];

            TSE.SimulatedValueCell = M[Well.Row, Well.Column];
            //Interpolates in the matrix
            TSE.SimulatedValue = GridInfo.Interpolate(Well.X, Well.Y, Well.Layer, M, out TSE.DryCells, out TSE.BoundaryCells);
              }
              else
              {
            TSE.Comment = "Depth is above the surface or below bottom of the model domain";
              }
            }
        }