Hi everyone,
I am facing problem in implementation of time dependent non linear pde. The following error I am getting.
Traceback (most recent call last):
File “demo_nonlinear-poisson.py”, line 79, in
J = derivative(F , u)
File “/usr/lib/python3/dist-packages/dolfin/fem/formmanipulations.py”, line 80, in derivative
raise RuntimeError(“Computing derivative of form w.r.t. ‘{}’. Supply Function as a Coefficient”.format(u))
RuntimeError: Computing derivative of form w.r.t. ‘v_1’. Supply Function as a Coefficient
Here is my full code :
import matplotlib.pyplot as plt
from fenics import *
import numpy as np
import time
T = 1.0 # final time
num_steps = 10 # number of time steps
dt = T / num_steps # time step size
if has_linear_algebra_backend(“Epetra”):
parameters[“linear_algebra_backend”] = “Epetra”
def boundary(x, on_boundary):
return on_boundary
Create mesh and define function space
mesh = UnitSquareMesh(32, 32)
File(“mesh.pvd”) << mesh
V = FunctionSpace(mesh, “CG”, 1)
u_0 = Expression(‘x[0]x[1](x[0]-1)*(x[1]-1)’, degree=1)
u_n = interpolate(u_0,V)
Define boundary condition
bc = DirichletBC(V, Constant(0) , boundary)
Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression('2x[1](1-x[1]) + 2x[1]x[1]x[1](x[1]-1)(x[1]-1)(x[1]-1)x[0](1-x[0])(5x[0]x[0]-5x[0]+1) + 2x[0](1-x[0]) +2x[0]x[0]x[0](x[0]-1)(x[0]-1)(x[0]-1)x[1](1-x[1])(5x[1]x[1]-5x[1]+1) + x[0]x[1](x[0]-1)(x[0]-1)exp(t)’, degree=2 , t=0)
F = uvdx + dt*inner((1 + u**2)*grad(u), grad(v))dx - (u_n + dtf)vdx
J = derivative(F , u)
Save solution in VTK format
file = File(“nonlinear_poisson.pvd”)
u = Function(V)
t = 0
for n in range(num_steps):
t += dt
Compute solution
solve(F == 0, u, bc)
file << (u,t)
plot(u)
plt.show()
u_n.assign(u)
Thank You in advance.