function exact_and_fe_node_flux_vec (mesh, length) % NOTE Fourier sign changes below % Copyright 2000, J.E. Akin. All rights reserved. % ------------------------------------------------------ % plot 2-D exact and SCP average flux vectors at the nodes % ------------------------------------------------------ % mesh = 1, show mesh lines, =0 omit % length = maximum length of arrows, in scaled x,y units % 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 % 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 % 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 ) mesh = 1 ; % show mesh length = 0.3 ; % the max length on paper elseif ( nargin == 1 ) length = 0.3 end % if % 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) % 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 nod_per_el = size (msh_typ_nodes,2) - pre_e -1; % nodes per element fprintf ('Read %g elements connections \n', nt) % Read new exact node flux components load exact_node_flux.tmp ; % du/dx, du/dy at nodes % Set control data: number of nodes npg = size(exact_node_flux,1) ; % pts w vectors if ( npg == 0 ) error ('Error: missing file exact_node_flux.tmp') end % if error fprintf ('Read %g nodal exact flux sets \n', npg) nf = size(exact_node_flux,2) ; % 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') error ('Error: These are not vector data') end % if vector data % Read new SCP node flux components load scp_node_ave_fluxes.tmp ; % du/dx, du/dy at nodes % Set control data: number of nodes npgs = size(scp_node_ave_fluxes,1) ; % pts w vectors if ( npgs == 0 ) error ('Error: missing file scp_node_ave_fluxes.tmp') end % if error fprintf ('Read %g nodal SCP flux sets \n', npgs) nfs = size(scp_node_ave_fluxes,2) ; % flux components if ( nfs ~= 2 ) % vectors not meaningful fprintf ('Read %g flux components instead of 2 \n', nfs) fprintf ('Use contour_el_fluxes or smooth_el_fluxes instead \n') 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 % 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 e_dx(npg) = 0. ; % pre-allocate flux array e_dy(npg) = 0. ; % pre-allocate flux array e_sq(npg) = 0. ; % pre-allocate magnitude array s_dx(npg) = 0. ; % pre-allocate flux array s_dy(npg) = 0. ; % pre-allocate flux array s_sq(npg) = 0. ; % pre-allocate magnitude 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 gxmax = max (x) ; gxmin = min (x) ; gymax = max (y) ; gymin = min (y) ; gxdiff = gxmax - gxmin ; gydiff = gymax - gymin ; if ( gydiff == 0.0 ) gydiff = 0.5 ; % allow for 1-D mesh (with y == 0) end % if no y coordinates % Exact Flux Values % Fourier sign change d_x(2) = 0. ; d_y(2) = 0. ; % vector ends on paper e_dx = -exact_node_flux(:,1) ; % flux e_dy = -exact_node_flux(:,2) ; % flux e_sq = sqrt (e_dx.^2 + e_dy.^2) ; big_e = max (e_sq) ; % magnitude largest = 1.e-6; % avoid division by zero if ( big_e > largest ) largest = big_e; end % if % SCP Flux Values % Fouried sign change s_dx = -scp_node_ave_fluxes(:,1) ; % flux s_dy = -scp_node_ave_fluxes(:,2) ; % flux s_sq = sqrt (s_dx.^2 + s_dy.^2) ; big_s = max (s_sq) ; % magnitude if ( big_s > largest ) largest = big_s; end % if % Scale exact flux vectors e_sq = e_sq*length/largest ; % flux scaled %b % Scale SCP flux vectors s_sq = s_sq*length/largest ; % flux scaled %b % convert flux vector end to scaled paper positioin s_dx = x + length * s_dx /largest ; % flux component end position s_dy = y + length * s_dy /largest ; % flux component end position e_dx = x + length * e_dx /largest ; % flux component end position e_dy = y + length * e_dy /largest ; % flux component end position % Node points are always on the mesh geometry, BUT % the ends of the scaled flux vector often is not. Check those % end points for plot scaling fxmax = max (e_dx) ; fxmin = min (e_dx) ; fymax = max (e_dy) ; fymin = min (e_dy) ; sxmax = max (s_dx) ; sxmin = min (s_dx) ; symax = max (s_dy) ; symin = min (s_dy) ; % Scale everything xmax = max([gxmax, fxmax, sxmax]); xmin = min([gxmin, fxmin, sxmin]); ymax = max([gymax, fymax, symax]); ymin = min([gymin, fymin, symin]); 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: ', int2str(nt),' Elements']) ylabel (['Y: ', int2str(np),' Nodes (', ... int2str(nod_per_el), ' per Element) ']) title (['Nodal 2-D Fluxes; Exact (solid, max = ', ... num2str(big_e), ') & FEA SCP (dash, max = ', ... num2str(big_s), ')' ]) % Select element type details [loop] = get_El_Loop (nod_per_el) ; % % Plot input mesh points & label them if (mesh == 0) % plot all points plot (x, y, 'g+') % mark each node end % if show labels % Show 20 nodes and 10 elements inc_p = floor(np/20) ; inc_e = floor(nt/10) ; 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_p=0 ; inc_e=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 (' ') if ( mesh == 1) % Loop over all elements, plot mesh for it = 1:nt ; % Extract corner connectivity t_nodes = msh_typ_nodes (it, (pre_e+2):(nod_per_el+pre_e+1)); % Extract corner coordinates t_x = x (t_nodes) ; % x at those nodes, only t_y = y (t_nodes) ; % y at those nodes, only % 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 plot (c_x, c_y, 'b-') % plot nod_per_el lines, in blue end % for over all elements end % if plot mesh % Finish the plots with polygon numbers if (inc_e > 0) % plot elem number, inclined for it = 1:inc_e:nt % convert to string % Extract corner connectivity t_nodes = msh_typ_nodes (it, (pre_e+2):(nod_per_el+pre_e+1)); % 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 = sum (t_x' )/nod_per_el ; y_bar = sum (t_y' )/nod_per_el ; t_text = sprintf (' %g', it); % offset # from pt text (x_bar, y_bar, t_text, 'Rotation', 45) % incline plot (x_bar, y_bar, 'g.') % centroid of each element end % for all polygons end % if show labels % ---------------- Now add the vectors to the mesh -------------- % Plot flux arrows at Gauss point for ig = 1:npg % FE values d_x(1) = x(ig) ; d_y(1) = y(ig) ; % vector start point % exact vector d_x(2) = e_dx(ig) ; % vector end position d_y(2) = e_dy(ig) ; % vector end position plot (d_x, d_y, 'r-') % red line plot (d_x(2), d_y(2), 'r.') % red end point % SCP average vector d_x(2) = s_dx(ig) ; % vector end position d_y(2) = s_dy(ig) ; % vector end position plot (d_x, d_y, 'k--') % black dash line plot (d_x(2), d_y(2), 'k.') % black end point end % for Gauss pts % -depsc -tiff % for an eps version %b print -dpsc exact_and_scp_2d_vectors hold off %b fprintf ('Created file exact_and_scp_2d_vectors.ps \n') % end