use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Vs30Point {
pub lon: f64,
pub lat: f64,
pub vs30: f64,
#[serde(default)]
pub dl: Option<f64>,
#[serde(default)]
pub xvf: Option<u8>,
}
#[derive(Debug)]
pub enum Magnitude {
Mw,
Ml,
}
#[derive(Debug)]
pub struct Earthquake {
pub lon: f64,
pub lat: f64,
pub depth: f64,
pub magnitude: f64,
pub magnitude_kind: Magnitude,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum GmpePointKind {
Pga,
Psa,
Pgv,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GmpePoint {
pub lon: f64,
pub lat: f64,
pub value: f64,
pub kind: GmpePointKind,
}
pub trait GroundMotionModeling {
fn calc_from_point(&self, point: &Vs30Point, eq: &Earthquake) -> GmpePoint;
}
impl Vs30Point {
pub fn new(lon: f64, lat: f64, vs30: f64, dl: Option<f64>, xvf: Option<u8>) -> Self {
Self {
lon,
lat,
vs30,
dl,
xvf,
}
}
pub fn get_gm<T: GroundMotionModeling>(&self, gmpe: &T, eq: &Earthquake) -> GmpePoint {
gmpe.calc_from_point(self, eq)
}
}
impl Earthquake {
pub fn new(lon: f64, lat: f64, depth: f64, magnitude: f64, magnitude_kind: Magnitude) -> Self {
Self {
lon,
lat,
depth,
magnitude,
magnitude_kind,
}
}
pub fn new_ml(lon: f64, lat: f64, depth: f64, magnitude: f64) -> Self {
Self::new(lon, lat, depth, magnitude, Magnitude::Ml)
}
pub fn new_mw(lon: f64, lat: f64, depth: f64, magnitude: f64) -> Self {
Self::new(lon, lat, depth, magnitude, Magnitude::Mw)
}
}
impl GmpePoint {
pub fn new(lon: f64, lat: f64, value: f64, kind: GmpePointKind) -> Self {
Self {
lon,
lat,
value,
kind,
}
}
pub fn new_pga(lon: f64, lat: f64, value: f64) -> Self {
Self::new(lon, lat, value, GmpePointKind::Pga)
}
pub fn new_pgv(lon: f64, lat: f64, value: f64) -> Self {
Self::new(lon, lat, value, GmpePointKind::Pgv)
}
pub fn new_psa(lon: f64, lat: f64, value: f64) -> Self {
Self::new(lon, lat, value, GmpePointKind::Psa)
}
}