Skip to content

Commit

Permalink
Fix for floating point precision kept through np.power
Browse files Browse the repository at this point in the history
Pass use_logp and check for it
  • Loading branch information
FlorianDeconinck committed Dec 19, 2024
1 parent 7914a94 commit 892f38e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pyFV3/stencils/nh_p_grad.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
from gt4py.cartesian.gtscript import PARALLEL, computation, interval

from ndsl import QuantityFactory, StencilFactory, orchestrate
Expand Down Expand Up @@ -127,7 +128,8 @@ def __init__(
stencil_factory: StencilFactory,
quantity_factory: QuantityFactory,
grid_data: GridData,
grid_type,
grid_type: int,
use_logp: bool,
):
orchestrate(
obj=self,
Expand All @@ -142,6 +144,14 @@ def __init__(
self.nk = grid_indexing.domain[2]
self._rdx = grid_data.rdx
self._rdy = grid_data.rdy
self._use_logp = use_logp
if self._use_logp:
# Requires computing and carrying `peln1` see below on
# top_level calculation
raise NotImplementedError(
"Non Hydrostatic Pressure Gradient (nh_p_grad) with"
" `use_logp` is not implemented."
)

self._tmp_wk = quantity_factory.zeros(
[X_DIM, Y_DIM, Z_INTERFACE_DIM],
Expand Down Expand Up @@ -226,7 +236,7 @@ def __call__(
# Fortran names:
# u=u v=v pp=pkc gz=gz pk3=pk3 delp=delp dt=dt

ptk = ptop ** akap
ptk = np.power(ptop, akap, dtype=Float)
top_value = ptk # = peln1 if spec.namelist.use_logp else ptk

# TODO: make it clearer that each of these a2b outputs is updated
Expand Down
1 change: 1 addition & 0 deletions tests/savepoint/translate/translate_nh_p_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def compute(self, inputs):
self.grid.quantity_factory,
grid_data=self.grid.grid_data,
grid_type=self.namelist.grid_type,
use_logp=self.namelist.use_logp,
)
self.make_storage_data_input_vars(inputs)
self.compute_func(**inputs)
Expand Down

0 comments on commit 892f38e

Please sign in to comment.