Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial port to CESM+NUOPC #1

Merged
merged 4 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 147 additions & 134 deletions cime_config/buildcpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ sys.path.append(os.path.join(CIMEROOT, "scripts", "Tools"))

from standard_script_setup import *

from CIME.utils import run_cmd_no_fail, expect
from CIME.utils import run_cmd
#from CIME.utils import run_cmd_no_fail, expect
#from CIME.utils import run_cmd
from CIME.case import Case
from CIME.buildnml import parse_input

import glob, shutil
logger = logging.getLogger(__name__)

###############################################################################
def buildcpp(case):
###############################################################################

# determine cice_config_opts
# tcraig, should move the decomposition stuff from buildcpp to buildnml
# the only thing needed here is the actual cpp stuff -Dncdf -DRASM -DCESMCOUPLED
# # determine cice_config_opts
cice_config_opts = case.get_value('CICE_CONFIG_OPTS')

# set ice grid settings
nx = case.get_value("ICE_NX")
ny = case.get_value("ICE_NY")
# # set ice grid settings
# nx = case.get_value("ICE_NX")
# ny = case.get_value("ICE_NY")

ice_grid = case.get_value('ICE_GRID')
if ice_grid == 'ar9v2':
Expand All @@ -40,118 +41,127 @@ def buildcpp(case):
else:
hgrid = ice_grid

# determine decomposition xml variables if CICE_AUTO_DECOMP is true
# - invoke generate_cice_decomp.pl and update env_build.xml settings to
# reflect changes in the configuration this will trigger
cice_auto_decomp = case.get_value("CICE_AUTO_DECOMP")

pts_mode = case.get_value("PTS_MODE")
if pts_mode:
# explicitl set values for single column mode
nx = 1
ny = 1
cice_auto_decomp = False
case.set_value("CICE_BLCKX", 1)
case.set_value("CICE_BLCKY", 1)
case.set_value("CICE_MXBLCKS", 1)
case.set_value("CICE_DECOMPTYPE", "cartesian")
case.set_value("CICE_DECOMPSETTING", "square-ice")

if cice_auto_decomp:
nthrds_ice = case.get_value("NTHRDS_ICE")
ninst_ice = case.get_value("NINST_ICE")
ntasks = case.get_value("NTASKS_PER_INST_ICE")
srcroot = case.get_value("SRCROOT")

cmd = os.path.join(srcroot, "components", "cice", "bld", "generate_cice_decomp.pl")
command = "%s -ccsmroot %s -res %s -nx %s -ny %s -nproc %s -thrds %s -output %s " \
% (cmd, srcroot, hgrid, nx, ny, ntasks, nthrds_ice, "all")
rc, out, err = run_cmd(command)

expect(rc==0,"Command %s failed rc=%d\nout=%s\nerr=%s"%(cmd,rc,out,err))
if out is not None:
logger.debug(" %s"%out)
if err is not None:
logger.debug(" %s"%err)

config = out.split()
if int(config[0]) > 0:
case.set_value("CICE_BLCKX", config[2])
case.set_value("CICE_BLCKY", config[3])
case.set_value("CICE_MXBLCKS",config[4])
case.set_value("CICE_DECOMPTYPE", config[5])
case.set_value("CICE_DECOMPSETTING", config[6])

# set cice mode and cice_config_opts
# # determine decomposition xml variables if CICE_AUTO_DECOMP is true
# # - invoke generate_cice_decomp.pl and update env_build.xml settings to
# # reflect changes in the configuration this will trigger
# cice_auto_decomp = case.get_value("CICE_AUTO_DECOMP")
#
# pts_mode = case.get_value("PTS_MODE")
# # set cice mode and cice_config_opts
cice_mode = case.get_value("CICE_MODE")

# set cice physics
if "cice5" in cice_config_opts:
phys = "cice5"
elif "cice4" in cice_config_opts:
phys = "cice4"

if cice_mode == 'prescribed':
case.set_value("CICE_DECOMPTYPE", "roundrobin")

if cice_mode == 'prescribed':
ntr_aero = 0
else:
ntr_aero = 3
ntr_aero = set_nondefault_cpp(cice_config_opts, "ntr_aero", ntr_aero)
case.set_value("ICE_NAERO", ntr_aero)

# set number of bgc tracers (valid values are 0->10)
if cice_mode == 'prescribed':
nbgclyr = 0
else:
nbgclyr = 3
nbgclyr = set_nondefault_cpp(cice_config_opts, "nbgclyr", nbgclyr)

# set isotope tracer
ntr_iso = 0
ntr_iso = set_nondefault_cpp(cice_config_opts, "ntr_iso", ntr_iso)

# set age tracer
trage = 1
trage = set_nondefault_cpp(cice_config_opts, "trage", trage)

# set first year ice tracer (valid values are 0,1)
trfy = 1
trfy = set_nondefault_cpp(cice_config_opts, "trfy", trfy)

