Skip to content

Commit

Permalink
Added ability to frequently write trajectories
Browse files Browse the repository at this point in the history
- traj_write_hrs controls interval between writing trajectories.
- Should help with issue #1.
- No answer changes.
  • Loading branch information
adcroft committed Jul 16, 2015
1 parent 6af1a80 commit a3913a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
20 changes: 11 additions & 9 deletions icebergs.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module ice_bergs
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
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
Expand Down Expand Up @@ -762,7 +762,7 @@ subroutine icebergs_run(bergs, time, calving, uo, vo, ui, vi, tauxa, tauya, ssh,
! Local variables
integer :: iyr, imon, iday, ihr, imin, isec, k
type(icebergs_gridded), pointer :: grd
logical :: lerr, sample_traj, lbudget, lverbose
logical :: lerr, sample_traj, write_traj, lbudget, lverbose
real :: unused_calving, tmpsum, grdd_berg_mass, grdd_bergy_mass
integer :: i, j, Iu, ju, iv, Jv, Iu_off, ju_off, iv_off, Jv_off
real :: mask
Expand Down Expand Up @@ -804,6 +804,10 @@ subroutine icebergs_run(bergs, time, calving, uo, vo, ui, vi, tauxa, tauya, ssh,
if (bergs%traj_sample_hrs>0) then
if (mod(24*iday+ihr,bergs%traj_sample_hrs).eq.0) sample_traj=.true.
end if
write_traj=.false.
if (bergs%traj_write_hrs>0) then
if (mod(24*iday+ihr,bergs%traj_write_hrs).eq.0) write_traj=.true.
end if
lverbose=.false.
if (bergs%verbose_hrs>0) then
if (mod(24*iday+ihr,bergs%verbose_hrs).eq.0) lverbose=verbose
Expand Down Expand Up @@ -961,6 +965,10 @@ subroutine icebergs_run(bergs, time, calving, uo, vo, ui, vi, tauxa, tauya, ssh,
! For each berg, record
call mpp_clock_begin(bergs%clock_dia)
if (sample_traj.and.associated(bergs%first)) call record_posn(bergs)
if (write_traj) then
call move_all_trajectories(bergs)
call write_trajectory(bergs%trajectories)
endif

! Gridded diagnostics
if (grd%id_uo>0) &
Expand Down Expand Up @@ -2172,13 +2180,7 @@ subroutine icebergs_end(bergs)

call mpp_clock_begin(bergs%clock_ini)
! Delete bergs and structures
this=>bergs%first
do while (associated(this))
next=>this%next
call move_trajectory(bergs, this)
call destroy_iceberg(this)
this=>next
enddo
call move_all_trajectories(bergs, delete_bergs=.true.)

call write_trajectory(bergs%trajectories)

Expand Down
30 changes: 27 additions & 3 deletions icebergs_framework.F90
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module ice_bergs_framework
public add_new_berg_to_list, count_out_of_order, check_for_duplicates
public insert_berg_into_list, create_iceberg, delete_iceberg_from_list, destroy_iceberg
public print_fld,print_berg, print_bergs,record_posn, push_posn, append_posn, check_position
public move_trajectory
public move_trajectory, move_all_trajectories
public find_cell,find_cell_by_search,count_bergs,is_point_in_cell,pos_within_cell
public sum_mass,sum_heat,bilin,yearday,bergs_chksum
public checksum_gridded
Expand Down Expand Up @@ -161,7 +161,7 @@ module ice_bergs_framework
real :: dt ! Time-step between iceberg calls (should make adaptive?)
integer :: current_year
real :: current_yearday ! 1.00-365.99
integer :: traj_sample_hrs
integer :: traj_sample_hrs, traj_write_hrs
integer :: verbose_hrs
integer :: clock, clock_mom, clock_the, clock_int, clock_cal, clock_com, clock_ini, clock_ior, clock_iow, clock_dia ! ids for fms timers
real :: rho_bergs ! Density of icebergs [kg/m^3]
Expand Down Expand Up @@ -253,6 +253,7 @@ subroutine ice_bergs_framework_init(bergs, &
! Namelist parameters (and defaults)
integer :: halo=4 ! Width of halo region
integer :: traj_sample_hrs=24 ! Period between sampling of position for trajectory storage
integer :: traj_write_hrs=480 ! Period between writing sampled trajectories to disk
integer :: verbose_hrs=24 ! Period between verbose messages
real :: rho_bergs=850. ! Density of icebergs
real :: LoW_ratio=1.5 ! Initial ratio L/W for newly calved icebergs
Expand All @@ -269,7 +270,7 @@ subroutine ice_bergs_framework_init(bergs, &
real, dimension(nclasses) :: distribution=(/0.24, 0.12, 0.15, 0.18, 0.12, 0.07, 0.03, 0.03, 0.03, 0.02/) ! Fraction of calving to apply to this class (non-dim)
real, dimension(nclasses) :: mass_scaling=(/2000, 200, 50, 20, 10, 5, 2, 1, 1, 1/) ! Ratio between effective and real iceberg mass (non-dim)
real, dimension(nclasses) :: initial_thickness=(/40., 67., 133., 175., 250., 250., 250., 250., 250., 250./) ! Total thickness of newly calved bergs (m)
namelist /icebergs_nml/ verbose, budget, halo, traj_sample_hrs, initial_mass, &
namelist /icebergs_nml/ verbose, budget, halo, traj_sample_hrs, traj_write_hrs, initial_mass, &
distribution, mass_scaling, initial_thickness, verbose_hrs, &
rho_bergs, LoW_ratio, debug, really_debug, use_operator_splitting, bergy_bit_erosion_fraction, &
parallel_reprod, use_slow_find, sicn_shift, add_weight_to_ocean, passive_mode, ignore_ij_restart, &
Expand Down Expand Up @@ -495,6 +496,7 @@ subroutine ice_bergs_framework_init(bergs, &
! Parameters
bergs%dt=dt
bergs%traj_sample_hrs=traj_sample_hrs
bergs%traj_write_hrs=traj_write_hrs
bergs%verbose_hrs=verbose_hrs
bergs%grd%halo=halo
bergs%rho_bergs=rho_bergs
Expand Down Expand Up @@ -1703,6 +1705,28 @@ end subroutine move_trajectory

! ##############################################################################

subroutine move_all_trajectories(bergs, delete_bergs)
! Arguments
type(icebergs), pointer :: bergs
logical, optional, intent(in) :: delete_bergs
! Local variables
type(iceberg), pointer :: this, next
logical :: delete_bergs_after_moving_traj

delete_bergs_after_moving_traj = .false.
if (present(delete_bergs)) delete_bergs_after_moving_traj = delete_bergs
this=>bergs%first
do while (associated(this))
next=>this%next
call move_trajectory(bergs, this)
! if (delete_bergs_after_moving_traj) call destroy_iceberg(this)
this=>next
enddo

end subroutine move_all_trajectories

! ##############################################################################

logical function find_cell_by_search(grd, x, y, i, j)
! Arguments
type(icebergs_gridded), pointer :: grd
Expand Down

0 comments on commit a3913a7

Please sign in to comment.