mdfimpdifftreq: 1D diffusion, boundary constant, FD implicit for specific...

Description Usage Arguments Value Examples

View source: R/funcs_diffs_implicit_reqs.R

Description

Function to solve diffusion equation using finite difference method, backward euler or implicit scheme, applied in the condition where: a) the diffusion occurs inside a slab of material unidimensionally, or only along one axis, b) the coefficient of diffusion is constant, and c) the boundary conditions are constant. It will return the solution values for the requested time point(s).

Usage

1
mdfimpdifftreq(D,Nx,Nt,l,T,C_i=0,C_f=1,treq)

Arguments

D

Coefficient of diffusion, constant

Nx

number of points in space (x)

Nt

number of points in time (t)

l

half-length of the slab, usually in cm

T

Total calculated diffusion time, usually in seconds

C_i

Initial concentration value inside the slab

C_f

Dirichlet boundary condition, final concentration coming from the outside of the slab, with one or two elements. If there is only one element, the two sides of the slab (x = -l and x = l) will have the same C_f. If there are two elements, the first element (C_f[1]) will be on x = -l while the second one will be on x = l.

treq

requested time value(s)

Value

A matrix with length(treq) number of row and Nx number of column, profiling the diffusion.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
C_i = 0.00 # Initial concentration inside the slab
C_f = 1.00	# Final concentration coming from outside
D = 1e-7 # Coefficient of diffusion, cm^2/s
Nt = 100 # points in time
Nx = 20 # points in space
l = 0.25 # half-thickness of the slab, in cm
T = 432000 # Total measured time in seconds (~5 days)
treq = 1e4 # requested time in seconds
u <- mdfimpdifftreq(D,Nx,Nt,l,T,C_i,C_f,treq)

# Using base plot
x <- seq(-l,l,length.out = Nx)
plot(x,u,type="b", xlab = "x (cm)", ylab = bquote(c["x,t"]))

ahmad-alkadri/Rdiffsolver documentation built on Feb. 4, 2020, 9:45 p.m.