-
Notifications
You must be signed in to change notification settings - Fork 43
Fix edge case where meshblocks can be improperly de-refined #1248
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
16 commits
Select commit
Hold shift + click to select a range
e6fec8a
lukes nicer cleanup
jonahm-LANL 51d5a4a
add compute asymmetry script
jonahm-LANL 822698b
Add shebang to movie2d
jonahm-LANL d622d1c
document how to change output cadence from restart
jonahm-LANL 88329de
changelog
jonahm-LANL 628df9b
CC
jonahm-LANL b7ceceb
Merge branch 'develop' into jmm/amr-fix
Yurlungur 6facd7f
CC
jonahm-LANL 26e6c4b
Merge branch 'jmm/amr-fix' of github.com:parthenon-hpc-lab/parthenon …
jonahm-LANL 508f0c7
Try to move all LogicalLocation related logic to class methods
lroberts36 2b8ab9b
fix bugs
lroberts36 48b65fc
make sure colorbar label generated
jonahm-LANL 37efb1f
Update doc/sphinx/src/outputs.rst
Yurlungur 2f11fcb
Update doc/sphinx/src/outputs.rst
Yurlungur 1aaa8b3
add resport_asymmetry
jonahm-LANL 17bc616
Merge branch 'jmm/amr-fix' of github.com:parthenon-hpc-lab/parthenon …
jonahm-LANL 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
66 changes: 66 additions & 0 deletions
66
scripts/python/packages/parthenon_tools/parthenon_tools/compute_asymmetry.py
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,66 @@ | ||
| #!/usr/bin/env python | ||
| # ======================================================================================== | ||
| # (C) (or copyright) 2025. Triad National Security, LLC. All rights reserved. | ||
| # | ||
| # This program was produced under U.S. Government contract 89233218CNA000001 for Los | ||
| # Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC | ||
| # for the U.S. Department of Energy/National Nuclear Security Administration. All rights | ||
| # in the program are reserved by Triad National Security, LLC, and the U.S. Department | ||
| # of Energy/National Nuclear Security Administration. The Government is granted for | ||
| # itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide | ||
| # license in this material to reproduce, prepare derivative works, distribute copies to | ||
| # the public, perform publicly and display publicly, and to permit others to do so. | ||
| # ======================================================================================== | ||
|
|
||
| import sys | ||
| import numpy as np | ||
| import h5py | ||
| from argparse import ArgumentParser | ||
|
|
||
|
|
||
| def compute_asymmetry(f, varname): | ||
| "Computes the asymmetry of var with varname in hdf5 output file object f" | ||
| xlocs = f["Locations/x"][:] | ||
| ylocs = f["Locations/y"][:] | ||
| iylocs = -np.flip(f["Locations/y"][:], axis=1) | ||
| matches = np.zeros((ylocs.shape[0]), dtype=int) | ||
| for b in range(ylocs.shape[0]): | ||
| for bb in range(ylocs.shape[0]): | ||
| if np.all(np.abs(ylocs[b] - iylocs[bb]) <= 1e-10) and np.all( | ||
| np.abs(xlocs[b] - xlocs[bb]) <= 1e-10 | ||
| ): | ||
| matches[b] = bb | ||
|
|
||
| var = f[varname][:] | ||
| var_diff = np.zeros_like(var) | ||
| for b in range(ylocs.shape[0]): | ||
| bb = matches[b] | ||
| if np.any(ylocs[b] >= 0): | ||
| for d in range(var_diff.shape[1]): | ||
| sign = -1 if (var.shape[1] == 3) and d == 1 else 1 | ||
| var_diff[b, d] = var[b, d] - sign * np.flip(var[bb, d], axis=-2) | ||
| var_diff[bb, d] = var[bb, d] - sign * np.flip(var[b, d], axis=-2) | ||
|
|
||
| return var_diff | ||
|
|
||
|
|
||
| parser = ArgumentParser( | ||
| prog="compute_asymmetry.py", | ||
| description="compute asymmetry in X2 of a field and save it to the output file. " | ||
| + "Assumes mesh is symmetric about 0 in X2. " | ||
| + "Only works for cell- and node-centered data.", | ||
| ) | ||
| parser.add_argument("field", type=str, help="Variable to compute") | ||
| parser.add_argument("files", type=str, nargs="+", help="Files to compute") | ||
|
|
||
| if __name__ == "__main__": | ||
| args = parser.parse_args() | ||
| for i, fname in enumerate(args.files): | ||
| with h5py.File(fname, "a") as f: | ||
| print(f"Computing asymmetry for {args.field} in {fname}...") | ||
| var_diff = compute_asymmetry(f, args.field) | ||
| savename = f"{args.field}_asymmetry" | ||
| try: | ||
| f.create_dataset(savename, data=var_diff) | ||
| except ValueError: | ||
| f[savename][:] = var_diff |
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| #!/usr/bin/env python | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shebang was just missing before. |
||
| # ========================================================================================= | ||
| # (C) (or copyright) 2020-2025. Triad National Security, LLC. All rights reserved. | ||
| # | ||
|
|
@@ -295,7 +296,7 @@ def plot_dump( | |
| if swarmx is not None and swarmy is not None: | ||
| p.scatter(swarmx, swarmy, s=particlesize, c=swarmcolor) | ||
| if colorbar is not None: | ||
| plt.colorbar(pm, fraction=0.02, pad=0.04, ax=p) | ||
| plt.colorbar(pm, label=colorbar, fraction=0.02, pad=0.04, ax=p) | ||
|
|
||
| fig.savefig(output_file, dpi=300) | ||
| plt.close(fig=fig) | ||
|
|
||
54 changes: 54 additions & 0 deletions
54
scripts/python/packages/parthenon_tools/parthenon_tools/report_asymmetry.py
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,54 @@ | ||
| #!/usr/bin/env/python | ||
| # ======================================================================================== | ||
| # (C) (or copyright) 2025. Triad National Security, LLC. All rights reserved. | ||
| # | ||
| # This program was produced under U.S. Government contract 89233218CNA000001 for Los | ||
| # Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC | ||
| # for the U.S. Department of Energy/National Nuclear Security Administration. All rights | ||
| # in the program are reserved by Triad National Security, LLC, and the U.S. Department | ||
| # of Energy/National Nuclear Security Administration. The Government is granted for | ||
| # itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide | ||
| # license in this material to reproduce, prepare derivative works, distribute copies to | ||
| # the public, perform publicly and display publicly, and to permit others to do so. | ||
| # ======================================================================================== | ||
|
|
||
| import sys | ||
| import numpy as np | ||
| from argparse import ArgumentParser | ||
|
|
||
| import os | ||
|
|
||
| sys.path.insert( | ||
| 0, "../external/parthenon/scripts/python/packages/parthenon_tools/parthenon_tools" | ||
| ) | ||
| import h5py | ||
| from compute_asymmetry import compute_asymmetry | ||
|
|
||
| parser = ArgumentParser( | ||
| prog="report_asymmetry.py", | ||
| description="Report asymmetry in X2 of all fields and save it to the output file. " | ||
| + "Assumes mesh is symmetric about 0 in X2. " | ||
| + "Only works for cell- and node-centered data.", | ||
| ) | ||
| parser.add_argument("files", type=str, nargs="+", help="Files to compute") | ||
|
|
||
| dset_type = h5py._hl.dataset.Dataset | ||
| if __name__ == "__main__": | ||
| args = parser.parse_args() | ||
| for fname in args.files: | ||
| with h5py.File(fname, "r") as f: | ||
| print(f"Computing asymmetry in {fname} for vars...") | ||
| for k, v in f.items(): | ||
| # Try to exclude face- and edge-centered data | ||
| if (type(v) == dset_type) and ("bnd_flux" not in k): | ||
| if len(v.shape) > 2: | ||
| print(f"\t...{k}:") | ||
| try: | ||
| var_diff = compute_asymmetry(f, k) | ||
| print( | ||
| "\t\t{:14e} out of {:14e}".format( | ||
| np.max(np.abs(var_diff)), np.max(np.abs(f[k])) | ||
| ) | ||
| ) | ||
| except ValueError: | ||
| print("\t\tcorrupted!") |
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.