Changeset 16305
- Timestamp:
- 10/07/13 08:51:47 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m
r16304 r16305 1 function exportVTK(filename,model ,Solution)1 function exportVTK(filename,model) 2 2 % vtk export 3 3 % function exportVTK(filename,model,Solution) … … 19 19 mkdir(filename); 20 20 21 %get the element related variables 21 22 points=[model.mesh.x model.mesh.y model.mesh.z]; 22 23 [num_of_points,dim]=size(points); 23 24 [num_of_elt]=size(model.mesh.elements,1); 24 25 [point_per_elt]=size(model.mesh.elements,2); 25 sol_enum=EnumToString(Solution);26 27 sol_struct=model.results.(sol_enum);28 26 29 27 %Select the type of element function of the number of nodes per elements … … 36 34 end 37 35 36 %sol_enum=EnumToString(Solution); 37 38 %this is the result structure 39 res_struct=model.results; 40 41 %Getting all the solutions of the model 42 solnames=fields(res_struct); 43 num_of_sols=length(solnames); 44 45 %building solution structure 46 for i=1:num_of_sols 47 sol_struct{i}=res_struct.(solnames{i}); 48 end 49 38 50 %looking for multiple time steps 39 num_of_timesteps=size(sol_struct ,2);51 num_of_timesteps=size(sol_struct{1},2); 40 52 41 %getting the number of fields in the solution 42 fieldnames=fields(sol_struct(1)); 43 num_of_fields=length(fieldnames); 44 45 if num_of_timesteps==1; %just one timestep only write one file 46 47 FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk'),'w+'); 53 for i=1:num_of_timesteps; 54 %by default, we take the timestep from the first solution sturcture 55 timestep=sol_struct{1}(i).step; 56 57 FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk',int2str(timestep),'.vtk'),'w+'); 48 58 fprintf(FID,'# vtk DataFile Version 2.0 \n'); 49 59 fprintf(FID,'Data for run %s \n',model.miscellaneous.name); 50 60 fprintf(FID,'ASCII \n'); 51 61 fprintf(FID,'DATASET UNSTRUCTURED_GRID \n'); 52 62 53 63 fprintf(FID,'POINTS %d float\n',num_of_points); 54 64 if(dim==3); … … 59 69 P=[points zeros(num_of_points,3-dim)]; 60 70 fprintf(FID,s,P'); 61 71 62 72 fprintf(FID,'CELLS %d %d\n',num_of_elt,num_of_elt*(point_per_elt+1)); 63 73 s='%d'; 64 74 for k=1:point_per_elt 65 75 s=horzcat(s,{' %d'}); 66 76 end 67 77 s=cell2mat(horzcat(s,{'\n'})); 68 78 fprintf(FID,s,[(point_per_elt)*ones(num_of_elt,1) model.mesh.elements-1]'); 69 79 70 80 fprintf(FID,'CELL_TYPES %d\n',num_of_elt); 71 81 s='%d\n'; 72 82 fprintf(FID,s,celltype*ones(num_of_elt,1)); 83 84 %loop over the different solution structures 85 for j=1:num_of_sols 73 86 74 %check which field is a real result and print 75 fprintf(FID,'POINT_DATA %s \n',num2str(num_of_points)); 76 for j=1:num_of_fields 77 78 if (length(sol_struct(1).(fieldnames{j}))==num_of_points); 79 fprintf(FID,'SCALARS %s float 1 \n',fieldnames{j}); 80 fprintf(FID,'LOOKUP_TABLE default\n'); 81 s='%e\n'; 82 fprintf(FID,s,sol_struct.(fieldnames{j})); 83 end 84 end 85 fclose(FID); 86 else 87 for i=1:num_of_timesteps; 88 timestep=sol_struct(i).step; 89 FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk',int2str(timestep),'.vtk'),'w+'); 90 fprintf(FID,'# vtk DataFile Version 2.0 \n'); 91 fprintf(FID,'Data for run %s \n',model.miscellaneous.name); 92 fprintf(FID,'ASCII \n'); 93 fprintf(FID,'DATASET UNSTRUCTURED_GRID \n'); 94 95 fprintf(FID,'POINTS %d float\n',num_of_points); 96 if(dim==3); 97 s='%f %f %f \n'; 98 elseif(dim==2); 99 s='%f %f \n'; 100 end 101 P=[points zeros(num_of_points,3-dim)]; 102 fprintf(FID,s,P'); 103 104 fprintf(FID,'CELLS %d %d\n',num_of_elt,num_of_elt*(point_per_elt+1)); 105 s='%d'; 106 for k=1:point_per_elt 107 s=horzcat(s,{' %d'}); 108 end 109 s=cell2mat(horzcat(s,{'\n'})); 110 fprintf(FID,s,[(point_per_elt)*ones(num_of_elt,1) model.mesh.elements-1]'); 111 112 fprintf(FID,'CELL_TYPES %d\n',num_of_elt); 113 s='%d\n'; 114 fprintf(FID,s,celltype*ones(num_of_elt,1)); 115 87 %getting the number of fields in the solution 88 fieldnames=fields(sol_struct{j}(i)); 89 num_of_fields=length(fieldnames); 90 116 91 %check which field is a real result and print 117 92 fprintf(FID,'POINT_DATA %s \n',num2str(num_of_points)); 118 for j=1:num_of_fields119 120 if ( length(sol_struct(1).(fieldnames{j}))==num_of_points);121 fprintf(FID,'SCALARS %s float 1 \n',fieldnames{ j});93 for k=1:num_of_fields 94 95 if ((length(sol_struct{j}(i).(fieldnames{k})))==num_of_points); 96 fprintf(FID,'SCALARS %s float 1 \n',fieldnames{k}); 122 97 fprintf(FID,'LOOKUP_TABLE default\n'); 123 98 s='%e\n'; 124 fprintf(FID,s,sol_struct (i).(fieldnames{j}));99 fprintf(FID,s,sol_struct{j}(i).(fieldnames{k})); 125 100 end 126 end 127 fclose(FID); 101 end 102 end 103 fclose(FID); 128 104 end 129 105 end
Note:
See TracChangeset
for help on using the changeset viewer.