forked from NOAA-GFDL/icebergs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicebergs.F90
2802 lines (2473 loc) · 119 KB
/
icebergs.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module ice_bergs
use constants_mod, only: pi, omega, HLF
use fms_mod, only: open_namelist_file, check_nml_error, close_file
use fms_mod, only: field_exist, get_global_att_value
use fms_mod, only: stdlog, stderr, error_mesg, FATAL, WARNING
use fms_mod, only: write_version_number, read_data, write_data, file_exist
use mosaic_mod, only: get_mosaic_ntiles, get_mosaic_ncontacts
use mpp_mod, only: mpp_npes, mpp_pe, mpp_root_pe, mpp_sum, mpp_min, mpp_max, NULL_PE
use mpp_mod, only: mpp_send, mpp_recv, mpp_sync_self, mpp_chksum
use mpp_mod, only: mpp_clock_begin, mpp_clock_end, mpp_clock_id
use mpp_mod, only: CLOCK_COMPONENT, CLOCK_SUBCOMPONENT, CLOCK_LOOP
use mpp_mod, only: mpp_gather
use fms_mod, only: clock_flag_default
use fms_io_mod, only: get_instance_filename
use mpp_domains_mod, only: domain2D, mpp_update_domains, mpp_define_domains
use mpp_parameter_mod, only: CGRID_NE, BGRID_NE, CORNER, AGRID
use mpp_domains_mod, only: mpp_get_compute_domain, mpp_get_data_domain
use mpp_domains_mod, only: mpp_get_neighbor_pe, NORTH, SOUTH, EAST, WEST
use time_manager_mod, only: time_type, get_date, get_time, set_date, operator(-)
use diag_manager_mod, only: register_diag_field, register_static_field, send_data
use diag_manager_mod, only: diag_axis_init
use ice_bergs_framework, only: ice_bergs_framework_init
use ice_bergs_framework, only: icebergs_gridded, xyt, iceberg, icebergs, buffer
use ice_bergs_framework, only: verbose, really_debug,debug,old_bug_rotated_weights,budget,use_roundoff_fix
use ice_bergs_framework, only: find_cell,find_cell_by_search,count_bergs,is_point_in_cell,pos_within_cell
use ice_bergs_framework, only: nclasses,old_bug_bilin
use ice_bergs_framework, only: sum_mass,sum_heat,bilin,yearday,count_bergs,bergs_chksum
use ice_bergs_framework, only: checksum_gridded,add_new_berg_to_list
use ice_bergs_framework, only: send_bergs_to_other_pes,move_trajectory,move_all_trajectories
use ice_bergs_framework, only: record_posn,check_position,print_berg,print_bergs,print_fld
use ice_bergs_framework, only: add_new_berg_to_list,delete_iceberg_from_list,destroy_iceberg
use ice_bergs_framework, only: grd_chksum2,grd_chksum3
use ice_bergs_framework, only: fix_restart_dates, offset_berg_dates
use ice_bergs_framework, only: orig_read ! Remove when backward compatibility no longer needed
use ice_bergs_io, only: ice_bergs_io_init,write_restart,write_trajectory
use ice_bergs_io, only: read_restart_bergs,read_restart_bergs_orig,read_restart_calving
implicit none ; private
public icebergs_init, icebergs_end, icebergs_run, icebergs_stock_pe, icebergs
public icebergs_incr_mass, icebergs_save_restart
real, parameter :: pi_180=pi/180. ! Converts degrees to radians
real, parameter :: rho_ice=916.7 ! Density of fresh ice @ 0oC (kg/m^3)
real, parameter :: rho_water=999.8 ! Density of fresh water @ 0oC (kg/m^3)
real, parameter :: rho_air=1.1 ! Density of air @ 0oC (kg/m^3) ???
real, parameter :: rho_seawater=1025. ! Approx. density of surface sea water @ 0oC (kg/m^3)
real, parameter :: gravity=9.8 ! Gravitational acceleratio (m/s^2)
real, parameter :: Cd_av=1.3 ! (Vertical) Drag coefficient between bergs and atmos (?)
real, parameter :: Cd_ah=0.0055 ! (Horizontal) Drag coefficient between bergs and atmos (?)
real, parameter :: Cd_wv=0.9 ! (Vertical) Drag coefficient between bergs and ocean (?)
real, parameter :: Cd_wh=0.0012 ! (Horizontal) Drag coefficient between bergs and ocean (?)
real, parameter :: Cd_iv=0.9 ! (Vertical) Drag coefficient between bergs and sea-ice (?)
!TOM> no horizontal drag for sea ice! real, parameter :: Cd_ih=0.0012 ! (Horizontal) Drag coefficient between bergs and sea-ice (?)
#ifdef _FILE_VERSION
character(len=128) :: version = _FILE_VERSION
#else
character(len=128) :: version = 'unknown'
#endif
contains
! ##############################################################################
subroutine icebergs_init(bergs, &
gni, gnj, layout, io_layout, axes, dom_x_flags, dom_y_flags, &
dt, Time, ice_lon, ice_lat, ice_wet, ice_dx, ice_dy, ice_area, &
cos_rot, sin_rot, ocean_depth, maskmap, fractional_area)
! Arguments
type(icebergs), pointer :: bergs
integer, intent(in) :: gni, gnj, layout(2), io_layout(2), axes(2)
integer, intent(in) :: dom_x_flags, dom_y_flags
real, intent(in) :: dt
type (time_type), intent(in) :: Time ! current time
real, dimension(:,:), intent(in) :: ice_lon, ice_lat, ice_wet
real, dimension(:,:), intent(in) :: ice_dx, ice_dy, ice_area
real, dimension(:,:), intent(in) :: cos_rot, sin_rot
real, dimension(:,:), intent(in), optional :: ocean_depth
logical, intent(in), optional :: maskmap(:,:)
logical, intent(in), optional :: fractional_area
integer :: stdlogunit, stderrunit
! Get the stderr and stdlog unit numbers
stderrunit=stderr()
stdlogunit=stdlog()
write(stdlogunit,*) "ice_bergs: "//trim(version)
call ice_bergs_framework_init(bergs, &
gni, gnj, layout, io_layout, axes, dom_x_flags, dom_y_flags, &
dt, Time, ice_lon, ice_lat, ice_wet, ice_dx, ice_dy, ice_area, &
cos_rot, sin_rot, ocean_depth=ocean_depth, maskmap=maskmap, fractional_area=fractional_area)
call mpp_clock_begin(bergs%clock_ior)
call ice_bergs_io_init(bergs,io_layout)
if(orig_read) then
call read_restart_bergs_orig(bergs,Time)
else
call read_restart_bergs(bergs,Time)
endif
call bergs_chksum(bergs, 'read_restart bergs')
if (fix_restart_dates) call offset_berg_dates(bergs,Time)
call read_restart_calving(bergs)
call mpp_clock_end(bergs%clock_ior)
if (really_debug) call print_bergs(stderrunit,bergs,'icebergs_init, initial status')
end subroutine icebergs_init
! ##############################################################################
subroutine interactive_force(bergs,berg,IA_x, IA_y, u0, v0, u1, v1, P_ia_11, P_ia_12, P_ia_21, P_ia_22, P_ia_times_u_x, P_ia_times_u_y) !Calculating interactive force between icebergs. Alon, Markpoint_4
type(icebergs), pointer :: bergs
type(iceberg), pointer :: berg
type(iceberg), pointer :: other_berg
real :: T1, L1, W1, lon1, lat1, x1, y1, R1, A1 !Current iceberg
real :: T2, L2, W2, lon2, lat2, x2, y2, R2, A2 !Other iceberg
real :: r_dist_x, r_dist_y, r_dist, A_o, trapped, T_min
real, intent(in) :: u0,v0, u1, v1
real :: P_11, P_12, P_21, P_22
real :: u2, v2
real :: Rearth
logical :: critical_interaction_damping_on
real :: spring_coef, accel_spring, radial_damping_coef, p_ia_coef, tangental_damping_coef
real, intent(out) :: IA_x, IA_y
real, intent(out) :: P_ia_11, P_ia_12, P_ia_22, P_ia_21, P_ia_times_u_x, P_ia_times_u_y
integer :: stderrunit
Rearth=6360.e3
!spring_coef=1.e-4
spring_coef=bergs%spring_coef
radial_damping_coef=bergs%radial_damping_coef
tangental_damping_coef=bergs%tangental_damping_coef
critical_interaction_damping_on=bergs%critical_interaction_damping_on
!Using critical values for damping rather than manually setting the damping.
if (critical_interaction_damping_on) then
radial_damping_coef=2.*sqrt(spring_coef) ! Critical damping
tangental_damping_coef=(2.*sqrt(spring_coef)/5) ! Critical damping /5 (just a guess)
endif
! Get the stderr unit number. Not sure what this does
stderrunit = stderr()
IA_x=0.
IA_y=0.
P_ia_11=0. ; P_ia_12=0. ; P_ia_21=0.; P_ia_22=0.
P_ia_times_u_x=0. ; P_ia_times_u_y=0.
L1=berg%length
W1=berg%width
T1=berg%thickness
A1=L1*W1
R1=sqrt(A1/pi) ! Interaction radius of the iceberg (assuming circular icebergs)
lon1=berg%lon; lat1=berg%lat
call rotpos_to_tang(lon1,lat1,x1,y1)
other_berg=>bergs%first
!Note: This summing should be made order invarient.
!Note: Need to limit how many icebergs we search over
do while (associated(other_berg)) ! loop over all other bergs
L2=other_berg%length
W2=other_berg%width
T2=other_berg%thickness
u2=other_berg%uvel_old !Old values are used to make it order invariant
v2=other_berg%vvel_old !Old values are used to make it order invariant
A2=L2*W2
R2=sqrt(A2/pi) ! Interaction radius of the other iceberg
lon2=berg%lon_old; lat2=berg%lat_old !Old values are used to make it order invariant
call rotpos_to_tang(lon2,lat2,x2,y2)
r_dist_x=x1-x2 ; r_dist_y=y1-y2
r_dist=sqrt( ((x1-x2)**2) + ((y1-y2)**2) )
call overlap_area(R1,R2,r_dist,A_o,trapped)
T_min=min(T1,T2)
!Calculating spring force (later this should only be done on the first time around)
accel_spring=spring_coef*(T_min/T1)*(A_o/A1)
if ((r_dist>0.) .AND. (r_dist< (R1+R2)) ) then
IA_x=IA_x+(accel_spring*(r_dist_x/r_dist))
IA_y=IA_y+(accel_spring*(r_dist_y/r_dist))
!Working out the damping
!Paralel velocity
P_11=(r_dist_x*r_dist_x)/(r_dist**2)
P_12=(r_dist_x*r_dist_y)/(r_dist**2)
P_21=(r_dist_x*r_dist_y)/(r_dist**2)
P_22=(r_dist_y*r_dist_y)/(r_dist**2)
p_ia_coef=radial_damping_coef*(T_min/T1)*(A_o/A1)
p_ia_coef=p_ia_coef*(0.5*(sqrt((((P_11*(u2-u1))+(P_12*(v2-v1)))**2)+ (((P_12*(u2-u1))+(P_22*(v2-v1)))**2))+sqrt((((P_11*(u2-u0))+(P_12*(v2-v0)))**2)+(((P_12*(u2-u0)) +(P_22*(v2-v0)))**2))))
P_ia_11=P_ia_11+p_ia_coef*P_11
P_ia_12=P_ia_12+p_ia_coef*P_12
P_ia_21=P_ia_21+p_ia_coef*P_21
P_ia_22=P_ia_22+p_ia_coef*P_22
P_ia_times_u_x=P_ia_times_u_x+ (p_ia_coef* ((P_11*u2) +(P_12*v2)))
P_ia_times_u_y=P_ia_times_u_y+ (p_ia_coef* ((P_12*u2) +(P_22*v2)))
!Normal velocities
P_11=1-P_11 ; P_12=-P_12 ; P_22=1-P_22
p_ia_coef=tangental_damping_coef*(T_min/T1)*(A_o/A1)
p_ia_coef=p_ia_coef*(0.5*(sqrt((((P_11*(u2-u1))+(P_12*(v2-v1)))**2)+ (((P_12*(u2-u1))+(P_22*(v2-v1)))**2))+sqrt((((P_11*(u2-u0))+(P_12*(v2-v0)))**2)+(((P_12*(u2-u0)) +(P_22*(v2-v0)))**2))))
P_ia_11=P_ia_11+p_ia_coef*P_11
P_ia_12=P_ia_12+p_ia_coef*P_12
P_ia_21=P_ia_21+p_ia_coef*P_21
P_ia_22=P_ia_22+p_ia_coef*P_22
P_ia_times_u_x=P_ia_times_u_x+ (p_ia_coef* ((P_11*u2) +(P_12*v2)))
P_ia_times_u_y=P_ia_times_u_y+ (p_ia_coef* ((P_12*u2) +(P_22*v2)))
!print *, 'P_11',P_11
!print *, 'P_21',P_21
!print *, 'P_12',P_12
!print *, 'P_22',P_22
endif
other_berg=>other_berg%next
enddo ! loop over all bergs
contains
subroutine overlap_area(R1,R2,d,A,trapped)
real, intent(in) :: R1, R2, d
real, intent(out) :: A, Trapped
real :: R1_sq, R2_sq, d_sq
R1_sq=R1**2
R2_sq=R2**2
d_sq=d**2
Trapped=0.
if (d>0.) then
if (d<(R1+R2)) then
if (d>abs(R1-R2)) then
A= (R1_sq*acos((d_sq+R1_sq-R2_sq)/(2.*d*R1))) + (R2_sq*acos((d_sq+R2_sq-R1_sq)/(2.*d*R2))) - (0.5*sqrt((-d+R1+R2)*(d+R1-R2)*(d-R1+R2)*(d+R1+R2)))
else
A=min(pi*R1_sq,pi*R2_sq)
Trapped=1.
endif
else
A=0.
endif
else
A=0. ! No area of perfectly overlapping bergs (ie: a berg interacting with itself)
endif
end subroutine overlap_area
subroutine rotpos_to_tang(lon, lat, x, y)
! Arguments
real, intent(in) :: lon, lat
real, intent(out) :: x, y
! Local variables
real :: r,colat,clon,slon
if (lat>90.) then
write(stderrunit,*) 'diamonds, rotpos_to_tang: lat>90 already!',lat
call error_mesg('diamonds, rotpos_to_tang','Something went very wrong!',FATAL)
endif
if (lat==90.) then
write(stderrunit,*) 'diamonds, rotpos_to_tang: lat==90 already!',lat
call error_mesg('diamonds, rotpos_to_tang','Something went wrong!',FATAL)
endif
colat=90.-lat
r=Rearth*(colat*pi_180)
clon=cos(lon*pi_180)
slon=sin(lon*pi_180)
x=r*clon
y=r*slon
end subroutine rotpos_to_tang
end subroutine interactive_force
! ##############################################################################
subroutine accel(bergs, berg, i, j, xi, yj, lat, uvel, vvel, uvel0, vvel0, dt, ax, ay, axn, ayn, bxn, byn, debug_flag) !Saving acceleration for Verlet, Adding Verlet flag - Alon
!subroutine accel(bergs, berg, i, j, xi, yj, lat, uvel, vvel, uvel0, vvel0, dt, ax, ay, debug_flag) !old version commmented out by Alon
! Arguments
type(icebergs), pointer :: bergs
type(iceberg), pointer :: berg
integer, intent(in) :: i, j
real, intent(in) :: xi, yj, lat, uvel, vvel, uvel0, vvel0, dt
real, intent(inout) :: ax, ay
real, intent(inout) :: axn, ayn, bxn, byn ! Added implicit and explicit accelerations to output -Alon
logical, optional :: debug_flag
! Local variables
type(icebergs_gridded), pointer :: grd
real :: uo, vo, ui, vi, ua, va, uwave, vwave, ssh_x, ssh_y, sst, cn, hi
real :: f_cori, T, D, W, L, M, F
real :: drag_ocn, drag_atm, drag_ice, wave_rad
real :: c_ocn, c_atm, c_ice
real :: ampl, wmod, Cr, Lwavelength, Lcutoff, Ltop
real, parameter :: accel_lim=1.e-2, Cr0=0.06, vel_lim=15.
real :: alpha, beta, C_N
real :: lambda, detA, A11, A12, A21, A22, RHS_x, RHS_y, D_hi
real :: uveln, vveln, us, vs, speed, loc_dx, new_speed
real :: u_star, v_star !Added by Alon
real :: IA_x, IA_y !Added by Alon
real :: P_ia_11, P_ia_12, P_ia_21, P_ia_22, P_ia_times_u_x, P_ia_times_u_y !Added by Alon
logical :: dumpit
logical :: interactive_icebergs_on ! Flag to decide whether to use forces between icebergs.
logical :: Runge_not_Verlet ! Flag to specify whether it is Runge-Kutta or Verlet
logical :: use_new_predictive_corrective !Flad to use Bob's predictive corrective scheme. (default off)
integer :: itloop
integer :: stderrunit
Runge_not_Verlet=bergs%Runge_not_Verlet ! Loading directly from namelist/default , Alon
interactive_icebergs_on=bergs%interactive_icebergs_on ! Loading directly from namelist/default , Alon
use_new_predictive_corrective=bergs%use_new_predictive_corrective ! Loading directly from namelist/default , Alon
!These values are no longer set as parameters, but rather can be changed as variables.
alpha=0.0
beta=1.0
C_N=0.0
!Alon: Verlet requires implicit Coriolis and implicit drag.
!Alon: Also, I think that the implicit Coriolis with RK gives icebergs which do not complete inertial circles.
if (.not.Runge_not_Verlet) then
alpha=1.0
C_N=1.0
beta=1.0
use_new_predictive_corrective=.True.
endif
!print *, 'axn=',axn,'ayn=',ayn
u_star=uvel0+(axn*(dt/2.)) !Alon
v_star=vvel0+(ayn*(dt/2.)) !Alon
! Get the stderr unit number.
stderrunit = stderr()
! For convenience
grd=>bergs%grd
! Interpolate gridded fields to berg - Note: It should be possible to move this to evolve, so that it only needs to be called once. !!!!
call interp_flds(grd, i, j, xi, yj, uo, vo, ui, vi, ua, va, ssh_x, ssh_y, sst, cn, hi)
f_cori=(2.*omega)*sin(pi_180*lat)
! f_cori=0.
M=berg%mass
T=berg%thickness ! total thickness
D=(bergs%rho_bergs/rho_seawater)*T ! draught (keel depth)
F=T-D ! freeboard
W=berg%width
L=berg%length
!Initializing accelerations - Alon. (I am not 100% sure this is needed). I'm not sure what is output if variable is not defined in the subroutine.
axn=0.
ayn=0.
bxn=0.
byn=0.
hi=min(hi,D)
D_hi=max(0.,D-hi)
! Wave radiation
uwave=ua-uo; vwave=va-vo ! Use wind speed rel. to ocean for wave model (aja)?
wmod=uwave*uwave+vwave*vwave ! The wave amplitude and length depend on the wind speed relative to the ocean current;
! actually wmod is wmod**2 here.
ampl=0.5*0.02025*wmod ! This is "a", the wave amplitude
Lwavelength=0.32*wmod ! Surface wave length fitted to data in table at
! http://www4.ncsu.edu/eos/users/c/ceknowle/public/chapter10/part2.html
Lcutoff=0.125*Lwavelength
Ltop=0.25*Lwavelength
Cr=Cr0*min(max(0.,(L-Lcutoff)/((Ltop-Lcutoff)+1.e-30)),1.) ! Wave radiation coefficient
! fitted to graph from Carrieres et al., POAC Drift Model.
wave_rad=0.5*rho_seawater/M*Cr*gravity*ampl*min(ampl,F)*(2.*W*L)/(W+L)
wmod = sqrt(ua*ua+va*va) ! Wind speed
if (wmod.ne.0.) then
uwave=ua/wmod ! Wave radiation force acts in wind direction ...
vwave=va/wmod
else
uwave=0.; vwave=0.; wave_rad=0. ! ... and only when wind is present.
endif
! Weighted drag coefficients
c_ocn=rho_seawater/M*(0.5*Cd_wv*W*(D_hi)+Cd_wh*W*L)
c_atm=rho_air /M*(0.5*Cd_av*W*F +Cd_ah*W*L)
c_ice=rho_ice /M*(0.5*Cd_iv*W*hi )
if (abs(ui)+abs(vi).eq.0.) c_ice=0.
!Turning drag off for testing - Alon
!c_ocn=0.
!c_atm=0.
!c_ice=0.
! Half half accelerations - axn, ayn
if (.not.Runge_not_Verlet) then
axn=-gravity*ssh_x +wave_rad*uwave
ayn=-gravity*ssh_y +wave_rad*vwave
else
! Not half half accelerations - for RK
bxn=-gravity*ssh_x +wave_rad*uwave
byn=-gravity*ssh_y +wave_rad*vwave
endif
! Interactive spring acceleration - (Does the spring part need to be called twice?)
if (interactive_icebergs_on) then
call Interactive_force(bergs, berg, IA_x, IA_y, uvel0, vvel0, uvel0, vvel0, P_ia_11, P_ia_12, P_ia_21, P_ia_22, P_ia_times_u_x, P_ia_times_u_y) ! Spring forces, Made by Alon.
if (.not.Runge_not_Verlet) then
axn=axn + IA_x
ayn=ayn + IA_y
else
bxn=bxn + IA_x
byn=byn + IA_y
endif
!print *,'IA_x=',IA_x
!print *,'IA_x=',IA_x,'IA_y',IA_y
!print *,'P_ia_11',P_ia_11,'P_ia_12',P_ia_12, 'P_ia_21',P_ia_21,'P_ia_22', P_ia_22
!print *, 'P_ia_times_u_x', P_ia_times_u_x, 'P_ia_times_u_y', P_ia_times_u_y
endif
if (alpha>0.) then ! If implicit Coriolis, use u_star rather than RK4 latest !Alon
if (C_N>0.) then ! C_N=1 for Crank Nicolson Coriolis, C_N=0 for full implicit Coriolis !Alon
axn=axn+f_cori*v_star
ayn=ayn-f_cori*u_star
else
bxn=bxn+f_cori*v_star
byn=byn-f_cori*u_star
endif
else
bxn=bxn+f_cori*vvel
byn=byn-f_cori*uvel
endif
if (use_new_predictive_corrective) then
uveln=uvel0; vveln=vvel0 ! Discuss this change with Alistair. Alon thinks that it is needed.
else
uveln=uvel; vveln=vvel
endif
do itloop=1,2 ! Iterate on drag coefficients
if (use_new_predictive_corrective) then
!Alon's proposed change - using Bob's improved scheme.
drag_ocn=c_ocn*0.5*(sqrt( (uveln-uo)**2+(vveln-vo)**2 )+sqrt( (uvel0-uo)**2+(vvel0-vo)**2 ))
drag_atm=c_atm*0.5*(sqrt( (uveln-ua)**2+(vveln-va)**2 )+sqrt( (uvel0-ua)**2+(vvel0-va)**2 ))
drag_ice=c_ice*0.5*(sqrt( (uveln-ui)**2+(vveln-vi)**2 )+sqrt( (uvel0-ui)**2+(vvel0-vi)**2 ))
else
!Original Scheme
us=0.5*(uveln+uvel); vs=0.5*(vveln+vvel)
drag_ocn=c_ocn*sqrt( (us-uo)**2+(vs-vo)**2 )
drag_atm=c_atm*sqrt( (us-ua)**2+(vs-va)**2 )
drag_ice=c_ice*sqrt( (us-ui)**2+(vs-vi)**2 )
endif
RHS_x=(axn/2) + bxn
RHS_y=(ayn/2) + byn
if (beta>0.) then ! If implicit, use u_star, v_star rather than RK4 latest
RHS_x=RHS_x - drag_ocn*(u_star-uo) -drag_atm*(u_star-ua) -drag_ice*(u_star-ui)
RHS_y=RHS_y - drag_ocn*(v_star-vo) -drag_atm*(v_star-va) -drag_ice*(v_star-vi)
else
RHS_x=RHS_x - drag_ocn*(uvel-uo) -drag_atm*(uvel-ua) -drag_ice*(uvel-ui)
RHS_y=RHS_y - drag_ocn*(vvel-vo) -drag_atm*(vvel-va) -drag_ice*(vvel-vi)
endif
if (interactive_icebergs_on) then
if (itloop>1) then
call Interactive_force(bergs, berg, IA_x, IA_y, us, vs, uvel0, vvel0, P_ia_11, P_ia_12, P_ia_21, P_ia_22, P_ia_times_u_x, P_ia_times_u_y) ! Spring forces, Made by Alon.
endif
if (beta>0.) then ! If implicit, use u_star, v_star rather than RK4 latest
RHS_x=RHS_x -(((P_ia_11*u_star)+(P_ia_12*v_star))-P_ia_times_u_x)
RHS_y=RHS_y -(((P_ia_21*u_star)+(P_ia_22*v_star))-P_ia_times_u_y)
else
RHS_x=RHS_x - (((P_ia_11*uvel)+(P_ia_12*vvel))-P_ia_times_u_x)
RHS_y=RHS_y - (((P_ia_21*uvel)+(P_ia_22*vvel))-P_ia_times_u_y)
endif
endif
! Solve for implicit accelerations
if (alpha+beta.gt.0.) then
lambda=drag_ocn+drag_atm+drag_ice
A11=1.+beta*dt*lambda
A22=1.+beta*dt*lambda
A12=-alpha*dt*f_cori
A21=alpha*dt*f_cori
!A12=dt*f_cori !Removed by ALon (in order to have the entire matrix. I hope the sign is correct)
if (C_N>0.) then !For Crank-Nicolson Coriolis term.
A12=A12/2.
A21=A21/2.
endif
if (interactive_icebergs_on) then
A11=A11+P_ia_11
A12=A12+P_ia_12
A21=A21+P_ia_21
A22=A22+P_ia_22
endif
detA=1./((A11*A22)-(A12*A21))
ax=detA*(A22*RHS_x-A12*RHS_y)
ay=detA*(A11*RHS_y-A21*RHS_x)
!Alistair's version removed by Alon
! detA=1./(A11**2+A12**2)
! ax=detA*(A11*RHS_x+A12*RHS_y)
! ay=detA*(A11*RHS_y-A12*RHS_x)
else
ax=RHS_x; ay=RHS_y
endif
uveln=u_star+dt*ax ! Alon
vveln=v_star+dt*ay ! Alon
enddo ! itloop
!Saving the totally explicit part of the acceleration to use in finding the next position and u_star -Alon
axn=0.
ayn=0.
if (.not.Runge_not_Verlet) then
axn=-gravity*ssh_x +wave_rad*uwave + IA_x
ayn=-gravity*ssh_y +wave_rad*vwave + IA_y
endif
if (C_N>0.) then ! C_N=1 for Crank Nicolson Coriolis, C_N=0 for full implicit Coriolis !Alon
axn=axn+f_cori*vveln
ayn=ayn-f_cori*uveln
endif
bxn= ax-(axn/2) !Alon
byn= ay-(ayn/2) !Alon
! Limit speed of bergs based on a CFL criteria
if (bergs%speed_limit>0.) then
speed=sqrt(uveln*uveln+vveln*vveln) ! Speed of berg
if (speed>0.) then
loc_dx=min(0.5*(grd%dx(i,j)+grd%dx(i,j-1)),0.5*(grd%dy(i,j)+grd%dy(i-1,j))) ! min(dx,dy)
!new_speed=min(loc_dx/dt*bergs%speed_limit,speed) ! Restrict speed to dx/dt x factor
new_speed=loc_dx/dt*bergs%speed_limit ! Speed limit as a factor of dx / dt
if (new_speed<speed) then
uveln=uveln*(new_speed/speed) ! Scale velocity to reduce speed
vveln=vveln*(new_speed/speed) ! without changing the direction
bergs%nspeeding_tickets=bergs%nspeeding_tickets+1
endif
endif
endif
dumpit=.false.
if (abs(uveln)>vel_lim.or.abs(vveln)>vel_lim) then
dumpit=.true.
write(stderrunit,'("pe=",i3,x,a)') mpp_pe(),'Dump triggered by excessive velocity'
endif
if (abs(ax)>accel_lim.or.abs(ay)>accel_lim) then
dumpit=.true.
write(stderrunit,'("pe=",i3,x,a)') mpp_pe(),'Dump triggered by excessive acceleration'
endif
if (present(debug_flag)) then
if (debug_flag) dumpit=.true.
write(stderrunit,'("pe=",i3,x,a)') mpp_pe(),'Debug dump flagged by arguments'
endif
if (dumpit) then
100 format('pe=',i3,a15,9(x,a8,es12.3))
200 format('pe=',i3,a15,(x,a8,i12),9(x,a8,es12.3))
write(stderrunit,200) mpp_pe(),'Starting pars:', &
'yr0=',berg%start_year, 'day0=',berg%start_day, &
'lon0=',berg%start_lon, 'lat0=',berg%start_lat, 'mass0=',berg%start_mass, &
'sclng=',berg%mass_scaling
write(stderrunit,100) mpp_pe(),'Geometry:', &
'M=',M, 'T=',T, 'D=',D, 'F=',F, 'W=',W, 'L=',L
write(stderrunit,100) mpp_pe(),'delta U:', &
'u(n)=',uvel0, 'u(*)=', uvel, 'u(n+1)=',uvel+dt*ax, 'del u=',dt*ax
write(stderrunit,100) mpp_pe(),'U terms', &
'f*v=',f_cori*vvel, &
'g*H_x=',-gravity*ssh_x, &
'wave*ua=',wave_rad*uwave, &
'd*(u-uo)=',-drag_ocn*(uvel-uo), &
'd*(u-ua)=',-drag_atm*(uvel-ua), &
'd*(u-ui)=',-drag_ice*(uvel-ui)
write(stderrunit,100) mpp_pe(),'U accel.', &
'RHS_x=',RHS_x, &
'ax=',ax, &
'ax(cori)=',detA*(A11*(f_cori*vvel)+A12*(-f_cori*uvel)), &
'ax(grav)=',detA*(A11*(-gravity*ssh_x)+A12*(-gravity*ssh_y)), &
'ax(wave)=',detA*(A11*(wave_rad*uwave)+A12*(wave_rad*vwave)), &
'ax(ocn)=',detA*(A11*(-drag_ocn*(uvel-uo))+A12*(-drag_ocn*(vvel-vo))), &
'ax(atm)=',detA*(A11*(-drag_atm*(uvel-ua))+A12*(-drag_atm*(vvel-va))), &
'ax(ice)=',detA*(A11*(-drag_ice*(uvel-ui))+A12*(-drag_ice*(vvel-vi)))
write(stderrunit,100) mpp_pe(),'delta V:', &
'v(n)=',vvel0, 'v(*)=', vvel, 'v(n+1)=',vvel+dt*ay, 'del v=',dt*ay
write(stderrunit,100) mpp_pe(),'V terms', &
'f*u=',-f_cori*uvel, &
'g*H_y=',-gravity*ssh_y, &
'wave*va=',wave_rad*vwave, &
'd*(v-vo)=',-drag_ocn*(vvel-vo), &
'd*(v-va)=',-drag_atm*(vvel-va), &
'd*(v-vi)=',-drag_ice*(vvel-vi)
write(stderrunit,100) mpp_pe(),'V accel. pe=', &
'RHS_y=',RHS_y, &
'ay=',ay, &
'ay(cori)=',detA*(-A12*(f_cori*vvel)+A11*(-f_cori*uvel)), &
'ay(grav)=',detA*(-A12*(-gravity*ssh_x)+A11*(-gravity*ssh_y)), &
'ay(wave)=',detA*(-A12*(wave_rad*uwave)+A11*(wave_rad*vwave)), &
'ay(ocn)=',detA*(-A12*(-drag_ocn*(uvel-uo))+A11*(-drag_ocn*(vvel-vo))), &
'ay(atm)=',detA*(-A12*(-drag_atm*(uvel-ua))+A11*(-drag_atm*(vvel-va))), &
'ay(ice)=',detA*(-A12*(-drag_ice*(uvel-ui))+A11*(-drag_ice*(vvel-vi)))
write(stderrunit,100) mpp_pe(),'Vel scales', &
'|va-vo|=',sqrt((ua-uo)**2+(va-vo)**2), &
'|vo-vb|=',sqrt((uvel-uo)**2+(vvel-vo)**2), &
'|va-vb|=',sqrt((uvel-ua)**2+(vvel-va)**2), &
'|vi-vb|=',sqrt((uvel-ui)**2+(vvel-vi)**2), &
'|vb|=',sqrt((uvel)**2+(vvel)**2), &
'|va|=',sqrt((ua)**2+(va)**2), &
'|vo|=',sqrt((uo)**2+(vo)**2), &
'|vi|=',sqrt((ui)**2+(vi)**2)
write(stderrunit,100) mpp_pe(),'Time scales', &
'f=',f_cori, 'wave_rad=',wave_rad, 'do=',drag_ocn, 'da=',drag_atm, 'di=',drag_ice
write(stderrunit,100) mpp_pe(),'u*', &
'd*=',lambda, &
'u*=',(drag_ocn*uo+drag_atm*ua+drag_ice*ui)/lambda, &
'uo*=',(drag_ocn*uo)/lambda, &
'ua*=',(drag_atm*ua)/lambda, &
'ui*=',(drag_ice*ui)/lambda
write(stderrunit,100) mpp_pe(),'v*', &
'd*=',lambda, &
'v*=',(drag_ocn*vo+drag_atm*va+drag_ice*vi)/lambda, &
'vo*=',(drag_ocn*vo)/lambda, &
'va*=',(drag_atm*va)/lambda, &
'vi*=',(drag_ice*vi)/lambda
write(stderrunit,100) mpp_pe(),'params', &
'a=',ampl, 'Lwl=',Lwavelength, 'Lcut=',Lcutoff, 'Ltop=',Ltop, 'hi=',hi, 'Cr=',Cr
write(stderrunit,100) mpp_pe(),'Position', &
'xi=',xi, 'yj=',yj, 'lat=',lat
call dump_locfld(grd,i,j,grd%msk,'MSK')
call dump_locfld(grd,i,j,grd%ssh,'SSH')
call dump_locfld(grd,i,j,grd%sst,'SST')
call dump_locvel(grd,i,j,grd%uo,'Uo')
call dump_locvel(grd,i,j,grd%vo,'Vo')
call dump_locvel(grd,i,j,grd%ua,'Ua')
call dump_locvel(grd,i,j,grd%va,'Va')
call dump_locvel(grd,i,j,grd%ui,'Ui')
call dump_locvel(grd,i,j,grd%vi,'Vi')
call dump_locfld(grd,i,j,grd%hi,'HI')
call dump_locfld(grd,i,j,grd%cn,'CN')
call dump_locvel(grd,i,j,grd%lon,'Lon')
call dump_locvel(grd,i,j,grd%lat,'Lat')
call print_berg(stderrunit,berg,'diamonds, accel, large accel')
endif
contains
subroutine dump_locfld(grd,i0,j0,A,lbl)
! Arguments
type(icebergs_gridded), pointer :: grd
integer, intent(in) :: i0, j0
real, dimension(grd%isd:grd%ied,grd%jsd:grd%jed), intent(in) :: A
character(len=*) :: lbl
! Local variables
integer :: i, j, ii, jj
real :: B(-1:1,-1:1), fac
do jj=-1,1
j=max(grd%jsd,min(grd%jed,jj+j0))
do ii=-1,1
i=max(grd%isd,min(grd%ied,ii+i0))
B(ii,jj)=A(i,j)
if ((i.ne.ii+i0).or.(j.ne.jj+j0)) B(ii,jj)=-9.999999e-99
enddo
enddo
write(stderrunit,'("pe=",i3,x,a8,3i12)') mpp_pe(),lbl,(i0+ii,ii=-1,1)
do jj=1,-1,-1
write(stderrunit,'("pe=",i3,x,i8,3es12.4)') mpp_pe(),j0+jj,(B(ii,jj),ii=-1,1)
enddo
end subroutine dump_locfld
subroutine dump_locvel(grd,i0,j0,A,lbl)
! Arguments
type(icebergs_gridded), pointer :: grd
integer, intent(in) :: i0, j0
real, dimension(grd%isd:grd%ied,grd%jsd:grd%jed), intent(in) :: A
character(len=*) :: lbl
! Local variables
integer :: i, j, ii, jj
real :: B(-1:0,-1:0), fac
do jj=-1,0
j=max(grd%jsd,min(grd%jed,jj+j0))
do ii=-1,0
i=max(grd%isd,min(grd%ied,ii+i0))
B(ii,jj)=A(i,j)
if ((i.ne.ii+i0).or.(j.ne.jj+j0)) B(ii,jj)=-9.999999e-99
enddo
enddo
write(stderrunit,'("pe=",i3,x,a8,3i12)') mpp_pe(),lbl,(i0+ii,ii=-1,0)
do jj=0,-1,-1
write(stderrunit,'("pe=",i3,x,i8,3es12.4)') mpp_pe(),j0+jj,(B(ii,jj),ii=-1,0)
enddo
end subroutine dump_locvel
end subroutine accel
! ##############################################################################
subroutine thermodynamics(bergs)
! Arguments
type(icebergs), pointer :: bergs
! Local variables
type(icebergs_gridded), pointer :: grd
real :: M, T, W, L, SST, Vol, Ln, Wn, Tn, nVol, IC, Dn
real :: Mv, Me, Mb, melt, dvo, dva, dM, Ss, dMe, dMb, dMv
real :: Mnew, Mnew1, Mnew2, Hocean
real :: Mbits, nMbits, dMbitsE, dMbitsM, Lbits, Abits, Mbb
integer :: i,j, stderrunit
type(iceberg), pointer :: this, next
real, parameter :: perday=1./86400.
! For convenience
grd=>bergs%grd
this=>bergs%first
do while(associated(this))
if (debug) call check_position(grd, this, 'thermodynamics (top)')
call interp_flds(grd, this%ine, this%jne, this%xi, this%yj, this%uo, this%vo, &
this%ui, this%vi, this%ua, this%va, this%ssh_x, this%ssh_y, this%sst, &
this%cn, this%hi)
SST=this%sst
IC=min(1.,this%cn+bergs%sicn_shift) ! Shift sea-ice concentration
M=this%mass
T=this%thickness ! total thickness
! D=(bergs%rho_bergs/rho_seawater)*T ! draught (keel depth)
! F=T-D ! freeboard
W=this%width
L=this%length
i=this%ine
j=this%jne
Vol=T*W*L
! Environment
dvo=sqrt((this%uvel-this%uo)**2+(this%vvel-this%vo)**2)
dva=sqrt((this%ua-this%uo)**2+(this%va-this%vo)**2)
Ss=1.5*(dva**0.5)+0.1*dva ! Sea state
! Melt rates in m/s
Mv=max( 7.62e-3*SST+1.29e-3*(SST**2), 0.) &! Buoyant convection at sides
*perday ! convert to m/s
Mb=max( 0.58*(dvo**0.8)*(SST+4.0)/(L**0.2), 0.) &! Basal turbulent melting
*perday ! convert to m/s
Me=max( 1./12.*(SST+2.)*Ss*(1+cos(pi*(IC**3))) ,0.) &! Wave erosion
*perday ! convert to m/s
if (bergs%use_operator_splitting) then
! Operator split update of volume/mass
Tn=max(T-Mb*bergs%dt,0.) ! new total thickness (m)
nVol=Tn*W*L ! new volume (m^3)
Mnew1=(nVol/Vol)*M ! new mass (kg)
dMb=M-Mnew1 ! mass lost to basal melting (>0) (kg)
Ln=max(L-Mv*bergs%dt,0.) ! new length (m)
Wn=max(W-Mv*bergs%dt,0.) ! new width (m)
nVol=Tn*Wn*Ln ! new volume (m^3)
Mnew2=(nVol/Vol)*M ! new mass (kg)
dMv=Mnew1-Mnew2 ! mass lost to buoyant convection (>0) (kg)
Ln=max(Ln-Me*bergs%dt,0.) ! new length (m)
Wn=max(Wn-Me*bergs%dt,0.) ! new width (m)
nVol=Tn*Wn*Ln ! new volume (m^3)
Mnew=(nVol/Vol)*M ! new mass (kg)
dMe=Mnew2-Mnew ! mass lost to erosion (>0) (kg)
dM=M-Mnew ! mass lost to all erosion and melting (>0) (kg)
else
! Update dimensions of berg
Ln=max(L-(Mv+Me)*(bergs%dt),0.) ! (m)
Wn=max(W-(Mv+Me)*(bergs%dt),0.) ! (m)
Tn=max(T-Mb*(bergs%dt),0.) ! (m)
! Update volume and mass of berg
nVol=Tn*Wn*Ln ! (m^3)
Mnew=(nVol/Vol)*M ! (kg)
dM=M-Mnew ! (kg)
dMb=(M/Vol)*(W*L)*Mb*bergs%dt ! approx. mass loss to basal melting (kg)
dMe=(M/Vol)*(T*(W+L))*Me*bergs%dt ! approx. mass lost to erosion (kg)
dMv=(M/Vol)*(T*(W+L))*Mv*bergs%dt ! approx. mass loss to buoyant convection (kg)
endif
! Bergy bits
if (bergs%bergy_bit_erosion_fraction>0.) then
Mbits=this%mass_of_bits ! mass of bergy bits (kg)
dMbitsE=bergs%bergy_bit_erosion_fraction*dMe ! change in mass of bits (kg)
nMbits=Mbits+dMbitsE ! add new bergy bits to mass (kg)
Lbits=min(L,W,T,40.) ! assume bergy bits are smallest dimension or 40 meters
Abits=(Mbits/bergs%rho_bergs)/Lbits ! Effective bottom area (assuming T=Lbits)
Mbb=max( 0.58*(dvo**0.8)*(SST+2.0)/(Lbits**0.2), 0.) &! Basal turbulent melting (for bits)
*perday ! convert to m/s
Mbb=bergs%rho_bergs*Abits*Mbb ! in kg/s
dMbitsM=min(Mbb*bergs%dt,nMbits) ! bergy bits mass lost to melting (kg)
nMbits=nMbits-dMbitsM ! remove mass lost to bergy bits melt
if (Mnew==0.) then ! if parent berg has completely melted then
dMbitsM=dMbitsM+nMbits ! instantly melt all the bergy bits
nMbits=0.
endif
else
Abits=0.
dMbitsE=0.
dMbitsM=0.
nMbits=this%mass_of_bits ! retain previous value incase non-zero
endif
! Add melting to the grid and field diagnostics
if (grd%area(i,j).ne.0.) then
melt=(dM-(dMbitsE-dMbitsM))/bergs%dt ! kg/s
grd%floating_melt(i,j)=grd%floating_melt(i,j)+melt/grd%area(i,j)*this%mass_scaling ! kg/m2/s
melt=melt*this%heat_density ! kg/s x J/kg = J/s
grd%calving_hflx(i,j)=grd%calving_hflx(i,j)+melt/grd%area(i,j)*this%mass_scaling ! W/m2
bergs%net_heat_to_ocean=bergs%net_heat_to_ocean+melt*this%mass_scaling*bergs%dt ! J
melt=dM/bergs%dt ! kg/s
grd%berg_melt(i,j)=grd%berg_melt(i,j)+melt/grd%area(i,j)*this%mass_scaling ! kg/m2/s
melt=dMbitsE/bergs%dt ! mass flux into bergy bits in kg/s
grd%bergy_src(i,j)=grd%bergy_src(i,j)+melt/grd%area(i,j)*this%mass_scaling ! kg/m2/s
melt=dMbitsM/bergs%dt ! melt rate of bergy bits in kg/s
grd%bergy_melt(i,j)=grd%bergy_melt(i,j)+melt/grd%area(i,j)*this%mass_scaling ! kg/m2/s
if(grd%id_melt_buoy>0) then
melt=dMb/bergs%dt ! melt rate due to buoyancy term in kg/s
grd%melt_buoy(i,j)=grd%melt_buoy(i,j)+melt/grd%area(i,j)*this%mass_scaling ! kg/m2/s
endif
if(grd%id_melt_eros>0) then
melt=dMe/bergs%dt ! erosion rate in kg/s
grd%melt_eros(i,j)=grd%melt_eros(i,j)+melt/grd%area(i,j)*this%mass_scaling ! kg/m2/s
endif
if(grd%id_melt_conv>0) then
melt=dMv/bergs%dt ! melt rate due to convection term in kg/s
grd%melt_conv(i,j)=grd%melt_conv(i,j)+melt/grd%area(i,j)*this%mass_scaling ! kg/m2/s
endif
else
stderrunit = stderr()
write(stderrunit,*) 'diamonds, thermodynamics: berg appears to have grounded!!!! PE=',mpp_pe(),i,j
call print_berg(stderrunit,this,'thermodynamics, grounded')
if (associated(this%trajectory)) &
write(stderrunit,*) 'traj=',this%trajectory%lon,this%trajectory%lat
write(stderrunit,*) 'msk=',grd%msk(i,j),grd%area(i,j)
call error_mesg('diamonds, thermodynamics', 'berg appears to have grounded!', FATAL)
endif
! Rolling
Dn=(bergs%rho_bergs/rho_seawater)*Tn ! draught (keel depth)
if ( Dn>0. ) then
if ( max(Wn,Ln)<sqrt(0.92*(Dn**2)+58.32*Dn) ) then
T=Tn
Tn=Wn
Wn=T
Dn=(bergs%rho_bergs/rho_seawater)*Tn ! re-calculate draught (keel depth) for grounding
end if
endif
! Store the new state of iceberg (with L>W)
this%mass=Mnew
this%mass_of_bits=nMbits
this%thickness=Tn
this%width=min(Wn,Ln)
this%length=max(Wn,Ln)
next=>this%next
! Did berg completely melt?
if (Mnew<=0.) then ! Delete the berg
call move_trajectory(bergs, this)
call delete_iceberg_from_list(bergs%first, this)
bergs%nbergs_melted=bergs%nbergs_melted+1
else ! Diagnose mass distribution on grid
if (grd%id_virtual_area>0)&
& grd%virtual_area(i,j)=grd%virtual_area(i,j)+(Wn*Ln+Abits)*this%mass_scaling ! m^2
if (grd%id_mass>0 .or. bergs%add_weight_to_ocean)&
& grd%mass(i,j)=grd%mass(i,j)+Mnew/grd%area(i,j)*this%mass_scaling ! kg/m2
if (grd%id_bergy_mass>0 .or. bergs%add_weight_to_ocean)&
& grd%bergy_mass(i,j)=grd%bergy_mass(i,j)+nMbits/grd%area(i,j)*this%mass_scaling ! kg/m2
if (bergs%add_weight_to_ocean .and. .not. bergs%time_average_weight) then
if (bergs%grounding_fraction>0.) then
Hocean=bergs%grounding_fraction*(grd%ocean_depth(i,j)+grd%ssh(i,j))
if (Dn>Hocean) Mnew=Mnew*min(1.,Hocean/Dn)
endif
call spread_mass_across_ocean_cells(grd, i, j, this%xi, this%yj, Mnew, nMbits, this%mass_scaling)
endif
endif
this=>next
enddo
end subroutine thermodynamics
! ##############################################################################
subroutine spread_mass_across_ocean_cells(grd, i, j, x, y, Mberg, Mbits, scaling)
! Arguments
type(icebergs_gridded), pointer :: grd
integer, intent(in) :: i, j
real, intent(in) :: x, y, Mberg, Mbits, scaling
! Local variables
real :: xL, xC, xR, yD, yC, yU, Mass
real :: yDxL, yDxC, yDxR, yCxL, yCxC, yCxR, yUxL, yUxC, yUxR
real, parameter :: rho_seawater=1035.
Mass=(Mberg+Mbits)*scaling
! This line attempts to "clip" the weight felt by the ocean. The concept of
! clipping is non-physical and this step should be replaced by grounding.
if (grd%clipping_depth>0.) Mass=min(Mass,grd%clipping_depth*grd%area(i,j)*rho_seawater)
xL=min(0.5, max(0., 0.5-x))
xR=min(0.5, max(0., x-0.5))
xC=max(0., 1.-(xL+xR))
yD=min(0.5, max(0., 0.5-y))
yU=min(0.5, max(0., y-0.5))
yC=max(0., 1.-(yD+yU))
yDxL=yD*xL*grd%msk(i-1,j-1)
yDxC=yD*xC*grd%msk(i ,j-1)
yDxR=yD*xR*grd%msk(i+1,j-1)
yCxL=yC*xL*grd%msk(i-1,j )
yCxR=yC*xR*grd%msk(i+1,j )
yUxL=yU*xL*grd%msk(i-1,j+1)
yUxC=yU*xC*grd%msk(i ,j+1)
yUxR=yU*xR*grd%msk(i+1,j+1)
yCxC=1.-( ((yDxL+yUxR)+(yDxR+yUxL)) + ((yCxL+yCxR)+(yDxC+yUxC)) )
grd%mass_on_ocean(i,j,1)=grd%mass_on_ocean(i,j,1)+yDxL*Mass
grd%mass_on_ocean(i,j,2)=grd%mass_on_ocean(i,j,2)+yDxC*Mass
grd%mass_on_ocean(i,j,3)=grd%mass_on_ocean(i,j,3)+yDxR*Mass
grd%mass_on_ocean(i,j,4)=grd%mass_on_ocean(i,j,4)+yCxL*Mass
grd%mass_on_ocean(i,j,5)=grd%mass_on_ocean(i,j,5)+yCxC*Mass
grd%mass_on_ocean(i,j,6)=grd%mass_on_ocean(i,j,6)+yCxR*Mass
grd%mass_on_ocean(i,j,7)=grd%mass_on_ocean(i,j,7)+yUxL*Mass
grd%mass_on_ocean(i,j,8)=grd%mass_on_ocean(i,j,8)+yUxC*Mass
grd%mass_on_ocean(i,j,9)=grd%mass_on_ocean(i,j,9)+yUxR*Mass
end subroutine spread_mass_across_ocean_cells
! ##############################################################################
subroutine interp_flds(grd, i, j, xi, yj, uo, vo, ui, vi, ua, va, ssh_x, ssh_y, sst, cn, hi)
! Arguments
type(icebergs_gridded), pointer :: grd
integer, intent(in) :: i, j
real, intent(in) :: xi, yj
real, intent(out) :: uo, vo, ui, vi, ua, va, ssh_x, ssh_y, sst, cn, hi
! Local variables
real :: cos_rot, sin_rot
#ifdef USE_OLD_SSH_GRADIENT
real :: dxm, dx0, dxp
#endif
real :: hxm, hxp
real, parameter :: ssh_coast=0.00
cos_rot=bilin(grd, grd%cos, i, j, xi, yj) ! If true, uses the inverted bilin function
sin_rot=bilin(grd, grd%sin, i, j, xi, yj)
uo=bilin(grd, grd%uo, i, j, xi, yj)
vo=bilin(grd, grd%vo, i, j, xi, yj)
ui=bilin(grd, grd%ui, i, j, xi, yj)
vi=bilin(grd, grd%vi, i, j, xi, yj)
ua=bilin(grd, grd%ua, i, j, xi, yj)
va=bilin(grd, grd%va, i, j, xi, yj)
! These fields are cell centered (A-grid) and would
! best be interpolated using PLM. For now we use PCM!
sst=grd%sst(i,j) ! A-grid
cn=grd%cn(i,j) ! A-grid
hi=grd%hi(i,j) ! A-grid
! Estimate SSH gradient in X direction
#ifdef USE_OLD_SSH_GRADIENT
dxp=0.5*(grd%dx(i+1,j)+grd%dx(i+1,j-1))
dx0=0.5*(grd%dx(i,j)+grd%dx(i,j-1))
dxm=0.5*(grd%dx(i-1,j)+grd%dx(i-1,j-1))
hxm=2.*(grd%ssh(i,j)-grd%ssh(i-1,j))/(dx0+dxm)*grd%msk(i-1,j) &
+(-ssh_coast)/(dx0+dxm)*(1.-grd%msk(i-1,j)) ! force to drive bergs away from coasts
hxp=2.*(grd%ssh(i+1,j)-grd%ssh(i,j))/(dx0+dxp)*grd%msk(i+1,j) &
+(+ssh_coast)/(dx0+dxp)*(1.-grd%msk(i+1,j)) ! force to drive bergs away from coasts
#else
if (yj>=0.5) then
hxp=(yj-0.5)*ddx_ssh(grd,i ,j+1)+(1.5-yj)*ddx_ssh(grd,i ,j )
hxm=(yj-0.5)*ddx_ssh(grd,i-1,j+1)+(1.5-yj)*ddx_ssh(grd,i-1,j )
else
hxp=(yj+0.5)*ddx_ssh(grd,i ,j )+(0.5-yj)*ddx_ssh(grd,i ,j-1)
hxm=(yj+0.5)*ddx_ssh(grd,i-1,j )+(0.5-yj)*ddx_ssh(grd,i-1,j-1)
endif
#endif