Hi I am a new user to with fenics. I have a stupid question. I tried to solve a 3D elasticity problem, and my code runs okay. It’s a cantilever beam problem with force applied. I wanted to plot its bending figure. But when I tried to plot it in my spyder on anaconda, it failed. Also, I tried to save it and plotted it with paraview. It failed too. The displacement in the function is “u”. The code is show below:
from __future__ import print_function from dolfin import * from fenics import * import matplotlib.pyplot as plt import math import ufl from mpl_toolkits import mplot3d import numpy as np from mpl_toolkits.mplot3d import Axes3D L = 25. H = 1. T = 1. Nx = 25 Ny = 5 Nz = 5 mesh = BoxMesh(Point(0., 0., 0.), Point(L, H, T), Nx, Ny, Nz) def eps(v): return sym(grad(v)) E = Constant(1e5) nu = Constant(0.3) lmbda = E*nu/(1+nu)/(1-2*nu) mu = E/2/(1+nu) lmbda = 2*mu*lmbda/(lmbda+2*mu) def sigma(v): return lmbda*tr(eps(v))*Identity(3) + 2.0*mu*eps(v) rho_g = 1e-3 f = Constant((0, -rho_g, 0)) V = VectorFunctionSpace(mesh, "CG", degree = 1) du = TrialFunction(V) u_ = TestFunction(V) a = inner(sigma(du), eps(u_))*dx l = inner(f, u_)*dx def left(x, on_boundary): return near(x[0], 0.) bc = DirichletBC(V, Constant((0., 0., 0.)), left) u = Function(V, name="Displacement") solve(a == l, u, bc) plot(u)
The saving codes are:
file = XDMFFile("output.xdmf") file.write(u, 0)
I also tried .pvd, but it failed too. I hope someone could help me out with this hard problem. Thanks a lot.
