arma-thesis

Simulation modelling of irregular waves for marine object dynamics programmes
git clone https://git.igankevich.com/arma-thesis.git
Log | Files | Refs | LICENSE

nonlinear.R (1997B)


      1 arma.middle_element <- function (x) {
      2   x[round(length(x) + 0.5)*2/3]
      3 }
      4 
      5 arma.read_zeta_slice <- function (filename) {
      6   # slice time and Y ranges through the center
      7   zeta <- read.csv(filename)
      8   slice_t <- arma.middle_element(unique(zeta$t))
      9   slice_y <- arma.middle_element(unique(zeta$y))
     10 
     11   # get wave profile
     12   slice_y <- arma.middle_element(unique(zeta$y))
     13   print(paste('Middle elements of zeta (TY) = ', slice_t, slice_y))
     14   zeta[zeta$t == slice_t & zeta$y == slice_y,]
     15 }
     16 
     17 arma.plot_nonlinear <- function (dirname, args) {
     18 
     19   zeta_none <- arma.read_zeta_slice(file.path(dirname, 'zeta-none.csv'))
     20   zeta_gcs <- arma.read_zeta_slice(file.path(dirname, 'zeta-gramcharlier.csv'))
     21   zeta_sn <- arma.read_zeta_slice(file.path(dirname, 'zeta-skewnormal.csv'))
     22 
     23   x <- unique(zeta_none$x)
     24   z <- unique(zeta_none$z)
     25 
     26   # plot the graph
     27   rx <- range(x)
     28   rz <- range(z)
     29   aspect_ratio <- 1
     30   plot.new()
     31   plot.window(xlim=rx, ylim=rz, asp=1)
     32   axis_args <- list()
     33   if ("axis" %in% names(args)) {
     34      axis_args <- args$axis
     35   }
     36   do.call(axis, c(list(side=1), axis_args))
     37   do.call(axis, c(list(side=2), axis_args))
     38   lines(zeta_none$x, zeta_none$z, lty='solid')
     39   lines(zeta_gcs$x, zeta_gcs$z, lty='dashed')
     40   lines(zeta_sn$x, zeta_sn$z, lty='dotted')
     41   title(args$title, xlab="x", ylab="z")
     42   box()
     43   legend_x <- "bottom"
     44   if ("legend" %in% names(args)) {
     45     legend_x <- args$legend
     46   }
     47   legend(
     48     legend_x,
     49     legend=paste(args$graphs),
     50     lty=paste(args$linetypes),
     51     horiz=TRUE
     52   )
     53 }
     54 
     55 arma.wave_height <- function (realisation) {
     56   sqrt(2*pi*var(realisation))
     57 }
     58 
     59 arma.print_wave_height <- function (dirname) {
     60   zeta_none <- read.csv(file.path(dirname, 'zeta-none.csv'))
     61   zeta_gcs <- read.csv(file.path(dirname, 'zeta-gramcharlier.csv'))
     62   zeta_sn <- read.csv(file.path(dirname, 'zeta-skewnormal.csv'))
     63   library('ascii')
     64   options(asciiType='org')
     65   data.frame(
     66     h1=arma.wave_height(zeta_none$z),
     67     h2=arma.wave_height(zeta_gcs$z),
     68     h3=arma.wave_height(zeta_sn$z)
     69   )
     70 }