From 4f2f6b83d52f259d4057bde6e060ee35325e1479 Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Fri, 13 Oct 2023 10:12:11 -0600 Subject: [PATCH] Clean up marbl_abio_dic_surface_flux_mod Turned some divisions into multiplications, cleaned up local variable names, and added a new settings variable to control whether we compute the derivative diagnostics. Also fixed a missing-import bug in MARBL_share.py --- MARBL_tools/MARBL_share.py | 3 + defaults/diagnostics_latest.yaml | 3 + defaults/json/diagnostics_latest.json | 9 +- defaults/json/settings_cesm2.0.json | 8 + defaults/json/settings_cesm2.1+cocco.json | 8 + defaults/json/settings_cesm2.1.json | 8 + defaults/json/settings_latest+4p2z.json | 8 + defaults/json/settings_latest+cocco.json | 8 + defaults/json/settings_latest.json | 9 ++ defaults/settings_cesm2.0.yaml | 7 + defaults/settings_cesm2.1+cocco.yaml | 7 + defaults/settings_cesm2.1.yaml | 7 + defaults/settings_latest+4p2z.yaml | 7 + defaults/settings_latest+cocco.yaml | 7 + defaults/settings_latest.yaml | 8 + src/marbl_abio_dic_diagnostics_mod.F90 | 79 +++++----- src/marbl_abio_dic_surface_flux_mod.F90 | 141 +++++++++--------- src/marbl_settings_mod.F90 | 13 ++ .../settings/marbl_with_abio_only.settings | 1 + 19 files changed, 232 insertions(+), 109 deletions(-) diff --git a/MARBL_tools/MARBL_share.py b/MARBL_tools/MARBL_share.py index 25f4f705..c0a9b379 100644 --- a/MARBL_tools/MARBL_share.py +++ b/MARBL_tools/MARBL_share.py @@ -221,6 +221,9 @@ def expand_template_value(key_name, MARBL_settings, unit_system, unprocessed_dic ################################################################################ def meet_dependencies(input_dict, MARBL_settings): + import logging + logger = logging.getLogger(__name__) + if "dependencies" in input_dict.keys(): for dependency in input_dict["dependencies"].keys(): if dependency not in MARBL_settings.settings_dict.keys(): diff --git a/defaults/diagnostics_latest.yaml b/defaults/diagnostics_latest.yaml index 3b98a922..82128fa0 100644 --- a/defaults/diagnostics_latest.yaml +++ b/defaults/diagnostics_latest.yaml @@ -307,6 +307,7 @@ ABIO_FG_DI14C : d_SF_ABIO_DIC_d_ABIO_DIC : dependencies : abio_dic_on : .true. + labio_derivative_diags : .true. longname : Derivative of STF_ABIO_DIC wrt ABIO_DIC units : cm/s vertical_grid : none @@ -315,6 +316,7 @@ d_SF_ABIO_DIC_d_ABIO_DIC : d_SF_ABIO_DI14C_d_ABIO_DIC : dependencies : abio_dic_on : .true. + labio_derivative_diags : .true. longname : Derivative of STF_ABIO_DI14C wrt ABIO_DIC units : cm/s vertical_grid : none @@ -323,6 +325,7 @@ d_SF_ABIO_DI14C_d_ABIO_DIC : d_SF_ABIO_DI14C_d_ABIO_DI14C : dependencies : abio_dic_on : .true. + labio_derivative_diags : .true. longname : Derivative of STF_ABIO_DI14C wrt ABIO_DI14C units : cm/s vertical_grid : none diff --git a/defaults/json/diagnostics_latest.json b/defaults/json/diagnostics_latest.json index 1512702b..c076351a 100644 --- a/defaults/json/diagnostics_latest.json +++ b/defaults/json/diagnostics_latest.json @@ -2363,7 +2363,8 @@ }, "d_SF_ABIO_DI14C_d_ABIO_DI14C": { "dependencies": { - "abio_dic_on": ".true." + "abio_dic_on": ".true.", + "labio_derivative_diags": ".true." }, "frequency": "never", "longname": "Derivative of STF_ABIO_DI14C wrt ABIO_DI14C", @@ -2373,7 +2374,8 @@ }, "d_SF_ABIO_DI14C_d_ABIO_DIC": { "dependencies": { - "abio_dic_on": ".true." + "abio_dic_on": ".true.", + "labio_derivative_diags": ".true." }, "frequency": "never", "longname": "Derivative of STF_ABIO_DI14C wrt ABIO_DIC", @@ -2383,7 +2385,8 @@ }, "d_SF_ABIO_DIC_d_ABIO_DIC": { "dependencies": { - "abio_dic_on": ".true." + "abio_dic_on": ".true.", + "labio_derivative_diags": ".true." }, "frequency": "never", "longname": "Derivative of STF_ABIO_DIC wrt ABIO_DIC", diff --git a/defaults/json/settings_cesm2.0.json b/defaults/json/settings_cesm2.0.json index 30763755..d989bfca 100644 --- a/defaults/json/settings_cesm2.0.json +++ b/defaults/json/settings_cesm2.0.json @@ -1097,6 +1097,14 @@ "subcategory": "5. general parameters", "units": 1 }, + "labio_derivative_diags": { + "datatype": "logical", + "default_value": ".false.", + "dependencies": "abio_dic_on", + "longname": "Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov)", + "subcategory": "3. config flags", + "units": "unitless" + }, "ladjust_bury_coeff": { "_append_to_config_keywords": true, "datatype": "logical", diff --git a/defaults/json/settings_cesm2.1+cocco.json b/defaults/json/settings_cesm2.1+cocco.json index 28f7f47e..73124350 100644 --- a/defaults/json/settings_cesm2.1+cocco.json +++ b/defaults/json/settings_cesm2.1+cocco.json @@ -1139,6 +1139,14 @@ "subcategory": "5. general parameters", "units": 1 }, + "labio_derivative_diags": { + "datatype": "logical", + "default_value": ".false.", + "dependencies": "abio_dic_on", + "longname": "Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov)", + "subcategory": "3. config flags", + "units": "unitless" + }, "ladjust_bury_coeff": { "_append_to_config_keywords": true, "datatype": "logical", diff --git a/defaults/json/settings_cesm2.1.json b/defaults/json/settings_cesm2.1.json index d2c3de83..7b0c8730 100644 --- a/defaults/json/settings_cesm2.1.json +++ b/defaults/json/settings_cesm2.1.json @@ -1097,6 +1097,14 @@ "subcategory": "5. general parameters", "units": 1 }, + "labio_derivative_diags": { + "datatype": "logical", + "default_value": ".false.", + "dependencies": "abio_dic_on", + "longname": "Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov)", + "subcategory": "3. config flags", + "units": "unitless" + }, "ladjust_bury_coeff": { "_append_to_config_keywords": true, "datatype": "logical", diff --git a/defaults/json/settings_latest+4p2z.json b/defaults/json/settings_latest+4p2z.json index ffae6fdb..59e4f119 100644 --- a/defaults/json/settings_latest+4p2z.json +++ b/defaults/json/settings_latest+4p2z.json @@ -1192,6 +1192,14 @@ "subcategory": "5. general parameters", "units": 1 }, + "labio_derivative_diags": { + "datatype": "logical", + "default_value": ".false.", + "dependencies": "abio_dic_on", + "longname": "Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov)", + "subcategory": "3. config flags", + "units": "unitless" + }, "ladjust_bury_coeff": { "_append_to_config_keywords": true, "datatype": "logical", diff --git a/defaults/json/settings_latest+cocco.json b/defaults/json/settings_latest+cocco.json index 6ea8f0cd..ab8a6421 100644 --- a/defaults/json/settings_latest+cocco.json +++ b/defaults/json/settings_latest+cocco.json @@ -1139,6 +1139,14 @@ "subcategory": "5. general parameters", "units": 1 }, + "labio_derivative_diags": { + "datatype": "logical", + "default_value": ".false.", + "dependencies": "abio_dic_on", + "longname": "Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov)", + "subcategory": "3. config flags", + "units": "unitless" + }, "ladjust_bury_coeff": { "_append_to_config_keywords": true, "datatype": "logical", diff --git a/defaults/json/settings_latest.json b/defaults/json/settings_latest.json index 3c57b918..68ba6bc0 100644 --- a/defaults/json/settings_latest.json +++ b/defaults/json/settings_latest.json @@ -1103,6 +1103,14 @@ "subcategory": "5. general parameters", "units": 1 }, + "labio_derivative_diags": { + "datatype": "logical", + "default_value": ".false.", + "dependencies": "abio_dic_on", + "longname": "Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov)", + "subcategory": "3. config flags", + "units": "unitless" + }, "ladjust_bury_coeff": { "_append_to_config_keywords": true, "datatype": "logical", @@ -1519,6 +1527,7 @@ }, "tracer_modules": { "abio_dic_on": { + "_append_to_config_keywords": true, "datatype": "logical", "default_value": ".false.", "longname": "Control whether abiotic carbon tracer module is active", diff --git a/defaults/settings_cesm2.0.yaml b/defaults/settings_cesm2.0.yaml index 05fa8cc4..9be372ea 100644 --- a/defaults/settings_cesm2.0.yaml +++ b/defaults/settings_cesm2.0.yaml @@ -374,6 +374,13 @@ general_parms : units : unitless datatype : logical default_value : .false. + labio_derivative_diags : + dependencies : abio_dic_on + longname : Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov) + subcategory : 3. config flags + units : unitless + datatype : logical + default_value : .false. bftt_dz_sum_thres: dependencies : base_bio_on longname : MARBL will abort if abs(1 - sum(bot_flux_to_tend)) exceeds this threshold diff --git a/defaults/settings_cesm2.1+cocco.yaml b/defaults/settings_cesm2.1+cocco.yaml index 0cbf6f54..afb8a369 100644 --- a/defaults/settings_cesm2.1+cocco.yaml +++ b/defaults/settings_cesm2.1+cocco.yaml @@ -378,6 +378,13 @@ general_parms : units : unitless datatype : logical default_value : .false. + labio_derivative_diags : + dependencies : abio_dic_on + longname : Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov) + subcategory : 3. config flags + units : unitless + datatype : logical + default_value : .false. bftt_dz_sum_thres: dependencies : base_bio_on longname : MARBL will abort if abs(1 - sum(bot_flux_to_tend)) exceeds this threshold diff --git a/defaults/settings_cesm2.1.yaml b/defaults/settings_cesm2.1.yaml index d985531c..ebc8871e 100644 --- a/defaults/settings_cesm2.1.yaml +++ b/defaults/settings_cesm2.1.yaml @@ -376,6 +376,13 @@ general_parms : units : unitless datatype : logical default_value : .false. + labio_derivative_diags : + dependencies : abio_dic_on + longname : Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov) + subcategory : 3. config flags + units : unitless + datatype : logical + default_value : .false. bftt_dz_sum_thres: dependencies : base_bio_on longname : MARBL will abort if abs(1 - sum(bot_flux_to_tend)) exceeds this threshold diff --git a/defaults/settings_latest+4p2z.yaml b/defaults/settings_latest+4p2z.yaml index fdc4d912..0eac3a76 100644 --- a/defaults/settings_latest+4p2z.yaml +++ b/defaults/settings_latest+4p2z.yaml @@ -394,6 +394,13 @@ general_parms : units : unitless datatype : logical default_value : .false. + labio_derivative_diags : + dependencies : abio_dic_on + longname : Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov) + subcategory : 3. config flags + units : unitless + datatype : logical + default_value : .false. bftt_dz_sum_thres: dependencies : base_bio_on longname : MARBL will abort if abs(1 - sum(bot_flux_to_tend)) exceeds this threshold diff --git a/defaults/settings_latest+cocco.yaml b/defaults/settings_latest+cocco.yaml index 81a2f01b..940d4715 100644 --- a/defaults/settings_latest+cocco.yaml +++ b/defaults/settings_latest+cocco.yaml @@ -378,6 +378,13 @@ general_parms : units : unitless datatype : logical default_value : .false. + labio_derivative_diags : + dependencies : abio_dic_on + longname : Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov) + subcategory : 3. config flags + units : unitless + datatype : logical + default_value : .false. bftt_dz_sum_thres: dependencies : base_bio_on longname : MARBL will abort if abs(1 - sum(bot_flux_to_tend)) exceeds this threshold diff --git a/defaults/settings_latest.yaml b/defaults/settings_latest.yaml index 162d6875..b2affdcf 100644 --- a/defaults/settings_latest.yaml +++ b/defaults/settings_latest.yaml @@ -263,6 +263,7 @@ tracer_modules : units : unitless datatype : logical default_value : .false. + _append_to_config_keywords : true ciso_on : longname : Control whether CISO tracer module is active subcategory : 1. tracer modules @@ -377,6 +378,13 @@ general_parms : units : unitless datatype : logical default_value : .false. + labio_derivative_diags : + dependencies : abio_dic_on + longname : Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov) + subcategory : 3. config flags + units : unitless + datatype : logical + default_value : .false. bftt_dz_sum_thres: dependencies : base_bio_on longname : MARBL will abort if abs(1 - sum(bot_flux_to_tend)) exceeds this threshold diff --git a/src/marbl_abio_dic_diagnostics_mod.F90 b/src/marbl_abio_dic_diagnostics_mod.F90 index 818a2e82..0ab66fc9 100644 --- a/src/marbl_abio_dic_diagnostics_mod.F90 +++ b/src/marbl_abio_dic_diagnostics_mod.F90 @@ -8,6 +8,7 @@ module marbl_abio_dic_diagnostics_mod use marbl_kinds_mod, only : char_len use marbl_settings_mod, only : unit_system_type + use marbl_settings_mod, only : labio_derivative_diags use marbl_interface_public_types, only : marbl_diagnostics_type @@ -187,40 +188,42 @@ subroutine marbl_abio_dic_diagnostics_init( & return end if - lname = 'Derivative of STF_ABIO_DIC wrt ABIO_DIC' - sname = 'd_SF_ABIO_DIC_d_ABIO_DIC' - units = vel_units - vgrid = 'none' - truncate = .false. - call diags%add_diagnostic(lname, sname, units, vgrid, truncate, & - ind%d_SF_ABIO_DIC_d_ABIO_DIC, marbl_status_log) - if (marbl_status_log%labort_marbl) then - call marbl_logging_add_diagnostics_error(marbl_status_log, sname, subname) - return - end if - - lname = 'Derivative of STF_ABIO_DI14C wrt ABIO_DIC' - sname = 'd_SF_ABIO_DI14C_d_ABIO_DIC' - units = vel_units - vgrid = 'none' - truncate = .false. - call diags%add_diagnostic(lname, sname, units, vgrid, truncate, & - ind%d_SF_ABIO_DI14C_d_ABIO_DIC, marbl_status_log) - if (marbl_status_log%labort_marbl) then - call marbl_logging_add_diagnostics_error(marbl_status_log, sname, subname) - return - end if - - lname = 'Derivative of STF_ABIO_DI14C wrt ABIO_DI14C' - sname = 'd_SF_ABIO_DI14C_d_ABIO_DI14C' - units = vel_units - vgrid = 'none' - truncate = .false. - call diags%add_diagnostic(lname, sname, units, vgrid, truncate, & - ind%d_SF_ABIO_DI14C_d_ABIO_DI14C, marbl_status_log) - if (marbl_status_log%labort_marbl) then - call marbl_logging_add_diagnostics_error(marbl_status_log, sname, subname) - return + if (labio_derivative_diags) then + lname = 'Derivative of STF_ABIO_DIC wrt ABIO_DIC' + sname = 'd_SF_ABIO_DIC_d_ABIO_DIC' + units = vel_units + vgrid = 'none' + truncate = .false. + call diags%add_diagnostic(lname, sname, units, vgrid, truncate, & + ind%d_SF_ABIO_DIC_d_ABIO_DIC, marbl_status_log) + if (marbl_status_log%labort_marbl) then + call marbl_logging_add_diagnostics_error(marbl_status_log, sname, subname) + return + end if + + lname = 'Derivative of STF_ABIO_DI14C wrt ABIO_DIC' + sname = 'd_SF_ABIO_DI14C_d_ABIO_DIC' + units = vel_units + vgrid = 'none' + truncate = .false. + call diags%add_diagnostic(lname, sname, units, vgrid, truncate, & + ind%d_SF_ABIO_DI14C_d_ABIO_DIC, marbl_status_log) + if (marbl_status_log%labort_marbl) then + call marbl_logging_add_diagnostics_error(marbl_status_log, sname, subname) + return + end if + + lname = 'Derivative of STF_ABIO_DI14C wrt ABIO_DI14C' + sname = 'd_SF_ABIO_DI14C_d_ABIO_DI14C' + units = vel_units + vgrid = 'none' + truncate = .false. + call diags%add_diagnostic(lname, sname, units, vgrid, truncate, & + ind%d_SF_ABIO_DI14C_d_ABIO_DI14C, marbl_status_log) + if (marbl_status_log%labort_marbl) then + call marbl_logging_add_diagnostics_error(marbl_status_log, sname, subname) + return + end if end if end associate @@ -297,9 +300,11 @@ subroutine marbl_abio_dic_diagnostics_surface_flux_compute( & diags(ind%ABIO_ALK_SURF)%field_2d(:) = alk_surf(:) diags(ind%ABIO_FG_DIC)%field_2d(:) = fg_dic(:) diags(ind%ABIO_FG_DI14C)%field_2d(:) = fg_di14c(:) - diags(ind%d_SF_ABIO_DIC_d_ABIO_DIC)%field_2d(:) = derivative_terms(:,1) - diags(ind%d_SF_ABIO_DI14C_d_ABIO_DIC)%field_2d(:) = derivative_terms(:,2) - diags(ind%d_SF_ABIO_DI14C_d_ABIO_DI14C)%field_2d(:) = derivative_terms(:,3) + if (labio_derivative_diags) then + diags(ind%d_SF_ABIO_DIC_d_ABIO_DIC)%field_2d(:) = derivative_terms(:,1) + diags(ind%d_SF_ABIO_DI14C_d_ABIO_DIC)%field_2d(:) = derivative_terms(:,2) + diags(ind%d_SF_ABIO_DI14C_d_ABIO_DI14C)%field_2d(:) = derivative_terms(:,3) + end if end associate diff --git a/src/marbl_abio_dic_surface_flux_mod.F90 b/src/marbl_abio_dic_surface_flux_mod.F90 index efcc88c1..1ef2668b 100644 --- a/src/marbl_abio_dic_surface_flux_mod.F90 +++ b/src/marbl_abio_dic_surface_flux_mod.F90 @@ -14,6 +14,7 @@ module marbl_abio_dic_surface_flux_mod use marbl_settings_mod, only : phlo_surf_init use marbl_settings_mod, only : phhi_surf_init use marbl_settings_mod, only : abio_dic_on + use marbl_settings_mod, only : labio_derivative_diags use marbl_interface_private_types, only : marbl_tracer_index_type use marbl_interface_private_types, only : marbl_surface_flux_saved_state_indexing_type @@ -87,15 +88,15 @@ subroutine marbl_abio_dic_surface_flux_compute(& real(r8) :: dpco2(num_elements) real(r8) :: co3(num_elements) ! Terms for computing derivative diagnostics - real(r8) :: ph_surf_tmp(num_elements) - real(r8) :: phlo_tmp(num_elements) - real(r8) :: phhi_tmp(num_elements) - real(r8) :: co2star_tmp1(num_elements) - real(r8) :: co2star_tmp2(num_elements) - real(r8) :: dco2star_tmp(num_elements) - real(r8) :: pco2surf_tmp(num_elements) - real(r8) :: dpco2_tmp(num_elements) - real(r8) :: co3_tmp(num_elements) + real(r8) :: ph_surf_pert(num_elements) + real(r8) :: phlo_pert(num_elements) + real(r8) :: phhi_pert(num_elements) + real(r8) :: co2star_pert_p1(num_elements) + real(r8) :: co2star_pert_m1(num_elements) + real(r8) :: dco2star_pert(num_elements) + real(r8) :: pco2surf_pert(num_elements) + real(r8) :: dpco2_pert(num_elements) + real(r8) :: co3_pert(num_elements) real(r8) :: derivative_terms(num_elements, 3) ! d[SF_ABIO_DIC]/d[ABIO_DIC] ! d[SF_ABIO_DI14C]/d[ABIO_DIC] ! d[SF_ABIO_DI14C]/d[ABIO_DI14C] @@ -136,7 +137,7 @@ subroutine marbl_abio_dic_surface_flux_compute(& else where R14C_ocn = c0 end where - R14C_atm = c1 + d14c(:) / 1000._r8 + R14C_atm = c1 + d14c(:) * 1.0e-3_r8 !----------------------------------------------------------------------- ! Use constant concentrations of silicate and phosphate @@ -159,15 +160,15 @@ subroutine marbl_abio_dic_surface_flux_compute(& phlo(:) = phlo_surf_init phhi(:) = phhi_surf_init end where - phlo_tmp(:) = phlo(:) - phhi_tmp(:) = phhi(:) + phlo_pert(:) = phlo(:) + phhi_pert(:) = phhi(:) ! In POP, ALK_bar_global = 2310._r8 microeq/kg = 2310._r8 neq/g ! and ocn_ref_salinity comes from shr_const (SHR_CONST_OCN_REF_SAL = 34.7) ! Orr et al eq (27): ! 2297 micromol / kg ! Sbar = "global- and annual- mean salinity" - alk_surf(:) = (2310._r8 * (unit_system%nmol2mol_prefix * unit_system%mass2g)) * rho_sw * sss(:) / 34.7_r8 + alk_surf(:) = (2310._r8 * (unit_system%nmol2mol_prefix * unit_system%mass2g)) * rho_sw * sss(:) * (c1 / 34.7_r8) ! Note the following computes a new ph_surf ! pass in sections of surface_flux_forcings instead of associated vars because of problems with intel/15.0.3 @@ -202,62 +203,64 @@ subroutine marbl_abio_dic_surface_flux_compute(& ! Compute derivative diagnostics derivative_terms(:,:) = c0 - call marbl_co2calc_surface(& - num_elements = num_elements, & - lcomp_co2calc_coeffs = .false., & - dic_in = tracers_at_surface(:,dic_ind) + c1, & - xco2_in = xco2(:), & - ta_in = alk_surf(:), & - pt_in = PO4(:), & - sit_in = SiO2(:), & - temp = sst(:), & - salt = sss(:), & - atmpres = ap_used(:), & - unit_system = unit_system, & - phlo = phlo_tmp, & - phhi = phhi_tmp, & - ph = ph_surf_tmp, & - co3 = co3_tmp(:), & - co2calc_coeffs = co2calc_coeffs, & - co2calc_state = co2calc_state, & - co2star = co2star_tmp1, & - dco2star = dco2star_tmp, & - pco2surf = pco2surf_tmp, & - dpco2 = dpco2_tmp, & - marbl_status_log = marbl_status_log) - call marbl_co2calc_surface(& - num_elements = num_elements, & - lcomp_co2calc_coeffs = .false., & - dic_in = tracers_at_surface(:,dic_ind) - c1, & - xco2_in = xco2(:), & - ta_in = alk_surf(:), & - pt_in = PO4(:), & - sit_in = SiO2(:), & - temp = sst(:), & - salt = sss(:), & - atmpres = ap_used(:), & - unit_system = unit_system, & - phlo = phlo_tmp, & - phhi = phhi_tmp, & - ph = ph_surf_tmp, & - co3 = co3_tmp(:), & - co2calc_coeffs = co2calc_coeffs, & - co2calc_state = co2calc_state, & - co2star = co2star_tmp2, & - dco2star = dco2star_tmp, & - pco2surf = pco2surf_tmp, & - dpco2 = dpco2_tmp, & - marbl_status_log = marbl_status_log) - derivative_terms(:,1) = -p5 * (co2star_tmp1(:) - co2star_tmp2(:)) * pv_co2(:) - where (tracers_at_surface(:,dic_ind) > 0) - derivative_terms(:,2) = -p5 * (co2star_tmp1(:) / (tracers_at_surface(:,dic_ind) + c1) & - - co2star_tmp2(:) / (tracers_at_surface(:,dic_ind) - c1)) & - * tracers_at_surface(:,di14c_ind) * pv_co2(:) - derivative_terms(:,3) = -pv_co2(:) * co2star(:) / tracers_at_surface(:,dic_ind) - else where - derivative_terms(:,2) = c0 - derivative_terms(:,3) = c0 - end where + if (labio_derivative_diags) then + call marbl_co2calc_surface(& + num_elements = num_elements, & + lcomp_co2calc_coeffs = .false., & + dic_in = tracers_at_surface(:,dic_ind) + c1, & + xco2_in = xco2(:), & + ta_in = alk_surf(:), & + pt_in = PO4(:), & + sit_in = SiO2(:), & + temp = sst(:), & + salt = sss(:), & + atmpres = ap_used(:), & + unit_system = unit_system, & + phlo = phlo_pert, & + phhi = phhi_pert, & + ph = ph_surf_pert, & + co3 = co3_pert(:), & + co2calc_coeffs = co2calc_coeffs, & + co2calc_state = co2calc_state, & + co2star = co2star_pert_p1, & + dco2star = dco2star_pert, & + pco2surf = pco2surf_pert, & + dpco2 = dpco2_pert, & + marbl_status_log = marbl_status_log) + call marbl_co2calc_surface(& + num_elements = num_elements, & + lcomp_co2calc_coeffs = .false., & + dic_in = tracers_at_surface(:,dic_ind) - c1, & + xco2_in = xco2(:), & + ta_in = alk_surf(:), & + pt_in = PO4(:), & + sit_in = SiO2(:), & + temp = sst(:), & + salt = sss(:), & + atmpres = ap_used(:), & + unit_system = unit_system, & + phlo = phlo_pert, & + phhi = phhi_pert, & + ph = ph_surf_pert, & + co3 = co3_pert(:), & + co2calc_coeffs = co2calc_coeffs, & + co2calc_state = co2calc_state, & + co2star = co2star_pert_m1, & + dco2star = dco2star_pert, & + pco2surf = pco2surf_pert, & + dpco2 = dpco2_pert, & + marbl_status_log = marbl_status_log) + derivative_terms(:,1) = -p5 * (co2star_pert_p1(:) - co2star_pert_m1(:)) * pv_co2(:) + where (tracers_at_surface(:,dic_ind) > 0) + derivative_terms(:,2) = -p5 * (co2star_pert_p1(:) / (tracers_at_surface(:,dic_ind) + c1) & + - co2star_pert_m1(:) / (tracers_at_surface(:,dic_ind) - c1)) & + * tracers_at_surface(:,di14c_ind) * pv_co2(:) + derivative_terms(:,3) = -pv_co2(:) * co2star(:) / tracers_at_surface(:,dic_ind) + else where + derivative_terms(:,2) = c0 + derivative_terms(:,3) = c0 + end where + end if ! update abiotic DIC diagnostics call marbl_abio_dic_diagnostics_surface_flux_compute( & diff --git a/src/marbl_settings_mod.F90 b/src/marbl_settings_mod.F90 index 7db8e855..b548776b 100644 --- a/src/marbl_settings_mod.F90 +++ b/src/marbl_settings_mod.F90 @@ -256,6 +256,7 @@ module marbl_settings_mod ! (this is done primarily in spinup runs) logical(log_kind), target :: lo2_consumption_scalef ! Apply o2_consumption_scalef to o2 consumption (and request it as a forcing) logical(log_kind), target :: lp_remin_scalef ! Apply p_remin_scalef to particulate remin (and request it as a forcing) + logical(log_kind), target :: labio_derivative_diags ! Compute derivative diagnostic terms in abiotic surface flux module character(len=char_len), target :: init_bury_coeff_opt @@ -426,6 +427,7 @@ subroutine marbl_settings_set_defaults_general_parms(unit_system) ladjust_bury_coeff = .false. ! CESM USERS - DO NOT CHANGE HERE! POP calls put_setting() for this var, see CESM NOTE above lo2_consumption_scalef = .false. ! CESM USERS - DO NOT CHANGE HERE! POP calls put_setting() for this var, see CESM NOTE above lp_remin_scalef = .false. ! CESM USERS - DO NOT CHANGE HERE! POP calls put_setting() for this var, see CESM NOTE above + labio_derivative_diags = .false. ! CESM USERS - DO NOT CHANGE HERE! POP calls put_setting() for this var, see CESM NOTE above particulate_flux_ref_depth = 100._r8 ! CESM USERS - DO NOT CHANGE HERE! POP calls put_setting() for this var, see CESM NOTE above bftt_dz_sum_thres = 1.0e-14_r8 ! CESM USERS - DO NOT CHANGE HERE! POP calls put_setting() for this var, see CESM NOTE above Jint_Ctot_thres_molpm2pyr = 1.0e-9_r8 ! CESM USERS - DO NOT CHANGE HERE! POP calls put_setting() for this var, see CESM NOTE above @@ -719,6 +721,17 @@ subroutine marbl_settings_define_general_parms(this, marbl_status_log) call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc) end if + if (abio_dic_on) then + sname = 'labio_derivative_diags' + lname = 'Control whether derivative diagnostics are computed in abiotic surface flux (useful for Newton-Krylov)' + units = 'unitless' + datatype = 'logical' + lptr => labio_derivative_diags + call this%add_var(sname, lname, units, datatype, category, & + marbl_status_log, lptr=lptr) + call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc) + end if + sname = 'lcheck_forcing' lname = 'Control whether consistency checks are performed on forcing input (useful for debugging)' units = 'unitless' diff --git a/tests/input_files/settings/marbl_with_abio_only.settings b/tests/input_files/settings/marbl_with_abio_only.settings index aa4dabf1..6abdb91d 100644 --- a/tests/input_files/settings/marbl_with_abio_only.settings +++ b/tests/input_files/settings/marbl_with_abio_only.settings @@ -1,2 +1,3 @@ abio_dic_on = .true. base_bio_on = .false. +labio_derivative_diags = .true.