1
- import sys
2
- from firedrake .configuration import setup_cache_dirs
1
+ # The range of PETSc versions supported by Firedrake. Note that unlike in
2
+ # firedrake-configure and pyproject.toml where we want to be strict about
3
+ # the specific version, here we are more permissive. This is to catch the
4
+ # case where users don't update their PETSc for a really long time or
5
+ # accidentally install a too-new release that isn't yet supported.
6
+ PETSC_SUPPORTED_VERSIONS = ">=3.23.0"
7
+
8
+
9
+ def init_petsc ():
10
+ import os
11
+ import sys
12
+ import petsctools
13
+
14
+ # We conditionally pass '-options_left no' as in some circumstances (e.g.
15
+ # when running pytest) PETSc complains that command line options are not
16
+ # PETSc options.
17
+ if os .getenv ("FIREDRAKE_DISABLE_OPTIONS_LEFT" ) == "1" :
18
+ petsctools .init (sys .argv + ["-options_left" , "no" ], version_spec = PETSC_SUPPORTED_VERSIONS )
19
+ else :
20
+ petsctools .init (sys .argv , version_spec = PETSC_SUPPORTED_VERSIONS )
21
+
22
+
23
+ # Ensure petsc is initialised right away
24
+ init_petsc ()
3
25
4
26
# Set up the cache directories before importing PyOP2.
27
+ from firedrake .configuration import setup_cache_dirs
28
+
5
29
setup_cache_dirs ()
6
30
7
- # Ensure petsc is initialised by us before anything else gets in there.
8
- # We conditionally pass '-options_left no' as in some circumstances (e.g.
9
- # when running pytest) PETSc complains that command line options are not
10
- # PETSc options.
11
- import os
12
- import petsc4py
13
- if os .getenv ("FIREDRAKE_DISABLE_OPTIONS_LEFT" ) == "1" :
14
- petsc4py .init (sys .argv + ["-options_left" , "no" ])
15
- else :
16
- petsc4py .init (sys .argv )
17
- del os , petsc4py
18
31
19
32
# Initialise PETSc events for both import and entire duration of program
33
+ import petsctools
20
34
from firedrake import petsc
21
- _is_logging = "log_view" in petsc .OptionsManager .commandline_options
35
+ _is_logging = "log_view" in petsctools .OptionsManager .commandline_options
22
36
if _is_logging :
23
37
_main_event = petsc .PETSc .Log .Event ("firedrake" )
24
38
_main_event .begin ()
29
43
import atexit
30
44
atexit .register (lambda : _main_event .end ())
31
45
del atexit
46
+ del petsctools
32
47
del petsc
33
48
34
49
from ufl import *
85
100
# from firedrake._deprecation import output
86
101
# sys.modules["firedrake.output"] = output
87
102
from firedrake .output import *
103
+ import sys
88
104
sys .modules ["firedrake.plot" ] = plot
89
105
from firedrake .plot import *
90
106
@@ -104,7 +120,7 @@ def set_blas_num_threads():
104
120
105
121
"""
106
122
from ctypes import cdll
107
- from firedrake . petsc import get_blas_library
123
+ from petsctools import get_blas_library
108
124
109
125
try :
110
126
blas_lib_path = get_blas_library ()
0 commit comments