_Dimensional_consistency.dox

1/*! \page Dimensional_consistency Dimensional Consistency Testing
2
3\section section_Dimensional_consistency Dimensional Consistency Testing
4
5 MOM6 uses a unique system for testing the dimensional consistency of all of
6its expressions. The internal representations of dimensional variables are
7rescaled by integer powers of 2 that depend on their units, with all input and
8output being rescaled back to their original MKS units. By choosing different
9powers of 2 for different units, the internal representations with different
10units scale differently, so dimensionally inconsistent expressions will not
11reproduce, but dimensionally inconsistent expressions give bitwise identical
12results. So, for example, if horizontal lengths scale by a factor of 2^6=64,
13and time is scaled by a factor of 2^4=16, horizontal velocities will scale by a
14factor of 2^(6-4)=4. In this case, expressions that combine velocities, all
15terms would scale by the same factor of 4. By contrast, if there were an
16expression where a variable with units of length were added to one with the
17units of a velocity, the results would scale inconsistently, and answers would
18change with different scaling factors.
19
20 What makes these integer powers of 2 special is the way that floating point
21numbers are written as an O(1) mantissa times 2 raised to an integer exponent
22between +/-1024. Multiplication by an integer power of 2 is just an integer
23shift in the exponent, so as long as the model is not rescaled by an overly
24large factor to encounter overflows and the model is not relying on automatic
25underflows being converted to 0, all floating point operations can be carried
26with one scale, and then rescaled to obtain identical answers. MOM6 has the
27option to explicitly handle all relevant cases of underflows, and it can be
28demonstrated to give identical answers when each of its units are scaled by
29factors ranging from 2^-140 ~= 7.2e-43 to 2^140 ~= 1.4e42.
30
31 When running with rescaling factors other than 2^0 = 1, there are some extra
32array copies and multiplies of input fields or diagnostic output, so it is
33slightly more efficient not to actively use the dimensional rescaling. For
34production runs, we typically set all of the rescaling powers to 0, but for
35debugging code problems, this rescaling can be an invaluable tool, especially
36when combined with the very verbose runtime setting DEBUG=True in a MOM_input or
37MOM_override file. Diffs of the output from runs with different scaling factors
38readily highlights the earliest instances of differences, which can be used to
39track down any dimensionally inconsistent expressions. Similarly, dimensional
40inconsistencies in diagnostics is easily tracked down by comparing the output
41from a pair of runs.
42
43 All real variables in MOM6 should have comments describing their purpose,
44along with their rescaled units and their mks counterparts with notation like
45"! A velocity [L T-1 ~> m s-1]". If the units vary with the Boussinesq
46approximation, the Boussinesq variant is given first. When variables are read
47in, their dimensions are usually specified with a 'scale=' optional argument on
48the MOM_get_param or MOM_read_data call, while the unscaling of diagnostics is
49specified with a 'conversion=' factor. In both cases, these arguments it next
50to a text string specifying the variable's units, which can then be check easily
51for self-consistency.
52
53 Currently in MOM6, the following dimensions have unique scaling, along with
54the notation used to describe these variables in comments:
55
56\li Time, scaled by 2^T_RESCALE_POWER, denoted as [T ~> s]
57\li Horizontal length, scaled by 2^L_RESCALE_POWER, denoted as [L ~> m]
58\li Vertical height, scaled by 2^Z_RESCALE_POWER, denoted as [Z ~> m]
59\li Vertical thickness, scaled by 2^H_RESCALE_POWER, denoted as [H ~> m or kg m-2]
60\li Density, scaled by 2^R_RESCALE_POWER, denoted as [R ~> kg m-3]
61\li Enthalpy (or heat content), scaled by 2^Q_RESCALE_POWER, denoted as [Q ~> J kg-1]
62
63 These rescaling capabilities are also used by the SIS2 sea ice model, but it
64does uses a non-Boussinesq mass scale of [R Z ~> kg m-2] for ice thicknesses,
65rather than having a separate scaling factor (of [H ~> m or kg m-2]) that varies
66between the Boussinesq and non-Boussinesq modes like MOM6 does. The actual
67powers used in the scaling are specified separately for MOM6 and SIS2 and
68need not be the same.
69
70 Each of these units can be scaled in separate test runs, or all of them can be
71rescaled simultaneously. In the latter case, MOM_unique_scales.F90 provides
72tools to evaluate whether the specific combinations of units used by a model
73scale by unique powers, and it can suggest scaling factors that provides unique
74combinations of rescaling factors for the dimensions being tested, using a
75cost-function based on the frequency with which units are used in the model (and
76specified inside of MOM_check_scaling.F90), with a cost going as the product of
77the frequency of units that resolve to the same scaling factor.
78
79 A separate set of scaling factors could also be used for different chemical
80tracer concentrations, for example. In this case, the tools in
81MOM_unique_scales.F90 could still be used, but there would need to be a separate
82equivalent of the unit_scaling_type with variables that are appropriate to the
83units of the tracers.
84
85*/