# set pond tracer (valid values are 0,1)
trpnd = 1
trpnd = set_nondefault_cpp(cice_config_opts, "trpnd", trpnd)

# set level ice tracer (valid values are 0,1)
trlvl = 1
trlvl = set_nondefault_cpp(cice_config_opts, "trlvl", trlvl)

# set brine tracer (valid values are 0,1)
trbri = 0
trbri = set_nondefault_cpp(cice_config_opts, "trbri", trbri)

# set skeletal layer tracer (valid values are 0,1)
trbgcs = 0
trbgcs = set_nondefault_cpp(cice_config_opts, "trbgcs", trbgcs)

# set number of ice layers
if phys == "cice4":
nicelyr = 4
elif "ar9v" in hgrid:
nicelyr = 7
else:
nicelyr = 8
case.set_value("ICE_NILYR", nicelyr)

# set number of snow layers
if phys == "cice4":
nsnwlyr = 1
else:
nsnwlyr = 3
case.set_value("ICE_NSLYR", nsnwlyr)

#
# if pts_mode:
# # explicitl set values for single column mode
# nx = 1
# ny = 1
# cice_auto_decomp = False
# case.set_value("CICE_BLCKX", 1)
# case.set_value("CICE_BLCKY", 1)
# case.set_value("CICE_MXBLCKS", 1)
# case.set_value("CICE_DECOMPTYPE", "cartesian")
# case.set_value("CICE_DECOMPSETTING", "square-ice")
#
# if cice_auto_decomp:
# nthrds_ice = case.get_value("NTHRDS_ICE")
# ninst_ice = case.get_value("NINST_ICE")
# ntasks = case.get_value("NTASKS_PER_INST_ICE")
# srcroot = case.get_value("SRCROOT")
#
# cmd = os.path.join(srcroot, "components", "cice", "bld", "generate_cice_decomp.pl")
# command = "%s -ccsmroot %s -res %s -nx %s -ny %s -nproc %s -thrds %s -output %s " \
# % (cmd, srcroot, hgrid, nx, ny, ntasks, nthrds_ice, "all")
# rc, out, err = run_cmd(command)
#
# expect(rc==0,"Command %s failed rc=%d\nout=%s\nerr=%s"%(cmd,rc,out,err))
# if out is not None:
# logger.debug(" %s"%out)
# if err is not None:
# logger.debug(" %s"%err)
#
# config = out.split()
# if int(config[0]) > 0:
# case.set_value("CICE_BLCKX", config[2])
# case.set_value("CICE_BLCKY", config[3])
# case.set_value("CICE_MXBLCKS",config[4])
# if cice_mode != 'prescribed':
# case.set_value("CICE_DECOMPTYPE", config[5])
# case.set_value("CICE_DECOMPSETTING", config[6])


# tcraig, moved to namelist_definition_cice.xml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the following are namelist settings - this logic should be moved to buildnml - and removed from buildcpp. Please remove the commented out code - since its clear from the PR code what has been removed - and this will make buildcpp much easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I noted above, I continue to work on the cleanup. I'm committing things as I make progress. I think we all recognize there is still work to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fine. I committing my changes to my branch as you suggested. I created PRs as you suggested. I think it's great that others are looking at what changes are coming in as I make progress. I encourage others to provide feedback, I don't really have a good handle on all aspects of these scripts. There is still work to do before this is done, and it might not "all" get done just in this PR. We can merge the PR whenever folks want.

# # set cice physics
# if "cice5" in cice_config_opts:
# phys = "cice5"
# elif "cice4" in cice_config_opts:
# phys = "cice4"

# if cice_mode == 'prescribed' and not pts_mode:
# case.set_value("CICE_DECOMPTYPE", "roundrobin")

