Scipy-based integrators#
Implements integrator based on scipy’s solve_ivp method.
- class atomsmltr.simulation.simulator.scipy.ScipyIVP_3D(config: Configuration = None, method: str = 'Radau', **solve_ivp_args)[source]#
Bases:
SimulationA simulation class based on Scipy’s
solve_ivpsolver- Parameters:
config (Configuration, optional) – the configuration to consider for the simulation
method (str, optional) – method used for the
solve_ivpsolver, by default “Radau”**solve_ivp_args – all other arguments are directly passed to
solve_ivp
References
https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html
- get_force(u)[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)
- atomsmltr.simulation.simulator.scipy.get_force_vec_scipy(pos_speed_vector: ndarray, config: Configuration) ndarray[source]#
Computes the force on an atom, by adding all radiations pressures, in a Scipy compatible vectorization style
- Parameters:
pos_speed_vector (array, shape (6,) or (6,k)) – cartesian position and speed vector
config (Configuration) – a configuration object
- Returns:
force – the force at the coordinates given by
pos_speed_vector- Return type:
array, shape (3,) or (3,k)
Notes
The position/speed vector ‘pos_speed_vector’ should be of shape (6,) or (6,k) with the first dimension containing (x, y, z, vx, vy, vz) in the lab frame
Note
The function is vectorized to be compatible with Scipy’s
solve_ivpfunction. Hence, it does not satisfy the functionnal vectorization used in the rest of this moduleExamples
# ... init a config object with the `Configuration` class from atomsmltr.simulation.simulator import get_force_vec_scipy import numpy as np # - init a position & speed vector grid # vx spans from -10 to 30 # x, y, z, vy, vz set to 0 vx_list = np.linspace(-10, 30, 301) pos_speed_vector = np.array([(0,0,0,vx,0,0,) for vx in vx_list]).T # - compute the force force = get_force_vec_scipy(pos_speed_vector, config) FX, FY, FZ = force # - print shapes for illustration print(f"{FX.shape=}") print(f"{pos_speed_vector.shape=}") print(f"{force.shape=}")
This returns
FX.shape=(301,) pos_speed_vector.shape=(6, 301) force.shape=(3, 301)
- atomsmltr.simulation.simulator.scipy.stop_position_event_scipy(t: float, u: ndarray, stop_position: list, offset: float = 0.0)[source]#
Implements ‘stop’ events for Scipy’s solve_ivp, based on atom’s position
- Parameters:
t (float) – time, not used here but required for the
eventsfunctions insolve_ivpu (array, shape (6,k)) – position/speed vector, according to
solve_ivpvectorization conventionstop_position (list) – list of Zones objects targetting position with actions set to stop
- Returns:
res – whether to stop the simulation
- Return type:
bool
- atomsmltr.simulation.simulator.scipy.stop_speed_event_scipy(t: float, u: ndarray, stop_speed: list, offset: float = 0.0)[source]#
Implements ‘stop’ events for Scipy’s solve_ivp, based on atom’s speed
- Parameters:
t (float) – time, not used here but required for the
eventsfunctions insolve_ivpu (array, shape (6,k)) – position/speed vector, according to
solve_ivpvectorization conventionstop_speed (list) – list of Zones objects targetting speed with actions set to stop
- Returns:
res – whether to stop the simulation
- Return type:
bool