I’m trying to compute the potential \Phi of a 2D velocity field (U,W) but I’m unable to represent the source correctly and I’m getting a RuntimeError
that says Error: Unable to successfully call PETSc function 'KSPSolve'.
.
If I understand correctly the variational formulation should be
with v a vector test function.
Below are the python code and error trace. I would appreciate any hints on how to improve this code!
I’m running this from this docker image quay.io/fenicsproject/stable:current
in jupyter.
Thanks!
import fenics
import matplotlib.pyplot as plt
%matplotlib inline
mesh = fenics.UnitSquareMesh(12,12)
V = fenics.FunctionSpace(mesh, 'P', 1)
V_vec = fenics.VectorFunctionSpace(mesh, 'P', 1, dim=2)
class VelocityFieldExpression(fenics.UserExpression):
def eval(self, values, x):
values[0] = x[0]
values[1] = x[1]
def value_shape(self):
return (2,)
u = fenics.TrialFunction(V)
v = fenics.TestFunction(V_vec)
velocity = VelocityFieldExpression()
a = fenics.dot(fenics.grad(u), v)*fenics.dx
L = fenics.dot(velocity, v)*fenics.dx
phi = fenics.Function(V)
fenics.solve(a == L, phi)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-7-c19cd53db90f> in <module>
23 phi = fenics.Function(V)
24
---> 25 fenics.solve(a == L, phi)
/usr/local/lib/python3.6/dist-packages/dolfin/fem/solving.py in solve(*args, **kwargs)
218 # tolerance)
219 elif isinstance(args[0], ufl.classes.Equation):
--> 220 _solve_varproblem(*args, **kwargs)
221
222 # Default case, just call the wrapped C++ solve function
/usr/local/lib/python3.6/dist-packages/dolfin/fem/solving.py in _solve_varproblem(*args, **kwargs)
245 solver = LinearVariationalSolver(problem)
246 solver.parameters.update(solver_parameters)
--> 247 solver.solve()
248
249 # Solve nonlinear variational problem
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 successfully call PETSc function 'KSPSolve'.
*** Reason: PETSc error code is: 62 (Invalid argument).
*** Where: This error was encountered inside /tmp/dolfin/dolfin/la/PETScKrylovSolver.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.1.0
*** Git changeset: 74d7efe1e84d65e9433fd96c50f1d278fa3e3f3f
*** -------------------------------------------------------------------------
```