Ejemplo n.º 1
0
        public void SetUp()
        {
            Debug.Write("\n Test Fixture Setup... ");

            omiPath = System.IO.Directory.GetCurrentDirectory() + "../../../Data/2dDiffusiveWave.omi";
            //config = System.IO.Directory.GetCurrentDirectory() + "../../../Data/2dDiffusiveWaveConfig.xml";

            omiPath = Path.GetFullPath(omiPath);
            //config = Path.GetFullPath(config);

            wrapper = new DiffusiveWave.Source.Wrapper();

            Debug.WriteLine("done. \n");
        }
Ejemplo n.º 2
0
        public void ComplexTerrain_RefactoredCode(string id, string elevTXT, double nx, double ny, double hw, double InStage)
        {
            //create input argument hashtable
            System.Collections.Hashtable args = BuildArgs(omiPath);
            //set elevation file in omi
            args["SurfaceElevation"] = elevTXT;

            //get xllcorner and yll corner for output file
            StreamReader sr = new StreamReader(elevTXT);
            string line = sr.ReadLine(); line = sr.ReadLine(); line = sr.ReadLine();
            string xllcorner = line; line = sr.ReadLine();
            string yllcorner = line; line = sr.ReadLine(); line = sr.ReadLine();
            string NoData = line;
            sr.Close();
            DiffusiveWave.Source.Wrapper2 wrapper = new DiffusiveWave.Source.Wrapper2(); 
            wrapper.nx = nx;
            wrapper.ny = ny;
            wrapper.hw = hw;
            //Initialize Model
            wrapper.Initialize(args);
            
            //create stage input array
            double[] stage = new double[wrapper.rows * wrapper.cols];
            for (int i = 0; i <= wrapper.rows - 1; i++)
                stage[i * wrapper.cols] = InStage;
            int print_num = 10;
            int print_count = 1;
            bool print = true;
            for (int time = 1; time <= 300; time++)
            {

                //set stage values
                IValueSet Stage = new ScalarSet(stage);
                wrapper.SetValues("Stage", "SmithBranch", Stage);

                //run timestep
                wrapper.PerformTimeStep();

                ScalarSet excess = (ScalarSet)wrapper.GetValues("Excess Rainfall", "Smith Branch");

                //get number of rows and cols, assuming a square matrix
                int elem = Convert.ToInt32(Math.Sqrt(Convert.ToDouble(excess.Count)));
                if (print_count == print_num)
                    print = true;

                if (print)
                {
                    //create output file and write some header data
                    StreamWriter sw = new StreamWriter("../../Data/model_output/" + id + "_" + (time * wrapper.GetTimeStep()).ToString("F2") + ".txt", false);
                    sw.WriteLine("ncols         " + wrapper.cols);
                    sw.WriteLine("nrows         " + wrapper.rows);
                    sw.WriteLine(xllcorner);
                    sw.WriteLine(yllcorner);
                    sw.WriteLine("cellsize      " + wrapper._cellsize);
                    sw.WriteLine(NoData);

                    //Write the output results to the screen
                    //Debug.WriteLine("Excess Rainfall Results");
                    Queue<double> s = new Queue<double>(stage);
                    double sum = 0;
                    //int k=0;
                    int c = 1;
                    for (int i = 0; i <= excess.Count - 1; i++)
                    {
                        //string value = (excess.data[i] + wrapper._elevation[k,i - k*wrapper._elevation.GetLength(1)]).ToString("F7");
                        string value = excess.data[i].ToString("F7");

                        if (excess.data[i] == 0)
                            value = "-9999";

                        //Debug.Write(value + "\t\t");
                        sw.Write(value + " ");

                        if (c == wrapper.cols)
                        {
                            //write a new line
                            //Debug.Write("\n");
                            sw.Write("\n");
                            //reset c
                            c = 1;
                        }
                        else
                        {
                            c++;
                        }

                        sum += excess.data[i];

                    }                
                    sw.Close();
                    if(time != 1)
                        print_count = 1;
                    print = false;
                }
                Debug.WriteLine("Time Step " + (time).ToString() + " completed...");
                print_count++;
            }
            //Teardown the component
            wrapper = null;
            Debug.WriteLine("\n--------------------------------------------");
            Debug.WriteLine("Stage Input Test has completed successfully");
        }
