Skip to main content

Package for calculating electric and magnetic fields and potentials in the FYS-1120 Course

Project description

General Info

Installation

>>> pip install OskarFieldModule

Importing

>>> import Field

Functions for calculating and plotting electromagnetic fields and potentials in 3d.

Functions

Efield, Epot

Field and potential from line charge parallel to x, y or z axis. Can be placed anywhere in 3D

EfieldCircle, EpotCircle

Field and potential from circle charge in origin

BfieldLine

Field from line current parallel to x, y or z axis. Can be placed anywhere in 3D

BfieldCircle

Field from circular current in origin

PlotVector

Plots vector field. Customize colorscheme, density, and figsize

PlotContour

Plots vector field. Customize colorscheme, levels, norm and figsize

PlotCircle

Plots circle just using radius

See example code below:

Single Point Charge

>>> L = 2
>>> N = 10
>>> Q = [1.0]
>>> r_Q = np.array([[0.0, 0.0, 0.0]])
>>> plane = 'xy'

>>> rx, ry, Ex, Ey = CalculateEfield(L, N, Q, r_Q, plane)
>>> PlotVector(rx, ry, Ex, Ey, 'quiver', show = True)

>>> N = 100
>>> rx, ry, V = CalculateEpot(L, N, Q, r_Q, plane)
>>> PlotContour(rx, ry, V, show=True)
## Double Point Charge Example     

>>> L = 2
>>> N = 100
>>> Q = [2.0, -2.0]
>>> r_Q = [-1, 1]
>>> r_Q = np.array([[-1.0, 0.0, 0.0], [1.0, 0.0, 0.0]])
>>> plane = 'xy'

>>> rx, ry, Ex, Ey = CalculateEfield(L, N, Q, r_Q, plane)
>>> PlotVector(rx, ry, Ex, Ey, 'stream', show = True, broken_streamlines = False)

Point Charge Field

Point Charge Potential

Double Point Charge Field

Double Line Charge Example

>>> L = 2
>>> N = 50
>>> line_charges = [-1, 1]
>>> line_lengths = [1, 1]
>>> line_center_coords = [[0, 0, -1], [0, 0, 1]]
>>> axis = ['x', 'x']
>>> plane = 'xz'

>>> rx, rz, Ex, Ez = CalculateEfieldLine(L, N, line_charges, line_lengths, line_center_coords, axis, plane)
>>> rx, rz, V = CalculateEpotLine(L, N, line_charges, line_lengths, line_center_coords, axis, plane)

>>> PlotVector(rx, rz, Ex, Ez, 'stream', broken_streamlines = False, show = True)
>>> PlotContour(rx, rz, V, show = True, norm = 'linear') 

Line Charge Field

Line Charge Potential

Circular Charge Example

>>> L = 5
>>> N = 100
>>> circle_charge = [5]
>>> radius = [2]
>>> plane = 'yz'
>>> plane_circles = ['yz']
>>> ry, rz, Ey, Ez = CalculateEfieldCircle(L, N, circle_charge, radius, plane, plane_circles)
>>> PlotVector(ry, rz, Ey, Ez, 'stream', show = False, equal = True)

>>> t = np.linspace(0, 2*np.pi, 100)
>>> plt.plot(radius[0]*np.cos(t), radius[0]*np.sin(t))
>>> plt.show()

>>> N = 500
>>> ry, rz, V = CalculateEpotCircle(L, N, circle_charge, radius, plane, plane_circles)
>>> PlotContour(ry, rz, V, show = False, equal = True)

>>> t = np.linspace(0, 2*np.pi, 100)
>>> plt.plot(radius[0]*np.cos(t), radius[0]*np.sin(t))
>>> plt.show()

Circular Charge Field

Circular Charge Potential

Line Current Example

>>> L = 5
>>> N = 24
>>> line_currents = [5]
>>> line_lengths = [1]
>>> line_center_coords = [[0.0, 0.0, 0.0]]
>>> axis = ['x']
>>> plane = 'yz'

>>> rx, rz, Bx, Bz = CalculateBfieldLine(L, N, line_currents, line_lengths, line_center_coords, axis, plane)

>>> PlotVector(rx, rz, Bx, Bz, 'quiver', title = 'Magnetic Field from Lin e Current', show = True)

Line Current Magnetic Field

Circular Current Example

>>> L = 8
>>> N = 40
>>> circle_currents = [5]
>>> radii = [5]
>>> plane = 'xz'
>>> circle_planes = ['xy']
>>> rx, rz, Bx, Bz = CalculateBfieldCircle(L, N, circle_currents, radii, plane, circle_planes)

>>> PlotVector(rx, rz, Bx, Bz, 'stream', broken_streamlines=False, show = True, cmap = 'inferno', density = .5)   

Circular Current Magnetic Field

GitHub

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

OskarFieldModule-0.4.3.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

OskarFieldModule-0.4.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file OskarFieldModule-0.4.3.tar.gz.

File metadata

  • Download URL: OskarFieldModule-0.4.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for OskarFieldModule-0.4.3.tar.gz
Algorithm Hash digest
SHA256 77ececc762f70246b4ec5dda380863dfa6205b16ca99c91b273034353c292a3e
MD5 47500eb4f3fd80be3a4018113d704a33
BLAKE2b-256 b16c7f06e21fc127eb2aae3c073ef913a04cd3824c6937c4988f21c750e20382

See more details on using hashes here.

File details

Details for the file OskarFieldModule-0.4.3-py3-none-any.whl.

File metadata

File hashes

Hashes for OskarFieldModule-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0537e4b52ac4f8173b6e86b22b34366ecc0e964f681abc58ce426b935c3c7b73
MD5 90e0322a8ee04e86cad540f5eb7a6487
BLAKE2b-256 8f36fe38b76bde5be6cefbb92e5daf50575d6e3c2a689f121dce619cd0f54edf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page