The simulation code

Learning by inspecting and tweaking

As mentioned in the forward, my learning breakthrough was facilitated by observing and modifying the code that actually performed the simulations. The purpose of this site is to help facilitate that learning process — and there really isn’t any substitute for looking at and playing with code that performs the ion simulations. The code for this site is freely available. The code that powers the Simulation Playground is written in Rust and contained in a single “lib.rs” file that can be found in the “Simulation Code” folder. The Rust code is compiled to Webassembly. Hosting is provided by GitHub. No cookies are used for this site, although Javascript must be enabled to use the Simulation Playground.

Python version

The code that started it all

This site all came about from a small script that I provided to my students. To download a .zip file containing this script as well as a “readme.pdf” and an “electrodes.png” files that are helpful for using the script, click the button below:

I have also provided the readme as a webpage. This readme walks through setting up the Python toolchain, using the script, and a few modifications to a simple einzel lens simulation. It also provides a short introduction to the Python programming language and some conceptual questions.

Excel version

For your inner accountant

I’ve complained that Microsoft Excel is a tool that people use and abuse well beyond the point where they’d benefit from a scripting language. Yet, I often resort to using Excel to explain concepts in programming as the grid-based nature of it allows for easy inspection and intuitive understanding. If you'd like to play around with an even-more-toy simulation program, go ahead and download the file below:

The grid size has been shrunk to 25 × 25 cells, only 100 cycles of the FDM method are applied, and each timestep is a chunky 10 ns, but everything is entierly done in Excel formulas — no Visual Basic, you get near real-time updates, and there's even a 3D viewer!

Licenses, citations, and attributions

If you are interested in using this site or materials from it

All Javascript, Python, Rust, and CSS code written for this site is in the public domain. Please see the License & attribution section of the README for the GitHub repository for more information. You are free and welcome to use my code, although I’d love a shoutout if you do. If you live somewhere that does not recognize public domain declarations, please contact me and I can provide you a permissive license.

Images are credited below the specific image with links where possible. Images have been sourced from the public domain, sources with permissive licenses, or places where my reading of their licensing allows use by this site. No copyright is claimed for the images in this site, including images created by me for the text. All images either retain their original license or, if created by me, fall under the CC-BY-SA 4.0 license.

The text Simulating Fields, Ions, and Optics is © 2022 by Ian Anthony. All rights reserved. No part of the text of this book or site may be reproduced without written permission from me. Reproductions that qualify as fair use under copyright law do not require permission.

Please use the following information for any citations:
Anthony, I. G. M. “Simulating Fields, Ions, and Optics.” igmanthony.com, 2022, igmanthony.com/fields-ions-optics/

Design

More stealing and praise

Although the overall design for this site was stolen from Jack Schaedler, some of the design specifics might be of interest to some.

The color scheme is usually Material Design — mostly because I have no eye for color coordination, but also because I’m colorblind and I can tell apart all the colors. The color map used in the Simulation Playground is Turbo, which I find to be an improved version of Jet and suitable for visualizing the positive and negative voltages of electrodes.

The fonts for this site are Montserrat and Crimson Pro. I’ve long been a fan of Sebastian Kosch, the designer of Crimson. I think Crimson Pro works even better than Crimson as a webfont. Montserrat is likely one of the most-used webfonts around — although a bit overexposed, it worked really well for the Simulation Playground so I kept it for the headings. Although it likely isn’t apparent from the text, I owe a great deal of gratitude to Matthew Butterick for his excellent book on Typography, both in terms of a resource but also as an example of how to do web book typography well.

Images have sometimes been cropped and dithered to reduce their file size and add visual interest. The inspiration for dithering large images was from LOW←TECH MAGAZINE. I used Dither Me This and GIMP for dithering and .png compression, respectively.

The HTML code for this site was all hand-written. The inspiration for that is mostly due to a love of @thebarrytone’s infamous site as well as some derivative works. By writing every line by hand, I can reduce the size of each page and shrink the overall footprint of the site. I can also ensure that the formatting looks good and that the site is a bit more accessible.