Skip to content

Commit

Permalink
Enable the use of auto_dt_bunch in FieldElement and PlasmaStage.
Browse files Browse the repository at this point in the history
  • Loading branch information
delaossa committed Jul 5, 2024
1 parent 09f4719 commit bf6b4e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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
11 changes: 10 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,17 @@ def __init__(
if self.wakefield is not None:
fields.append(self.wakefield)
fields.extend(self.external_fields)
self.auto_dt_bunch = auto_dt_bunch
if self.auto_dt_bunch is None:
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

0 comments on commit bf6b4e6

Please sign in to comment.