Skip to content

Commit

Permalink
fix self consistency stuff better
Browse files Browse the repository at this point in the history
  • Loading branch information
YigitElma committed Dec 14, 2024
1 parent 654d3b3 commit 59fb333
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 31 deletions.
26 changes: 2 additions & 24 deletions desc/equilibrium/equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -2275,22 +2275,11 @@ def solve(
options=options,
copy=copy,
)
from desc.objectives import (
AxisRSelfConsistency,
BoundaryRSelfConsistency,
SectionRSelfConsistency,
)
from desc.objectives import SectionRSelfConsistency
from desc.objectives.getters import maybe_add_self_consistency

constraints = maybe_add_self_consistency(self, constraints)
# TODO: make this more general and probably put it somewhere else
if not (
is_any_instance(constraints, BoundaryRSelfConsistency)
and is_any_instance(constraints, AxisRSelfConsistency)
):
things[0].surface = things[0].get_surface_at(rho=1.0)
if not is_any_instance(constraints, AxisRSelfConsistency):
things[0].axis = things[0].get_axis()
if not is_any_instance(constraints, SectionRSelfConsistency):
things[0].xsection = things[0].get_surface_at(zeta=0)

Expand Down Expand Up @@ -2376,22 +2365,11 @@ def optimize(
options=options,
copy=copy,
)
from desc.objectives import (
AxisRSelfConsistency,
BoundaryRSelfConsistency,
SectionRSelfConsistency,
)
from desc.objectives import SectionRSelfConsistency
from desc.objectives.getters import maybe_add_self_consistency

constraints = maybe_add_self_consistency(self, constraints)
# TODO: make this more general and probably put it somewhere else
if not (
is_any_instance(constraints, BoundaryRSelfConsistency)
and is_any_instance(constraints, AxisRSelfConsistency)
):
things[0].surface = things[0].get_surface_at(rho=1.0)
if not is_any_instance(constraints, AxisRSelfConsistency):
things[0].axis = things[0].get_axis()
if not is_any_instance(constraints, SectionRSelfConsistency):
things[0].xsection = things[0].get_surface_at(zeta=0)

Expand Down
6 changes: 6 additions & 0 deletions desc/objectives/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ def maybe_add_self_consistency(thing, constraints): # noqa: C901
# For example, if we are fixing the boundary R, then we add a dummy fixed
# parameter for the section R. This is not ideal, but it is a workaround.
# This helps with the factorization of the linear constraints matrix.
# Extra conditions are added to avoid edge cases like calling this function
# twice. The first turn will change the constraints, and the second turn
# should account for that.
if {"R_lmn", "Rb_lmn"} <= params and not is_any_instance(
constraints, BoundaryRSelfConsistency
):
Expand All @@ -393,6 +396,7 @@ def maybe_add_self_consistency(thing, constraints): # noqa: C901
if (
{"R_lmn", "Rp_lmn"} <= params
and not is_any_instance(constraints, SectionRSelfConsistency)
and not is_any_instance(constraints, FixBoundaryR)
and is_any_instance(constraints, FixSectionR)
):
constraints += (SectionRSelfConsistency(eq=thing),)
Expand All @@ -403,6 +407,7 @@ def maybe_add_self_consistency(thing, constraints): # noqa: C901
if (
{"Z_lmn", "Zp_lmn"} <= params
and not is_any_instance(constraints, SectionZSelfConsistency)
and not is_any_instance(constraints, FixBoundaryZ)
and is_any_instance(constraints, FixSectionZ)
):
constraints += (SectionZSelfConsistency(eq=thing),)
Expand All @@ -413,6 +418,7 @@ def maybe_add_self_consistency(thing, constraints): # noqa: C901
if (
{"L_lmn", "Lp_lmn"} <= params
and not is_any_instance(constraints, SectionLambdaSelfConsistency)
and not is_any_instance(constraints, FixBoundaryR)
and is_any_instance(constraints, FixSectionLambda)
):
constraints += (SectionLambdaSelfConsistency(eq=thing),)
Expand Down
7 changes: 0 additions & 7 deletions desc/perturbations.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,6 @@ def perturb( # noqa: C901
timer.disp("Total perturbation")

# TODO: make this more general and probably put it somewhere else
if not (
is_any_instance(constraints, BoundaryRSelfConsistency)
and is_any_instance(constraints, AxisRSelfConsistency)
):
eq_new.surface = eq_new.get_surface_at(rho=1.0)
if not is_any_instance(constraints, AxisRSelfConsistency):
eq_new.axis = eq_new.get_axis()
if not is_any_instance(constraints, SectionRSelfConsistency):
eq_new.xsection = eq_new.get_surface_at(zeta=0)

Expand Down

0 comments on commit 59fb333

Please sign in to comment.