I’m trying to set all nodes to the same initial condition, which is a constant.
However, I cannot figure out why I keep getting TypeError: interpolate(): incompatible function arguments. How exactly should I interpolate a constant to all nodes?
The same error persists even without two function spaces (which I created as only 2 of 5 variables are time-dependent. Would appreciate any advice on whether this is a wise option or whether I should just put dummy variables in place too!).
Dolfinx installed via conda on Mac M1 Monterey.
Thank you!
Below is the code:
import ufl
from dolfinx import mesh, fem, io, nls, log
from mpi4py import MPI
from petsc4py import PETSc
import numpy as np
xmin = -5
xmax = 5
ymax = 5
domain = mesh.create_rectangle(MPI.COMM_WORLD, [(xmin,0),(xmax,ymax)], n=[200, 50])
x = ufl.SpatialCoordinate(domain)
degree = 3
P1 = ufl.FiniteElement("Lagrange", domain.ufl_cell(), degree)
element = ufl.MixedElement([P1, P1, P1, P1, P1]) #create a mixed function space
V = fem.FunctionSpace(domain, element)
#we create another function space for the t dependent h1 and h2 only
element2 = ufl.MixedElement([P1, P1])
W = fem.FunctionSpace(domain, element2)
v1, v2, v3, v4, v5 = ufl.TestFunctions(V)
u = fem.Function(V)
u_n = fem.Function(W) #update previous solution
h1, h2, p1, p2, ul = ufl.split(u)
h1_n, h2_n = ufl.split(u_n)
#Define constants
Hbath = 2.0
#ERROR
u.sub(0).interpolate(fem.Constant(domain, PETSc.ScalarType(Hbath)), V)
u.x.scatter_forward()