Skip to content

Commit 244b126

Browse files
committed
Update README and add example for Landau damping simulation
1 parent 576b1f3 commit 244b126

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@
4848

4949
## Overview
5050

51-
JAX-in-Cell is an open-source project in Python that uses JAX to speedup simulations, leading to a simple to use, fast and concise code. It can be imported in a Python script using the **jaxincell** package, or run directly in python using its `simulation()` function. To install it, use
51+
JAX-in-Cell is an open-source project in Python that uses JAX to speedup simulations, leading to a simple to use, fast and concise code. It can be imported in a Python script using the **jaxincell** package, or run directly in the command line as `jaxincell`. To install it, use
5252

5353
```sh
5454
pip install jaxincell
5555
```
5656

57-
Alternatively, you can simple install the Python dependencies `jax`, `jax_tqdm` and `matplotlib`, and run the `main.py` script in the repository after downloading it as
57+
Alternatively, you can install the Python dependencies `jax`, `jax_tqdm` and `matplotlib`, and run the [example script](example_script.py) in the repository after downloading it as
5858

5959
```sh
60-
python main.py
60+
git clone https://github.com/uwplasma/JAX-in-Cell
61+
python example_script.py
6162
```
6263

6364
This allows JAX-in-Cell to be run without any installation.
@@ -159,7 +160,7 @@ To run a simple case of JAX-in-Cell, you can simply call `jaxincell` from the te
159160
jaxincell
160161
```
161162

162-
This runs JAX-in-Cell using standard input parameters of the two-stream instability. To change input parameters, use a TOML file similar to the [example input](example_input.toml) present in the repository as
163+
This runs JAX-in-Cell using standard input parameters of Landau damping. To change input parameters, use a TOML file similar to the [example input](example_input.toml) present in the repository as
163164

164165
```sh
165166
jaxincell example_input.toml

examples/Landau_damping.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## Langmuir_wave.py
2+
# Example of plasma oscillations of electrons
3+
import os, sys;
4+
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
5+
from jaxincell.plot import plot
6+
from jaxincell.simulation import simulation
7+
import jax.numpy as jnp
8+
from jax import block_until_ready
9+
10+
input_parameters = {
11+
"length" : 1e-2, # dimensions of the simulation box in (x, y, z)
12+
"amplitude_perturbation_x" : 5e-4, # amplitude of sinusoidal perturbation in x
13+
"wavenumber_electrons": 8, # Wavenumber of sinusoidal electron density perturbation in x (factor of 2pi/length)
14+
"grid_points_per_Debye_length" : 5, # dx over Debye length
15+
"vth_electrons_over_c" : 0.05, # thermal velocity of electrons over speed of light
16+
"ion_temperature_over_electron_temperature": 1e-9, # Temperature of ions over temperature of electrons
17+
"timestep_over_spatialstep_times_c": 0.5, # dt * speed_of_light / dx
18+
"print_info" : True, # print information about the simulation
19+
}
20+
21+
solver_parameters = {
22+
"field_solver" : 0, # Algorithm to solve E and B fields - 0: Curl_EB, 1: Gauss_1D_FFT, 2: Gauss_1D_Cartesian, 3: Poisson_1D_FFT,
23+
"number_grid_points" : 33, # Number of grid points
24+
"number_pseudoelectrons" : 3000, # Number of pseudoelectrons
25+
"total_steps" : 1000, # Total number of time steps
26+
}
27+
28+
output = block_until_ready(simulation(input_parameters, **solver_parameters))
29+
30+
print(f"Dominant FFT frequency (f): {output['dominant_frequency']} Hz")
31+
print(f"Plasma frequency (w_p): {output['plasma_frequency']} Hz")
32+
print(f"Error: {jnp.abs(output['dominant_frequency'] - output['plasma_frequency']) / output['plasma_frequency'] * 100:.2f}%")
33+
34+
plot(output)

jaxincell/simulation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ def initialize_simulation_parameters(user_parameters={}):
4242
default_parameters = {
4343
# Basic simulation settings
4444
"length": 1e-2, # Dimensions of the simulation box
45-
"amplitude_perturbation_x": 1e-7, # Amplitude of sinusoidal (sin) perturbation in x
45+
"amplitude_perturbation_x": 5e-4, # Amplitude of sinusoidal (sin) perturbation in x
4646
"wavenumber_electrons": 8, # Wavenumber of sinusoidal electron density perturbation in x (factor of 2pi/length)
4747
"wavenumber_ions": 0, # Wavenumber of sinusoidal ion density perturbation in x (factor of 2pi/length)
4848
"grid_points_per_Debye_length": 2, # dx over Debye length
4949
"vth_electrons_over_c": 0.05, # Thermal velocity of electrons over speed of light
5050
"ion_temperature_over_electron_temperature": 0.01, # Temperature ratio of ions to electrons
5151
"timestep_over_spatialstep_times_c": 1.0, # dt * speed_of_light / dx
5252
"seed": 1701, # Random seed for reproducibility
53-
"electron_drift_speed": 1e8, # Drift speed of electrons
53+
"electron_drift_speed": 0, # Drift speed of electrons
5454
"ion_drift_speed": 0, # Drift speed of ions
55-
"velocity_plus_minus_electrons": True, # create two groups of electrons moving in opposite directions
55+
"velocity_plus_minus_electrons": False, # create two groups of electrons moving in opposite directions
5656
"velocity_plus_minus_ions": False, # create two groups of electrons moving in opposite directions
5757
"print_info": True, # Print information about the simulation
5858

0 commit comments

Comments
 (0)