I am trying to save my model result in pvd format. The model is about the elasticity and y need plot the displacement a stress. When i save the displacements like:
#u = Function(V, name=“Displacement”)
#solve(a == l, u, bc)
#vtkfile=File(‘solution_displa.pvd’)
#vtkfile << u
Its work. But, y continue the proces to get the principal stress values like:
#stress = sigma(u)
#sx = -stress[0,0]
#sy = -stress[1,1]
#txy = -stress[0,1]
#def sigma1(sigma_x, sigma_y, tau_xy): # magnitude of first principal stress
return((sigma_x+sigma_y)/2 + sqrt(((sigma_x-sigma_y)/2)2 + tau_xy2))
#def sigma3(sigma_x, sigma_y, tau_xy): # magnitude of first principal stress
return((sigma_x+sigma_y)/2 - sqrt(((sigma_x-sigma_y)/2)2 + tau_xy2));
#S1 = sigma1(sx,sy,txy);
#S3 = sigma3(sx,sy,txy)
And
#vtkfile=File("S1.pvd’)
#vtkfile << S1 Dont work.
How i can do this?? Thanks.
The complete code is:
from dolfin import *
mesh = Mesh(“p1_2vetas.xml”)
#plot(mesh)
cd=MeshFunction(‘size_t’,mesh,“p1_2vetas_physical_region.xml”)
plot(cd)
def eps(v):
return sym(grad(v))
class Young(UserExpression): # UserExpression instead of Expression
def init(self, markers, **kwargs):
super().init(**kwargs) # This part is new!
self.markers = markers
def eval_cell(self, values, x, cell):
if self.markers[cell.index] == 1:
values[0] = 30e9
elif self.markers[cell.index] ==2:
values[0] = 15e9
elif self.markers[cell.index] ==3:
values[0] = 15e9
elif self.markers[cell.index] ==4:
values[0] = 30e9
elif self.markers[cell.index] ==5:
values[0] = 15e9
elif self.markers[cell.index] ==6:
values[0] = 15e9
else:
values[0] = 30e9
E=Young(cd,degree=0)
nu = Constant(0.3)
mu = E/2/(1+nu)
lmbda =Enu/(1+nu)/(1-2nu)
def sigma(v):
return lmbdatr(eps(v))Identity(2) + 2.0mueps(v)
rho_g = 1e-3
f = Constant((0, -rho_g))
V = VectorFunctionSpace(mesh, ‘Lagrange’, degree=2)
du = TrialFunction(V)
u_ = TestFunction(V)
a = inner(sigma(du), eps(u_))*dx
l = inner(f, u_)*dx;
def bottom(x, on_boundary):
return near(x[1], 0.)
def left(x, on_boundary):
return near(x[0], 0.)
def right(x, on_boundary):
return near(x[0], 914.5695)
bc1 = DirichletBC(V, Constant((0.,0.)), bottom)
bc2 = DirichletBC(V.sub(0), Constant(0.), left)
bc3 = DirichletBC(V.sub(0), Constant(0.), right)
bc=[bc1,bc2,bc3]
u = Function(V, name=“Displacement”)
solve(a == l, u, bc)
#vtkfile=File(‘solution_displa.pvd’)
#vtkfile << u
p = plot(u,mode=“displacement”,cmap=“jet”)
plt.colorbar(p);
stress = sigma(u)
sx = -stress[0,0]
sy = -stress[1,1]
txy = -stress[0,1]
def sigma1(sigma_x, sigma_y, tau_xy): # magnitude of first principal stress
return((sigma_x+sigma_y)/2 + sqrt(((sigma_x-sigma_y)/2)2 + tau_xy2))
def sigma3(sigma_x, sigma_y, tau_xy): # magnitude of first principal stress
return((sigma_x+sigma_y)/2 - sqrt(((sigma_x-sigma_y)/2)2 + tau_xy2));
S1 = sigma1(sx,sy,txy);
S3 = sigma3(sx,sy,txy);
p = plot(S1,cmap=“jet”);
plt.colorbar(p,label=“σ1(MPa)”);