On Mon, Apr 2, 2012 at 3:12 AM, Yun Tao <[email protected]> wrote:

> Hi group,
>
> Two very elementary questions that I have trouble answering myself:
>
> 1. If I want to define a 1D mesh that extends into the negative domain,
> how do I do so?
>

>>> import fipy
>>> print (fipy.Grid1D(nx=2) + [[-1]]).getCellCenters()
[[-0.5  0.5]]


>
> 2. When I try to simulate a simple moving pulse with no diffusion nor
> source term but only a rudimentary convection term (see below), I could not
> get the moving wave I expected. Instead, the original distribution appears
> to diffuse on its own. Is this an artifice of setting the initial condition
> as a probability density function? If so, is there a way around it?
>

The regular convection term in FiPy is only first order accurate. The
VanLeerConvectionTerm is second order. This does a better job.

##from matplotlib import pylab
from fipy import *
from fipy import numerix
# pylab config
##fig = pylab.figure(figsize=(5, 5))
##ax = pylab.subplot((111))
# mesh config
l = 50.
nx = 100.
dx = l / nx
mesh = Grid1D(nx = nx, dx = dx)

# stochasticity
x = mesh.getCellCenters()[0]
distr = 1/numerix.sqrt(1*numerix.pi) * numerix.exp(-((x - 12) ** 2) / 2)
# variable config
phi = CellVariable(name='$\phi$', mesh=mesh, value=distr)

# viewer config
viewer = Viewer(vars=phi,
  limits={'ymin': 0., 'ymax': 1.5},
  title="$\phi$")


# pde config
convCoeff = (-40.,)

##eq = TransientTerm() == PowerLawConvectionTerm(coeff=convCoeff)
eq = TransientTerm() == VanLeerConvectionTerm(coeff=convCoeff)

# temporal config
#timeStepDuration = 0.1 * dx ** 2 / (2 * 30) *3
dt = 0.9 * dx / abs(convCoeff[0])
steps = 500
# solve for transient solution
for steps in range(steps):
    eq.solve(var=phi, dt=dt)
    print phi[-3]
    viewer.plot()
    raw_input()


-- 
Daniel Wheeler
_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to