From 4e534e094a201e6f3ece0b05d2fd7fd4a1f93a90 Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Wed, 17 Dec 2025 10:28:41 +0000 Subject: [PATCH 1/8] Add reverse_current to tokamak_example.py --- examples/tokamak/tokamak_example.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/tokamak/tokamak_example.py b/examples/tokamak/tokamak_example.py index 28e3a461..074ff700 100755 --- a/examples/tokamak/tokamak_example.py +++ b/examples/tokamak/tokamak_example.py @@ -87,6 +87,7 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): parser.add_argument("--ny", type=int, default=65) parser.add_argument("--np", "--number-of-processors", type=int, default=-1) parser.add_argument("--no-plot", action="store_true", default=False) + parser.add_argument("--reverse-current", action="store_true", default=False) args = parser.parse_args() if "sn" in args.geometry: @@ -105,6 +106,9 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): if args.np >= 0: options.update(number_of_processors=args.np) + + if args.reverse_current: + options.update(reverse_current=True) # Generate an artificial poloidal flux function r1d, z1d, psi2d, psi1d = create_tokamak( From 6f521e69bc699ad8fac870c64123d91a39ea8b4b Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Wed, 17 Dec 2025 10:33:10 +0000 Subject: [PATCH 2/8] Add new tokamak_example flag to whats-new --- doc/whats-new.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.md b/doc/whats-new.md index ca2d954c..23a429fa 100644 --- a/doc/whats-new.md +++ b/doc/whats-new.md @@ -35,6 +35,8 @@ Release history By [John Omotani](https://github.com/johnomotani) - Script to convert UEDGE grid file to BOUT++ grid file (#136). By [Ben Dudson](https://github.com/bendudson) +- Add flag for `tokamak_example.py` to generate grids with reversed current. This + prevents negative `dx`/`J` and allows them to be run in BOUT++. 0.5.2 (13th March 2023) ------------------------- From 20018a3a2e56af6b8c4f226fee061389df815c48 Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Wed, 17 Dec 2025 15:51:26 +0000 Subject: [PATCH 3/8] Reverse_current true by default in tokamak_example --- examples/tokamak/tokamak_example.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/tokamak/tokamak_example.py b/examples/tokamak/tokamak_example.py index 074ff700..81753014 100755 --- a/examples/tokamak/tokamak_example.py +++ b/examples/tokamak/tokamak_example.py @@ -87,7 +87,12 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): parser.add_argument("--ny", type=int, default=65) parser.add_argument("--np", "--number-of-processors", type=int, default=-1) parser.add_argument("--no-plot", action="store_true", default=False) - parser.add_argument("--reverse-current", action="store_true", default=False) + parser.add_argument( + "--original-cocos", + action="store_true", + default=False, + help="Do not reverse current direction. WARNING: will cause warnings of negative J on running. Default: False.", + ) args = parser.parse_args() if "sn" in args.geometry: @@ -106,8 +111,9 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): if args.np >= 0: options.update(number_of_processors=args.np) - - if args.reverse_current: + + # Reverse current by default, unless --original-cocos=True + if not args.original_cocos: options.update(reverse_current=True) # Generate an artificial poloidal flux function From 97958501ac51abe9606e6dbc438046fb6a723ad9 Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Wed, 17 Dec 2025 15:52:01 +0000 Subject: [PATCH 4/8] tokamak_example: add no_guards flag --- examples/tokamak/tokamak_example.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/tokamak/tokamak_example.py b/examples/tokamak/tokamak_example.py index 81753014..c9a05b8a 100755 --- a/examples/tokamak/tokamak_example.py +++ b/examples/tokamak/tokamak_example.py @@ -93,6 +93,12 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): default=False, help="Do not reverse current direction. WARNING: will cause warnings of negative J on running. Default: False.", ) + parser.add_argument( + "--no-guards", + action="store_true", + default=False, + help="Remove Y boundary guards? Default: False.", + ) args = parser.parse_args() if "sn" in args.geometry: @@ -116,6 +122,9 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): if not args.original_cocos: options.update(reverse_current=True) + if args.no_guards: + options.update(y_boundary_guards=0) + # Generate an artificial poloidal flux function r1d, z1d, psi2d, psi1d = create_tokamak( geometry=args.geometry, From af51cbf929c48f9d4fe5c48dd15a7cc2181221ab Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Wed, 17 Dec 2025 15:57:22 +0000 Subject: [PATCH 5/8] tokamak_example.py: put reverse_current default into yaml --- examples/tokamak/connected-double-null.yaml | 1 + examples/tokamak/disconnected-double-null.yaml | 1 + examples/tokamak/single-null.yaml | 1 + examples/tokamak/tokamak_example.py | 6 +++--- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/tokamak/connected-double-null.yaml b/examples/tokamak/connected-double-null.yaml index 906f5c3d..d3ac6e39 100644 --- a/examples/tokamak/connected-double-null.yaml +++ b/examples/tokamak/connected-double-null.yaml @@ -32,3 +32,4 @@ target_all_poloidal_spacing_length: 0.3 # Smaller -> pack near targets xpoint_poloidal_spacing_length: 0.05 # Smaller -> pack near X-points y_boundary_guards: 2 +reverse_current: true diff --git a/examples/tokamak/disconnected-double-null.yaml b/examples/tokamak/disconnected-double-null.yaml index c45fa2fe..c8c3e337 100644 --- a/examples/tokamak/disconnected-double-null.yaml +++ b/examples/tokamak/disconnected-double-null.yaml @@ -33,3 +33,4 @@ target_all_poloidal_spacing_length: 0.3 # Smaller -> pack near targets xpoint_poloidal_spacing_length: 0.05 # Smaller -> pack near X-points y_boundary_guards: 2 +reverse_current: true \ No newline at end of file diff --git a/examples/tokamak/single-null.yaml b/examples/tokamak/single-null.yaml index 9d989a1d..d9107f74 100644 --- a/examples/tokamak/single-null.yaml +++ b/examples/tokamak/single-null.yaml @@ -29,3 +29,4 @@ target_all_poloidal_spacing_length: 0.3 # Smaller -> pack near targets xpoint_poloidal_spacing_length: 0.05 # Smaller -> pack near X-points y_boundary_guards: 2 +reverse_current: true \ No newline at end of file diff --git a/examples/tokamak/tokamak_example.py b/examples/tokamak/tokamak_example.py index c9a05b8a..457559ee 100755 --- a/examples/tokamak/tokamak_example.py +++ b/examples/tokamak/tokamak_example.py @@ -91,7 +91,7 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): "--original-cocos", action="store_true", default=False, - help="Do not reverse current direction. WARNING: will cause warnings of negative J on running. Default: False.", + help="Do not reverse current direction. WARNING: will cause warnings of negative J on running in BOUT++. Default: False.", ) parser.add_argument( "--no-guards", @@ -119,8 +119,8 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): options.update(number_of_processors=args.np) # Reverse current by default, unless --original-cocos=True - if not args.original_cocos: - options.update(reverse_current=True) + if args.original_cocos: + options.update(reverse_current=False) if args.no_guards: options.update(y_boundary_guards=0) From 3ce376fed6041a2b3d381e7cb080e35a50909030 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Wed, 17 Dec 2025 17:44:55 +0000 Subject: [PATCH 6/8] Option to manually trigger CI workflows --- .github/workflows/pythonpackage.yml | 1 + .github/workflows/pythonpublish.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 998d5f69..95725bf8 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -6,6 +6,7 @@ name: Python package on: push: pull_request: + workflow_dispatch: schedule: - cron: '25 1 3 * *' diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml index 71f79e67..707a876d 100644 --- a/.github/workflows/pythonpublish.yml +++ b/.github/workflows/pythonpublish.yml @@ -7,6 +7,7 @@ name: Upload Python Package on: release: types: [created] + workflow_dispatch: jobs: pytest: From e9347fc56b0b13f0eec97cbfdc937daa2b5efb9f Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Fri, 19 Dec 2025 10:39:52 +0000 Subject: [PATCH 7/8] flake8 formatting --- examples/tokamak/tokamak_example.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/tokamak/tokamak_example.py b/examples/tokamak/tokamak_example.py index 457559ee..c702840d 100755 --- a/examples/tokamak/tokamak_example.py +++ b/examples/tokamak/tokamak_example.py @@ -91,7 +91,9 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): "--original-cocos", action="store_true", default=False, - help="Do not reverse current direction. WARNING: will cause warnings of negative J on running in BOUT++. Default: False.", + help="""Do not reverse current direction. + WARNING: will cause warnings of negative J on running in BOUT++. + Default: False.""", ) parser.add_argument( "--no-guards", From f19862c7e7de3e8ae8f1f2b7b6ecdc0c53035a34 Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Tue, 6 Jan 2026 15:52:01 +0000 Subject: [PATCH 8/8] flake8 fix --- examples/tokamak/tokamak_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tokamak/tokamak_example.py b/examples/tokamak/tokamak_example.py index c702840d..bc2c5af2 100755 --- a/examples/tokamak/tokamak_example.py +++ b/examples/tokamak/tokamak_example.py @@ -91,8 +91,8 @@ def create_tokamak(geometry="lsn", nx=65, ny=65): "--original-cocos", action="store_true", default=False, - help="""Do not reverse current direction. - WARNING: will cause warnings of negative J on running in BOUT++. + help="""Do not reverse current direction. + WARNING: will cause warnings of negative J on running in BOUT++. Default: False.""", ) parser.add_argument(