function shaft_section_force_color (i_p, i_d) % Copyright 2006, J.E. Akin. All rights reserved. % ------------------------------------------------------ % Graph of (space frame) shaft generalized forces % plot component i_p along direction axis i_d % components are 1-3 Force in x-Z, 4-6 Moments % ------------------------------------------------------ % c_x = x coordinates of nod_per_el line polygon % c_y = y coordinates of nod_per_el line polygon % inc_e = increment in element numbers on plot, if > 0 % inc_p = increment in node numbers on plot, if > 0 % loop = corners for nod_per_el line polygon % lab_p = 1, if node points are circled lab_p = 0; % msh_bc_xyz = Nodal coordinates (with preceeding data) % msh_typ_nodes = connectivity list for elements, nt x nod_per_el % nod_per_el = Nodes per element % np = Number of Points % nt = Number of elements % S_1 = Element shrink ratio, 1 = none S_1 = 0.8 ; % S_2 = Gap size, = 1 - S_1 S_2 = 1 - S_1 ; % pre_e = Element items before connectivity list pre_e = 0 ; % pre_p = Nodal items before coordinates pre_p = 1; % 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 if ( nargin == 0 ) i_p = 1 ; i_d = 1 ; elseif ( nargin == 1 ) i_d = 1 ; end % if no arguments % Read coordinate file and connectivity file % integer bc code, real xy pairs for np points (pre_p = 1) % Set control data: number of points load msh_bc_xyz.tmp ; np = size (msh_bc_xyz,1) ; % number of nodal points 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 ('Read %g mesh coordinate pairs \n', np) if (ns > 1 ) % then assume z=0 fprintf('Using only coordinate direction %g. \n', i_d) end % if x (np) = 0. ; % pre-allocate array x % msh_bc_xyz has: pre_p items then: x, y, z %b x = msh_bc_xyz (1:np, (pre_p+1)) ; % extract x column of xy x = msh_bc_xyz (1:np, (pre_p+i_d)) ; % extract x column of xy %b if ( ns >= 2) %b y = msh_bc_xyz (1:np, (pre_p+2)) ; % extract y column of xy %b else %b y (1:np) = 0. ; %b 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 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 elem fprintf ('Read %g elements with %g nodes each \n', nt,nod_per_el) [M_min, J_min] = min ( msh_typ_nodes ) ; if any ( M_min < 1 ) fprintf ('Mesh seems to have mixed element types, \n') end % if % get element result magnitude from node 1 to 2 load el_sect_xyz_forces.tmp en = size(el_sect_xyz_forces,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 % set constants [loop] = get_El_Loop (nod_per_el) ; % Initialize plots xmax = max (x) ; xmin = min (x) ; xdiff = xmax - xmin ; ymax = max (el_sect_xyz_forces(:, 4+i_p)) ; ymin = min (el_sect_xyz_forces(:, 4+i_p)) ; %b y_scale = abs (ymin) + abs (ymax) ; %b if ( y_scale == 0 ) %b fprintf ('WARNING, all selected shaft values are zero. \n') if ( ymax == ymin ) ymax = ymax + 1. ; ymin = ymin - 1. ; end % IF y (1:np) = ymin ; % SET TO ZERO FOR LABELS ydiff = ymax - ymin ; if ( ydiff == 0.0 ) ydiff = 0.5 ; % allow for 1-D mesh (with y == 0) end % if no y coordinates clf % clear graphics axis ([xmin, xmax, ymin, ymax]) % set axes hold on % hold image for plots grid % add grid dots if ( i_d == 1 ) xlabel (['X for mesh with ', int2str(np),' nodes, ' ... int2str(nt), ' elements (',int2str(nod_per_el), ... ' nodes per element)']) elseif ( i_d == 2 ) xlabel (['Y for mesh with ', int2str(np),' nodes, ' ... int2str(nt), ' elements (',int2str(nod_per_el), ... ' nodes per element)']) else xlabel (['Z for mesh with ', int2str(np),' nodes, ' ... int2str(nt), ' elements (',int2str(nod_per_el), ... ' nodes per element)']) end % if coordinate axis if ( i_p == 1 ) ylabel ('Force F_x (axial)') elseif ( i_p == 2 ) ylabel ('Force F_y (for bending about z)') elseif ( i_p == 3 ) ylabel ('Force F_z (for bending about y)') elseif ( i_p == 4 ) ylabel ('Moment M_x (torsional)') elseif ( i_p == 5 ) ylabel ('Moment M_y (bending about y)') elseif ( i_p == 6 ) ylabel ('Moment M_z (bending about z)') else error ('First argument is 1 <= i_p <= 6.') end % if title (['Shaft Generalized Force ', int2str(i_p), ... ' (max = ', num2str(ymax), ', min = ', num2str(ymin), ')']) % Plot input mesh points & label them if (lab_p == 1) % plot all points plot (x, y, 'b.') % mark each node end % if show labels % Show 20 nodes and 50 elements, or all for small mesh inc_p = floor(np/20) ; inc_e = floor(nt/50) ; if (inc_p == 0 ) inc_p = np - 1 ; end % if inc_p if (inc_e == 0 ) inc_e = nt - 1 ; end % if inc_e % Show all if a small mesh if ( np <= 20 ) inc_p = 1 ; end % if np if ( nt <= 50 ) inc_e = 1 ; end % if nt %b inc_p = 1 %b inc_e = 0 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 I_J = msh_typ_nodes(i, j+1) ; if ( I_J > 0 ) in_mesh ( I_J ) = 1; % flag as present end % if a non-zero node % in_mesh (msh_typ_nodes(i, j)) = 1; % flag as present end % for its nodes end % for all elements for i = 1:inc_p:np ; % convert to string 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 plot (x(i), y(i), 'g*') end % if present end % for all points end % if show labels % 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, (pre_e+2):(nod_per_el+pre_e+1)); [N_min, I_min] = min ( t_nodes ) ; if ( N_min < 1 ) fprintf ('Element %g connectivity corrected \n', it) t_nodes ( I_min:nod_per_el ) = t_nodes ( I_min - 1 ) ; % repeat the last non-zero node end % if % Extract corner coordinates t_x = x (t_nodes) ; % x at those nodes, only t_y = y (t_nodes) ; % y at those nodes, only % Get the centroid x_bar (it) = sum (t_x' )/nod_per_el ; y_bar (it) = sum (t_y' )/nod_per_el ; % Plot this 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 c_x = S_1 * c_x + S_2 * x_bar (it) ; % shrink x c_y = S_1 * c_y + S_2 * y_bar (it) ; % shrink y % 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_forces (k_row, 4+i_p) ; k_gen (2) = el_sect_xyz_forces (k_end, 4+i_p) ; force = max (k_gen) ; % get shaft force rectangle (? polygon ?) dx = el_sect_xyz_forces(k_end,2)-el_sect_xyz_forces(k_row,2) ; dy = el_sect_xyz_forces(k_end,3)-el_sect_xyz_forces(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) ; y_off (1:2) = dx/L * k_gen (1:2) ; fx (1) = el_sect_xyz_forces (k_row, 2) ; fx (2) = el_sect_xyz_forces (k_end, 2) ; fx (3) = fx (2) + x_off (2) ; fx (4) = fx (1) + x_off (1) ; fy (1) = el_sect_xyz_forces (k_row, 3) ; fy (2) = el_sect_xyz_forces (k_end, 3) ; fy (3) = fy (2) + y_off (2) ; fy (4) = fy (1) + y_off (1) ; fill (fx, fy, force) % plot force color 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 % print -dpsc shaft_section_force_color hold off % fprintf ('Created file shaft_section_force_color.ps \n') % end of shaft_section_force_color