Changeset 19197


Ignore:
Timestamp:
03/16/15 10:23:06 (10 years ago)
Author:
bdef
Message:

NEW: adding support for forcings

Location:
issm/trunk-jpl/src/m/contrib/paraview
Files:
2 edited

Legend:

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

    r18746 r19197  
    5151                if(size(sol_struct{i},2)>num_of_timesteps);
    5252                        num_of_timesteps=size(sol_struct{i},2);
     53                        outstep=model.timestepping.time_step*model.settings.output_frequency
     54    end
    5355  end
    54  end
    5556else
    5657        num_of_timesteps=1;
     
    5960       
    6061        timestep=step;
    61 
    6262        fid = fopen(strcat(path,filesep,name,filesep,'timestep.vtk',int2str(timestep),'.vtk'),'w+');
    6363        fprintf(fid,'# vtk DataFile Version 2.0 \n');
     
    8585        if exist('low_elt_num')
    8686                triaconnect=zeros(num_of_elt,3);
    87                 triaconnect(1:low_elt_num,:)= ...
    88                                 model.mesh.elements(find(isnan(model.mesh.lowerelements)),1:3);
    89                 upshift=-min(min(model.mesh.elements(find(isnan(model.mesh.upperelements)),4:6)))...
    90                                                 +1+max(max(model.mesh.elements(find(isnan(model.mesh.lowerelements)),1:3)));
     87                triaconnect(1:low_elt_num,:)=model.mesh.elements(find(isnan(model.mesh.lowerelements)),1:3);
     88                upshift=-min(min(model.mesh.elements(find(isnan(model.mesh.upperelements)),4:6)))+1+max(max(model.mesh.elements(find(isnan(model.mesh.lowerelements)),1:3)));
    9189                triaconnect(1+low_elt_num:num_of_elt,:)=model.mesh.elements(find(isnan(model.mesh.upperelements)),4:6)+upshift;
    9290                fprintf(fid,s,[(3)*ones(num_of_elt,1) triaconnect-1]');
     
    109107                                timestep = size(sol_struct{j},2);
    110108            end
    111                        
    112109                        %getting the number of fields in the solution
    113                         fieldnames=fields(sol_struct{j}(timestep));
    114                         num_of_fields=length(fieldnames);
    115                        
     110                        resfields=fields(sol_struct{j}(timestep));
     111                        num_of_fields=length(resfields);
    116112                        %check which field is a real result and print
    117113                        for k=1:num_of_fields
    118                                 if ((numel(sol_struct{j}(timestep).(fieldnames{k})))==tot_points);
     114                                if ((numel(sol_struct{j}(timestep).(resfields{k})))==tot_points);
    119115                                        %paraview does not like NaN, replacing
    120                                         nanval=find(isnan(sol_struct{j}(timestep).(fieldnames{k})));
    121                                         sol_struct{j}(timestep).(fieldnames{k})(nanval)=-9999;
     116                                        nanval=find(isnan(sol_struct{j}(timestep).(resfields{k})));
     117                                        sol_struct{j}(timestep).(resfields{k})(nanval)=-9999;
    122118                                        %also checking for verry small value that mess up
    123                                         smallval=(abs(sol_struct{j}(timestep).(fieldnames{k}))<1.0e-20);
    124                                         sol_struct{j}(timestep).(fieldnames{k})(smallval)=0.0;
    125                                         fprintf(fid,'SCALARS %s float 1 \n',fieldnames{k});
     119                                        smallval=(abs(sol_struct{j}(timestep).(resfields{k}))<1.0e-20);
     120                                        sol_struct{j}(timestep).(resfields{k})(smallval)=0.0;
     121                                        fprintf(fid,'SCALARS %s float 1 \n',resfields{k});
    126122                                        fprintf(fid,'LOOKUP_TABLE default\n');
    127123                                        s='%e\n';
    128                                         fprintf(fid,s,sol_struct{j}(timestep).(fieldnames{k})(IsEnveloppe));
     124                                        fprintf(fid,s,sol_struct{j}(timestep).(resfields{k})(IsEnveloppe));
    129125                    end         
    130126            end
     
    149145                                s='%e\n';
    150146                                fprintf(fid,s,res_struct.(fieldnames{k})(IsEnveloppe));
    151             end         
     147                                %check for forcings     
     148                        elseif (size(res_struct.(fieldnames{k}),1)==tot_points+1);
     149                                %paraview does not like NaN, replacing
     150                                nanval=find(isnan(res_struct.(fieldnames{k})));
     151                                res_struct.(fieldnames{k})(nanval)=-9999;
     152                                %also checking for verry small value that mess up
     153                                smallval=(abs(res_struct.(fieldnames{k}))<1.0e-20);
     154                                res_struct.(fieldnames{k})(smallval)=0.0;
     155                                if (size(res_struct.(fieldnames{k}),2)==num_of_timesteps),
     156                                        fprintf(fid,'SCALARS %s float 1 \n',fieldnames{k});
     157                                        fprintf(fid,'LOOKUP_TABLE default\n');
     158                                        s='%e\n';
     159                                        fprintf(fid,s,res_struct.(fieldnames{k})(IsEnveloppe,timestep));
     160                                else,
     161                                        %forcing and results not on the same timestep,need some treatment
     162                                        fprintf(fid,'SCALARS %s float 1 \n',fieldnames{k});
     163                                        fprintf(fid,'LOOKUP_TABLE default\n');
     164                                        index=1
     165                                        currenttime=((timestep-1)*outstep)+model.timestepping.start_time+model.timestepping.time_step
     166                                        while (res_struct.(fieldnames{k})(end,index)<=currenttime);
     167                                                index=index+1
     168                      end
     169                                        uptime=res_struct.(fieldnames{k})(end,index);
     170                                        uplim=res_struct.(fieldnames{k})(IsEnveloppe,index);
     171                                        uptime
     172                                        while (res_struct.(fieldnames{k})(end,index)>=currenttime);
     173                                                index=index-1
     174                      end
     175                                        lowtime=res_struct.(fieldnames{k})(end,index);
     176                                        lowlim=res_struct.(fieldnames{k})(IsEnveloppe,index);
     177                                        lowtime
     178                                        interp=lowlim+(uplim-lowlim)*((currenttime-lowtime)/(uptime-lowtime))
     179                                        s='%e\n';
     180                                        fprintf(fid,s,interp);
     181                                end     
     182                  end           
    152183                end
    153184        end
  • issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m

    r19157 r19197  
    5959                if(size(sol_struct{i},2)>num_of_timesteps);
    6060                        num_of_timesteps=size(sol_struct{i},2);
    61     end
     61          end
     62                outstep=model.timestepping.time_step*model.settings.output_frequency;
    6263  end
    6364else
     
    145146                                s='%e\n';
    146147                                fprintf(fid,s,res_struct.(fieldnames{k}));
    147             end         
     148                                %check for forcings     
     149                        elseif (size(res_struct.(fieldnames{k}),1)==num_of_points+1);
     150                                %paraview does not like NaN, replacing
     151                                nanval=find(isnan(res_struct.(fieldnames{k})));
     152                                res_struct.(fieldnames{k})(nanval)=-9999;
     153                                %also checking for verry small value that mess up
     154                                smallval=(abs(res_struct.(fieldnames{k}))<1.0e-20);
     155                                res_struct.(fieldnames{k})(smallval)=0.0;
     156                                if (size(res_struct.(fieldnames{k}),2)==num_of_timesteps),
     157                                        fprintf(fid,'SCALARS %s float 1 \n',fieldnames{k});
     158                                        fprintf(fid,'LOOKUP_TABLE default\n');
     159                                        s='%e\n';
     160                                        fprintf(fid,s,res_struct.(fieldnames{k})(1:end-1,timestep));
     161                                else,
     162                                        %forcing and results not on the same timestep,need some treatment
     163                                        fprintf(fid,'SCALARS %s float 1 \n',fieldnames{k});
     164                                        fprintf(fid,'LOOKUP_TABLE default\n');
     165                                        index=1;
     166                                        currenttime=((timestep-1)*outstep)+model.timestepping.start_time;
     167                                        while (res_struct.(fieldnames{k})(end,index)<=currenttime);
     168                                                if index==size(res_struct.(fieldnames{k}),2)
     169                                                        break
     170                                                end     
     171                                                index=index+1;
     172                      end
     173                                        uptime=res_struct.(fieldnames{k})(end,index);
     174                                        uplim=res_struct.(fieldnames{k})(1:end-1,index);
     175                                        while (res_struct.(fieldnames{k})(end,index)>=currenttime);
     176                                                if index==1
     177                                                        break
     178                              end
     179                                                index=index-1;
     180                      end
     181                                        lowtime=res_struct.(fieldnames{k})(end,index);
     182                                        lowlim=res_struct.(fieldnames{k})(1:end-1,index);
     183                                        if uptime==currenttime,
     184                                                interp=uplim;
     185                                        elseif lowtime==currenttime,
     186                                                interp=lowlim;
     187                                        else
     188                                                interp=lowlim+(uplim-lowlim)*((currenttime-lowtime)/(uptime-lowtime));
     189                                        end
     190                                        s='%e\n';
     191                                        fprintf(fid,s,interp);
     192                                end
     193                  end           
    148194                end
    149195        end
Note: See TracChangeset for help on using the changeset viewer.