[515] | 1 |
|
---|
[575] | 2 | %'calc_field_tps': defines fields (velocity, vort, div...) from civ data and calculate them with tps interpolation
|
---|
[515] | 3 | %---------------------------------------------------------------------
|
---|
[651] | 4 | % [DataOut,VarAttribute,errormsg]=calc_field_tps(Coord_tps,NbCentre,SubRange,FieldVar,FieldName,Coord_interp)
|
---|
[515] | 5 | %
|
---|
| 6 | % OUTPUT:
|
---|
| 7 | % DataOut: structure representing the output fields
|
---|
[675] | 8 | % VarAttribute: cell array of structures coontaining the variable attributes
|
---|
| 9 | % errormsg: error msg , = '' by default
|
---|
[515] | 10 | %
|
---|
| 11 | % INPUT:
|
---|
[651] | 12 | % Coord_tps: coordinates of the centres, of dimensions [nb_point,nb_coord,nb_subdomain], where
|
---|
| 13 | % nb_point is the max number of data point in a subdomain,
|
---|
| 14 | % nb_coord the space dimension,
|
---|
| 15 | % nb_subdomain the nbre of subdomains used for tps
|
---|
| 16 | % NbCentre: nbre of tps centres for each subdomain, of dimension nb_subdomain
|
---|
| 17 | % SubRange: coordinate range for each subdomain, of dimensions [nb_coord,2,nb_subdomain]
|
---|
[675] | 18 | % FieldVar: array representing the input fields as tps weights with dimension (nbvec_sub+3,NbSubDomain,nb_dim)
|
---|
| 19 | % nbvec_sub= max nbre of vectors in a subdomain
|
---|
| 20 | % NbSubDomain =nbre of subdomains
|
---|
| 21 | % nb_dim: nbre of dimensions for vector components (x-> 1, y->2)
|
---|
[651] | 22 | % FieldName: cell array representing the list of operations (eg div(U,V), rot(U,V))
|
---|
| 23 | % Coord_interp: coordinates of sites on which the fields need to be calculated of dimensions
|
---|
| 24 | % [nb_site,nb_coord] for an array of interpolation sites
|
---|
| 25 | % [nb_site_y,nb_site_x,nb_coord] for interpolation on a plane grid of size [nb_site_y,nb_site_x]
|
---|
[515] | 26 |
|
---|
[651] | 27 | function [DataOut,VarAttribute,errormsg]=calc_field_tps(Coord_tps,NbCentre,SubRange,FieldVar,FieldName,Coord_interp)
|
---|
[515] | 28 |
|
---|
| 29 | %list of defined scalars to display in menus (in addition to 'ima_cor').
|
---|
| 30 | % a type is associated to each scalar:
|
---|
| 31 | % 'discrete': related to the individual velocity vectors, not interpolated by patch
|
---|
| 32 | % 'vel': calculated from velocity components, continuous field (interpolated with velocity)
|
---|
| 33 | % 'der': needs spatial derivatives
|
---|
| 34 | % 'var': the scalar name corresponds to a field name in the netcdf files
|
---|
| 35 | % a specific variable name for civ1 and civ2 fields are also associated, if
|
---|
| 36 | % the scalar is calculated from other fields, as explicited below
|
---|
| 37 | errormsg='';
|
---|
| 38 |
|
---|
| 39 | %% nbre of subdomains
|
---|
| 40 | if ndims(Coord_interp)==3
|
---|
| 41 | nb_coord=size(Coord_interp,3);
|
---|
| 42 | npx=size(Coord_interp,2);
|
---|
| 43 | npy=size(Coord_interp,1);
|
---|
| 44 | nb_sites=npx*npy;
|
---|
| 45 | Coord_interp=reshape(Coord_interp,nb_sites,nb_coord);
|
---|
| 46 | else
|
---|
| 47 | nb_coord=size(Coord_interp,2);
|
---|
| 48 | nb_sites=size(Coord_interp,1);
|
---|
| 49 | end
|
---|
| 50 | NbSubDomain=size(Coord_tps,3);
|
---|
| 51 | nbval=zeros(nb_sites,1);
|
---|
| 52 |
|
---|
| 53 | %% list of operations
|
---|
| 54 | check_grid=0;
|
---|
| 55 | check_der=0;
|
---|
[675] | 56 | check_vec=0;
|
---|
| 57 | check_remove=false(size(FieldName));
|
---|
| 58 | VarAttribute={};
|
---|
[581] | 59 | for ilist=1:length(FieldName)
|
---|
[675] | 60 | FieldNameType=regexprep(FieldName{ilist},'(.+','');% detect the char string before the parenthesis
|
---|
| 61 | VarAttributeNew={};
|
---|
[581] | 62 | switch FieldNameType
|
---|
[515] | 63 | case 'vec'
|
---|
[521] | 64 | check_grid=1;
|
---|
[515] | 65 | DataOut.U=zeros(nb_sites,1);
|
---|
| 66 | DataOut.V=zeros(nb_sites,1);
|
---|
[675] | 67 | VarAttributeNew{1}.Role='vector_x';
|
---|
| 68 | VarAttributeNew{2}.Role='vector_y';
|
---|
| 69 | check_vec=1;
|
---|
| 70 | case {'U','V'}
|
---|
| 71 | if check_vec% no new data needed
|
---|
| 72 | check_remove(ilist)=1;
|
---|
| 73 | else
|
---|
[515] | 74 | check_grid=1;
|
---|
[581] | 75 | DataOut.(FieldNameType)=zeros(nb_sites,1);
|
---|
[675] | 76 | VarAttributeNew{1}.Role='scalar';
|
---|
| 77 | end
|
---|
| 78 | case 'norm'
|
---|
| 79 | check_grid=1;
|
---|
| 80 | DataOut.(FieldNameType)=zeros(nb_sites,1);
|
---|
| 81 | VarAttributeNew{1}.Role='scalar';
|
---|
[515] | 82 | case {'curl','div','strain'}
|
---|
| 83 | check_der=1;
|
---|
[581] | 84 | DataOut.(FieldNameType)=zeros(nb_sites,1);
|
---|
[675] | 85 | VarAttributeNew{1}.Role='scalar';
|
---|
[515] | 86 | end
|
---|
[675] | 87 | VarAttribute=[VarAttribute VarAttributeNew];
|
---|
[515] | 88 | end
|
---|
| 89 | Attr_FF.Role='errorflag';
|
---|
| 90 | VarAttribute=[VarAttribute {Attr_FF}];
|
---|
[675] | 91 | FieldName(check_remove)=[];
|
---|
[515] | 92 |
|
---|
| 93 | %% loop on subdomains
|
---|
| 94 | for isub=1:NbSubDomain
|
---|
[651] | 95 | nbvec_sub=NbCentre(isub);
|
---|
[515] | 96 | check_range=(Coord_interp >=ones(nb_sites,1)*SubRange(:,1,isub)' & Coord_interp<=ones(nb_sites,1)*SubRange(:,2,isub)');
|
---|
| 97 | ind_sel=find(sum(check_range,2)==nb_coord);
|
---|
| 98 | nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for eacn interpolation point (in case of subdomain overlap)
|
---|
| 99 | if check_grid
|
---|
| 100 | EM = tps_eval(Coord_interp(ind_sel,:),Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the velocity from tps 'sources'
|
---|
| 101 | end
|
---|
| 102 | if check_der
|
---|
| 103 | [EMDX,EMDY] = tps_eval_dxy(Coord_interp(ind_sel,:),Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the spatial derivatives from tps 'sources'
|
---|
| 104 | end
|
---|
[675] | 105 | % ListVar={};
|
---|
[581] | 106 | for ilist=1:length(FieldName)
|
---|
[675] | 107 | % var_count=numel(ListVar);
|
---|
[581] | 108 | switch FieldName{ilist}
|
---|
[515] | 109 | case 'vec(U,V)'
|
---|
[675] | 110 | % ListVar=[ListVar {'U', 'V'}];
|
---|
| 111 | % VarAttribute{var_count+1}.Role='vector_x';
|
---|
| 112 | % VarAttribute{var_count+2}.Role='vector_y';
|
---|
[515] | 113 | DataOut.U(ind_sel)=DataOut.U(ind_sel)+EM *FieldVar(1:nbvec_sub+3,isub,1);
|
---|
| 114 | DataOut.V(ind_sel)=DataOut.V(ind_sel)+EM *FieldVar(1:nbvec_sub+3,isub,2);
|
---|
| 115 | case 'U'
|
---|
[675] | 116 | % ListVar=[ListVar {'U'}];
|
---|
| 117 | % VarAttribute{var_count+1}.Role='scalar';
|
---|
[515] | 118 | DataOut.U(ind_sel)=DataOut.U(ind_sel)+EM *FieldVar(1:nbvec_sub+3,isub,1);
|
---|
| 119 | case 'V'
|
---|
[675] | 120 | % ListVar=[ListVar {'V'}];
|
---|
| 121 | % VarAttribute{var_count+1}.Role='scalar';
|
---|
[515] | 122 | DataOut.V(ind_sel)=DataOut.V(ind_sel)+EM *FieldVar(1:nbvec_sub+3,isub,2);
|
---|
| 123 | case 'norm(U,V)'
|
---|
[675] | 124 | % ListVar=[ListVar {'norm'}];
|
---|
| 125 | % VarAttribute{var_count+1}.Role='scalar';
|
---|
[515] | 126 | U=DataOut.U(ind_sel)+EM *FieldVar(1:nbvec_sub+3,isub,1);
|
---|
| 127 | V=DataOut.V(ind_sel)+EM *FieldVar(1:nbvec_sub+3,isub,2);
|
---|
| 128 | DataOut.norm(ind_sel)=sqrt(U.*U+V.*V);
|
---|
| 129 | case 'curl(U,V)'
|
---|
[675] | 130 | % ListVar=[ListVar {'curl'}];
|
---|
| 131 | % VarAttribute{var_count+1}.Role='scalar';
|
---|
[515] | 132 | DataOut.curl(ind_sel)=DataOut.curl(ind_sel)-EMDY *FieldVar(1:nbvec_sub+3,isub,1)+EMDX *FieldVar(1:nbvec_sub+3,isub,2);
|
---|
| 133 | case 'div(U,V)'
|
---|
[675] | 134 | % ListVar=[ListVar {'div'}];
|
---|
| 135 | % VarAttribute{var_count+1}.Role='scalar';
|
---|
[515] | 136 | DataOut.div(ind_sel)=DataOut.div(ind_sel)+EMDX*FieldVar(1:nbvec_sub+3,isub,1)+EMDY *FieldVar(1:nbvec_sub+3,isub,2);
|
---|
| 137 | case 'strain(U,V)'
|
---|
[675] | 138 | % ListVar=[ListVar {'strain'}];
|
---|
| 139 | % VarAttribute{var_count+1}.Role='scalar';
|
---|
[515] | 140 | DataOut.strain(ind_sel)=DataOut.strain(ind_sel)+EMDY*FieldVar(1:nbvec_sub+3,isub,1)+EMDX *FieldVar(1:nbvec_sub+3,isub,2);
|
---|
| 141 | end
|
---|
| 142 | end
|
---|
| 143 | end
|
---|
| 144 | DataOut.FF=nbval==0; %put errorflag to 1 for points outside the interpolation rang
|
---|
| 145 | nbval(nbval==0)=1;% to avoid division by zero for averaging
|
---|
| 146 | ListFieldOut=fieldnames(DataOut);
|
---|
| 147 | for ifield=1:numel(ListFieldOut)
|
---|
| 148 | DataOut.(ListFieldOut{ifield})=DataOut.(ListFieldOut{ifield})./nbval;
|
---|
| 149 | DataOut.(ListFieldOut{ifield})=reshape(DataOut.(ListFieldOut{ifield}),npy,npx);
|
---|
| 150 | end
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 |
|
---|