You are on page 1of 87

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/236681135

NUMERICAL SOLUTIONS TO THE WATER FLOW EQUATIONS IN UNSATURATED


SOILS -Explicit and Implicit Schemes of Finite Different Method- -Dirichlet,
Neumann and Cauchy Boundary Conditions-...

Technical Report · May 2013

CITATIONS READS
0 1,904

3 authors:

Budi Indra Setiawan Ulrik Ilstedt


Bogor Agricultural University Swedish University of Agricultural Sciences
211 PUBLICATIONS   713 CITATIONS    75 PUBLICATIONS   3,054 CITATIONS   

SEE PROFILE SEE PROFILE

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

The Sow-a-Seed (INIKEA) Rain Forest Restoration Project View project

All content following this page was uploaded by Budi Indra Setiawan on 03 June 2014.

The user has requested enhancement of the downloaded file.


NUMERICAL SOLUTIONS TO THE WATER
FLOW EQUATIONS IN UNSATURATED SOILS
-Explicit and Implicit Schemes of Finite Different Method-
-Dirichlet, Neumann and Cauchy Boundary Conditions-
-Microsoft Excel and Visual Basic Editor-

Budi I. Setiawan

Professor, Department of Agricultural Engineering


Bogor Agricultural Technology, Bogor 16680, Indonesia.
Email: budindra@ipb.ac.id, Http://web.ipb.ac.id/~budindra/

Visiting Professor, Department of Forest Ecology


Swedish University of Agricultural Sciences, Umeå, Sweden. Nov 2006-Jan 2007.

Ulrik Ilstedt and Anders Malmer

Assistant and Associate Professors, Department of Forest Ecology


Swedish University of Agricultural Sciences, Umeå, Sweden.
Email: ulrik.ilstedt@sek.slu.se and anders.malmer@sek.slu.se
Numerical Solutions of Water Flow in Unsaturated Soils

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.

The computer program is written in Microsoft Excel Spreadsheet combined with


Visual Basic. It is the main pupose that the user can follow every step of
calculations, advantages and disadvantages of using different schemes, and also
effects of applying different types of boundry conditions. Descriptions of how to
build computer program in Microsoft Excel also are given in Appendices.

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.

Finally, we acknowledge Erasmus Mundus, Department of Forest Ecology of


Swedish University of Agricultural Scienes, and those whorehave given appropriate
efforts from the preparation and to the implementation of this Third Country
Scholar Mobility Program.

Umeå, January 2007

Budi I. Setiawan, Ulrik Ilstedt, Anders Malmer

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 2


B.I. Setiawan, U.Ilstedt & A.Malmer
Table of Contents

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

3 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
List of Figures

Figure 1. Water retention and specific water capacity curves........................ 9


Figure 2. Hydraulic conductivity and water diffusivity curves ...................... 9
Figure 3. Explicit scheme: Discretization and determination of specific water
capacity and hydraulic conductivity............................................. 10
Figure 4. Appearance of worksheet for WFUSIM1.XLS............................ 25
Figure 5. Pressure head and equivalent depth of water when applying
WFUSIM1.................................................................................. 25
Figure 6. Comparison between the results of WFUSEX1 and WFUSIM1. 26
Figure 7. Appearance of worksheet for WFUSIM2.................................... 29
Figure 8. Pressure head and equivalent depth of water when applying
WFUSIM2.................................................................................. 29
Figure 9. Appearance of worksheet for WFUSIM3.................................... 32
Figure 10. Pressure head and equivalent depth of water when applying
WFUSIM3.................................................................................. 32
Figure 11. Appearance of worksheet for WFUSIM4. ................................. 35
Figure 12. Pressure head and equivalent depth of water when applying
WFUSIM4.................................................................................. 35

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 4


B.I. Setiawan, U.Ilstedt & A.Malmer

List of Symbols and Notations

Simbols and Notations


Unit Description
Equation Program
Z Zn cm Depth of soil column
z z cm Depth of soil layer/element
n Nz integer Number of elements
∆z dZ cm Thickness of soil element
θ w cm3/cm3 Volumetric wetness
θs Ws cm3/cm3 Saturated volumetric wetness
θr Wr cm3/cm3 Residual volumetric wetness
α Alpha 1/cm Parameter of Genuchten model
n n1 Parameter of Genuchten model
m m1 Parameter of Genuchten model
k k cm/s Hydraulic conductivity
ks Ks cm/s Saturated hydraulic conductivity
m m2 Parameter of Mualem model
s s 1/s Sources or sinks
c c 1/cm Specific water capacity
h h, ht cmH2O Pressure head (h) at t and (ht) at t+dt
t t second time
λ Lamda Multiplying constant of time step
∆t dT s Time step
Ts s Sampling time
Nt integer Number of sampling times
ε Tolerance Error tolerance
Error Cumulative errors of water balance equations
k It Integer Iteration
kmin Itmin Integer Minimum iteration
kmax Itmax Integer Maximum iteration
Counter Integer Number of repetitions or calculation cycles
SimTime s Simulation time
ComTime s Computational time
δ Delta Constant to increase time step
κ Kappa Constant to decrease time step
TSP TSP cm Thickness of semi-previous layer
KSP KSP cm/s Conductivity of semi-previous layer
CSP CSP s Resistance of semi-previous layer

5 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

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:


C= ........................................................................................................................ (1.3)
dh

The governing equation can be expanded, and becomes:

∂h ∂k ∂h ∂ 2 h ∂k
C = +k 2 − + s( z, t ) ................................................................. (1.4)
∂t ∂z ∂z ∂z ∂z

2. Initial and Boundary Conditions

Initial condition (IC) of pressure head may be uniform or varies over the soil
profiles, which is written as follows.

h (z,0) = h (z ) → 0 ≤ z ≤ Z ..................................................................................... (2.1)

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:

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 6


B.I. Setiawan, U.Ilstedt & A.Malmer
h (0, t ) = h0 → 0 < t < ∞ ......................................................................................... (2.2)

h (Z , t ) = h (Z ) → 0 < t < ∞ .................................................................................... (2.3)

The second type is known as Neumann BC with which flux or gradient of pressure
head is prescribed, in example:

q(Z , t ) = q(Z ) → 0 < t < ∞ .................................................................................... (2.4)

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.

Genuchten model takes the form of:

7 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
θs − θr
θ (h ) = θ r +
(1 + [α h ] )
........................................................................................ (3.1)
n m

Its first derivative, or the water specific capacity, C, is:

α ⋅ n ⋅ m(α ⋅ h )
n −1

=−
( )
....................................................................................... (3.2)
1 + [α h ]
dh n m +1

Mualem model takes the form:

( [
K (S ) = K s ⋅ S 0.5 ⋅ 1 − 1 − S 1/ m ])
m 2
........................................................................ (3.3)

Where, S which is called degree of saturation is:

θ − θ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.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 8


B.I. Setiawan, U.Ilstedt & A.Malmer

Figure 1. Water retention and specific water capacity curves

Figure 2. Hydraulic conductivity and water diffusivity curves

9 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

4. Explicit Scheme: Dirichlet Boundary Conditions

4.1. Finite Difference Equations

Figure 3. Explicit scheme: Discretization and determination of specific water


capacity and hydraulic conductivity.

Figure 3 shows discretization of flow domain and procedure to determine specific


water capacity and hydraulic conductivity. Refering to the governing equation
(Eq.1.4), the first derivative of pressure head over time in the form of forward
difference can be written:

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:

h tj+ ∆t = a tj ⋅ h tj −1 + b tj ⋅ h tj + c tj ⋅ h tj +1 + d tj ................................................. (4.5)

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)

The specific water capacity is obtained from pressure head (Eq.3.2):

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

4.2. Calculation Procedures

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.

4.3. Computer Program

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.

A new FORM SHEET can be re-generated by clicking [DataSheet], in example if


there is any value in the DATA SHEET must be changed.

If the second Command-Button [FormSheet & Execute] is clicked then the


calculation begins. There are two options available to monitor the progress of
calculation:

1. Counter as it appears in lower part of DATA SHEET. If the Check-Box is


filled then the Counter will show numbers of calculation cycles.
2. SimTime (Simulation Time) will show successive increases of simulation
times until the end of the Sampling times.

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.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 14


B.I. Setiawan, U.Ilstedt & A.Malmer
Figure 4 shows also results of running WFUSEX1 using the values in DATA
SHEET, and Fig.5 shows graphs of pressure head and equivalent depth of water in
the soil colum at each sampling time. The initial pressure head is uniform -1000 cm.
Pressure head on the soil surface is 0 cmH2O. Time step is 0.002 s. Oscillation
appears at 30 s but then it disappears at longer times. Lowering the time step will
prevent the appearance of oscillation but it will also take longer computational time.
The soil column will not become saturated because of the effect of Dirichlet
condition at its bottom. The computational time is 486 s using Pentium 3. The
counter shows 900 thousand cycles of calculation, which is large enough to cause
calculation errors due to rounding-up.

Appendix I shows computer program to activate the main program in Appendix D.


These programs are put under the CommandButtons, Image, and Worksheet.
These same programs will also be used to activate the other implicit schemes.

15 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

Figure 4. Appearance of worksheet for program WFUSEX1.

Figure 5. Pressure head and equivalent depth of water when applying WFUSEX1.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 16


B.I. Setiawan, U.Ilstedt & A.Malmer

5. Implicit Scheme: Dirichlet Boundary Conditions

5.1. Finite Difference Equations

Figure 6. Implicit scheme: Discretization and determination of specific water


capacity and hydraulic conductivity

Figure 6 shows discretization of flow domain and procedure to determine specific


water capacity and hydraulic conductivity. The first derivative of pressure over time
is:

t + ∆t
∂h h j − h j
t

≈ ......................................................................................................... (5.1)
∂t ∆t

The first derivative of pressure head over distance is:

t + ∆t t + ∆t
∂h h j +1 − h j −1
≈ ................................................................................................ (5.2)
∂z 2∆z

17 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
The first derivative of hydraulic conductivity over distance is:

t + ∆t / 2
∂k k j +1 − k tj+−1∆t / 2
≈ ....................................................................................... (5.3)
∂z 2∆z

The second derivative of pressure head over distance is:

∂ 2h h tj++1∆t − 2h tj+ ∆t + h tj+−1∆t


≈ ......................................................................... (5.4)
∂z 2 ∆z 2

Substitution of Eq.5.1, Eq.5.2, Eq.5.3, and Eq.5.4 into Eq.1.4 becomes:

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
 

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 18


B.I. Setiawan, U.Ilstedt & A.Malmer
The hydraulic conductivity is calculated from a temporal average of volumetric
wetness:

( )
k tj+ ∆t / 2 = k θ tj+ ∆t / 2 .......................................................................................... (5.10)

The temporal average of volumetric wetness is calculated as follows:

θ tj +∆t / 2 =
2
[
1 t + ∆t
]
θ j + θ tj ............................................................................................ (5.11)

The volumetric wetness in an element at the same time is calculated by a spatial


average as follows:

θ tj =
1
2
[ ]
θ (h tj −1 ) + θ (h tj ) .......................................................................................... (5.12)

θ tj+ ∆t =
1
2
[( ) ( )]
θ h tj+−1∆t + θ h tj+ ∆t ......................................................................... (5.13)

