samplemaker / freefem_matlab_octave_plot

Examples how to plot FreeFem++ simulation results from within matlab and octave
GNU General Public License v3.0
25 stars 13 forks source link

Make movie with data from Freefem++ #2

Closed RioMSHJiang closed 5 years ago

RioMSHJiang commented 6 years ago

When I export the numerical solutions from Freefem++ (heat equation with periodic boundary condition). I would like to make one movie to represent the profile of temperature and save in Avi format. The code as below, the movie is not includ "x axis", "title", the "colorbar", I think maybe the reason is the function "ffpdeplot". could you help to improve it? Thanks a lot.

// heats.edp real t=0; real dt = 0.001,T=1; real D=0.1; mesh Th=square(30,30,[2xpi,2ypi]); fespace Vh(Th,P1,periodic=[[2,y],[4,y],[1,x],[3,x]]); Vh uh,uold,vh; func f=sin(x+pi/4.)cos(y+pi/2.); problem Heat(uh,vh) = int2d(Th)(uhvh/dt+ Ddx(uh) dx(vh) + Ddy(uh) dy(vh) ) -int2d(Th)(uold*vh/dt);

savemesh(Th,"periodic.msh"); Vh u0=0.1exp(-10(x-pi)^2-10*(y-pi)^2); uold=u0; int round = 0; while (t + dt/2. < T) { t = t+ dt; round++; Heat; uold=uh;

if(round % 200 == 0) { plot(uh,fill=true,value=true); { ofstream file("periodic"+round+".txt"); int nbvertices = Th.nv; for (int i=0; i<nbvertices; i++){ file << uh(Th(i).x, Th(i).y) << "\n"; } } } } %%%%%%%%%%%%%%%%%%%%

clear all; addpath('ffmatlib'); %Reads a FreeFem++ mesh created with the savemesh(Th,"mesh.msh"); command [p,b,t,nv,nbe,nt,labels]=ffreadmesh('periodic.msh'); %Reads the PDE data [u2]=ffreaddata('periodic200.txt'); [u4]=ffreaddata('periodic400.txt'); [u6]=ffreaddata('periodic600.txt'); [u8]=ffreaddata('periodic800.txt'); [u10]=ffreaddata('periodic1000.txt');

%%%%% 2D Patch (density map) Plot + Contour

theAxes=axis; fmat=moviein(5); ffpdeplot(p,b,t, ... 'XYData',u2, ... 'Mesh','off', ... 'Boundary','on', ... 'Contour','on', ... 'Title','Patch Plot + Contour'); fmat(:,1)=getframe; ffpdeplot(p,b,t, ... 'XYData',u4, ... 'Mesh','off', ... 'Boundary','on', ... 'Contour','on', ... 'Title','Patch Plot + Contour'); fmat(:,2)=getframe; ffpdeplot(p,b,t, ... 'XYData',u6, ... 'Mesh','off', ... 'Boundary','on', ... 'Contour','on', ... 'Title','Patch Plot + Contour'); fmat(:,3)=getframe; ffpdeplot(p,b,t, ... 'XYData',u8, ... 'Mesh','off', ... 'Boundary','on', ... 'Contour','on', ... 'Title','Patch Plot + Contour'); fmat(:,4)=getframe; ffpdeplot(p,b,t, ... 'XYData',u10, ... 'Mesh','off', ... 'Boundary','on', ... 'Contour','on', ... 'Title','Patch Plot + Contour'); fmat(:,5)=getframe; figure() movie(fmat,5)

%%make movie %%%%%%%%%%%%%%%%%%%%%%%% aviobj=VideoWriter('heats.avi'); open(aviobj) for ii=1:5 currFrame(ii)=fmat(:,ii); writeVideo(aviobj,currFrame(ii)); end close(aviobj)

samplemaker commented 6 years ago

I can not reproduce the problem. In the avi file everything is visible (color bar, title, etc.) as it should be. However, I have seen that there is an issue report on getframe in older versions of Matlab. maybe that's the problem. Anyway, I uploaded my code (see movie.edp and movie_matlab.m). maybe that will help you.

RioMSHJiang commented 5 years ago

Thanks a lot. your program works. I am trying to write my problem's code again. I am happy to get your help! Thanks again.