function fem_basis_t6_display ( node_file, element_file ) %% FEM_BASIS_T6_DISPLAY displays a finite element T6 basis. % % Discussion: % % This program reads a data file defining a set of nodes, and a % data file defining the triangulation of those nodes using 6 node triangles. % % It is assumed that the 6 node triangles have straight sides, that is, % that each midside node lies on the line segment connecting the % corresponding vertices. % % The program then asks the user interactively to select one of the % nodes. It computes the basis function associated with that node % and displays it over the entire mesh. Of course, the basis function % will only be nonzero over a small number of the elements, but it % is instructive to see the entire mesh. % % The display is initially "flat", but by using the manipulator % on the graphics menu, the user can easily get some dramatic images % of the basis function. % % Usage: % % fem_basis_t6_display ( 'node_file.txt', 'element_file.txt' ) % % Modified: % % 13 August 2006 % % Author: % % John Burkardt % timestamp; fprintf ( 1, '\n' ); fprintf ( 1, 'FEM_BASIS_T6_DISPLAY:\n' ); fprintf ( 1, ' MATLAB version\n' ); fprintf ( 1, ' Display a basis function associated with a finite element grid.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' This program reads two files:\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' * node_file, the node file,\n' ); fprintf ( 1, ' * element_file, the element file,\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' The user specifies a basis function by node index,\n' ); fprintf ( 1, ' and the program displays a surface plot of that basis function.\n' ); % % Read the data. % p = load ( node_file )'; [ dim_num, node_num ] = size ( p ); t = load ( element_file )'; [ triangle_order, triangle_num ] = size ( t ); fprintf ( 1, '\n' ); fprintf ( 1, 'Every basis function is associated with a node.\n' ); fprintf ( 1, 'To chooose a basis function, you specify a node.\n' ); fprintf ( 1, 'Nodes range in value from 1 to %d.\n', node_num ); fprintf ( 1, '\n' ); node_index = input ( 'Enter the index of a node: ' ); % % Clear the graphics page. % clf fprintf ( 1, '\n' ); for triangle = 1 : triangle_num pt(1,1:6) = p(1,t(1:6,triangle)); pt(2,1:6) = p(2,t(1:6,triangle)); local = 0; for j = 1 : 6 if ( t(j,triangle) == node_index ) local = j; fprintf ( 1, ' Node %d occurs as local node %d in element %d.\n', ... node_index, j, triangle ); end end if ( local == 0 ) x = zeros(2,2); y = zeros(2,2); z = zeros(2,2); x(1,1) = pt(1,1); y(1,1) = pt(2,1); x(2,1) = pt(1,1); y(2,1) = pt(2,1); x(1,2) = pt(1,2); y(1,2) = pt(2,2); x(2,2) = pt(1,3); y(2,2) = pt(2,3); else for i = 0 : 10 % % To use surface, we need to define a logical rectangular grid of points. % But our region is a triangle, so the easiest thing to do is to identify % two corners of the grid. % We try to do this in such a way that the same thing happens in each % element, and the resulting grid looks less haphazard. % if ( local == 1 | local == 5 ) xlo = ( ( 10 - i ) * pt(1,1) + i * pt(1,2) ) / 10; ylo = ( ( 10 - i ) * pt(2,1) + i * pt(2,2) ) / 10; xhi = ( ( 10 - i ) * pt(1,1) + i * pt(1,3) ) / 10; yhi = ( ( 10 - i ) * pt(2,1) + i * pt(2,3) ) / 10; elseif ( local == 2 | local == 6 ) xlo = ( ( 10 - i ) * pt(1,2) + i * pt(1,1) ) / 10; ylo = ( ( 10 - i ) * pt(2,2) + i * pt(2,1) ) / 10; xhi = ( ( 10 - i ) * pt(1,2) + i * pt(1,3) ) / 10; yhi = ( ( 10 - i ) * pt(2,2) + i * pt(2,3) ) / 10; elseif ( local == 3 | local == 4 ) xlo = ( ( 10 - i ) * pt(1,3) + i * pt(1,2) ) / 10; ylo = ( ( 10 - i ) * pt(2,3) + i * pt(2,2) ) / 10; xhi = ( ( 10 - i ) * pt(1,3) + i * pt(1,1) ) / 10; yhi = ( ( 10 - i ) * pt(2,3) + i * pt(2,1) ) / 10; end for j = 0 : 10 pp(1) = ( ( 10 - j ) * xlo + j * xhi ) / 10; pp(2) = ( ( 10 - j ) * ylo + j * yhi ) / 10; zz = basis_11_t6 ( pt, local, pp ); x(i+1,j+1) = pp(1); y(i+1,j+1) = pp(2); z(i+1,j+1) = zz; end end end caxis ( [ -0.4, 1.2 ] ) surface ( x, y, z, 'FaceColor', 'interp' ) end xlabel ( '--X axis--' ) ylabel ( '--Y axis--' ) zlabel ( '--Z axis--' ) title_string = s_escape_tex ( element_file ); title ( title_string ) fprintf ( 1, '\n' ); fprintf ( 1, 'Press return...\n' ); pause fprintf ( 1, '\n' ); fprintf ( 1, 'FEM_BASIS_T6_DISPLAY:\n' ); fprintf ( 1, ' Normal end of execution.\n' ); fprintf ( 1, '\n' ); timestamp;