Skip to content

aragog.rheology_lid

The aragog.rheology_lid module implements stagnant-lid identification, boundary-layer convective stress scaling (Foley and Bercovici, 2014), the minimum plastic yield viscosity closure (Moresi and Solomatov, 1998; Tackley, 2000), and the local strain-rate closure dispatcher. All functions accept an xp array namespace (numpy or jax.numpy) and run at 64-bit precision.

Name Role
COHESION_FLOOR Minimum positive yield-stress floor (\(10^{-6}\text{ Pa}\)) preventing zero viscosity when cohesion and friction are zero at zero pressure.
compute_stagnant_lid_state Identify the convecting interior state (\(T_i, P_{T_i}, \eta_i, \mu_i\)), stagnant-lid base and thickness (\(r_\mathrm{lid,base}, d_\mathrm{lid}, \delta_\mathrm{rh}\)), Frank-Kamenetskii contrast \(\theta\), convective velocity \(v_m\), driving stress \(\tau_d\), lid yield stress \(\tau_{y,\mathrm{lid}}\), smooth lid mask \(w_\mathrm{lid}\), and regime indicator lid_regime.
compute_effective_viscosity Combine diffusion-creep viscosity and plastic yield viscosity via the minimum closure in boundary-layer 'lid' mode or local mixing-length 'local' mode.
stress_closure Local strain-rate dispatcher for stress_closure_mode = 'local'.

For the physical derivations and asymptotic regimes, see Solid-state convection and lithospheric rheology.

rheology_lid

Stagnant lid boundary layer indicators and effective viscosity closures.

Intentional non-smooth switches retained for boolean diagnostics and physical bounds include is_convecting, has_lid, the is_convecting gate on v_i, the cap of f at 1, f_int_max = max(f * interior_node_mask), max(T_0, 1.0), max(T_1, 1.0), max(H_0, 1.0e-6), max(H_1, 1.0e-6), the w_eff clip to [0, 1], dT_ep_nz, is_mono_T, the 1 - 1e-15 selectors on w_eff and w_weight, DeltaT_conv = max(T_i - T_surf, 1.0e-6), max(theta, 1.0e-6), max(Ra_rh_raw, 1.0e-30), the elementwise maxima in w_interior and w_hot_sol, dTdr_floor with max(dr_min, 1.0), the r[-1] - r[0] cap on delta_rh, the COHESION_FLOOR yield-stress clamp, if_lid (where(w_lid_present >= 1 - 1e-12)), d_geom, the max in d_lid_raw, max(w_conv - w_conv_0, 0), f_int_scale, the v_m_raw branches, and the 1.0e-30 denominators.

compute_effective_viscosity(eta_diff, tau_d=None, tau_y_lid=None, stress_closure_mode='lid', unyielded_velocity=None, mixing_length=None, tau_y_profile=None, w_lid=None, strain_rate=None, tau_y=None, eta_i=None, xp=np)

Compute effective dynamic viscosity with boundary-layer or local stress closure.

Both boundary-layer lid mode and local stress closure mode use a smooth minimum closure of diffusion creep and plastic yield viscosity per Moresi & Solomatov (1998):

In boundary-layer lid mode, plastic yield viscosity is evaluated from the supplied driving shear stress tau_d (in solver pass 2, stagnant_lid_state['tau_d_lid'], corresponding to the lid strain-rate scale 2 * v_m / d_geom = tau_d_lid / eta_i): log10(eta_y) = _softmin2(log10(eta_diff), log10(eta_i * (tau_y_lid / tau_d)), LOCAL_CAP_LOG10_WIDTH) w_b = 0.5 * (1 + tanh(((tau_d / tau_y_lid) - 1) / YIELD_BLEND_RATIO_WIDTH)) log10(eta_eff_lid) = (1 - w_b) * log10(eta_diff) + w_b * log10(eta_y) with linear stress-ratio width YIELD_BLEND_RATIO_WIDTH (0.025) and yield-branch log10 cap width LOCAL_CAP_LOG10_WIDTH (0.01). eta_i, tau_d, and tau_y_lid are required in 'lid' mode.

In local stress closure mode, eta_y = max(tau_y, COHESION_FLOOR) / (2 * sr_safe) with sr_safe = sqrt(strain_rate**2 + LOCAL_STRAIN_RATE_FLOOR**2) and smooth log10 softplus cap of width LOCAL_CAP_LOG10_WIDTH (0.01). In the two-pass mixing-length solver, where the pass-1 viscous buoyancy stress tau_buoy,1 = eta_diff * |v_visc,1| / l_v is independent of eta_diff, yielding in 'local' mode lowers eta_eff by tau_y / tau_buoy,1 so pass 2 scales the viscous velocity and eddy diffusivity by tau_buoy,1 / tau_y; it is not a stress cap.

Parameters:

Name Type Description Default
eta_diff FloatOrArray

Unyielded diffusion-creep dynamic viscosity [Pa s], strictly positive and finite (0, +inf).

required
tau_d FloatOrArray or None

Convective driving shear stress [Pa] for stress_closure_mode='lid', non-negative and finite [0, +inf). Must be None in 'local' mode.

None
tau_y_lid FloatOrArray or None

Representative lid Byerlee yield stress [Pa] for stress_closure_mode='lid', non-negative [0, +inf] (+inf disables yielding). Must be None in 'local' mode.

None
stress_closure_mode str

Plastic stress closure mode, either 'lid' (boundary-layer stress closure) or 'local' (local strain-rate closure).

'lid'
unyielded_velocity FloatOrArray or None

Unyielded pass-1 viscous convective velocity [m/s] for 'local' mode when strain_rate is not supplied directly; finite (-inf, +inf).

None
mixing_length FloatOrArray or None

Convective mixing length [m] for 'local' mode when strain_rate is not supplied directly; non-negative and finite [0, +inf).

None
tau_y_profile FloatOrArray or None

Alias for tau_y [Pa] in 'local' mode, non-negative [0, +inf]; at most one of tau_y and tau_y_profile may be passed.

None
w_lid FloatOrArray or None

Dimensionless lid membership mask weight in [0, 1] for 'lid' mode; when provided, log-blends the yielded viscosity on lid nodes with eta_diff in the convecting interior.

None
strain_rate FloatOrArray or None

Local convective strain rate [1/s] for 'local' mode, non-negative and finite [0, +inf).

None
tau_y FloatOrArray or None

Local Byerlee yield stress [Pa] for 'local' mode, non-negative [0, +inf] (+inf disables yielding).

None
eta_i FloatOrArray or None

Representative interior viscosity [Pa s] for 'lid' mode, strictly positive and finite (0, +inf). Must be None in 'local' mode.

None
xp module

Array backend (numpy or jax.numpy).

numpy

Returns:

Type Description
FloatOrArray

Effective dynamic viscosity eta_eff [Pa s], bounded in (0, eta_diff].

Raises:

Type Description
ValueError

