Changeset 896 for trunk/src/filter_tps.m


Ignore:
Timestamp:
May 23, 2015, 5:09:49 PM (9 years ago)
Author:
sommeria
Message:

bug corrected in civ_series/patch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/filter_tps.m

    r809 r896  
    11%'filter_tps': find the thin plate spline coefficients for interpolation-smoothing
    22%------------------------------------------------------------------------
    3 % [SubRange,NbCentre,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomain,Rho,Threshold)
     3% [SubRange,NbCentre,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomainSize,Rho,Threshold)
    44%
    55% OUTPUT:
     
    3737%=======================================================================
    3838
    39 function [SubRange,NbCentre,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomain,Rho,Threshold)
     39function [SubRange,NbCentre,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomainSize,Rho,Threshold)
    4040
    4141%% adjust subdomain decomposition
    4242warning off
    43 NbVec=size(Coord,1);
    44 NbCoord=size(Coord,2);
     43NbVec=size(Coord,1);% nbre of vectors in the field to interpolate
     44NbCoord=size(Coord,2);% space dimension
    4545MinCoord=min(Coord,[],1);%lower coordinate bounds
    4646MaxCoord=max(Coord,[],1);%upper coordinate bounds
    4747Range=MaxCoord-MinCoord;
    4848AspectRatio=Range(2)/Range(1);
    49 NbSubDomain=NbVec/SubDomain;
    50 NbSubDomainX=max(floor(sqrt(NbSubDomain/AspectRatio)),1);
    51 NbSubDomainY=max(floor(sqrt(NbSubDomain*AspectRatio)),1);
    52 NbSubDomain=NbSubDomainX*NbSubDomainY;
     49NbSubDomain=NbVec/SubDomainSize;% estimated number of subdomains
     50NbSubDomainX=max(floor(sqrt(NbSubDomain/AspectRatio)),1);% estimated number of subdomains in x
     51NbSubDomainY=max(floor(sqrt(NbSubDomain*AspectRatio)),1);% estimated number of subdomains in y
     52NbSubDomain=NbSubDomainX*NbSubDomainY;% new estimated number of subdomains in a matrix shape partition in subdomains
    5353Siz(1)=Range(1)/NbSubDomainX;%width of subdomains
    5454Siz(2)=Range(2)/NbSubDomainY;%height of subdomains
    55 CentreX=linspace(MinCoord(1)+Siz(1)/2,MaxCoord(1)-Siz(1)/2,NbSubDomainX);
    56 CentreY=linspace(MinCoord(2)+Siz(2)/2,MaxCoord(2)-Siz(2)/2,NbSubDomainY);
     55CentreX=linspace(MinCoord(1)+Siz(1)/2,MaxCoord(1)-Siz(1)/2,NbSubDomainX);% X positions of subdomain centres
     56CentreY=linspace(MinCoord(2)+Siz(2)/2,MaxCoord(2)-Siz(2)/2,NbSubDomainY);% Y positions of subdomain centres
    5757[CentreX,CentreY]=meshgrid(CentreX,CentreY);
     58CentreX=reshape(CentreX,1,[]);% X positions of subdomain centres
    5859CentreY=reshape(CentreY,1,[]);% Y positions of subdomain centres
    59 CentreX=reshape(CentreX,1,[]);% X positions of subdomain centres
    6060
    6161%% smoothing parameter
     
    6363
    6464%% default output
    65 SubRange=zeros(NbCoord,2,NbSubDomain);%initialise the positions of subdomains
    66 NbCentre=zeros(1,NbSubDomain);%number of interpolated values per subdomain, =0 by default
     65SubRange=zeros(NbCoord,2,NbSubDomain);%initialise the boundaries of subdomains
     66Coord_tps=zeros(1,NbCoord,NbSubDomain);% initialize coordinates of interpolated data
     67U_tps=zeros(1,NbSubDomain);% initialize  interpolated u component
     68V_tps=zeros(1,NbSubDomain);% initialize interpolated v component
     69NbCentre=zeros(1,NbSubDomain);%number of interpolated field values per subdomain, =0 by default
    6770W_tps=[];%default (2 component case)
    6871U_smooth=zeros(NbVec,1); % smoothed velocity U at the initial positions
     
    7376check_empty=zeros(1,NbSubDomain);
    7477
     78
    7579%% calculate tps coeff in each subdomain
    7680for isub=1:NbSubDomain
    77     SubRange(1,:,isub)=[CentreX(isub)-0.55*Siz(1) CentreX(isub)+0.55*Siz(1)];
    78     SubRange(2,:,isub)=[CentreY(isub)-0.55*Siz(2) CentreY(isub)+0.55*Siz(2)];
     81    SubRange(1,:,isub)=[CentreX(isub)-0.55*Siz(1) CentreX(isub)+0.55*Siz(1)];%bounds of subdomain #isub in x coordinate
     82    SubRange(2,:,isub)=[CentreY(isub)-0.55*Siz(2) CentreY(isub)+0.55*Siz(2)];%bounds of subdomain #isub in y coordinate
    7983    ind_sel_previous=[];
    80     ind_sel=0;
     84    ind_sel=0;%initialize set of vector indices in the subdomain
    8185    %increase iteratively the subdomain if it contains less than SubDomainNbVec/4 source vectors
    8286    while numel(ind_sel)>numel(ind_sel_previous)
    83         ind_sel_previous=ind_sel;
     87        ind_sel_previous=ind_sel;% record the set of selected vector indices for next iteration
    8488        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));
    85         % if no vector in the subdomain, skip the subdomain
     89        % if no vector in the subdomain  #isub, skip the subdomain
    8690        if isempty(ind_sel)
    8791            check_empty(isub)=1;
    88             U_tps(1,isub)=0;%define U_tps and V_tps by default
    89             V_tps(1,isub)=0;
    90             break
    91             % if too few selected vectors, increase the subrange for next iteration
    92         elseif numel(ind_sel)<SubDomain/4 && ~isequal( ind_sel,ind_sel_previous);
     92            break %  go to next subdomain
     93        % if too few selected vectors, increase the subrange for next iteration
     94        elseif numel(ind_sel)<SubDomainSize/4 && ~isequal( ind_sel,ind_sel_previous);
    9395            SubRange(:,1,isub)=SubRange(:,1,isub)-Siz'/4;
    9496            SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4;
     97        % subdomain includes enough vectors, perform tps interpolation
    9598        else
    9699            [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel,:),U(ind_sel),rho);
    97100            [V_smooth_sub,V_tps_sub]=tps_coeff(Coord(ind_sel,:),V(ind_sel),rho);
    98             UDiff=U_smooth_sub-U(ind_sel);
    99             VDiff=V_smooth_sub-V(ind_sel);
    100             NormDiff=UDiff.*UDiff+VDiff.*VDiff;
     101            UDiff=U_smooth_sub-U(ind_sel);% difference between interpolated U component and initial value
     102            VDiff=V_smooth_sub-V(ind_sel);% difference between interpolated V component and initial value
     103            NormDiff=UDiff.*UDiff+VDiff.*VDiff;% Square of difference norm
    101104            ind_ind_sel=1:numel(ind_sel);%default
    102105            if exist('Threshold','var')&&~isempty(Threshold)
     
    113116                V_tps(1:NbCentre(isub)+3,isub)=V_tps_sub;
    114117                nb_select(ind_sel)=nb_select(ind_sel)+1;
    115                 display('good')
     118                display(['tps done in subdomain # ' num2str(isub)  ' among ' num2str(NbSubDomain)])
    116119                break
    117                 % if too few selected vectors, increase the subrange for next iteration
    118             elseif numel(ind_ind_sel)<SubDomain/4 && ~isequal( ind_sel,ind_sel_previous);
     120            % if too few selected vectors, increase the subrange for next iteration
     121            elseif numel(ind_ind_sel)<SubDomainSize/4 && ~isequal( ind_sel,ind_sel_previous);
    119122                SubRange(:,1,isub)=SubRange(:,1,isub)-Siz'/4;
    120123                SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4;
    121                 % else interpolation-smoothing is done again with the selected vectors
     124            % else interpolation-smoothing is done again with the selected vectors
    122125            else
    123126                [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel(ind_ind_sel),:),U(ind_sel(ind_ind_sel)),rho);
     
    130133                V_tps(1:NbCentre(isub)+3,isub)=V_tps_sub;
    131134                nb_select(ind_sel(ind_ind_sel))=nb_select(ind_sel(ind_ind_sel))+1;
    132                 display('good2')
     135                display(['tps redone after elimination of erratic vectors in subdomain # ' num2str(isub) ' among ' num2str(NbSubDomain)])
    133136                break
    134137            end
     
    144147    U_tps(:,ind_empty)=[];
    145148    V_tps(:,ind_empty)=[];
     149    NbCentre(ind_empty)=[];
    146150end
    147151
Note: See TracChangeset for help on using the changeset viewer.