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

Select_Colour_Redistribution_Method_2010d.m
% same code as above but in vectorial fashion usind abosolute

if  strcmp(Refill_method,'Keller'),  % VECTORIAL CODE
    %tC2=C2(:,1:8);
    
    
    if(0) % VERY VERY SLOW 
        % Min/Max selection Search for k smallest or largest elements in the array  Author: Bruno Luong
        new_order = repmat(int32(0),lenag,9); %
        [unused, new_order] = maxk(Grad_List,4,2,'sorting',false);
        new_order = int32(new_order);
        new_order=[new_order, repmat(int32(9),lenag,1) ,ic_op(new_order(:,[4 3 2 1]))];
        %new_order = [new_order(:,1:4), repmat(int32(9),lenag,1) , new_order(:,5:8)]; % RP=9 ... link prioritization !
    end
    
    if(1) % FAST 
        
        new_order = zeros(lenag,9,'int32'); % new_order = repmat(int32(0),lenag,9); %
        [~, new_order] = sort((Grad_List),2,'descend'); % use 2009b
        new_order = int32(new_order);
        new_order = [new_order(:,1:4), repmat(int32(9),lenag,1) , new_order(:,5:8)]; % RP=9 ... link prioritization !
    end
    
    if (0) % AVERAGE SPEED 
         new_order = repmat(int32(0),lenag,9); %
        % breaking sort in two parts ( positiva values & neg. values)
        
        G_listma0 = zeros(lenag,4,'single') ; %G_listmi0 = zeros(lenag,4,'single');
       % ima0m = zeros(lenag,4,'int32') ;  imi0m=zeros(lenag,4,'int32') ;
        
      %  zetre=int32([0,1,2,3]).*lenag;
        inolg=(1:lenag).';
       % indicx1=repmat(zetre,lenag,1)+int32(repmat((inolg),1,4));
        
        bima0=logical(Grad_List>=eps(1)); % logical 
        bneq4= sum(bima0,2)~=4;
        
    %   if(1)
        
            if any(bneq4)
                
                 inol4=inolg(bneq4); lenl4=int32(length(inol4));
                
               %  for ino=inol4.' ; % row vector
                    % iz1(iino)  = find(bima0(ino,:)==0,1);  bima0(ino,iz1(iino))=1;
                    % bima0(ino,find(bima0(ino,:)==0,1))=1;
               %  end
                
                iz=int32(findfirst(bima0(inol4.',:)==0,2,1)); %
                bima0(inol4 + (iz-1).*lenag )=true(lenl4,1);
                
            end
                
             %   for ino=1:lenag, 
             %ima0m(ino,:) = int32(find(bima0(ino,:),4)) ;  end
             
%              
%              for ino=1:lenag
%                  cnt = 1;
%                  for cno = 1:8,
%                      if bima0(ino,cno)
%                          ima0m(ino,cnt) = int32(cno);
%                          cnt = cnt + 1;
%                          if cnt>4 
%                              break
%                          end
%                     end
%                 end
%              end
% %             

           ima0m = int32(findfirst(bima0,2,4));
                
     %     end

     %   end  
        
        
        indicx2=(ima0m(:,:)-ones(lenag,4,'int32')).*lenag+repmat(inolg,1,4);
        
      %  G_listma0(indicx1(:))= single(Grad_List( indicx2(:)));
         G_listma0(:)= single(Grad_List( indicx2(:)));
         
        [~,isma] = sort(G_listma0,2,'descend');
        
        
        indicx3=(int32(isma)-ones(lenag,4,'int32')).*lenag+repmat(inolg,1,4);
        
       % ima0m(indicx1(:))=ima0m(indicx3);
        ima0m(:)=ima0m(indicx3);
        
       % imi0m = ic_op( fliplr(ima0m) ) ;
        imi0m = ic_op( ima0m(:,[4,3,2,1]) ) ;
        
        new_order=[ima0m, repmat(int32(9),lenag,1) ,imi0m];
        
    end
    
    %new_order = repmat(double(ijagr(:)),1,9) + double(NxM)*(new_order-1); % 9 elements vector
    new_order = repmat(ijagr(:),1,9) + NxM.*(int32(new_order-1)); % 9 elements  su ogni riga
    %%
    %Colour_refill_vector_based_2010; % sequential fast m code ( as today)
    %Colour_refill_parfor; % slow m code
    %Colour_refill_vector_based_Luigino; % seq medium speed m code
    %Colour_refill_parfor_4; % new but still slow m code
    %Colour_refill_parfor_41; % new but still slow m code
    Colour_refill_all_at_once;
end % END VECTORIAL SECTION

if strcmp(Refill_method,'Latvo_Kakko') % LATVA KOKKO IMPROVED METHOD Physical Review E 72 2005
    Latva_Kokko_Colour_Redistribution_Vet;
end

Contact us