mdfexdiffxtreq: 1D diffusion, boundary constant, FD explicit for specific...

Description Usage Arguments Value Examples

View source: R/funcs_diffs_explicit_reqs.R

Description

Function to solve diffusion equation using finite difference method, forward euler or explicit 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 space (x) and time (t) point(s).

Usage

1
mdfexdiffxtreq(D,dt,l,xreq,treq,T,C_i=0,C_f=1,F=0.5)

Arguments

D

Coefficient of diffusion, constant

dt

different between each time steps

l

half-length of the slab, usually in cm

xreq

requested x point(s)

treq

requested t point(s)

T

Total calculated diffusion time

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.

F

Fourier's mesh number, should be less than or equal to 0.5 to make sure that the solution is stable

Value

A matrix with length(treq) number of row and length(xreq) number of column, profiling the diffusion in the slab for the requested x and t points.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
C_i = 0.00 # Initial concentration inside the slab
C_f = 1.00	# Final concentration coming from outside
D = 10^-7 # Coefficient of diffusion, cm^2/s
dt = 60 # difference between each time step
l = 0.25 # half-thickness of the slab, in cm
F = 0.5 # Fourier's mesh number
T = 432000 # Total measured time in seconds (~5 days)
xreq = seq(-0.25,0,length.out = 20) # requested space (x) points
treq = seq(1e2,1e5,length.out = 40) # requested time (t) points
ureq <- mdfexdiffxtreq(D,dt,l,xreq,treq,T,C_i,C_f,F)

# Using plotly for plotting a contour plot
library(plotly)

df.list <- list(x = xreq,
                y = treq,
                z = ureq)

plot_ly() %>%
    add_contour(x = df.list$x, y = df.list$y, z = df.list$z) %>%
    layout(title = "Contour plot diffusion",
           xaxis = list(title = "Requested x points (cm)"),
           yaxis = list(title = "t (s)"))

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