-
Dear Thomas - Is there a quick way to create scattering XS arrays separately? E.g., Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Sorry for taking so long to answer, the question arrived during my vacation and I missed it! Anyway, the answer is to use the #!/usr/bin/env python3
import NCrystal as NC
import numpy as np
#Energy array (default NCrystal unit is eV):
energies = np.geomspace( 1e-7, 10.0, 10000 )
#cfg-string to be investigated:
mycfg = 'Al_sg225.ncmat;temp=200K'
##############################################################################
#Approach #1, if you already know which component you want, you can use the
#comp=xxx cfg-string parameter to directly select it
#(cf. https://github.com/mctools/ncrystal/wiki/CfgRefDoc for more info about the
#"comp" parameter):
mat_bragg = NC.load(f'{mycfg};comp=bragg')
#Getting the cross sections is simple (note: if dealing with an oriented
#single-crystal material you would have to also specify the neutron direction):
xs_bragg = mat_bragg.scatter.xsect( ekin = energies )
#xs_bragg is now a numpy array of cross sections of the corresponding neutron
#energies in the "energies" array.
##############################################################################
#Approach #2, if you do not already know which component you want, since you do
#not know what is available in the material, you can figure this out with the
#NCrystal.misc.detect_scattering_components(..) function. Internally, it simply
#tries all possible components, and then asks the resulting scattering process
#if it is a null (vanishing) process or not:
from NCrystal.misc import detect_scattering_components
comp2xs = {}
for compname in detect_scattering_components( mycfg ):
mat_comp = NC.load(f'{mycfg};comp={compname}')
comp2xs[compname] = mat_comp.scatter.xsect( ekin = energies )
#Voila, "comp2xs" is now a dictionary with component names as keys, and the
#corresponding cross section arrays as values.
import pprint
pprint.pprint(comp2xs)
#We can of course try to plot these curves:
import matplotlib.pyplot as plt
for compname, xs in sorted(comp2xs.items()):
plt.plot( energies, xs, label = compname )
#We also add a "total" curve before showing the plot:
plt.plot( energies,
NC.load(mycfg).scatter.xsect(ekin = energies),
label='Total' )
plt.title(mycfg)
plt.loglog()
plt.grid()
plt.legend()
plt.show() Example output:
|
Beta Was this translation helpful? Give feedback.
Sorry for taking so long to answer, the question arrived during my vacation and I missed it! Anyway, the answer is to use the
comp
cfg-string parameter to select out the component in question (read more about it on https://github.com/mctools/ncrystal/wiki/CfgRefDoc). Here is a complete script showing what I mean. It also shows how to use thedetect_scattering_components
function from theNCrystal.misc
module to more generically detect the available components: