Simulation post-processing – video

In this example of material calibration, we will post-process simulation data coming from VPS.

Timeseries analysis

The first script extracts physical values at each time steps from an ESI Result File (ERF):

timeseries.sce

myFile="ex_cr_J-C-Material_105_RESULT.erfh5";

erf_file = erfOpenFile(myFile);

stage = "post";

//Main function to extract TIMESERIES

res_node = erfGetHistoryResult(erf_file, stage, "TIMESERIES1", "Translational_Displacement");

//Gather the output along X axis, stored in column 1

res1=res_node(2,1,:)(:);


res_section = erfGetHistoryResult(erf_file, stage, "TIMESERIES1", "Section_Force", "SECTION");

res2=res_section(1,1,:)(:);

plot(res2)

xlabel('TIME (millisec)')

ylabel('Force (kN)')

title('SECTION')


//Force depending on Displacement

plot(res1,-res2)

xlabel('DISPLACEMENT (mm)')

ylabel('Force (kN)')


M=[res1,-res2]

csvWrite(M,'serie.csv')

Plot Animation

Now we will create as many images as time steps or here 1/10 to reduce the sampling:

timeseries2png.sce

tic()

data=csvRead("serie.csv",",")
stress=data(:,1)'
strain=data(:,2)'
clear data

frame_start=1
frame_end=1001
newstress=stress(1):(stress($)-stress(1))/(frame_end-frame_start):stress($);
newstrain=interp1(stress,strain,newstress,"linear");

waitbar_handle = waitbar(msprintf("Creating Graph Sequence"));

f=figure("background",color('white'),"figure_position",[64 0],"figure_size",[460+16  460+126+1]);
for i=1:10:max(size(newstress))
    drawlater()
    plot(newstress(1,1:i),newstrain(1,1:i),"b","thickness",2)
    h=legend([strcat(["Force: ",msprintf('%5.3f',newstress(i))," (kN)",..
        " - Displacement: ",msprintf('%5.3f',newstrain(1,i))," (mm)"])])
    xlabel("Force (kN)","color","black");
    ylabel("Displacement (mm)","color","black");
    zoom_rect([0 0 max(stress)+0.1 max(strain)+0.2])
    xgrid(color('grey'),1,8)
    a = gca();
    a.labels_font_color=color('black');
    a.foreground=color('black');
    a.font_size=2;
    a.x_label.font_size=3;
    a.x_label.font_style=8;
    a.y_label.font_size=3;
    a.y_label.font_style=8;
    h.line_mode="off";
    h.foreground=color('white');
    h.font_size=3;
    h.font_color=-1;
    h.fill_mode="on";
    h.background=color('white');
    h.font_foreground=color('black');
    h.legend_location="upper_caption";
    drawnow()
    xs2png(gcf(),"graph\"+strcat(["graph-frame-",msprintf('%4.4i',i),".png"]))
    waitbar(i/max(size(newstress)),msprintf("Creating Graph Sequence   "), waitbar_handle);
end
close(waitbar_handle);
xdel(winsid())
disp(toc())

 

 

Contour Animation

Contour represent the evolution of the physical values on a mesh. With our model reduction toolbox, we can animate those results:

Data2png.sce

myFile="ex_cr_J-C-Material_105_RESULT.erfh5";
erf_file = erfOpenFile(myFile);
stage = "post";
nodes = erfGetNode(erf_file, stage);
[faces, elementIds, partIds] = erfGetElement(erf_file,stage, 0, "SHELL");

//Mesh generation
Mesh = create_mesh(nodes, faces, %f);
mesh2d(Mesh)

//Simulation 
states = erfGetState(erf_file, stage);
state=states($);
Dis=erfGetResult(erf_file, stage, "Translational_Displacement", state);
//DisX=Dis(:,1)
//fem2d(Mesh,DisX)
//f=gcf();f.color_map=parulacolormap(128);
 
DisField = list();
for k=1:length(states)
    Dis=erfGetResult(erf_file, stage, "Translational_Displacement", states(k));
    DisField(k) = Dis(:,1);
end
//save("DisField.sod","DisField")
//tree_show(DisField)
Simu=create_simulation(Mesh,DisField)
show_simulation(Simu)
save_simulation(Simu)

 

Merge graphs into videos

Now with the help of the Image Processing and Computer Vision toolbox IPCV, we can merge the two graphs into one video within two steps:

CreateMixSeq.sce

tic()
cd frames
[a1,b]=dos('dir /b /on g*.png');
//a1=ls('frames');
vidlist=a1;
cd ../graph
[a2,b]=dos('dir /b /on g*.png');
cd ..
//a2=ls('graph');
gralist=a2;
nf=max(size(gralist));
img1 = imread('graph/'+gralist(1));
[h1,w1,dim]=size(img1);
img2 = imread('frames/'+vidlist(1));
[h2,w2,dim]=size(img2);

waitbar_handle = waitbar(msprintf("Creating Mixed Sequence"));

aa=zeros(h1,w1+w2,3);
aaa=iconvert(aa,11);
for i=1:nf
    image1 = imread('graph/'+gralist(i));
    image2 = imread('frames/'+vidlist(i));
    for k=1:3
       aaa(1:h1,1:w1,k)=image1(1:h1,1:w1,k);
       aaa(1:h1,w1+1:w1+w2,k)=image2(1:h1,1:w2,k);
    end
    imwrite(aaa,"results/"+strcat(["frame-",msprintf('%4.4i',i),".png"]));
    waitbar(i/nf,msprintf("Creating Mixed Sequence   "), waitbar_handle);
end
close(waitbar_handle);
disp(toc())

CreateVid.sce

This function takes pictures as input and produces videos:

tic()
cd results
[a,b]=dos('dir /b /on frame*.png');
cd ..
//a=ls('results');
filelistnames=a;
nf=max(size(filelistnames));
videoname="tractionmix.avi"

img = imread('results/'+filelistnames(1));
n = avifile(videoname, [size(img)(2);size(img)(1)], 30,'xvid');

waitbar_handle = waitbar(msprintf("Creating video %s...", videoname));    

for i=1:nf
    img = imread('results/'+filelistnames(i));
    aviaddframe(n, img);
    waitbar(i/nf,msprintf("Creating video %s ...", videoname), waitbar_handle);
end
close(waitbar_handle);
disp(toc())