-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tracer advection stencils zero copy (#106)
(feat) - stencil to set field to zero for Field[[CellDim], float] and Field[[CellDim, KDim], float]
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# ICON4Py - ICON inspired code in Python and GT4Py | ||
# | ||
# Copyright (c) 2022, ETH Zurich and MeteoSwiss | ||
# All rights reserved. | ||
# | ||
# This file is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the | ||
# Free Software Foundation, either version 3 of the License, or any later | ||
# version. See the LICENSE.txt file at the top-level directory of this | ||
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from functional.common import Field | ||
from functional.ffront.decorator import field_operator, program | ||
from functional.ffront.fbuiltins import broadcast | ||
|
||
from icon4py.common.dimension import CellDim | ||
|
||
|
||
@field_operator | ||
def _set_zero_c() -> Field[[CellDim], float]: | ||
return broadcast(0.0, (CellDim, )) | ||
|
||
|
||
@program | ||
def set_zero_c(field: Field[[CellDim], float]): | ||
_set_zero_c(out=field) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# ICON4Py - ICON inspired code in Python and GT4Py | ||
# | ||
# Copyright (c) 2022, ETH Zurich and MeteoSwiss | ||
# All rights reserved. | ||
# | ||
# This file is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the | ||
# Free Software Foundation, either version 3 of the License, or any later | ||
# version. See the LICENSE.txt file at the top-level directory of this | ||
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from functional.common import Field | ||
from functional.ffront.decorator import field_operator, program | ||
from functional.ffront.fbuiltins import broadcast | ||
|
||
from icon4py.common.dimension import CellDim, KDim | ||
|
||
|
||
@field_operator | ||
def _set_zero_c_k() -> Field[[CellDim, KDim], float]: | ||
return broadcast(0.0, (CellDim, KDim)) | ||
|
||
|
||
@program | ||
def set_zero_c_k(field: Field[[CellDim, KDim], float]): | ||
_set_zero_c_k(out=field) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# ICON4Py - ICON inspired code in Python and GT4Py | ||
# | ||
# Copyright (c) 2022, ETH Zurich and MeteoSwiss | ||
# All rights reserved. | ||
# | ||
# This file is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the | ||
# Free Software Foundation, either version 3 of the License, or any later | ||
# version. See the LICENSE.txt file at the top-level directory of this | ||
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import numpy as np | ||
|
||
from icon4py.advection.set_zero_c import set_zero_c | ||
from icon4py.common.dimension import CellDim | ||
from icon4py.testutils.simple_mesh import SimpleMesh | ||
from icon4py.testutils.utils import random_field, zero_field | ||
|
||
|
||
def test_set_zero_cell_k(): | ||
mesh = SimpleMesh() | ||
field = random_field(mesh, CellDim) | ||
|
||
set_zero_c(field, offset_provider={}) | ||
assert np.allclose(field, zero_field(mesh, CellDim)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# ICON4Py - ICON inspired code in Python and GT4Py | ||
# | ||
# Copyright (c) 2022, ETH Zurich and MeteoSwiss | ||
# All rights reserved. | ||
# | ||
# This file is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the | ||
# Free Software Foundation, either version 3 of the License, or any later | ||
# version. See the LICENSE.txt file at the top-level directory of this | ||
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import numpy as np | ||
|
||
from icon4py.advection.set_zero_c_k import set_zero_c_k | ||
from icon4py.common.dimension import CellDim, KDim | ||
from icon4py.testutils.simple_mesh import SimpleMesh | ||
from icon4py.testutils.utils import random_field, zero_field | ||
|
||
|
||
def test_set_zero_c_k(): | ||
mesh = SimpleMesh() | ||
field = random_field(mesh, CellDim, KDim) | ||
|
||
set_zero_c_k(field, offset_provider={}) | ||
assert np.allclose(field, zero_field(mesh, CellDim, KDim)) |