Changeset 246 for trunk/src/calc_field.m


Ignore:
Timestamp:
Apr 28, 2011, 10:52:31 AM (13 years ago)
Author:
sommeria
Message:

thin plate shell (patch) introduced

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/calc_field.m

    r236 r246  
    6060        nbcoord=2;
    6161    end
    62     DataOut=DataIn; %reproduce global attribute
    6362    ListVarName={};
    6463    ValueList={};
    6564    RoleList={};
    6665    units_cell={};
    67     for ilist=1:length(FieldName)
    68         if ~isempty(FieldName{ilist})
    69             [VarName,Value,Role,units]=feval(FieldName{ilist},DataIn);%calculate field with appropriate function named FieldName{ilist}
    70             ListVarName=[ListVarName VarName];
    71             ValueList=[ValueList Value];
    72             RoleList=[RoleList Role];
    73             units_cell=[units_cell units];
    74         end
    75     end
    76     %erase previous data (except coordinates)
    77     for ivar=nbcoord+1:length(DataOut.ListVarName)
    78         VarName=DataOut.ListVarName{ivar};
    79         DataOut=rmfield(DataOut,VarName);
    80     end
    81     DataOut.ListVarName=DataOut.ListVarName(1:nbcoord);
    82     if isfield(DataOut,'VarDimName')
    83         DataOut.VarDimName=DataOut.VarDimName(1:nbcoord);
    84     else
    85         errormsg='element .VarDimName missing in input data';
    86         return
    87     end
    88     DataOut.VarAttribute=DataOut.VarAttribute(1:nbcoord);
    89     %append new data
    90     DataOut.ListVarName=[DataOut.ListVarName ListVarName];
    91     for ivar=1:length(ListVarName)
    92         DataOut.VarDimName{nbcoord+ivar}=DataOut.VarDimName{1};
    93         DataOut.VarAttribute{nbcoord+ivar}.Role=RoleList{ivar};
    94         DataOut.VarAttribute{nbcoord+ivar}.units=units_cell{ivar};
    95         eval(['DataOut.' ListVarName{ivar} '=ValueList{ivar};'])
    96     end
    97 end
     66    % new civ data
     67    if isfield(DataIn,'X_SubRange')
     68        XMax=max(max(DataIn.X_SubRange));
     69        YMax=max(max(DataIn.Y_SubRange));
     70        XMin=min(min(DataIn.X_SubRange));
     71        YMin=min(min(DataIn.Y_SubRange));
     72        Mesh=sqrt((YMax-YMin)*(XMax-XMin)/numel(DataIn.X_tps));%2D
     73        xI=XMin:Mesh:XMax;
     74        yI=YMin:Mesh:YMax;
     75        [XI,YI]=meshgrid(xI,yI);
     76        XI=reshape(XI,[],1);
     77        YI=reshape(YI,[],1);
     78        DataOut.ListGlobalAttribute=DataIn.ListGlobalAttribute; %reproduce global attribute
     79        for ilist=1:numel(DataOut.ListGlobalAttribute)
     80            eval(['DataOut.' DataOut.ListGlobalAttribute{ilist} '=DataIn.' DataIn.ListGlobalAttribute{ilist} ';'])
     81        end
     82        DataOut.ListVarName={'coord_y','coord_x','FF'};
     83        DataOut.VarDimName{1}='coord_y';
     84        DataOut.VarDimName{2}='coord_x';
     85        DataOut.coord_y=[yI(1) yI(end)];
     86        DataOut.coord_x=[xI(1) xI(end)];
     87        DataOut.U=zeros(size(XI));
     88        DataOut.V=zeros(size(XI));
     89        DataOut.vort=zeros(size(XI));
     90        DataOut.div=zeros(size(XI));
     91        nbval=zeros(size(XI));
     92        [NbSubDomain,xx]=size(DataIn.X_SubRange);
     93        for isub=1:NbSubDomain
     94            nbvec_sub=DataIn.NbSites(isub);         
     95                ind_sel=find(XI>=DataIn.X_SubRange(isub,1) & XI<=DataIn.X_SubRange(isub,2) & YI>=DataIn.Y_SubRange(isub,1) & YI<=DataIn.Y_SubRange(isub,2));
     96                %rho smoothing parameter
     97                epoints = [XI(ind_sel) YI(ind_sel)];% coordinates of interpolation sites
     98                ctrs=[DataIn.X_tps(1:nbvec_sub,isub) DataIn.Y_tps(1:nbvec_sub,isub)];%(=initial points) ctrs
     99                nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for eacn interpolation point (in case of subdomain overlap)
     100%                 PM = [ones(size(epoints,1),1) epoints];
     101                switch FieldName{1}
     102                    case {'velocity','u','v'}
     103                       % DM_eval = DistanceMatrix(epoints,ctrs);%2D matrix of distances between extrapolation points epoints and spline centres (=site points) ctrs
     104                       % EM = tps(1,DM_eval);%values of thin plate
     105                        EM = tps_eval(epoints,ctrs);
     106                    case{'vort','div'}
     107                        EMDXY = tps_eval_dxy(epoints,ctrs);%2D matrix of distances between extrapolation points epoints and spline centres (=site points) ctrs
     108     
     109                end
     110                switch FieldName{1}
     111                    case 'velocity'
     112                        ListFields={'U', 'V'};
     113                        VarAttributes{1}.Role='vector_x';
     114                        VarAttributes{2}.Role='vector_y';
     115                        DataOut.U(ind_sel)=DataOut.U(ind_sel)+EM *DataIn.U_tps(1:nbvec_sub+3,isub);
     116                        DataOut.V(ind_sel)=DataOut.V(ind_sel)+EM *DataIn.V_tps(1:nbvec_sub+3,isub);
     117                    case 'u'
     118                        ListFields={'U'};
     119                        VarAttributes{1}.Role='scalar';
     120                        DataOut.U(ind_sel)=DataOut.U(ind_sel)+EM *DataIn.U_tps(1:nbvec_sub+3,isub);
     121                    case 'v'
     122                        ListFields={'V'};
     123                        VarAttributes{1}.Role='scalar';
     124                        DataOut.V(ind_sel)=DataOut.V(ind_sel)+EM *DataIn.V_tps(1:nbvec_sub+3,isub);
     125                    case 'vort'
     126                        ListFields={'vort'};
     127                        VarAttributes{1}.Role='scalar';
     128%                         EMX = [DMXY(:,:,1) PM];
     129%                         EMY = [DMXY(:,:,2) PM];
     130%                         DataIn.U_tps(nbvec_sub+1,isub)=0;%constant value suppressed by spatial derivatives
     131%                         DataIn.V_tps(nbvec_sub+1,isub)=0;%constant value suppressed by spatial derivatives
     132%                         DataIn.V_tps(nbvec_sub+2,isub)=0;% X coefficient suppressed for x wise derivatives
     133%                         DataIn.U_tps(nbvec_sub+3,isub)=0;% Y coefficient suppressed for x wise derivatives
     134                        DataOut.vort(ind_sel)=DataOut.vort(ind_sel)+EMDXY(:,:,2) *DataIn.U_tps(1:nbvec_sub+3,isub)-EMDXY(:,:,1) *DataIn.V_tps(1:nbvec_sub+3,isub);
     135                    case 'div'
     136                        ListFields={'div'};
     137                        VarAttributes{1}.Role='scalar';
     138%                         EMX = [DMXY(:,:,1) PM];
     139%                         EMY = [DMXY(:,:,2) PM];
     140%                         DataIn.U_tps(nbvec_sub+1,isub)=0;%constant value suppressed by spatial derivatives
     141%                         DataIn.V_tps(nbvec_sub+1,isub)=0;%constant value suppressed by spatial derivatives
     142%                         DataIn.V_tps(nbvec_sub+2,isub)=0;% X coefficient suppressed for x wise derivatives
     143%                         DataIn.U_tps(nbvec_sub+3,isub)=0;% Y coefficient suppressed for x wise derivatives
     144                        DataOut.div(ind_sel)=DataOut.div(ind_sel)+EMDXY(:,:,1)*DataIn.U_tps(1:nbvec_sub+3,isub)+EMDXY(:,:,2) *DataIn.V_tps(1:nbvec_sub+3,isub);
     145                end
     146        end
     147        DataOut.FF=nbval==0; %put errorflag to 1 for points outside the interpolation rang 
     148       
     149        DataOut.FF=reshape(DataOut.FF,numel(yI),numel(xI));
     150        nbval(nbval==0)=1;
     151        DataOut.U=DataOut.U ./nbval;
     152        DataOut.V=DataOut.V ./nbval;
     153        DataOut.U=reshape(DataOut.U,numel(yI),numel(xI));
     154        DataOut.V=reshape(DataOut.V,numel(yI),numel(xI));
     155        DataOut.vort=reshape(DataOut.vort,numel(yI),numel(xI));
     156        DataOut.div=reshape(DataOut.div,numel(yI),numel(xI));
     157        DataOut.ListVarName=[DataOut.ListVarName ListFields];
     158        for ilist=3:numel(DataOut.ListVarName)
     159            DataOut.VarDimName{ilist}={'coord_y','coord_x'};
     160        end
     161        DataOut.VarAttribute={[],[]};
     162        DataOut.VarAttribute{3}.Role='errorflag';
     163        DataOut.VarAttribute=[DataOut.VarAttribute VarAttributes];     
     164    else   
     165        DataOut=DataIn;
     166        for ilist=1:length(FieldName)
     167            if ~isempty(FieldName{ilist})
     168                [VarName,Value,Role,units]=feval(FieldName{ilist},DataIn);%calculate field with appropriate function named FieldName{ilist}
     169                ListVarName=[ListVarName VarName];
     170                ValueList=[ValueList Value];
     171                RoleList=[RoleList Role];
     172                units_cell=[units_cell units];
     173            end
     174        end
     175        %erase previous data (except coordinates)
     176        for ivar=nbcoord+1:length(DataOut.ListVarName)
     177            VarName=DataOut.ListVarName{ivar};
     178            DataOut=rmfield(DataOut,VarName);
     179        end
     180        DataOut.ListVarName=DataOut.ListVarName(1:nbcoord);
     181        if isfield(DataOut,'VarDimName')
     182            DataOut.VarDimName=DataOut.VarDimName(1:nbcoord);
     183        else
     184            errormsg='element .VarDimName missing in input data';
     185            return
     186        end
     187        DataOut.VarAttribute=DataOut.VarAttribute(1:nbcoord);
     188        %append new data
     189        DataOut.ListVarName=[DataOut.ListVarName ListVarName];
     190        for ivar=1:length(ListVarName)
     191            DataOut.VarDimName{nbcoord+ivar}=DataOut.VarDimName{1};
     192            DataOut.VarAttribute{nbcoord+ivar}.Role=RoleList{ivar};
     193            DataOut.VarAttribute{nbcoord+ivar}.units=units_cell{ivar};
     194            eval(['DataOut.' ListVarName{ivar} '=ValueList{ivar};'])
     195        end
     196    end
     197end
     198
    98199
    99200%%%%%%%%%%%%% velocity fieldn%%%%%%%%%%%%%%%%%%%%
Note: See TracChangeset for help on using the changeset viewer.