Hello, I am trying to use FEniCsX to solve a time-dependent PDE with a non-linear coefficient. However, I am getting an error stating: “ValueError: Found Argument in Cos id=6262508512, this is an invalid expression.” …when I formulate my variational problem (a,L)=system(F)
. I am wondering if this is because system() sets up a linear system to solve with a linear solver? Also can NonLinearSolver() be used to solve time-dependent PDEs? My PDE is essentially a Fokker-plank equation with a non-linear drift (or velocity) term. Please find my code below. Any help/clarification would be greatly appreciated. Thanks in advance!
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from dolfinx import mesh, fem, io, plot, la
import pyvista
import ufl
import numpy as np
from dolfinx import *
import dolfinx
import numpy, sys
from mpi4py import MPI
from petsc4py import PETSc
from ufl import (VectorElement, FiniteElement,
SpatialCoordinate, TrialFunction, TestFunction,
as_vector, cos, sin, inner, div, grad, dx, pi, system)
from dolfinx import mesh, fem, io, nls, log
from dolfinx.fem.petsc import NonlinearProblem
from dolfinx.nls.petsc import NewtonSolver
##cretae a rectangular mesh with quadrilateral elements
##note: here theta=x
from mpi4py import MPI
length, height = 10, 3
Nx, Ny = 80, 60
extent = [[0., 0.], [length, height]]
domain = mesh.create_rectangle(
MPI.COMM_WORLD, extent, [Nx, Ny], mesh.CellType.quadrilateral)
##define the non-linear coeff
omega=(np.pi/2)
##define the non-linear coefficient
def vel(x):
return omega + cos(x)
##setting up the variational problem
from ufl import (TestFunction, SpatialCoordinate, TrialFunction,
as_vector, dx, grad, inner, system, equation, Constant)
V = fem.FunctionSpace(domain, ("Lagrange", 1))
u = TrialFunction(V) ##time-dep c at n+1
v = TestFunction(V)
un = fem.Function(V) ##time dep C at n
D= fem.Constant(domain, 1.0) ##diffusion constant
dt = fem.Constant(domain, 0.05)
##define the variational problem
F= (un*v*ufl.dx) - (v*ufl.dx) ##note: i think it should be L=un*v -v*dx
F-= u*dx - v*dx - vel(u)*u*v*dt*dx - D*dt*inner(grad(u), grad(v))*dx + D*dt*v*dx
#variational problem stated as a=L
(a,L)=system(F)```