function triangulation_rcm ( input_node_filename, input_triangulation_filename ) %% MAIN is the main program for TRIANGULATION_RCM. % % Discussion: % % TRIANGULATION_RCM applies the RCM reordering to a triangulation. % % The user supplies a node file and a triangle file, containing % the coordinates of the nodes, and the indices of the nodes that % make up each triangle. Either 3-node or 6-node triangles 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 triangles, and writes out % new node and triangle files that correspond to the RCM permutation. % % Note that node data is normally two dimensional, that is, % each node has an X and Y 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. % % Modified: % % 08 January 2007 % % Author: % % John Burkardt % % Usage: % % triangulation_rcm ( 'node_file', 'triangulation_file' ) % timestamp; fprintf ( 1, '\n' ); fprintf ( 1, 'TRIANGULATION_RCM\n' ); fprintf ( 1, ' MATLAB version\n' ); fprintf ( 1, ' Read a node dataset of NODE_NUM points in 2 dimensions.\n' ); fprintf ( 1, ' Read an associated triangulation dataset of TRIANGLE_NUM\n' ); fprintf ( 1, ' triangles using 3 or 6 nodes.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' Apply the RCM reordering (Reverse Cuthill-McKee).\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' Reorder the data and write it out to files.\n' ); % % Get the number of command line arguments. % if ( nargin < 1 ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRIANGULATION_RCM:\n' ); input_node_filename = input ( ... ' Please enter the name of the node file.' ); end if ( nargin < 2 ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRIANGULATION_RCM:\n' ); input_triangulation_filename = input ( ... ' Please enter the name of the triangulation file.' ); end % % Read the node data. % [ dim_num, node_num ] = dtable_header_read ( ... input_node_filename ); fprintf ( 1, '\n' ); fprintf ( 1, ' Read the header of ""%s".\n', input_node_filename ); fprintf ( 1, '\n' ); fprintf ( 1, ' Spatial dimension DIM_NUM = %d\n', dim_num ); fprintf ( 1, ' Number of nodes NODE_NUM = %d\n', node_num ); node_xy(1:dim_num,1:node_num) = dtable_data_read ( ... input_node_filename, dim_num, node_num ); fprintf ( 1, '\n' ); fprintf ( 1, ' Read the data in ""%s".\n', input_node_filename ); r8mat_transpose_print_some ( dim_num, node_num, node_xy, ... 1, 1, dim_num, 5, ' Coordinates of first 5 nodes:' ); % % Read the triangulation data. % [ triangle_order, triangle_num ] = itable_header_read ( ... input_triangulation_filename ); if ( triangle_order ~= 3 & triangle_order ~= 6 ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRIANGULATION_RCM - Fatal error!\n' ); fprintf ( 1, ' Data is not for a 3-node or 6-node triangulation.\n' ); error ( 'TRIANGULATION_RCM - Fatal error!' ); end fprintf ( 1, '\n' ); fprintf ( 1, ' Read the header of ""%s".\n', input_triangulation_filename ); fprintf ( 1, '\n' ); fprintf ( 1, ' Triangle order = %d\n', triangle_order ); fprintf ( 1, ' Number of triangles TRIANGLE_NUM = %d\n', triangle_num ); triangle_node(1:triangle_order,1:triangle_num) = itable_data_read ( ... input_triangulation_filename, triangle_order, triangle_num ); fprintf ( 1, '\n' ); fprintf ( 1, ' Read the data in ""%s".\n', input_triangulation_filename ); i4mat_transpose_print_some ( triangle_order, triangle_num, triangle_node, ... 1, 1, triangle_order, 5, ' First five triangles:' ); if ( triangle_order == 3 ) % % Create the triangle neighbor array. % triangle_neighbor = triangulation_order3_neighbor_triangles ( triangle_num, ... triangle_node ); % % Count the number of adjacencies, and set up the ADJ_ROW % adjacency pointer array. % [ adj_num, adj_row ] = triangulation_order3_adj_count ( node_num, ... triangle_num, triangle_node, triangle_neighbor ); % % Set up the ADJ adjacency array. % adj = triangulation_order3_adj_set ( node_num, triangle_num, triangle_node, ... triangle_neighbor, adj_num, adj_row ); elseif ( triangle_order == 6 ) % % Create the triangle neighbor array. % triangle_neighbor = triangulation_order6_neighbor_triangles ( triangle_num, ... triangle_node ); % % Count the number of adjacencies, and set up the ADJ_ROW % adjacency pointer array. % [ adj_num, adj_row ] = triangulation_order6_adj_count ( node_num, ... triangle_num, triangle_node, triangle_neighbor ); % % Set up the ADJ adjacency array. % adj = triangulation_order6_adj_set ( node_num, triangle_num, triangle_node, ... triangle_neighbor, adj_num, adj_row ); end bandwidth = adj_bandwidth ( node_num, adj_num, adj_row, adj ); fprintf ( 1, '\n' ); fprintf ( 1, ' ADJ bandwidth = %d\n', bandwidth ); % % Compute the RCM permutation. % perm = genrcm ( node_num, adj_num, adj_row, adj ); perm_inv = perm_inverse3 ( node_num, perm ); bandwidth = adj_perm_bandwidth ( node_num, adj_num, adj_row, adj, ... perm, perm_inv ); fprintf ( 1, '\n' ); fprintf ( 1, ' Permuted ADJ bandwidth = %d\n', bandwidth ); % % Permute the nodes according to the permutation vector. % node_xy = r8col_permute ( dim_num, node_num, node_xy, perm ); % % Permute the node indices in the triangle array. % for i = 1 : triangle_order for j = 1 : triangle_num node = triangle_node(i,j); triangle_node(i,j) = perm_inv ( node ); end end % % Create the output file names from the input file names. % output_node_filename = file_name_ext_swap ( ... input_node_filename, 'rcm.txt' ); output_triangulation_filename = file_name_ext_swap ( ... input_triangulation_filename, 'rcm.txt' ); % % Write out the node and triangle data for the quadratic mesh % header = 1; dtable_write ( output_node_filename, dim_num, ... node_num, node_xy, header ); fprintf ( 1, '\n' ); fprintf ( 1, ' Created the node file "%s".\n', output_node_filename ); itable_write ( output_triangulation_filename, triangle_order, ... triangle_num, triangle_node, header ); fprintf ( 1, '\n' ); fprintf ( 1, ' Created the triangulation file "%s".\n', ... output_triangulation_filename ); fprintf ( 1, '\n' ); fprintf ( 1, 'TRIANGULATION_RCM\n' ); fprintf ( 1, ' Normal end of execution.\n' ); fprintf ( 1, '\n' ); timestamp;