Skip to content

Commit

Permalink
prepping to try pareto scans with net force and torques.
Browse files Browse the repository at this point in the history
  • Loading branch information
akaptano committed Oct 15, 2024
1 parent fcd3dff commit 8eb1b6b
Show file tree
Hide file tree
Showing 8 changed files with 1,575 additions and 0 deletions.
645 changes: 645 additions & 0 deletions examples/3_Advanced/analysis_tools.py

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions examples/3_Advanced/coil_force_pareto_scans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python

"""
Example script for the force metric in a stage-two coil optimization
"""
from analysis_tools import *
from optimization_tools import *
import imageio
import matplotlib
import matplotlib.pyplot as plt
import os

# plt.ioff()
initial_optimizations(N=10, with_force=False, MAXITER=400)
df, df_filtered, df_pareto = get_dfs()
success_plt(df, df_filtered).show()

df, df_filtered, df_pareto = get_dfs()

y_axes = ["max_max_force", "mean_RMS_force"]
labels = ["max force [N/m]", "mean force [N/m]"]
y_lims = [(8500, 25000), (6000, 10000)]
for y_axis, label, y_lim in zip(y_axes, labels, y_lims):

fig = plt.figure(figsize=(6.5, 6.5))
# plt.rc("font", size=13)
plt.rc("font", size=17)
markersize = 5
n_pareto = df_pareto.shape[0]
n_filtered = df_filtered.shape[0] - n_pareto
color="coil_surface_distance"
color_label="coil-surface distance [m]"
norm = plt.Normalize(min(df_filtered[color]), max(df_filtered[color]))
plt.scatter(
df_filtered["normalized_BdotN"],
df_filtered[y_axis],
c=df_filtered[color],
s=markersize,
label=f'all optimizations, N={n_filtered}',
norm=norm
)
plt.scatter(
df_pareto["normalized_BdotN"],
df_pareto[y_axis],
c=df_pareto[color],
marker="+",
label=f'Pareto front, N={n_pareto}',
norm=norm,
)
plt.xlabel(r'$\langle|\mathbf{B}\cdot\mathbf{n}|\rangle/\langle B \rangle$ [unitless]')
plt.ylabel(label)
plt.xlim(0.7 * min(df_filtered["normalized_BdotN"]), max(df_filtered["normalized_BdotN"]))
plt.ylim(y_lim)
plt.xscale("log")
plt.colorbar(label=color_label)
plt.clim(0.17, 0.31)
plt.legend(loc='upper right', fontsize='11')
# plt.title('Pareto Front')
plt.savefig(f"./output/QA/with-force-penalty/4/pareto_{y_axis}.pdf", bbox_inches='tight')
plt.show()
17 changes: 17 additions & 0 deletions examples/3_Advanced/gen_pareto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
# sys.path.append("/global/homes/s/shurwitz/Force-Optimizations/" )

from analysis_tools import *

iteration = int(sys.argv[1])
INPUT_DIR = f"../output/QA/without-force-penalty/{iteration-1}/optimizations/"
OUTPUT_DIR = f"../output/QA/without-force-penalty/{iteration-1}/pareto/"
_, df_filtered, _ = get_dfs(INPUT_DIR=INPUT_DIR)
df_sorted = df_filtered.sort_values(by=["normalized_BdotN"])

if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
for UUID in df_sorted[:100]['UUID']:
SOURCE_DIR = glob.glob(f"../**/{UUID}/", recursive=True)[0]
DEST_DIR = f"{OUTPUT_DIR}{UUID}/"
shutil.copytree(SOURCE_DIR, DEST_DIR)
Binary file not shown.
104 changes: 104 additions & 0 deletions examples/3_Advanced/inputs/input.LandremanPaul2021_QA
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
&INDATA
!----- Runtime Parameters -----
DELT = 9.00E-01
NITER = 10000
NSTEP = 200
TCON0 = 2.00E+00
! NS_ARRAY = 16 50
! NITER_ARRAY = 600 3000
! FTOL_ARRAY = 1.0E-16 1.0E-11

NS_ARRAY = 12 25 50 75 100 150 201
NITER_ARRAY = 1200 2000 3000 4000 5000 6000 20000
FTOL_ARRAY = 1.0E-17 1.0e-17 1.0e-17 1.0e-17 1.0e-17 1.0e-17 2.0e-17

