diff --git a/examples/2_Intermediate/exactPM4Stell_noSym.py b/examples/2_Intermediate/exactPM4Stell_noSym.py index 78be70343..ffafa0835 100644 --- a/examples/2_Intermediate/exactPM4Stell_noSym.py +++ b/examples/2_Intermediate/exactPM4Stell_noSym.py @@ -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 @@ -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 @@ -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 @@ -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)) diff --git a/src/simsopt/field/magneticfieldclasses.py b/src/simsopt/field/magneticfieldclasses.py index accb8934e..45b94a269 100644 --- a/src/simsopt/field/magneticfieldclasses.py +++ b/src/simsopt/field/magneticfieldclasses.py @@ -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 diff --git a/src/simsopt/geo/permanent_magnet_grid.py b/src/simsopt/geo/permanent_magnet_grid.py index 297aeac04..cd5ee8104 100644 --- a/src/simsopt/geo/permanent_magnet_grid.py +++ b/src/simsopt/geo/permanent_magnet_grid.py @@ -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 @@ -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: