Changeset 408


Ignore:
Timestamp:
05/13/09 17:24:05 (16 years ago)
Author:
Mathieu Morlighem
Message:

minor

Location:
issm/trunk/src/m/solutions/macayeal
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/solutions/macayeal/control.m

    r170 r408  
    2020
    2121%Check that control is done on flow law, and not drag (not supported yet):
    22 if ~strcmp(md.control_type,'B')
    23         error('macayealcontrol error message: only ''flow'' law inversion supported yet');
    24 end
     22%if ~strcmp(md.control_type,'B')
     23%       error('macayealcontrol error message: only ''B'' inversion supported yet');
     24%end
    2525
    2626%Transfer model fields into matlab variables
     
    4848tolx=md.tolx;
    4949maxiter=md.maxiter(1);
    50 B_ini=md.B;
    51 drag_coeff_ini=md.drag;
     50if strcmp(md.control_type,'B')
     51        B_ini=md.B;
     52        B_to_p=10^-3*yts^(-1/3);
     53else
     54        drag_coeff_ini=md.drag;
     55end
    5256glen_coeff=md.n;
    5357vx_obs=md.vx_obs/md.yts; %From m/a to m/s
    5458vy_obs=md.vy_obs/md.yts;
    5559nsteps=md.nsteps;
    56 B_to_p=10^-3*yts^(-1/3);
    5760
    5861%Build length_icefront and normal_icefront:
     
    6871create_el2nod_matrices
    6972old_direction=zeros(nods,1);
    70 
    7173
    7274%setup some fake distributions.
     
    8183z_bed_ybar=matrix_ybar*z_bed;
    8284
    83 
    8485%data_elements and data_nodes are the elements and nodes where
    8586%we have observations
     
    104105setup_control
    105106
    106 %setup initial flow law paramter distribution to startup the optimization.
    107 B_bar_ini=(B_ini(index(:,1))+B_ini(index(:,2))+B_ini(index(:,3)))/3;
    108 B=B_ini;  %variables used in optimziation are B and B_bar.
    109 B_bar=B_bar_ini;
    110 
    111107%setup initial drag paramter distribution to startup the optimization.
    112108drag_type=md.drag_type;
    113109qcoeff=md.q;
    114110pcoeff=md.p;
    115 if strcmp(md.control_type,'basal') & (drag_type~=2), error('md.drag_type must be 2 for control methods'); end
    116 drag_coeff_bar_ini=(drag_coeff_ini(index(:,1))+drag_coeff_ini(index(:,2))+drag_coeff_ini(index(:,3)))/3;
    117 drag_coeff=drag_coeff_ini;  %variables used in optimziation are drag_coeff and drag_coeff_bar.
    118 drag_coeff_bar=drag_coeff_bar_ini;
     111
     112if strcmp(md.control_type,'B')
     113        %setup initial flow law paramter distribution to startup the optimization.
     114        B_bar_ini=(B_ini(index(:,1))+B_ini(index(:,2))+B_ini(index(:,3)))/3;
     115        B=B_ini;  %variables used in optimziation are B and B_bar.
     116        B_bar=B_bar_ini;
     117else
     118        B_bar=(md.B(index(:,1))+md.B(index(:,2))+md.B(index(:,3)))/3;
     119        if (drag_type~=2), error('md.drag_type must be 2 for control methods'); end
     120                drag_coeff_bar_ini=(drag_coeff_ini(index(:,1))+drag_coeff_ini(index(:,2))+drag_coeff_ini(index(:,3)))/3;
     121                drag_coeff=drag_coeff_ini;  %variables used in optimziation are drag_coeff and drag_coeff_bar.
     122                drag_coeff_bar=drag_coeff_bar_ini;
     123end
     124
     125
    119126
    120127%check that the model is not a pure ice shelf (no friction on ice shelves)
    121 if strcmp(md.control_type,'basal') & (length(find(drag_coeff))==0),
     128if strcmp(md.control_type,'drag') & (length(find(drag_coeff))==0),
    122129    disp(sprintf('\n      No drag pure for ice shelves => STOP'))
    123130    return
     
    239246    md.cont_parameter=B;
    240247
    241 elseif strcmp(md.control_type,'basal'),
     248elseif strcmp(md.control_type,'drag'),
    242249    for niteration=1:nsteps,
    243250
     
    264271        v_objective=v;
    265272
    266         %Orthogonalize direction
    267        direction=real(direction);
    268        direction=direction/sqrt(direction'*direction);
    269        pos=find(nodes_on_iceshelf);
    270        direction(pos)=0;
    271 
    272 
    273        % rough orthagonalization
    274        direction=direction-(direction'*old_direction)*old_direction;
    275        old_direction=direction;
    276 
    277        %visualize direction
    278                  if md.plot==1,
    279                          if niteration==1
    280                                  scrsz = get(0,'ScreenSize');
    281                                  figure('Position',[10 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3])
    282                          end
    283                          plotmodel(md,'data',direction,'title','Orthogonal direction','figure',2);drawnow;
    284                  end
    285 
    286 
    287        % normalize direction to 10^4, so that when variations on drag are computed
    288        %they will be significant.
    289        if abs(max(direction))>abs(min(direction))
    290           direction=10^4*direction/abs(max(direction));
    291        else
    292           direction=10^4*direction/abs(min(direction));
    293        end
    294 
    295        %during optimization, bounds on drag variations can vary. Here, they are less
    296        %strict in the first iteration.
    297        if niteration<=2,
    298           upperbound=2;
    299           lowerbound=-2;
    300        else
    301           upperbound=1;
    302           lowerbound=-1;
    303        end
    304 
    305        %search the multiplicative constant to the direction, that will
    306        %be used to modify drag.
    307 
    308        search_constant=fminbnd('objectivefunction_C_drag',lowerbound,upperbound, ...
    309           options,B,glen_coeff,drag_coeff,direction,Rhs,S,F,P,specified_velocity,nods,nel,vx_obs, ...
    310           vy_obs,u_objective, v_objective, index,alpha, beta, area,weighting,rowD,colD,rowDshort,colDshort,valueuu,valuevv,valueuv,matrix_bar,criterion);
    311 
    312 
    313         %update value of drag
    314         drag_coeff_old=drag_coeff;
    315         drag_coeff_new=drag_coeff+search_constant*direction;
    316         drag_coeff=drag_coeff_new;
    317    
    318         if length(find(drag_coeff<0))~=0,
    319             disp(sprintf('\n      Some basal drag coefficient negative => STOP'))
    320             break
    321         end
    322 
    323        %Average drag over elements:
    324        if niteration==1
    325            scrsz = get(0,'ScreenSize');
    326            figure('Position',[scrsz(3)*1.97/3 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3])
    327        end
    328        drag_coeff_bar=(drag_coeff(index(:,1))+drag_coeff(index(:,2))+drag_coeff(index(:,3)))/3;
    329 
    330        %visualize new distribution.
    331                  if md.plot==1,
    332                          plotmodel(md,'data',drag_coeff,'title',['Drag at iteration ' num2str(niteration)],'caxis',[0 1000],'colorbar','on','figure',3);drawnow;
    333                  end
    334 
    335        %evaluate new misfit.
    336        %@@@AK load F_file   %this file was created in objectivefunction_C, and is reloaded
     273                  %Orthogonalize direction
     274                  direction=real(direction);
     275                  direction=direction/sqrt(direction'*direction);
     276                  pos=find(nodes_on_iceshelf);
     277                  direction(pos)=0;
     278
     279
     280                  % rough orthagonalization
     281                  direction=direction-(direction'*old_direction)*old_direction;
     282                  old_direction=direction;
     283
     284                  %visualize direction
     285                  if md.plot==1,
     286                          if niteration==1
     287                                  scrsz = get(0,'ScreenSize');
     288                                  figure('Position',[10 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3])
     289                          end
     290                          plotmodel(md,'data',direction,'title','Orthogonal direction','figure',2);drawnow;
     291                  end
     292
     293
     294                  % normalize direction to 50, so that when variations on drag are computed
     295                  %they will be significant.
     296                  direction=50*direction/max(abs(direction));
     297
     298                  %during optimization, bounds on drag variations can vary. Here, they are less
     299                  %strict in the first iteration.
     300                  if niteration<=2,
     301                          upperbound=2;
     302                          lowerbound=0;
     303                  else
     304                          upperbound=1;
     305                          lowerbound=0;
     306                  end
     307
     308                  %search the multiplicative constant to the direction, that will
     309                  %be used to modify drag.
     310
     311                  search_constant=fminbnd('objectivefunction_C_drag',lowerbound,upperbound, ...
     312                          options,B,glen_coeff,drag_coeff,direction,Rhs,S,F,P,specified_velocity,nods,nel,vx_obs, ...
     313                          vy_obs,u_objective, v_objective, index,alpha, beta, area,weighting,rowD,colD,rowDshort,colDshort,valueuu,valuevv,valueuv,matrix_bar,criterion);
     314
     315                  %update value of drag
     316                  drag_coeff_old=drag_coeff;
     317                  drag_coeff_new=drag_coeff+search_constant*direction;
     318                  drag_coeff=drag_coeff_new;
     319
     320                  if length(find(drag_coeff<0))~=0,
     321                          disp(sprintf('\n      Some basal drag coefficient negative => STOP'))
     322                          break
     323                  end
     324
     325                  %Average drag over elements:
     326                  if niteration==1
     327                          scrsz = get(0,'ScreenSize');
     328                          figure('Position',[scrsz(3)*1.97/3 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3])
     329                  end
     330                  drag_coeff_bar=(drag_coeff(index(:,1))+drag_coeff(index(:,2))+drag_coeff(index(:,3)))/3;
     331
     332                  %visualize new distribution.
     333                  if md.plot==1,
     334                          plotmodel(md,'data',drag_coeff,'title',['Drag at iteration ' num2str(niteration)],'caxis',[0 1000],'colorbar','on','figure',3);drawnow;
     335                  end
     336
     337                  %evaluate new misfit.
     338                  %@@@AK load F_file   %this file was created in objectivefunction_C, and is reloaded
    337339       %here to win some computation time.
    338340       load F_file
  • issm/trunk/src/m/solutions/macayeal/grad_J_flow.m

    r1 r408  
    5656           (  2*beta(:,k).*v(index(:,k))  +  alpha(:,k).*u(index(:,k))  ).*2.*  beta(:,l).*adjointv(index(:,l))...
    5757           );
    58        
    5958
    6059      end
Note: See TracChangeset for help on using the changeset viewer.