internal PhreaticPotential(IXYZTDataSet Potential, MikeSheGridInfo Grid, double DeleteValue)
 {
   _deleteValue = DeleteValue;
   _potential = Potential;
   _bottomOfCell = Grid.LowerLevelOfComputationalLayers;
   _thicknessOfCell = Grid.ThicknessOfComputationalLayers;
 }
Exemple #2
0
 /// <summary>
 /// Constructs the Results from a MikeShe setup file (.she)
 /// </summary>
 /// <param name="SheFileName"></param>
 public Results(string SheFileName)
 {
     FileNames fn = new FileNames(SheFileName);
       _grid = new MikeSheGridInfo(fn.PreProcessedSZ3D, fn.PreProcessed2D);
       Initialize3DSZ(fn.Get3DSZFileName);
       Initialize3DSZFlow(fn.get3DSZFlowFileName);
 }
Exemple #3
0
        public void EqualsTest()
        {
            MikeSheGridInfo M1 = new MikeSheGridInfo(@"..\..\..\TestData\TestModel.she - Result Files\TestModel_PreProcessed_3DSZ.DFS3", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_PreProcessed.DFS2");
            MikeSheGridInfo M2 = new MikeSheGridInfo(@"..\..\..\TestData\TestModel.she - Result Files\TestModel_PreProcessed_3DSZ.DFS3", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_PreProcessed.DFS2");

            Assert.IsTrue(M1.Equals(M2));
            M1.Dispose();
            M2.Dispose();
        }
    public void EqualsTest()
    {

      MikeSheGridInfo M1 = new MikeSheGridInfo(@"..\..\..\TestData\TestModel.she - Result Files\TestModel_PreProcessed_3DSZ.DFS3", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_PreProcessed.DFS2");
      MikeSheGridInfo M2 = new MikeSheGridInfo(@"..\..\..\TestData\TestModel.she - Result Files\TestModel_PreProcessed_3DSZ.DFS3", @"..\..\..\TestData\TestModel.she - Result Files\TestModel_PreProcessed.DFS2");

      Assert.IsTrue(M1.Equals(M2));
      M1.Dispose();
      M2.Dispose();
    }
    public MikeSheWell(string ID, double UTMX, double UTMY, MikeSheGridInfo MSGI)
      : this(ID, UTMX, UTMY)
    {
      int i;
      int j;

      MSGI.TryGetIndex(UTMX, UTMY, out i, out j);
      Column = i;
      Row = j;
    }
 /// <summary>
 /// Select the wells that are inside the model area. Does not look at the 
 /// z - coordinate
 /// </summary>
 /// <param name="MikeShe"></param>
 public static IEnumerable<MikeSheWell> SelectByMikeSheModelArea(MikeSheGridInfo Grid, IEnumerable<MikeSheWell> Wells)
 {
   int Column;
   int Row;
   foreach (MikeSheWell W in Wells)
   {
     //Gets the index and sets the column and row
     if (Grid.TryGetIndex(W.X, W.Y, out Column, out Row))
     {
       W.Column = Column;
       W.Row = Row;
       yield return W;
     }
   }
 }
Exemple #7
0
        /// <summary>
        /// Select the wells that are inside the model area. Does not look at the
        /// z - coordinate
        /// </summary>
        /// <param name="MikeShe"></param>
        public static IEnumerable <MikeSheWell> SelectByMikeSheModelArea(MikeSheGridInfo Grid, IEnumerable <MikeSheWell> Wells)
        {
            int Column;
            int Row;

            foreach (MikeSheWell W in Wells)
            {
                //Gets the index and sets the column and row
                if (Grid.TryGetIndex(W.X, W.Y, out Column, out Row))
                {
                    W.Column = Column;
                    W.Row    = Row;
                    yield return(W);
                }
            }
        }
        private void Initialize(string PreProcessed3dSzFile, string PreProcessed2dSzFile)
        {
            //Open File with 3D data
              _PreProcessed_3DSZ = new DFS3(PreProcessed3dSzFile);

              //Generate 3D properties
              for (int i = 0; i < _PreProcessed_3DSZ.ItemNames.Length; i++)
              {
            switch (_PreProcessed_3DSZ.ItemNames[i])
            {
              case "Horizontal conductivity in the saturated zone":
            _horizontalConductivity = new DataSetsFromDFS3(_PreProcessed_3DSZ, i+1);
            break;
              case "Vertical conductivity in the saturated zone":
            _verticalConductivity = new DataSetsFromDFS3(_PreProcessed_3DSZ, i+1);
            break;
              case "Transmissivity in the saturated zone":
            _transmissivity = new DataSetsFromDFS3(_PreProcessed_3DSZ, i+1);
            break;
              case "Specific yield in the saturated zone":
            _specificYield = new DataSetsFromDFS3(_PreProcessed_3DSZ, i+1);
            break;
              case "Specific storage in the saturated zone":
            _specificStorage = new DataSetsFromDFS3(_PreProcessed_3DSZ, i+1);
            break;
              case "Initial potential heads in the saturated zone":
            _initialHeads = new DataSetsFromDFS3(_PreProcessed_3DSZ, i+1);
            break;
              default: //Unknown item
            break;
            }
              }

              //Open File with 2D data
              _prePro2D = new DFS2(PreProcessed2dSzFile);

              //Generate 2D properties by looping the items
              for (int i = 0; i < _prePro2D.ItemNames.Length; i++)
              {
            switch (_prePro2D.ItemNames[i])
            {
              case "Net Rainfall Fraction":
            _netRainFallFraction = new DataSetsFromDFS2(_prePro2D, i +1);
            break;
              case "Infiltration Fraction":
            _infiltrationFraction = new DataSetsFromDFS2(_prePro2D, i +1);
            break;
              default: //Unknown item
            break;
            }
              }

              //Now construct the grid from the open files
              _grid = new MikeSheGridInfo(_PreProcessed_3DSZ, _prePro2D);
        }
		public static void Main(string[] args)
		{
      DFS.DFS3.MaxEntriesInBuffer =10;
      bool stay = true;

      while (stay)
      {
        stay = false;
        foreach (var v in System.Diagnostics.Process.GetProcesses())
        {
          if (v.Id != System.Diagnostics.Process.GetCurrentProcess().Id)
          {
            if (v.ProcessName.ToLower().StartsWith("ls.exe"))
            {
              if (v.UserProcessorTime > TimeSpan.FromSeconds(0.2))
              {
                stay = true;
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(30));
                break;
              }
            }
          }
        }
      }

      MikeSheGridInfo _grid = null;
      Results _res = null;
      try
      {
        string ObsFileName;

        //Input is a -she-file and an observation file
        if (args.Length == 2)
        {
          Model MS = new Model(args[0]);
          _grid = MS.GridInfo;
          _res = MS.Results;
          ObsFileName = args[1];
        }
        //Input is an .xml-file
        else if (args.Length == 1)
        {
          Configuration cf = Configuration.ConfigurationFactory(args[0]);

          _grid = new MikeSheGridInfo(cf.PreProcessedDFS3, cf.PreProcessedDFS2);

          if (cf.HeadItemText != null)
            _res = new Results(cf.ResultFile, _grid, cf.HeadItemText);
          else
            _res = new Results(cf.ResultFile, _grid);

          if (_res.Heads == null)
            throw new Exception("Heads could not be found. Check that item: \"" + _res.HeadElevationString + "\" exists in + " + cf.ResultFile);

          if (_grid.NumberOfLayers != _res.Heads.TimeData(0).LayerCount)
            throw new Exception("Number of layers in preprocessed files do not match number of layers in resultfile: " + cf.ResultFile);

          ObsFileName = cf.ObservationFile;
        }
        else
        {
          OpenFileDialog Ofd = new OpenFileDialog();

          Ofd.Filter = "Known file types (*.she)|*.she";
          Ofd.ShowReadOnly = true;
          Ofd.Title = "Select a MikeShe setup file";


          if (DialogResult.OK == Ofd.ShowDialog())
          {
            Model MS = new Model(Ofd.FileName);
            _grid = MS.GridInfo;
            _res = MS.Results;
            Ofd.Filter = "Known file types (*.txt)|*.txt";
            Ofd.ShowReadOnly = true;
            Ofd.Title = "Select a LayerStatistics setup file";

            if (DialogResult.OK == Ofd.ShowDialog())
              ObsFileName = Ofd.FileName;
            else
              return;
          }
          else
            return;
        }

        InputOutput IO = new InputOutput(_grid.NumberOfLayers);

        string _baseOutPutFileName;
        string path = Path.GetDirectoryName(ObsFileName);
        string FileName = Path.GetFileNameWithoutExtension(ObsFileName);
        _baseOutPutFileName = Path.Combine(path, FileName);


        //Read in the wells
        Dictionary<string, MikeSheWell> Wells = IO.ReadFromLSText(ObsFileName);

        int NLay = _grid.NumberOfLayers;
        double[] ME = new double[NLay];
        double[] RMSE = new double[NLay];
        int[] ObsUsed = new int[NLay];
        int[] ObsTotal = new int[NLay];

        //Initialiserer
        for (int i = 0; i < NLay; i++)
        {
          ME[i] = 0;
          RMSE[i] = 0;
          ObsUsed[i] = 0;
          ObsTotal[i] = 0;
        }

        //Only operate on wells within the mikeshe area
        var SelectedWells = _grid.SelectByMikeSheModelArea(Wells.Values);


        StreamWriter sw = new StreamWriter(_baseOutPutFileName + "_observations.txt");
        StreamWriter swell = new StreamWriter(_baseOutPutFileName + "_wells.txt");

        sw.WriteLine("OBS_ID\tX\tY\tDepth\tLAYER\tOBS_VALUE\tDATO\tSIM_VALUE_INTP\tSIM_VALUE_CELL\tME\tME^2\t#DRY_CELLS\t#BOUNDARY_CELLS\tCOLUMN\tROW\tCOMMENT\t#OBSInWell");
        swell.WriteLine("OBS_ID\tX\tY\tDepth\tLAYER\tME\tME^2");


        //Loops the wells that are within the model area and set the layer or depth
        foreach (MikeSheWell W in SelectedWells)
        {
          //Get layer or depth
          if (W.Layer == -3)
            W.Layer = _grid.GetLayerFromDepth(W.Column, W.Row, W.Depth.Value);
          else
            W.Depth = _grid.SurfaceTopography.Data[W.Row, W.Column] - (_grid.LowerLevelOfComputationalLayers.Data[W.Row, W.Column, W.Layer] + 0.5 * _grid.ThicknessOfComputationalLayers.Data[W.Row, W.Column, W.Layer]);
        }

        System.Diagnostics.Stopwatch swm = new System.Diagnostics.Stopwatch();

        swm.Start();


        foreach (Observation TSE in SelectedWells.Where(var => var.Layer >= 0).SelectMany(var2 => var2.Intakes).SelectMany(var3 => ((LsIntake)var3).Observations).OrderBy(var4 => var4.Time))
        {
          var M = _res.PhreaticHead.TimeData(TSE.Time)[TSE.Well.Layer];
          TSE.SimulatedValueCell= M[TSE.Well.Row, TSE.Well.Column];
          int DryCells = 0;
          int BoundaryCells = 0;

          //Interpolates in the matrix
          TSE.InterpolatedValue = _grid.Interpolate(TSE.Well.X, TSE.Well.Y, TSE.Well.Layer, M, out DryCells, out BoundaryCells);

          TSE.DryCells = DryCells;
          TSE.BoundaryCells = BoundaryCells;
        }
        swm.Stop();


        //Loops the wells that are within the model area
        foreach (MikeSheWell W in SelectedWells)
        {
          double MEWell = 0;
          double RMSWell = 0;
          int UsedObsInWells = 0;

          //Calculate results
          foreach (LsIntake I in W.Intakes)
          {
            foreach (Observation TSE in I.Observations.OrderBy(var=>var.Time))
            {
              StringBuilder ObsString = new StringBuilder();
              string Comment = "";
              double? MECell = null;
              double? RMSCell = null;

              if (W.Layer < 0)
                Comment = "Depth is above the surface or below bottom of the model domain";
              else
              {

                MECell = TSE.Value - TSE.InterpolatedValue;
                RMSCell = Math.Pow(MECell.Value, 2);

                if (TSE.SimulatedValueCell == _res.DeleteValue)
                {
                  Comment = "Cell is dry";
                }
                else
                {
                  UsedObsInWells++;
                  MEWell += MECell.Value;
                  RMSWell += RMSCell.Value;
                }
              }
              ObsString.Append(W.ID + "\t");
              ObsString.Append(W.X + "\t");
              ObsString.Append(W.Y + "\t");
              ObsString.Append(W.Depth + "\t");

              if (W.Layer >= 0)
                ObsString.Append((_grid.NumberOfLayers - W.Layer) + "\t");
              else
                ObsString.Append((W.Layer) + "\t");
              ObsString.Append(TSE.Value + "\t");
              ObsString.Append(TSE.Time.ToString("dd-MM-yyyy") + "\t");
              ObsString.Append(TSE.InterpolatedValue + "\t");
              ObsString.Append(TSE.SimulatedValueCell + "\t");
              ObsString.Append(MECell + "\t");
              ObsString.Append(RMSCell + "\t");
              ObsString.Append(TSE.DryCells + "\t");
              ObsString.Append(TSE.BoundaryCells + "\t");
              ObsString.Append(W.Column + "\t");
              ObsString.Append(W.Row + "\t");
              ObsString.Append(Comment + "\t");
              ObsString.Append(I.Observations.Count);
              sw.WriteLine(ObsString.ToString());
            }
          }

          if (UsedObsInWells > 0)
          {
            MEWell /= UsedObsInWells;
            RMSWell /= UsedObsInWells;
            ME[W.Layer] += MEWell;
            RMSE[W.Layer] += RMSWell;
            ObsUsed[W.Layer]++;
          }

          if (W.Layer>=0)
            ObsTotal[W.Layer]++;

          //Write for each well
          StringBuilder WellString = new StringBuilder();
          WellString.Append(W.ID + "\t");
          WellString.Append(W.X + "\t");
          WellString.Append(W.Y + "\t");
          WellString.Append(W.Depth + "\t");
          if (W.Layer >= 0)
          {
            WellString.Append((_grid.NumberOfLayers - W.Layer) + "\t");
            WellString.Append(MEWell + "\t");
            WellString.Append(RMSWell+ "\t");
          }
          else
            WellString.Append((W.Layer) + "\t" + "\t" + "\t");
          swell.WriteLine(WellString.ToString());
        }
        sw.Dispose();

        swell.Dispose();



        //Divide with the number of observations.
        for (int i = 0; i < NLay; i++)
        {
          ME[i] = ME[i] / ObsUsed[i];
          RMSE[i] = Math.Pow(RMSE[i] / ObsUsed[i], 0.5);
        }

        //Write output
        IO.WriteLayers(ME, RMSE, ObsUsed, ObsTotal);

      }

      catch (Exception e)
      {
        MessageBox.Show("An error has occurred in LayerStatistics  " + e.Message);
      }

      finally
      {
        //Dispose MikeShe
        _grid.Dispose();
        _res.Dispose();
      }
		}
Exemple #10
0
        public static void Main(string[] args)
        {
            DFS.DFS3.MaxEntriesInBuffer = 10;
            bool stay = true;

            while (stay)
            {
                stay = false;
                foreach (var v in System.Diagnostics.Process.GetProcesses())
                {
                    if (v.Id != System.Diagnostics.Process.GetCurrentProcess().Id)
                    {
                        if (v.ProcessName.ToLower().StartsWith("ls.exe"))
                        {
                            if (v.UserProcessorTime > TimeSpan.FromSeconds(0.2))
                            {
                                stay = true;
                                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(30));
                                break;
                            }
                        }
                    }
                }
            }

            MikeSheGridInfo _grid = null;
            Results         _res  = null;

            try
            {
                string ObsFileName;

                //Input is a -she-file and an observation file
                if (args.Length == 2)
                {
                    Model MS = new Model(args[0]);
                    _grid       = MS.GridInfo;
                    _res        = MS.Results;
                    ObsFileName = args[1];
                }
                //Input is an .xml-file
                else if (args.Length == 1)
                {
                    Configuration cf = Configuration.ConfigurationFactory(args[0]);

                    _grid = new MikeSheGridInfo(cf.PreProcessedDFS3, cf.PreProcessedDFS2);

                    if (cf.HeadItemText != null)
                    {
                        _res = new Results(cf.ResultFile, _grid, cf.HeadItemText);
                    }
                    else
                    {
                        _res = new Results(cf.ResultFile, _grid);
                    }

                    if (_res.Heads == null)
                    {
                        throw new Exception("Heads could not be found. Check that item: \"" + _res.HeadElevationString + "\" exists in + " + cf.ResultFile);
                    }

                    if (_grid.NumberOfLayers != _res.Heads.TimeData(0).LayerCount)
                    {
                        throw new Exception("Number of layers in preprocessed files do not match number of layers in resultfile: " + cf.ResultFile);
                    }

                    ObsFileName = cf.ObservationFile;
                }
                else
                {
                    OpenFileDialog Ofd = new OpenFileDialog();

                    Ofd.Filter       = "Known file types (*.she)|*.she";
                    Ofd.ShowReadOnly = true;
                    Ofd.Title        = "Select a MikeShe setup file";


                    if (DialogResult.OK == Ofd.ShowDialog())
                    {
                        Model MS = new Model(Ofd.FileName);
                        _grid            = MS.GridInfo;
                        _res             = MS.Results;
                        Ofd.Filter       = "Known file types (*.txt)|*.txt";
                        Ofd.ShowReadOnly = true;
                        Ofd.Title        = "Select a LayerStatistics setup file";

                        if (DialogResult.OK == Ofd.ShowDialog())
                        {
                            ObsFileName = Ofd.FileName;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }

                InputOutput IO = new InputOutput(_grid.NumberOfLayers);

                string _baseOutPutFileName;
                string path     = Path.GetDirectoryName(ObsFileName);
                string FileName = Path.GetFileNameWithoutExtension(ObsFileName);
                _baseOutPutFileName = Path.Combine(path, FileName);


                //Read in the wells
                Dictionary <string, MikeSheWell> Wells = IO.ReadFromLSText(ObsFileName);

                int      NLay     = _grid.NumberOfLayers;
                double[] ME       = new double[NLay];
                double[] RMSE     = new double[NLay];
                int[]    ObsUsed  = new int[NLay];
                int[]    ObsTotal = new int[NLay];

                //Initialiserer
                for (int i = 0; i < NLay; i++)
                {
                    ME[i]       = 0;
                    RMSE[i]     = 0;
                    ObsUsed[i]  = 0;
                    ObsTotal[i] = 0;
                }

                //Only operate on wells within the mikeshe area
                var SelectedWells = _grid.SelectByMikeSheModelArea(Wells.Values);


                StreamWriter sw    = new StreamWriter(_baseOutPutFileName + "_observations.txt");
                StreamWriter swell = new StreamWriter(_baseOutPutFileName + "_wells.txt");

                sw.WriteLine("OBS_ID\tX\tY\tDepth\tLAYER\tOBS_VALUE\tDATO\tSIM_VALUE_INTP\tSIM_VALUE_CELL\tME\tME^2\t#DRY_CELLS\t#BOUNDARY_CELLS\tCOLUMN\tROW\tCOMMENT\t#OBSInWell");
                swell.WriteLine("OBS_ID\tX\tY\tDepth\tLAYER\tME\tME^2");


                //Loops the wells that are within the model area and set the layer or depth
                foreach (MikeSheWell W in SelectedWells)
                {
                    //Get layer or depth
                    if (W.Layer == -3)
                    {
                        W.Layer = _grid.GetLayerFromDepth(W.Column, W.Row, W.Depth.Value);
                    }
                    else
                    {
                        W.Depth = _grid.SurfaceTopography.Data[W.Row, W.Column] - (_grid.LowerLevelOfComputationalLayers.Data[W.Row, W.Column, W.Layer] + 0.5 * _grid.ThicknessOfComputationalLayers.Data[W.Row, W.Column, W.Layer]);
                    }
                }

                System.Diagnostics.Stopwatch swm = new System.Diagnostics.Stopwatch();

                swm.Start();


                foreach (Observation TSE in SelectedWells.Where(var => var.Layer >= 0).SelectMany(var2 => var2.Intakes).SelectMany(var3 => ((LsIntake)var3).Observations).OrderBy(var4 => var4.Time))
                {
                    var M = _res.PhreaticHead.TimeData(TSE.Time)[TSE.Well.Layer];
                    TSE.SimulatedValueCell = M[TSE.Well.Row, TSE.Well.Column];
                    int DryCells      = 0;
                    int BoundaryCells = 0;

                    //Interpolates in the matrix
                    TSE.InterpolatedValue = _grid.Interpolate(TSE.Well.X, TSE.Well.Y, TSE.Well.Layer, M, out DryCells, out BoundaryCells);

                    TSE.DryCells      = DryCells;
                    TSE.BoundaryCells = BoundaryCells;
                }
                swm.Stop();


                //Loops the wells that are within the model area
                foreach (MikeSheWell W in SelectedWells)
                {
                    double MEWell         = 0;
                    double RMSWell        = 0;
                    int    UsedObsInWells = 0;

                    //Calculate results
                    foreach (LsIntake I in W.Intakes)
                    {
                        foreach (Observation TSE in I.Observations.OrderBy(var => var.Time))
                        {
                            StringBuilder ObsString = new StringBuilder();
                            string        Comment   = "";
                            double?       MECell    = null;
                            double?       RMSCell   = null;

                            if (W.Layer < 0)
                            {
                                Comment = "Depth is above the surface or below bottom of the model domain";
                            }
                            else
                            {
                                MECell  = TSE.Value - TSE.InterpolatedValue;
                                RMSCell = Math.Pow(MECell.Value, 2);

                                if (TSE.SimulatedValueCell == _res.DeleteValue)
                                {
                                    Comment = "Cell is dry";
                                }
                                else
                                {
                                    UsedObsInWells++;
                                    MEWell  += MECell.Value;
                                    RMSWell += RMSCell.Value;
                                }
                            }
                            ObsString.Append(W.ID + "\t");
                            ObsString.Append(W.X + "\t");
                            ObsString.Append(W.Y + "\t");
                            ObsString.Append(W.Depth + "\t");

                            if (W.Layer >= 0)
                            {
                                ObsString.Append((_grid.NumberOfLayers - W.Layer) + "\t");
                            }
                            else
                            {
                                ObsString.Append((W.Layer) + "\t");
                            }
                            ObsString.Append(TSE.Value + "\t");
                            ObsString.Append(TSE.Time.ToString("dd-MM-yyyy") + "\t");
                            ObsString.Append(TSE.InterpolatedValue + "\t");
                            ObsString.Append(TSE.SimulatedValueCell + "\t");
                            ObsString.Append(MECell + "\t");
                            ObsString.Append(RMSCell + "\t");
                            ObsString.Append(TSE.DryCells + "\t");
                            ObsString.Append(TSE.BoundaryCells + "\t");
                            ObsString.Append(W.Column + "\t");
                            ObsString.Append(W.Row + "\t");
                            ObsString.Append(Comment + "\t");
                            ObsString.Append(I.Observations.Count);
                            sw.WriteLine(ObsString.ToString());
                        }
                    }

                    if (UsedObsInWells > 0)
                    {
                        MEWell        /= UsedObsInWells;
                        RMSWell       /= UsedObsInWells;
                        ME[W.Layer]   += MEWell;
                        RMSE[W.Layer] += RMSWell;
                        ObsUsed[W.Layer]++;
                    }

                    if (W.Layer >= 0)
                    {
                        ObsTotal[W.Layer]++;
                    }

                    //Write for each well
                    StringBuilder WellString = new StringBuilder();
                    WellString.Append(W.ID + "\t");
                    WellString.Append(W.X + "\t");
                    WellString.Append(W.Y + "\t");
                    WellString.Append(W.Depth + "\t");
                    if (W.Layer >= 0)
                    {
                        WellString.Append((_grid.NumberOfLayers - W.Layer) + "\t");
                        WellString.Append(MEWell + "\t");
                        WellString.Append(RMSWell + "\t");
                    }
                    else
                    {
                        WellString.Append((W.Layer) + "\t" + "\t" + "\t");
                    }
                    swell.WriteLine(WellString.ToString());
                }
                sw.Dispose();

                swell.Dispose();



                //Divide with the number of observations.
                for (int i = 0; i < NLay; i++)
                {
                    ME[i]   = ME[i] / ObsUsed[i];
                    RMSE[i] = Math.Pow(RMSE[i] / ObsUsed[i], 0.5);
                }

                //Write output
                IO.WriteLayers(ME, RMSE, ObsUsed, ObsTotal);
            }

            catch (Exception e)
            {
                MessageBox.Show("An error has occurred in LayerStatistics  " + e.Message);
            }

            finally
            {
                //Dispose MikeShe
                _grid.Dispose();
                _res.Dispose();
            }
        }
Exemple #11
0
        public static void Main(string[] args)
        {
            try
              {
            MikeSheGridInfo _grid = null;
            Results _res = null;
            string ObsFileName;

            //Input is a -she-file and an observation file
            if (args.Length == 2)
            {
              Model MS = new Model(args[0]);
              _grid = MS.GridInfo;
              _res = MS.Results;
              ObsFileName = args[1];
            }
            //Input is an .xml-file
            else if (args.Length == 1)
            {
              Configuration cf = Configuration.ConfigurationFactory(args[0]);

              _grid = new MikeSheGridInfo(cf.PreProcessedDFS3, cf.PreProcessedDFS2);

              if (cf.HeadItemText != null)
            _res = new Results(cf.ResultFile, _grid, cf.HeadItemText);
              else
            _res = new Results(cf.ResultFile, _grid);

              if (_res.Heads == null)
            throw new Exception("Heads could not be found. Check that item: \"" + _res.HeadElevationString + "\" exists in + " + cf.ResultFile);

              ObsFileName = cf.ObservationFile;
            }
            else
            {
              OpenFileDialog Ofd = new OpenFileDialog();

              Ofd.Filter = "Known file types (*.she)|*.she";
              Ofd.ShowReadOnly = true;
              Ofd.Title = "Select a MikeShe setup file";

              if (DialogResult.OK == Ofd.ShowDialog())
              {
            Model MS = new Model(Ofd.FileName);
            _grid = MS.GridInfo;
            _res = MS.Results;
            Ofd.Filter = "Known file types (*.txt)|*.txt";
            Ofd.ShowReadOnly = true;
            Ofd.Title = "Select a LayerStatistics setup file";

            if (DialogResult.OK == Ofd.ShowDialog())
              ObsFileName = Ofd.FileName;
            else
              return;
              }
              else
            return;
            }

            InputOutput IO = new InputOutput(_grid.NumberOfLayers);

            //Read in the wells
            Dictionary<string, MikeSheWell> Wells = IO.ReadFromLSText(ObsFileName);

            int NLay = _grid.NumberOfLayers;
            double [] ME = new double[NLay];
            double [] RMSE = new double[NLay];
            int [] ObsUsed = new int[NLay];
            int [] ObsTotal = new int[NLay];

            //Initialiserer
            for (int i=0;i<NLay;i++)
            {
              ME[i]       = 0;
              RMSE[i]     = 0;
              ObsUsed[i]  = 0;
              ObsTotal[i] = 0;
            }

            //Only operate on wells within the mikeshe area
            var SelectedWells = HeadObservations.SelectByMikeSheModelArea(_grid, Wells.Values);

            //Loops the wells that are within the model area
            foreach (MikeSheWell W in SelectedWells)
            {
              if (W.Layer == -3)
              {

            W.Layer = _grid.GetLayerFromDepth(W.Column, W.Row, W.Depth );
              }
              else
              {
            W.Depth =_grid.SurfaceTopography.Data[W.Row,W.Column]- (_grid.LowerLevelOfComputationalLayers.Data[W.Row, W.Column, W.Layer] + 0.5 * _grid.ThicknessOfComputationalLayers.Data[W.Row, W.Column, W.Layer]);
              }

              //Henter de simulerede værdier

              HeadObservations.GetSimulatedValuesFromGridOutput(_res, _grid, W);

              //Samler resultaterne for hver lag
              foreach (ObservationEntry TSE in W.Intakes.First().Observations)
              {
            if (TSE.SimulatedValueCell == _res.DeleteValue)
            {
                ObsTotal[W.Layer]++;
                TSE.Comment = "Cell is dry";
            }
            else if(TSE.SimulatedValueCell.HasValue)
            {
              ME[W.Layer] += TSE.ME.Value;
              RMSE[W.Layer] += TSE.RMSE.Value;
              ObsUsed[W.Layer]++;
              ObsTotal[W.Layer]++;
            }
              }
            }

            //Divide with the number of observations.
            for (int i=0;i<NLay;i++)
            {
              ME[i]   = ME[i]/ObsUsed[i];
              RMSE[i] = Math.Pow(RMSE[i]/ObsUsed[i], 0.5);
            }

            //Write output
            IO.WriteObservations(SelectedWells);
            IO.WriteLayers(ME,RMSE,ObsUsed,ObsTotal);

            //Dispose MikeShe
            _grid.Dispose();
            _res.Dispose();

              }
              catch (Exception e)
              {
            MessageBox.Show("Der er opstået en fejl af typen: " + e.Message);
              }
        }
        /// <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";
              }
            }
        }
