def test_non_constant(Nx, sparse, ordinal): x = de.Chebyshev('x', Nx, interval=(0, 5)) d = de.Domain([ x, ]) prob = de.EVP(d, ['y', 'yx', 'yxx', 'yxxx'], 'sigma') prob.add_equation( "dx(yxxx) -0.02*x*x*yxx -0.04*x*yx + (0.0001*x*x*x*x - 0.02)*y - sigma*y = 0" ) prob.add_equation("dx(yxx) - yxxx = 0") prob.add_equation("dx(yx) - yxx = 0") prob.add_equation("dx(y) - yx = 0") prob.add_bc("left(y) = 0") prob.add_bc("right(y) = 0") prob.add_bc("left(yx) = 0") prob.add_bc("right(yx) = 0") EP = Eigenproblem(prob, use_ordinal=ordinal) EP.solve(sparse=sparse) indx = EP.evalues_good.argsort() five_evals = EP.evalues_good[indx][0:5] print("First five good eigenvalues are: ") print(five_evals) print(five_evals[-1]) reference = np.array([ 0.86690250239956 + 0j, 6.35768644786998 + 0j, 23.99274694653769 + 0j, 64.97869559403952 + 0j, 144.2841396045761 + 0j ]) assert np.allclose(reference, five_evals, rtol=1e-4)
orr_somerfeld.parameters['Re'] = 10000. orr_somerfeld.add_equation( 'dz(wzzz) - 2*alpha**2*wzz + alpha**4*w - sigma*(wzz-alpha**2*w)-1j*alpha*(Re*(1-z**2)*(wzz-alpha**2*w) + 2*Re*w) = 0 ' ) orr_somerfeld.add_equation('dz(w)-wz = 0') orr_somerfeld.add_equation('dz(wz)-wzz = 0') orr_somerfeld.add_equation('dz(wzz)-wzzz = 0') orr_somerfeld.add_bc('left(w) = 0') orr_somerfeld.add_bc('right(w) = 0') orr_somerfeld.add_bc('left(wz) = 0') orr_somerfeld.add_bc('right(wz) = 0') # create an Eigenproblem object EP = Eigenproblem(orr_somerfeld, sparse=True) # create a shim function to translate (x, y) to the parameters for the eigenvalue problem: def shim(x, y): gr, indx, freq = EP.growth_rate({"Re": x, "alpha": y}) ret = gr + 1j * freq if type(ret) == np.ndarray: return ret[0] else: return ret cf = CriticalFinder(shim, comm)
widegap.add_equation("dr(A) - Ar = 0") widegap.add_equation("dr(B) - Br = 0") widegap.add_bc('left(u) = 0') widegap.add_bc('right(u) = 0') widegap.add_bc('left(psi) = 0') widegap.add_bc('right(psi) = 0') widegap.add_bc('left(A) = 0') widegap.add_bc('right(A) = 0') widegap.add_bc('left(psir) = 0') widegap.add_bc('right(psir) = 0') widegap.add_bc('left(B + r*Br) = 0') widegap.add_bc('right(B + r*Br) = 0') # axial component of current = 0 # create an Eigenproblem object EP = Eigenproblem(widegap) # create a shim function to translate (x, y) to the parameters for the eigenvalue problem: def shim(x,y): gr, indx, freq = EP.growth_rate({"Rm":x,"k":y}) val = gr + 1j*freq if type(val) == np.ndarray: return val[0] else: return val cf = CriticalFinder(shim, comm) # generating the grid is the longest part start = time.time() gridl = 10
def linearStabilityAnalysisPar(f, tht, kappa, Pr, U, Uz, V, Vz, B, Bz, nz, H, l, k, domain): # Need to decide whether input variables are in rotated frame or not. import sys import numpy as np import pdb from mpi4py import MPI from eigentools import Eigenproblem, CriticalFinder # import matplotlib.pyplot as plt # from pylab import * # import scipy.integrate as integrate from dedalus import public as de # import logging # logger = logging.getLogger(__name__) # LOAD IN PARAMETERS #f = parameters, tht, kappa, Pr, U, Uz, V, Vz, B, Bz, nz, H, ll, domain) # f, tht, kappa, Pr, U, Uz, V, Vz, B, Bz, nz, H, ll, domain): # pdb.set_trace() # f = args[0] # tht = args[1] # kappa = args[2] # Pr = args[3] # U = args[4] # Uz = args[5] # V = args[6] # Vz = args[7] # B = args[8] # Bz = args[9] # nz = args[10] # H = args[11] # ll = args[12] ## domain = args[13] # z_basis = de.Chebyshev('z', nz, interval=(0, H)) # domain = de.Domain([z_basis], np.complex128) # non-constant coefficients # kap = domain.new_field(name='kap') # z = domain.grid(0) # kap['g'] = kapi # SETUP LINEAR STABILITY ANALYSIS problem = de.EVP( domain, variables=['u', 'v', 'w', 'b', 'p', 'uz', 'vz', 'wz', 'bz'], eigenvalue='omg', tolerance=1e-3) problem.parameters['U'] = U problem.parameters['V'] = V problem.parameters['B'] = B problem.parameters['Uz'] = Uz problem.parameters['Vz'] = Vz problem.parameters['Bz'] = Bz problem.parameters['f'] = f problem.parameters['tht'] = tht problem.parameters['kap'] = kappa problem.parameters['Pr'] = Pr problem.parameters['k'] = 0. # will be set in loop problem.parameters['l'] = 0. # will be set in loop problem.substitutions['dx(A)'] = "1j*k*A" problem.substitutions['dy(A)'] = "1j*l*A" problem.substitutions['dt(A)'] = "-1j*omg*A" problem.add_equation( ('dt(u) + U*dx(u) + V*dy(u) + w*Uz - f*v*cos(tht) + dx(p)' '- b*sin(tht) - Pr*(kap*dx(dx(u)) + kap*dy(dy(u)) + dz(kap)*uz' '+ kap*dz(uz)) = 0')) problem.add_equation( ('dt(v) + U*dx(v) + V*dy(v) + w*Vz + f*u*cos(tht)' '- f*w*sin(tht) + dy(p) - Pr*(kap*dx(dx(v)) + kap*dy(dy(v))' '+ dz(kap)*vz + kap*dz(vz)) = 0')) # problem.add_equation(('dt(w) + U*dx(w) + V*dy(w) + f*v*sin(tht) + dz(p)' # '- b*cos(tht) - Pr*(kap*dx(dx(w)) + kap*dy(dy(w)) + dz(kap)*wz' # '+ kap*dz(wz)) = 0')) problem.add_equation( '0*(dt(w) + U*dx(w) + V*dy(w)) + f*v*sin(tht) + dz(p)' '- b*cos(tht) - Pr*(kap*dx(dx(w)) + kap*dy(dy(w)) + dz(kap)*wz' '+ kap*dz(wz)) = 0') # problem.add_equation(('dt(b) + U*dx(b) + V*dy(b) + u*N**2*sin(tht)' # '+ w*(N**2*cos(tht) + Bz) - kap*dx(dx(b)) - kap*dy(dy(b)) - dz(kap)*bz' # '- kap*dz(bz) = 0')) problem.add_equation( ('dt(b) + U*dx(b) + V*dy(b) + u*Vz*f' '+ w*(Bz) - kap*dx(dx(b)) - kap*dy(dy(b)) - dz(kap)*bz' '- kap*dz(bz) = 0')) problem.add_equation('dx(u) + dy(v) + wz = 0') problem.add_equation('uz - dz(u) = 0') problem.add_equation('vz - dz(v) = 0') problem.add_equation('wz - dz(w) = 0') problem.add_equation('bz - dz(b) = 0') problem.add_bc('left(u) = 0') problem.add_bc('left(v) = 0') problem.add_bc('left(w) = 0') problem.add_bc('left(bz) = 0') problem.add_bc('right(uz) = 0') problem.add_bc('right(vz) = 0') problem.add_bc('right(w) = 0') problem.add_bc('right(bz) = 0') problem.namespace['k'].value = k problem.namespace['l'].value = l # solve problem EP = Eigenproblem(problem) (gr, idx, freq) = EP.growth_rate({}) # print(str(np.max(idx))) # print(str(idx[-1])) # if idx[-1]>nz: # grt = 0 gr = np.array([gr]) # #get full eigenvectors and eigenvalues for l with largest growth ## idx = sorted_eigen(0., ll[np.argmax(gr)]) # solver.set_state(idx[-1]) # # # collect eigenvector # u = solver.state['u'] # v = solver.state['v'] # w = solver.state['w'] # b = solver.state['b'] # shear production # SP = -2*np.real(np.conj(w['g'])*(u['g']*Uz['g']+v['g']*Vz['g'])) # # # buoyancy production # BP = 2*np.real((u['g']*np.sin(tht)+w['g']*np.cos(tht))*np.conj(b['g'])) return (gr, 0, 0, 0, 0)
#waves.add_bc('right(epsilon0*Q*vdz0/(1+epsilon0) + epsilon0*Udz + Ugz)=0') if diffusion == True: waves.add_bc('right(Q)=0') if viscosity_pert == True: waves.add_bc('left(Ugx_p)=0') waves.add_bc('left(Ugy_p)=0') waves.add_bc('right(Ugx_p)=0') waves.add_bc('right(Ugy_p)=0') ''' eigenvalue problem, sweep through kx space for each kx, filter modes and keep most unstable one ''' EP_list = [Eigenproblem(waves), Eigenproblem(waves, sparse=True)] kx_space = np.logspace(np.log10(kx_min),np.log10(kx_max), num=nkx) eigenfreq = [] eigenfunc = {'W':[], 'Q':[], 'Ugx':[], 'Ugy':[], 'Ugz':[], 'Udx':[], 'Udy':[], 'Udz':[]} for i, kx in enumerate(kx_space): if ((i == 0) and (first_solve_dense == True)) or all_solve_dense == True: EP = EP_list[0] else: EP = EP_list[1] EP.EVP.namespace['kx'].value = kx EP.EVP.parameters['kx'] = kx
mri.add_equation( "sigma*u - iR*dx(ux) + iR*Q**2*u - (q - 2)*1j*Q*psi - (2/beta)*1j*Q*B = 0") mri.add_equation("sigma*A - iRm*dx(Ax) + iRm*Q**2*A - 1j*Q*psi = 0") mri.add_equation("sigma*B - iRm*dx(Bx) + iRm*Q**2*B - 1j*Q*u + q*1j*Q*A = 0") mri.add_equation("dx(psi) - psix = 0") mri.add_equation("dx(psix) - psixx = 0") mri.add_equation("dx(psixx) - psixxx = 0") mri.add_equation("dx(u) - ux = 0") mri.add_equation("dx(A) - Ax = 0") mri.add_equation("dx(B) - Bx = 0") mri.add_bc("left(u) = 0") mri.add_bc("right(u) = 0") mri.add_bc("left(psi) = 0") mri.add_bc("right(psi) = 0") mri.add_bc("left(A) = 0") mri.add_bc("right(A) = 0") mri.add_bc("left(psix) = 0") mri.add_bc("right(psix) = 0") mri.add_bc("left(Bx) = 0") mri.add_bc("right(Bx) = 0") # create an Eigenproblem object EP = Eigenproblem(mri, sparse=True) gr, idx, freq = EP.growth_rate({}) print("MRI growth rate = {0:10.5e}".format(gr)) EP.spectrum(spectype='good', title='mri')
else: problem.add_bc("left(ωy) = 0") problem.add_bc("left(ωz) = 0") problem.add_bc("left(bx) = 0") problem.add_bc("left(jxx) = 0") problem.add_bc("right(ωy) = 0") problem.add_bc("right(ωz) = 0") problem.add_bc("right(bx) = 0") problem.add_bc("right(jxx) = 0") # GO EP = Eigenproblem(problem) t1 = time.time() gr, idx, freq = EP.growth_rate(sparse=sparse) t2 = time.time() logger.info("Solve time: {}".format(t2-t1)) logger.info("growth rate = {}, freq = {}".format(gr,freq)) # save_vtk = False # if save_vtk: # vtkfile = filename.stem + '.vtk' # from pyevtk.hl import gridToVTK # pointData = {'p':p.copy(), 'u':u.copy(), 'v':v.copy(), 'w':w.copy(), # 'Bx':Bx.copy(), 'By':By.copy(), 'Bz':Bz.copy()} # print("p flags", pointData['p'].flags) # gridToVTK(vtkfile, xx, yy, zz, pointData=pointData)
mri.add_equation("dx(A) - Ax = 0") mri.add_equation("dx(B) - Bx = 0") mri.add_bc("left(u) = 0") mri.add_bc("right(u) = 0") mri.add_bc("left(psi) = 0") mri.add_bc("right(psi) = 0") mri.add_bc("left(A) = 0") mri.add_bc("right(A) = 0") mri.add_bc("left(psix) = 0") mri.add_bc("right(psix) = 0") mri.add_bc("left(Bx) = 0") mri.add_bc("right(Bx) = 0") # create an Eigenproblem object EP = Eigenproblem(mri) cf = CriticalFinder(EP, ("Q", "Rm"), comm, find_freq=False) # generating the grid is the longest part nx = 20 ny = 20 xpoints = np.linspace(0.5, 1.5, nx) ypoints = np.linspace(4.6, 5.5, ny) file_name = 'mri_growth_rate' try: cf.load_grid('{}.h5'.format(file_name)) except: start = time.time() cf.grid_generator((xpoints, ypoints), sparse=True)
orr_somerfeld.parameters['Re'] = 10000. orr_somerfeld.add_equation( 'dz(wzzz) - 2*alpha**2*wzz + alpha**4*w - sigma*(wzz-alpha**2*w)-1j*alpha*(Re*(1-z**2)*(wzz-alpha**2*w) + 2*Re*w) = 0 ' ) orr_somerfeld.add_equation('dz(w)-wz = 0') orr_somerfeld.add_equation('dz(wz)-wzz = 0') orr_somerfeld.add_equation('dz(wzz)-wzzz = 0') orr_somerfeld.add_bc('left(w) = 0') orr_somerfeld.add_bc('right(w) = 0') orr_somerfeld.add_bc('left(wz) = 0') orr_somerfeld.add_bc('right(wz) = 0') # create an Eigenproblem object EP = Eigenproblem(orr_somerfeld) # create a shim function to translate (x, y) to the parameters for the eigenvalue problem: cf = CriticalFinder(EP, ("alpha", "Re"), comm, find_freq=True) # generating the grid is the longest part start = time.time() nx = 20 ny = 20 xpoints = np.linspace(1.0, 1.1, nx) ypoints = np.linspace(5500, 6000, ny) try: cf.load_grid('{}.h5'.format(file_name)) except: cf.grid_generator((xpoints, ypoints), sparse=True)
problem.add_equation("Ψz - dz(Ψ) = 0") problem.add_equation("phiz - dz(phi) = 0") problem.add_equation("phizz - dz(phiz) = 0") problem.add_equation("phizzz - dz(phizz) = 0") problem.add_bc("right(θ) = 0") problem.add_bc("right(Ψ) = 0") problem.add_bc("right(phi) = 0") problem.add_bc("right(phiz) = 0") problem.add_bc("left(θ) = 0") problem.add_bc("left(Ψ) = 0") problem.add_bc("left(phi) = 0") problem.add_bc("left(phiz) = 0") EP = Eigenproblem(problem, sparse=True) def shim(x, y): gr, indx, freq = EP.growth_rate({"Ra": x, "ky": y}) ret = gr + 1j * freq if type(ret) == np.ndarray: return ret[0] else: return ret cf = CriticalFinder(shim, comm) # generating the grid is the longest part start = time.time()
mri.add_equation("dx(A) - Ax = 0") mri.add_equation("dx(B) - Bx = 0") mri.add_bc("left(u) = 0") mri.add_bc("right(u) = 0") mri.add_bc("left(psi) = 0") mri.add_bc("right(psi) = 0") mri.add_bc("left(A) = 0") mri.add_bc("right(A) = 0") mri.add_bc("left(psix) = 0") mri.add_bc("right(psix) = 0") mri.add_bc("left(Bx) = 0") mri.add_bc("right(Bx) = 0") # create an Eigenproblem object EP = Eigenproblem(mri, sparse=True) # create a shim function to translate (x, y) to the parameters for the eigenvalue problem: def shim(x, y): iRm = 1 / x iRe = (iRm * Pm) print("Rm = {}; Re = {}; Pm = {}".format(1 / iRm, 1 / iRe, Pm)) gr, indx, freq = EP.growth_rate({"Q": y, "iRm": iRm, "iR": iRe}) ret = gr + 1j * freq return ret cf = CriticalFinder(shim, comm) # generating the grid is the longest part
"right(s) = 0") # Fixed entropy at upper boundary, arbitarily set to 0 rayleigh_benard.add_bc( "left(sz) = 0") # Fixed flux at bottom boundary, F = F_cond #Impenetrable rayleigh_benard.add_bc('left(w) = 0') rayleigh_benard.add_bc('right(w) = 0') #Stress free rayleigh_benard.add_bc('left(uz) = 0') rayleigh_benard.add_bc('right(uz) = 0') rayleigh_benard.add_bc("left(vz) = 0") rayleigh_benard.add_bc("right(vz) = 0") # create an Eigenproblem object EP = Eigenproblem(rayleigh_benard, sparse=True) # create a shim function to translate (x, y) to the parameters for the eigenvalue problem: def shim(x, y): # print(f"Processor: {comm.rank} \n Ra={int(x)}, k={y:.3}") gr, indx, freq = EP.growth_rate({"Ra": x, "k": y}) # print(f"Processor: {comm.rank} \n Ra={int(x)}, k={y:.3}, gr={gr}") ret = gr + 1j * freq if type(ret) == np.ndarray: return ret[0] else: return ret cf = CriticalFinder(shim, comm)
mri.add_equation("dx(psi) - psix = 0") mri.add_equation("dx(psix) - psixx = 0") mri.add_equation("dx(psixx) - psixxx = 0") mri.add_equation("dx(u) - ux = 0") mri.add_equation("dx(A) - Ax = 0") mri.add_equation("dx(B) - Bx = 0") mri.add_bc("left(u) = 0") mri.add_bc("right(u) = 0") mri.add_bc("left(psi) = 0") mri.add_bc("right(psi) = 0") mri.add_bc("left(A) = 0") mri.add_bc("right(A) = 0") mri.add_bc("left(psix) = 0") mri.add_bc("right(psix) = 0") mri.add_bc("left(Bx) = 0") mri.add_bc("right(Bx) = 0") # create an Eigenproblem object EP = Eigenproblem(mri) gr, indx, freq = EP.growth_rate({}) EP.solver.set_state(indx) x = EP.solver.domain.grid(0) psi = EP.solver.state['psi']['g'] plt.plot(x, psi.real) plt.plot(x, psi.imag) plt.savefig('mri_psi_evec.png')
"r*r*dt(u) - nu*Lap_r - 2*r*v0*v + r*v0*dtheta(u) + r*r*dr(p) = 0") problem.add_equation( "r*r*dt(v) - nu*Lap_t + r*r*dv0dr*u + r*v0*u + r*v0*dtheta(v) + r*dtheta(p) = 0" ) problem.add_equation("r*r*dt(w) - nu*Lap_z + r*r*dz(p) + r*v0*dtheta(w) = 0.") #continuity problem.add_equation("r*ur + u + dtheta(v) + r*dz(w) = 0") #Auxillilary equations problem.add_equation("ur - dr(u) = 0") problem.add_equation("vr - dr(v) = 0") problem.add_equation("wr - dr(w) = 0") #Boundary Conditions problem.add_bc("left(u) = 0") problem.add_bc("right(u) = 0") problem.add_bc("left(v) = 0") problem.add_bc("right(v) = 0") problem.add_bc("left(w) = 0") problem.add_bc("right(w) = 0") ep = Eigenproblem(problem) growth, index, freq = ep.growth_rate({}) logger.info("Growth rate = {:16.15e}; frequency = {:16.15e}".format( growth, freq[0])) #ep.spectrum(spectype='hires')
c01 = d.new_field(name='c01') xx = x.grid() # this is not a reasonable way to do this; it's just to test non-constant coefficients c3['g'] = -0.02 * xx**2 c1['g'] = -0.04 * xx c01['g'] = 0.0001 * xx**4 prob.parameters['c3'] = c3 prob.parameters['c1'] = c1 prob.parameters['c01'] = c01 prob.parameters['c02'] = -0.02 prob.add_equation("dx(yxxx) + c3*yxx + c1*yx + (c01 + c02)*y - sigma*y = 0") prob.add_equation("dx(yxx) - yxxx = 0") prob.add_equation("dx(yx) - yxx = 0") prob.add_equation("dx(y) - yx = 0") prob.add_bc("left(y) = 0") prob.add_bc("right(y) = 0") prob.add_bc("left(yx) = 0") prob.add_bc("right(yx) = 0") EP = Eigenproblem(prob, sparse=False) EP.solve() EP.reject_spurious() indx = EP.evalues_good.argsort() print("First five good eigenvalues are: ") print(EP.evalues_good[indx][0:5])
#fixed temperature rayleigh_benard.add_bc('left(b) = 0') rayleigh_benard.add_bc('right(b) = 0') #Impenetrable rayleigh_benard.add_bc('left(w) = 0') rayleigh_benard.add_bc('right(w) = 0') if no_slip: rayleigh_benard.add_bc('left(u) = 0') rayleigh_benard.add_bc('right(u) = 0') elif stress_free: rayleigh_benard.add_bc('left(uz) = 0') rayleigh_benard.add_bc('right(uz) = 0') # create an Eigenproblem object EP = Eigenproblem(rayleigh_benard) cf = CriticalFinder(EP, ("k", "Ra"), comm, find_freq=True) # generating the grid is the longest part start = time.time() if no_slip: nx = 20 ny = 20 xpoints = np.linspace(2, 4, ny) ypoints = np.linspace(1000, 3000, nx) elif stress_free: #657.5, 2.221 nx = 10 ny = 10 xpoints = np.linspace(2, 2.4, ny)
else: problem.add_equation("θz - dz(θ) = 0") problem.add_equation("uz - dz(u) = 0") problem.add_equation("vz - dz(v) = 0") problem.add_equation("wz - dz(w) = 0") problem.add_bc("right(θ) = 0") problem.add_bc("right(u) = 0") problem.add_bc("right(v) = 0") problem.add_bc("right(w) = 0") problem.add_bc("left(θ) = 0") problem.add_bc("left(u) = 0") problem.add_bc("left(v) = 0") problem.add_bc("left(w) = 0") EP = Eigenproblem(problem, sparse=True) if find_crit: def shim(x, y): gr, indx, freq = EP.growth_rate({"Ra": x, "ky": y}) ret = gr + 1j * freq if type(ret) == np.ndarray: return ret[0] else: return ret cf = CriticalFinder(shim, comm) # generating the grid is the longest part start = time.time()
logger.debug("Setting energy equation") waves.add_equation("dt(T1) + w*T0_z + (gamma-1)*T0*Div_u = 0 ") waves.add_equation("dz(w) - w_z = 0 ") #waves.add_bc('left(dz(u)) = 0') #waves.add_bc('right(dz(u)) = 0') waves.add_bc('left(w) = 0') waves.add_bc('right(w) = 0') # value at top of atmosphere in isothermal layer brunt_max = np.max(np.sqrt(np.abs(brunt2))) # max value in atmosphere k_Hρ = -1/2*del_ln_rho0.interpolate(z=0)['g'][0].real c_s = np.sqrt(T0.interpolate(z=0)['g'][0].real) logger.info("max Brunt is |N| = {} and k_Hρ is {}".format(brunt_max, k_Hρ)) start_time = time.time() EP = Eigenproblem(waves) # Distribute wavenumbers ks = np.logspace(-1, 2, num=20) * k_Hρ batch = int(np.ceil(len(ks) / cw_size)) ks_local = ks[batch*cw_rank:batch*(cw_rank+1)] freqs = [] eigenfunctions = {'w':[], 'u':[], 'T':[]} omega = {'ω_plus_min':[], 'ω_minus_max':[]} w_weights = [] KE = domain_EVP.new_field() rho0 = domain_EVP.new_field() rho0['g'] = np.exp(ln_rho0['g']) rho0_avg = (rho0.integrate('z')['g'][0]/Lz).real logger.debug("aveage ρ0 = {:g}".format(rho0_avg))