@@ -21,7 +21,7 @@ Currently, this work with ClimaCoreTempestRemap. `ClimaCoreTempestRemap` uses Te
21
21
a command-line utility. Hence, This function has to process files, so, for this regridder,
22
22
we cannot really split file processing and remapping.
23
23
24
- TempestRegridder only works on CPU and on a single process.
24
+ TempestRegridder only works on CPU and on a single process, and for a non-3D target space .
25
25
26
26
Implicit assumptions in the code:
27
27
- input_file contains "lat" and "lon"
@@ -225,12 +225,18 @@ function read_from_hdf5(REGRID_DIR, hd_outfile_root, time, varname, space)
225
225
field = ClimaCore. InputOutput. read_field (hdfreader, varname)
226
226
Base. close (hdfreader)
227
227
228
- # Ensure the field is on the correct space when reusing regridded files
229
- # between simulations
228
+ # Ensure the field is on the correct space
229
+ @assert ClimaCore. Spaces. topology (axes (field)) ==
230
+ ClimaCore. Spaces. topology (space)
231
+ @assert ClimaCore. Spaces. quadrature_style (axes (field)) ==
232
+ ClimaCore. Spaces. quadrature_style (space)
233
+ @assert ClimaCore. Spaces. global_geometry (axes (field)) ==
234
+ ClimaCore. Spaces. global_geometry (space)
235
+
236
+ # Since the spaces aren't the same, we need to copy the field values onto the space
230
237
return swap_space (field, space)
231
238
end
232
239
233
-
234
240
"""
235
241
write_to_hdf5(REGRID_DIR, hd_outfile_root, time, field, varname,
236
242
comms_ctx = ClimaComms.SingletonCommsContext())
@@ -283,6 +289,44 @@ function write_to_hdf5(
283
289
Base. close (hdfwriter)
284
290
end
285
291
292
+ """
293
+ construct_singleton_space(space)
294
+
295
+ Constructs a singleton space from a given space. This is not ideal, but
296
+ necessary to use TempestRemap regridding, which is not MPI or GPU compatible.
297
+ """
298
+ function construct_singleton_space (space)
299
+ # If doesn't make sense to regrid with GPUs/MPI processes
300
+ cpu_context =
301
+ ClimaComms. SingletonCommsContext (ClimaComms. CPUSingleThreaded ())
302
+
303
+ # Check if input space was constructed using `spacefillingcurve`
304
+ use_spacefillingcurve =
305
+ ClimaCore. Spaces. topology (space). elemorder isa CartesianIndices ?
306
+ false : true
307
+
308
+ mesh = ClimaCore. Spaces. topology (space). mesh
309
+ topology = nothing
310
+ if use_spacefillingcurve
311
+ topology = ClimaCore. Topologies. Topology2D (
312
+ cpu_context,
313
+ mesh,
314
+ ClimaCore. Topologies. spacefillingcurve (mesh),
315
+ )
316
+ else
317
+ topology = ClimaCore. Topologies. Topology2D (cpu_context, mesh)
318
+ end
319
+ Nq =
320
+ ClimaCore. Spaces. Quadratures. polynomial_degree (
321
+ ClimaCore. Spaces. quadrature_style (space),
322
+ ) + 1
323
+ space_singleton = ClimaCore. Spaces. SpectralElementSpace2D (
324
+ topology,
325
+ ClimaCore. Spaces. Quadratures. GLL {Nq} (),
326
+ )
327
+
328
+ return space_singleton
329
+ end
286
330
287
331
"""
288
332
function hdwrite_regridfile_rll_to_cgll(
@@ -334,23 +378,9 @@ function hdwrite_regridfile_rll_to_cgll(
334
378
weightfile = joinpath (REGRID_DIR, outfile_root * " _remap_weights.nc" )
335
379
336
380
# If doesn't make sense to regrid with GPUs/MPI processes
337
- cpu_context =
338
- ClimaComms. SingletonCommsContext (ClimaComms. CPUSingleThreaded ())
339
-
340
- # Note: this topology gives us `space == space_undistributed` in the undistributed
341
- # case (as desired), which wouldn't hold if we used `spacefillingcurve` here.
342
- topology = ClimaCore. Topologies. Topology2D (
343
- cpu_context,
344
- ClimaCore. Spaces. topology (space). mesh,
345
- )
346
- Nq =
347
- ClimaCore. Spaces. Quadratures. polynomial_degree (
348
- ClimaCore. Spaces. quadrature_style (space),
349
- ) + 1
350
- space_undistributed = ClimaCore. Spaces. SpectralElementSpace2D (
351
- topology,
352
- ClimaCore. Spaces. Quadratures. GLL {Nq} (),
353
- )
381
+ space_singleton = construct_singleton_space (space)
382
+ topology_singleton = ClimaCore. Spaces. topology (space_singleton)
383
+ cpu_context = ClimaCore. Spaces. topology (space_singleton). context
354
384
355
385
if isfile (datafile_cgll) == false
356
386
isdir (REGRID_DIR) ? nothing : mkpath (REGRID_DIR)
@@ -362,7 +392,7 @@ function hdwrite_regridfile_rll_to_cgll(
362
392
ClimaCoreTempestRemap. rll_mesh (meshfile_rll; nlat = nlat, nlon = nlon)
363
393
364
394
# write cgll mesh, overlap mesh and weight file
365
- ClimaCoreTempestRemap. write_exodus (meshfile_cgll, topology )
395
+ ClimaCoreTempestRemap. write_exodus (meshfile_cgll, topology_singleton )
366
396
ClimaCoreTempestRemap. overlap_mesh (
367
397
meshfile_overlap,
368
398
meshfile_rll,
@@ -372,6 +402,10 @@ function hdwrite_regridfile_rll_to_cgll(
372
402
# 'in_np = 1' and 'mono = true' arguments ensure mapping is conservative and monotone
373
403
# Note: for a kwarg not followed by a value, set it to true here (i.e. pass 'mono = true' to produce '--mono')
374
404
# Note: out_np = degrees of freedom = polynomial degree + 1
405
+ Nq =
406
+ ClimaCore. Spaces. Quadratures. polynomial_degree (
407
+ ClimaCore. Spaces. quadrature_style (space),
408
+ ) + 1
375
409
kwargs = (; out_type = out_type, out_np = Nq)
376
410
kwargs = mono ? (; (kwargs). .. , in_np = 1 , mono = mono) : kwargs
377
411
ClimaCoreTempestRemap. remap_weights (
@@ -400,8 +434,8 @@ function hdwrite_regridfile_rll_to_cgll(
400
434
401
435
target_unique_idxs =
402
436
out_type == " cgll" ?
403
- collect (ClimaCore. Spaces. unique_nodes (space_undistributed )) :
404
- collect (ClimaCore. Spaces. all_nodes (space_undistributed ))
437
+ collect (ClimaCore. Spaces. unique_nodes (space_singleton )) :
438
+ collect (ClimaCore. Spaces. all_nodes (space_singleton ))
405
439
target_unique_idxs_i =
406
440
map (row -> target_unique_idxs[row][1 ][1 ], row_indices)
407
441
target_unique_idxs_j =
@@ -412,7 +446,7 @@ function hdwrite_regridfile_rll_to_cgll(
412
446
413
447
R = (; target_idxs = target_unique_idxs, row_indices = row_indices)
414
448
415
- offline_field = ClimaCore. Fields. zeros (FT, space_undistributed )
449
+ offline_field = ClimaCore. Fields. zeros (FT, space_singleton )
416
450
417
451
times = [DateTime (0 )]
418
452
# Save regridded HDF5 file for each variable in `varnames`
@@ -452,6 +486,7 @@ function hdwrite_regridfile_rll_to_cgll(
452
486
length (times),
453
487
)
454
488
489
+ # Save regridded HDF5 file for each time slice
455
490
map (
456
491
x -> write_to_hdf5 (
457
492
REGRID_DIR,
0 commit comments