Changeset 18515
- Timestamp:
- 09/12/14 15:39:55 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/contrib/paraview/exportVTK.py
r18513 r18515 1 1 import numpy 2 3 2 def exportVTK(filename,model,options): 4 3 ''' … … 27 26 28 27 #get the element related variables 29 points=[model.mesh.x model.mesh.y model.mesh.z] 28 if model.mesh.shape[0]==2: 29 points=[model.mesh.x model.mesh.y zeros(model.mesh.numberofvertices,1)]; 30 else: 31 points=[model.mesh.x model.mesh.y model.mesh.z] 32 30 33 [num_of_points,dim]=numpy.size(points) 31 34 [num_of_elt]=numpy.size(model.mesh.elements,1) … … 42 45 #this is the result structure 43 46 res_struct=model.results 44 #Getting all the solutions of the model 45 solnames=fields(res_struct) 46 num_of_sols=numpy.length(solnames) 47 num_of_timesteps=1 48 #%building solutionstructure 49 for solution in num_of_sols: 50 sol_struct{i}=res_struct.(solnames{i}); 51 #looking for multiple time steps 52 if(numpy.size(sol_struct{i},2)>num_of_timesteps): 53 num_of_timesteps=numpy.size(sol_struct{i},2); 47 if (len(fields(res_struct))>0): 48 #Getting all the solutions of the model 49 solnames=fields(res_struct) 50 num_of_sols=numpy.length(solnames) 51 num_of_timesteps=1 52 #%building solutionstructure 53 for solution in num_of_sols: 54 sol_struct{i}=res_struct.(solnames{i}); 55 #looking for multiple time steps 56 if(numpy.size(sol_struct{i},2)>num_of_timesteps): 57 num_of_timesteps=numpy.size(sol_struct{i},2); 58 59 else: 60 num_of_timesteps=1 54 61 55 62 for step in num_of_timesteps: … … 73 80 74 81 fid.write('CELLS %d %d\n' % num_of_elt % num_of_elt*(point_per_elt+1)) 75 76 77 82 s='%d' 83 for j=1:point_per_elt: 84 s=horzcat(s,{' %d'}) 78 85 79 s=cell2mat(horzcat(s,{'\n'})) 80 fid.write(fid,s,[(point_per_elt)*ones(num_of_elt,1) model.mesh.elements-1]transpose) 81 82 fid.write(fid,'CELL_TYPES %d\n',num_of_elt) 83 s='%d\n' 84 fid.write(fid,s,celltype*ones(num_of_elt,1)) 85 fid.write(fid,'POINT_DATA %s \n',num2str(num_of_points)) 86 87 #loop over the different solution structures 88 for j=1:num_of_sols: 86 s=cell2mat(horzcat(s,{'\n'})) 87 fid.write(fid,s,[(point_per_elt)*ones(num_of_elt,1) model.mesh.elements-1]transpose) 88 89 fid.write(fid,'CELL_TYPES %d\n',num_of_elt) 90 s='%d\n' 91 fid.write(fid,s,celltype*ones(num_of_elt,1)) 92 fid.write(fid,'POINT_DATA %s \n',num2str(num_of_points)) 93 94 #loop over the different solution structures 95 if 'num_of_sols' in locals(): 96 for j=1:num_of_sols: 89 97 #dealing with results on different timesteps 90 98 if(numpy.size(sol_struct{j},2)>timestep): … … 92 100 else: 93 101 timestep = numpy.size(sol_struct{j},2) 94 102 95 103 #getting the number of fields in the solution 96 104 fieldnames=fields(sol_struct{j}(timestep)) … … 111 119 fid.write(s % sol_struct{j}(timestep).(fieldnames{k})) 112 120 113 114 115 116 117 118 119 120 if ((numel(res_struct.(fieldnames{k})))==num_of_points) 121 122 123 124 125 126 127 128 129 130 131 121 #loop on arguments, if something other than result is asked, do 122 #it now 123 for j= 1:nargin-2: 124 res_struct=model.(varargin{j}) 125 fieldnames=fields(res_struct) 126 num_of_fields=numpy.length(fieldnames) 127 for k=1:num_of_fields: 128 if ((numel(res_struct.(fieldnames{k})))==num_of_points): 129 #paraview does not like NaN, replacing 130 nanval=find(isnan(res_struct.(fieldnames{k}))) 131 res_struct.(fieldnames{k})(nanval)=-9999 132 #also checking for verry small value that mess up 133 smallval=(abs(res_struct.(fieldnames{k}))<1.0e-20) 134 res_struct.(fieldnames{k})(smallval)=0.0 135 fid.write(fid,'SCALARS %s float 1 \n',fieldnames{k}) 136 fid.write(fid,'LOOKUP_TABLE default\n') 137 s='%e\n' 138 fid.write(fid,s,res_struct.(fieldnames{k})) 139 fid.close();
Note:
See TracChangeset
for help on using the changeset viewer.