# LENRARA Python Simulation Suite with GUI (WORK IN PROGRESS)
# The following is a set of computational function variables to help us simulate Hydrogen Fusion Processes in Condensed Matter Nuclear Science
# License GNU 3.0 Conscious Energy 2024

import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from scipy.integrate import odeint, solve_ivp
import tkinter as tk
from tkinter import ttk

# 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

# Thermodynamic properties
delta_H = -40e3  # Enthalpy of formation, J/mol H2
delta_S = 130  # Entropy, J/mol·K H2

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 fusion_cross_section(T):
    """Calculate fusion cross-section."""
    term1 = (e**2 / (4 * np.pi * hbar * c))**2
    term2 = (1 / (k_B * T))**2
    term3 = np.exp(-3 * np.pi / (4 * np.sqrt(2)) * (Z_1 * Z_2 * e**2 / (hbar * c))**2 / (k_B * T))
    return 1e-24 * term1 * term2 * term3

def fusion_rate(n1, n2, sigma, v_rel):
    """Calculate fusion rate."""
    return n1 * n2 * sigma * v_rel

def simulate_fusion(T, n1, n2, v_rel):
    """Simulate LENR fusion event."""
    sigma = fusion_cross_section(T)
    rate = fusion_rate(n1, n2, sigma, v_rel)
    return 1 / rate, sigma

def excess_heat_generation(time, P_excess):
    """Calculate excess heat generation."""
    return np.trapz(P_excess, time)

def transmutation_model(y, t, k):
    """Transmutation pathways model."""
    return -k * y

def glow_discharge_power(I, V):
    """Calculate glow discharge power."""
    return I * V

def neutron_production_rate(sigma, rho_e, rho_p, E_e):
    """Calculate neutron production rate."""
    return hbar * sigma * rho_e * rho_p * E_e

def tsc_fusion_rate(S, G, T):
    """Calculate TSC fusion rate."""
    return S * G * T

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

# Modeling transmutation decay channels
def neutron_capture(y, t, n_density, capture_rate):
    """Modeling neutron capture and decay."""
    N, D, He, gamma_photons = y
    dNdt = -capture_rate * n_density * N
    dDdt = capture_rate * n_density * N - capture_rate * D
    dHedt = capture_rate * D
    dGammadt = capture_rate * D
    return [dNdt, dDdt, dHedt, dGammadt]

# Simulating cavitation using Rayleigh-Plesset equation
def rayleigh_plesset(t, R, P0, Pv, rho, gamma, mu, sigma):
    """Modeling bubble dynamics under sonication."""
    R, R_dot = R
    P = P0 - (2 * sigma / R) - (4 * mu * R_dot / R)
    P_bubble = Pv + (2 * sigma / R)
    R_ddot = (P - P_bubble) / (rho * R) - (3 / 2) * (R_dot ** 2 / R)
    return [R_dot, R_ddot]

