@@ -208,26 +208,6 @@ def test_petsc_cast():
208208 '(PetscScalar (*)[info.gym][info.gxm]) x_f3_vec;' in str (op3 .ccode )
209209
210210
211- # # TODO: add more thorough tests for solver_parameters
212- # # @skipif('petsc')
213- # # def test_LinearSolveExpr():
214-
215- # # grid = Grid((2, 2), dtype=np.float64)
216-
217- # # f = Function(name='f', grid=grid, space_order=2)
218- # # g = Function(name='g', grid=grid, space_order=2)
219-
220- # # eqn = Eq(f, g.laplace)
221-
222- # # linsolveexpr = LinearSolveExpr(eqn.rhs, field_data=FieldData(target=f))
223-
224- # # # Check the solver parameters
225- # # assert linsolveexpr.solver_parameters == \
226- # # {'snes_type': 'ksponly', 'ksp_type': 'gmres', 'pc_type': 'none',
227- # # 'ksp_rtol': 1e-05, 'ksp_atol': 1e-50, 'ksp_divtol': 100000.0,
228- # # 'ksp_max_it': 10000}
229-
230-
231211@skipif ('petsc' )
232212def test_dmda_create ():
233213
@@ -794,7 +774,7 @@ def test_coupled_vs_non_coupled(self, eq1, eq2, so):
794774 # less callback functions than solving them separately.
795775 # TODO: As noted in the other test, some efuncs are not reused
796776 # where reuse is possible, investigate.
797- assert len (callbacks1 ) == 10
777+ assert len (callbacks1 ) == 12
798778 assert len (callbacks2 ) == 8
799779
800780 # Check field_data type
@@ -1494,8 +1474,11 @@ def test_logging_multiple_solves(self):
14941474class TestSolverParameters :
14951475
14961476 @skipif ('petsc' )
1497- def setup_method (self ):
1498- """Setup grid and functions shared across tests in this class"""
1477+ def setup_class (self ):
1478+ """
1479+ Setup grid, functions and equations shared across
1480+ tests in this class
1481+ """
14991482 grid = Grid (shape = (11 , 11 ), dtype = np .float64 )
15001483 self .e , self .f , self .g , self .h = [
15011484 Function (name = n , grid = grid , space_order = 2 )
@@ -1506,44 +1489,27 @@ def setup_method(self):
15061489
15071490 @skipif ('petsc' )
15081491 def test_differing_solver_params (self ):
1509- """
1510- """
1492+ # Explicitly set the solver parameters
15111493 solver1 = PETScSolve (
15121494 self .eq1 , target = self .e , solver_parameters = {'ksp_rtol' : '1e-10' }
15131495 )
1496+ # This solver uses the defaults
15141497 solver2 = PETScSolve (self .eq2 , target = self .g )
15151498
15161499 with switchconfig (language = 'petsc' ):
15171500 op = Operator ([solver1 , solver2 ])
15181501
15191502 # Check that there are two `SetPetscOptions` callbacks since the solver
1520- # parameters are different for each solver.
1503+ # parameters are different for each solver
15211504 assert 'SetPetscOptions0' in op ._func_table
15221505 assert 'SetPetscOptions1' in op ._func_table
15231506
1524- assert 'PetscCall(PetscOptionsSetValue(NULL,"-ksp_rtol" ,"1e-10")); ' \
1507+ assert '_ksp_rtol" ,"1e-10"' \
15251508 in str (op ._func_table ['SetPetscOptions0' ].root )
15261509
1527- assert 'PetscCall(PetscOptionsSetValue(NULL,"-ksp_rtol" ,"1e-05")); ' \
1510+ assert '_ksp_rtol" ,"1e-05"' \
15281511 in str (op ._func_table ['SetPetscOptions1' ].root )
15291512
1530- @skipif ('petsc' )
1531- def test_options_with_no_value (self ):
1532- """
1533- Test solver parameters that do not require a value, such as
1534- `snes_view`.
1535- """
1536- solver1 = PETScSolve (
1537- self .eq1 , target = self .e , solver_parameters = {'snes_view' : None }
1538- )
1539-
1540- with switchconfig (language = 'petsc' ):
1541- op = Operator (solver1 )
1542- op .apply ()
1543-
1544- assert 'PetscCall(PetscOptionsSetValue(NULL,"-snes_view",NULL));' \
1545- in str (op ._func_table ['SetPetscOptions0' ].root )
1546-
15471513 @skipif ('petsc' )
15481514 def test_options_prefix (self ):
15491515 solver1 = PETScSolve (self .eq1 , self .e ,
@@ -1556,7 +1522,7 @@ def test_options_prefix(self):
15561522 with switchconfig (language = 'petsc' ):
15571523 op = Operator ([solver1 , solver2 ])
15581524
1559- # Check the options prefix has been correctly set on each snes solver
1525+ # Check the options prefix has been correctly set for each snes solver
15601526 assert 'PetscCall(SNESSetOptionsPrefix(snes0,"poisson1_"));' in str (op )
15611527 assert 'PetscCall(SNESSetOptionsPrefix(snes1,"poisson2_"));' in str (op )
15621528
@@ -1567,6 +1533,24 @@ def test_options_prefix(self):
15671533 assert 'PetscCall(PetscOptionsSetValue(NULL,"-poisson2_ksp_rtol","1e-12"));' \
15681534 in str (op ._func_table ['SetPetscOptions1' ].root )
15691535
1536+
1537+ @skipif ('petsc' )
1538+ def test_options_with_no_value (self ):
1539+ """
1540+ Test solver parameters that do not require a value, such as
1541+ `snes_view` and `ksp_view`
1542+ """
1543+ solver = PETScSolve (
1544+ self .eq1 , target = self .e , solver_parameters = {'snes_view' : None },
1545+ options_prefix = 'solver1'
1546+ )
1547+ with switchconfig (language = 'petsc' ):
1548+ op = Operator (solver )
1549+ op .apply ()
1550+
1551+ assert 'PetscCall(PetscOptionsSetValue(NULL,"-solver1_snes_view",NULL));' \
1552+ in str (op ._func_table ['SetPetscOptions0' ].root )
1553+
15701554 @skipif ('petsc' )
15711555 @pytest .mark .parametrize ('log_level' , ['PERF' , 'DEBUG' ])
15721556 def test_tolerances (self , log_level ):
@@ -1594,11 +1578,11 @@ def test_tolerances(self, log_level):
15941578 assert tolerances ['maxits' ] == params ['ksp_max_it' ]
15951579
15961580
1597-
15981581 # TODO: ADD TEST TO CHECK FOR DEFAULT LINEAR SOLVER PARAMETERS
15991582 # TODO: add test to check that the correct options are unset properly
16001583 # TODO: Add a test to check that the command line args override anything set
16011584 # in the solver_parameters dictionary
1585+ # TODO: add hashing tests to petscsolve
16021586
16031587 # @skipif('petsc')
16041588 # def test_command_line_priority(self):
0 commit comments