Skip to content

Reflectivity and transmittivity calculation with xradyb - #62

Open
yxrmz wants to merge 6 commits into
ochubar:masterfrom
yxrmz:srw-reflectivity
Open

Reflectivity and transmittivity calculation with xradyb#62
yxrmz wants to merge 6 commits into
ochubar:masterfrom
yxrmz:srw-reflectivity

Conversation

@yxrmz

@yxrmz yxrmz commented Jun 24, 2026

Copy link
Copy Markdown

This PR adds utilities for calculating SRW-compatible reflectivity and transmittivity coefficients using xraydb library.
This way material properties for optical elements can be defined alongside the propagation script, rather then being imported from file or pre-calculated elsewhere.
We are adding the srwlpy.uti_mtrl module with the following utilities:

  • bulk mirror complex amplitude reflectivity calc_refl_arr
  • coated mirror reflectivity calc_coated_refl_arr
  • multilayer reflectivity calc_multilayer_refl_arr
  • refractive index decrement and attenuation length calc_delta_atten_len
  • plane absorbing optical elements (filters) srwl_opt_setup_transm_from_material
  • adding materials to xraydb add_mat

New example is added featuring new capabilities, see Example22. In this example we demonstrate how to add a filter made of a pre-defined material (Aluminum), bulk mirror made of a new material (B4C), a coated mirror (pre-defined Pt on Si), and a Diamond CRL array (providing custom density).

Python/C++ wrapper code is modified to provide safe reflectivity array object cleanup.

xraydb is an optional depenedency. If this package is missing, or material definition is incomplete - utility functions will substitute the amplitude of 1 for reflectivity and 0 for absorption. Users can add new materials to the runtime instance of xraydb with add_mat(Chemical composition and density are required)

@himanshugoel2797

Copy link
Copy Markdown
Contributor

I tested compiling via Visual Studio on Windows, and via CMake in WSL2/Linux. Example 22 works in both cases without additional edits. It works well.

Maybe we should think about the results when xraydb is not installed. I see that warnings are emitted indicating that it's missing, but I wonder if it might be better to error out so that we do not show results that are likely to not be what the user is expecting.

static const char strEr_BadOptWG[] = "Incorrect Optical Waveguide structure";
static const char strEr_BadOptG[] = "Incorrect Optical Grating structure";
static const char strEr_BadOptT[] = "Incorrect Optical Generic Transmission structure";
static const char strEr_BadOptR[] = "Incorrect Reflectivity Object structure";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Incorrect Reflectivity structure"?

from srwpy.srwlib import *
from srwpy.uti_plot import *
from srwpy.uti_mtrl import *

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like:

xraydb_avail = False
try:
    import ...
    xraydb_avail = True
except:
    ....

?


# Aluminum filter
filter_thick = 50.e-06 # [m]
al_delta, al_atten_len = calc_delta_atten_len('Al', photon_energy)

@himanshugoel2797 himanshugoel2797 Jul 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard code or load values from files for when xraydb is unavailable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants