예제 #1
0
    private static void Main(string[] args)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for TET_MESH_TET_NEIGHBORS.
    //
    //  Discussion:
    //
    //    TET_MESH_TET_NEIGHBORS manages the tet mesh neighbor calculation.
    //
    //    A tet mesh of order 4 or order 10 may be used.
    //
    //  Usage:
    //
    //    tet_mesh_tet_neighbors prefix
    //
    //    where prefix is the common file prefix:
    //
    //    * prefix_nodes.txt,    the node coordinates (not needed by this program);
    //    * prefix_elements.txt,    the linear element definitions.
    //    * prefix_element_neighbors.txt, the element neighbors.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 September 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int node_num = 0;
        string    prefix;

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_TET_NEIGHBORS");
        Console.WriteLine("  Read a tet mesh dataset of TETRA_NUM");
        Console.WriteLine("  tetrahedrons, using 4 or 10 nodes.");
        Console.WriteLine("");
        Console.WriteLine("  Compute the tet mesh neighbors, and write this");
        Console.WriteLine("  information to a file");
        Console.WriteLine("");
        //
        //  Get the filename prefix.
        //
        try
        {
            prefix = args[0];
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_TET_NEIGHBORS:");
            Console.WriteLine("  Please enter the filename prefix.");

            prefix = Console.ReadLine();
        }

        //
        //  Create the filenames.
        //
        string element_filename  = prefix + "_elements.txt";
        string neighbor_filename = prefix + "_element_neighbors.txt";
        //
        //  Read the tet mesh data.
        //
        TableHeader h             = typeMethods.i4mat_header_read(element_filename);
        int         element_order = h.m;
        int         element_num   = h.n;

        if (element_order != 4 && element_order != 10)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_TET_NEIGHBORS - Fatal error!");
            Console.WriteLine("  The tet mesh must have order 4 or order 10.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + element_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Tetrahedron order = " + element_order + "");
        Console.WriteLine("  Number of tetras  = " + element_num + "");

        int[] element_node = typeMethods.i4mat_data_read(element_filename, element_order,
                                                         element_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + element_filename + "\".");

        typeMethods.i4mat_transpose_print_some(element_order, element_num,
                                               element_node, 1, 1, element_order, 5, "  First 5 tetrahedrons:");
        //
        //  Detect and correct 1-based node indexing.
        //
        TetMesh.tet_mesh_base_zero(node_num, element_order, element_num, ref element_node);
        //
        //  Compute the neighbor information.
        //
        int[] element_neighbor = TetMesh_Neighbors.tet_mesh_neighbor_tets(element_order, element_num,
                                                                          element_node);

        typeMethods.i4mat_transpose_print_some(4, element_num,
                                               element_neighbor, 1, 1, 4, 5, "  First 5 neighbor sets:");
        //
        //  Write the neighbor information to a file.
        //
        typeMethods.i4mat_write(neighbor_filename, 4, element_num, element_neighbor);

        Console.WriteLine("");
        Console.WriteLine("  Created the file \"" + neighbor_filename + "\".");

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_TET_NEIGHBORS:");
        Console.WriteLine("  Normal end of execution.");

        Console.WriteLine("");
    }
