Exemplo n.º 1
0
        public static NCGrid_Distribution from_file(string title, bool using_full_path)
        {
            string path = Paths.DistributionRepo + "\\" + title + ".dist";

            if (using_full_path)
            {
                path = title;
            }
            string[]  contents   = File.ReadAllLines(path);
            int       length     = contents.Length;
            RBounds2D new_bounds = RBounds2D.fromstring(contents[0]);

            string[] numbers = contents[1].Split(':');
            int      nx, ny;

            if (!(int.TryParse(numbers[1], out nx) && int.TryParse(numbers[3], out ny)))
            {
                throw new Exception("File format error");
            }
            NCGrid_Distribution created = new NCGrid_Distribution(new_bounds, nx, ny);

            for (int q = additional_file_lines; q < contents.Length; q++)
            {
                int qprime = q - additional_file_lines;
                int i      = qprime % nx;
                int j      = (qprime - i) / nx;
                created[i, j] = NCAMRNode.fromstring(contents[q]);
            }
            return(created);
        }
Exemplo n.º 2
0
        public BoundaryConditions(string title, bool using_full_path)
        {
            string path = bc_repo + "//" + title + ".bc";

            if (using_full_path)
            {
                path = title;
            }
            string[] contents = File.ReadAllLines(path);
            bounds = RBounds2D.fromstring(contents[0]);
            if (!(int.TryParse(contents[1].Split(':')[1], out xcount) && int.TryParse(contents[1].Split(':')[3], out ycount)))
            {
                throw new Exception("Error: Improper file format.");
            }
            int px_offset = 3;
            int nx_offset = px_offset + 1 + xcount;
            int py_offset = nx_offset + 1 + xcount;
            int ny_offset = py_offset + 1 + ycount;
            int terminal  = ny_offset + 1 + ycount;

            positive_x_vals = new double[xcount];
            positive_y_vals = new double[xcount];
            negative_x_vals = new double[ycount];
            negative_y_vals = new double[ycount];
            positive_x      = ConditionTypeFromString(contents[px_offset - 1].Split(':')[1]);
            negative_x      = ConditionTypeFromString(contents[nx_offset - 1].Split(':')[1]);
            positive_y      = ConditionTypeFromString(contents[py_offset - 1].Split(':')[1]);
            negative_y      = ConditionTypeFromString(contents[ny_offset - 1].Split(':')[1]);
            for (int i = px_offset; i < nx_offset - 1; i++)
            {
                double z;
                if (!double.TryParse(contents[i], out z))
                {
                    throw new Exception("Error: Improper file format");
                }
                positive_x_vals[i - px_offset] = z;
            }
            for (int i = nx_offset; i < py_offset - 1; i++)
            {
                double z;
                if (!double.TryParse(contents[i], out z))
                {
                    throw new Exception("Error: Improper file format");
                }
                negative_x_vals[i - nx_offset] = z;
            }
            for (int i = py_offset; i < ny_offset - 1; i++)
            {
                double z;
                if (!double.TryParse(contents[i], out z))
                {
                    throw new Exception("Error: Improper file format");
                }
                positive_y_vals[i - py_offset] = z;
            }
            for (int i = ny_offset; i < terminal - 1; i++)
            {
                double z;
                if (!double.TryParse(contents[i], out z))
                {
                    throw new Exception("Error: Improper file format");
                }
                negative_y_vals[i - ny_offset] = z;
            }
        }