I have the following dolfinx code, where I am trying to solve a 2D linear elasticity problem on a 2D plate with 2 materials
import dolfinx
import numpy as np
import ufl
from mpi4py import MPI
from petsc4py.PETSc import ScalarType
from dolfinx import mesh, fem, io
import meshio
import gmsh
import numpy as np
from dolfinx.fem import (Constant, dirichletbc, Function, FunctionSpace,
form, locate_dofs_geometrical)
from dolfinx.fem.petsc import LinearProblem
from dolfinx.io import XDMFFile
from ufl import (TestFunction, TrialFunction,
dx, grad, inner)
from mpi4py import MPI
from petsc4py.PETSc import ScalarType
import gmsh
from dolfinx.io import gmshio
rve_mesh, cell_tags, facet_tags = gmshio.read_from_msh("/mnt/c/Users/ABC/sfepy/simplerve.msh", MPI.COMM_WORLD,gdim=2)
ds = ufl.Measure("ds", domain=rve_mesh, subdomain_data=facet_tags)
dx = ufl.Measure("dx", domain=rve_mesh, subdomain_data=cell_tags)
from dolfinx.fem import VectorFunctionSpace
V = VectorFunctionSpace(rve_mesh, ("Lagrange", 1))
def clamped_boundary(x):
return np.isclose(x[0], 0)
lam_values = [0.005,121]
mu_values = [0.007, 81.9]
mu = Function(V)
lam = Function(V)
for cell_no in range(len(cell_tags.values)):
subdomain_no = cell_tags.values[cell_no]
subdomain_no = int(subdomain_no-1)
mu.x.array[cell_no] = mu_values[subdomain_no]
lam.x.array[cell_no] = lam_values[subdomain_no]
u, v = TrialFunction(V), TestFunction(V)
fdim = rve_mesh.topology.dim - 1
boundary_facets = mesh.locate_entities_boundary(rve_mesh, fdim, clamped_boundary)
u_D = np.array([0,0], dtype=ScalarType)
bc = fem.dirichletbc(u_D, fem.locate_dofs_topological(V, fdim, boundary_facets), V)
def epsilon(u):
return ufl.sym(ufl.grad(u)) # Equivalent to 0.5*(ufl.nabla_grad(u) + ufl.nabla_grad(u).T)
def sigma_matrix(u):
return lam_values[0] * ufl.nabla_div(u) * ufl.Identity(u.geometric_dimension()) + 2*mu_values[0]*epsilon(u)
def sigma_fiber(u):
return lam_values[1] * ufl.nabla_div(u) * ufl.Identity(u.geometric_dimension()) + 2*mu_values[1]*epsilon(u)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
f = fem.Constant(rve_mesh, ScalarType((0, 0.01)))
T = fem.Constant(rve_mesh, ScalarType((0, 0)))
a = (ufl.inner(sigma_matrix(u), epsilon(v)) * ufl.dx(1) + ufl.inner(sigma_fiber(u), epsilon(v)) * ufl.dx(2))
L = (ufl.dot(f, v) * ufl.dx(1) + ufl.dot(f, v) * ufl.dx(2) + ufl.dot(T, v) * ds)
problem = fem.petsc.LinearProblem(a, L,[bc], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
uh = problem.solve()
The 2nd to last line throws the error.
ValueError: too many values to unpack (expected 1)
I am following the following tutorial
https://jorgensd.github.io/dolfinx-tutorial/chapter2/linearelasticity_code.html