The specific water capacity is calculated by temporal average as follows:

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)

19 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

( )
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.

5.2. 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.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 20


B.I. Setiawan, U.Ilstedt & A.Malmer
 f1   b1 c1 0 0 0 0   h1   d1   e1 − a1 ⋅ h0 
 f   a2 b2 c2 0 0 0   h2   d 2   e2 
 2        
 f3   0 a3 b3 c3 0 0   h3   d 3   e3 
 =  + − 
 ⋅   ⋅ ⋅ ⋅ ⋅ ⋅ ⋅  ⋅   ⋅   ⋅ 
 f n −1   0 0 0 a n −1 bn −1 cn −1  hn −1  d n −1   en −1 
        
 fn   0 0 0 0 an bn   hn   d n  en − cn ⋅ hn 
....................................................................................................................................... (5.23)

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 

Derivatives in the Jacobian matrix can be calculated as follows (Setiawan, 1993;


Askari, 2006):

∂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

21 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
∂f j f j (h j +1 + ∆h' j +1 ) − f j (h j +1 )
c' j = ≈ ........................................... (5.27)
∂h j +1 ∆h' j +1

∆h' j = ξ ⋅ h j ξ → 0 ..................................................................................... (5.28)

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

In the beginning, the time step is given by the following equation:

∆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:

∆t t + ∆t = ∆t t + δ ⋅ ∆t 0 → k < k min → 0 < δ < 1 ............................................. (5.33)

∆t t + ∆t = κ ⋅ ∆t t → k > k max → 0 < κ < 1 .................................................. (5.34)

∆t t + ∆t = ∆t 0 → ∆t t + ∆t < ∆t 0 ................................................................................ (5.35)

5.3. Calculation Procedures

1) Inputting data:

a. Parameters of water retention (Eq.3.1): θs, θr, α, n and m1.


Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 22
B.I. Setiawan, U.Ilstedt & A.Malmer
b. Parameters of hydraulic conductivity (Eq.3.3): ks and m2.
c. Depth of soil, and number of elements: Z, and Nz.
d. Initial and Boundary Conditions: h(z,t), h(0,t) and h(Z,t).

2) Inputting and calculating numerical constants:

a. Inputting constant of time step (Eq.5.31): λ


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 (e.5.21): ∆z=Z/Nz.
e. Calculating time step (Eq.5.31): ∆t.
f. Calculating elements of soil depth (Eq.5.20): z(j); j=0,1,2,3,…,Nz.

3) Calculate hydraulic properties for pressure head at time t:

a. Volumetric wetness (Eq.5.12): θj.


b. Hydraulic Conductivity (Eq.5.10): kj.
c. Specific Water Capacity (Eq.5.15): Cj.

4) Give initial approximation of pressure head for pressure head at t+ ∆t .


5) Calculate hydraulic properties:

a. Volumetric wetness (Eq.5.13): θj.


b. Hydraulic Conductivity (Eq.5.10): kj
c. Specific Water Capacity (Eq.5.14): Cj.

6) Calculate water balance equations (Eq.5.23), and check whether it has


confirmed to Eq.5.30. If it is yes then and go to Step 9. If it is not then go
to Step 8.
7) Calculate Eq.5.24, and obtain increments of pressure head, and update
pressure head (Eq.5.29). Go to step 3, and continue looping, and record
iteration numbers.
8) Accept the values of pressure head, and increase the simulation time, and
check whether it reaches any sampling time to show the results. Check the
iteration numbers for possible changes of the time step (Eq.5.33, Eq.5.34,
and Eq.35).
9) End the calculation when the maximum sampling time has been exceeded.

5.4. Computer Program

The complete computer program is listed Appendix E, and is saved in file


WFUSIM1.XLS. As shown in Fig.7, DATA SHEET and FORM SHEET have

23 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
similar contents except cells for Tolerance, Error and Iteration are active now.
Tolerance must be inputted but Error and Iteration will de display automatically at
each sampling time, or the related Check-Box can be filled to monitor the
calculation progress.

With similar initial and boundary conditions as previously calculated by WFUSEX1,


the Counter recorded only 9670 numbers of calculation cycles. However, it took
longer computational time due to the iteration processes. The time step fluctuated
and reached a thousand time higher than the original time step (0.002 s), and finally
reached 0.136 s. The time step reduced significantly when gradients of pressure
head became higher because of the negative effect of Dirichlet boundary condition.
The calculation however must be stopped before this effect appears because it is
also unnatural.

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.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 24


B.I. Setiawan, U.Ilstedt & A.Malmer

Figure 4. Appearance of worksheet for WFUSIM1.XLS

Figure 5. Pressure head and equivalent depth of water when applying WFUSIM1.

25 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

6. Comparison: Explicit and Implicit Schemes

Figure 9 shows comparisons of equivalent depth of water and pressure head


profiles between the Explicit and Impicit schemes. In the early calculation, the
Explicit scheme produced less equivalent depth of water but at the later times larger
than that of the Implicit scheme. The correlation coeffient fluctuated with time and
reached higher values in the middle of sampling times. The highest correlation at
1800 s is not a surprise since the soil is relatively saturated except at the elements
close to the bottom of the soil.

Figure 6. Comparison between the results of WFUSEX1 and WFUSIM1.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 26


B.I. Setiawan, U.Ilstedt & A.Malmer

7. Implicit Scheme: Dirichlet and Neumann Boundary Conditions

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 (0, t ) = h0 → 0 < t < ∞ ......................................................................................... (7.1)

q (Z , t ) = q Z → 0 < t < ∞ ...................................................................................... (7.2)

The governing equation is written in the form:

∂h ∂q
C = − + s( z, t ) .............................................................................................. (7.3)
∂t ∂z

The gradient of water flux in form of finite different equation is:

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

Inserting Eq.7.5 and Eq.7.6 to Eq.5.5 for j=n will give:

ent + ∆t = a nt + ∆t / 2 ⋅ hnt +−1∆t + bnt + ∆t / 2 ⋅ h tj+ ∆t + cnt + ∆t / 2 ⋅ h tj++1∆t + d nt + ∆t ........................... (7.7)

Where,

k nt + ∆t / 2 ∆t
ant + ∆t / 2 = ⋅ t + ∆t / 2 ......................................................................................... (7.8)
∆z 2
Cn

27 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

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

The computer program is listed in Appendix F, and saved in file WFUSIM2.XLS.


There is only minor modifications in Rem 9) for the water balance equations, and
because the pressure head at the bottom must be found then the element now
includes j=Nz.

Figure 10 shows the appearance of WFUSIM2. There is q(Z,t) that must be


inputted instead of h(Z,t) in the DATA SHEET. As also shown in Fig.11, pressure
head at the bottom is now allowed to change ehen the wetting front approached it.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 28


B.I. Setiawan, U.Ilstedt & A.Malmer

Figure 7. Appearance of worksheet for WFUSIM2.

Figure 8. Pressure head and equivalent depth of water when applying WFUSIM2

29 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

8. Implicit Scheme: Neumann Boundary Conditions

In this section, the implicit scheme is subjected to Neumann BCs both on the soil
surface and at the bottom of the soil column:

q(0, t ) = q0 → 0 < t < ∞ .......................................................................................... (8.1)

q(Z , t ) = qZ → 0 < t < ∞ ....................................................................................... (8.2)

The governing equation is written in the form of:

∂h ∂q
C = − + s( z, t ) .............................................................................................. (8.3)
∂t ∂z

The gradient of water flux in finite difference equation is:

∂q q −q 
= − 1 0  + s ( z, t ) ....................................................................................... (8.4)
∂z  ∆z 

Where,

 h − h 
q1 = − k1  1 0 − 1  .......................................................................................... (8.5)
  ∆z 

Inserting Eq.8.4 and Eq.8.5 to Eq.5.5 for j=0 gives:

e0t + ∆t = a0t + ∆t / 2 ⋅ h−t +1 ∆t + b0t + ∆t / 2 ⋅ h0t + ∆t + c0t + ∆t / 2 ⋅ h1t + ∆t + d0t + ∆t ...... (8.6)

Where,

a0t + ∆t / 2 = 0 .................................................................................................................... (8.7)

k1t + ∆t / 2 ∆t
b0t + ∆t / 2 =− ⋅ + 1 ................................................................... (8.8)
∆z 2 C 0t + ∆t / 2

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 30


B.I. Setiawan, U.Ilstedt & A.Malmer

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

The computer program is listed in Appendix G, and is saved in file


WFUSIM3.XLS. A minor modification is seen in Rem 9) for the water balance
equations, and since pressure had on the soil surface must be found then the
calculation is carried out also at j=0.

Figure 12 shows the appearance of worksheet of WFUSIM3. There is q(0,t) in the


DATA SHEET instead of h(0,t). The value of saturated conductivity is given to
q(0,t). As also shown in Fig.13 the pressure head on the soil surface changes with
time and then approaches saturation.

31 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

Figure 9. Appearance of worksheet for WFUSIM3.

Figure 10. Pressure head and equivalent depth of water when applying WFUSIM3.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 32


B.I. Setiawan, U.Ilstedt & A.Malmer

9. Implicit Scheme: Neumann and Cauchy Boundary Conditions

In this section, the implicit scheme is subjected to Neumann boundary condition


on the soil surface and Cauchy boundary condition at the bottom of the soil
column.

q(0, t ) = q0 → 0 < t < ∞ .......................................................................................... (9.1)

q(Z , t ) = qSP → 0 < t < ∞ ....................................................................................... (9.2)

Where,

 h − hn 
qSP = − SP  .................................................................................................... (9.3)
 CSP 

T
C SP = SP ............................................................................................................... (9.4)
K SP

The gradient of water flux in finite difference equation is:

∂q  q − qn 
= − SP  + s( z, t ) .................................................................................... (9.5)
∂z  ∆z 

Where,

  h − hn −1  
qn = −  k n  n − 1  ...................................................................................... (9.6)
  ∆z 

Inserting Eq.9.4 and Eq.9.5 to Eq.5.5 for j=n gives:

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,

33 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
t + ∆t / 2
k ∆t
a0t + ∆t / 2 = n
⋅ t + ∆t / 2
......................................................................................... (9.8)
∆z C n

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

The complete program is listed in Appendix H, and is saved in file WFUSIM4.XLS.


A minor modification can bee seen in Rem 9) for the water balance equations. The
calculation is carried out from j=0 to j=Nz.

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.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 34


B.I. Setiawan, U.Ilstedt & A.Malmer

Figure 11. Appearance of worksheet for WFUSIM4.

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

Askari, M. 2006. Studies on infiltration in Various Tropical Soil Textures. Master


Thesis. Graduate School of Bogor Agricultural University. Bogor, Indonesia.

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.

Hermantoro, 2003. Effectiveness of Pitcher Fertigation System. Case Studies on


Bush Peppers. Dissertation. Graduate School of Bogor Agricultural
University. Bogor, Indonesia.

Hillel, D. 1998. Environmental Soil Physics. Academic Press. Amsterdam.

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.

Setiawan, B.I., Hermantoro, and Rudiyanto. 2006. Effectiveness of pitcher


fertigation on bush pepper plants. Proceeding of 7th international micro
irrigation congress. Kuala Lumpur, 10-16 September 2006.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 36


