Skip to content

Commit

Permalink
Fix cffi_utils for non abscence of petsc4py
Browse files Browse the repository at this point in the history
  • Loading branch information
schnellerhase committed Jul 18, 2024
1 parent fe7f279 commit acd43c7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions python/dolfinx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ctypes as _ctypes
import os
import pathlib
import warnings

import numpy as np

Expand Down Expand Up @@ -193,18 +194,24 @@ def set_vals(A: int,
ffi.from_buffer(rows(data), mode)
"""

try:
from petsc4py import PETSc as _PETSc
import cffi as _cffi

_ffi = _cffi.FFI()

import cffi as _cffi
try:
import numba as _numba
import numba.core.typing.cffi_utils as _cffi_support

# Register complex types
_ffi = _cffi.FFI()
_cffi_support.register_type(_ffi.typeof("float _Complex"), _numba.types.complex64)
_cffi_support.register_type(_ffi.typeof("double _Complex"), _numba.types.complex128)

except ImportError:
warnings.warn("Could not import numba, so complex types are not registered!", ImportWarning)

try:
from petsc4py import PETSc as _PETSc

_lib_cffi = _ffi.dlopen(str(get_petsc_lib()))

_CTYPES = {
Expand Down Expand Up @@ -238,5 +245,7 @@ def set_vals(A: int,
"""See PETSc `MatSetValuesBlockedLocal
<https://petsc.org/release/manualpages/Mat/MatSetValuesBlockedLocal>`_
documentation."""
except (ImportError, KeyError):
pass
except ImportError:
warnings.warn(
"Could not import petsc4py, so numba petsc overloads are not available!", ImportWarning
)

0 comments on commit acd43c7

Please sign in to comment.