-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution_diffusion.reaction.equation.py
86 lines (86 loc) · 2.59 KB
/
solution_diffusion.reaction.equation.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
########################################################################
# R.A.Borrelli
# @TheDoctorRAB
# rev.03.June.2014
########################################################################
# Analytical solution to the diffusion reaction equation.
# Cartesian coordinates are used.
# This is for a semi-infinite domain with Dirichlet boundary conditions.
# The initial condition is zero.
# The solution is normalized to the initial condition.
# This is also used as a comparison for the companion FEM solution.
########################################################################
#
########################################################################
# e,i,j,k,n are used for loop indices
########################################################################
#
#
#
####### imports
import numpy
import scipy.special
import side_conditions
import fem_functions as fem_f
import physical_constants as phyc
import make_plot
#######
#
####### read in the input data
# boundary conditions and time
bc1,bc2,time=side_conditions.side_conditions()
###
# physical constants
decay_constant,diffusion_coefficient,porosity,retardation=phyc.physical_constants()
#######
#
####### construct spatial domain
# this uses a function created for the FEM solution
# h and element are not needed for this routine
# they are needed for the FEM solution and this function just does all that
#
spatial_mesh,h,node,element=fem_f.spatial_mesh_discretization()
#######
#
####### initialize the solution matrix
# the spatial mesh is arbitrarily chosen to be 1001 points
solution=numpy.zeros((node,2))
#######
#
####### load in the spatial domain to the solution matrix
for i in range(0,node):
solution[i,0]=spatial_mesh[i]
# end i
#######
#
#######
# compute solution
# the arguments in the exp and erfc are complicated
# so just simplify them here for coding ease
###
#
###
erfc1=numpy.sqrt((retardation)/(4*porosity*diffusion_coefficient*time))
erfc2=decay_constant*time
exp=numpy.sqrt((retardation*decay_constant)/(porosity*diffusion_coefficient))
###
# assign boundary conditions
solution[0,1]=bc1
solution[node-1,1]=bc2
for j in range(1,node-1):
solution[j,1]=(0.5)*((scipy.exp(solution[j,0]*exp)*scipy.special.erfc((solution[j,0]*erfc1)+(erfc2))+(scipy.exp(-solution[j,0]*exp)*scipy.special.erfc((solution[j,0]*erfc1)-(erfc2)))))
# end j
#######
#
####### plot
make_plot.makeplot(solution,1)
#######
# save solution
numpy.savetxt('solution_diffusion.reaction.equation.out',solution)
#######
#
#
#
########################################################################
# EOF
########################################################################