Hi IgorBaratta, thanks for your reply. I am studying the code you shared assemble_cell.py · GitHub. However, I have three questions.
(1) When I try to test the function K = assemble_matrix(a)
in this code, it does not work. The code is as follows.
# The beginning part is the same as assemble_cell.py in GitHub
# https://gist.github.com/IgorBaratta/d0b84fd5d77f2628204097a1c0b180fb
# Now we add the following lines
import dolfinx
import numpy as np
from mpi4py import MPI
from dolfinx.cpp.mesh import CellType
import ufl
mesh = dolfinx.RectangleMesh(MPI.COMM_WORLD, [np.array([0, 0, 0]), np.array([2, 2, 0])], [2, 1], CellType.quadrilateral)
V = dolfinx.VectorFunctionSpace(mesh, ("CG", 1))
lambda_ = 1
mu = 1
T = dolfinx.Constant(mesh, (0, -1)) # traction
f = dolfinx.Constant(mesh, (0, 0)) # body force
def epsilon(u):
return ufl.sym(ufl.grad(u)) # Equivalent to 0.5*(ufl.nabla_grad(u) + ufl.nabla_grad(u).T)
def sigma(u):
return lambda_ * ufl.nabla_div(u) * ufl.Identity(u.geometric_dimension()) + 2*mu*epsilon(u)
ds = ufl.Measure("ds", domain=mesh)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
a = ufl.inner(sigma(u), epsilon(v)) * ufl.dx
K = assemble_matrix(a)
The error message is:
root@6a07b7581972:/shared# /usr/bin/python3 /shared/assemble_cell.py
Traceback (most recent call last):
File "/shared/assemble_cell.py", line 205, in <module>
K = assemble_matrix(a)
File "/shared/assemble_cell.py", line 65, in assemble_matrix
ufc_form = dolfinx.jit.ffcx_jit(a, form_compiler_parameters={
File "/usr/local/dolfinx-real/lib/python3.8/dist-packages/dolfinx/jit.py", line 60, in mpi_jit
if comm.size == 1:
AttributeError: 'Form' object has no attribute 'size'
However, when I use the function K = dolfinx.fem.assemble_matrix(a)
in the official package, it does work.
(2) In addition, which type of parameter should I pass in active_entities
of function assemble_matrix(a, active_entities=None)
in assemble_cell.py · GitHub to obtain the element stiffness matrix?
(3) It seems FEniCS and FEniCS-X are excellent open-source projects, and I do find part of the source codes in GitHub. But where can I find the source code such as dolfinx.fem.assemble_matrix
and dolfinx.fem.assemble_vector
?
Thanks!