<jupyter_start><jupyter_text>Number of collisions<jupyter_code>%matplotlib widget 

# global import
import numpy as np
import pandas as pd

# plotting
import matplotlib.pyplot as plt
import seaborn as sns
# local import
import lppydsmc as ld

seed = 1111
np.random.seed(seed)
def number_of_collisions(mass, radius, quantity, time_step, iterations, temperature = 300, density = 3.2e19, cell_volume = 1e-9, seed = None):
    import pandas as pd
    import lppydsmc as ld
    import numpy as np
    from tqdm import tqdm
    from pathlib import Path
    np.random.seed(seed)
    collisions_list = []
    points = 1e-3*np.array([[0,0],[0,1],[1,1],[1,0]])
    positions = ld.initialization.particles.uniform_position(quantity, points)

    vel_std = ld.utils.physics.gaussian(temperature, mass)
    velocities = np.random.normal(loc=0.0, scale=vel_std, size = (quantity,3))
    
    arrays = [np.concatenate((positions, velocities), axis = 1)]
    
    grid = np.array([np.zeros((quantity,2))]) # 1 cell
    grid[0][:,1] = np.array([k for k in range(quantity)])
    currents = np.array([quantity])
    averages = np.array([quantity])
    
    cross_section = np.pi*4*radius*radius
    cross_sections = np.array([[cross_section]])

    max_proba = np.array([3*cross_section*ld.utils.physics.maxwellian_mean_speed(temperature, mass)])

    target_density = density
    cell_volume = cell_volume
    particles_weight = target_density*cell_volume/quantity
    remains_per_cell = np.array([0.])
    masses = np.array([mass])
    monitoring = None
    group_fn = None
    
    period_saving = 10

    for iteration in tqdm(range(1,iterations+1)) :
        
        results = ld.collision.handler_particles_collisions(arrays, grid, currents, time_step, \
            averages, max_proba, cross_sections, cell_volume, particles_weight, remains_per_cell, masses, monitoring = monitoring, group_fn = group_fn)
        collisions_list.append(results)
        # if(iteration%100 == 0):
        #    print(ld.collision.collider.candidates(currents, time_step, averages, max_proba, cell_volume, particles_weight, remains_per_cell))
        #    print(remains_per_cell)
        #     fig, ax = plt.subplots(3)
        #     ax[0].hist(arrays[0][:,2],color = 'r', bins = 30)
        #     ax[1].hist(arrays[0][:,3], color = 'g', bins = 30)
        #     ax[2].hist(arrays[0][:,4], color = 'b', bins = 30)
    return collisions_list
mass = 2.16e-25 # kg
time_step = 1e-5
radius = 2e-10
J_TO_EV = 1/1.6e-19
iterations = 1000
T = 300
n = 3.2e19
quantity = int(1e5)
cell_volume = 1e-9
collisions_list = number_of_collisions(mass = mass, radius = radius, quantity = quantity, time_step = time_step, \
                                       iterations = iterations, temperature = T, density= n,cell_volume = cell_volume, seed = 1111)
fig, ax = plt.subplots()
ax.plot(collisions_list)
BOLTZMAN_CONSTANT = 1.38064e-23 # J K−1

def relative_speed_maxwellian(temperature,mass):
    return 4/np.sqrt(np.pi)*np.sqrt(BOLTZMAN_CONSTANT*temperature/mass)
# 1st : theoretical collision frequency for MB distribution
def number_of_collisions_per_time_and_volume(T, m, d, n): # per unit of volume and time
    cross_section = np.pi*d*d
    return 1/2 * cross_section *n**2 * relative_speed_maxwellian(T,m)
relative_speed_maxwellian(T, mass)
nu_c = number_of_collisions_per_time_and_volume(T = T, m = mass, d=2*radius, n = n)
simu_time = iterations*time_step
volume_system = 1e-9
particles_weight = n*volume_system/quantity
particles_weight
collisions_nb = np.sum(np.array(collisions_list)) # we count twice too many 
print('Total number of collision : {:e}'.format(collisions_nb));
print('Equivalent in reality : {:e}'.format(particles_weight*collisions_nb))
print('Expected number of collisions in reality : {:e}'.format(nu_c*simu_time*volume_system))
print('Ratio of the two : {:.2}'.format(100*(particles_weight*collisions_nb-nu_c*simu_time*volume_system)/(nu_c*simu_time*volume_system)))<jupyter_output>Total number of collision : 2.511540e+06
Equivalent in reality : 8.036928e+11
Expected number of collisions in reality : 8.042644e+11
Ratio of the two : -0.071
{'fraction_non_alphanumeric': 0.12091107341894838, 'fraction_numerical': 0.034892173491640414, 'mean_word_length': 4.127950310559006, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '487305', 'license': 'MIT', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1426, 'n_words': 312, 'path': 'benchmarks/notebooks/number_of_collisions.ipynb', 'repo_name': 'Quettle/lppydsmc', 'size': '4127'}