@@ -204,8 +204,87 @@ def test_PolarProjection_V1(Projector, R, ncells, degree, hbc, transposed):
204204 assert np .allclose (z [0 ][:, :], y [0 ][:, :], atol = 1e-12 , rtol = 1e-12 )
205205 assert np .allclose (z [1 ][:, :], y [1 ][:, :], atol = 1e-12 , rtol = 1e-12 )
206206
207- # Comparing the global sparse matrix to reference file
208207 sp_P1 = P1 .tosparse ()
208+ print (sp_P1 .toarray ())
209+
210+ [n01 , n02 ] = V1_h .coeff_space [0 ].npts
211+ [n11 , n12 ] = V1_h .coeff_space [1 ].npts
212+
213+ assert sp_P1 .shape == (n01 * n02 + n11 * n12 , n01 * n02 + n11 * n12 )
214+
215+ # gather sparse matrix entries (rows, columns, data) on root process
216+ payload = (sp_P1 .row , sp_P1 .col , sp_P1 .data )
217+ parts = mpi_comm .gather (payload , root = 0 )
218+
219+ if mpi_comm .rank == 0 :
220+
221+ # Concatenate the result of gather (equivalent to summation of local matrices)
222+ rows = np .concatenate ([p [0 ] for p in parts ])
223+ cols = np .concatenate ([p [1 ] for p in parts ])
224+ data = np .concatenate ([p [2 ] for p in parts ])
225+
226+ # Check the number of non-zero entries in the sparse matrix
227+ if Projector == C0PolarProjection_V1 :
228+ assert len (data ) == n01 * n02 + 2 * n02 + (n11 - (3 if hbc else 2 )) * n12
229+ else :
230+ print (len (data ))
231+ assert len (data ) == 3 * n02 * n02 + n02 * (n01 - 1 ) + (n11 - (3 if hbc else 2 )) * n12
232+
233+ if transposed :
234+ rows , cols = cols , rows
235+
236+ # Check all non-zero entries
237+ for i , j , v in zip (rows , cols , data ):
238+ if Projector == C0PolarProjection_V1 :
239+ # Block P1_00
240+ if i < n01 * n02 :
241+ # identity
242+ assert i == j
243+ assert np .isclose (v , 1.0 , atol = 1e-12 , rtol = 1e-12 )
244+ # Block P1_10
245+ elif n01 * n02 + n02 <= i < n01 * n02 + 2 * n02 :
246+ # d matrix
247+ if j == i - n02 * (n01 + 1 ):
248+ assert np .isclose (v , - 1.0 , atol = 1e-12 , rtol = 1e-12 )
249+ else :
250+ assert np .isclose (v , 1.0 , atol = 1e-12 , rtol = 1e-12 )
251+ assert j == (i - n02 * (n01 + 1 ) + 1 ) % n02
252+ # Block P1_11
253+ else :
254+ assert i >= n01 * n02 + 2 * n02
255+ assert j == i
256+ assert np .isclose (v , 1.0 , atol = 1e-12 , rtol = 1e-12 )
257+
258+ if Projector == C1PolarProjection_V1 :
259+ p_ij = 2 / n02 * np .cos ((i - j ) * 2 * np .pi / n02 )
260+ # Block P1_00
261+ if i < n02 :
262+ # matrix p
263+ assert j < n02
264+ assert np .isclose (v , p_ij , atol = 1e-12 , rtol = 1e-12 )
265+ elif 2 * n02 > i >= n02 > j :
266+ # matrix I - p
267+ if i == j + n02 :
268+ assert np .isclose (v , 1 - p_ij , atol = 1e-12 , rtol = 1e-12 )
269+ else :
270+ assert np .isclose (v , - p_ij , atol = 1e-12 , rtol = 1e-12 )
271+ elif n02 <= i < n01 * n02 :
272+ assert j == i
273+ assert np .isclose (v , 1.0 , atol = 1e-12 , rtol = 1e-12 )
274+
275+ # Block P1_10
276+ elif j < n02 :
277+ # matrix q
278+ q_ij = (2 / n02 * np .cos ((i + 1 - j ) * 2 * np .pi / n02 ) - p_ij )
279+ assert np .isclose (v , q_ij , atol = 1e-12 , rtol = 1e-12 )
280+
281+ # Block P1_11
282+ else :
283+ assert i == j
284+ assert i >= n01 * n02 + 2 * n02
285+ assert np .isclose (v , 1.0 , atol = 1e-12 , rtol = 1e-12 )
286+
287+ # Comparing the global sparse matrix to reference file
209288 sp_P1_global = mpi_comm .allreduce (sp_P1 .toarray (), op = MPI .SUM )
210289 if mpi_comm .rank == 0 :
211290 name = Projector .__name__
0 commit comments