|
1 | | -import warnings |
2 | 1 | from collections.abc import Sequence |
3 | 2 |
|
4 | 3 | from gt4py.cartesian import gtscript |
5 | 4 | from gt4py.cartesian.gtscript import PARALLEL, computation, horizontal, interval, region |
6 | 5 |
|
7 | 6 | from ndsl import StencilFactory |
8 | | -from ndsl.constants import ( |
9 | | - X_DIM, |
10 | | - X_INTERFACE_DIM, |
11 | | - Y_DIM, |
12 | | - Y_INTERFACE_DIM, |
13 | | - Z_INTERFACE_DIM, |
14 | | -) |
| 7 | +from ndsl.constants import X_INTERFACE_DIM, Y_INTERFACE_DIM, Z_INTERFACE_DIM |
15 | 8 | from ndsl.dsl.stencil import GridIndexing |
16 | 9 | from ndsl.dsl.typing import FloatField |
17 | 10 |
|
18 | 11 |
|
19 | | -class CopyCorners: |
20 | | - """ |
21 | | - Helper-class to copy corners corresponding to the fortran functions |
22 | | - copy_corners_x or copy_corners_y respectively |
23 | | - """ |
24 | | - |
25 | | - def __init__(self, direction: str, stencil_factory: StencilFactory) -> None: |
26 | | - """The grid for this stencil""" |
27 | | - warnings.warn( |
28 | | - "Usage of the GT4Py implementation of CopyCorners is discouraged and will" |
29 | | - "be removed in the next release. Use `CopyCornersX` or `CopyCornersY` in PyFV3" |
30 | | - "for a more future-proof implementation of the same code.", |
31 | | - DeprecationWarning, |
32 | | - 2, |
33 | | - ) |
34 | | - grid_indexing = stencil_factory.grid_indexing |
35 | | - |
36 | | - n_halo = grid_indexing.n_halo |
37 | | - origin, domain = grid_indexing.get_origin_domain( |
38 | | - dims=[X_DIM, Y_DIM, Z_INTERFACE_DIM], halos=(n_halo, n_halo) |
39 | | - ) |
40 | | - |
41 | | - ax_offsets = grid_indexing.axis_offsets(origin, domain) |
42 | | - if direction == "x": |
43 | | - self._copy_corners = stencil_factory.from_origin_domain( |
44 | | - func=copy_corners_x_stencil_defn, |
45 | | - origin=origin, |
46 | | - domain=domain, |
47 | | - externals={ |
48 | | - **ax_offsets, |
49 | | - }, |
50 | | - ) |
51 | | - elif direction == "y": |
52 | | - self._copy_corners = stencil_factory.from_origin_domain( |
53 | | - func=copy_corners_y_stencil_defn, |
54 | | - origin=origin, |
55 | | - domain=domain, |
56 | | - externals={ |
57 | | - **ax_offsets, |
58 | | - }, |
59 | | - ) |
60 | | - else: |
61 | | - raise ValueError("Direction must be either 'x' or 'y'") |
62 | | - |
63 | | - def __call__(self, field: FloatField): |
64 | | - """ |
65 | | - Fills cell quantity field using corners from itself and multipliers |
66 | | - in the direction specified initialization of the instance of this class. |
67 | | - """ |
68 | | - self._copy_corners(field, field) |
69 | | - |
70 | | - |
71 | 12 | class CopyCornersXY: |
72 | 13 | """ |
73 | 14 | Helper-class to copy corners corresponding to the Fortran functions |
@@ -313,126 +254,6 @@ def fill_corners_3cells_mult_y( |
313 | 254 | return q |
314 | 255 |
|
315 | 256 |
|
316 | | -def copy_corners_x_stencil_defn(q_in: FloatField, q_out: FloatField): |
317 | | - from __externals__ import i_end, i_start, j_end, j_start |
318 | | - |
319 | | - with computation(PARALLEL), interval(...): |
320 | | - with horizontal( |
321 | | - region[i_start - 3, j_start - 3], region[i_end + 3, j_start - 3] |
322 | | - ): |
323 | | - q_out = q_in[0, 5, 0] |
324 | | - with horizontal( |
325 | | - region[i_start - 2, j_start - 3], region[i_end + 3, j_start - 2] |
326 | | - ): |
327 | | - q_out = q_in[-1, 4, 0] |
328 | | - with horizontal( |
329 | | - region[i_start - 1, j_start - 3], region[i_end + 3, j_start - 1] |
330 | | - ): |
331 | | - q_out = q_in[-2, 3, 0] |
332 | | - with horizontal( |
333 | | - region[i_start - 3, j_start - 2], region[i_end + 2, j_start - 3] |
334 | | - ): |
335 | | - q_out = q_in[1, 4, 0] |
336 | | - with horizontal( |
337 | | - region[i_start - 2, j_start - 2], region[i_end + 2, j_start - 2] |
338 | | - ): |
339 | | - q_out = q_in[0, 3, 0] |
340 | | - with horizontal( |
341 | | - region[i_start - 1, j_start - 2], region[i_end + 2, j_start - 1] |
342 | | - ): |
343 | | - q_out = q_in[-1, 2, 0] |
344 | | - with horizontal( |
345 | | - region[i_start - 3, j_start - 1], region[i_end + 1, j_start - 3] |
346 | | - ): |
347 | | - q_out = q_in[2, 3, 0] |
348 | | - with horizontal( |
349 | | - region[i_start - 2, j_start - 1], region[i_end + 1, j_start - 2] |
350 | | - ): |
351 | | - q_out = q_in[1, 2, 0] |
352 | | - with horizontal( |
353 | | - region[i_start - 1, j_start - 1], region[i_end + 1, j_start - 1] |
354 | | - ): |
355 | | - q_out = q_in[0, 1, 0] |
356 | | - with horizontal(region[i_start - 3, j_end + 1], region[i_end + 1, j_end + 3]): |
357 | | - q_out = q_in[2, -3, 0] |
358 | | - with horizontal(region[i_start - 2, j_end + 1], region[i_end + 1, j_end + 2]): |
359 | | - q_out = q_in[1, -2, 0] |
360 | | - with horizontal(region[i_start - 1, j_end + 1], region[i_end + 1, j_end + 1]): |
361 | | - q_out = q_in[0, -1, 0] |
362 | | - with horizontal(region[i_start - 3, j_end + 2], region[i_end + 2, j_end + 3]): |
363 | | - q_out = q_in[1, -4, 0] |
364 | | - with horizontal(region[i_start - 2, j_end + 2], region[i_end + 2, j_end + 2]): |
365 | | - q_out = q_in[0, -3, 0] |
366 | | - with horizontal(region[i_start - 1, j_end + 2], region[i_end + 2, j_end + 1]): |
367 | | - q_out = q_in[-1, -2, 0] |
368 | | - with horizontal(region[i_start - 3, j_end + 3], region[i_end + 3, j_end + 3]): |
369 | | - q_out = q_in[0, -5, 0] |
370 | | - with horizontal(region[i_start - 2, j_end + 3], region[i_end + 3, j_end + 2]): |
371 | | - q_out = q_in[-1, -4, 0] |
372 | | - with horizontal(region[i_start - 1, j_end + 3], region[i_end + 3, j_end + 1]): |
373 | | - q_out = q_in[-2, -3, 0] |
374 | | - |
375 | | - |
376 | | -def copy_corners_y_stencil_defn(q_in: FloatField, q_out: FloatField): |
377 | | - from __externals__ import i_end, i_start, j_end, j_start |
378 | | - |
379 | | - with computation(PARALLEL), interval(...): |
380 | | - with horizontal( |
381 | | - region[i_start - 3, j_start - 3], region[i_start - 3, j_end + 3] |
382 | | - ): |
383 | | - q_out = q_in[5, 0, 0] |
384 | | - with horizontal( |
385 | | - region[i_start - 2, j_start - 3], region[i_start - 3, j_end + 2] |
386 | | - ): |
387 | | - q_out = q_in[4, 1, 0] |
388 | | - with horizontal( |
389 | | - region[i_start - 1, j_start - 3], region[i_start - 3, j_end + 1] |
390 | | - ): |
391 | | - q_out = q_in[3, 2, 0] |
392 | | - with horizontal( |
393 | | - region[i_start - 3, j_start - 2], region[i_start - 2, j_end + 3] |
394 | | - ): |
395 | | - q_out = q_in[4, -1, 0] |
396 | | - with horizontal( |
397 | | - region[i_start - 2, j_start - 2], region[i_start - 2, j_end + 2] |
398 | | - ): |
399 | | - q_out = q_in[3, 0, 0] |
400 | | - with horizontal( |
401 | | - region[i_start - 1, j_start - 2], region[i_start - 2, j_end + 1] |
402 | | - ): |
403 | | - q_out = q_in[2, 1, 0] |
404 | | - with horizontal( |
405 | | - region[i_start - 3, j_start - 1], region[i_start - 1, j_end + 3] |
406 | | - ): |
407 | | - q_out = q_in[3, -2, 0] |
408 | | - with horizontal( |
409 | | - region[i_start - 2, j_start - 1], region[i_start - 1, j_end + 2] |
410 | | - ): |
411 | | - q_out = q_in[2, -1, 0] |
412 | | - with horizontal( |
413 | | - region[i_start - 1, j_start - 1], region[i_start - 1, j_end + 1] |
414 | | - ): |
415 | | - q_out = q_in[1, 0, 0] |
416 | | - with horizontal(region[i_end + 1, j_start - 3], region[i_end + 3, j_end + 1]): |
417 | | - q_out = q_in[-3, 2, 0] |
418 | | - with horizontal(region[i_end + 2, j_start - 3], region[i_end + 3, j_end + 2]): |
419 | | - q_out = q_in[-4, 1, 0] |
420 | | - with horizontal(region[i_end + 3, j_start - 3], region[i_end + 3, j_end + 3]): |
421 | | - q_out = q_in[-5, 0, 0] |
422 | | - with horizontal(region[i_end + 1, j_start - 2], region[i_end + 2, j_end + 1]): |
423 | | - q_out = q_in[-2, 1, 0] |
424 | | - with horizontal(region[i_end + 2, j_start - 2], region[i_end + 2, j_end + 2]): |
425 | | - q_out = q_in[-3, 0, 0] |
426 | | - with horizontal(region[i_end + 3, j_start - 2], region[i_end + 2, j_end + 3]): |
427 | | - q_out = q_in[-4, -1, 0] |
428 | | - with horizontal(region[i_end + 1, j_start - 1], region[i_end + 1, j_end + 1]): |
429 | | - q_out = q_in[-1, 0, 0] |
430 | | - with horizontal(region[i_end + 2, j_start - 1], region[i_end + 1, j_end + 2]): |
431 | | - q_out = q_in[-2, -1, 0] |
432 | | - with horizontal(region[i_end + 3, j_start - 1], region[i_end + 1, j_end + 3]): |
433 | | - q_out = q_in[-3, -2, 0] |
434 | | - |
435 | | - |
436 | 257 | def copy_corners_xy_stencil_defn( |
437 | 258 | q_in: FloatField, q_out_x: FloatField, q_out_y: FloatField |
438 | 259 | ): |
|
0 commit comments