def plot_physical_evolution(function_evolution, x, t, dW, storedTime, N, L):
    vf.is_vector(x)
    # vf.is_matrix(function_evolution) # function_evolution is not a numpy matrix
    fig = plt.figure()
    ax = fig.add_subplot(111)
    plotVal = function_evolution[0, :]
    axis_ceil = 1.1 * np.max(np.abs(plotVal))
    line = ax.plot(x, np.real(plotVal), 'b', x, np.imag(plotVal), 'r', x,
                   np.abs(plotVal), 'y')

    W = np.cumsum(sum(dW))
    W = np.insert(W, 0, 0)
    for i in range(storedTime):
        index = int((i + 1) * N / storedTime)
        t_val = t[index]
        W_val = W[index]

        plotVal = function_evolution[i + 1, :]
        line[0].set_ydata(np.real(plotVal))
        line[1].set_ydata(np.imag(plotVal))
        line[2].set_ydata(np.abs(plotVal))
        plt.legend(line, ['real(u)', 'imag(u)', 'abs(u)'])
        #plt.plot(x, np.real(plotVal),'b', x, np.imag(plotVal),'r', x, np.abs(plotVal), 'y')
        plt.axis([-L, L, -axis_ceil, axis_ceil])
        plt.suptitle('t = {:1.4f}, W_t = {:4.4f}'.format(
            t_val, W_val))  #,fontsize=20)
        #plt.draw()
        fig.canvas.draw()
        fig.canvas.flush_events()
        plt.pause(np.spacing(1))

    plt.show()
def plot_norm_evolution(norm_evolution, stored_t, axis_args, norm_string,
                        save_title):
    vf.is_vector(norm_evolution)
    # vf.is_matrix(function_evolution) # function_evolution is not a numpy matrix
    fig = plt.figure(figsize=(15, 15))
    plt.plot(stored_t, np.real(norm_evolution))
    plt.axis(axis_args)
    plt.xlabel('t')
    plt.ylabel(norm_string)
    #plt.show()
    plt.savefig(save_title)
    return fig
Esempio n. 3
0
def FD_N_star_solver(currU,firstHalfdW,FDMatSq,h,sigma):
	vf.is_vector(currU)
	# Initialize loop variables
	crit = True
	i = 1
	NStar = currU
	# Calculate some values which don't change
	a = linalg.expm(1j*firstHalfdW*FDMatSq).dot(currU)
	
	while crit and i < 120:
		oldNStar = NStar
		tempNStar = a+h/2*NStar
		NStar = cubicU(tempNStar,sigma)
		crit = linalg.norm(oldNStar-NStar) > np.spacing(1);
		i = i+1;
	return NStar
Esempio n. 4
0
def FDEulTypeSolver(currU,dW,FDMatSq,h,sigma,G):
	vf.is_vector(currU)
	# Initialize loop variables
	crit = True;
	i = 1;
	nextU = currU;
	# Calculate some values which don't change
	A = sparse.eye(len(currU)) + 1j*dW/2*FDMatSq
	B = sparse.eye(len(currU)) - 1j*dW/2*FDMatSq
	AcurrU = A.dot(currU)

	while (crit and i < 120):
		tempU = nextU;
		nextU = spla.spsolve(B,AcurrU + 1j*h*G(currU,nextU,sigma))
		crit = linalg.norm(tempU-nextU) > np.spacing(1);
		i = i+1;
	return nextU
Esempio n. 5
0
def PS_N_star_solver(currU,firstHalfdW,kSq,h,sigma):
	vf.is_vector(currU)
	# Initialize loop variables
	crit = True
	i = 1
	NStar = currU
	# Calculate some values which don't change
	a = np.multiply(
		np.exp(-firstHalfdW*1j*kSq),
		currU)
		
	while crit and i < 120:
		oldNStar = NStar
		tempNStar = a + h/2*NStar
		NStar = fft(1j*cubicU(ifft(tempNStar),sigma))
		crit = linalg.norm(oldNStar-NStar) > np.spacing(1);
		i = i+1;
	return NStar
Esempio n. 6
0
def pseudospectral_simulation(N,h,kSq,sigma,u0,W,scheme,queries):
	vf.is_vector(u0)
	vf.is_vector(kSq)
	# Need to preallocate memory for query results
	currU = u0
	queryStorage = []
	queryIndex = []
	for q in range(len(queries)):
		queryStorage.append(queries[q].preallocateQueryResult())
		queryStorage[q][0,:] = queries[q].function(currU)
		queryIndex.append(1)
	
	for i in range(N):
		dW = W[:,i]
		# dW = np.random.randn(2,1)*(h/2)
		currU = scheme(currU,dW,kSq,h,sigma)
		for q in range(len(queries)):
			if (i % queries[q].periodicity) == (queries[q].periodicity - 1):
				queryStorage[q][queryIndex[q],:] = queries[q].function(currU)
				queryIndex[q] += 1
			
	return queryStorage
Esempio n. 7
0
def PSEulTypeSolver(currU,dW,kSq,h,sigma,G):
	vf.is_vector(currU)
	# Initialize loop variables
	crit = True;
	i = 1;
	nextU = currU;
	realSpaceCurrU = ifft(currU);
	realSpaceNextU = realSpaceCurrU;
	# Calculate some values which don't change
	a = np.multiply(
		np.divide(1 - 1j*dW/2*kSq,
			1 + 1j*dW/2*kSq),
		currU)
	b = 1j*h/(1 + 1j*dW/2*kSq);

	while (crit and i < 120):
		tempU = nextU;
		nextU = a + np.multiply(b,fft(G(realSpaceCurrU,realSpaceNextU,sigma)));
		realSpaceNextU=ifft(nextU);
		crit = linalg.norm(tempU-nextU) > np.spacing(1);
		i = i+1;
	return nextU
Esempio n. 8
0
def finite_difference_simulation(N,h,FDMatSq,sigma,u0,W,scheme,queries):
	vf.is_vector(u0)
	# Need to preallocate memory for query results
	currU = u0
	queryStorage = []
	queryIndex = []
	for q in range(len(queries)):
		queryStorage.append(queries[q].preallocateQueryResult())
		queryStorage[q][0,:] = queries[q].function(currU)
		queryIndex.append(1)
	
	for i in range(N):
		dW = W[:,i]
		# dW = np.random.randn(2,1)*(h/2)
		currU = scheme(currU,dW,FDMatSq,h,sigma)
		for q in range(len(queries)):
			if (i % queries[q].periodicity) == (queries[q].periodicity - 1):
				#print(currU)
				#print(type(currU))
				#print(q)
				queryStorage[q][queryIndex[q],:] = queries[q].function(currU)
				queryIndex[q] += 1
			
	return queryStorage
def H1_norm(u, dx):
    vf.is_vector(u)
    deriv_val = (u[1:] - u[:-1]) / dx
    return L2_norm(u, dx) + L2_norm(np.append(deriv_val, deriv_val[-1]), dx)
def L2_norm(u, dx):
    vf.is_vector(u)
    int_val = np.power(np.abs(u), 2)
    return trapezoidal_integral(int_val, dx)
def trapezoidal_integral(u, dx):
    vf.is_vector(u)
    return dx / 2 * np.sum(u[:-1] + u[1:])
Esempio n. 12
0
def cubicU(currU,sigma):
	vf.is_vector(currU)
	return np.multiply(np.power(np.absolute(currU),2*sigma),currU)