If eta_diff is None. If stress_closure_mode is not 'lid' or 'local', if required mode arguments are missing or cross-mode arguments are passed, if any input is non-real (such as a boolean, string, or complex value), or, on the eager NumPy path (xp is np), if eta_diff or eta_i is non-positive or infinite, if strain_rate or mixing_length is negative or infinite, if tau_d is negative or infinite, if unyielded_velocity is infinite, if w_lid lies outside [0, 1], or if tau_y_lid, tau_y, or tau_y_profile is negative (including -inf; +inf is allowed). On the JAX path, out-of-range numeric values return NaN.

Notes

Setting tau_y_lid = +inf in 'lid' mode (or tau_y = +inf in 'local' mode) represents infinite yield strength (no plastic yielding); a double-where substitution replaces +inf with a finite placeholder before the ratio so jax.grad remains finite while returning eta_diff in the outer where without capping finite yield stresses or high diffusion viscosities.

References

Moresi & Solomatov (1998), p. 672, eqs. 13-14, doi:10.1046/j.1365-246X.1998.00521.x (viscosity switch / minimum form eta_eff = min(eta_creep, eta_yield)) Foley & Bercovici (2014), p. 588, eq. 28, doi:10.1093/gji/ggu275 (convective driving shear stress tau_d = 2 * mu_i * v_m / d) Tackley (2000), eq. 8, p. 4, doi:10.1029/2000GC000036 (viscosity cap / minimum form eta_eff = min[eta, sigma_y / (2 e_dot)]) Foley & Becker (2009), eqs. 7-8, p. 3, doi:10.1029/2009GC002378 (alternative harmonic mean formulation)

