function bare_el_error_color_plot () % Copyright 2000, J.E. Akin. All rights reserved. % ------------------------------------------------------ % Matlab plot 2-D FE numerical error in elements by color % ------------------------------------------------------ % 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 %-error on plot, if > 0 inc_e = 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; % nod_per_el = Nodes per element % np = Number of Points % nt = Number of elements % pre_e = Element items before type, connectivity list % 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 % 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 fprintf ('Read %g mesh coordinate pairs \n', np) % fprintf (' x y \n') % Set control data: number elements & nodes per element pre_e = 0 ; % items before type, connectivity list 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 el fprintf ('Read %g elements connections \n', nt) % fprintf ('Pt1 Pt2 Pt3 Pt4 Pt5 Pt6 Pt7 Pt8 \n') load el_error_est.tmp nerr = size (el_error_est,1) ; if ( nerr == 0 ) error ('Error missing file el_error_est.tmp') end % if error fprintf ('Read %g elements error values \n', nerr) [V_X, L_X] = max (el_error_est) ; [V_N, L_N] = min (el_error_est) ; V_XN = V_X - V_N + eps; % for color scale Rank_X = 14; Rank_N = 1; % for color scale fprintf ('Max value is %g in element %g \n', V_X, L_X) fprintf ('Min value is %g in element %g \n', V_N, L_N) 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 % set constants [loop] = get_El_Loop (nod_per_el) ; % 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 % Initialize plots fprintf ('Begin element error value plots: \n') xmax = max (x) ; xmin = min (x) ; ymax = max (y) ; ymin = min (y) ; xdiff = xmax - xmin ; ydiff = ymax - ymin ; if ( ydiff == 0.0 ) ydiff = 0.1 * xdiff ; % allow for 1-D mesh (with y == 0) ymax = ymin + ydiff ; end % if no y coordinates % xmax = xmax + xdiff/10; ymax = ymax + ydiff/10; % xmin = xmin - xdiff/10; ymin = ymin - ydiff/10; 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']) xlabel (['X: ', int2str(nt),' Elements (with ', ... int2str(nod_per_el), ' nodes)']) ylabel (['Y: ', int2str(np),' Nodes']) format short title(['FEA SCP Error Estimate, ', num2str(V_N*100), '-', ... num2str(V_X*100), ' % Energy\_norm * 100']) % text ((xmin+xdiff/20), (ymin+ydiff/20), ... % ['High = ', num2str(V_X*100), ', Low = ', num2str(V_N*100)]) % Plot input mesh points if (lab_p == 1) % plot all points plot (x, y, 'b.') % mark each node end % if show labels % Show 20 nodes and 50 elements 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 % Loop over all elements for it = 1:nt ; % Rank the colors V_R = el_error_est (it) ; Rank = round ((Rank_X * (V_R-V_N) + Rank_N * (V_X-V_R)) / V_XN); % disp(V_R) % disp(Rank) % scale 14 colors as one set of 7 if ( Rank == 14) ; color = 'r' ; % red elseif ( Rank == 13) ; color = 'r' ; % red elseif ( Rank == 12) ; color = 'y' ; % yellow elseif ( Rank == 11) ; color = 'y' ; % yellow elseif ( Rank == 10) ; color = 'g' ; % green elseif ( Rank == 9 ) ; color = 'g' ; % green elseif ( Rank == 8 ) ; color = 'b' ; % blue elseif ( Rank == 7 ) ; color = 'b' ; % blue elseif ( Rank == 6 ) ; color = 'c' ; % cyan elseif ( Rank == 5 ) ; color = 'c' ; % cyan elseif ( Rank == 4 ) ; color = 'm' ; % magenta elseif ( Rank == 3 ) ; color = 'm' ; % magenta elseif ( Rank == 2 ) ; color = 'w' ; % white elseif ( Rank == 1 ) ; color = 'w' ; % white else ; color = 'k' ; % black (impossible ??) end % if for rank color % disp(color) % switch Rank % for 14 color scale (two sets of 7) % case {(Rank == 14), (Rank == 7)} ; color = 'r' ; % red % case {(Rank == 13), (Rank == 6)} ; color = 'y' ; % yellow % case {(Rank == 12), (Rank == 5)} ; color = 'g' ; % green % case {(Rank == 11), (Rank == 4)} ; color = 'b' ; % blue % case {(Rank == 10), (Rank == 3)} ; color = 'c' ; % cyan % case {(Rank == 9), (Rank == 2)} ; color = 'm' ; % magenta % case {(Rank == 8), (Rank == 1)} ; color = 'w' ; % white % otherwise ; color = 'k' % black % end % switch % 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 (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 fill (c_x, c_y, color) % fill element color %% Show max element in red % if ( it == L_X ) % fill (c_x, c_y,'r') % fill with red % end % if max end % for over all elements % Show max & min element value p_text = sprintf ('*---MIN %6.1f', V_N*100); % offset # from pt text (x_bar(L_N), y_bar(L_N), p_text) % plot min value p_text = sprintf ('*---MAX %6.1f', V_X*100); % offset # from pt text (x_bar(L_X), y_bar(L_X), p_text) % plot max value 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 (' ') % Finish the plots with elem error estimate numbers inc_e = 0 if (inc_e > 0) % plot elem number, inclined for i = 1:inc_e:nt % convert to string v = 100. * el_error_est (i) ; % el %-error value t_text = sprintf ('%6.1f', v); % convert to text text (x_bar(i), y_bar(i), t_text, 'Rotation', 40) % incline end % for all polygons end % if show labels % -depsc -tiff % for an eps version %bprint -dpsc bare_el_error_color_plot hold off %bfprintf ('Created file bare_el_error_color_plot.ps \n') % end of bare_el_error_color_plot