Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions IM/konno_ohmachi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 9 additions & 7 deletions src-rust/arias_intensity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
//! 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};

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.
Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions src-rust/cav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src-rust/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading