kklmn / xrt

Package xrt (XRayTracer) is a python software library for ray tracing and wave propagation in x-ray regime. It is primarily meant for modeling synchrotron sources, beamlines and beamline elements.
MIT License
80 stars 29 forks source link

Calculating crystal reflectivity without constructing a beamline #181

Open zhangyujun08 opened 2 months ago

zhangyujun08 commented 2 months ago

I hope to calculate energy spectra of multi-bounce monochromators with xrt. Since I only care about the spectrum and do not need real space information, I am trying to calculate without constructing a beamline. I tried racing.materials.crystal.get_amplitude and it worked well. When I input the array of incident angle, it returns the array of reflectivity. But one problem I encounter is that this function does not allow me to define an angle of asymmetry (alpha) for the crystal. I found in the documentation that there is a get_amplitude_pytte function, which allows to do this, but when I define alpha, the output seems to be always exactly the same as alpha=0, no matter how I change the alpha. Could you please provide some solutions? Thanks a lot!

kklmn commented 2 months ago

On the documentation page Tests for Materials one can see reflectivity curves for various asymmetry angles (alphas). The script that makes these curves is tests/raycing/test_materials.py. Look for compare_rocking_curves() in it for flat crystals and compare_rocking_curves_bent() for bent ones.

zhangyujun08 commented 1 month ago

Thanks a lot! This solves my problem.

Konstantin Klementiev @.***> 于2024年6月24日周一 16:00写道:

On the documentation page Tests for Materials https://xrt.readthedocs.io/test_materials.html#test-materials one can see reflectivity curves for various asymmetry angles (alphas). The script that makes these curves is tests/raycing/test_materials.py. Look for compare_rocking_curves() in it.

— Reply to this email directly, view it on GitHub https://github.com/kklmn/xrt/issues/181#issuecomment-2185858919, or unsubscribe https://github.com/notifications/unsubscribe-auth/BDKPXCLMAKBQBIFSWQVSJMTZI7G2PAVCNFSM6AAAAABJZAFZO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBVHA2TQOJRHE . You are receiving this because you authored the thread.Message ID: @.***>

zhangyujun08 commented 1 month ago

Another related question. Now I understand that by using get_amplitude(E, beamInDotNormal, beamOutDotNormal, beamInDotHNormal), reflectivity can be calculated for asymmetrically cut crystals. However, here beamInDotNormal, beamOutDotNormal, and beamInDotHNormal all correspond to the angles within the crystal. Is there any way to calculate the angles outside the crystal (the angle of incidence and emergence)? Thank you very much!

kklmn commented 1 month ago

beamInDotNormal is cosine of the angle of incidence counted from the normal. Subtract it from π/2 to have it relative to the surface.

The emergence direction for a general asymmetric case is given by the grating equation as explained in the docs with a reference to Sánchez del Río and Cerrina.

zhangyujun08 commented 1 month ago

Thanks for your instruction. So does it mean that I need to implement these following formula into the code by myself? Or is there an easier way to do it? 1719481123270

kklmn commented 1 month ago

I thought you didn't want any optical element, did you? The method reflect() does the job: it finds a new propagation direction for each ray and applies material reflectivity/transmittivity. As you don't want it, you need to implement these formulas yourself.

zhangyujun08 commented 1 month ago

Thanks a lot! I will try both ways, either implementing the formulas or using reflect() method.

Konstantin Klementiev @.***> 于2024年6月27日周四 20:09写道:

I thought you didn't want any optical element, did you? The method reflect() does the job: it finds a new propagation direction for each ray and applies material reflectivity/transmittivity. As you don't want it, you need to implement these formulas yourself.

— Reply to this email directly, view it on GitHub https://github.com/kklmn/xrt/issues/181#issuecomment-2194519719, or unsubscribe https://github.com/notifications/unsubscribe-auth/BDKPXCO5AZ6O76FWMXVLBNDZJP6IXAVCNFSM6AAAAABJZAFZO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJUGUYTSNZRHE . You are receiving this because you authored the thread.Message ID: @.***>