Git Product home page Git Product logo

pyboltz's Introduction

PyBoltz_Tests

PyBoltz

This software package is a translation of the Fortran based Magboltz code (Biagi, 2001) into Cython. This project was built to allow for more productive work to be done with magboltz.

General information.

About PyBoltz

PyBoltz is an electron swarm Monte Carlo package for calcualting transport parameters of electrons in different gas mixtures that are relevant to particle detectors.

To cite PyBoltz, and for more information:

Electron transport in gaseous detectors with a Python-based Monte Carlo simulation code
B. Al Atoum et al, Comp Phys Comm 254 (2020) 107357
https://www.sciencedirect.com/science/article/abs/pii/S0010465520301533

About Magboltz.

The Magboltz program computes drift gas properties by "numerically integrating the Boltzmann transport equation"-- i.e., simulating an electron bouncing around inside a gas. By tracking how far the virtual electron propagates, the program can compute the drift velocity. By including a magnetic field, the program can also calculate the Lorentz angle. Read more.

Why Cython?

Cython's static typing improves the speed of python code by about a hundred times. In other words, Cython provides us with the simplicity of python and the speed of Fortran/C. Read more.

Setting up and running instructions.

Setting up.

To be able to run this project you will need python3+, cython, and numpy installed. Our setup has python 3.6.7, Cython 0.29.3, and numpy 1.16.1.

First method.

For simple running purposes, one can simply install PyBoltz using the following command. Note: This method needs a new version of PIP.

python3 -m pip install --upgrade  git+https://github.com/UTA-REST/PyBoltz.git --user

Second method.

For developing purposes, follow the steps below.

Cloning.

Start off by simply cloning this repository.

Gasmix module.

Before building the code make sure to run the following command to install the PyGasMix module.

$ sudo pip3 install --upgrade  git+https://github.com/UTA-REST/PyGasMix --user

Notice If you are planning to develop upon the Gasmix module as well, you should be installing the PyGasMix module by following the steps in the repository link below. (steps detailed in the readme). PyGasMix.

Building.

Finally, to build the code, run the following command. This should compile all of the Cython files and add the path of the repository directory to your PYTHONPATH so you can access the libraries from anywhere. This will take a few minutes the first time.

$ source setup.sh

Please note that you might need to change the commands inside the setup.sh file to match your python version.

Running PyBoltz.

To run the code, you will need to import PyBoltz and instantiate an instance of the PyBoltz object, fill in the input parameters and call the PyBoltz.Start() function. There are examples in the Examples directory on to how to use PyBoltz. The main example is the Test_PyBoltz_NoWrapper.py code. This example also has a list of the gases in PyBoltz.

Input parameters.

  • PyBoltz.NumberOfGases - The number of gases in the mixture (goes up to 6).
  • PyBoltz.MaxNumberOfCollisions - The number of simulated events / 2*10E7.
  • PyBoltz.Enable_Penning - Penning effects included (0 or 1).
  • PyBoltz.Enable_Thermal_Motion - Thermal motion included (0 or 1).
  • PyBoltz.Max_Electron_Energy - Upper limit of electron energy integration (0.0 to automatically calculate this value).
  • PyBoltz.GasIDs - Array of six elements that has the number of each gas in the mixture.
  • PyBoltz.GasFractions - Array of six elements that has the percentage of each gas in the mixture.
  • PyBoltz.TemperatureCentigrade - The tempreture in degrees centigrade.
  • PyBoltz.Pressure_Torr - The pressure [torr].
  • PyBoltz.EField - The electric field in the chamber [Volts/Cm].
  • PyBoltz.BField_Mag - The magnitude of the magentic field [KiloGauss].
  • PyBoltz.BField_Angle - The angle between the magentic field and the electric field.
  • PyBoltz.Which_Angular_Model - This variable is used to fix the angular distrubtions to one of the following types.
    • Okhrimvoskky Type - PyBoltz.WhichAngularModel = 2 (default value).
    • Capitelli Longo Type - PyBoltz.WhichAngularModel = 1.
    • Isotropic Scattering - PyBoltz.WhichAngularModel = 0.
  • PyBoltz.Console_Output_Flag - This variable is used to tell PyBoltz to print to the console.
    • Print to the console - PyBoltz.ConsoleOutputFlag = 1.
    • Avoid printing to the console - PyBoltz.ConsoleOutputFlag = 0.
  • PyBoltz.Random_Seed - This variable is used to set the seed for the random number geenerator used by the simulation.

