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

Remove pre levelmask from vel adv because cfl_clipping is the same thing #258

Merged
merged 6 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adjust unit tests
  • Loading branch information
muellch committed Aug 22, 2023
commit 218d362e6440fd8f90ba4e17d63757ff10ee9754
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class TestMoVelocityAdvectionStencil14(StencilTest):
PROGRAM = mo_velocity_advection_stencil_14
OUTPUTS = ("cfl_clipping", "pre_levelmask", "vcfl", "z_w_con_c")
OUTPUTS = ("cfl_clipping", "vcfl", "z_w_con_c")

@staticmethod
def reference(
Expand All @@ -41,11 +41,6 @@ def reference(
np.zeros_like(z_w_con_c),
)
num_rows, num_cols = cfl_clipping.shape
pre_levelmask = np.where(
cfl_clipping == 1.0,
np.ones([num_rows, num_cols]),
np.zeros_like(cfl_clipping),
)
vcfl = np.where(cfl_clipping == 1.0, z_w_con_c * dtime / ddqz_z_half, 0.0)
z_w_con_c = np.where(
(cfl_clipping == 1.0) & (vcfl < -0.85),
Expand All @@ -58,7 +53,6 @@ def reference(

return dict(
cfl_clipping=cfl_clipping,
pre_levelmask=pre_levelmask,
vcfl=vcfl,
z_w_con_c=z_w_con_c,
)
Expand All @@ -68,9 +62,6 @@ def input_data(self, mesh):
ddqz_z_half = random_field(mesh, CellDim, KDim)
z_w_con_c = random_field(mesh, CellDim, KDim)
cfl_clipping = random_mask(mesh, CellDim, KDim, dtype=bool)
pre_levelmask = random_mask(
mesh, CellDim, KDim, dtype=bool
) # TODO should be just a K field
vcfl = zero_field(mesh, CellDim, KDim)
cfl_w_limit = 5.0
dtime = 9.0
Expand All @@ -79,7 +70,6 @@ def input_data(self, mesh):
ddqz_z_half=ddqz_z_half,
z_w_con_c=z_w_con_c,
cfl_clipping=cfl_clipping,
pre_levelmask=pre_levelmask,
vcfl=vcfl,
cfl_w_limit=cfl_w_limit,
dtime=dtime,
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

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

why not also port it to the new format using the StencilTest? Or is there a reason why this is not possible for this stencil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but I will do that as a follow up. For now it is important that everyone gets the fixes, so they can run the correct code.
I can put the tests into the new format on my fused velocity advection branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def mo_velocity_advection_stencil_20_numpy(
w_con_e = np.zeros_like(vn)
difcoef = np.zeros_like(vn)

levelmask_offset_1 = np.roll(levelmask, shift=-1, axis=0)
levelmask_offset_0 = levelmask[:-1]
levelmask_offset_1 = levelmask[1:]

c_lin_e = np.expand_dims(c_lin_e, axis=-1)
geofac_grdiv = np.expand_dims(geofac_grdiv, axis=-1)
Expand All @@ -59,12 +60,12 @@ def mo_velocity_advection_stencil_20_numpy(
inv_primal_edge_length = np.expand_dims(inv_primal_edge_length, axis=-1)

w_con_e = np.where(
(levelmask == 1) | (levelmask_offset_1 == 1),
(levelmask_offset_0 == 1) | (levelmask_offset_1 == 1),
np.sum(c_lin_e * z_w_con_c_full[e2c], axis=1),
w_con_e,
)
difcoef = np.where(
((levelmask == 1) | (levelmask_offset_1 == 1))
((levelmask_offset_0 == 1) | (levelmask_offset_1 == 1))
& (np.abs(w_con_e) > cfl_w_limit * ddqz_z_full_e),
scalfac_exdiff
* np.minimum(
Expand All @@ -74,11 +75,10 @@ def mo_velocity_advection_stencil_20_numpy(
difcoef,
)
ddt_vn_adv = np.where(
((levelmask == 1) | (levelmask_offset_1 == 1))
((levelmask_offset_0 == 1) | (levelmask_offset_1 == 1))
& (np.abs(w_con_e) > cfl_w_limit * ddqz_z_full_e),
ddt_vn_adv
+ difcoef * area_edge * np.sum(geofac_grdiv * vn[e2c2eO], axis=1)
+ tangent_orientation * inv_primal_edge_length * np.sum(zeta[e2v], axis=1),
ddt_vn_adv + difcoef * area_edge *
(np.sum(geofac_grdiv * vn[e2c2eO], axis=1) + tangent_orientation * inv_primal_edge_length * (zeta[e2v][:, 1] - zeta[e2v][:, 0])),
ddt_vn_adv,
)
return ddt_vn_adv
Expand All @@ -87,7 +87,7 @@ def mo_velocity_advection_stencil_20_numpy(
def test_mo_velocity_advection_stencil_20():
mesh = SimpleMesh()

levelmask = random_mask(mesh, KDim)
levelmask = random_mask(mesh, KDim, extend={KDim: 1})
c_lin_e = random_field(mesh, EdgeDim, E2CDim)
z_w_con_c_full = random_field(mesh, CellDim, KDim)
ddqz_z_full_e = random_field(mesh, EdgeDim, KDim)
Expand Down