Hi there,
I am trying to scale my vector field by some constant. But, I cannot get the correct dofs of the subdomain. Here is the MWE;
import gmsh
import numpy as np
import pyvista
from dolfinx.fem import (Constant, dirichletbc, Function, FunctionSpace, assemble_scalar,
form, locate_dofs_geometrical, locate_dofs_topological)
from dolfinx.io import XDMFFile
from dolfinx.mesh import create_unit_square, locate_entities
from ufl import VectorElement
from mpi4py import MPI
from petsc4py.PETSc import ScalarType
# pyvista.start_xvfb()
mesh = create_unit_square(MPI.COMM_WORLD, 10, 10)
# Q = FunctionSpace(mesh, ("DG", 0))
v_cg = VectorElement("CG", mesh.ufl_cell(), 1)
Q = FunctionSpace(mesh, v_cg)
def Omega_0(x):
return x[1] <= 0.3
def Omega_1(x):
return x[1] >= 0.7
kappa = Function(Q)
cells_0 = locate_entities(mesh, mesh.topology.dim, Omega_0)
cells_1 = locate_entities(mesh, mesh.topology.dim, Omega_1)
dofs_0 = locate_dofs_geometrical(Q, Omega_0)
dofs_1 = locate_dofs_geometrical(Q, Omega_1)
kappa.x.array[dofs_0] = 1
kappa.x.array[dofs_1] = 0.1
with XDMFFile(MPI.COMM_WORLD, "test.xdmf", "w", encoding=XDMFFile.Encoding.HDF5 ) as xdmf:
xdmf.write_mesh(mesh)
xdmf.write_function(kappa)
I import subdomains from gmsh and I can access the cell tags by;
cell_tags = subdomains.find(tag)
How can I access the dofs of the cell_tags
?
I get this;
whereas I should get this;
Any help would be much appreciated!