Skip to content

Commit

Permalink
Allow calculations to use previously computed strains for initial con…
Browse files Browse the repository at this point in the history
…ditions.
  • Loading branch information
arkottke committed Sep 24, 2024
1 parent 0c082a6 commit 9289e31
Showing 1 changed file with 49 additions and 15 deletions.
64 changes: 49 additions & 15 deletions src/pystrata/propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import numba
import numpy as np
import numpy.typing as npt
from scipy.optimize import minimize

from .motion import GRAVITY, Motion, WaveField
Expand All @@ -34,11 +35,25 @@ def __init__(self):
self._motion: None | Motion = None
self._profile: None | Profile = None

def __call__(self, motion: Motion, profile: Profile, loc_input: Location):
def __call__(
self,
motion: Motion,
profile: Profile,
loc_input: Location,
reset_layers=True,
**kwds,
):
self._motion = motion
self._profile = profile
self._loc_input = loc_input

if reset_layers:
# Set initial properties
for layer in profile:
layer.reset()
if layer.strain is None:
layer.strain = 0.0

@property
def motion(self):
return self._motion
Expand Down Expand Up @@ -84,7 +99,14 @@ def __init__(self, site_atten=None, method="standard"):
self._site_atten = site_atten
self._method = method

def __call__(self, motion, profile, loc_input):
def __call__(
self,
motion: Motion,
profile: Profile,
loc_input: Location,
reset_layers=True,
**kwds,
):
"""Perform the wave propagation.
Parameters
Expand All @@ -98,7 +120,7 @@ def __call__(self, motion, profile, loc_input):
loc_input: :class:`~.base.site.Location`
Location of the input motion.
"""
super().__call__(motion, profile, loc_input)
super().__call__(motion, profile, loc_input, reset_layers=reset_layers, **kwds)

self._crustal_amp, self._site_term = self._calc_amp(
profile.density, profile.thickness, profile.slowness
Expand Down Expand Up @@ -138,7 +160,9 @@ def site_term(self) -> np.ndarray:
def site_atten(self) -> float | None:
return self._site_atten

def _calc_amp(self, density, thickness, slowness):
def _calc_amp(
self, density: npt.ArrayLike, thickness: npt.ArrayLike, slowness: npt.ArrayLike
) -> tuple[np.ndarray, np.ndarray]:
freqs = self.motion.freqs
# 1/4 wavelength depth -- estimated for mean slowness
qwl_depth = 1 / (4 * np.mean(slowness) * freqs)
Expand Down Expand Up @@ -297,7 +321,14 @@ def __init__(self):
self._waves_b = np.array([])
self._wave_nums = np.array([])

def __call__(self, motion, profile, loc_input):
def __call__(
self,
motion: Motion,
profile: Profile,
loc_input: Location,
reset_layers=True,
**kwds,
):
"""Perform the wave propagation.
Parameters
Expand All @@ -311,13 +342,7 @@ def __call__(self, motion, profile, loc_input):
loc_input: :class:`~.base.site.Location`
Location of the input motion.
"""
super().__call__(motion, profile, loc_input)

# Set initial properties
for layer in profile:
layer.reset()
if layer.strain is None:
layer.strain = 0.0
super().__call__(motion, profile, loc_input, reset_layers=reset_layers, **kwds)

self._calc_waves(motion.angular_freqs, profile)

Expand Down Expand Up @@ -526,7 +551,14 @@ def __init__(
self._max_iterations = max_iterations
self._strain_limit = strain_limit

def __call__(self, motion: Motion, profile: Profile, loc_input: Location):
def __call__(
self,
motion: Motion,
profile: Profile,
loc_input: Location,
reset_layers=True,
**kwds,
):
"""Perform the wave propagation.
Parameters
Expand All @@ -540,9 +572,11 @@ def __call__(self, motion: Motion, profile: Profile, loc_input: Location):
loc_input: :class:`~.base.site.Location`
Location of the input motion.
"""
super().__call__(motion, profile, loc_input)
super().__call__(motion, profile, loc_input, reset_layers=reset_layers, **kwds)

self._estimate_strains()
if reset_layers:
# Use the previously established layer strains
self._estimate_strains()

iteration = 0
# The iteration at which strains were last limited
Expand Down

0 comments on commit 9289e31

Please sign in to comment.