@@ -133,7 +133,7 @@ def u_exact(x):
133133# and {py:func}`ufl.TestFunctions` as one would do with a {py:func}`basix.ufl.mixed_element`.
134134# ```
135135
136- if dolfinx .__version__ == "0.8.0" :
136+ if Version ( dolfinx .__version__ ) == Version ( "0.8.0" ) :
137137 u = ufl .TrialFunction (V )
138138 lmbda = ufl .TrialFunction (R )
139139 du = ufl .TestFunction (V )
@@ -169,24 +169,24 @@ def u_exact(x):
169169# We can now assemble the matrix and vector usig {py:func}`dolfinx.fem.petsc.assemble_matrix`
170170# and {py:func}`dolfinx.fem.petsc.assemble_vector`.
171171
172- try :
172+ if Version ( dolfinx . __version__ ) < Version ( "0.10.0" ) :
173173 A = dolfinx .fem .petsc .assemble_matrix_block (a_compiled )
174- except AttributeError :
174+ else :
175175 A = dolfinx .fem .petsc .assemble_matrix (a_compiled )
176176A .assemble ()
177177
178178
179- # On the main branch of DOLFINx, the `assemble_vector` function for blocked spaces has been rewritten to reflect how
179+ # In DOLFINx>=v0.10.0 , the `assemble_vector` function for blocked spaces has been rewritten to reflect how
180180# it works for standard assembly and `nest` assembly. This means that lifting is applied manually.
181181# In this case, with no Dirichlet BC, we could skip those steps.
182182# However, for clarity we include them here.
183183
184184bcs = []
185- main_assembly = False
186- try :
185+
186+
187+ if Version (dolfinx .__version__ ) < Version ("0.10.0" ):
187188 b = dolfinx .fem .petsc .assemble_vector_block (L_compiled , a_compiled , bcs = bcs )
188- except AttributeError :
189- main_assembly = True
189+ else :
190190 b = dolfinx .fem .petsc .assemble_vector (L_compiled , kind = "mpi" )
191191 apply_lifting_and_set_bc (b , a_compiled , bcs = bcs )
192192
@@ -197,7 +197,7 @@ def u_exact(x):
197197# +
198198uh = dolfinx .fem .Function (V , name = "u" )
199199
200- if main_assembly :
200+ if Version ( dolfinx . __version__ ) >= Version ( "0.10.0" ) :
201201 # We start by inserting the value in the real space
202202 rh = dolfinx .fem .Function (R )
203203 rh .x .array [0 ] = h
@@ -239,7 +239,7 @@ def u_exact(x):
239239pc .setType ("lu" )
240240pc .setFactorSolverType ("mumps" )
241241
242- if main_assembly :
242+ if Version ( dolfinx . __version__ ) >= Version ( "0.10.0" ) :
243243 xh = b .duplicate ()
244244else :
245245 xh = dolfinx .fem .petsc .create_vector_block (L_compiled )
@@ -251,7 +251,7 @@ def u_exact(x):
251251# Finally, we extract the solution u from the blocked system and compute the error
252252
253253uh = dolfinx .fem .Function (V , name = "u" )
254- if main_assembly :
254+ if Version ( dolfinx . __version__ ) >= Version ( "0.10.0" ) :
255255 dolfinx .fem .petsc .assign (xh , [uh , rh ])
256256else :
257257 x_local = get_local_vectors (xh , maps )
@@ -280,7 +280,6 @@ def u_exact(x):
280280# +
281281vtk_mesh = dolfinx .plot .vtk_mesh (V )
282282
283- pyvista .start_xvfb (1.0 )
284283grid = pyvista .UnstructuredGrid (* vtk_mesh )
285284grid .point_data ["u" ] = uh .x .array .real
286285
0 commit comments