function hcell_contour_display ( node_xy_file_name, p_file_name ) %% HCELL_CONTOUR_DISPLAY displays a contour plot for the H-Cell problem. % % Discussion: % % This function reads the H-Cell flow data for a single timestep: % % geometry ( X, Y values at the 3-node triangle nodes); % pressure ( or any corresponding scalar quantity.) % % It could also handle the pair % % geometry ( X, Y values at the 6-node triangle nodes); % velocity norm ( calculated externally and stored in a file) % % The data is arranged to suit a call to MATLAB's CONTOURF routine. % % Usage: % % hcell_contour_display ( node_xy_file_name, p_file_name ) % % A typical invocation might be % % hcell_contour_display ( 'xy3.txt', 'p000.txt' ) % % But if you simply say % % hcell_contour_display % % the program will give you a chance to enter the file names % interactively. % % Modified: % % 30 April 2004 % % Author: % % John Burkardt % % Parameters: % % Input, NODE_XY_FILE_NAME, the name of the file containing the % coordinates of the nodes. % % Input, P_FILE_NAME, the name of the file containing the values of % the scalar quantity (such as pressure) at the nodes. % fprintf ( 1, '\n' ); fprintf ( 1, 'HCELL_CONTOUR_DISPLAY:\n' ); fprintf ( 1, ' MATLAB version\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' Display scalar data contours in the HCELL problem.\n' ); % % Do we have the XY file? % if ( nargin < 1 ) fprintf ( 1, '\n' ); fprintf ( 1, 'HCELL_CONTOUR_DISPLAY:\n' ); node_xy_file_name = input ( 'Enter the name of the XY coordinate file:' ); end node_xy = table_read ( node_xy_file_name ); [ m1, n1 ] = size ( node_xy ); % % Do we have the P file? % if ( nargin < 2 ) fprintf ( 1, '\n' ); fprintf ( 1, 'HCELL_CONTOUR_DISPLAY:\n' ); p_file_name = input ( 'Enter the name of the scalar (pressure?) file:' ); end p = table_read ( p_file_name ); [ m2, n2 ] = size ( p ); % % Make sure the number of coordinates and values match. % if ( n1 ~= n2 ) fprintf ( 1, '\n' ); fprintf ( 1, 'HCELL_CONTOUR_DISPLAY - Fatal error!\n' ); fprintf ( 1, ' The number of coordinates is %d\n', n1 ); fprintf ( 1, ' but the number of pressure values is %d\n', n2 ); return end % % Our X, Y data is logically rectangular, with some holes. % CONTOURF requires 2D arrays, with no holes. % Figure out the number of rows and columns, % construct the data, and fill in the holes. % x = sort ( node_xy(1,1:n1) ); x_tol = 0.0001 * ( x(n1) - x(1) ); [ n, x_unique ] = r8vec_sorted_unique ( n1, x, x_tol ); y = sort ( node_xy(2,1:n1) ); y_tol = 0.0001 * ( y(n1) - y(1) ); [ m, y_unique ] = r8vec_sorted_unique ( n1, y, y_tol ); [ x_grid, y_grid ] = meshgrid ( x_unique, y_unique ); p_min = min ( p(1,1:n2) ); p_max = max ( p(1,1:n2) ); z_grid(1:m,1:n) = p_min + ( p_min - p_max ); z_grid(1:m,1:n) = NaN; % % For each computational node, copy the value of P into the array. % for k = 1 : n1 i = r8vec_sorted_nearest ( n, x_unique, node_xy(1,k) ); j = r8vec_sorted_nearest ( m, y_unique, node_xy(2,k) ); z_grid(j,i) = p(k); end % % Set the contour levels evenly spaced between P_MIN and P_MAX. % level_num = 15; for level = 1 : level_num level_value(i) = ( ( 2 * level_num - 2 * level + 1 ) * p_min ... + ( 2 * level - 1 ) * p_max ) ... / ( 2 * level_num ); end [ C1, h1 ] = contourf ( x_unique, y_unique, z_grid, 15 ); colorbar; axis equal; % [ C1, h1 ] = contourf ( x_grid, y_grid, z_grid, level_value ); % % Add the boundary of the region to the plot. % hcell_boundary_add ( 'r' ) % % Add the invisible bounding box. % hcell_box_add ( 'w' ) % % Set up a colormap. % colormap ( jet ); % % Label the axes and the plot. % xlabel ( 'X', 'FontName', 'Helvetica', 'FontWeight', 'bold', ... 'FontSize', 16 ); ylabel ( 'Y', 'FontName', 'Helvetica', 'FontWeight', 'bold', ... 'FontSize', 16, 'Rotation', 0 ); title ( 'Pressure Contours', 'FontName', 'Helvetica', 'FontWeight', ... 'bold', 'FontSize', 16 ); fprintf ( 1, '\n' ); fprintf ( 1, 'HCELL_CONTOUR_DISPLAY:\n' ); fprintf ( 1, ' Normal end of execution.\n' );