xrd_simulator icon indicating copy to clipboard operation
xrd_simulator copied to clipboard

Vectorization of xrd_simulator

Open Marcraven opened this issue 10 months ago • 5 comments

This pull request is a generealized vectorization of most procedures in xrd_simulator.

The main idea behind is to increase computation speed an facilitate code parallelization whenever possible. The motivation behind was my intention to use this code to simulate powder samples with several million tetrahedra.

The main files affected are:

mesh.py

Once the mesh is created by meshio/pygalmesh, subsequent computations related to bounding spheres, centroids etc. have all been vectorized.

polycrystal.py

The _diffract method has been extensively modified to compute all diffraction points simultaneously for each phase present in the sample. There is still work to be done on the side of the tetrahedron-beam intersection, in which a faster bounding-box approximation has been implemented. The convex-hull calculation for the ScatteringUnit is still a bottleneck, but so far I have no idea how to improve it.

Another minor improvement has been adding zd and yd to the scattering unit to prevent repeating the calculation later in the rendering.

utils.py

Geometric calculations for circumspheres have been added here which help accelerate the mesh.py script a lot. A printvars utility has been added to help debugging memory issues during code execution.

Current bottlenecks

  • The tetrahedra-beam intersection
  • The convex-hull calculation
  • The intensity calculation during rendering

Vectorization of these last steps is not trivial and has to be thought through. The last one is probably doable although I could not find the time.

Suggestions

  • Include beam absorption physics
  • Allow for a range of wavelengths to be simulated rather than a single one
  • Do not impose >0 rotation for rigid body motions, perhaps one only wants to translate.

Marcraven avatar Apr 11 '24 14:04 Marcraven