Ejemplo n.º 3
0
        public void ComplexTerrain(string id, string elevTXT, double nx, double ny, double hw, double InStage)
        {
            //create input argument hashtable
            System.Collections.Hashtable args = BuildArgs(omiPath);
            //set elevation file in omi
            args["SurfaceElevation"] = elevTXT;

            //get xllcorner and yll corner for output file
            StreamReader sr = new StreamReader(elevTXT);
            string line = sr.ReadLine(); line = sr.ReadLine(); line = sr.ReadLine();
            string xllcorner = line; line = sr.ReadLine();
            string yllcorner = line;line = sr.ReadLine();line = sr.ReadLine();
            string NoData = line;
            sr.Close();

            wrapper.nx = nx;
            wrapper.ny = ny;
            wrapper.hw = hw;
            //Initialize Model
            wrapper.Initialize(args);

            //create stage input array
            double[] stage = new double[wrapper._sox.GetLength(0) * wrapper._sox.GetLength(1)];
            for (int i = 0; i <= wrapper._sox.GetLength(0)-1; i++)
                stage[i * wrapper._sox.GetLength(0)] = InStage;

            for (int time = 1; time <= 2; time++)
            {

                //set stage values
                IValueSet Stage = new ScalarSet(stage);
                wrapper.SetValues("Stage", "SmithBranch", Stage);

                //run timestep
                wrapper.PerformTimeStep();

                ScalarSet excess = (ScalarSet)wrapper.GetValues("Excess Rainfall", "Smith Branch");

                //get number of rows and cols, assuming a squar matrix
                int elem = Convert.ToInt32(Math.Sqrt(Convert.ToDouble(excess.Count)));

                //create output file and write some header data
                StreamWriter sw = new StreamWriter(id + "_" + time*wrapper.GetTimeStep() + ".txt", false);
                sw.WriteLine("ncols         " + wrapper._sox.GetLength(1));
                sw.WriteLine("nrows         " + wrapper._sox.GetLength(0));
                sw.WriteLine(xllcorner);
                sw.WriteLine(yllcorner);
                sw.WriteLine("cellsize      " + wrapper._cellsize);
                sw.Write(NoData);

                //Write the output results to the screen
                Debug.WriteLine("Excess Rainfall Results");
                Queue<double> s = new Queue<double>(stage);
                double sum = 0;
                int c = 1 ;
                for (int i = 0; i <= excess.Count - 1; i++)
                {
                    string value = excess.data[i].ToString("F7");

                    if (excess.data[i] == 0)
                        value = "-9999";

                    Debug.Write(value + "\t\t");
                    sw.Write(value + " ");

                    if (c == wrapper._sox.GetLength(1))
                    {
                        //write a new line
                        Debug.Write("\n");
                        sw.Write("\n");
                        //reset c
                        c = 1;
                    }
                    else
                    {
                        c++;
                    }

                    sum += excess.data[i];

                }

                Debug.Write("\nTotal head on floodplain = " + sum.ToString() + ". \n");
                Debug.WriteLine("\nStage Input Test has completed successfully");
                sw.Close();

            }
            //Teardown the component
            wrapper = null;

        }
Ejemplo n.º 4
0
        public void ExcessInput(string id,  string elevTxt, double nx, double ny, double hw, double[] InExcess)
        {
            Debug.WriteLine("\n\n---------------------------------------------------");
            Debug.WriteLine("Running the 'Excess Input' Test, ID: " + id);
            Debug.WriteLine("---------------------------------------------------");


            //get xllcorner and yll corner for output file
            StreamReader sr = new StreamReader(elevTxt);
            string line = sr.ReadLine(); line = sr.ReadLine(); line = sr.ReadLine();
            string xllcorner = line; line = sr.ReadLine();
            string yllcorner = line; line = sr.ReadLine(); line = sr.ReadLine();
            string NoData = line;
            sr.Close();

            //create input argument hashtable
            System.Collections.Hashtable args = BuildArgs(omiPath);

            //set elevation file in omi
            args["SurfaceElevation"] = elevTxt;
            wrapper = new DiffusiveWave.Source.Wrapper();
            wrapper.nx = nx;
            wrapper.ny = ny;
            wrapper.hw = hw;
            //Initialize Model
            wrapper.Initialize(args);

            int num_rows = wrapper._sox.GetLength(0);
            int num_cols = wrapper._sox.GetLength(1);
            double inexcess = 0.001;
            StreamWriter results_output = new StreamWriter("flood_results.csv",false);
            results_output.WriteLine(wrapper._elevation.GetLength(0).ToString() + "," + wrapper._elevation.GetLength(1).ToString());
            for (int time = 1; time <= 3642; time++)
            {
                //inexcess = 0.01 / 3652;
                //double supplied_excess = InExcess[time-1] * num_cols * num_rows;

                //create stage array with values of zero
                double[] stage = new double[wrapper._sox.GetLength(0) * wrapper._sox.GetLength(1)];

                //create excess array
                double[] excess = new double[wrapper._sox.GetLength(0) * wrapper._sox.GetLength(1)];
                for (int i = 0; i <= excess.Length - 1; i++)
                    excess[i] = inexcess;
                    //excess[i] = InExcess[time-1];

                //set excess and stage values
                IValueSet Excess = new ScalarSet(excess);
                wrapper.SetValues("Excess Rainfall", "SmithBranch", Excess);
                IValueSet Stage = new ScalarSet(stage);
                wrapper.SetValues("Stage", "SmithBranch", Stage);

                //run timestep
                wrapper.PerformTimeStep();

                //get result values
                ScalarSet result = (ScalarSet)wrapper.GetValues("Excess Rainfall", "Smith Branch");


                //create output file and write some header data
                //StreamWriter sw = new StreamWriter(id + "_" + time * wrapper.GetTimeStep() + ".txt", false);
                //sw.WriteLine("ncols         " + wrapper._sox.GetLength(1));
                //sw.WriteLine("nrows         " + wrapper._sox.GetLength(0));
                //sw.WriteLine(xllcorner);
                //sw.WriteLine(yllcorner);
                //sw.WriteLine("cellsize      " + wrapper._cellsize);
                //sw.WriteLine(NoData);


                //get number of rows and cols, assuming a squar matrix
                int elem = Convert.ToInt32(Math.Sqrt(Convert.ToDouble(result.Count)));

                //Write the output results to the screen
                Debug.WriteLine("Excess Rainfall Results: current time= " + (time*wrapper._dt).ToString() + "seconds");
                double calculated_excess = 0;

                results_output.WriteLine((time * wrapper._dt).ToString());

                for (int row = 0; row <= num_rows - 1; row++)
                {
                    for (int col = 0; col <= num_cols - 1; col++)
                    {
                        calculated_excess += result.data[row * num_cols + col];

                        string value = null;
                        if (result.data[row * num_cols + col] == 0)
                            value = "-9999";
                        else
                            value = result.data[row * num_cols + col].ToString("F7");


                        //Debug.Write(value + " ");
                        //sw.Write(value + " ");
                        results_output.Write(value + ",");
                    }

                    //Debug.Write("\n");
                    results_output.Write("\n");
                    //if (row != num_rows - 1)
                    //    sw.Write("\n");

                }
                //double initialExcess = InExcess[time-1] * result.Count;
                //Debug.Write("Total excess on floodplain = " + calculated_excess.ToString() + ". Initial excess = " + supplied_excess.ToString());
                //Debug.WriteLine("\n Stage Input Test has completed successfully");
                //Debug.WriteLine("----------");
                //sw.Close();
                inexcess = 0;

            }

            results_output.Close();

            //Teardown the component
            wrapper.Finish();

        }