@@ -87,12 +87,22 @@ def elem_node(elements, nodes):
8787 return op2 .Map (elements , nodes , 3 , elem_node_map , "elem_node" )
8888
8989
90- @pytest .fixture ( scope = 'module' )
90+ @pytest .fixture
9191def mat (elem_node , dnodes ):
9292 sparsity = op2 .Sparsity ((dnodes , dnodes ), (elem_node , elem_node ), name = "sparsity" )
9393 return op2 .Mat (sparsity , valuetype , "mat" )
9494
9595
96+ @pytest .fixture
97+ def mass_mat (mass , elements , mat , coords , elem_node ):
98+ mat .zero ()
99+ op2 .par_loop (mass , elements ,
100+ mat (op2 .INC , (elem_node , elem_node )),
101+ coords (op2 .READ , elem_node ))
102+ mat .assemble ()
103+ return mat
104+
105+
96106@pytest .fixture
97107def coords (dvnodes ):
98108 coord_vals = np .asarray ([(0.0 , 0.0 ), (2.0 , 0.0 ),
@@ -101,7 +111,7 @@ def coords(dvnodes):
101111 return op2 .Dat (dvnodes , coord_vals , valuetype , "coords" )
102112
103113
104- @pytest .fixture ( scope = 'module' )
114+ @pytest .fixture
105115def g (request ):
106116 return op2 .Global (1 , 1.0 , np .float64 , "g" )
107117
@@ -118,18 +128,28 @@ def f_vec(dvnodes):
118128 return op2 .Dat (dvnodes , f_vals , valuetype , "f" )
119129
120130
121- @pytest .fixture ( scope = 'module' )
131+ @pytest .fixture
122132def b (dnodes ):
123133 b_vals = np .zeros (NUM_NODES , dtype = valuetype )
124134 return op2 .Dat (dnodes , b_vals , valuetype , "b" )
125135
126136
127- @pytest .fixture ( scope = 'module' )
137+ @pytest .fixture
128138def b_vec (dvnodes ):
129139 b_vals = np .zeros (NUM_NODES * 2 , dtype = valuetype )
130140 return op2 .Dat (dvnodes , b_vals , valuetype , "b" )
131141
132142
143+ @pytest .fixture
144+ def b_rhs (b , rhs , elements , coords , f , elem_node ):
145+ b .zero ()
146+ op2 .par_loop (rhs , elements ,
147+ b (op2 .INC , elem_node ),
148+ coords (op2 .READ , elem_node ),
149+ f (op2 .READ , elem_node ))
150+ return b
151+
152+
133153@pytest .fixture
134154def x (dnodes ):
135155 x_vals = np .zeros (NUM_NODES , dtype = valuetype )
@@ -667,11 +687,10 @@ def test_assemble_rhs(self, rhs, elements, b, coords, f,
667687 eps = 1.e-12
668688 assert_allclose (b .data , expected_rhs , eps )
669689
670- def test_solve (self , mat , b , x , f ):
690+ def test_solve (self , mass_mat , b_rhs , x , f ):
671691 """Solve a linear system where the solution is equal to the right-hand
672692 side and check the result."""
673- mat .assemble ()
674- x = np .linalg .solve (mat .values , b .data )
693+ x = np .linalg .solve (mass_mat .values , b_rhs .data )
675694 eps = 1.e-8
676695 assert_allclose (x , f .data , eps )
677696
@@ -699,7 +718,6 @@ def test_set_matrix(self, mat, elements, elem_node,
699718 g (op2 .READ ))
700719 mat .assemble ()
701720 assert mat .values .sum () == (3 * 3 - 2 ) * elements .size
702- mat .zero ()
703721
704722 def test_zero_rhs (self , b , zero_dat , nodes ):
705723 """Test that the RHS is zeroed correctly."""
@@ -743,32 +761,35 @@ def test_rhs_ffc_itspace(self, rhs_ffc_itspace, elements, b,
743761 eps = 1.e-6
744762 assert_allclose (b .data , expected_rhs , eps )
745763
746- def test_zero_rows (self , mat , expected_matrix ):
764+ def test_zero_rows (self , mass_mat , expected_matrix ):
747765 """Zeroing a row in the matrix should set the diagonal to the given
748766 value and all other values to 0."""
749767 expected_matrix [0 ] = [12.0 , 0.0 , 0.0 , 0.0 ]
750- mat .zero_rows ([0 ], 12.0 )
768+ mass_mat .zero_rows ([0 ], 12.0 )
751769 eps = 1.e-5
752- assert_allclose (mat .values , expected_matrix , eps )
770+ assert_allclose (mass_mat .values , expected_matrix , eps )
753771
754- def test_zero_rows_subset (self , nodes , mat , expected_matrix ):
772+ def test_zero_rows_subset (self , nodes , mass_mat , expected_matrix ):
755773 """Zeroing rows in the matrix given by a :class:`op2.Subset` should
756774 set the diagonal to the given value and all other values to 0."""
757775 expected_matrix [0 ] = [12.0 , 0.0 , 0.0 , 0.0 ]
758776 ss = op2 .Subset (nodes , [0 ])
759- mat .zero_rows (ss , 12.0 )
760- assert_allclose (mat .values , expected_matrix , 1e-5 )
777+ mass_mat .zero_rows (ss , 12.0 )
778+ assert_allclose (mass_mat .values , expected_matrix , 1e-5 )
761779
762- def test_zero_last_row (self , mat , expected_matrix ):
780+ def test_zero_last_row (self , nodes , mass_mat , expected_matrix ):
763781 """Zeroing a row in the matrix should set the diagonal to the given
764782 value and all other values to 0."""
783+ expected_matrix [0 ] = [12.0 , 0.0 , 0.0 , 0.0 ]
784+ ss = op2 .Subset (nodes , [0 ])
785+ mass_mat .zero_rows (ss , 12.0 )
786+
765787 which = NUM_NODES - 1
766- # because the previous test zeroed the first row
767788 expected_matrix [0 ] = [12.0 , 0.0 , 0.0 , 0.0 ]
768789 expected_matrix [which ] = [0.0 , 0.0 , 0.0 , 4.0 ]
769- mat .zero_rows ([which ], 4.0 )
790+ mass_mat .zero_rows ([which ], 4.0 )
770791 eps = 1.e-5
771- assert_allclose (mat .values , expected_matrix , eps )
792+ assert_allclose (mass_mat .values , expected_matrix , eps )
772793
773794 def test_mat_nbytes (self , mat ):
774795 """Check that the matrix uses the amount of memory we expect."""
0 commit comments