B.I. Setiawan, U.Ilstedt & A.Malmer

Appendix A: Microsoft Visual Basic Editor

Worksheet in Microsoft Excel has becomes a common software to store data,


performing calculation in a cell with inputs from one or more cells, making various
type of charts, etc. Performing calculation in a cell can be done directly by typing an
equation in one line. It is practical and straightforward when the equation is simple.
But, it becomes uneasy to type the equation in only one line when the equation is
long, such as involving many operators, brackets, etc. The equation itself becomes
difficult to read even by the programmer him/herself, is not stored permanently in
the library of Excel and accordingly when it is accidentally deleted the programmer
should rewrite from the beginning again.

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.

From an active worksheet, Visual Basic Editor can be opened by Clicking:


Tools>Macro>Visual Basic Editor, such as shown in the Fig.A.1.

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.

Modules should be inserted as a new directory. This can be done by clicking:


Insert>Module, such as shown in Fig.A.3.

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.

Rem Genuchten model for water retention curve


Function WRC(TheS, TheR, Alpha, n, m1, hx)
X = (1 + (Alpha * Abs(hx)) ^ n) ^ m1
WRC = TheR + (TheS - TheR) / X

37 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
End Function

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 button OK is clicked then it will appear a new window of Function


Arguments (Fig.A.7). This window has 6 TextBox, one for each input of the
Function WRC. These inputs can be inserted to test the function. In example,
TheS=0.4, TheR=0.02, Alpha=0.04, N=6.78, M1=0.13 and hx=-100, the result is
shown under the last input and in the lower part, Formula result=0.131975561.

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.

Fig.A.8 shows an example to use Function WRC to calculate volumetric wetness, θ,


from pressure head. In the active Sheet1, there are parameters of Genuchten model
and 20 data of pressure head, h. The Function WRC is assigned to cell C10 with
inputs from cells B2:B6 for the parameters of water retention, and cell B10 for
pressure head. The following calculated volumetric wetness is obtained with ‘copy
and paste’ from cell C10.

Another option to use Function WRC is to call it by other procedures (Function


and/or Sub). The following example is to use a procedure Sub WRC2:

1) Read parameters of water retention from cells B2:B6.


2) Read data of pressure head from B10:B29.
3) Calculate volumetric wetness.
4) Display the results in cells D10:D29.

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

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 38


B.I. Setiawan, U.Ilstedt & A.Malmer
w(nj) to store data of volumetric wetness, and other variables to store the
parameters of water retention curve.

To execute or RUN the Sub WRC2, a CommandButton11 is placed in the active


worksheet. To write an executing program, in the Design Mode, the
CommandButton1 is double-clicked, and it will appear a procedure Private Sub
CommandButton1_Click() follows with Ed Sub in Microsoft Visual Basic. In
between of these two statements, the Sub WRC2 is called. The result is such as
follows:

Private Sub CommandButton1_Click()


Module1.WRC2
End Sub

This computer program is stores in sub-directory Sheet1(Sheet1) under the


directory of Microsoft Excel Objects. Now, if the Control ToolBox is in Exit
Design Mode, clicking the CommandButton1 will execute Module1.WRC2. The
result is that other data of volumetric wetness will be displayed in cells D10:D29,
such as shown in Fig.A.10.

Rem Definition of variables and arrays


Const nj As Integer = 20
Dim h(nj), w(nj), TheS, TheR, Alpha, n, m1

Rem Genuchten model for water retention curve


Function WRC(TheS, TheR, Alpha, n, m1, hx)
X = (1 + (Alpha * Abs(hx)) ^ n) ^ m1
WRC = TheR + (TheS - TheR) / X
End Function

Rem procedure to read data, calculate and display w


Sub WRC2()
Rem 1) Read parameters
TheS = Cells(2, 2)
TheR = Cells(3, 2)
Alpha = Cells(4, 2)
n = Cells(5, 2)
m1 = Cells(6, 2)
Rem 2) Read data of pressure head
For j = 1 To nj
h(j) = Cells(9 + j, 2)

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

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 40


B.I. Setiawan, U.Ilstedt & A.Malmer

A. 1 Open Visual Basic Editor from an active Worksheet.

A. 2 Microsoft Visual Basic Editor

41 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

A. 3 To create a new directory for Modules

A. 4 Sub-directory Module1 has been created and a space to write computer


programs has been prepared.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 42


B.I. Setiawan, U.Ilstedt & A.Malmer

A. 5 A function is written in the Microsoft Visual Basic, stored in Module1, and


save in a file named MVBExample

A. 6 Function WRC is in the User Defined category in the file MVBExample

43 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

A. 7 Window of Function Arguments to test the Function WRC for the given
values of inputs/arguments.

A. 8 Using Function WRC to calculate volumetric wetness from data of pressure


head in an active worksheet.

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 44


B.I. Setiawan, U.Ilstedt & A.Malmer

A. 9 Procedure Sub WRC2 to call Function WRC to calculate and display


volumetric wetness in an active workseet.

A. 10 Calculated volumetric wetness using Function WRC and Sub WRC2.

45 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Appendix B: Solver in Microsoft Excel

Solver in Microsoft Excel is a valuable tool especially to find fitted parameters of a


mathematical model. In example here, in finding the parameters θs, θr, α, n and m
of Genuchten model (Eq.3.1) when there is a pair of data of pressure head, h, and
volumetric wetness, θ, such as shown in Fig.B.1.

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.

The window of the Solver Parameters is opened by clicking: Tools>Solver2. The


purpose of using this solver is to find an optimum combination of the parameters
that produces minimum error. Then, Cell C30 is inserted in Set Target Cell, and
Equal To is set to Min. Whilst, Cells B2:B6 are inserted into By Changing Cells.
This setting is sufficient to be executed, and it is done by clicking Solve button.

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. 1. Solver to find fitted parameters of Genuchten model from a pair of data of


pressure head and volumetric wetness

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.

47 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Appendix C: Source Codes of Hydraulic Properties

Rem Hydraulic Properties functions

Rem 1) water retention


Function WRC(TheS, TheR, Alpha, n, m1, hx)
X = (1 + (Alpha * Abs(hx)) ^ n) ^ m1
WRC = TheR + (TheS - TheR) / X
End Function

Rem 2) specific water capacity


Function SWC(TheS, TheR, Alpha, n, m1, hx)
X = Alpha * n * m1 * (Alpha * Abs(hx)) ^ (n - 1)
Y = (1 + (Alpha * Abs(hx)) ^ n) ^ (m1 + 1)
SWC = Abs(-X / Y)
If SWC < 0.00001 Then SWC = 0.00001
End Function

Rem 3) saturation degree


Function SAT(TheS, TheR, wx)
SAT = (wx - TheR) / (TheS - TheR)
End Function

Rem 4) hydraulic conductivity


Function HCC(TheS, TheR, Ks, m2, wx)
Se = SAT(TheS, TheR, wx)
HCC = Ks * Se ^ 0.5 * (1 - (1 - Se ^ (1 / m2)) ^ m2) ^ 2
End Function

Rem 5)inverse of WRC


Function WRCi(TheS, TheR, Alpha, n, m1, wx)
Se = SAT(TheS, TheR, wx)
If Se < 0.00001 Then Se = 0.00001
WRCi = 1 / Alpha * ((1 / Se) ^ (1 / m1) - 1) ^ (1 / n)
End Function

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 48


B.I. Setiawan, U.Ilstedt & A.Malmer

Appendix D: Source Codes of WFUSEX1

Rem Water Flow in Unsaturated Soil with Explicit scheme (WFUSEX1)


Rem Dirichlet Boundary Conditions
Rem Budi I. Setiawan, Ulrik Ilstedt and Anders Malmer
Rem Bogor Agricultural University, Bogor 16680, Indonesia
Rem Swedish University of Agricultural Sciences, Umeå, Sweden
Rem budindra@ipb.ac.id, http://ipb.ac.id/~budindra
Rem ulrik.ilstedt@sek.slu.se, and anders.malmer@sek.slu.se

Rem Definitions of constants and variables


Const mz As Integer = 50
Const mt As Integer = 10
Dim TheS, TheR, Alpha, n, m1, Ks, m2, Dw, De, hT0, hZ0, hZn
Dim Zn, Nz, Lamda, Nt, dZ, dT, t, counter
Dim z(mz), h(mz), ht(mz), w(mz), k(mz), c(mz), s(mz), Ts(mt)
Dim TotalTime, Finish, Start, Flag1, Flag2

Rem 1) Read from DataSheet


Sub ReadData()
Rem a) soil depth, number of elements and spatial increment
Zn = Cells(4, 2)
Nz = Cells(5, 2)
dZ = Zn / Nz:
Cells(6, 2) = dZ
Rem b) Water retention parameters
TheS = Cells(8, 2)
TheR = Cells(9, 2)
Alpha = Cells(10, 2)
n = Cells(11, 2)
m1 = Cells(12, 2)
Rem c) Hydraulic conductivity parameters
Ks = Cells(14, 2)
m2 = Cells(15, 2)
Rem d) Initial and boundary values
hT0 = Cells(17, 2)
hZ0 = Cells(18, 2)
hZn = Cells(19, 2)
Rem e) calculate time step
Lamda = Cells(21, 2)
Dw = Ks / SWC(TheS, TheR, Alpha, n, m1, 0)
dT = (Lamda * dZ * dZ) / Dw:
Cells(22, 2) = dT

49 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Nt = Cells(23, 2)
Rem f) assign values z(j), s(j), and for h(j) at t=0
For j = 0 To Nz
z(j) = j * dZ
s(j) = 0
h(j) = hT0
Next j
End Sub

Rem 2) create a form to insert data and display results


Sub FormSheet()
Cells(2, 5) = "FORM SHEET"
Cells(3, 5) = "Time Series"
Cells(4, 5) = "Sampling Times (s)"
Cells(5, 5) = "Equivalent Depth (cmH2O)"
For i = 0 To Nt
Cells(3, 8 + i) = i
Cells(4, 8 + i) = i
Cells(5, 8 + i) = 0
Next
Cells(6, 5) = "j"
Cells(6, 6) = "z (cm)"
Cells(6, 7) = "s (1/s)"
Cells(6, 8) = "h (cmH2O)"
For j = 0 To Nz
Cells(7 + j, 5) = j
Cells(7 + j, 6) = z(j)
Cells(7 + j, 7) = s(j)
Cells(7 + j, 8) = h(j)
Next j
End Sub

Rem 3)read data from the FormSheet


Sub ReadForm()
Rem read sampling times
For i = 0 To Nt
Ts(i) = Cells(4, 8 + i)
Next i
Rem read sources/sink and intial condition
For j = 0 To Nz
s(j) = Cells(7 + j, 7)
h(j) = Cells(7 + j, 8)
Next j
Rem calculate equivalent depth of water
De = 0

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 50


B.I. Setiawan, U.Ilstedt & A.Malmer
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
De = De + w(j) * dZ
Next j
Cells(5, 8) = De
Rem read boundary conditions
hZ0 = Cells(18, 2)
hZn = Cells(19, 2)
h(0) = hZ0
h(Nz) = hZn
End Sub

Rem 4) display resuts in the FormSheet