Source code in src/aragog/rheology_lid.py
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
def compute_effective_viscosity(
    eta_diff: FloatOrArray,
    tau_d: FloatOrArray | None = None,
    tau_y_lid: FloatOrArray | None = None,
    stress_closure_mode: str = 'lid',
    unyielded_velocity: FloatOrArray | None = None,
    mixing_length: FloatOrArray | None = None,
    tau_y_profile: FloatOrArray | None = None,
    w_lid: FloatOrArray | None = None,
    strain_rate: FloatOrArray | None = None,
    tau_y: FloatOrArray | None = None,
    eta_i: FloatOrArray | None = None,
    xp: Any = np,
) -> FloatOrArray:
    r"""Compute effective dynamic viscosity with boundary-layer or local stress closure.

    Both boundary-layer lid mode and local stress closure mode use a smooth
    minimum closure of diffusion creep and plastic yield viscosity per
    Moresi & Solomatov (1998):

    In boundary-layer lid mode, plastic yield viscosity is evaluated from the supplied
    driving shear stress ``tau_d`` (in solver pass 2, ``stagnant_lid_state['tau_d_lid']``,
    corresponding to the lid strain-rate scale ``2 * v_m / d_geom = tau_d_lid / eta_i``):
        log10(eta_y) = _softmin2(log10(eta_diff), log10(eta_i * (tau_y_lid / tau_d)), LOCAL_CAP_LOG10_WIDTH)
        w_b = 0.5 * (1 + tanh(((tau_d / tau_y_lid) - 1) / YIELD_BLEND_RATIO_WIDTH))
        log10(eta_eff_lid) = (1 - w_b) * log10(eta_diff) + w_b * log10(eta_y)
    with linear stress-ratio width ``YIELD_BLEND_RATIO_WIDTH`` (0.025) and
    yield-branch log10 cap width ``LOCAL_CAP_LOG10_WIDTH`` (0.01). ``eta_i``,
    ``tau_d``, and ``tau_y_lid`` are required in ``'lid'`` mode.

    In local stress closure mode, ``eta_y = max(tau_y, COHESION_FLOOR) / (2 * sr_safe)``
    with ``sr_safe = sqrt(strain_rate**2 + LOCAL_STRAIN_RATE_FLOOR**2)`` and
    smooth log10 softplus cap of width ``LOCAL_CAP_LOG10_WIDTH`` (0.01). In the
    two-pass mixing-length solver, where the pass-1 viscous buoyancy stress
    ``tau_buoy,1 = eta_diff * |v_visc,1| / l_v`` is independent of ``eta_diff``,
    yielding in ``'local'`` mode lowers ``eta_eff`` by ``tau_y / tau_buoy,1`` so
    pass 2 scales the viscous velocity and eddy diffusivity by
    ``tau_buoy,1 / tau_y``; it is not a stress cap.

    Parameters
    ----------
    eta_diff : FloatOrArray
        Unyielded diffusion-creep dynamic viscosity [Pa s], strictly positive
        and finite ``(0, +inf)``.
    tau_d : FloatOrArray or None, default None
        Convective driving shear stress [Pa] for ``stress_closure_mode='lid'``,
        non-negative and finite ``[0, +inf)``. Must be ``None`` in ``'local'`` mode.
    tau_y_lid : FloatOrArray or None, default None
        Representative lid Byerlee yield stress [Pa] for
        ``stress_closure_mode='lid'``, non-negative ``[0, +inf]`` (``+inf``
        disables yielding). Must be ``None`` in ``'local'`` mode.
    stress_closure_mode : str, default 'lid'
        Plastic stress closure mode, either ``'lid'`` (boundary-layer stress
        closure) or ``'local'`` (local strain-rate closure).
    unyielded_velocity : FloatOrArray or None, default None
        Unyielded pass-1 viscous convective velocity [m/s] for ``'local'`` mode
        when ``strain_rate`` is not supplied directly; finite ``(-inf, +inf)``.
    mixing_length : FloatOrArray or None, default None
        Convective mixing length [m] for ``'local'`` mode when ``strain_rate`` is
        not supplied directly; non-negative and finite ``[0, +inf)``.
    tau_y_profile : FloatOrArray or None, default None
        Alias for ``tau_y`` [Pa] in ``'local'`` mode, non-negative ``[0, +inf]``;
        at most one of ``tau_y`` and ``tau_y_profile`` may be passed.
    w_lid : FloatOrArray or None, default None
        Dimensionless lid membership mask weight in ``[0, 1]`` for ``'lid'``
        mode; when provided, log-blends the yielded viscosity on lid nodes with
        ``eta_diff`` in the convecting interior.
    strain_rate : FloatOrArray or None, default None
        Local convective strain rate [1/s] for ``'local'`` mode, non-negative
        and finite ``[0, +inf)``.
    tau_y : FloatOrArray or None, default None
        Local Byerlee yield stress [Pa] for ``'local'`` mode, non-negative
        ``[0, +inf]`` (``+inf`` disables yielding).
    eta_i : FloatOrArray or None, default None
        Representative interior viscosity [Pa s] for ``'lid'`` mode, strictly
        positive and finite ``(0, +inf)``. Must be ``None`` in ``'local'`` mode.
    xp : module, default numpy
        Array backend (``numpy`` or ``jax.numpy``).

    Returns
    -------
    FloatOrArray
        Effective dynamic viscosity ``eta_eff`` [Pa s], bounded in
        ``(0, eta_diff]``.

    Raises
    ------
    ValueError
        If ``eta_diff`` is None.
        If ``stress_closure_mode`` is not ``'lid'`` or ``'local'``, if required
        mode arguments are missing or cross-mode arguments are passed, if any
        input is non-real (such as a boolean, string, or complex value), or, on
        the eager NumPy path (``xp is np``), if ``eta_diff`` or ``eta_i`` is
        non-positive or infinite, if ``strain_rate`` or ``mixing_length`` is
        negative or infinite, if ``tau_d`` is negative or infinite, if
        ``unyielded_velocity`` is infinite, if ``w_lid`` lies outside
        ``[0, 1]``, or if ``tau_y_lid``,
        ``tau_y``, or ``tau_y_profile`` is negative (including ``-inf``;
        ``+inf`` is allowed). On the JAX path, out-of-range numeric values
        return ``NaN``.

    Notes
    -----
    Setting ``tau_y_lid = +inf`` in ``'lid'`` mode (or ``tau_y = +inf`` in
    ``'local'`` mode) represents infinite yield strength (no plastic yielding);
    a double-``where`` substitution replaces ``+inf`` with a finite placeholder
    before the ratio so ``jax.grad`` remains finite while returning ``eta_diff``
    in the outer ``where`` without capping finite yield stresses or high
    diffusion viscosities.

    References
    ----------
    Moresi & Solomatov (1998), p. 672, eqs. 13-14, doi:10.1046/j.1365-246X.1998.00521.x
        (viscosity switch / minimum form eta_eff = min(eta_creep, eta_yield))
    Foley & Bercovici (2014), p. 588, eq. 28, doi:10.1093/gji/ggu275
        (convective driving shear stress tau_d = 2 * mu_i * v_m / d)
    Tackley (2000), eq. 8, p. 4, doi:10.1029/2000GC000036
        (viscosity cap / minimum form eta_eff = min[eta, sigma_y / (2 e_dot)])
    Foley & Becker (2009), eqs. 7-8, p. 3, doi:10.1029/2009GC002378
        (alternative harmonic mean formulation)
    """
    _require_x64_if_jax(xp)
    if eta_diff is None:
        raise ValueError('eta_diff must be a real number or array, got None')
    if stress_closure_mode not in ('lid', 'local'):
        hint = (
            ". 'global' mode is unsupported; use 'lid'."
            if stress_closure_mode == 'global'
            else ''
        )
        raise ValueError(
            f"Unknown stress_closure_mode {stress_closure_mode!r}; expected 'lid' or 'local'{hint}"
        )
    if stress_closure_mode == 'local':
        if any(x is not None for x in (tau_d, tau_y_lid, w_lid, eta_i)):
            raise ValueError(
                "tau_d, tau_y_lid, w_lid, and eta_i are not allowed when stress_closure_mode='local'"
            )
        if strain_rate is None and (unyielded_velocity is None or mixing_length is None):
            raise ValueError("mixing_length and unyielded_velocity required for 'local' mode")
        if tau_y is not None and tau_y_profile is not None:
            raise ValueError("Provide either tau_y or tau_y_profile in 'local' mode, not both")
        ty_raw = tau_y if tau_y is not None else tau_y_profile
        if ty_raw is None:
            raise ValueError("tau_y or tau_y_profile required for 'local' mode")
        invalid_local = _validate_inputs(
            (
                ('eta_diff', eta_diff, 'pos', False),
                ('strain_rate', strain_rate, 'nonneg', False),
                ('unyielded_velocity', unyielded_velocity, 'finite', False),
                ('mixing_length', mixing_length, 'nonneg', False),
                ('tau_y', tau_y, 'nonneg_or_posinf', False),
                ('tau_y_profile', tau_y_profile, 'nonneg_or_posinf', False),
            ),
            xp,
        )
        sr_local = (
            compute_strain_rate_local(unyielded_velocity, mixing_length, xp=xp)
            if strain_rate is None
            else strain_rate
        )
        res = _compute_effective_viscosity_core(
            eta_diff=eta_diff,
            stress_closure_mode='local',
            unyielded_velocity=unyielded_velocity,
            mixing_length=mixing_length,
            tau_y_profile=tau_y_profile,
            strain_rate=sr_local,
            tau_y=tau_y,
            xp=xp,
        )
        return xp.where(invalid_local, xp.nan, res)

    if any(
        x is not None
        for x in (strain_rate, tau_y, tau_y_profile, unyielded_velocity, mixing_length)
    ):
        raise ValueError(
            'strain_rate, tau_y, tau_y_profile, unyielded_velocity, and mixing_length '
            "are not allowed when stress_closure_mode='lid'"
        )
    if eta_i is None:
        raise ValueError("eta_i is required when stress_closure_mode='lid'")
    if tau_d is None or tau_y_lid is None:
        raise ValueError("tau_d and tau_y_lid are required when stress_closure_mode='lid'")

    if w_lid is not None and not _is_non_real(w_lid) and not _is_non_real(eta_diff):
        ed_arr = xp.asarray(eta_diff, dtype=float)
        wl_arr = xp.asarray(w_lid, dtype=float)
        if wl_arr.ndim > 0 and ed_arr.ndim > 0 and wl_arr.shape != ed_arr.shape:
            raise ValueError(
                f'w_lid shape {wl_arr.shape} must match eta_diff shape {ed_arr.shape}'
            )
    invalid_lid = _validate_inputs(
        (
            ('eta_diff', eta_diff, 'pos', False),
            ('eta_i', eta_i, 'pos', False),
            ('tau_d', tau_d, 'nonneg', False),
            ('tau_y_lid', tau_y_lid, 'nonneg_or_posinf', False),
            ('w_lid', w_lid, 'unit', False),
        ),
        xp,
    )
    eta_eff_val = _compute_effective_viscosity_core(
        eta_diff=eta_diff,
        tau_d=tau_d,
        tau_y_lid=tau_y_lid,
        stress_closure_mode='lid',
        w_lid=w_lid,
        eta_i=eta_i,
        xp=xp,
    )
    return xp.where(invalid_lid, xp.nan, eta_eff_val)

compute_stagnant_lid_state(radii, temperature, pressure, convective_flux, total_flux, solidus_temperature, melt_fraction, params, viscosity_solid, phi_rheo, phi_width, unyielded_velocity=None, viscosity_mixture=None, density=3300.0, gravity=9.81, thermal_expansivity=3e-05, thermal_diffusivity=1e-06, a_rh_fb=1.3, C4=0.125, xp=np)

Compute stagnant lid boundary-layer indicators and convective driving stress.

Parameters:

Name Type Description Default
radii array - like

Radial grid coordinates r [m] from core to surface.

required
temperature array - like

Radial temperature profile T [K].

required
pressure array - like

Radial pressure profile P [Pa] (non-negative; negative round-off excursions down to -PRESSURE_ROUNDOFF_TOLERANCE = -1.0 Pa are clamped to 0.0 Pa).

required
convective_flux array - like

Convective heat flux profile F_conv [W/m^2].

required
total_flux array - like

Total heat flux profile F_tot [W/m^2].

required
solidus_temperature float or array - like or None

