In [1]:
Copied!
# Useful for debugging
%load_ext autoreload
%autoreload 2
# Useful for debugging
%load_ext autoreload
%autoreload 2
pySuperfish Poisson example¶
This example should run on Linux, macOS, and Windows
In [2]:
Copied!
from superfish import Superfish
from superfish import Superfish
In [3]:
Copied!
# by default, will try to use the private container hhslepicka/poisson-superfish:latest
# see https://github.com/hhslepicka/docker-poisson-superfish-nobin for instructions
# on building and using your own docker container
Superfish._container_image = "poisson-superfish"
# by default, will try to use the private container hhslepicka/poisson-superfish:latest
# see https://github.com/hhslepicka/docker-poisson-superfish-nobin for instructions
# on building and using your own docker container
Superfish._container_image = "poisson-superfish"
In [4]:
Copied!
import os
AMFILE = os.path.join('data', 'solenoid.am')
assert os.path.exists(AMFILE)
import os
AMFILE = os.path.join('data', 'solenoid.am')
assert os.path.exists(AMFILE)
In [5]:
Copied!
# by default, will auto-detect system and use a container on macOS, or no container on (native) Windows
SF = Superfish(AMFILE, problem='poisson', verbose=True)
# On Windows Subsystem for Linux (WSL), if you want to run this notebook on Linux but
# have PySuperfish use the Windows executables, you can do this instead:
#SF = Superfish(AMFILE, problem='poisson', verbose=True, use_container=False)
#Superfish._windows_exe_path = '/mnt/c/LANL/'
# by default, will auto-detect system and use a container on macOS, or no container on (native) Windows
SF = Superfish(AMFILE, problem='poisson', verbose=True)
# On Windows Subsystem for Linux (WSL), if you want to run this notebook on Linux but
# have PySuperfish use the Windows executables, you can do this instead:
#SF = Superfish(AMFILE, problem='poisson', verbose=True, use_container=False)
#Superfish._windows_exe_path = '/mnt/c/LANL/'
Configured to run in: /tmp/tmpslpp806s
Using container on Linux:
docker run {interactive_flags} --rm -v {local_path}:/data/ {image} {cmds}
In [6]:
Copied!
# Run, should take about a minute
SF.run()
# Run, should take about a minute
SF.run()
Running: docker run --rm -v /tmp/tmpslpp806s:/data/ poisson-superfish automesh SOLENOID.AM Running: docker run --rm -v /tmp/tmpslpp806s:/data/ poisson-superfish poisson Running: docker run --rm -v /tmp/tmpslpp806s:/data/ poisson-superfish sfo Done in 39.14 seconds Parsed output: /tmp/tmpslpp806s/SOLENOID.SFO
In [7]:
Copied!
# This is automatically done above
SF.load_output()
# This is automatically done above
SF.load_output()
Parsed output: /tmp/tmpslpp806s/SOLENOID.SFO
SFO Output¶
In [8]:
Copied!
SF.output.keys()
SF.output.keys()
Out[8]:
dict_keys(['sfo'])
In [9]:
Copied!
SF.output['sfo'].keys()
SF.output['sfo'].keys()
Out[9]:
dict_keys(['wall_segments', 'other', 'header'])
In [10]:
Copied!
# Readback of the basic parameters, with the description
header = SF.output['sfo']['header']
for key in header['variable']:
print(f"{key:10} {header['variable'][key]:16} {header['description'][key]}")
# Readback of the basic parameters, with the description
header = SF.output['sfo']['header']
for key in header['variable']:
print(f"{key:10} {header['variable'][key]:16} {header['description'][key]}")
ANGLE 0.0 Extent of arc for interpolating potential ANGLZ 0.0 Initial point on arc for interpolation CLIGHT 29979245800.0 Exact speed of light in cm/sec CONV 1.0 Length conversion (number of units per cm) DIAGDLL 0 If 1, DLL writes diagnostics to DiagDLL.txt DX1 0.1 First X mesh interval (at XMIN) DXMIN 0.1 Minimum X mesh interval (found by Automesh) DYMIN 0.08665511265 Minimum Y mesh interval (found by Automesh) EPS0 8.854187818e-12 Permittivity of free space EPSILA 5e-07 Convergence PARAMETER: air, interface points EPSILI 5e-07 Convergence parameter for iron points EPSO 1e-05 Convergence parameter in mesh optimization ETAAIR 0.987808462 Rate of convergence in air, cycle N ETAFE 0.989365314 Rate of convergence in iron, cycle N FIXEPS 9.0 Permittivity when MODE=-1 FIXGAM 0.004 Reluctivity when MODE=-1 FMU0 1.256637061e-06 Permeability of free space ICAL 0 Type of formula for currents near coils ICCC 1 1 in Poisson/Pandira problems (all real arrays) ICYCLE 980 Present iteration number ICYLIN 1 0 for X,Y problems, 1 for Z,R problems ICYSEN 0 If zero, do not print boundary integrals IENERGY -1 If 1, calculate stored energy IHDL 100000 Cycles between H*dl integrals IMAX 313 KMAX+2 IPERM 0 0 = real currents, 1 = no real currents IPIVOT 1 Pivoting in matrix inversion routines IPRFQ 0 Print frequency during Poisson iterations IRMAX 25 Used in optimization of RHOXY ISKIP 1 Cycles between calculation of reluctance ITOT 181540 (KMAX+2)*(LMAX+2) IVERG 10 Number of cycles between convergence tests KBZERO 1 Logical K coordinate where B = BDES KMAX 311 Number of horizontal logical mesh points KMIN 1 Lower K bound for computing field KPROB 0 Problem type indicator (Poisson) KTOP 311 Upper K bound for computing field KTYPE 2 Symmetry indicator for harmonic analysis LAST35 5 Code for last program to update T35 file LBZERO 1 Logical L coordinate where B = BDES LCYCLE 124 Iteration number LMAX 578 Number of vertical logical mesh points LMIN 1 Lower L bound for computing field LTOP 1 Upper L bound for computing field MAP 1 Conformal mapping parameter MAXCY 100000 Maximum number of cycles (-1: use default) MAXPPR 1776 Maximum points per region MODE 0 Material property indicator NAIR 172118 Number of air points NAMAX 0 Number of points for recalculating couplings NBND 1465 Number of Dirichlet boundary points NBSLF 0 Left-side boundary condition NBSLO 1 Lower boundary condition NBSRT 0 Right-side boundary condition NBSUP 0 Upper boundary condition NEGAT 0 Zero-area triangle indicator NFE 4865 Number of iron points NGMAX 5823 Number of points for recalculating gammas NGSAM 5219 Number of points for reluctivity when NM6=NM1 NINTER 1310 Number of interface points NMATR 2 Number of material records in T35 file NOTE 1 Determines relaxation order NPBOUND 3252 Total number of boundary points in the mesh NPINP 179758 Total points in problem NPONTS 176520 Number of unknown relaxation points NPTC 0 Number of arc points for interpolation NREG 8 Number of regions NSEG 48 Number of boundary segments NSPL 0 Number of special-potential points NTERM 0 Number of coefficients in harmonic analysis NWMAX 6051 Number of points for recalculating couplings OMEGAM 0.001 Used in optimization of RHOXY OMEGAP 0.001 Optimization parameter for RHOAIR in Poisson PI 3.14159265 The number pi to machine precision RATIO 0.0 BZERO/XJFACT for air solution RESIDA 9.155112959e-08 Residual for air RESIDI 4.770025063e-07 Residual for iron RHOAIR 1.98161022 Over-relaxation factor: air, interface points RHOFE 1.0 Over-relaxation factor for iron points RHOGAM 0.08 Under-relaxation parameter for reluctivity RHOPT1 1.9 If = RHOAIR, causes optimization of RHOAIR RHOXY 1.6 Over-relaxation factor for mesh optimization RINT 0.0 Radius of arc for interpolating potential RNORM 0.0 Aperture radius in harmonic analysis RZERO 1.0 Scaling factor for conformal transformation SNEGA 0.0 Total negative current, this solution SNEGG 0.0 Total negative current at generation SPOSA 10000.0 total positive current, this solution SPOSG 10000.0 Total positive current at generation STACK 1.0 Stacking factor STOTA 10000.0 Total current in problem, this solution STOTG 10000.0 Total current in problem at generation TNEGC 0.0 Negative current after conformal transformation TPOSC 0.0 Positive current after conformal transformation TRIAVG 0.004332755633 Average area of all triangles TRIMAX 0.006386207084 Area of the largest positive-area triangle TRIMIN 0.001701059799 Area of the smallest positive-area triangle VOLUME 150953.527 Cavity volume (cylindrical symmetry only) XJFACT 1.0 Factor multiplying currents XJFEND 1.0 Ending XJFACT for a range of multipliers XJSTEPS 0 Number of steps from XJFACT to XJFEND XJTOL 5e-07 Tolerance on XJFACT XMAXF 0.0 Upper X bound for computing field XMAXG 31.0 Upper X bound of the problem geometry XMINF 0.0 Lower X bound for computing field XMING 0.0 Lower X bound of the problem geometry XORG 0.0 X coordinate center of harmonic analysis circle XYAREA 1550.0 Total cross sectional area YMAXF 0.0 Upper Y bound for computing field YMAXG 30.0 Upper Y bound of the problem geometry YMINF 0.0 Lower Y bound for computing field YMING -20.0 Lower Y bound of the problem geometry YORG 0.0 Y coordinate center of harmonic analysis circle
Plot¶
In [11]:
Copied!
# Nicer plotting
import matplotlib.pyplot as plt
%config InlineBackend.figure_format = 'retina'
# Nicer plotting
import matplotlib.pyplot as plt
%config InlineBackend.figure_format = 'retina'
In [12]:
Copied!
SF.plot_wall(field='B')
SF.plot_wall(field='B')
In [13]:
Copied!
SF.plot_wall(perp_scale=2, field='B', figsize=(16,9))
SF.plot_wall(perp_scale=2, field='B', figsize=(16,9))
Interpolate¶
In [14]:
Copied!
?SF.interpolate
?SF.interpolate
Signature: SF.interpolate(zmin=-1000, zmax=1000, nz=100, rmin=0, rmax=0, nr=1) Docstring: Interpolates field over a grid. File: ~/github/PySuperfish/superfish/superfish.py Type: method
In [15]:
Copied!
# Get the data
t7data = SF.interpolate(zmin=-10, zmax = 10, rmax = 10, nz=201, nr=101)
t7data.keys()
# Get the data
t7data = SF.interpolate(zmin=-10, zmax = 10, rmax = 10, nz=201, nr=101)
t7data.keys()
Running: docker run --rm -v /tmp/tmpslpp806s:/data/ poisson-superfish sf7 SOLENOID.IN7 SOLENOID.T35
Out[15]:
dict_keys(['geometry', 'problem', 'rmin', 'rmax', 'nr', 'zmin', 'zmax', 'nz', 'Br', 'Bz'])
In [16]:
Copied!
from superfish import plot
import numpy as np
z = np.linspace(t7data['zmin'], t7data['zmax'], t7data['nz'])
Bz = t7data['Bz'][0, :]
plt.title('On-axis field')
plt.xlabel('z (cm)')
plt.ylabel('Bz (G)')
plt.plot(z, Bz, color='black')
from superfish import plot
import numpy as np
z = np.linspace(t7data['zmin'], t7data['zmax'], t7data['nz'])
Bz = t7data['Bz'][0, :]
plt.title('On-axis field')
plt.xlabel('z (cm)')
plt.ylabel('Bz (G)')
plt.plot(z, Bz, color='black')
Out[16]:
[<matplotlib.lines.Line2D at 0x7f292bfc2030>]
In [17]:
Copied!
# Plot field data
fig, ax = plt.subplots(figsize=(12,7))
ax.set_title(AMFILE)
plot.add_t7data_to_axes(t7data, ax, field='B', vmin=None)
plot.plot_wall(SF.output['sfo']['wall_segments'], ax=ax)
# Plot field data
fig, ax = plt.subplots(figsize=(12,7))
ax.set_title(AMFILE)
plot.add_t7data_to_axes(t7data, ax, field='B', vmin=None)
plot.plot_wall(SF.output['sfo']['wall_segments'], ax=ax)
In [17]:
Copied!
# Use this as the example data
#!cp {SF.path}/*T7 data/SOLENOID.T7
# Use this as the example data
#!cp {SF.path}/*T7 data/SOLENOID.T7
Interactive¶
You can use Superfish's own graphical tools (when running in a container) with the interactive flag (currently, only supported on macOS).
In [18]:
Copied!
SF.interactive = True
# This will pop up the WSFPLOT.EXE window.
SF.run_cmd('wsfplot')
SF.interactive = True
# This will pop up the WSFPLOT.EXE window.
SF.run_cmd('wsfplot')
Running: /mnt/c/LANL/WSFPLOT.EXE
Out[18]:
CompletedProcess(args=['/mnt/c/LANL/WSFPLOT.EXE'], returncode=0)
In [ ]:
Copied!