Skip to content

Simulations

Tomek Roszczynialski edited this page Apr 29, 2016 · 14 revisions

Setting up simulations

Due to XRT design, multi-processing simulations must be run as python scripts. This wiki page shows how to prepare them. Simple example is present in the defaul version of main.py file.

The whole process can be broken up into three steps:

Prepare lens and capillaries

from lenses import pollycapillary as lp

lens = lp.PolyCurveLens('A')
caps = lens.get_capillaries()

For possible manipulations please see the Lens and Capillaries pages.

Prepare xrt-ray traycing setup

Controlling xrt backend requires defining a special class that will take capillaries generated in the previous step and run the xrt based ray-traycing simulation. For a model in which source of light shines directly into each of the capillaries MultipleCapillariesFittedSource class was created.

setup = fl.MultipleCapillariesFittedSource()
setup.set_capillaries(caps)

Source

Source size is automatically fitted to cover capillary entrance -- it is a rectangle circumscribed (pl: opisany?) on a capillary entrance-defining circle. Source position is right at the beginning of the capillary. Number of generated photons can be controlled with the use of two parameters:

setup.set_nrays(800)
setup.set_repeats(6)

Where nrays is (for this setup) a number of photons per repeat per capillary. So for 100 capillaries that would give 100*800*6 = 480000 photons total.

Source divergence can be set with setup.set_dxprime(value) and setup.set_dzprime(value). See the source page. Here You can simply do

setup.set_dxprime(0.00001)
setup.set_dzprime(0.1)

to get very unreal and asymmetric source. Default value for both x and z directions is equal to 0.01.

Number of processes used for simulation can be set simply by:

setup.set_processes(8)

Finally xrt requires You to override a run_process method which is internally responsible for performing the simulation. Your version of this method can be defined inside the setup class, but if so, it must be a static method. Than in Your file:

import xrt.backends.raycing.run as rr
rr.run_process = fl.MultipleCapillariesFittedSource.local_process

Run simulation and save data

Because photon data is stored as a collection of *.csv files, special directory must be created where program will be able to write:

import os

dirname = 'example_lens'

# Check if directory exists and create one if not
if not os.path.exists(dirname):
    os.makedirs(dirname)

# Set the setup to write in this directory
setup.set_folder(dirname)

After that You can start the simulation:

setup.run_it()

If no errors occur, in Your selected directory files should start to appear with names formated like processXX.csv where XX corresponds to the internal number of python process from which the file was created - this contraption guaranties no conflicts between processes trying to write into the same file.

Complete realization of this concept can be seen in the create_beam() function here.

While those files are filled with data, You can view them.

Clone this wiki locally