示例#1
0
radial = lambda A: de.RadialComponent(A)
angular = lambda A: de.AngularComponent(A, index=1)
trace = lambda A: de.Trace(A)
power = lambda A, B: de.Power(A, B)
lift_basis = b.clone_with(k=2)
lift = lambda A, n: de.LiftTau(A, lift_basis, n)
integ = lambda A: de.Integrate(A, c)
azavg = lambda A: de.Average(A, c.coords[0])
shellavg = lambda A: de.Average(A, c.S2coordsys)
avg = lambda A: de.Integrate(A, c) / (4 / 3 * np.pi * radius**3)

# NCCs and variables of the problem
ez = d.VectorField(c, name='ez', bases=b)
ez['g'][1] = -np.sin(theta)
ez['g'][2] = np.cos(theta)
ez_g = de.Grid(ez).evaluate()
ez_g.name = 'ez_g'

r_cyl = d.VectorField(c, name='r_cyl', bases=b)
r_cyl['g'][2] = r * np.sin(theta)
r_cyl['g'][1] = -r * np.cos(theta)

r_vec = d.VectorField(c, name='r_vec', bases=b)
r_vec['g'][2] = r
r_vec_g = de.Grid(r_vec).evaluate()

structure = lane_emden(Nr, n_rho=n_rho, m=1.5, comm=MPI.COMM_SELF)

bk2 = b.clone_with(k=2)
bk1 = b.clone_with(k=1)
T = d.Field(name='T', bases=b.radial_basis)
    logger.info("Ra(z=0)   = {:.2g}".format(Ra_bot[0][0]))
    logger.info("Ra(z={:.1f}) = {:.2g}".format(Lz / 2, Ra_mid[0][0]))
    logger.info("Ra(z={:.1f}) = {:.2g}".format(Lz, Ra_top[0][0]))
    logger.info("Δs = {:.2g} ({:.2g} to {:.2g})".format(
        s_bot[0][0] - s_top[0][0], s_bot[0][0], s_top[0][0]))
    logger.info("Δθ = {:.2g} ({:.2g} to {:.2g})".format(
        θ_bot[0][0] - θ_top[0][0], θ_bot[0][0], θ_top[0][0]))
    logger.info("ΔT = {:.2g} ({:.2g} to {:.2g})".format(
        T_bot[0][0] - T_top[0][0], T_bot[0][0], T_top[0][0]))
    logger.info("ΔΥ = {:.2g} ({:.2g} to {:.2g})".format(
        Υ_bot[0][0] - Υ_top[0][0], Υ_bot[0][0], Υ_top[0][0]))
scale = d.Field(name='scale', bases=zb2)
scale.require_scales(dealias)
scale['g'] = T0['g']

h0_grad_s0_g = de.Grid(h0 * grad(s0)).evaluate()
h0_grad_s0_g.name = 'h0_grad_s0_g'
h0_g = de.Grid(h0).evaluate()
h0_g.name = 'h0_g'

for ncc in [grad(Υ0), grad(T0), T0, np.exp(-Υ0), ρ0_inv]:
    logger.info('scaled {:} has  {:} terms'.format(ncc, (np.abs(
        (scale * ncc).evaluate()['c']) > ncc_cutoff).sum()))

# Υ = ln(ρ), θ = ln(h)
problem = de.IVP([Υ, u, T, τu1, τu2, τs1, τs2])
problem.add_equation((scale * (dt(Υ) + trace(grad_u) + dot(u, grad(Υ0))),
                      scale * (-dot(u, grad(Υ)))))
problem.add_equation((scale*(dt(u) + grad(T) \
                      + T*grad(Υ0) + T0*grad(Υ)
                      - μ*ρ0_inv*viscous_terms) \
h0 = d.Field(name='h0', bases=zb)
h0['g'] = h_bot + z * h_slope  #(Lz+1)-z

θ0 = np.log(h0).evaluate()
Υ0 = (m_ad * θ0).evaluate()
Υ0.name = 'Υ0'
ρ0 = np.exp(Υ0).evaluate()
ρ0.name = 'ρ0'
ρ0_inv = np.exp(-Υ0).evaluate()
ρ0_inv.name = '1/ρ0'
grad_h0 = grad(h0).evaluate()
grad_θ0 = grad(θ0).evaluate()
grad_Υ0 = grad(Υ0).evaluate()

h0_g = de.Grid(h0).evaluate()
h0_inv_g = de.Grid(1 / h0).evaluate()
grad_h0_g = de.Grid(grad(h0)).evaluate()
ρ0_g = de.Grid(ρ0).evaluate()

ρ0_grad_h0_g = de.Grid(ρ0 * grad(h0)).evaluate()
ρ0_h0_g = de.Grid(ρ0 * h0).evaluate()

source = d.Field(name='source', bases=b)
source.change_scales(dealias)
source['g'] = (ε * scrR / Pr / h0).evaluate()['g']
source_g = de.Grid(source).evaluate()

Υ_bot = Υ0(z=0).evaluate()['g']
Υ_top = Υ0(z=Lz).evaluate()['g']