Hai,
I wanted to export the Tresca stress plot over the model domain for a simple linear elasticity problem to ParaView.
WW = FunctionSpace(mesh, 'DG', 0)
sigmaT = ((2*mu*sym(grad(unew)) + lmbda*tr(grad(unew))*Identity(2)))
sigma_max = 0.5*(sigmaT[0,0] + sigmaT[1,1]) + sqrt( (0.5*(sigmaT[0,0] - sigmaT[1,1]))**2 + (sigmaT[0,1])**2 )
sigma_min = 0.5*(sigmaT[0,0] + sigmaT[1,1]) - sqrt( (0.5*(sigmaT[0,0] - sigmaT[1,1]))**2 + (sigmaT[0,1])**2 )
###tresca_plot
test=(sigma_max,sigma_min,(sigma_max-sigma_min))
Tres=project(test.max(),WW,solver_type="cg")
T_plot<<Tres
I was getting error computing this.
which is the correct way?
dokken
July 9, 2022, 12:28pm
2
You can only project objects that are ufl expressions. Here it Seems like you are mixing numpy arrays and ufl expressions. Please post a minimal example that reproduces the error to make it more likely that people can help you.
from dolfin import *
E=3300 #in mpa
nu=0.37
lmbda, mu = E*nu/((1.0 + nu )*(1.0-2.0*nu)) , E/(2*(1+nu))
# Create mesh and define function space
mesh = Mesh('plate.xml')
V = VectorFunctionSpace(mesh, "CG", 2)
WV=TensorFunctionSpace(mesh, "DG", 1)
WW = FunctionSpace(mesh, 'DG', 0)
# Define boundary condition
tol = 1E-14
bot = CompiledSubDomain("near(x[1],-30)&& on_boundary") #bottom fixed
top=CompiledSubDomain("near(x[1],30)&& on_boundary")
bc1 = DirichletBC(V, Constant((0, 0)), bot)
bc=[bc1]
boundary = MeshFunction("size_t", mesh,mesh.topology().dim() - 1)
boundary.set_all(0)
top.mark(boundary, 1)
ds = Measure("ds")(subdomain_data=boundary)
n = FacetNormal(mesh)
Trc=30*n
# Define strain and stress
def sigma(u):
return 2.0*mu*sym(grad(u)) + lmbda*tr(sym(grad(u)))*Identity(len(u))
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(v),sigma(u))*dx
L = dot(v, Trc)*ds(1)
# Compute solution
unew = Function(V)
solve(a == L, unew, bc, solver_parameters={'linear_solver':'cg'})
T_plot= File ("./ResultsDir-new/tres.pvd")
# Plot stress
sigmaT = ((2*mu*sym(grad(unew)) + lmbda*tr(grad(unew))*Identity(2)))
sigma_max = 0.5*(sigmaT[0,0] + sigmaT[1,1]) + sqrt( (0.5*(sigmaT[0,0] - sigmaT[1,1]))**2 + (sigmaT[0,1])**2 )
sigma_min = 0.5*(sigmaT[0,0] + sigmaT[1,1]) - sqrt( (0.5*(sigmaT[0,0] - sigmaT[1,1]))**2 + (sigmaT[0,1])**2 )
###tresca_plot
test=(sigma_max,sigma_min,(sigma_max-sigma_min))
Tres=project(test.max(),WW,solver_type="cg")
T_plot<<Tres