-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial condition for jw test #446
Changes from 25 commits
49e165a
7c20ea6
6e02762
7a900f7
8242587
4951b81
17e1d51
8be6e12
92c3db0
994b32e
33abcd2
37725c1
9445dd5
9ac856c
ebd03db
617b312
b092957
ccc4b05
b44895d
b9a3061
3342960
b557e1c
21eb5a0
53a0d6c
00ce346
4d16b5d
9fdc961
d3e1d7a
1908c52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# 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 gt4py.next.common import GridType | ||
from gt4py.next.ffront.decorator import field_operator, program, scan_operator | ||
from gt4py.next.ffront.fbuiltins import Field, exp, int32, sqrt | ||
|
||
from icon4py.model.common.dimension import CellDim, KDim | ||
from icon4py.model.common.settings import backend | ||
from icon4py.model.common.type_alias import vpfloat, wpfloat | ||
|
||
|
||
@scan_operator(axis=KDim, forward=False, init=(0.0, 0.0, True)) | ||
def _scan_pressure( | ||
state: tuple[vpfloat, vpfloat, bool], | ||
ddqz_z_full: vpfloat, | ||
temperature: vpfloat, | ||
pressure_sfc: vpfloat, | ||
grav_o_rd: wpfloat, | ||
): | ||
pressure_interface = ( | ||
pressure_sfc * exp(-grav_o_rd * ddqz_z_full / temperature) | ||
if state[2] | ||
else state[1] * exp(-grav_o_rd * ddqz_z_full / temperature) | ||
) | ||
pressure = ( | ||
sqrt(pressure_sfc * pressure_interface) if state[2] else sqrt(state[1] * pressure_interface) | ||
) | ||
return pressure, pressure_interface, False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you return here two fields one with shape (cell, num_lev) and one with shape (cell, num_lev + 1) interesting for the horizontal stencils we sometimes had problems with that due to the bounds. But lets keep it that way as long as it works. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know that. Probably, in this case, because the diagnose_pressure stencil should be called with bounds (:, 0:nlev), gt4py did not complain anything? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This stencil does not compile when backend is roundtrip. I added a few lines in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a |
||
|
||
|
||
@field_operator | ||
def _diagnose_pressure( | ||
ddqz_z_full: Field[[CellDim, KDim], wpfloat], | ||
temperature: Field[[CellDim, KDim], vpfloat], | ||
pressure_sfc: Field[[CellDim], vpfloat], | ||
grav_o_rd: wpfloat, | ||
) -> tuple[Field[[CellDim, KDim], vpfloat], Field[[CellDim, KDim], vpfloat]]: | ||
pressure, pressure_ifc, _ = _scan_pressure(ddqz_z_full, temperature, pressure_sfc, grav_o_rd) | ||
return pressure, pressure_ifc | ||
|
||
|
||
@program(grid_type=GridType.UNSTRUCTURED, backend=backend) | ||
def diagnose_pressure( | ||
ddqz_z_full: Field[[CellDim, KDim], wpfloat], | ||
temperature: Field[[CellDim, KDim], vpfloat], | ||
pressure_sfc: Field[[CellDim], vpfloat], | ||
pressure: Field[[CellDim, KDim], vpfloat], | ||
pressure_ifc: Field[[CellDim, KDim], vpfloat], | ||
grav_o_rd: wpfloat, | ||
horizontal_start: int32, | ||
horizontal_end: int32, | ||
vertical_start: int32, | ||
vertical_end: int32, | ||
): | ||
_diagnose_pressure( | ||
ddqz_z_full, | ||
temperature, | ||
pressure_sfc, | ||
grav_o_rd, | ||
out=(pressure, pressure_ifc), | ||
domain={CellDim: (horizontal_start, horizontal_end), KDim: (vertical_start, vertical_end)}, | ||
) | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you have this docstring for some particular reason? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot to delete the testing code when I was trying to verify this stencil. I have deleted. |
||
_scan_pressure_test( | ||
ddqz_z_full, | ||
temperature, | ||
pressure_sfc, | ||
out=(pressure, pressure_ifc), | ||
domain={CellDim: (horizontal_start, horizontal_end), KDim: (vertical_start, vertical_end)}, | ||
) | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# 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 gt4py.next.common import GridType | ||
from gt4py.next.ffront.decorator import field_operator, program | ||
from gt4py.next.ffront.fbuiltins import Field, exp, int32, log | ||
|
||
from icon4py.model.common.dimension import CellDim, KDim, Koff | ||
from icon4py.model.common.settings import backend | ||
from icon4py.model.common.type_alias import vpfloat, wpfloat | ||
|
||
|
||
@field_operator | ||
def _diagnose_surface_pressure( | ||
exner: Field[[CellDim, KDim], vpfloat], | ||
temperature: Field[[CellDim, KDim], vpfloat], | ||
ddqz_z_full: Field[[CellDim, KDim], wpfloat], | ||
cpd_o_rd: wpfloat, | ||
p0ref: wpfloat, | ||
grav_o_rd: wpfloat, | ||
) -> Field[[CellDim, KDim], vpfloat]: | ||
pressure_sfc = p0ref * exp( | ||
cpd_o_rd * log(exner(Koff[-3])) | ||
+ grav_o_rd | ||
* ( | ||
ddqz_z_full(Koff[-1]) / temperature(Koff[-1]) | ||
+ ddqz_z_full(Koff[-2]) / temperature(Koff[-2]) | ||
+ 0.5 * ddqz_z_full(Koff[-3]) / temperature(Koff[-3]) | ||
) | ||
) | ||
return pressure_sfc | ||
|
||
|
||
@program(grid_type=GridType.UNSTRUCTURED, backend=backend) | ||
def diagnose_surface_pressure( | ||
exner: Field[[CellDim, KDim], vpfloat], | ||
temperature: Field[[CellDim, KDim], vpfloat], | ||
ddqz_z_full: Field[[CellDim, KDim], wpfloat], | ||
pressure_sfc: Field[[CellDim, KDim], vpfloat], | ||
cpd_o_rd: wpfloat, | ||
p0ref: wpfloat, | ||
grav_o_rd: wpfloat, | ||
horizontal_start: int32, | ||
horizontal_end: int32, | ||
vertical_start: int32, | ||
vertical_end: int32, | ||
): | ||
_diagnose_surface_pressure( | ||
exner, | ||
temperature, | ||
ddqz_z_full, | ||
cpd_o_rd, | ||
p0ref, | ||
grav_o_rd, | ||
out=pressure_sfc, | ||
domain={ | ||
CellDim: (horizontal_start, horizontal_end), | ||
KDim: (vertical_start, vertical_end), | ||
}, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 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 gt4py.next.common import GridType | ||
from gt4py.next.ffront.decorator import field_operator, program | ||
from gt4py.next.ffront.fbuiltins import Field, int32 | ||
|
||
from icon4py.model.common.dimension import CellDim, KDim | ||
from icon4py.model.common.settings import backend | ||
from icon4py.model.common.type_alias import vpfloat | ||
|
||
|
||
@field_operator | ||
def _diagnose_temperature( | ||
theta_v: Field[[CellDim, KDim], vpfloat], | ||
exner: Field[[CellDim, KDim], vpfloat], | ||
) -> Field[[CellDim, KDim], vpfloat]: | ||
temperature = theta_v * exner | ||
return temperature | ||
|
||
|
||
@program(grid_type=GridType.UNSTRUCTURED, backend=backend) | ||
def diagnose_temperature( | ||
theta_v: Field[[CellDim, KDim], vpfloat], | ||
exner: Field[[CellDim, KDim], vpfloat], | ||
temperature: Field[[CellDim, KDim], vpfloat], | ||
horizontal_start: int32, | ||
horizontal_end: int32, | ||
vertical_start: int32, | ||
vertical_end: int32, | ||
): | ||
_diagnose_temperature( | ||
theta_v, | ||
exner, | ||
out=(temperature), | ||
domain={ | ||
CellDim: (horizontal_start, horizontal_end), | ||
KDim: (vertical_start, vertical_end), | ||
}, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I added this in PR 428 Can you check for duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I confirm that it is duplicated. I deleted my one.