Professional Documents
Culture Documents
Numerical Solutionsof Water Flowin Unsaturated Soils 8
Numerical Solutionsof Water Flowin Unsaturated Soils 8
net/publication/236681135
CITATIONS READS
0 1,904
3 authors:
Anders Malmer
Swedish University of Agricultural Sciences
54 PUBLICATIONS 1,963 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
Balancing production and ecosystem services from degraded tropical rain forests to aid the transition to a more sustainable bio-based economy View project
All content following this page was uploaded by Budi Indra Setiawan on 03 June 2014.
Budi I. Setiawan
Forewords
This manuscript is one of the results of the Erasmus Mundus Third Country
Scholar Mobility Program given to the first author in the period of three months
between Novermber 2006 and January 2007. The scholar was hosted by the Soil
Science Section, the Department of Forest Ecology, the Faculty of Forest Sciences,
and Swedish University of Agricultural Sciences in Umeå, Sweden. The scholar was
given opportunities to give lectures in three different classes of master programs,
and presented papers and attended seminars in the Department, and also visited the
Soil Physics and Eco-hydrology Research Groups in the Netherlands.
One of the lectures mentioned above was Soil Physics, which was the main concern
to the scholar in this Erasmus Mundus Program. The lecture used Environmental
Soil Physics by Hillel (1998) as the main textbook. This manuscript was intended to
help students solving water flow equation in unsaturated soils.
The manuscript contains throughout solutions to the Darcy and Richards’ equation
by means of Explicit and Implicit schemes of Finite Difference method subjected
to various boundary conditions, uniform or varied initial conditions including
source/sink terms.
We hope this manuscript contributes to the development of the lecture and also
give valuable references for those who have interest in Soil Physics as a whole.
Forewords ................................................................................................. 2
Table of Contents...................................................................................... 3
List of Figures ........................................................................................... 4
List of Symbols and Notations .................................................................. 5
1.Governing Equations.............................................................................. 6
2.Initial and Boundary Conditions ............................................................. 6
3.Hydraulic Properties ............................................................................... 7
4.Explicit Scheme: Dirichlet Boundary Conditions .................................. 10
4.1. Finite Difference Equations .................................................. 10
4.2. Calculation Procedures.......................................................... 12
4.3. Computer Program ............................................................... 13
5.Implicit Scheme: Dirichlet Boundary Conditions .................................. 17
5.1. Finite Difference Equations .................................................. 17
5.2. Linearization Process..................................................................... 20
5.3. Calculation Procedures .................................................................. 22
5.4. Computer Program ........................................................................ 23
6.Comparison: Explicit and Implicit Schemes.......................................... 26
7.Implicit Scheme: Dirichlet and Neumann Boundary Conditions ........... 27
8.Implicit Scheme: Neumann Boundary Conditions ................................ 30
9.Implicit Scheme: Neumann and Cauchy Boundary Conditions ............. 33
References ............................................................................................... 36
Appendix A: Microsoft Visual Basic Editor ............................................. 37
Appendix B: Solver in Microsoft Excel.................................................... 46
Appendix C: Source Codes of Hydraulic Properties................................. 48
Appendix D: Source Codes of WFUSEX1 .............................................. 49
Appendix E: Source Codes of WFUSIM1 ............................................... 54
Appendix F: Source Codes of WFUSIM2................................................ 62
Appendix G: Source Codes of WFUSIM3............................................... 70
Appendix H: Source Codes of WFUSIM4 ............................................... 78
Appendix I: Source Codes of Worksheet and Workbook ........................ 86
1. Governing Equations
Water flow in an unsaturated soil with the assumptions of isothermal and isotropic,
on dimensional porous medium, with the presence of sources/sinks, can be written
in form of Darcy & Richards’s equation (Hillel, 1998. Page: 210-214) as follows.
∂θ ∂ ∂h
= K − 1 + s ( z , t ) ............................................................................. (1.1)
∂t ∂z ∂z
The water flow is considered positive downward, and can be transformed to the
following equation:
∂h ∂ ∂h
C = K − 1 + s( z, t ) ......................................................................... (1.2)
∂t ∂z ∂z
Where, C is the specific water capacity, which is the first derivative of a relation
between volumetric wetness and pressure head, such as:
dθ
C= ........................................................................................................................ (1.3)
dh
∂h ∂k ∂h ∂ 2 h ∂k
C = +k 2 − + s( z, t ) ................................................................. (1.4)
∂t ∂z ∂z ∂z ∂z
Initial condition (IC) of pressure head may be uniform or varies over the soil
profiles, which is written as follows.
In general, there are known three types of boundary conditions for partial
differential equations (Bear and Verruijt, 1987). The first type is known as Dirichlet
BC with which pressured head is prescribed, in examples:
The second type is known as Neumann BC with which flux or gradient of pressure
head is prescribed, in example:
The third type is known as Cauchy BC where there is a semi-previous layer, such as
water flow in pitcher irrigation system (Setiawan, et.al., 2006; Hermantoro, 2003):
hSP − hZ
q (Z , t ) = − → 0 < t < ∞ ........................................................................ (2.5)
C SP
Where,
TSP
C SP = → 0 < t < ∞ ......................................................................................... (2.6)
K SP
3. Hydraulic Properties
Hydraulic properties of the unsaturated soil have to be known before solving the
governing equation subjected to initial and boundary conditions. The hydraulic
properties consist of water retention and hydraulic conductivity curves. The water
retention curve is a relationship between volumetric wetness and water pressure
head, and the hydraulic conductivity curve can be a relationship between hydraulic
conductivity and volumetric wetness. These data generally are provided from
independent measurements, and there must be functions that can represent those
relationships.
For this simulation, data presented by Hillel (1998, Page: 235-236) will be used, and
Genuchten for water retention and Mualem model for hydraulic conductivity curve
(Hillel, 1998. Page: 209) will be applied.
α ⋅ n ⋅ m(α ⋅ h )
n −1
dθ
=−
( )
....................................................................................... (3.2)
1 + [α h ]
dh n m +1
( [
K (S ) = K s ⋅ S 0.5 ⋅ 1 − 1 − S 1/ m ])
m 2
........................................................................ (3.3)
θ − θr
S= ................................................................................................................. (3.4)
θs − θr
Figure 1 shows data and curves of water retention and water specific capacity. The
parameters are obtained using Visual Basic and Solver and in Microsoft Excel
(Appendix A and Appendix B). Genuchten model conforms well to the data as
error is close to 0 and the correlation coefficient approaches unity. Figure 2 shows
data and curves of hydraulic conductivity and water diffusivity. Mualem model
conforms well to the data as the error also is close to zero and the correlation
coefficient approaches unity. The computer program for the hydraulic properties is
listed in Appendix C.
t + ∆t
∂h h j − h j
t
≈ ......................................................................................................... (4.1)
∂t ∆t
The first derivative of pressure head over distance in the the form of central
difference can be written:
∂h h j +1 − h j −1
t t
≈ ......................................................................................................... (4.2)
∂z 2 ∆z
The first derivative of hydraulic conductivity over distance in the form of central
difference can be written:
Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 10
B.I. Setiawan, U.Ilstedt & A.Malmer
∂k k − k
t t
j +1 j −1
≈ ........................................................................................................ (4.3)
∂z 2∆z
The second derivative of pressure head over distance takes the form:
∂ 2 h h j +1 − 2h j + h j −1
t t t
≈ ........................................................................................... (4.4)
∂z 2 ∆z 2
Substituting Eq.4.1, Eq.4.2, Eq.4.3 and Eq.4.4 into Eq.1.4 and by making an
arrangement lead to a system of finite difference equations as follows:
Equation 4.5 is also known as water balance equations, where the coefficients are as
follows:
kt k tj +1 − k tj −1 ∆t
j
a tj = − t .......................................................................... (4.6)
∆z 2 4∆z 2 Cj
k tj ∆t
b tj
= 1− 2 .............................................................................................. (4.7)
∆z 2 t
C
j
kt k tj +1 − k tj −1 ∆t
t j
cj = + t .......................................................................... (4.8)
∆z 2 4∆z 2 Cj
k tj +1 − k tj −1 ∆t
d tj = s tj − t ............................................................................. (4.9)
2∆z Cj
The hydraulic conductivity is calculated from volumetric wetness (see, Eq.3.3 and
E.3.4):
( )
k tj = k θ tj ................................................................................................................ (4.10)
11 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007
Numerical Solutions of Water Flow in Unsaturated Soils
The volumetric wetness is an average value of two neighboring pressure head (see,
Eq.3.1):
θ tj =
1
2
[ ( ) ( )]
θ h tj −1 + θ h tj ....................................................................................... (4.11)
( )
C tj = C h tj ............................................................................................................... (4.12)
Source or sink can be as a function of depth and time, but now is considered as a
function of depth only. In general form, source or sink can be calculated as follows:
s tj = S (z tj ) .................................................................................................................. (4.13)
The whole soil column is divided into n elements, and each element is given index,
j=1, 2, 3, …, n, so that:
z j = j ⋅ ∆z .................................................................................................................. (4.14)
Z
∆z = ....................................................................................................................... (4.15)
n
By giving the initial condition of pressure head, Eq. 4.5 can be solved directly and
successively. However, since this explicit scheme is known as conditionally stable
(Burden and Faires, 1997), the time step must follow:
∆z 2
∆t = λ ⋅ → 0 < λ < 0.5 ................................................................................ (4.16)
Ds
Ks
Ds = .............................................................................................................. (4.17)
C (θ s )
1) Inputting data:
a. Parameters of water retention (Eq.3.1): θs, θr, α, n and m1.
b. Parameters of hydraulic conductivity (Eq.3.3): ks and m2.
c. Depth of soil, and number of elements: Z, and Nz.
Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 12
B.I. Setiawan, U.Ilstedt & A.Malmer
d. Initial and Boundary Conditions (Eq.2.1, Eq.2.2, and Eq.2.3):
h(z,0), h(0,t) and h(Z,t).
2) Inputting and calculating numerical constants:
a. Inputting constant of time step (Eq.4.15): λ
b. Inputting number of sampling time, Nt and sampling times, Ts(i);
i=0,1,2,3..Nt.
c. Inputting source or sink: s(z,0).
d. Calculating spatial interval (Eq.4.14): ∆z.
e. Calculating time step (Eq.4.15): ∆t
f. Calculating elements of soil depth (Eq.4.13): z(j).
3) Assign initial time t=0, and sampling index i=1
4) Calculating hydraulic properties:
a. Volumetric wetness (Eq.4.11): θj.
b. Hydraulic Conductivity (Eq.4.10): kj.
c. Specific Water Capacity (Eq.4.12): Cj.
5) Calculating coefficients of water balance equations:
a. Coefficient aj (Eq.4.6).
b. Coefficient bj (Eq.4.7).
c. Coefficient cj (Eq.4.8).
d. Coefficient dj (Eq.4.9)
6) Calculating new values of hj at t+∆t (Eq.4.5)
7) Assign new time: t=t+∆t
8) Display or save hj when t≥Ts(i), and assign i=i+1.
9) Go back to Step 3 with new hj,
10) Repeat Step 8 until t ≥ Ts(Nt).
11) End.
The computer program is listed in Appendix D and the program is saved in Excel
file WFUSEX1.XLS. Figure 1 will appear when the file is opened. It has a
BANNER, DATA SHEET, FORM SHEET, two Check-Boxes and three
Command-Buttons. Initially, only the first Command-Button [DataSheet] is in
enable mode. The other two are in disable mode, and they become enabling after
[DataShet] has been clicked.
DATA SHEET contains data that must be inputted, some are calculated values,
and the others are displaying indicators of calculation progress. Each cell has its
comment for the meaning of name or symbol. One or more of the content, and
also its order of DATA SHEET must not be moved or deleted since the program
refers to them consistently. For emergency, if something has happened that the
DATA SHEET is incomplete, the BANNER can be clicked to restore the list and
the order of DATA SHEET. Cells for Tolerance, Error and Iteration are inactive
and will be used later for the implicit scheme.
13 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007
Numerical Solutions of Water Flow in Unsaturated Soils
FORM SHEET will appear after the [DataSheet] has been clicked, and the other
two Button will be in enable mode. A brieft description of the content of FORM
SHEET is as follows:
1. Time Series contains index and number of how many times calculated
results (equivalent depth of water and pressure head) will be displayed in
the FORM SHEET. The list of index will be automatically given, and the
number is according to the value of Nt in the DATA SHEET. Now, the
largest number of Nt is limited to 10. It can easily be increased by replacing
it in the header of the program (Appendix D).
2. Sampling Time contains a list of simulation times at which the results will
be displayed in the FORM SHEET. Sampling times can be entered or
changed as necessary but it must be in order from low to higher values.
3. Equivalent Depth displays amount of water in the soil at the initial
condition and at each sampling time.
4. The 4 columns below list spatial index (j), soil depth (z), source/sink (s)
and initial pressure head (h). Source/sink can be entered, and the initial
pressure head can be changed at any soil depth.
Either using one or two of these Check-Boxes will increase the ComTime
(Computational Time). ComTime generally increases one-third if one Check-Box is
filled, and about one-half if both Check-Boxes are filled.
As the calculation progress, results of equivalent depth of water and pressure head
will be dispalyed in the column below each sampling time, and a message
‘COMPLETED’ will show up at end of the sampling time.
The third Command-Button [Clear Last Values] is another option to clear or empty
the FORM SHEET from the values of equivalent depth of water and pressure
head, and to prepare the FORM SHEET for another calculation without changing
values in the DATA SHEET, and Sampling Times.
Figure 5. Pressure head and equivalent depth of water when applying WFUSEX1.
t + ∆t
∂h h j − h j
t
≈ ......................................................................................................... (5.1)
∂t ∆t
t + ∆t t + ∆t
∂h h j +1 − h j −1
≈ ................................................................................................ (5.2)
∂z 2∆z
t + ∆t / 2
∂k k j +1 − k tj+−1∆t / 2
≈ ....................................................................................... (5.3)
∂z 2∆z
e tj+ ∆t = a tj+ ∆t / 2 ⋅ h tj+−1∆t + b tj+ ∆t / 2 ⋅ h tj+ ∆t + c tj+ ∆t / 2 ⋅ h tj++1∆t + d tj+ ∆t ... (5.5)
Where,
k t + ∆t / 2
j k tj++1∆t / 2 − k tj+−1∆t / 2 ∆t
a tj+ ∆t / 2 = − t + ∆t / 2 ............................... (5.6)
∆z 2 4∆z 2 Cj
t + ∆t / 2
k tj+ ∆t / 2 ∆t
.............................................................. (5.7)
bj = − 1 + 2
2 t + ∆t / 2
∆z Cj
k t + ∆t / 2
j k tj++1∆t / 2 − k tj+−1∆t / 2 ∆t
c tj+ ∆t / 2 = + t + ∆t / 2 ............................... (5.8)
∆z 2 4∆z 2 Cj
k tj++1∆t / 2 − k tj+−1∆t / 2
∆t
d tj+ ∆t / 2 = h tj + s tj+ ∆t / 2 − t + ∆t / 2 ...................... (5.9)
2∆z Cj
( )
k tj+ ∆t / 2 = k θ tj+ ∆t / 2 .......................................................................................... (5.10)
θ tj +∆t / 2 =
2
[
1 t + ∆t
]
θ j + θ tj ............................................................................................ (5.11)
θ tj =
1
2
[ ]
θ (h tj −1 ) + θ (h tj ) .......................................................................................... (5.12)
θ tj+ ∆t =
1
2
[( ) ( )]
θ h tj+−1∆t + θ h tj+ ∆t ......................................................................... (5.13)
C tj + ∆t / 2 =
2
[
1 t + ∆t
]
C j + C tj ......................................................................................... (5.14)
( )
C tj = C h tj ............................................................................................................... (5.15)
( )
C tj+ ∆t = C h tj+ ∆t ................................................................................................... (5.16)
Source or sink can be as a function of depth and time, but now is considered as a
function of depth only. In general form, source or sink can be calculated as follows:
s tj+ ∆t / 2 =
2
[
1 t + ∆t
]
s j + s tj ............................................................................................ (5.17)
s tj = S (z tj ) .................................................................................................................. (5.18)
( )
s tj+ ∆t = S z tj+ ∆t .................................................................................................... (5.19)
The whole soil column is divided into n elements, and each element is given index
j=1, 2, 3, …, n, so that:
z j = j ⋅ ∆z .................................................................................................................. (5.20)
Z
∆z = ....................................................................................................................... (5.21)
n
By giving the already known pressure head and initial approximation of pressure
head ahead, Eq. 5.5 can be solved interatively so that it approaches to a given
tolerance. However, Eq.5.5 can not be solved directly since it is a system of non-
linear equations. It needs a linearization process.
Linearization process can be carried out using Newton’s method (Burden and
Faiers, 1997) Equation 5.5 can be written in form of matrices (Eq.5.22). The
pressure head in the boundaries is placed on the right side. The coefficients form a
tridiagonal matrix.
b1 c1 0 0 0 0 h1 d1 e1 − a1 ⋅ h0
a2 b2 c2 0 0 0 h2 d 2 e2
0 a3 b3 c3 0 0 h3 d 3 e3
+ = .. (5.22)
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
0 0 0 a n −1 bn −1
cn −1 hn −1 d n −1 en −1
0 0 0 0 an bn hn d n en − cn ⋅ hn
New functions (fj) are now assigned to represent Eq.5.22. These functions indeed
are analog to Eq.5.5 since fj will be made to approach zero, or a tolerance value.
A Jacobian matrix can be introduced to linearize Eq.5.23 (Burden and Faires, 1997),
which also forms a tridiagonal matrix:
∂f1 ∂f1
0 0 0 0
∂h1 ∂h2
∂f 2 ∂f 2 ∂f 2
0 0 0 ∆h1 f1
∂h1 ∂h2 ∂h3 f
∂f 3 ∂f 3 ∂f 3 ∆h2 2
0 0 0
∂h2 ∂h3 ∂h4 3 = − f 3 ..... (5.24)
∆ h
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
∆hn −1 f n −1
∂f n −1 ∂f n −1 ∂f n −1
0 0 0 ∆hn fn
∂hn −2 ∂hn −1 ∂hn
∂f n ∂f n
0 0 0 0
∂hn −1 ∂hn
∂f j f j ( h j −1 + ∆h' j −1 ) − f j ( h j −1 )
a' j = ≈ ...................................................... (5.25)
∂h j −1 ∆h' j −1
∂f j f j ( h j + ∆h' j ) − f j ( h j )
b' j = ≈ ................................................................. (5.26)
∂h j ∆h' j
Thomas or Crout Reduction algorithm can be used (Burden and Faires, 1997) to
solve a tridiagonal matrix, such as Eq.5.24. The solution will give increments of
pressure head. The values of pressure head are updated as follows:
h kj +1 = h kj + ∆h kj ....................................................................................................... (5.29)
Final values of pressure head are obtained after the following condition is reached:
n
0 < ∑ f j < ε .......................................................................................................... (5.30)
j =1
∆z 2
∆t = λ ⋅ → 0 < λ < 0.5 ................................................................................ (5.31)
Ds
Ks
Ds = .............................................................................................................. (5.32)
C (θ s )
The time step will then change according to the following conditions:
1) Inputting data:
Figure 8 shows pressure head and equivalent depth of water. Now, there is no
oscillation. The calculation results are stable all the time even though with the time
step greater thousand times than that when applying the explicit scheme.
Figure 5. Pressure head and equivalent depth of water when applying WFUSIM1.
In this section, the implicit scheme is subjected to two different types of boundary
conditions. Dirichlet BC is on the soil surface and Neumann BC is at the bottom of
the soil column.
∂h ∂q
C = − + s( z, t ) .............................................................................................. (7.3)
∂t ∂z
∂q q − qn
= − n +1 ................................................................................................... (7.4)
∂z ∆z
Where,
h − hn −1
qn = − k n n − 1 ..................................................................................... (7.5)
∆z
q n +1 = q Z ................................................................................................................... (7.6)
Where,
k nt + ∆t / 2 ∆t
ant + ∆t / 2 = ⋅ t + ∆t / 2 ......................................................................................... (7.8)
∆z 2
Cn
k t + ∆t / 2 ∆t
bnt + ∆t / 2 = − n ⋅ − 1 ................................................................... (7.9)
∆z 2 C nt + ∆t / 2
c nt + ∆t / 2 = 0 ............................................................................................................. (7.10)
q − k nt + ∆t / 2
⋅ ∆t
d nt + ∆t / 2 = hnt + s ( j ) − Z .................................... (7.11)
∆z C t + ∆t / 2
n
Figure 8. Pressure head and equivalent depth of water when applying WFUSIM2
In this section, the implicit scheme is subjected to Neumann BCs both on the soil
surface and at the bottom of the soil column:
∂h ∂q
C = − + s( z, t ) .............................................................................................. (8.3)
∂t ∂z
∂q q −q
= − 1 0 + s ( z, t ) ....................................................................................... (8.4)
∂z ∆z
Where,
h − h
q1 = − k1 1 0 − 1 .......................................................................................... (8.5)
∆z
e0t + ∆t = a0t + ∆t / 2 ⋅ h−t +1 ∆t + b0t + ∆t / 2 ⋅ h0t + ∆t + c0t + ∆t / 2 ⋅ h1t + ∆t + d0t + ∆t ...... (8.6)
Where,
k1t + ∆t / 2 ∆t
b0t + ∆t / 2 =− ⋅ + 1 ................................................................... (8.8)
∆z 2 C 0t + ∆t / 2
k t + ∆t / 2 ∆t
c0t + ∆t / 2 = 1 ⋅ ............................................................................... (8.9)
2 t + ∆t / 2
∆z C0
k1t + ∆t / 2 − q 0
⋅ ∆t
d 0t + ∆t / 2 = h0t + s( j ) − ..................................... (8.10)
∆z C t + ∆t / 2
0
Figure 10. Pressure head and equivalent depth of water when applying WFUSIM3.
Where,
h − hn
qSP = − SP .................................................................................................... (9.3)
CSP
T
C SP = SP ............................................................................................................... (9.4)
K SP
∂q q − qn
= − SP + s( z, t ) .................................................................................... (9.5)
∂z ∆z
Where,
h − hn −1
qn = − k n n − 1 ...................................................................................... (9.6)
∆z
ent + ∆t = a nt + ∆t / 2 ⋅ hnt +−1∆t + bnt + ∆t / 2 ⋅ hnt + ∆t + cnt + ∆t / 2 ⋅ hnt ++1∆t + d nt + ∆t ........................... (9.7)
Where,
k nt + ∆t / 2 ∆t 1
bnt + ∆t / 2 =− ⋅ −1− ..................................................... (9.9)
∆z t + ∆t / 2 C SP
Cn
c 0t + ∆t / 2 = 0
.............................................................................................................. (9.10)
h ∆t
d nt + ∆t / 2 = hnt + s ( j ) + k nt + ∆t / 2 + SP ⋅ .............................. (9.11)
C SP t + ∆t / 2
Cn
Figure 14 shows the appearance of program WFUSIM4. There are three additional
cells for inputting data of the semi-previous layer. Calculated water flux through the
semi-previous layer is displayed in the DATA SHEET automatically at each
sampling time. Water flux on the soil surface is set equal to the saturated hydraulic
conductivity, and the semi-previous layer is 10-6 cm/s. It should be noted that the
semi-prevous layer is more impermeable than the soil. As also shown in Fig.15,
pressure head at the lower part changes with time but very slow due to the upward
water flux which is relatively small. As shown in the DATA SHEET, the upward
flux, q(Z,t), has a negative sign.
Figure 12. Pressure head and equivalent depth of water when applying WFUSIM4.
35 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007
Numerical Solutions of Water Flow in Unsaturated Soils
References
Bear, J., and A. Verruijt. 1987. Modeling Groundwater Flow and Pollution. D.
Reidel Publishing Company. Dordrecht, Holland. Pages:68-72.
Burden, R.L., and J.D. Faires. 1997. Numerical Analysis. 6th Edition. Brooks/Cole
Publishing Company. USA.
Setiawan, B.I. 1993. Studies of water flow in soil with macropores. Dissertation.
Graduate School of Agricultural and Life Sciences, The University of Tokyo.
Tokyo, Japan.
Microsoft Excel has another tool for writing equations and also computer programs
containing many procedures. There is an editor called Visual Basic Editor to
facilitate the computational programming. If one makes a function there then the
function can be called and assigned to a single cell in the worksheet just like calling
a function from Excel Library. The function is stored in User Defined Function
within Excel Library.
After that, a new page named Microsoft Visual Basic will appear, such shown in
Fig.A.2, under the Microsoft Excel Objects, there sub-directories for active Sheets,
and ThisWorkbook.
As shown in Fig.A.4, a directory for Modules has been created and exists at the
same level with Microsoft Excel Objects. The directory has a sub-directory
Module1, and the empty space under Book1-Module1 (Code) is the place to write
computer programs that will be stored in Module1.
First, the Genuchten model (Eq.1.3) will be written and stored in Module1. A
possible computer program for this model in form of function is as follows.
It begins with a reserved word (an optional), Rem, follows with information or
description of the function to be defined. This line proceeded with Rem is not a
computer program, so it will not be executed. The Function WRC has 6 inputs:
TheS for θs, TheR for θr, Alpha for α, n, m1, and hx for pressure head (h). This
function is closed with End Function.
Fig.A.5 shows the function after it is written in the editor, and saved in a file named
MVBExample.XLS.
The next step is to see whether the function is already inside Excel library. This can
be done by clicking the symbol fx (insert function), and select a category User
Defined, and WRC will be displayed in Select a function’s window (Fig.A.6). If
the WRC is highlighted then the in the lower part it will shows a complete syntax of
the function with its inputs in order manner such as written and stored in Module1.
If the result is correct then the Function WRC is ready to use in a cell in an active
worksheet, or is referred by other programs written in the same Module1 or other
Modules.
As shown in Fig.A.9, in the header there are definition of variables and arrays for nj
which is a constant equals to 20, array h(nj) to store data of pressure head, array
1
CommandButton is located in Control ToolBox. It can be called by clicking:
View>Toolbars>Control ToolBox
39 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007
Numerical Solutions of Water Flow in Unsaturated Soils
Next j
Rem 3) Calculate volumetric wetness
For j = 1 To nj
w(j) = WRC(TheS, TheR, Alpha, n, m1, h(j))
Next j
Rem 4) Display volumetric wetness
For j = 1 To nj
Cells(9 + j, 4) = w(j)
Next j
End Sub
A. 7 Window of Function Arguments to test the Function WRC for the given
values of inputs/arguments.
Cells B2:B6 contains initial estimation of the parameters. Cells B10:B29 contains
measured pressure head, and Cells C10:C29 contains measured volumetric wetness,
and Cells D10:D29 contains calculated volumetric wetness using the model. When
using these parameters, there are big difference between those measured and
calculated volumetric wetness. The sum of the squared differences (error) is shown
in Cell C30, and with their correlation coefficient is shown Cell C31.
Figure B.2 shows the Solver Results where now the parameters in Cells B2:B6 have
been optimized and now produce far smaller error in Cell C30. So, it can be
concluded that the calculated volumetric wetness using Genuchten model
conforms to the data quite well. The Solver was also be used to find parameters of
Mualem model (Eq.1.5) from a pair of data of volumetric wetness and hydraulic
conductivity, such as described before in Sub-section 4.4.
2
If the Solver does not exist in Tools, then it can be installed by clicking: Tools>Add-
ins, and then select Solver Add-in
Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 46
B.I. Setiawan, U.Ilstedt & A.Malmer
B. 2. Solver results show error in Cell C30 is far smaller now than before the
parameters were optimized, and also the correlation coefficient is close to unity.
End Sub
End Sub
Rem ThisWorkbook
Private Sub Workbook_Open()
Msg = "This program is free to copy. Please, email us if there's any inquiries"
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
Sheet1.CommandButton2.Enabled = False
Sheet1.CommandButton3.Enabled = False
End Sub