R-Lum / RLumModel
 1 ```#' sequence step LM-OSL-simulation ``` 2 ```#' ``` 3 ```#' This function simulates the LM-OSL measurement of quartz in the energy-band-model. ``` 4 ```#' ``` 5 ```#' @param temp \code{\link{numeric}} (\bold{required}): set temperature [deg. C] of the LM-OSL simulation ``` 6 ```#' ``` 7 ```#' @param duration \code{\link{numeric}} (\bold{required}): duration of the LM-OSL simulation ``` 8 ```#' ``` 9 ```#' @param start_power \code{\link{numeric}}: % of the power density at the start of the measurement. ``` 10 ```#' ``` 11 ```#' @param end_power \code{\link{numeric}}: % of the power density at the end of the measurement. ``` 12 ```#' 100 % equates to 20 mW/cm^2 ``` 13 ```#' ``` 14 ```#' @param RLumModel_ID \code{\link{numeric}} (optional): A ID-number for the LM-OSL-step. This ID ``` 15 ```#' is pass down to \link{calc_concentrations} so all concentrations had the same ID as the ``` 16 ```#' sequence step they were calculated from. This ID is identic to the sequence step in "sequence". ``` 17 ```#' ``` 18 ```#' @param n \code{\link{numeric}} or \code{\linkS4class{RLum.Results}} (\bold{required}): ``` 19 ```#' concentration of electron-/holetraps, valence- and conduction band ``` 20 ```#' from step before. This is necessary to get the boundary condition for the ODEs. ``` 21 ```#' ``` 22 ```#' @param parms \code{\linkS4class{RLum.Results}} (\bold{required}): The specific model parameters are used to simulate ``` 23 ```#' numerical quartz luminescence results. ``` 24 ```#' ``` 25 ```#' @return This function returns an RLum.Results object from the LM-OSL simulation. ``` 26 ```#' ``` 27 ```#' @section Function version: 0.1.1 ``` 28 ```#' ``` 29 ```#' @author Johannes Friedrich, University of Bayreuth (Germany), ``` 30 ```#' ``` 31 ```#' @references ``` 32 ```#' ``` 33 ```#' @seealso \code{\link{plot}} ``` 34 ```#' ``` 35 ```#' @examples ``` 36 ```#' ``` 37 ```#' #so far no example available ``` 38 ```#' ``` 39 ```#' @noRd ``` 40 ```.simulate_LM_OSL <- function( ``` 41 ``` temp, ``` 42 ``` duration, ``` 43 ``` start_power = 0, ``` 44 ``` end_power = 100, ``` 45 ``` RLumModel_ID = NULL, ``` 46 ``` n, ``` 47 ``` parms ``` 48 ```){ ``` 49 50 ```# check input arguments --------------------------------------------------- ``` 51 52 ``` ##check if temperature is > 0 K (-273 degree celsius) ``` 53 6 ``` if(temp < -273){ ``` 54 6 ``` stop("\n [.simulate_LM_OSL()] Argument 'temp' has to be > 0 K!") ``` 55 ``` } ``` 56 57 ``` ##check if duration is > 0s ``` 58 6 ``` if(duration < 0){ ``` 59 6 ``` stop("\n [.simulate_LM_OSL()] Argument 'duration' has to be a positive number!") ``` 60 ``` } ``` 61 62 ``` ##check if start_power is > 0 ``` 63 6 ``` if(start_power < 0){ ``` 64 6 ``` stop("\n [.simulate_LM_OSL()] Argument 'start_power' has to be a positive number!") ``` 65 ``` } ``` 66 67 ``` ##check if end_power > start_power ``` 68 6 ``` if(start_power > end_power){ ``` 69 6 ``` stop("\n [.simulate_LM_OSL()] Argument 'start_power' has to be smaller than 'end_power'!") ``` 70 ``` } ``` 71 72 ``` ##check if object is of class RLum.Data.Curve ``` 73 6 ``` if(class(n) != "RLum.Results"){ ``` 74 6 ``` n <- n ``` 75 ``` } else { ``` 76 6 ``` n <- n\$n ``` 77 ``` } ``` 78 79 ```# Set parameters for ODE --------------------------------------------------- ``` 80 81 82 ``` ##============================================================================## ``` 83 ``` # SETTING PARAMETERS FOR ILLUMINATION ``` 84 ``` # ``` 85 ``` # R: electron-hole-production-rate = 0 ``` 86 ``` # P: Photonflux (in Bailey 2004: wavelength [nm]) = 1 ``` 87 ``` # b: heating rate [deg. C/s] = 0 ``` 88 ``` # a: rate of stimulationintensity, P*20, because in Bailey2001 P = 1 equates to 20 mW cm^(-2) ``` 89 ``` ##============================================================================## ``` 90 91 6 ``` if(parms\$model == "Bailey2004" || parms\$model == "Bailey2002"){ ``` 92 6 ``` P <- 0.02/(1.6*10^(-19)*(1240/470)) ``` 93 6 ``` a <- 20*((end_power - start_power)/100)/duration ``` 94 ``` } ``` 95 ``` else{ ``` 96 6 ``` P <- 2 ``` 97 6 ``` a <- P*20*((end_power - start_power)/100)/duration ``` 98 ``` } ``` 99 100 6 ``` b <- 0 ``` 101 6 ``` R <- 0 ``` 102 103 ``` ##============================================================================## ``` 104 ``` # SETTING PARAMETERS FOR ODE ``` 105 ``` ##============================================================================## ``` 106 107 6 ``` times <- seq(from = 0, to = duration, by = 0.1) ``` 108 6 ``` parameters.step <- .extract_pars(parameters.step = list( ``` 109 6 ``` a = a, ``` 110 6 ``` R = R, ``` 111 6 ``` P = P, ``` 112 6 ``` temp = temp, ``` 113 6 ``` b = b, ``` 114 6 ``` times = times, ``` 115 6 ``` parms = parms)) ``` 116 ``` ``` 117 ``` ##============================================================================## ``` 118 ``` # SOLVING ODE (deSolve requiered) ``` 119 ``` ##============================================================================## ``` 120 6 ``` out <- deSolve::ode(y = n, times = times, parms = parameters.step, func = .set_ODE_Rcpp_LM_OSL, rtol=1e-3, atol=1e-3, maxsteps=1e5, method = "bdf") ``` 121 ``` ##============================================================================## ``` 122 123 ``` ##============================================================================## ``` 124 ``` # CALCULATING RESULTS FROM ODE SOLVING ``` 125 ``` ##============================================================================## ``` 126 127 6 ``` signal <- .calc_signal(object = out, parameters = parameters.step) ``` 128 129 ``` ##============================================================================## ``` 130 ``` # CALCULATING CONCENTRATIONS FROM ODE SOLVING ``` 131 ``` ##============================================================================## ``` 132 133 6 ``` name <- c("LM-OSL") ``` 134 6 ``` concentrations <- .calc_concentrations( ``` 135 6 ``` data = out, ``` 136 6 ``` times = times, ``` 137 6 ``` name = name, ``` 138 6 ``` RLumModel_ID = RLumModel_ID) ``` 139 140 ``` ##============================================================================## ``` 141 ``` # TAKING THE LAST LINE OF "OUT" TO COMMIT IT TO THE NEXT STEP ``` 142 ``` ##============================================================================## ``` 143 144 6 ``` return(Luminescence::set_RLum( ``` 145 6 ``` class = "RLum.Results", ``` 146 6 ``` data = list( ``` 147 6 ``` n = out[length(times),-1], ``` 148 6 ``` LM_OSL.data = Luminescence::set_RLum( ``` 149 6 ``` class = "RLum.Data.Curve", ``` 150 6 ``` data = matrix(data = c(times[2:length(times)], signal[2:length(signal)]),ncol = 2), ``` 151 6 ``` recordType = "LM-OSL", ``` 152 6 ``` curveType = "simulated", ``` 153 6 ``` info = list( ``` 154 6 ``` curveDescripter = NA_character_), ``` 155 6 ``` .pid = as.character(RLumModel_ID) ``` 156 ``` ), ``` 157 6 ``` temp = temp, ``` 158 6 ``` concentrations = concentrations) ``` 159 ``` ) ``` 160 ``` ) ``` 161 162 163 ```}#end function ```

Read our documentation on viewing source code .