-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poincare Boundary Condition #782
base: master
Are you sure you want to change the base?
Conversation
| benchmark_name | dt(%) | dt(s) | t_new(s) | t_old(s) |
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
test_build_transform_fft_lowres | +1.07 +/- 1.43 | +5.58e-03 +/- 7.47e-03 | 5.29e-01 +/- 6.3e-03 | 5.24e-01 +/- 4.0e-03 |
-test_equilibrium_init_medres | +11.22 +/- 0.85 | +5.00e-01 +/- 3.79e-02 | 4.96e+00 +/- 2.1e-02 | 4.46e+00 +/- 3.2e-02 |
-test_equilibrium_init_highres | +26.54 +/- 3.82 | +1.55e+00 +/- 2.23e-01 | 7.39e+00 +/- 1.4e-01 | 5.84e+00 +/- 1.7e-01 |
test_objective_compile_dshape_current | -2.26 +/- 5.35 | -9.53e-02 +/- 2.26e-01 | 4.12e+00 +/- 1.3e-01 | 4.22e+00 +/- 1.8e-01 |
-test_objective_compute_dshape_current | +34.64 +/- 1.84 | +1.80e-03 +/- 9.58e-05 | 7.00e-03 +/- 8.6e-05 | 5.20e-03 +/- 4.2e-05 |
test_objective_jac_dshape_current | +4.53 +/- 7.41 | +1.91e-03 +/- 3.13e-03 | 4.42e-02 +/- 2.4e-03 | 4.23e-02 +/- 2.0e-03 |
test_perturb_2 | +3.59 +/- 2.15 | +7.07e-01 +/- 4.23e-01 | 2.04e+01 +/- 2.8e-01 | 1.97e+01 +/- 3.2e-01 |
test_proximal_freeb_jac | +0.11 +/- 2.09 | +7.89e-03 +/- 1.51e-01 | 7.21e+00 +/- 9.4e-02 | 7.21e+00 +/- 1.2e-01 |
test_solve_fixed_iter | +1.20 +/- 2.51 | +3.88e-01 +/- 8.08e-01 | 3.26e+01 +/- 6.7e-01 | 3.22e+01 +/- 4.5e-01 |
test_LinearConstraintProjection_build | +1.80 +/- 2.95 | +1.86e-01 +/- 3.04e-01 | 1.05e+01 +/- 1.3e-01 | 1.03e+01 +/- 2.7e-01 |
test_build_transform_fft_midres | +4.42 +/- 6.26 | +2.82e-02 +/- 3.99e-02 | 6.65e-01 +/- 9.8e-03 | 6.37e-01 +/- 3.9e-02 |
test_build_transform_fft_highres | +4.92 +/- 4.14 | +4.85e-02 +/- 4.08e-02 | 1.03e+00 +/- 3.6e-02 | 9.86e-01 +/- 1.9e-02 |
-test_equilibrium_init_lowres | +14.68 +/- 2.24 | +6.39e-01 +/- 9.77e-02 | 4.99e+00 +/- 4.0e-02 | 4.35e+00 +/- 8.9e-02 |
test_objective_compile_atf | +1.65 +/- 3.73 | +1.40e-01 +/- 3.17e-01 | 8.64e+00 +/- 3.1e-01 | 8.50e+00 +/- 4.4e-02 |
-test_objective_compute_atf | +16.51 +/- 4.87 | +2.71e-03 +/- 7.99e-04 | 1.91e-02 +/- 6.0e-04 | 1.64e-02 +/- 5.3e-04 |
test_objective_jac_atf | +2.99 +/- 1.84 | +5.94e-02 +/- 3.65e-02 | 2.05e+00 +/- 2.2e-02 | 1.99e+00 +/- 2.9e-02 |
test_perturb_1 | +5.23 +/- 4.14 | +7.94e-01 +/- 6.30e-01 | 1.60e+01 +/- 3.9e-01 | 1.52e+01 +/- 4.9e-01 |
test_proximal_jac_atf | +0.83 +/- 0.71 | +6.92e-02 +/- 5.91e-02 | 8.37e+00 +/- 5.3e-02 | 8.31e+00 +/- 2.7e-02 |
test_proximal_freeb_compute | +3.47 +/- 1.91 | +6.51e-03 +/- 3.59e-03 | 1.94e-01 +/- 2.0e-03 | 1.88e-01 +/- 3.0e-03 |
test_solve_fixed_iter_compiled | +2.99 +/- 2.80 | +6.21e-01 +/- 5.81e-01 | 2.14e+01 +/- 4.2e-01 | 2.08e+01 +/- 4.1e-01 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the better API would be to introduce new degrees of freedom Rp, Zp etc like we have for the LCFS and axis, and then constrain those to be self consistent.
This would eliminate the boundary_mode
thing, and allow more flexibility for setting up constraints.
Each equilibrium, in addition to having a .surface
and .axis
attribute would have a .poincare
or .section
property with the ZernikeRZToroidalSurface object. This would then have an assigned zeta value so we wouldn't need to pass around zeta to different functions.
@f0uriest I made some changes to the API. First of all, I created a new class called PoincareSurface (which is an inherited class of ZernikeRzToroidalSection) to be able to store lambda basis and coefficients in the section. That class needs more cleaning but my main aim is to decide which type of objectives to use by checking the eq.surface type. This can be either FourierRZToroidalSurface or PoincareSurface. I changed the previous eq.bdry_mode stuff to that. Also, I am using the zeta of the surface now, so no need to pass zeta value to optimizer and objectives anymore. |
Let's get rid of support for the Poincare BC from a text input file in this PR |
I changed the hacky way with another approach where I declare some parameters non-optimizable. To do so, I added a new function inside |
@@ -3,34 +3,33 @@ | |||
# on 11/20/2023 at 14:54:04. | |||
# For details on the various options see https://desc-docs.readthedocs.io/en/stable/input.html | |||
|
|||
# global parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from bdry_mode = lcfs
line, rest is due to black formatter
…izable by default, if FixSection added then they become optimizable
@@ -693,6 +695,8 @@ def solve_continuation( # noqa: C901 | |||
NotImplementedError, | |||
"Continuation method with anisotropic pressure is not currently supported", | |||
) | |||
# TODO: add warning for cases with Poincare BC. This needs a better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this done above?
@@ -12,6 +12,11 @@ def compute_scaling_factors(thing): | |||
|
|||
scales = {} | |||
|
|||
# change this to also work with Poincare XS where bdry is ZernikePolynomial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can get rid of this comment
@@ -67,6 +70,20 @@ def get_deltas(things1, things2): # noqa: C901 | |||
if not jnp.allclose(a2.Z_n, a1.Z_n): | |||
deltas["Za_n"] = a2.Z_n - a1.Z_n | |||
|
|||
if "surface_poincare" in things1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should call this section
or xsection
or whatever name we use elsewhere (pick one and use it consistently)
eq_poin.change_resolution(eq.L, eq.M, eq.N) | ||
eq_poin.axis = eq_poin.get_axis() | ||
eq_poin.surface = eq_poin.get_surface_at(rho=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these necessary? Shouldn't these already be set when you create the equilibrium?
desc/equilibrium/equilibrium.py
Outdated
|
||
constraints = maybe_add_self_consistency(self, constraints) | ||
# TODO: make this more general and probably put it somewhere else | ||
if not is_any_instance(constraints, SectionRSelfConsistency): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we end up keeping this, it should be in Optimizer.optimize
not here, otherwise it won't get called in some cases
desc/equilibrium/equilibrium.py
Outdated
|
||
constraints = maybe_add_self_consistency(self, constraints) | ||
# TODO: make this more general and probably put it somewhere else | ||
if not is_any_instance(constraints, SectionRSelfConsistency): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
warnif( | ||
zeta != 0, | ||
UserWarning, | ||
"The lambda value of the returned surface will not be correct " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still need to do this
Resolves #204
Resolves #773
This PR focuses on solving equilibrium by giving a Poincare section at zeta 0 surfaces instead of giving the last closed flux surface, LCFS.
This method gives exactly same results for high NFP >12, but different results for low NFP cases. Note: as far as my observation, the difference is caused by the NFP, but it might caused by something else that I am missing.
Tasks,
get_fixed_xsection_constraints()
utilityPrevious tasks that I am not sure about,
Rp_lmn
Zp_lmn
Lp_lmn
andxsection
.Equilibrium
with a Poincare section, check that initial axis is consistent with the equilibrium (it should just be a circular axis at the poincare section axis position) (I think it is like that but I don't know what Dario meant exactly)