Hi,guys!As the title suggests.I want interpolate on different grids.
As code shows:I want to interpolate the function u1 on a coarse grid to the function u2 on a fine grid.
from mpi4py import MPI
from petsc4py import PETSc
import numpy as np
from dolfinx import default_real_type, fem, io, mesh,default_scalar_type
from dolfinx.fem.petsc import assemble_matrix, assemble_vector
from ufl import (CellDiameter, FacetNormal, TestFunction, TrialFunction, avg,
conditional, div, dot, dS, ds, dx, grad, gt, inner, outer,
TrialFunctions,TestFunctions,curl,cross)
import ufl
from dolfinx.io import gmshio,XDMFFile
from basix.ufl import element,mixed_element
from dolfinx.fem.petsc import (apply_lifting, assemble_matrix, assemble_vector,
create_vector, set_bc,create_matrix)
import time
import os
import dolfinx
from dolfinx.cpp.mesh import CellType
def initial(x):
values = np.zeros((2, x.shape[1]), dtype=PETSc.ScalarType)
values[0]=x[0]
values[1]=x[1]
return values
n1=5
n2=10
msh1 =mesh.create_unit_square(MPI.COMM_WORLD, n1, n1,cell_type=CellType.triangle) #triangle quadrilateral
msh2 =mesh.create_unit_square(MPI.COMM_WORLD, n2, n2,cell_type=CellType.triangle) #triangle quadrilateral
U1_element=element("DG", msh1.basix_cell(),1, shape=(msh1.geometry.dim,))
U2_element=element("DG", msh2.basix_cell(),1, shape=(msh1.geometry.dim,))
V1=fem.functionspace(msh1,U1_element)
V2=fem.functionspace(msh2,U2_element)
u1=fem.Function(V1)
u2=fem.Function(V2)
u1.interpolate(initial)
print(u1.x.array)
u2.interpolate(u1)
Thanks!!!