function fem_basis_t3_display ( node_file, element_file ) %% FEM_BASIS_T3_DISPLAY displays a finite element T3 basis. % % Discussion: % % This program reads a data file defining a set of nodes, and a % data file defining the triangulation of those nodes using 3 node triangles % (or 6 node triangles, as long as the vertices are listed first). % % 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_t3_display ( 'node_file.txt', 'element_file.txt' ) % % Modified: % % 22 August 2006 % % Author: % % John Burkardt % % Parameters: % % Input, string NODE_FILE, ELEMENT_FILE, the names of the files % containing the node and element information. % timestamp; fprintf ( 1, '\n' ); fprintf ( 1, 'FEM_BASIS_T3_DISPLAY:\n' ); fprintf ( 1, ' MATLAB version\n' ); fprintf ( 1, ' Display a basis function associated with \n' ); fprintf ( 1, ' a finite element grid of linear triangles ("T3").\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, and\n' ); fprintf ( 1, ' 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' ); if ( triangle_order == 6 ) fprintf ( 1, '\n' ); fprintf ( 1, ' This mesh uses 6-node triangles.\n' ); fprintf ( 1, ' The code will not work for the midside nodes,\n' ); fprintf ( 1, ' so try NOT to pick those!\n' ); fprintf ( 1, '\n' ); end 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 local = 0.0; for j = 1 : 3 if ( t(j,triangle) == node_index ) fprintf ( 1, ' Node %d occurs as local node %d in element %d.\n', ... node_index, j, triangle ); local = j; end end if ( local == 0 ) x(1,1) = p(1,t(1,triangle)); y(1,1) = p(2,t(1,triangle)); x(2,1) = p(1,t(1,triangle)); y(2,1) = p(2,t(1,triangle)); x(1,2) = p(1,t(2,triangle)); y(1,2) = p(2,t(2,triangle)); x(2,2) = p(1,t(3,triangle)); y(2,2) = p(2,t(3,triangle)); z(1:2,1:2) = 0.0; else x(1,1) = p(1,t(local,triangle)); y(1,1) = p(2,t(local,triangle)); x(2,1) = p(1,t(local,triangle)); y(2,1) = p(2,t(local,triangle)); j = i4_wrap ( local + 1, 1, 3 ); x(1,2) = p(1,t(j,triangle)); y(1,2) = p(2,t(j,triangle)); j = i4_wrap ( local + 2, 1, 3 ); x(2,2) = p(1,t(j,triangle)); y(2,2) = p(2,t(j,triangle)); z(1:2,1:2) = 0.0; z(1:2,1) = 1.0; 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_T3_DISPLAY:\n' ); fprintf ( 1, ' Normal end of execution.\n' ); fprintf ( 1, '\n' ); timestamp;