예제 #2
0
    private static void Main(string[] args)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for TET_MESH_REFINE.
    //
    //  Discussion:
    //
    //    TET_MESH_REFINE refines a tetrahedral mesh of order 4 (linear).
    //
    //  Usage:
    //
    //    tet_mesh_refine prefix
    //
    //    where prefix is the common file prefix:
    //
    //    * prefix_nodes.txt,    the node coordinates;
    //    * prefix_elements.txt,    the element definitions.
    //    * prefix_ref_nodes.txt,    the new node coordinates;
    //    * prefix_ref_elements.txt,    the new element definitions.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 August 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int[] element_node2 = new int[1];
        int   element_num2  = 0;
        int   node_num2     = 0;

        double[] node_xyz2 = new double[1];
        string   prefix;

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_REFINE");
        Console.WriteLine("  READ a tet mesh, REFINE it, and WRITE the new data.");
        Console.WriteLine("");
        Console.WriteLine("  READ:");
        Console.WriteLine("    a node dataset of NODE_NUM1 points in 3 dimensions.");
        Console.WriteLine("    a tet mesh of TETRA_NUM1 tets of order TET_ORDER.");
        Console.WriteLine("");
        Console.WriteLine("  REFINE:");
        Console.WriteLine("    compute a new set of nodes and tets, which is an");
        Console.WriteLine("    eightfold refinement of the input mesh.");
        Console.WriteLine("");
        Console.WriteLine("  WRITE:");
        Console.WriteLine("    a node dataset of NODE_NUM2 points in 3 dimensions.");
        Console.WriteLine("    a tet mesh of 8*TETRA_NUM1 tets of order TET_ORDER.");
        Console.WriteLine("");
        Console.WriteLine("  At the moment, this program only works for a linear");
        Console.WriteLine("  mesh (TET_ORDER=4).");
        Console.WriteLine("");
        //
        //  Get the filename prefix.
        //
        try
        {
            prefix = args[0];
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_REFINE:");
            Console.WriteLine("  Please enter the filename prefix.");

            prefix = Console.ReadLine();
        }

        //
        //  Create the filenames.
        //
        string input_node_filename     = prefix + "_nodes.txt";
        string input_element_filename  = prefix + "_elements.txt";
        string output_node_filename    = prefix + "_ref_nodes.txt";
        string output_element_filename = prefix + "_ref_elements.txt";
        //
        //  Read the node data.
        //
        TableHeader h         = typeMethods.r8mat_header_read(input_node_filename);
        int         dim_num   = h.m;
        int         node_num1 = h.n;

        if (dim_num != 3)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_REFINE - Fatal error!");
            Console.WriteLine("  The spatial dimension must be 3.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + input_node_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Spatial dimension = " + dim_num + "");
        Console.WriteLine("  Number of nodes   = " + node_num1 + "");

        double[] node_xyz1 = typeMethods.r8mat_data_read(input_node_filename, dim_num,
                                                         node_num1);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + input_node_filename + "\".");

        typeMethods.r8mat_transpose_print_some(dim_num, node_num1,
                                               node_xyz1, 1, 1, dim_num, 5, "  First 5 input nodes:");
        //
        //  Read the tet mesh data.
        //
        h = typeMethods.i4mat_header_read(input_element_filename);
        int element_order = h.m;
        int element_num1  = h.n;

        switch (element_order)
        {
        case 4:
            break;

        case 10:
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_REFINE - Fatal error!");
            Console.WriteLine("  The program cannot yet handel the 10-node case.");
            Console.WriteLine("  Try using the sequence:");
            Console.WriteLine("    TET_MESH_Q2L --> TET_MESH_REFINE --> TET_MESH_L2Q.");
            return;

        default:
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_REFINE - Fatal error!");
            Console.WriteLine("  The tet mesh must have order 4 or order 10.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + input_element_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Tetrahedron order = " + element_order + "");
        Console.WriteLine("  Number of tetras  = " + element_num1 + "");

        int[] element_node1 = typeMethods.i4mat_data_read(input_element_filename, element_order,
                                                          element_num1);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + input_element_filename + "\".");

        typeMethods.i4mat_transpose_print_some(element_order, element_num1,
                                               element_node1, 1, 1, element_order, 5, "  First 5 input tetrahedrons:");
        //
        //  Check for 1-based node-indexing, and convert it to 0-based.
        //
        TetMesh.tet_mesh_base_zero(node_num1, element_order, element_num1, ref element_node1);
        switch (element_order)
        {
        //
        //  Compute the refined mesh.
        //
        case 4:
            int[] edge_data = new int[5 * 6 * element_num1];

            TetMesh_Refine.tet_mesh_order4_refine_size(node_num1, element_num1, element_node1,
                                                       ref node_num2, ref element_num2, ref edge_data);

            Console.WriteLine("  Number of refined nodes =  " + node_num2 + "");
            Console.WriteLine("  Number of refined tetras = " + element_num2 + "");

            node_xyz2     = new double[dim_num * node_num2];
            element_node2 = new int[element_order * element_num2];

            TetMesh_Refine.tet_mesh_order4_refine_compute(node_num1, element_num1, node_xyz1,
                                                          element_node1, node_num2, element_num2, edge_data, ref node_xyz2, ref element_node2);
            break;

        case 10:
        {
            break;
        }
        }

        //
        //  Print a small amount of the refined data.
        //
        typeMethods.r8mat_transpose_print_some(dim_num, node_num2, node_xyz2,
                                               1, 1, dim_num, 5, "  First 5 output nodes:");

        typeMethods.i4mat_transpose_print_some(element_order, element_num2, element_node2,
                                               1, 1, element_order, 5, "  First 5 output tetras");
        //
        //  Write out the node and tetra data for the refined mesh
        //
        typeMethods.r8mat_write(output_node_filename, dim_num, node_num2, node_xyz2);

        Console.WriteLine("");
        Console.WriteLine("  Wrote the file \"" + output_node_filename + "\".");

        typeMethods.i4mat_write(output_element_filename, element_order, element_num2, element_node2);

        Console.WriteLine("  Wrote the file \"" + output_element_filename + "\".");

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_REFINE:");
        Console.WriteLine("  Normal end of execution.");

        Console.WriteLine("");
    }
