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_all_at_once.m
if(1) % FAST FOR LOOP .... TRADITIONAL FOR
    
    Red_alloc_gr = rhoR(ijagr);
    incr=zeros(lenag,1,'double');
    
   
    for ic=1:N_c,
        indeces = new_order(:,ic);
        f_indeces=f(indeces);
        incr = min(Red_alloc_gr,f_indeces); % removed max (X,0)
        Red(indeces) = incr; % Red
        Blue(indeces) = f_indeces - incr; % the remaining is Blue ***
        Red_alloc_gr = Red_alloc_gr-incr;
    end % for ic
   % note : on my CPU :
   % the *** in the for loop is faster !!! than the treatment of Blue after the loop 
   % you can comment out *** and activate onle of the follow 
   %%% Blue(Nr,Mc,9); % recall size ..  preallocation trick
   % Blue(new_order) = f(new_order) - Red(new_order); % slower than ***
   % Blue = f - Red; % (slower or) not faster than ***  as well 
    
end %  for traditional loop 


% LITTLE SLOWER VECTORIAL ALTERNATIVE ( 10 % slower) 
if(0) % avoiding for loop ... uses cumsum & sum ... that are slow
    %
    if ~isempty(ijagr)
    Red_alloc_gr = rhoR(ijagr);
    
    %Red_cum=cumsum(f(new_order(:,:)),2); % row wise , i.e. link wise cumsum
    %bin_19_Red2refil = Red_cum(:,:) <= repmat(Red_alloc_gr(:),1,9); % Red only
    bin_19_Red2refil= bsxfun(@le,cumsum(f(new_order),2),Red_alloc_gr);
   % bin_19_Red2refil= bsxfun(@le,Red_cum,Red_alloc_gr);
    bin_19_Blue2refil=not(bin_19_Red2refil);
    %   
    %ind_Red  = (new_order).* int32( bin_19_Red2refil);% indeces Red
    %ind_Red  = ind_Red(ind_Red>0);
    ind_Red = new_order(bin_19_Red2refil);
    %ind_Blue = (new_order).* int32( bin_19_Blue2refil);% indeces Blue
    %ind_Blue =ind_Blue(ind_Blue>0);
    ind_Blue = new_order(bin_19_Blue2refil);
    %
    % bin_19_Blue2refil [0 0 0 1 1 1 1 ... 1] that is  [Red Red Red Mix Blue Blue ...]
    % " [1 1 1 1 1 ... 1] that is [Mix Blue Blue ...]
    % " [0 0 0 ... 1] that is [Red Red Red ... Mix]
    % " [0 0 0 .... 0 ] that is all Red 
    %     
    % idxab=int32(findfirst(bin_19_Blue2refil,2,1,'first'));% 
    idxab1=int32(findfirst(bin_19_Blue2refil,2));% % in short 
    %
    idxab2=idxab1(idxab1>0);
    %
    fBmz=int32(find(idxab1>0)); % first Blue > 0
    % (jcol-1)*NumRow + irow ; Nr= lenag ; j= 1:9 
    idxab=(idxab2-1).* lenag + fBmz; % indice assoluto 
    mininB=new_order(idxab) ; % min index Blue of possible mix (Blue & Red)) link 
    %
 %  Red(new_order)=0; Blue(new_order)=0; % safer 
    Red(ind_Blue)=0; 
    Blue(ind_Red)=0; 
    Red(ind_Red) = f(ind_Red); % Red ( 100 % Red)
    Red(mininB) = max(Red_alloc_gr(fBmz)- sum(Red(new_order(fBmz,:)),2),0);
    %%Red(mininB) = Red_cum(idxab)-Red_alloc_gr(fBmz);%avoids sum...tocheck
    %Red(mininB) = max(rhoR(fBmz)- sum(Red(new_order(fBmz,:)),2),0);
    Blue(ind_Blue) = f(ind_Blue); % - Red(ind_Blue);
    Blue(mininB)=f(mininB)-Red(mininB); 
    end % isempty ijagr
    
end % end vector version (10% slower ! or so )   




Contact us