Metadata-Version: 2.4
Name: simplestoragering
Version: 0.0.3
Summary: simple storage ring for single particle dynamics simulation.
Author-email: Bingfeng WEI <wbf2016@mail.ustc.edu.cn>
License: MIT License
        
        Copyright (c) 2021 Wei, Bingfeng
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/wei0852/simplestoragering
Project-URL: Repository, https://github.com/wei0852/simplestoragering.git
Project-URL: Issues, https://github.com/wei0852/simplestoragering/issues
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Cython
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy<2,>=1.18
Requires-Dist: matplotlib>3.4.0
Requires-Dist: PyNAFF
Requires-Dist: scipy
Dynamic: license-file

# SimpleStorageRing
SimpleStorageRing is a python project to simulate single particle dynamics in a simple storage ring and calculate lattice data.

You can sort the components to generate a ring, and then calculate the data of storage ring by Courant-Snyder method. 


## Installation

Download from PyPi:

```command
pip install -U simplestoragering
```

or download the source files and then compile them using Cython:

----------------------
```command
git clone https://github.com/wei0852/simplestoragering.git
cd simplestoragering
pip install .
```

## Usage

see `example_features.py`.

set reference particle (electron) energy first:

```
set_ref_energy(energy_MeV: float)
```
or
```
set_ref_gamma(gamma: float)
```
### components
A storage ring consists of many magnets to guide electron beam,

* `Mark`
* `Drift`
* `HBend`, horizontal bend.
* `Quadrupole`
* `Sextupole`
* `Octupole`

$k_n = \dfrac{q}{P_0} \dfrac{\partial^n B_y}{\partial x^n}$. All the components are child classes of the Element class. 

### Courant-Snyder lattice
`CSLattice(ele_list: list[Element], n_periods: int)`, lattice solved by C-S method.

## Functions

`symplectic_track(particle, lattice, n_turns: int, record = True)`

`track_4d_closed_orbit(lattice: CSLattice, delta, resdl_limit=1e-16, matrix_precision=1e-9)`

`output_opa_file(lattice: CSLattice, file_name=None)`

`output_elegant_file(lattice: CSLattice, filename=None, new_version=True)`

`chromaticity_correction(lattice: CSLattice, sextupole_name_list: list, target: list=None, initial_k2=None, update_sext=True, verbose=True)`

`adjust_tunes(lattice: CSLattice, quadrupole_name_list: list, target: list, iterations=5, initialize=True)`

## DA & LMA

* XYGrid()
* XDeltaGrid()
* NLine()
* LocalMomentumAperture()

and some functions:

`plot_layout_in_ax(ele_list: list, ax: Axes, ratio=0.03)`

`plot_resonance_line_in_ax(ax: Axes, order: int = 3, refnux: float=None, refnuy: float=None)`

`plot_lattice(ele_list, parameter: str or list[str], with_layout=True)`

or use `get_col(ele_list, parameter)` to get a column of the parameter along the element list.

