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

ILB_initial_RB_colours.m
% INITIAL COLOUR DISTRIBUTION INTO WET LOCATIONS
% initialization arrays : start Kolour values in the wet area
%Initial_Colour_Distribution = 'Rand_Unif'
%Initial_Colour_Distribution ='Vert_Interf';
%Initial_Colour_Distribution ='Horiz_Interf';
%Initial_Colour_Distribution ='Red_Lane';
%Initial_Colour_Distribution ='Red_Buble2D';

switch lower(Initial_Colour_Distribution)
    
    case {'rand_unif'}
        disp('Initial_Colour_Distribution is Rand_Unif')
        % alternative 1:random distribution of the Blue and Red
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            % decide if location is Blue or Red based on given fraction Red
            % ...location i,j can be mix
            if ( rand(1,1) < fct_Red ), % random uniform in 0 - 1
                Red(i,j,:) =1/9.; % then Red (it was 0)
            else
                Blue(i,j,:)=1/9.; %  Blue in not Red , fraction (1-fct_Red)
            end
        end
        
    case {'horiz_interf'}
        disp('Initial_Colour_Distribution has a horiz interface')
        %alternative 2 : one colour intrudes and desplaces the other
        % Red on Top
        Nr_Red=round(Nr*fct_Red);
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            if i<=Nr_Red
                Red(i,j,:)=1/9  ;  Blue(i,j,:)=0  ;
            else
                Blue(i,j,:)=1/9 ;  Red(i,j,:)=0  ;
            end
        end
        
    case {'horiz_interf_flip'}
        disp('Initial_Colour_Distribution has a horiz interface')
        %alternative 2 : one colour intrudes and desplaces the other
        % Red on Top
        Nr_Red=round(Nr*fct_Red);
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            if i<=Nr_Red
                Red(i,j,:)=0 ;  Blue(i,j,:)=1/9  ;
            else
                Blue(i,j,:)=0 ;  Red(i,j,:)=1/9  ;
            end
        end
        % striscia blue alla fine del condotto
        %Blue(end:end,:,:)=1/9 ;  Red(end:end,:,:)=0  ;
        %
        
    case {'red_stripe'}
        disp('Initial_Colour_Distribution has a horiz interface')
        %alternative 2 : one colour intrudes and desplaces the other
        % Red on Top
        Nr_B=round(Nr*(1-fct_Red)*0.5); Nr_B1= Nr-Nr_B
        % half-way red stripe
        
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            
            if ( i<=Nr_B || i> Nr_B1 ),
                %
                Blue(i,j,:)=1/9 ;  Red(i,j,:)=0  ;
            else
                Red(i,j,:)=1/9  ;   Blue(i,j,:)=0  ;
            end
        end
        
    case {'red_spot'}
        Blue(:,:,:)=0; Red(:,:,:)=0;
        for ia=1:lena % stat values
            i=iawet(ia);  j=jawet(ia);
            if Channel2D(i,j)
                Blue(i,j,:)=1/9 ;  Red(i,j,:)=0  ;  % all blue
            end
        end
        % dove si posiziona la macchia e dove deve finire
        
        ars=0; %area red spot
        for ir=7:1:11;
            for jr=79:1:81;
                
                if Channel2D(ir,jr); % solo nelle locazioni bagnate
                    Red(ir,jr,:)=1/9 ;Blue(ir,jr,:)=0 ;  % macchia rossa
                    ars=ars+1; % somma pix rossi
                end
                
            end
        end
        % perimetro iniziale circolo
     Perim0  = sqrt(ars*4/pi).*pi; 
        
    case {'vert_interf'}
        disp('Initial_Colour_Distribution has a vertical interface')
        %alternative 2 : one colour intrudes and desplaces the other
        % Red on Top
        Mc_Red=round(Mc*fct_Red);
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            if j<=Mc_Red
                Red(i,j,:)=1/9  ;  Blue(i,j,:)=0  ;
            else
                Blue(i,j,:)=1/9 ;  Red(i,j,:)=0  ;
            end
        end
        
    case {'red_lane'}
        disp('Initial_Colour_Distribution is a Red Lane')
        % alternative 1:random distribution of the Blue and Red
        WRed=round(Mc*fct_Red); WBlue=Mc-WRed;
        WBlue_Left=round(WBlue/2); Lim_Blue_dx=WBlue_Left+WRed;
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            if (j>=WBlue_Left && j< Lim_Blue_dx),
                Red(i,j,:)=1/9  ;  Blue(i,j,:)=0  ;
            else
                Blue(i,j,:)=1/9 ;  Red(i,j,:)=0  ;
            end
        end
        
    case {'red_buble2d'}
        
        Xcentre=round(Mc/2); Ycentre=round(Nr/2);
        fct_Red , % given
        fct_Red=min(fct_Red,1/2*(pi/4));
        fct_Red , % corrected (max)
        Dbub=round( sqrt(fct_Red*pi/4)*(min(Nr,Mc)) );
        buble2D=zeros(Nr,Mc);
        x = [1:Mc]; x = repmat(x, Nr, 1);
        y = [1:Nr]; y= repmat(y', 1, Mc);
        buble2D= ( (x-Xcentre).^2 + (y-Ycentre).^2 ) <= (Dbub/2).^2 ;
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            if buble2D(i,j)==1 % bubble
                Red(i,j,:)=1./9  ;  Blue(i,j,:)=0  ;
            else
                Blue(i,j,:)=1/9 ;  Red(i,j,:)=0  ;
            end
        end
        
    case {'all_red'}
        disp('Initial_Colour_Distribution is all Red')
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            Red(i,j,:)=1/9  ;  Blue(i,j,:)=1.E-10  ;
        end
        
    case {'all_blue'}
        disp('Initial_Colour_Distribution is all Blue')
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            % all Blue
            Blue(i,j,:)=1/9 ;  Red(i,j,:)=1.E-10  ;
        end
        
        
        clear x y buble2D
        
    case {'red_focused'}
        
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            % all Blue
            
            if Channel2D(i,j)
               % if i < Nr-1
                if i < Nr
                    Blue(i,j,:)=1/9 ;  Red(i,j,:)=0;
                else
                    Blue(i,j,:)=0 ;  Red(i,j,:)=1/9;
                end
            end
        end
        
        % prende variabili definite in vessels
        Red(2:L_can,P_can+sps+1:P_can+sps+w_can,1:9)=1/9;
        Blue(2:L_can,P_can+sps+1:P_can+sps+w_can,1:9)=0;
        
    case {'porous_colours'}
        % Top_bufe  Bot_buf=3 definiti in vessel
        for ia=1:lena % stat values in the active cells only ; 0 outside
            i=iawet(ia);  j=jawet(ia);
            % all Blue
            
            if Channel2D(i,j) ,
                
                if strcmp(type_displacement,'imbibition'),
                    if (i >= Top_buf && i<= Nr-Bot_buf) ;
                        % Blue(i,j,:)=1/9 ;  Red(i,j,:)=0; % full of water
                        Blue(i,j,:)=0 ;  Red(i,j,:)=1/9; % full of oil
                    end
                    if (i < Top_buf ) ; %top buffer colour
                        Blue(i,j,:)=1/9 ;  Red(i,j,:)=0; % top buffer of water
                        % Blue(i,j,:)=0 ;  Red(i,j,:)=1/9; % bot buffer of oil
                    end
                    if (i > Nr-Bot_buf) ; % opzionale
                        %Blue(i,j,:)=1/9 ;  Red(i,j,:)=0; % full of water
                        Blue(i,j,:)=0 ;  Red(i,j,:)=1/9; % full of oil
                    end
                end% if strcmp(type_displacement,'imbibition'),
                
                
                if strcmp(type_displacement,'drainage'),
                    if (i >= Top_buf && i<= Nr-Bot_buf) ;
                        Blue(i,j,:)=1/9 ;  Red(i,j,:)=0; % full of water
                    end
                    if (i < Top_buf ) ; %top buffer colour
                        Blue(i,j,:)=0 ;  Red(i,j,:)=1/9; % bot buffer of oil
                    end
                    if (i > Nr-Bot_buf) ;
                        Blue(i,j,:)=0 ;  Red(i,j,:)=1/9; % full of oil
                    end
                end % if strcmp(type_displacement,'imbibition'),
                
                 if strcmp(type_displacement,'mix_w_oil_in'),
                    if (i >= Top_buf && i<= Nr-Bot_buf) ;
                        Blue(i,j,:)=1/9 ;  Red(i,j,:)=0; % full of water
                    end
                    
                    if (i < Top_buf ) ; %top buffer colour
                       k = (rand(1,1)<=fct_Red); 
                        if k, % vero 
                            Blue(i,j,:)=0 ;  Red(i,j,:)=1/9; 
                        else % falso 
                            Blue(i,j,:)=1/9; Red(i,j,:)=0;
                        end
                    end
                    
                    if (i > Nr-Bot_buf) ;
                        Blue(i,j,:)=0 ;  Red(i,j,:)=1/9; % full of oil
                    end
                end % if strcmp(type_displacement,'imbibition'),
                
                
            end %
        end  % for ia .. case {'porous_colours'}
        
end % switch

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Contact us