Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laterally graded multilayer #28

Open
hgretar opened this issue Dec 6, 2018 · 11 comments
Open

Laterally graded multilayer #28

hgretar opened this issue Dec 6, 2018 · 11 comments

Comments

@hgretar
Copy link

hgretar commented Dec 6, 2018

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?

@kklmn
Copy link
Owner

kklmn commented Dec 6, 2018

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.

@hgretar
Copy link
Author

hgretar commented Dec 6, 2018

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?

@kklmn
Copy link
Owner

kklmn commented Dec 6, 2018

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__ .

@hgretar
Copy link
Author

hgretar commented Dec 7, 2018

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.

@yxrmz
Copy link
Collaborator

yxrmz commented Dec 7, 2018

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

@hgretar
Copy link
Author

hgretar commented Dec 7, 2018

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.

@yxrmz
Copy link
Collaborator

yxrmz commented Dec 7, 2018

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.

@hgretar
Copy link
Author

hgretar commented Dec 8, 2018

It would be great if you could implement that.

@kklmn
Copy link
Owner

kklmn commented Dec 8, 2018

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.

@yxrmz
Copy link
Collaborator

yxrmz commented Dec 8, 2018

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.

@hgretar
Copy link
Author

hgretar commented Dec 10, 2018

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.

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

No branches or pull requests

3 participants