Skip to content

Commit

Permalink
Fixed particle on boundary issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pnsaevik committed Sep 23, 2024
1 parent b27a61e commit 4b9bdc3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.
- Multiplicity to the releaser module


## [Unreleased] - 2024-09-19
## [2.0.3] - 2024-09-19
### Fixed
- Can import local IBM and gridforce modules
- zROMS module now works with legacy config file
- Simulation no longer breaks if particles reach domain boundary
### Changed
- Logger now outputs current time

Expand Down
2 changes: 1 addition & 1 deletion ladim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '2.0.2'
__version__ = '2.0.3'

from .main import main, run
14 changes: 14 additions & 0 deletions ladim/gridforce/ROMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def sample_depth(self, X, Y):
"""Return the depth of grid cells"""
I = X.round().astype(int) - self.i0
J = Y.round().astype(int) - self.j0
I = np.minimum(np.maximum(I, 0), self.H.shape[1] - 1)
J = np.minimum(np.maximum(J, 0), self.H.shape[0] - 1)
return self.H[J, I]

def lonlat(self, X, Y, method="bilinear"):
Expand All @@ -191,6 +193,8 @@ def lonlat(self, X, Y, method="bilinear"):
# else: containing grid cell, less accurate
I = X.round().astype("int") - self.i0
J = Y.round().astype("int") - self.j0
I = np.minimum(np.maximum(I, 0), self.lon.shape[1] - 1)
J = np.minimum(np.maximum(J, 0), self.lon.shape[0] - 1)
return self.lon[J, I], self.lat[J, I]

def ingrid(self, X: np.ndarray, Y: np.ndarray) -> np.ndarray:
Expand All @@ -206,6 +210,11 @@ def onland(self, X, Y):
"""Returns True for points on land"""
I = X.round().astype(int) - self.i0
J = Y.round().astype(int) - self.j0

# Constrain to valid indices
I = np.minimum(np.maximum(I, 0), self.M.shape[-1] - 1)
J = np.minimum(np.maximum(J, 0), self.M.shape[-2] - 1)

return self.M[J, I] < 1

# Error if point outside
Expand Down Expand Up @@ -802,6 +811,11 @@ def sample3D(F, X, Y, K, A, method="bilinear"):
# else: method == 'nearest'
I = X.round().astype("int")
J = Y.round().astype("int")

# Constrain to valid indices
I = np.minimum(np.maximum(I, 0), F.shape[-1] - 1)
J = np.minimum(np.maximum(J, 0), F.shape[-2] - 1)

return F[K, J, I]


Expand Down

0 comments on commit 4b9bdc3

Please sign in to comment.