diff --git a/R/anchor.R b/R/anchor.R index 7e17e86..f3704d4 100644 --- a/R/anchor.R +++ b/R/anchor.R @@ -31,9 +31,9 @@ #' #' @author Dan Kelley anchor <- function(model = "1 Railway Wheel", buoyancy = NULL, height = NULL, CD = NULL) { - #message("about to try anchorS7...") - #print(anchorS7()) - #message("... did it work?") + # message("about to try anchorS7...") + # print(anchorS7()) + # message("... did it work?") data("mooringElements", package = "mooring", envir = environment()) mooringElements <- get("mooringElements") if (model == "?") { @@ -67,16 +67,15 @@ anchor <- function(model = "1 Railway Wheel", buoyancy = NULL, height = NULL, CD #' Find Anchor Weight of a Mooring #' -#' @param m an object of class `"mooring"`, created with [mooring()]. +#' @template mTemplate #' -#' @return `anchorWeight` returns the weight (i.e. the negative of the -#' buoyancy) of the anchor in the mooring. +#' @return `anchorWeight` returns the weight of the mooring anchor, +#' in kg. #' #' @export #' #' @author Dan Kelley -anchorWeight <- function(m) -{ +anchorWeight <- function(m) { if (!is.mooring(m)) { stop("m must be a mooring object, created with mooring()") } diff --git a/R/app2bs.R b/R/app2bs.R index a5fd581..40cdeb1 100644 --- a/R/app2bs.R +++ b/R/app2bs.R @@ -404,7 +404,7 @@ app2bs <- function(debug = FALSE) { "exp(-depth/300)" = function(depth) input$u * exp(-depth / 300) ) msk <- knockdown(ms, u, debug = debug) - attr <- attributes(msk) + diagnostics <- msk@diagnostics mar <- c(0.5, 2.5, 3.75, 0.5) mgp <- c(1.5, 0.5, 0) cex <- 1.2 @@ -437,14 +437,14 @@ app2bs <- function(debug = FALSE) { if (!titleShown) { mtext( sprintf( - if (attr$converged) { + if (diagnostics$converged) { "Converged to %.03fm and %.02fdeg in %s" } else { "Not yet converged (%.03fm and %.02fdeg in %s)" }, - attr$RMSDepthChange, - attr$RMSAngleChange, - pluralize("iteration", n = attr$iteration) + diagnostics$RMSDepthChange, + diagnostics$RMSAngleChange, + pluralize("iteration", n = diagnostics$iteration) ), cex = par("cex"), col = 2, diff --git a/R/knockdown.R b/R/knockdown.R index 12ebca0..d9ac201 100644 --- a/R/knockdown.R +++ b/R/knockdown.R @@ -13,7 +13,7 @@ #' Examples 2 and 3. #' #' @param m an object of the `"mooring"` class, usually created with -#' [segmentize()]. +#' [mooring()], followed by a call to [segmentize()]. #' #' @template uTemplate #' @@ -200,9 +200,19 @@ knockdown <- function(m, u = 1, convergence = 0.1, maxiteration = 100, debug = 0 )) } m@u <- u - attr(m, "iteration") <- iterationCount - attr(m, "RMSAngleChange") <- 180 / pi * RMSAngleChange - attr(m, "RMSDepthChange") <- RMSDepthChange - attr(m, "converged") <- iterationCount < maxiteration + insufficientBuoyancy <- max(depth(m)) > waterDepth + #attr(m, "iteration") <- iterationCount + #attr(m, "RMSAngleChange") <- 180 / pi * RMSAngleChange + #attr(m, "RMSDepthChange") <- RMSDepthChange + #attr(m, "converged") <- iterationCount < maxiteration + #attr(m, "insufficientBuoyancy") <- insufficientBuoyancy + m@attributes$iteration <- iterationCount + m@attributes$RMSAngleChange <- 180 / pi * RMSAngleChange + m@attributes$RMSDepthChange <- RMSDepthChange + m@attributes$converged <- iterationCount < maxiteration + m@attributes$insufficientBuoyancy <- insufficientBuoyancy + if (insufficientBuoyancy) { + warning("More buoyancy is needed to lift all mooring elements off the bottom") + } m } # knockdown() diff --git a/R/oo.R b/R/oo.R index 97e7b0e..5e138b9 100644 --- a/R/oo.R +++ b/R/oo.R @@ -4,7 +4,8 @@ mooringS7 <- S7::new_class("mooringS7", properties = list( elements = class_list, # holds mooringElement items waterDepth = class_numeric, - u = class_any + u = class_any, + attributes = class_list ), validator = function(self) { NULL @@ -15,7 +16,10 @@ mooringS7 <- S7::new_class("mooringS7", # cat("elements[[1]] follows\n");print(elements[[1]]) if (!is.anchor(elements[[1]])) stop("element 1 is not an anchor") if (is.na(waterDepth)) stop("must specify waterDepth") - new_object(S7_object(), elements = elements, waterDepth = waterDepth, u = 0.0) + new_object(S7_object(), + elements = elements, waterDepth = waterDepth, u = 0.0, + attributes = list() + ) } ) @@ -273,7 +277,7 @@ S7::method(`plot`, mooring:::mooringS7) <- function( # message("plot 15") # draw anchor (only makes sense for shape diagrams) if (which == "shape") { - waterDepth <- attr(m, "waterDepth") + waterDepth <- m@waterDepth n <- length(m@elements) A <- m@elements[[n]]@height anchorSymbol <- list(x = sqrt(3.0 / 4.0) * c(-A, 0, A), y = waterDepth - c(0, A, 0)) @@ -403,6 +407,11 @@ S7::method(`plot`, mooring:::mooringS7) <- function( } } mtext(title, side = 1, cex = par("cex")) + if (isTRUE(m@attributes$insufficientBuoyancy)) { + mtext("mooring needs more buoyancy", + side = 3, line = -1, cex = 1.1 * par("cex"), col = 2 + ) + } mooringDebug(debug, "} # plot()\n", sep = "") } @@ -435,16 +444,16 @@ S7::method(`summary`, mooring:::mooringS7) <- function( stop("internal programming error: how did an element call this?") } n <- length(x@elements) - if (is.null(attr(x, "segmentized"))) { + if (!isTRUE(x@attributes$segmentized)) { cat(sprintf( "Mooring in %gm of water that has %d elements, listed from the top down:\n", x@waterDepth, n )) } else { - if (is.null(attr(x, "u"))) { + if (is.null(x@u)) { cat("Segmentized mooring with", n, "elements, listed from the top down:\n") } else { - cat("Segmentized a knocked-over mooring with", n, "elements, listed from the top down:\n") + cat("Segmentized knocked-over mooring with", n, "elements, listed from the top down:\n") } } prefix <- " " diff --git a/docs/articles/object_orientation.html b/docs/articles/object_orientation.html index 806386f..1a439d3 100644 --- a/docs/articles/object_orientation.html +++ b/docs/articles/object_orientation.html @@ -231,7 +231,8 @@

2024-06-11

## .. ..@ tau : num 310 ## .. ..@ group : num 0 ## @ waterDepth: num 100 -## @ u : num 0 +## @ u : num 0 +## @ attributes: list()

The way to get the top element is e.g.

 m@elements[[1]]
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index b4a190b..be96f12 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -8,5 +8,5 @@ articles: mooring: mooring.html object_orientation: object_orientation.html table_tennis: table_tennis.html -last_built: 2024-06-11T11:57Z +last_built: 2024-06-11T17:31Z diff --git a/docs/reference/anchorWeight.html b/docs/reference/anchorWeight.html index f1e4e48..69371c0 100644 --- a/docs/reference/anchorWeight.html +++ b/docs/reference/anchorWeight.html @@ -84,15 +84,15 @@

Find Anchor Weight of a Mooring

Arguments

m
-

an object of class "mooring", created with mooring().

+

a mooring object, created by mooring().

Value

-

anchorWeight returns the weight (i.e. the negative of the -buoyancy) of the anchor in the mooring.

+

anchorWeight returns the weight of the mooring anchor, +in kg.

Author

diff --git a/docs/reference/knockdown.html b/docs/reference/knockdown.html index f5abfd1..76deee6 100644 --- a/docs/reference/knockdown.html +++ b/docs/reference/knockdown.html @@ -99,7 +99,7 @@

Compute mooring knockdown by a horizontal current

Arguments

m

an object of the "mooring" class, usually created with -segmentize().

+mooring(), followed by a call to segmentize().

u
diff --git a/docs/reference/summaryMooring.html b/docs/reference/summaryMooring.html index 466e3b7..e137dcf 100644 --- a/docs/reference/summaryMooring.html +++ b/docs/reference/summaryMooring.html @@ -150,6 +150,7 @@

Examples

#> .. ..@ group : num 0 #> @ waterDepth: num 100 #> @ u : num 0 +#> @ attributes: list()
diff --git a/man/anchorWeight.Rd b/man/anchorWeight.Rd index a0cf69b..1624c67 100644 --- a/man/anchorWeight.Rd +++ b/man/anchorWeight.Rd @@ -7,11 +7,11 @@ anchorWeight(m) } \arguments{ -\item{m}{an object of class \code{"mooring"}, created with \code{\link[=mooring]{mooring()}}.} +\item{m}{a mooring object, created by \code{\link[=mooring]{mooring()}}.} } \value{ -\code{anchorWeight} returns the weight (i.e. the negative of the -buoyancy) of the anchor in the mooring. +\code{anchorWeight} returns the weight of the mooring anchor, +in kg. } \description{ Find Anchor Weight of a Mooring diff --git a/man/knockdown.Rd b/man/knockdown.Rd index ecad9cf..8e5104a 100644 --- a/man/knockdown.Rd +++ b/man/knockdown.Rd @@ -8,7 +8,7 @@ knockdown(m, u = 1, convergence = 0.1, maxiteration = 100, debug = 0L) } \arguments{ \item{m}{an object of the \code{"mooring"} class, usually created with -\code{\link[=segmentize]{segmentize()}}.} +\code{\link[=mooring]{mooring()}}, followed by a call to \code{\link[=segmentize]{segmentize()}}.} \item{u}{either a non-negative number indicating depth-independent velocity, or a function that returns that velocity as a function of depth (m)