Skip to content

Commit eefb286

Browse files
committed
[JTH] merge changes from chyswash development branch
1 parent 4c13150 commit eefb286

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

bluemath_tk/core/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import numpy as np
1111
import pandas as pd
1212
import xarray as xr
13+
from scipy import constants
1314
from sklearn.metrics import (
1415
explained_variance_score,
1516
mean_absolute_error,
@@ -36,6 +37,8 @@ class BlueMathModel(ABC):
3637
Abstract base class for handling default functionalities across the project.
3738
"""
3839

40+
gravity = constants.g
41+
3942
@abstractmethod
4043
def __init__(self) -> None:
4144
self._logger: logging.Logger = None

bluemath_tk/waves/series.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,23 @@ def series_regular_bichromatic(waves):
396396

397397

398398
def waves_dispersion(T, h):
399-
"Solve the wave dispersion relation"
399+
"""
400+
Solve the wave dispersion relation to calculate the wavelength (L), wave number (k), and phase speed (c).
401+
Parameters
402+
----------
403+
T : float
404+
Wave period in seconds.
405+
h : float
406+
Water depth in meters.
407+
Returns
408+
-------
409+
L : float
410+
Wavelength in meters.
411+
k : float
412+
Wave number in radians per meter.
413+
c : float
414+
Phase speed in meters per second.
415+
"""
400416

401417
L1 = 1
402418
L2 = ((9.81 * T**2) / 2 * np.pi) * np.tanh(h * 2 * np.pi / L1)

bluemath_tk/wrappers/swash/swash_example.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def build_case(
4646
waves_dict = {
4747
"H": case_context["Hs"],
4848
"T": np.sqrt(
49-
(case_context["Hs"] * 2 * np.pi) / (9.806 * case_context["Hs_L0"])
49+
(case_context["Hs"] * 2 * np.pi)
50+
/ (self.gravity * case_context["Hs_L0"])
5051
),
5152
"gamma": self.gamma,
5253
"warmup": self.warmup,
@@ -65,7 +66,7 @@ def build_case(
6566
_L, _k, c = waves_dispersion(T=waves_dict["T"], h=self.depth_array[0])
6667
# comp_dx = L1 / np.abs(self.depth[0]) # MAL: Hecho por JAvi y Valva
6768
dx = L1 / self.n_nodes_per_wavelength
68-
deltc = 0.5 * dx / (np.sqrt(9.81 * self.depth_array[0]) + np.abs(c))
69+
deltc = 0.5 * dx / (np.sqrt(self.gravity * self.depth_array[0]) + np.abs(c))
6970
mxc = int(self.xlenc / dx)
7071

7172
# Update the case context
@@ -106,7 +107,8 @@ def build_case(
106107
waves_dict = {
107108
"H": case_context["Hs"],
108109
"T": np.sqrt(
109-
(case_context["Hs"] * 2 * np.pi) / (9.806 * case_context["Hs_L0"])
110+
(case_context["Hs"] * 2 * np.pi)
111+
/ (self.gravity * case_context["Hs_L0"])
110112
),
111113
"gamma": self.gamma,
112114
"warmup": self.warmup,
@@ -130,7 +132,7 @@ def build_case(
130132
_L, _k, c = waves_dispersion(T=waves_dict["T"], h=self.depth_array[0])
131133
# comp_dx = L1 / np.abs(self.depth[0]) # MAL: Hecho por JAvi y Valva
132134
dx = L1 / self.n_nodes_per_wavelength
133-
deltc = 0.5 * dx / (np.sqrt(9.81 * self.depth_array[0]) + np.abs(c))
135+
deltc = 0.5 * dx / (np.sqrt(self.gravity * self.depth_array[0]) + np.abs(c))
134136
mxc = int(self.xlenc / dx)
135137

136138
# Update the case context

bluemath_tk/wrappers/swash/swash_wrapper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from ...waves.statistics import upcrossing
1313
from .._base_wrappers import BaseModelWrapper
1414

15+
np.random.seed(42) # TODO: check global behavior.
16+
1517

1618
class SwashModelWrapper(BaseModelWrapper):
1719
"""

0 commit comments

Comments
 (0)