PRECON_TYPE = 'none'
PREC2D_THRESHOLD = 1.000000E-19
!----- Grid Parameters -----
LASYM = F
NFP = 0002
MPOL = 00016
NTOR = 00012
PHIEDGE = 0.08385727554
!----- Free Boundary Parameters -----
LFREEB = F
NVACSKIP = 6
!----- Pressure Parameters -----
GAMMA = 0.000000000000E+000
BLOAT = 1.000000000000E+000
SPRES_PED = 1.000000000000E+000
PRES_SCALE = 1.000000000000E+000
PMASS_TYPE = 'power_series'
AM = 000000000E+00
!----- Current/Iota Parameters -----
CURTOR = 0
NCURR = 1
PIOTA_TYPE = 'power_series'
PCURR_TYPE = 'power_series'
!----- Axis Parameters -----
RAXIS_CC = 0
ZAXIS_CS = 0
!----- Boundary Parameters -----
! n comes before m!
RBC( 0, 0) = 1.000000000000000e+00, ZBS( 0, 0) = -0.000000000000000e+00
RBC( 1, 0) = 1.635736469509085e-01, ZBS( 1, 0) = -1.253658594586452e-01
RBC( 2, 0) = 1.153464403265224e-02, ZBS( 2, 0) = -1.143100828466809e-02
RBC( 3, 0) = 1.660825542716507e-04, ZBS( 3, 0) = -1.836705489992535e-04
RBC( 4, 0) = -4.289839778893124e-05, ZBS( 4, 0) = 6.379980554947428e-05
RBC( 5, 0) = -7.088365208037713e-06, ZBS( 5, 0) = 6.424749751809887e-06
RBC( -5, 1) = -1.234892163278594e-06, ZBS( -5, 1) = 1.650698547431063e-06
RBC( -4, 1) = 5.885906939720765e-05, ZBS( -4, 1) = 7.747703517376636e-05
RBC( -3, 1) = 1.177705088726893e-03, ZBS( -3, 1) = 8.768242973159689e-04
RBC( -2, 1) = 6.117449935928349e-03, ZBS( -2, 1) = 6.917463886154144e-03
RBC( -1, 1) = 3.695998128952078e-02, ZBS( -1, 1) = 3.357703036173842e-02
RBC( 0, 1) = 1.658776713857751e-01, ZBS( 0, 1) = 2.153938070783234e-01
RBC( 1, 1) = -1.088789497913388e-01, ZBS( 1, 1) = 8.004202421496563e-02
RBC( 2, 1) = -2.128857374166514e-02, ZBS( 2, 1) = 1.941805377930779e-02
RBC( 3, 1) = -2.300157572693968e-03, ZBS( 3, 1) = 2.043310207615721e-03
RBC( 4, 1) = -2.627971451624495e-05, ZBS( 4, 1) = 9.515817827817248e-05
RBC( 5, 1) = -3.624748429446710e-06, ZBS( 5, 1) = 2.237608189340047e-06
RBC( -5, 2) = 3.429971812740527e-07, ZBS( -5, 2) = 3.653065246955757e-06
RBC( -4, 2) = 4.850684989433037e-05, ZBS( -4, 2) = 2.581277522578798e-05
RBC( -3, 2) = -1.629464724791329e-05, ZBS( -3, 2) = 9.255771223110816e-05
RBC( -2, 2) = 6.490349497379012e-04, ZBS( -2, 2) = 3.952687065376200e-04
RBC( -1, 2) = 3.445618605450382e-05, ZBS( -1, 2) = -1.331440902105533e-03
RBC( 0, 2) = 1.582563423506581e-02, ZBS( 0, 2) = 1.561378330710932e-02
RBC( 1, 2) = 2.546788563643479e-02, ZBS( 1, 2) = 8.409380325679782e-05
RBC( 2, 2) = 3.589988783905243e-03, ZBS( 2, 2) = -7.162905352448011e-03
RBC( 3, 2) = 2.023292416997494e-03, ZBS( 3, 2) = -1.623525685575538e-03
RBC( 4, 2) = 1.334125199187403e-04, ZBS( 4, 2) = -2.144823958959020e-04
RBC( 5, 2) = 7.495835691917963e-06, ZBS( 5, 2) = -3.041995113869397e-06
RBC( -5, 3) = 2.595971377554895e-06, ZBS( -5, 3) = 7.546398657171724e-07
RBC( -4, 3) = -2.752586825793088e-05, ZBS( -4, 3) = -1.293908425979845e-05
RBC( -3, 3) = -6.881215658169502e-05, ZBS( -3, 3) = -1.146639773380277e-04
RBC( -2, 3) = 1.851061354443457e-04, ZBS( -2, 3) = 2.034757712275398e-04
RBC( -1, 3) = -9.499158045035575e-04, ZBS( -1, 3) = -1.194121521590374e-03
RBC( 0, 3) = 6.789213877319417e-04, ZBS( 0, 3) = 2.074912419441758e-03
RBC( 1, 3) = 1.278256592588691e-04, ZBS( 1, 3) = 1.453779212226518e-03
RBC( 2, 3) = 1.216640222421739e-04, ZBS( 2, 3) = 1.751939663468610e-03
RBC( 3, 3) = -8.824623427313230e-04, ZBS( 3, 3) = 4.283901601890926e-04
RBC( 4, 3) = -8.290455528140711e-05, ZBS( 4, 3) = 1.361192934036727e-04
RBC( 5, 3) = -7.724473257867983e-06, ZBS( 5, 3) = 8.518581946796281e-06
RBC( -5, 4) = -4.525265993447933e-07, ZBS( -5, 4) = -4.025242836970244e-07
RBC( -4, 4) = -3.765525591663771e-06, ZBS( -4, 4) = -5.091039705513993e-06
RBC( -3, 4) = 1.302918803102485e-05, ZBS( -3, 4) = 2.938909520741841e-06
RBC( -2, 4) = -9.479666265169178e-05, ZBS( -2, 4) = -2.244078515714136e-05
RBC( -1, 4) = 2.264194360369701e-04, ZBS( -1, 4) = -2.520850733246328e-05
RBC( 0, 4) = -3.151153789937265e-04, ZBS( 0, 4) = 9.320140252262431e-05
RBC( 1, 4) = 3.296873412220537e-04, ZBS( 1, 4) = -2.042044185495455e-05
RBC( 2, 4) = 3.702513915656681e-04, ZBS( 2, 4) = 4.064784880640345e-05
RBC( 3, 4) = 1.391783522713434e-04, ZBS( 3, 4) = -1.361278177512208e-05
RBC( 4, 4) = 6.688738405012066e-06, ZBS( 4, 4) = -6.608364805280040e-05
RBC( 5, 4) = 1.339256039281701e-05, ZBS( 5, 4) = -4.386750839649032e-06
RBC( -5, 5) = -4.605122542160908e-07, ZBS( -5, 5) = -1.918844832075774e-07
RBC( -4, 5) = 4.705334806798627e-06, ZBS( -4, 5) = 4.045952798129327e-06
RBC( -3, 5) = -3.907227055013670e-06, ZBS( -3, 5) = 1.473135558324792e-06
RBC( -2, 5) = 1.564971051544039e-06, ZBS( -2, 5) = -4.697232422054022e-06
RBC( -1, 5) = 1.512725785055272e-05, ZBS( -1, 5) = 2.716682965888606e-05
RBC( 0, 5) = 2.685611719517791e-05, ZBS( 0, 5) = 4.010578314605041e-05
RBC( 1, 5) = -6.524317753178391e-05, ZBS( 1, 5) = 1.623461963012973e-05
RBC( 2, 5) = -3.537817812851590e-05, ZBS( 2, 5) = -3.511150206275442e-05
RBC( 3, 5) = 3.342938698620821e-05, ZBS( 3, 5) = 2.352419744940536e-05
RBC( 4, 5) = -9.745754270559217e-06, ZBS( 4, 5) = 1.637637084327691e-06
RBC( 5, 5) = -1.976517490730610e-06, ZBS( 5, 5) = 4.498757881413679e-08
/
145 changes: 145 additions & 0 deletions examples/3_Advanced/inputs/input.LandremanPaul2021_QH_magwell
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
!----- Runtime Parameters -----
&INDATA
DELT = 9.000000000000E-001
NITER = 10000
NSTEP = 200
TCON0 = 2.000000000000E+000
NS_ARRAY = 12 25 50 75
100 150 201
FTOL_ARRAY = 1.000000E-17 1.000000E-17 1.000000E-17 1.000000E-17
1.000000E-17 1.000000E-17 2.000000E-17
NITER_ARRAY = 1200 2000 3000 4000
5000 6000 20000
PRECON_TYPE = 'none'
PREC2D_THRESHOLD = 1.000000E-19
!----- Grid Parameters -----
LASYM = F
NFP = 0004
MPOL = 0008
NTOR = 0008
PHIEDGE = 4.551294381756E+001
NTHETA = 0000
NZETA = 0000
!----- Free Boundary Parameters -----
LFREEB = F
!----- Pressure Parameters -----
GAMMA = 0.000000000000E+000
BLOAT = 1.000000000000E+000
SPRES_PED = 1.000000000000E+000
PRES_SCALE = 3.439366905306E+001
PMASS_TYPE = 'power_series'
AM = 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00
!----- ANI/FLOW Parameters -----
BCRIT = 1.000000000000E+000
PT_TYPE = 'power_series'
AT = 1.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00
PH_TYPE = 'power_series'
AH = 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00
!----- Current/Iota Parameters -----
CURTOR = 0.000000000000E+000
NCURR = 1
PIOTA_TYPE = 'power_series'
AI = 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00
PCURR_TYPE = 'power_series'
AC = 0.000000000000E+000 0.000000000000E+000 0.000000000000E+000 0.000000000000E+000
0.000000000000E+000 0.000000000000E+000 0.000000000000E+000 0.000000000000E+000
0.000000000000E+000 0.000000000000E+000 0.000000000000E+000 0.000000000000E+000
0.000000000000E+000 0.000000000000E+000 0.000000000000E+000 0.000000000000E+000
0.000000000000E+000 0.000000000000E+000 0.000000000000E+000 0.000000000000E+000
0.000000000000E+000
!----- Axis Parameters -----
RAXIS_CC = 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00
0.00000000000000E+00
ZAXIS_CS = 0.000000000000E+000 0.000000000000E+000 0.000000000000E+000 0.000000000000E+000
0.000000000000E+000 0.000000000000E+000 0.000000000000E+000 0.000000000000E+000
0.000000000000E+000
!----- Boundary Parameters -----
RBC( 000,000) = 1.378480264360E+001 ZBS( 000,000) = 0.000000000000E+000
RBC( 001,000) = 1.726187404079E+000 ZBS( 001,000) = 1.100163466578E+000
RBC( 002,000) = 6.784619411470E-002 ZBS( 002,000) = 7.875463181795E-002
RBC( 003,000) = -8.610603893077E-003 ZBS( 003,000) = -4.473489744658E-003
RBC( 004,000) = -6.954768654741E-005 ZBS( 004,000) = 1.588395888575E-004
RBC( 005,000) = 9.681155117252E-006 ZBS( 005,000) = 4.138060458560E-005
RBC(-005,001) = -7.090062438846E-005 ZBS(-005,001) = -5.640105757046E-005
RBC(-004,001) = 2.462338732367E-003 ZBS(-004,001) = -2.148554902649E-003
RBC(-003,001) = -1.896117167297E-002 ZBS(-003,001) = 1.594981036419E-002
RBC(-002,001) = -2.137920688773E-001 ZBS(-002,001) = 2.506646350870E-001
RBC(-001,001) = -1.362873009923E+000 ZBS(-001,001) = 8.962984591705E-001
RBC( 000,001) = 1.733237139203E+000 ZBS( 000,001) = 2.081327204381E+000
RBC( 001,001) = 4.417119515646E-001 ZBS( 001,001) = 4.553330033140E-001
RBC( 002,001) = 6.695419953370E-002 ZBS( 002,001) = 7.309171552376E-002
RBC( 003,001) = 4.586829621480E-003 ZBS( 003,001) = 4.687286129107E-003
RBC( 004,001) = 4.667077346695E-004 ZBS( 004,001) = -1.027361195085E-004
RBC( 005,001) = 1.175176479306E-005 ZBS( 005,001) = -2.552650176539E-005
RBC(-005,002) = 1.575377035260E-005 ZBS(-005,002) = 9.901363685120E-005
RBC(-004,002) = 2.261424757931E-003 ZBS(-004,002) = -3.956732991220E-003
RBC(-003,002) = 4.309259932575E-002 ZBS(-003,002) = -2.805088743419E-002
RBC(-002,002) = 1.315953940480E-002 ZBS(-002,002) = -1.704646792977E-001
RBC(-001,002) = 4.304332319616E-001 ZBS(-001,002) = 3.215570994146E-001
RBC( 000,002) = 2.868901853821E-001 ZBS( 000,002) = 1.667695990457E-001
RBC( 001,002) = 1.931383998087E-002 ZBS( 001,002) = -1.404506982196E-003
RBC( 002,002) = 1.565755517097E-003 ZBS( 002,002) = 3.373921721361E-003
RBC( 003,002) = 1.111978236837E-003 ZBS( 003,002) = 8.029270102691E-004
RBC( 004,002) = 3.212364014056E-004 ZBS( 004,002) = 3.123283352231E-004
RBC( 005,002) = 3.930745657250E-005 ZBS( 005,002) = 9.979673774622E-005
RBC(-005,003) = -2.253965955942E-004 ZBS(-005,003) = 2.851378679531E-004
RBC(-004,003) = -8.964050388804E-004 ZBS(-004,003) = 3.120148794567E-003
RBC(-003,003) = -2.917431937647E-002 ZBS(-003,003) = 7.844357333328E-003
RBC(-002,003) = -1.581028170367E-003 ZBS(-002,003) = 5.005227155127E-002
RBC(-001,003) = 2.494149802424E-002 ZBS(-001,003) = 2.636750589380E-002
RBC( 000,003) = -3.851998943789E-003 ZBS( 000,003) = 5.133128097390E-003
RBC( 001,003) = 1.563504795759E-003 ZBS( 001,003) = 9.062801189268E-003
RBC( 002,003) = 6.042310892453E-003 ZBS( 002,003) = 8.373946146862E-003
RBC( 003,003) = 1.935609824006E-003 ZBS( 003,003) = 1.991723637988E-003
RBC( 004,003) = 2.583033337260E-004 ZBS( 004,003) = 2.930369647971E-004
RBC( 005,003) = 7.771615403367E-005 ZBS( 005,003) = 1.801603873809E-005
RBC(-005,004) = 1.989970159442E-004 ZBS(-005,004) = -7.617610661490E-005
RBC(-004,004) = 3.133474921973E-003 ZBS(-004,004) = -3.926686806018E-003
RBC(-003,004) = 1.688513373469E-003 ZBS(-003,004) = 1.588962033956E-003
RBC(-002,004) = 9.542511784421E-003 ZBS(-002,004) = 5.383886804322E-003
RBC(-001,004) = 1.581562725838E-002 ZBS(-001,004) = 4.929187684486E-004
RBC( 000,004) = 3.741454918911E-003 ZBS( 000,004) = 1.375986819706E-003
RBC( 001,004) = 3.967477935721E-003 ZBS( 001,004) = 3.679633131334E-003
RBC( 002,004) = 2.956934985275E-003 ZBS( 002,004) = 2.135542216902E-003
RBC( 003,004) = 4.356320120811E-004 ZBS( 003,004) = -5.186710313568E-005
RBC( 004,004) = -9.630558365277E-005 ZBS( 004,004) = -1.889282254155E-004
RBC( 005,004) = -6.633879325437E-005 ZBS( 005,004) = -5.671974511566E-005
RBC(-005,005) = -4.133502120774E-005 ZBS(-005,005) = -7.005722734239E-005
RBC(-004,005) = -2.658222009382E-004 ZBS(-004,005) = 2.116648875803E-004
RBC(-003,005) = -1.756431084094E-005 ZBS(-003,005) = 1.776829639892E-004
RBC(-002,005) = 3.799362725283E-004 ZBS(-002,005) = -1.795387962455E-004
RBC(-001,005) = -3.390501030100E-005 ZBS(-001,005) = -2.995903236632E-004
RBC( 000,005) = -3.278942957178E-004 ZBS( 000,005) = -2.507480133573E-004
RBC( 001,005) = 1.127886913857E-004 ZBS( 001,005) = -2.617033500753E-004
RBC( 002,005) = -9.475120829442E-005 ZBS( 002,005) = -2.234820548655E-004
RBC( 003,005) = -2.122004096876E-004 ZBS( 003,005) = -9.817830003961E-005
RBC( 004,005) = 2.786329922830E-005 ZBS( 004,005) = 7.264324435394E-005
RBC( 005,005) = 5.820410564626E-006 ZBS( 005,005) = 1.186994399716E-005
/
! RMIN = 9.416741239278133
! RMAX = 17.062045101562568
! ZMIN = -3.974708748860022
! ZMAX = 3.974708748860023
! PHIMIN = 0.0
! PHIMAX = 1.5707963267948966
Loading

0 comments on commit 8eb1b6b

Please sign in to comment.