Dear everyone,
I have been using different versions of a mesh, and it was working well. Now, I am having issues when projecting. All I get are np.inf
. If anybody has the time to look at this, I would appreciate it. Thanks in advance, and sorry if it is too simple.
MWE
import ufl
import basix
import dolfinx
from dolfinx import fem
from dolfinx import mesh
import dolfinx.fem.petsc
from mpi4py import MPI
from dolfinx import default_scalar_type as num_type
# dolfinx_cyclic_vM_project.py
def project(v, target_func, bc=[]) -> fem.petsc.LinearProblem:
"""Project UFL expression.
Copyright
---------
SPDX-License-Identifier: GPL-3.0-only
(GNU Public License version 3.0)
This function was modified from dolfiny (MIT license)
Michal Habera, michal.habera@uni.lu,
Andreas Zilian, andreas.zilian@uni.lu.
See also
--------
https://hplgit.github.io/INF5620/doc/pub/H14/fem/html/._main_fem003.html#___sec9
https://fenicsproject.discourse.group/t/how-to-compute-the-strain-stress-matrices/2756/7
"""
petsc = fem.petsc
# Ensure we have a mesh and attach to measure
V = target_func.function_space
dx = ufl.dx(V.mesh)
# Define variational problem for projection
w = ufl.TestFunction(V)
Pv = ufl.TrialFunction(V)
a = ufl.inner(Pv, w) * dx
L = ufl.inner(v, w) * dx
problem = petsc.LinearProblem(
a, L, bcs=bc, u=target_func,
petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
problem.solve()
return problem
domain = dolfinx.io.gmshio.read_from_msh(
"my_mesh.msh", comm=MPI.COMM_WORLD)[0]
# # This works ##############################
# domain = mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
# #########################################
# 589
msh_cell_type = domain.basix_cell()
# 599
Ve_quad_scal = basix.ufl.quadrature_element(
msh_cell_type, value_shape=(), degree=2)
V_quad_scal = fem.functionspace(domain, Ve_quad_scal)
# 605
p = fem.Function(V_quad_scal)
p.x.array[:] = range(len(p.x.array))
# 746
Ve_dg_scal = basix.ufl.element(
"Discontinuous Lagrange", msh_cell_type, degree=2,
shape=())
V_dg_scal = fem.functionspace(domain, Ve_dg_scal)
p_dg_scal = fem.Function(V_dg_scal, dtype=num_type)
p_dg_scal_project = project(p, p_dg_scal)
p_dg_scal.x.array
# array([inf, inf, inf, ..., inf, inf, inf])
My system
- FEniCSx software
dolfinx: 0.8.0_r27835.5a20e2b-1
basix: 0.8.0_r1067.0ed41b0-1
ufl: 2024.2.0.dev0_r3610.72a1bfa-1
ffcx: 0.8.0_r7150.38260c0-1
- Dependencies
adios2: 2.10.0-2
blas-openblas: 0.3.26-3
boost: 1.83.0-7
chrpath: 0.17-1
cmake: 3.29.2-1
cython: 3.0.10-3
eigen: 3.4.0-2
glew: 2.2.0-6
gcc-fortran: 13.2.1-6
hdf5-openmpi: 1.14.3-3
ninja: 1.12.0-2
openmpi: 5.0.3-1
parallel: 20240322-1
pybind11: 2.12.0-4
python-anyio: 4.3.0-3
python-build: 1.2.1-3
python-cattrs: 23.2.3-3
python-cffi: 1.16.0-2
python-docutils:
python-fsspec:
python-hatch-fancy-pypi-readme: 24.1.0-3
python-hatch-vcs: 0.4.0-3
python-hatchling: 1.24.2-1
python-installer: 0.7.0-8
python-mako: 1.3.3-2
python-mpi4py: 3.1.5-5
python-numpy: 1.26.4-2
python-pathspec: 0.12.1-2
python-pygments: 2.17.2-3
python-pyproject-metadata: 0.8.0-1
python-pytest: 1:8.1.2-1
python-pytest-asyncio: 0.23.6-2
python-pytest-rerunfailures: 14.0-2
python-pyvista: 0.43.4.r0.g3d6e327a7-1
python-rich: 13.7.1-2
python-scikit-build: 0.17.6-3
python-scipy: 1.13.0-2
python-setuptools-scm: 8.0.4-3
python-sphinx:
python-sympy: 1.12.1rc1-1
python-virtualenv: 20.25.0-3
python-wheel: 0.43.0-4
pugixml: 1.14-1
sowing: 1.1.26.9-1
superlu: 6.0.1-1
nanobind: 1.9.2-1
petsc: 3.21.0-1
python-cppimport: 22.08.02-2
python-imageio: 2.34.1-2
python-imageio-ffmpeg: 0.4.9-1
python-meshio: 5.3.5-2
python-scikit-build-core: 0.8.2-1
python-setuptools: 1:69.0.3-6
python-tifffile: 2024.5.3-1
python-wheel: 0.43.0-4
superlu_dist: 8.1.2-1
- Insight-toolkit & dependencies
castxml: 0.6.4-1
eigen: 3.4.0-2
expat: 2.6.2-1
gcc-libs: 13.2.1-6
gdcm: 3.0.12-1
glibc: 2.39-4
hdf5: 1.14.3-3
insight-toolkit: 5.4.0.rc04-1
libjpeg-turbo: 3.0.2-2
libpng: 1.6.43-1
libtiff: 4.6.0-4
meson-python: 0.16.0-3
openjpeg2: 2.5.2-1
openmp: 17.0.6-2
python-flit-core: 3.9.0-4
python-itk-elastix: 5.4.0.rc04-1
python-networkx: 3.3-1
python-pythran: 0.16.0-1
swig: 4.2.1-3
zlib: 1:1.3.1-2
- Others
python-scooby: 0.10.0-1
python-lazy-loader: 0.4-1
python-scikit-image: 0.23.2-1
paraview: 5.12.1-8
dcmtk: 3.6.8-1
python-tifffile: 2024.5.3-1
mumps: 5.7.1-1
hypre: 2.31.0-1
metis: 5.2.1-2
scalapack: 2.2.0-1
superlu_dist: 8.1.2-1
gklib: 5.1.1-4
mfront: 20240324.r2770.1e94d01fd-1
libfyaml: 0.9-1
- Operating system
Arch Linux: 6.9.0-rc6-gnu-rc6
CPU: 12th Gen Intel(R) Core(TM) i7-1260P
I could not upload the mesh file (the link will expire on the 18th of July 2024):