Commit d7360b6d by Otthorn 🤔

### Merge branch 'python3' of gitlab.crans.org:Otthorn/staticbs into python3

parents f421a3e8 5e9563a6
 ... ... @@ -5,6 +5,9 @@ /dist/ /data/ # IDE file /.idea # Python egg metadata, regenerated from source files by setuptools. /*.egg-info ... ...
 ... ... @@ -44,7 +44,7 @@ The observation grid is the collection of points where the B field will be evalu Currently, there is a polygon class that can make regular polygons to approximate your coil shape. If you need a non-regular polygon shape, then create a class that inherits from the loop class and calculates the vertices of the non-regular shape. The new shape class then needs to call create_segments and pass in the vertices. Consider pushing your shape to the repo so others may use it too! Copy and paste the code block below into your shape class to do this. ```python self.segments = self.create_segments(self.vertices) self.segments = self.create_segments() ``` 1. Look in the section called: *create coil* ... ...
 #!/usr/bin/env python from pylab import * import matplotlib.pyplot as plt import scipy.integrate as integrate import staticbs as bs import sys import numpy as np from plot import * def save(data_dir='./data/', **kwargs): ... ... @@ -11,33 +11,30 @@ def save(data_dir='./data/', **kwargs): print((fn, kwargs[fn])) np.save(data_dir + fn, kwargs[fn]) # print dir(static_bs_module) # observation grid setup # grid units are in meters x = linspace(-0.1, 0.1, 10) y = linspace(-0.1, 0.1, 10) z = linspace(-0.2, 0.2, 10) ## Example for how to ignore the z axis #z = zeros((x.shape[0])) + 1e-2 #zz = zeros(x.shape + y.shape) + 1e-2 #xx, yy = meshgrid(x, y) xx, yy, zz = meshgrid(x, y, z) observation_points = rollaxis(np.array((xx, yy, zz)), 0, xx.ndim+1) x = linspace(-0.1, 0.1, 100) y = linspace(-0.1, 0.1, 100) #x = np.arange(-0.5, 0.51, 0.05) #y = np.arange(-0.5, 0.51, 0.05) #z = np.arange(-0.5, 0.51, 0.05) enable_3D = False #X, Y, Z = np.meshgrid(x, y, z) #XYZ = np.array([X.flatten(), Y.flatten(), Z.flatten()]).T # ====2D case==== if not enable_3D: # Example for how to ignore the z axis z = zeros((x.shape[0])) + 1e-2 zz = zeros(x.shape + y.shape) + 1e-2 xx, yy = meshgrid(x, y) #observation_points = np.array([XYZ]) # ====3D case==== else: z = linspace(-2, 2, 20) xx, yy, zz = meshgrid(x, y, z) observation_points = rollaxis(np.array((xx, yy, zz)), 0, xx.ndim+1) # current and amp turns definitions ... ... @@ -50,14 +47,23 @@ amp_turns = simulation_current * num_loops velocity = np.array([0.001 ,0, 0]) # m/s # create coil coil_radius = 0.1 # meters coil = bs.shapes.polygon(8, (0,0,0), coil_radius) coil_radius = 0.02 # meters # coil_A = bs.shapes.Polygon(4, (-1,-1,0), coil_radius) # coil_B = bs.shapes.Polygon(4, (1,1,0), coil_radius) coil_A = bs.shapes.RectangularCoil((-0.04, 0, 0), coil_radius) coil_B = bs.shapes.RectangularCoil((0.04, 0, 0), coil_radius) # make a list of all of the current segments current_object = bs.iobjs.current_obj_list(coil.get_segments() ) # current_A = bs.iobjs.current_obj_list(coil_A.get_segments()) # current_object = bs.iobjs.CurrentObjList(coil_A.get_segments() + coil_B.get_segments()) #make e field object e_field = bs.eobjs.e_field(amp_turns, current_object, velocity) current_object = bs.iobjs.CurrentObjList(coil_A.get_segments() + coil_B.get_segments()) #current_object = bs.iobjs.CurrentObjList(dual_coil.get_segments()) # make e field object e_field = bs.eobjs.EField(amp_turns, current_object, velocity) # calculate magnetic field at observation points print("calculating B field") ... ... @@ -68,7 +74,23 @@ E_obs = e_field.E(observation_points) # E field line integral #result = integrate.quad(sim_obj.E_integrand, 1, 1, args=(0, 1)) #print(result) # result = integrate.quad(sim_obj.E_integrand, 1, 1, args=(0, 1)) # print(result) save(B_test=B_obs, E_test=E_obs, obs_points=observation_points) if not enable_3D: plot_B('./data/B_test.npy') plot_E('./data/E_test.npy') if enable_3D: plot_3D('./data/B_test.npy') # octagonal_coil = bs.shapes.Octagon(0.8, 0.2, 0.2, 0.2, 0.1) plot_coil(coil_A) plot_coil(coil_B) # plot_coil(octagonal_coil) plt.show()
 #!/usr/bin/env python from pylab import * from mpl_toolkits.mplot3d import axes3d import numpy as np from staticbs.common import mag def plot_linearity(B_fn, obs_points_fn="./data/obs_points_linearity.npy"): obs_points = np.load(obs_points_fn) B = np.load(B_fn) ... ... @@ -43,7 +42,8 @@ def scatter_3D(B_fn, obs_points_fn="data/obs_points.npy"): fig = plt.figure() ax = fig.gca(projection='3d') ax.scatter(xx, yy, zz, c=mag(B)) sc = ax.scatter(xx, yy, zz, c=mag(B)) plt.colorbar(cs) def plot_3D(B_fn, obs_points_fn="./data/obs_points.npy"): ... ... @@ -61,7 +61,8 @@ def plot_3D(B_fn, obs_points_fn="./data/obs_points.npy"): ax3.quiver(xx[::4, ::4], yy[::4, ::4], zz[::4, ::4], B[::4, ::4, 0]/float(np.amax(B[::4, ::4, 0])), B[::4, ::4, 1]/float(np.amax(B[::4, ::4, 1])), B[::4, ::4, 2]/float(np.amax(B[::4, ::4, 2])), color='blue', length=0.1) B[::4, ::4, 2]/float(np.amax(B[::4, ::4, 2])), color='blue', length=0.001) def plot_B(B_fn, obs_points_fn="./data/obs_points.npy"): """Plot of 2 vector graph of the B field""" ... ... @@ -77,7 +78,7 @@ def plot_B(B_fn, obs_points_fn="./data/obs_points.npy"): fig1 = plt.figure() ax1 = fig1.gca() title_txt = 'XY View of the Octagon B Field' title_txt = 'XY View of the triangle B Field' ax1.set_title(title_txt) ax1.CS = contourf(x, y, mag(B)) ax1.quiver(xx[::4, ::4], yy[::4, ::4], ... ... @@ -85,6 +86,7 @@ def plot_B(B_fn, obs_points_fn="./data/obs_points.npy"): B[::4, ::4, 1], color='white') plt.colorbar(ax1.CS) def plot_E(E_fn, obs_points_fn="./data/obs_points.npy"): """Plot of 2 vector graph of the E field""" obs_points = np.load(obs_points_fn) ... ... @@ -99,7 +101,7 @@ def plot_E(E_fn, obs_points_fn="./data/obs_points.npy"): fig2 = plt.figure() ax2 = fig2.gca() title_txt2 = 'XY View of the Octagon E Field' title_txt2 = 'XY View of the triangle E Field' ax2.set_title(title_txt2) ax2.CS = contourf(x, y, mag(E)) ax2.quiver(xx[::4, ::4], yy[::4, ::4], ... ... @@ -107,13 +109,26 @@ def plot_E(E_fn, obs_points_fn="./data/obs_points.npy"): E[::4, ::4, 1], color='white') plt.colorbar(ax2.CS) if __name__ == '__main__': plot_B(sys.argv[1]) #plot_E(sys.argv[2]) #plot_3D(sys.argv[1]) #scatter_3D(sys.argv[1]) #plot_linearity(sys.argv[1]) def plot_coil(coil): """Plot the vertices of a coil in a 3D graph""" plt.show() vertices = coil.vertices xx = vertices[:, 0] yy = vertices[:, 1] zz = vertices[:, 2] fig = plt.figure() ax = fig.gca(projection='3d') ax.plot(xx, yy, zz, ":o") if __name__ == '__main__': # plot_B(sys.argv[1]) # plot_E(sys.argv[2]) # plot_3D(sys.argv[1]) scatter_3D(sys.argv[1]) # plot_linearity(sys.argv[1]) plt.show() \ No newline at end of file