# tcraig, moved to namelist_definition_cice.xml
# if cice_mode == 'prescribed':
# ntr_aero = 0
# elif "tx0.25" in hgrid:
# ntr_aero = 0
# else:
# ntr_aero = 3
# ntr_aero = set_nondefault_cpp(cice_config_opts, "ntr_aero", ntr_aero)
#
# # set number of number of bio grid layers (valid values are 0->10)
# if cice_mode == 'prescribed':
# nbgclyr = 0
# elif "tx0.25" in hgrid:
# nbgclyr = 7
# else:
# nbgclyr = 3
# nbgclyr = set_nondefault_cpp(cice_config_opts, "nbgclyr", nbgclyr)
#
# # set isotope tracer
# ntr_iso = 0
# ntr_iso = set_nondefault_cpp(cice_config_opts, "ntr_iso", ntr_iso)
#
# # set age tracer
# trage = 1
# trage = set_nondefault_cpp(cice_config_opts, "trage", trage)
#
# # set first year ice tracer (valid values are 0,1)
# trfy = 1
# trfy = set_nondefault_cpp(cice_config_opts, "trfy", trfy)
#
# # set pond tracer (valid values are 0,1)
# trpnd = 1
# trpnd = set_nondefault_cpp(cice_config_opts, "trpnd", trpnd)
#
# # set level ice tracer (valid values are 0,1)
# trlvl = 1
# trlvl = set_nondefault_cpp(cice_config_opts, "trlvl", trlvl)
#
# # set brine tracer (valid values are 0,1)
# trbri = 0
# trbri = set_nondefault_cpp(cice_config_opts, "trbri", trbri)
#
# # set skeletal layer tracer (valid values are 0,1)
# trbgcs = 0
# trbgcs = set_nondefault_cpp(cice_config_opts, "trbgcs", trbgcs)
#
# # set number of ice layers
# if phys == "cice4":
# nicelyr = 4
# elif "ar9v" in hgrid:
# nicelyr = 7
# elif "tx0.25" in hgrid:
# nicelyr = 7
# else:
# nicelyr = 8
#
# # set number of snow layers
# if phys == "cice4":
# nsnwlyr = 1
# elif "tx0.25" in hgrid:
# nsnwlyr = 1
# else:
# nsnwlyr = 3
#
# set number of ice categories
# NOTE that ICE_NCAT is used by both cice and pop - but is set by cice
# and as a result it is assumed that the cice buildcpp is called
Expand All @@ -165,29 +175,32 @@ def buildcpp(case):
case.set_value("ICE_NCAT",ncat)
logger.debug("cice: number of ice categories (ncat) is %s" %ncat)

# set decomposition block sizes
cice_blckx = case.get_value("CICE_BLCKX")
cice_blcky = case.get_value("CICE_BLCKY")
cice_mxblcks = case.get_value("CICE_MXBLCKS")
# # set decomposition block sizes
# cice_blckx = case.get_value("CICE_BLCKX")
# cice_blcky = case.get_value("CICE_BLCKY")
# cice_mxblcks = case.get_value("CICE_MXBLCKS")

cice_cppdefs = " -DCESMCOUPLED -Dncdf -DNUMIN=11 -DNUMAX=99 " \
" -DNICECAT=%s -DNXGLOB=%s -DNYGLOB=%s -DNTRAERO=%s -DNTRISO=%s" \
" -DNBGCLYR=%s -DNICELYR=%s -DNSNWLYR=%s" \
" -DTRAGE=%s -DTRFY=%s -DTRLVL=%s -DTRPND=%s -DTRBRI=%s -DTRBGCS=%s" \
%(ncat,nx,ny,ntr_aero,ntr_iso,nbgclyr,nicelyr,nsnwlyr,trage,trfy,trlvl,trpnd,trbri,trbgcs)
comp_atm = case.get_value("COMP_ATM")
comp_ocn = case.get_value("COMP_OCN")
# cice_cppdefs = " -Dncdf -DNUMIN=11 -DNUMAX=99 " \
# " -DNICECAT=%s -DNXGLOB=%s -DNYGLOB=%s -DNTRAERO=%s -DNTRISO=%s" \
# " -DNBGCLYR=%s -DNICELYR=%s -DNSNWLYR=%s" \
# " -DTRAGE=%s -DTRFY=%s -DTRLVL=%s -DTRPND=%s -DTRBRI=%s -DTRBGCS=%s" \
# %(ncat,nx,ny,ntr_aero,ntr_iso,nbgclyr,nicelyr,nsnwlyr,trage,trfy,trlvl,trpnd,trbri,trbgcs)
cice_cppdefs = " -Dncdf"

if (comp_atm == 'fv3gfs' and comp_ocn == "mom"):
cice_cppdefs = cice_cppdefs + " -DNEMS_COUPLED"

# trigger RASM options with ar9v grid, otherwise set CESM options
if "ar9v" in hgrid:
cice_cppdefs = cice_cppdefs + "-DRASM_MODS"

# determine cice_cppdefs used in build
cice_cppdefs = cice_cppdefs + " -DBLCKX=%s -DBLCKY=%s -DMXBLCKS=%s"%(cice_blckx, cice_blcky, cice_mxblcks)
cice_cppdefs = cice_cppdefs + " -DRASM_MODS"

cice_cppdefs = " -DCESMCOUPLED -Dncdf "
# # determine cice_cppdefs used in build
# cice_cppdefs = cice_cppdefs + " -DBLCKX=%s -DBLCKY=%s -DMXBLCKS=%s"%(cice_blckx, cice_blcky, cice_mxblcks)

# update the xml variable CICE_CPPDEFS with the above definition
case.set_value("CICE_CPPDEFS", cice_cppdefs)
case.flush()

return cice_cppdefs

Expand All @@ -205,7 +218,7 @@ def set_nondefault_cpp(cice_config_opts, string, value):
def _main_func():

caseroot = parse_input(sys.argv)
with Case(caseroot) as case:
with Case(caseroot, read_only=False) as case:
cice_cppdefs = buildcpp(case)
logger.info("CICE_CPPDEFS: %s" %cice_cppdefs)

Expand Down
Loading