Skip to content

Commit

Permalink
Did some initial fixes to get the exact field calculation working in …
Browse files Browse the repository at this point in the history
…the example script.
  • Loading branch information
akaptano committed Aug 1, 2024
1 parent 1a73d9c commit e04e8e7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
21 changes: 17 additions & 4 deletions examples/2_Intermediate/exactPM4Stell_noSym.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
max_nMagnets = 20
downsample = 100 # drastically downsample the grid if running CI
else:
N = 2 # >= 64 for high-resolution runs
N = 16 # >= 64 for high-resolution runs
nIter_max = 1000
max_nMagnets = 10
max_nMagnets = 100
downsample = 100
dims = np.array([1,1,1]) * 1e-7 #currently can only have all magnets be same shape
dims = np.array([1,1,1]) #currently can only have all magnets be same shape

nphi = N
ntheta = N
Expand All @@ -70,6 +70,13 @@
s2 = SurfaceRZFourier.from_focus(
fname_plasma, range='full torus', nphi=nphi, ntheta=ntheta
)
lcfs_ncsx.nfp = 1
lcfs_ncsx.stellsym = False

s1.nfp = 1
s1.stellsym = False
s2.nfp = 1
s2.stellsym = False

# Make higher resolution surface for plotting Bnormal
qphi = 2 * nphi
Expand Down Expand Up @@ -161,7 +168,7 @@
)

import sys
sys.path.append('/Users/willhoffman/simsopt/Codes')
sys.path.append('/Users/akaptanoglu/simsopt/Codes')
import Bcube as exact
from simsoptpp import dipole_field_Bn

Expand All @@ -183,6 +190,12 @@
1, 0, dip_ncsx.b_obj
).reshape(Acub.shape[0], Acub.shape[1])

Ngrid = dip_ncsx.nphi * dip_ncsx.ntheta
AsimDip = AsimDip.reshape(dip_ncsx.nphi * dip_ncsx.ntheta, dip_ncsx.ndipoles * 3)
Nnorms = np.ravel(np.sqrt(np.sum(dip_ncsx.plasma_boundary.normal() ** 2, axis=-1)))
for i in range(AsimDip.shape[0]):
AsimDip[i, :] = AsimDip[i, :] * np.sqrt(Nnorms[i] / Ngrid)

print('direct = ',Acub)
print('from grid = ',pm_ncsx.A_obj)
print('close = ', np.allclose(Acub, pm_ncsx.A_obj))
Expand Down
2 changes: 1 addition & 1 deletion src/simsopt/field/magneticfieldclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .magneticfield import MagneticField
from .._core.json import GSONDecoder
import sys
sys.path.append('/Users/willhoffman/simsopt/Codes')
sys.path.append('/Users/akaptanoglu/simsopt/Codes')

import Bcube as cub
import Bgrad as dcub
Expand Down
14 changes: 9 additions & 5 deletions src/simsopt/geo/permanent_magnet_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import simsoptpp as sopp

import sys
sys.path.append('/Users/willhoffman/simsopt/Codes')
sys.path.append('/Users/akaptanoglu/simsopt/Codes')
import Bcube as cub
import Bgrad as dcub

Expand Down Expand Up @@ -836,11 +836,15 @@ def geo_setup_from_famus(cls, plasma_boundary, Bn, famus_filename, **kwargs):
if m_maxima is None:
B_max = 1.465 # value used in FAMUS runs for MUSE
mu0 = 4 * np.pi * 1e-7
# cell_vol = M0s * mu0 / B_max
cell_vol = np.full(len(M0s), np.prod(dims))
cell_vol = M0s * mu0 / B_max

# Assumes that the magnets are all the same shape, and are perfect cubes!
cube_root_vol = np.cbrt(cell_vol[0]) # need to fix if the magnets have different sizes!
dims = np.array([cube_root_vol, cube_root_vol, cube_root_vol])
#cell_vol = np.full(len(M0s), np.prod(dims))

print(cell_vol)
print(M0s * mu0 / B_max)
# print(cell_vol)
# print(M0s * mu0 / B_max)

pm_grid.m_maxima = B_max * cell_vol[nonzero_inds] / mu0
else:
Expand Down

0 comments on commit e04e8e7

Please sign in to comment.