Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中调制不稳定性的模拟_Python_Numpy_Matplotlib_Physics_Differential Equations - Fatal编程技术网

Python中调制不稳定性的模拟

Python中调制不稳定性的模拟,python,numpy,matplotlib,physics,differential-equations,Python,Numpy,Matplotlib,Physics,Differential Equations,我试图展示一维非线性薛定谔方程中的调制不稳定性()。以下代码根据由常数加上小扰动组成的初始波函数,为波函数的密度剖面和相位剖面生成数值解(使用分步傅里叶方法) 代码: 因此,对于α=β=1,ε=0.0001,m=2,并且假设初始振幅(rho)为4或更大,我应该看到基于色散关系的调制不稳定性: \ω=+/-sqrt(β)*mod(k)*sqrt(β*mod(k)^2-2*alpha+rho) 对于复杂的欧米茄,应发生不稳定性 k=2*m*pi/lx(参见lx代码) 我需要使用更小的时间步长吗?我已

我试图展示一维非线性薛定谔方程中的调制不稳定性()。以下代码根据由常数加上小扰动组成的初始波函数,为波函数的密度剖面和相位剖面生成数值解(使用分步傅里叶方法)

代码:

因此,对于α=β=1,ε=0.0001,m=2,并且假设初始振幅(rho)为4或更大,我应该看到基于色散关系的调制不稳定性:

\ω=+/-sqrt(β)*mod(k)*sqrt(β*mod(k)^2-2*alpha+rho)

对于复杂的欧米茄,应发生不稳定性

k=2*m*pi/lx(参见lx代码)

我需要使用更小的时间步长吗?我已经制作了500多张图片,但仍然没有看到不稳定的情况

我的朋友建议计算每个时间步的波函数的最大值和最小值,然后根据时间进行绘图,但我也不知道如何做到这一点

The equation in question takes the form

i * psi_t + beta * psi_xx + alpha * |psi|^2 psi = 0.

Essentially, spectral and pseudospectral methods work by splitting a PDE into linear and nonlinear parts. These
components are numerically solved individually under an iterative process, after which the results are combined. We
will use the pseudospectral method called the split-step Fourier method.
'''

# Computation and Plotting modules

import numpy as np
import matplotlib.pyplot as plt
import random

# File modules
import os



N = 10000

# Coefficients

#print("Example values might be -1, 0 or 1.")
alpha = float(input("Choose a suitable value for the nonlinear coefficient: "))
beta = float(input("Choose a suitable value for the linear coefficient: "))


# First we need to establish the time and space steps.

nx = 256 # Number of uniform points on spatial axis
lx = 100 # Spatial axis domain length
dx = lx / nx # Space step
x = np.linspace(0, lx, num=nx, endpoint=False)


StepStart = 0     # First step
StepStop = 10000  # Final step
t = np.linspace(StepStart, StepStop, 256)
dt = 1.e-10       # Integration time step

psisave = 500 # save the plot at 500th step
#timeframes = np.linspace(0, 4 * np.pi, 1000)


# Plots Directory

dirPlots = './Solution Plots'

if not os.path.exists(dirPlots):
    os.makedirs(dirPlots)

print('Plots file created. ')

# Fourier space details

dk = 2 * np.pi / lx
k = np.fft.ifftshift(dk * np.arange(-nx/2, nx/2)) # FFT - Fast Fourier Transform
ksquare = np.square(k * x)

'''
Consider a stability check. We compare the integration time-step dt with the fastest linear period: the 
wave with the maximal phase and therefore highest frequency. Since we want to trace out the solution, dt should 
be smaller.
'''

MaxLinFreq = np.abs(beta) * np.max(ksquare)
FastestLinPeriod = 2 * np.pi / MaxLinFreq

if (dt > FastestLinPeriod):
    print('Numerical instability detected. To achieve a stable result, choose a smaller dt.')


# Set the initial condition (initial wave function)
# Consider a constant initial wave function subjected to a minor perturbation.
gamma = np.random.rand((256))
gammanoise = 0.0000001 * gamma
A = float(input("Give an amplitude for the initial wave function: "))
eps = float(input("Choose a perturbation coefficient. Make it small!: "))
m = int(input("Choose an INTEGER. This ensures the perturbation is periodic on the boundaries: "))
k2 = float(2 * np.pi * m / lx)
psi_0 = A + gammanoise + eps * np.exp(1j * k2 * x)
psi = psi_0

framestep = StepStart
PsiStep = 1000 #

# Iterative formula  (integration loop)

LinearPart = np.exp(-1j * beta * k * dt) # Linear component of numerical solution

step = StepStart
if np.mod(step, psisave) == 0:
    # Density profile
    filename = '%s/densityprofile%05d.png' % (dirPlots, step / psisave)
    plt.plot(x, np.square(np.abs(psi)))
    plt.xlabel('x')
    plt.ylabel('$|\psi|^2$', rotation=0)
    #plt.ylim([0, 1.2])
    plt.savefig(filename)
    plt.close('all')

    # Phase profile
    filename = '%s/phaseprofile%05d.png' % (dirPlots, step / psisave)
    fig = plt.figure()
    plt.plot(x, np.angle(psi))
    plt.xlabel('x')
    plt.ylabel('$arg(\psi)$', rotation=0)
    plt.savefig(filename)
    plt.close('all')

for step in range(StepStart +1, StepStop + 1):
    psi = psi * np.exp(1j * alpha * dt * np.abs(psi)**2) # Nonlinear component
    psi = np.fft.fft(psi)                                # Map to Fourier space
    psi = psi * LinearPart                               # Multiply by linear component
    psi = np.fft.ifft(psi)                               # Invert FFT back to physical space


# Now we computed the solutions, we can plot the density and phase profiles at different stages.

    if np.mod(step, psisave) == 0:                       # Save density and phase plots
        # Density profile
        filename = '%s/densityprofile%05d.png' % (dirPlots, step / psisave)
        plt.plot(x, np.square(np.abs(psi)))
        plt.xlabel('x')
        plt.ylabel('$|\psi|^2$', rotation=0)
        #plt.ylim([-10, 10])
        plt.savefig(filename)
        plt.close('all')

        # Phase profile
        filename = '%s/phaseprofile%05d.png' % (dirPlots, step / psisave)
        fig = plt.figure()
        plt.plot(x, np.angle(psi))
        plt.xlabel('x')
        plt.ylabel('$arg(\psi)$', rotation=0)
        plt.savefig(filename)
        plt.close('all')

       



print('Numerical solution computed!')
print('Density profile solution frames saved!')
print('Phase profile solution frames saved!')