function true_cubic_result_1d (i_p, Exact) % Copyright 2000 J.E. Akin. All rights reserved. % under construction: requires analytic exact solution % variable "ar" (analytic result) for "Exact" case number % ------------------------------------------------------ % Matlab graph of i_p-th component value at mesh nodes % for a mesh of 4 node cubic line elements % If i_p = 0, show RMS value % ------------------------------------------------------ % c_x = x coordinates of nod_per_el line element % msh_typ_nodes = connectivity list for elements, nt x nod_per_el % loop = corners for nod_per_el line element % nod_per_el = Nodes per element % np = Number of Points % nt = Number of elements % pre_e = Element items before connectivity list pre_e = 0 ; % pre_p = Nodal items before coordinates pre_p = 1; % msh_bc_xyz = Nodal coordinates (with preceeding data) % t_x = x coordinates of nod_per_el corners % UNDER_CONSTRUCTION if ( nargin == 0 ) i_p = 0 ; Exact = 0 ; end % if no arguments if ( nargin == 1 ) Exact = 0 ; end % if 1 argument %b fprintf ('Begin graph for exact case %g \n', Exact) % Read coordinate file and connectivity file % integer bc code, real xy pairs for np points (pre_p = 1) load msh_bc_xyz.tmp ; % Set control data: number of points np = size (msh_bc_xyz,1) ; % number of nodal points fprintf ('Read %g mesh coordinate pairs \n', np) ns = size (msh_bc_xyz,2) - pre_p ; % space dimension if ( ns ~= 1) error ('This is not a 1D mesh') end % if not 1D data % Set control data: number elements load msh_typ_nodes.tmp ; % nod_per_el nodes per element nt = size (msh_typ_nodes,1) ; % number of elements in mesh nod_per_el = size (msh_typ_nodes,2) - pre_e -1 ; % nodes per elem fprintf ('Read %g elements connections \n', nt) if ( nod_per_el ~= 4 ) error ('This is not a mesh of 4 node line elements') end % if load node_results.tmp nr = size (node_results, 1); if ( nr == 0 ) error ('Error missing file node_results.tmp') end % if error max_p = size (node_results, 2) ; % number of columns fprintf ('Read %g nodal solution values \n', nr) fprintf (' with %g components each \n', max_p) if ( i_p > max_p ) fprintf ('Data requested for component i_p = %g \n', i_p) error ('i_p > available data') end % if error H (4) = 0. ; x (np) = 0. ; % pre-allocate array x y (np) = 0. ; % pre-allocate array y t_nodes (nod_per_el) = 0 ; % Optional pre-allocation t_x (nod_per_el) = 0 ; % Optional pre-allocation t_y (nod_per_el) = 0 ; % Optional pre-allocation c_x (nod_per_el) = 0 ; % Optional pre-allocation c_y (nod_per_el) = 0 ; % Optional pre-allocation % set constants loop = [1:nod_per_el] ; % default to sequential order % msh_bc_xyz has: pre_p items then: x, y x = msh_bc_xyz (1:np, (pre_p+1)) ; % extract x column xmax = max (x) ; xmin = min (x) ; % add analytic points %b a_inc = (xmax-xmin)/(10*nt) ; a_inc = (xmax-xmin)/101 ; ax = [xmin:a_inc:xmax] ; % analytic points [ar] = analytic_1_d_result (i_p, ax, Exact); % analytic results if ( i_p >= 1 ) % get FEA answers y = node_results(:, i_p) ; else % i_p = 0, get root mean sq for k = 1:np y (k) = sqrt ( sum (node_results (k, 1:max_p).^2)) ; end % for k end % if get RMS value maxa = max (ar) ; mina = min (ar) ; % Cite max, min values [V_X, L_X] = max (y) ; [V_N, L_N] = min (y) ; fprintf ('Max value is %g at node %g \n', V_X, L_X) fprintf ('Min value is %g at node %g \n', V_N, L_N) null (1:np) = V_N ; % Initialize plots maxy = max (y) ; miny = min (y) ; % finalize axes ymax = max ([maxy, maxa]) ; ymin = min ([miny, mina]) ; if ( ymax == ymin ) if ( abs (ymax) > 0 ) ymax = ymax + abs (ymax)/20. ; ymin = ymin - abs (ymin)/20. ; end % if end % if %b ymin=-0.7 clf % clear graphics axis ([xmin, xmax, ymin, ymax]) % set axes hold on % hold image for plots xlabel (['X, Node at 45 deg (', int2str(nod_per_el), ... ' per element), Element at 90 deg']) if ( i_p >= 1 ) title(['Exact (dash) & Cubic FEA Component\_', int2str(i_p),': ', ... int2str(nt),' Elements, ', int2str(np),' Nodes (', ... int2str(nod_per_el), ' per Element)']) ylabel (['Component ', int2str(i_p), ' (max = ', ... num2str(V_X), ', min = ', num2str(V_N), ')']) else % i_p = 0, get root mean sq title(['Exact (dash) & Cubic FEA RMS\_value: ', int2str(nt), ... ' Elements, ', int2str(np),' Nodes (', ... int2str(nod_per_el), ' per Element)']) ylabel (['Solution RMS Value (max = ', ... num2str(V_X), ', min = ', num2str(V_N), ')']) end % if get RMS value % add anal plot plot (ax, ar, 'r--') % Loop over all elements for it = 1:nt ; % Extract element connectivity t_nodes = msh_typ_nodes (it, (pre_e+2):(nod_per_el+pre_e+1)); % Skip point elements, if any if ( all (t_nodes) ) % then valid line % Extract element coordinates & values t_x = x (t_nodes) ; % x at those nodes, only t_y = y (t_nodes) ; % y at those nodes, only plot (t_x, t_y, 'ko') % plot nodal value symbols % Plot the element number x_bar = sum (t_x' )/nod_per_el ; t_text = sprintf (' (%g)', it); % offset # from pt text (x_bar, V_N, t_text, 'Rotation', 90) % incline plot (x_bar, V_N, 'k+') %b text (x_bar, 0.0, t_text, 'Rotation', 90) % incline %b plot (x_bar, 0.0, 'k+') % Plot this element (if non-sequential use loop) % % c_x = t_x (loop) ; % x for nod_per_el line element % % c_y = t_y (loop) ; % values at nodes % % plot (c_x, c_y) % plot nod_per_el lines % plot (t_x, t_y) % plot nod_per_el lines % Loop over local points on the cubic polynomial element n_poly = ceil (100 / nt) for k = 1: (n_poly + 1) % points in parametric space % get element parametric interpolation functions R = (k - 1)/n_poly ; % on 0 to 1 X = 2*R - 1 ; % on -1 to 1 % X = LOCAL COORDIATE OF POINT, -1 <= X <= +1 % LOCAL NODE COORD. ARE 1----2---3----4 H (1) = (1 - X)*(3*X + 1)*(3*X - 1)/16 ; % shape functions H (2) = 9*(1 + X)*(X - 1)*(3*X - 1)/16 ; % shape functions H (3) = 9*(1 + X)*(1 - X)*(3*X + 1)/16 ; % shape functions H (4) = (1 + X)*(3*X + 1)*(3*X - 1)/16 ; % shape functions x_el (k) = H * t_x ; % true x value y_el (k) = H * t_y ; % true y value end % for k plot (x_el, y_el) end % if zero in connectivity end % for over all elements % plot node points on axis for i = 1:np t_text = sprintf (' %g', i); % offset # from pt text (x(i), null(i), t_text, 'Rotation', 45) % incline end % for all plot (x, null, 'k*') grid % label max min points % plot (x(L_X), y(L_X), 'kx') % plot (x(L_N), y(L_N), 'ko') v_text = sprintf ('---min') ; text (x(L_N), V_N, v_text) ; v_text = sprintf ('---max') ; text (x(L_X), V_X, [v_text]) ; % -depsc -tiff % for an eps version %b print ('-dpsc', ['true_L4_result_', int2str(i_p), '_graph']) hold off %b v_text = ['Created true_L4_result_', int2str(i_p), '_graph.ps'] ; %b fprintf (1,'%s', v_text) ; fprintf (1, ' \n' ) % end of true_cubic_result_1d