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

Description Usage Arguments Value Author(s) See Also Examples

View source: R/setup.grid.1D.R

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

1
2
3
4
5
6
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 class '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]

Author(s)

Filip Meysman <filip.meysman@nioz.nl>, Karline Soetaert <karline.soetaert@nioz.nl>

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

 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
# 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)

Example output

Loading required package: rootSolve
Loading required package: deSolve
Loading required package: shape
$x.up
[1] 0

$x.down
[1] 10

$x.mid
 [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5

$x.int
 [1]  0  1  2  3  4  5  6  7  8  9 10

$dx
 [1] 1 1 1 1 1 1 1 1 1 1

$dx.aux
 [1] 0.5 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5

$N
[1] 10

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
 [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5

$x.int
 [1]  0  1  2  3  4  5  6  7  8  9 10

$dx
 [1] 1 1 1 1 1 1 1 1 1 1

$dx.aux
 [1] 0.5 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5

$N
[1] 10

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
 [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5

$x.int
 [1]  0  1  2  3  4  5  6  7  8  9 10

$dx
 [1] 1 1 1 1 1 1 1 1 1 1

$dx.aux
 [1] 0.5 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5

$N
[1] 10

attr(,"class")
[1] "grid.1D"
$x.up
[1] 5

$x.down
[1] 10

$x.mid
 [1] 5.25 5.75 6.25 6.75 7.25 7.75 8.25 8.75 9.25 9.75

$x.int
 [1]  5.0  5.5  6.0  6.5  7.0  7.5  8.0  8.5  9.0  9.5 10.0

$dx
 [1] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5

$dx.aux
 [1] 0.25 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.25

$N
[1] 10

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
[1] 0.3871196 1.2387828 2.2607786 3.4871736 4.9588476 6.7248564 8.8440670

$x.int
[1]  0.0000000  0.7742393  1.7033264  2.8182309  4.1561164  5.7615789  7.6881339
[8] 10.0000000

$dx
[1] 0.7742393 0.9290871 1.1149045 1.3378854 1.6054625 1.9265550 2.3118661

$dx.aux
[1] 0.3871196 0.8516632 1.0219958 1.2263950 1.4716740 1.7660088 2.1192105
[8] 1.1559330

$N
[1] 7

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
[1] 1.155933 3.275144 5.041152 6.512826 7.739221 8.761217 9.612880

$x.int
[1]  0.000000  2.311866  4.238421  5.843884  7.181769  8.296674  9.225761
[8] 10.000000

$dx
[1] 2.3118661 1.9265550 1.6054625 1.3378854 1.1149045 0.9290871 0.7742393

$dx.aux
[1] 1.1559330 2.1192105 1.7660088 1.4716740 1.2263950 1.0219958 0.8516632
[8] 0.3871196

$N
[1] 7

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
[1] 0.5000011 1.6013999 2.9261544 4.5195596 6.4360959 8.7412919

$x.int
[1]  0.000000  1.000002  2.202798  3.649511  5.389608  7.482584 10.000000

$dx
[1] 1.000002 1.202795 1.446714 1.740097 2.092976 2.517416

$dx.aux
[1] 0.5000011 1.1013988 1.3247545 1.5934052 1.9165363 2.3051960 1.2587081

$N
[1] 6

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
[1] 1.258708 3.563904 5.480440 7.073846 8.398600 9.499999

$x.int
[1]  0.000000  2.517416  4.610392  6.350489  7.797202  8.999998 10.000000

$dx
[1] 2.517416 2.092976 1.740097 1.446714 1.202795 1.000002

$dx.aux
[1] 1.2587081 2.3051960 1.9165363 1.5934052 1.3247545 1.1013988 0.5000011

$N
[1] 6

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
 [1] 0.04223264 0.13514444 0.24663861 0.38043160 0.54098320 0.73364512
 [7] 0.96483942 1.24227258 1.57519237 1.97469612 2.45410062 3.02938601
[13] 3.71972849 4.54813947 5.45186053 6.28027151 6.97061399 7.54589938
[19] 8.02530388 8.42480763 8.75772742 9.03516058 9.26635488 9.45901680
[25] 9.61956840 9.75336139 9.86485556 9.95776736

$x.int
 [1]  0.00000000  0.08446528  0.18582361  0.30745361  0.45340960  0.62855680
 [7]  0.83873343  1.09094540  1.39359975  1.75678498  2.19260725  2.71559398
[13]  3.34317805  4.09627894  5.00000000  5.90372106  6.65682195  7.28440602
[19]  7.80739275  8.24321502  8.60640025  8.90905460  9.16126657  9.37144320
[25]  9.54659040  9.69254639  9.81417639  9.91553472 10.00000000

$dx
 [1] 0.08446528 0.10135833 0.12163000 0.14595600 0.17514720 0.21017664
 [7] 0.25221196 0.30265436 0.36318523 0.43582227 0.52298673 0.62758407
[13] 0.75310089 0.90372106 0.90372106 0.75310089 0.62758407 0.52298673
[19] 0.43582227 0.36318523 0.30265436 0.25221196 0.21017664 0.17514720
[25] 0.14595600 0.12163000 0.10135833 0.08446528

$dx.aux
 [1] 0.04223264 0.09291180 0.11149416 0.13379300 0.16055160 0.19266192
 [7] 0.23119430 0.27743316 0.33291979 0.39950375 0.47940450 0.57528540
[13] 0.69034248 0.82841097 0.90372106 0.82841097 0.69034248 0.57528540
[19] 0.47940450 0.39950375 0.33291979 0.27743316 0.23119430 0.19266192
[25] 0.16055160 0.13379300 0.11149416 0.09291180 0.04223264

$N
[1] 28

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
 [1] 0.04999958 0.16661030 0.32196303 0.52892919 0.80465650 1.17198974
 [7] 1.66136350 2.31332376 3.18188725 4.33901687 5.66098313 6.81811275
[13] 7.68667624 8.33863650 8.82801026 9.19534350 9.47107081 9.67803697
[19] 9.83338970 9.95000042

$x.int
 [1]  0.00000000  0.09999916  0.23322143  0.41070463  0.64715375  0.96215925
 [7]  1.38182023  1.94090677  2.68574075  3.67803374  5.00000000  6.32196626
[13]  7.31425925  8.05909323  8.61817977  9.03784075  9.35284625  9.58929537
[19]  9.76677857  9.90000084 10.00000000

$dx
 [1] 0.09999916 0.13322226 0.17748320 0.23644912 0.31500551 0.41966098
 [7] 0.55908654 0.74483398 0.99229299 1.32196626 1.32196626 0.99229299
[13] 0.74483398 0.55908654 0.41966098 0.31500551 0.23644912 0.17748320
[19] 0.13322226 0.09999916

$dx.aux
 [1] 0.04999958 0.11661071 0.15535273 0.20696616 0.27572731 0.36733324
 [7] 0.48937376 0.65196026 0.86856349 1.15712963 1.32196626 1.15712963
[13] 0.86856349 0.65196026 0.48937376 0.36733324 0.27572731 0.20696616
[19] 0.15535273 0.11661071 0.04999958

$N
[1] 20

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
 [1] 0.09205067 0.28535709 0.49799415 0.73189491 0.98918575 1.27220567
 [7] 1.58352758 1.92598169 2.30268121 2.69731879 3.07401831 3.41647242
[13] 3.72779433 4.01081425 4.26810509 4.50200585 4.71464291 4.90794933
[19] 5.09205067 5.28535709 5.49799415 5.73189491 5.98918575 6.27220567
[25] 6.58352758 6.92598169 7.30268121 7.69731879 8.07401831 8.41647242
[31] 8.72779433 9.01081425 9.26810509 9.50200585 9.71464291 9.90794933

$x.int
 [1]  0.0000000  0.1841013  0.3866128  0.6093755  0.8544144  1.1239571
 [7]  1.4204542  1.7466010  2.1053624  2.5000000  2.8946376  3.2533990
[13]  3.5795458  3.8760429  4.1455856  4.3906245  4.6133872  4.8158987
[19]  5.0000000  5.1841013  5.3866128  5.6093755  5.8544144  6.1239571
[25]  6.4204542  6.7466010  7.1053624  7.5000000  7.8946376  8.2533990
[31]  8.5795458  8.8760429  9.1455856  9.3906245  9.6133872  9.8158987
[37] 10.0000000

$dx
 [1] 0.1841013 0.2025115 0.2227626 0.2450389 0.2695428 0.2964971 0.3261468
 [8] 0.3587614 0.3946376 0.3946376 0.3587614 0.3261468 0.2964971 0.2695428
[15] 0.2450389 0.2227626 0.2025115 0.1841013 0.1841013 0.2025115 0.2227626
[22] 0.2450389 0.2695428 0.2964971 0.3261468 0.3587614 0.3946376 0.3946376
[29] 0.3587614 0.3261468 0.2964971 0.2695428 0.2450389 0.2227626 0.2025115
[36] 0.1841013

$dx.aux
 [1] 0.09205067 0.19330642 0.21263706 0.23390076 0.25729084 0.28301992
 [7] 0.31132191 0.34245411 0.37669952 0.39463759 0.37669952 0.34245411
[13] 0.31132191 0.28301992 0.25729084 0.23390076 0.21263706 0.19330642
[19] 0.18410135 0.19330642 0.21263706 0.23390076 0.25729084 0.28301992
[25] 0.31132191 0.34245411 0.37669952 0.39463759 0.37669952 0.34245411
[31] 0.31132191 0.28301992 0.25729084 0.23390076 0.21263706 0.19330642
[37] 0.09205067

$N
[1] 36

attr(,"class")
[1] "grid.1D"
$x.up
[1] 0

$x.down
[1] 10

$x.mid
 [1] 0.1000059 0.3048835 0.5197296 0.7450293 0.9812912 1.2290485 1.4888608
 [8] 1.7613145 2.0470246 2.3466363 2.6533637 2.9529754 3.2386855 3.5111392
[15] 3.7709515 4.0187088 4.2549707 4.4802704 4.6951165 4.8999941 5.1000025
[22] 5.3471071 5.7105939 6.2452773 7.0317879 7.9682121 8.7547227 9.2894061
[29] 9.6528929 9.8999975

$x.int
 [1]  0.0000000  0.2000117  0.4097552  0.6297040  0.8603546  1.1022277
 [7]  1.3558694  1.6218522  1.9007767  2.1932725  2.5000000  2.8067275
[13]  3.0992233  3.3781478  3.6441306  3.8977723  4.1396454  4.3702960
[19]  4.5902448  4.7999883  5.0000000  5.2000050  5.4942092  5.9269787
[25]  6.5635759  7.5000000  8.4364241  9.0730213  9.5057908  9.7999950
[31] 10.0000000

$dx
 [1] 0.2000117 0.2097435 0.2199488 0.2306506 0.2418731 0.2536417 0.2659828
 [8] 0.2789245 0.2924958 0.3067275 0.3067275 0.2924958 0.2789245 0.2659828
[15] 0.2536417 0.2418731 0.2306506 0.2199488 0.2097435 0.2000117 0.2000050
[22] 0.2942042 0.4327696 0.6365971 0.9364241 0.9364241 0.6365971 0.4327696
[29] 0.2942042 0.2000050

$dx.aux
 [1] 0.1000059 0.2048776 0.2148461 0.2252997 0.2362618 0.2477574 0.2598123
 [8] 0.2724537 0.2857102 0.2996116 0.3067275 0.2996116 0.2857102 0.2724537
[15] 0.2598123 0.2477574 0.2362618 0.2252997 0.2148461 0.2048776 0.2000084
[22] 0.2471046 0.3634869 0.5346834 0.7865106 0.9364241 0.7865106 0.5346834
[29] 0.3634869 0.2471046 0.1000025

$N
[1] 30

attr(,"class")
[1] "grid.1D"

ReacTran documentation built on Dec. 18, 2019, 3:12 a.m.