Skip to content

Commit

Permalink
Add negative sign to residual for diagbroyden optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
unalmis committed Sep 18, 2024
1 parent 426c985 commit 97d1747
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
6 changes: 3 additions & 3 deletions desc/equilibrium/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def map_coordinates( # noqa: C901
L_lmn=params["L_lmn"],
L_basis=eq.L_basis,
guess=guess[:, 1] if guess is not None else None,
period=period[1] if period is not None else 2 * np.pi,
period=period[1] if period is not None else np.inf,
tol=tol,
maxiter=maxiter,
full_output=full_output,
Expand Down Expand Up @@ -289,7 +289,7 @@ def _map_PEST_coordinates(
L_lmn,
L_basis,
guess,
period=2 * np.pi,
period=np.inf,
tol=1e-6,
maxiter=30,
full_output=False,
Expand All @@ -311,7 +311,7 @@ def _map_PEST_coordinates(
Shape (k, ).
Optional initial guess for the computational coordinates.
period : float
Assumed periodicity for ϑ. Default is 2π.
Assumed periodicity for ϑ.
Use ``np.inf`` to denote no periodicity.
tol : float
Stopping tolerance.
Expand Down
1 change: 0 additions & 1 deletion desc/equilibrium/equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,6 @@ def compute_theta_coords(
inbasis=("rho", "theta_PEST", "zeta"),
outbasis=("rho", "theta", "zeta"),
params=self.params_dict if L_lmn is None else {"L_lmn": L_lmn},
period=(np.inf, 2 * np.pi, np.inf),
tol=tol,
maxiter=maxiter,
full_output=full_output,
Expand Down
8 changes: 2 additions & 6 deletions desc/vmec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ def root_fun(theta):
)
theta_PEST_k = theta + lmbda
r = theta_PEST_k - theta_PEST
return r
return -r # the negative sign is necessary

out = optimize.root(
root_fun, x0=theta_PEST, method="diagbroyden", options={"ftol": 1e-6}
Expand Down Expand Up @@ -1786,11 +1786,7 @@ def compute_coord_surfaces(cls, equil, vmec_data, Nr=10, Nt=8, Nz=None, **kwargs

# find theta angles corresponding to desired theta* angles
v_grid = Grid(
equil.map_coordinates(
t_grid.nodes,
inbasis=("rho", "theta_PEST", "zeta"),
period=(np.inf, 2 * np.pi, np.inf),
)
equil.map_coordinates(t_grid.nodes, inbasis=("rho", "theta_PEST", "zeta"))
)
r_coords_desc = equil.compute(["R", "Z"], grid=r_grid)
v_coords_desc = equil.compute(["R", "Z"], grid=v_grid)
Expand Down

0 comments on commit 97d1747

Please sign in to comment.