Changeset 16490


Ignore:
Timestamp:
10/21/13 16:43:38 (11 years ago)
Author:
bdef
Message:

exportVTK can now export other fields than results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m

    r16353 r16490  
    1 function exportVTK(filename,model)
     1function exportVTK(filename,model,varargin)
    22% vtk export
    33% function exportVTK(filename,model)
     
    1111%------------------------------------------------------------------
    1212%        model      this is md
     13%------------------------------------------------------------------
     14% By default only the results are exported, you can add whichever
     15% field you need as a string:
     16% add 'geometry' to export md.geometry
    1317%
    1418% Basile de Fleurian:
     
    3539%this is the result structure
    3640res_struct=model.results;
    37 
    3841%Getting all the solutions of the model
    3942solnames=fields(res_struct);
    4043num_of_sols=length(solnames);
    41 
    4244%building solution structure
    4345for i=1:num_of_sols
     
    4850num_of_timesteps=size(sol_struct{1},2);
    4951
    50 for i=1:num_of_timesteps;
     52for step=1:num_of_timesteps;
    5153        %by default, we take the timestep from the first solution sturcture
    52         timestep=sol_struct{1}(i).step;
     54        timestep=sol_struct{1}(step).step;
    5355       
    5456        FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk',int2str(timestep),'.vtk'),'w+');
     
    6668        P=[points zeros(num_of_points,3-dim)];
    6769        fprintf(FID,s,P');
    68  
     70       
    6971        fprintf(FID,'CELLS %d %d\n',num_of_elt,num_of_elt*(point_per_elt+1));
    7072        s='%d';
    71         for k=1:point_per_elt
     73        for j=1:point_per_elt
    7274                s=horzcat(s,{' %d'});
    7375  end
    7476        s=cell2mat(horzcat(s,{'\n'}));
    7577        fprintf(FID,s,[(point_per_elt)*ones(num_of_elt,1) model.mesh.elements-1]');
    76  
     78       
    7779        fprintf(FID,'CELL_TYPES %d\n',num_of_elt);
    7880        s='%d\n';
    7981        fprintf(FID,s,celltype*ones(num_of_elt,1));
    80        
     82        fprintf(FID,'POINT_DATA %s \n',num2str(num_of_points));
     83
    8184        %loop over the different solution structures
    8285        for j=1:num_of_sols
    83 
     86               
    8487                %getting the number of fields in the solution
    85                 fieldnames=fields(sol_struct{j}(i));
     88                fieldnames=fields(sol_struct{j}(step));
    8689                num_of_fields=length(fieldnames);
    8790               
    8891                %check which field is a real result and print
    89                 fprintf(FID,'POINT_DATA %s \n',num2str(num_of_points));
    90                 for k=1:num_of_fields
    91                        
    92                         if ((length(sol_struct{j}(i).(fieldnames{k})))==num_of_points);
     92                        for k=1:num_of_fields
     93                        if ((length(sol_struct{j}(step).(fieldnames{k})))==num_of_points);
    9394                                fprintf(FID,'SCALARS %s float 1 \n',fieldnames{k});
    9495                                fprintf(FID,'LOOKUP_TABLE default\n');
    9596                                s='%e\n';
    96                                 fprintf(FID,s,sol_struct{j}(i).(fieldnames{k}));
     97                                fprintf(FID,s,sol_struct{j}(step).(fieldnames{k}));
     98        end             
     99          end
     100        end
     101       
     102        %loop on arguments, if something other than result is asked, do
     103        %it now
     104        for j= 1:nargin-2
     105                res_struct=model.(varargin{j});
     106                solnames=fields(res_struct);
     107                num_of_sols=length(solnames);
     108                for k=1:num_of_sols
     109                        if ((length(res_struct.(solnames{k})))==num_of_points);
     110                                fprintf(FID,'SCALARS %s float 1 \n',solnames{k});
     111                                fprintf(FID,'LOOKUP_TABLE default\n');
     112                                s='%e\n';
     113                                fprintf(FID,s,res_struct.(solnames{k}));
    97114            end         
    98      end
    99          end
    100          fclose(FID);
    101   end
     115                end
     116        end
     117        fclose(FID);
    102118end
Note: See TracChangeset for help on using the changeset viewer.