Output parameters.

Please note that the following are only the main output parameters. One can still get any value from the parameters within the Magboltz class.

  • PyBoltz.VelocityZ - Drift velocity in the Z direction [mm/mus].
  • PyBoltz.VelocityY - Drift velocity in the Y direction [mm/mus].
  • PyBoltz.VelocityX - Drift velocity in the X direction [mm/mus].
  • PyBoltz.VelocityErrorZ - Error for the Magboltz.WZ value (+- Magboltz.DWZ * Magboltz.WZ).
  • PyBoltz.VelocityErrorY - Error for the Magboltz.WY value (+- Magboltz.DWY * Magboltz.WY).
  • PyBoltz.VelocityErrorX - Error for the Magboltz.WX value (+- Magboltz.DWX * Magboltz.WX).
  • PyBoltz.TransverseDiffusion - Transverse diffusion [cm^2/s].
  • PyBoltz.TransverseDiffusionError - Error for the Magboltz.DIFTR value (+- Magboltz.DFTER * Magboltz.DIFTR).
  • PyBoltz.LongitudinalDiffusion - Longitudinal diffusion [cm^2/s]..
  • PyBoltz.LongitudinalDiffusionError - Error for the Magboltz.DIFLN value (+- Magboltz.DFLER * Magboltz.DIFLN).
  • PyBoltz.TransverseDiffusion1 - Transverse diffusion [mum/cm^0.5].
  • PyBoltz.TransverseDiffusion1Error - Error for the Magboltz.DTMN value (+- Magboltz.DTMN * Magboltz.DFTER1).
  • PyBoltz.LongitudinalDiffusion1 - Longitudinal diffusion [mum/cm^0.5].
  • PyBoltz.LongitudinalDiffusion1Error - Error for the Magboltz.DLMN vlaue (+- Magboltz.DLMN * Magboltz.DFLER1).
  • PyBoltz.MeanElectronEnergy - Mean electron energy [eV].
  • PyBoltz.MeanElectronEnergyError - Error for the Magboltz.AVE value (+- Magboltz.AVE * Magboltz.DEN).
  • PyBoltz.DiffusionX - Diffusion in the X plane [cm^2/s].
  • PyBoltz.ErrorDiffusionX - Error for the Magboltz.DIFXX value (+- Magboltz.DIFXX * Magboltz.DXXER).
  • PyBoltz.DiffusionY - Diffusion in the Y plane [cm^2/s].
  • PyBoltz.ErrorDiffusionY - Error for the Magboltz.DIFYY value (+- Magboltz.DIFYY * Magboltz.DYYER).
  • PyBoltz.DiffusionZ - Diffusion in the Z plane [cm^2/s].
  • PyBoltz.ErrorDiffusionZ - Error for the Magboltz.DIFZZ value (+- Magboltz.DIFZZ * Magboltz.DZZER).
  • PyBoltz.DiffusionYZ - Diffusion in the YZ plane [cm^2/s].
  • PyBoltz.ErrorDiffusionYZ - Error for the Magboltz.DIFYZ value (+- Magboltz.DIFYZ * Magboltz.DYZER).
  • PyBoltz.DiffusionXY - Diffusion in the XY plane [cm^2/s].
  • PyBoltz.ErrorDiffusionXY - Error for the Magboltz.DIFXY value (+- Magboltz.DIFXY * Magboltz.DXYER).
  • PyBoltz.DiffusionXZ - Diffusion in the XZ plane [cm^2/s].
  • PyBoltz.ErrorDiffusionXZ - Error for the Magboltz.DIFXZ value (+- Magboltz.DIFXZ * Magboltz.DXZER).
  • PyBoltz.MeanCollisionTime - Mean Collision Time.
  • TOF Outputs - Those outputs include townsend coeffiecents, diffusion and energy values. Those outputs are calculated from the time of flight simulation. Check the PyBoltz object documentation for more details.
  • SST Outputs - Those outputs include townsend coeffiecents, diffusion and energy values. Those outputs are calculated from the steady state simulation. Check the PyBoltz object documentation for more details.
  • Collision type counters - Six elements arraies that houses the number of collisions of each gas for each types. The types are elastic, inelastic, super-elastic, ionisation, and attachment. Check the PyBoltz object documentaion for more details.

