Skip to content

Commit

Permalink
+ subdivisions
Browse files Browse the repository at this point in the history
Added option to change params of numeric integration by the user
  • Loading branch information
NiklasHohmann committed Jan 4, 2024
1 parent 5d028c2 commit fd427bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/sedrate_to_multiadm.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sedrate_to_multiadm = function(h_tp, t_tp, sed_rate_gen, h, no_of_rep = 100L,
sedrate_to_multiadm = function(h_tp, t_tp, sed_rate_gen, h, no_of_rep = 100L, subdivisions = 100L,
T_unit = NULL, L_unit = NULL){

#'
Expand All @@ -9,6 +9,7 @@ sedrate_to_multiadm = function(h_tp, t_tp, sed_rate_gen, h, no_of_rep = 100L,
#' @param sed_rate_gen : function, returns sedimentation rate functions
#' @param h : numeric, heights where the adm is calculated
#' @param no_of_rep : numeric, number of repetitions
#' @param subdivisions maximum no of subintervals used in numeric integration
#' @param T_unit time unit
#' @param L_unit length unit
#'
Expand Down Expand Up @@ -41,13 +42,13 @@ sedrate_to_multiadm = function(h_tp, t_tp, sed_rate_gen, h, no_of_rep = 100L,
h_relevant = c(h1_sample, h[h> h1_sample & h < h2_sample], h2_sample)

sed_rate_sample = sed_rate_gen()
c_corr = (t2_sample-t1_sample)/stats::integrate(function(x) 1/sed_rate_sample(x), lower = h1_sample, upper = h2_sample)$value
c_corr = (t2_sample-t1_sample)/stats::integrate(function(x) 1/sed_rate_sample(x), lower = h1_sample, upper = h2_sample, subdivisions = subdivisions)$value
tp_corr_sed_rate_sample = function(x) sed_rate_sample(x) / c_corr

t_out = rep(NA, length(h))

for (j in seq_along(h)){
t_out[j] = t1_sample + stats::integrate( function(x) 1/tp_corr_sed_rate_sample(x), lower = h1_sample, upper = h[j])$value
t_out[j] = t1_sample + stats::integrate( function(x) 1/tp_corr_sed_rate_sample(x), lower = h1_sample, upper = h[j], subdivisions = subdivisions)$value
}

h_list[[i]] = h
Expand Down
3 changes: 3 additions & 0 deletions man/sedrate_to_multiadm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fd427bd

Please sign in to comment.