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

Enables passing a function for auto_dt_bunch in PlasmaStage #159

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions wake_t/beamline_elements/field_element.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Union, List, Literal
from typing import Optional, Union, Callable, List, Literal

import scipy.constants as ct

Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(
n_out: Optional[int] = 1,
name: Optional[str] = 'field element',
fields: Optional[List[Field]] = [],
auto_dt_bunch: Optional[str] = None,
auto_dt_bunch: Optional[Callable[[ParticleBunch], float]] = None,
push_bunches_before_diags: Optional[bool] = True,
) -> None:
self.length = length
Expand Down
12 changes: 11 additions & 1 deletion wake_t/beamline_elements/plasma_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import wake_t.physics_models.plasma_wakefields as wf
from wake_t.fields.base import Field
from .field_element import FieldElement
from wake_t.particles.particle_bunch import ParticleBunch


DtBunchType = Union[float, str, List[Union[float, str]]]
Expand Down Expand Up @@ -50,6 +51,10 @@ class PlasmaStage(FieldElement):
stage. A list of values can also be provided. In this case, the list
should have the same order as the list of bunches given to the
``track`` method.
auto_dt_bunch : callable, optional
Function used to determine the adaptive time step for bunches in
which the time step is set to ``'auto'``. The function should take
solely a ``ParticleBunch`` as argument.
push_bunches_before_diags : bool, optional
Whether to push the bunches before saving them to the diagnostics.
Since the time step of the diagnostics can be different from that
Expand Down Expand Up @@ -93,6 +98,7 @@ def __init__(
wakefield_model: Optional[str] = 'simple_blowout',
bunch_pusher: Optional[Literal['boris', 'rk4']] = 'boris',
dt_bunch: Optional[DtBunchType] = 'auto',
auto_dt_bunch: Optional[Callable[[ParticleBunch], float]] = None,
push_bunches_before_diags: Optional[bool] = True,
n_out: Optional[int] = 1,
name: Optional[str] = 'Plasma stage',
Expand All @@ -106,14 +112,18 @@ def __init__(
if self.wakefield is not None:
fields.append(self.wakefield)
fields.extend(self.external_fields)
if auto_dt_bunch is not None:
self.auto_dt_bunch = auto_dt_bunch
else:
self.auto_dt_bunch = self._get_optimized_dt
super().__init__(
length=length,
dt_bunch=dt_bunch,
bunch_pusher=bunch_pusher,
n_out=n_out,
name=name,
fields=fields,
auto_dt_bunch=self._get_optimized_dt,
auto_dt_bunch=self.auto_dt_bunch,
push_bunches_before_diags=push_bunches_before_diags,
)

Expand Down