Thank you. When i try a simple 2d square mesh. I want to double the mesh point per side. and it gives me error. And sorry my version on the virtual environment is Dolfinx version: 0.5.2.
Traceback (most recent call last):
File “finer-mesh.py”, line 59, in
u1.interpolate(u0)
File “miniconda/envs/fenicsx-env/lib/python3.10/site-packages/dolfinx/fem/function.py”, line 343, in interpolate
_interpolate(u, cells)
File “miniconda/envs/fenicsx-env/lib/python3.10/functools.py”, line 889, in wrapper
return dispatch(args[0].class)(*args, **kw)
File “miniconda/envs/fenicsx-env/lib/python3.10/site-packages/dolfinx/fem/function.py”, line 324, in _
self._cpp_object.interpolate(u._cpp_object, cells)
RuntimeError: Interpolation on different meshes not supported (yet).
The below is the code:
#import cffi
import numpy as np
#import pytest
import ufl
from dolfinx.fem import (Function, FunctionSpace, TensorFunctionSpace,
VectorFunctionSpace, assemble_scalar, form)
from dolfinx.geometry import (BoundingBoxTree, compute_colliding_cells,
compute_collisions)
from dolfinx.mesh import (CellType, create_mesh, create_unit_cube,
create_unit_square, locate_entities_boundary,
meshtags)
from mpi4py import MPI
from petsc4py import PETSc
import dolfinx
import numpy as np
from mpi4py import MPI
from petsc4py import PETSc
import dolfinx
from dolfinx import fem, mesh, io
from dolfinx.fem import Constant
from dolfinx.fem.assemble import assemble_matrix, create_vector, assemble_vector, apply_lifting, set_bc, assemble_scalar
import ufl
**n_nodes = 10 **
nx = n_nodes
ny = n_nodes
**mesh0 = mesh.create_rectangle(MPI.COMM_WORLD, [np.array([-1.0, -1.0]), np.array([1.0, 1.0])], [nx, ny], dolfinx.cpp.mesh.CellType.triangle) **
mesh1 = mesh.create_rectangle(MPI.COMM_WORLD, [np.array([-1.0, -1.0]), np.array([1.0, 1.0])], [2nx, 2ny], dolfinx.cpp.mesh.CellType.triangle)
def f(x):
return (7 * x[1], x[2] + 0.4)
el0 = ufl.VectorElement(“Lagrange”, mesh0.ufl_cell(), 1, dim=2)
V0 = FunctionSpace(mesh0, el0)
el1 = ufl.VectorElement(“Lagrange”, mesh1.ufl_cell(), 1, dim=2)
V1 = FunctionSpace(mesh1, el1)
Interpolate on 3D mesh
u0 = Function(V0)
u0.interpolate(f)
u0.x.scatter_forward()
Interpolate 3D->2D
u1 = Function(V1)
u1.interpolate(u0)
u1.x.scatter_forward()
Exact interpolation on 2D mesh
u1_ex = Function(V1)
u1_ex.interpolate(f)
u1_ex.x.scatter_forward()
assert np.allclose(u1_ex.x.array, u1.x.array)