Search code examples
matlabsimulationfluid-dynamics

simulating the movement of droplet in a microfluidic device using matlab


I would like to know, how to simulate droplet movement in a microfluidic device using matlab.

I'll try to narrow it down as much as I can, It's a situation where a water droplet is moving in a stream of oil, It's a potential flow(Inviscid, Incompressible and Irrotational), on the basis of this paper I have managed to arrive at their equation (1) (page 3) for $\dot{x}$ and $\dot{y}$ and I wish to show the movement of the droplets in matlab in some kind of movie format

I have only basic knowledge of fluid dynamics, and I have never used matlab for more than just implementing mathematical methods, So I would appreciate any kind of help, if further details about the problem are required to help me understand what to do, please let me know

I posted in the physics.stackexchange website, and I was advised to post it here because It pertains to programming.


Solution

  • To answer the first part of the question, how to show the droplet movement:

    If example you can do:

    X = rand(10,1)*10;
    Y = rand(10,1)*10;
    figure
    
    for i = 1:length(X)
        plot(X(i),Y(i),'o')
        xlim([0,10]) %fix the x and y limit 
        ylim([0,10]) %fix the x and y limit 
        F(i) = getframe;
        drawnow
    end
    
    movie(F)
    

    We have to fix the x-limit and y-limit otherwise your dot will always appear at the middle of the screen.

    If you want to save the video (.avi for example):

    X = rand(10,1)*10;
    Y = rand(10,1)*10;
    
    v = VideoWriter('test.avi'); %create a video in your current folder
    open(v)
    
    figure
    
    for i = 1:length(X)
        plot(X(i),Y(i),'o')
        xlim([0,10])
        ylim([0,10])
        F(i) = getframe;
        writeVideo(v,F(i))
    end
    
    close(v)
    

    And just for fun in 3d:

    X = 1:100;
    Y = 1:100;
    Z = 1:100;
    
    v = VideoWriter('test2.avi');
    open(v)
    
    [x,y,z] = sphere;
    
    figure
    
    for i = 1:length(X)
        surf(x+0.1*X(i),y+0.1*Y(i),z+0.1*Z(i));
        xlim([0,10])
        ylim([0,10])
        zlim([0,10])
        view(30,30)
        F(i) = getframe;
        writeVideo(v,F(i))
    end
    
    
    
    close(v)
    

    But this method is quit slow because matlab have to render each frame.