from dolfin import * mesh = Mesh("cyl.xml") V = VectorFunctionSpace(mesh, 'CG', 1) u = TrialFunction(V) v = TestFunction(V) # Lag SubDomains av grenseflatene i topp og bunn top = AutoSubDomain(lambda x, on_bnd: near(x[2], 10.)) bottom = AutoSubDomain(lambda x, on_bnd: near(x[2], 0.)) # Marker grenseflatene med en FacetFunction mf = FacetFunction('uint', mesh) mf.set_all(0) top.mark(mf, 1) bottom.mark(mf, 2) ds = Measure("ds", domain=mesh, subdomain_data=mf) # Lag en grensebetingelse for P*n traction = Constant((0, -1, 0)) #traction = Expression(("0", "0", "std::abs(x[0]) < 1e-1 && std::abs(x[1]) < 1e-1 ? -1 : 0")) # Lag en grensebetingelse for ingen forskyvning i topp av cylinderen bc1 = DirichletBC(V, Constant((0, 0, 0)), bottom) # Sett konstanter Lambda = Constant(200) mu = Constant(100) # Sett opp likningene P = Lambda * div(u) * Identity(3) + mu * (grad(u) + grad(u).T) F = inner(grad(v), P)*dx - inner(v, traction)*ds(1) # Assemble and solve problem A = assemble(lhs(F)) b = assemble(rhs(F)) u = Function(V) bc1.apply(A, b) solve(A, u.vector(), b) #plot(u[2], title="Forskyvning i z-retning", interactive=True) f = File("traction2.pvd") f << u