# Getting started with newmark

## Overview

`newmark` implements a four-workflow pipeline for probabilistic seismic performance analysis of slopes and embankments:

1. Dynamic Site Response — compute the fundamental period Ts and site-amplified UHS from the soil profile (`getSiteProperties`, `getCylinderRoots`, `fitSaF`).
2. Hazard import — import PSHA output from OpenQuake (`buildGMDP`).
3. Displacement curves — Monte Carlo Newmark ensemble Dn(ky) (`getDnKy`, `fitDnCurve`).
4. Seismic coefficient — invert ensemble draws to kmax(d*) (`invertDnDraws`).

This vignette demonstrates Workflows 3 and 4 using the bundled example dataset. For the full pipeline see the `pipeline` vignette (`vignette("pipeline", package = "newmark")`).

## Example dataset

`uhs.csv` is a site-amplified uniform-hazard spectrum included with the package: NBCC hazard model, Vs30 = 560 m/s, TR = 10 000 yr, with quantile levels 0.05–0.95 and mean (Mode B input).

    library(newmark)
    library(data.table)
    #>
    #> Attaching package: 'data.table'
    #> The following object is masked from 'package:base':
    #>
    #>     %notin%

    uhs <- fread(system.file("extdata", "uhs.csv", package = "newmark"))
    uhs[p %in% c("0.16", "mean", "0.84") & Tn <= 0.2, .(Tn, p, Sa)]
    #>        Tn      p      Sa
    #>     <num> <char>   <num>
    #>  1: 0.000   0.16 0.12513
    #>  2: 0.000   0.84 0.21655
    #>  3: 0.000   mean 0.18228
    #>  4: 0.050   0.16 0.39859
    #>  5: 0.050   0.84 0.69551
    #>  6: 0.050   mean 0.54639
    #>  7: 0.075   0.16 0.43086
    #>  8: 0.075   0.84 0.73093
    #>  9: 0.075   mean 0.57871
    #> 10: 0.100   0.16 0.41504
    #> 11: 0.100   0.84 0.72926
    #> 12: 0.100   mean 0.56767
    #> 13: 0.120   0.16 0.39547
    #> 14: 0.120   0.84 0.67237
    #> 15: 0.120   mean 0.53474
    #> 16: 0.150   0.16 0.36396
    #> 17: 0.150   0.84 0.61739
    #> 18: 0.150   mean 0.49354
    #> 19: 0.180   0.16 0.32485
    #> 20: 0.180   0.84 0.54772
    #> 21: 0.180   mean 0.44060
    #> 22: 0.200   0.16 0.29781
    #> 23: 0.200   0.84 0.49987
    #> 24: 0.200   mean 0.41868
    #>        Tn      p      Sa
    #>     <num> <char>   <num>

## Parameters

    # Ts: fundamental period of the sliding mass (s).
    # In production, derived from getSiteProperties() + getCylinderRoots()
    # using the soil USCS profile and slope geometry (Ishihara 1996,
    # Gazetas & Dakoulas 1985). Here set to a representative value.
    Ts <- 0.60

    # Mw: moment magnitude from PSHA disaggregation.
    Mw <- 6.8

    # Ensemble weights (0 = model inactive).
    weights <- c(AM88 = 1, JB07 = 0, BT07 = 1, SR08 = 1, BM17 = 0, BM19 = 1)

    # Displacement targets (cm).
    Da <- c(0.5, 2.5, 5.0, 25.0)

## Workflow 3 — Displacement curve Dn(ky)

    ky     <- getDnKy(uhs, Ts = Ts)
    result <- fitDnCurve(
      uhs     = uhs,
      ky      = ky,
      Ts      = Ts,
      Mw      = Mw,
      NS      = 200,
      weights = weights
    )

    result$curve[IDn == "ensemble" & p == "mean", .(ky, Dn)]
    #>             ky           Dn
    #>          <num>        <num>
    #>  1: 0.01000000 1.121272e+02
    #>  2: 0.01163118 9.693224e+01
    #>  3: 0.01352844 8.326480e+01
    #>  4: 0.01573517 7.099464e+01
    #>  5: 0.01830186 6.001353e+01
    #>  6: 0.02128722 5.022985e+01
    #>  7: 0.02475955 4.156492e+01
    #>  8: 0.02879828 3.395006e+01
    #>  9: 0.03349580 2.732386e+01
    #> 10: 0.03895957 2.162868e+01
    #> 11: 0.04531458 1.680673e+01
    #> 12: 0.05270620 1.279597e+01
    #> 13: 0.06130353 9.527087e+00
    #> 14: 0.07130325 6.922682e+00
    #> 15: 0.08293409 4.899072e+00
    #> 16: 0.09646214 3.369684e+00
    #> 17: 0.11219685 2.248552e+00
    #> 18: 0.13049819 1.456726e+00
    #> 19: 0.15178479 9.232847e-01
    #> 20: 0.17654363 5.808861e-01
    #> 21: 0.20534109 3.657307e-01
    #> 22: 0.23883592 2.330730e-01
    #> 23: 0.27779437 1.538469e-01
    #> 24: 0.32310764 1.032081e-01
    #> 25: 0.37581233 6.862348e-02
    #> 26: 0.43711410 4.512239e-02
    #> 27: 0.50841530 2.934577e-02
    #> 28: 0.59134701 1.888046e-02
    #> 29: 0.68780637 1.201908e-02
    #> 30: 0.80000000 7.571768e-03
    #>             ky           Dn
    #>          <num>        <num>

## Workflow 4 — Seismic coefficient kmax(d*)

    kmax <- invertDnDraws(result$draws, Da = Da, weights = weights)
    kmax[p %in% c("0.16", "mean", "0.84")]
    #>        Da      p       kmax
    #>     <num> <char>      <num>
    #>  1:   0.5   mean 0.16395083
    #>  2:   0.5   0.16 0.11503928
    #>  3:   0.5   0.84 0.21360317
    #>  4:   2.5   mean 0.09520809
    #>  5:   2.5   0.16 0.06372356
    #>  6:   2.5   0.84 0.12648907
    #>  7:   5.0   mean 0.07203611
    #>  8:   5.0   0.16 0.04653948
    #>  9:   5.0   0.84 0.09761571
    #> 10:  25.0   mean 0.03090696
    #> 11:  25.0   0.16 0.01579160
    #> 12:  25.0   0.84 0.04549790

`kmax` is in g. The normalised pseudostatic coefficient is Kh = kmax / PGA_rock x 100 %.

## Next steps

- `vignette("dynamic-site-response", package = "newmark")` — soil profile to fundamental period and site amplification (`getSiteProperties`, `geSiteTable`, `getCylinderRoots`, `fitModel.Ts`, `fitSaF`).
- `vignette("ensemble-formulation", package = "newmark")` — mathematical derivation of the probabilistic propagation.
- `vignette("pipeline", package = "newmark")` — the four-workflow overview at function level.
- Function reference: `?fitSaF`, `?getDnKy`, `?fitDnCurve`, `?invertDnDraws`, `?getSiteProperties`, `?getCylinderRoots`, `?buildGMDP`.