Sub DisplayResults(i)
Finish = Timer
TotalTime = Finish - Start
Cells(27, 2) = counter - 1
Cells(28, 2) = t
Cells(29, 2) = TotalTime
Cells(5, 8 + i) = De
For j = 0 To Nz
Cells(7 + j, 8 + i) = h(j)
Next j
If i = Nt Then Msg = "COMPLETED": Response = MsgBox(Msg, Style, Title,
Help, Ctxt)
End Sub

Rem 5) clear FormSheet fromthe last calculated values


Sub ClearValues()
For i = 1 To Nt
Cells(5, 8 + i) = ""
For j = 0 To Nz
Cells(7 + j, 8 + i) = ""
Next j
Next i
Cells(22, 2) = ""
Cells(25, 2) = ""
Cells(26, 2) = ""
Cells(27, 2) = ""
Cells(28, 2) = ""
Cells(29, 2) = ""
End Sub

51 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

Rem 6) create Sheet for DataEntry


Sub DataEntrySheet()
Cells(2, 1) = "DATA SHEET"
Cells(3, 1) = "Soil Dimension)"
Cells(4, 1) = "Zn"
Cells(5, 1) = "Nz"
Cells(6, 1) = "dZ"
Cells(7, 1) = "Water Retention"
Cells(8, 1) = "Ws"
Cells(9, 1) = "Wr"
Cells(10, 1) = "Alpha"
Cells(11, 1) = "n"
Cells(12, 1) = "m1"
Cells(13, 1) = "Hydraulic Conductivity"
Cells(14, 1) = "Ks"
Cells(15, 1) = "m2"
Cells(16, 1) = "Initial & Boundary"
Cells(17, 1) = "h(z,0)"
Cells(18, 1) = "h(0,t)"
Cells(19, 1) = "h(Z,t)"
Cells(20, 1) = "Time Constants"
Cells(21, 1) = "Lamda"
Cells(22, 1) = "dT"
Cells(23, 1) = "Nt"
Cells(24, 1) = "Tolerance"
Cells(25, 1) = "Error"
Cells(26, 1) = "Iteration"
Cells(27, 1) = "Counter"
Cells(28, 1) = "SimTime"
Cells(29, 1) = "ComTime"
End Sub

Rem 7) known values of w, k, c and De at t


Sub KnownValues()
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
k(j) = HCC(TheS, TheR, Ks, m2, w(j))
c(j) = SWC(TheS, TheR, Alpha, n, m1, h(j))
De = De + w(j) * dZ
Next j
End Sub

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 52


B.I. Setiawan, U.Ilstedt & A.Malmer

Rem 8) new values of h(j) or ht(j) at t+dt


Sub NewValues()
dZ1 = 2 * dZ
dZ2 = dZ * dZ
For j = 1 To Nz - 1
Bi = k(j) / dZ2
Ci = dT / c(j)
Di = (k(j + 1) - k(j - 1)) / dZ1
Aj = (Bi - Di / dZ1) * Ci
Bj = (1 - 2 * Bi * Ci)
Cj = (Bi + Di / dZ1) * Ci
Dj = (s(j) - Di) * Ci
ht(j) = Aj * h(j - 1) + Bj * h(j) + Cj * h(j + 1) + Dj
Next j
End Sub

Rem 9) assign new values ht(j) to h(j)


Sub UpdateValues()
For j = 1 To Nz - 1
h(j) = ht(j)
Next j
End Sub

Rem 10) the main program


Sub MainPart()
If Sheet1.CheckBox1.Value = True Then Flag1 = 1 Else Flag1 = 0
If Sheet1.CheckBox2.Value = True Then Flag2 = 1 Else Flag2 = 0
Start = Timer
ReadForm
KnownValues
counter = 0
t=0
For i = 1 To Nt
Do
NewValues
UpdateValues
counter = counter + 1: If Flag1 = 1 Then Cells(27, 2) = counter
t = t + dT: If Flag2 = 1 Then Cells(28, 2) = t
KnownValues
Loop Until t >= Ts(i)
Call DisplayResults(i)
Next i
End Sub

53 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Appendix E: Source Codes of WFUSIM1

Rem Water Flow in Unsaturated Soil with Implicit scheme (WFUSIM1)


Rem Dirichlet Boundary Conditions
Rem Budi I. Setiawan, Ulrik Ilstedt and Anders Malmer
Rem Bogor Agricultural University, Bogor 16680, Indonesia
Rem Swedish University of Agricultural Sciences, Umeå, Sweden
Rem budindra@ipb.ac.id, http://ipb.ac.id/~budindra
Rem ulrik.ilstedt@sek.slu.se, and anders.malmer@sek.slu.se

Rem Definitions of constants and variables


Const mz As Integer = 50
Const mt As Integer = 10
Dim TheS, TheR, Alpha, n, m1, Ks, m2, Dw, De, hT0, hZ0, hZn
Dim Zn, Nz, Lamda, Nt, dZ, dT, t, counter
Dim z(mz), h(mz), ht(mz), w(mz), k(mz), kt(mz), co(mz), ct(mz), s(mz), Ts(mt)
Dim TotalTime, Finish, Start, Flag0, Flag1, Flag2, Flag3, Flag4, Flag5
Dim tol, error, It, Itmin, Itmax, dTi
Dim a(mz), b(mz), c(mz), d(mz)

Rem 1) Read from DataSheet


Sub ReadData()
Rem a) soil depth, number of elements and spatial increment
Zn = Cells(4, 2)
Nz = Cells(5, 2)
dZ = Zn / Nz:
Cells(6, 2) = dZ
Rem b) Water retention parameters
TheS = Cells(8, 2)
TheR = Cells(9, 2)
Alpha = Cells(10, 2)
n = Cells(11, 2)
m1 = Cells(12, 2)
Rem c) Hydraulic conductivity parameters
Ks = Cells(14, 2)
m2 = Cells(15, 2)
Rem d) Initial and boundary values
hT0 = Cells(17, 2)
hZ0 = Cells(18, 2)
hZn = Cells(19, 2)
Rem e) calculate time step
Lamda = Cells(21, 2)
Dw = Ks / SWC(TheS, TheR, Alpha, n, m1, h(0))
dTi = (Lamda * dZ * dZ) / Dw:
dT = dTi

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 54


B.I. Setiawan, U.Ilstedt & A.Malmer
Cells(22, 2) = dT
Nt = Cells(23, 2)
tol = Cells(24, 2)
Itmin = 5
Itmax = 25
Rem f) assign values z(j), s(j), and for h(j) at t=0
For j = 0 To Nz
z(j) = j * dZ
s(j) = 0
h(j) = hT0
ht(j) = h(j)
Next j
End Sub

Rem 2) create a form to insert data and display results


Sub FormSheet()
Cells(2, 5) = "FORM SHEET"
Cells(3, 5) = "Time Series"
Cells(4, 5) = "Sampling Times (s)"
Cells(5, 5) = "Equivalent Depth (cmH2O)"
For i = 0 To Nt
Cells(3, 8 + i) = i
Cells(4, 8 + i) = i
Cells(5, 8 + i) = 0
Next
Cells(6, 5) = "j"
Cells(6, 6) = "z (cm)"
Cells(6, 7) = "s (1/s)"
Cells(6, 8) = "h (cmH2O)"
For j = 0 To Nz
Cells(7 + j, 5) = j
Cells(7 + j, 6) = z(j)
Cells(7 + j, 7) = s(j)
Cells(7 + j, 8) = h(j)
Next j
End Sub

Rem 3) read data from the FormSheet


Sub ReadForm()
Rem read sampling times
For i = 0 To Nt
Ts(i) = Cells(4, 8 + i)
Next i
Rem read sources/sink and intial condition

55 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
For j = 0 To Nz
s(j) = Cells(7 + j, 7)
h(j) = Cells(7 + j, 8)
Next j
Rem calculate equivalent depth of water
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
De = De + w(j) * dZ
Next j
Cells(5, 8) = De
Rem read boundary conditions
hZ0 = Cells(18, 2)
hZn = Cells(19, 2)
h(0) = hZ0: ht(0) = h(0)
h(Nz) = hZn: ht(Nz) = h(Nz)
End Sub

Rem 4) display resuts in the FormSheet


Sub DisplayResults(i)
Finish = Timer
TotalTime = Finish - Start
Cells(22, 2) = dT
Cells(25, 2) = error
Cells(26, 2) = It
Cells(27, 2) = counter - 1
Cells(28, 2) = t
Cells(29, 2) = TotalTime
Cells(5, 8 + i) = De
For j = 0 To Nz
Cells(7 + j, 8 + i) = h(j)
Next j
If i = Nt Then Msg = "COMPLETED": Response = MsgBox(Msg, Style, Title,
Help, Ctxt)
End Sub

Rem 5) clear FormSheet fromthe last calculated values


Sub ClearValues()
For i = 1 To Nt
Cells(5, 8 + i) = ""
For j = 0 To Nz
Cells(7 + j, 8 + i) = ""
Next j

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 56


B.I. Setiawan, U.Ilstedt & A.Malmer
Next i
Cells(22, 2) = ""
Cells(25, 2) = ""
Cells(26, 2) = ""
Cells(27, 2) = ""
Cells(28, 2) = ""
Cells(29, 2) = ""
End Sub

Rem 6) create Sheet for DataEntry


Sub DataEntrySheet()
Cells(2, 1) = "DATA SHEET"
Cells(3, 1) = "Soil Dimension)"
Cells(4, 1) = "Zn"
Cells(5, 1) = "Nz"
Cells(6, 1) = "dZ"
Cells(7, 1) = "Water Retention"
Cells(8, 1) = "Ws"
Cells(9, 1) = "Wr"
Cells(10, 1) = "Alpha"
Cells(11, 1) = "n"
Cells(12, 1) = "m1"
Cells(13, 1) = "Hydraulic Conductivity"
Cells(14, 1) = "Ks"
Cells(15, 1) = "m2"
Cells(16, 1) = "Initial & Boundary"
Cells(17, 1) = "h(z,0)"
Cells(18, 1) = "h(0,t)"
Cells(19, 1) = "h(Z,t)"
Cells(20, 1) = "Time Constants"
Cells(21, 1) = "Lamda"
Cells(22, 1) = "dT"
Cells(23, 1) = "Nt"
Cells(24, 1) = "Tolerance"
Cells(25, 1) = "Error"
Cells(26, 1) = "Iteration"
Cells(27, 1) = "Counter"
Cells(28, 1) = "SimTime"
Cells(29, 1) = "ComTime"
End Sub

Rem 7) known values of w, k, c and De at t


Public Sub KnownValues()
De = 0

57 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
k(j) = HCC(TheS, TheR, Ks, m2, w(j))
co(j) = SWC(TheS, TheR, Alpha, n, m1, h(j))
De = De + w(j) * dZ
Next j
End Sub

Rem 8)intermediate values of w, k and c


Public Sub InterValues(j, hT0, ht1, ht2)
If j = 1 Then w0 = WRC(TheS, TheR, Alpha, n, m1, hT0): kt(0) = HCC(TheS,
TheR, Ks, m2, w0)
w1 = 0.5 * (WRC(TheS, TheR, Alpha, n, m1, hT0) + WRC(TheS, TheR, Alpha, n,
m1, ht1))
w1 = 0.5 * (w1 + w(j))
kt(j) = HCC(TheS, TheR, Ks, m2, w1)
w2 = 0.5 * (WRC(TheS, TheR, Alpha, n, m1, ht1) + WRC(TheS, TheR, Alpha, n,
m1, ht2))
w2 = 0.5 * (w2 + w(j + 1))
kt(j + 1) = HCC(TheS, TheR, Ks, m2, w2)
ct(j) = SWC(TheS, TheR, Alpha, n, m1, ht1)
ct(j) = 0.5 * (co(j) + ct(j))
End Sub

