Skip to content

Commit

Permalink
New version preparation intermediate commit
Browse files Browse the repository at this point in the history
  • Loading branch information
devpro authored and devpro committed May 8, 2024
1 parent 6ac93ce commit 4f01b9a
Show file tree
Hide file tree
Showing 55 changed files with 699 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .src/criticality.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library(igraph)
library(pipenostics)

g <- graph_from_data_frame(m325testbench[, c("sender", "acceptor")])
g <- graph_from_data_frame(m325nxdata[, c("sender", "acceptor")])
x <- V(g)
checkmate::assert_true(is_dag(g))
n <- vapply(
Expand Down
12 changes: 5 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ Package: pipenostics
Type: Package
Title:
Diagnostics, Reliability and Predictive Maintenance of Pipeline Systems
Version: 0.2.0
Version: 0.2.1
Authors@R: person("Yuri", "Possokhov", email = "omega1x@gmail.com",
role = c("aut", "cre"), comment = c(ORCID = "0000-0002-3570-4337"))
Description: Functions representing some useful empirical and data-driven
models of heat loss, corrosion diagnostics, reliability and predictive
maintenance of pipeline systems. The package is an option for technical
engineering departments of heat generating and heat transfer companies
that use or plan to use regulatory calculations in their activities.
Methods are described in
Description: Functions that represent some useful empirical and data-driven
models for heat loss, corrosion diagnostics, and predictive maintenance of
pipeline systems. The package is designed for engineers who are involved in
exploratory or routine calculations. Methods are described in
Timashev et al. (2016) <doi:10.1007/978-3-319-25307-7>,
A.C.Reddy (2017) <doi:10.1016/j.matpr.2017.07.081>,
Minenergo (2008) <https://docs.cntd.ru/document/902148459>,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export(b31gmodpf)
export(b31gops)
export(b31gpf)
export(b31gsap)
export(b36d)
export(b36mass)
export(b36wth)
export(c_f)
export(c_k)
export(dnvpf)
Expand Down
18 changes: 16 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# pipenostics 0.2.0
# pipenostics 0.2.1

## Backlog

- add data to `b36pipedata` from API 5L Tables
- deprecate function `wth_d`
- spread diameter `d` and wall thickness `wth` checkmates to all functions with those arguments
- add `rulc` - remain useful life calculator

## Current version

- cosmetic improvements to documentation
- datasets `api5l3t` and `m325testbench` are renamed to `api5l3tdata` and `m325nxdata` appropriately for the purpose of unification with dataset naming rules
- functions `b36mass()`, `b36wth()` `b36d()` are introduced to calculate mass and geometric characteristics of actually manufactured pipes
- nominal specifications of the manufactured pipes now are represented in `b36pipedata`-dataset

## Version 0.2.0

- where possible and justified, support for multi-threaded data processing, based on the capabilities of the parallel package, has been added.
- functions for determining the state of water and steam ([IAPWS](http://www.iapws.org/)) have been excluded from the package due to the decision to use the built-in functions from [iapws](https://CRAN.R-project.org/package=data.table)-package imported from [CRAN](https://cran.r-project.org/).
- functions for determining the state of water and steam ([IAPWS](http://www.iapws.org/)) have been excluded from the package due to the decision to use the built-in functions from [iapws](https://CRAN.R-project.org/package=iapws)-package imported from [CRAN](https://cran.r-project.org/).
- set of functions `mgtdhid()`, `mgtdhidt()`, `mgtdhgeo()`, `mgtdhgeot()` are introduced to interface with *Modified Ground Temperature Double Harmonic Model*.
- function `meteos()` is introduced to get a list of weather stations
- functions `geodist()` and `geoarea()` for calculating geographical metrics are added.
Expand Down
23 changes: 18 additions & 5 deletions R/api5l3t.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
#'
#' Data represents specified minimum yield strength (SMYS) and ultimate
#' tensile strength (UTS) both achieved when producing line pipes
#' according to
#' \href{https://law.resource.org/pub/us/cfr/ibr/002/api.5l.2004.pdf}{API SPECIFICATION 5L}.
#' according to regulatory specifications.
#'
#' @format A data frame with 11 rows and 3 variables:
#' @format A data frame with 57 rows and 4 variables:
#'
#' \describe{
#' \item{grade}{designation of standard grade of manufactured pipe. Type: \code{\link{assert_character}}.}
#' \item{smys}{SMYS - specified minimum yield strength, [\emph{psi}]. Type: \code{\link{assert_double}}.}
#' \item{uts}{UTS - ultimate tensile strength, [\emph{psi}]. Type: \code{\link{assert_double}}.}
#' \item{origin}{
#' Identifier for the information origin regarding the specifications of pipe, []:
#' \describe{
#' \item{\code{10}}{\href{https://law.resource.org/pub/us/cfr/ibr/002/api.5l.2004.pdf}{API SPECIFICATION 5L}. Table 3A}
#' \item{\code{3}}{\href{https://docs.cntd.ru/document/1200002056}{GOST 20295-85}. Table 7}
#' \item{\code{11}}{\href{https://docs.cntd.ru/document/1200103221}{GOST 31443-2012}. Tables 6, 7}
#' }
#' Type: \code{\link{assert_integer}}.
#' }
#' }
#' @source \url{https://law.resource.org/pub/us/cfr/ibr/002/api.5l.2004.pdf}
"api5l3t"
#' @references
#' \enumerate{
#' \item \href{https://law.resource.org/pub/us/cfr/ibr/002/api.5l.2004.pdf}{API SPECIFICATION 5L}. Specification for Line Pipe
#' \item \href{https://docs.cntd.ru/document/1200002056}{GOST 20295-85}. Steel welded pipes for main gas-and-oil pipelines. Specifications
#' \item \href{https://docs.cntd.ru/document/1200103221}{GOST 31443-2012}. Steel pipes for crafts pipelines. Specifications
#' }
"api5l3tdata"
241 changes: 241 additions & 0 deletions R/b36mass.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
#' @title
#' Estimate pipe mass
#'
#' @family utils
#'
#' @description
#' Estimate mass or geometric specifications of the manufactured pipes
#'
#' @details
#' The mass of a one-meter pipe segment is determined by linear interpolation based on
#' the tabular data provided in the specified origins (see \code{\link{b36pipedata}}). If
#' the \code{origin} of the initial data is \code{NULL} (default), the mass of the pipe is calculated using a formula:
#' \deqn{M = 10^{-3} \pi \rho w \left(d - w \right ) \cdot l}
#' where
#' \itemize{
#' \item \eqn{M} - mass of a pipe, [\emph{kg}]
#' \item \eqn{\rho} - mass density of pipe material, [\emph{g/cm^3}]
#' \item \eqn{w} - nominal wall thickness of the manufactured pipe, [\emph{mm}]
#' \item \eqn{d} - nominal outside diameter of the manufactured pipe, [\emph{mm}]
#' \item \eqn{l} - actual pipe length, [\emph{m}]
#' }
#' For \code{origin} in \code{c(1, 2, 4, 5)} the values provided in the
#' \code{\link{b36pipedata}} match the calculated values obtained from the formula
#' with an accuracy of 1 \%.
#'
#' Inverse calculations \code{\link{b36wth}} and \code{\link{b36d}} are performed using
#' algebraically derived formulas.
#'
#' @param d
#' nominal outside diameter of pipe, [\emph{mm}]. Type: \code{\link{assert_double}}
#'
#' @param wth
#' nominal wall thickness of pipe, [\emph{mm}]. Type: \code{\link{assert_double}}.
#'
#' @param len
#' pipe length, [\emph{m}]. Type: \code{\link{assert_double}}.
#'
#' @param rho
#' mass density of pipe material, [\emph{g/cm^3}]. Type: \code{\link{assert_double}}.
#'
#' @param origin
#' identifier for the information origin regarding the specifications of pipe.
#' Type: \code{\link{assert_integer}}.
#'
#' @param mass
#' actual mass of pipe, [\emph{kg}]. Type: \code{\link{assert_double}}.
#'
#' @return
#' \describe{
#' \item{for \code{\link{b36mass}}}{pipe mass, [\emph{kg}]}
#' \item{for \code{\link{b36wth}}}{pipe wall thickness, [\emph{mm}]}
#' \item{for \code{\link{b36d}}}{outside diameter of pipe, [\emph{mm}]}
#' }
#'
#' @examples
#' library(pipenostics)
#' # Since some specification origins provide the mass of a one-meter pipe segment taking
#' # into account possible deviations during its production process, when the user
#' # specifies the origin ID directly, the mass values are calculated using linear
#' # interpolation:
#' b36mass(68, 13, rho = 7.9, origin = 7L)
#' # [1] 16.43
#'
#' # The discrepancy with the calculations based on the formula can be more than 7 %:
#' b36mass(68, 13, rho = 7.9, origin = NULL)
#' # [1] 17.74529
#'
#' # For origins which are ASME B36 standards such differences should be minimal:
#' b36mass(965, 10.31, origin = 1L) - b36mass(965, 10.31, origin = NULL)
#' # [1] 0.0004356046
#'
#' # The calculations of diameter and wall thickness are straightforward and use
#' # only inverse formulas without origin references:
#' b36d(10.31, 242.74)
#' # [1] 965.0017
#'
#' b36wth(965, 242.74)
#' # [1] 10.31002
#'
#' @rdname b36mass
#' @export
b36mass <- function(d, wth, len = 1, rho = 7.85, origin = NULL) {
L_ORIGIN <- "origin"
L_DIAMETER <- "d"
L_THICKNESS <- "wth"
L_LENGTH <- "len"
L_DENSITY <- "rho"
L_MASS <- "mass"
L_ONE <- L_FIRST <- 1L
L_TWO <- 2
D_OFFSET <- .4 # Pipe diameter tolerance, [mm]

md <- pipenostics::b36pipedata
checkmate::assert_double(
d,
lower = min(md[[L_DIAMETER]]) - D_OFFSET, upper = max(md[[L_DIAMETER]]) + D_OFFSET,
any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_double(
wth,
lower = min(md[[L_THICKNESS]]), upper = max(md[[L_THICKNESS]]),
any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_double(
len,
lower = 0, finite = TRUE, any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_double(
rho,
lower = 7.75, upper = 8.05, any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_true(commensurable(c(length(d), length(wth), length(len), length(rho))))
checkmate::assert_double(
wth/d,
lower = .Machine[["double.eps"]], upper = max(md[[L_THICKNESS]]/md[[L_DIAMETER]])
)
checkmate::assert_integer(
origin,
lower = min(md[[L_ORIGIN]]), upper = max(md[[L_ORIGIN]]),
any.missing = FALSE, min.len = L_ONE, max.len = length(unique(md[[L_ORIGIN]])),
unique = TRUE, null.ok = TRUE
)

pipe_mass <- (d - wth) * 1e-3 * wth * rho * len * base::pi
if (is.null(origin)) return(pipe_mass)

C <- data.frame(
a = c(
1.34639486196096e-05, -0.269421768471856, -0.543828305826526,
-0.32040873191324 , -0.001023302221079, 0.000750308148511,
-8.88387684950809e-05
),
b = c(
0.99993868472687, 1.06490339805795, 1.07025471029979 ,
1.04765386422189, 1.00035194161928, 0.999990376939387 ,
1.00000056550023
)
)
pipe <- data.frame(d = d, wth = wth, len = len, rho = rho)
md <- md[md[[L_ORIGIN]] %in% origin, ]
vapply(
seq_len(nrow(pipe)),
function(i){
m <- md[
md[[L_DIAMETER ]] == pipe[i, L_DIAMETER ] &
md[[L_THICKNESS]] == pipe[i, L_THICKNESS] &
md[[L_DENSITY ]] == pipe[i, L_DENSITY ]
,
L_MASS
]
if (isTRUE(as.logical(length(m)))) return(m[[L_FIRST]])
if (
pipe[i, L_DIAMETER] < min(md[[L_DIAMETER]]) - D_OFFSET |
pipe[i, L_DIAMETER] > max(md[[L_DIAMETER]]) + D_OFFSET
) return(NA_real_)
dst <- (md[[L_DIAMETER ]] - pipe[i, L_DIAMETER ])^L_TWO +
(md[[L_THICKNESS]] - pipe[i, L_THICKNESS])^L_TWO +
(md[[L_DENSITY ]] - pipe[i, L_DENSITY ])^L_TWO
oid <- md[which.min(dst), L_ORIGIN]
pipe_mass[[i]] * C[oid, "b"] + C[oid, "a"]
},
double(L_ONE)
) * pipe[[L_LENGTH]]
}

#' @rdname b36mass
#' @export
b36d <- function(wth, mass, len = 1, rho = 7.85) {
L_THICKNESS <- "wth"
L_MASS <- "mass"
L_ONE <- 1L

md <- pipenostics::b36pipedata
checkmate::assert_double(
wth,
lower = min(md[[L_THICKNESS]]), upper = max(md[[L_THICKNESS]]),
any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_double(
mass,
lower = 0, finite = TRUE, any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_double(
len,
lower = 0.1, finite = TRUE, any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_double(
rho,
lower = 7.75, upper = 8.05, any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_true(commensurable(c(length(wth), length(mass), length(len), length(rho))))

unit_mass <- mass/len
checkmate::assert_double(
unit_mass,
lower = min(md[[L_MASS]]), upper = max(md[[L_MASS]]),
any.missing = FALSE, min.len = L_ONE
)
1e3 * unit_mass/base::pi/wth/rho + wth
}

#' @rdname b36mass
#' @export
b36wth <- function(d, mass, len = 1, rho = 7.85) {
L_DIAMETER <- "d"
L_MASS <- "mass"
L_ONE <- 1L
D_OFFSET <- .4 # Pipe diameter tolerance, [mm]

md <- pipenostics::b36pipedata
checkmate::assert_double(
d,
lower = min(md[[L_DIAMETER]]) - D_OFFSET, upper = max(md[[L_DIAMETER]]) + D_OFFSET,
any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_double(
mass,
lower = 0, finite = TRUE, any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_double(
len,
lower = 0.1, finite = TRUE, any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_double(
rho,
lower = 7.75, upper = 8.05, any.missing = FALSE, min.len = L_ONE
)
checkmate::assert_true(commensurable(c(length(d), length(mass), length(len), length(rho))))

unit_mass <- mass/len
checkmate::assert_double(
unit_mass,
lower = min(md[[L_MASS]]), upper = max(md[[L_MASS]]),
any.missing = FALSE, min.len = L_ONE
)

r <- .5 * d
D <- r^2 - unit_mass/base::pi/rho * 1e3
D[D < 0] <- NA_real_
r - sqrt(D)
}
47 changes: 47 additions & 0 deletions R/b36pipedata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' Specifications of the manufactured pipes
#'
#' Data represents the nominal specifications of steel pipes produced
#' by the industry according to regulatory standards.
#'
#' @family utils
#'
#' @format A data frame with 6064 rows and 5 variables:
#' \describe{
#' \item{d}{Nominal outside diameter of the manufactured pipe, [\emph{mm}]. Type: \code{\link{assert_double}}.}
#' \item{wth}{Nominal wall thickness of the manufactured pipe, [\emph{mm}]. Type: \code{\link{assert_double}}.}
#' \item{rho}{Nominal mass density of the steel rank applied in the pipe manufacturing, [\emph{g/cm³}]. Type: \code{\link{assert_double}}.}
#' \item{mass}{Nominal mass of one-meter length pipe segment, [\emph{kg}]. Type: \code{\link{assert_double}}.}
#' \item{origin}{
#' Identifier for the information origin regarding the specifications of pipe, []:
#' \describe{
#' \item{\code{1}}{\href{https://www.asme.org/codes-standards/find-codes-standards/b36-10m-welded-seamless-wrought-steel-pipe/2018/nondrm-enabled-pdf}{ASME B36.10M-2018}}
#' \item{\code{2}}{\href{https://www.asme.org/codes-standards/find-codes-standards/b36-19m-stainless-steel-pipe}{ASME B36.19M-2018}}
#' \item{\code{3}}{\href{https://docs.cntd.ru/document/1200002056}{GOST 20295-85}. Table 1}
#' \item{\code{4}}{\href{https://docs.cntd.ru/document/1200129487}{GOST 33229-2015}. Table 1}
#' \item{\code{5}}{\emph{GOST 33229-2015}. Table 2}
#' \item{\code{6}}{\href{https://docs.cntd.ru/document/1200144603}{GOST R 57423-2017}. Table 1}
#' \item{\code{7}}{\emph{GOST R 57423-2017}. Table 2}
#' \item{\code{8}}{\emph{GOST R 57423-2017}. Table 3}
#' \item{\code{9}}{\emph{GOST R 57423-2017}. Table 4}
#' }
#' Type: \code{\link{assert_integer}}.
#' }
#' }
#' \emph{NOTE!} Due to numerous typos in origins with identifiers \code{4}, \code{5} all mass values in those origins are the recalculations made with formula
#' \deqn{M = 0.02466 \cdot w\left(d - w \right )}
#' where
#' \itemize{
#' \item \eqn{M} - mass of one-meter pipe segment, [\emph{kg}]
#' \item \eqn{d} - nominal outside diameter of the manufactured pipe, [\emph{mm}]
#' \item \eqn{w} (\code{wth}) - nominal wall thickness of the manufactured pipe, [\emph{mm}]
#' }
#'
#' @references
#' \enumerate{
#' \item \href{https://www.asme.org/codes-standards/find-codes-standards/b36-10m-welded-seamless-wrought-steel-pipe/2018/nondrm-enabled-pdf}{ASME B36.10M-2018}. Welded and seamless wrought steel pipe
#' \item \href{https://www.asme.org/codes-standards/find-codes-standards/b36-19m-stainless-steel-pipe}{ASME B36.19M-2018}. Stainless steel pipe
#' \item \href{https://docs.cntd.ru/document/1200002056}{GOST 20295-85}. Steel welded pipes for main gas-and-oil pipelines. Specifications
#' \item \href{https://docs.cntd.ru/document/1200129487}{GOST 33229-2015}. Tubes for boiler and heat exchanging equipment. Technical specifications. Part 1. Seamless steel pipes to work under pressure not more than 6,4 MPa and at temperatures not exceeding 400°C
#' \item \href{https://docs.cntd.ru/document/1200144603}{GOST R 57423-2017}. Tubes for boiler and heat exchanging equipment. Part 2. Seamless steel tubes for pressure purposes more 6,4 MPa and temperatures exceeding 400°C. Specifications
#' }
"b36pipedata"
Loading

0 comments on commit 4f01b9a

Please sign in to comment.