Learn R Programming

ReacTran (version 1.4.3.1)

tran.polar: Diffusive Transport in polar (r, theta) coordinates.

Description

Estimates the transport term (i.e. the rate of change of a concentration due to diffusion) in a polar (r, theta) coordinate system

Usage

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)

Arguments

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 NULL, the direction in which a cyclic boundary is defined, i.e. cyclicBnd = 1 for the r direction, cyclicBnd = 2 for the theta direction and cyclicBnd = c(1,2) for both the r and theta direction.

D.r

diffusion coefficient in r-direction, defined on grid cell interfaces. One value, a vector of length (Nr+1), a prop.1D list created by setup.prop.1D, or a (Nr+1)* Nteta matrix [L2/T].

D.theta

diffusion coefficient in theta-direction, defined on grid cell interfaces. One value, a vector of length (Ntheta+1), a prop.1D list created by setup.prop.1D, or a Nr*(Ntheta+1) matrix [L2/T].

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 = FALSE; TRUE slows down execution by 20 percent).

out

output as returned by tran.polar, and which is to be mapped from polar to cartesian coordinates

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

Value

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 full.output = TRUE.

C.r.down

concentration at the downstream interface in r-direction. A vector of length Nteta [M/L3]. Only when full.output = TRUE.

C.theta.up

concentration at the the upstream interface in theta-direction. A vector of length Nr [M/L3]. Only when full.output = TRUE.

C.theta.down

concentration at the downstream interface in theta-direction. A vector of length Nr [M/L3]. Only when full.output = TRUE.

r.flux

flux across the interfaces in x-direction of the grid cells. A (Nr+1)*Nteta matrix [M/L2/T]. Only when full.output = TRUE.

theta.flux

flux across the interfaces in y-direction of the grid cells. A Nr*(Nteta+1) matrix [M/L2/T]. Only when full.output = TRUE.

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].

Details

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.

References

Soetaert and Herman, 2009. a practical guide to ecological modelling - using R as a simulation platform. Springer

See Also

tran.cylindrical, tran.spherical for a discretisation of 3-D transport equations in cylindrical and spherical coordinates

tran.1D, tran.2D, tran.3D

Examples

Run this code
# NOT RUN {
## =============================================================================
## 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)
          
# }

Run the code above in your browser using DataLab