0

What's the correct approach to the terms containing derivatives that cannot be represented (at least in any obvious way) as either convection or diffusion in FiPy? For example, in a system of PDEs being solved for functions u_i on a 2d region with coordinates x,y , one of the equations contains the term

u_2 * \partial_x u_1

I can represent it as a source, given that x and u_i are cell variables:

eq = ... + fipy.tools.numerix.dot(x.grad,u_1.grad) * u_2

However, due to how the gradient is computed in FiPy, x.grad is a vector with the value of (1,0) everywhere except the cells directly next to the x boundary, where it becomes (2,0). Which means that I have to use the vector (1,0) instead of x.grad from the start. But at this point I become unsure whether u_1.grad would have the correct value at the boundaries for the purpose of representing my term, and most probably, my whole approach is incorrect. What should I do to represent such a term?

morion
  • 1
  • The way to get `\partial_x u_1` by itself is `fipy.tools.numerix.dot([[1],[0]], u_1.grad)`, although see [my answer](https://stackoverflow.com/a/49516024/2019542) for the correct way to get a semi-implicit term – jeguyer Mar 27 '18 at 14:48

1 Answers1

0

[edited answer to reflect question asked]

u_2 \partial_x u_1 is equivalent to u_2 (1 0)\cdot\nabla u_1, which is rendered in FiPy as:

eq = ... + fp.ImplicitSourceTerm(coeff=fp.tools.numerix.dot([[1], [0]], u1.grad), var=u2)
jeguyer
  • 2,379
  • 1
  • 11
  • 15
  • Thank you! But from the fipy documentation, I thought that DiffusionTerm always corresponds to the second order derivative, so that fp.DiffusionTerm(coeff=u2*(((1., 0.), (0., 0.)),), var=u1) would represent \partial_x (u_2 \partial_x u_1) . Is that not so? – morion Mar 29 '18 at 08:32
  • Absolutely! My apologies. I've corrected my answer to reflect what you actually asked. – jeguyer Mar 30 '18 at 13:49