Skip to content
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

[WIP] Rayleigh Damping mixed precision fix #32

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pyFV3/stencils/fv_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,6 @@ def compute_preamble(self, state: DycoreState, is_root_rank: bool):
"Dynamical Core (fv_dynamics): compute total energy is not implemented"
)

if (not self.config.rf_fast) and self.config.tau != 0:
raise NotImplementedError(
"Dynamical Core (fv_dynamics): Rayleigh_Super,"
" called when rf_fast=False and tau !=0, is not implemented"
)

if self.config.adiabatic and self.config.kord_tm > 0:
raise NotImplementedError(
"Dynamical Core (fv_dynamics): Adiabatic with positive kord_tm"
Expand Down
30 changes: 20 additions & 10 deletions pyFV3/stencils/ray_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
FORWARD,
PARALLEL,
computation,
f64,
horizontal,
interval,
log,
Expand All @@ -14,13 +15,10 @@

import ndsl.constants as constants
from ndsl import StencilFactory, orchestrate
from ndsl.constants import X_INTERFACE_DIM, Y_INTERFACE_DIM, Z_DIM
from ndsl.constants import SECONDS_PER_DAY, X_INTERFACE_DIM, Y_INTERFACE_DIM, Z_DIM
from ndsl.dsl.typing import Float, FloatField, FloatFieldK


SDAY = 86400.0


# NOTE: The fortran version of this computes rf in the first timestep only. Then
# rf_initialized let's you know you can skip it. Here we calculate it every
# time.
Expand All @@ -36,7 +34,7 @@ def compute_rf_vals(pfull, bdt, rf_cutoff, tau0, ptop):
@gtscript.function
def compute_rff_vals(pfull, dt, rf_cutoff, tau0, ptop):
rffvals = compute_rf_vals(pfull, dt, rf_cutoff, tau0, ptop)
rffvals = 1.0 / (1.0 + rffvals)
rffvals = f64(1.0) / (f64(1.0) + rffvals)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an f32 run, aren't you only promoting the constants here and not rffvals?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upcaster will force in the rffvals to be f64. Alternatively you could, type hint rffvals e.g.

rffvals: f64 = ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upcaster follows basic C up-casting rules

return rffvals


Expand Down Expand Up @@ -76,7 +74,7 @@ def ray_fast_wind_compute(
if pfull < rf_cutoff:
# rf is rayleigh damping increment, fraction of vertical velocity
# left after doing rayleigh damping (w -> w * rf)
rf = compute_rff_vals(pfull, dt, rf_cutoff, tau * SDAY, ptop)
rf = compute_rff_vals(pfull, dt, rf_cutoff, tau * SECONDS_PER_DAY, ptop)
with computation(FORWARD):
with interval(0, 1):
if pfull < rf_cutoff_nudge:
Expand Down Expand Up @@ -155,14 +153,26 @@ class RayleighDamping:
Fortran name: ray_fast.
"""

def __init__(self, stencil_factory: StencilFactory, rf_cutoff, tau, hydrostatic):
def __init__(
self,
stencil_factory: StencilFactory,
rf_cutoff: Float,
tau: Float,
hydrostatic: bool,
):
orchestrate(obj=self, config=stencil_factory.config.dace_config)
grid_indexing = stencil_factory.grid_indexing
self._rf_cutoff = rf_cutoff
self._rf_cutoff = Float(rf_cutoff)
origin, domain = grid_indexing.get_origin_domain(
[X_INTERFACE_DIM, Y_INTERFACE_DIM, Z_DIM]
)

if tau == 0:
raise NotImplementedError(
"Dynamical Core (fv_dynamics): RayleighDamping,"
" with tau <= 0, is not implemented"
)

ax_offsets = grid_indexing.axis_offsets(origin, domain)
local_axis_offsets = {}
for axis_offset_name, axis_offset_value in ax_offsets.items():
Expand All @@ -175,7 +185,7 @@ def __init__(self, stencil_factory: StencilFactory, rf_cutoff, tau, hydrostatic)
domain=domain,
externals={
"hydrostatic": hydrostatic,
"rf_cutoff": rf_cutoff,
"rf_cutoff": self._rf_cutoff,
"tau": tau,
**local_axis_offsets,
},
Expand All @@ -191,7 +201,7 @@ def __call__(
dt: Float,
ptop: Float,
):
rf_cutoff_nudge = self._rf_cutoff + min(100.0, 10.0 * ptop)
rf_cutoff_nudge = self._rf_cutoff + min(Float(100.0), Float(10.0) * ptop)

self._ray_fast_wind_compute(
u,
Expand Down
Loading