Skip to content

Commit

Permalink
Merge branch 'dev/gfdl' into visc_rem_cont
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallward committed Sep 17, 2024
2 parents e23fb51 + b2db6bf commit 03c66b1
Show file tree
Hide file tree
Showing 76 changed files with 4,102 additions and 1,719 deletions.
2 changes: 1 addition & 1 deletion .github/actions/ubuntu-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ runs:
run: |
echo "::group::config.mk"
cd .testing
echo "FCFLAGS_DEBUG = -g -O0 -Wextra -Wno-compare-reals -fbacktrace -ffpe-trap=invalid,zero,overflow -fcheck=bounds" >> config.mk
echo "FCFLAGS_DEBUG = -g -O0 -std=f2018 -Wextra -Wno-compare-reals -fbacktrace -ffpe-trap=invalid,zero,overflow -fcheck=bounds" >> config.mk
echo "FCFLAGS_REPRO = -g -O2 -fbacktrace" >> config.mk
echo "FCFLAGS_INIT = -finit-real=snan -finit-integer=2147483647 -finit-derived" >> config.mk
echo "FCFLAGS_FMS = -g -fbacktrace -O0" >> config.mk
Expand Down
8 changes: 5 additions & 3 deletions .testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,21 @@ export FMS_URL
# TODO: This needs more automated configuration
MPIRUN ?= mpirun

# Generic compiler variables are pass through to the builds
# Generic compiler variables are passed through to the builds
export CC
export MPICC
export FC
export MPIFC

# Builds are distinguished by FCFLAGS
FCFLAGS_DEBUG ?= -g -O0
FCFLAGS ?= -g -O0

FCFLAGS_DEBUG ?= $(FCFLAGS)
FCFLAGS_REPRO ?= -g -O2
FCFLAGS_OPT ?= -g -O3 -mavx -fno-omit-frame-pointer
FCFLAGS_INIT ?=
FCFLAGS_COVERAGE ?= -g -O0 -fbacktrace --coverage
FCFLAGS_FMS ?= $(FCFLAGS_DEBUG)
FCFLAGS_FMS ?= $(FCFLAGS)
# Additional notes:
# - These default values are simple, minimalist flags, supported by nearly all
# compilers, and are somewhat analogous to GFDL's DEBUG and REPRO builds.
Expand Down
6 changes: 6 additions & 0 deletions .testing/tc1/MOM_input
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ BOUND_CORIOLIS = True ! [Boolean] default = False
! have no effect on the SADOURNY Coriolis scheme if it
! were possible to use centered difference thickness fluxes.

! === module MOM_PressureForce_FV ===
MASS_WEIGHT_IN_PRESSURE_GRADIENT = True ! [Boolean] default = False
! If true, use mass weighting when interpolating T/S for integrals
! near the bathymetry in FV pressure gradient calculations.


! === module MOM_hor_visc ===
AH_VEL_SCALE = 0.05 ! [m s-1] default = 0.0
! The velocity scale which is multiplied by the cube of
Expand Down
7 changes: 6 additions & 1 deletion .testing/tc2/MOM_input
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,16 @@ PGF_STANLEY_T2_DET_COEFF = -1.0 ! [nondim] default = -1.0
! gradient in the deterministic part of the Stanley form of the Brankart
! correction. Negative values disable the scheme.

! === module MOM_PressureForce_FV ===
MASS_WEIGHT_IN_PRESSURE_GRADIENT = True ! [Boolean] default = False
! If true, use mass weighting when interpolating T/S for integrals
! near the bathymetry in FV pressure gradient calculations.

! === module MOM_hor_visc ===
LAPLACIAN = True
KH_VEL_SCALE = 0.05
SMAGORINSKY_KH = True ! [Boolean] default = False
SMAG_LAP_CONST = 0.06 ! [nondim] default = 0.0
SMAG_LAP_CONST = 0.06 ! [nondim] default = 0.0
AH_VEL_SCALE = 0.05 ! [m s-1] default = 0.0
! The velocity scale which is multiplied by the cube of
! the grid spacing to calculate the Laplacian viscosity.
Expand Down
3 changes: 3 additions & 0 deletions .testing/tc4/MOM_input
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ BOUND_CORIOLIS = True ! [Boolean] default = False
! === module MOM_PressureForce ===

