Outils pour utilisateurs

Outils du site


sunfluidh:sunfluidh_matlab

Reading output files with Matlab (examples)

Three different matlab functions can read sunfluidh output files. download the files. Make sure the directory where you have untar these files is listed in the matlabpath1).

  1. read_sunfluidh_data reads res* or rst* files
  2. read_sunfluidh_probes reads all probes files *_ins_*
  3. read-sunfluidh-namelist reads check_namelist_data.dat

As for any matlab function, the documentation is built in. In the command window just type : help read_sunfluidh_data or doc read_sunfluidh_data.

Here, we assume you have already run the case 2D laminar channel flow with a constriction. Make sure the current directory for matlab is also the directory where you have the output files.

Instantaneous (or statistical) fields

Visualisation of U velocity component.

f = read_sunfluidh_data(7) % read res_00000_0000007.d. If you omit (7), the function tries to read the lastest generated file.
pcolor(f.xu,f.yc,f.U') % Note the transpose ' for f.U
axis image
shading interp

Add a colorbar, labels and increase the font size.

colorbar
xlabel('x'); ylabel('y'), set(gca,'FontSize',16)

Add on the same figure the contour for the isovalue 0 for the U component. The isocontour is red with a thick line.

hold on
contour(f.xu,f.yc,f.U',[0 0],'r','linewidth',2)
hold off

Extract the profiles from the instantaneous field. For instance, the U profile as a function of x for the grid nodes 48 in the y direction.

plot(f.xu,f.U(:,48))

Add another profile for grid nodes 19, labels.

hold on
plot(f.xu,f.U(:,19))
hold off
xlabel('x'); ylabel('U(x)'), set(gca,'FontSize',18)
grid on

Add a legend retreiving the coordinates of the 19 and 48 grid nodes from f.yc.

legend(['y = ',num2str(f.yc(48))],['y = ',num2str(f.yc(19))] )

Plotting the profiles along the y direction is very similar. Here, the ghost cells are removed.

xind = 152; % pick an indice
plot(f.U(xind,2:end-1),f.yc(2:end-1))
xlabel('U(y)'),ylabel('y')

Retrieve from the namelists stored in check_namelist_data.dat the dynamic viscosity and the mesh size to make a title

nml  = read_sunfluidh_namelist
nx   = nml.DOMAIN_FEATURES.CELLS_NUMBER_I_DIRECTION;
ny   = nml.DOMAIN_FEATURES.CELLS_NUMBER_J_DIRECTION;
Rey  = 1/nml.FLUID_PROPERTIES.REFERENCE_DYNAMIC_VISCOSITY;
mystring = [' Profile at x= ',num2str(f.xu(xind)), ' Re = ',num2str(Rey), ...
              ', grid size = ' num2str(nx),'x', num2str(ny) ];
title(mystring)
For statistical fields you can use read_sunfluidh_data. You just need to add the 'stat' option (see doc read_sunfluidh_data). For statistical fields all data are centered on scalar grid points. It is also possible to center the instantaneaous fields with the option 'center'. This can be handy in a post processing when computing quantities with different velocity field components

Temporal series

The *ins* files or more generally temporal series are ascii files in which the first column is time and the first line is a header. There is no special needs to have a script for these files. You can use directly builtin matlab functions that you can taylor to your needs.

Reading the file resid_L2_Li.d with builtin matlab function

s =  importdata('resid_L2_Li.d');
time = s.data(:,1);
L2  = s.data(:,2);
Linf = s.data(:,3);
semilogy(time,L2)
grid on
xlabel('t','FontSize',16); ylabel('L2 norm','FontSize',16)
set(gca,'FontSize',16)

Plotting the U velocity component for the second probe with builtin matlab function

s =  importdata('u_ins_00000.d',' ',1)
time = s.data(:,1);
u2  = s.data(:,3);
plot(time,u2)
grid on
xlabel('t'); ylabel('u probe2')

You can use read_sunfluid_probes.m that attempts to read in the current directory all the *ins* files and build a structure with the variable names. It intends to make life a bit easier but it is however quite fragile and may fail.

Exemple:

s = read_sunfluidh_probes;
plot(s.time,s.u(:,2)) % to plot u velocity component for probe number 2
1)
For Unix system you can add the following command in ~/.bashrc : export MATLABPATH='directory_where_the_files_are_stored'
sunfluidh/sunfluidh_matlab.txt · Dernière modification: 2020/08/31 15:29 de witko