-
Notifications
You must be signed in to change notification settings - Fork 435
EAMxx: dycore energy fixer #7553
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f16c96e
rename conservation files
oksanaguba 0f71895
implement fixer
oksanaguba 5c1db62
nl changes for fixer
oksanaguba 30b27fc
add fixer test and post proc script
oksanaguba ed6043d
delete renamed files
oksanaguba 5b382d1
remove comments that are not relevant
oksanaguba eb5a9b5
add metadata for fixer entries
oksanaguba 0cbd887
remove permamently disabled ifdef
oksanaguba 9c77714
fixes for new ekat
oksanaguba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
components/eamxx/cime_config/testdefs/testmods_dirs/eamxx/fixer_debug_output/shell_commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$CIMEROOT/../components/eamxx/scripts/atmchange homme::enable_energy_fixer_debug_info=true -b | ||
./xmlchange POSTRUN_SCRIPT="$CIMEROOT/../components/eamxx/scripts/check-fixer-output" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#!/usr/bin/env python3 | ||
|
||
#""" | ||
#aaa | ||
#""" | ||
|
||
import sys, re, glob, pathlib, argparse, gzip | ||
|
||
from utils import run_cmd_no_fail, expect, GoodFormatter | ||
|
||
############################################################################### | ||
def parse_command_line(args, description): | ||
############################################################################### | ||
parser = argparse.ArgumentParser( | ||
usage="""\n{0} <CASE_DIR> [<param>=<val>] ... | ||
OR | ||
{0} --help | ||
|
||
\033[1mEXAMPLES:\033[0m | ||
\033[1;32m# Run hash checker on /my/case/dir \033[0m | ||
> {0} /my/case/dir | ||
""".format(pathlib.Path(args[0]).name), | ||
description=description, | ||
formatter_class=GoodFormatter | ||
) | ||
|
||
parser.add_argument( | ||
"case_dir", | ||
help="The test case you want to check" | ||
) | ||
|
||
return parser.parse_args(args[1:]) | ||
|
||
############################################################################### | ||
def readall(fn): | ||
############################################################################### | ||
with open(fn,'r') as f: | ||
txt = f.read() | ||
return txt | ||
|
||
############################################################################### | ||
def greptxt(pattern, txt): | ||
############################################################################### | ||
return re.findall('(?:' + pattern + ').*', txt, flags=re.MULTILINE) | ||
|
||
############################################################################### | ||
def grep(pattern, fn): | ||
############################################################################### | ||
txt = readall(fn) | ||
return greptxt(pattern, txt) | ||
|
||
############################################################################### | ||
def get_log_glob_from_atm_modelio(case_dir): | ||
############################################################################### | ||
filename = case_dir / 'CaseDocs' / 'atm_modelio.nml' | ||
ln = grep('diro = ', filename)[0] | ||
run_dir = pathlib.Path(ln.split()[2].split('"')[1]) | ||
ln = grep('logfile = ', filename)[0] | ||
atm_log_fn = ln.split()[2].split('"')[1] | ||
return str(run_dir / '**' / f'atm.log.*') | ||
|
||
############################################################################### | ||
oksanaguba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# EAMxx:: energy fixer: T tend added to each physics midlevel 0.000222 | ||
# EAMxx:: energy fixer: total energy before fix 32486509719.486938 | ||
# EAMxx:: energy fixer: rel energy error after fix -7.63290383866757e-18 | ||
|
||
def get_fixer_lines(fn,start_from_line): | ||
############################################################################### | ||
fixer_lines = [] | ||
error_vals = [] | ||
|
||
lines = [] | ||
with gzip.open(fn,'rt') as file: | ||
start_line_found = False | ||
for line in file: | ||
if start_line_found: | ||
lines.append(line) | ||
elif start_from_line in line: | ||
start_line_found = True | ||
|
||
i = 0 | ||
while i < len(lines): | ||
oksanaguba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
line = lines[i] | ||
i = i+1 | ||
# eamxx hash line has the form "eamxx hash> date=YYYY-MM-DD-XXXXX (STRING), naccum=INT | ||
# The INT at the end says how many of the following line contain hashes for this proc-step | ||
if "EAMxx:: energy fixer: rel energy error" in line: | ||
fixer_lines.append(line) | ||
lline = (line.strip('\n')) | ||
errr = float(lline.split()[8]) | ||
error_vals.append(errr) | ||
|
||
return fixer_lines,error_vals | ||
|
||
############################################################################### | ||
def get_model_start_of_step_lines (atm_log): | ||
############################################################################### | ||
lines = [] | ||
with gzip.open(atm_log,'rt') as file: | ||
for line in file: | ||
if "model beg-of-step time" in line: | ||
lines.append(line) | ||
return lines | ||
|
||
############################################################################### | ||
def check_fixer_output(case_dir): | ||
############################################################################### | ||
|
||
####################### TOLERANCE | ||
TOL = 1e-12 | ||
|
||
case_dir_p = pathlib.Path(case_dir) | ||
expect(case_dir_p.is_dir(), f"{case_dir} is not a dir") | ||
|
||
# Look for the two atm.log files. | ||
glob_pat = get_log_glob_from_atm_modelio(case_dir_p) | ||
atm_fns = glob.glob(glob_pat, recursive=True) | ||
if len(atm_fns) == 0: | ||
print('Could not find atm.log files with glob string {}'.format(glob_pat)) | ||
return False | ||
if len(atm_fns) == 1: | ||
print('Found output file {}'.format(atm_fns[0])) | ||
|
||
start_line = get_model_start_of_step_lines(atm_fns[0])[0] | ||
|
||
print (start_line) | ||
|
||
# Extract hash lines, along with their timestamps, but ignore anything | ||
# before the line $start_line | ||
f = atm_fns[0] | ||
fixer_lines,errs = get_fixer_lines(f,start_line) | ||
print('Array of rel. energy errors after energy fixer:',errs) | ||
errsa = [abs(ele) for ele in errs] | ||
mmax = max(errs) | ||
print('Abs. max. for the rel. energy errors:',mmax) | ||
|
||
if mmax < TOL: | ||
print('SUCCESS') | ||
return True | ||
else: | ||
print('FAIL, abs. max is less than tolerance, which is ', TOL) | ||
return False | ||
|
||
|
||
|
||
############################################################################### | ||
def _main_func(description): | ||
############################################################################### | ||
success = check_fixer_output(**vars(parse_command_line(sys.argv, description))) | ||
sys.exit(0 if success else 1) | ||
|
||
############################################################################### | ||
|
||
if (__name__ == "__main__"): | ||
_main_func(__doc__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.