Ignore:
Timestamp:
Jul 7, 2024, 11:22:00 PM (3 months ago)
Author:
sommeria
Message:

various improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/filter_tps.m

    r1152 r1154  
    66% SubRange(NbCoord,2,NbSubdomain): range (min, max) of the coordinates x and y respectively, for each subdomain
    77% NbCentre(NbSubdomain): number of source points for each subdomain
    8 % FF: false flags preserved from the input, or equal to 20 for vectors excluded by the difference with the smoothed field
     8% FF: false flags preserved from the input, or equal to true for vectors excluded by the difference with the smoothed field
    99% U_smooth, V_smooth: filtered velocity components at the positions of the initial data
    1010% Coord_tps(NbCentre,NbCoord,NbSubdomain): positions of the tps centres
     
    6161
    6262%% smoothing parameter: CHANGED 03 May 2024 TO GET RESULTS INDEPENDENT OF SUBDOMAINSIZE
    63 %smoothing=Siz(1)*Siz(2)*FieldSmooth/1000%optimum smoothing increase as the area of the subdomain (division by 1000 to reach good values with the default GUI input)
     63%smoothing=Siz(1)*Siz(2)*FieldSmooth/1000%old calculation before 03 May < r1129
    6464NbVecSub=NbVec/NbSubDomain;% refined estimation of the nbre of vectors per subdomain
    6565smoothing=sqrt(Siz(1)*Siz(2)/NbVecSub)*FieldSmooth;%optimum smoothing increase as the typical mesh size =sqrt(SizX*SizY/NbVecSub)^1/2
     66Threshold=Threshold*Threshold;% take the square of the threshold to work with the modulus squared (not done before r1154)
    6667
    6768%% default output
     
    7576V_smooth=zeros(NbVec,1);% smoothed velocity V at the initial positions
    7677W_smooth=[];%default (2 component case)
    77 FF=zeros(NbVec,1);
     78FF=false(NbVec,1);%false flag=0 (false) by default
    7879nb_select=zeros(NbVec,1);
    7980check_empty=zeros(1,NbSubDomain);
     
    8889    while numel(ind_sel)>numel(ind_sel_previous)
    8990        ind_sel_previous=ind_sel;% record the set of selected vector indices for next iteration
    90         ind_sel= find(FF==0 & Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub));% indices of vectors in the subdomain #isub
     91        ind_sel= find(~FF & Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub));% indices of vectors in the subdomain #isub
     92        %ind_sel= find( Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub));% indices of vectors in the subdomain #isub
    9193        % if no vector in the subdomain  #isub, skip the subdomain
    9294        if isempty(ind_sel)
     
    9799            SubRange(:,1,isub)=SubRange(:,1,isub)-Siz'/4;
    98100            SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4;
    99         % subdomain includes enough vectors, perform tps interpolation
     101        % if subdomain includes enough vectors, perform tps interpolation
    100102        else
    101103            [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel,:),U(ind_sel),smoothing);
     
    106108            ind_ind_sel=1:numel(ind_sel);%default
    107109            if exist('Threshold','var')&&~isempty(Threshold)
    108                 FF(ind_sel)=4*(NormDiff>Threshold);%put FF value to 4 to identify the criterium of elimmination
    109                 ind_ind_sel=find(FF(ind_sel)==0); % select the indices of remaining vectors in the subset of ind_sel vectors
     110                FF(ind_sel)=(NormDiff>Threshold);%put FF value to 1 to identify the criterium of elimmination
     111                ind_ind_sel=find(~FF(ind_sel)); % select the indices of remaining vectors in the subset of ind_sel vectors
    110112            end
    111113            % if no value exceeds threshold, the result is recorded
     
    116118                y_dist=(Coord(ind_sel,2)-CentreY(isub))/y_width;% relative ydistance to the retangle centre
    117119                weight=cos(x_dist).*cos(y_dist);%weighting fct =1 at the rectangle center and 0 at edge
     120                %weight=1;% case for r1129 and before
    118121                U_smooth(ind_sel)=U_smooth(ind_sel)+weight.*U_smooth_sub;
    119122                V_smooth(ind_sel)=V_smooth(ind_sel)+weight.*V_smooth_sub;
     
    138141                y_dist=(Coord(ind_sel(ind_ind_sel),2)-CentreY(isub))/y_width;% relative ydistance to the retangle centre
    139142                weight=cos(x_dist).*cos(y_dist);%weighting fct =1 at the rectangle center and 0 at edge
     143                %weight=1;
    140144                U_smooth(ind_sel(ind_ind_sel))=U_smooth(ind_sel(ind_ind_sel))+weight.*U_smooth_sub;
    141145                V_smooth(ind_sel(ind_ind_sel))=V_smooth(ind_sel(ind_ind_sel))+weight.*V_smooth_sub;
     
    166170U_smooth=U_smooth./nb_select;% take the average at the intersection of several subdomains
    167171V_smooth=V_smooth./nb_select;
    168 U_smooth(FF==4)=U(FF==4);% set to the initial values the eliminated vectors (flagged as false)
    169 V_smooth(FF==4)=V(FF==4);
     172
     173%eliminate the vectors with diff>threshold not yet eliminated
     174if exist('Threshold','var')&&~isempty(Threshold)
     175UDiff=U_smooth-U;% difference between interpolated U component and initial value
     176VDiff=V_smooth-V;% difference between interpolated V component and initial value
     177NormDiff=UDiff.*UDiff+VDiff.*VDiff;% Square of difference norm
     178FF(NormDiff>Threshold)=true;%put FF value to 1 to identify the criterium of elimmination
     179end
     180
     181U_smooth(FF)=U(FF);% set to the initial values the eliminated vectors (flagged as false)
     182V_smooth(FF)=V(FF);
    170183fill=zeros(NbCoord+1,NbCoord,size(SubRange,3)); %matrix of zeros to complement the matrix Data.Civ1_Coord_tps (conveninent for file storage)
    171184Coord_tps=cat(1,Coord_tps,fill);
Note: See TracChangeset for help on using the changeset viewer.