Rem 9) mass balance equations


Public Function WaterBalance(j, h1, hT0, ht1, ht2)
Call InterValues(j, hT0, ht1, ht2)
dZ1 = 2 * dZ
dZ2 = dZ * dZ
Bi = kt(j) / dZ2
Ci = dT / ct(j)
Di = (kt(j + 1) - kt(j - 1)) / dZ1
Aj = (Bi - Di / dZ1) * Ci
Bj = -(1 + 2 * Bi * Ci)
Cj = (Bi + Di / dZ1) * Ci
Dj = h1 + (s(j) - Di) * Ci
WaterBalance = Aj * hT0 + Bj * ht1 + Cj * ht2 + Dj
End Function

Rem 10) Jacobian matricex


Public Sub Jacobian()
error = 0
For j = 1 To Nz - 1

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 58


B.I. Setiawan, U.Ilstedt & A.Malmer
d(j) = WaterBalance(j, h(j), ht(j - 1), ht(j), ht(j + 1))
f1 = d(j)
Rem coefficient a(j)
dh = 0.001 * ht(j - 1): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1) + dh, ht(j), ht(j + 1))
a(j) = (f2 - f1) / dh
Rem coefficient b(j)
dh = 0.001 * ht(j): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1), ht(j) + dh, ht(j + 1))
b(j) = (f2 - f1) / dh
Rem coefficient c(j)
dh = 0.001 * ht(j + 1): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1), ht(j), ht(j + 1) + dh)
c(j) = (f2 - f1) / dh
error = error + Abs(d(j)) 'Sum of water balance errors
d(j) = -d(j) ' negate d(j) regarding to Newton Algorithm
Next j
End Sub

Rem 11) Thomas algorithm to solve tridiagonal matrices


Public Sub Thomas(mn, a, b, c, d)
b(1) = b(1)
c(1) = c(1) / b(1)
For l = 2 To (mn - 1)
b(l) = b(l) - a(l) * c(l - 1)
c(l) = c(l) / b(l)
Next l
b(mn) = b(mn) - a(mn) * c(mn - 1)
d(1) = d(1) / b(1)
For l = 2 To mn
d(l) = (d(l) - a(l) * d(l - 1)) / b(l)
Next l
d(mn) = d(mn)
For l = (mn - 1) To 1 Step -1
d(l) = d(l) - c(l) * d(l + 1)
Next l
End Sub

Rem 12) iteration to find new values of h(j)


Public Sub Iteration()
It = 0
Do
Jacobian
Call Thomas(Nz - 1, a, b, c, d)

59 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Rem update ht(j)
For j = 1 To Nz - 1
ht(j) = ht(j) + d(j)
Next j
It = It + 1
If Flag3 = 1 Then Cells(25, 2) = error
If Flag4 = 1 Then Cells(26, 2) = It
Loop Until error <= tol Or It > Itmax
End Sub

Rem 13) assign new values ht(j) to h(j)


Sub UpdateValues()
For j = 1 To Nz - 1
h(j) = ht(j)
Next j
t = t + dT
KnownValues
Flag0 = 0
End Sub

Rem 14) hold the last values of h(j)


Sub HoldValues()
For j = 1 To Nz - 1
ht(j) = h(j)
Next j
dT = 0.5 * dT: If dT < dTi Then dT = dTi
Flag0 = Flag0 + 1
If Flag0 > Itmax Then Msg = "FAILED": Response = MsgBox(Msg, Style, Title,
Help, Ctxt): End
End Sub

Rem 15) the main program


Sub MainPart()
If Sheet1.CheckBox1.Value = True Then Flag1 = 1 Else Flag1 = 0
If Sheet1.CheckBox2.Value = True Then Flag2 = 1 Else Flag2 = 0
If Sheet1.CheckBox3.Value = True Then Flag3 = 1 Else Flag3 = 0
If Sheet1.CheckBox4.Value = True Then Flag4 = 1 Else Flag4 = 0
If Sheet1.CheckBox5.Value = True Then Flag5 = 1 Else Flag5 = 0
Start = Timer
ReadForm
KnownValues
counter = 0
t=0
For i = 1 To Nt
Do

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 60


B.I. Setiawan, U.Ilstedt & A.Malmer
Iteration
If It <= Itmax Then UpdateValues Else HoldValues
If It < Itmin Then dT = dT + dTi
counter = counter + 1
If Flag1 = 1 Then Cells(27, 2) = counter
If Flag2 = 1 Then Cells(28, 2) = t
If Flag5 = 1 Then Cells(22, 2) = dT
Loop Until t >= Ts(i)
Call DisplayResults(i)
Next i
End Sub

61 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

Appendix F: Source Codes of WFUSIM2

Rem Water Flow in Unsaturated Soil with Implicit scheme (WFUSIM2)


Rem Dirichlet and Neumann Boundary Conditions
Rem Budi I. Setiawan, Ulrik Ilstedt and Anders Malmer
Rem Bogor Agricultural University, Bogor 16680, Indonesia
Rem Swedish University of Agricultural Sciences, Umeå, Sweden
Rem budindra@ipb.ac.id, http://ipb.ac.id/~budindra
Rem ulrik.ilstedt@sek.slu.se, and anders.malmer@sek.slu.se

Rem Definitions of constants and variables


Const mz As Integer = 50
Const mt As Integer = 10
Dim TheS, TheR, Alpha, n, m1, Ks, m2, Dw, De, hT0, hZ0, hZn, qZ
Dim Zn, Nz, h0, Lamda, Nt, dZ, dT, t, counter, ho, hzo
Dim z(mz), h(mz), ht(mz), w(mz), k(mz), kt(mz), co(mz), ct(mz), s(mz), ts(mt)
Dim TotalTime, Finish, Start, Flag0, Flag1, Flag2, Flag3, Flag4, Flag5
Dim tol, error, It, Itmin, Itmax, dTi
Dim a(mz), b(mz), c(mz), d(mz)
Dim mn

Rem 1) Read from DataSheet


Sub ReadData()
Rem a) soil depth, number of elements and spatial increment
Zn = Cells(4, 2)
Nz = Cells(5, 2)
dZ = Zn / Nz:
Cells(6, 2) = dZ
Rem b) Water retention parameters
TheS = Cells(8, 2)
TheR = Cells(9, 2)
Alpha = Cells(10, 2)
n = Cells(11, 2)
m1 = Cells(12, 2)
Rem c) Hydraulic conductivity parameters
Ks = Cells(14, 2)
m2 = Cells(15, 2)
Rem d) Initial and boundary values
hT0 = Cells(17, 2)
hZ0 = Cells(18, 2)
qZ = Cells(19, 2)
Rem e) calculate time step
Lamda = Cells(21, 2)
Dw = Ks / SWC(TheS, TheR, Alpha, n, m1, h(0))

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 62


B.I. Setiawan, U.Ilstedt & A.Malmer
dTi = (Lamda * dZ * dZ) / Dw
dT = dTi
Cells(22, 2) = dT
Nt = Cells(23, 2)
tol = Cells(24, 2)
Itmin = 5
Itmax = 25
Rem f) assign values z(j), s(j), and for h(j) at t=0
For j = 0 To Nz
z(j) = j * dZ
s(j) = 0
h(j) = hT0
Next j

End Sub

Rem 2) create a form to insert data and display results


Sub FormSheet()
Cells(2, 5) = "FORM SHEET"
Cells(3, 5) = "Time Series"
Cells(4, 5) = "Sampling Times (s)"
Cells(5, 5) = "Equivalent Depth (cmH2O)"
For i = 0 To Nt
Cells(3, 8 + i) = i
Cells(4, 8 + i) = i
Cells(5, 8 + i) = 0
Next
Cells(6, 5) = "j"
Cells(6, 6) = "z (cm)"
Cells(6, 7) = "s (1/s)"
Cells(6, 8) = "h (cmH2O)"
For j = 0 To Nz
Cells(7 + j, 5) = j
Cells(7 + j, 6) = z(j)
Cells(7 + j, 7) = s(j)
Cells(7 + j, 8) = h(j)
Next j
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
De = De + w(j) * dZ
Next j

63 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Cells(5, 8) = De
h(0) = hZ0
End Sub

Rem 3) read data from the FormSheet


Sub ReadForm()
Rem read sampling times
For i = 0 To Nt
ts(i) = Cells(4, 8 + i)
Next i
Rem read sources/sink and intial condition
For j = 0 To Nz
s(j) = Cells(7 + j, 7)
h(j) = Cells(7 + j, 8)
ht(j) = h(j)
Next j
Rem calculate equivalent depth of water
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
De = De + w(j) * dZ
Next j
Cells(5, 8) = De
Rem read boundary conditions
hZ0 = Cells(18, 2)
qZ = Cells(19, 2)
h(0) = hZ0: ht(0) = h(0)
'h(Nz) = hZn: ht(Nz) = h(Nz)
End Sub

Rem 4) display resuts in the FormSheet


Sub DisplayResults(i)
Finish = Timer
TotalTime = Finish - Start
Cells(22, 2) = dT
Cells(25, 2) = error
Cells(26, 2) = It
Cells(27, 2) = counter - 1
Cells(28, 2) = t
Cells(29, 2) = TotalTime
Cells(5, 8 + i) = De
For j = 0 To Nz
Cells(7 + j, 8 + i) = h(j)

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 64


B.I. Setiawan, U.Ilstedt & A.Malmer
Next j
If i = Nt Then Msg = "COMPLETED": Response = MsgBox(Msg, Style, Title,
Help, Ctxt)
End Sub

Rem 5) clear FormSheet fromthe last calculated values


Sub ClearValues()
For i = 1 To Nt
Cells(5, 8 + i) = ""
For j = 0 To Nz
Cells(7 + j, 8 + i) = ""
Next j
Next i
Cells(22, 2) = ""
Cells(25, 2) = ""
Cells(26, 2) = ""
Cells(27, 2) = ""
Cells(28, 2) = ""
Cells(29, 2) = ""
End Sub

Rem 6) create Sheet for DataEntry


Sub DataEntrySheet()
Cells(2, 1) = "DATA SHEET"
Cells(3, 1) = "Soil Dimension)"
Cells(4, 1) = "Zn"
Cells(5, 1) = "Nz"
Cells(6, 1) = "dZ"
Cells(7, 1) = "Water Retention"
Cells(8, 1) = "Ws"
Cells(9, 1) = "Wr"
Cells(10, 1) = "Alpha"
Cells(11, 1) = "n"
Cells(12, 1) = "m1"
Cells(13, 1) = "Hydraulic Conductivity"
Cells(14, 1) = "Ks"
Cells(15, 1) = "m2"
Cells(16, 1) = "Initial & Boundary"
Cells(17, 1) = "h(z,0)"
Cells(18, 1) = "h(0,t)"
Cells(19, 1) = "q(Z,t)"
Cells(20, 1) = "Time Constants"
Cells(21, 1) = "Lamda"
Cells(22, 1) = "dT"