예제 #3
0
    private static void Main(string[] args)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for TET_MESH_L2Q.
    //
    //  Discussion:
    //
    //    TET_MESH_L2Q makes a quadratic tet mesh from a linear one.
    //
    //  Usage:
    //
    //    tet_mesh_l2q prefix
    //
    //    where prefix is the common file prefix:
    //
    //    * prefix_nodes.txt,    the node coordinates;
    //    * prefix_elements.txt,    the linear element definitions.
    //    * prefix_l2q_nodes.txt, the quadratic node coordinates,
    //    * prefix_l2q_elements.txt,    the quadratic element definitions.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 October 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int element_order2 = 10;
        int       node_num2      = 0;
        string    prefix;

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_L2Q");
        Console.WriteLine("  Read a \"linear\" tet mesh and");
        Console.WriteLine("  write out a \"quadratic\" one.");
        Console.WriteLine("");
        Console.WriteLine("  Read a node file of NODE_NUM1 nodes in 3 dimensions.");
        Console.WriteLine("  Read an associated tet mesh of TETRA_NUM");
        Console.WriteLine("  tetrahedrons, using 4 nodes per tetrahedron.");
        Console.WriteLine("");
        Console.WriteLine("  Create new nodes which are midpoints of sides,");
        Console.WriteLine("  generate new node and tet mesh data for");
        Console.WriteLine("  quadratic 10-node tetrahedrons, and write them out.");
        Console.WriteLine("");
        //
        //  Get the filename prefix.
        //
        try
        {
            prefix = args[0];
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_L2Q:");
            Console.WriteLine("  Please enter the filename prefix.");

            prefix = Console.ReadLine();
        }

        //
        //  Create the filenames.
        //
        string input_node_filename     = prefix + "_nodes.txt";
        string input_element_filename  = prefix + "_elements.txt";
        string output_node_filename    = prefix + "_l2q_nodes.txt";
        string output_element_filename = prefix + "_l2q_elements.txt";
        //
        //  Read the node data.
        //
        TableHeader h         = typeMethods.r8mat_header_read(input_node_filename);
        int         dim_num   = h.m;
        int         node_num1 = h.n;

        if (dim_num != 3)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_L2Q - Fatal error!");
            Console.WriteLine("  The spatial dimension must be 3.");
            Console.WriteLine("  This data has dimension = " + dim_num + "");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + input_node_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Spatial dimension = " + dim_num + "");
        Console.WriteLine("  Number of nodes   = " + node_num1 + "");

        double[] node_xyz1 = typeMethods.r8mat_data_read(input_node_filename, dim_num,
                                                         node_num1);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + input_node_filename + "\".");

        typeMethods.r8mat_transpose_print_some(dim_num, node_num1,
                                               node_xyz1, 1, 1, dim_num, 5, "  First 5 nodes:");
        //
        //  Read the tet mesh data.
        //
        h = typeMethods.i4mat_header_read(input_element_filename);
        int element_order1 = h.m;
        int element_num    = h.n;

        if (element_order1 != 4)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_L2Q - Fatal error!");
            Console.WriteLine("  The tet mesh must have order 4.");
            Console.WriteLine("  This mesh has order " + element_order1 + "");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + input_element_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Tetrahedron order = " + element_order1 + "");
        Console.WriteLine("  Number of tetras  = " + element_num + "");

        int[] element_node1 = typeMethods.i4mat_data_read(input_element_filename, element_order1,
                                                          element_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + input_element_filename + "\".");

        typeMethods.i4mat_transpose_print_some(element_order1, element_num,
                                               element_node1, 1, 1, element_order1, 5, "  First 5 tetrahedrons:");
        //
        //  If the element information is 1-based, make it 0-based.
        //
        TetMesh.tet_mesh_base_zero(node_num1, element_order1, element_num, ref element_node1);
        //
        //  Compute the quadratic mesh.
        //
        int[] edge_data = new int[5 * 6 * element_num];

        TetMesh_L2Q.tet_mesh_order4_to_order10_size(element_num, element_node1, node_num1,
                                                    ref edge_data, ref node_num2);

        Console.WriteLine("  Number of quadratic nodes = " + node_num2 + "");

        double[] node_xyz2     = new double[dim_num * node_num2];
        int[]    element_node2 = new int[element_order2 * element_num];

        TetMesh_L2Q.tet_mesh_order4_to_order10_compute(element_num, element_node1, node_num1,
                                                       node_xyz1, edge_data, ref element_node2, node_num2, ref node_xyz2);
        //
        //  Print a small amount of the quadratic data.
        //
        typeMethods.r8mat_transpose_print_some(dim_num, node_num2, node_xyz2,
                                               1, 1, dim_num, 5, "  First 5 quadratic nodes:");

        typeMethods.i4mat_transpose_print_some(element_order2, element_num, element_node2,
                                               1, 1, element_order2, 5, "  First 5 quadratic tetras");
        //
        //  Write out the node and tetra data for the quadratic mesh
        //
        typeMethods.r8mat_write(output_node_filename, dim_num, node_num2, node_xyz2);

        Console.WriteLine("");
        Console.WriteLine("  Wrote the file \"" + output_node_filename + "\".");

        typeMethods.i4mat_write(output_element_filename, element_order2, element_num, element_node2);

        Console.WriteLine("  Wrote the file \"" + output_element_filename + "\".");

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_L2Q:");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }
예제 #4
0
    private static void Main(string[] args)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for TET_MESH_RCM.
    //
    //  Discussion:
    //
    //    TET_MESH_RCM applies the RCM reordering to a tet mesh.
    //
    //    The user supplies a node file and a tetrahedron file, containing
    //    the coordinates of the nodes, and the indices of the nodes that
    //    make up each tetrahedron.  Either 4-node or 10-node tetrahedrons may
    //    be used.
    //
    //    The program reads the data, computes the adjacency information,
    //    carries out the RCM algorithm to get the permutation, applies
    //    the permutation to the nodes and tetrahedrons, and writes out
    //    new node and tetrahedron files that correspond to the RCM permutation.
    //
    //    Note that node data is normally three dimensional, that is,
    //    each node has an X, Y and Z coordinate.  In some applications, it
    //    may be desirable to specify more information.  This program
    //    will accept node data that includes DIM_NUM entries on each line,
    //    as long as DIM_NUM is the same for each entry.
    //
    //    Thanks to Xingxing Zhang for pointing out some problems with a
    //    previous version of this program, 10 May 2011.
    //
    //  Usage:
    //
    //    tet_mesh_rcm prefix
    //
    //    where prefix is the common file prefix:
    //
    //    * prefix_nodes.txt,           the node coordinates (input);
    //    * prefix_elements.txt,        the element definitions (input).
    //    * prefix_rcm_nodes.txt,       the new node coordinates (output);
    //    * prefix_rcm_elements.txt,    the new element definitions (output).
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    08 March 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int[] adj     = new int[1];
        int   adj_num = 0;

        int[]      adj_row = new int[1];
        const bool debug   = false;
        int        i;
        int        j;
        string     prefix;

        Console.WriteLine("");

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_RCM");
        Console.WriteLine("  Read a node dataset of NODE_NUM points in 3 dimensions.");
        Console.WriteLine("  Read an associated tet mesh dataset of TETRA_NUM");
        Console.WriteLine("  tetrahedrons using 4 or 10 nodes.");
        Console.WriteLine("");
        Console.WriteLine("  Apply the RCM reordering (Reverse Cuthill-McKee).");
        Console.WriteLine("");
        Console.WriteLine("  Reorder the data and write it out to files.");
        Console.WriteLine("");
        //
        //  Get the filename prefix.
        //
        try
        {
            prefix = args[0];
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_RCM:");
            Console.WriteLine("  Please enter the filename prefix.");

            prefix = Console.ReadLine();
        }

        //
        //  Create the filenames.
        //
        string node_filename        = prefix + "_nodes.txt";
        string element_filename     = prefix + "_elements.txt";
        string node_rcm_filename    = prefix + "_rcm_nodes.txt";
        string element_rcm_filename = prefix + "_rcm_elements.txt";
        //
        //  Read the node data.
        //
        TableHeader h        = typeMethods.r8mat_header_read(node_filename);
        int         dim_num  = h.m;
        int         node_num = h.n;

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + node_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Spatial dimension DIM_NUM =  " + dim_num + "");
        Console.WriteLine("  Number of points NODE_NUM  = " + node_num + "");

        double[] node_xyz = typeMethods.r8mat_data_read(node_filename, dim_num, node_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + node_filename + "\".");

        typeMethods.r8mat_transpose_print_some(dim_num, node_num, node_xyz, 1, 1, dim_num, 5,
                                               "  Coordinates of first 5 nodes:");
        //
        //  Read the tet mesh data.
        //
        h = typeMethods.i4mat_header_read(element_filename);
        int element_order = h.m;
        int element_num   = h.n;

        if (element_order != 4 && element_order != 10)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_RCM - Fatal error!");
            Console.WriteLine("  The tet mesh must have order 4 or order 10.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + element_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Tetrahedron order = " + element_order + "");
        Console.WriteLine("  Number of tetras  = " + element_num + "");

        int[] element_node = typeMethods.i4mat_data_read(element_filename, element_order,
                                                         element_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + element_filename + "\".");

        typeMethods.i4mat_transpose_print_some(element_order, element_num,
                                               element_node, 1, 1, element_order, 5, "  First 5 tetrahedrons:");
        //
        //  If the element information is 1-based, make it 0-based.
        //
        int base_user = TetMesh.tet_mesh_base_zero(node_num, element_order,
                                                   element_num, ref element_node);

        if (base_user != 0 && base_user != 1)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_RCM - Fatal error!");
            Console.WriteLine("  The input data does not seem to be 0-based or 1-based.");
        }

        switch (element_order)
        {
        //
        //  Following code depends on the element order.
        //
        case 4:
        {
            //
            //  Count the number of adjacencies.
            //  Set up the ADJ_ROW adjacency pointer array.
            //
            adj_row = new int[node_num + 1];

            TetMesh.tet_mesh_order4_adj_count(node_num, element_num, element_node,
                                              ref adj_num, ref adj_row);

            if (debug || node_num < 10)
            {
                Console.WriteLine("");
                Console.WriteLine("  ADJ_NUM = " + adj_num + "");

                typeMethods.i4vec_print(node_num + 1, adj_row, "  ADJ_ROW:");
            }

            //
            //  Set up the ADJ adjacency array.
            //
            adj = TetMesh.tet_mesh_order4_adj_set(node_num, element_num, element_node,
                                                  adj_num, adj_row);

            switch (node_num)
            {
            case < 10:
                AdjacencyMatrix.adj_print(node_num, adj_num, adj_row, adj, "  ADJ");
                break;
            }

            break;
        }

        case 10:
        {
            //
            //  Count the number of adjacencies.
            //  Set up the ADJ_ROW adjacency pointer array.
            //
            adj_row = new int[node_num + 1];

            TetMesh.tet_mesh_order10_adj_count(node_num, element_num, element_node,
                                               ref adj_num, ref adj_row);

            if (debug || node_num < 10)
            {
                Console.WriteLine("");
                Console.WriteLine("  ADJ_NUM = " + adj_num + "");

                typeMethods.i4vec_print(node_num + 1, adj_row, "  ADJ_ROW:");
            }

            //
            //  Set up the ADJ adjacency array.
            //
            adj = TetMesh.tet_mesh_order10_adj_set(node_num, element_num, element_node,
                                                   ref adj_num, ref adj_row);

            switch (node_num)
            {
            case < 10:
                AdjacencyMatrix.adj_print(node_num, adj_num, adj_row, adj, "  ADJ");
                break;
            }

            break;
        }
        }

        //
        //  Compute the bandwidth.
        //
        int bandwidth = AdjacencyMatrix.adj_bandwidth(node_num, adj_num, adj_row, adj);

        Console.WriteLine("");
        Console.WriteLine("  ADJ bandwidth = " + bandwidth + "");
        //
        //  GENRCM computes the RCM permutation.
        //
        int[] perm = GenRCM.genrcm(node_num, adj_num, adj_row, adj);
        //
        //  Compute the inverse permutation.
        //
        int[] perm_inv = typeMethods.perm_inverse3(node_num, perm);

        switch (node_num)
        {
        case < 10:
        {
            Console.WriteLine("");
            Console.WriteLine("         I   PERM[I] INVERSE[I]");
            Console.WriteLine("");
            for (i = 0; i < node_num; i++)
            {
                Console.WriteLine("  " + i.ToString().PadLeft(8)
                                  + "  " + perm[i].ToString().PadLeft(8)
                                  + "  " + perm_inv[i].ToString().PadLeft(8) + "");
            }

            break;
        }
        }

        //
        //  Compute the bandwidth of the permuted array.
        //
        bandwidth = AdjacencyMatrix.adj_perm_bandwidth(node_num, adj_num, adj_row, adj,
                                                       perm, perm_inv);

        Console.WriteLine("");
        Console.WriteLine("  ADJ bandwidth after RCM permutation = " + bandwidth + "");
        //
        //  Permute the nodes in NODE_XYZ.
        //
        int base_internal = 0;

        typeMethods.r8col_permute(dim_num, node_num, perm, base_internal, node_xyz);
        //
        //  Permute the node indices in ELEMENT_NODE.
        //
        for (j = 0; j < element_num; j++)
        {
            for (i = 0; i < element_order; i++)
            {
                int node = element_node[i + j * element_order];
                element_node[i + j * element_order] = perm_inv[node];
            }
        }

        switch (base_user)
        {
        //
        //  If the user base was 1, restore it!
        //
        case 1:
        {
            for (i = 0; i < element_num; i++)
            {
                for (j = 0; j < element_order; j++)
                {
                    element_node[i + j * element_order] += 1;
                }
            }

            Console.WriteLine("");
            Console.WriteLine("  Output files will use the same 1-based ordering used by the input.");
            break;
        }
        }

        //
        //  Write the node and element data.
        //
        typeMethods.r8mat_write(node_rcm_filename, dim_num, node_num, node_xyz);

        Console.WriteLine("");
        Console.WriteLine("  Created the file \"" + node_rcm_filename + "\".");

        typeMethods.i4mat_write(element_rcm_filename, element_order, element_num, element_node);

        Console.WriteLine("  Created the file \"" + element_rcm_filename + "\".");

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_RCM:");
        Console.WriteLine("  Normal end of execution.");

        Console.WriteLine("");
    }
