Learn R Programming

ReacTran (version 1.4.3.1)

setup.grid.1D: Creates a One-Dimensional Finite Difference Grid

Description

Subdivides the one-dimensional model domain into one or more zones that are each sub-divided into grid cells. The resulting grid structure can be used in the other ReacTran functions.

The grid structure is characterized by the position of the middle of the grid cells (x.mid) and the position of the interfaces between grid cells (x.int).

Distances are calculated between the interfaces (dx), i.e. the thickness of the grid cells. An auxiliary set of distances (dx.aux) is calculated between the points where the concentrations are specified (at the center of each grid cell and the two external interfaces).

A more complex grid consisting of multiple zones can be constructed when specifying the endpoints of ech zone (x.down), the interval length (L), and the number of layers in each zone (N) as vectors. In each zone, one can control the grid resolution near the upstream and downstream boundary.

The grid resolution at the upstream interface changes according to the power law relation dx[i+1] = min(max.dx.1,p.dx.1*dx[i]), where p.dx.1 determines the rate of increase and max.dx.1 puts an upper limit on the grid cell size.

A similar formula controls the resolution at the downstream interface. This allows refinement of the grid near the interfaces.

If only x.up, N and dx.1 are specified, then the grid size is taken constant = dx.1 (and L=N*dx.1)

Usage

setup.grid.1D(x.up = 0, x.down = NULL, L = NULL, N = NULL, dx.1 = NULL,
              p.dx.1 = rep(1, length(L)), max.dx.1 = L, dx.N = NULL,
              p.dx.N = rep(1, length(L)), max.dx.N = L)

# S3 method for grid.1D plot(x, …)

Arguments

x.up

position of the upstream interface; one value [L]

x.down

position of the endpoint of each zone; one value when the model domain covers only one zone (x.down = position of downstream interface), or a vector of length M when the model domain is divided into M zones (x.down[M] = position of downstream interface) [L]

L

thickness of zones; one value (model domain = one zone) or a vector of length M (model domain = M zones) [L]

N

number of grid cells within a zone; one value or a vector of length M [-]

dx.1

size of the first grid cell in a zone; one value or a vector of length M [L]

p.dx.1

power factor controlling the increase in grid cell size near the upstream boundary; one value or a vector of length M. The default value is 1 (constant grid cell size) [-]

max.dx.1

maximum grid cell size in the upstream half of the zone; one value or a vector of length M [L]

dx.N

size of the last grid cell in a zone; one value or a vector of length M [L]

p.dx.N

power factor controlling the increase in grid cell size near the downstream boundary; one value or a vector of length M. The default value is 1 (constant grid cell size) [-]

max.dx.N

maximum grid cell size in the downstream half of the zone; one value or a vector of length M [L]

x

the object of class grid.1D that needs plotting

...

additional arguments passed to the function plot

Value

a list of type grid.1D containing:

N

the total number of grid cells [-]

x.up

position of the upstream interface; one value [L]

x.down

position of the downstream interface; one value [L]

x.mid

position of the middle of the grid cells; vector of length N [L]

x.int

position of the interfaces of the grid cells; vector of length N+1 [L]

dx

distance between adjacent cell interfaces (thickness of grid cells); vector of length N [L]

dx.aux

auxiliary vector containing the distance between adjacent cell centers; at the upper and lower boundary calculated as (x[1]-x.up) and (x.down-x[N]) respectively; vector of length N+1 [L]

See Also

tran.1D, for a discretisation of the general transport equation in 1-D

setup.grid.2D for the creation of grids in 2-D

setup.prop.1D, for defining properties on the 1-D grid.

Examples

Run this code
# NOT RUN {
# one zone, constant resolution
(GR <- setup.grid.1D(x.up = 0, L = 10, N = 10))
(GR <- setup.grid.1D(x.up = 0, L = 10, dx.1 = 1))
(GR <- setup.grid.1D(x.up = 0, L = 10, dx.N = 1))
plot(GR)

# one zone, constant resolution, origin not zero
(GR <- setup.grid.1D(x.up = 5, x.down = 10, N = 10))
plot(GR)

# one zone, variable resolution
(GR <- setup.grid.1D(x.up = 0, L = 10, dx.1 = 1, p.dx.1 = 1.2))
(GR <- setup.grid.1D(x.up = 0, L = 10, dx.N = 1, p.dx.N = 1.2))
plot(GR)

# one zone, variable resolution, imposed number of layers
(GR <- setup.grid.1D(x.up = 0, L = 10, N = 6, dx.1 = 1, p.dx.1 = 1.2))
(GR <- setup.grid.1D(x.up = 0, L = 10, N = 6, dx.N = 1, p.dx.N = 1.2))
plot(GR)

# one zone, higher resolution near upstream and downstream interfaces
(GR <- setup.grid.1D(x.up = 0, x.down = 10, dx.1 = 0.1,
                     p.dx.1 = 1.2, dx.N = 0.1, p.dx.N = 1.2))
plot(GR)

# one zone, higher resolution near upstream and downstream interfaces
# imposed number of layers 
(GR <- setup.grid.1D(x.up = 0, x.down = 10, N = 20, 
                     dx.1 = 0.1, p.dx.1 = 1.2, 
                     dx.N = 0.1, p.dx.N = 1.2))
plot(GR)

# two zones, higher resolution near the upstream
# and downstream interface
(GR<-setup.grid.1D(x.up = 0, L = c(5, 5), 
         dx.1 = c(0.2, 0.2), p.dx.1 = c(1.1, 1.1), 
         dx.N = c(0.2, 0.2), p.dx.N = c(1.1, 1.1)))
plot(GR)

# two zones, higher resolution near the upstream
# and downstream interface
# the number of grid cells in each zone is imposed via N
(GR <- setup.grid.1D(x.up = 0, L = c(5, 5), N = c(20, 10),
         dx.1 = c(0.2, 0.2), p.dx.1 = c(1.1, 1.1), 
         dx.N = c(0.2, 0.2), p.dx.N = c(1.1, 1.1)))
plot(GR)
# }

Run the code above in your browser using DataLab