在R中使用反应物的扩散反应模型

时间:2017-04-13 15:49:42

标签: r

我正在尝试在deSolve包中使用reacTran实现反应扩散PDE。但是,时间依赖的反应项不起作用。任何关于如何实现这一点的建议将不胜感激!

library(ReacTran)
library(deSolve)

N <- 1000
xgrid <- setup.grid.1D(x.up = 0, x.down = 10, N = N)
x <- xgrid$x.mid
D.coeff <- 1
k <- 1

Diffusion <- function (t, Y, parms){
  tran <- tran.1D(C = Y, C.up = 0, C.down = 0, D = D.coeff, dx = xgrid)-k*t
  reac <- -kt
  return(list(tran$dC+reac))
}

# Set initial conditions as gaussian distribution
C0 <- 10            #Initial concentration (mg/L)
X0 <- 5             #Location of initial concentration (m)
sig <- .2           #Spread of Gaussian distribution
C <- rep(0,N)       #matrix
Yini <- C+C0*exp(-((x-X0)/sig)^2)

parms1 <- list(D=D.coeff, k=k)

times <- seq(from = 0, to = 5, by = 0.01)
print(system.time(
  out <- ode.1D(y = Yini, times = times, func = Diffusion,
            parms = parms1, dimens = N)))

0 个答案:

没有答案