Skip to content

Commit

Permalink
Merge branch 'exact_pms' of https://github.com/hiddenSymmetries/simsopt
Browse files Browse the repository at this point in the history
… into exact_pms

Resolving merge conflicts
  • Loading branch information
WillhHoffman committed Aug 15, 2024
2 parents 36278c1 + fe11388 commit 0a3dbeb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
27 changes: 12 additions & 15 deletions examples/2_Intermediate/exact_magnet_PM4Stell.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@
max_nMagnets = 20
downsample = 100 # drastically downsample the grid if running CI
else:
N = 16 # >= 64 for high-resolution runs
nIter_max = 100000
max_nMagnets = 1000
N = 32 # >= 64 for high-resolution runs
nIter_max = 40000
# max_nMagnets = 2000
downsample = 1
dims = np.array([1,1,1]) #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
algorithm = 'ArbVec_backtracking'
nBacktracking = 200
nAdjacent = 10
thresh_angle = np.pi # / np.sqrt(2)
algorithm = 'baseline'
# nBacktracking = 200
# nAdjacent = 10
# thresh_angle = np.pi # / np.sqrt(2)
nHistory = 10
angle = int(thresh_angle * 180 / np.pi)
out_dir = Path("exactPM4Stell_angle{angle}_nb{nBacktracking)_na{nAdjacent}")
# angle = int(thresh_angle * 180 / np.pi)
out_dir = Path("exactPM4Stell")
out_dir.mkdir(parents=True, exist_ok=True)
print('out directory = ', out_dir)

Expand Down Expand Up @@ -145,10 +145,7 @@
pol_vectors[:, :, 2] = mag_data.pol_z

# Using m_maxima functionality to try out unrealistically strong magnets
B_max = 5 # 5 Tesla!!!!
mu0 = 4 * np.pi * 1e-7
m_maxima = B_max / mu0
kwargs_geo = {"pol_vectors": pol_vectors, "m_maxima": m_maxima, "downsample": downsample, "dims": dims}
kwargs_geo = {"pol_vectors": pol_vectors, "downsample": downsample}

# Initialize the permanent magnet grid from the PM4Stell arrangement
pm_ncsx = ExactMagnetGrid.geo_setup_from_famus(
Expand All @@ -173,7 +170,7 @@

# Save files
if True:
pm_ncsx.dims = dims
# pm_ncsx.dims = dims
# Make BiotSavart object from the magnets and plot solution
b_exact = ExactField(
pm_ncsx.pm_grid_xyz,
Expand Down
8 changes: 4 additions & 4 deletions examples/2_Intermediate/permanent_magnet_PM4Stell.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
downsample = 100 # drastically downsample the grid if running CI
else:
N = 16 # >= 64 for high-resolution runs
nIter_max = 1000
max_nMagnets = 400
downsample = 50
nIter_max = 40000
max_nMagnets = 10000
downsample = 4

nphi = N
ntheta = N
Expand All @@ -51,7 +51,7 @@
# nBacktracking = 200
# nAdjacent = 10
# thresh_angle = np.pi # / np.sqrt(2)
nHistory = 100
nHistory = 10
# angle = int(thresh_angle * 180 / np.pi)
out_dir = Path("PM4Stell")
out_dir.mkdir(parents=True, exist_ok=True)
Expand Down
7 changes: 6 additions & 1 deletion src/simsopt/geo/permanent_magnet_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,23 +371,28 @@ def geo_setup_between_toroidal_surfaces(
normal_inner = inner_toroidal_surface.unitnormal().reshape(-1, 3)
normal_outer = outer_toroidal_surface.unitnormal().reshape(-1, 3)
pm_grid._setup_uniform_grid()
<<<<<<< HEAD
print(normal_inner.shape, normal_outer.shape, pm_grid.xyz_uniform.shape, pm_grid.xyz_inner.shape, pm_grid.xyz_outer.shape)
=======
>>>>>>> fe113881e652e58bc85b9ba9847357f9a2f9f5ef
# pm_grid.dipole_grid_xyz = define_a_uniform_cartesian_grid_between_two_toroidal_surfaces(
# normal_inner,
# normal_outer,
# pm_grid.xyz_uniform,
# pm_grid.xyz_inner,
# pm_grid.xyz_outer
# )
<<<<<<< HEAD

=======
>>>>>>> fe113881e652e58bc85b9ba9847357f9a2f9f5ef
pm_grid.dipole_grid_xyz = sopp.define_a_uniform_cartesian_grid_between_two_toroidal_surfaces(
contig(normal_inner),
contig(normal_outer),
contig(pm_grid.xyz_uniform),
contig(pm_grid.xyz_inner),
contig(pm_grid.xyz_outer))
inds = np.ravel(np.logical_not(np.all(pm_grid.dipole_grid_xyz == 0.0, axis=-1)))
print(inds.shape)
pm_grid.dipole_grid_xyz = pm_grid.dipole_grid_xyz[inds, :]
pm_grid.ndipoles = pm_grid.dipole_grid_xyz.shape[0]
pm_grid.pm_phi = np.arctan2(pm_grid.dipole_grid_xyz[:, 1], pm_grid.dipole_grid_xyz[:, 0])
Expand Down

0 comments on commit 0a3dbeb

Please sign in to comment.