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

custom ruling density definition possible? #180

Open
tmazza79xfel opened this issue Aug 22, 2017 · 8 comments
Open

custom ruling density definition possible? #180

tmazza79xfel opened this issue Aug 22, 2017 · 8 comments

Comments

@tmazza79xfel
Copy link

In the definition of a grating, the ruling density can be defined in several manners: costant on xy plane or on mirror surface, fan type, polynomial density, holographic.
To be able to estimate the impact of errors in the production process on the performances, it would be convenient to have the possibility to specify the ruling density as a vector of values: rather than passing a set of parameters (e.g. the polynomial factors), to give a set of numbers (e.g. as a file in a suitable format), that has the same size as the grid defining the distance from the grating pole along the outcoming ray direction. This set of number would define locally the grooving density. In this manner, gratings with arbitrary ruling laws, including discontinuous functions, could be simulated.
How difficult would it be to implement this?
Referring back to my question #172 and the relative answer by Manolo, I would naively assume it is enough to replace the building of the ruling density from the polynomial coefficients RUL_A by some external data input…
thanks!

@lucarebuffi
Copy link
Member

You need to change shadow3 kernel libraries and it is not trivial and not immediate. You can't use the coefficients as shadow3 normally does, since they are no more a global property but a local property of the system. You can probably try something by adding a surface error profile, but maybe it not easy to fully reproduce what you need. It is a very nice suggestion, but I don't think it will be implemented soon.

@srio
Copy link
Member

srio commented Sep 12, 2017

Hello,
my suggestion is not to implement that in the shadow3 kernel but start thinking in a standalone new element (provisional) that could in the future integrate the new shadow4 in python.

The reason is that I do not want to further develop the fortran kernel but slowly moving to python everything. Even though shadow3 has mechanism to do such interpolation from a vector array map (e/g/, for external spline profiles, or something implemented for multilayers), the use is not trivial and the code is extremely difficult as it calls pieces of undocumented libraries.

What I suggest is to identify your user case, is the surface plane or other? do you use finite dimensions, etc? and then start creating a python program that can be implemented in a oasys script that accepts the shadow beam from the previous element, and compute intersections and scatter (we can make a template) and then we left to you to implement the scattering part. Then you can use it for your case and we will further use the code for implementing the functionality in oasys.

What do you think?

Best regards,

Manuel

@lucarebuffi
Copy link
Member

Sounds nice, maybe sharing the effort it could be done in a short time.

@tmazza79xfel
Copy link
Author

Hi,
I am very willing to put my part of effort in this. Yet I don't understand in what my duty would consist. you would write a python program that can go in a script. basically something standalone, not part of the shadow library.
this program (call it custom_grating) takes the output of shadow.beam.traceOE and "computes intersections and scatter", that is if I understand correctly it outputs something similar to the output of shadow.beam.traceOE, so I can e.g. call custom_grating.getshcol and get this or that output coordinate. what would be the "scattering part" that would be left to me to implement?

@srio
Copy link
Member

srio commented Sep 12, 2017

could you define the parameters of a simple example with a source and only a grating and share the workspace? I can first try to redo the grating with a script. Then we will see how to implement the external grating.

@srio
Copy link
Member

srio commented Sep 13, 2017

Thank you.
I started the work:

  1. I modified your Oasys workspace to avoid using "finite dimensions" in the grating. At a first version this is a bit complex. I defined an entrance slit that cuts the beam. I run Oasys and saved the python script to gratings.py . This script only needs python with shadow3 installed to run.

  2. Then I want to trace the grating (oe2) using a new python code. For that I first extend the Shadow.Beam object with new methods. One of the methods is traceVLSGrating, which will do the work for us.

  3. The new method traceVLSGrating must do:
    i) receive the beam from the previous element
    ii) put it in the grating coordinate system
    iii) calculate the intercept
    iv) calculate the scattering of the grating with the help of the apply_grating_vls_on_beam method
    v) put back the beam in the lab system
    vi) return the traced beam

Everything is implemented except iv). Instead, for this template I apply simple reflection, like a mirror or zeroth order. The routine apply_grating_vls_on_beam must be rewritten, to first reproduce shadow results with the VLS, and second to include the custom ruling density you need.

Then it will be easy to couple in Oasys.

Does it sound complicated?

The code is in the github project: https://github.com/srio/extend_shadow_gratings/

I added you as collaborators, so you can push there.

@tmazza79xfel
Copy link
Author

no it does not sound complicated. I will look to the code you have pushed already and come back with questions probably.
it would help if you could point to the section of the fortran shadow3 kernel where the scattering is implemented. I am not fluent in fortran (nor in python actually) but it would be useful to look at it. thanks!

@srio
Copy link
Member

srio commented Sep 14, 2017

I will try to implement the current shadow VLS in the new code. I need some time. I certainly can help in pointing to the old code and identifying the equations used.

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

No branches or pull requests

3 participants