@@ -153,63 +153,6 @@ def testRectilinear(dim, nVar, nSteps, dtypeIdx):
153153 assert np .allclose (u2 , u1 ), f"{ idx } 's fields in { f1 } has incorrect values"
154154
155155
156- def initGrid (nVar , gridSizes ):
157- dim = len (gridSizes )
158- coords = [np .linspace (0 , 1 , num = n , endpoint = False ) for n in gridSizes ]
159- s = [None ] * dim
160- u0 = np .array (np .arange (nVar ) + 1 )[:, * s ]
161- for x in np .meshgrid (* coords , indexing = "ij" ):
162- u0 = u0 * x
163- return coords , u0
164-
165-
166- def writeFields_MPI (fileName , dtypeIdx , algo , nSteps , nVar , nX ):
167- coords , u0 = initGrid (nVar , nX )
168-
169- from mpi4py import MPI
170- from pySDC .helpers .blocks import BlockDecomposition
171- from pySDC .helpers .fieldsIO import Rectilinear
172-
173- comm = MPI .COMM_WORLD
174- MPI_SIZE = comm .Get_size ()
175- MPI_RANK = comm .Get_rank ()
176-
177- blocks = BlockDecomposition (MPI_SIZE , nX , algo , MPI_RANK )
178-
179- iLoc , nLoc = blocks .localBounds
180- Rectilinear .setupMPI (comm , iLoc , nLoc )
181- s = [slice (i , i + n ) for i , n in zip (iLoc , nLoc )]
182- u0 = u0 [:, * s ]
183- print (MPI_RANK , u0 .shape )
184-
185- f1 = Rectilinear (DTYPES [dtypeIdx ], fileName )
186- f1 .setHeader (nVar = nVar , coords = coords )
187-
188- u0 = np .asarray (u0 , dtype = f1 .dtype )
189- f1 .initialize ()
190-
191- times = np .arange (nSteps ) / nSteps
192- for t in times :
193- ut = (u0 * t ).astype (f1 .dtype )
194- f1 .addField (t , ut )
195-
196- return u0
197-
198-
199- def compareFields_MPI (fileName , u0 , nSteps ):
200- from pySDC .helpers .fieldsIO import FieldsIO
201-
202- f2 = FieldsIO .fromFile (fileName )
203-
204- times = np .arange (nSteps ) / nSteps
205- for idx , t in enumerate (times ):
206- u1 = u0 * t
207- t2 , u2 = f2 .readField (idx )
208- assert t2 == t , f"fields[{ idx } ] in { f2 } has incorrect time ({ t2 } instead of { t } )"
209- assert u2 .shape == u1 .shape , f"{ idx } 's fields in { f2 } has incorrect shape"
210- assert np .allclose (u2 , u1 ), f"{ idx } 's fields in { f2 } has incorrect values"
211-
212-
213156@pytest .mark .mpi4py
214157@pytest .mark .parametrize ("nVar" , [1 , 4 ])
215158@pytest .mark .parametrize ("nSteps" , [1 , 10 ])
@@ -232,7 +175,7 @@ def testRectilinear_MPI(dim, nProcs, dtypeIdx, algo, nSteps, nVar):
232175 p .wait ()
233176 assert p .returncode == 0 , f"MPI write with { nProcs } proc(s) did not return code 0, but { p .returncode } "
234177
235- from pySDC .helpers .fieldsIO import FieldsIO , Rectilinear
178+ from pySDC .helpers .fieldsIO import FieldsIO , Rectilinear , initGrid
236179
237180 f2 : Rectilinear = FieldsIO .fromFile (fileName )
238181
@@ -266,5 +209,8 @@ def testRectilinear_MPI(dim, nProcs, dtypeIdx, algo, nSteps, nVar):
266209 parser .add_argument ('--nX' , type = int , nargs = '+' , help = "number of grid points in each dimensions" )
267210 args = parser .parse_args ()
268211
269- u0 = writeFields_MPI (** args .__dict__ )
270- compareFields_MPI (args .fileName , u0 , args .nSteps )
212+ if sys .version_info >= (3 , 11 ):
213+ from pySDC .helpers .fieldsIO import writeFields_MPI , compareFields_MPI
214+
215+ u0 = writeFields_MPI (** args .__dict__ )
216+ compareFields_MPI (args .fileName , u0 , args .nSteps )
0 commit comments