Commit 9073fd9b authored by Ahmad Alkadri's avatar Ahmad Alkadri 🎧
Browse files

Putting the functions

parent 57e7b0f1
^.*\.Rproj$
^\.Rproj\.user$
Package: woodhyst
Type: Package
Title: Modeling Wood Moisture Hysteresis Curves
Date: 2019-08-27
Version: 0.1.0
Authors@R:
person(given = "Ahmad",
family = "Alkadri",
role = c("aut", "cre"),
email = "ahmad.alkadri@umontpellier.fr")
Maintainer: Ahmad Alkadri <ahmad.alkadri@umontpellier.fr>
Description: This is an R package with functions
useful for modeling the hysteresis curves of
wood's equilibrium moisture content.
It is largely based on Pederson's and
Merakeb's hysteresis model.
Imports: rio
Depends: R (>= 3.0.0)
License: GPL-2
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
exportPattern("^[[:alpha:]]+")
#' w_after: predicting the EMC of wood for a series of imposed humidity
#'
#' @description A function for predicting the moisture content of wood
#' after its surrounding atmosphere's humidity changed
#'
#' @usage w_after(w_i,h_f,h_c,w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD)
#'
#' @param w_i the initial moisture content of wood measured at RH = h_c
#'
#' @param h_c the initial RH of the atmosphere,
#' wherein the w_i value was measured
#'
#' @param h_f the actual RH of the atmosphere surrounding the wood
#'
#' @param w_s the fiber saturation point of the wood, defaulted at 0.25 (25\%)
#'
#' @param phi_a the material's parameter for adsorption
#'
#' @param phi_d the material's parameter for desorption
#'
#' @param asoi the fitting parameter for adsorption
#'
#' @param adoi the fitting parameter for desorption
#'
#' @param AA the fitting parameter for hysteresis (1)
#'
#' @param BB the fitting parameter for hysteresis (2)
#'
#' @param DD the fitting parameter for hysteresis (3)
#'
#' @return the current moisture content of wood at RH = h_c
#'
#' @examples
#'
#' # Example for ebony wood
#' w_i = 0.03 #Initial moisture content = 3%
#'
#' h_c = 0.20 #Initial relative humidity = 20%
#'
#' h_f = 0.50 #Current relative humidity of the surrounding wood
#'
#' # Material parameters:
#' phi_d <- 0.556
#' phi_a <- 1.707
#' w_s <- 0.16 #Fiber saturation point = 16%
#' asoi <- 0.007
#' adoi <- 0.669
#' AA <- 0.328
#' DD <- -0.099
#' BB <- 0.411
#'
#' # Calculation:
#'
#' w_after(w_i,h_f,h_c,w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD)
w_after <- function(w_i,h_f,h_c,w_s=0.25,phi_a,phi_d,asoi,adoi,AA,BB,DD) {
##Implementation of Merakeb's EMC formula in R
w_a = w_s*(exp(phi_a*(log(h_c))*(exp(h_c*asoi))))
wf_a = w_s*(exp(phi_a*(log(h_f))*(exp(h_f*asoi))))
w_d = w_s*(exp(phi_d*(log(h_c))*(exp(h_c*adoi))))
wf_d = w_s*(exp(phi_d*(log(h_f))*(exp(h_f*adoi))))
if(h_c==0 | w_i==0 | h_c == w_s){
stop("ERROR: please choose humidity other than 0 or w_s OR MC initial not 0")
}
##dw_a et dw_d
dw_a = (((h_c^-1)*(exp(h_c*asoi))) + (log(h_c))*(exp(h_c*asoi))*asoi)*(w_s*phi_a*(exp(phi_a*(log(h_c))*(exp(h_c*asoi)))))
dw_d = (((h_c^-1)*(exp(h_c*adoi))) + (log(h_c))*(exp(h_c*adoi))*adoi)*(w_s*phi_d*(exp(phi_d*(log(h_c))*(exp(h_c*adoi)))))
##dwdh_a
dwdh_a = (abs((w_i-w_a)/(w_d-w_a))^BB)*AA*dw_d + (abs((w_i-w_d)/(w_d-w_a))^BB)*dw_a
dwdh_d = (abs((w_i-w_a)/(w_d-w_a))^BB)*dw_d + (abs((w_i-w_d)/(w_d-w_a))^BB)*DD*dw_a
##dw/dh actuel
if (h_f<h_c){
dwdh = dwdh_d
des = 1
} else {
dwdh = dwdh_a
des = 0
}
wtemp_c = w_i+dwdh*(h_f-h_c)
##Pour verifier si la valeur w finale est dans le courbe w_a et w_d ou pas
# if (des ==1 & wtemp_c > wf_d){
# wfin = wf_d
# } else {
# if (des == 0 & wtemp_c < wf_a){
# w_fin = wf_a
# } else {
# if (des == 1 & h_c == 1) {
# w_fin = wf_d
# } else {
# if (des == 0 & h_c == 0){
# w_fin = wf_a
# } else {
# w_fin = wtemp_c
# }
# }
# }
# }
##Valeur finale
return(wtemp_c)
}
\ No newline at end of file
#' w_evo: predicting the EMC of wood for a series of imposed humidity
#'
#' @description A function for predicting the moisture content of wood
#' after being imposed of a series of various humidity relative
#'
#' @usage w_evo(hr,w_ini,w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD)
#'
#' @param w_ini the initial moisture content of wood measured at RH = hr[1]
#'
#' @param h_c the initial RH of the atmosphere,
#' wherein the w_i value was measured
#'
#' @param h_f the actual RH of the atmosphere surrounding the wood
#'
#' @param w_s the fiber saturation point of the wood, defaulted at 0.25 (25\%)
#'
#' @param phi_a the material's parameter for adsorption
#'
#' @param phi_d the material's parameter for desorption
#'
#' @param asoi the fitting parameter for adsorption
#'
#' @param adoi the fitting parameter for desorption
#'
#' @param AA the fitting parameter for hysteresis (1)
#'
#' @param BB the fitting parameter for hysteresis (2)
#'
#' @param DD the fitting parameter for hysteresis (3)
#'
#' @return the EMC values of wood for each sequence values of `hr` vector
#'
#' @examples
#'
#' # Example for ebony wood
#' w_ini = 0.001 #Initial moisture content = 0.1%
#'
#' ad_href = seq(from = 0.001, to = 0.999, by = 0.001)
#'
#' de_href = seq(from = 0.999, to = 0.001, by = -0.001)
#'
#' href = c(ad_href,de_href)
#'
#' # Material parameters:
#' phi_d <- 0.556
#' phi_a <- 1.707
#' w_s <- 0.16 #Fiber saturation point = 16%
#' asoi <- 0.007
#' adoi <- 0.669
#' AA <- 0.328
#' DD <- -0.099
#' BB <- 0.411
#'
#' # Calculation:
#'
#' emc_results <- w_evo(hr=href,w_ini,w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD)
#'
#' plot(x = href, y = emc_results, type = "l")
w_evo <- function(hr,w_ini,w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD){
#h_r is a vector containing the whole sequence of relative humidity imposed upon the wood
#w_ini is the very first MC initial for the very first value of h_r
#thus
wr = matrix(0,nrow = length(hr), ncol = 1)
for (i in 1:length(hr)) {
if (i == 1){
wr[i] <- w_ini
} else {
wr[i] <- w_after(w_i = wr[i-1],
h_f = hr[i],
h_c = hr[i-1],w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD)
}
}
return(wr)
}
\ No newline at end of file
#' @docType package
#' @name woodhyst
#' @title Modeling Wood Moisture Hysteresis
#' @author
#' \strong{Maintainer:} Ahmad Alkadri (email: \href{mailto:ahmad.alkadri@umontpellier.fr}{ahmad.alkadri@umontpellier.fr})
#'
#' \strong{Contributor:} Ahmad Alkadri, Delphine Jullien, Olivier Arnould, Joseph Gril
#' @description This is an R package with functions
#' useful for modeling the hysteresis curves of
#' wood's equilibrium moisture content.
#' It is largely based on Pederson's and
#' Merakeb's hysteresis model.
NULL
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/w_after.R
\name{w_after}
\alias{w_after}
\title{w_after: predicting the EMC of wood for a series of imposed humidity}
\usage{
w_after(w_i,h_f,h_c,w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD)
}
\arguments{
\item{w_i}{the initial moisture content of wood measured at RH = h_c}
\item{h_f}{the actual RH of the atmosphere surrounding the wood}
\item{h_c}{the initial RH of the atmosphere,
wherein the w_i value was measured}
\item{w_s}{the fiber saturation point of the wood, defaulted at 0.25 (25\%)}
\item{phi_a}{the material's parameter for adsorption}
\item{phi_d}{the material's parameter for desorption}
\item{asoi}{the fitting parameter for adsorption}
\item{adoi}{the fitting parameter for desorption}
\item{AA}{the fitting parameter for hysteresis (1)}
\item{BB}{the fitting parameter for hysteresis (2)}
\item{DD}{the fitting parameter for hysteresis (3)}
}
\value{
the current moisture content of wood at RH = h_c
}
\description{
A function for predicting the moisture content of wood
after its surrounding atmosphere's humidity changed
}
\examples{
# Example for ebony wood
w_i = 0.03 #Initial moisture content = 3\%
h_c = 0.20 #Initial relative humidity = 20\%
h_f = 0.50 #Current relative humidity of the surrounding wood
# Material parameters:
phi_d <- 0.556
phi_a <- 1.707
w_s <- 0.16 #Fiber saturation point = 16\%
asoi <- 0.007
adoi <- 0.669
AA <- 0.328
DD <- -0.099
BB <- 0.411
# Calculation:
w_after(w_i,h_f,h_c,w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/w_evo.R
\name{w_evo}
\alias{w_evo}
\title{w_evo: predicting the EMC of wood for a series of imposed humidity}
\usage{
w_evo(hr,w_ini,w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD)
}
\arguments{
\item{w_ini}{the initial moisture content of wood measured at RH = hr[1]}
\item{w_s}{the fiber saturation point of the wood, defaulted at 0.25 (25\%)}
\item{phi_a}{the material's parameter for adsorption}
\item{phi_d}{the material's parameter for desorption}
\item{asoi}{the fitting parameter for adsorption}
\item{adoi}{the fitting parameter for desorption}
\item{AA}{the fitting parameter for hysteresis (1)}
\item{BB}{the fitting parameter for hysteresis (2)}
\item{DD}{the fitting parameter for hysteresis (3)}
\item{h_c}{the initial RH of the atmosphere,
wherein the w_i value was measured}
\item{h_f}{the actual RH of the atmosphere surrounding the wood}
}
\value{
the EMC values of wood for each sequence values of `hr` vector
}
\description{
A function for predicting the moisture content of wood
after being imposed of a series of various humidity relative
}
\examples{
# Example for ebony wood
w_ini = 0.001 #Initial moisture content = 0.1\%
ad_href = seq(from = 0.001, to = 0.999, by = 0.001)
de_href = seq(from = 0.999, to = 0.001, by = -0.001)
href = c(ad_href,de_href)
# Material parameters:
phi_d <- 0.556
phi_a <- 1.707
w_s <- 0.16 #Fiber saturation point = 16\%
asoi <- 0.007
adoi <- 0.669
AA <- 0.328
DD <- -0.099
BB <- 0.411
# Calculation:
emc_results <- w_evo(hr=href,w_ini,w_s,phi_a,phi_d,asoi,adoi,AA,BB,DD)
plot(x = href, y = emc_results, type = "l")
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/woodhyst.R
\docType{package}
\name{woodhyst}
\alias{woodhyst}
\alias{woodhyst-package}
\title{Modeling Wood Moisture Hysteresis}
\description{
This is an R package with functions
useful for modeling the hysteresis curves of
wood's equilibrium moisture content.
It is largely based on Pederson's and
Merakeb's hysteresis model.
}
\author{
\strong{Maintainer:} Ahmad Alkadri (email: \href{mailto:ahmad.alkadri@umontpellier.fr}{ahmad.alkadri@umontpellier.fr})
\strong{Contributor:} Ahmad Alkadri, Delphine Jullien, Olivier Arnould, Joseph Gril
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment