[382] | 1 | %------------------------------------------------------------------------ |
---|
| 2 | % patch function |
---|
| 3 | % OUTPUT: |
---|
| 4 | % SubRange(NbCoord,NbSubdomain,2): range (min, max) of the coordiantes x and y respectively, for each subdomain |
---|
| 5 | % NbSites(NbSubdomain): number of source points for each subdomain |
---|
| 6 | % FF: false flags |
---|
| 7 | % U_smooth, V_smooth: filtered velocity components at the positions of the initial data |
---|
| 8 | % Coord_tps(NbSites,NbCoord,NbSubdomain): positions of the tps centres |
---|
| 9 | % U_tps,V_tps: weight of the tps for each subdomain |
---|
| 10 | % |
---|
| 11 | % INPUT: |
---|
| 12 | % X, Y: set of coordinates of the initial data |
---|
| 13 | % U,V: set of velocity components of the initial data |
---|
| 14 | % Rho: smoothing parameter |
---|
| 15 | % Threshold: max diff accepted between smoothed and initial data |
---|
| 16 | % Subdomain: estimated number of data points in each subdomain |
---|
| 17 | |
---|
| 18 | %function [SubRangx,SubRangy,nbpoints,FF,U_smooth,V_smooth,X_tps,Y_tps,U_tps,V_tps,Indices_tps] =filter_tps(Coord,U,V,W,SubDomain,Rho,Threshold) |
---|
| 19 | function [SubRange,NbSites,Coord_tps,U_tps,V_tps,W_tps,U_smooth,V_smooth,W_smooth,FF] =filter_tps(Coord,U,V,W,SubDomain,Rho,Threshold) |
---|
| 20 | %subdomain decomposition |
---|
| 21 | warning off |
---|
| 22 | % U=reshape(U,[],1); |
---|
| 23 | % V=reshape(V,[],1); |
---|
| 24 | % X=reshape(X,[],1); |
---|
| 25 | % Y=reshape(Y,[],1); |
---|
| 26 | nbvec=size(Coord,1); |
---|
| 27 | W_tps=[];%default |
---|
| 28 | W_smooth=[]; |
---|
| 29 | NbCoord=size(Coord,2); |
---|
| 30 | NbSubDomain=ceil(nbvec/SubDomain); |
---|
| 31 | MinCoord=min(Coord,[],1); |
---|
| 32 | % MinY=min(Y,); |
---|
| 33 | MaxCoord=max(Coord,[],1); |
---|
| 34 | % MaxY=max(Y); |
---|
| 35 | Range=MaxCoord-MinCoord; |
---|
| 36 | % RangY=MaxY-MinY; |
---|
| 37 | AspectRatio=Range(2)/Range(1); |
---|
| 38 | NbSubDomainX=max(floor(sqrt(NbSubDomain/AspectRatio)),1); |
---|
| 39 | NbSubDomainY=max(floor(sqrt(NbSubDomain*AspectRatio)),1); |
---|
| 40 | NbSubDomain=NbSubDomainX*NbSubDomainY; |
---|
| 41 | Siz(1)=Range(1)/NbSubDomainX;%width of subdomains |
---|
| 42 | Siz(2)=Range(2)/NbSubDomainY;%height of subdomains |
---|
| 43 | CentreX=linspace(MinCoord(1)+Siz(1)/2,MaxCoord(1)-Siz(1)/2,NbSubDomainX); |
---|
| 44 | CentreY=linspace(MinCoord(2)+Siz(2)/2,MaxCoord(2)-Siz(2)/2,NbSubDomainY); |
---|
| 45 | [CentreX,CentreY]=meshgrid(CentreX,CentreY); |
---|
| 46 | CentreY=reshape(CentreY,1,[]);% Y positions of subdomain centres |
---|
| 47 | CentreX=reshape(CentreX,1,[]);% X positions of subdomain centres |
---|
| 48 | rho=Siz(1)*Siz(2)*Rho/1000000;%optimum rho increase as the area of the subdomain (division by 10^6 to reach good values with the default GUI input) |
---|
| 49 | U_tps_sub=zeros(nbvec,NbSubDomain);%default spline |
---|
| 50 | V_tps_sub=zeros(nbvec,NbSubDomain);%default spline |
---|
| 51 | Indices_tps=zeros(nbvec,NbSubDomain);%default indices |
---|
| 52 | U_smooth=zeros(nbvec,1); |
---|
| 53 | V_smooth=zeros(nbvec,1); |
---|
| 54 | nb_select=zeros(nbvec,1); |
---|
| 55 | FF=zeros(nbvec,1); |
---|
| 56 | check_empty=zeros(1,NbSubDomain); |
---|
| 57 | SubRange=zeros(NbCoord,2,NbSubDomain);%initialise the positions of subdomains |
---|
| 58 | % SubRangy=zeros(NbSubDomain,2); |
---|
| 59 | for isub=1:NbSubDomain |
---|
| 60 | SubRange(1,:,isub)=[CentreX(isub)-0.55*Siz(1) CentreX(isub)+0.55*Siz(1)]; |
---|
| 61 | SubRange(2,:,isub)=[CentreY(isub)-0.55*Siz(2) CentreY(isub)+0.55*Siz(2)]; |
---|
| 62 | ind_sel_previous=[]; |
---|
| 63 | ind_sel=0; |
---|
| 64 | while numel(ind_sel)>numel(ind_sel_previous) %increase the subdomain during four iterations at most |
---|
| 65 | ind_sel_previous=ind_sel; |
---|
| 66 | 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)); |
---|
| 67 | % if no vector in the subdomain, skip the subdomain |
---|
| 68 | if isempty(ind_sel) |
---|
| 69 | check_empty(isub)=1; |
---|
| 70 | U_tps(1,isub)=0;%define U_tps and V_tps by default |
---|
| 71 | V_tps(1,isub)=0; |
---|
| 72 | break |
---|
| 73 | % if too few selected vectors, increase the subrange for next iteration |
---|
| 74 | elseif numel(ind_sel)<SubDomain/4 && ~isequal( ind_sel,ind_sel_previous); |
---|
[387] | 75 | SubRange(:,1,isub)=SubRange(:,1,isub)-Siz'/4; |
---|
| 76 | SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4; |
---|
[382] | 77 | % SubRangy(isub,1)=SubRangy(isub,1)-Siz(2)/4; |
---|
| 78 | % SubRangy(isub,2)=SubRangy(isub,2)+Siz(2)/4; |
---|
| 79 | else |
---|
| 80 | |
---|
| 81 | [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel,:),U(ind_sel),rho); |
---|
| 82 | [V_smooth_sub,V_tps_sub]=tps_coeff(Coord(ind_sel,:),V(ind_sel),rho); |
---|
| 83 | UDiff=U_smooth_sub-U(ind_sel); |
---|
| 84 | VDiff=V_smooth_sub-V(ind_sel); |
---|
| 85 | NormDiff=UDiff.*UDiff+VDiff.*VDiff; |
---|
| 86 | ind_ind_sel=1:numel(ind_sel);%default |
---|
| 87 | if exist('Threshold','var') |
---|
| 88 | FF(ind_sel)=20*(NormDiff>Threshold);%put FF value to 20 to identify the criterium of elimmination |
---|
| 89 | ind_ind_sel=find(FF(ind_sel)==0); % select the indices of ind_sel corresponding to the remaining vectors |
---|
| 90 | end |
---|
[387] | 91 | % if no value exceeds threshold, the result is recorded |
---|
[382] | 92 | if isequal(numel(ind_ind_sel),numel(ind_sel)) |
---|
| 93 | U_smooth(ind_sel)=U_smooth(ind_sel)+U_smooth_sub; |
---|
| 94 | V_smooth(ind_sel)=V_smooth(ind_sel)+V_smooth_sub; |
---|
| 95 | NbSites(isub)=numel(ind_sel); |
---|
| 96 | Coord_tps(1:NbSites(isub),:,isub)=Coord(ind_sel,:); |
---|
| 97 | U_tps(1:NbSites(isub)+3,isub)=U_tps_sub; |
---|
| 98 | V_tps(1:NbSites(isub)+3,isub)=V_tps_sub; |
---|
| 99 | nb_select(ind_sel)=nb_select(ind_sel)+1; |
---|
[387] | 100 | display('good') |
---|
[382] | 101 | break |
---|
[387] | 102 | % if too few selected vectors, increase the subrange for next iteration |
---|
[382] | 103 | elseif numel(ind_ind_sel)<SubDomain/4 && ~isequal( ind_sel,ind_sel_previous); |
---|
[387] | 104 | SubRange(:,1,isub)=SubRange(:,1,isub)-Siz'/4; |
---|
| 105 | SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4; |
---|
| 106 | % else interpolation-smoothing is done again with the selected vectors |
---|
[382] | 107 | else |
---|
[387] | 108 | [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel(ind_ind_sel),:),U(ind_sel(ind_ind_sel)),rho); |
---|
| 109 | [V_smooth_sub,V_tps_sub]=tps_coeff(Coord(ind_sel(ind_ind_sel),:),V(ind_sel(ind_ind_sel)),rho); |
---|
[382] | 110 | U_smooth(ind_sel(ind_ind_sel))=U_smooth(ind_sel(ind_ind_sel))+U_smooth_sub; |
---|
| 111 | V_smooth(ind_sel(ind_ind_sel))=V_smooth(ind_sel(ind_ind_sel))+V_smooth_sub; |
---|
| 112 | NbSites(isub)=numel(ind_ind_sel); |
---|
| 113 | %Indices_tps(1:NbSites(isub),isub)=ind_sel(ind_ind_sel); |
---|
| 114 | Coord_tps(1:NbSites(isub),:,isub)=Coord(ind_sel(ind_ind_sel),:); |
---|
| 115 | % Y_tps(1:NbSites(isub),:,isub)=Coord(ind_sel(ind_ind_sel),2); |
---|
| 116 | U_tps(1:NbSites(isub)+3,isub)=U_tps_sub; |
---|
| 117 | V_tps(1:NbSites(isub)+3,isub)=V_tps_sub; |
---|
| 118 | nb_select(ind_sel(ind_ind_sel))=nb_select(ind_sel(ind_ind_sel))+1; |
---|
| 119 | display('good2') |
---|
| 120 | break |
---|
| 121 | end |
---|
| 122 | end |
---|
| 123 | end |
---|
| 124 | end |
---|
| 125 | ind_empty=find(check_empty); |
---|
| 126 | %remove empty subdomains |
---|
| 127 | if ~isempty(ind_empty) |
---|
| 128 | SubRange(:,:,ind_empty)=[]; |
---|
| 129 | % SubRangy(ind_empty,:)=[]; |
---|
| 130 | % Indices_tps(:,ind_empty)=[]; |
---|
| 131 | Coord_tps(:,:,ind_empty)=[]; |
---|
| 132 | % Y_tps(:,ind_empty)=[]; |
---|
| 133 | U_tps(:,ind_empty)=[]; |
---|
| 134 | V_tps(:,ind_empty)=[]; |
---|
| 135 | end |
---|
| 136 | nb_select(nb_select==0)=1;%ones(size(find(nb_select==0))); |
---|
| 137 | U_smooth=U_smooth./nb_select; |
---|
| 138 | V_smooth=V_smooth./nb_select; |
---|