source:
issm/oecreview/Archive/18296-19100/ISSM-18532-18533.diff@
19102
Last change on this file since 19102 was 19102, checked in by , 10 years ago | |
---|---|
File size: 28.0 KB |
-
TabularUnified ../trunk-jpl/test/NightlyRun/test4001.m
1 %ISSM/MITgcm coupled set-up 2 % 3 %Script control parameters 4 steps=1:15; 5 final_time=1; 6 7 %Organizer 8 mkdir Models 9 org=organizer('repository','Models/','prefix','IceOcean.2013#','steps',steps); 10 11 presentdirectory=pwd; 12 addpath([pwd '/../MITgcm/tools']); 13 14 % {{{ Parameters: 15 if perform(org,'Parameters'), 16 Nx=20; %number of longitude cells 17 Ny=40; %number of latitude cells 18 Nz=30; %number of MITgcm vertical cells 19 nPx=2; %number of MITgcm processes to use in x direction 20 nPy=4; %number of MITgcm processes to use in y direction 21 xgOrigin=0; %origin of longitude 22 ygOrigin=-80; %origin of latitude 23 dLong=.25; %longitude grid spacing 24 dLat=.05; %latitude grid spacing 25 delZ=30; %thickness of vertical levels 26 icefront_position_ratio=.75; 27 ice_thickness=100; 28 rho_ice=917; 29 rho_water=1028.14; 30 di=rho_ice/rho_water; 31 32 % MITgcm initial and lateral boundary conditions 33 iniSalt = 34.4; % initial salinity (PSU) 34 iniTheta = -1.9; % initial potential temperature (deg C) 35 obcSalt = 34.4; % open boundary salinity (PSU) 36 obcTheta = 1.0; % open boundary potential temperature (deg C) 37 mlDepth = 120.; % mixed layer depth (m) 38 mlSalt = 33.4; % open boundary salinity (PSU) 39 mlTheta = -1.9; % open boundary potential temperature (deg C) 40 obcUvel = -0.1; % open boundary velocity (m/s) 41 42 MITgcmDeltaT=600; % MITgcm time step in seconds 43 y2s=31536000; % year to seconds conversion, i.e., seconds per year 44 45 % start_time, final_time, and time_step 46 start_time=0; % in decimal years 47 time_step=1/12; % coupling interval in decimal years 48 async_step_MITgcm_multiplier=1/30; % used to reduce run time for MItgcm 49 50 % bedrock/bathymetry 51 hmax=1000; 52 trough_depth=200; 53 deltah=300; 54 sea_level=1095; 55 56 % issm settings: 57 higherorder=0; 58 numlayers=10; 59 60 savedata(org, Nx, Ny, nPx, nPy, Nz, dLong, dLat, delZ, xgOrigin, ... 61 ygOrigin, icefront_position_ratio, ice_thickness, rho_ice, ... 62 rho_water, di, hmax, trough_depth, deltah, sea_level, ... 63 iniSalt, iniTheta, obcSalt, obcTheta, mlDepth, mlSalt, ... 64 mlTheta, obcUvel, start_time, time_step, MITgcmDeltaT, y2s,... 65 higherorder,numlayers,async_step_MITgcm_multiplier); 66 end 67 % }}} 68 % {{{ Bathymetry: 69 if perform(org,'Bathymetry'), 70 71 loaddata(org,'Parameters'); 72 %create lat,long 73 lat=(ygOrigin+dLat/2):dLat:(ygOrigin+Ny*dLat); 74 long=(xgOrigin+dLong/2):dLong:(xgOrigin+Nx*dLong); 75 [lat long]=meshgrid(lat,long); 76 77 longmin=min(long(:)); 78 longmax=max(long(:)); 79 latmin=min(lat(:)); 80 latmax=max(lat(:)); 81 82 %create bedrock/bathymetry: 83 bedrock=zeros(Nx,Ny); 84 bedrock=hmax-deltah*tanh(pi*(2*(lat-latmin)./(latmax-latmin)-1))+ ... 85 trough_depth*cos(2*pi*long./(longmax-longmin)); 86 87 %save bathymetry file for MITgcm 88 bathymetry=bedrock-sea_level; 89 savedata(org,lat,long,bathymetry); 90 91 end 92 % }}} 93 % {{{ IceSheetGeometry: 94 if perform(org,'IceSheetGeometry'), 95 96 loaddata(org,'Parameters'); 97 loaddata(org,'Bathymetry'); 98 latmin=min(lat(:)); 99 latmax=max(lat(:)); 100 101 %put ice_thickness constant layer of ice over the bathymetry, unless it floats: 102 s=size(bathymetry); 103 thickness=ice_thickness*ones(s); 104 105 %figure out ice shelf: 106 pos=find(-di*thickness>bathymetry); 107 iceshelf_mask=zeros(s); 108 iceshelf_mask(pos)=1; 109 110 ice_mask=ones(s); 111 pos=find((lat-latmin)/(latmax-latmin)>(icefront_position_ratio)); 112 ice_mask(pos)=0; 113 iceshelf_mask(pos)=0; 114 115 %compute draft of ice shelf: 116 draft=bathymetry; 117 pos=find(iceshelf_mask); 118 draft(pos)=-di*thickness(pos); 119 pos=find(~ice_mask); 120 draft(pos)=0; 121 122 savedata(org,ice_mask,iceshelf_mask,draft,thickness); 123 end 124 % }}} 125 126 %Configure MITgcm 127 % {{{ GetMITgcm: 128 if perform(org,'GetMITgcm'), 129 %system([pwd '/../MITgcm/get_mitgcm.sh']); 130 end 131 % }}} 132 % {{{ BuildMITgcm: 133 if perform(org,'BuildMITgcm'), 134 135 %load data: 136 loaddata(org,'Parameters'); 137 138 %specify computational grid in SIZE.h 139 fidi=fopen('../MITgcm/code/SIZE.h.bak','r'); 140 fido=fopen('../MITgcm/code/SIZE.h','w'); 141 tline = fgetl(fidi); 142 fprintf(fido,'%s\n',tline); 143 while 1 144 tline = fgetl(fidi); 145 if ~ischar(tline), break, end 146 %do the change here: 147 if strcmpi(tline,' & sNx = 20,'), 148 fprintf(fido,'%s%i%s\n',' & sNx = ',round(Nx/nPx),','); 149 continue; 150 end 151 if strcmpi(tline,' & sNy = 20,'), 152 fprintf(fido,'%s%i%s\n',' & sNy = ',round(Ny/nPy),','); 153 continue; 154 end 155 if strcmpi(tline,' & nPx = 1,'), 156 fprintf(fido,'%s%i%s\n',' & nPx = ',nPx,','); 157 continue; 158 end 159 if strcmpi(tline,' & nPy = 2,'), 160 fprintf(fido,'%s%i%s\n',' & nPy = ',nPy,','); 161 continue; 162 end 163 fprintf(fido,'%s\n',tline); 164 end 165 %close files 166 fclose(fidi); 167 fclose(fido); 168 169 system('./build_mitgcm.sh generic'); 170 end 171 % }}} 172 % {{{ RunUncoupledMITgcm: 173 if perform(org,'RunUncoupledMITgcm'), 174 175 %load data: 176 loaddata(org,'Parameters'); 177 loaddata(org,'Bathymetry'); 178 loaddata(org,'IceSheetGeometry'); 179 endtime = round(MITgcmDeltaT * ... 180 floor(time_step*y2s*async_step_MITgcm_multiplier/MITgcmDeltaT)); 181 182 % {{{ prepare MITgcm 183 % rename previous run directory and create new one 184 if exist ('run.old') 185 !\rm -rf run.old 186 end 187 if exist ('run') 188 !\mv run run.old 189 end 190 !\mkdir run 191 !\cp ../MITgcm/build/mitgcmuv run 192 !\cp ../MITgcm/input/* run 193 194 %load data: 195 loaddata(org,'Parameters'); 196 197 % initial salinity 198 S=iniSalt*ones(Nx,Ny,Nz); 199 writebin('run/Salt.bin',S); 200 201 % initial temperature 202 T=iniTheta*ones(Nx,Ny,Nz); 203 writebin('run/Theta.bin',T); 204 205 % initial velocity 206 Z=zeros(Nx,Ny,Nz); 207 writebin('run/Uvel.bin',Z); 208 writebin('run/Vvel.bin',Z); 209 210 % initial sea surface height 211 Z=zeros(Nx,Ny); 212 writebin('run/Etan.bin',Z); 213 214 % salinity boundary conditions 215 S=obcSalt*ones(Ny,Nz); 216 thk=delZ*ones(Nz,1); 217 bot=cumsum(thk); 218 ik=find(bot<=mlDepth); 219 S(:,ik)=mlSalt; 220 writebin('run/OBs.bin',S); 221 222 % temperature boundary conditions 223 T=obcTheta*ones(Ny,Nz); 224 T(:,ik)=mlTheta; 225 writebin('run/OBt.bin',T); 226 227 % zonal velocity boundary conditions 228 U=obcUvel*ones(Ny,Nz); 229 writebin('run/OBu.bin',U); 230 231 % zero boundary conditions 232 Z=zeros(Ny,Nz); 233 writebin('run/zeros.bin',Z); 234 235 % build parameter file data.obcs 236 fidi=fopen('../MITgcm/input/data.obcs','r'); 237 fido=fopen('run/data.obcs','w'); 238 tline = fgetl(fidi); 239 fprintf(fido,'%s\n',tline); 240 while 1 241 tline = fgetl(fidi); 242 if ~ischar(tline), break, end 243 %do the change here: 244 if strcmpi(tline,' OB_Iwest = 40*1,'), 245 fprintf(fido,'%s%i%s\n',' OB_Iwest = ',Ny,'*1,'); 246 continue; 247 end 248 if strcmpi(tline,' OB_Ieast = 40*-1,'), 249 fprintf(fido,'%s%i%s\n',' OB_Ieast = ',Ny,'*-1,'); 250 continue; 251 end 252 fprintf(fido,'%s\n',tline); 253 end 254 %close files 255 fclose(fidi); 256 fclose(fido); 257 258 %save bathymetry and bedrock in run directory 259 writebin('run/bathymetry.bin',bathymetry); 260 writebin('run/icetopo.bin',draft); 261 % }}} 262 263 %start looping: 264 for t=start_time:time_step:final_time, 265 disp(['Year: ' num2str(t)]) 266 % {{{ generate MITgcm parameter file data 267 fidi=fopen('../MITgcm/input/data','r'); 268 fido=fopen('run/data','w'); 269 tline = fgetl(fidi); 270 fprintf(fido,'%s\n',tline); 271 while 1 272 tline = fgetl(fidi); 273 if ~ischar(tline), break, end 274 %do the change here: 275 if strcmpi(tline,' xgOrigin = 0.0,'), 276 fprintf(fido,'%s%i%s\n',' xgOrigin = ',xgOrigin,','); 277 continue; 278 end 279 if strcmpi(tline,' ygOrigin = -80.0,'), 280 fprintf(fido,'%s%i%s\n',' ygOrigin = ',ygOrigin,','); 281 continue; 282 end 283 if strcmpi(tline,' delX = 20*0.25,'), 284 fprintf(fido,'%s%i*%g%s\n',' delX = ',Nx,dLong,','); 285 continue; 286 end 287 if strcmpi(tline,' delY = 20*0.25,'), 288 fprintf(fido,'%s%i*%g%s\n',' delY = ',Ny,dLat,','); 289 continue; 290 end 291 if strcmpi(tline,' delZ = 30*30.0,'), 292 fprintf(fido,'%s%i*%g%s\n',' delZ = ',Nz,delZ,','); 293 continue; 294 end 295 if strcmpi(tline,' endTime=2592000.,'), 296 fprintf(fido,'%s%i%s\n',' endTime= ',endtime,','); 297 continue; 298 end 299 if strcmpi(tline,' deltaT=1200.0,'), 300 fprintf(fido,'%s%i%s\n',' deltaT= ',MITgcmDeltaT,','); 301 continue; 302 end 303 if strcmpi(tline,' pChkptFreq=2592000.,'), 304 fprintf(fido,'%s%i%s\n',' pChkptFreq= ',endtime,','); 305 continue; 306 end 307 if strcmpi(tline,' taveFreq=2592000.,'), 308 fprintf(fido,'%s%i%s\n',' taveFreq= ',endtime,','); 309 continue; 310 end 311 if strcmpi(tline,' rhoConst=1030.,'), 312 fprintf(fido,'%s%i%s\n',' rhoConst= ',rho_water,','); 313 continue; 314 end 315 if strcmpi(tline,' rhoNil=1030.,'), 316 fprintf(fido,'%s%i%s\n',' rhoNil= ',rho_water,','); 317 continue; 318 end 319 fprintf(fido,'%s\n',tline); 320 end 321 %close files 322 fclose(fidi); 323 fclose(fido); 324 % }}} 325 % {{{ generate initial MITgcm conditions 326 327 ds=round(endtime/MITgcmDeltaT); 328 if t>start_time 329 % Read pickup file 330 fnm=['run/pickup.' myint2str(ds,10) '.data']; 331 U=readbin(fnm,[Nx Ny Nz],1,'real*8',0); 332 V=readbin(fnm,[Nx Ny Nz],1,'real*8',1); 333 T=readbin(fnm,[Nx Ny Nz],1,'real*8',2); 334 S=readbin(fnm,[Nx Ny Nz],1,'real*8',3); 335 E=readbin(fnm,[Nx Ny],1,'real*8',8*Nz); 336 writebin('run/Salt.bin' ,S); 337 writebin('run/Theta.bin',T); 338 writebin('run/Uvel.bin' ,U); 339 writebin('run/Vvel.bin' ,V); 340 writebin('run/Etan.bin' ,E); 341 end 342 343 % }}} 344 % {{{ system call to run MITgcm 345 cd run 346 eval(['!mpirun -np ' int2str(nPx*nPy) ' ./mitgcmuv']); 347 ts=round((t+time_step)*y2s/MITgcmDeltaT); 348 eval(['!\mv STDERR.0000 STDERR_' myint2str(ts,10) '.data']) 349 eval(['!\mv STDOUT.0000 STDOUT_' myint2str(ts,10) '.data']) 350 eval(['!\cp hFacC.data hFacC_' myint2str(ts,10) '.data']) 351 eval(['!\cp icetopo.bin icetopo_' myint2str(ts,10) '.data']) 352 for fld={'S','T','U','V','Eta', ... 353 'SHICE_heatFluxtave','SHICE_fwFluxtave'} 354 eval(['!\mv ' fld{1} '.' myint2str(ds,10) '.data ' ... 355 fld{1} '_' myint2str(ts,10) '.data']) 356 end 357 cd .. 358 % }}} 359 end 360 end 361 % }}} 362 363 %Configure ISSM 364 % {{{ CreateMesh: 365 if perform(org,'CreateMesh'), 366 367 loaddata(org,'Parameters'); 368 loaddata(org,'Bathymetry'); 369 loaddata(org,'IceSheetGeometry'); 370 371 %create model: 372 md=model(); 373 374 %Grab lat,long from MITgcm: 375 lat=lat(:); 376 long=long(:); 377 378 %project lat,long: 379 [x,y]=ll2xy(lat,long,-1); 380 381 index=[]; 382 383 % C D 384 % A B 385 for j=1:Ny-1, 386 for i=1:Nx-1, 387 A=(j-1)*Nx+i; 388 B=(j-1)*Nx+i+1; 389 C=j*Nx+i; 390 D=j*Nx+i+1; 391 index(end+1,:)=[A B C]; 392 index(end+1,:)=[C B D]; 393 end 394 end 395 396 %fill mesh and model: 397 md=meshconvert(md,index,x,y); 398 md.mesh.lat=lat; 399 md.mesh.long=long; 400 401 savemodel(org,md); 402 403 end 404 % }}} 405 % {{{ MeshGeometry: 406 if perform(org,'MeshGeometry'), 407 408 loaddata(org,'Parameters'); 409 loaddata(org,'CreateMesh'); 410 loaddata(org,'Bathymetry'); 411 loaddata(org,'IceSheetGeometry'); 412 413 %transfer to vertices: 414 bathymetry=bathymetry(:); 415 iceshelf_mask=iceshelf_mask(:); 416 ice_mask=ice_mask(:); 417 thickness=thickness(:); 418 draft=draft(:); 419 420 %start filling some of the fields 421 md.geometry.bed=bathymetry; 422 md.geometry.thickness=thickness; 423 md.geometry.base=md.geometry.bed; 424 pos=find(iceshelf_mask); md.geometry.base(pos)=draft(pos); 425 md.geometry.surface=md.geometry.base+md.geometry.thickness; 426 427 %nothing passes icefront: 428 pos=find(~ice_mask); 429 md.geometry.thickness(pos)=1; 430 md.geometry.surface(pos)=(1-di)*md.geometry.thickness(pos); 431 md.geometry.base(pos)=-di*md.geometry.thickness(pos); 432 433 %level sets: 434 md.mask.groundedice_levelset=-ones(md.mesh.numberofvertices,1); 435 md.mask.ice_levelset=ones(md.mesh.numberofvertices,1); 436 437 pos=find(ice_mask); md.mask.ice_levelset(pos)=-1; 438 pos=find(~iceshelf_mask & ice_mask); md.mask.groundedice_levelset(pos)=1; 439 440 %identify edges of grounded ice: 441 groundedice_levelset=md.mask.groundedice_levelset; 442 for i=1:md.mesh.numberofelements, 443 m=groundedice_levelset(md.mesh.elements(i,:)); 444 if abs(sum(m))~=3, 445 pos=find(m==1); md.mask.groundedice_levelset(md.mesh.elements(i,pos))=0; 446 end 447 end 448 449 %identify edges of ice: 450 ice_levelset=md.mask.ice_levelset; 451 for i=1:md.mesh.numberofelements, 452 m=ice_levelset(md.mesh.elements(i,:)); 453 if abs(sum(m))~=3, 454 pos=find(m==-1); md.mask.ice_levelset(md.mesh.elements(i,pos))=0; 455 end 456 end 457 458 savemodel(org,md); 459 end 460 % }}} 461 % {{{ ParameterizeIce: 462 if perform(org,'ParameterizeIce'), 463 464 loaddata(org,'Parameters'); 465 loaddata(org,'CreateMesh'); 466 loaddata(org,'MeshGeometry'); 467 468 %miscellaneous 469 md.miscellaneous.name='IceOcean'; 470 471 %initial velocity: 472 md.initialization.vx=zeros(md.mesh.numberofvertices,1); 473 md.initialization.vy=zeros(md.mesh.numberofvertices,1); 474 md.initialization.vz=zeros(md.mesh.numberofvertices,1); 475 476 %friction: 477 md.friction.coefficient=30*ones(md.mesh.numberofvertices,1); 478 pos=find(md.mask.groundedice_levelset<=0); 479 md.friction.coefficient(pos)=0; 480 481 md.friction.p=ones(md.mesh.numberofelements,1); 482 md.friction.q=ones(md.mesh.numberofelements,1); 483 484 %temperatures and surface mass balance: 485 md.initialization.temperature=(273.15-20)*ones(md.mesh.numberofvertices,1); 486 md.initialization.pressure=md.materials.rho_ice*md.constants.g*(md.geometry.surface-md.geometry.base); 487 md.surfaceforcings.mass_balance = [1*ones(md.mesh.numberofvertices,1); 1]; 488 489 %Flow law 490 md.materials.rheology_B=paterson(md.initialization.temperature); 491 md.materials.rheology_n=3*ones(md.mesh.numberofelements,1); 492 md.damage.D=zeros(md.mesh.numberofvertices,1); 493 md.damage.spcdamage=NaN*ones(md.mesh.numberofvertices,1); 494 495 % {{{ Deal with boundary conditions: we have the level sets right, just a matter of getting 496 497 %the spcs going. 498 md.stressbalance.spcvx=NaN*ones(md.mesh.numberofvertices,1); 499 md.stressbalance.spcvy=NaN*ones(md.mesh.numberofvertices,1); 500 md.stressbalance.spcvz=NaN*ones(md.mesh.numberofvertices,1); 501 md.stressbalance.referential=NaN*ones(md.mesh.numberofvertices,6); 502 md.stressbalance.loadingforce=0*ones(md.mesh.numberofvertices,3); 503 md.masstransport.spcthickness=NaN*ones(md.mesh.numberofvertices,1); 504 505 %deal with water: 506 pos=find(md.mask.ice_levelset>0); 507 md.stressbalance.spcvx(pos)=0; 508 md.stressbalance.spcvy(pos)=0; 509 md.stressbalance.spcvz(pos)=0; 510 md.masstransport.spcthickness(pos)=0; 511 512 %get some flux at the ice divide: 513 pos=find(md.mesh.lat==min(md.mesh.lat)); 514 md.stressbalance.spcvy(pos)=200; 515 516 %deal with boundaries, excluding icefront: 517 vertex_on_boundary=zeros(md.mesh.numberofvertices,1); 518 vertex_on_boundary(md.mesh.segments(:,1:2))=1; 519 pos=find(vertex_on_boundary & md.mask.groundedice_levelset<=0); 520 md.stressbalance.spcvx(pos)=md.initialization.vx(pos); 521 md.stressbalance.spcvy(pos)=md.initialization.vy(pos); 522 md.stressbalance.spcvz(pos)=md.initialization.vz(pos); 523 md.masstransport.spcthickness(pos)=md.geometry.thickness(pos); 524 % }}} 525 526 md.basalforcings.groundedice_melting_rate=zeros(md.mesh.numberofvertices,1); 527 md.basalforcings.floatingice_melting_rate=zeros(md.mesh.numberofvertices,1); 528 md.thermal.spctemperature=[md.initialization.temperature; 1]; %impose observed temperature on surface 529 md.basalforcings.geothermalflux=.064*ones(md.mesh.numberofvertices,1); 530 531 %flow equations: 532 md=setflowequation(md,'SSA','all'); 533 534 savemodel(org,md); 535 end 536 % }}} 537 % {{{ Extrude: 538 if perform(org,'Extrude'), 539 540 loaddata(org,'Parameters'); 541 loaddata(org,'ParameterizeIce'); 542 543 if higherorder, 544 md=extrude(md,numlayers,3); 545 md=setflowequation(md,'HO','all'); 546 547 %water needs to be spc'd: 548 pos=find(md.mask.ice_levelset>0); 549 md.stressbalance.spcvx(pos)=0; 550 md.stressbalance.spcvy(pos)=0; 551 md.stressbalance.spcvz(pos)=0; 552 md.masstransport.spcthickness(pos)=0; 553 end 554 555 savemodel(org,md); 556 end 557 % }}} 558 % {{{ RunUncoupledISSM: 559 if perform(org,'RunUncoupledISSM'), 560 561 loaddata(org,'Parameters'); 562 loaddata(org,'Extrude'); 563 564 %timestepping: 565 md.timestepping.final_time=final_time; 566 md.timestepping.time_step=time_step; 567 md.timestepping.time_adapt=0; 568 md.transient.isgroundingline=1; 569 md.transient.isthermal=0; 570 md.groundingline.migration='SubelementMigration2'; 571 572 md.cluster=generic('name',oshostname(),'np',2); 573 md=solve(md,TransientSolutionEnum); 574 575 savemodel(org,md); 576 end 577 % }}} 578 579 %Run MITgcm/ISSM 580 % {{{ RunCoupledMITgcmISSM: 581 if perform(org,'RunCoupledMITgcmISSM'), 582 583 %load data: 584 loaddata(org,'Parameters'); 585 loaddata(org,'Extrude'); 586 loaddata(org,'Bathymetry'); 587 loaddata(org,'IceSheetGeometry'); 588 endtime = round(MITgcmDeltaT * ... 589 floor(time_step*y2s*async_step_MITgcm_multiplier/MITgcmDeltaT)); 590 591 % {{{ prepare MITgcm 592 % rename previous run directory and create new one 593 if exist ('run.old') 594 !\rm -rf run.old 595 end 596 if exist ('run') 597 !\mv run run.old 598 end 599 !\mkdir run 600 !\cp ../MITgcm/build/mitgcmuv run 601 !\cp ../MITgcm/input/* run 602 603 %load data: 604 loaddata(org,'Parameters'); 605 606 % initial salinity 607 S=iniSalt*ones(Nx,Ny,Nz); 608 writebin('run/Salt.bin',S); 609 610 % initial temperature 611 T=iniTheta*ones(Nx,Ny,Nz); 612 writebin('run/Theta.bin',T); 613 614 % initial velocity 615 Z=zeros(Nx,Ny,Nz); 616 writebin('run/Uvel.bin',Z); 617 writebin('run/Vvel.bin',Z); 618 619 % initial sea surface height 620 Z=zeros(Nx,Ny); 621 writebin('run/Etan.bin',Z); 622 623 % salinity boundary conditions 624 S=obcSalt*ones(Ny,Nz); 625 thk=delZ*ones(Nz,1); 626 bot=cumsum(thk); 627 ik=find(bot<=mlDepth); 628 S(:,ik)=mlSalt; 629 writebin('run/OBs.bin',S); 630 631 % temperature boundary conditions 632 T=obcTheta*ones(Ny,Nz); 633 T(:,ik)=mlTheta; 634 writebin('run/OBt.bin',T); 635 636 % zonal velocity boundary conditions 637 U=obcUvel*ones(Ny,Nz); 638 writebin('run/OBu.bin',U); 639 640 % zero boundary conditions 641 Z=zeros(Ny,Nz); 642 writebin('run/zeros.bin',Z); 643 644 % build parameter file data.obcs 645 fidi=fopen('../MITgcm/input/data.obcs','r'); 646 fido=fopen('run/data.obcs','w'); 647 tline = fgetl(fidi); 648 fprintf(fido,'%s\n',tline); 649 while 1 650 tline = fgetl(fidi); 651 if ~ischar(tline), break, end 652 %do the change here: 653 if strcmpi(tline,' OB_Iwest = 40*1,'), 654 fprintf(fido,'%s%i%s\n',' OB_Iwest = ',Ny,'*1,'); 655 continue; 656 end 657 if strcmpi(tline,' OB_Ieast = 40*-1,'), 658 fprintf(fido,'%s%i%s\n',' OB_Ieast = ',Ny,'*-1,'); 659 continue; 660 end 661 fprintf(fido,'%s\n',tline); 662 end 663 %close files 664 fclose(fidi); 665 fclose(fido); 666 667 %save bathymetry in MITgcm run directory 668 writebin('run/bathymetry.bin',bathymetry); 669 % }}} 670 671 % {{{ ISSM settings: 672 673 setenv('DYLD_LIBRARY_PATH', '/usr/local/gfortran/lib') 674 %timestepping: 675 md.timestepping.start_time=start_time; 676 md.timestepping.final_time=final_time; 677 md.timestepping.time_step=time_step; 678 md.timestepping.time_adapt=0; 679 md.cluster=generic('name',oshostname(),'np',2); 680 md.results.TransientSolution.Base=md.geometry.base; 681 md.transient.isgroundingline=1; 682 md.transient.isthermal=0; 683 md.groundingline.migration='SubelementMigration2'; 684 685 % }}} 686 687 %start looping: 688 results=md.results; 689 690 for t=start_time:time_step:final_time 691 disp(['Year: ' num2str(t)]) 692 693 %send draft from ISSM to MITgcm: 694 draft=md.results.TransientSolution(end).Base; 695 pos=find(md.mask.ice_levelset>0); draft(pos)=0; 696 if md.mesh.dimension==3, 697 %collapse onto bottom layer: 698 draft=project2d(md,draft,1); 699 end 700 if t>start_time 701 old_draft=readbin('run/icetopo.bin',[Nx,Ny]); 702 end 703 writebin('run/icetopo.bin',draft); 704 705 % {{{ generate MITgcm parameter file data 706 fidi=fopen('../MITgcm/input/data','r'); 707 fido=fopen('run/data','w'); 708 tline = fgetl(fidi); 709 fprintf(fido,'%s\n',tline); 710 while 1 711 tline = fgetl(fidi); 712 if ~ischar(tline), break, end 713 %do the change here: 714 if strcmpi(tline,' xgOrigin = 0.0,'), 715 fprintf(fido,'%s%i%s\n',' xgOrigin = ',xgOrigin,','); 716 continue; 717 end 718 if strcmpi(tline,' ygOrigin = -80.0,'), 719 fprintf(fido,'%s%i%s\n',' ygOrigin = ',ygOrigin,','); 720 continue; 721 end 722 if strcmpi(tline,' delX = 20*0.25,'), 723 fprintf(fido,'%s%i*%g%s\n',' delX = ',Nx,dLong,','); 724 continue; 725 end 726 if strcmpi(tline,' delY = 20*0.25,'), 727 fprintf(fido,'%s%i*%g%s\n',' delY = ',Ny,dLat,','); 728 continue; 729 end 730 if strcmpi(tline,' delZ = 30*30.0,'), 731 fprintf(fido,'%s%i*%g%s\n',' delZ = ',Nz,delZ,','); 732 continue; 733 end 734 if strcmpi(tline,' endTime=2592000.,'), 735 fprintf(fido,'%s%i%s\n',' endTime= ',endtime,','); 736 continue; 737 end 738 if strcmpi(tline,' deltaT=1200.0,'), 739 fprintf(fido,'%s%i%s\n',' deltaT= ',MITgcmDeltaT,','); 740 continue; 741 end 742 if strcmpi(tline,' pChkptFreq=2592000.,'), 743 fprintf(fido,'%s%i%s\n',' pChkptFreq= ',endtime,','); 744 continue; 745 end 746 if strcmpi(tline,' taveFreq=2592000.,'), 747 fprintf(fido,'%s%i%s\n',' taveFreq= ',endtime,','); 748 continue; 749 end 750 if strcmpi(tline,' rhoConst=1030.,'), 751 fprintf(fido,'%s%i%s\n',' rhoConst= ',rho_water,','); 752 continue; 753 end 754 if strcmpi(tline,' rhoNil=1030.,'), 755 fprintf(fido,'%s%i%s\n',' rhoNil= ',rho_water,','); 756 continue; 757 end 758 fprintf(fido,'%s\n',tline); 759 end 760 %close files 761 fclose(fidi); 762 fclose(fido); 763 % }}} 764 765 % {{{ generate initial MITgcm conditions 766 ds=round(endtime/MITgcmDeltaT); 767 if t>start_time 768 % Read pickup file 769 fnm=['run/pickup.' myint2str(ds,10) '.data']; 770 U=readbin(fnm,[Nx Ny Nz],1,'real*8',0); 771 V=readbin(fnm,[Nx Ny Nz],1,'real*8',1); 772 T=readbin(fnm,[Nx Ny Nz],1,'real*8',2); 773 S=readbin(fnm,[Nx Ny Nz],1,'real*8',3); 774 E=readbin(fnm,[Nx Ny],1,'real*8',8*Nz); 775 776 % find indices of locations where ice shelf retreated 777 h=readbin('run/hFacC.data',[Nx Ny Nz]); 778 msk=sum(h,3); 779 msk(find(msk))=1; 780 [iw jw]=find(msk); % horizontal indices where there is water 781 tmp=reshape(draft,[Nx,Ny])-old_draft; 782 tmp(find(tmp<0))=0; 783 [im jm]=find(tmp); % horizontal indices where there is melt 784 785 % Extrapolate T/S to locations where ice shelf retreated 786 for i=1:length(im) 787 788 % first try vertical extrapolation 789 in=find(h(im(i),jm(i),:)); 790 if length(in)>0; 791 S(im(i),jm(i),1:min(in) ) = S(im(i),jm(i),min(in)); 792 T(im(i),jm(i),1:min(in) ) = T(im(i),jm(i),min(in)); 793 continue 794 end 795 796 % if not succesful, use closest neighbor horizontal extrapolation 797 [y c]=min((iw-im(i)).^2+(jw-jm(i)).^2); 798 salt=squeeze(S(iw(c),jw(c),:)); % salinity profile of closest neighbor 799 temp=squeeze(T(iw(c),jw(c),:)); % salinity profile of closest neighbor 800 in=find(h(iw(c),jw(c),:)); 801 salt(1:min(in))=salt(min(in)); 802 temp(1:min(in))=temp(min(in)); 803 salt(max(in):end)=salt(max(in)); 804 temp(max(in):end)=temp(max(in)); 805 S(im(i),jm(i),:)=salt; 806 T(im(i),jm(i),:)=temp; 807 end 808 809 % Write initial conditions 810 writebin('run/Salt.bin' ,S); 811 writebin('run/Theta.bin',T); 812 writebin('run/Uvel.bin' ,U); 813 writebin('run/Vvel.bin' ,V); 814 writebin('run/Etan.bin' ,E); 815 end 816 % }}} 817 818 % {{{ system call to run MITgcm 819 cd run 820 eval(['!mpirun -np ' int2str(nPx*nPy) ' ./mitgcmuv']); 821 ts=round((t+time_step)*y2s/MITgcmDeltaT); 822 eval(['!\mv STDERR.0000 STDERR_' myint2str(ts,10) '.data']) 823 eval(['!\mv STDOUT.0000 STDOUT_' myint2str(ts,10) '.data']) 824 eval(['!\cp hFacC.data hFacC_' myint2str(ts,10) '.data']) 825 eval(['!\cp icetopo.bin icetopo_' myint2str(ts,10) '.data']) 826 for fld={'S','T','U','V','Eta', ... 827 'SHICE_heatFluxtave','SHICE_fwFluxtave'} 828 eval(['!\mv ' fld{1} '.' myint2str(ds,10) '.data ' ... 829 fld{1} '_' myint2str(ts,10) '.data']) 830 end 831 cd .. 832 % }}} 833 834 %get melting rates from MITgcm 835 %upward fresh water flux (kg/m^2/s): 836 fnm=['run/SHICE_fwFluxtave_' myint2str(ts,10) '.data']; 837 melting_rate=readbin(fnm,[Nx Ny]); 838 839 %send averaged melting rate to ISSM 840 %downward fresh water flux (m/y): 841 melting_rate=-melting_rate(:)*y2s/rho_ice; 842 if md.mesh.dimension==3, 843 md.basalforcings.floatingice_melting_rate=project3d(md,'vector',melting_rate,'type','node'); 844 else 845 md.basalforcings.floatingice_melting_rate=melting_rate; 846 end 847 848 % {{{ run ISSM and recover results 849 850 md.timestepping.start_time=t; 851 md.timestepping.final_time=t+time_step;; 852 md=solve(md,TransientSolutionEnum); 853 854 base=md.results.TransientSolution(end).Base; 855 thickness=md.results.TransientSolution(end).Thickness; 856 if md.mesh.dimension==3, 857 md.mesh.z=base+thickness./md.geometry.thickness.*(md.mesh.z-md.geometry.bed); 858 md.initialization.vz=md.results.TransientSolution(end).Vz; 859 end 860 md.geometry.base=base; 861 md.geometry.thickness=thickness; 862 md.geometry.surface=md.geometry.base+md.geometry.thickness; 863 md.initialization.vx=md.results.TransientSolution(end).Vx; 864 md.initialization.vy=md.results.TransientSolution(end).Vy; 865 md.initialization.vel=md.results.TransientSolution(end).Vel; 866 md.initialization.pressure=md.results.TransientSolution(end).Pressure; 867 md.mask.groundedice_levelset=md.results.TransientSolution(end).MaskGroundediceLevelset; 868 md.results.TransientSolution(end).FloatingiceMeltingRate=md.basalforcings.floatingice_melting_rate; 869 870 %save these results in the model, otherwise, they'll be wiped out 871 results(end+1)=md.results; 872 873 % }}} 874 875 end 876 877 md.results=results; 878 savemodel(org,md); 879 end 880 % }}}
Note:
See TracBrowser
for help on using the repository browser.