Thank you Dokken!
I tried to implement it in my code:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from dolfin import *
from fenics_shells import *
from ufl import nabla_div
mesh = RectangleMesh(Point(0.0, 0.0), Point(1000.0, 2000.0), 64, 64)
element = MixedElement([VectorElement("Lagrange", triangle, 2),
FiniteElement("Lagrange", triangle, 1),
FiniteElement("N1curl", triangle, 1),
FiniteElement("N1curl", triangle, 1)])
U = ProjectedFunctionSpace(mesh, element, num_projected_subspaces=2)
U_F = U.full_space
u_ = Function(U_F)
theta_, w_, R_gamma_, p_ = split(u_)
u = TrialFunction(U_F)
u_t = TestFunction(U_F)
E = Constant(70000.0)
nu = Constant(0.22)
kappa = Constant(5.0/6.0)
t = Constant(10)
k = sym(grad(theta_))
D = (E*t**3)/(24.0*(1.0 - nu**2))
psi_M = D*((1.0 - nu)*tr(k*k) + nu*(tr(k))**2)
psi_T = ((E*kappa*t)/(4.0*(1.0 + nu)))*inner(R_gamma_, R_gamma_)
f = Constant(0.000001)
W_ext = inner(f*t**3, w_)*dx
gamma = grad(w_) - theta_
# We instead use the :py:mod:`fenics_shells` provided :py:func:`inner_e` function::
L_R = inner_e(gamma - R_gamma_, p_)
L = psi_M*dx + psi_T*dx + L_R - W_ext
F = derivative(L, u_, u_t)
J = derivative(F, u_, u)
sigma = E/(1.0-nu**2)*(u_.dx(0).dx(0) + nu*u_.dx(1).dx(1))*t/2
xdmf_file = XDMFFile("sigma")
sigma_out = project(sigma, U_F)
sigma_out.rename("sigma", "stress")
xdmf_file.write(sigma_out, 0.0)
A, b = assemble(U, J, -F)
# and apply simply-supported boundary conditions::
def all_boundary(x, on_boundary):
return on_boundary
def left(x, on_boundary):
return on_boundary and near(x[0], 0.0)
def right(x, on_boundary):
return on_boundary and near(x[0], 1000.0)
def bottom(x, on_boundary):
return on_boundary and near(x[1], 0.0)
def top(x, on_boundary):
return on_boundary and near(x[1], 2000.0)
# Simply supported boundary conditions.
bcs = [DirichletBC(U, Constant((0.0,0.0,0.0)), all_boundary),
DirichletBC(U.sub(0).sub(0), Constant(0.0), top),
DirichletBC(U.sub(0).sub(0), Constant(0.0), bottom),
DirichletBC(U.sub(0).sub(1), Constant(0.0), left),
DirichletBC(U.sub(0).sub(1), Constant(0.0), right)]
for bc in bcs:
bc.apply(A, b)
# and solve the linear system of equations before writing out the results to
# files in ``output/``::
u_p_ = Function(U)
solver = PETScLUSolver("mumps")
solver.solve(A, u_p_.vector(), b)
reconstruct_full_space(u_, u_p_, J, -F)
save_dir = "output/"
theta, w, R_gamma, p = u_.split()
fields = {"theta": theta, "w": w, "R_gamma": R_gamma, "p": p}
for name, field in fields.items():
field.rename(name, name)
field_file = XDMFFile("%s/%s.xdmf" % (save_dir, name))
field_file.write(field)
plt.xlabel("Tizio%s"%name)
plt.ylabel("Caio")
c = plot(field)
cb = plt.colorbar(c)
plt.savefig("output/1-%s.png"%name)
cb.remove()
print("{customTag}%s{/customTag}" % name)
plt.figure()
c = plot(sigma)
cb = plt.colorbar(c)
plt.savefig("sigma.png")
cb.remove()
# We check the result against an analytical solution calculated using a
# series expansion::
from fenics_shells.analytical.simply_supported import Displacement
w_e = Displacement(degree=3)
w_e.t = t.values()
w_e.E = E.values()
w_e.p = f.values()*t.values()**3
w_e.nu = nu.values()
print("Numerical out-of-plane displacement at centre: %.4e" % w((500, 1000)))
print("Analytical out-of-plane displacement at centre: %.4e" % w_e((500, 1000)))
# Unit testing
# ============
#
# ::
def test_close():
import numpy as np
assert(np.isclose(w((500, 500)), w_e((500, 500)), atol=1E-3, rtol=1E-3))
But I have this error:
Traceback (most recent call last):
File "demo_reissner-mindlin-simply-supported.py", line 69, in <module>
sigma_out = project(sigma, U_F)
File "/home/fenics/shared/fenics_shells/fem/solving.py", line 26, in project
u_V_F = Function(V)
NameError: name 'Function' is not defined
Thank you for help