Ejemplo n.º 1
0
        public void ExtractTimeSeries(HeadObservation[] wells, MatrixCube <float> arrayCube, DateTime start, int DayInteval)
        {
            int nwell = wells.Length;
            //compute monthly averaged value, thus divided by 3
            int nl = arrayCube.Layer;

            int[] ids = new int[nwell];
            for (int i = 0; i < nwell; i++)
            {
                ids[i] = mfgrid.Topology.ActiveCellIndex[wells[i].CellID];
                DateTime[] dates = new DateTime[nl];
                for (int l = 0; l < nl; l++)
                {
                    dates[l] = start.AddDays(l * DayInteval);
                }
                double[] values = new double[nl];
                wells[i].TimeSeries = new NumericalTimeSeries(values, dates);
            }
            for (int l = 0; l < nl; l++)
            {
                for (int i = 0; i < nwell; i++)
                {
                    wells[i].TimeSeries.DataValueVector[l] = arrayCube.LayeredSerialValue[l][ids[i]];
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// write matrix in the type of Constant or Matrix using given format
        /// </summary>
        /// <param name="sw"></param>
        /// <param name="matrix"></param>
        /// <param name="multiplier"></param>
        /// <param name="clayer"></param>
        /// <param name="format"></param>
        /// <param name="iprn"></param>
        /// <param name="comment"></param>
        public static void WriteInternalMatrix(StreamWriter sw, MatrixCube <float> matrix, float multiplier, int clayer, string format, int iprn, string comment)
        {
            if (matrix.IsConstant[clayer])
            {
                string line = string.Format("CONSTANT\t{0}\t{1}", matrix.LayeredConstantValues[clayer], comment);
                sw.WriteLine(line);
            }
            else
            {
                string line = string.Format("INTERNAL\t{0}\t(FREE)\t{1}\t{2}", multiplier, iprn, comment);
                int    row  = matrix.Row;
                int    col  = matrix.Column;

                sw.WriteLine(line);

                for (int r = 0; r < row; r++)
                {
                    line = "";
                    for (int c = 0; c < col; c++)
                    {
                        line += matrix.LayeredValues[clayer][r, c].ToString(format) + StreamReaderSequence.stab;
                    }
                    line = line.Trim(StreamReaderSequence.ctab);
                    sw.WriteLine(line);
                }
            }
        }
Ejemplo n.º 3
0
        public float ExtractPointValue(HeadObservation obs, MatrixCube <float> arrayCube, int step)
        {
            float value = 0;
            int   ids   = mfgrid.Topology.ActiveCellIndex[obs.CellID];

            value = arrayCube.LayeredSerialValue[step][ids];
            return(value);
        }
Ejemplo n.º 4
0
        public Grid(int rowN, int colNum, Envelope bbox)
        {
            BBox        = bbox;
            RowCount    = rowN;
            ColumnCount = colNum;
            float ri = (float)bbox.Height / RowCount;
            float ci = (float)bbox.Width / ColumnCount;

            RowInteval = new MatrixCube <float>(1);
            ColInteval = new MatrixCube <float>(1);
            RowInteval.LayeredValues[0] = new float[1, rowN];
            ColInteval.LayeredValues[0] = new float[1, colNum];

            for (int i = 0; i < rowN; i++)
            {
                RowInteval.LayeredValues[0][0, i] = ri;
            }
            for (int i = 0; i < colNum; i++)
            {
                ColInteval.LayeredValues[0][0, i] = ci;
            }
        }
Ejemplo n.º 5
0
        public static void WriteSerialArray <T>(StreamWriter sw, MatrixCube <T> matrix, T multiplier, MFGrid grid, int clayer, int iprn, string comment)
        {
            if (matrix.IsConstant[clayer])
            {
                string line = string.Format("CONSTANT\t{0}\t{1}", matrix.LayeredConstantValues[clayer], comment);
                sw.WriteLine(line);
            }
            else
            {
                string line = string.Format("INTERNAL\t{0}\t(FREE)\t{1}\t{2}", multiplier, iprn, comment);
                int    row  = grid.RowCount;
                int    col  = grid.ColumnCount;

                sw.WriteLine(line);
                int index = 0;

                for (int r = 0; r < row; r++)
                {
                    line = "";
                    for (int c = 0; c < col; c++)
                    {
                        if (grid.IBound.LayeredValues[0][r, c] != 0)
                        {
                            line += matrix.LayeredSerialValue[clayer][index] + StreamReaderSequence.stab;
                            index++;
                        }
                        else
                        {
                            line += "0" + StreamReaderSequence.stab;
                        }
                    }
                    line = line.Trim(StreamReaderSequence.ctab);
                    sw.WriteLine(line);
                }
            }
        }
Ejemplo n.º 6
0
        public static void ReadInternalMatrix <T>(StreamReader sr, MatrixCube <T> matrix, int row, int col, int cLayer)
        {
            string line = sr.ReadLine().ToUpper();
            var    strs = TypeConverterEx.Split <string>(line);

            // Read constant matrix
            if (strs[0].ToUpper() == "CONSTANT")
            {
                var ar   = TypeConverterEx.Split <string>(line);
                T   conv = TypeConverterEx.ChangeType <T>(ar[1]);
                matrix.LayeredConstantValues[cLayer] = conv;
                matrix.IsConstant[cLayer]            = true;
            }
            // Read internal matrix
            else
            {
                matrix.LayeredValues[cLayer] = new T[row, col];
                matrix.IsConstant[cLayer]    = false;
                T multiplier = TypeConverterEx.ChangeType <T>(strs[1]);
                line = sr.ReadLine();
                var values = TypeConverterEx.Split <T>(line);

                if (values.Length == col)
                {
                    for (int c = 0; c < col; c++)
                    {
                        matrix.LayeredValues[cLayer][0, c] = values[c];// *multiplier;
                    }
                    for (int r = 1; r < row; r++)
                    {
                        line   = sr.ReadLine();
                        values = TypeConverterEx.Split <T>(line);
                        matrix.SetRowVector(values, cLayer, r, col);
                    }
                }
                else
                {
                    int colLine = (int)Math.Ceiling(col / 10.0);
                    for (int r = 0; r < row; r++)
                    {
                        int i = 0;
                        if (r == 0)
                        {
                            i = 1;
                        }
                        else
                        {
                            i    = 0;
                            line = "";
                        }
                        for (; i < colLine; i++)
                        {
                            line += sr.ReadLine() + " ";
                        }

                        values = TypeConverterEx.Split <T>(line);
                        matrix.SetRowVector(values, cLayer, r, col);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static void ReadSerialArray <T>(StreamReader sr, MatrixCube <T> matrix, MFGrid grid, int cLayer)
        {
            string line = sr.ReadLine().ToUpper();
            var    strs = TypeConverterEx.Split <string>(line);

            // Read constant matrix
            if (strs[0].ToUpper() == "CONSTANT")
            {
                var ar   = TypeConverterEx.Split <string>(line);
                T   conv = TypeConverterEx.ChangeType <T>(ar[1]);
                matrix.LayeredConstantValues[cLayer] = conv;
                matrix.IsConstant[cLayer]            = true;
            }
            // Read internal matrix
            else
            {
                matrix.LayeredSerialValue[cLayer] = new T[grid.ActiveCellCount];
                matrix.IsConstant[cLayer]         = false;
                T multiplier = TypeConverterEx.ChangeType <T>(strs[1]);
                line = sr.ReadLine();
                var values = TypeConverterEx.Split <T>(line);
                int col    = grid.ColumnCount;
                int row    = grid.RowCount;

                if (values.Length == col)
                {
                    int index = 0;
                    for (int c = 0; c < col; c++)
                    {
                        if (grid.IBound.LayeredValues[0][0, c] != 0)
                        {
                            matrix.LayeredSerialValue[cLayer][index] = values[c];
                            index++;
                        }
                    }
                    for (int r = 1; r < row; r++)
                    {
                        line   = sr.ReadLine();
                        values = TypeConverterEx.Split <T>(line);
                        for (int c = 0; c < col; c++)
                        {
                            if (grid.IBound.LayeredValues[0][r, c] != 0)
                            {
                                matrix.LayeredSerialValue[cLayer][index] = values[c];
                                index++;
                            }
                        }
                    }
                }
                else
                {
                    int index   = 0;
                    int colLine = (int)Math.Ceiling(col / 10.0);
                    for (int r = 0; r < row; r++)
                    {
                        int i = 0;
                        if (r == 0)
                        {
                            i = 1;
                        }
                        else
                        {
                            i    = 0;
                            line = "";
                        }
                        for (; i < colLine; i++)
                        {
                            line += sr.ReadLine() + " ";
                        }

                        values = TypeConverterEx.Split <T>(line);
                        for (int c = 0; c < col; c++)
                        {
                            if (grid.IBound.LayeredValues[0][r, c] != 0)
                            {
                                matrix.LayeredSerialValue[cLayer][index] = values[c];
                                index++;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public override void Read(string filename = "")
        {
            if (filename == "")
            {
                filename = GetInputFile(this.Name);
            }

            if (File.Exists(filename))
            {
                var grid  = mfgrid;
                int layer = grid.ActualLayerCount;
                var upw   = this;

                layer = 3;

                StreamReader sr = new StreamReader(filename);
                //Data Set 1: # ILPFCB, HDRY, NPLPF
                string  newline = ReadCommet(sr);
                float[] fv      = TypeConverterEx.Split <float>(newline, 4);
                upw.ILPFCB = (short)fv[0];
                upw.HDRY   = fv[1];
                upw.NPLPF  = (short)fv[2];
                upw.IPHDRY = (short)fv[3];
                //Data Set 2: #
                newline    = sr.ReadLine();
                upw.LAYTYP = TypeConverterEx.Split <int>(newline, layer);

                //Data Set 3: #
                newline    = sr.ReadLine();
                upw.LAYAVG = TypeConverterEx.Split <int>(newline, layer);

                //Data Set 4: #
                newline   = sr.ReadLine();
                upw.CHANI = TypeConverterEx.Split <int>(newline, layer);

                //Data Set 5: #
                newline    = sr.ReadLine();
                upw.LAYVKA = TypeConverterEx.Split <int>(newline, layer);

                //Data Set 6: #
                newline    = sr.ReadLine();
                upw.LAYWET = TypeConverterEx.Split <int>(newline, layer);

                //Data Set 7: #
                //grid.LPFProperty.HK = new LayeredMatrix<float>(layer);
                //grid.LPFProperty.HANI = new LayeredMatrix<float>(layer);
                //grid.LPFProperty.VKA = new LayeredMatrix<float>(layer);
                //grid.LPFProperty.SS = new LayeredMatrix<float>(layer);
                //grid.LPFProperty.SY = new LayeredMatrix<float>(layer);

                var hania = new float[layer];
                MatrixExtension <float> .Set(hania, 1);

                var hk     = new MatrixCube <float>(layer);
                var hani   = new MatrixCube <float>(layer);
                var vka    = new MatrixCube <float>(layer);
                var ss     = new MatrixCube <float>(layer);
                var sy     = new MatrixCube <float>(layer);
                var wetdry = new MatrixCube <float>(layer);

                Parameters["HK"].Value     = hk;
                Parameters["HANI"].Value   = hani;
                Parameters["VKA"].Value    = vka;
                Parameters["SS"].Value     = ss;
                Parameters["SY"].Value     = sy;
                Parameters["WETDRY"].Value = wetdry;

                for (int l = 0; l < layer; l++)
                {
                    ReadInternalMatrix(sr, hk, grid.RowCount, grid.ColumnCount, l);
                    ReadInternalMatrix(sr, hani, grid.RowCount, grid.ColumnCount, l);
                    ReadInternalMatrix(sr, vka, grid.RowCount, grid.ColumnCount, l);
                    ReadInternalMatrix(sr, ss, grid.RowCount, grid.ColumnCount, l);
                    if (upw.LAYTYP[l] != 0)
                    {
                        ReadInternalMatrix(sr, sy, grid.RowCount, grid.ColumnCount, l);
                    }
                }
                sr.Close();
            }
        }
Ejemplo n.º 9
0
        public override void Load(object[] para)
        {
            if (para == null)
            {
                return;
            }
            var dt_domain = DotSpatial.Data.FeatureSet.Open(para[0].ToString()).DataTable;
            var dt_grid   = DotSpatial.Data.FeatureSet.Open(para[1].ToString()).DataTable;

            dt_grid.DefaultView.Sort = para[2].ToString();
            string hkField = para[3].ToString();

            int[] ty = new int[] { 1, 1, 0, 0, 0 };

            DataRow dr = dt_domain.Rows[0];

            Parameters["LAYTYP"].Value = TypeConverterEx.Split <int>(dr["LAYTYP"].ToString());
            Parameters["LAYTYP"].Value = ty;
            Parameters["LAYAVG"].Value = TypeConverterEx.Split <int>(dr["LAYAVG"].ToString());
            Parameters["CHANI"].Value  = TypeConverterEx.Split <int>(dr["CHANI"].ToString());
            Parameters["LAYVKA"].Value = TypeConverterEx.Split <int>(dr["LAYVKA"].ToString());
            Parameters["LAYWET"].Value = TypeConverterEx.Split <int>(dr["LAYWET"].ToString());
            int layer = int.Parse(dr["NLayer"].ToString());
            var hania = new float[layer];

            MatrixExtension <float> .Set(hania, 1);

            var hk     = new MatrixCube <float>(layer);
            var hani   = new MatrixCube <float>(hania);
            var vka    = new MatrixCube <float>(layer);
            var ss     = new MatrixCube <float>(layer);
            var sy     = new MatrixCube <float>(layer);
            var wetdry = new MatrixCube <float>(layer);

            Parameters["HK"].Value     = hk;
            Parameters["HANI"].Value   = hani;
            Parameters["VKA"].Value    = vka;
            Parameters["SS"].Value     = ss;
            Parameters["SY"].Value     = sy;
            Parameters["WETDRY"].Value = wetdry;

            for (int l = 0; l < mfgrid.ActualLayerCount; l++)
            {
                hk.LayeredValues[l]  = new float[mfgrid.RowCount, mfgrid.ColumnCount];
                vka.LayeredValues[l] = new float[mfgrid.RowCount, mfgrid.ColumnCount];
                ss.LayeredValues[l]  = new float[mfgrid.RowCount, mfgrid.ColumnCount];
                if (Parameters["LAYTYP"].IntValues[l] != 0)
                {
                    sy.LayeredValues[l] = new float[mfgrid.RowCount, mfgrid.ColumnCount];
                }
                if (Parameters["LAYTYP"].IntValues[l] != 0 && Parameters["LAYWET"].IntValues[l] != 0)
                {
                    wetdry.LayeredValues[l] = new float[mfgrid.RowCount, mfgrid.ColumnCount];
                }
            }

            int i = 0;

            foreach (var ac in mfgrid.Topology.ActiveCellLocation.Values)
            {
                hk.LayeredValues[0][ac[0], ac[1]] = (float)dt_grid.Rows[i][hkField];
                i++;
            }
            CreateUnifiedLPF();
        }