/
dashytka
/
QuantumFluxSimulator
Обзор
Документация
Войти
/
dashytka
/
QuantumFluxSimulator
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
python
87 строк
3 KB
dashytka
create python
23 окт 2025, 21:18
23 окт 2025, 21:18
bbe8f0d
Код
Авторство
О чём код?
# QuantumFluxSimulator.py """ Quantum Flux Simulator - Models quantum particle behavior in magnetic fields Simulates electron wave function propagation through varying potential barriers """ import numpy as np import matplotlib.pyplot as plt from scipy import linalg class QuantumFluxSimulator: def __init__(self, grid_size=1000, dt=0.001): self.grid_size = grid_size self.dt = dt self.x = np.linspace(-10, 10, grid_size) self.dx = self.x[1] - self.x[0] self.psi = None self.V = None def gaussian_wave_packet(self, x0=0, k0=5, sigma=1): """Initialize Gaussian wave packet""" self.psi = np.exp(-(self.x - x0)**2 / (2 * sigma**2)) * np.exp(1j * k0 * self.x) self.psi = self.psi / np.sqrt(np.sum(np.abs(self.psi)**2) * self.dx) def harmonic_potential(self, k=0.5): """Set harmonic oscillator potential""" self.V = 0.5 * k * self.x**2 def rectangular_barrier(self, center=0, width=2, height=10): """Set rectangular potential barrier""" self.V = np.zeros_like(self.x) self.V[(self.x > center - width/2) & (self.x < center + width/2)] = height def time_step(self): """Perform single time step using Crank-Nicolson method""" # Construct Hamiltonian matrices diag = 2 + 2j * self.dt / self.dx**2 + 1j * self.dt * self.V off_diag = -1j * self.dt / self.dx**2 * np.ones(self.grid_size - 1) A = np.diag(diag) + np.diag(off_diag, 1) + np.diag(off_diag, -1) B = np.conj(A) - 4j * np.diag(np.ones(self.grid_size)) # Solve linear system self.psi = linalg.solve(A, B.dot(self.psi)) def simulate(self, steps=1000): """Run full simulation""" probabilities = [] for step in range(steps): self.time_step() prob = np.abs(self.psi)**2 probabilities.append(prob.copy()) if step % 100 == 0: print(f"Step {step}/{steps}") return np.array(probabilities) def visualize(self, probabilities): """Create animation of wave function evolution""" fig, ax = plt.subplots(figsize=(12, 6)) for i in range(0, len(probabilities), 50): ax.clear() ax.plot(self.x, probabilities[i], 'b-', label='|ψ|²', linewidth=2) if self.V is not None: ax.plot(self.x, self.V / np.max(self.V) * np.max(probabilities[i]), 'r--', label='Potential', alpha=0.7) ax.set_ylim(0, np.max(probabilities) * 1.1) ax.set_xlabel('Position') ax.set_ylabel('Probability Density') ax.legend() ax.set_title(f'Quantum Wave Propagation - Step {i}') plt.pause(0.01) plt.show() # Example usage if __name__ == "__main__": simulator = QuantumFluxSimulator() simulator.gaussian_wave_packet(x0=-5, k0=2, sigma=0.5) simulator.rectangular_barrier(center=0, width=1, height=15) probabilities = simulator.simulate(steps=500) simulator.visualize(probabilities)