Solidus temperature profile T_sol [K]. When provided, the solidus crossing indicators w_hot_sol and w_hot_sol_mask take the elementwise maximum of the thermal tanh((T - T_sol) / scale) ramp and the melt-fraction ramp centered at SOLIDUS_MELT_FRACTION_THRESHOLD (0.01). When None, they use the melt-fraction ramp alone. Not used in the activation enthalpy H(P) when params.activation_energy is set.

required
melt_fraction array - like

Melt mass fraction profile phi [-].

required
params SolidRheologyParams

Rheology parameter set.

required
viscosity_solid float

Reference solid mantle viscosity [Pa s] such that viscosity_solid * f_water equals eta_diff at (params.arrhenius_t_ref, P = 0) for the linear solidus and for the saturating activation law (params.activation_energy set); when params.activation_energy is None and a solidus_temperature table is provided, viscosity_solid is referenced to params.t_sol_0, so the table eta_diff(T, 0) scales relative to the linear-solidus eta_diff(T, 0) at the same T by exp(g_hom * (T_sol(0) - params.t_sol_0) / T) (a ratio of 2.752, or 2.75x, at 1600 K for 1464.8 K against 1400 K).

required
phi_rheo float

Critical melt fraction for rheological transition [-].

required
phi_width float

Transition width for rheological melt fraction indicator [-].

required
unyielded_velocity float or array - like

Unyielded convective velocity profile v [m/s].

None
viscosity_mixture float or array - like

Effective mixture viscosity profile [Pa s] of the convecting layer (in mush, the blended two-phase viscosity used by the solver). When provided, mu_i blends smoothly via w_weight = tanh(_smooth_max(w_conv_int) / 1e-6) between the W_tilde-weighted log mean of viscosity_mixture and the solid Arrhenius viscosity eta_arr_i; otherwise falls back to eta_arr_i.

None
density float or array - like

Mantle density rho [kg/m^3].

3300.0
gravity float or array - like

Gravitational acceleration g [m/s^2].

9.81
thermal_expansivity float or array - like

Thermal expansivity alpha [1/K].

3.0e-5
thermal_diffusivity float or array - like

Thermal diffusivity kappa [m^2/s].

1.0e-6
a_rh_fb float

Rheological sublayer parameter fitted with C4 in FB2014 (p. 589).

1.3
C4 float

Convective velocity prefactor in FB2014 (Eq. 26, p. 586-587; p. 589).

0.125
xp array module

Array namespace module (numpy or jax.numpy).

np

Returns:

Type Description
dict[str, Any]

Dictionary of boundary layer state diagnostics, including tau_d = w_lid_present * w_active * 2 * eta_i * v_m_raw / d_conv and the lid-thickness-scaled stress diagnostic tau_d_lid = w_lid_present * w_active * 2 * eta_i * v_m_raw / d_geom with smooth geometric length floor d_geom = _softmax2(r_top - r_lid_base, d_geom_floor, 0.01 * d_geom_floor) and d_geom_floor = _softmax2(delta_rh, dr_top, 0.01 * dr_top) (gated smoothly by w_lid_present = w_d * w_T * w_act_gate * w_sum_gate * w_weight; returns 0.0 in non-lid columns, and tau_d_lid / tau_d = d_conv / d_geom is bounded above by d_conv / max(delta_rh, dr_top) on incipient lids). has_lid is False when any input is NaN while numeric diagnostics propagate NaN. P_T_i and r_i are diagnostics, evaluated on the geotherm for a monotone T profile and as the W_tilde mean otherwise, and the two can differ by tens of GPa (no solver term reads them).

Raises:

Type Description
ValueError

If viscosity_solid, phi_rheo, or phi_width is None; if scalar parameters (viscosity_solid, phi_rheo, phi_width, a_rh_fb, C4) are non-scalar; if radii is not a 1-D array of at least 3 nodes; if any profile input does not match radii in 1-D length; if any input is non-real (such as a boolean, string, or complex value); or, on the eager NumPy path (xp is np), if radii is not strictly increasing or has inf values (NaN propagates), if any input is infinite, if viscosity_solid, phi_width, a_rh_fb, C4, temperature, solidus_temperature, viscosity_mixture, density, gravity, thermal_expansivity, or thermal_diffusivity is non-positive, if pressure is below -PRESSURE_ROUNDOFF_TOLERANCE (-1.0 Pa) or infinite, or if phi_rheo or melt_fraction lies outside [0, 1]. Under jax.jit, traced out-of-range numeric values (including non-increasing radii) propagate NaN through zero_or_nan.

Notes

See docs/Explanations/solid_state_convection.md for model formulation and derivations.

The Frank-Kamenetskii parameter theta, rheological temperature scale dT_rh, interior Arrhenius log-viscosity log10(eta_arr_i) (and thus eta_i when viscosity_mixture is None), and geotherm diagnostics (P_T_i, r_i) (on a monotone temperature profile) are endpoint-blended between the conduction-limit state 0 at node 1 (T_0 = T[1], P_0 = P[1]) and the convecting-interior boundary state 1 (T_1 = sum(W_Ti_tilde * T), P_1 = sum(W_Ti_tilde * P)): theta = w_eff * theta_1 + (1 - w_eff) * theta_0 and dT_rh = w_eff * dT_rh_1 + (1 - w_eff) * dT_rh_0, where theta_k = H_k * (T_k - T_surf) / (R_GAS * max(T_k, 1.0)**2) and dT_rh_k = R_GAS * max(T_k, 1.0)**2 / max(H_k, 1.0e-6) for k in {0, 1}, with w_eff = clip((T_0 - T_i) / (T_0 - T_1), 0.0, 1.0) when dT_ep_nz (|T_0 - T_1| > 1.0e-12) holds and w_weight otherwise. Activation enthalpy H_k = H(P_k) follows the homologous law H(P) = params.g_homologous * R_GAS * T_sol(P) when params.activation_energy is None (using t_sol_0 + dt_sol_dp * P when solidus_temperature is None), and the saturating integral law H(P) = E_a + V_0 * P_decay * (1 - exp(-P / P_decay)) when params.activation_energy is set (solidus_temperature, g_homologous, t_sol_0, and dt_sol_dp are not used in H(P) when params.activation_energy is set).

When convective layer weights place interior temperature T_i below lid base temperature T_lid (for example in cold_top_lid where T_i < T_lid), the solver evaluates theta and driving stress directly from the convective layer state T_i without clamping T_i to T_lid.

