def plot(self, G, phi, grad, color): matrices = m.Matrices() fig = plt.figure() ax1 = fig.add_subplot(2, 2, 1) ax2 = fig.add_subplot(2, 2, 2) ax3 = fig.add_subplot(2, 2, 3) ax4 = fig.add_subplot(2, 2, 4) ax_list = [ax1, ax2, ax3, ax4] for i in ax_list: i.xaxis.tick_top() # i.axis('off') i.imshow(matrices.G, cmap='coolwarm') self.build_walls(i, G) self.plot_contour(ax1, phi, color) ax2.quiver(grad[1], grad[0]) ax3.streamplot(np.linspace(0, Nx * h - 1, Nx * h), np.linspace(0, Ny * h - 1, Ny * h), grad[1], grad[0], linewidth=.75, arrowsize=.75) self.plot_contour(ax4, matrices.pressure, color) # Saving the figure # figname = "../figures/{}_x={}_y={}_h={}.pdf".format(geometry, # Nx, Ny, h) figname = "../figures/{}_x={}_y={}.pdf".format(geometry, Nx, Ny) plt.savefig(figname)
def __init__(self, pot, pars): self.generic_initialization(pot, pars) self.p_dist = pars['p_dist'] self.mat = matrices.Matrices(self.tau, self.gamma, self.p_dist, self.N, periodic=pars['periodic']) self.ou_phys = scipy.sqrt(self.sigma* 4*self.gamma*self.upsilon_linear_nonlocal/(self.beta*self.tau)) self.rhs_matrix = scipy.sparse.identity(self.N) + .5*self.mat.A*self.upsilon_linear_nonlocal self.lhs_matrix = scipy.sparse.identity(self.N) - .5*self.mat.A*self.upsilon_linear_nonlocal
def temp(self, G): matrices = m.Matrices() fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax1.imshow(matrices.G, cmap='coolwarm', interpolation='bilinear') X = np.linspace(0, Nx * h, Nx * h + 1) Y = np.linspace(0, Ny * h, Ny * h + 1) XX, YY = np.meshgrid(X, Y) # ax1.plot(XX - .5, YY - .5, color='black') # ax1.plot(YY - .5, XX - .5, color='black') figname = "../figures/{}_x={}_y={}.pdf".format(geometry, Nx, Ny) plt.savefig(figname)
def domain_check(): matrix = matrices.Matrices() if matrix.M.max() + 1 > 5000: print("You started the program with a rather big domain (more than" " 5000 fluid cells).\nThe computation can take some time," " are you sure want to continue (Yes/No) ?") answer = input("\n> ") if answer == "Yes" or answer == "yes": pass elif answer == "No" or answer == "no": sys.exit("\nOperation cancelled") else: sys.exit("\nInvalid input, operation cancelled")
upsilon_nonlinear_nonlocal = 0. upsilon_nonlinear_local = 0. if not (Strang_order == 0).sum() == 0: upsilon_linear_nonlocal = upsilon / (Strang_order == 0).sum() if not (Strang_order == 1).sum() == 0: upsilon_nonlinear_nonlocal = upsilon / (Strang_order == 1).sum() if not (Strang_order == 2).sum() == 0: upsilon_nonlinear_local = upsilon / (Strang_order == 2).sum() upsilons = (upsilon_linear_nonlocal, upsilon_nonlinear_nonlocal, upsilon_nonlinear_local) pot = potential.Potential() mat = matrices.Matrices(tau, beta, gamma, p_dist, N, upsilon, compute_expm=True) print # for the DST: (!) # d2 = -(scipy.arange(N-1)+1)**2*(scipy.pi/T)**2 # # d4 = (scipy.arange(N-1)+1)**4*(scipy.pi/T)**4 # d4 = d2**2 # for the (R)FFT: d2_complex = -(2 * scipy.pi / T * scipy.arange(N / 2 + 1))**2 d2 = scipy.zeros((N, )) print d2.shape d2[0::2] = d2_complex[:-1]
#!/usr/bin/env python3 # Main program import time from parameters import recompute import matrices import plot import data_check t_init = time.time() data_check.data_check() matrices = matrices.Matrices() if recompute or data_check.existing_data(): data_check.domain_check() print('\nComputing new data...') matrices.make_data() else: print('Running the program using existing data\n') data = matrices.load_data() plot = plot.Plot() plot.plot_graphs("potential", data) plot.plot_graphs("velocity", data) plot.plot_graphs("streamlines", data) plot.plot_graphs("pressure", data) t_end = time.time() print("\nProgram executed in {:.3f} seconds."
#!/usr/bin/env python3 # Main program import numpy as np import matrices as m import plot as p import data_check as dc dc.data_check() # Builds the different objects needed matrices = m.Matrices() buildplots = p.BuildPlots() buildplots.temp(matrices.G) # buildplots.plot(matrices.G, matrices.phi_neumann, matrices.grad, 'green')
pars['N'] = 100 # number of time steps beta = pars['beta'] gamma = pars['gamma'] upsilon = pars['upsilon'] N = pars['N'] T = pars['T'] p_dist = pars['p_dist'] tau = T / N for periodic in (True, False): mat = matrices.Matrices(tau, beta, gamma, p_dist, N, upsilon, periodic=periodic) print mat.A.toarray()[:5, :5] print mat.A.toarray()[-5:, -5:] try: assert (abs(mat.A.toarray()[:, :] - mat.A.toarray()[-1::-1, -1::-1]) < 1.e-10).all() except AssertionError: print "Matrix A not symmetric" print mat.A.toarray()[:, :] - mat.A.toarray()[-1::-1, -1::-1] print mat.B.toarray()[:5, :5]