예제 #5
0
    private static void Main(string[] args)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for TET_MESH_QUALITY.
    //
    //  Discussion:
    //
    //    TET_MESH_QUALITY determines quality measures for a tet mesh.
    //
    //  Usage:
    //
    //    tet_mesh_quality prefix
    //
    //    where prefix is the common file prefix:
    //
    //    * prefix_nodes.txt contains the node coordinates;
    //    * prefix_elements.txt contains the element definitions.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 September 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int    i;
        string prefix;
        double value_max  = 0;
        double value_mean = 0;
        double value_min  = 0;
        double value_var  = 0;

        Console.WriteLine("");

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_QUALITY");
        Console.WriteLine("  Compute tet mesh quality measures.");
        Console.WriteLine("");
        //
        //  Get the filename prefix.
        //
        try
        {
            prefix = args[0];
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_QUALITY:");
            Console.WriteLine("  Please enter the file prefix.");

            prefix = Console.ReadLine();
        }

        //
        //  Create the filenames.
        //
        string node_filename    = prefix + "_nodes.txt";
        string element_filename = prefix + "_elements.txt";
        //
        //  Read the node data.
        //
        TableHeader h        = typeMethods.r8mat_header_read(node_filename);
        int         dim_num  = h.m;
        int         node_num = h.n;

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + node_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Spatial dimension DIM_NUM =  " + dim_num + "");
        Console.WriteLine("  Number of points NODE_NUM  = " + node_num + "");

        if (dim_num != 3)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_QUALITY - Fatal error!");
            Console.WriteLine("  Dataset must have spatial dimension 3.");
            return;
        }

        double[] node_xyz = typeMethods.r8mat_data_read(node_filename, dim_num, node_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + node_filename + "\".");

        typeMethods.r8mat_transpose_print_some(dim_num, node_num, node_xyz, 1, 1, 5, 5,
                                               "  5 by 5 portion of data read from file:");
        //
        //  Read the tetra data.
        //
        h = typeMethods.i4mat_header_read(element_filename);

        int element_order = h.m;
        int element_num   = h.n;

        if (element_order != 4)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_QUALITY - Fatal error!");
            Console.WriteLine("  Data is not for a 4 node tet mesh.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + element_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Element order      = " + element_order + "");
        Console.WriteLine("  Number of elements = " + element_num + "");

        int[] element_node = typeMethods.i4mat_data_read(element_filename, element_order,
                                                         element_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + element_filename + "\".");

        typeMethods.i4mat_transpose_print_some(element_order, element_num,
                                               element_node, 1, 1, element_order, 10, "  Portion of ELEMENT_NODE:");
        //
        //  If the element information is 1-based, make it 0-based.
        //
        TetMesh.tet_mesh_base_zero(node_num, element_order, element_num, ref element_node);
        //
        //  Compute and print the quality measures.
        //
        Console.WriteLine("");
        Console.WriteLine("                           Minimum    Mean         Maximum    Variance");
        Console.WriteLine("");

        TetMesh.tet_mesh_quality1(node_num, node_xyz, element_order, element_num,
                                  element_node, ref value_min, ref value_mean, ref value_max, ref value_var);

        Console.WriteLine("  Quality measure 1 = "
                          + "  " + value_min.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_mean.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_max.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_var.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");

        TetMesh.tet_mesh_quality2(node_num, node_xyz, element_order, element_num,
                                  element_node, ref value_min, ref value_mean, ref value_max, ref value_var);

        Console.WriteLine("  Quality measure 2 = "
                          + "  " + value_min.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_mean.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_max.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_var.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");

        TetMesh.tet_mesh_quality3(node_num, node_xyz, element_order, element_num,
                                  element_node, ref value_min, ref value_mean, ref value_max, ref value_var);

        Console.WriteLine("  Quality measure 3 = "
                          + "  " + value_min.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_mean.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_max.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_var.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");

        TetMesh.tet_mesh_quality4(node_num, node_xyz, element_order, element_num,
                                  element_node, ref value_min, ref value_mean, ref value_max, ref value_var);

        Console.WriteLine("  Quality measure 4 = "
                          + "  " + value_min.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_mean.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_max.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_var.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");

        TetMesh.tet_mesh_quality5(node_num, node_xyz, element_order, element_num,
                                  element_node, ref value_min, ref value_mean, ref value_max, ref value_var);

        Console.WriteLine("  Quality measure 5 = "
                          + "  " + value_min.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_mean.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_max.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                          + "  " + value_var.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");

        int[] node_order = TetMesh.tet_mesh_node_order(element_order, element_num, element_node,
                                                       node_num);

        int histo_num = typeMethods.i4vec_max(node_num, node_order);

        int[] histo_gram = typeMethods.i4vec_histogram(node_num, node_order, histo_num);

        Console.WriteLine("");
        Console.WriteLine("  Here is a numerical histogram of the order of");
        Console.WriteLine("  each node in the mesh, that is, the number of");
        Console.WriteLine("  tetrahedrons that include that node as a vertex.");
        Console.WriteLine("");
        Console.WriteLine("  For a regular mesh, most nodes would have the");
        Console.WriteLine("  same order.");
        Console.WriteLine("");
        Console.WriteLine("   Order  Number of Nodes");
        Console.WriteLine("");

        for (i = 0; i <= histo_num; i++)
        {
            if (histo_gram[i] != 0)
            {
                Console.WriteLine("  " + i.ToString(CultureInfo.InvariantCulture).PadLeft(6)
                                  + "  " + histo_gram[i].ToString(CultureInfo.InvariantCulture).PadLeft(6) + "");
            }
        }

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_QUALITY:");
        Console.WriteLine("  Normal end of execution.");

        Console.WriteLine("");
    }
예제 #6
0
    private static void Main(string[] args)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for TET_MESH_VOLUMES.
    //
    //  Discussion:
    //
    //    TET_MESH_VOLUMES determines the element volumes of a tet mesh.
    //
    //  Usage:
    //
    //    tet_mesh_volumes prefix
    //
    //    where
    //
    //    * prefix_nodes.txt contains nodal coordinates;
    //    * prefix_elements.txt contains the element definitions;
    //    * prefix_volumes.txt will contain the element volumes.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    13 August 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int    element;
        string prefix;

        double[] tetra = new double[3 * 4];

        Console.WriteLine("");

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_VOLUMES");
        Console.WriteLine("  Compute volume of each tetrahedron in a tet mesh..");
        Console.WriteLine("");
        //
        //  Get the filename prefix.
        //
        try
        {
            prefix = args[0];
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_VOLUMES:");
            Console.WriteLine("  Please enter the filename prefix.");

            prefix = Console.ReadLine();
        }

        //
        //  Create the filenames.
        //
        string node_filename    = prefix + "_nodes.txt";
        string element_filename = prefix + "_elements.txt";
        string volume_filename  = prefix + "_volumes.txt";
        //
        //  Read the node data.
        //
        TableHeader h        = typeMethods.r8mat_header_read(node_filename);
        int         dim_num  = h.m;
        int         node_num = h.n;

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + node_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Spatial dimension DIM_NUM =  " + dim_num + "");
        Console.WriteLine("  Number of points NODE_NUM  = " + node_num + "");

        if (dim_num != 3)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_VOLUMES - Fatal error!");
            Console.WriteLine("  Dataset must have spatial dimension 3.");
            return;
        }

        double[] node_xyz = typeMethods.r8mat_data_read(node_filename, dim_num, node_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + node_filename + "\".");

        typeMethods.r8mat_transpose_print_some(dim_num, node_num, node_xyz, 1, 1, 5, 5,
                                               "  5 by 5 portion of data read from file:");
        //
        //  Read the tetra data.
        //
        h = typeMethods.i4mat_header_read(element_filename);
        int element_order = h.m;
        int element_num   = h.n;

        if (element_order != 4)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_VOLUMES - Fatal error!");
            Console.WriteLine("  Data is not for a 4 node tet mesh.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + element_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Tetrahedron order = " + element_order + "");
        Console.WriteLine("  Number of tetras  = " + element_num + "");

        int[] element_node = typeMethods.i4mat_data_read(element_filename, element_order,
                                                         element_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + element_filename + "\".");

        typeMethods.i4mat_transpose_print_some(element_order, element_num,
                                               element_node, 1, 1, element_order, 10, "  Portion of ELEMENT_NODE:");
        //
        //  If the element information is 1-based, make it 0-based.
        //
        TetMesh.tet_mesh_base_zero(node_num, element_order, element_num, ref element_node);
        //
        //  Compute and print the quality measures.
        //
        double[] volume = new double[element_num];

        for (element = 0; element < element_num; element++)
        {
            int j;
            for (j = 0; j < 4; j++)
            {
                int i;
                for (i = 0; i < 3; i++)
                {
                    int node = element_node[j + element * element_order];
                    tetra[i + j * 3] = node_xyz[i + node * 3];
                }
            }

            volume[element] = Tetrahedron.tetrahedron_volume(tetra);
        }

        double volume_max = typeMethods.r8vec_max(element_num, volume);
        double volume_min = typeMethods.r8vec_min(element_num, volume);
        double volume_ave = typeMethods.r8vec_mean(element_num, volume);
        double volume_tot = typeMethods.r8vec_sum(element_num, volume);
        double volume_var = typeMethods.r8vec_variance(element_num, volume);

        Console.WriteLine("");
        Console.WriteLine("  Minimum:   " + volume_min + "");
        Console.WriteLine("  Average:   " + volume_ave + "");
        Console.WriteLine("  Maximum:   " + volume_max + "");
        Console.WriteLine("  Total:     " + volume_tot + "");
        Console.WriteLine("  Variance:  " + volume_var + "");

        typeMethods.r8mat_write(volume_filename, 1, element_num, volume);

        Console.WriteLine("");
        Console.WriteLine("  Full list of volumes written to \"" + volume_filename + "\".");

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_VOLUMES:");
        Console.WriteLine("  Normal end of execution.");

        Console.WriteLine("");
    }
예제 #7
0
    private static void Main(string[] args)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for TET_MESH_TO_XML.
    //
    //  Discussion:
    //
    //    TET_MESH_TO_XML converts a tet mesh, using 4 or 10 node
    //    tetrahedral elements, to a DOLFIN XML mesh file.
    //
    //  Usage:
    //
    //    tet_mesh_to_xml prefix
    //
    //    where prefix is the common file prefix:
    //
    //    * prefix_nodes.txt,       the node coordinates;
    //    * prefix_elements.txt,    the linear element definitions.
    //    * prefix.xml,             the DOLFIN XML mesh file.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    04 June 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    Anders Logg, Kent-Andre Mardal, Garth Wells,
    //    Automated Solution of Differential Equations by the Finite Element
    //    Method: The FEniCS Book,
    //    Lecture Notes in Computational Science and Engineering,
    //    Springer, 2011,
    //    ISBN13: 978-3642230981
    //
    {
        string prefix;

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_TO_XML;");
        Console.WriteLine("  Convert a tet mesh to DOLFIN XML format");
        Console.WriteLine("");
        Console.WriteLine("  Read \"prefix\"_nodes.txt, node coordinates.");
        Console.WriteLine("  Read \"prefix\"_elements.txt, 4, 10 or 20 node element definitions.");
        Console.WriteLine("");
        Console.WriteLine("  Create \"prefix\".xml, a corresponding DOLFIN XML mesh file.");
        Console.WriteLine("");
        //
        //  Get the filename prefix.
        //
        try
        {
            prefix = args[0];
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_TO_XML:");
            Console.WriteLine("  Please enter the filename prefix.");

            prefix = Console.ReadLine();
        }

        //
        //  Create the filenames.
        //
        string node_filename    = prefix + "_nodes.txt";
        string element_filename = prefix + "_elements.txt";
        string xml_filename     = prefix + ".xml";
        //
        //  Read the node data.
        //
        TableHeader h        = typeMethods.r8mat_header_read(node_filename);
        int         dim_num  = h.m;
        int         node_num = h.n;

        if (dim_num != 3)
        {
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_TO_XML; - Fatal error!");
            Console.WriteLine("  The spatial dimension must be 3.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + node_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Spatial dimension = " + dim_num + "");
        Console.WriteLine("  Number of nodes   = " + node_num + "");

        double[] node_xyz = typeMethods.r8mat_data_read(node_filename, dim_num, node_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + node_filename + "\".");

        typeMethods.r8mat_transpose_print_some(dim_num, node_num,
                                               node_xyz, 1, 1, dim_num, 5, "  First 5 nodes:");
        //
        //  Read the element data.
        //
        h = typeMethods.i4mat_header_read(element_filename);
        int element_order = h.m;
        int element_num   = h.n;

        switch (element_order)
        {
        case 4:
            break;

        case 10:
            break;

        case 20:
            break;

        default:
            Console.WriteLine("");
            Console.WriteLine("TET_MESH_TO_XML - Fatal error!");
            Console.WriteLine("  The tet mesh must have order 4, 10, or 20.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("  Read the header of \"" + element_filename + "\".");
        Console.WriteLine("");
        Console.WriteLine("  Element order = " + element_order + "");
        Console.WriteLine("  Number of elements  = " + element_num + "");

        int[] element_node = typeMethods.i4mat_data_read(element_filename, element_order,
                                                         element_num);

        Console.WriteLine("");
        Console.WriteLine("  Read the data in \"" + element_filename + "\".");

        typeMethods.i4mat_transpose_print_some(element_order, element_num,
                                               element_node, 1, 1, element_order, 5, "  First 5 elements:");
        //
        //  Use 0-based indexing.
        //
        TetMesh.tet_mesh_base_zero(node_num, element_order, element_num, ref element_node);
        //
        //  Write the DOLFIN XML file.
        //
        XML.xml_write(xml_filename, dim_num, node_num, node_xyz, element_order,
                      element_num, element_node);

        Console.WriteLine("");
        Console.WriteLine("  Created XML file \"" + xml_filename + "\".");

        Console.WriteLine("");
        Console.WriteLine("TET_MESH_TO_XML;");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }