Advertisement
Guest User

Mesh Import Example

a guest
May 23rd, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.33 KB | None | 0 0
  1. function [Points, vVolumeFaceMx, vSurfFaceMx] = ansysMeshReader(fileName)
  2.  
  3. fid = fopen(fileName, 'r');
  4.  
  5. %% Write all lines as strings
  6. cac = textscan( fid, '%[^\n]' );
  7.     fclose(fid);
  8.     A  = char( cac{1} );
  9.  
  10. %% Locate Point Mx
  11. i=1;
  12. % Initalize Termination Conditions: do while termination condition == 0
  13. end_of_points = 0; end_of_volume_faces = 0; end_of_surface_faces1 = 0;
  14. while (i<=size(A,1)-1)
  15.     if strcmp(A(i, 1:4), '(10 ')==1 && strcmp(A(i+1, 1:4), '(10 ')~=1 % Find line before points defined, usually line 5
  16.         start_of_points=i+2;    % i+2 modified for ANSYS mesh files
  17.         while end_of_points == 0
  18.             if strcmp(A(i, 1:2),'))')==1
  19.                 end_of_points=i-1;  
  20.             end
  21.             i=i+1;
  22.         end
  23.     end
  24.    
  25.     % Count on (for now) volume faces coming first
  26.    
  27.     if strcmp(A(i, 1:4), '(13 ')==1 && strcmp(A(i+2, 1:4), '(13 ')~=1 && end_of_volume_faces == 0
  28.         start_of_volume_faces=i+1;
  29.         while end_of_volume_faces == 0
  30.             if strcmp(A(i, 1), ')') && strcmp(A(i+1, 1), ')') ==1
  31.                 end_of_volume_faces=i-1;
  32.             end
  33.             i=i+1;
  34.         end
  35.     end
  36.     if strcmp(A(i, 1:4), '(13 ')==1 && end_of_volume_faces ~=0
  37.         start_of_surface_faces1=i+1;
  38.         while end_of_surface_faces1 == 0
  39.             if strcmp(A(i, 1), ')') && strcmp(A(i+1, 1), ')') ==1
  40.                 end_of_surface_faces1=i-1;
  41.                 i=size(A,1);
  42.             end
  43.             i=i+1;
  44.         end
  45.     end
  46.     i=i+1;
  47. end
  48.  
  49.  
  50. % Write points to MX
  51. Points = zeros(end_of_points,3);    % Initialize
  52. for i=start_of_points : end_of_points
  53.     Points(i-start_of_points+1, :)=sscanf(A(i,:), '%f');
  54. end
  55.  
  56. % Write volume faces to a matrix
  57. for i=start_of_volume_faces : end_of_volume_faces
  58. %    vFaceMx(i-start_of_faces+1, :)=sscanf(A(i,:), '%f'); %if mesh does not have hexidec notation
  59.      vVolumeFaceMx(i-start_of_volume_faces+1, :)=sscanf(A(i,:), '%x'); %if mesh uses hexidec notation
  60. end
  61.  
  62. % Write Surface Faces to a Matrix
  63. for i=start_of_surface_faces1 : end_of_surface_faces1
  64. %    vFaceMx(i-start_of_faces+1, :)=sscanf(A(i,:), '%f'); %if mesh does not have hexidec notation
  65.      vSurfFaceMx(i-start_of_surface_faces1+1, :)=sscanf(A(i,:), '%x'); %if mesh uses hexidec notation
  66. end
  67.  
  68. vVolumeFaceMx = vVolumeFaceMx(:,1:4);
  69. vSurfFaceMx = vSurfFaceMx(:,1:3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement