Skip to content

RuiFilipeCampos/MontyCarlo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MontyCarlo (alpha, developmental releases)

license pyversion architecture os

MontyCarlo is a python framework for setting up simulations and/or developing applications whose basis is the simulation of particle transport. It simulates the propagation and effects of ionizing radiation (photons, electrons and positrons with energies between 1keV and 1GeV) in matter of homogeneous density, filling constructive solid geometry models.

This work has a poster presentation in the 3rd European Congress of Medical Physics and has been presented in a workshop organized by the Faculty of Sciences of the University of Porto and the Ludwig Maximilian University of Munich.

Getting started

Clone this repository and run

docker compose up 

This will start a jupyter notebook server listening on http://localhost:8888.

Have fun exploring high energy particle tracks in a 3d environment!

  • White tracks: Photons
  • Blue tracks: electrons
  • Red tracks: positrons

The innermost sphere contains water, the outer sphere contains air and the rest of space is filled with gold.

ex01

Be sure to zoom in on every detail!

ex02

Other cool examples

CSGexample

img1

img2

What to expect

Speed

Although it is a python module this package is written in a happy mix of Python, Cython, C++. A notable example of a package that also does this is Numpy. Most of the initialization and pretty much all the programming user interface is in Python, so while setting up your simulation or handling the results of it, you'll be dealing with Python. However, from the moment you tell MontyCarlo to start simulating, it leaves the world of Python and starts running optimized C code. Each language is therefore placed strategically so that it can play to its strenghts.

Fun

Using the power of vtk through the wonderful work of mayavi remarkable visualizations are easy in Monty Carlo.

50keV electrons in water (secondary particles off):

Electrons in Water

10MeV electrons in water (primary in red, secondary photon in green)

image

SSSS250k

Bugs

This is a very early version of a fairly large code. Bugs are guaranteed! Submitting an issue is a great way to contribute to the project at this stage!

Available Features:

  • Construction of any material via a stochiometric formula and density water = Mat({1:2, 8:1}, 1);
  • Constructed materials are automatically cached in the folder your_project\mat.
  • Only spheres are available. This will remain as such until all this has been thoroughly tested:
    • Constructive Solid Geometry (CSG) using the | & and - operators;
    • linear transformations on the volumes (translation and rotation);
    • bounding volume hierarchy (BVH) constructed with the aid of the user;
    • a syntatic indication of the BVH using with statements;
    • a new method of particle transport that greatly accelerates the simulation of electrons and positrons;
  • The volumes surfaces are rendered and cached in your_project/geo;
  • Three particles are available:
    • Photons (analogue simulation);
      • Compton Scattering;
      • Rayleigh Scattering;
      • Photoelectric Effect;
      • Pair Production;
      • Triplet Production;
    • Electrons (class II condensed history);
      • Elastic Scattering (atom is not affected): Angular Deflection + Bremstrahlung Production;
      • Inelastic Scattering (atom is affected): Interaction with an individual atom + with the condensed medium as a whole;
    • Positrons (class II condensed history);
      • Elastic Scattering (atom is not affected): Angular Deflection + Bremstrahlung Production;
      • Inelastic Scattering (atom is affected): Interaction with an individual atom + with the condensed medium as a whole;
      • Anihilation (positron meets electron);
  • The simulation is coupled (e.g. supports secondary particle creation)
  • Supports simulation of post-ionization relaxation effects;
  • Two particle sources are available:
    • Isotropic point source: emits particles from a point with randomized directions - IsotropicPoint
    • Directional point source: emits particles from a point towards a specified direction - Beam
  • Automated database download on first import;
  • 3d plotting of particle trajectories;
  • 3d plotting of the constructed geometry;
  • simultaneous plotting of both geometry and trajectories;
  • One tally is available:
    • Z_TALLY - calculates PDD's
  • Automatic generation of *.html output files (work in progress though)

Possible Future Work

  • Sources
  • Tallying
    • Energy Deposition (1d, 2d, 3d, 4d(spatial + temporal) )
    • Flux
    • Others
  • Variance reduction
  • Image Detectors
  • Extension to E < 1keV (for laser applications)
  • Extension to E > 1GeV (for thermonuclear applications)
  • Implementation of other particles
    • Protons
    • Neutrons
    • etc...
  • Dedicated graphics engine (w/sphere tracing)
  • An auto-cad like GUI for CSG modeling
  • Geant4 like API
  • GPU accelaration
  • CPU multiprocessing/multithreading
  • Advanced data vizualization (w/ ParaView)
  • Distributed Cloud Computing
  • Dedicated python notebook (like Jupyter)