Exemple #13
0
 /// <summary>
 /// Constructs results from .dfs3 file with head data and a GridInfo object. 
 /// This constructor is only to be used by LayerStatistics.
 /// </summary>
 /// <param name="SZ3DFileName"></param>
 /// <param name="Grid"></param>
 public Results(string SZ3DFileName, MikeSheGridInfo Grid)
 {
   _grid = Grid;
   Initialize3DSZ(SZ3DFileName);
 }
Exemple #14
0
 /// <summary>
 /// Use this when the filenames object and the GridInfo object have already been constructed
 /// </summary>
 /// <param name="fileNames"></param>
 /// <param name="Grid"></param>
 internal Results(Model Mshe)
 {
   mshe = Mshe;
   _grid = mshe.GridInfo;
   if (System.IO.File.Exists(Mshe.Files.SZ3DFileName))
   {
     Initialize3DSZ(mshe.Files.SZ3DFileName);
     Initialize3DSZFlow(mshe.Files.SZ3DFlowFileName);
   }
 }
Exemple #15
0
 /// <summary>
 /// Constructs results from .dfs3 file with head data and a GridInfo object. 
 /// This constructor is only to be used by LayerStatistics.
 /// </summary>
 /// <param name="SZ3DFileName"></param>
 /// <param name="Grid"></param>
 public Results(string SZ3DFileName, MikeSheGridInfo Grid, string HeadElevationString)
 {
   this.HeadElevationString = HeadElevationString;
   _grid = Grid;
   Initialize3DSZ(SZ3DFileName);
 }
Exemple #16
0
 /// <summary>
 /// Use this when the filenames object and the GridInfo object have already been constructed
 /// </summary>
 /// <param name="fileNames"></param>
 /// <param name="Grid"></param>
 internal Results(FileNames fileNames, MikeSheGridInfo Grid)
 {
     _grid = Grid;
       Initialize3DSZ(fileNames.Get3DSZFileName);
       Initialize3DSZFlow(fileNames.get3DSZFlowFileName);
 }