##LENRARA Python Simulation Suite (WORK IN PROGRESS)
#The following is a set of computational function variables to help us simulate Hydrogen Fusion Processes in Condensed Matter Nuclar Science
#License GNU 3.0 Conscious Energy 2024
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation
from scipy.integrate import odeint, solve_ivp
Constants
k_B = 1.380649e-23 # Boltzmann constant, J/K
hbar = 1.0545718e-34 # Reduced Planck constant, J·s
e = 1.60217662e-19 # Elementary charge, C
c = 3.0e8 # Speed of light, m/s
Z_1 = 1 # Atomic number for hydrogen
Z_2 = 1 # Atomic number for hydrogen
a = 1.0 # Lattice parameter
n = 3 # Number of unit cells along each axis
def create_fcc_lattice(a, n):
"""Create FCC lattice."""
positions = []
basis_vectors = [(0, 0, 0), (0.5, 0.5, 0), (0.5, 0, 0.5), (0, 0.5, 0.5)]
for i in range(n):
for j in range(n):
for k in range(n):
for vec in basis_vectors:
pos = (i + vec[0], j + vec[1], k + vec[2])
positions.append(pos)
return np.array(positions) * a
def vant_hoff(delta_H, delta_S, T):
"""Calculate equilibrium pressure using Van't Hoff equation."""
R = 8.314 # J/(mol·K)
return np.exp((delta_H - T * delta_S) / (R * T))
def tsc_fusion_rate(S, G, T):
"""Calculate TSC fusion rate."""
return S * G * T
Initialize lattice and parameters
fcc_lattice = create_fcc_lattice(a, n)
T = 300 # Temperature in Kelvin
n1, n2 = 1e28, 1e28 # Number densities in m^-3
v_rel = 1e6 # Relative velocity in m/s
Calculate equilibrium pressure using van't Hoff equation
t = np.linspace(0, 100, 1000)
k = 0.1 # Arbitrary rate constant
y0 = 1e23 # Initial concentration
transmutation_result = odeint(transmutation_model, y0, t, args=(k,))
print(f'Transmutation result at final time: {transmutation_result[-1][0]:.2e}')
Example glow discharge calculation
I = 1.0 # Current in Amperes
V = 100 # Voltage in Volts
P_glow = glow_discharge_power(I, V)
print(f'Glow Discharge Power: {P_glow:.2e} W')
Example neutron production rate calculation
sigma = 1e-28 # Cross-section for the electron-proton reaction, m^2
rho_e = 1e28 # Electron density, m^-3
rho_p = 1e28 # Proton density, m^-3
E_e = 1e6 # Electron energy, eV
R_n = neutron_production_rate(sigma, rho_e, rho_p, E_e)
print(f'Neutron Production Rate: {R_n:.2e} neutrons/s')
Example TSC fusion rate calculation
S = 1.0 # Symmetry factor
G = 1.0 # Gibbs free energy for TSC formation
T = 300 # System's temperature in Kelvin
R_TSC = tsc_fusion_rate(S, G, T)
print(f'TSC Fusion Rate: {R_TSC:.2e} reactions/s')
Sonication simulation using FDTD
def sonication_simulation(nx, nt, dx, dt, source_position):
"""Simulate sonication using FDTD."""
p = np.zeros(nx) # Pressure field
v = np.zeros(nx) # Velocity field
p[source_position] = 1 # Initial disturbance
for t in range(nt):
v[1:] += (dt / dx) * (p[1:] - p[:-1])
p[:-1] += (dt / dx) * (v[1:] - v[:-1])
return p
nx = 200 # Number of spatial steps
nt = 750 # Number of time steps
dx = 0.01 # Spatial step (m)
dt = dx / (2 * c) # Time step (s)
source_position = nx // 2
ani = FuncAnimation(fig, update, frames=len(sol.t), init_func=init, blit=True)
Save the animation (optional)
ani.save('bubble_dynamics.mp4', writer='ffmpeg')
plt.show() ANIMATION FOR THE EVENT SIMUALTIONAND BUBBLE DYNAMICS IMULATION ARE NOT VISBILE IS THERE ANYTHING MISSING FIX THE CODE
The issue you're experiencing with the animations not being visible is primarily due to the placement of plt.show() and variable naming conflicts in your code. Here's how you can fix the code:
Remove Intermediate plt.show() Calls:
The plt.show() function blocks the execution of the code until the window it creates is closed. If you have multiple plt.show() calls, the subsequent code (including the second animation) won't execute until the first plot window is closed.
Solution: Remove the first plt.show() call so that both animations are set up before displaying.
Avoid Variable Naming Conflicts:
Variables like fig, ax, and ani are used in both animations. This can lead to unexpected behavior as the variables may overwrite each other.
Solution: Use distinct variable names for each animation (e.g., fig1, ax1, ani1 for the first animation and fig2, ax2, ani2 for the second).
Correct the Time Decrement in the LENR Animation:
In your update function for the LENR animation, you're subtracting cumulative time from decay_times, which isn't accurate. You should subtract the time step (dt) instead of the cumulative frame time.
Solution: Modify the update function to decrement decay_times by a fixed dt per frame.
Here's the corrected code with these fixes applied:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation
from scipy.integrate import odeint, solve_ivp
# Constants (same as before)
# ... [Your constants here]
# Functions (same as before)
# ... [Your functions here]
# Initialize lattice and parameters (same as before)
# ... [Your initialization code here]
# Calculate equilibrium pressure using van't Hoff equation (same as before)
# ... [Your equilibrium calculation here]
# Simulate LENR event (same as before)
# ... [Your LENR simulation code here]
# Modify the decay times variable
decay_times = np.random.exponential(scale=time_to_fusion, size=decay_positions.shape[0])
# Plotting initial lattice
fig1 = plt.figure()
ax1 = fig1.add_subplot(111, projection='3d')
scat = ax1.scatter([], [], [], c='r', s=100)
ax1.set_xlim([0, n])
ax1.set_ylim([0, n])
ax1.set_zlim([0, n])
ax1.set_title('LENR Event Simulation')
def update_lenr(frame_num, scat, decay_positions, decay_times, dt):
"""Update function for LENR animation."""
decay_times -= dt
active_indices = decay_times > 0
scat._offsets3d = (decay_positions[active_indices, 0],
decay_positions[active_indices, 1],
decay_positions[active_indices, 2])
return scat,
dt = 0.1
frames = int(20 / dt)
ani1 = FuncAnimation(fig1, update_lenr, frames=frames,
fargs=(scat, decay_positions, decay_times, dt), interval=50)
# Remove plt.show() here
# Bubble Dynamics under Sonication Animation
# Simulating cavitation using Rayleigh-Plesset equation
# ... [Your Rayleigh-Plesset code here]
# Set up the figure and axis for the bubble dynamics animation
fig2, ax2 = plt.subplots()
ax2.set_xlim(t_span)
ax2.set_ylim(0, np.max(sol.y[0]) * 1.1)
line, = ax2.plot([], [], lw=2)
ax2.set_xlabel('Time [s]')
ax2.set_ylabel('Bubble Radius [m]')
ax2.set_title('Bubble Dynamics under Sonication')
def init_bubble():
line.set_data([], [])
return line,
def update_bubble(frame_num):
line.set_data(sol.t[:frame_num], sol.y[0][:frame_num])
return line,
ani2 = FuncAnimation(fig2, update_bubble, frames=len(sol.t), init_func=init_bubble, blit=True)
# Only one plt.show() at the end
plt.show()
Explanation of Changes:
Variable Renaming: Changed fig, ax, and ani to fig1, ax1, ani1 for the first animation and fig2, ax2, ani2 for the second animation to prevent variable overwriting.
Removed Intermediate plt.show(): Eliminated the plt.show() call after the first animation setup.
Corrected Time Decrement: Modified the update function (update_lenr) for the LENR animation to decrement decay_times by a constant dt instead of frame.
Note: Ensure all necessary code sections (like constants, functions, and other calculations) are appropriately placed in your script.
Additional Tips:
Save Animations (Optional): If you wish to save the animations to files, you can uncomment and adjust the ani.save() calls accordingly.
Display Animations in Notebooks: If you're running this code in a Jupyter notebook, you might need to include %matplotlib notebook or %matplotlib inline at the top of your notebook to properly display animations.
Testing the Code:
Run the script in your preferred Python environment.
Both animations should now appear in separate windows after executing the code.
Ensure that all dependencies (like matplotlib, numpy, and scipy) are installed and up to date.