Compilation issues.

This sections is written here to help troubleshoot compilation issues. The following are links to the two main issues:

Gas list.

The current PyBoltz version has the following gases. Please note that the number of the gas is used as an indicator to that gas in the code.

  • CF4 - Gas # 1.
  • Argon Gas # 2.
  • Helium-4 Gas # 3.
  • Helium-3 Gas # 4.
  • Neon Gas # 5.
  • Krypton Gas #6.
  • Xenon Gas # 7.
  • CH4 Gas # 8.
  • Ethane Gas # 9.
  • Propane Gas # 10.
  • Isobutane Gas # 11.
  • CO2 Gas # 12.
  • H2O Gas # 14.
  • Oxygen Gas # 15.
  • Nitrogen Gas # 16.
  • Hydrogen Gas # 21.
  • Deuterium Gas # 22.
  • DME Gas # 25.
  • XenonMert Gas # 61 (This gas requires extra parameters, check /Examples/Test_PyBoltz_mert.py).

Testing

To be able to run the tests for this module, you will need to have pytest installed on your machine. Also, you need to run the following to install the testing data package.

$ sudo pip3 install --upgrade  git+https://github.com/UTA-REST/PyBoltz_Test_Data --user

After doing so, go to the test directory and run the following.

$ pytest

This will run all the tests. If you are intrested in a single test, add the name of the testing python file to the end of the above command.

For more information on the testing data package, check the following repository. Testing Data Package.

Documentaion link

Documentaion....

pyboltz's People

Contributors

austinmcdonald avatar basharatoum avatar benjpjones avatar cuddandr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyboltz's Issues

Units of Errors?

Hi,

It is not clear to me what are the units of the error values.
If I take this example: /Example_PyBoltz_mert.py
I should expect that they are given in % which I remember from old Magboltz times.

On the other hand, if I look at the error values obtained in the way described in this example: https://github.com/UTA-REST/PyBoltz/blob/master/examples/Example.py
I am pretty sure that the errors are given in absolute values since the values are strange if these are %.

Could someone clarify this for me?

Thanks a lot!

Energy Range Not Updating

After I create a gas table using PyBoltz and Odie (code snippet below), I get a maximum energy warning when loading the gas table into Garfield and run a Macro simulation. I do not think PyBoltz is actually accepting my maximum electron energy. These warning start at 40eV, which is the default energy limit in MagBoltz.

"
MediumMagboltz::GetElectronCollisionRate:
Rate at 86.8656 eV is not included in the current table.
Increasing energy range to 91.2089 eV.

"

#Set up helper object
Odie = OdieRun()

Configure settings for our simulation

base_settings = {
'Gases': ['Ar', 'CH4'],
'Fractions': [98.5, 1.5],
'Max_collisions': 1e8,
'EField_Vcm': 100,
'Max_electron_energy': 400,
'Temperature_C': 23,
'Pressure_Torr': 3100.8,
'BField_Tesla': 0,
'BField_angle': 0,
'Angular_dist_model': 2,
'Enable_penning': 1,
'Enable_thermal_motion': 1,
'ConsoleOutputFlag': 0,
'NumSamples':100
}

t_start = time.time()

#Load base settings into Odie, this is required for
#running on a grid.
Odie.LoadSettings(base_settings, PrintSettings=True)

#Odie also can read in the settings from a JSON file
#Odie.LoadSettings(JSONFileName="input.json", PrintSettings=True)

#Generate output for a grid of possible EFields
mine= 1
maxe = 1e4
samp = 2
GridOutput = Odie.GenerateGasGrid(mine, maxe, samp, LogScale=True)

Running issue #2 - numpy path

