Changeset 896 for trunk/src/filter_tps.m
- Timestamp:
- May 23, 2015, 5:09:49 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/filter_tps.m
r809 r896 1 1 %'filter_tps': find the thin plate spline coefficients for interpolation-smoothing 2 2 %------------------------------------------------------------------------ 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) 4 4 % 5 5 % OUTPUT: … … 37 37 %======================================================================= 38 38 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)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,SubDomainSize,Rho,Threshold) 40 40 41 41 %% adjust subdomain decomposition 42 42 warning off 43 NbVec=size(Coord,1); 44 NbCoord=size(Coord,2); 43 NbVec=size(Coord,1);% nbre of vectors in the field to interpolate 44 NbCoord=size(Coord,2);% space dimension 45 45 MinCoord=min(Coord,[],1);%lower coordinate bounds 46 46 MaxCoord=max(Coord,[],1);%upper coordinate bounds 47 47 Range=MaxCoord-MinCoord; 48 48 AspectRatio=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; 49 NbSubDomain=NbVec/SubDomainSize;% estimated number of subdomains 50 NbSubDomainX=max(floor(sqrt(NbSubDomain/AspectRatio)),1);% estimated number of subdomains in x 51 NbSubDomainY=max(floor(sqrt(NbSubDomain*AspectRatio)),1);% estimated number of subdomains in y 52 NbSubDomain=NbSubDomainX*NbSubDomainY;% new estimated number of subdomains in a matrix shape partition in subdomains 53 53 Siz(1)=Range(1)/NbSubDomainX;%width of subdomains 54 54 Siz(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); 55 CentreX=linspace(MinCoord(1)+Siz(1)/2,MaxCoord(1)-Siz(1)/2,NbSubDomainX);% X positions of subdomain centres 56 CentreY=linspace(MinCoord(2)+Siz(2)/2,MaxCoord(2)-Siz(2)/2,NbSubDomainY);% Y positions of subdomain centres 57 57 [CentreX,CentreY]=meshgrid(CentreX,CentreY); 58 CentreX=reshape(CentreX,1,[]);% X positions of subdomain centres 58 59 CentreY=reshape(CentreY,1,[]);% Y positions of subdomain centres 59 CentreX=reshape(CentreX,1,[]);% X positions of subdomain centres60 60 61 61 %% smoothing parameter … … 63 63 64 64 %% 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 65 SubRange=zeros(NbCoord,2,NbSubDomain);%initialise the boundaries of subdomains 66 Coord_tps=zeros(1,NbCoord,NbSubDomain);% initialize coordinates of interpolated data 67 U_tps=zeros(1,NbSubDomain);% initialize interpolated u component 68 V_tps=zeros(1,NbSubDomain);% initialize interpolated v component 69 NbCentre=zeros(1,NbSubDomain);%number of interpolated field values per subdomain, =0 by default 67 70 W_tps=[];%default (2 component case) 68 71 U_smooth=zeros(NbVec,1); % smoothed velocity U at the initial positions … … 73 76 check_empty=zeros(1,NbSubDomain); 74 77 78 75 79 %% calculate tps coeff in each subdomain 76 80 for 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 79 83 ind_sel_previous=[]; 80 ind_sel=0; 84 ind_sel=0;%initialize set of vector indices in the subdomain 81 85 %increase iteratively the subdomain if it contains less than SubDomainNbVec/4 source vectors 82 86 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 84 88 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 subdomain89 % if no vector in the subdomain #isub, skip the subdomain 86 90 if isempty(ind_sel) 87 91 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); 93 95 SubRange(:,1,isub)=SubRange(:,1,isub)-Siz'/4; 94 96 SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4; 97 % subdomain includes enough vectors, perform tps interpolation 95 98 else 96 99 [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel,:),U(ind_sel),rho); 97 100 [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 101 104 ind_ind_sel=1:numel(ind_sel);%default 102 105 if exist('Threshold','var')&&~isempty(Threshold) … … 113 116 V_tps(1:NbCentre(isub)+3,isub)=V_tps_sub; 114 117 nb_select(ind_sel)=nb_select(ind_sel)+1; 115 display( 'good')118 display(['tps done in subdomain # ' num2str(isub) ' among ' num2str(NbSubDomain)]) 116 119 break 117 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); 119 122 SubRange(:,1,isub)=SubRange(:,1,isub)-Siz'/4; 120 123 SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4; 121 124 % else interpolation-smoothing is done again with the selected vectors 122 125 else 123 126 [U_smooth_sub,U_tps_sub]=tps_coeff(Coord(ind_sel(ind_ind_sel),:),U(ind_sel(ind_ind_sel)),rho); … … 130 133 V_tps(1:NbCentre(isub)+3,isub)=V_tps_sub; 131 134 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)]) 133 136 break 134 137 end … … 144 147 U_tps(:,ind_empty)=[]; 145 148 V_tps(:,ind_empty)=[]; 149 NbCentre(ind_empty)=[]; 146 150 end 147 151
Note: See TracChangeset
for help on using the changeset viewer.