Problem in calculating f using sym function

sir my code is not working properly…Please check it.

from fenics import *
import sympy as sym
from sympy.vector import CoordSys3D, Del
from sympy.vector import divergence
from sympy import cos, sin, pi
x, y = sym.symbols('x[0], x[1]')
R = CoordSys3D('R')
delop = Del()
mu = 1
u = (pi*cos(pi*R.y)*sin(pi*R.x)*sin(pi*R.y))*R.i + (-pi*cos(pi*R.x)*sin(pi*R.y)*sin(pi*R.x))*R.j+0*R.k
p = R.x*R.y*(1-R.x)*(1-R.y)-0.0277777
def epsilon(u):
    return 0.5*(grad(u) + grad(u).T)
f1 = - 2*mu* + delop(p)
f = sym.simplify(f1)
u_code = sym.printing.ccode(u)
f_code = sym.printing.ccode(f)
print('u=', u_code)
print('f =', f_code)

You are mixing sympy and dolfin symbols. This is not valid coding. You need to write your whole formulation using pure sympy operators.

1 Like

Am trying…I don’t know the exact mistake…can you send a file in which we apply sympy function when u is a vector valued function.

This is a question about how to use sympy, and I suggest you ask in a more relevant forum about this, or have a look at the sympy docs: Basic Implementation details — SymPy 1.10.1 documentation
Scalar and Vector Field Functionality — SymPy 1.10.1 documentation

Am following same document but still my code is not working. Please recorrect it if possible.

You are not,

grad is an operator imported from FEniCS, as I already said in the previous post

You need to use:

delop = Del()
as shown in the second sympy link.

After changing this …still it is not working

You are not showing your modified code, and therefore no one will be able to guide you

1 Like

As stated, sympy is not a component of the FEniCS project. Consider their support page.