Skip to content

Commit

Permalink
Clean up marbl_abio_dic_surface_flux_mod
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mnlevy1981 committed Oct 13, 2023
1 parent 39a008d commit 4f2f6b8
Show file tree
Hide file tree
Showing 19 changed files with 232 additions and 109 deletions.
3 changes: 3 additions & 0 deletions MARBL_tools/MARBL_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 3 additions & 0 deletions defaults/diagnostics_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions defaults/json/diagnostics_latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions defaults/json/settings_cesm2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions defaults/json/settings_cesm2.1+cocco.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions defaults/json/settings_cesm2.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions defaults/json/settings_latest+4p2z.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions defaults/json/settings_latest+cocco.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions defaults/json/settings_latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions defaults/settings_cesm2.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions defaults/settings_cesm2.1+cocco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions defaults/settings_cesm2.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions defaults/settings_latest+4p2z.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions defaults/settings_latest+cocco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions defaults/settings_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
79 changes: 42 additions & 37 deletions src/marbl_abio_dic_diagnostics_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 4f2f6b8

Please sign in to comment.