MOM6
MOM_unit_scaling.F90
Go to the documentation of this file.
1 !> Provides a transparent unit rescaling type to facilitate dimensional consistency testing
3 
4 ! This file is part of MOM6. See LICENSE.md for the license.
5 
6 use mom_error_handler, only : mom_error, mom_mesg, fatal
8 
9 implicit none ; private
10 
12 
13 !> Describes various unit conversion factors
14 type, public :: unit_scale_type
15  real :: m_to_z !< A constant that translates distances in meters to the units of depth.
16  real :: z_to_m !< A constant that translates distances in the units of depth to meters.
17  real :: m_to_l !< A constant that translates lengths in meters to the units of horizontal lengths.
18  real :: l_to_m !< A constant that translates lengths in the units of horizontal lengths to meters.
19  real :: s_to_t !< A constant that translates time intervals in seconds to the units of time.
20  real :: t_to_s !< A constant that translates the units of time to seconds.
21  real :: r_to_kg_m3 !< A constant that translates the units of density to kilograms per meter cubed.
22  real :: kg_m3_to_r !< A constant that translates kilograms per meter cubed to the units of density.
23 
24  ! These are useful combinations of the fundamental scale conversion factors above.
25  real :: z_to_l !< Convert vertical distances to lateral lengths
26  real :: l_to_z !< Convert vertical distances to lateral lengths
27  real :: l_t_to_m_s !< Convert lateral velocities from L T-1 to m s-1.
28  real :: m_s_to_l_t !< Convert lateral velocities from m s-1 to L T-1.
29  real :: l_t2_to_m_s2 !< Convert lateral accelerations from L T-2 to m s-2.
30  real :: z2_t_to_m2_s !< Convert vertical diffusivities from Z2 T-1 to m2 s-1.
31  real :: m2_s_to_z2_t !< Convert vertical diffusivities from m2 s-1 to Z2 T-1.
32 
33  ! These are used for changing scaling across restarts.
34  real :: m_to_z_restart = 0.0 !< A copy of the m_to_Z that is used in restart files.
35  real :: m_to_l_restart = 0.0 !< A copy of the m_to_L that is used in restart files.
36  real :: s_to_t_restart = 0.0 !< A copy of the s_to_T that is used in restart files.
37  real :: kg_m3_to_r_restart = 0.0 !< A copy of the kg_m3_to_R that is used in restart files.
38 end type unit_scale_type
39 
40 contains
41 
42 !> Allocates and initializes the ocean model unit scaling type
43 subroutine unit_scaling_init( param_file, US )
44  type(param_file_type), intent(in) :: param_file !< Parameter file handle/type
45  type(unit_scale_type), pointer :: us !< A dimensional unit scaling type
46 
47  ! This routine initializes a unit_scale_type structure (US).
48 
49  ! Local variables
50  integer :: z_power, l_power, t_power, r_power
51  real :: z_rescale_factor, l_rescale_factor, t_rescale_factor, r_rescale_factor
52  ! This include declares and sets the variable "version".
53 # include "version_variable.h"
54  character(len=16) :: mdl = "MOM_unit_scaling"
55 
56  if (associated(us)) call mom_error(fatal, &
57  'unit_scaling_init: called with an associated US pointer.')
58  allocate(us)
59 
60  ! Read all relevant parameters and write them to the model log.
61  call log_version(param_file, mdl, version, &
62  "Parameters for doing unit scaling of variables.")
63  call get_param(param_file, mdl, "Z_RESCALE_POWER", z_power, &
64  "An integer power of 2 that is used to rescale the model's "//&
65  "intenal units of depths and heights. Valid values range from -300 to 300.", &
66  units="nondim", default=0, debuggingparam=.true.)
67  call get_param(param_file, mdl, "L_RESCALE_POWER", l_power, &
68  "An integer power of 2 that is used to rescale the model's "//&
69  "intenal units of lateral distances. Valid values range from -300 to 300.", &
70  units="nondim", default=0, debuggingparam=.true.)
71  call get_param(param_file, mdl, "T_RESCALE_POWER", t_power, &
72  "An integer power of 2 that is used to rescale the model's "//&
73  "intenal units of time. Valid values range from -300 to 300.", &
74  units="nondim", default=0, debuggingparam=.true.)
75  call get_param(param_file, mdl, "R_RESCALE_POWER", r_power, &
76  "An integer power of 2 that is used to rescale the model's "//&
77  "intenal units of density. Valid values range from -300 to 300.", &
78  units="nondim", default=0, debuggingparam=.true.)
79  if (abs(z_power) > 300) call mom_error(fatal, "unit_scaling_init: "//&
80  "Z_RESCALE_POWER is outside of the valid range of -300 to 300.")
81  if (abs(l_power) > 300) call mom_error(fatal, "unit_scaling_init: "//&
82  "L_RESCALE_POWER is outside of the valid range of -300 to 300.")
83  if (abs(t_power) > 300) call mom_error(fatal, "unit_scaling_init: "//&
84  "T_RESCALE_POWER is outside of the valid range of -300 to 300.")
85  if (abs(r_power) > 300) call mom_error(fatal, "unit_scaling_init: "//&
86  "R_RESCALE_POWER is outside of the valid range of -300 to 300.")
87 
88  z_rescale_factor = 1.0
89  if (z_power /= 0) z_rescale_factor = 2.0**z_power
90  us%Z_to_m = 1.0 * z_rescale_factor
91  us%m_to_Z = 1.0 / z_rescale_factor
92 
93  l_rescale_factor = 1.0
94  if (l_power /= 0) l_rescale_factor = 2.0**l_power
95  us%L_to_m = 1.0 * l_rescale_factor
96  us%m_to_L = 1.0 / l_rescale_factor
97 
98  t_rescale_factor = 1.0
99  if (t_power /= 0) t_rescale_factor = 2.0**t_power
100  us%T_to_s = 1.0 * t_rescale_factor
101  us%s_to_T = 1.0 / t_rescale_factor
102 
103  r_rescale_factor = 1.0
104  if (r_power /= 0) r_rescale_factor = 2.0**r_power
105  us%R_to_kg_m3 = 1.0 * r_rescale_factor
106  us%kg_m3_to_R = 1.0 / r_rescale_factor
107 
108  ! These are useful combinations of the fundamental scale conversion factors set above.
109  us%Z_to_L = us%Z_to_m * us%m_to_L
110  us%L_to_Z = us%L_to_m * us%m_to_Z
111  us%L_T_to_m_s = us%L_to_m * us%s_to_T
112  us%m_s_to_L_T = us%m_to_L * us%T_to_s
113  us%L_T2_to_m_s2 = us%L_to_m * us%s_to_T**2
114  ! It does not look like US%m_s2_to_L_T2 would be used, so it does not exist.
115  us%Z2_T_to_m2_s = us%Z_to_m**2 * us%s_to_T
116  us%m2_s_to_Z2_T = us%m_to_Z**2 * us%T_to_s
117 
118 end subroutine unit_scaling_init
119 
120 !> Set the unit scaling factors for output to restart files to the unit scaling
121 !! factors for this run.
122 subroutine fix_restart_unit_scaling(US)
123  type(unit_scale_type), intent(inout) :: us !< A dimensional unit scaling type
124 
125  us%m_to_Z_restart = us%m_to_Z
126  us%m_to_L_restart = us%m_to_L
127  us%s_to_T_restart = us%s_to_T
128  us%kg_m3_to_R_restart = us%kg_m3_to_R
129 
130 end subroutine fix_restart_unit_scaling
131 
132 !> Deallocates a unit scaling structure.
133 subroutine unit_scaling_end( US )
134  type(unit_scale_type), pointer :: us !< A dimensional unit scaling type
135 
136  deallocate( us )
137 
138 end subroutine unit_scaling_end
139 
140 end module mom_unit_scaling
mom_file_parser::log_version
An overloaded interface to log version information about modules.
Definition: MOM_file_parser.F90:109
mom_error_handler::mom_mesg
subroutine, public mom_mesg(message, verb, all_print)
This provides a convenient interface for writing an informative comment.
Definition: MOM_error_handler.F90:53
mom_file_parser::param_file_type
A structure that can be parsed to read and document run-time parameters.
Definition: MOM_file_parser.F90:54
mom_file_parser::get_param
An overloaded interface to read and log the values of various types of parameters.
Definition: MOM_file_parser.F90:102
mom_unit_scaling::unit_scale_type
Describes various unit conversion factors.
Definition: MOM_unit_scaling.F90:14
mom_file_parser
The MOM6 facility to parse input files for runtime parameters.
Definition: MOM_file_parser.F90:2
mom_unit_scaling
Provides a transparent unit rescaling type to facilitate dimensional consistency testing.
Definition: MOM_unit_scaling.F90:2
mom_unit_scaling::fix_restart_unit_scaling
subroutine, public fix_restart_unit_scaling(US)
Set the unit scaling factors for output to restart files to the unit scaling factors for this run.
Definition: MOM_unit_scaling.F90:123
mom_error_handler::mom_error
subroutine, public mom_error(level, message, all_print)
This provides a convenient interface for writing an mpp_error message with run-time filter based on a...
Definition: MOM_error_handler.F90:72
mom_unit_scaling::unit_scaling_end
subroutine, public unit_scaling_end(US)
Deallocates a unit scaling structure.
Definition: MOM_unit_scaling.F90:134
mom_file_parser::log_param
An overloaded interface to log the values of various types of parameters.
Definition: MOM_file_parser.F90:96
mom_error_handler
Routines for error handling and I/O management.
Definition: MOM_error_handler.F90:2
mom_unit_scaling::unit_scaling_init
subroutine, public unit_scaling_init(param_file, US)
Allocates and initializes the ocean model unit scaling type.
Definition: MOM_unit_scaling.F90:44