-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointMagneticField.py
53 lines (42 loc) · 2.31 KB
/
PointMagneticField.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import numpy as np
from AbstractPointField import AbstractPointFieldClass
import scipy.constants as const
class PointMagneticFieldClass(AbstractPointFieldClass):
""" Class that generates an magnetic field originating from a point particle
Class Attributes:
sourceParticle (object: Particle): The source particle that generates the
magnetic field
name (string): Name of the point source magnetic field
"""
def __init__(self, sourceParticle, name='Magnetic Point Field'):
""" Constructor for the PointMagneticFieldClass class
Inherits the __init__ from AbstractPointFieldClass
Args:
sourceParticle (object: Particle): The source particle that generates the
magnetic field
name (string): Name of the point source magnetic field
"""
super().__init__(sourceParticle=sourceParticle
, name=name)
def __repr__(self):
return 'Magnetic Point Field: {0}, Source Particle of Magnetic Field: {1}'.format(
self.name, self.sourceParticle)
def GenerateField(self, affectedParticle):
""" Method that returns the magnetic field generated by the source particle
that affects the affectedParticle.
Args:
affectedParticle (object: Particle): The particle being affected by the
magnetic field
Parameters:
displacement (ndarray): The vector that represents the position of
the source particle subtracted from the position of the affected particle.
distance (float): The norm of the displacement between the two particles
Returns:
Magnetic Field (ndarray): The magnetic field that acts on the affectedParticle
, originating from the sourceParticle.
"""
displacement = affectedParticle.position - self.sourceParticle.position
distance = np.linalg.norm(displacement)
return (const.mu_0 * self.sourceParticle.charge * np.cross(
self.sourceParticle.velocity, displacement) / (4 * const.pi
* distance * distance * distance))