How to Implement First and Second Derivatives w.r.t. Specific Directions in FEniCS

Dear everyone,

I am currently working on solving a PDE with first and second derivatives explicitly with respect to two spatial variables π‘₯1 and π‘₯2. I am having some difficulty identifying the correct FEniCS operators to implement this equation properly. The equation I am trying to solve is:

(𝐹,22 βˆ’ β„Ž1) 𝑓,11 + (𝐹,11 βˆ’ β„Ž2) 𝑓,22 βˆ’ 2 𝐹,12 𝑓,12 βˆ’ 𝑓,1 πœ†1 π‘βˆ’ 𝑓,2 πœ†2 𝑝 βˆ’ 𝑝 = 0

Where
𝑓(x1, x2) is the unknown function
𝑓,i represents the first derivatives with respect to π‘₯𝑖
𝑓,ij represents the second derivatives with respect to π‘₯𝑖 and π‘₯𝑗.
F(x1, x2) represents a scalar function of spatial variables x1 and x2 with its second variables.
h1, h2, πœ†1 and πœ†2 are scalars and p is a known load term.

I attempted to implement the equation using grad(f) and inner() terms, but this approach includes derivatives in all spatial directions, which does not match the PDE that requires derivatives explicitly with respect to π‘₯1 and π‘₯2 only.

My weak form currently looks like this:

    a = (F_S22_minus_h1 * inner(grad(f), grad(v)) * dx
         + F_S11_minus_h2 * inner(grad(f), grad(v)) * dx
         - 2 * F_S12 * inner(grad(f), grad(v)) * dx) 
    -load_times_lambda_1 * v * dx - + load_times_lambda_2 * v * dx
    
    L = -load * v * dx

How can I explicitly apply first and second derivatives with respect to π‘₯1 and π‘₯2 only in the weak form of my PDE? Is there a better operator or method in FEniCS to achieve this? I apologize if this is a basic questionβ€”I am still quite new to FEniCS and learning its syntax. Any guidance, hints, or references would be greatly appreciated!

Thank you very much, and I look forward to hearing from you.

Best Regards,
Luigi

Fenics permits simply f.dx(0) to take the derivative of a Function object f wrt x0. You can repeat this operation, ie. f.dx(0).dx(0).

Note that for C0 continuous functions this is a β€˜dangerous’ operation, and often is not what you actually want… (Taking second derivatives, that is)

1 Like