정보통신기술(ICT)

파이썬-기반 GUI 볼텍스 형상화(Python-based GUI Vortex Visualization)

해머슴 2024. 11. 11. 10:41
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import tkinter as tk

# Vortex simulation function using Ginzburg-Landau parameters
def generate_vortex_pattern(B, xi, lambda_, grid_size=100):
    x = np.linspace(-grid_size / 2, grid_size / 2, grid_size)
    y = np.linspace(-grid_size / 2, grid_size / 2, grid_size)
    X, Y = np.meshgrid(x, y)
   
    # Distance from the origin
    R = np.sqrt(X**2 + Y**2)
   
    # Simplified vortex model
    psi = np.exp(-R / lambda_) * np.sin(2 * np.pi * R / xi)
   
    # Magnetic field intensity
    B_field = B * np.exp(-R / lambda_)
   
    return psi, B_field

# Function to update the plot based on user inputs
def update_plot():
    B = float(entry_B.get())
    xi = float(entry_xi.get())
    lambda_ = float(entry_lambda.get())
   
    # Generate vortex patterns
    psi, B_field = generate_vortex_pattern(B, xi, lambda_)
   
    # Clear and update plot
    ax.clear()
    ax.set_title("Vortex Pattern in Type-II Superconductor")
    vortex = ax.imshow(psi, cmap='viridis', extent=(-50, 50, -50, 50))
    fig.colorbar(vortex, ax=ax, label="Order Parameter |ψ|")
    canvas.draw()

# Setup GUI window using Tkinter
root = tk.Tk()
root.title("Ginzburg-Landau Vortex Simulation")

# Create input fields for parameters
tk.Label(root, text="Magnetic Field (B)").grid(row=0, column=0)
entry_B = tk.Entry(root)
entry_B.grid(row=0, column=1)
entry_B.insert(0, "1.0")

tk.Label(root, text="Coherence Length (ξ)").grid(row=1, column=0)
entry_xi = tk.Entry(root)
entry_xi.grid(row=1, column=1)
entry_xi.insert(0, "5.0")

tk.Label(root, text="Penetration Depth (λ)").grid(row=2, column=0)
entry_lambda = tk.Entry(root)
entry_lambda.grid(row=2, column=1)
entry_lambda.insert(0, "10.0")

# Create plot area for vortex pattern
fig, ax = plt.subplots(figsize=(5, 5))
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.get_tk_widget().grid(row=3, column=0, columnspan=2)

# Add button to update plot based on parameters
tk.Button(root, text="Generate Vortex Pattern", command=update_plot).grid(row=4, column=0, columnspan=2)

# Run the GUI application
root.mainloop()