When convection is inactive or no physical conductive lid forms (d_lid_raw <= NO_LID_THICKNESS_THRESHOLD of 1.0 m or T_i - T_surf <= NO_LID_DT_THRESHOLD of 1.0e-3 K, where the w_active > 0.05 threshold sits at f_int_max = params.interior_flux_fraction + 0.01 * atanh(-0.9) = 0.035278 at the default interior_flux_fraction = 0.05), boundary-layer diagnostics (d_lid, Ra_eff, Ra_rh, v_m, tau_d, tau_d_lid, tau_buoy, tau_d_over_tau_buoy, w_y, lid_regime) are smoothly gated by w_lid_present = w_d * w_T * w_act_gate * w_sum_gate * w_weight (where w_d and w_sum_gate are \(C^0\) with a one-sided slope at the domain edge d_lid_raw >= 0 and W_sum >= 0, and w_T uses the \(C^1\) positive part where(dT_lid > 0, dT_lid * tanh(dT_lid / (0.3 * NO_LID_DT_WIDTH)), 0) so w_lid_present vanishes identically when d_lid_raw <= 0, T_i - T_surf <= 0, or W_sum <= 0) and has_lid is False, while T_i, eta_i, mu_i, and theta serve as interior fallback diagnostics and all solver-facing outputs vary continuously across uniform convective flux fractions f in [0, 1e-3]. Intentional non-smooth switches retained for boolean diagnostics and physical bounds include is_convecting, has_lid, the is_convecting gate on the diagnostic v_i, the cap of f at 1, f_int_max = max(f * interior_node_mask), max(T_0, 1.0), max(T_1, 1.0), max(H_0, 1.0e-6), max(H_1, 1.0e-6), the w_eff clip to [0, 1], dT_ep_nz, is_mono_T, the 1 - 1e-15 selectors on w_eff and w_weight, DeltaT_conv = max(T_i - T_surf, 1.0e-6), max(theta, 1.0e-6), max(Ra_rh_raw, 1.0e-30), the elementwise maxima in w_interior and w_hot_sol, the temperature-gradient floor dTdr_floor with max(dr_min, 1.0) in delta_rh, the domain-thickness cap r[-1] - r[0] on delta_rh, the COHESION_FLOOR clamp on yield stress, if_lid (where(w_lid_present >= 1 - 1e-12)), d_geom, the max in d_lid_raw, max(w_conv - w_conv_0, 0), f_int_scale, the v_m_raw branches, and the 1.0e-30 denominators (while the 5-node local interior RMS |F_tot| floor F_tot_floor = _softmax2(F_TOT_FLOOR_FRAC * F_loc_rms, 1.0e-12, 0.01 * 1.0e-12) replaces boundary nodes k = 0 and k = N - 1 by their adjacent interior nodes F_tot[1] and F_tot[N - 2] before 2-node edge replication, is continuous in every F_k, and differs from a scalar 1.0e-12 floor only at nodes where F_conv > 0 and |F_tot| < 0.0014 * F_loc_rms when 1.0e-3 * F_loc_rms >> 1.0e-12 W/m2).

The lid-base locator W_base_tilde = _boundary_weights(w_interior, xp)[0] scans w_interior (smoothed over the local cell temperature step scale = lid_mask_width_cells * _softmax2(|grad T|, 1.0 K, SCALE_FLOOR_WIDTH)) from the outermost node r[-1] inward, whereas the nodal lid mask w_lid = (1 - w_interior_mask) * w_active uses the smooth capped width scale_mask = _softmin2(scale, scale_cap, SCALE_MASK_REL_WIDTH * scale_cap) with scale_cap = lid_mask_width_cells * _softmax2(dT_rh, 1.0 K, SCALE_FLOOR_WIDTH). In 'fixed' mode (lid_base_mode = 'fixed'), both 1 - w_hot_iso and 1 - w_hot_iso_mask are multiplied by w_nonconv = 1 - _melt_ramp(f, f_thresh, 0.2 * f_thresh, compact=True) so a convecting node is never part of the lid; when no node is non-convecting (w_nonconv == 0 everywhere), w_interior == 1 on all nodes and r_lid_base sits at r[-1] with d_lid_raw = 0 and d_lid = 0. The solidus crossing indicators w_hot_sol and w_hot_sol_mask evaluate the compactly supported \(C^2\) quintic melt-fraction ramp w_sol_phi on [SOLIDUS_MELT_FRACTION_THRESHOLD - SOLIDUS_MELT_FRACTION_WIDTH, SOLIDUS_MELT_FRACTION_THRESHOLD + SOLIDUS_MELT_FRACTION_WIDTH] = [0.008, 0.012], so that w_sol_phi == 0 for phi <= 0.008 and w_sol_phi == 1 for phi >= 0.012, giving has_lid = False and d_lid = 0 for any column with phi >= 0.012 at every node across all mesh resolutions N.

Raises:

Type Description
ValueError

If any required parameter or array (radii, temperature, pressure, convective_flux, total_flux, melt_fraction, viscosity_solid, phi_rheo, phi_width) is None. If array dimensions or shapes do not match radii. If any scalar argument is array-valued or non-real. If radii is not strictly increasing.

