Skip to content

Commit 43d7cb1

Browse files
author
Lee Carver
committed
Merge branch 'master' into modify_beamloading
2 parents 2189aee + 43d4d3a commit 43d7cb1

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

pyat/at.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static PyObject *at_atpass(PyObject *self, PyObject *args, PyObject *kwargs) {
342342
"bunch_spos", "bunch_currents", "start_elem", "end_elem", NULL};
343343
static double lattice_length = 0.0;
344344
static int last_turn = 0;
345-
static int valid = 0;
345+
static PyObject *lattice_id = NULL;
346346

347347
PyObject *lattice;
348348
PyObject *particle;
@@ -434,11 +434,12 @@ static PyObject *at_atpass(PyObject *self, PyObject *args, PyObject *kwargs) {
434434
}
435435
#endif /*_OPENMP*/
436436

437-
if (!(keep_lattice && valid)) {
437+
if (!(keep_lattice && lattice_id == lattice)) {
438438
PyObject **element;
439439
double *elem_length;
440440
track_function *integrator;
441441
PyObject **pyintegrator;
442+
442443
/* Release the stored elements */
443444
for (elem_index=0; elem_index < num_elements; elem_index++) {
444445
free(elemdata_list[elem_index]);
@@ -499,7 +500,7 @@ static PyObject *at_atpass(PyObject *self, PyObject *args, PyObject *kwargs) {
499500
*elem_length++ = length;
500501
Py_INCREF(el); /* Keep a reference to each element in case of reuse */
501502
}
502-
valid = 0;
503+
lattice_id = NULL;
503504
}
504505

505506
/* Check for partial turn tracking */
@@ -641,7 +642,7 @@ static PyObject *at_atpass(PyObject *self, PyObject *args, PyObject *kwargs) {
641642
param.nturn++;
642643
start_elem = 0;
643644
}
644-
valid = 1; /* Tracking successful: the lattice can be reused */
645+
lattice_id = lattice; /* Tracking successful: the lattice can be reused */
645646
last_turn = param.nturn; /* Store turn number in a static variable */
646647

647648
#ifdef _OPENMP

pyat/at/lattice/elements/basic_elements.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,24 +556,24 @@ def __init__(
556556
if taux == 0.0:
557557
dampx = 1
558558
else:
559-
dampx = np.exp(-1 / taux)
559+
dampx = np.exp(-2 / taux)
560560

561561
assert tauy >= 0.0, "tauy must be greater than or equal to 0"
562562
if tauy == 0.0:
563563
dampy = 1
564564
else:
565-
dampy = np.exp(-1 / tauy)
565+
dampy = np.exp(-2 / tauy)
566566

567567
assert tauz >= 0.0, "tauz must be greater than or equal to 0"
568568
if tauz == 0.0:
569569
dampz = 1
570570
else:
571-
dampz = np.exp(-1 / tauz)
571+
dampz = np.exp(-2 / tauz)
572572

573573
kwargs.setdefault("PassMethod", self.default_pass[True])
574574
kwargs.setdefault("U0", U0)
575575
kwargs.setdefault(
576-
"damp_mat_diag", np.array([dampx, dampx, dampy, dampy, dampz, dampz])
576+
"damp_mat_diag", np.array([1, dampx, 1, dampy, dampz, 1])
577577
)
578578

579579
super().__init__(family_name, **kwargs)

pyat/at/tracking/track.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from __future__ import annotations
22

33
__all__ = [
4-
"lattice_track",
4+
"MPMode",
55
"element_track",
6-
"internal_lpass",
6+
"gpu_core_count",
7+
"gpu_info",
78
"internal_epass",
9+
"internal_lpass",
810
"internal_plpass",
9-
"gpu_info",
10-
"gpu_core_count",
11-
"MPMode",
11+
"lattice_track",
1212
]
1313

1414
import multiprocessing
@@ -31,7 +31,7 @@
3131

3232
class MPMode(Enum):
3333
"""
34-
Multi Processing mode
34+
Multi Processing mode.
3535
"""
3636

3737
CPU = 1 #: CPU multiprocessing
@@ -55,14 +55,14 @@ class MPMode(Enum):
5555

5656

5757
def _atpass_fork(seed, rank, rin, **kwargs):
58-
"""Single forked job"""
58+
"""Single forked job."""
5959
reset_rng(rank=rank, seed=seed)
6060
result = _atpass(_globring, rin, **kwargs)
6161
return rin, result
6262

6363

6464
def _atpass_spawn(ring, seed, rank, rin, **kwargs):
65-
"""Single spawned job"""
65+
"""Single spawned job."""
6666
reset_rng(rank=rank, seed=seed)
6767
result = _atpass(ring, rin, **kwargs)
6868
return rin, result
@@ -99,23 +99,23 @@ def _lattice_pass(
9999
r_in,
100100
nturns: int = 1,
101101
refpts: Refpts = End,
102-
no_varelem=True,
102+
no_varelem: bool = True,
103103
seed: int | None = None,
104104
use_gpu: bool = False,
105105
**kwargs,
106106
):
107107
kwargs["reuse"] = kwargs.pop("keep_lattice", False)
108108
if no_varelem:
109109
lattice = disable_varelem(lattice)
110-
else:
111-
if sum(variable_refs(lattice)) > 0:
112-
kwargs["reuse"] = False
110+
elif sum(variable_refs(lattice)) > 0:
111+
kwargs["reuse"] = False
113112
refs = get_uint32_index(lattice, refpts)
114113
if seed is not None:
115114
reset_rng(seed=seed)
116115
if use_gpu:
117116
if not (iscuda() or isopencl()):
118-
raise AtError("No GPU support enabled")
117+
msg = "No GPU support enabled"
118+
raise AtError(msg)
119119
else:
120120
return _gpupass(lattice, r_in, nturns, refpts=refs, **kwargs)
121121
else:
@@ -129,11 +129,10 @@ def _plattice_pass(
129129
nturns: int = 1,
130130
refpts: Refpts = End,
131131
seed: int | None = None,
132-
pool_size: int = None,
133-
start_method: str = None,
132+
pool_size: int | None = None,
133+
start_method: str | None = None,
134134
**kwargs,
135135
):
136-
verbose = kwargs.pop("verbose", False)
137136
refpts = get_uint32_index(lattice, refpts)
138137
any_collective = has_collective(lattice)
139138
kwargs["reuse"] = kwargs.pop("keep_lattice", False)
@@ -208,7 +207,8 @@ def lattice_track(
208207
continue the sequence
209208
keep_lattice (bool): Use elements persisted from a previous
210209
call. If :py:obj:`True`, assume that the lattice has not changed
211-
since the previous call.
210+
since the previous call. Ignored if *lattice* differs from the cached one.
211+
Default: :py:obj:`False`
212212
keep_counter (bool): Keep the turn number from the previous
213213
call.
214214
turn (int): Starting turn number. Ignored if
@@ -379,7 +379,7 @@ def element_track(element: Element, r_in, in_place: bool = False, **kwargs):
379379
"""
380380
:py:func:`element_track` tracks particles through one element of a
381381
calling the element-specific tracking function specified in the
382-
Element's *PassMethod* field
382+
Element's *PassMethod* field.
383383
384384
Usage:
385385
>>> element_track(element, r_in)

0 commit comments

Comments
 (0)