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)
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])
logger.info("grid generation time: {:10.5f} sec".format(end - start)) crit = cf.crit_finder(polish_roots=False) if comm.rank == 0: logger.info("critical Rm = {:10.5f}, Q = {:10.5f}".format( crit[1], crit[0])) # create plot of critical parameter space pax, cax = cf.plot_crit() fig = pax.figure # add an interpolated critical line x_lim = cf.parameter_grids[0][0, np.isfinite(cf.roots)] x_hires = np.linspace(x_lim[0], x_lim[-1], 100) pax.plot(x_hires, cf.root_fn(x_hires), color='k') fig.savefig('{}.png'.format(file_name), dpi=300) # plot the spectrum for the critical mode logger.info("solving dense eigenvalue problem for critical parameters") EP.solve(parameters={"Q": crit[0], "Rm": crit[1]}, sparse=False) ax = EP.plot_spectrum() # mark critical mode eps = 1e-2 mask = np.abs(EP.evalues.real) < eps ax.scatter(EP.evalues[mask].real, EP.evalues[mask].imag, c='red') ax.figure.savefig('mri_critical_spectrum.png', dpi=300) # plot drift ratio for critical mode ax = EP.plot_drift_ratios() ax.figure.savefig('mri_critical_drift_ratios.png', dpi=300)