Source code in src/aragog/rheology_lid.py
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
def compute_stagnant_lid_state(
    radii: FloatOrArray,
    temperature: FloatOrArray,
    pressure: FloatOrArray,
    convective_flux: FloatOrArray,
    total_flux: FloatOrArray,
    solidus_temperature: FloatOrArray | None,
    melt_fraction: FloatOrArray,
    params: Any,
    viscosity_solid: float,
    phi_rheo: float,
    phi_width: float,
    unyielded_velocity: FloatOrArray | None = None,
    viscosity_mixture: FloatOrArray | None = None,
    density: FloatOrArray = 3300.0,
    gravity: FloatOrArray = 9.81,
    thermal_expansivity: FloatOrArray = 3.0e-5,
    thermal_diffusivity: FloatOrArray = 1.0e-6,
    a_rh_fb: float = 1.3,
    C4: float = 0.125,
    xp: Any = np,
) -> dict[str, Any]:
    r"""Compute stagnant lid boundary-layer indicators and convective driving stress.

    Parameters
    ----------
    radii : array-like
        Radial grid coordinates r [m] from core to surface.
    temperature : array-like
        Radial temperature profile T [K].
    pressure : array-like
        Radial pressure profile P [Pa] (non-negative; negative round-off
        excursions down to ``-PRESSURE_ROUNDOFF_TOLERANCE`` = -1.0 Pa are
        clamped to 0.0 Pa).
    convective_flux : array-like
        Convective heat flux profile F_conv [W/m^2].
    total_flux : array-like
        Total heat flux profile F_tot [W/m^2].
    solidus_temperature : float or array-like or None
        Solidus temperature profile T_sol [K]. When provided, the solidus
        crossing indicators ``w_hot_sol`` and ``w_hot_sol_mask`` take the
        elementwise maximum of the thermal ``tanh((T - T_sol) / scale)`` ramp
        and the melt-fraction ramp centered at
        ``SOLIDUS_MELT_FRACTION_THRESHOLD`` (0.01). When None, they use the
        melt-fraction ramp alone. Not used in the activation enthalpy ``H(P)``
        when ``params.activation_energy`` is set.
    melt_fraction : array-like
        Melt mass fraction profile phi [-].
    params : SolidRheologyParams
        Rheology parameter set.
    viscosity_solid : float
        Reference solid mantle viscosity [Pa s] such that
        ``viscosity_solid * f_water`` equals ``eta_diff`` at
        ``(params.arrhenius_t_ref, P = 0)`` for the linear solidus and for the
        saturating activation law (``params.activation_energy`` set); when
        ``params.activation_energy`` is ``None`` and a ``solidus_temperature``
        table is provided, ``viscosity_solid`` is referenced to ``params.t_sol_0``,
        so the table ``eta_diff(T, 0)`` scales relative to the linear-solidus
        ``eta_diff(T, 0)`` at the same ``T`` by
        ``exp(g_hom * (T_sol(0) - params.t_sol_0) / T)`` (a ratio of 2.752, or
        2.75x, at 1600 K for 1464.8 K against 1400 K).
    phi_rheo : float
        Critical melt fraction for rheological transition [-].
    phi_width : float
        Transition width for rheological melt fraction indicator [-].
    unyielded_velocity : float or array-like, optional
        Unyielded convective velocity profile v [m/s].
    viscosity_mixture : float or array-like, optional
        Effective mixture viscosity profile [Pa s] of the convecting layer (in mush,
        the blended two-phase viscosity used by the solver). When provided, mu_i
        blends smoothly via ``w_weight = tanh(_smooth_max(w_conv_int) / 1e-6)``
        between the W_tilde-weighted log mean of ``viscosity_mixture`` and the
        solid Arrhenius viscosity ``eta_arr_i``; otherwise falls back to ``eta_arr_i``.
    density : float or array-like, default 3300.0
        Mantle density rho [kg/m^3].
    gravity : float or array-like, default 9.81
        Gravitational acceleration g [m/s^2].
    thermal_expansivity : float or array-like, default 3.0e-5
        Thermal expansivity alpha [1/K].
    thermal_diffusivity : float or array-like, default 1.0e-6
        Thermal diffusivity kappa [m^2/s].
    a_rh_fb : float, default 1.3
        Rheological sublayer parameter fitted with C4 in FB2014 (p. 589).
    C4 : float, default 0.125
        Convective velocity prefactor in FB2014 (Eq. 26, p. 586-587; p. 589).
    xp : array module, default np
        Array namespace module (numpy or jax.numpy).

    Returns
    -------
    dict[str, Any]
        Dictionary of boundary layer state diagnostics, including
        ``tau_d = w_lid_present * w_active * 2 * eta_i * v_m_raw / d_conv``
        and the lid-thickness-scaled stress diagnostic
        ``tau_d_lid = w_lid_present * w_active * 2 * eta_i * v_m_raw / d_geom``
        with smooth geometric length floor
        ``d_geom = _softmax2(r_top - r_lid_base, d_geom_floor, 0.01 * d_geom_floor)``
        and ``d_geom_floor = _softmax2(delta_rh, dr_top, 0.01 * dr_top)``
        (gated smoothly by ``w_lid_present = w_d * w_T * w_act_gate * w_sum_gate * w_weight``;
        returns 0.0 in non-lid columns, and ``tau_d_lid / tau_d = d_conv / d_geom``
        is bounded above by ``d_conv / max(delta_rh, dr_top)`` on incipient lids).
        ``has_lid`` is False when any input is NaN while numeric diagnostics propagate NaN.
        ``P_T_i`` and ``r_i`` are diagnostics, evaluated on the geotherm for a
        monotone ``T`` profile and as the ``W_tilde`` mean otherwise, and the
        two can differ by tens of GPa (no solver term reads them).

    Raises
    ------
    ValueError
        If ``viscosity_solid``, ``phi_rheo``, or ``phi_width`` is None; if
        scalar parameters (``viscosity_solid``, ``phi_rheo``, ``phi_width``,
        ``a_rh_fb``, ``C4``) are non-scalar; if ``radii``
        is not a 1-D array of at least 3 nodes; if any profile input does not
        match ``radii`` in 1-D length; if any input is non-real (such as a
        boolean, string, or complex value); or, on the eager NumPy path
        (``xp is np``), if ``radii`` is not strictly increasing or has ``inf``
        values (``NaN`` propagates), if any input is infinite, if
        ``viscosity_solid``, ``phi_width``, ``a_rh_fb``, ``C4``,
        ``temperature``, ``solidus_temperature``,
        ``viscosity_mixture``, ``density``, ``gravity``,
        ``thermal_expansivity``, or ``thermal_diffusivity`` is non-positive, if
        ``pressure`` is below ``-PRESSURE_ROUNDOFF_TOLERANCE`` (-1.0 Pa) or
        infinite, or if ``phi_rheo`` or ``melt_fraction`` lies
        outside ``[0, 1]``. Under ``jax.jit``, traced out-of-range numeric
        values (including non-increasing ``radii``) propagate ``NaN`` through
        ``zero_or_nan``.

    Notes
    -----
    See ``docs/Explanations/solid_state_convection.md`` for model formulation
    and derivations.

    The Frank-Kamenetskii parameter ``theta``, rheological temperature scale
    ``dT_rh``, interior Arrhenius log-viscosity ``log10(eta_arr_i)`` (and thus
    ``eta_i`` when ``viscosity_mixture`` is ``None``), and geotherm diagnostics
    ``(P_T_i, r_i)`` (on a monotone temperature profile) are endpoint-blended
    between the conduction-limit state 0 at node 1 ``(T_0 = T[1], P_0 = P[1])``
    and the convecting-interior boundary state 1
    ``(T_1 = sum(W_Ti_tilde * T), P_1 = sum(W_Ti_tilde * P))``:
    ``theta = w_eff * theta_1 + (1 - w_eff) * theta_0`` and
    ``dT_rh = w_eff * dT_rh_1 + (1 - w_eff) * dT_rh_0``, where
    ``theta_k = H_k * (T_k - T_surf) / (R_GAS * max(T_k, 1.0)**2)`` and
    ``dT_rh_k = R_GAS * max(T_k, 1.0)**2 / max(H_k, 1.0e-6)`` for ``k in {0, 1}``,
    with ``w_eff = clip((T_0 - T_i) / (T_0 - T_1), 0.0, 1.0)`` when
    ``dT_ep_nz`` (``|T_0 - T_1| > 1.0e-12``) holds and ``w_weight`` otherwise.
    Activation enthalpy ``H_k = H(P_k)`` follows the homologous law
    ``H(P) = params.g_homologous * R_GAS * T_sol(P)`` when
    ``params.activation_energy`` is ``None`` (using ``t_sol_0 + dt_sol_dp * P``
    when ``solidus_temperature`` is ``None``), and the saturating integral law
    ``H(P) = E_a + V_0 * P_decay * (1 - exp(-P / P_decay))`` when
    ``params.activation_energy`` is set (``solidus_temperature``, ``g_homologous``,
    ``t_sol_0``, and ``dt_sol_dp`` are not used in ``H(P)`` when
    ``params.activation_energy`` is set).

    When convective layer weights place interior temperature T_i below lid base
    temperature T_lid (for example in cold_top_lid where T_i < T_lid), the solver
    evaluates theta and driving stress directly from the convective layer state T_i
    without clamping T_i to T_lid.

    When convection is inactive or no physical conductive lid forms
    (``d_lid_raw <= NO_LID_THICKNESS_THRESHOLD`` of 1.0 m or
    ``T_i - T_surf <= NO_LID_DT_THRESHOLD`` of 1.0e-3 K, where the ``w_active > 0.05``
    threshold sits at ``f_int_max = params.interior_flux_fraction + 0.01 * atanh(-0.9) = 0.035278``
    at the default ``interior_flux_fraction = 0.05``), boundary-layer diagnostics
    (``d_lid``, ``Ra_eff``, ``Ra_rh``, ``v_m``, ``tau_d``, ``tau_d_lid``,
    ``tau_buoy``, ``tau_d_over_tau_buoy``, ``w_y``, ``lid_regime``) are smoothly
    gated by ``w_lid_present = w_d * w_T * w_act_gate * w_sum_gate * w_weight``
    (where ``w_d`` and ``w_sum_gate`` are $C^0$ with a one-sided slope at the
    domain edge ``d_lid_raw >= 0`` and ``W_sum >= 0``, and ``w_T`` uses the $C^1$
    positive part ``where(dT_lid > 0, dT_lid * tanh(dT_lid / (0.3 * NO_LID_DT_WIDTH)), 0)``
    so ``w_lid_present`` vanishes identically when ``d_lid_raw <= 0``,
    ``T_i - T_surf <= 0``, or ``W_sum <= 0``) and ``has_lid`` is False, while
    ``T_i``, ``eta_i``, ``mu_i``, and ``theta`` serve as interior fallback
    diagnostics and all solver-facing outputs vary continuously across uniform
    convective flux fractions ``f`` in ``[0, 1e-3]``. Intentional non-smooth
    switches retained for boolean diagnostics and physical bounds include
    ``is_convecting``, ``has_lid``, the ``is_convecting`` gate on the diagnostic
    ``v_i``, the cap of ``f`` at 1, ``f_int_max = max(f * interior_node_mask)``,
    ``max(T_0, 1.0)``, ``max(T_1, 1.0)``, ``max(H_0, 1.0e-6)``, ``max(H_1, 1.0e-6)``,
    the ``w_eff`` clip to ``[0, 1]``, ``dT_ep_nz``, ``is_mono_T``, the ``1 - 1e-15``
    selectors on ``w_eff`` and ``w_weight``,
    ``DeltaT_conv = max(T_i - T_surf, 1.0e-6)``, ``max(theta, 1.0e-6)``,
    ``max(Ra_rh_raw, 1.0e-30)``, the elementwise maxima in ``w_interior`` and
    ``w_hot_sol``, the temperature-gradient floor ``dTdr_floor`` with
    ``max(dr_min, 1.0)`` in ``delta_rh``, the domain-thickness cap ``r[-1] - r[0]``
    on ``delta_rh``, the ``COHESION_FLOOR`` clamp on yield stress,
    ``if_lid`` (``where(w_lid_present >= 1 - 1e-12)``), ``d_geom``, the max in
    ``d_lid_raw``, ``max(w_conv - w_conv_0, 0)``, ``f_int_scale``, the
    ``v_m_raw`` branches, and the ``1.0e-30`` denominators (while the
    5-node local interior RMS ``|F_tot|`` floor
    ``F_tot_floor = _softmax2(F_TOT_FLOOR_FRAC * F_loc_rms, 1.0e-12, 0.01 * 1.0e-12)``
    replaces boundary nodes ``k = 0`` and ``k = N - 1`` by their adjacent interior
    nodes ``F_tot[1]`` and ``F_tot[N - 2]`` before 2-node edge replication, is
    continuous in every ``F_k``, and differs from a scalar ``1.0e-12`` floor only at
    nodes where ``F_conv > 0`` and ``|F_tot| < 0.0014 * F_loc_rms`` when
    ``1.0e-3 * F_loc_rms >> 1.0e-12 W/m2``).

    The lid-base locator ``W_base_tilde = _boundary_weights(w_interior, xp)[0]`` scans
    ``w_interior`` (smoothed over the local cell temperature step
    ``scale = lid_mask_width_cells * _softmax2(|grad T|, 1.0 K, SCALE_FLOOR_WIDTH)``) from
    the outermost node ``r[-1]`` inward, whereas the nodal lid mask
    ``w_lid = (1 - w_interior_mask) * w_active`` uses the smooth capped width
    ``scale_mask = _softmin2(scale, scale_cap, SCALE_MASK_REL_WIDTH * scale_cap)`` with
    ``scale_cap = lid_mask_width_cells * _softmax2(dT_rh, 1.0 K, SCALE_FLOOR_WIDTH)``.
    In ``'fixed'`` mode (``lid_base_mode = 'fixed'``), both ``1 - w_hot_iso`` and
    ``1 - w_hot_iso_mask`` are multiplied by
    ``w_nonconv = 1 - _melt_ramp(f, f_thresh, 0.2 * f_thresh, compact=True)``
    so a convecting node is never part of the lid; when no node is non-convecting
    (``w_nonconv == 0`` everywhere), ``w_interior == 1`` on all nodes and ``r_lid_base``
    sits at ``r[-1]`` with ``d_lid_raw = 0`` and ``d_lid = 0``.
    The solidus crossing indicators ``w_hot_sol`` and ``w_hot_sol_mask`` evaluate the
    compactly supported $C^2$ quintic melt-fraction ramp ``w_sol_phi`` on
    ``[SOLIDUS_MELT_FRACTION_THRESHOLD - SOLIDUS_MELT_FRACTION_WIDTH,
    SOLIDUS_MELT_FRACTION_THRESHOLD + SOLIDUS_MELT_FRACTION_WIDTH] = [0.008, 0.012]``,
    so that ``w_sol_phi == 0`` for ``phi <= 0.008`` and ``w_sol_phi == 1`` for
    ``phi >= 0.012``, giving ``has_lid = False`` and ``d_lid = 0`` for any column
    with ``phi >= 0.012`` at every node across all mesh resolutions ``N``.

    Raises
    ------
    ValueError
        If any required parameter or array (``radii``, ``temperature``,
        ``pressure``, ``convective_flux``, ``total_flux``, ``melt_fraction``,
        ``viscosity_solid``, ``phi_rheo``, ``phi_width``) is None.
        If array dimensions or shapes do not match ``radii``.
        If any scalar argument is array-valued or non-real.
        If ``radii`` is not strictly increasing.
    """
    _require_x64_if_jax(xp)
    if viscosity_solid is None or phi_rheo is None or phi_width is None:
        raise ValueError('viscosity_solid, phi_rheo, and phi_width must be provided')
    if _is_non_real(radii):
        raise ValueError(f'radii must be a real number or array, got {radii!r}')
    r = xp.asarray(radii, dtype=float)
    if r.ndim != 1 or r.shape[0] < 3:
        raise ValueError('radii must be a 1-D array with at least 3 nodes')
    try:
        r_np = np.asarray(r, dtype=float)
    except Exception:
        r_np = None
    if r_np is not None:
        dr_np = r_np[1:] - r_np[:-1]
        if np.any(np.isinf(r_np)) or np.any(np.isinf(dr_np) | (dr_np <= 0.0)):
            raise ValueError('radii must be strictly increasing from core to surface')
    for name, val, allow_scalar in (
        ('temperature', temperature, False),
        ('pressure', pressure, False),
        ('convective_flux', convective_flux, False),
        ('total_flux', total_flux, False),
        ('melt_fraction', melt_fraction, False),
        ('solidus_temperature', solidus_temperature, True),
        ('unyielded_velocity', unyielded_velocity, True),
        ('viscosity_mixture', viscosity_mixture, True),
        ('density', density, True),
        ('gravity', gravity, True),
        ('thermal_expansivity', thermal_expansivity, True),
        ('thermal_diffusivity', thermal_diffusivity, True),
    ):
        if val is None:
            if not allow_scalar:
                raise ValueError(f'{name} must be a real number or array, got None')
            continue
        if _is_non_real(val):
            raise ValueError(f'{name} must be a real number or array, got {val!r}')
        a = xp.asarray(val, dtype=float)
        if not ((allow_scalar and a.ndim == 0) or (a.ndim == 1 and a.shape[0] == r.shape[0])):
            raise ValueError(f'{name} must have the same 1-D length as radii ({r.shape[0]})')

    invalid_inputs = _validate_inputs(
        (
            ('viscosity_solid', viscosity_solid, 'pos', True),
            ('phi_width', phi_width, 'pos', True),
            ('phi_rheo', phi_rheo, 'unit', True),
            ('a_rh_fb', a_rh_fb, 'pos', True),
            ('C4', C4, 'pos', True),
            ('radii', radii, 'finite', False),
            ('temperature', temperature, 'pos', False),
            ('pressure', pressure, 'pressure', False),
            ('convective_flux', convective_flux, 'finite', False),
            ('total_flux', total_flux, 'finite', False),
            ('melt_fraction', melt_fraction, 'unit', False),
            ('solidus_temperature', solidus_temperature, 'pos', False),
            ('unyielded_velocity', unyielded_velocity, 'finite', False),
            ('viscosity_mixture', viscosity_mixture, 'pos', False),
            ('density', density, 'pos', False),
            ('gravity', gravity, 'pos', False),
            ('thermal_expansivity', thermal_expansivity, 'pos', False),
            ('thermal_diffusivity', thermal_diffusivity, 'pos', False),
        ),
        xp,
        reduce_any=True,
    )
    invalid_inputs = invalid_inputs | _vmax_not_above_log10_viscosity(
        viscosity_solid, params.viscosity_max_log10, xp
    )
    # Evaluates _boundary_weights(w_Ti, xp, fallback=W_conv_tilde) inside the core helper.
    return _compute_stagnant_lid_state_core(
        radii=radii,
        temperature=temperature,
        pressure=pressure,
        convective_flux=convective_flux,
        total_flux=total_flux,
        solidus_temperature=solidus_temperature,
        melt_fraction=melt_fraction,
        params=params,
        viscosity_solid=viscosity_solid,
        phi_rheo=phi_rheo,
        phi_width=phi_width,
        unyielded_velocity=unyielded_velocity,
        viscosity_mixture=viscosity_mixture,
        density=density,
        gravity=gravity,
        thermal_expansivity=thermal_expansivity,
        thermal_diffusivity=thermal_diffusivity,
        a_rh_fb=a_rh_fb,
        C4=C4,
        xp=xp,
        _invalid_inputs=invalid_inputs,
        _use_public_kernels=True,
    )

