Hi all,

I've been trying to get the first variation of a functional that depends on
the function phi, and its first and second gradient. I'm probably doing
something wrong.

the function phi:

    φ(x, y, t)

its first gradient gradient_1_phi:

    ⎡∂               ∂             ⎤
    ⎢──(φ(x, y, t))  ──(φ(x, y, t))⎥
    ⎣∂x              ∂y            ⎦
its second gradient gradient_2_phi:

    ⎡   2                  2             ⎤
    ⎢  ∂                  ∂              ⎥
    ⎢ ───(φ(x, y, t))   ─────(φ(x, y, t))⎥
    ⎢   2               ∂y ∂x            ⎥
    ⎢ ∂x                                 ⎥
    ⎢                                    ⎥
    ⎢   2                  2             ⎥
    ⎢  ∂                  ∂              ⎥
    ⎢─────(φ(x, y, t))   ───(φ(x, y, t)) ⎥
    ⎢∂y ∂x                 2             ⎥
    ⎣                    ∂y              ⎦

For the sake of simplicity, I split the functional in three parts, one
containing phi, another its first gradient, and the last containing the
second gradient. These are potential_PFC, regularizers_PFC_1, and
regularizers_PFC_2 respectively.

Problem: when computing the first variation of regularizers_PFC_2 wrt the
second gradient gradient_2_phi, the cross derivatives disappear.

In regularizers_PFC_2, I would expect to get

    ⎡        4                     4                        4
              ⎤
    ⎢       ∂                     ∂                       ∂
              ⎥
    ⎢- 1.0⋅───(φ(x, y, t)) - 1.0⋅───(φ(x, y, t)) - 2.0⋅ ──────(φ(x, y, t))
= 0, True, True⎥
    ⎢        4                     4                      2  2
               ⎥
    ⎣      ∂x                    ∂y                     ∂x ∂y
              ⎦

but I get

    ⎡        4                     4                            ⎤
    ⎢       ∂                     ∂                             ⎥
    ⎢- 1.0⋅───(φ(x, y, t)) - 1.0⋅───(φ(x, y, t)) = 0, True, True⎥
    ⎢        4                     4                            ⎥
    ⎣      ∂x                    ∂y                             ⎦

Here is the code, I appreciate very much and suggestion.

    from sympy import Symbol, Function
    from sympy.calculus.euler import euler_equations
    from sympy import tensorcontraction, tensorproduct, eye
    from sympy.tensor.array import derive_by_array
    from sympy import init_printing
    init_printing()

    La = Lb = Lc = 1

    t     = Symbol('t')
    x     = Symbol('x')
    y     = Symbol('y')

    phi   = Function('phi')(x,y,t)
    gradient_1_phi = Function('gradient_1_phi')(x,y,t)
    gradient_2_phi = Function('gradient_2_phi')(x,y,t)

    grad_1_phi = derive_by_array(phi,[x,y])
    grad_2_phi = derive_by_array(grad_1_phi,[x,y])
    regularizers_PFC_1 =
-Lb*tensorcontraction(tensorproduct(grad_1_phi,grad_1_phi), (0, 1))
    regularizers_PFC_2 =
+0.5*Lc*tensorcontraction(tensorproduct(grad_2_phi,grad_2_phi),(0,1,2,3))
    potential_PFC = La*(0.5*(1.0-0.2)*phi**2 + 0.25*phi*phi*phi*phi)
    d_regularizers_PFC_1 = euler_equations(regularizers_PFC_1,
[phi,gradient_1_phi,gradient_2_phi], [x,y,t])
    d_regularizers_PFC_2 = euler_equations(-regularizers_PFC_2,
[phi,gradient_1_phi,gradient_2_phi], [x,y,t])

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CA%2BFGQFC8i5sLaoZfhb0R5m2_2O_m45S%3DokrwBcmLtKw2N2Ybdw%40mail.gmail.com.

Reply via email to