def pyoculusPoincare(stel, qvfilename, Rbegin=1.55, Rend=1.62, nPpts=50, nPtrj=5): from axisOptFuncs import importCoils, getFourierCurve from pyoculus.solvers import PoincarePlot import matplotlib.pyplot as plt _, current = importCoils("coils." + qvfilename) outputFile = qvfilename + "_coil_coeffs.dat" coils, currents = getFourierCurve(outputFile, current) bs = BiotSavart(coils, currents) sbsp = SimsgeoBiotSavart(bs, R0=sum(stel.rc), Z0=0, Nfp=stel.nfp) params = dict() Rbegin = 1.01 * sum(stel.rc) params["Rbegin"] = Rbegin params["Rend"] = Rend params["nPpts"] = nPpts params["nPtrj"] = nPtrj p = PoincarePlot(sbsp, params) poincare_output = p.compute() p.plot(s=1) plt.savefig("poincarePyoculus_" + qvfilename + '.pdf', bbox_inches='tight', pad_inches=0) iota = p.compute_iota() p.plot_iota() plt.savefig("iotaPyoculus_" + qvfilename + '.pdf', bbox_inches='tight', pad_inches=0) plt.show()
def coils2simsgeo(qvfilename, NFP, nPCoils, accuracy): print("Convert resulting coils to SIMSGEO curves") from axisOptFuncs import importCoils, cartesianCoils2fourier, getFourierCurve, export_coils coilsCartesian, current = importCoils("coils." + qvfilename) outputFile = qvfilename + "_coil_coeffs.dat" cartesianCoils2fourier(coilsCartesian, outputFile, nPCoils, accuracy) coils, currents = getFourierCurve(outputFile, current) filename = "coils." + qvfilename + "2" export_coils(coils, filename, currents, NFP) return coils, currents
def getResidue(stel, axis, qvfilename, guess=1.6, pp=3, qq=8, sbegin=1.58, send=1.62): from axisOptFuncs import importCoils, getFourierCurve from pyoculus.solvers import FixedPoint _, current = importCoils("coils." + qvfilename) outputFile = qvfilename + "_coil_coeffs.dat" coils, currents = getFourierCurve(outputFile, current) bs = BiotSavart(coils, currents) sbsp = SimsgeoBiotSavart(bs, R0=sum(stel.rc), Z0=0, Nfp=stel.nfp) fp = FixedPoint(sbsp, {"Z": 0.0}) #sbegin=1.01*sum(stel.rc) output = fp.compute(guess=guess, pp=pp, qq=qq, sbegin=sbegin, send=send) residue = output.GreenesResidue print(residue)
def CoilsBonAxis(axis, qvfilename, NFP): from axisOptFuncs import importCoils, getFourierCurve, plot_stellarator from simsopt.geo.biotsavart import BiotSavart from numpy import sqrt, dot import matplotlib.pyplot as plt _, current = importCoils("coils." + qvfilename) outputFile = qvfilename + "_coil_coeffs.dat" coils, currents = getFourierCurve(outputFile, current) print("Look at resulting coils") plot_stellarator("coils_FOURIER_", qvfilename, coils, NFP, axis, "quasisymmetry_out." + qvfilename + ".nc") print("Plot on-axis B from these coils") bs = BiotSavart(coils, currents) bs.set_points(axis.gamma()) Bfield = bs.B() Bstrength = [sqrt(dot(Bfieldi, Bfieldi)) for Bfieldi in Bfield] plt.figure() plt.plot(Bstrength) plt.xlabel('phi') plt.ylabel('B') plt.savefig("Bonaxis" + qvfilename + '.pdf', bbox_inches='tight', pad_inches=0)
def optaxiscoil(qvfilename, stel, iotaTarget, nIterations=30, nquadrature=150): from simsopt.core.least_squares_problem import LeastSquaresProblem from simsopt.solve.serial_solve import least_squares_serial_solve from simsopt.geo.curverzfourier import CurveRZFourier from axisOptFuncs import getFourierCurve, plot_stellarator, export_coils from numpy import sqrt, dot from os import remove from glob import glob import matplotlib.pyplot as plt outputFile = qvfilename + "_coil_coeffs.dat" current = 3.11049660e+05 coils, _ = getFourierCurve(outputFile, current) axis = CurveRZFourier(nquadrature, len(stel.rc) - 1, stel.nfp, True) axis.set_dofs(concatenate((stel.rc, stel.zs[1:]))) obj = objaxiscoil(coils, current, axis, stel) term = [(obj.iota, iotaTarget, 1e4), (obj.devBonAxis, 0, 1e0), (obj, 'max_elongation', 0, 1e1), (obj.stdBonAxis, 0, 1e5), (obj.residue, 0, 1e5)] prob = LeastSquaresProblem(term) obj.all_fixed() # obj.set_fixed('rc(1)', False) # obj.set_fixed('zs(1)', False) # obj.set_fixed('rc(2)', False) # obj.set_fixed('zs(2)', False) obj.set_fixed('rc(3)', False) obj.set_fixed('zs(3)', False) obj.set_fixed('rc(4)', False) obj.set_fixed('zs(4)', False) obj.set_fixed('rc(5)', False) obj.set_fixed('zs(5)', False) #obj.set_fixed('etabar', False) #obj.set_fixed('current', False) #obj.fixed[obj.nAxisFour:obj.nAxisFour+(obj.ncoils+1)*obj.nCoilFour]=False ################################################ rcInit = obj.stel.rc zsInit = obj.stel.zs plt.figure() plt.plot(obj.BonAxis()) plt.xlabel('phi') plt.ylabel('B') ################ OPTIMIZE #################### least_squares_serial_solve(prob, max_nfev=nIterations) #, method='lm') ################################################ for f in glob("residuals_2021*.dat"): remove(f) for f in glob("simsopt_2021*.dat"): remove(f) ################################################ rcFinal = obj.stel.rc zsFinal = obj.stel.zs rcDelta = [ 100 * (rcf - rcInit[count]) / rcInit[count] for count, rcf in enumerate(rcFinal) ] zsDelta = [ 100 * (zsf - zsInit[count]) / zsInit[count] for count, zsf in enumerate(zsFinal) ] print('Initial rc = [', ','.join([str(elem) for elem in rcInit]), ']') print('Final rc = [', ','.join([str(elem) for elem in rcFinal]), ']') print('Initial zs = [', ','.join([str(elem) for elem in zsInit]), ']') print('Final zs = [', ','.join([str(elem) for elem in zsFinal]), ']') print('Percentage change in rc = [', ','.join([str(elem) for elem in rcDelta]), ']') print('Percentage change in zs = [', ','.join([str(elem) for elem in zsDelta]), ']') print('Target iota = ', iotaTarget, ', final iota = ', obj.stel.iota) ################################################ print("Plot on-axis B from these coils") plt.plot(obj.BonAxis()) plt.savefig("optimizedBonaxis_" + qvfilename + '.pdf', bbox_inches='tight', pad_inches=0) ################################################ print("Plot final coils and axis") plot_stellarator("coils_axis_Optimized_", qvfilename, obj.coils, obj.nfp, obj.axis) filename = "coils." + qvfilename + "Optimized" export_coils(obj.coils, filename, obj.currents, obj.nfp) return obj.stel, obj.axis