Skip to content

Commit

Permalink
Added water loading component (#72)
Browse files Browse the repository at this point in the history
* add WaterFlexure to subside due to water loading

* add a ParameterMismatchError exception

* add the WaterFlexure component, calculate change in water loading

* additionally calculate change in sea level

* update logging styles

* add news fragment
  • Loading branch information
mcflugen committed Nov 17, 2022
1 parent afb0e8d commit b976a4e
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 115 deletions.
3 changes: 3 additions & 0 deletions news/72.feature
@@ -0,0 +1,3 @@

Added a new component, :class:`~sequence.sediment_flexure.WaterFlexure`, that
calculates deflections based on changes in water loading.
12 changes: 12 additions & 0 deletions sequence/errors.py
Expand Up @@ -38,3 +38,15 @@ def __init__(self, name: str):
def __str_(self) -> str:
"""Return an error message in human-readable form, including the name of the missing variable."""
return f"{self._name!r}"


class ParameterMismatchError(SequenceError):
"""Raise this error if two configurations have different values for the same parameter."""

def __init__(self, keys):
self.keys = tuple(keys)

def __str__(self):
"""Return an error message with the offending keys."""
params = ", ".join([repr(key) for key in self.keys])
return f"mismatch in parameter{'s' if len(self.keys) > 1 else ''}: {params}"
4 changes: 2 additions & 2 deletions sequence/logging.py
Expand Up @@ -10,9 +10,9 @@

LOG_LEVEL_STYLES: dict[str, dict[str, Any]] = {
"DEBUG": {"bold": True, "dim": True},
"INFO": {"bold": True, "dim": True},
"INFO": {"bold": True, "dim": True, "fg": "green"},
"WARNING": {"bold": True, "fg": "bright_yellow"},
"ERROR": {"bold": True, "fg": "red"},
"ERROR": {"bold": True, "fg": "bright_red"},
"CRITICAL": {"bold": True, "fg": "bright_red"},
}

Expand Down
17 changes: 15 additions & 2 deletions sequence/sea_level.py
Expand Up @@ -31,7 +31,15 @@ class SeaLevelTimeSeries(Component):
"units": "m",
"mapping": "grid",
"doc": "Sea level elevation",
}
},
"sea_level__increment_of_elevation": {
"dtype": "float",
"intent": "out",
"optional": False,
"units": "m",
"mapping": "grid",
"doc": "Change in sea level elevation",
},
}

def __init__(
Expand Down Expand Up @@ -109,7 +117,12 @@ def run_one_step(self, dt: float) -> None:
The time step.
"""
self._time += dt
self.grid.at_grid["sea_level__elevation"] = self._sea_level(self.time)
old_sea_level = self.grid.at_grid["sea_level__elevation"]
new_sea_level = self._sea_level(self.time)
self.grid.at_grid["sea_level__elevation"] = new_sea_level
self.grid.at_grid["sea_level__increment_of_elevation"] = (
new_sea_level - old_sea_level
)


class SinusoidalSeaLevel(SeaLevelTimeSeries):
Expand Down

0 comments on commit b976a4e

Please sign in to comment.