Ray,

Thank you for your response.  I understand the constraints with the
convection equation and non-linearities, but as you mentioned I do need to
solve this type of problem but in a more complex setting.

I did not know about Clawpack before, so I will check that out.  Thank you
so much for your suggestion!

Tyler Abbot
Phd Student
Department of Economics
Sciences Po, Paris
[email protected]

2016-03-23 13:38 GMT+01:00 Raymond Smith <[email protected]>:

> First, I hope you're considering the broad set of FiPy examples
> <http://www.ctcms.nist.gov/fipy/examples/README.html> as part of the
> documentation. They can serve as a great starting point for many problems.
> Second, solving convection problems without any diffusion is notoriously a
> bit difficult with standard finite volume techniques. So, despite the
> apparent simplicity of your starting example, you've happened to pick one
> that's likely to disagree with the analytical solution because of numerical
> challenges. That said, you may try using different forms of the convection
> term (mentioned here
> <http://www.ctcms.nist.gov/fipy/examples/convection/generated/examples.convection.exponential1D.mesh1D.html>)
> and letting the simulation run for convection beyond a single grid point.
> Anyway, it's usually a good idea to start with simple examples like this,
> but here, you might consider letting FiPy's examples guide your choice in
> getting started unless you're specifically looking at problems of the form
> you've begun with here.
>
> If you really need to solve convection problems without the numerically
> smoothing diffusion, then you might consider different numerical schemes
> designed for hyperbolic equations, such as those implemented in clawpack:
> http://www.clawpack.org/
> Very similar to your problem:
>
> http://www.clawpack.org/pyclaw/gallery/gallery_all.html#dimensional-advection
>
> Best,
> Ray
>
> On Wed, Mar 23, 2016 at 7:54 AM, Tyler ABBOT <[email protected]>
> wrote:
>
>> Hello!
>>
>> I'm new to FiPy and am having a lot of trouble finding my way using only
>> the documentation...
>>
>> I am trying to understand how FiPy works by working an example, in
>> particular I would like to solve the following simple convection equation
>> with periodic boundary:
>>
>> $$\partial_t u + \partial_x u = 0$$
>>
>> If initial data is given by $u(x, 0) = F(x)$, then the analytical
>> solution is $u(x, t) = F(x - t)$. I do get a solution, but it is not
>> correct.
>>
>> What am I missing? Is there a better resource for understanding FiPy than
>> the documentation? It is very sparse...
>>
>> Here is my attempt
>>
>> from fipy import *
>> import numpy as np
>>
>> # Generate mesh
>> nx = 20
>> dx = 2*np.pi/nx
>> mesh = PeriodicGrid1D(nx=nx, dx=dx)
>>
>> # Generate solution object with initial discontinuity
>> phi = CellVariable(name="solution variable", mesh=mesh)
>> phiAnalytical = CellVariable(name="analytical value", mesh=mesh)
>> phi.setValue(1.)
>> phi.setValue(0., where=x > 1.)
>>
>> # Define the pde
>> D = [[-1.]]
>> eq = TransientTerm() == ConvectionTerm(coeff=D)
>>
>> # Set discretization so analytical solution is exactly one cell translation
>> dt = 0.01*dx
>> steps = 2*int(dx/dt)
>>
>> # Set the analytical value at the end of simulation
>> phiAnalytical.setValue(np.roll(phi.value, 1))
>>
>> for step in range(steps):
>>     eq.solve(var=phi, dt=dt)
>>
>> print(phi.allclose(phiAnalytical, atol=1e-1))
>>
>> Thanks for any guidance you could give!
>>
>> Tyler Abbot
>> Phd Student
>> Department of Economics
>> Sciences Po, Paris
>> [email protected]
>>
>> _______________________________________________
>> fipy mailing list
>> [email protected]
>> http://www.ctcms.nist.gov/fipy
>>   [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
>>
>>
>
> _______________________________________________
> fipy mailing list
> [email protected]
> http://www.ctcms.nist.gov/fipy
>   [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
>
>
_______________________________________________
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