Hello everyone,
I’m trying to create an adaptative mesh and for that I have to change my mesh during the computation. The problem is that I need to pass the values of a function created in the first mesh to the second mesh. I suppose this should be done by interpolation since the nodes of the two meshes do not coincide. However, when I try it, it tells me in the error that this is not implemented yet. I have also tried to make a projection on the new mesh but it does not work. I attach MWE with the mentioned cases.
#Import libraries
import dolfinx.generation
import dolfinx.fem
from mpi4py import MPI
import numpy as np
import ufl
#Creation of the first mesh
mesh1 = dolfinx.generation.RectangleMesh(MPI.COMM_WORLD, [np.array([0,0,0]), np.array([25e-6,150e-6,0])], [70,400])
#Define function space
P1 = ufl.FiniteElement("Lagrange", mesh1.ufl_cell(), 1)
ME1 = dolfinx.fem.FunctionSpace(mesh1,ufl.MixedElement([P1, P1]))
# Define functions
u1 = dolfinx.fem.Function(ME1)
# Split mixed functions
c1, eta1 = ufl.split(u1)
#Interpolate a function
u1.sub(0).interpolate(lambda x: 1/(1+ufl.e**(2e6*(x[1]-0.9*150e-6))))
u1.sub(1).interpolate(lambda x: 1/(1+ufl.e**(1.6e6*(x[1]-0.9*150e-6))))
u1.x.scatter_forward()
#Creation of the second mesh with different number of nodes
mesh2 = dolfinx.generation.RectangleMesh(MPI.COMM_WORLD, [np.array([0,0,0]), np.array([25e-6,150e-6,0])], [80,500])
#Define function space
P2 = ufl.FiniteElement("Lagrange", mesh2.ufl_cell(), 1)
ME2 = dolfinx.fem.FunctionSpace(mesh2,ufl.MixedElement([P2, P2]))
# Define functions
u2 = dolfinx.fem.Function(ME2)
# Split mixed functions
c2, eta2 = ufl.split(u2)
#First option --RuntimeError: Interpolation on different meshes not supported (yet).
u1.sub(0).interpolate(u2.sub(0))
#Second option -- Kernel restarted
def project(expression, V):
dx = ufl.dx(V.mesh)
u_, v_ = ufl.TrialFunction(V), ufl.TestFunction(V)
a_p = ufl.inner(u_, v_) * dx
L_p = ufl.inner(expression, v_) * dx
projection = dolfinx.fem.LinearProblem(a_p, L_p)
return projection.solve()
V2 = dolfinx.fem.FunctionSpace(mesh2,P2)
c2 = project(c1, V2)
I would like to know if there is a way to do this in dolfinx as I did in dolfin with:
u2.assign(interpolate(u1,ME2))
Thank you very much and best regards,
Jesús