65 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Cells(23, 1) = "Nt"
Cells(24, 1) = "Tolerance"
Cells(25, 1) = "Error"
Cells(26, 1) = "Iteration"
Cells(27, 1) = "Counter"
Cells(28, 1) = "SimTime"
Cells(29, 1) = "ComTime"
End Sub

Rem 7) known values of w, k, c and De at t


Public Sub KnownValues()
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
k(j) = HCC(TheS, TheR, Ks, m2, w(j))
co(j) = SWC(TheS, TheR, Alpha, n, m1, h(j))
De = De + w(j) * dZ
Next j
End Sub

Rem 8)intermediate values of w, k and c


Public Sub InterValues(j, hT0, ht1, ht2)
If j = 1 Then w0 = WRC(TheS, TheR, Alpha, n, m1, hT0): kt(0) = HCC(TheS,
TheR, Ks, m2, w0)
w1 = 0.5 * (WRC(TheS, TheR, Alpha, n, m1, hT0) + WRC(TheS, TheR, Alpha, n,
m1, ht1))
w1 = 0.5 * (w1 + w(j))
kt(j) = HCC(TheS, TheR, Ks, m2, w1)
w2 = 0.5 * (WRC(TheS, TheR, Alpha, n, m1, ht1) + WRC(TheS, TheR, Alpha, n,
m1, ht2))
w2 = 0.5 * (w2 + w(j + 1))
kt(j + 1) = HCC(TheS, TheR, Ks, m2, w2)
ct(j) = SWC(TheS, TheR, Alpha, n, m1, ht1)
ct(j) = 0.5 * (co(j) + ct(j))
End Sub

Rem 9) Mass balance equations


Public Function WaterBalance(j, h1, hT0, ht1, ht2)
Call InterValues(j, hT0, ht1, ht2)
dZ1 = 2 * dZ
dZ2 = dZ * dZ
Bi = kt(j) / dZ2
Ci = dT / ct(j)

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 66


B.I. Setiawan, U.Ilstedt & A.Malmer
Di = (kt(j + 1) - kt(j - 1)) / dZ1
Aj = (Bi - Di / dZ1) * Ci
Bj = -(1 + 2 * Bi * Ci)
Cj = (Bi + Di / dZ1) * Ci
Dj = h1 + (s(j) - Di) * Ci
If j = Nz Then Aj = Bi * Ci: Bj = -(Bi * Ci + 1): Cj = 0: Dj = h1 + (s(j) - (qZ -
k(Nz)) / dZ) * Ci
WaterBalance = Aj * hT0 + Bj * ht1 + Cj * ht2 + Dj
End Function

Rem 10) Jacobian matrices


Public Sub Jacobian()
error = 0
For j = 1 To Nz
d(j) = WaterBalance(j, h(j), ht(j - 1), ht(j), ht(j + 1))
f1 = d(j)
Rem coefficient a(j)
dh = 0.001 * ht(j - 1): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1) + dh, ht(j), ht(j + 1))
a(j) = (f2 - f1) / dh
Rem coefficient b(j)
dh = 0.001 * ht(j): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1), ht(j) + dh, ht(j + 1))
b(j) = (f2 - f1) / dh
Rem coefficient c(j)
dh = 0.001 * ht(j + 1): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1), ht(j), ht(j + 1) + dh)
c(j) = (f2 - f1) / dh
error = error + Abs(d(j)) 'Sum of water balance errors
d(j) = -d(j) ' negate d(j) regarding to Newton Algorithm
Next j
End Sub

Rem 11) Thomas algorithm to solve tridiagonal matrices


Public Sub Thomas(mn, a, b, c, d)
b(1) = b(1)
c(1) = c(1) / b(1)
For l = 2 To (mn - 1)
b(l) = b(l) - a(l) * c(l - 1)
c(l) = c(l) / b(l)
Next l
b(mn) = b(mn) - a(mn) * c(mn - 1)
d(1) = d(1) / b(1)
For l = 2 To mn

67 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
d(l) = (d(l) - a(l) * d(l - 1)) / b(l)
Next l
d(mn) = d(mn)
For l = (mn - 1) To 1 Step -1
d(l) = d(l) - c(l) * d(l + 1)
Next l
End Sub

Rem 12) iteration to find new values of h(j)


Public Sub Iteration()
It = 0
Do
Jacobian
mn = Nz
Call Thomas(mn, a, b, c, d)
Rem update ht(j)
For j = 1 To Nz
ht(j) = ht(j) + d(j)
Next j
It = It + 1
If Flag3 = 1 Then Cells(25, 2) = error
If Flag4 = 1 Then Cells(26, 2) = It
Loop Until error <= tol Or It > Itmax
End Sub

Rem 13) assign new values ht(j) to h(j)


Sub UpdateValues()
For j = 1 To Nz
h(j) = ht(j)
Next j
t = t + dT
KnownValues
Flag0 = 0
End Sub

Rem 14) hold the last values of h(j)


Sub HoldValues()
For j = 1 To Nz
ht(j) = h(j)
Next j
dT = 0.5 * dT: If dT < dTi Then dT = dTi
Flag0 = Flag0 + 1
If Flag0 > Itmax Then Msg = "FAILED": Response = MsgBox(Msg, Style, Title,
Help, Ctxt): End
End Sub

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 68


B.I. Setiawan, U.Ilstedt & A.Malmer

Rem 15) the main program


Sub MainPart()
If Sheet1.CheckBox1.Value = True Then Flag1 = 1 Else Flag1 = 0
If Sheet1.CheckBox2.Value = True Then Flag2 = 1 Else Flag2 = 0
If Sheet1.CheckBox3.Value = True Then Flag3 = 1 Else Flag3 = 0
If Sheet1.CheckBox4.Value = True Then Flag4 = 1 Else Flag4 = 0
If Sheet1.CheckBox5.Value = True Then Flag5 = 1 Else Flag5 = 0
Start = Timer
ReadForm
KnownValues
counter = 0
t=0
For i = 1 To Nt
Do
Iteration
If It <= Itmax Then UpdateValues Else HoldValues
If It < Itmin Then dT = dT + dTi
counter = counter + 1
If Flag1 = 1 Then Cells(27, 2) = counter
If Flag2 = 1 Then Cells(28, 2) = t
If Flag5 = 1 Then Cells(22, 2) = dT
Loop Until t >= ts(i)
Call DisplayResults(i)
Next i
End Sub

69 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Appendix G: Source Codes of WFUSIM3

Rem Water Flow in Unsaturated Soil with Implicit scheme (WFUSIM3)


Rem Neumann Boundary Conditions
Rem Budi I. Setiawan, Ulrik Ilstedt and Anders Malmer
Rem Bogor Agricultural University, Bogor 16680, Indonesia
Rem Swedish University of Agricultural Sciences, Umeå, Sweden
Rem budindra@ipb.ac.id, http://ipb.ac.id/~budindra
Rem ulrik.ilstedt@sek.slu.se, and anders.malmer@sek.slu.se

Rem Definitions of constants and variables


Const mz As Integer = 50
Const mt As Integer = 10
Dim TheS, TheR, Alpha, n, m1, Ks, m2, Dw, De, hT0, hZ0, hZn, qZ, q0
Dim Zn, Nz, h0, Lamda, Nt, dZ, dT, t, counter
Dim z(mz), h(mz), ht(-1 To mz), w(mz), k(mz), kt(-1 To mz), co(mz), ct(mz), s(mz),
ts(mt)
Dim TotalTime, Finish, Start, Flag0, Flag1, Flag2, Flag3, Flag4, Flag5
Dim tol, error, It, Itmin, Itmax, dTi
Dim a(mz), b(mz), c(mz), d(mz)
Dim mn

Rem 1) Read from DataSheet


Sub ReadData()
Rem a) soil depth, number of elements and spatial increment
Zn = Cells(4, 2)
Nz = Cells(5, 2)
dZ = Zn / Nz:
Cells(6, 2) = dZ
Rem b) Water retention parameters
TheS = Cells(8, 2)
TheR = Cells(9, 2)
Alpha = Cells(10, 2)
n = Cells(11, 2)
m1 = Cells(12, 2)
Rem c) Hydraulic conductivity parameters
Ks = Cells(14, 2)
m2 = Cells(15, 2)
Rem d) Initial and boundary values
hT0 = Cells(17, 2)
q0 = Cells(18, 2)
qZ = Cells(19, 2)
Rem e) calculate time step
Lamda = Cells(21, 2)
Dw = Ks / SWC(TheS, TheR, Alpha, n, m1, 0)

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 70


B.I. Setiawan, U.Ilstedt & A.Malmer
dTi = (Lamda * dZ * dZ) / Dw:
dT = dTi
Cells(22, 2) = dT
Nt = Cells(23, 2)
tol = Cells(24, 2)
Itmin = 5
Itmax = 25
Rem f) assign values z(j), s(j), and for h(j) at t=0
For j = 0 To Nz
z(j) = j * dZ
s(j) = 0
h(j) = hT0
ht(j) = h(j)
Next j
End Sub

Rem 2) create a form to insert data and display results


Sub FormSheet()
Cells(2, 5) = "FORM SHEET"
Cells(3, 5) = "Time Series"
Cells(4, 5) = "Sampling Times (s)"
Cells(5, 5) = "Equivalent Depth (cmH2O)"
For i = 0 To Nt
Cells(3, 8 + i) = i
Cells(4, 8 + i) = i
Cells(5, 8 + i) = 0
Next
Cells(6, 5) = "j"
Cells(6, 6) = "z (cm)"
Cells(6, 7) = "s (1/s)"
Cells(6, 8) = "h (cmH2O)"
For j = 0 To Nz
Cells(7 + j, 5) = j
Cells(7 + j, 6) = z(j)
Cells(7 + j, 7) = s(j)
Cells(7 + j, 8) = h(j)
Next j
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
De = De + w(j) * dZ
Next j

71 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Cells(5, 8) = De
End Sub

Rem 3) read data from the FormSheet


Sub ReadForm()
For i = 0 To Nt
ts(i) = Cells(4, 8 + i)
Next i
Rem read sources/sinks and initial condition
For j = 0 To Nz
s(j) = Cells(7 + j, 7)
h(j) = Cells(7 + j, 8)
ht(j) = h(j)
Next j
Rem calculate equivalent depth of water
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
De = De + w(j) * dZ
Next j
Cells(5, 8) = De
Rem read boundary condition
q0 = Cells(18, 2)
qZ = Cells(19, 2)
End Sub

Rem 4) display resuts in the FormSheet


Sub DisplayResults(i)
Finish = Timer
TotalTime = Finish - Start
Cells(22, 2) = dT
Cells(25, 2) = error
Cells(26, 2) = It
Cells(27, 2) = counter - 1
Cells(28, 2) = t
Cells(29, 2) = TotalTime
Cells(5, 8 + i) = De
For j = 0 To Nz
Cells(7 + j, 8 + i) = h(j)
Next j
If i = Nt Then Msg = "COMPLETED": Response = MsgBox(Msg, Style, Title,
Help, Ctxt)
End Sub

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 72


B.I. Setiawan, U.Ilstedt & A.Malmer

