Description Usage Arguments Details Value References See Also Examples
Estimates the transport term (i.e. the rate of change of a concentration due to diffusion) in a polar (r, theta) coordinate system
1 2 3 4 5 6 7 8 | tran.polar (C, C.r.up = NULL, C.r.down = NULL,
C.theta.up = NULL, C.theta.down = NULL,
flux.r.up = NULL, flux.r.down = NULL,
flux.theta.up = NULL, flux.theta.down = NULL,
cyclicBnd = NULL, D.r = 1, D.theta = D.r,
r = NULL, theta = NULL, full.output = FALSE)
polar2cart (out, r, theta, x = NULL, y = NULL)
|
C |
concentration, expressed per unit volume, defined at the centre of each grid cell; Nr*Nteta matrix [M/L3]. |
C.r.up |
concentration at upstream boundary in r(x)-direction; vector of length Nteta [M/L3]. |
C.r.down |
concentration at downstream boundary in r(x)-direction; vector of length Nteta [M/L3]. |
C.theta.up |
concentration at upstream boundary in theta-direction; vector of length Nr [M/L3]. |
C.theta.down |
concentration at downstream boundary in theta-direction; vector of length Nr [M/L3]. |
flux.r.up |
flux across the upstream boundary in r-direction, positive = INTO model domain; vector of length Ntheta [M/L2/T]. |
flux.r.down |
flux across the downstream boundary in r-direction, positive = OUT of model domain; vector of length Ntheta [M/L2/T]. |
flux.theta.up |
flux across the upstream boundary in theta-direction, positive = INTO model domain; vector of length Nr [M/L2/T]. |
flux.theta.down |
flux across the downstream boundary in theta-direction, positive = OUT of model domain; vector of length Nr [M/L2/T]. |
cyclicBnd |
If not |
D.r |
diffusion coefficient in r-direction, defined on grid cell
interfaces. One value, a vector of length (Nr+1),
a |
D.theta |
diffusion coefficient in theta-direction, defined on grid cell
interfaces. One value, a vector of length (Ntheta+1),
a |
r |
position of adjacent cell interfaces in the r-direction. A vector of length Nr+1 [L]. |
theta |
position of adjacent cell interfaces in the theta-direction. A vector of length Ntheta+1 [L]. Theta should be within [0,2 pi] |
full.output |
logical flag enabling a full return of the output
(default = |
out |
output as returned by |
x |
The cartesian x-coordinates to whicht the polar coordinates are to be mapped |
y |
The cartesian y-coordinates to whicht the polar coordinates are to be mapped |
tran.polar
performs (simplified) transport in polar coordinates
The boundary conditions are either
(1) zero gradient
(2) fixed concentration
(3) fixed flux
(4) cyclic boundary
This is also the order of priority. The cyclic boundary overrules the other.
If fixed concentration, fixed flux, and cyclicBnd are NULL
then
the boundary is zero-gradient
A cyclic boundary condition has concentration and flux at upstream and downstream boundary the same.
polar2cart
maps the polar coordinates to cartesian coordinates
If x
and y
is not provided, then it will create an (x,y)
grid based on r
: seq(-maxr, maxr, length.out=Nr)
, where
maxr
is the maximum value of r
, and Nr
is the number
of elements in r
.
a list containing:
dC |
the rate of change of the concentration C due to transport, defined in the centre of each grid cell, a Nr*Nteta matrix. [M/L3/T]. |
C.r.up |
concentration at the upstream interface in r-direction.
A vector of length Nteta [M/L3]. Only when |
C.r.down |
concentration at the downstream interface in r-direction.
A vector of length Nteta [M/L3]. Only when |
C.theta.up |
concentration at the the upstream interface in theta-direction.
A vector of length Nr [M/L3]. Only when |
C.theta.down |
concentration at the downstream interface in theta-direction.
A vector of length Nr [M/L3]. Only when |
r.flux |
flux across the interfaces in x-direction of the grid cells.
A (Nr+1)*Nteta matrix [M/L2/T]. Only when |
theta.flux |
flux across the interfaces in y-direction of the grid cells.
A Nr*(Nteta+1) matrix [M/L2/T]. Only when |
flux.r.up |
flux across the upstream boundary in r-direction, positive = INTO model domain. A vector of length Nteta [M/L2/T]. |
flux.r.down |
flux across the downstream boundary in r-direction, positive = OUT of model domain. A vector of length Nteta [M/L2/T]. |
flux.theta.up |
flux across the upstream boundary in theta-direction, positive = INTO model domain. A vector of length Nr [M/L2/T]. |
flux.theta.down |
flux across the downstream boundary in theta-direction, positive = OUT of model domain. A vector of length Nr [M/L2/T]. |
Soetaert and Herman, 2009. a practical guide to ecological modelling - using R as a simulation platform. Springer
tran.cylindrical
, tran.spherical
for a discretisation of 3-D transport equations in cylindrical and
spherical coordinates
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | ## =============================================================================
## Testing the functions
## =============================================================================
# Parameters
F <- 100 # input flux [micromol cm-2 yr-1]
D <- 400 # mixing coefficient [cm2 yr-1]
# Grid definition
r.N <- 4 # number of cells in r-direction
theta.N <- 6 # number of cells in theta-direction
r.L <- 8 # domain size r-direction [cm]
r <- seq(0, r.L,len = r.N+1) # cell size r-direction [cm]
theta <- seq(0, 2*pi,len = theta.N+1) # theta-direction - theta: from 0, 2pi
# Intial conditions
C <- matrix(nrow = r.N, ncol = theta.N, data = 0)
# Boundary conditions: fixed concentration
C.r.up <- rep(1, times = theta.N)
C.r.down <- rep(0, times = theta.N)
C.theta.up <- rep(1, times = r.N)
C.theta.down <- rep(0, times = r.N)
# Concentration boundary conditions
tran.polar(C = C, D.r = D, D.theta = D,
r = r, theta = theta,
C.r.up = C.r.up, C.r.down = C.r.down,
C.theta.up = C.theta.up, C.theta.down = C.theta.down)
# Flux boundary conditions
flux.r.up <- rep(200, times = theta.N)
flux.r.down <- rep(-200, times = theta.N)
flux.theta.up <- rep(200, times = r.N)
flux.theta.down <- rep(-200, times = r.N)
tran.polar(C = C, D.r = D, r = r, theta = theta,
flux.r.up = flux.r.up, flux.r.down = flux.r.down,
flux.theta.up = flux.theta.up, flux.theta.down = flux.theta.down,
full.output = TRUE)
## =============================================================================
## A model with diffusion and first-order consumption
## =============================================================================
N <- 50 # number of grid cells
XX <- 4 # total size
rr <- 0.005 # consumption rate
ini <- 1 # initial value at x=0
D <- 400
r <- seq (2, 4, len = N+1)
theta <- seq(0, 2*pi, len = N+1)
theta.m <- 0.5*(theta[-1]+theta[-(N+1)])
# The model equations
Diffpolar <- function (t, y, parms) {
CONC <- matrix(nrow = N, ncol = N, data = y)
tran <- tran.polar(CONC, D.r = D, D.theta = D, r = r, theta = theta,
C.r.up = 0, C.r.down = 1*sin(5*theta.m),
cyclicBnd = 2, full.output=TRUE )
dCONC <- tran$dC - rr * CONC
return (list(dCONC))
}
# solve to steady-state; cyclicBnd = 2, because of C.theta.up, C.theta.down
out <- steady.2D (y = rep(0, N*N), func = Diffpolar, parms = NULL,
dim = c(N, N), lrw = 1e6, cyclicBnd = 2)
image(out)
cart <- polar2cart(out, r = r, theta = theta,
x = seq(-4, 4, len = 100),
y = seq(-4, 4, len = 100))
image(cart)
|
Loading required package: rootSolve
Loading required package: deSolve
Loading required package: shape
$dC
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 729.51252 0 0 0 0 0
[2,] 81.05695 0 0 0 0 0
[3,] 29.18050 0 0 0 0 0
[4,] 14.88801 0 0 0 0 0
$flux.r.up
[1] 400 400 400 400 400 400
$flux.r.down
[1] 0 0 0 0 0 0
$flux.theta.up
[1] 763.9437 254.6479 152.7887 109.1348
$flux.theta.down
[1] 0 0 0 0
$dC
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 190.98593 0.0000 0.0000 0.0000 0.0000 190.98593
[2,] 63.66198 0.0000 0.0000 0.0000 0.0000 63.66198
[3,] 38.19719 0.0000 0.0000 0.0000 0.0000 38.19719
[4,] 141.56942 114.2857 114.2857 114.2857 114.2857 141.56942
$C.r.up
[1] 0.5 0.5 0.5 0.5 0.5 0.5
$C.r.down
[1] 0.5 0.5 0.5 0.5 0.5 0.5
$C.theta.up
[1] 0.2617994 0.7853982 1.3089969 1.8325957
$C.theta.down
[1] 0.2617994 0.7853982 1.3089969 1.8325957
$r.flux
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 200 200 200 200 200 200
[2,] 0 0 0 0 0 0
[3,] 0 0 0 0 0 0
[4,] 0 0 0 0 0 0
[5,] -200 -200 -200 -200 -200 -200
$theta.flux
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 200 0 0 0 0 0 -200
[2,] 200 0 0 0 0 0 -200
[3,] 200 0 0 0 0 0 -200
[4,] 200 0 0 0 0 0 -200
$flux.r.up
[1] 200 200 200 200 200 200
$flux.r.down
[1] -200 -200 -200 -200 -200 -200
$flux.theta.up
[1] 200 200 200 200
$flux.theta.down
[1] -200 -200 -200 -200
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.