How to use Magboltz 11.11 from Python 3
Posted: Sat Feb 06, 2021 8:39 pm
If you ever wondered if Magboltz can be used from Python, the answer is yes, and it is easier that you could think.
- Download Magboltz from its homepage
- Apply this patch to Magboltz (it was created for version 11.11, but it should work for newer versions too)
Code: Select all
patch magboltz-11.11.f.test < magboltz.patch
- Install numpy and gfortran
Code: Select all
sudo aptitude purge gfortran python3-numpy
- Create the f2py bindings
Code: Select all
f2py3 -c -m magboltz magboltz-11.11.f
- And enjoy...
Code: Select all
#!/usr/bin/env python3 import magboltz # First card magboltz.inpt.ngas = 2 # Number of gases in the mixture magboltz.setp.nmax = 3 # Number of real collisions [10^7] magboltz.inpt.ipen = 0 # Penning effects magboltz.thrm.ithrm = 1 # Enable gas temperature magboltz.inpt.efinal = 0.0 # Upper limit of the electron energy [eV] # Second card magboltz.gasn.ngasn = [ 2, 12, 0, 0, 0, 0 ] # Gas codes (Ar:CO2) # Third card magboltz.ratio.frac = [ 93.0, 7.0, 0.0, 0.0, 0.0, 0.0 ] # Gas fractions magboltz.inpt.tempc = 25. # Gas temperature [C] magboltz.inpt.torr = 760. # Gas pressure [Torr] # Forth card magboltz.setp.efield = 600. # Electric field [V/cm] magboltz.bfld.bmag = 1. # Magnetic field [kG] magboltz.bfld.btheta = 0. # Angle between the electric and magnetic field [deg] # Running Magboltz magboltz.run() # Printing results print('=' * 50) print("Velocity") print(" X: {} cm/s (err: {} %)".format(magboltz.vel.wx, magboltz.velerr.dwx)) print(" Y: {} cm/s (err: {} %)".format(magboltz.vel.wy, magboltz.velerr.dwy)) print(" Z: {} cm/s (err: {} %)".format(magboltz.vel.wz, magboltz.velerr.dwz))