Evaluating product of testfunction and gradient of trailfunction

Hi

I’m just getting started with Fenics and I’m trying to apply fenics to the following formula: beta(x) dy/dx = f(x), and after applying Galerkin method, I have the following:
let u(x) be the test function and v(x) be the trail function, then I have

beta(x) * u(x) *( dv / dx) dx = u(x) f(x) dx

But I just can’t find a way to put u(x) and dv/dx together, can anyone help me with it please?

Here’s my code:


a = 0
b = 2
N = 10

mesh = IntervalMesh(N,a,b)
V = FunctionSpace(mesh, "Lagrange",1)
exact = Expression("2/3 * x[0] ", degree = 1)
def bounds(x,on_bound):
  return on_bound
bc = DirichletBC(V, exact, bounds)
u = TestFunction(V)
v = TrialFunction(V)
beta = Expression("3.0 * x[0]", degree =1)

A = beta_f * u *nabla_grad(v) *dx

I tried a few other ways to get A ( interpolate, project beta on V, evaluate testfunction and trailfunction) but none of them works, I’m not sure what I can do to testfunction and trialfunction.

what about:

A = beta_f * u * v.dx(0) * dx

That works perfectly! Thanks a lot for your help! So just to be clear, if I had some expression *dx, then I’m evaluating the integral and if I do something.dx(0) it means I’m take derivative? Is that right?

Yes, see:
https://fenics.readthedocs.io/projects/ufl/en/latest/manual/form_language.html?highlight=Dx#basic-spatial-derivatives
and
https://fenics.readthedocs.io/projects/ufl/en/latest/manual/form_language.html?highlight=Dx#forms-and-integrals