function quiver_qp_3d_flux_mesh (scale, inc_g, sign) % default (1.0, 1, 1) % Copyright 2000, J.E. Akin. All rights reserved. % ------------------------------------------------------ % Matlab plot of 2-D FE flux vectors at elem Gauss pts, with mesh % ------------------------------------------------------ % 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_g = increment in Gauss point vector plot, default = 1 % 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; % length = maximum length of arrows, in scaled x,y units % 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_p = 1 ; % msh_bc_xyz = Nodal coordinates (with preceeding data) % scale = standard Matlab scale argument, default 1.0 % 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 % set constants if ( nargin == 0 ) scale = 1. ; % the default scale inc_g = 1 ; sign = 1 ; inc_e = 0 ; inc_p = 0 ; elseif ( nargin == 1 ) inc_g = 1 ; sign = 1 ; inc_e = 0 ; inc_p = 0 ; elseif ( nargin == 2 ) sign = 1 ; inc_e = 0 ; inc_p = 0 ; end % if fprintf ('Using a scale of %g and vector increment of %g \n', ... scale, inc_g) % 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 ns = size (msh_bc_xyz,2) - 1; % dimension of space fprintf ('Read %g mesh coordinates \n', np) fprintf ('In %g spatial dimensions \n', ns) % fprintf (' x y \n') % 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 pre_e = 0 ; nod_per_el = size (msh_typ_nodes,2) - pre_e -1; % nodes per element fprintf ('Read %g elements connections \n', nt) face_nodes = 4; faces=6; if ( nod_per_el ~= 8 ) error ('This is not a hexahedra mesh') end % if H8 % Read new Gauss locations & flux components load el_qp_xyz_fluxes.tmp ; % x, y, du/dx, du/dy at qp % Set control data: number of gauss points npg = size(el_qp_xyz_fluxes,1) ; % quadrature pts w vectors if ( npg == 0 ) error ('Error: missing file el_qp_xyz_fluxes.tmp') end % if error fprintf ('Read %g Gauss x & y coord & flux sets \n', npg) nf = size(el_qp_xyz_fluxes,2) - ns; % flux components if ( nf ~= 2 ) % vectors not meaningful fprintf ('Read %g flux components instead of 2 \n', nf) fprintf ('Use contour_el_fluxes or smooth_el_fluxes instead \n') if ( ns == 1 ) % 1-d data fprintf ('Use el_qp_1d_flux_graph for 1-D data \n') end % if 1-d fprintf ('Will use first 2 components only. \n') nf = 2; %b error ('Error: These are not vector data') end % if vector data x (np) = 0. ; % pre-allocate array x y (np) = 0. ; % pre-allocate array y z (np) = 0. ; % pre-allocate array y 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 (face_nodes + 1) = 0 ; % Optional pre-allocation c_y (face_nodes + 1) = 0 ; % Optional pre-allocation c_z (face_nodes + 1) = 0 ; % Optional pre-allocation loop (face_nodes + 1) = 0 ; % Optional pre-allocation % g_x(npg) = 0. ; % pre-allocate position array % g_y(npg) = 0. ; % pre-allocate position array % g_dx(npg) = 0. ; % pre-allocate flux array % g_dy(npg) = 0. ; % pre-allocate flux array % Mesh Range Alone % msh_bc_xyz has: pre_p items then: x, y x = msh_bc_xyz (1:np, (pre_p+1)) ; % extract x column of xy y = msh_bc_xyz (1:np, (pre_p+2)) ; % extract y column of xy z = msh_bc_xyz (1:np, (pre_p+3)) ; % extract z column of xy gxmax = max (x) ; gxmin = min (x) ; gymax = max (y) ; gymin = min (y) ; gzmax = max (z) ; gzmin = min (z) ; if ( gzmax == gzmin ) gzmax = gzmin + 0.1 ; if ( gymax == gymin ) gymax = gymin + 0.1 ; end % if end % if planar or axial %% FE Flux Values % d_x(2) = 0. ; d_y(2) = 0. ; % vector ends on paper g_x = el_qp_xyz_fluxes(1:inc_g:npg,1) ; % position g_y = el_qp_xyz_fluxes(1:inc_g:npg,2) ; % position g_z = el_qp_xyz_fluxes(1:inc_g:npg,3) ; % position g_dx = sign * el_qp_xyz_fluxes(1:inc_g:npg,4) ; % flux g_dy = sign * el_qp_xyz_fluxes(1:inc_g:npg,5) ; % flux g_dz = sign * el_qp_xyz_fluxes(1:inc_g:npg,6) ; % flux g_sq = sqrt (g_dx.^2 + g_dy.^2 + g_dz.^2) ; big = max (g_sq) ; % magnitude g_dx = - g_dx ; g_dy = - g_dy ; % Fourier law sign change g_dz = - g_dz ; % Fourier law sign change largest = 0.0 ; % Scale flux vectors if ( big > largest ) largest = big; % g_sq = g_sq*length/largest ; % flux scaled %b % %% convert flux vector end to scaled paper positioin % g_dx = g_x + length * g_dx /big ; % flux component end position % g_dy = g_y + length * g_dy /big ; % flux component end position % %% Gauss points are always inside the mesh geometry, BUT %% the ends of the scaled flux vector often is not. Check those %% end points for plot scaling % fxmax = max (g_dx) ; fxmin = min (g_dx) ; % fymax = max (g_dy) ; fymin = min (g_dy) ; % Scale everything % xmax = max([gxmax, fxmax]); xmin = min([gxmin, fxmin]); % ymax = max([gymax, fymax]); ymin = min([gymin, fymin]); % xmax = gxmax ; xmin = gxmin ; % ymax = gymax ; ymin = gymin ; % xmax = gxmax + gxdiff/10 ; ymax = gymax + gydiff/10 ; % keep % xmin = gxmin - gxdiff/10 ; ymin = gymin - gydiff/10 ; % keep % xmax = gxmax + gxdiff/20 ; % ymax = gymax + gydiff/20 ; % xmin = gxmin - gxdiff/20 ; % ymin = gymin - gydiff/20 ; clf % clear graphics axis ([gxmin, gxmax, gymin, gymax, gzmin, gzmax]) % set axes axis ('equal') % true shape style hold on % hold image for plots grid % add grid dots % xlabel (['X; for ', int2str(nt),' Elements']) xlabel (['X for ', int2str(nt),' Elements with ', ... int2str(nod_per_el), ' nodes']) ylabel (['Y; for ', int2str(np),' Nodes']) zlabel ('Z') if ( inc_g == 1 ) title (['FEA Element 3-D Flux Vectors at ', int2str(npg), ... ' Gauss Points, max = ', num2str(largest)]) % add title else title (['FEA Element 3-D Flux Vectors at ', int2str(npg), ... ' Gauss Points, inc = ', int2str(inc_g), ... ', max = ', num2str(largest)]) % add title end % if alternate title %% Plot input mesh points & label them % if (lab_p == 1) % plot all points % plot (x, y, z, 'b.') % mark each node % end % if show labels % Show 20 nodes and 10 elements inc_p = floor(np/10) ; inc_e = floor(nt/5) ; 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 <= 10 ) inc_e = 1 ; end % if nt % inc_e = 1 % inc_p = 1 % inc_p = 0 if (inc_p > 0) % plot node numbers for i = 1:inc_p:np % convert to string p_text = sprintf (' %g', i); % offset # from pt text (x(i), y(i), p_text) % plot pt number end % for all points end % if show labels % disp (' ') % Loop over all elements for it = 1:nt ; % Extract corner connectivity t_nodes = msh_typ_nodes (it, (pre_e+2):(nod_per_el+pre_e+1)); 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 % Select element type details clear loop; if ( nod_per_t == 8 ) % then solid [loop] = get_Solid_El_Loop (nod_per_t) ; elseif ( nod_per_t == 4 ) % then face [loop] = [1, 2, 3, 4, 1] ; % get_El_Loop(nod_per_t); elseif ( nod_per_t == 2 ) % then line [loop] = [1,2] ; else % point [loop] = [1]; end % if % Extract corner coordinates t_x = x (t_nodes(1:nod_per_t)) ; % x at those nodes, only t_y = y (t_nodes(1:nod_per_t)) ; % y at those nodes, only t_z = z (t_nodes(1:nod_per_t)) ; % z at those nodes, only % Get the centroid x_bar (it) = sum (t_x' )/nod_per_t ; y_bar (it) = sum (t_y' )/nod_per_t ; z_bar (it) = sum (t_z' )/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) ; 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) ; plot3 (c_x, c_y, c_z) % plot nod_per_el lines end % if brick end % for over all elements % Finish the plots with polygon numbers % inc_e = 0 %b if (inc_e > 0) % plot elem number, inclined % plot (x_bar, y_bar, z_bar, 'g.') % centroid of each element for i = 1:inc_e:nt % convert to string t_text = sprintf (' %g', i); % offset # from pt text (x_bar(i), y_bar(i), z_bar(i), t_text, 'Rotation', 45) end % for all polygons end % if show labels % ---------------- Now add the vectors to the mesh -------------- quiver3 (g_x, g_y, g_z, g_dx, g_dy, g_dz, scale) % -depsc -tiff % for an eps version % print -dpsc quiver_qp_xyz_flux_mesh hold off % fprintf ('Created file quiver_qp_xyz_flux_mesh.ps \n') end % quiver_qp_3d_flux_mesh