! === module MOM_PressureForce_FV ===
MASS_WEIGHT_IN_PRESSURE_GRADIENT = True ! [Boolean] default = False
! If true, use mass weighting when interpolating T/S for integrals
! near the bathymetry in FV pressure gradient calculations.
RECONSTRUCT_FOR_PRESSURE = False ! [Boolean] default = True
! If True, use vertical reconstruction of T & S within the integrals of the FV
! pressure gradient calculation. If False, use the constant-by-layer algorithm.
Expand Down
114 changes: 69 additions & 45 deletions ac/makedep
Original file line number Diff line number Diff line change
Expand Up @@ -214,68 +214,91 @@ def create_deps(src_dirs, skip_dirs, makefile, debug, exec_target, fc_rule,
# Create new makefile
with open(makefile, 'w') as file:
print("# %s created by makedep" % (makefile), file=file)
print("", file=file)
print(file=file)
print("# Invoked as", file=file)
print('# '+' '.join(sys.argv), file=file)
print("", file=file)
print(file=file)
print("all:", " ".join(targets), file=file)
print("", file=file)

# print(file=file)
# print("# SRC_DIRS is usually set in the parent Makefile but in case is it not we", file=file)
# print("# record it here from when makedep was previously invoked.", file=file)
# print("SRC_DIRS ?= ${SRC_DIRS}", file=file)
# print("", file=file)

# print(file=file)
# print("# all_files:", ' '.join(all_files), file=file)
# print("", file=file)

# Write rule for each object from Fortran
for o in sorted(o2F90.keys()):
found_mods = [m for m in o2uses[o] if m in all_modules]
found_objs = [mod2o[m] for m in o2uses[o] if m in all_modules]
for obj in sorted(o2F90.keys()):
found_mods = [m for m in o2uses[obj] if m in all_modules]
found_objs = [mod2o[m] for m in o2uses[obj] if m in all_modules]
found_deps = [
dep for pair in zip(found_mods, found_objs) for dep in pair
]
missing_mods = [m for m in o2uses[o] if m not in all_modules]
missing_mods = [m for m in o2uses[obj] if m not in all_modules]

incs, inc_used = nested_inc(o2h[o] + o2inc[o], f2F, defines)
inc_mods = [u for u in inc_used if u not in found_mods and u in all_modules]
incs, inc_used = nested_inc(o2h[obj] + o2inc[obj], f2F, defines)
inc_mods = [
u for u in inc_used if u not in found_mods and u in all_modules
]

incdeps = sorted(set([f2F[f] for f in incs if f in f2F]))
incargs = sorted(set(['-I'+os.path.dirname(f) for f in incdeps]))
incargs = sorted(set(['-I' + os.path.dirname(f) for f in incdeps]))

# Header
print(file=file)
if debug:
print("# Source file {} produces:".format(o2F90[o]), file=file)
print("# object:", o, file=file)
print("# modules:", ' '.join(o2mods[o]), file=file)
print("# uses:", ' '.join(o2uses[o]), file=file)
print("# Source file {} produces:".format(o2F90[obj]), file=file)
print("# object:", obj, file=file)
print("# modules:", ' '.join(o2mods[obj]), file=file)
print("# uses:", ' '.join(o2uses[obj]), file=file)
print("# found mods:", ' '.join(found_mods), file=file)
print("# found objs:", ' '.join(found_objs), file=file)
print("# missing:", ' '.join(missing_mods), file=file)
print("# includes_all:", ' '.join(incs), file=file)
print("# includes_pth:", ' '.join(incdeps), file=file)
print("# incargs:", ' '.join(incargs), file=file)
print("# program:", ' '.join(o2prg[o]), file=file)
if o2mods[o]:
print(' '.join(o2mods[o])+':', o, file=file)
print(o + ':', o2F90[o], ' '.join(inc_mods + incdeps + found_deps), file=file)
print('\t'+fc_rule, ' '.join(incargs), file=file)
print("# program:", ' '.join(o2prg[obj]), file=file)

# Fortran Module dependencies
if o2mods[obj]:
print(' '.join(o2mods[obj]) + ':', obj, file=file)

# Fortran object dependencies
obj_incs = ' '.join(inc_mods + incdeps + found_deps)
print(obj + ':', o2F90[obj], obj_incs, file=file)

# Fortran object build rule
obj_rule = ' '.join([fc_rule] + incargs + ['-c', '$<'])
print('\t' + obj_rule, file=file)

# Write rule for each object from C
for o in sorted(o2c.keys()):
incdeps = sorted(set([f2F[h] for h in o2h[o] if h in f2F]))
incargs = sorted(set(['-I'+os.path.dirname(f) for f in incdeps]))
for obj in sorted(o2c.keys()):
incdeps = sorted(set([f2F[h] for h in o2h[obj] if h in f2F]))
incargs = sorted(set(['-I' + os.path.dirname(f) for f in incdeps]))

# Header
print(file=file)
if debug:
print("# Source file %s produces:" % (o2c[o]), file=file)
print("# object:", o, file=file)
print("# includes_all:", ' '.join(o2h[o]), file=file)
print("# Source file %s produces:" % (o2c[obj]), file=file)
print("# object:", obj, file=file)
print("# includes_all:", ' '.join(o2h[obj]), file=file)
print("# includes_pth:", ' '.join(incdeps), file=file)
print("# incargs:", ' '.join(incargs), file=file)
print(o+':', o2c[o], ' '.join(incdeps), file=file)
print('\t$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c $<', ' '.join(incargs), file=file)

# C object dependencies
print(obj + ':', o2c[obj], ' '.join(incdeps), file=file)

# C object build rule
c_rule = ' '.join(
['$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS)'] + incargs + ['-c', '$<']
)
#print('\t' + c_rule, ' '.join(incargs), '-c', '$<', file=file)
print('\t' + c_rule, file=file)

# Externals (so called)
if link_externals:
print("", file=file)
print(file=file)
print("# Note: The following object files are not associated with "
"modules so we assume we should link with them:", file=file)
print("# ", ' '.join(externals), file=file)
Expand All @@ -286,23 +309,23 @@ def create_deps(src_dirs, skip_dirs, makefile, debug, exec_target, fc_rule,
# Write rules for linking executables
for p in sorted(prg2o.keys()):
o = prg2o[p]
print("", file=file)
print(file=file)
print(p+':', ' '.join(link_obj(o, o2uses, mod2o, all_modules) + externals), file=file)
print('\t$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)', file=file)

# Write rules for building libraries
for lb in sorted(targ_libs):
print("", file=file)
print(file=file)
print(lb+':', ' '.join(list(o2F90.keys()) + list(o2c.keys())), file=file)
print('\t$(AR) $(ARFLAGS) $@ $^', file=file)

# Write cleanup rules
print("", file=file)
print(file=file)
print("clean:", file=file)
print('\trm -f *.mod *.o', ' '.join(list(prg2o.keys()) + targ_libs), file=file)

# Write re-generation rules
print("", file=file)
print(file=file)
print("remakedep:", file=file)
print('\t'+' '.join(sys.argv), file=file)

Expand Down Expand Up @@ -366,24 +389,23 @@ def scan_fortran_file(src_file, defines=None):

cpp_defines = defines if defines is not None else []

#cpp_macros = [define.split('=')[0] for define in cpp_defines]
cpp_macros = dict([t.split('=') for t in cpp_defines])
cpp_group_stack = []

with io.open(src_file, 'r', errors='replace') as file:
lines = file.readlines()

external_namespace = True
# True if we are in the external (i.e. global) namespace
# True if we are in the external (i.e. global) namespace

file_has_externals = False
# True if the file contains any external objects
# True if the file contains any external objects

cpp_exclude = False
# True if the parser excludes the subsequent lines
# True if the parser excludes the subsequent lines

cpp_group_stack = []
# Stack of condition group exclusion states
# Stack of condition group exclusion states

for line in lines:
# Start of #ifdef condition group
Expand Down Expand Up @@ -446,14 +468,16 @@ def scan_fortran_file(src_file, defines=None):
if match:
new_macro = line.lstrip()[1:].split()[1]
try:
cpp_macros.remove(new_macro)
except:
# Ignore missing macros (for now?)
cpp_macros.pop(new_macro)
except KeyError:
# C99: "[A macro] is ignored if the specified identifier is
# not currently defined as a macro name."
continue

match = re_module.match(line.lower())
if match:
if match.group(1) not in 'procedure': # avoid "module procedure" statements
# Avoid "module procedure" statements
if match.group(1) not in 'procedure':
module_decl.append(match.group(1))
external_namespace = False

Expand Down Expand Up @@ -632,9 +656,9 @@ parser.add_argument(
)
parser.add_argument(
'-f', '--fc_rule',
default="$(FC) $(DEFS) $(FCFLAGS) $(CPPFLAGS) -c $<",
default="$(FC) $(DEFS) $(CPPFLAGS) $(FCFLAGS)",
help="String to use in the compilation rule. Default is: "
"'$(FC) $(DEFS) $(FCFLAGS) $(CPPFLAGS) -c $<'"
"'$(FC) $(DEFS) $(CPPFLAGS) $(FCFLAGS)'"
)
parser.add_argument(
'-x', '--exec_target',
Expand Down
14 changes: 7 additions & 7 deletions config_src/drivers/FMS_cap/MOM_surface_forcing_gfdl.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,10 @@ subroutine extract_IOB_stresses(IOB, index_bounds, Time, G, US, CS, taux, tauy,
tau_mag = 0.0 ; gustiness = CS%gust_const
if (((G%mask2dBu(I,J) + G%mask2dBu(I-1,J-1)) + &
(G%mask2dBu(I,J-1) + G%mask2dBu(I-1,J))) > 0.0) then
tau_mag = sqrt(((G%mask2dBu(I,J)*(taux_in_B(I,J)**2 + tauy_in_B(I,J)**2) + &
G%mask2dBu(I-1,J-1)*(taux_in_B(I-1,J-1)**2 + tauy_in_B(I-1,J-1)**2)) + &
(G%mask2dBu(I,J-1)*(taux_in_B(I,J-1)**2 + tauy_in_B(I,J-1)**2) + &
G%mask2dBu(I-1,J)*(taux_in_B(I-1,J)**2 + tauy_in_B(I-1,J)**2)) ) / &
tau_mag = sqrt(((G%mask2dBu(I,J)*((taux_in_B(I,J)**2) + (tauy_in_B(I,J)**2)) + &
G%mask2dBu(I-1,J-1)*((taux_in_B(I-1,J-1)**2) + (tauy_in_B(I-1,J-1)**2))) + &
(G%mask2dBu(I,J-1)*((taux_in_B(I,J-1)**2) + (tauy_in_B(I,J-1)**2)) + &
G%mask2dBu(I-1,J)*((taux_in_B(I-1,J)**2) + (tauy_in_B(I-1,J)**2))) ) / &
((G%mask2dBu(I,J) + G%mask2dBu(I-1,J-1)) + (G%mask2dBu(I,J-1) + G%mask2dBu(I-1,J))) )
if (CS%read_gust_2d) gustiness = CS%gust(i,j)
endif
Expand All @@ -1117,7 +1117,7 @@ subroutine extract_IOB_stresses(IOB, index_bounds, Time, G, US, CS, taux, tauy,
enddo ; enddo
elseif (wind_stagger == AGRID) then
do j=js,je ; do i=is,ie
tau_mag = G%mask2dT(i,j) * sqrt(taux_in_A(i,j)**2 + tauy_in_A(i,j)**2)
tau_mag = G%mask2dT(i,j) * sqrt((taux_in_A(i,j)**2) + (tauy_in_A(i,j)**2))
gustiness = CS%gust_const
if (CS%read_gust_2d .and. (G%mask2dT(i,j) > 0.0)) gustiness = CS%gust(i,j)
if (do_ustar) ustar(i,j) = sqrt(gustiness*IRho0 + IRho0 * tau_mag)
Expand All @@ -1133,10 +1133,10 @@ subroutine extract_IOB_stresses(IOB, index_bounds, Time, G, US, CS, taux, tauy,
do j=js,je ; do i=is,ie
taux2 = 0.0 ; tauy2 = 0.0
if ((G%mask2dCu(I-1,j) + G%mask2dCu(I,j)) > 0.0) &
taux2 = (G%mask2dCu(I-1,j)*taux_in_C(I-1,j)**2 + G%mask2dCu(I,j)*taux_in_C(I,j)**2) / &
taux2 = (G%mask2dCu(I-1,j)*(taux_in_C(I-1,j)**2) + G%mask2dCu(I,j)*(taux_in_C(I,j)**2)) / &
(G%mask2dCu(I-1,j) + G%mask2dCu(I,j))
if ((G%mask2dCv(i,J-1) + G%mask2dCv(i,J)) > 0.0) &
tauy2 = (G%mask2dCv(i,J-1)*tauy_in_C(i,J-1)**2 + G%mask2dCv(i,J)*tauy_in_C(i,J)**2) / &
tauy2 = (G%mask2dCv(i,J-1)*(tauy_in_C(i,J-1)**2) + G%mask2dCv(i,J)*(tauy_in_C(i,J)**2)) / &
(G%mask2dCv(i,J-1) + G%mask2dCv(i,J))
tau_mag = sqrt(taux2 + tauy2)

Expand Down
8 changes: 4 additions & 4 deletions config_src/drivers/FMS_cap/ocean_model_MOM.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1065,10 +1065,10 @@ subroutine ocean_model_data2D_get(OS, Ocean, name, array2D, isc, jsc)
type(ocean_public_type), intent(in) :: Ocean !< A structure containing various publicly
!! visible ocean surface fields.
character(len=*) , intent(in) :: name !< The name of the field to extract
real, dimension(isc:,jsc:), intent(out):: array2D !< The values of the named field, it must
!! cover only the computational domain [various]
integer , intent(in) :: isc !< The starting i-index of array2D
integer , intent(in) :: jsc !< The starting j-index of array2D
real, dimension(isc:,jsc:), intent(out):: array2D !< The values of the named field, it must
!! cover only the computational domain [various]

integer :: g_isc, g_iec, g_jsc, g_jec, g_isd, g_ied, g_jsd, g_jed, i, j

Expand Down Expand Up @@ -1188,10 +1188,10 @@ subroutine ocean_model_get_UV_surf(OS, Ocean, name, array2D, isc, jsc)
type(ocean_public_type), intent(in) :: Ocean !< A structure containing various publicly
!! visible ocean surface fields.
character(len=*) , intent(in) :: name !< The name of the current (ua or va) to extract
real, dimension(isc:,jsc:), intent(out):: array2D !< The values of the named field, it must
!! cover only the computational domain [L T-1 ~> m s-1]
integer , intent(in) :: isc !< The starting i-index of array2D
integer , intent(in) :: jsc !< The starting j-index of array2D
real, dimension(isc:,jsc:), intent(out):: array2D !< The values of the named field, it must
!! cover only the computational domain [L T-1 ~> m s-1]

type(ocean_grid_type) , pointer :: G !< The ocean's grid structure
type(surface), pointer :: sfc_state !< A structure containing fields that
Expand Down
Loading

0 comments on commit 03c66b1

Please sign in to comment.