Changeset 16303


Ignore:
Timestamp:
10/04/13 17:53:42 (11 years ago)
Author:
bdef
Message:

Upgraded export vtk to grab all the solutions of all the result structures

File:
1 edited

Legend:

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

    r15414 r16303  
    1 function exportVTK(filename,model,Solution)
     1function exportVTK(filename,model)
    22% vtk export
    33% function exportVTK(filename,model,Solution)
     
    1919mkdir(filename);
    2020
     21%get the element related variables
    2122points=[model.mesh.x model.mesh.y model.mesh.z];
    2223[num_of_points,dim]=size(points);
    2324[num_of_elt]=size(model.mesh.elements,1);
    2425[point_per_elt]=size(model.mesh.elements,2);
    25 sol_enum=EnumToString(Solution);
    26 
    27 sol_struct=model.results.(sol_enum);
    2826
    2927%Select the type of element function of the number of nodes per elements
     
    3634end
    3735
     36%sol_enum=EnumToString(Solution);
     37
     38%this is the result structure
     39res_struct=model.results;
     40
     41%Getting all the solutions of the model
     42solnames=fields(res_struct);
     43num_of_sols=length(solnames);
     44
     45%building solution structure
     46for i=1:num_of_sols
     47        sol_struct{i}=res_struct.(solnames{i});
     48end
     49
    3850%looking for multiple time steps
    39 num_of_timesteps=size(sol_struct,2);
     51num_of_timesteps=size(sol_struct{1},2);
    4052
    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+');
     53for 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+');
    4858        fprintf(FID,'# vtk DataFile Version 2.0 \n');
    4959        fprintf(FID,'Data for run %s \n',model.miscellaneous.name);
    5060        fprintf(FID,'ASCII \n');
    5161        fprintf(FID,'DATASET UNSTRUCTURED_GRID \n');
    52 
     62       
    5363        fprintf(FID,'POINTS %d float\n',num_of_points);
    5464        if(dim==3);
     
    5969        P=[points zeros(num_of_points,3-dim)];
    6070        fprintf(FID,s,P');
    61 
     71 
    6272        fprintf(FID,'CELLS %d %d\n',num_of_elt,num_of_elt*(point_per_elt+1));
    6373        s='%d';
    6474        for k=1:point_per_elt
    65     s=horzcat(s,{' %d'});
     75                s=horzcat(s,{' %d'});
    6676  end
    6777        s=cell2mat(horzcat(s,{'\n'}));
    6878        fprintf(FID,s,[(point_per_elt)*ones(num_of_elt,1) model.mesh.elements-1]');
    69 
     79 
    7080        fprintf(FID,'CELL_TYPES %d\n',num_of_elt);
    7181        s='%d\n';
    7282        fprintf(FID,s,celltype*ones(num_of_elt,1));
     83       
     84        %loop over the different solution structures
     85        for j=1:num_of_sols
    7386
    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               
    11691                %check which field is a real result and print
    11792                fprintf(FID,'POINT_DATA %s \n',num2str(num_of_points));
    118                 for j=1:num_of_fields
    119 
    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});
    12297                                fprintf(FID,'LOOKUP_TABLE default\n');
    12398                                s='%e\n';
    124                                 fprintf(FID,s,sol_struct(i).(fieldnames{j}));
     99                                fprintf(FID,s,sol_struct{j}(i).(fieldnames{k}));
    125100            end         
    126     end
    127                 fclose(FID);
     101     end
     102         end
     103         fclose(FID);
    128104  end
    129105end
Note: See TracChangeset for help on using the changeset viewer.