Solving simple non-linear diffusion equation


408
views
0
7 months ago by
Hi everyone,

I am trying to solve a simple non-linear diffusion equation. I need to use solve(F==0, bc, V). But it returns the error:

Solving nonlinear variational problem.
Newton iteration 0: r (abs) = 7.263e-02 (tol = 1.000e-10) r (rel) = 1.000e+00 (tol = 1.000e-09)
Traceback (most recent call last):
File "guassian.py", line 44, in <module>
solve(F==0, u, bc)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 300, in solve
_solve_varproblem(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 349, in _solve_varproblem
solver.solve()
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 'MatSetValuesLocal'.
*** Reason: PETSc error code is: 63 (Argument out of range).
*** Where: This error was encountered inside /build/dolfin-yRhxwC/dolfin-2017.1.0/dolfin/la/PETScMatrix.cpp.
*** Process: 0
***
*** DOLFIN version: 2017.1.0

The same error appears when I try to execute the (very slight) modified version of the heat equation example found in the FEniCS tutorial (code attached)

from fenics import *
import time

T = 2.0 # final time
num_steps = 50 # number of time steps
dt = T / num_steps # time step size

# Create mesh and define function space
nx = ny = 30
mesh = RectangleMesh(Point(-2, -2), Point(2, 2), nx, ny)
V = FunctionSpace(mesh, 'P', 1)

# Define boundary condition
def boundary(x, on_boundary):
return on_boundary

bc = DirichletBC(V, Constant(0), boundary)

# Define initial value
u_0 = Expression('exp(-a*pow(x[0], 2) - a*pow(x[1], 2))',
degree=2, a=5)
u_n = interpolate(u_0, V)

# Define variational problem
u = Function(V)
v = TestFunction(V)
f = Constant(0)

F = u*v*dx + dt*dot(grad(u), grad(v))*dx - (u_n + dt*f)*v*dx
#a, L = lhs(F), rhs(F)

# Create VTK file for saving solution
vtkfile = File('heat_gaussian/solution.pvd')

# Time-stepping
u = Function(V)
t = 0
for n in range(num_steps):

# Update current time
t += dt

# Compute solution
solve(F==0, u, bc)

# Save to file and plot solution
vtkfile << (u, t)
plot(u)

# Update previous solution
u_n.assign(u)

# Hold plot
interactive()


Can anybody help me?

Zhen
Community: FEniCS Project

1 Answer


4
7 months ago by
Just remove the second definition of the function u in the section # Time-stepping
Thank you very much!!!
written 7 months ago by zhen shao  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »