Code covered by the BSD License  

Highlights from
immiscible LB

immiscible LB

by

 

23 Jul 2009 (Updated )

Implements Immiscible Lattice Boltzmann (ILB, D2Q9) method for two phase flows

Colour_refill_vector_based_2010.m

% avoid for loop , uses cumsum , sum etc ...
 % but uses cumsum & sum ... that is 25 %
    % slower than the loop based code
    %Red_cum=cumsum(f(sia_ic));
    %bin_19_Red2refil= Red_cum <= Red_allocable;
    
    if Red_allocable < f(sia_ic(1)),
        %if bin_19_Red2refil(1)==0,% case: bin_19_Red2refil=[0 0 0 ... 0]
        Red(sia_ic) =0; % Red(sia_ic(2:9)) =0;
        Red(sia_ic(1)) = Red_allocable;
        %Blue(sia_ic(2:9))= f(sia_ic(2:9));
        Blue(sia_ic)= f(sia_ic);
        Blue(sia_ic(1))= f(sia_ic(1)) - Red_allocable;
        
    else % case: bin_19_Red2refil=[1 1 0 ... 0]
        Red_cum=cumsum(f(sia_ic(:)),1);
        bin_19_Red2refil= Red_cum <= Red_allocable;
        
        ind_Blue=sia_ic(not(bin_19_Red2refil));
        ind_Red=sia_ic(bin_19_Red2refil);
        
        Red(ind_Red)=f(ind_Red);
        %Red(ind_Blue(2:end))=0;
        Red(ind_Blue)=0; % faster than above
        Blue(ind_Red)=0; %
        
        %Red(ind_Blue(1))=Red_allocable-sum(Red(ind_Red),'double');
        %Red(ind_Blue(1))=Red_allocable-Red_cum(length(ind_Red));
        Red_all_cum=Red_allocable-Red_cum(length(ind_Red));
        Red(ind_Blue(1))=Red_all_cum;
        %Blue(ind_Blue(2:end)) =  f(ind_Blue(2:end));
        Blue(ind_Blue) =  f(ind_Blue); % prob faster than above
        Blue(ind_Blue(1))=  f(ind_Blue(1))-Red_all_cum;
    end
    


%%% ends here


Contact us