Skip to content

Commit

Permalink
Add pip features
Browse files Browse the repository at this point in the history
  • Loading branch information
CB-Lim committed Feb 29, 2024
1 parent df99ae6 commit 8e0aea1
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 84 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# 2024.02.23
# 2024.02.27

- Features: Implements Dean article
- Features: Implements Bernabeu article
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# IHSetDean
# IHSetBernabeu

Dean (1991) have proposed the concept of an equilibrium beach profile. Dean (1991) derived the equilibrium beach profile model with the wave energy dissipation similar to other previous works (e.g., Bruun, 1954). The equilibrium beach profile equation is very simple, but has been used by many researchers for coastal engineering.

Expand All @@ -8,18 +8,18 @@ Dean (1991) have proposed the concept of an equilibrium beach profile. Dean (199
To install this module use:

```sh
pip install https://github.com/IHCantabria/IHSetDean/archive/refs/tags/latest.zip
pip install https://github.com/IHCantabria/IHSetBernabeu/archive/refs/tags/latest.zip
```

Run tests to validate:

```sh
ihsetdean-tests
ihsetbernabeu-tests
```

## Documentation

Documentation is available at https://ihcantabria.github.io/IHSetDean
Documentation is available at https://ihcantabria.github.io/IHSetBernabeu

## Credits

Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
from IHSetDean.__init__ import __version__
# from IHSetBernabeu.__init__ import __version__


project = "IHSetDean"
__version__ = "0.1.0"
project = "IHSetBernabeu"
copyright = "2024, Lim, Changbin"
author = "Lim, Changbin"
version = release = __version__

html_context = {
"display_github": True, # Integrate GitHub
"github_user": "ihcantabria", # Username
"github_repo": "IHSetDean", # Repo name
"github_repo": "IHSetBernabeu", # Repo name
"github_version": "main", # Version
"conf_py_path": "/docs/",
}
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# IHSetDean
# IHSetBernabeu

## Summary

Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"


[project]
name = "IHSetDean"
name = "IHSetBernabeu"
authors = [{ name = "Lim, Changbin", email = "changbin.lim@unican.es" }]
maintainers = [{ name = "Lim, Changbin", email = "changbin.lim@unican.es" }]
readme = "README.md"
Expand All @@ -23,21 +23,21 @@ classifiers = [
]
dynamic = ["version", "description"]

dependencies = ["numpy", "pytest >=7", "scipy"]
dependencies = ["numpy", "pytest >=7", "scipy", "shapely"]


[project.optional-dependencies]
dev = ["flit", "black", "sphinx", "myst-nb", "sphinx_rtd_theme", "pre-commit"]


[project.urls]
documentation = "https://ihcantabria.github.io/IHSetDean/"
repository = "https://github.com/IHCantabria/IHSetDean"
changelog = "https://github.com/IHCantabria/IHSetDean/blob/main/CHANGELOG.md"
documentation = "https://ihcantabria.github.io/IHSetBernabeu/"
repository = "https://github.com/IHCantabria/IHSetBernabeu"
changelog = "https://github.com/IHCantabria/IHSetBernabeu/blob/main/CHANGELOG.md"


[project.scripts]
ihsetdean-tests = "IHSetDean.tests.__init__:run_tests"
ihsetbernabeu-tests = "IHSetBernabeu.tests.__init__:run_tests"


[tool.pytest.ini_options]
Expand Down
100 changes: 100 additions & 0 deletions src/IHSetBernabeu/IHSetBernabeu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import numpy as np
from scipy.interpolate import interp1d
from shapely.geometry import LineString

def caida_grano(D50):
ws = np.nan
if D50 < 0.1:
ws = 1.1e6 * (D50 * 0.001) ** 2
elif 0.1 <= D50 <= 1:
ws = 273 * (D50 * 0.001) ** 1.1
elif D50 > 1:
ws = 4.36 * D50**0.5
return ws


def RMSEq(Y, Y2t):
return np.sqrt(np.mean((Y - Y2t) ** 2, axis=0))


def Bernabeu(dp, zp, CM, D50, Hs, Tp):
z = zp - zp[0]
d = dp - dp[0]

# Profile with equidistant points
dp = np.linspace(0, dp[-1], 500).reshape(-1, 1) # 500 points
interp_func = interp1d(d, z, kind='linear', fill_value='extrapolate')
zp = interp_func(dp)
zp = zp[1:]
dp = dp[1:]

rotura = 0
ws = caida_grano(D50)
gamma = Hs / (ws * Tp)

Ar = 0.21 - 0.02 * gamma
B = 0.89 * np.exp(-1.24 * gamma)
C = 0.06 + 0.04 * gamma
D = 0.22 * np.exp(-0.83 * gamma)

Ks = [Ar, B, C, D]

a = Ar**(-1.5)
b = B / Ar**(1.5)
c = C**(-1.5)
d = D / C**(1.5)

ha = 3 * Hs
hr = 1.1 * Hs

Xr = ((hr + CM) / Ar)**(1.5) + B / Ar**(1.5) * (hr + CM)**3
Xo = Xr - (hr / C)**(1.5) - D / C**(1.5) * hr**3
Xa = Xo + c * (ha**(1.5)) + d * ha**3

hini = np.arange(0, 10.1, 0.1)
xini = a * hini**1.5 + b * hini**3

hrot = rotura - hini
xrot = xini + rotura

xdos = c * hini**(1.5) + d * hini**3

haso = rotura - hini - CM
xaso = xdos + Xo + rotura

line_coords1 = list(zip(xaso, haso))
polygon1 = LineString(line_coords1)

line_coords2 = list(zip(xrot, hrot))
polygon2 = LineString(line_coords2)
intersection = polygon1.intersection(polygon2)
iX = np.array(intersection.xy).T[0][0]
iZ = np.array(intersection.xy).T[0][1]

haso = haso[iX < xaso]
xaso = xaso[iX < xaso]

hrot = hrot[iX > xrot]
xrot = xrot[iX > xrot]

X = np.concatenate([xrot, xaso])
hm = np.concatenate([hrot, haso])

hmi = interp1d(X, hm, kind='linear', fill_value='extrapolate')(dp)

err = RMSEq(zp, hmi)

Para = {
'model': 'Bernabeu (Dos tramos)',
'formulation': [
r'$x_r = \frac{h}{A_r}^{1.5} + \frac{B}{A_r^{1.5}}h^3$',
r'$x_a = x - x_0 = \left(\frac{h-M}{C}\right)^{1.5} + \frac{D}{C^{1.5}}(h-M)^3$'
],
'name_coeffs': ['Ar', 'B', 'C', 'D'],
'coeffs': Ks,
'RMSE': err
}

model = {'D': np.concatenate([[0], dp.flatten()]), 'Z': np.concatenate([[0], hmi.flatten()])}

return Para, model
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from scipy import io
import numpy as np
from IHSetDean import IHSetDean
from IHSetBernabeu import IHSetBernabeu
from scipy.interpolate import interp1d


def test_Dean():
def test_Bernabeu():

perfil = io.loadmat("./data/perfiles_cierre.mat")
p = 0
d = perfil["perfil"]["d"][0][p].flatten()
d = d - d[0]
z = perfil["perfil"]["z"][0][p].flatten()
CM = perfil["perfil"]["CM_95"][0][p].flatten()
Hs = perfil["perfil"]['Hs50'][0][p].flatten()
Tp = perfil["perfil"]['Tp50'][0][p].flatten()
z = z - CM
di = np.linspace(d[0], d[-1], 100)
z = interp1d(d, z, kind="linear", fill_value="extrapolate")(di)
Expand All @@ -20,5 +21,5 @@ def test_Dean():
D50 = perfil["perfil"]["D50"][0][p].flatten()

# Assuming the 'ajuste_perfil' function is defined as in the previous code
pDeank, mDeank = IHSetDean.Dean(d, z, D50)
assert pDeank["RMSE"][0] == 0.4840710371023019
pBerna, mBerna = IHSetBernabeu.Bernabeu(d, z, CM, D50, Hs, Tp)
assert pBerna["RMSE"][0] == 2.9464755964823985
62 changes: 0 additions & 62 deletions src/IHSetDean/IHSetDean.py

This file was deleted.

0 comments on commit 8e0aea1

Please sign in to comment.