Hi Fenicsx community,
I’m trying to modify the assembled matrix from the linear part in order to apply a point force. I saw from here : Dirac delta distribution (dolfinx) that the Dirac delta distribution is not yet implemented in fenicsx, unless I misunderstood.
But like said in https://fenicsproject.org/qa/14258/how-to-apply-pointsource-to-linearvariationalproblem/, there is another option, add the force on assembled vectors.
So far, I’ve tried to do the second solution, it works, but only if I solve the problem with numpy, by transferring the dense matrix to python, but it is not an efficient method. Here is what I did :
from mpi4py import MPI
from petsc4py.PETSc import ScalarType
from ufl import dx, ds, Measure, TrialFunction, TestFunction, sym, grad, div, Identity, inner, dot
from dolfinx import mesh, fem, plot, io
import numpy as np
domain = mesh.create_rectangle(MPI.COMM_SELF, ((-2, 0), (2, 1)), (50,30), mesh.CellType.quadrilateral)
V2 = fem.VectorFunctionSpace(domain, ("CG", 2))
E = fem.Constant(domain, ScalarType(1))
nu = fem.Constant(domain, ScalarType(0.3))
lamda = E * nu / (1 + nu) / (1 - 2 * nu)
mu = E / (2 * (1 + nu))
T = fem.Constant(domain, ScalarType((0, 0)))
boundary_dofs = fem.locate_dofs_topological(V2, f_dim, lambda x: np.isclose(x[0], -2))
bc = fem.dirichletbc(np.zeros([2], dtype=ScalarType), boundary_dofs, V2)
dofs = fem.locate_dofs_geometrical(V2, lambda x: np.isclose(x[0], 2) & np.isclose(x[1], 0.5))
u = TrialFunction(V2)
v = TestFunction(V2)
def eps(u):
return sym(grad(u))
def sigma(u):
return (lamda * div(u) * Identity(2) + 2 * mu * eps(u))
a = inner(sigma(u), eps(v)) * dx
L = dot(T, v) * ds
problem = fem.petsc.LinearProblem(a, L, bcs=[bc], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
problem.b.setValue(dofs, -1) # Assign the force on the good dof
uh = problem.solve()
print((uh.x.array == 0).all()) # return True
print(problem.b.getArray()[dofs]) # After solving the problem it is = 0 instead of -1 :(
Thanks for your help