### calculate strain and stress in 1D

364

views

0

Hi, I want to solve bar element in FEniCS and calculate strain and stress. But getting Error: TypeError: unsupported operand type(s) for *: 'float' and 'instancemethod'

any suggestions?

Thanks for help

any suggestions?

Thanks for help

```
from dolfin import *
import matplotlib.pyplot as plt
E = 29e3
mesh = IntervalMesh(60,0,60)
#plot(mesh, interactive = True)
V = FunctionSpace(mesh,'CG',1)
u = TrialFunction(V)
v = TestFunction(V)
F = E*inner(grad(u),grad(v))*dx
a = lhs(F)
L = rhs(F)
u = Function(V)
class right(SubDomain):
def inside(self,x,on_boundary):
tol = 1e-10
return abs(x[0]-60.0) < tol and on_boundary
class left(SubDomain):
def inside(self,x,on_boundary):
tol = 1e-10
return abs(x[0]-0.0) < tol and on_boundary
Right = right()
Left = left()
uml = Expression('t', t = 0.0)
bcl= DirichletBC(V, Constant(0.0), Left)
bcr = DirichletBC(V, uml, Right)
bc = [bcl, bcr]
t = 0.0
dt = 0.005
num_steps = (0.5-0.0)/dt
num_steps = 100
for n in range(num_steps):
t+=dt
uml.t = t
solve(a==L, u, bc)
plot(u, key = 'u')
eps = u.dx
stress = E*eps
right = Point(60.0)
print eps
```

Community: FEniCS Project

### 1 Answer

3

`eps = u.dx(0)`

will fix the error but then eps is just a symbolic expression and printing it doesn't make much sense -- you might want to project to it.

Thanks it works and for plotting I have done as:

written
11 months ago by
hirshikesh

Please login to add an answer/comment or follow this question.