Hello,
I am trying to run the code below but receive a shape mismatch error when trying to state the variational problem. I am very confused by this. Any help would be greatly appreciated.
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from dolfinx import mesh, fem, io, plot, la
import pyvista
from dolfinx import plot
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)
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 + sin(x)
##setting up the variational problem
from ufl import (TestFunction, SpatialCoordinate, TrialFunction,
as_vector, dx, grad, inner, system, equation)
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
#f = fem.Constant(domain, 0.0)
D = fem.Constant(domain, 1.0) ##difusion constant
dt = fem.Constant(domain, 0.05)
##define the variational problem
L= vel(u)inner(ufl.grad(u),v)dx + vel(u)vdx + Dinner(grad(u),grad(v)) - Dgrad(u)vdx
a= v*(u-un)dtdx - v*dx
#variational problem stated as a=L
(a, L) = system(ufl.equation(a==L))