11 implicit none ;
private 20 real :: min_thickness = 0.
27 logical :: integrate_downward_for_e = .false.
30 real,
allocatable,
dimension(:) :: target_density
36 public init_coord_rho, set_rho_params, build_rho_column, old_inflate_layers_1d, end_coord_rho
41 subroutine init_coord_rho(CS, nk, ref_pressure, target_density, interp_CS)
43 integer,
intent(in) :: nk
44 real,
intent(in) :: ref_pressure
45 real,
dimension(:),
intent(in) :: target_density
48 if (
associated(cs))
call mom_error(fatal,
"init_coord_rho: CS already associated!")
50 allocate(cs%target_density(nk+1))
53 cs%ref_pressure = ref_pressure
54 cs%target_density(:) = target_density(:)
55 cs%interp_CS = interp_cs
57 end subroutine init_coord_rho
60 subroutine end_coord_rho(CS)
64 if (.not.
associated(cs))
return 65 deallocate(cs%target_density)
67 end subroutine end_coord_rho
70 subroutine set_rho_params(CS, min_thickness, integrate_downward_for_e, interp_CS)
72 real,
optional,
intent(in) :: min_thickness
73 logical,
optional,
intent(in) :: integrate_downward_for_e
79 if (.not.
associated(cs))
call mom_error(fatal,
"set_rho_params: CS not associated")
81 if (
present(min_thickness)) cs%min_thickness = min_thickness
82 if (
present(integrate_downward_for_e)) cs%integrate_downward_for_e = integrate_downward_for_e
83 if (
present(interp_cs)) cs%interp_CS = interp_cs
84 end subroutine set_rho_params
90 subroutine build_rho_column(CS, nz, depth, h, T, S, eqn_of_state, z_interface, &
91 h_neglect, h_neglect_edge)
93 integer,
intent(in) :: nz
94 real,
intent(in) :: depth
95 real,
dimension(nz),
intent(in) :: h
96 real,
dimension(nz),
intent(in) :: t
97 real,
dimension(nz),
intent(in) :: s
98 type(
eos_type),
pointer :: eqn_of_state
99 real,
dimension(CS%nk+1), &
100 intent(inout) :: z_interface
101 real,
optional,
intent(in) :: h_neglect
103 real,
optional,
intent(in) :: h_neglect_edge
107 integer :: k, count_nonzero_layers
108 integer,
dimension(nz) :: mapping
109 real,
dimension(nz) :: pres
110 real,
dimension(nz) :: h_nv
111 real,
dimension(nz) :: densities
112 real,
dimension(nz+1) :: xtmp
113 real,
dimension(CS%nk) :: h_new
114 real,
dimension(CS%nk+1) :: x1
117 call copy_finite_thicknesses(nz, h, cs%min_thickness, count_nonzero_layers, h_nv, mapping)
119 if (count_nonzero_layers > 1)
then 121 do k = 1,count_nonzero_layers
122 xtmp(k+1) = xtmp(k) + h_nv(k)
126 pres(:) = cs%ref_pressure
128 do k = 1,count_nonzero_layers
129 densities(k) = densities(mapping(k))
133 call build_and_interpolate_grid(cs%interp_CS, densities, count_nonzero_layers, &
134 h_nv, xtmp, cs%target_density, cs%nk, h_new, &
135 x1, h_neglect, h_neglect_edge)
138 call old_inflate_layers_1d(cs%min_thickness, cs%nk, h_new)
141 x1(1) = 0.0 ;
do k = 1,cs%nk ; x1(k+1) = x1(k) + h_new(k) ;
enddo 143 h_new(k) = x1(k+1) - x1(k)
147 if (nz == cs%nk)
then 156 if (cs%integrate_downward_for_e)
then 160 z_interface(k+1) = z_interface(k) - h_new(k)
164 z_interface(cs%nk+1) = -depth
166 z_interface(k) = z_interface(k+1) + h_new(k)
170 end subroutine build_rho_column
186 subroutine build_rho_column_iteratively(CS, remapCS, nz, depth, h, T, S, eqn_of_state, &
187 zInterface, h_neglect, h_neglect_edge, dev_tol)
190 integer,
intent(in) :: nz
191 real,
intent(in) :: depth
192 real,
dimension(nz),
intent(in) :: h
193 real,
dimension(nz),
intent(in) :: T
194 real,
dimension(nz),
intent(in) :: S
195 type(
eos_type),
pointer :: eqn_of_state
196 real,
dimension(nz+1),
intent(inout) :: zInterface
197 real,
optional,
intent(in) :: h_neglect
200 real,
optional,
intent(in) :: h_neglect_edge
203 real,
optional,
intent(in) :: dev_tol
208 real,
dimension(nz+1) :: x0, x1, xTmp
209 real,
dimension(nz) :: pres
210 real,
dimension(nz) :: densities
211 real,
dimension(nz) :: T_tmp, S_tmp
212 real,
dimension(nz) :: Tmp
213 real,
dimension(nz) :: h0, h1, hTmp
216 real :: deviation_tol
219 integer,
dimension(nz) :: mapping
220 integer :: k, m, count_nonzero_layers
223 integer,
parameter :: NB_REGRIDDING_ITERATIONS = 1
225 threshold = cs%min_thickness
226 pres(:) = cs%ref_pressure
233 deviation_tol = 1.0e-15*depth ;
if (
present(dev_tol)) deviation_tol = dev_tol
235 do m=1,nb_regridding_iterations
238 call copy_finite_thicknesses(nz, h0, threshold, count_nonzero_layers, htmp, mapping)
239 if ( count_nonzero_layers <= 1 )
then 245 do k = 1,count_nonzero_layers
246 xtmp(k+1) = xtmp(k) + htmp(k)
252 do k = 1,count_nonzero_layers
253 densities(k) = densities(mapping(k))
258 call build_and_interpolate_grid(cs%interp_CS, densities, count_nonzero_layers, &
259 htmp, xtmp, cs%target_density, nz, h1, x1, h_neglect, h_neglect_edge)
261 call old_inflate_layers_1d( cs%min_thickness, nz, h1 )
262 x1(1) = 0.0 ;
do k = 1,nz ; x1(k+1) = x1(k) + h1(k) ;
enddo 266 h1(k) = x1(k+1) - x1(k)
269 call remapping_core_h(remapcs, nz, h0, s, nz, h1, tmp, h_neglect, h_neglect_edge)
272 call remapping_core_h(remapcs, nz, h0, t, nz, h1, tmp, h_neglect, h_neglect_edge)
280 x0(k) = x0(k-1) + h0(k-1)
281 x1(k) = x1(k-1) + h1(k-1)
282 deviation = deviation + (x0(k)-x1(k))**2
284 deviation = sqrt( deviation / (nz-1) )
286 if ( deviation <= deviation_tol )
exit 292 if (cs%integrate_downward_for_e)
then 295 zinterface(k+1) = zinterface(k) - h1(k)
301 zinterface(nz+1) = -depth
303 zinterface(k) = zinterface(k+1) + h1(k)
309 end subroutine build_rho_column_iteratively
312 subroutine copy_finite_thicknesses(nk, h_in, thresh, nout, h_out, mapping)
313 integer,
intent(in) :: nk
314 real,
dimension(nk),
intent(in) :: h_in
315 real,
intent(in) :: thresh
317 integer,
intent(out) :: nout
318 real,
dimension(nk),
intent(out) :: h_out
319 integer,
dimension(nk),
intent(out) :: mapping
321 integer :: k, k_thickest
322 real :: thickness_in_vanished
323 real :: thickest_h_out
327 thickness_in_vanished = 0.0
328 thickest_h_out = h_in(1)
333 if (h_in(k) > thresh)
then 337 h_out(nout) = h_in(k)
338 if (h_out(nout) > thickest_h_out)
then 339 thickest_h_out = h_out(nout)
344 thickness_in_vanished = thickness_in_vanished + h_in(k)
349 if (nout <= 1)
return 352 h_out(k_thickest) = h_out(k_thickest) + thickness_in_vanished
354 end subroutine copy_finite_thicknesses
358 subroutine old_inflate_layers_1d( min_thickness, nk, h )
361 real,
intent(in) :: min_thickness
362 integer,
intent(in) :: nk
363 real,
dimension(:),
intent(inout) :: h
368 integer :: count_nonzero_layers
374 count_nonzero_layers = 0
376 if ( h(k) > min_thickness )
then 377 count_nonzero_layers = count_nonzero_layers + 1
382 if ( count_nonzero_layers == nk )
return 385 if ( count_nonzero_layers == 0 )
then 395 if ( h(k) <= min_thickness )
then 396 delta = min_thickness - h(k)
397 correction = correction + delta
406 if ( h(k) > maxthickness )
then 412 h(k_found) = h(k_found) - correction
414 end subroutine old_inflate_layers_1d
Control structure containing required parameters for the rho coordinate.
Calculates density of sea water from T, S and P.
Provides column-wise vertical remapping functions.
Container for remapping parameters.
Routines for error handling and I/O management.
Provides subroutines for quantities specific to the equation of state.
Control structure for regrid_interp module.
Regrid columns for the continuous isopycnal (rho) coordinate.
Vertical interpolation for regridding.
A control structure for the equation of state.