Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Output undulator structure in setup_source function in srwl_bl.py. #9

Closed
wants to merge 5 commits into from

Conversation

bnash
Copy link

@bnash bnash commented May 15, 2018

No description provided.

@bnash
Copy link
Author

bnash commented May 15, 2018

Still a problem here, before we merge.

The undulator is output from setup_source, but now calc_all doesn't work:

srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
File "/home/vagrant/src/srbright18/jupyter/srwl_bl.py", line 48, in init
raise Exception("Incorrect Magnetic Field Container structure")
Exception: Incorrect Magnetic Field Container structure

The problem is here:
https://github.com/radiasoft/SRW-light/blob/master/env/work/srw_python/srwl_bl.py#L49-#L51

@@ -3043,6 +3043,7 @@ def setup_source(v): #MR20160617 - moved from Sirepo .jinja template
del v.und_g
if hasattr(v, 'gbm_pen'):
del v.gbm_pen
mag = SRWLMagFldU([SRWLMagFldH(1, 'v', v.und_by, v.und_phy, v.und_sy, 1), SRWLMagFldH(1, 'h', v.und_bx, v.und_phx, v.und_sx, 1)], v.und_per, v.und_per) #BN20180515 - output undulator structure as mag
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd recommend to split the line to 2 or 3, it's hard to read.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I'll do that

@bnash
Copy link
Author

bnash commented May 16, 2018

Now there's a problem passing the undulator into set_und_sin due to https://github.com/radiasoft/SRW-light/blob/master/env/work/srw_python/srwl_bl.py#L283-L287

I think this is a bug. mag_approx field is deleted, then asked if it is zero. Since it doesn't exist, this gives an error.

@bnash
Copy link
Author

bnash commented May 16, 2018

After most recent fix, it looks like it works for me. But I'd appreciate a review of all the changes here.
The output of mag is now the container with the undulator. The K value can be computed with
mag.arMagFld[0].get_K()

Copy link
Collaborator

@mrakitin mrakitin left a comment

Choose a reason for hiding this comment

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

Please remove the two images added to git:

  • env/work/srw_python/uti_plot-0.png
  • env/work/srw_python/uti_plot-1.png

I'm not sure the changes won't break anything... I'd recommend to use SRW from this branch and try it with Sirepo locally. If all the existing examples reproduce the results which are on alpha/beta servers, that's good to merge.

@bnash
Copy link
Author

bnash commented May 16, 2018

Ok, I removed .png files.
I will try to see how to run Sirepo locally to try the tests you suggest.

@mrakitin
Copy link
Collaborator

Thanks. Please also pay attention to the tabulated undulator examples.

You may also consider to run all Sirepo tests, which may help to reveal the hidden issues.

In the future it would be nice to have a solid test suite for SRW (see #4 and #5). This will help to test changes quickly.

@bnash
Copy link
Author

bnash commented May 16, 2018

I get the point about the tabulated undulator. I should understand how this is represented in python. I see the structure is created in python here

@robnagler robnagler closed this Oct 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants