Estimates the transport term (i.e. the rate of change of a concentration due to diffusion and advection) in a three-dimensional rectangular model domain.
Do not use with too many boxes!
tran.3D (C, C.x.up = C[1,,], C.x.down = C[dim(C)[1],,],
C.y.up = C[ ,1, ], C.y.down=C[ ,dim(C)[2], ],
C.z.up = C[ , ,1], C.z.down=C[ , ,dim(C)[3]],
flux.x.up = NULL, flux.x.down = NULL,
flux.y.up = NULL, flux.y.down = NULL,
flux.z.up = NULL, flux.z.down = NULL,
a.bl.x.up = NULL, a.bl.x.down = NULL,
a.bl.y.up = NULL, a.bl.y.down = NULL,
a.bl.z.up = NULL, a.bl.z.down = NULL,
D.grid = NULL, D.x = NULL, D.y = D.x, D.z = D.x,
v.grid = NULL, v.x = 0, v.y = 0, v.z = 0,
AFDW.grid = NULL, AFDW.x = 1, AFDW.y = AFDW.x, AFDW.z = AFDW.x,
VF.grid = NULL, VF.x = 1, VF.y = VF.x, VF.z = VF.x,
A.grid = NULL, A.x = 1, A.y = 1, A.z = 1,
grid = NULL, dx = NULL, dy = NULL, dz = NULL,
full.check = FALSE, full.output = FALSE)
concentration, expressed per unit volume, defined at the centre of each grid cell; Nx*Ny*Nz array [M/L3].
concentration at upstream boundary in x-direction; matrix of dimensions Ny*Nz [M/L3].
concentration at downstream boundary in x-direction; matrix of dimensions Ny*Nz [M/L3].
concentration at upstream boundary in y-direction; matrix of dimensions Nx*Nz [M/L3].
concentration at downstream boundary in y-direction; matrix of dimensions Nx*Nz [M/L3].
concentration at upstream boundary in z-direction; matrix of dimensions Nx*Ny [M/L3].
concentration at downstream boundary in z-direction; matrix of dimensions Nx*Ny [M/L3].
flux across the upstream boundary in x-direction, positive = INTO model domain; matrix of dimensions Ny*Nz [M/L2/T].
flux across the downstream boundary in x-direction, positive = OUT of model domain; matrix of dimensions Ny*Nz [M/L2/T].
flux across the upstream boundary in y-direction, positive = INTO model domain; matrix of dimensions Nx*Nz [M/L2/T].
flux across the downstream boundary in y-direction, positive = OUT of model domain; matrix of dimensions Nx*Nz [M/L2/T].
flux across the upstream boundary in z-direction, positive = INTO model domain; matrix of dimensions Nx*Ny [M/L2/T].
flux across the downstream boundary in z-direction, positive = OUT of model domain; matrix of dimensions Nx*Ny [M/L2/T].
transfer coefficient across the upstream boundary layer. in x-direction
Flux=a.bl.x.up*(C.x.up-C[1,,])
. One value [L/T].
transfer coefficient across the downstream boundary layer in x-direction;
Flux=a.bl.x.down*(C[Nx,,]-C.x.down)
.
One value [L/T].
transfer coefficient across the upstream boundary layer. in y-direction
Flux=a.bl.y.up*(C.y.up-C[,1,])
. One value [L/T].
transfer coefficient across the downstream boundary layer in y-direction;
Flux=a.bl.y.down*(C[,Ny,]-C.y.down)
.
One value [L/T].
transfer coefficient across the upstream boundary layer. in y-direction
Flux=a.bl.y.up*(C.y.up-C[,,1])
. One value [L/T].
transfer coefficient across the downstream boundary layer in z-direction;
Flux=a.bl.z.down*(C[,,Nz]-C.z.down)
.
One value [L/T].
diffusion coefficient defined on all grid cell interfaces. Should contain elements x.int, y.int, z.int, arrays with the values on the interfaces in x, y and z-direction, and with dimensions (Nx+1)*Ny*Nz, Nx*(Ny+1)*Nz and Nx*Ny*(Nz+1) respectively. [L2/T].
diffusion coefficient in x-direction, defined on grid cell interfaces. One value, a vector of length (Nx+1), or a (Nx+1)* Ny *Nz array [L2/T].
diffusion coefficient in y-direction, defined on grid cell interfaces. One value, a vector of length (Ny+1), or a Nx*(Ny+1)*Nz array [L2/T].
diffusion coefficient in z-direction, defined on grid cell interfaces. One value, a vector of length (Nz+1), or a Nx*Ny*(Nz+1) array [L2/T].
advective velocity defined on all grid cell interfaces. Can be positive (downstream flow) or negative (upstream flow). Should contain elements x.int, y.int, z.int, arrays with the values on the interfaces in x, y and z-direction, and with dimensions (Nx+1)*Ny*Nz, Nx*(Ny+1)*Nz and Nx*Ny*(Nz+1) respectively. [L/T].
advective velocity in the x-direction, defined on grid cell interfaces. Can be positive (downstream flow) or negative (upstream flow). One value, a vector of length (Nx+1), or a (Nx+1)*Ny*Nz array [L/T].
advective velocity in the y-direction, defined on grid cell interfaces. Can be positive (downstream flow) or negative (upstream flow). One value, a vector of length (Ny+1), or a Nx*(Ny+1)*Nz array [L/T].
advective velocity in the z-direction, defined on grid cell interfaces. Can be positive (downstream flow) or negative (upstream flow). One value, a vector of length (Nz+1), or a Nx*Ny*(Nz+1) array [L/T].
weight used in the finite difference scheme for advection in the x-direction, defined on grid cell interfaces; backward = 1, centred = 0.5, forward = 0; default is backward. Should contain elements x.int, y.int, z.int, arrays with the values on the interfaces in x, y and z-direction, and with dimensions (Nx+1)*Ny*Nz, Nx*(Ny+1)*Nz and Nx*Ny*(Nz+1) respectively. [-].
weight used in the finite difference scheme for advection
in the x-direction, defined on grid cell interfaces; backward = 1,
centred = 0.5, forward = 0; default is backward.
One value, a vector of length (Nx+1),
a prop.1D
list created by setup.prop.1D
,
or a (Nx+1)*Ny*Nz array [-].
weight used in the finite difference scheme for advection
in the y-direction, defined on grid cell interfaces; backward = 1,
centred = 0.5, forward = 0; default is backward.
One value, a vector of length (Ny+1),
a prop.1D
list created by setup.prop.1D
,
or a Nx*(Ny+1)*Nz array [-].
weight used in the finite difference scheme for advection
in the z-direction, defined on grid cell interfaces; backward = 1,
centred = 0.5, forward = 0; default is backward.
One value, a vector of length (Nz+1),
a prop.1D
list created by setup.prop.1D
,
or a Nx*Ny*(Nz+1) array [-].
Volume fraction. A list. Should contain elements x.int, y.int, z.int, arrays with the values on the interfaces in x, y and z-direction, and with dimensions (Nx+1)*Ny*Nz, Nx*(Ny+1)*Nz and Nx*Ny*(Nz+1) respectively. [-].
Volume fraction at the grid cell interfaces in the x-direction.
One value, a vector of length (Nx+1),
a prop.1D
list created by setup.prop.1D
,
or a (Nx+1)*Ny*Nz array [-].
Volume fraction at the grid cell interfaces in the y-direction.
One value, a vector of length (Ny+1),
a prop.1D
list created by setup.prop.1D
,
or a Nx*(Ny+1)*Nz array [-].
Volume fraction at the grid cell interfaces in the z-direction.
One value, a vector of length (Nz+1),
a prop.1D
list created by setup.prop.1D
,
or a Nx*Ny*(Nz+1) array [-].
Interface area, a list. Should contain elements x.int, y.int, z.int, arrays with the values on the interfaces in x, y and z-direction, and with dimensions (Nx+1)*Ny*Nz, Nx*(Ny+1)*Nz and Nx*Ny*(Nz+1) respectively. [L2].
Interface area defined at the grid cell interfaces in
the x-direction. One value, a vector of length (Nx+1),
a prop.1D
list created by setup.prop.1D
,
or a (Nx+1)*Ny*Nz array [L2].
Interface area defined at the grid cell interfaces in
the y-direction. One value, a vector of length (Ny+1),
a prop.1D
list created by setup.prop.1D
,
or a Nx*(Ny+1)*Nz array [L2].
Interface area defined at the grid cell interfaces in
the z-direction. One value, a vector of length (Nz+1),
a prop.1D
list created by setup.prop.1D
,
or a Nx*Ny*(Nz+1) array [L2].
distance between adjacent cell interfaces in the x-direction (thickness of grid cells). One value or vector of length Nx [L].
distance between adjacent cell interfaces in the y-direction (thickness of grid cells). One value or vector of length Ny [L].
distance between adjacent cell interfaces in the z-direction (thickness of grid cells). One value or vector of length Nz [L].
discretization grid, a list containing at least elements
dx
, dx.aux
, dy
, dy.aux
, dz
, dz.aux
(see setup.grid.2D
) [L].
logical flag enabling a full check of the consistency
of the arguments (default = FALSE
; TRUE
slows down
execution by 50 percent).
logical flag enabling a full return of the output
(default = FALSE
; TRUE
slows down execution by 20 percent).
a list containing:
the rate of change of the concentration C due to transport, defined in the centre of each grid cell, an array with dimension Nx*Ny*Nz [M/L3/T].
concentration at the upstream interface in x-direction.
A matrix of dimension Ny*Nz [M/L3]. Only when full.output = TRUE
.
concentration at the downstream interface in x-direction.
A matrix of dimension Ny*Nz [M/L3]. Only when full.output = TRUE
.
concentration at the upstream interface in y-direction.
A matrix of dimension Nx*Nz [M/L3]. Only when full.output = TRUE
.
concentration at the downstream interface in y-direction.
A matrix of dimension Nx*Nz [M/L3]. Only when full.output = TRUE
.
concentration at the upstream interface in z-direction.
A matrix of dimension Nx*Ny [M/L3]. Only when full.output = TRUE
.
concentration at the downstream interface in z-direction.
A matrix of dimension Nx*Ny [M/L3]. Only when full.output = TRUE
.
flux across the interfaces in x-direction of the grid cells.
A (Nx+1)*Ny*Nz array [M/L2/T]. Only when full.output = TRUE
.
flux across the interfaces in y-direction of the grid cells.
A Nx*(Ny+1)*Nz array [M/L2/T]. Only when full.output = TRUE
.
flux across the interfaces in z-direction of the grid cells.
A Nx*Ny*(Nz+1) array [M/L2/T]. Only when full.output = TRUE
.
flux across the upstream boundary in x-direction, positive = INTO model domain. A matrix of dimension Ny*Nz [M/L2/T].
flux across the downstream boundary in x-direction, positive = OUT of model domain. A matrix of dimension Ny*Nz [M/L2/T].
flux across the upstream boundary in y-direction, positive = INTO model domain. A matrix of dimension Nx*Nz [M/L2/T].
flux across the downstream boundary in y-direction, positive = OUT of model domain. A matrix of dimension Nx*Nz [M/L2/T].
flux across the upstream boundary in z-direction, positive = INTO model domain. A matrix of dimension Nx*Ny [M/L2/T].
flux across the downstream boundary in z-direction, positive = OUT of model domain. A matrix of dimension Nx*Ny [M/L2/T].
Do not use this with too large grid.
The boundary conditions are either
(1) zero-gradient
(2) fixed concentration
(3) convective boundary layer
(4) fixed flux
This is also the order of priority. The zero gradient is the default, the fixed flux overrules all other.
Soetaert and Herman, a practical guide to ecological modelling - using R as a simulation platform, 2009. Springer
tran.cylindrical
, tran.spherical
for a discretisation of 3-D transport equations in cylindrical and
spherical coordinates
# NOT RUN {
## =============================================================================
## Diffusion in 3-D; imposed boundary conditions
## =============================================================================
diffusion3D <- function(t, Y, par) {
yy <- array(dim = c(n, n, n), data = Y) # vector to 3-D array
dY <- -r * yy # consumption
BND <- matrix(nrow = n, ncol = n, 1) # boundary concentration
dY <- dY + tran.3D(C = yy,
C.x.up = BND, C.y.up = BND, C.z.up = BND,
C.x.down = BND, C.y.down = BND, C.z.down = BND,
D.x = Dx, D.y = Dy, D.z = Dz,
dx = dx, dy = dy, dz = dz, full.check = TRUE)$dC
return(list(dY))
}
# parameters
dy <- dx <- dz <- 1 # grid size
Dy <- Dx <- Dz <- 1 # diffusion coeff, X- and Y-direction
r <- 0.025 # consumption rate
n <- 10
y <- array(dim = c(n, n, n), data = 10.)
print(system.time(
ST3 <- steady.3D(y, func = diffusion3D, parms = NULL,
pos = TRUE, dimens = c(n, n, n),
lrw = 2000000, verbose = TRUE)
))
pm <- par(mfrow = c(1,1))
y <- array(dim = c(n, n, n), data = ST3$y)
filled.contour(y[ , ,n/2], color.palette = terrain.colors)
# a selection in the x-direction
image(ST3, mfrow = c(2, 2), add.contour = TRUE, legend = TRUE,
dimselect = list(x = c(1, 4, 8, 10)))
par(mfrow = pm)
# }
Run the code above in your browser using DataLab