Rem 5) clear FormSheet fromthe last calculated values


Sub ClearValues()
For i = 1 To Nt
Cells(5, 8 + i) = ""
For j = 0 To Nz
Cells(7 + j, 8 + i) = ""
Next j
Next i
Cells(22, 2) = ""
Cells(25, 2) = ""
Cells(26, 2) = ""
Cells(27, 2) = ""
Cells(28, 2) = ""
Cells(29, 2) = ""
End Sub

Rem 6) create Sheet for DataEntry


Sub DataEntrySheet()
Cells(2, 1) = "DATA SHEET"
Cells(3, 1) = "Soil Dimension)"
Cells(4, 1) = "Zn"
Cells(5, 1) = "Nz"
Cells(6, 1) = "dZ"
Cells(7, 1) = "Water Retention"
Cells(8, 1) = "Ws"
Cells(9, 1) = "Wr"
Cells(10, 1) = "Alpha"
Cells(11, 1) = "n"
Cells(12, 1) = "m1"
Cells(13, 1) = "Hydraulic Conductivity"
Cells(14, 1) = "Ks"
Cells(15, 1) = "m2"
Cells(16, 1) = "Initial & Boundary"
Cells(17, 1) = "h(z,0)"
Cells(18, 1) = "q(0,t)"
Cells(19, 1) = "q(Z,t)"
Cells(20, 1) = "Time Constants"
Cells(21, 1) = "Lamda"
Cells(22, 1) = "dT"
Cells(23, 1) = "Nt"
Cells(24, 1) = "Tolerance"
Cells(25, 1) = "Error"
Cells(26, 1) = "Iteration"

73 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Cells(27, 1) = "Counter"
Cells(28, 1) = "SimTime"
Cells(29, 1) = "ComTime"
End Sub

Rem 7) known values of w, k, c and De at t


Public Sub KnownValues()
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
k(j) = HCC(TheS, TheR, Ks, m2, w(j))
co(j) = SWC(TheS, TheR, Alpha, n, m1, h(j))
De = De + w(j) * dZ
Next j
End Sub

Rem 8)intermediate values of w, k and c


Public Sub InterValues(j, hT0, ht1, ht2)
w1 = 0.5 * (WRC(TheS, TheR, Alpha, n, m1, hT0) + WRC(TheS, TheR, Alpha, n,
m1, ht1))
w1 = 0.5 * (w1 + w(j))
kt(j) = HCC(TheS, TheR, Ks, m2, w1)
w2 = 0.5 * (WRC(TheS, TheR, Alpha, n, m1, ht1) + WRC(TheS, TheR, Alpha, n,
m1, ht2))
w2 = 0.5 * (w2 + w(j + 1))
kt(j + 1) = HCC(TheS, TheR, Ks, m2, w2)
ct(j) = SWC(TheS, TheR, Alpha, n, m1, ht1)
ct(j) = 0.5 * (co(j) + ct(j))
If j = 1 Then w0 = WRC(TheS, TheR, Alpha, n, m1, hT0): kt(0) = HCC(TheS,
TheR, Ks, m2, w0)
End Sub

Rem 9) Mass balance equations


Public Function WaterBalance(j, h1, hT0, ht1, ht2)
Call InterValues(j, hT0, ht1, ht2)
dZ1 = 2 * dZ
dZ2 = dZ * dZ
Bi = kt(j) / dZ2
Ci = dT / ct(j)
Di = (kt(j + 1) - kt(j - 1)) / dZ1
Aj = (Bi - Di / dZ1) * Ci
Bj = -(1 + 2 * Bi * Ci)
Cj = (Bi + Di / dZ1) * Ci

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 74


B.I. Setiawan, U.Ilstedt & A.Malmer
Dj = h1 + (s(j) - Di) * Ci
If j = 0 Then Aj = 0: Bj = -Bi * Ci - 1: Cj = Bi * Ci: Dj = h1 + (s(j) - (k(1) - q0) /
dZ) * Ci
If j = Nz Then Aj = Bi * Ci: Bj = -Bi * Ci - 1: Cj = 0: Dj = h1 + (s(j) - (qZ - k(j)) /
dZ) * Ci
WaterBalance = Aj * hT0 + Bj * ht1 + Cj * ht2 + Dj
End Function

Rem 10) Jacobian matrices


Public Sub Jacobian()
error = 0
For j = 0 To Nz
d(j + 1) = WaterBalance(j, h(j), ht(j - 1), ht(j), ht(j + 1))
f1 = d(j + 1)
Rem coefficient a(j)
dh = 0.001 * ht(j - 1): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1) + dh, ht(j), ht(j + 1))
a(j + 1) = (f2 - f1) / dh
Rem coefficient b(j)
dh = 0.001 * ht(j): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1), ht(j) + dh, ht(j + 1))
b(j + 1) = (f2 - f1) / dh
Rem coefficient c(j)
dh = 0.001 * ht(j + 1): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1), ht(j), ht(j + 1) + dh)
c(j + 1) = (f2 - f1) / dh
error = error + Abs(d(j)) 'Sum of water balance errors
d(j + 1) = -d(j + 1) ' negate d(j) regarding to Newton Algorithm
Next j
End Sub

Rem 11) Thomas algorithm to solve tridiagonal matrices


Public Sub Thomas(mn, a, b, c, d)
b(1) = b(1)
c(1) = c(1) / b(1)
For l = 2 To (mn - 1)
b(l) = b(l) - a(l) * c(l - 1)
c(l) = c(l) / b(l)
Next l
b(mn) = b(mn) - a(mn) * c(mn - 1)
d(1) = d(1) / b(1)
For l = 2 To mn
d(l) = (d(l) - a(l) * d(l - 1)) / b(l)
Next l

75 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
d(mn) = d(mn)
For l = (mn - 1) To 1 Step -1
d(l) = d(l) - c(l) * d(l + 1)
Next l
End Sub

Rem 12) iteration to find new values of h(j)


Public Sub Iteration()
It = 0
Do
Jacobian
mn = Nz + 1
Call Thomas(mn, a, b, c, d)
Rem update ht(j)
For j = 0 To Nz
ht(j) = ht(j) + d(j + 1)
Next j
It = It + 1
If Flag3 = 1 Then Cells(25, 2) = error
If Flag4 = 1 Then Cells(26, 2) = It
Loop Until error <= tol Or It > Itmax
End Sub

Rem 13) assign new values ht(j) to h(j)


Sub UpdateValues()
For j = 0 To Nz
h(j) = ht(j)
Next j
t = t + dT
KnownValues
Flag0 = 0
End Sub

Rem 14) hold the last values of h(j)


Sub HoldValues()
For j = 0 To Nz
ht(j) = h(j)
Next j
dT = 0.5 * dT: If dT < dTi Then dT = dTi
Flag0 = Flag0 + 1
If Flag0 > Itmax Then Msg = "FAILED": Response = MsgBox(Msg, Style, Title,
Help, Ctxt): End
End Sub

Rem 15) the main program

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 76


B.I. Setiawan, U.Ilstedt & A.Malmer
Sub MainPart()
If Sheet1.CheckBox1.Value = True Then Flag1 = 1 Else Flag1 = 0
If Sheet1.CheckBox2.Value = True Then Flag2 = 1 Else Flag2 = 0
If Sheet1.CheckBox3.Value = True Then Flag3 = 1 Else Flag3 = 0
If Sheet1.CheckBox4.Value = True Then Flag4 = 1 Else Flag4 = 0
If Sheet1.CheckBox5.Value = True Then Flag5 = 1 Else Flag5 = 0
Start = Timer
ReadForm
KnownValues
counter = 0
t=0
For i = 1 To Nt
Do
Iteration
If It <= Itmax Then UpdateValues Else HoldValues
If It < Itmin Then dT = dT + dTi
counter = counter + 1
If Flag1 = 1 Then Cells(27, 2) = counter
If Flag2 = 1 Then Cells(28, 2) = t
If Flag5 = 1 Then Cells(22, 2) = dT
Loop Until t >= ts(i)
Call DisplayResults(i)
Next i
End Sub

77 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils

Appendix H: Source Codes of WFUSIM4

Rem Water Flow in Unsaturated Soil with Implicit scheme (WFUSIM4)


Rem Neumann and Cauchy Boundary Conditions
Rem Budi I. Setiawan, Ulrik Ilstedt and Anders Malmer
Rem Bogor Agricultural University, Bogor 16680, Indonesia
Rem Swedish University of Agricultural Sciences, Umeå, Sweden
Rem budindra@ipb.ac.id, http://ipb.ac.id/~budindra
Rem ulrik.ilstedt@sek.slu.se, and anders.malmer@sek.slu.se

Rem Definitions of constants and variables


Const mz As Integer = 50
Const mt As Integer = 10
Dim TheS, TheR, Alpha, n, m1, Ks, m2, Dw, De, hT0, hZ0, hZn, qZ, q0
Dim Zn, Nz, h0, Lamda, Nt, dZ, dT, t, counter
Dim z(mz), h(mz), ht(-1 To mz), w(mz), k(mz), kt(-1 To mz), co(mz), ct(mz), s(mz),
ts(mt)
Dim TotalTime, Finish, Start, Flag0, Flag1, Flag2, Flag3, Flag4, Flag5
Dim tol, error, It, Itmin, Itmax, dTi
Dim a(mz), b(mz), c(mz), d(mz)
Dim mn, Hsp, Ksp, Tsp, Csp, Qsp

Rem 1) Read from DataSheet


Sub ReadData()
Rem a) soil depth, number of elements and spatial increment
Zn = Cells(4, 2)
Nz = Cells(5, 2)
dZ = Zn / Nz:
Cells(6, 2) = dZ
Rem b) Water retention parameters
TheS = Cells(8, 2)
TheR = Cells(9, 2)
Alpha = Cells(10, 2)
n = Cells(11, 2)
m1 = Cells(12, 2)
Rem c) Hydraulic conductivity parameters
Ks = Cells(14, 2)
m2 = Cells(15, 2)
Rem d) Initial and boundary values
hT0 = Cells(17, 2)
q0 = Cells(18, 2)
qZ = Cells(19, 2)
Rem e) calculate time step
Lamda = Cells(21, 2)

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 78


B.I. Setiawan, U.Ilstedt & A.Malmer
Dw = Ks / SWC(TheS, TheR, Alpha, n, m1, 0)
dTi = (Lamda * dZ * dZ) / Dw:
dT = dTi
Cells(22, 2) = dT
Nt = Cells(23, 2)
tol = Cells(24, 2)
Itmin = 5
Itmax = 25
Rem f) assign values z(j), s(j), and for h(j) at t=0
For j = 0 To Nz
z(j) = j * dZ
s(j) = 0
h(j) = hT0
ht(j) = h(j)
Next j
Rem g) data from the semi-pervious layer
Tsp = Cells(31, 2)
Ksp = Cells(32, 2)
Hsp = Cells(33, 2)
Csp = Tsp / Ksp
End Sub

Rem 2) create a form to insert data and display results


