Skip to content

Allow distributing the points on the inner surface more smoothly#35

Merged
ZedThree merged 53 commits intomasterfrom
more-6
Nov 24, 2025
Merged

Allow distributing the points on the inner surface more smoothly#35
ZedThree merged 53 commits intomasterfrom
more-6

Conversation

@dschwoerer
Copy link
Copy Markdown
Collaborator

This commits adds the option inner_maxmode, which can be used in combination with inner_ort to distribute the points on the inner boundary more smoothly. Unlike maxmode_inner, this does not sets a maximum ratio, but ensures that the points are distributed locally smoothly, by removing high frequency modes in the distrbution.

This is not enabled by default, as the value of inner_maxmode depends on the the specific mesh. But it seems that for simple cases, low values around 5 seem to be good.

dschwoerer and others added 28 commits December 9, 2024 10:52
This commits adds the option `inner_maxmode`, which can be used in combination
with `inner_ort` to distribute the points on the inner boundary more smoothly.
Unlike `maxmode_inner`, this does not sets a maximum ratio, but ensures that
the points are distributed locally smoothly, by removing high frequency modes
in the distrbution.

This is not enabled by default, as the value of inner_maxmode depends on
the the specific mesh. But it seems that for simple cases, low values
around 5 seem to be good.
Also remove some debugging code.
This is needed if additional worktrees are checked out for building the
package.
This allows to gradually write a file. This can reduce memory
consumptions and allows to continue if it fails while running.

It also fixes the calculation of the parallel slices.
servers are sometimes busy
This reverts commit 8102f0b.

This caused the package build to miss some files.
For large grids that fail to converge, the current upper bound of
iterations can be extremly time consuming. This new, lower bound seems
to also work for strongly shaped grids, if it is converging at all.
Mostly churn, zoidberg had a real bug
This class wraps a fieldlinetracer, and returns a previous result, if
the same x, z and y coordinates are given. If other parameters change,
like magnetic field, the user has to change the field name to avoid
returning the wrong result.
Do only trace once in forward and backward direction, not once per
target.

For myg=2 this should reduce tracing cost by about 33%.
Ensures that dy has no jump to negative values where the periodic
boundary is crossed.
This is a memory efficient version, that can be conviniently called on
the MapWriter
"""
Parameters
----------
m: torodial mode number
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.

This 'm' and 'n' choice seems to be opposite to the usual convention: 'n' is usually used for toroidal mode number, 'm' for poloidal.

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.

@bendudson Should we change the order or n and m? It might break any code that passes m= - but it might be broken now and that fixes it ...
I did not use the code, just fixed it as ruff was complaining, so I have no strong opinion either way ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 for m: poloidal, n: toroidal, this is a pretty strong convention

@dschwoerer
Copy link
Copy Markdown
Collaborator Author

I think I have addressed all concerns.

I have stayed with asserts, but added a (hopefully) helpful error message to them. I find that cleaner.

@dschwoerer dschwoerer requested a review from ZedThree October 30, 2025 09:25
@dschwoerer dschwoerer mentioned this pull request Oct 30, 2025
for k in "RZ":
n = parallel_slice_field_name(k, offset)
keep[n] = maps[n]
del maps
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't do anything, it just deletes the local reference which will be deleted when it goes out of scope anyway

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.

_write_par_metric may use a lot of memory, so it is good to free up before what we can easily.

Comment on lines +305 to +306
del R
del Z
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But they're going to go out of scope at the end of this function, can we really not call _write_metric if these haven't been GC'd? There's no guarantee that it will run before then anyway

Comment on lines +489 to +498
if update:
oldattrs = f.list_file_attributes()
for k in list(attrs.keys()):
if k in oldattrs:
oldattr = f"old_{k}"
j = 0
while oldattr in oldattrs:
oldattr = f"old{j}_{k}"
j += 1
attrs[oldattr] = f.read_file_attribute(k)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure I see the point in updating a grid file -- why not just keep the old one?

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.

The old grid file may not have parallel metrics or other thinks.
Sometimes it is easier to update a grid then to start from scratch.

self,
gridfile="fci.grid.nc",
new_names=False,
format="NETCDF4",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's just drop this. I'm not sure there are any other sensible choices!

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.

👍

@ZedThree
Copy link
Copy Markdown
Member

Leftover format argument in the MMS test :)

@dschwoerer
Copy link
Copy Markdown
Collaborator Author

Not in the MMS tests, but in write_maps.
A bit worrying that only the MMS tests noticed this 😓

@ZedThree ZedThree merged commit 68ffe3c into master Nov 24, 2025
11 checks passed
@ZedThree ZedThree deleted the more-6 branch November 24, 2025 11:30
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