Skip to content

fix restart file writing when grid has no y-guard cells#333

Open
Vandoo wants to merge 2 commits intomasterfrom
pad_restart_ybndry
Open

fix restart file writing when grid has no y-guard cells#333
Vandoo wants to merge 2 commits intomasterfrom
pad_restart_ybndry

Conversation

@Vandoo
Copy link
Copy Markdown
Collaborator

@Vandoo Vandoo commented Feb 9, 2026

Use boutdata (which includes guard cells) to create new restart files even when the original grid file lacks y-guard cells.

Qian Xia and others added 2 commits February 9, 2026 18:03
Use boutdata (which includes guard cells) to create new restart
files even when the original grid file lacks y-guard cells.
@mikekryjak
Copy link
Copy Markdown
Collaborator

Hi @Vandoo, thanks for this!

I'm not sure if I understand the changes in the PR. I don't see boutdata being used. Is this because I missed something or because the PR is not yet finished?

@Vandoo
Copy link
Copy Markdown
Collaborator Author

Vandoo commented Feb 11, 2026

It's a quick fix on line 327 in xbout/utils.py. When writing new restart files from a full dataset that includes y_guard cells, _pad_y_boundaries() would incorrectly add extra ghost values if the current grid didn't have guard cells. This change skips the padding in that specific case and copies boundary values directly from the source dataset instead.

@dschwoerer
Copy link
Copy Markdown
Contributor

The question is why is ds.metadata["keep_yboundaries"] not set then?
How did you get to the dataset?

@Vandoo
Copy link
Copy Markdown
Collaborator Author

Vandoo commented Feb 11, 2026

The question is why is ds.metadata["keep_yboundaries"] not set then? How did you get to the dataset?

The dataset with extra guard cells are obtained with squashoutput(datadir='./'). I use the default

ds = xhermes.open_hermesdataset(prepath+dataname)

to open the file. However, the loaded data contains'keep_yboundaries': False,. I also tried the lower-level xBOUT call a = open_boutdataset('BOUT.dmp.*.nc'), but it gives the same result.

And because it is not compatible with the grid resolution, I could not use something like:

ds = xhermes.open_hermesdataset(prepath+dataname, geometry="toroidal", gridfilepath=gridname, keep_yboundaries=...)

@mikekryjak
Copy link
Copy Markdown
Collaborator

And because it is not compatible with the grid resolution, I could not use something like:

ds = xhermes.open_hermesdataset(prepath+dataname, geometry="toroidal", gridfilepath=gridname, keep_yboundaries=...)

What do you mean when you say this is not compatible with the grid resolution? Is it something to do with greater computational cost in 3D simulations?

@Vandoo
Copy link
Copy Markdown
Collaborator Author

Vandoo commented Feb 14, 2026

What do you mean when you say this is not compatible with the grid resolution? Is it something to do with greater computational cost in 3D simulations?

kinda. To reduce the computional cost in 3D, we could start with a small-resolution case (e.g. ny=28, with only 4 cells in the outer divertor leg on the MAST-U grid provided by Ben). But it is very challenge to grid such a small mesh with y guard cells in hypnotoad, thus the gridfile does not have it.

However, if you then use bout.to_restart, the generated restart files will not contain y guard cells. As a result, any sheath-related data stored in those guard cells is lost. Also, you can see this directly by checking the restart files in the simulation directory. The restart files include guard cells regardless of whether y guard cells exist in the grid file or not. I believe this is the default behaviour in parallel simulations.

@johnomotani
Copy link
Copy Markdown
Collaborator

If this issue is being that much of a problem in xbout, an alternative approach could be to duplicate the BOUT++ extrapolation in hypnotoad as an option, so that boundary cells could be created without actually using the equilibrium in them. This would need to be implemented in a sort of 'post-processing' step after generating the grid but before writing output. It probably shouldn't be too hard to implement, as I think there is a single function that converts 2D arrays to output format, and that should be the only place that needs to be modified.

@mikekryjak
Copy link
Copy Markdown
Collaborator

@Vandoo I'm still very confused, I don't think I understand your issue. Could you explain in a different way from scratch? Is the simulation you reading into xHermes/xBOUT with or without guard cells?

@Vandoo
Copy link
Copy Markdown
Collaborator Author

Vandoo commented Feb 19, 2026

@Vandoo I'm still very confused, I don't think I understand your issue. Could you explain in a different way from scratch? Is the simulation you reading into xHermes/xBOUT with or without guard cells?

The grid file itself has no guard cells. Hermes-3 reconstructs them at runtime as you know. When loading into xBOUT, I can choose whether to keep guard cells or not, which is just post-processing. Then

  1. For any calculation that requires the geometry (i.e. uses gridfilepath), we normally drop the guard cells from BOUT.dmp.*.nc to stay consistent with the original grid file.
  2. For writing restart files, however, guard cells are normally required. In parallel runs they are part of the evolving state.

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.

4 participants