diff --git a/IM/konno_ohmachi.py b/IM/konno_ohmachi.py index 4a039b80..18023f45 100644 --- a/IM/konno_ohmachi.py +++ b/IM/konno_ohmachi.py @@ -176,9 +176,10 @@ def get( with self._lock: if (matrix := self._cache.get(key)) is not None: # NOTE: Python dicts maintain insertion order. Doing a pop and - # re-insert shifts the key to the front of the insertion order - # which makes the dict a cheap LRU cache. Functools implements a - # doubly-linked list which is great but extra bookkeeping. + # re-insert moves the key to the end of the insertion order + # (most recently used), which makes the dict a cheap LRU cache. + # Functools implements a doubly-linked list which is great but + # extra bookkeeping. self._cache[key] = self._cache.pop(key) return matrix diff --git a/src-rust/arias_intensity.rs b/src-rust/arias_intensity.rs index baf2e216..f93183dc 100644 --- a/src-rust/arias_intensity.rs +++ b/src-rust/arias_intensity.rs @@ -3,10 +3,12 @@ //! This module provides functions to calculate the intensity of earthquake ground motion //! based on the integral of the square of acceleration. //! -//! The formula used is: -//! $$I_A = \frac{\pi}{2g} \int_{0}^{T} a(t)^2 \, dt$$ +//! The formula used, for acceleration $a$ expressed in units of $g$, is: +//! $$I_A = \frac{\pi g}{2} \int_{0}^{T} a(t)^2 \, dt$$ //! -//! Where $g$ is the acceleration due to gravity (set here to $9.81 \text{ m/s}^2$). +//! This is equivalent to the standard $I_A = \frac{\pi}{2g} \int_{0}^{T} a(t)^2 \, dt$ +//! with $a(t)$ in physical units. Here $g$ is the acceleration due to gravity +//! (set here to $9.81 \text{ m/s}^2$). use crate::trapz::{cumulative_trapz_with_fun, trapz_with_fun}; @@ -14,7 +16,7 @@ use crate::constants::G; use ndarray::prelude::*; use std::f64::consts::PI; -/// Precomputed scaling factor: $\frac{\pi}{2g}$ +/// Precomputed scaling factor: $\frac{\pi g}{2}$ const ARIAS_CONSTANT: f64 = G * PI / 2.0; /// Computes the total Arias Intensity ($I_A$) for each row. @@ -45,14 +47,14 @@ mod tests { #[test] fn test_arias_physical_constant() { - // If a = 1.0 cm/s^2 (constant) for 1 second with dt=1 + // If a = 1.0 g (constant) for 1 second with dt=1 // Integral of a^2 dt from 0 to 1 is 1.0. - // Result should be PI / (2.0 * 981.0) + // Result should be 9.81 * PI / 2.0 let waveforms = array![[1.0, 1.0]]; let dt = 1.0; let result = arias_intensity(waveforms.view(), dt); - let expected = ARIAS_CONSTANT; + let expected = 9.81 * PI / 2.0; assert_abs_diff_eq!(result[0], expected, epsilon = 1e-10); } diff --git a/src-rust/cav.rs b/src-rust/cav.rs index d6aba2a4..18ea2b91 100644 --- a/src-rust/cav.rs +++ b/src-rust/cav.rs @@ -3,8 +3,8 @@ //! This module provides functions to calculate the intensity of earthquake ground motion //! based on the integral of the absolute value of acceleration. //! -//! The formula used is: -//! $$CAV = \int_{0}^{T} |a(t)| \, dt$$ +//! The formula used, for acceleration $a$ expressed in units of $g$, is: +//! $$CAV = g \int_{0}^{T} |a(t)| \, dt$$ //! use crate::constants::G; @@ -30,9 +30,9 @@ mod tests { #[test] fn test_cav_constant() { - // If a = 1.0 cm/s^2 (constant) for 1 second with dt = 1 + // If a = 1.0 g (constant) for 1 second with dt = 1 // Integral of |a| dt from 0 to 1 is 1.0. - // Result should be G (9.81 cm/s) + // Result should be G (9.81 m/s) let waveforms = array![[1.0, 1.0]]; let dt = 1.0; let result = cav(waveforms.view(), dt); diff --git a/src-rust/constants.rs b/src-rust/constants.rs index b3e2cc08..2559ed6d 100644 --- a/src-rust/constants.rs +++ b/src-rust/constants.rs @@ -2,6 +2,3 @@ /// Gravitational acceleration in m/s². pub const G: f64 = 9.81; - -/// Gravitational acceleration in cm/s² (Gal). -pub const GAL: f64 = 981.0;