simulators objects#
Here we implements the generic Simulation class. Actual implementions are to be
defined in other submodules.
- class atomsmltr.simulation.simulator.simbase.SimRes(y: ndarray, t: ndarray, y_last: ndarray = None, tags: set = None, t_events: list = None, y_events: list = None, success: bool = True)[source]#
Bases:
objectClass for simulation results
- class atomsmltr.simulation.simulator.simbase.Simulation(config: Configuration = None)[source]#
Bases:
ABCThe generic Simulation object
- Parameters:
config (Configuration, optional) – the configuration to consider, by default None
Note
this is an abstract class, actual implementations are defined elsewhere and inherit from this class
- property config#
the configuration for this simulation
- Type:
- abstractmethod get_force(u: ndarray) ndarray[source]#
returns the force felt at a position/speed vector u
- Parameters:
u (array, shape (6,) or (n1, n2, .., 6)) – array of cartesian coordinates (position and speed) in the lab frame
- Returns:
force – the force at the coordinates given by
pos_speed_vector- Return type:
array, shape (3,) or (n1, n2, .., 3)
- integrate(u0: ndarray, t: ndarray)[source]#
Integrates the system with initial conditions
u0- Parameters:
u0 (array, shape (6,)) – the initial conditions (x, y, z, vx, vy, vz)
t (array, shape (n,)) – the timesteps to integrate
- Returns:
the result of the simulation
- Return type:
res
- run(t: ndarray, u0_list: list = None, npools: int = 0, verbose: bool = False) list[source]#
Runs a batch of simulations from a list of initial conditions
- Parameters:
t (array, shape (n,)) – time steps for the simulation
u0_list (list, optional) – list of initial conditions, by default None
npools (int, optional) – number of pools for parallel computing. If set to zero, no paralalelisation, by default 0
verbose (bool, optional) – if set to True, a progress bar is displayed, by default False
- Returns:
res_list – a list of results
- Return type:
list
Examples
# ... init a config object with the `Configuration` class # - import a simulation class from atomsmltr.simulation import ScipyIVP_3D # - init and setup sim = ScipyIVP_3D(method="Radau") sim.config = config # - parameters # initial conditions vz_list = np.linspace(10, 300, 40) u0_list = [(0, 0, -0.15, 0, 0, v) for v in vz_list] sim.u0_list = u0_list # time t = np.linspace(0, 0.05, 1000) # - run a batch in parallel res_list = sim.run(t, npools=5, verbose=True)
- property u0_list#
a list of initial conditions for batch running
- Type:
list
- atomsmltr.simulation.simulator.simbase.get_force_vec(pos_speed_vector: ndarray, config: Configuration, return_list: bool = False) ndarray[source]#
Computes the force on an atom, by adding all radiations pressures, in a vectorization style that matches the package’s standards
- Parameters:
pos_speed_vector (array, shape (6,) or (n1, n2, .., 6)) – array of cartesian coordinates (position and speed) in the lab frame
config (Configuration) – a configuration object
return_list (bool (opt, default=False)) – if set to True, also returns the scattering rates and laser wavenumbers this is used to compute the stochastic part of the force (spont. em.)
- Returns:
force (array, shape (3,) or (n1, n2, .., 3)) – the force at the coordinates given by
pos_speed_vectorscattering_list (list) – returned only if
return_listis set toTruelist of lasers scattering rates and wavenumbers.
Notes
pos_speed_vectoris an array_like object, with shape (6,) or (n1, n2, .., 6).In all cases, the last dimension contains cordinates (x, y, z, vx, vy, vz), in meter or meter/seconds and in the lab frame
Examples
# ... init a config object with the `Configuration` class from atomsmltr.simulation.simulator import get_force_vec import numpy as np # - init a position & speed vector grid # x spans from -0.1 to 0.1 # vx spans from -10 to 30 # y, z, vy, vz set to 0 grid = np.mgrid[ -0.1:0.1:100j, # x 0:0:1j, # y 0:0:1j, # z -10:30:101j, # vx 0:0:1j, # vy 0:0:1j, # vz ] # squeeze unused dimensions grid = np.squeeze(grid) # get X and VX grids (for instance for plotting) X, _, _, VX, _, _ = grid # make (x, y, z, vx, vy, vz) the last dimension # as requested by vectorization convention pos_speed_vector = grid.T # - compute the force force = get_force_vec(pos_speed_vector, config) FX, FY, FZ = force.T # - print shapes for illustration print(f"{grid.shape=}") print(f"{X.shape=}") print(f"{FX.shape=}") print(f"{pos_speed_vector.shape=}") print(f"{force.shape=}")
This returns
grid.shape=(6, 100, 101) X.shape=(100, 101) FX.shape=(100, 101) pos_speed_vector.shape=(101, 100, 6) force.shape=(101, 100, 3)