function frame_stress_plot (i_p, d_scale, inc_m, inc_e, inc_p, row) %CL % inc_m = 1, include original mesh, else omit % inc_e = increment in element numbers on plot, if > 0 % inc_p = increment in node numbers on plot, if > 0 % row = row number where cord & connectivity start, 1 or 2 %CL % Copyright 2005, J.E. Akin. All rights reserved. % function frame_stress_plot (d_scale, inc_m) % ------------------------------------------------------ % Matlab program to plot 2-D deformed FE meshes % ------------------------------------------------------ % d_scale = deflection multiplier (default 100) % c_x = x coordinates of nod_per_el line polygon % c_y = y coordinates of nod_per_el line polygon % msh_typ_nodes = connectivity list for elements, nt x nod_per_el % loop = corners for nod_per_el line polygon % lab_p = 1, if node points are circled lab_p = 0; % nod_per_el = Nodes per element % np = Number of Points % nt = Number of elements % pre_e = Element items before connectivity list % pre_p = Nodal items before coordinates % pre_r = Nodal items before results %CL % msh_bc_xyz = Nodal coordinates (with preceeding data) % sx, sy = scaled mesh positions = x + d_scale * x_def, etc % t_x = x coordinates of nod_per_el corners % t_y = y coordinates of nod_per_el corners % x_bar = x-centroid of each element % xy = Coordinates of points, np x 2 % y_bar = y-centroid of each element pre_e = 0 ; pre_p = 1; pre_r = 0 ; %CL format short g if ( nargin == 0 ) i_p = 4; d_scale = 1.0 ; inc_m = 1; inc_e = 0; inc_p = 0; row = 1 ; %CL end % if no arguments if ( nargin == 1 ) d_scale = 1.0 ; inc_e = 0; inc_p = 0; inc_m = 1; row = 1 ; %CL end % if no arguments if ( nargin == 2 ) inc_m = 1; inc_e = 0; inc_p = 0; row = 1 ; %CL end % if no arguments if ( nargin == 3 ) inc_e = 0; inc_p = 0; row = 1 ; %CL end % if no arguments if ( nargin == 4 ) inc_p = 0; row = 1 ; %CL end % if no arguments if ( nargin == 5 ) row = 1; end % if no arguments if ( nargin == 5 ) pre_e = 0 ; pre_r = 2 ; %CL end % if no arguments less = row - 1 ; %CL fprintf ('Using scale %g, d_scale ') % Read coordinate file and connectivity file % integer bc code, real xy pairs for np points % Set control data: number of points load msh_bc_xyz.tmp ; np = size (msh_bc_xyz,1) ; % number of nodal points np = np - less ; %CL ns = size (msh_bc_xyz,2) - pre_p ; % dimension of space if ( np == 0 ) error ('Error missing file msh_bc_xyz.tmp') end % if error fprintf ('and %g coordinate pairs \n', np) x (np) = 0. ; % pre-allocate array x y (np) = 0. ; % pre-allocate array y sx (np) = 0. ; % pre-allocate array sx sy (np) = 0. ; % pre-allocate array sy % msh_bc_xyz has: pre_p items then: x, y %b x = msh_bc_xyz (1:np, (pre_p+1)) ; % extract x column of xy x = msh_bc_xyz (row:(np+less), (pre_p+1)) ; % extract x %CL if ( ns >= 2 ) %b y = msh_bc_xyz (1:np, (pre_p+2)) ; % extract y column of xy y = msh_bc_xyz (row:(np+less), (pre_p+2)) ; % extract y %CL else y (1:np) = 0. ; end % if 1D % Set control data: number elements & nodes_per_element load msh_typ_nodes.tmp ; % nod_per_el nodes per element nt = size (msh_typ_nodes,1); % number of elements nt = nt - less ; %CL if ( nt == 0 ) error ('Error missing file msh_typ_nodes.tmp') end % if error nod_per_el = size (msh_typ_nodes,2) - pre_e -1 ; % nodes per element fprintf ('Read %g elements with %g nodes each \n', nt,nod_per_el) Col_1 = pre_e+2 ; %CL Col_2 = nod_per_el+pre_e+1 ; %CL % Get deflections load node_results.tmp nd = size (node_results, 1) ; if ( nd == 0 ) error ('Error missing file node_results.tmp') end % if error fprintf ('Read %g mesh deformations \n', nd) [X_X, L_X] = max ( abs (node_results (:, pre_r+1)) ) ; %CL [Y_X, L_Y] = max ( abs (node_results (:, pre_r+2)) ); %CL Max_Disp = max (X_X, Y_X) ; maxx = max (x) ; minx = min (x) ; maxy = max (y) ; miny = min (y) ; Max_Len= max((maxx-minx),(maxy-miny)) ; Good_Scale=Max_Len/Max_Disp/20 ; fprintf ('Suggested displacement scale = %g \n', Good_Scale) X_X = node_results (L_X, pre_r+1) ; %CL Y_X = node_results (L_Y, pre_r+2) ; %CL if ( ns == 1 ) % then 1-D plot as transverse sx = x ; sy = d_scale * node_results (:, pre_r+1) ; %CL else sx = d_scale * node_results (:, pre_r+1) + x ; %CL sy = d_scale * node_results (:, pre_r+2) + y ; %CL end% if 1D % get element result magnitude from node 1 to 2 load el_sect_xyz_stress.tmp en = size(el_sect_xyz_stress,1) ; n_sec = en/nt ; % segments per el value (nt) = 0. ; x_bar (nt) = 0. ; % pre-allocate array x_bar y_bar (nt) = 0. ; % pre-allocate array y_bar 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 + 1) = 0 ; % Optional pre-allocation c_y (nod_per_el + 1) = 0 ; % Optional pre-allocation loop (nod_per_el + 1) = 0 ; % Optional pre-allocation Smax = max (el_sect_xyz_stress(:, 4+i_p)) ; Smin = min (el_sect_xyz_stress(:, 4+i_p)) ; if ( Smax == Smin ) Smax = Smax + 1. ; Smin = Smin - 1. ; end % IF S (1:np) = Smin ; % SET TO ZERO FOR LABELS % set constants [loop] = get_El_Loop (nod_per_el) ; % Initialize plots maxsx = max (sx) ; minsx = min (sx) ; maxsy = max (sy) ; minsy = min (sy) ; xmax = max ([maxx, maxsx]) ; xmin = min ([minx, minsx]) ; ymax = max ([maxy, maxsy]) ; ymin = min ([miny, minsy]) ; Diagonal = sqrt((xmax-xmin)^2 + (ymax-ymin)^2) / 5 ; xmax = xmax + Diagonal / 2 ; ymax = ymax + Diagonal / 2 ; xmin = xmin - Diagonal / 2 ; ymin = ymin - Diagonal / 2 ; clf % clear graphics axis ([xmin, xmax, ymin, ymax]) % set axes axis ('equal') % true shape style hold on % hold image for plots grid % add grid dots xlabel (['X for ', int2str(nt),' Elements (with ', ... int2str(nod_per_el), ' nodes)']) ylabel (['Y for ', int2str(np), ' Nodes. ', ... 'Displacement scale = ', num2str(d_scale)]) if ( i_p == 1 ) title (['Max Principle Stress, P1 ', ... ' (max = ', num2str(Smax), ', min = ', num2str(Smin), ')']) elseif ( i_p == 2 ) title (['Min Principle Stress, P2', ... ' (max = ', num2str(Smax), ', min = ', num2str(Smin), ')']) elseif ( i_p == 3 ) title (['Maximum Shear Stress, PS', ... ' (max = ', num2str(Smax), ', min = ', num2str(Smin), ')']) elseif ( i_p == 4 ) title (['Max Von Mises Stress, VM', ... ' (max = ', num2str(Smax), ', min = ', num2str(Smin), ')']) elseif ( i_p == 5 ) title (['Centroidal Axial Stress, Sx', ... ' (max = ', num2str(Smax), ', min = ', num2str(Smin), ')']) elseif ( i_p == 6 ) title (['Max Torsional Stress, St', ... ' (max = ', num2str(Smax), ', min = ', num2str(Smin), ')']) else error ('First argument is 1 <= i_p <= 6.') end % if S_range = Smax - Smin ; if ( S_range <= 0. ) S_range = 1.0; end %if % Plot input mesh points & label them if (lab_p == 1) % plot all points plot (x, y, 'b.') % mark each node end % if show labels if (inc_p > 0) % plot node numbers, if node in mesh in_mesh (1:np) = 0 ; % default to missing for i = 1:nt % loop all elements for j = 1:nod_per_el % loop its nodes %b in_mesh (msh_typ_nodes(i, j)) = 1; % flag as present in_mesh (msh_typ_nodes(i+less, j+pre_e+1)) = 1; % present %CL end % for its nodes end % for all elements for i = 1:inc_p:np % convert to string %b if ( in_mesh (i) > 0 ) % it is present p_text = sprintf (' %g', i); % offset # from pt text (x(i), y(i), p_text) % plot pt number %b end % if present end % for all points end % if show labels disp (' ') % Loop over all elements Less = n_sec-1 ; % trapezoids per element inc = 1 ; % next row if ( n_sec == 3 ) % linear plot, one trapezoid per element Less = 1 ; inc = 2 ; elseif ( n_sec == 5 ) Less = 1 ; inc = 4 ; end % if i_f = 4 + i_p ; % force column for it = 1:nt ; % Extract corner connectivity t_nodes = msh_typ_nodes ((it+less), Col_1:Col_2 ) ; %CL t_x = x (t_nodes) ; % x original t_y = y (t_nodes) ; % y original % Get the centroid x_bar (it) = sum (t_x' )/nod_per_el ; y_bar (it) = sum (t_y' )/nod_per_el ; c_x = t_x (loop) ; c_y = t_y (loop) ; % Plot the original ploygon if ( inc_m == 1) plot (c_x, c_y, 'g-') plot (c_x, c_y, 'g*') end % if original mesh % Extract corner coordinates of displaced mesh t_x = sx (t_nodes) ; % sx at those nodes, only t_y = sy (t_nodes) ; % sy at those nodes, only % Plot this deformed polygon c_x = t_x (loop) ; % x for nod_per_el line polygon c_y = t_y (loop) ; % y for nod_per_el line polygon plot (c_x, c_y) % plot nod_per_el lines % plot (c_x, c_y, 'ko') % plot nod_per_el lines % loop over n_sec slices of the element for k = 1:Less ; k_row = (it - 1)*n_sec + k ; k_end = k_row + inc ; k_gen (1) = el_sect_xyz_stress (k_row, 4+i_p) ; k_gen (2) = el_sect_xyz_stress (k_end, 4+i_p) ; force = max (k_gen) ; k_gen = k_gen / S_range ; % -1 to +1 in stress % get shaft force rectangle (? polygon ?) dx = el_sect_xyz_stress(k_end,2)-el_sect_xyz_stress(k_row,2) ; dy = el_sect_xyz_stress(k_end,3)-el_sect_xyz_stress(k_row,3) ; L = sqrt(dx*dx + dy*dy) ; if ( L > 0.0 ) % can plot x_off (1:2) = -dy/L * k_gen (1:2) * Diagonal ; y_off (1:2) = dx/L * k_gen (1:2) * Diagonal ; fx (1) = c_x (1) ; %b el_sect_xyz_stress (k_row, 2) ; fx (2) = c_x (2) ; %b el_sect_xyz_stress (k_end, 2) ; fx (3) = fx (2) + x_off (2) ; fx (4) = fx (1) + x_off (1) ; fy (1) = c_y (1) ; %b el_sect_xyz_stress (k_row, 3) ; fy (2) = c_y (2) ; %b el_sect_xyz_stress (k_end, 3) ; fy (3) = fy (2) + y_off (2) ; fy (4) = fy (1) + y_off (1) ; fill (fx, fy, force) % plot force color %b if ( it == 11) %b disp(force) %b disp(L) %b disp(x_off) %b disp(y_off) %b disp(fx) %b disp(fy) %b end % if end % if zero length end % for k % % plot (c_x, c_y) % plot nod_per_el lines end % for over all elements colorbar % Finish the plots with polygon numbers if (inc_e > 0) % plot elem number, inclined for i = 1:inc_e:nt % convert to string t_text = sprintf (' %g', i); % offset # from pt text (x_bar(i), y_bar(i), t_text, 'Rotation', 45) % incline end % for all polygons end % if show labels % -depsc -tiff % for an eps version %b print -dpsc frame_stress_plot hold off %b fprintf ('Created file frame_stress_plot.ps \n') % end of frame_stress_plot