# GUI Application
class LENRSimulationApp:
    def __init__(self, master):
        self.master = master
        master.title("LENRARA Python Simulation Suite")
        self.create_widgets()

    def create_widgets(self):
        # Create Notebook (Tabs)
        self.tabControl = ttk.Notebook(self.master)

        # Create tabs
        self.tab1 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab1, text='Equilibrium Pressure')

        self.tab2 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab2, text='LENR Event Simulation')

        self.tab3 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab3, text='Excess Heat Generation')

        self.tab4 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab4, text='Transmutation Calculation')

        self.tab5 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab5, text='Glow Discharge')

        self.tab6 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab6, text='Neutron Production Rate')

        self.tab7 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab7, text='TSC Fusion Rate')

        self.tab8 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab8, text='Sonication Simulation')

        self.tab9 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab9, text='Neutron Capture and Decay')

        self.tab10 = ttk.Frame(self.tabControl)
        self.tabControl.add(self.tab10, text='Bubble Dynamics')

        self.tabControl.pack(expand=1, fill="both")

        self.create_equilibrium_pressure_tab()
        self.create_lenr_event_simulation_tab()
        self.create_excess_heat_generation_tab()
        self.create_transmutation_calculation_tab()
        self.create_glow_discharge_tab()
        self.create_neutron_production_rate_tab()
        self.create_tsc_fusion_rate_tab()
        self.create_sonication_simulation_tab()
        self.create_neutron_capture_tab()
        self.create_bubble_dynamics_tab()

    def create_equilibrium_pressure_tab(self):
        # Equilibrium Pressure Tab
        frame = self.tab1

        ttk.Label(frame, text="Temperature (K):").grid(column=0, row=0, padx=5, pady=5)
        self.ep_temperature_entry = ttk.Entry(frame)
        self.ep_temperature_entry.insert(0, "300")
        self.ep_temperature_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Button(frame, text="Calculate", command=self.calculate_equilibrium_pressure).grid(column=0, row=1, padx=5, pady=5, columnspan=2)

        self.ep_result_label = ttk.Label(frame, text="Equilibrium Pressure: ")
        self.ep_result_label.grid(column=0, row=2, padx=5, pady=5, columnspan=2)

    def calculate_equilibrium_pressure(self):
        try:
            T = float(self.ep_temperature_entry.get())
            equilibrium_pressure = vant_hoff(delta_H, delta_S, T)
            self.ep_result_label.config(text=f"Equilibrium Pressure: {equilibrium_pressure:.2e} Pa")
        except ValueError:
            self.ep_result_label.config(text="Invalid input. Please enter a numeric value.")

    def create_lenr_event_simulation_tab(self):
        # LENR Event Simulation Tab
        frame = self.tab2

        ttk.Label(frame, text="Temperature (K):").grid(column=0, row=0, padx=5, pady=5)
        self.les_temperature_entry = ttk.Entry(frame)
        self.les_temperature_entry.insert(0, "300")
        self.les_temperature_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Label(frame, text="Number Density n1 (1/m³):").grid(column=0, row=1, padx=5, pady=5)
        self.les_n1_entry = ttk.Entry(frame)
        self.les_n1_entry.insert(0, "1e28")
        self.les_n1_entry.grid(column=1, row=1, padx=5, pady=5)

        ttk.Label(frame, text="Number Density n2 (1/m³):").grid(column=0, row=2, padx=5, pady=5)
        self.les_n2_entry = ttk.Entry(frame)
        self.les_n2_entry.insert(0, "1e28")
        self.les_n2_entry.grid(column=1, row=2, padx=5, pady=5)

        ttk.Label(frame, text="Relative Velocity (m/s):").grid(column=0, row=3, padx=5, pady=5)
        self.les_vrel_entry = ttk.Entry(frame)
        self.les_vrel_entry.insert(0, "1e6")
        self.les_vrel_entry.grid(column=1, row=3, padx=5, pady=5)

        ttk.Button(frame, text="Simulate", command=self.simulate_lenr_event).grid(column=0, row=4, padx=5, pady=5, columnspan=2)

        # Plot area
        self.les_fig = Figure(figsize=(6, 5), dpi=100)
        self.les_canvas = FigureCanvasTkAgg(self.les_fig, master=frame)
        self.les_canvas.get_tk_widget().grid(column=0, row=5, columnspan=2)

    def simulate_lenr_event(self):
        try:
            a = 1.0  # Lattice parameter
            n_cells = 3  # Number of unit cells along each axis
            fcc_lattice = create_fcc_lattice(a, n_cells)

            T = float(self.les_temperature_entry.get())
            n1 = float(self.les_n1_entry.get())
            n2 = float(self.les_n2_entry.get())
            v_rel = float(self.les_vrel_entry.get())

            time_to_fusion, sigma = simulate_fusion(T, n1, n2, v_rel)
            decay_positions = fcc_lattice.copy()
            decay_times = np.random.exponential(scale=time_to_fusion, size=decay_positions.shape[0])

            # Plotting
            self.les_fig.clf()
            ax = self.les_fig.add_subplot(111, projection='3d')
            ax.scatter(decay_positions[:, 0], decay_positions[:, 1], decay_positions[:, 2], c='r', s=20)
            ax.set_xlim([0, n_cells])
            ax.set_ylim([0, n_cells])
            ax.set_zlim([0, n_cells])
            ax.set_title(f'LENR Event Simulation\nTime to Fusion: {time_to_fusion:.2e} s\nFusion Cross Section: {sigma:.2e} m²')
            self.les_canvas.draw()
        except ValueError:
            tk.messagebox.showerror("Invalid input", "Please enter numeric values for all parameters.")

    def create_excess_heat_generation_tab(self):
        # Excess Heat Generation Tab
        frame = self.tab3

        ttk.Label(frame, text="Time Duration (s):").grid(column=0, row=0, padx=5, pady=5)
        self.ehg_time_entry = ttk.Entry(frame)
        self.ehg_time_entry.insert(0, "100")
        self.ehg_time_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Button(frame, text="Calculate", command=self.calculate_excess_heat_generation).grid(column=0, row=1, padx=5, pady=5, columnspan=2)

        self.ehg_result_label = ttk.Label(frame, text="Excess Heat Generated: ")
        self.ehg_result_label.grid(column=0, row=2, padx=5, pady=5, columnspan=2)

        # Plot area
        self.ehg_fig = Figure(figsize=(6, 5), dpi=100)
        self.ehg_canvas = FigureCanvasTkAgg(self.ehg_fig, master=frame)
        self.ehg_canvas.get_tk_widget().grid(column=0, row=3, columnspan=2)

    def calculate_excess_heat_generation(self):
        try:
            duration = float(self.ehg_time_entry.get())
            time = np.linspace(0, duration, 1000)
            P_excess = np.sin(time / 10) + 1  # Arbitrary excess power pattern
            Q_excess = excess_heat_generation(time, P_excess)
            self.ehg_result_label.config(text=f"Excess Heat Generated: {Q_excess:.2e} J")

            # Plotting
            self.ehg_fig.clf()
            ax = self.ehg_fig.add_subplot(111)
            ax.plot(time, P_excess)
            ax.set_xlabel('Time [s]')
            ax.set_ylabel('Excess Power [W]')
            ax.set_title('Excess Power over Time')
            self.ehg_canvas.draw()
        except ValueError:
            tk.messagebox.showerror("Invalid input", "Please enter a numeric value for time duration.")

    def create_transmutation_calculation_tab(self):
        # Transmutation Calculation Tab
        frame = self.tab4

        ttk.Label(frame, text="Time Duration (s):").grid(column=0, row=0, padx=5, pady=5)
        self.tc_time_entry = ttk.Entry(frame)
        self.tc_time_entry.insert(0, "100")
        self.tc_time_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Label(frame, text="Rate Constant k:").grid(column=0, row=1, padx=5, pady=5)
        self.tc_k_entry = ttk.Entry(frame)
        self.tc_k_entry.insert(0, "0.1")
        self.tc_k_entry.grid(column=1, row=1, padx=5, pady=5)

        ttk.Label(frame, text="Initial Concentration y0:").grid(column=0, row=2, padx=5, pady=5)
        self.tc_y0_entry = ttk.Entry(frame)
        self.tc_y0_entry.insert(0, "1e23")
        self.tc_y0_entry.grid(column=1, row=2, padx=5, pady=5)

        ttk.Button(frame, text="Calculate", command=self.calculate_transmutation).grid(column=0, row=3, padx=5, pady=5, columnspan=2)

        self.tc_result_label = ttk.Label(frame, text="Final Concentration: ")
        self.tc_result_label.grid(column=0, row=4, padx=5, pady=5, columnspan=2)

        # Plot area
        self.tc_fig = Figure(figsize=(6, 5), dpi=100)
        self.tc_canvas = FigureCanvasTkAgg(self.tc_fig, master=frame)
        self.tc_canvas.get_tk_widget().grid(column=0, row=5, columnspan=2)

    def calculate_transmutation(self):
        try:
            duration = float(self.tc_time_entry.get())
            k = float(self.tc_k_entry.get())
            y0 = float(self.tc_y0_entry.get())
            t = np.linspace(0, duration, 1000)
            transmutation_result = odeint(transmutation_model, y0, t, args=(k,))
            final_concentration = transmutation_result[-1][0]
            self.tc_result_label.config(text=f"Final Concentration: {final_concentration:.2e}")

            # Plotting
            self.tc_fig.clf()
            ax = self.tc_fig.add_subplot(111)
            ax.plot(t, transmutation_result)
            ax.set_xlabel('Time [s]')
            ax.set_ylabel('Concentration')
            ax.set_title('Transmutation over Time')
            self.tc_canvas.draw()
        except ValueError:
            tk.messagebox.showerror("Invalid input", "Please enter numeric values for all parameters.")

    def create_glow_discharge_tab(self):
        # Glow Discharge Tab
        frame = self.tab5

        ttk.Label(frame, text="Current I (A):").grid(column=0, row=0, padx=5, pady=5)
        self.gd_current_entry = ttk.Entry(frame)
        self.gd_current_entry.insert(0, "1.0")
        self.gd_current_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Label(frame, text="Voltage V (V):").grid(column=0, row=1, padx=5, pady=5)
        self.gd_voltage_entry = ttk.Entry(frame)
        self.gd_voltage_entry.insert(0, "100")
        self.gd_voltage_entry.grid(column=1, row=1, padx=5, pady=5)

        ttk.Button(frame, text="Calculate", command=self.calculate_glow_discharge).grid(column=0, row=2, padx=5, pady=5, columnspan=2)

        self.gd_result_label = ttk.Label(frame, text="Glow Discharge Power: ")
        self.gd_result_label.grid(column=0, row=3, padx=5, pady=5, columnspan=2)

    def calculate_glow_discharge(self):
        try:
            I = float(self.gd_current_entry.get())
            V = float(self.gd_voltage_entry.get())
            P_glow = glow_discharge_power(I, V)
            self.gd_result_label.config(text=f"Glow Discharge Power: {P_glow:.2e} W")
        except ValueError:
            self.gd_result_label.config(text="Invalid input. Please enter numeric values.")

    def create_neutron_production_rate_tab(self):
        # Neutron Production Rate Tab
        frame = self.tab6

        ttk.Label(frame, text="Cross-section σ (m²):").grid(column=0, row=0, padx=5, pady=5)
        self.npr_sigma_entry = ttk.Entry(frame)
        self.npr_sigma_entry.insert(0, "1e-28")
        self.npr_sigma_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Label(frame, text="Electron Density ρe (1/m³):").grid(column=0, row=1, padx=5, pady=5)
        self.npr_rhoe_entry = ttk.Entry(frame)
        self.npr_rhoe_entry.insert(0, "1e28")
        self.npr_rhoe_entry.grid(column=1, row=1, padx=5, pady=5)

        ttk.Label(frame, text="Proton Density ρp (1/m³):").grid(column=0, row=2, padx=5, pady=5)
        self.npr_rhop_entry = ttk.Entry(frame)
        self.npr_rhop_entry.insert(0, "1e28")
        self.npr_rhop_entry.grid(column=1, row=2, padx=5, pady=5)

        ttk.Label(frame, text="Electron Energy Ee (eV):").grid(column=0, row=3, padx=5, pady=5)
        self.npr_Ee_entry = ttk.Entry(frame)
        self.npr_Ee_entry.insert(0, "1e6")
        self.npr_Ee_entry.grid(column=1, row=3, padx=5, pady=5)

        ttk.Button(frame, text="Calculate", command=self.calculate_neutron_production_rate).grid(column=0, row=4, padx=5, pady=5, columnspan=2)

        self.npr_result_label = ttk.Label(frame, text="Neutron Production Rate: ")
        self.npr_result_label.grid(column=0, row=5, padx=5, pady=5, columnspan=2)

    def calculate_neutron_production_rate(self):
        try:
            sigma = float(self.npr_sigma_entry.get())
            rho_e = float(self.npr_rhoe_entry.get())
            rho_p = float(self.npr_rhop_entry.get())
            E_e = float(self.npr_Ee_entry.get())
            R_n = neutron_production_rate(sigma, rho_e, rho_p, E_e)
            self.npr_result_label.config(text=f"Neutron Production Rate: {R_n:.2e} neutrons/s")
        except ValueError:
            self.npr_result_label.config(text="Invalid input. Please enter numeric values.")

    def create_tsc_fusion_rate_tab(self):
        # TSC Fusion Rate Tab
        frame = self.tab7

        ttk.Label(frame, text="Symmetry Factor S:").grid(column=0, row=0, padx=5, pady=5)
        self.tfr_S_entry = ttk.Entry(frame)
        self.tfr_S_entry.insert(0, "1.0")
        self.tfr_S_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Label(frame, text="Gibbs Free Energy G:").grid(column=0, row=1, padx=5, pady=5)
        self.tfr_G_entry = ttk.Entry(frame)
        self.tfr_G_entry.insert(0, "1.0")
        self.tfr_G_entry.grid(column=1, row=1, padx=5, pady=5)

        ttk.Label(frame, text="Temperature T (K):").grid(column=0, row=2, padx=5, pady=5)
        self.tfr_T_entry = ttk.Entry(frame)
        self.tfr_T_entry.insert(0, "300")
        self.tfr_T_entry.grid(column=1, row=2, padx=5, pady=5)

        ttk.Button(frame, text="Calculate", command=self.calculate_tsc_fusion_rate).grid(column=0, row=3, padx=5, pady=5, columnspan=2)

        self.tfr_result_label = ttk.Label(frame, text="TSC Fusion Rate: ")
        self.tfr_result_label.grid(column=0, row=4, padx=5, pady=5, columnspan=2)

    def calculate_tsc_fusion_rate(self):
        try:
            S = float(self.tfr_S_entry.get())
            G = float(self.tfr_G_entry.get())
            T = float(self.tfr_T_entry.get())
            R_TSC = tsc_fusion_rate(S, G, T)
            self.tfr_result_label.config(text=f"TSC Fusion Rate: {R_TSC:.2e} reactions/s")
        except ValueError:
            self.tfr_result_label.config(text="Invalid input. Please enter numeric values.")

    def create_sonication_simulation_tab(self):
        # Sonication Simulation Tab
        frame = self.tab8

        ttk.Label(frame, text="Number of spatial steps nx:").grid(column=0, row=0, padx=5, pady=5)
        self.ss_nx_entry = ttk.Entry(frame)
        self.ss_nx_entry.insert(0, "200")
        self.ss_nx_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Label(frame, text="Number of time steps nt:").grid(column=0, row=1, padx=5, pady=5)
        self.ss_nt_entry = ttk.Entry(frame)
        self.ss_nt_entry.insert(0, "750")
        self.ss_nt_entry.grid(column=1, row=1, padx=5, pady=5)

        ttk.Button(frame, text="Simulate", command=self.simulate_sonication).grid(column=0, row=2, padx=5, pady=5, columnspan=2)

        # Plot area
        self.ss_fig = Figure(figsize=(6, 5), dpi=100)
        self.ss_canvas = FigureCanvasTkAgg(self.ss_fig, master=frame)
        self.ss_canvas.get_tk_widget().grid(column=0, row=3, columnspan=2)

    def simulate_sonication(self):
        try:
            nx = int(self.ss_nx_entry.get())
            nt = int(self.ss_nt_entry.get())
            dx = 0.01  # Spatial step (m)
            dt = dx / (2 * c)  # Time step (s)
            source_position = nx // 2

            p_final = sonication_simulation(nx, nt, dx, dt, source_position)
            x = np.arange(nx) * dx

            # Plotting
            self.ss_fig.clf()
            ax = self.ss_fig.add_subplot(111)
            ax.plot(x, p_final)
            ax.set_xlabel('Position [m]')
            ax.set_ylabel('Pressure')
            ax.set_title('Final Pressure Field after Sonication Simulation')
            self.ss_canvas.draw()
        except ValueError:
            tk.messagebox.showerror("Invalid input", "Please enter integer values for nx and nt.")

    def create_neutron_capture_tab(self):
        # Neutron Capture and Decay Tab
        frame = self.tab9

        ttk.Label(frame, text="Time Duration (s):").grid(column=0, row=0, padx=5, pady=5)
        self.nc_time_entry = ttk.Entry(frame)
        self.nc_time_entry.insert(0, "100")
        self.nc_time_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Label(frame, text="Neutron Density (1/m³):").grid(column=0, row=1, padx=5, pady=5)
        self.nc_density_entry = ttk.Entry(frame)
        self.nc_density_entry.insert(0, "1e28")
        self.nc_density_entry.grid(column=1, row=1, padx=5, pady=5)

        ttk.Label(frame, text="Capture Rate:").grid(column=0, row=2, padx=5, pady=5)
        self.nc_rate_entry = ttk.Entry(frame)
        self.nc_rate_entry.insert(0, "1e-3")
        self.nc_rate_entry.grid(column=1, row=2, padx=5, pady=5)

        ttk.Button(frame, text="Simulate", command=self.simulate_neutron_capture).grid(column=0, row=3, padx=5, pady=5, columnspan=2)

        # Plot area
        self.nc_fig = Figure(figsize=(6, 5), dpi=100)
        self.nc_canvas = FigureCanvasTkAgg(self.nc_fig, master=frame)
        self.nc_canvas.get_tk_widget().grid(column=0, row=4, columnspan=2)

    def simulate_neutron_capture(self):
        try:
            duration = float(self.nc_time_entry.get())
            n_density = float(self.nc_density_entry.get())
            capture_rate = float(self.nc_rate_entry.get())

            y0 = [1e23, 0, 0, 0]  # Initial concentrations
            t = np.linspace(0, duration, 1000)  # Time array

            sol = odeint(neutron_capture, y0, t, args=(n_density, capture_rate))

            # Plotting
            self.nc_fig.clf()
            ax = self.nc_fig.add_subplot(111)
            ax.plot(t, sol[:, 0], label='Neutron')
            ax.plot(t, sol[:, 1], label='Deuterium')
            ax.plot(t, sol[:, 2], label='Helium-3')
            ax.plot(t, sol[:, 3], label='Gamma photons')
            ax.set_xlabel('Time [s]')
            ax.set_ylabel('Concentration')
            ax.legend()
            ax.set_title('Neutron Capture and Decay')
            self.nc_canvas.draw()
        except ValueError:
            tk.messagebox.showerror("Invalid input", "Please enter numeric values for all parameters.")

    def create_bubble_dynamics_tab(self):
        # Bubble Dynamics Tab
        frame = self.tab10

        ttk.Label(frame, text="Time Duration (s):").grid(column=0, row=0, padx=5, pady=5)
        self.bd_time_entry = ttk.Entry(frame)
        self.bd_time_entry.insert(0, "0.01")
        self.bd_time_entry.grid(column=1, row=0, padx=5, pady=5)

        ttk.Button(frame, text="Simulate", command=self.simulate_bubble_dynamics).grid(column=0, row=1, padx=5, pady=5, columnspan=2)

        # Plot area
        self.bd_fig = Figure(figsize=(6, 5), dpi=100)
        self.bd_canvas = FigureCanvasTkAgg(self.bd_fig, master=frame)
        self.bd_canvas.get_tk_widget().grid(column=0, row=2, columnspan=2)

    def simulate_bubble_dynamics(self):
        try:
            duration = float(self.bd_time_entry.get())
            R0 = [1e-6, 0]  # Initial radius and velocity
            t_span = (0, duration)
            t_eval = np.linspace(*t_span, 1000)
            P0 = 101325  # Ambient pressure (Pa)
            Pv = 2338  # Vapor pressure of water at 20°C (Pa)
            rho = 1000  # Density of water (kg/m^3)
            gamma = 1.4  # Polytropic index
            mu = 0.001  # Viscosity of water (Pa·s)
            sigma = 0.0728  # Surface tension of water (N/m)

            sol = solve_ivp(rayleigh_plesset, t_span, R0, args=(P0, Pv, rho, gamma, mu, sigma), t_eval=t_eval)

            # Plotting
            self.bd_fig.clf()
            ax = self.bd_fig.add_subplot(111)
            ax.plot(sol.t, sol.y[0])
            ax.set_xlabel('Time [s]')
            ax.set_ylabel('Bubble Radius [m]')
            ax.set_title('Bubble Dynamics under Sonication')
            self.bd_canvas.draw()
        except ValueError:
            tk.messagebox.showerror("Invalid input", "Please enter a valid numeric value for time duration.")

def main():
    root = tk.Tk()
    app = LENRSimulationApp(root)
    root.mainloop()

if __name__ == "__main__":
    main()
 why does the simulations doesnot show time evolutions ,remove unwanted incorrect code blocks