Hi, I’m struggling to understand the PETSc options process, but from what I have found, something along the lines of what is present in this MWE should work to solve my error (ERROR 76).
I have a new error raised:
Traceback (most recent call last):
File "/testfile.py", line 35, in <module>
problem = dolfinx.fem.petsc.NonlinearProblem(F, u, bc)
File "/usr/lib/petsc/lib/python3/dist-packages/dolfinx/fem/petsc.py", line 904, in __init__
du = ufl.TrialFunction(V)
File "/usr/lib/python3/dist-packages/ufl/argument.py", line 285, in TrialFunction
return Argument(function_space, 1, part)
File "/usr/lib/python3/dist-packages/ufl/argument.py", line 176, in __init__
BaseArgument.__init__(self, function_space, number, part)
File "/usr/lib/python3/dist-packages/ufl/argument.py", line 46, in __init__
raise ValueError("Expecting a FunctionSpace.")
ValueError: Expecting a FunctionSpace.
Here is the MWE:
import fenics as fn
import dolfinx.fem.petsc
import numpy as np
import scipy.constants as sc
from scipy.interpolate import RegularGridInterpolator as rgi
import matplotlib.pyplot as plt
from petsc4py import PETSc
from mpi4py import MPI
# Parameters
# in SI
# Material and environmental constants for Quartz and the laser setup
B = 0.02 # x-dimension of the box in meters
l = 0.02 # y-dimension of the box in meters
h = 0.01 # z-dimension of the box in meters (height of the material)
# Mesh Creation
mesh = fn.BoxMesh(MPI.COMM_WORLD, fn.Point(0, 0, 0), fn.Point(B, l, h), 20, 20, 20)
# Function Space Initialization
V = fn.FunctionSpace(mesh, "CG", 2)
# Variational Problem Definition
u = fn.TrialFunction(V)
v = fn.TestFunction(V)
f = fn.Constant(0)
bc = []
F = fn.dot(fn.grad(u), fn.grad(v))*fn.dx
a, L = fn.lhs(F), fn.rhs(F)
problem = dolfinx.fem.petsc.NonlinearProblem(F, u, bc)
solver = dolfinx.nls.petsc.NewtonSolver(mesh.comm, problem)
solver.error_on_nonconvergence = False
ksp = solver.krylov_solver
opts = PETSc.Options()
option_prefix = ksp.getOptionsPrefix()
opts[f"{option_prefix}ksp_type"] = "preonly"
opts[f"{option_prefix}pc_type"] = "lu"
opts[f"{option_prefix}pc_factor_mat_solver_type"]="mumps"
ksp.setFromOptions()
print(">SOLVING...\n...")
u = fn.Function(V) # new unknown function
fn.solve(a == L, u, bc)
I’m not sure where to begin when solving this, does anyone have some insight on where to start?
Thanks in advance!