Hello, I am having difficulty in understanding the following error -
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/tmp/ipykernel_3949/1105952868.py in <module>
5 # AMG). The solution vector is passed so that it can be copied to
6 # generate compatible vectors for the nullspace.
----> 7 null_space = build_nullspace(V, u.vector())
8
9 # Attach near nullspace to matrix
/tmp/ipykernel_3949/3298775566.py in build_nullspace(V, x)
15 # Create vector space basis and orthogonalize
16 basis = VectorSpaceBasis(nullspace_basis)
---> 17 basis.orthonormalize()
18
19 return basis
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to orthonormalize vector basis.
*** Reason: Vector space has linear dependency.
*** Where: This error was encountered inside VectorSpaceBasis.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: ubuntu
*** -------------------------------------------------------------------------
I was running out of memory when using linear solver so in this post @dokken suggested me to use CG with a GAMG preconditioner which is available on Bitbucket.
Here is the minimum working example to reproduce the above error -
from dolfin import *
import matplotlib.pyplot as plt
if not has_linear_algebra_backend("PETSc"):
print("DOLFIN has not been configured with PETSc. Exiting.")
exit()
parameters["linear_algebra_backend"] = "PETSc"
def build_nullspace(V, x):
nullspace_basis = [x.copy() for i in range(6)]
V.sub(0).dofmap().set(nullspace_basis[0], 1.0);
V.sub(1).dofmap().set(nullspace_basis[1], 1.0);
V.sub(2).dofmap().set(nullspace_basis[2], 1.0);
for x in nullspace_basis:
x.apply("insert")
# Create vector space basis and orthogonalize
basis = VectorSpaceBasis(nullspace_basis)
basis.orthonormalize()
return basis
from mshr import *
cylinder = Cylinder(Point(0.5, 0.5, 0), Point(0.5, 0.5, 2), 0.25, 0.25)
cube = Box(Point(0, 0, 0),Point(1, 1, 1))
domain = cube - cylinder
mesh = generate_mesh(domain, 40)
E = Constant(200e3)
nu = Constant(0.3)
mu = E/2/(1+nu)
lmbda = E*nu/(1+nu)/(1-2*nu)
def epsilon(u):
return sym(grad(u))
def sigma(u):
return lmbda*tr(epsilon(u))*Identity(3) + 2*mu*epsilon(u)
V = VectorFunctionSpace(mesh, "Lagrange", 1)
f = Constant((0., 0., 0.))
u = TrialFunction(V)
v = TestFunction(V)
a = inner(sigma(u), epsilon(v))*dx
L = inner(f, v)*dx
class left(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and near(x[0], 0., 0.1)
class right(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and near(x[0], 1., 0.1)
boundaries = MeshFunction("size_t", mesh, mesh.geometry().dim() - 1)
left().mark(boundaries, 1)
right().mark(boundaries, 2)
bc_left = DirichletBC(V, Constant((0., 0., 0.)), boundaries, 1)
bc_right = DirichletBC(V.sub(0), Constant(1.) , boundaries, 2)
bcs = [bc_left, bc_right]
A, b = assemble_system(a, L, bcs)
u = Function(V)
null_space = build_nullspace(V, u.vector())
as_backend_type(A).set_near_nullspace(null_space)
pc = PETScPreconditioner("petsc_amg")
PETScOptions.set("mg_levels_ksp_type", "chebyshev")
PETScOptions.set("mg_levels_pc_type", "jacobi")
PETScOptions.set("mg_levels_esteig_ksp_type", "cg")
PETScOptions.set("mg_levels_ksp_chebyshev_esteig_steps", 50)
solver = PETScKrylovSolver("cg", pc)
solver.parameters["monitor_convergence"] = True
solver.set_operator(A);
solver.solve(u.vector(), b);
Any help regarding the above would be highly appreciated.
Thank You.