Customization¶
BubbleBox contains a selection of "setters" and "getters" for setting and getting properties of the system. Here, we'll present the basic functions for setting system variables after initialization.
import bubblebox as bb
import numpy as np
b = bb.showcase.repulsive_gas()
Positions¶
To set new positions, call the set_pos
-method as follows:
new_positions = np.random.uniform(-1,1,b.pos.shape)
b.set_pos(new_positions)
Velocities¶
To set new velocities, call the set_vel
-method as follows:
new_velocities = np.random.uniform(-1,1,b.pos.shape)
b.set_vel(new_velocities)
Note that the default time-integration technique is velocity-verlet (wikipedia), which operates on the half-step velocities. Thus, at any instance, the actual velocities are approximated from these half-step velocities, and setting the vel
(instant) and vel_
(half-step) arrays must be done simultaneously.
Masses¶
BubbleBox stores both masses and their inverse separately, thus to properly update the masses you should call the set_masses
method as follows:
new_masses = np.random.uniform(1,5,b.masses.shape)
b.set_masses(new_masses)
Forces¶
Forces in BubbleBox are explicitly defined for each pair of bubbles in a n_bubbles x n_bubbles x 3 matrix. On the one hand, this results in some performance issues for large systems, while on the other hand it makes it easy to implement heterogenous interactions such that Harmonic-, Coulomb-, Lennard-Jones- or custom forces simultaneously.
In order to set the forces between a set of bubbles, you may do the following:
from bubblebox.mdbox import lj_force, no_force, coulomb_force, hook_force
bubbles_a = [0,2,3] #indexed in same order as pos
bubbles_b = [1,4,5] #indexed in same order as pos
# set interaction potential to 10*(∆x - 2)**2 :
b.set_forces(hook_force, bubbles_a = bubbles_a, bubbles_b = bubbles_b, force_params = np.array([10.0,2]))