# FEniCS: how to access coordinates when writing an equation for a trial function

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?

## 1 Answer

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.

• This doesn't work anymore in the new FEniCS. – facetus Nov 1 '18 at 17:53
• @facetus since this is related to the working of a library, it is best to ask this question on the fenics forum or google group. – cfdlab Nov 3 '18 at 4:36
• I know. But other people who can try to look here for an answer don't. – facetus Nov 3 '18 at 4:40