stress_closure(mode, viscous_velocity, mixing_length=None, eps=1e-15, xp=np)

Calculate strain rate dispatching on stress closure mode.

Parameters:

Name Type Description Default
mode str

Stress closure mode; 'local' evaluates local strain rate via :func:~aragog.rheology.compute_strain_rate_local, while 'lid' uses boundary-layer stress closure via :func:compute_stagnant_lid_state.

required
viscous_velocity FloatOrArray

Viscous convective velocity [m/s], finite real scalar or array in (-inf, +inf).

required
mixing_length FloatOrArray or None

Convective mixing length [m], non-negative and finite in [0, +inf); required when mode='local'.

None
eps float

Positive regularisation scale [m] for mixing_length in (0, +inf).

1.0e-15
xp module

Array backend (numpy or jax.numpy).

numpy

Returns:

Type Description
FloatOrArray

Local convective strain rate [1/s], non-negative in [0, +inf).

Raises:

Type Description
ValueError

If mode is 'lid' (which uses :func:compute_stagnant_lid_state instead of a local strain-rate dispatch), 'global' (unsupported), or any value other than 'local', if mixing_length is None when mode='local', or if inputs violate the domain of :func:~aragog.rheology.compute_strain_rate_local.

Source code in src/aragog/rheology_lid.py
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
def stress_closure(
    mode: str,
    viscous_velocity: FloatOrArray,
    mixing_length: FloatOrArray | None = None,
    eps: float = 1.0e-15,
    xp: Any = np,
) -> FloatOrArray:
    r"""Calculate strain rate dispatching on stress closure mode.

    Parameters
    ----------
    mode : str
        Stress closure mode; ``'local'`` evaluates local strain rate via
        :func:`~aragog.rheology.compute_strain_rate_local`, while ``'lid'``
        uses boundary-layer stress closure via :func:`compute_stagnant_lid_state`.
    viscous_velocity : FloatOrArray
        Viscous convective velocity [m/s], finite real scalar or array in
        ``(-inf, +inf)``.
    mixing_length : FloatOrArray or None, default None
        Convective mixing length [m], non-negative and finite in ``[0, +inf)``;
        required when ``mode='local'``.
    eps : float, default 1.0e-15
        Positive regularisation scale [m] for ``mixing_length`` in
        ``(0, +inf)``.
    xp : module, default numpy
        Array backend (``numpy`` or ``jax.numpy``).

    Returns
    -------
    FloatOrArray
        Local convective strain rate [1/s], non-negative in ``[0, +inf)``.

    Raises
    ------
    ValueError
        If ``mode`` is ``'lid'`` (which uses :func:`compute_stagnant_lid_state`
        instead of a local strain-rate dispatch), ``'global'`` (unsupported),
        or any value other than ``'local'``, if ``mixing_length`` is ``None``
        when ``mode='local'``, or if inputs violate the domain of
        :func:`~aragog.rheology.compute_strain_rate_local`.
    """
    _require_x64_if_jax(xp)
    if mode == 'local':
        if mixing_length is None:
            raise ValueError("mixing_length must be provided when mode='local'")
        return compute_strain_rate_local(viscous_velocity, mixing_length, eps=eps, xp=xp)
    elif mode == 'global':
        raise ValueError(
            "Unknown stress closure mode 'global'; expected 'lid' or 'local'. "
            "'global' mode is unsupported; use 'lid'."
        )
    elif mode == 'lid':
        raise ValueError(
            "Mode 'lid' uses boundary-layer stress closure via compute_stagnant_lid_state"
        )
    else:
        raise ValueError(f"Unknown stress closure mode {mode!r}; expected 'lid' or 'local'")