Sub FormSheet()
Cells(2, 5) = "FORM SHEET"
Cells(3, 5) = "Time Series"
Cells(4, 5) = "Sampling Times (s)"
Cells(5, 5) = "Equivalent Depth (cmH2O)"
For i = 0 To Nt
Cells(3, 8 + i) = i
Cells(4, 8 + i) = i
Cells(5, 8 + i) = 0
Next
Cells(6, 5) = "j"
Cells(6, 6) = "z (cm)"
Cells(6, 7) = "s (1/s)"
Cells(6, 8) = "h (cmH2O)"
For j = 0 To Nz
Cells(7 + j, 5) = j
Cells(7 + j, 6) = z(j)
Cells(7 + j, 7) = s(j)
Cells(7 + j, 8) = h(j)
Next j
De = 0

79 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
De = De + w(j) * dZ
Next j
Cells(5, 8) = De
End Sub

Rem 3) read data from the FormSheet


Sub ReadForm()
For i = 0 To Nt
ts(i) = Cells(4, 8 + i)
Next i
Rem read sources/sinks and initial condition
For j = 0 To Nz
s(j) = Cells(7 + j, 7)
h(j) = Cells(7 + j, 8)
ht(j) = h(j)
Next j
Rem calculate equivalent depth of water
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
De = De + w(j) * dZ
Next j
Cells(5, 8) = De
Rem read boundary condition
q0 = Cells(18, 2)
qZ = Cells(19, 2)
End Sub

Rem 4) display resuts in the FormSheet


Sub DisplayResults(i)
Finish = Timer
TotalTime = Finish - Start
Qsp = -(Hsp - h(Nz)) / Csp
Cells(19, 2) = Qsp
Cells(22, 2) = dT
Cells(25, 2) = error
Cells(26, 2) = It
Cells(27, 2) = counter - 1
Cells(28, 2) = t

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 80


B.I. Setiawan, U.Ilstedt & A.Malmer
Cells(29, 2) = TotalTime
Cells(5, 8 + i) = De
For j = 0 To Nz
Cells(7 + j, 8 + i) = h(j)
Next j
If i = Nt Then Msg = "COMPLETED": Response = MsgBox(Msg, Style, Title,
Help, Ctxt)
End Sub

Rem 5) clear FormSheet fromthe last calculated values


Sub ClearValues()
For i = 1 To Nt
Cells(5, 8 + i) = ""
For j = 0 To Nz
Cells(7 + j, 8 + i) = ""
Next j
Next i
Cells(22, 2) = ""
Cells(25, 2) = ""
Cells(26, 2) = ""
Cells(27, 2) = ""
Cells(28, 2) = ""
Cells(29, 2) = ""
End Sub

Rem 6) create Sheet for DataEntry


Sub DataEntrySheet()
Cells(2, 1) = "DATA SHEET"
Cells(3, 1) = "Soil Dimension)"
Cells(4, 1) = "Zn"
Cells(5, 1) = "Nz"
Cells(6, 1) = "dZ"
Cells(7, 1) = "Water Retention"
Cells(8, 1) = "Ws"
Cells(9, 1) = "Wr"
Cells(10, 1) = "Alpha"
Cells(11, 1) = "n"
Cells(12, 1) = "m1"
Cells(13, 1) = "Hydraulic Conductivity"
Cells(14, 1) = "Ks"
Cells(15, 1) = "m2"
Cells(16, 1) = "Initial & Boundary"
Cells(17, 1) = "h(z,0)"
Cells(18, 1) = "q(0,t)"

81 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Cells(19, 1) = "q(Z,t)"
Cells(20, 1) = "Time Constants"
Cells(21, 1) = "Lamda"
Cells(22, 1) = "dT"
Cells(23, 1) = "Nt"
Cells(24, 1) = "Tolerance"
Cells(25, 1) = "Error"
Cells(26, 1) = "Iteration"
Cells(27, 1) = "Counter"
Cells(28, 1) = "SimTime"
Cells(29, 1) = "ComTime"
Cells(30, 1) = "Semi-pervious layer"
Cells(31, 1) = "Tsp"
Cells(32, 1) = "Ksp"
Cells(33, 1) = "Hsp"

End Sub

Rem 7) known values of w, k, c and De at t


Public Sub KnownValues()
De = 0
For j = 1 To Nz
w1 = WRC(TheS, TheR, Alpha, n, m1, h(j - 1))
w2 = WRC(TheS, TheR, Alpha, n, m1, h(j))
w(j) = 0.5 * (w1 + w2)
k(j) = HCC(TheS, TheR, Ks, m2, w(j))
co(j) = SWC(TheS, TheR, Alpha, n, m1, h(j))
De = De + w(j) * dZ
Next j
End Sub

Rem 8)intermediate values of w, k and c


Public Sub InterValues(j, hT0, ht1, ht2)
w1 = 0.5 * (WRC(TheS, TheR, Alpha, n, m1, hT0) + WRC(TheS, TheR, Alpha, n,
m1, ht1))
w1 = 0.5 * (w1 + w(j))
kt(j) = HCC(TheS, TheR, Ks, m2, w1)
w2 = 0.5 * (WRC(TheS, TheR, Alpha, n, m1, ht1) + WRC(TheS, TheR, Alpha, n,
m1, ht2))
w2 = 0.5 * (w2 + w(j + 1))
kt(j + 1) = HCC(TheS, TheR, Ks, m2, w2)
ct(j) = SWC(TheS, TheR, Alpha, n, m1, ht1)
ct(j) = 0.5 * (co(j) + ct(j))
If j = 1 Then w0 = WRC(TheS, TheR, Alpha, n, m1, hT0): kt(0) = HCC(TheS,
TheR, Ks, m2, w0)

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 82


B.I. Setiawan, U.Ilstedt & A.Malmer
End Sub

Rem 9) Mass balance equations


Public Function WaterBalance(j, h1, hT0, ht1, ht2)
Call InterValues(j, hT0, ht1, ht2)
dZ1 = 2 * dZ
dZ2 = dZ * dZ
Bi = kt(j) / dZ2
Ci = dT / ct(j)
Di = (kt(j + 1) - kt(j - 1)) / dZ1
Aj = (Bi - Di / dZ1) * Ci
Bj = -(1 + 2 * Bi * Ci)
Cj = (Bi + Di / dZ1) * Ci
Dj = h1 + (s(j) - Di) * Ci
If j = 0 Then Aj = 0: Bj = -Bi * Ci - 1: Cj = Bi * Ci: Dj = h1 + (s(j) - (k(1) - q0) /
dZ) * Ci
If j = Nz Then kdZ = k(j) / dZ: Aj = kdZ * Ci: Bj = -kdZ * Ci - 1 - 1 / Csp: Cj =
0: Dj = h1 + (s(j) + k(j) + Hsp / Csp) * Ci
WaterBalance = Aj * hT0 + Bj * ht1 + Cj * ht2 + Dj
End Function

Rem 10) Jacobian matrices


Public Sub Jacobian()
error = 0
For j = 0 To Nz
d(j + 1) = WaterBalance(j, h(j), ht(j - 1), ht(j), ht(j + 1))
f1 = d(j + 1)
Rem coefficient a(j)
dh = 0.001 * ht(j - 1): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1) + dh, ht(j), ht(j + 1))
a(j + 1) = (f2 - f1) / dh
Rem coefficient b(j)
dh = 0.001 * ht(j): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1), ht(j) + dh, ht(j + 1))
b(j + 1) = (f2 - f1) / dh
Rem coefficient c(j)
dh = 0.001 * ht(j + 1): If dh < 0.001 Then dh = 0.001
f2 = WaterBalance(j, h(j), ht(j - 1), ht(j), ht(j + 1) + dh)
c(j + 1) = (f2 - f1) / dh
error = error + Abs(d(j)) 'Sum of water balance errors
d(j + 1) = -d(j + 1) ' negate d(j) regarding to Newton Algorithm
Next j
End Sub

83 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Rem 11) Thomas algorithm to solve tridiagonal matrices
Public Sub Thomas(mn, a, b, c, d)
b(1) = b(1)
c(1) = c(1) / b(1)
For l = 2 To (mn - 1)
b(l) = b(l) - a(l) * c(l - 1)
c(l) = c(l) / b(l)
Next l
b(mn) = b(mn) - a(mn) * c(mn - 1)
d(1) = d(1) / b(1)
For l = 2 To mn
d(l) = (d(l) - a(l) * d(l - 1)) / b(l)
Next l
d(mn) = d(mn)
For l = (mn - 1) To 1 Step -1
d(l) = d(l) - c(l) * d(l + 1)
Next l
End Sub

Rem 12) iteration to find new values of h(j)


Public Sub Iteration()
It = 0
Do
Jacobian
mn = Nz + 1
Call Thomas(mn, a, b, c, d)
Rem update ht(j)
For j = 0 To Nz
ht(j) = ht(j) + d(j + 1)
Next j
It = It + 1
If Flag3 = 1 Then Cells(25, 2) = error
If Flag4 = 1 Then Cells(26, 2) = It
Loop Until error <= tol Or It > Itmax
End Sub

Rem 13) assign new values ht(j) to h(j)


Sub UpdateValues()
For j = 0 To Nz
h(j) = ht(j)
Next j
t = t + dT
KnownValues
Flag0 = 0
End Sub

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 84


B.I. Setiawan, U.Ilstedt & A.Malmer

Rem 14) hold the last values of h(j)


Sub HoldValues()
For j = 0 To Nz
ht(j) = h(j)
Next j
dT = 0.5 * dT: If dT < dTi Then dT = dTi
Flag0 = Flag0 + 1
If Flag0 > Itmax Then Msg = "FAILED": Response = MsgBox(Msg, Style, Title,
Help, Ctxt): End
End Sub

Rem 15) the main program


Sub MainPart()
If Sheet1.CheckBox1.Value = True Then Flag1 = 1 Else Flag1 = 0
If Sheet1.CheckBox2.Value = True Then Flag2 = 1 Else Flag2 = 0
If Sheet1.CheckBox3.Value = True Then Flag3 = 1 Else Flag3 = 0
If Sheet1.CheckBox4.Value = True Then Flag4 = 1 Else Flag4 = 0
If Sheet1.CheckBox5.Value = True Then Flag5 = 1 Else Flag5 = 0
Start = Timer
ReadForm
KnownValues
counter = 0
t=0
For i = 1 To Nt
Do
Iteration
If It <= Itmax Then UpdateValues Else HoldValues
If It < Itmin Then dT = dT + dTi
counter = counter + 1
If Flag1 = 1 Then Cells(27, 2) = counter
If Flag2 = 1 Then Cells(28, 2) = t
If Flag5 = 1 Then Cells(22, 2) = dT
Loop Until t >= ts(i)
Call DisplayResults(i)
Next i
End Sub

85 Erasmus Mundus Third Country Scholar Mobility Program, Nov.2006-Jan.2007


Numerical Solutions of Water Flow in Unsaturated Soils
Appendix I: Source Codes of Worksheet and Workbook

Rem Sheet1 to activate CommandButton 1, 2 , 3 and Image1


Private Sub CommandButton1_Click()
ReadData
FormSheet
Sheet1.CommandButton2.Enabled = True
Sheet1.CommandButton3.Enabled = True
End Sub
Private Sub CommandButton2_Click()
MainPart
End Sub
Private Sub CommandButton3_Click()
ClearValues
End Sub
Private Sub Image1_Click()
DataEntrySheet
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

Erasmus Mundus Third Country Scholar Mobility Program Nov.2006-Jan.2007 86

View publication stats

You might also like