1- import os , sys
1+ import os
2+ import sys
23import numpy as np
34import pyvista as pv
45import matplotlib .pyplot as plt
1516
1617import pytest
1718
19+ # Run with:
20+ # mpiexec -n 2 python -m pytest --color=yes -v -s tests/test_007_mpi_lossy_cavity.py
21+
1822# Turn true when running local
1923flag_plot_3D = True
2024
@@ -92,7 +96,6 @@ def test_mpi_import(self):
9296 from mpi4py import MPI
9397
9498 comm = MPI .COMM_WORLD # Get MPI communicator
95- rank = comm .Get_rank () # Process ID
9699 size = comm .Get_size () # Total number of MPI processes
97100 if size > 1 :
98101 use_mpi = True
@@ -184,10 +187,12 @@ def test_mpi_simulation(self):
184187 beam .update (solver , n * solver .dt )
185188 solver .mpi_one_step ()
186189
187- Ez = solver .mpi_gather ('Ez' , x = int (Nx / 2 ), y = int (Ny / 2 ), z = np . s_ [:: 5 ] )
190+ Ez = solver .mpi_gather ('Ez' , x = int (Nx / 2 ), y = int (Ny / 2 ))
188191 if solver .rank == 0 :
189192 #print(Ez)
190- assert np .allclose (Ez , self .Ez , rtol = 0.1 ), "Electric field Ez samples MPI failed"
193+ print (len (Ez ))
194+ assert len (Ez ) == NZ , "Electric field Ez samples length mismatch"
195+ assert np .allclose (Ez [np .s_ [::5 ]], self .Ez , rtol = 0.1 ), "Electric field Ez samples MPI failed"
191196 else :
192197 Nt = 3000
193198 for n in tqdm (range (Nt )):
@@ -197,9 +202,9 @@ def test_mpi_simulation(self):
197202
198203 Ez = solver .E [int (Nx / 2 ), int (Ny / 2 ), np .s_ [::5 ], 'z' ]
199204 #print(Ez)
205+ assert len (solver .E [int (Nx / 2 ), int (Ny / 2 ), :, 'z' ]) == NZ , "Electric field Ez samples length mismatch"
200206 assert np .allclose (Ez , self .Ez , rtol = 0.1 ), "Electric field Ez samples failed"
201207
202-
203208 def test_mpi_gather_asField (self ):
204209 # Plot inspect after mpi gather
205210 global solver
@@ -292,10 +297,13 @@ def test_long_wake_potential(self):
292297 if use_mpi :
293298 if solver .rank == 0 :
294299 #print(wake.WP[::50])
300+ print (len (wake .WP ))
301+ assert len (wake .WP ) == 5195 , "Wake potential samples length mismatch"
295302 assert np .allclose (wake .WP [::50 ], self .WP , rtol = 0.1 ), "Wake potential samples failed"
296303 assert np .cumsum (np .abs (wake .WP ))[- 1 ] == pytest .approx (184.43818552913254 , 0.1 ), "Wake potential cumsum MPI failed"
297304 else :
298305 #print(wake.WP[::50])
306+ assert len (wake .WP ) == 5195 , "Wake potential samples length mismatch"
299307 assert np .allclose (wake .WP [::50 ], self .WP , rtol = 0.1 ), "Wake potential samples failed"
300308 assert np .cumsum (np .abs (wake .WP ))[- 1 ] == pytest .approx (184.43818552913254 , 0.1 ), "Wake potential cumsum MPI failed"
301309
@@ -305,12 +313,15 @@ def test_long_impedance(self):
305313 if use_mpi :
306314 if solver .rank == 0 :
307315 #print(wake.Z[::20])
316+ print (len (wake .Z ))
317+ assert len (wake .Z ) == 998 , "Impedance samples length mismatch"
308318 assert np .allclose (np .abs (wake .Z )[::20 ], np .abs (self .Z ), rtol = 0.1 ), "Abs Impedance samples MPI failed"
309319 assert np .allclose (np .real (wake .Z )[::20 ], np .real (self .Z ), rtol = 0.1 ), "Real Impedance samples MPI failed"
310320 assert np .allclose (np .imag (wake .Z )[::20 ], np .imag (self .Z ), rtol = 0.1 ), "Imag Impedance samples MPI failed"
311321 assert np .cumsum (np .abs (wake .Z ))[- 1 ] == pytest .approx (250910.51090497518 , 0.1 ), "Abs Impedance cumsum MPI failed"
312322 else :
313323 #print(wake.Z[::20])
324+ assert len (wake .Z ) == 998 , "Impedance samples length mismatch"
314325 assert np .allclose (np .abs (wake .Z )[::20 ], np .abs (self .Z ), rtol = 0.1 ), "Abs Impedance samples failed"
315326 assert np .allclose (np .real (wake .Z )[::20 ], np .real (self .Z ), rtol = 0.1 ), "Real Impedance samples failed"
316327 assert np .allclose (np .imag (wake .Z )[::20 ], np .imag (self .Z ), rtol = 0.1 ), "Imag Impedance samples failed"
0 commit comments