xrt icon indicating copy to clipboard operation
xrt copied to clipboard

Laterally graded multilayer

Open hgretar opened this issue 5 years ago • 11 comments

Hi guys,

I'm trying to implement a laterally graded multilayer. What I have been doing so far is to create a subclass of Multlayer and redefined get_t_thickness(self, x, y, iPair) and get_b_thickness(self, x, y, iPair). See below:

`class LMultilayer(rmats.Multilayer):

def __init__(self, *args, **kwargs):
	self.tError = kwargs.pop('tError', 10)  # R meridional
	rmats.Multilayer.__init__(self, *args, **kwargs)

def get_t_thickness(self, x, y, iPair) :
	f = np.random.normal(size=len(x))*self.tError + 1 
	return self.dti[iPair] * f
	
def get_b_thickness(self, x, y, iPair):
	f = np.random.normal(size=len(x))*self.tError + 1 
	return self.dbi[iPair] * f `

I then go on and use the LMultilayer class but so far I'm not able to see any difference in reflected intensity despite creating variations in the d-spacing of each pairs.

Do you know what could be missing? Or alternatively could you provide a short example of laterally graded multilayer?

hgretar avatar Dec 06 '18 07:12 hgretar

Hi,

As I understand you want a lateral grading, not depth grading, so don't mix them. In your implementation, even for one ray the thickness variation is averaged out as it propagates through the layers. Then also many rays are averaged over the footprint. I would go in a more deterministic way. For example, make the 4 quadrants different in t and b thickness (but not vary with depth) and see the results. A linear gradient is may be a next trial.

If you don't see any change, please send me your script.

kklmn avatar Dec 06 '18 11:12 kklmn

I've tried to follow where get_t_thickness is used in the Multilayer class. I've realized that it only appears in get_amplitude but there I'm not able to use is since "if ucl is None" gives False. What is ucl and how do I change it to None?

hgretar avatar Dec 06 '18 12:12 hgretar

you don't need to modify get_amplitude. You only need to specify get_t_thickness and get_b_thickness accordingly to your lateral grading. If you need some user parameters that you pass to your formulas, you also need to modify __init__ .

kklmn avatar Dec 06 '18 13:12 kklmn

Following your advice I've split the Multilayer into 4 segments each with different t and b thickness. It's now clear that this works, I get steps in reflectivity as a function of beam height. Thanks for your suggestion. This however only works if I do not use targetOpenCL=r"auto" for my OE.

hgretar avatar Dec 07 '18 12:12 hgretar

Hi, could you clarify what happens if you do calculate the ML amplitudes with OpenCL?

yxrmz avatar Dec 07 '18 18:12 yxrmz

Then get_t_thickness or get_b_thickness are never called in the get_amplitude function of the Multilayer class. This mean there is no lateral grading.

hgretar avatar Dec 07 '18 20:12 hgretar

Oh, I see what you mean now, I thought it stops with errors. Now there's no way to expose custom user functions to OpenCL, but if you are interested it's not hard to implement.

yxrmz avatar Dec 07 '18 23:12 yxrmz

It would be great if you could implement that.

hgretar avatar Dec 08 '18 08:12 hgretar

I hope you understand that OpenCL is only for acceleration of reflectivity calculations. And by the way, this acceleration is not as dramatic as for other heavy calculations: undulator source and wave propagation. You can do lateral grading already now, no reason for waiting for custom functions in OpenCL Multilayer. Just remove targetOpenCL from the constructor options of your optical element and implement your own get_t_thickness and get_b_thickness in a Multilayer subclass.

To write these methods in OpenCL (basically C language) is possible, as Roman has said, but one needs these functions in hands. "Implement that" -- what is "that"? Give it. Or you want an automatic translation of python functions to OpenCL? We don't have it.

kklmn avatar Dec 08 '18 11:12 kklmn

Wait for it, the plan is to pass the get_t and get_b functions as multiline text varialbe, similar to OpenGL shaders (if you know what this is). I'll explain the rules and give an example.

yxrmz avatar Dec 08 '18 21:12 yxrmz

Ok, but there is no rush. As Konstantin pointed out this already works without OpenCL and the calculations are not that heavy. I simply did not know the scope of this problem.

hgretar avatar Dec 10 '18 16:12 hgretar