Skip to content

Conversation

@finnerudo
Copy link
Collaborator

Modified stage, stage_hipace and hipace_wrapper to extract middle step field information aswell.

@finnerudo finnerudo added the enhancement New feature or request label Oct 13, 2025
@ben-c-2013
Copy link
Collaborator

Would it be possible to modify this to let the user specify the step number to extract?


if output_period is None:
output_period = int(num_steps)
output_period = int(num_steps/2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If output_period is set, this leads to Hipace not dumping the middle time step, so that __extract_initial_middle_and_final_step() will fail because it does not find the middle time step.

self.initial.beam.density.rho = -jz0_beam.T/(SI.c*SI.e)

# extract middle beam density
jz0_beam, metadata0_beam = ts.get_field(field='jz_beam', iteration=int(max(ts.iterations)/2))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check that this is actually valid before blindly trying (either try/except or verify before starting simulation or in constructor etc.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Pick the middlemost timestep here, and include the actual location (s_stage value) in the plots for verification

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Top comment: It's not possible to check before simulation as you extract these attributes from the h5 files at the end of the simulation, but I have been using this in my own working directory and it works. It would not work if we don't have any of the requested fields as requested output in our input file, but we have them in the input template as default and we dont have a flag in HiPACE++ to change the requested output fields yet.

self.num_steps = np.ceil(self.length_flattop/dz)
self.num_steps = int(np.ceil(self.length_flattop / dz))
# Adds 1 to make it even if odd
self.num_steps += self.num_steps % 2 # make it even (add 1 if odd)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note, this enforces there is never a time step in the middle :P

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we are counting from 0 when extracting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does have to be even actually. Because we have h5 files from 0 up until num_steps, so if its even there is a step in the middle. num_steps is a bit misleading because its really number of steps + 1

Copy link
Collaborator

@kyrsjo kyrsjo left a comment

Choose a reason for hiding this comment

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

see comments about "middle" wrt odd (1st / 2nd / 3rd / etc. step vs. numstep and counting from 0, and picking the closest), and being safe wrt to user selected output timestep.

@kyrsjo
Copy link
Collaborator

kyrsjo commented Nov 11, 2025

Please merge #136 before #138

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants