Skip to content

Add reverse_current to tokamak_example.py#206

Merged
bendudson merged 9 commits into
masterfrom
examples-reverse-current
Jan 15, 2026
Merged

Add reverse_current to tokamak_example.py#206
bendudson merged 9 commits into
masterfrom
examples-reverse-current

Conversation

@mikekryjak
Copy link
Copy Markdown
Collaborator

@mikekryjak mikekryjak commented Dec 17, 2025

tokamak_example.py is a precious resource because it can generate example grids of all topologies. We need this for all kinds of tests in Hermes-3, xBOUT and xHermes.

Unfortunately, the COCOS convention is such that you get warnings about negative J due to a negative dx when you run with the grids.

This PR adds the flag --reverse-current to tokamak_example.py which passes it to the yaml input file. This flips the psi direction and allows it to be run.

This PR changes the default current direction in the YAML files for the examples. There is now a new flag --original-cocos to disable reverse_current. There is also a new flag called --no-guards to generate a grid without guard cells.

  • Add feature
  • Updated doc/whats-new.md with a summary of the changes

Copy link
Copy Markdown
Collaborator

@johnomotani johnomotani left a comment

Choose a reason for hiding this comment

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

Looks good to me. @mikekryjak up to you if you want to address the comment.

Comment thread examples/tokamak/tokamak_example.py Outdated
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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this example only works properly with the current reversed, maybe we want to default to doing this, so make the command line flag --no-reverse-current and reverse the current unless the user passes this flag?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I didn't want to break anything else that this example is used for. If you can't think of anything, then happy to do this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As far as I know this example isn't used in production for anything, or for tests (apart from a test that it runs at all), so I think it should be fine. Anyway, better to have a more usable solution than stick to the existing one just for historical consistency - something like this I think is low risk and if it affects anyone they can raise an issue.

@johnomotani
Copy link
Copy Markdown
Collaborator

Added a new commit, mostly to trigger the CI jobs (which had been suspended due to inactivity on the repo). Added the option to manually trigger CI, which would have been useful now!

@mikekryjak
Copy link
Copy Markdown
Collaborator Author

@johnomotani I fixed the flake issues but there seems to be a spurious CI failure. Are we OK to merge? Is there a way to re-trigger the CI to see if it's spurious?

@mikekryjak
Copy link
Copy Markdown
Collaborator Author

The LDN topology has the opposite psi sign to the other examples:

"ldn": lambda R, Z: (
-np.exp(-((R - r0) ** 2 + Z**2) / 0.3**2)
- np.exp(-((R - r0) ** 2 + (Z + 2 * z0) ** 2) / 0.3**2)
- np.exp(-((R - r0) ** 2 + (Z - 2 * z0 - 0.003) ** 2) / 0.3**2)

I'd like to make it consistent but I'm wondering if this was done on purpose. @bendudson do you remember if this is required?

@bendudson bendudson merged commit ffc1852 into master Jan 15, 2026
36 of 37 checks passed
@bendudson bendudson deleted the examples-reverse-current branch January 15, 2026 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants