# Define the grid grid = initialize_grid() # Set up the initial conditions for the fields and particles fields = initialize_fields(grid) particles = initialize_particles(grid) # Loop over timesteps while (time < end_time): # Advance the particles using the Lorentz force particles = push_particles(particles, fields, dt) # Update the fields based on the current particle positions and velocities fields = solve_fields(fields, particles, dt) # Deposit the particle currents onto the grid fields = deposit_currents(fields, particles) # Interpolate the fields at the particle positions fields_at_particles = interpolate_fields(fields, particles) # Compute the Lorentz force on the particles particles = compute_lorentz_force(particles, fields_at_particles) # Increment time time += dt
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter