5. Python API
5.1. Principles
The python script can be run in mpi mode.
Each method and class is ended by subscript “_(N)D” for indicating the dimension N. For example
throw_spheres_3D. By convention, everything is here indicated with a final subscript_3D. Nevertheless, these can be replaced by_2D, etc.
5.2. Header
import mpi4py
mpi4py.rc.thread_level = "funneled"
from mpi4py import MPI
Then, import the python interface:
import rsa_mpi_py as rsa_mpi
5.3. Fast methods
- For throwing spheres inside a cube of length
Lof radii \(r_1, ..., r_n\), with prescribed volume fractions \(\phi_1, ..., \phi_n\) and phase (=identifier) \(p_1, ..., p_n\), use:
throw_spheres_3D(L, desired_radius_volumeFraction_phase, seed, write_paraview)L: size of the box \([0, L]^3\)desired_radius_volumeFraction_phase: vector of triples [(double) radius , (double) volumeFraction, (int) phase]seedindicates the random seed for the pseudo-random generatorwrite_paraview: bool write a paraview output”return The local list of spheres inside the domain
Warning
This function Returns the local list of spheres inside the domain only on a single the MPI processes.
5.4. Classes
The principle is the following: a domain is defined, then, the polydispersity of the spheres is chosen, then, the algorithm is launched. Each task is abstracted by a single class.
rsa_domain_3D: Data storage for the spheres. Pave a cuboid \([l_{\min}[0], l_{\max}[0]] x ... [l_{\min}[D], l_{\max}[D]]\). Inside a domain, spheres are partitionned between different cells (=small cuboids). Methods:rsa_domain_3D([l_min[0], ... l_min[D]], [l_max[0], ... l_max[D]], a_ghost_layer, a_rad). Constructor.a_rad: the size of each cell in any direction should be larger thana_rada_ghost_layer: Number of ghost layers around the cell. Should be taken as 1.
domain_log: Display.get_total_volume: Return the total volume of the (global) cuboid.paraview: Print paraview output.compute_total_volume_of_spheres: Compute the cumulated volume of all spheres inside the whole domainsextract_spheres: return list of spheres inside the domain. :warning: only on a single MPI processe
radius_generator_3D: Store the prescribed radius distribution fixed by the user. Methods:radius_generator_3D([[rad[0], N[0], p[0]], ...], exclusion_distance): First placeN[0]spheres of radiusrad[0], denoted by phasep[0], thenN[1]spheres… All spheres are separated by a distanceexclusion_distance.radius_generator_3D([[rad[0], phi[0], p[0]], ...], volume_total, exclusion_distance): First placeNspheres of radiusrad[0]denoted by phasep[0]such that the resulting volume fraction isphi[0], thenNspheres… All spheres are separated by a distanceexclusion_distance. The total volume of the domain isvolume_total.
rsa_algo_3D: Class for execution of the algorithm. Methods:rsa_algo_3D(rsa_domain, radius_generator): Constructorproceed(seed): Execute the RSA algorithm, with the seed for the pseudo-random generator.reset_radius_generator(a_radius_generator): Reset the radius generator, but retains the already placed spheres. Proceed can then be appealed once more.