diff --git a/advection/src/icon4py/advection/set_zero_c.py b/advection/src/icon4py/advection/set_zero_c.py new file mode 100644 index 0000000000..8d8ef32c97 --- /dev/null +++ b/advection/src/icon4py/advection/set_zero_c.py @@ -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 . +# +# 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) diff --git a/advection/src/icon4py/advection/set_zero_c_k.py b/advection/src/icon4py/advection/set_zero_c_k.py new file mode 100644 index 0000000000..2f30957b5c --- /dev/null +++ b/advection/src/icon4py/advection/set_zero_c_k.py @@ -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 . +# +# 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) diff --git a/advection/tests/test_set_zero_c.py b/advection/tests/test_set_zero_c.py new file mode 100644 index 0000000000..018cc1fc3a --- /dev/null +++ b/advection/tests/test_set_zero_c.py @@ -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 . +# +# 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)) diff --git a/advection/tests/test_set_zero_c_k.py b/advection/tests/test_set_zero_c_k.py new file mode 100644 index 0000000000..1323924730 --- /dev/null +++ b/advection/tests/test_set_zero_c_k.py @@ -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 . +# +# 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))