After running the setup.sh script, I am encountered with

ALPCALCT.c:611:10: fatal error: 'numpy/arrayobject.h' file not found
#include "numpy/arrayobject.h"
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1

Python 3.7.3 running issue

After trying to run Magboltz with python 3.7.3, I get the following error:

.
.
.
Original exception was:
Traceback (most recent call last):
  File "/home/bashar/.local/lib/python3.7/site-packages/numpy/lib/npyio.py", line 453, in load
    pickle_kwargs=pickle_kwargs)
  File "/home/bashar/.local/lib/python3.7/site-packages/numpy/lib/format.py", line 722, in read_array
    raise ValueError("Object arrays cannot be loaded when "
ValueError: Object arrays cannot be loaded when allow_pickle=False
Exception ignored in: 'CF4.Gas1'
.
.
.

Difference of iC4H10 in PyBoltz when compared to Magboltz v11.9

We did a comparison of isoButane simulated with PyBoltz @ d6f3dbc and Magboltz v11.9 and found some deviation.

For fields exceeding ~7500V/cm some transport parameters start to systematically take off from the Magboltz "baseline". Longitudinal diffusion and drift velocity deviate, but transverse diffusion and first Townsend coefficient do not.

Is this expected behaviour in some way? From the magboltz source code (changelog at the top) I gather iC4H10 has not been touched since v10.5

If we can provide any more information, just let us know.

Pictures:
iC4H10_v_d_p=1000mbar_T=298K
iC4H10_dsmall_l_p=1000mbar_T=298K
iC4H10_dsmall_t_p=1000mbar_T=298K
iC4H10_alpha_p=1000mbar_T=298K

Configuration of our PyBoltz run:

        # Configure settings for our simulation
        [...]
        Boltzer.MaxNumberOfCollisions = 50 * 1e7
        Boltzer.Enable_Penning = 0
        Boltzer.Enable_Thermal_Motion = 1
        Boltzer.Max_Electron_Energy = 0
        Boltzer.TemperatureCentigrade = 298
        Boltzer.Pressure_Torr = 750.1
        [...]
        Boltzer.BField_Mag = 0
        Boltzer.BField_Angle = 0
        Boltzer.Console_Output_Flag = 1
        Boltzer.Steady_State_Threshold = 40
        Boltzer.Which_Angular_Model = 2

PyBoltz Installation Help

Hi,

I've followed the installation guide on github but I'm having troubles running the setup.sh files for both PyBoltz and PyGasMix. I've tried both on Windows using Cygwin/Git Bash, and running it via Ubuntu as a subsystem of my laptop. I get a few different errors when trying to run

warning: PyGasMix/Gas.pxd:4:15: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.

[Errno 13] Permission denied: '/home/PyGasMix/PyGasMix/Gases/ARGON.c' Traceback (most recent call last): File "/home/sk5717/.local/lib/python3.8/site-packages/Cython/Build/Dependencies.py", line 1208, in cythonize_one result = compile_single(pyx_file, options, full_module_name=full_module_name) File "/home/sk5717/.local/lib/python3.8/site-packages/Cython/Compiler/Main.py", line 727, in compile_single return run_pipeline(source, options, full_module_name)

PermissionError: [Errno 13] Permission denied: '/home/PyGasMix/PyGasMix/Gases/ARGON.c' Traceback (most recent call last): File "setup_build.py", line 34, in setup(ext_modules=cythonize(extensions)) File "/home/sk5717/.local/lib/python3.8/site-packages/Cython/Build/Dependencies.py", line 1102, in cythonize cythonize_one(*args) File "/home/sk5717/.local/lib/python3.8/site-packages/Cython/Build/Dependencies.py", line 1225, in cythonize_one raise CompileError(None, pyx_file)

I'm relatively new to using Linux and this sort of thing so I may just be messing up somewhere without knowing. I'm also using slightly more recent versions of the software/packages
Python 3.8.5
Cython 0.29.21
Numpy 1.19.4
which may be causing the errors?
Any help would be much appreciated
Many thanks

Please improve examples

Please improve the example section adding a sample configuration for the calculation of the Townsend coefficient.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.