Hi everybody!
I am trying to define a function, depending on locally varyíng coefficients and on spatial coordinates, but so far without success. Here is my MWE based on a tutorial example “Defining subdomains for different materials”.
I am using FEniCSx v0.10.0.
from dolfinx import default_scalar_type
from dolfinx.fem import (
Constant,
Function,
functionspace,
)
from dolfinx.mesh import create_unit_square, locate_entitiesfrom mpi4py import MPI
mesh = create_unit_square(MPI.COMM_WORLD, 10, 10)
Q = functionspace(mesh, (“DG”, 0))def Omega_0(x):
return x[1] <= 0.5def Omega_1(x):
return x[1] >= 0.5kappa = Function(Q)
cells_0 = locate_entities(mesh, mesh.topology.dim, Omega_0)
cells_1 = locate_entities(mesh, mesh.topology.dim, Omega_1)myfunction = Function(Q)
myfunction.interpolate(lambda x: kappa*x[0])
But that does not work, the message is
UserWarning: Couldn’t map ‘f’ to a float, returning ufl object without evaluation.
I’ve figured out how to interpolate a function across subdomains and use that to create a global function. However, for my application, it would be great, if the coefficients depend on space and that the function can be interpolated with coefficients over the entire domain.
Does anyone have any idea how this might work? Is there a way? I’d really appreciate any feedback.
