Git Product home page Git Product logo

rapt's Introduction

Binder

RAPT: A Python framework for tracing relativistic test particles in general electromagnetic fields

RAPT (Rice Adaptive Particle Tracer) is an object-oriented package for simulating trajectories of charged particles under electric and magnetic fields. It is intended to be used for plasma physics research and education.

Features:

  • Relativistic equations of motion.
  • Following the particle or guiding center trajectories.
  • Automatic switching between particle and guiding-center trajectories for efficiency.
  • Accurate, state-of-the-art equations for the guiding center.
  • Support for time-dependent fields.
  • Extensible with user-defined field models.
  • Magnetic field-line tracing.
  • Utilities to evaluate particle-related or field-line related quantities.
  • Modular, object-oriented design for easy maintenance and extension.

This version is not stable and it is subject to change in future.

Requirements

  • numpy>=1.17
  • scipy>=1.3.1

Installation

The package can be installed using pip with the following command

pip install git+https://github.com/mkozturk/rapt@master

Examples

Proton trajectory around the Earth dipole

from rapt import m_pr, e, Re, Particle, params
from rapt.utils import speedfromKE
from rapt.fields import EarthDipole

params["cyclotronresolution"] = 20  # set step size to about 1/20 of a period
v = speedfromKE(1e6, m_pr, 'ev')    # speed of a 1MeV proton
pa = 30 * pi / 180                  # pitch angle

# Create an instance of Particle class and initialize
p = Particle(
        pos = (6*Re, 0, 0),                 # initial position
        vel = (0, - v*sin(pa), v*cos(pa)),  # initial velocity 
        t0 = 0,                             # starting time
        mass = m_pr,                        # proton mass
        charge = e,                         # proton charge
        field = EarthDipole()               # Earth's dipole field
)
# Follow the particle for 100s, store result internally
p.advance(10)

# Optional visualization with matplotlib:
import matplotlib.pyplot as pl
from mpl_toolkits.mplot3d import Axes3D

pl.figure(1)
pl.plot(p.gett(), p.getz()/Re) # Plot the z coordinate vs. time
pl.xlabel('time [s]')
pl.ylabel('z [Re]')
pl.grid()

fig = pl.figure(2)
ax = fig.add_subplot(111, projection='3d') # Display the trajectory in 3D
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.plot(p.getx()/Re, p.gety()/Re, p.getz()/Re)

pl.show()

Jupyter notebooks

rapt's People

Contributors

mkozturk avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

mshumko

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.