Skip to content

Add API to normalise metrics - #3463

Open
dschwoerer wants to merge 14 commits into
nextfrom
normalise-metrics
Open

Add API to normalise metrics#3463
dschwoerer wants to merge 14 commits into
nextfrom
normalise-metrics

Conversation

@dschwoerer

Copy link
Copy Markdown
Contributor

With the encapsulation of the metrics, it got a bit more annoying to normalise the metrics.

Doing it in BOUT++ simplifies user code, but still allowing to do it in different ways, if you want something else.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread src/mesh/coordinates.cxx Outdated
Comment thread src/mesh/coordinates.cxx Outdated
@ZedThree

Copy link
Copy Markdown
Member

Is this different from TokamakCoordinates?

Could this also be a free function, rather than a member of Coordinates?

@dschwoerer

Copy link
Copy Markdown
Contributor Author

Is this different from TokamakCoordinates?

Yes, this is from the Hermes-3 branch that uses the metrics provided, and just normalises them.
The TokamakCoordinates should probably be used to replace https://github.com/boutproject/hermes-3/blob/master/src/recalculate_metric.cxx

Could this also be a free function, rather than a member of Coordinates?

No, because calling the setter on the metric tensor does recompute J and B. This is very wrong for FCI, and even for non-FCI not wanted. We want to just rescale those quantities.

@ZedThree

Copy link
Copy Markdown
Member

Ah, that's because we forgot to add an overload to setMetricTensor() to also take J and B. If you add that, then these could be free functions (or a method on TokamakCoordinates?), and we can avoid tying Coordinates to tokamaks.

Comment thread src/mesh/coordinates.cxx
Comment on lines +1341 to +1348
if (Bxy().isFci()) {
g_22_ylow();
g_22_yhigh();
ASSERT2(_g_22_ylow.has_value());
(*_g_22_ylow) /= rhoSQ;
ASSERT2(_g_22_yhigh.has_value());
(*_g_22_yhigh) /= rhoSQ;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ZedThree But then we need to expose an API for this?
I really think we should not do that.

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.

What if we move them to MetricTensor, and then TokamakCoordinates can also take care of normalising them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We could, but that surely should be FCICoordinates?

Are we fine with MetricTensor having a pointer to the mesh, so that it can load from the grid?

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.

I don't follow, sorry. g_22_ylow/high are computed for both FCI and non-FCI, and this normalisation is a particular tokamak one rather than FCI specific.

We could do that, or we could just load it along with the rest of the metric if it exists?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't follow, sorry. g_22_ylow/high are computed for both FCI and non-FCI,

Somewhat. For FCI, zoidberg does the computation using the actually magnetic field line length. On the BOUT++ side, it just gets loaded. For non-FCI we just interpolate.

and this normalisation is a particular tokamak one rather than FCI specific.

It needs to be done for the FCI, as we load it, rather then interpolate. And I think I also put it correctly in the FCI branch.

We could do that, or we could just load it along with the rest of the metric if it exists?

So you want to not do the lazy loading of that anymore? Should we then always throw for FCI if it is missing from the grid, even if the g_22_ylow is not used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we move this to the metric and keep it lazy, the metric now needs to now about the parallel transform.

I am wondering whether all the extra work is worth it? Should we maybe just accept that it is probably easier to have the normalisation done by the coordinates, and have an argument to select what kind of normalisation you want? Then it could not be done by a derived class without issues, but we could still offer the user a choice beyond the FCI and Tokamak geometries?

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.

2 participants