6

I need to solve the following equation in FEniCS: $$ \boldsymbol{\nabla} \cdot \begin{pmatrix} f(y)\frac{\partial u}{\partial x} - g(x,y)\frac{\partial u}{\partial y} \\ - g(x,y)\frac{\partial u}{\partial x}+f(x)\frac{\partial u}{\partial y} \end{pmatrix}=0. $$ As far as I understand, the weak form will look like: $$ \int_{\Omega} \begin{pmatrix} f(y)\frac{\partial u}{\partial x} - g(x,y)\frac{\partial u}{\partial y} \\ - g(x,y)\frac{\partial u}{\partial x}+f(x)\frac{\partial u}{\partial y} \end{pmatrix} \cdot \nabla v \, \mathrm{d}x = 0 \quad \forall v \in V. $$ I have problems expressing this equation in FEniCS. I figured I need something like this:

u = TrialFunction(V)
v = TestFunction(V)
g = as_vector((u.dx(0), u.dx(1))) # <-- modify here?
a = dot(g, grad(v))*dx
u = Function(V)
solve(a == Constant(0) * v * dx, u, bc)

How to add something that depends on coordinates $x$, $y$ to the variable g above?

Also do I have to write Constant(0) * v * dx as the right part? Can it be just 0?

facetus
  • 358
  • 2
  • 8

1 Answers1

8
x = V.cell().x

then use x[0] and x[1] as $x$ and $y$ respectively.

Right-hand side of LinearVariationalProblem needs to be rank 1 form - this is expressed by dependendnce on TestFunction and independence on TrialFunction.

Jan Blechta
  • 927
  • 5
  • 13