示例#1
0
    def plot_potential_cartesian(self, fig=None, x=None, y=None, z=None):
        if not self.USE_MAYAVI:
            return None
        if fig is None:
            fig = mlab.figure('Potential')#, bgcolor=(0, 0, 0))
            #fig = mlab.figure('Potential', bgcolor=(0, 0, 0))
        else:
            mlab.figure(fig, bgcolor=fig.scene.background)

        if x is None:
            x = np.linspace(1e-9, 5e-8, num=100, endpoint=True)
        if y is None:
            y = np.linspace(1e-9, 5e-8, num=100, endpoint=True)
        if z is None:
            z = np.linspace(1e-9, 5e-8, num=100, endpoint=True)
        x_grid, y_grid, z_grid = np.meshgrid(x, y, z)
        r_grid, theta_grid, phi_grid = Vectors3D.cartesian_to_spherical(x_grid, y_grid, z_grid)
        volumetric_data = self.potential_on_grid(r_grid, theta_grid, phi_grid)
        #volumetric_data = 1 / (x_grid**2 + y_grid**2 + z_grid**2)
        #mlab.contour3d(x_grid, y_grid, z_grid, volumetric_data, colormap='jet')
        #mlab.contour3d(volumetric_data, colormap='jet')

        source = mlab.pipeline.scalar_field(volumetric_data)
        min = volumetric_data.min()
        max = volumetric_data.max()
        vol = mlab.pipeline.volume(source)
        #vol = mlab.pipeline.volume(source, vmin=min + 0.65 * (max - min),
        #                           vmax=min + 0.9 * (max - min))


        mlab.outline()
        return fig
示例#2
0
 def field_cartesian(self, x, y, z):
     potential_sign = -1 if self.attractive else 1
     x_grid, y_grid, z_grid = np.meshgrid(x, y, z)
     r_grid, theta_grid, phi_grid = Vectors3D.cartesian_to_spherical(x_grid, y_grid, z_grid)
     F_r = -potential_sign * self.a / r_grid**2
     F_x, F_y, F_z = Vectors3D.spherical_to_cartesian(F_r, theta_grid, phi_grid)
     return F_x, F_y, F_z
示例#3
0
 def field_cartesian(self, x, y, z):
     potential_sign = -1 if self.attractive else 1
     x_grid, y_grid, z_grid = np.meshgrid(x, y, z)
     r_grid, theta_grid, phi_grid = Vectors3D.cartesian_to_spherical(x_grid, y_grid, z_grid)
     F_r = -potential_sign * self.a / r_grid**2
     F_x, F_y, F_z = Vectors3D.spherical_to_cartesian(F_r, theta_grid, phi_grid)
     return F_x, F_y, F_z
示例#4
0
    def plot_potential_cartesian(self, fig=None, x=None, y=None, z=None):
        if not self.USE_MAYAVI:
            return None
        if fig is None:
            fig = mlab.figure('Potential')#, bgcolor=(0, 0, 0))
            #fig = mlab.figure('Potential', bgcolor=(0, 0, 0))
        else:
            mlab.figure(fig, bgcolor=fig.scene.background)

        if x is None:
            x = np.linspace(1e-9, 5e-8, num=100, endpoint=True)
        if y is None:
            y = np.linspace(1e-9, 5e-8, num=100, endpoint=True)
        if z is None:
            z = np.linspace(1e-9, 5e-8, num=100, endpoint=True)
        x_grid, y_grid, z_grid = np.meshgrid(x, y, z)
        r_grid, theta_grid, phi_grid = Vectors3D.cartesian_to_spherical(x_grid, y_grid, z_grid)
        volumetric_data = self.potential_on_grid(r_grid, theta_grid, phi_grid)
        #volumetric_data = 1 / (x_grid**2 + y_grid**2 + z_grid**2)
        #mlab.contour3d(x_grid, y_grid, z_grid, volumetric_data, colormap='jet')
        #mlab.contour3d(volumetric_data, colormap='jet')

        source = mlab.pipeline.scalar_field(volumetric_data)
        min = volumetric_data.min()
        max = volumetric_data.max()
        vol = mlab.pipeline.volume(source)
        #vol = mlab.pipeline.volume(source, vmin=min + 0.65 * (max - min),
        #                           vmax=min + 0.9 * (max - min))


        mlab.outline()
        return fig
示例#5
0
 def field(self, r, theta, phi):
     r_grid, theta_grid, phi_grid = np.meshgrid(r, theta, phi)
     x_grid, y_grid, z_grid = Vectors3D.spherical_to_cartesian(r_grid, theta_grid, phi_grid)
     super_x = np.zeros_like(x_grid)
     super_y = np.zeros_like(y_grid)
     super_z = np.zeros_like(z_grid)
     for potential in self.potentials:
         F_r, F_theta, F_phi = potential.field(r, theta, phi)
         F_x, F_y, F_z = Vectors3D.spherical_to_cartesian(F_r, F_theta, F_phi)
         super_x += F_x
         super_y += F_y
         super_z += F_z
     super_r, super_theta, super_phi = Vectors3D.cartesian_to_spherical(super_x, super_y, super_z)
     return super_r, super_theta, super_phi
示例#6
0
 def field(self, r, theta, phi):
     r_grid, theta_grid, phi_grid = np.meshgrid(r, theta, phi)
     x_grid, y_grid, z_grid = Vectors3D.spherical_to_cartesian(r_grid, theta_grid, phi_grid)
     super_x = np.zeros_like(x_grid)
     super_y = np.zeros_like(y_grid)
     super_z = np.zeros_like(z_grid)
     for potential in self.potentials:
         F_r, F_theta, F_phi = potential.field(r, theta, phi)
         F_x, F_y, F_z = Vectors3D.spherical_to_cartesian(F_r, F_theta, F_phi)
         super_x += F_x
         super_y += F_y
         super_z += F_z
     super_r, super_theta, super_phi = Vectors3D.cartesian_to_spherical(super_x, super_y, super_z)
     return super_r, super_theta, super_phi
示例#7
0
 def field_cartesian(self, x, y, z):
     x_grid, y_grid, z_grid = np.meshgrid(x, y, z)
     r_grid, theta_grid, phi_grid = Vectors3D.cartesian_to_spherical(x_grid, y_grid, z_grid)
     F_r = self.a / r_grid
     F_x, F_y, F_z = Vectors3D.spherical_to_cartesian(F_r, theta_grid, phi_grid)
     return F_x, F_y, F_z
示例#8
0
 def field_cartesian(self, x, y, z):
     x_grid, y_grid, z_grid = np.meshgrid(x, y, z)
     r_grid, theta_grid, phi_grid = Vectors3D.cartesian_to_spherical(x_grid, y_grid, z_grid)
     F_r = self.a / r_grid
     F_x, F_y, F_z = Vectors3D.spherical_to_cartesian(F_r, theta_grid, phi_grid)
     return F_x, F_y, F_z