calculate strain and stress in 1D


133
views
0
3 months ago by
hsk  
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
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
3 months ago by
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:
P1 = FunctionSpace(mesh,'DG',0)
ep = project(eps,P1)
plot(ep)​
written 3 months ago by hsk  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »