This code provides a simple 2D Smith-Purcell simulator using standard Python packages along with MEEP for Python.
The most important files included in this package are described briefly below.
Core Python script for running the simulation. This can be called from the command line with a single prefix input that lets the script know where to find the appropriate settings yaml file and how to name the output files.
This Jupyter notebook provides an overview of the simulation routine that is the core of smith_purcell_simulator.py
. The intention of this notebook is to teach the user how the script works in case they want to modify it to their needs.
This notebook also provides a complete description of all settings used so that the user can understand how the settings in the yaml files work. Naming conventions are kept consistent between the settings file and Python scripts.
This houses an example_settings.yaml
file that is complete and can be modified for your own simulation. The suggested way to perform simulations would be to make directories for each set of simulations, and execute from there using a local settings file.
These scripts assume that the user has the following tools and packages installed.
- Python 3
- Numpy
- Scipy
- Meep
The most straightforward way to run this code is to use Anaconda as the Python management package. From there, Anaconda can be used to install Numpy, Scipy, and MEEP.
Numpy and Scipy are standard packages.
MEEP install instructions can be found here.
Create a settings file in the working directory. The file should be named with the convention NAME_settings.yaml
. You can see the /example/example_settings.yaml
provided as a starting point, and the simulation-overview.ipynb
notebook for a description of what the settings control.
From the working directory, then call python to execute the script. For example, with for NAME_settings.yaml
:
python /PATH/TO/smith_purcell_simulator.py NAME
This will run the simulation, using the prefix NAME
prepended to all output files so you can track the simulations to the outputs.
If you are running the MPI-enabled version of MEEP you can use multiple cores as follows:
mpirun -np N python /PATH/TO/smith_purcell_simulator.py NAME
where N
is the number of cores to use.
All outputs are in either .mat
or .h5
format. These can be used with most standard visualization tools in MATLAB, Python, Octave, etc.
The following steps are required to get started with using meep on a Windows machine.
- Set up Windows Subsystems for Linux (WSL).
- Turn on Developer mode, this is located under Settings > Updates & Security > For developers > Developer mode.
- Turn on Windows Subsystems for Linux, this is located under Control panel > Programs > Turn Windows features on and off
- Restart the computer.
- Install Ubuntu for Windows
- Download and install the Ubuntu app from the Microsoft Store.
- Start the Ubuntu app and install Anaconda.
- Follow the on-screen steps to complete the setup.
- Download Anaconda (in the terminal) by running the following command:
~$ wget https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
- Install Anaconda by running the following command:
~$ bash Anaconda3-2019.03-Linux-x86_64.sh
- You may remove the download file now, with the command
~$ rm Anaconda3-2019.03-Linux-x86_64.sh
- Start Anaconda by using the following command
~$ source ~anaconda3/bin/activiate
~$ conda update --all
- Create a meep profile, with the following comands
~$ conda create -n mp -c conda-forge pymeep
~$ conda activate mp
- Note, this should change the
(base)
environment into(mp)
.
- Install additional packages needed for meep
- Run the following list of commands to install necessary dependencies:
~$ pip install pyyaml
~$ conda install -c conda-forge mpi4py
~$ conda install -c conda-forge scipy
- Run the following list of commands to install necessary dependencies:
- Accessing the Ubuntu home directory through the Windows explorer
- The Ubuntu directories are available at this file location:
- Type
\\wsl$
in the Windows explorer address bar. - Navigate to
Ubuntu/home/<username>/
.
- Type
- The Ubuntu directories are available at this file location:
WSL and Ubuntu should now be fully configured for use with meep. Notice that prior to starting a simulation, to run the following command first: ~$ conda activate mp
.
Notice: the simulator does not run natively under Windows, because of a restriction in the MEEP package. For this reason, it is not possible to edit and run the code in VS Code.