function spaceframe_load_quiver (d_scale, inc_m, inc_e, inc_p, Type) % Copyright 2005, J.E. Akin. All rights reserved. % ------------------------------------------------------ % Matlab program to calculate & plot 3-D FE meshes % d_scale = deflection multiplier (default 100) % inc_m = 1, include original mesh, else omit % If Type = 0, plot all elements, else only type % If inc_ < 0 show no numbers, = 0 show max of 10 % > 0 use given increment in plotting numbers % ------------------------------------------------------ if ( nargin == 0 ) d_scale = 100.0 ; inc_m = 1; inc_e = 1 ; inc_p = 1 ; Type = 0 ; elseif ( nargin == 1 ) inc_m = 1; inc_e = 1 ; inc_p = 1 ; Type = 0 ; elseif ( nargin == 2 ) inc_e = 1 ; inc_p = 1 ; Type = 0 ; elseif ( nargin == 3 ) inc_p = 1 ; Type = 0 ; elseif ( nargin == 4 ) Type = 0 ; end % if nargin fprintf ('Using scale %g, d_scale ') % S_1 = Element shrink ratio, 1 = none S_1 = 1.0 ; %b 0.8 ; % TURN THIS OFF % S_2 = Gap size, = 1 - S_1 S_2 = 1 - S_1 ; % 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 % 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 % nod_per_t = Nodes per type % np = Number of Points % nt = Number of elements % pre_e = Element items before connectivity list pre_e = 0 ; % pre_p = Nodal items before coordinates % msh_bc_xyz = Nodal coordinates (with preceeding data) % 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 % 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 ; pre_p = 1; 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) % fprintf (' x y \n') x (np) = 0. ; % pre-allocate array x y (np) = 0. ; % pre-allocate array y z (np) = 0. ; % pre-allocate array y sx (np) = 0. ; ! load component sy (np) = 0. ; ! load component sz (np) = 0. ; ! load component %b sv (np) = 0. ; ! load value % msh_bc_xyz has: pre_p items then: x, y x = msh_bc_xyz (1:np, (pre_p+1)) ; % extract x column of xyz y = msh_bc_xyz (1:np, (pre_p+2)) ; % extract y column of xyz z = msh_bc_xyz (1:np, (pre_p+3)) ; % extract z column of xyz % 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 %b nod_per_el = size (msh_typ_nodes,2) - pre_e ; % nodes per element nod_per_el = size (msh_typ_nodes,2) - pre_e - 1 ; % nodes per element nod_per_t = nod_per_el ; fprintf ('Read %g elements with an element type \n', nt) fprintf ('and %g nodes each \n', nod_per_el) face_nodes = 4; faces=6; % Get applied forces load msh_pt_load.tmp % node, component, value, eq_no nd = size (msh_pt_load, 1) ; if ( nd == 0 ) error ('Error missing file msh_pt_load.tmp') end % if error fprintf ('Read %g applied load components \n', nd) % insert non-zero values for j = 1:nd j_N = msh_pt_load (j, 1) ; j_DOF = msh_pt_load (j, 2) ; j_V = msh_pt_load (j, 3) if ( j_V ~= 0 ) % active load (not input terminator) if (j_DOF < 4 ) % then force not moment if ( j_DOF == 1 ) sx(j_N) = j_V ; elseif ( j_DOF == 2 ) sy(j_N) = j_V ; elseif ( j_DOF == 3 ) sz(j_N) = j_V ; else error ('Invalid load data at node %g \n, j_N') end % if which j_DOF end % if j_DOF end % if j_V EQ = 3*(j_N - 1) + j_DOF ; %b sv (EQ) = sqrt ( sx(EQ)^2 + sy(EQ)^2 + sz(EQ)^2 ) ; end % for j pre_r = 0; [X_X, L_X] = max ( abs ( sx (:) ) ) ; [Y_X, L_Y] = max ( abs ( sy (:) ) ) ; [Z_X, L_Z] = max ( abs ( sz (:) ) ) ; Max_Disp = max ([X_X, Y_X, Z_X]) ; maxx = max (x) ; minx = min (x) ; maxy = max (y) ; miny = min (y) ; maxz = max (z) ; minz = min (z) ; Max_Len= max([(maxx-minx),(maxy-miny),(maxz-minz)]) ; Good_Scale=Max_Len/Max_Disp/200 ; fprintf ('Suggested scale = %g \n', Good_Scale) %b X_X = msh_pt_load (L_X, pre_r+1) ; %CL %b Y_X = msh_pt_load (L_Y, pre_r+2) ; %CL %b Z_X = msh_pt_load (L_Z, pre_r+3) ; %CL %% zero out the load components % sx = d_scale * msh_pt_load (:, pre_r+1) ; %CL % sy = d_scale * msh_pt_load (:, pre_r+2) ; %CL % sz = d_scale * msh_pt_load (:, pre_r+3) ; %CL el_type (nt) = 0 ; % pre-allocate array el_type x_bar (nt) = 0. ; % pre-allocate array x_bar y_bar (nt) = 0. ; % pre-allocate array y_bar z_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 t_z (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 c_z (nod_per_el + 1) = 0 ; % Optional pre-allocation loop (nod_per_el + 1) = 0 ; % Optional pre-allocation % fprintf ('Begin element plots:') % Initialize plots size(x) size(sx) maxsx = max (sx'+x) ; minsx = min (sx'+x) ; maxsy = max (sy'+y) ; minsy = min (sy'+y) ; maxsz = max (sz'+z) ; minsz = min (sz'+z) ; xmax = max ([maxx, maxsx]) ; xmin = min ([minx, minsx]) ; ymax = max ([maxy, maxsy]) ; ymin = min ([miny, minsy]) ; zmax = max ([maxz, maxsz]) ; zmin = min ([minz, minsz]) ; ymin = 0. clf % clear graphics axis ([xmin, xmax, ymin, ymax, zmin, zmax]) % set axes axis ('equal') % true shape style hold on % hold image for plots grid % add grid dots xlabel ('X') ylabel ('Y') zlabel ('Z') % get the element types Max_type = max (el_type) ; fprintf (' Maximum element type number is %g \n', Max_type) if ( Type < 0 | Type > Max_type ) error ('Error requested type not available') end % if error % count various types Type_count (1:Max_type) = 0 ; if ( Max_type > 1 ) for j = 1:nt k = el_type (j) ; Type_count ( k ) = Type_count ( k ) + 1 ; end % for j for j = 1:Max_type fprintf ('Type %g has %g elements \n', j, Type_count (j)) end % for j end % if Max_typ %% Show 10 nodes and 10 elements, or all for small mesh if ( inc_e == 0 ) nt_show = nt ; if ( Type > 0 ) nt_show = Type_count (Type) ; end % if Type if ( nt_show <= 10 ) inc_e = 1 ; % else % inc_e = floor(nt_show/10) ; end % if show end % if inc_e if (inc_p == 0 ) if ( np <= 10 ) inc_p = 1 ; % else % inc_p = floor(np/10) ; end % if np end % if inc_p if ( inc_p > 0 ) in_mesh (1:np) = 0 ; % assume nodes absent end % if % Plot input mesh points & label them if (lab_p == 1) % plot all points plot3 (x, y, z, 'r.') % mark each node end % if show labels % Loop over all elements [loop] = get_El_Loop (nod_per_el) ; Old_type = 0; for it = 1:nt ; This_type = el_type (it) ; if ( This_type == Type | Type == 0 ) % then plot it % Extract corner connectivity t_nodes = msh_typ_nodes (it, (pre_e+2):(nod_per_el+pre_e+1)); % Get the type, nodes per type and loop array if ( Old_type ~= This_type ) Old_type = This_type ; nod_per_t = nod_per_el ; [Low_node, Low_I] = min (t_nodes) ; if ( Low_node <= 0 ) nod_per_t = Low_I - 1 ; end % if shorter topology list end % if a new type % Plot the original polygon t_x = x (t_nodes) ; % x original t_y = y (t_nodes) ; % y original t_z = z (t_nodes) ; % z original if ( inc_m == 1) c_x = t_x (loop) ; c_y = t_y (loop) ; c_z = t_z (loop) ; plot3 (c_x, c_y, c_z, 'g-') % plot nod_per_el lines end % if original mesh %% Extract corner coordinates % t_x = sx (t_nodes) ; % sx at those nodes, only % t_y = sy (t_nodes) ; % sy at those nodes, only % t_z = sz (t_nodes) ; % sz at those nodes, only % Flag these element's nodes as present in the mesh if ( inc_p > 0 ) in_mesh (t_nodes (1:nod_per_t)) = 1 ; end % if inc_p % Get the centroid x_bar (it) = sum (t_x (1:nod_per_t)' )/nod_per_t ; y_bar (it) = sum (t_y (1:nod_per_t)' )/nod_per_t ; z_bar (it) = sum (t_z (1:nod_per_t)' )/nod_per_t ; % Plot this polygon if (nod_per_t == 8 ) % then brick % Loop over each face for jf = 1:faces % Extract face nodes [loop] = get_H8_Face_Loop (jf) ; % continue if normal vector is visible % 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_z = t_z (loop) ; 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 c_z = S_1 * c_z + S_2 * z_bar (it) ; % shrink z plot3 (c_x, c_y, c_z) % plot nod_per_el lines end % for faces else % face, edge, or point 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_z = t_z (loop) ; 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 c_z = S_1 * c_z + S_2 * z_bar (it) ; % shrink z plot3 (c_x, c_y, c_z) % plot nod_per_el lines end % if brick end % if the right type end % for over all elements % Add the node numbers if requested Flip = 0; if ( inc_p > 0 ) % show labels 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 if ( Flip ) text (x(i), y(i), z(i), p_text) % plot pt number else text (sx(i), sy(i), sz(i), p_text) % plot pt number end % if Flip end % if present end % for all points end % if show labels % Finish the plots with polygon numbers if (inc_e > 0) % plot elem number, inclined % plot3 (x_bar, y_bar, z_bar, 'g.') % centroid of each element for it = 1:inc_e:nt % convert to string This_type = el_type (it) ; if ( This_type == Type | Type == 0 ) % then plot it t_text = sprintf (' %g', it); % offset # from pt text (x_bar(it),y_bar(it),z_bar(it),t_text,'Rotation',45) % incline plot3 (x_bar(it),y_bar(it),z_bar(it),'k.') % centroid end % if right type end % for all polygons end % if show labels if ( Type == 0 ) title (['Space Frame Applied Force Vectors * ', ... num2str(d_scale),': ', ... int2str(nt), ' Elements, ', int2str(np),' Nodes', ... ' (', int2str(nod_per_el), ' per element)']) else title (['Type ', int2str(Type), ' FE 3D Applied Force Vectors : ', ... int2str(Type_count (Type)), ' of ', ... int2str(nt), ' Elements, ', int2str(np),' Nodes', ... ' (', int2str(nod_per_t), ' per element)']) end % if % ---------------- Now add the vectors to the mesh -------------- %b quiver3 (x, y, z, sx, sy, sz, d_scale) already scaled quiver3 (x, y, z, sx', sy', sz', 1.0) % Plot input mesh points & label them % if (lab_p == 1) % plot all points plot3 (x, y, z, 'r.') % mark each node % end % if show labels % -depsc -tiff % for an eps version %bprint -dpsc spaceframe_load_quiver hold off %bfprintf ('Created file spaceframe_load_quiver.ps \n') % end of spaceframe_load_quiver