Skip to content

Commit

Permalink
transport.gotm: compress domain
Browse files Browse the repository at this point in the history
  • Loading branch information
jornbr committed Jan 13, 2025
1 parent fdeffbd commit 99e96f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/fabmos/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,33 @@ def compress(
The resulting domain will have ny=1 and nx=number of wet points.
"""
nwet, kwargs = None, {}
nwet = None
if full_domain.comm.rank == 0:
# Squeeze out columns with only land. This maps the horizontal from 2D to 1D
mask_hz = full_domain._mask[1::2, 1::2] == 1
nwet = mask_hz.sum()
nwet = full_domain.comm.bcast(nwet)

n_ori = full_domain.nx * full_domain.ny
if nwet == n_ori:
# Original domain already contained water points only
return full_domain

full_domain.logger.info(
f"Compressing {full_domain.nx} x {full_domain.ny} grid"
f" to {nwet} wet points ({100 * nwet / n_ori:.1f} %)"
)

# Squeeze out land points from arguments that wil be provided to Domain
kwargs = {}
if full_domain.comm.rank == 0:
kwargs["mask"] = 1
for n in ("lon", "lat", "x", "y", "f", "H"):
source = getattr(full_domain, "_" + n)
if source is not None:
kwargs[n] = source[1::2, 1::2][mask_hz]

nx = full_domain.comm.bcast(nwet)

domain = Domain(
nx, 1, **kwargs, logger=full_domain.root_logger, comm=full_domain.comm
nwet, 1, **kwargs, logger=full_domain.root_logger, comm=full_domain.comm
)

domain.global_indices = (None, None)
Expand Down
4 changes: 2 additions & 2 deletions src/fabmos/transport/gotm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from pygetm.constants import INTERFACES, FILL_VALUE, GRAVITY, RHO0, CENTERS
from .. import simulator, Array
from fabmos.domain import freeze_vertical_coordinates
from fabmos.domain import freeze_vertical_coordinates, compress
import fabmos


Expand Down Expand Up @@ -227,7 +227,7 @@ def __init__(
fabm_libname = os.path.join(os.path.dirname(__file__), "..", "fabm_gotm")

super().__init__(
domain,
compress(domain),
nz=vertical_coordinates.nz,
fabm=fabm,
log_level=log_level,
Expand Down

0 comments on commit 99e96f9

Please sign in to comment.