plt.savefig('Results/ReimanInitialPoincare.png', dpi=500) plt.savefig('Results/ReimanInitialPoincare.pdf') p.plot_iota() plt.tight_layout() plt.savefig('Results/ReimanInitialIota.png') # exit() ## Optimization prob = LeastSquaresProblem([(obj.residue1, 0, 1)]) # Set degrees of freedom for the optimization obj.all_fixed() obj.set_fixed('epsilon', False) # Run optimization problem # nIterations = 10 print('Starting optimization...') least_squares_serial_solve( prob, bounds=[-0.037, 0.021], xtol=1e-12, ftol=1e-12, gtol=1e-12) #, method='lm', max_nfev=nIterations) print('Optimization finished...') ## Create final Poincare Plot solFinal = [obj.residue()] p = obj.poincare(nPpts=350, nPtrj=8, Rbegin=1.19, Rend=1.23) p.plot(s=1.5) [ plt.scatter(fSol[1], fSol[2], s=35, marker="x", label=f"Periods = {fSol[3]:.0f}, Residue = {fSol[0]:.4f}") for fSol in solFinal ]
# Curve itself. obj = CurveLength(curve) print('Initial curve length: ', obj.J()) # Each target function is then equipped with a shift and weight, to # become a term in a least-squares objective function. # A list of terms are combined to form a nonlinear-least-squares # problem. prob = LeastSquaresProblem([(obj, 0.0, 1.0)]) # At the initial condition, get the Jacobian two ways: analytic # derivatives and finite differencing. The difference should be small. fd_jac = prob.dofs.fd_jac() jac = prob.dofs.jac() print('finite difference Jacobian:') print(fd_jac) print('Analytic Jacobian:') print(jac) print('Difference:') print(fd_jac - jac) # Solve the minimization problem: least_squares_serial_solve(prob) print('At the optimum, x: ', prob.x) print(' Final curve dofs: ', curve.get_dofs()) print(' Final curve length: ', obj.J()) print(' Expected final length: ', 2 * np.pi * x0[0]) print(' objective function: ', prob.objective())
# Each Target is then equipped with a shift and weight, to become a # term in a least-squares objective function. A list of terms are # combined to form a nonlinear-least-squares problem. desired_volume = 0.15 volume_weight = 1 term1 = (equil.volume, desired_volume, volume_weight) desired_iota = -0.41 iota_weight = 1 term2 = (equil.iota, desired_iota, iota_weight) prob = LeastSquaresProblem([term1, term2]) # Solve the minimization problem: least_squares_serial_solve(prob, grad=True) print("At the optimum,") print(" rc(m=1,n=1) = ", surf.get_rc(1, 1)) print(" zs(m=1,n=1) = ", surf.get_zs(1, 1)) print(" volume, according to VMEC = ", equil.volume()) print(" volume, according to Surface = ", surf.volume()) print(" iota on axis = ", equil.iota()) print(" objective function = ", prob.objective()) # The tests here are based on values from the VMEC version in # https://github.com/landreman/stellopt_scenarios/tree/master/2DOF_vmecOnly_targetIotaAndVolume # Due to this and the fact that we don't yet have iota on axis from SPEC, the tolerances are wide. assert np.abs(surf.get_rc(1, 1) - 0.0313066948) < 0.001 assert np.abs(surf.get_zs(1, 1) - (-0.031232391)) < 0.001 assert np.abs(equil.volume() - 0.178091) < 0.001
plt.tight_layout() plt.savefig('Results/DommaschkInitialIota.png') ## Optimization prob = LeastSquaresProblem([(obj.residue1, 0, 1), (obj.residue2, 0, 1), (obj.residue3, 0, 1)]) # Set degrees of freedom for the optimization obj.all_fixed() obj.set_fixed('bc(5,10)', False) obj.set_dofs([5, 2, 5, 4, 5, 10, 1.4, 1.4, 19.25, 0, -1e4]) # Run optimization problem nIterations = 400 print('Starting optimization...') least_squares_serial_solve(prob, xtol=1e-9, ftol=1e-9, gtol=1e-9, method='lm', max_nfev=nIterations) print('Optimization finished...') ## Create final Poincare Plot solFinal = [] # residueInputs = [[1.1884,8],[1.124,9],[1.075,11],[1.150,8]] residueInputs = [[1.1884, 8], [1.124, 9], [1.075, 11]] [ solFinal.append(obj.residue(resIn[0], resIn[1])) for resIn in residueInputs ] p = obj.poincare(nPpts=500, nPtrj=50, Rbegin=0.98, Rend=1.18) p.plot(s=1.5) [