master thesis francesco serafin

102
UNIVERSITY OF TRENTO Department of Civil,Environmental and Mechanical Engineering Master T hesis in Environmental and Land Engineering P atterns for the application of modern informatics to the integration of PDEs: the case of the Boussinesq Equation Advisor Author PhD Prof Riccardo Rigon Francesco Serafin Co-Advisor PhD Emanuele Cordano PhD Giuseppe Formetta Academic Year 2013 - 2014

Upload: riccardo-rigon

Post on 17-Mar-2018

2.134 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Master thesis Francesco Serafin

UNIVERSITY OF TRENTODepartment of Civil, Environmental and Mechanical

Engineering

Master Thesis in

Environmental and Land Engineering

Patterns for the application of modern informatics to the

integration of PDEs: the case of the Boussinesq Equation

Advisor Author

PhD Prof Riccardo Rigon Francesco Serafin

Co-Advisor

PhD Emanuele Cordano

PhD Giuseppe Formetta

Academic Year 2013 - 2014

Page 2: Master thesis Francesco Serafin
Page 3: Master thesis Francesco Serafin

C O N T E N T S

Introduction 1

1 setting up a modern environment for scientific com-puting 3

1.1 Before starting 3

1.1.1 Software engineering & UML 4

1.1.2 Version Control System 7

1.1.3 Integrated development environment 10

1.2 The advantages of Object-Oriented Programming 11

1.2.1 Object and Class 13

1.2.2 OOP features 13

1.3 Java as programming language for scientific computing 15

1.3.1 Java performance 17

1.4 The Object Modeling System 18

1.5 Lessons to take home 19

2 the boussinesq’s groundwater equation 21

2.1 The physical problem 21

2.1.1 Some definitions 21

2.1.2 The moisture distribution in a vertical profile 22

2.1.3 Phreatic aquifer and its properties 22

2.2 The Boussinesq equation 23

2.3 Mass conservative scheme for wetting and drying 24

2.3.1 Unstructured orthogonal grid 25

2.3.2 Spatial discretization 27

2.3.3 Time discretization 28

2.4 Boundary conditions 30

2.4.1 Flux-Based boundary conditions (Neumann) 30

2.4.2 Head-Based boundary conditions (Dirichlet) 31

2.5 Lesson to take home 32

3 software implementation 33

3.1 Object-oriented unstructured mesh 36

3.1.1 First design step: find different ways of implementa-tion 36

3.1.2 Second design step: class hierarchy 37

3.1.3 Third step: the implementation 38

3.2 Object-oriented differential equations 41

3.2.1 First design step: find different implementation ways 41

3.2.2 Second design step: class hierarchy 42

3.2.3 Third step: the implementation of the Boussinesq’sequation (BEq) 51

3.3 Input/output management 55

3.4 Conclusions 55

4 test case 57

4.1 Analytical Non-linear Solution with planar topography 57

4.1.1 Analytical non-linear one-dimensional Boussinesq Equa-tion 57

4.1.2 Comparison between analytical and numerical solu-tion 59

4.1.3 Nondimensionalization & maximum norm computa-tion 63

i

Page 4: Master thesis Francesco Serafin

Contents

4.2 Conclusions 65

5 summary 67

a the structure of the numerical solver utilized 69

b how to store sparse matrices 71

b.1 Triplet form 71

b.2 Compressed-row form 72

b.3 Matrix-vector multiplication 72

c about open source java matrices libraries - focusing

on parallel colt 75

d other comparisons between analytical and numeri-cal simulations 77

d.1 Simulations at 5 days 78

d.2 Simulations at 15 days 82

d.3 Simulations at 20 days 86

bibliography 91

ii

Page 5: Master thesis Francesco Serafin

L I S T O F S Y M B O L S

Other Symbols

Symbol Description Dimension Unit

θw Volumetric soil watercontent

[−] [−]

~Tj Transport coefficientalong the j-th edge

[L3 T−1] [m3/s]

~nj Outcoming versor or-thogonal to the j-th edge

[−] [−]

H Thickness of the aquifer [L] [m]

hw Total water volumestored in a soil columnper planimetric unit area

[L] [m]

hw Water volume per unitarea between the bedrockand the free surface level

[L3/L2] [m3/m2]

KS Saturated hydraulic con-ductivity

[L T−1] [m/s]

pi Planimetric area of thecell

[L2] [m2]

Q Source term per plani-metric unit area

[L T−1] [m/s]

Qni Water-table recharge (ora sink)

[L2 T−1] [m2/s]

qL Outgoing water flux (wa-ter discharge per unitvertical area) normal tothe boundary

[L T−1] [m/s]

s Drainable porosity [−] [−]

t Time [T ] [ s]

x, y Planimetric cartesian co-ordinates

[L] [m]

zb Bedrock elevation [L] [m]

zs Elevation of the terrainsurface

[L] [m]

Greek Symbols

Symbol Description Dimension Unit

δj Distance between thecenters of the i-th andrho(i, j)-th polygons

[L] [m]

iii

Page 6: Master thesis Francesco Serafin

List of Symbols

η Piezometric head [L] [m]

λj Length of the j-th edge [L] [m]

∇ · Divergence operator [L−1] [ /m]

~∇ Gradient operator [L−1] [ /m]

iv

Page 7: Master thesis Francesco Serafin

A C R O N Y M S

BC Boundary conditions

BEq Boussinesq’s equation

CG Conjugate Gradient

DC Dirichlet cells

DVCS Distributed Version Control System

EJML Efficient Java Matrix Library

EMF Environmental Modeling Framework

FDM Finite Difference Methods

FEM Finite Element Method

FVM Finite Volume Methods

GC Garbage Collector

GPL General Public License

ICC Incomplete Cholesky Decomposition

IDE Integrated Development Environment

ILU Incomplete LU factorization

ILUT Incomplete LU Transpose factorization

ISO International Organization for Standardization

JIT Just-in-time

JVM Java Virtual Machine

MMS Modular Modeling System

ODE Ordinary Differential Equation

OMS Object Modeling System

OOP Object Oriented Programming

PDE Partial Differential Equations

SWEq Shallow Water Equation

UJM Universal Java Matrix Package

UML Unified Modeling Language

VCS Version Control System

v

Page 8: Master thesis Francesco Serafin
Page 9: Master thesis Francesco Serafin

I N T R O D U C T I O N

Mathematical models play a fundamental role in many scientific and en-gineering fields in today’s world. They are used for example in geotechnicsto evalute the hillslope stability, in weather science to predict weather trendsand produce weather reports, in structural design to study the resistance tostress, and in fluid dynamics to compute fluid flows and air flows.

Consequently mathematical models are evolving all the time: more andmore new numerical methods are being invented to solve the Partial Dif-ferential Equations (PDE)s that describe physical problems with increasingprecision, and more and more complex and efficient processor units arebeing created to reduce the computational time.

Therefore, the code into which the mathematical models are translatedhas to be “dynamic” in order to be easily updated on the basis of the con-tinuous developments (Formetta et al. (2014) [16]).

On the other hand, completely different physical problems are often de-scribed using similar PDEs. For this reason, the numerical methods whichprovide solutions to different problems can be the same. This suggest theimplementation of an IT infrastructure that hosts a standard structure forsolving PDEs and that can serve various disciplines with the minimum ofhassles.

This work is focused on the application of what is envisioned above, withthe main purpose of the creation of an abstract code for implementing everytype of mathematical model described by PDEs.

We work on hydrological topics but we hope to design a structure ofgeneral interest. Obviously the final goal of any work of this type is to finda proper numerical solver, and therefore, part of the thesis is devoted to theanalysis of the problem under scrutiny, and the description of the solutionfound.

The thesis is organized as follows.In the first chapter an introduction to the software engineering and the

tools that improve the team work for programming development is done.These aspects are usually neglected in environmental engineers practice.However the acquisition and the application of these notions is deemed nec-essary to a collaborative and incremental work, where many people can addtheir brick of specific knowledge and exploit their work. Positive and neg-ative aspects of object oriented languages are shown, because OO program-ming is an important element that helps to obtain short, readable, robust,manageable and portable codes.

In the second chapter, the physical problem under analysis, the flow ofa phreatic table, is introduced: the model implemented is the Boussinesq’sgroundwater equation. This equation is central to describing problems likerunoff formation, soil moisture distribution, and the prevention from hill-slopes instability. There are many models that solve this equation, such asHarman and Sivapalan (2009) [22], Harbaugh et al. (2000) [21], Painter et al.(2008) [28]. The implemented model merges the achievements of Brugnanoand Casulli (2008) [3] and Casulli (2009) [5] and is further developed by Cor-dano and Rigon (2013) [10] to include any type of boundary conditions.

1

Page 10: Master thesis Francesco Serafin

It not only solves the BEq but also rigorously treats the “wetting-and-drying” problem with a clean, new numerical method. In fact it allowsfor a water table to dry up and form patchy spots of saturation without cre-ating any numerical problems, a characteristic considered very important inhillslope hydrology [24, 25].

The third chapter is the original contribution of this thesis. It contains theentire software engineering work that implements the general structure thatsolves PDEs, and in particular non linear parabolic ones, discretized throughan unstructured grid. In the same chapter it is discussed the application ofthe abstract structure to the solution of the BEq.

The fourth chapter shows a comparison between the numerical solutionand an analytical one, to verify the goodness of the model. This concludes acycle of software engineering in which first of all the software requirementswere delineated, then the system was subsequently designed, coded, andfinally tested. As developed, the cycle shows the peculiarities and the speci-ficities of the scientific problem under analysis, i.e. solving PDEs, and openstowards the final challenging phases of software engineering, the code main-tenance and debugging.

The thesis has four appendices.In Appendix A, the structure of the numerical solver utilized is analyzed

in depth.In Appendix B, the compressed format used to store matrices involved in

the computation is described. In addition, the algorithm used to computematrix-vector multiplication in row compressed format is shown.

In Appendix C, the Parallel Colt library used to implement the paral-lelized Conjugate Gradient is introduced.

In Appendix D, the graphs to compare analytical and numerical solutionnot used in Chapter 4 are attached.

Page 11: Master thesis Francesco Serafin

1S E T T I N G U P A M O D E R N E N V I R O N M E N T F O RS C I E N T I F I C C O M P U T I N G

Contents1.1 Before starting 3

1.1.1 Software engineering & UML 4

1.1.2 Version Control System 7

1.1.3 Integrated development environment 10

1.2 The advantages of Object-Oriented Programming 111.2.1 Object and Class 13

1.2.2 OOP features 13

1.3 Java as programming language for scientific computing 151.3.1 Java performance 17

1.4 The Object Modeling System 181.5 Lessons to take home 19

The main purpose of this thesis is to build of a new, complete, computingenvironment in which scientific models can be created. Programmers (andconsequently a scientific model developers) never work alone. The environ-ment is therefore conceived to facilitate the interactions of a working group.Various tools are essential for achieving this:

• to maximize efficiency of team work, Unified Modeling Language(UML) can be used to design a robust code which allows every pro-grammer to implement a subpart of the code;

• to bring together the various subparts, it is necessary to work on anopen remote repository via Version Control System (VCS);

• to develop a project working with VCS and UML while writing the code,an Integrated Development Environment (IDE) allows you to do every-thing with only one program;

• to realize a robust, maintainable and portable code, an object-orientedlanguage is necessary;

• the Object Modeling System (OMS) offers the possibility of integratingthis simple model with more complex ones, in order to solve inter-disciplinary problems without conflicting data, scales, methodologiesand input/output formats.

1.1 before starting

Before starting to analyze the features of the chosen programming lan-guage, it is necessary to address some practical aspects like software design,secure backup, sharing of parts of the code of the project via VCS and remoterepository. Moreover, there is a category of programs that make it possibleto manage all these aspects while working on a project with a single devel-opment environment. These programs are the IDEs, and a brief introductionto them will be made at the end of this section.

3

Page 12: Master thesis Francesco Serafin

setting up a modern environment for scientific computing

1.1.1 Software engineering & UML

Software engineering is probably the most important part of this work,because it is essential to the design of a complete code structure that willprovide a base project as a starting point to implement the scientific model.However, at the same time, this is the least visible part, because it cannot beidentified with a single block of work. Indeed, software engineering is de-sign, development, maintenance, testing and evaluation of the software [48].There is also a part concerning systems that make computers or anythingcontaining software operative, but it is outside this subject. Thus, softwareengineering is work done before, during and after the creation of the soft-ware.

The UML is a tool which can be used to apply these principles. It is a familyof graphical notations1, backed by single meta-model2, which is designed toprovide a standard mode for visualizing the design of a system built usingthe object-oriented style [50, 17]. It has been accepted by the InternationalOrganization for Standardization (ISO) as an approved ISO standard since2000.

It is a versatile tool, indeed as reported in Fowler (2004) [17] there arethree ways in which UML is used:

• Sketch: to assist in communicating some aspects of a system;

• Blueprint: forward-engineering (for drawing a UML diagram beforewriting code) and reverse-engineering (building a UML diagram fromexisting code in order to help understand it);

• Programming language: as more and more work is done in UML andthe programming gets increasingly mechanical, it becomes obviousthat the programming should be automated. Thus, there are tools thatallow developers to draw UML diagrams that are compiled directly toexecutable code, and the UML becomes the source code.

In this work, UML is used to improve the design of the code during its de-velopment. The main reason for this choice is my total lack of experience inObject Oriented Programming (OOP) and related tools. Good design beforestructuring the code entails a faster and more orderly drafting of the code.

UML2 describes 13 official types of diagram (see Figure 1), divided intotwo subgroups: the structure diagram and the behaviour diagram.

The kind of structure diagram used is the class diagram, it describes thetypes of objects in the system and the various types of static relationshipsbetween them, the properties and operations of a class, and the constraintsUML2: description

of the Class Diagram that apply to the way objects are connected [17]. Classes are represented byboxes divided in three parts:

• The top part contains the name of the class and the package wherethe class is located.

• The middle part contains attributes (fields) of the class.

• The bottom part contains the methods of the class.

1 The notation is the graphical syntax of the modelling language. In a class diagram, notationdefines how items and concepts, such as class, association, and multiplicity are represented.

2 The notation does not define every item and concept exactly, it is rather informal.Meta-modelimproves the rigour of the method, without sacrificing its usefulness in defining the conceptsof the language.

4

Page 13: Master thesis Francesco Serafin

1.1 before starting

UML Diagram

Structure Diagram

Class Diagram

Component Diagram

Composite Structure Diagram

Deployment Diagram

Object Diagram

Package Diagram

Behavior Diagram

Activity Diagram

Interaction Diagram

Sequence Diagram

Communication Diagram

Interaction Overview Diagram

Timing Diagram

State Machine Diagram

Use Case Diagram

Figure 1.: Classification of UML diagram types

A symbol precedes methods and fields of the class, to specify their visibility:

+ Public

- Private

# Protected

/ Derived

~ Package

There are also several symbols to represent the relationships betweenclasses or objects.

The main Class level relationship is the Generalization (inheritance or “isa” relationship): the subclass is considered to be a specialized form of thesuperclass, while the latter is considered a generalization of the former. TheUML graphical representation of a Generalization is a hollow triangle shapeon the superclass end of the line that connects it to one or more subclasses(see Figure 2).

The main Instance level relationships are:

• Association: represents basic relationships between objects and is drawnas a line.

5

Page 14: Master thesis Francesco Serafin

setting up a modern environment for scientific computing

• Aggregation: is a variant of the “has a” association relationship, andnormally occur when a class is a collection or container of other classes.In UML, it is graphically represented as a hollow diamond shape on thecontaining class end of the tree with a single line that connects the con-tained class to the containing class (Figure 2). The aggregate is seman-tically an extended object that is treated as a unit in many operations,although physically it is made up of several lesser objects [40].

Figure 2.: An example with a Class level and an Instance level relationships: Gener-alization is blue, while Aggregation is grey

The kind of behavior diagram used is the activity diagram, a technique todescribe procedural logic, business process and work flow. It is very similarUML2: description

of the ActivityDiagram

to a flowchart; the main difference is that it support parallel actions [17].The shapes used to create this type of diagram are (an example is shown inFigure 3):

• Arrows: represent the order in which activities happen.

• Rounded rectangles: represent actions; each action has a single flowcoming in and a single flow going out.

• Diamonds: represent decisions; it has a single incoming flow andseveral guarded out-bound flows. The guard of each outbound flow isa Boolean condition placed inside square brackets. Diamonds can alsorepresent a merge, i.e. the end of a conditional statement started by adecision. Each merge has multiple input flows and a single output.

• Bars: represent a fork or juncture of concurrent activities; each junc-ture has one incoming flow and several outgoing concurrent flows,

6

Page 15: Master thesis Francesco Serafin

1.1 before starting

and is the starting point of parallel activities. A juncture is used tosynchronize parallelism, thus the outgoing flow is taken only whenall the incoming flows reach the juncture.

• A black circle: represents the initial state of the workflow.

• An encircled black circle: represents the final state.

Figure 3.: An example of Activity Diagram

1.1.2 Version Control System

If software engineering allows the designing, development, maintainance,testing and evaluation of the code or the entire project, then version controlsystems VCS implement software engineering principles, especially usefulwhen working with other programmers. Version control is a system that What is a VCS?

records changes to a file or a set of files over time so that a specific versioncan be recalled at a later time. It makes it possible to revert files back to aprevious state, compare changes over time, see who last modified somethingthat might be causing a problem, who introduced an issue and when, andmore [7].

7

Page 16: Master thesis Francesco Serafin

setting up a modern environment for scientific computing

This is possible because changes are univocally identified by an alphanu-meric code (normally hexadecimal code), called the revision number.

Version control is very useful to developers that have to track and providecontrol over changes to source code and possibly over changes to documen-tation and configuration files. Exclusively focusing attention to debugginga code or a project, as part of the software engineering, can become gradu-ally more complex, and consequently it can also submit new bug to fix. Forthe purpose of locating and fixing bugs, it is very important to be able toretrieve and run different versions of the software to determine in whichversion(s) the problem occurs, and if necessary reconstruct the history ofthe bugs.

We can find three different types of version control:

• Local Version Control Systems. These are simple databases that keepall the changes to a file under revision control. These systems usuallywork by keeping patch sets, and not by keeping copies of the entirefile. For example, this is done also to track changes to configurationfiles, such as those typically stored in /etc or /usr/local/etc on Unixsystems [47]. Obviously, if the local machine breaks down, everythingwill be lost. This is the risk when the entire history of the project issaved in a single location.

• Centralized Version Control Systems. In software development it isnecessary to work as a team. This can be done with a server that con-tains all the versioned files, while several clients check out files fromthis central location. This kind of VCS facilitates teamwork. Further-more, every client can have a certain degree of access to what otherclients are doing on the project. The biggest flaw of this system comesto light when the central point goes into failure: if the server goesdown, nobody can work, or worse, if the hard disks of the server be-come corrupted, and proper backups have not been made, the entirehistory of the project is lost except for whatever single snapshots usershappen to have on their local machines [7].

• Distributed Version Control Systems. With this kind of system, everyclient repository fully mirrors the server repository. Thus if the serverdies, any of the client repositories can be copied back up to the serverto restore it. Compared to the Centralized Version Control System,this system offers lower probability of losing the entire project. Fur-thermore, Distributed Version Control System (DVCS)s deal quite wellwith having several remote repositories that they can work with, so itis possible to collaborate with different groups of people in differentways simultaneously within the same project. This allows the settingup of several types of work-flows that are not possible in centralizedsystems, such as hierarchical models [7].

From this description it should be clear that DVCS is the state of the art inthe revision control field. In fact, the code implemented in this work isloaded by a DVCS i nto a remote repository. The web hosting service chosenis GitHub, which uses git as DVCS.

Beginning from the latter, git was initially designed and developed by Li-nus Torvald for the Linux Kernel development in 2005, following the break-down of relations with the commercial company that developed BitKeeper(a proprietary DVCS where the Linux Kernel had been maintained between2002 and 2005).

8

Page 17: Master thesis Francesco Serafin

1.1 before starting

While any other VCS stores information as a list of file-based changes, gittreats its data more like a set of snapshots of a mini filesystem: every timeyou modify your project and push it into the repository, git takes a pictureof what all your files look like at that moment and stores a reference to thatsnapshot [7]. For optimal efficiency, git has a sort of pointer indicating the Snapshot, not

differencesfiles that do not show changes. Thus git only stores a link to the previousidentical file it has already stored, and not the complete file again. The mostimportant feature of git, however, is the possibility it offers to perform mostoperations only with local files and resources. Indeed, a git working direc-tory is a fully fledged repository with a complete history and full versiontracking capabilities [47]. For example, to browse the history of the project, Nearly every

operation is localgit does not need to go out to the server to get the history and display it, itsimply reads it directly from the local database. This means that the projecthistory can be seen almost instantly. This is also possible with changes intro-duced some revisions ago. Most operations can be performed offline, andthe network connection is needed only to upload the changes.

The history of revisions is depicted1

2

3

4

5

6

T1

7

8

9

10

T2

Figure 4.: Example history graph of aDVCS (taken from [47])

as a graph, both in git and in mostDVCSs. The type of graph is a tree withmerges (an example is shown in Figure DVCS graph

structure4): the versions are conceived as a line,the main line of development (calledtrunk or master, in green in Figure 4)with branching (called branch, in yel-low in Figure 4) off the trunk. If thereis only the master without branches,the version forms a single line basedon its immediate predecessor alone, theHEAD version. Then, the new versionis identified as the new HEAD. In thepresence of a branch, the relationshipbetween version and derived version(the branch) is an arrow, pointing fromolder to newer in the same directionas time. After branching process, ifthe new revision is based only on theolder derived revision (the branch isgrowing), then it is the new HEAD.When the new revision is based on morethan one previous revision the result-ing process is called merging. This istypical when changes occur in multi-ple branches (most often two, but moreare possible), which are then merged into a single branch incorporating bothsets of changes; a merge is drawn as a red arrow in Figure 4. In the pres-ence of merges, the resulting graph is no longer a tree, but a rooted directedacyclic graph [47].

Observing Figure 4, there are two other features to mention. The first isrepresented by a blue rectangle, which is called tag. This is a functionality tomark release points at a specific time in the progress of the work; it is storedas a full object. The second feature is represented by a cyan circle, whichmarks a Discontinued Development Branch: a branch does not necessarily

9

Page 18: Master thesis Francesco Serafin

setting up a modern environment for scientific computing

have to be merged with the master version, it can simply follow a differentdevelopment path, as has been done for various Linux distributions.

git can be used via command line. Assuming that the remote repositoryhas already been created, to run any git command it is necessary to changedirectory to git projects folder. To configure the protocol, the command viassh is:

$ git config remote.origin.url [email protected]:yourUserName/project.git

Then you have to initialize the repository via

$ git init

This creates a new subdirectory named .git that contains all the necessaryrepository files, the git repository skeleton. However, nothing in the projectis tracked yet. In order to start version controlling existing files, you have tospecify the files you want to track with:

$ git add .

followed by a commit:

$ git commit -m " insert your commit"

Then you can share your tracked files in your repository by pushing themupstream. The simple command is:

$ git push [remote-name] [branch-name]

This command only works if you have cloned from a server to which youhave write access and nobody has pushed in the meantime. If you areworking in a team in the same repository, and someone pushes upstreamand then you push upstream, your push will rightly be rejected. You willhave to pull down the other work first and incorporate it into yours, beforeyou will be allowed to push [7]:

$ git pull [remote-name]

In the most famous IDE, git can be integrated as a plug-in or installed bydefault. For Eclipse, this is called EGit and it allows complete control overyour git project via Graphical User Interface.

Regarding GitHub, this is simply the web-based hosting service that usesgit as DVCS. It is mainly used for software development projects.

1.1.3 Integrated development environment

This is the final link of the chain that connects software engineering withcode writing. An IDE is a software application that provides computer pro-grammers with comprehensive facilities for software development [42].

It has sprung up in order to organize, accelerate, and standardize the de-velopment of applications, making them more accurate, faster, more robustand easier to maintain. In particular this is because it reduces the configura-tions necessary to piece together multiple development utilities, providingthe same set of capabilities as a cohesive unit. The main features of IDEs are:

10

Page 19: Master thesis Francesco Serafin

1.2 the advantages of object-oriented programming

• a Graphical User Interface that enables users to conveniently managethe task at hand;

• a complete environment for building an application (building automa-tion tools);

• helpful views of the application and components under construction;

• cross-references to provide instant feedback about changes to the ap-plication;

• prebuilt frameworks, components, and tools that work together seam-lessly;

• debugging facilities to step through the running of the application andidentify errors.

The IDE used in application building doubles as a platform for maintain-ing and enhancing the application. The modular structure of an applicationbuilt with an IDE enables developers other than the creators to understand,maintain, and enhance it [33]. In general, an IDE improves:

• development time of applications;

• software engineering (many modern IDEs also have a class browser, anobject browser, and a class hierarchy diagram to use in object-orientedsoftware development), and as a consequence, modularity and organi-zation applications;

• reusability of components and pieces of code;

• maintainability and code development, especially in a team projects(sometimes DVCS/VCS are integrated).

These features can be summed up in one sentence: an IDE reduces the re-sources needed to build and maintain applications.

The most famous multiple-language IDEs are Eclipse, IntelliJ IDEA, Mi-crosoft Visual Studio, NetBeans, Oracle JDeveloper.

This work has been developed with Eclipse, an IDE based on an extensibleplug-in system. Thus users can customize it or extend its abilities by in-stalling plugins written for the Eclipse Platform, such as development toolk-its for other programming languages. A matter worthy of attention is theEclipse License. The Eclipse IDE is released under Eclipse Public License(EPL), an open source software license used by the Eclipse Foundation forits software. EPL licensed programs can be used, modified, copied and dis-tributed free of charge. The Eclipse IDE is only one of the Eclipse projects.An Open Source Community creates these products; the Eclipse Founda-tion, a non-profit, member-supported corporation hosts the Eclipse OpensSource projects and helps to cultivate both an Open Source Community andan ecosystem of products and services [36].

1.2 the advantages of object-oriented programming

The story that leads from monolithic programming to OOP can be seen asa sort of “Growing of Abstraction”. Eckel (2003) [14] introduces this concept:all programming languages provide abstractions. In this sense, you can viewabstraction like a progress bar, in which the lower level corresponds to the

11

Page 20: Master thesis Francesco Serafin

setting up a modern environment for scientific computing

machine model, or rather the solution space where you are implementingthe solution to a problem; on the other hand, there is the problem modelthat corresponds to the higher level of abstraction, or rather the problemspace where the problem exists.

If your abstraction level is small, you are very close to the machine model;Solution space, thelowest abstraction

levelthe classical example is the ASSEMBLY language (even before the binarylanguage). Many so-called imperative languages that followed (such as FOR-TRAN, BASIC and C) are abstractions of the ASSEMBLY language, thusthey have come closer to the problem space. However, all these languagesrequire you to think in terms of the computer structure, rather than theproblem structure you are trying to solve. All of this implies the drafting ofcomplex codes, that are difficult to read and expensive to maintain.

If the abstraction level is high, you are closer to the problem. An exampleProblem space, thehighest abstraction

levelwould be a language like LISP, for which “All problems are ultimately lists”.Quoting Eckel (2003) [14]

The object-oriented approach goes a step further by providing toolsfor the programmer to represent elements in the problem space. Thisrepresentation is general enough that the programer is not constrainedto an particular type of problem. We refer to the elements on the prob-lem space and their representations in the solution space as “objects”.The idea is that the program is allowed to adapt itself to the lingo ofthe problem by adding new types of objects, so when you read the codedescribing the solution, you’re reading words that also express the prob-lem. [. . . ] Thus, OOP allows you to describe the problem in terms of theproblem, rather than in terms of the computer where the solution willrun.

- Bruce Eckel -

Nowadays, OOP is the highest level of abstraction, involving the most flexibleand powerful language. Indeed, it provides barriers to break down a largeprogram into smaller structures (the classes), offering features (analized inparagraph 1.2.2) that can improve the design, implementation, debugging,and maintenance of codes. This makes it easy to manage large and complexproblems. Thus OOP is very useful in implementing elaborate situations,such as numerical problems in scientific computing, in particular given howeasy it is to improve and replace entire sections of code.

However, one of the main issues of scientific computing is performance– and OOP is slower than imperative programming. The observed perfor-OOP in scientific

computing mance loss of OOP led to it only being used experimentally by the scientificcommunity, until it was understood, at least in part, that it is necessary tohave the flexibility of OOP in order to easily develop ever more complexcodes. The reason is quite simple: if you have to update a numerical modelwith a new linear system solver and you have to go to the trouble of ex-tricating between 1 000 or more lines of code, which has been poorly com-mented by other people, perhaps only to replace the call to the old objectLinearSystemSolver with the call to the new object LinearSystemSolverEvolution,then optimizing this process with OOP by itself could pay for the computa-tional time lost later. Moreover, an imperative code is fast and efficient onlyif it is well written, otherwise there is the opposite effect. An imperativecode is usually not so easy to write. So which is better - an accurate andefficient object-oriented code, or an approximate monolithic one?

12

Page 21: Master thesis Francesco Serafin

1.2 the advantages of object-oriented programming

1.2.1 Object and Class

Object and class are the innovative features of this kind of language. Themost important step is understanding the philosophy behind the use ofobject and class.

The next step is to apply these tools within a scientific field. It is difficultto identify an object in a mathematical element, while identifying real ob-jects is quite easy, e.g. in a game like bingo, the objects might be player, card,poster etc. For clarity, an example is shown in the following paragraph.

What is an Object?

An object in OOP can be identified with something similar in a real-worldcontext. It has two characteristics: state and related behaviour. For example, Every object has

states and behavioursin the real world . . .

a radio might have some states like on, off, current volume, current stationand the related behaviours like turn on, turn off, increase volume, decreasevolume, seek, scan and tune. A good numerical example could be a matrix:its states could be the number of rows, the number of columns, the determi-nant, eigenvectors and eigenvalues. Its related behaviours could be fill thematrix, compute the determinant, compute eigenvectors and eigenvalues, isthe matrix positive definite etc. . . . which become

fields and methods inthe OOP world

As has been just stated, translating into the world of OOP, the states be-come the fields and the behaviours become the methods (variables and func-tions in some programming languages, respectively).

What is a Class?

In the real world, there are many individual objects all of the same kind(how many radios are there in the world?). Keeping up the comparison The origin of Class

keywordbetween real world and programming world, objects that are identical ex-cept for their states during program execution (e.g. the number of columnsfor two objects matrix could be different, but the two object matrix remainequal), are grouped together into classes of objects, and this is where thekeyword class originated.

But a class is not only a kind of object, it is also a new abstract data type.This is a fundamental concept in OOP. Abstract data types work almost Class: abstract data

type like built-in typeexactly like built-in types: you can create variables of a type (called objector istance in OOP) and manipulate these variables (called sending messagesor request: you send a message and the object figures out what to do withit) [14].

Always considering the high level of abstraction. A class is useful to aprogrammer because it can fit to a part of the analyzed problem, while anexisting data type is designed to represent a unit of storage in a machinewith a low level of abstraction.

1.2.2 OOP features

The most important feature of OOP is data abstraction. However, there arealso three other aspects that make this kind of programming very useful.These features are (not in order of importance): inheritance, encapsula-tion (also improperly called implementation hiding, because encapsulation isa combination of wrapping data and methods within classes and implemen-tation hiding), and dynamic binding (also called polymorphism).

13

Page 22: Master thesis Francesco Serafin

setting up a modern environment for scientific computing

Inheritance

As seen in paragraph 1.2.1, a class defines a new type of object. Forexample, in the scientific world, a class can be well represented by a matrix,but there are several types of matrices: sparse, dense, diagonal, etc. So, onceyou have created the class Matrix.java with all its methods, why should youhave to create a class DenseMatrix.java that might have similar functionality?

The inheritance allows the cloning of the original class Matrix.java (calledthe base class, or superclass or parent class) and eventually makes additionssuperclasses &

subclasses and modifications in a modified clone (called the derived class or inheritedclass or subclass or child class) like the DenseMatrix.java.

The differences between base types and derived types are:

• base types contain characteristics (variables) and behaviours (meth-ods) inherited by all the derived types;

• derived types are a new type that contains not only all the membersof existing type [14].

Indeed, if there is the necessity to differentiate the derived class from theoriginal base one, you can:

a. add new methods that are not part of the base class;

b. change the behaviour of an existing base class method; this is referredto as overriding that method.

Encapsulation

Encapsulation is a form of wrapping data and methods within classes incombination with implementation hiding [14]. There are two reason to usethis feature.

The first is to establish what the client programmers can and cannot use,restricting the access to the object’s components.

The second reason is to separate the interface3 from the implementation,in such a way that the client programmers can use the code by sending mes-sages to the public interface without worrying about code implementation.However the programmer can access and change all the code.

There are three terms to manage the accessibility of an object (listed frommost access to least access):3P for the access to

an object: Private,Public and Protected a. Public: everything that is declared public is available to everyone.

b. Protected: everything that is declared protected is closely linked toinheritance. When the derived class (class which inherits from thebase class) and the base class are in different packages, the derivedclass can access members of the original class. Only with protectedthe programmer grants access to a particular member of the derivedclass. protected also gives package access – that is, other classes in thesame package may access protected elements [14].

c. Private: no one can access that member except the class that containsthat member [14]. In this way, the programmer insulates the member,as other classes in the same package cannot access it either.

3 The interface determines the request that can be made to a particular object. However, theremust be the code somewhere to satisfy that request, but this is related to the implementationpart.

14

Page 23: Master thesis Francesco Serafin

1.3 java as programming language for scientific computing

For example, this kind of features can be used in a library: the library creatordecides what is available to the client programmer and what is not, whilethe consumer uses the library without rewriting or changing pieces of code.In general, the consumer wants results from libraries; he is not interested inthe design decisions which led to a particular implementation of the library.

Dynamic binding

In the example used in the inheritance paragraph, the base class Matrix.

java is inherited by DenseMatrix.java, SparseMatrix.java, DiagonalMatrix.java, etc.Dynamic binding (also called polymorphism) is the feature by which the Polymorphism, to

decide the type atrun-time

programmer declares an object to be of type matrix, for example, whilewriting the code, but the allocation of the object occurs only at run-time,when the variable is allocated according to the better type, i.e. sparse matrixrather than dense, etc.

This feature implies another characteristic: upcasting. It occurs when anobject referenced in a method is done as a base type. This allows the passingof every derived type to that method without causing errors. Following thisprinciple, it is possible to write the entire code referring only to the baseclass, and deciding on the most suitable type of object at run-time.

1.3 java as programming language for scientific computing

Java was not designed to be a scientific computing language, but throughan analysis of its main positive and negative characteristics, it is possibleto demonstrate that it has a great deal to offer and it may also have animportant role in the scientific environment.

Object Oriented Programming

The most important feature is the OOP, as the main need in scientific com-puting is to evolve code either by improving it or increasing its complexity,and OOP makes the code easy to mantain. However, a more in-depth analy-sis has already been made in section 1.2.

Java Virtual Machine

Java is portable at both the source and object format levels. This meansthat, considering the main formats of a Java file4, all types are expected tobehave in the same way on any computer with the appropriate Java com-piler and Java Virtual Machine (JVM) as the standard run-time system. Themotto of the first Java developers was “write once, run anywhere” (WORA) “write once, run

anywhere”– this has become fundamental in the academic environment as Java runson virtually every University platform in the world making any code easilydistributable via any type of VCS. Certainly, JVM increases the computationaltime, but this question is particularly thorny and is therefore treated in para-graph 1.3.1.

Memory management

Memory management is another important feature: each object requireresources (memory) in order to exist, and it is very difficult to know if andwhen it can be destroyed after use.

4 The source format is the code in a .java file, while the object format is the bytecode in a .class

file.

15

Page 24: Master thesis Francesco Serafin

setting up a modern environment for scientific computing

In general, some programming languages like C++ allow full memorymanagement during the writing of the code. Thus, you can decide in whichtype of memory allocate a particular type of variable, when to allocate it andwhen to destroy it. For a computer technician, these kinds of operations aredaily routine with a low difficulty level. For a non-computer technician,the risk of memory leaks is very high, especially when he is focused onsolving mathematical/numerical problems, rather than on computer tricks.For example, in C++ there is a pointer variable that contains the memoryaddress of an object: if in writing your code, you delete the pointer withoutdeallocating the slot of memory occupied by the pointed object, a memoryleak error may be generated, especially if you make this object into a loop,increasing the memory usage without control.

The JVM has, in fact, the Garbage Collector (GC), which attempts to re-Garbage Collectorintroduction claim memory occupied by objects that are no longer in use by the program.

In this way, the programmer is free from manually dealing with memorydeallocation, and certain categories of bugs, like some kinds of memoryleaks, are eliminated. Moreover, GC has a sort of memory defragmentation.As reported in [30], this feature is very useful because when you create anew object in Java, the JVM automatically allocates a block of memory largeenough to fit the new object on the heap. Repeated allocation and reclama-tion leads to memory fragmentation, which is similar to disk fragmentation.This phenomenon implies two problems:Garbage Collector

defragmentingsystem

1. Reduced allocation speed: The JVM tracks free memory in lists orga-nized by block size. To create a new object, Java searches through thelists to select and allocate an optimally sized block. Fragmentationslows the allocation process, slowing the execution of the application.

2. Allocation errors: Allocation errors happen when fragmentation be-comes so great that JVM is unable to allocate a sufficiently large blockof memory for a new object.

The defragmenting system compacts memory by moving all live objects toone end of the heap and removing any fragments of free space, thereforethe allocation becomes much faster.

Obviously, the GC itself has a cost in terms of efficiency and memoryconsumption.

Firstly, whenever the GC is triggered all application threads are stopped,and the JVM is suspended for the complete duration of a run. The impactof the GC depends on the number of live objects, and not on the number ofGarbage Collector

efficiency dead ones, because the GC suspends the execution of the program to ensurethe integrity of object trees. Thus, the more live objects there are, then thelonger is the suspension; the more objects die, the faster is the GC [30].

Secondly, all Java objects consume an extra 8 B of memory, because the JVMGarbage Collectormemory

consumptionuses these bytes to keep track of the objects and it automatically reclaimsmemory through GC when the objects are no longer needed [20].

So, as reported in Eckel (2003) [14], there are two different approaches:the main objective of the C++ language is speed of memory allocation andmemory release, sacrificing flexibility, because it is necessary to know theexact quantity, lifetime, and type of objects while writing the code; the mainobjective of the Java language, on the other hand, is flexibility, because youdon’t know how many objects you need, what their lifetime is, or whatexact type they are until run-time. In other words, the storage is manageddynamically. Obviously, the amount of time required to allocate storage on

16

Page 25: Master thesis Francesco Serafin

1.3 java as programming language for scientific computing

the heap can be noticeably longer than time to allocate storage on the stack,because the latter requires a single assembly instruction to move the stackpointer down, while the time to create heap storage depends on design ofthe storage mechanism.

Open source project

Java is an open source project. Perhaps, this aspect may appear as notbeing very important. Indeed, it is a philosophical matter: to develop open Java is an open

source projectsource software, such as in this work, you cannot use any programming lan-guage but only an open source language. Sun Microsystems accomplishedreleasing Java as a free and open source software on May 8, 2007 under theterm of the GNU General Public License (GPL).

1.3.1 Java performance

Java performance requires a separate discussion. A common reaction ofthe advanced numerical programmers regarding Java as a programminglanguage for their codes is “But Java is too slow!”. While Java is slower thancompiled languages, it is not as slow as it was some years ago.

At the beginning of the JVM, the computational time was very long be-cause the JVM worked by strictly interpreting the bytecode of the .class files.Some people reported that the Java programs were up to 500 times slowerthan the equivalent C or Fortran codes.

Much has changed in the past few years. Today, almost all JVMs for tra- To improve theperformance of Java:the JIT

ditional computing devices use Just-in-time (JIT) compiler technology (alsoknown as dynamic translation). JITs operate as part of the JVM, compil-ing Java bytecode into native machine code at run-time. As reported inWikipedia [44], in a bytecode-compiled system, source code is translatedinto an intermediate representation known as bytecode. The latter is notthe machine code for any particular computer, and may be portable amongcomputer architectures. The bytecode may then be interpreted by, or run on,a virtual machine. The JIT compiler reads the bytecodes in many sections(or, rarely, in full) and compiles them dynamically into machine languageso the program can run faster. Java performs run-time checks on varioussections of the code and this is the reason the entire code is not compiled atonce. This can be done per-file, per-function or even on any arbitrary codefragment; the code can be compiled when it is about to be executed (hencethe name “just-in-time”), and then cached and reused later without needingto be recompiled.

A common motivation for using JIT techniques is to reach or surpassthe performance of static compilation, while maintaining the advantages ofbytecode interpretation. Nowadays, the ratio between C++ and Java perfor- Java is not so slow

mance is 1:1.7, but a C++ code can lose most of its performance, transferringthe executable file to a machine with different architecture.

Thus, the statement “Java is slow” is not completely true; moreover, thepositive features of this kind of language far outweigh the loss of computa-tional time.

17

Page 26: Master thesis Francesco Serafin

setting up a modern environment for scientific computing

1.4 the object modeling system

The code related to this work has been integrated into OMS, an Envi-ronmental Modeling Framework (EMF) for environmental model develop-ment [15].

Frameworks were developed during ’90s because human managementissues of the natural word required the solving of ever more complex inter-disciplinary problems. Every model described only a single physical phe-nomenon in that period, thus several of these models often had to be appliedwithin the context of a single project application. Frameworks were built asa supporting structure (integrated modelling framework) around which tointegrate several models.

Frameworks are essential to better enable software engineering processesin support of scientific modelling, because they improve not only developerWhy to use a

framework productivity but also the quality and reliability of the software product it-self. It allows developers to focus development efforts on supporting uniqueapplication requirements (as opposed to developing application infrastruc-ture) [12].

Typically, environmental modellers are not software engineers, hence theyare focused on the choice of the best set of equations, algorithms, and math-ematical constructs to create environmental models. The EMF manages thesoftware engineering part of the model by black-box programming inter-faces that can hide information related to input/output management, coderelationship, etc.

In summary, the main purposes of frameworks are to enhance modularity,reusability, and interoperability of every science and auxiliary component,allowing modellers to focus on the model development.

Regarding OMS, its development started in the early 2000s as a vehicleto migrate the design principles of the Modular Modeling System (MMS)written in C/Motiv, into a reusable EMF [12]. It has now arrived at the thirdversion.

OMS is an interagency project between the USDA-ARS (Agricultural Re-search Service), USGS (U.S. Geological Service) and USDA-NRCS (NaturalResources Conservation Service), and the aim is to make it an even moreadvanced modular modelling framework based on enhanced modularity,reusability and interoperability of all its components. OMS provides a con-sistent and efficient way to:

• create science simulation components;

• develop, parameterize, and evaluate environmental models and mod-ify/adjust them as science advances;

• re-purpose environmental models for emerging customer requirements.

OMS3 is comprised of four primarily architectural foundations, includingmodelling resources, the system knowledge base, development tools, andmodelling products (see Figure 5). The OMS3 core consists of an internalmetadata knowledge base for model and simulation creation. A simulationin OMS is defined as a collection of resources (parameter sets, input data,modelling components, model execution methods, etc.) required to pro-duce desired modelling outputs. The system supports harnessing metadatafrom various sources, including natural resources databases (e.g. land use/-cover, soil), web-based data provisioning services, version control systems

18

Page 27: Master thesis Francesco Serafin

1.5 lessons to take home

and/or other code repositories. These are incorporated into the frameworkknowledge base, which various OMS3 development tools employ to createmodelling products. OMS3 modelling products include science componentsand complete models, simulations supporting parameter estimation andsensitivity/uncertainty analysis, output analysis (e.g., statistical evaluationand graphical visualization), tools, modelling audit trails (i.e., reproducingmodel results for legal purposes), and miscellaneous technical/user docu-mentation [12].

Figure 5.: OMS3 principle framework architecture

1.5 lessons to take home

In summary, the most suitable base IT tools for the development of mod-ern codes have been chosen in this chapter. These tools allow to:

• work in teams, splitting the work to be done (UML) and sharing thework already done (DVCS);

• write short, readable, robust, correct, manageable, and documentedprograms (OOP & Java);

• have total control over previous tools using only one program (IDE &Eclipse).

Thus, a complete environment is now available to realize a scientific model.Environmental phenomena are always described by Ordinary DifferentialEquation (ODE)s and PDEs. Therefore, to prove the advantages given bythese tools, they are applied to a parabolic PDE, for example: the Boussinesqgroundwater equation.

Before implementing the code structure, in the next chapter, the physicalproblem is analyzed and the mathematical steps to convert the PDE into alinear system, through spatial and time discretizations, are described.

19

Page 28: Master thesis Francesco Serafin
Page 29: Master thesis Francesco Serafin

2T H E B O U S S I N E S Q ’ S G R O U N D WAT E R E Q U AT I O N

Contents2.1 The physical problem 21

2.1.1 Some definitions 21

2.1.2 The moisture distribution in a vertical profile 22

2.1.3 Phreatic aquifer and its properties 22

2.2 The Boussinesq equation 232.3 Mass conservative scheme for wetting and drying 24

2.3.1 Unstructured orthogonal grid 25

2.3.2 Spatial discretization 27

2.3.3 Time discretization 28

2.4 Boundary conditions 302.4.1 Flux-Based boundary conditions (Neumann) 30

2.4.2 Head-Based boundary conditions (Dirichlet) 31

2.5 Lesson to take home 32

As seen in the introduction, there is a necessity to describe flow throughporous media, both to estimate the water stored in the groundwater zoneand to know the water movements of the water table, in order to preventhydro-geological instability.

The Boussinesq groundwater equation describes this phenomenon in aphreatic aquifer.

2.1 the physical problem

This paragraph is a brief summary that presents the physics of the prob-lem. It is based on the work done by Bear (1988) [2].

Firstly, the most important definitions will be presented.

2.1.1 Some definitions

An aquifer is a geological formation, or stratum, that contains water, andpermits significant amounts of water to move through it under ordinaryfield conditions. In contradistinction, an aquiclude is a formation that maycontain water (even in appreciable amounts), but it is incapable of trans-mitting significant quantities under ordinary field conditions, e.g. a claylayer. Thus, for all practical purposes, an aquiclude is considered an imper-vious formation. An aquitard is a semi-pervious geological formation thattransmits water at a very slow rate as compared to the aquifer. However,over a large (horizontal) area it may permit the passage of large amountsof water between adjacent aquifers, which it separates from each other. Anaquifuge is an impervious formation that neither contains nor transmitswater. Groundwater is a term used to denote all waters found beneath theground surface. However, the groundwater hydrologist, who is primarilyconcerned with the water contained in the zone of saturation, uses the termgroundwater to denote water in this zone, and this is the meaning used in

21

Page 30: Master thesis Francesco Serafin

the boussinesq’s groundwater equation

this work. That portion of rock not occupied by solid matter is the voidspace or pore space, pores, interstices and fissures. This space contains wa-ter and/or air. Only connected interstices can act as elementary conduitswithin the formation.

2.1.2 The moisture distribution in a vertical profile

In order to analyze the physics of the problem, it is essential to makean accurate description of the moisture distribution in a vertical profile.Subsurface water may be divided vertically into zones depending on the rel-ative proportion of the pore space occupied by water: a zone of saturation,in which all pores are completely filled with water, and an overlying zoneof aeration, in which the pores contain both gases (mainly air and watervapour) and water.

Thus the physical problem may be easily described: once water arrives onthe ground surface, either by precipitation or irrigation, it slowly infiltratesand moves downwards, following the gravitational field. Having reachedthe impervious bedrock, the water begins to accumulate, filling all intercon-nected pores. A zone of saturation is thus formed and is bounded above bya water table (or phreatic surface), that identifies the surface at atmosphericpressure.

The remaining part of the ground is the zone of aeration and can be di-vided in three sub-zones. Continuing to observe from the bottom upwards,the first layer is the capillary zone (or capillary fringe). Its thickness de-The Capillary Fringe:

the deepest zone ofaeration

pends on the soil and on the uniformity of pore size: in coarse materialsthis layer is practically non-existent; in fine materials (e.g. clay), the thick-ness may be of 2÷ 3 m or more. Within the capillary zone there is usually agradual decrease in moisture content with height above the water table, in-deed, the pressure is less than atmospheric; moving higher, only the smallerconnected pores contain water. Observing a hillslope, the flow in the un-saturated zones may be of primary importance, while in the flat areas ofa basin, the saturated zone below the water table is much thicker than thecapillary fringe, thus the flow in the latter is often neglected.

Over the capillary zone, there is the intermediate zone. This extends fromThe IntermediateZone: pellicular andgravitational water

the upper limit of the capillary fringe to the lower edge of the soil waterzone. Normally, water moves downward through this zone as gravitationalwater; but when the water table is too high, this layer does not exist and thecapillary fringe may extend into the soil water zone, or even to the groundsurface.

The highest layer is the soil water zone, this is adjacent to the groundsurface, and is affected by conditions at the ground surface: e.g. fluctuationsThe Soil Water Zone:

where the moisturedistribution is

affected by conditionsat the ground surface

of precipitation, irrigation, air temperature and air humidity, and by thepresence of a shallow water table. In this layer, water can normally movedownwards during infiltration, as in the other lower layers, but it may alsomove upwards by evaporation and plant transpiration. When the infiltrationis excessive, usually during a short period, the soil in this zone may bealmost completely saturated.

2.1.3 Phreatic aquifer and its properties

The difference between unconfined or confined aquifers depends onlyon the presence or absence of a water table respectively. Thus a phreaticaquifer (also called unconfined aquifer or water table aquifer) is one with a

22

Page 31: Master thesis Francesco Serafin

2.2 the boussinesq equation

water table (phreatic surface) serving as its upper boundary. Normally,it is bounded below by impervious formations, while a confined aquiferis bounded above and below by impervious formations. In contrast to aconfined aquifer, in an observation well (or piezometer), the water level isequal to the piezometric head, and marks the height of the water table. Ina confined aquifer (also known as a pressure aquifer), an observation wellidentifies the piezometric head, that is normally above the base of the con-fining formation; if the confined aquifer is an artesian aquifer the elevationof piezometric surface is above ground surface.

Lastly, it is useful to define some general properties of an aquifer, in orderto unify the physical phenomenon with mathematical formulae.

The hydraulic conductivity indicates capacity of the aquifer material toconduct water through it under hydraulic gradients. It is, therefore, a coeffi-

KScient that depends on solid matrix properties (pore-size distribution, shapeof pores, tortuosity and porosity) and on fluid properties (density and vis-cosity).

The aquifer transmissivity indicates the ability of the aquifer to transmit

Twater through its entire thickness, when the flow is essentially horizontal. Itis the product of the hydraulic conductivity and the thickness of the aquifer.

The storativity of an aquifer indicates the relationship between the changes

Sin the quantity of water stored in an aquifer and the corresponding changesin the elevations of the phreatic surface for an unconfined aquifer. The stora-tivity can be defined as that volume of water released from (or added to) avertical column of an aquifer with a unit horizontal cross-section, per unitof decline (or rise) of the phreatic surface.

In this work, the focus is on the groundwater zone of an unconfinedaquifer, with the aim to identifying the water table and its movements.

2.2 the boussinesq equation

The major part of this work is based on the BEq, the governing equation ofgroundwater flow. It is based on Darcy’s Law and the continuity equation The conservative

form of the BEqand, thus, it has been derived from the hydraulic theory of unconfined,saturated, groundwater flow in a sloping aquifer.

The BEq used in this work has the following two-dimensional form:

∂hw (η, x,y)∂t

= ∇ ·[KS(x,y, z)h(η, x,y)~∇η

]+Q(x,y), (2.1)

where η is the unknown piezometric head (it can be seen as water-table ele-vation); x, y are the planimetric cartesian coordinates; t is time; hw(η, x,y)is the total water volume stored in a soil column of unit planimetric area;h(η, x,y) is the thickness of the aquifer, which is a function of η and spacesince it is defined as h := max(0,η− zb(x,y)) where zb(x,y) is the bedrockelevation; ∇ · is the divergence operator; ~∇ is the gradient operator; Q(x,y)is a source term per unit planimetric area, which is also used as Boundaryconditions (BC); KS(x,y, z) is the saturated hydraulic conductivity.

Multiplying hw(η, x,y) by the domain area gives the total volume of waterstored. But it is necessary to compute this magnitude. So, as shown in

23

Page 32: Master thesis Francesco Serafin

the boussinesq’s groundwater equation

Cordano and Rigon (2008) [9], considering a vertical hydrostatic distributionof soil water pressure:

hw(η, x,y) =∫zs−∞ θw(x,y, z,η− z)dz, (2.2)

where zs is the elevation of the terrein surface, and θw(x,y, z,ψ) is the vol-umetric soil water content. Then, the drainable porosity s(x,y) is calculatedby deriving hw(η, x,y) with respect to η:

s(x,y) =∂hw(η, x,y)

∂η. (2.3)

Equation (2.1) is written in conservative form, i.e. the time derivative iswith respect to the volume of total stored water per unit area, which is theconserved quantity, and the second addendum of the equation contains thedivergence of mass flux. By appling definition (2.3) and the derivation chainThe BEq

rule to the left-hand side of (2.1), BEq can be rewritten in the form usuallyfound in papers and manuals [2, 21, 28]:

s(x,y)∂η

∂t= ∇ ·

[KS(x,y, z)h(η, x,y)~∇η

]+Q(x,y). (2.4)

2.3 mass conservative scheme for wetting and drying

Obviously, numerical approximation is typically used to solve the Boussi-nesq groundwater equation. But choosing the most appropriate numericmethod is not so simple because the mass balance must not contain errors,especially in presence of wetting and drying.

The first step is to choose the equation, because solving the (2.4) or the(2.1) is not the same thing. Indeed, the water level η(x,y) is not a smoothfunction at the edge of the wet zones, thus equation (2.1) is the best choicein order to conserve mass.

The next step is to choose the numerical method. To solve a generic, free-Conservative methodwhich simulates

wetting and dryingfronts

surface, hydrodynamic problem, i.e. the Shallow Water Equation (SWEq) orthe BEq, Brugano and Casulli in [3] found a rigorous numerical method.This method is conservative and can simulate wetting and drying fronts.

Thus, the Boussinesq equation (2.1) can be cast as a system of the form:

V (

ξ ) + T ·

ξ =

b , (2.5)

where

•ξ = [ξ1, . . . , ξi, . . . , ξNp ]

T is the array of unknown quantities;

•b = [b1, . . . ,bi, . . . ,bNp ]

T is the array of known parameters;

•V (

ξ ) = [V1(ξ1), . . . ,Vi(ξi), . . . ,VNp(ξNp)]

T are the values of the fieldconserved quantity, i.e. the water volume stored in the i-th cell, a non-linear function of η.

24

Page 33: Master thesis Francesco Serafin

2.3 mass conservative scheme for wetting and drying

All these “vectors” are denoted by the symbol · , or harpoon, to distinguishthem from space vectors, denoted by ~· . In the following paragraphs it isshown that the discretization adopted endows the matrix T with proper-ties, as specified in Appendix A, that make the system numerically solvablewith the use of the Newton method [23] and the conjugate gradient algo-rithm [31] having convergence to solution guaranteed a priori [3].

2.3.1 Unstructured orthogonal grid

Before discretizing the equation (2.1), the horizontal (x,y) domain is cov-ered by an unstructured orthogonal grid of non-overlapping convex poly-gons. As reported in Casulli and Walters (2000) [6], in this type of grid, Definition of

unstructured gridwithin each polygon a point can be identified such that the segment joiningthe centres of two adjacent polygons and the side shared by the two poly-gons, have a non-empty intersection and are orthogonal to each other. Thecentre of a polygon does not necessarily coincide with its geometrical centre,but it does coincide with its circumcentre.

Thus the integration domain is divided into Np polygons (grid elements).Each side of a polygon is either a boundary line or the side of an adjacentpolygon; when the standard approximation applied to the spatial domain isthe finite volume method, the solution is computed only in the centres of thecells. Thus the boundary lines are not useful for method resolution. Thenumbered sides are only the Ns shared edges. In the example, the domainis divided into 8 polygons, while the numbered shared edges are 9.

Figure 6.: Unstructured grid - the polygons are numbered in red, the shared edgesare numbered in blue

How to describetopologicalconnection: theAdjacency Matrix

The topological connection between the i-th geometric element and them(i,j)-th adjacent cell can be described through the use of an adjacency ma-trix. According to its definition, an adjacency matrix is a square binary

25

Page 34: Master thesis Francesco Serafin

the boussinesq’s groundwater equation

matrix where row names and column names are vertices of the graph andit represents which vertices (or nodes) of the graph are adjacent to whichother vertices. In this case, the graph vertices are the circumcentres of thecells of the integration domain, thus:

Aij =

1 if the j-th polygon is adjacent to the i-th polygon

0 elsewhere. (2.6)

Applying this definition to the example above returns the adjacency matrixAij of dimensions Np x Np:

Aij =

Np x Np 0 1 2 3 4 5 6 7

0 0 1 0 0 0 0 0 1

1 1 0 1 0 0 0 0 0

2 0 1 0 1 0 0 1 0

3 0 0 1 0 1 0 0 0

4 0 0 0 1 0 1 0 0

5 0 0 0 0 1 0 1 0

6 0 0 1 0 0 1 0 1

7 1 0 0 0 0 0 1 0

. (2.7)

However, in this way the topological connections are not represented; af-ter numbering the shared sides of the polygons, it is known as an “adja-cency” matrix of dimension Np x Ns, such that:

Bir =

1 if the r-th edge is part of the i-th polygon

0 elsewhere, (2.8)

Bir =

Np x Ns 1 2 3 4 5 6 7 8 9

0 1 0 0 0 0 0 0 0 1

1 1 1 0 0 0 0 0 0 0

2 0 1 1 0 0 0 0 1 0

3 0 0 1 1 0 0 0 0 0

4 0 0 0 1 1 0 0 0 0

5 0 0 0 0 1 1 0 0 0

6 0 0 0 0 0 1 1 1 0

7 0 0 0 0 0 0 1 0 1

. (2.9)

This matrix is also useful to define the subset of the shared edges for eachi-th polygon:

Fi = r if Bir = 1. (2.10)

The subset Fi will be used later for the discretization of the divergenceterm in (2.1). Now, the two important pieces of information collected in thematrices A and B, must be combined into a single matrix: the shared edgesadjacency matrix Mij. The simple statement that summarize the computeof this matrix is:

Mij =

r if Aij = 1 and Bir = 1

0 otherwise. (2.11)

26

Page 35: Master thesis Francesco Serafin

2.3 mass conservative scheme for wetting and drying

Thus a new adjacency matrix Mij, of dimension Np x Np, is defined andif the entry is non-zero it coincides with the numbers of the sides sharedbetween the polygon corresponding to the row pointer and the polygoncorresponding to the column pointer.

Mij =

Np x Np 0 1 2 3 4 5 6 7

0 0 1 0 0 0 0 0 9

1 1 0 2 0 0 0 0 0

2 0 2 0 3 0 0 8 0

3 0 0 3 0 4 0 0 0

4 0 0 0 4 0 5 0 0

5 0 0 0 0 5 0 6 0

6 0 0 8 0 0 6 0 7

7 9 0 0 0 0 0 7 0

. (2.12)

Modified AdjacencyMatrixFor computational purpose, the element −1 is added on the diagonal of

the Mij matrix, and the result is:

Mij =

Np x Np 0 1 2 3 4 5 6 7

0 −1 1 0 0 0 0 0 9

1 1 −1 2 0 0 0 0 0

2 0 2 −1 3 0 0 8 0

3 0 0 3 −1 4 0 0 0

4 0 0 0 4 −1 5 0 0

5 0 0 0 0 5 −1 6 0

6 0 0 8 0 0 6 −1 7

7 9 0 0 0 0 0 7 −1

. (2.13)

2.3.2 Spatial discretization

By integrating (2.1) over the i-th polygon, one obtains:

∫pi

∂hw(η, x,y)∂t

dxdy =

=

∫pi

∇ ·[KS(x,y,h)h(η, x,y)~∇η

]dxdy+

∫pi

Q(x,y)dxdy,(2.14)

where pi is the planimetric area of the cell. Therefore, observing that thevolume of stored water in the i-th cell is:

Vi(ηi) =

∫pi

hw(ηi, x,y)dxdy, (2.15)

and given that hw is the water volume per unit area between the bedrock The integrated formof the BEqand the free surface level (η) as defined by (2.2), and then applying the

divergence theorem, the following integrated form of the BEq is obtained:

∂Vi∂t

=∑j∈Fi

∫λj

KS(x,y,h)h(η(x,y))(~∇η · ~nj)dλj+∫pi

Q(x,y)dxdy, (2.16)

where λj is the length of the j-th edge, dλj is the differential along the j-thedge, ~nj is the outcoming versor orthogonal to the j-th edge, and ~∇η · ~nj is

27

Page 36: Master thesis Francesco Serafin

the boussinesq’s groundwater equation

the derivative (gradient) of η, estimated at the j-th edge and orthogonal toit. Remarkably, it can be noticed from (2.15) that the total stored volumeis dependent on the spatial variability of hw within the cell and, therefore,on the sub-grid variability of the drainable porosity, the bedrock and sur-face elevation. Due to the orthogonality of the grid, the spatial gradientcomponent can be approximated with the finite difference:

~∇η · ~nj ≈ηρ(i,j) − ηi

δj, (2.17)

where δj is the distance between the centre of the i-th and ρ(i, j)-th adjacentpolygons. Thus (2.16) is transformed into:Spatial discretization

of the BEq

∂Vi(ηi)

∂t=∑j∈Fi

Tj(ηi,ηρ(i,j)) ·ηρ(i,j) − ηi

δj+

∫pi

Q(x,y)dxdy, (2.18)

where ~Tj(ηi,ηρ(i,j)) is a transport coefficient along the j-th edge, estimatedwith an upstream weighting scheme as follows [28]:

Tj(ηi,ηρ(i,j)) := max

∫λj

[KS(x,y,h)h(ηi, x,y)]dλj ,

∫λj

[KS(x,y,h)h(ηρ(i,j), x,y)]dλj

.

(2.19)

The main advantage of this upstream weighting estimator, Tj, is that it pre-vents water from leaving a nearly dry cell and allows water to flow intoinitially dry cells during a flooding [28]. However, it can also be easilymodified on the basis of knowledge of the local variability of hydraulictransmissivity (the integrand) in the volumes under consideration. It is re-markable that Tj is a property of the j-th edge and is symmetric with respectto the level of η in adjacent cells, i.e. ~Tj(ηi,ηρ(i,j)) = ~Tj(ηρ(i,j),ηi). If thevariations of hydraulic conductivity and porosity in space are known, forinstance with a stochastic theory of the medium, e.g. [11], the above integralcan be estimated with a Monte-Carlo method when the cells are big enoughto ensure ergodicity .

2.3.3 Time discretization

Each term in Equation (2.18) depends on time (which has been left im-plicit so far), and it can be discretized in a semi-implicit way as follows:

Vi(ηn+1i ) = Vi(η

ni ) +∆t

∑j∈Fi

Tnj

ηn+1ρ(i,j) − η

n+1i

δj+∆t pi Q

ni , (2.20)

where ∆t is the time step and all the superscripts indicate the time instant.The transport coefficient Tj is estimated at time n (and is therefore known),as is Qni , the water-table recharge (or a sink) averaged over the whole i-th

28

Page 37: Master thesis Francesco Serafin

2.3 mass conservative scheme for wetting and drying

polygon. The gradient is treated implicitly and the solution of (2.20) mustbe sought by solving an algebraic non-linear system:

Vi(ηn+1i ) −∆t

∑j∈Fi

Tnj

ηn+1ρ(i,j) − η

n+1i

δj= Vi(η

ni ) +∆t pi Q

ni , (2.21)

for i = 1 to Np. The system in (2.21) is a particular case of (2.5) where ξi is Time discretization ofthe BEqreplaced with ηn+1i and the following equalities are taken:

[T · ξn+1

]i= −∆t

∑j∈Fi

ηρi, jn+1 − ηn+1i

δj(2.22)

and

bi = Vi(ηni ) +∆t pi Q

ni . (2.23)

From (2.22), T results to be a symmetric and positive semidefinite matrix,which satisfies the T2 property, defined in Appendix A, with diagonal en-tries:

Tii = ∆t∑j∈Fi

Tj

δj(2.24)

and off-diagonal entries:

Tir = −∆tTnj

δjδr,ρ(i,j) i 6= r, (2.25)

where δr,ρ(i,j) is the Kronecker delta symbol. It can be shown that in eachrow of T the sum of the entries is zero:

Np∑r=1

Tir = 0. (2.26)

Finally, Equation (2.21) is rewritten with index notation as follows: Discretized form ofthe BEq

Vi(ηn+1i ) +

Np∑i=1

Tijηn+1j = bi. (2.27)

From (2.22) it follows that the unit vector, [1, . . . , 1]T , is the eigenvector of Tassociated to the null eigenvalue. This happens when the hydraulic head isuniformly distributed and, according to Darcy’s law, there is no flux. Thestability and convergence to the exact solution is verified according to theconditions (A.9) or (A.10).

However, it can happen that T is reducible (and then Tii = 0 for a certainvalue of i and Til = 0 for certain adjacent cells i and l). In this case, nowater flux occurs through the sides of some cells and there is a disconnected“wet” domain. Consequently, the matrix T has as many eigenventors

v

29

Page 38: Master thesis Francesco Serafin

the boussinesq’s groundwater equation

corresponding to the zero eigenvalue as there are wet domains, i.e. groupsof connected cells. The condition for each group of connected cells (to becompared with (A.9)) becomes:

∑i∈Ωd

Vi(ηni ) +∆t

∑i∈Ωd

piQni > 0 1 6 d 6 Nsd, (2.28)

where d is the index of the group of connected cells Ωd.

2.4 boundary conditions

Equation (2.21), which represents the water balance of a generic cell, issolved by coupling with BC, which can be either flux BC (Neumann type) orhead BC (Dirichlet type). In the following we analyze how each choice ofboundary condition modifies the integration properties of the system and,in particular, requires the modification of (2.21).

2.4.1 Flux-Based boundary conditions (Neumann)

Neumann BC assess a positive or negative water flux along a certain partof the boundary. It consists in the introduction of a further source/sink termfor the cells that are adjacent to the boundary of the integration domain, andcan be accounted for with the following reformulation of the known termbi:

bi = Vi(ηni ) +∆tpiQ

ni −∆t

∑j∈Fi/Fi

∫λj

qL(ηni , x,y)h(ηni , x,y)dλj, (2.29)

where Fi is like Fi, but includes the boundary edges, thus Fi/Fi is thesubset of the edges of the i-th polygon belonging to the boundary andqL(η

ni , x,y) is the outgoing water flux (water discharge per unit vertical

area) normal to the boundary. The new source/sink term affects the numer-ical stability of the method, therefore, (2.28) needs to be modified to accountfor the outgoing water flux as follows:

∑i∈Ωd

Vi(ηni ) +∆t

∑i∈Ωd

piQni +

−∆t∑i∈Ωd

∑j∈Fi/Fi

∫λj

qL(ηni , x,y)h(ηni , x,y)dλj > 0 1 6 d 6 Nsd.

(2.30)

However, in this work, this type of BC is computed like a rating curve ofoutgoing water flux in every i-th cell. Thus equation (2.29) becomes:Implemented

Neumann boundaryconditions

bi = Vi(ηni ) +∆tpiQ

ni −∆t pi ci h(η

ni , x,y)mi . (2.31)

30

Page 39: Master thesis Francesco Serafin

2.4 boundary conditions

2.4.2 Head-Based boundary conditions (Dirichlet)

Dirichlet BC assign the time-variable value for η at some boundary or inter-nal cells according to a known function. Therefore, for any i cell belongingto the boundary:

ηn+1i = ηi(tn+1), (2.32)

where ˆηi(t) is an external forcing known a priori. Such i cells are calledDirichlet cells (DC). In this case, the non-linear system to be solved is formedby (2.32) for the DC and by (2.27) for the other cells. Therefore, such asystem has a non-linear part similar to (2.5), i.e. one resulting in a monotonicfunction of η but also having a linear part which is not symmetric. In fact,for a cell adjacent to a DC, the left-hand side of (2.27) depends on valuesfrom the DC. On the contrary, (2.32) does not contain any unknown valuesfrom neighboring cells. Because this asymmetry makes the new algebraicequation system different from (2.5), the procedure described in Appendixto solve it may not work correctly.It is possible to avoid this problem by splitting the matrix T , defined by (2.5),into two components:

T = TND + TD, (2.33)

where TND and TD are both symmetric matrices constructed as follows:

TNDij =

Tij if neither i-th nor j-th cells are DC

0 elsewhere, (2.34)

and

TDij =

Tij if either i-th or j-th cells are DC

0 elsewhere. (2.35)

The matrix TND contains information about the connection between cellsnot belonging to the boundary, whereas TD assumes non-zero values onlyin correspondence of DC. Then, (2.27) becomes:

Vi(ηn+1i ) +

Np∑i=1

TNDij ηn+1j +

Np∑i=1

TDij ηn+1j = bi. (2.36)

Equation (2.36) is applied to non-Dirichlet cell i; however TDij can assume ImplementedDirichlet boundaryconditions

non-null values only if j refers to a Dirichlet cell, therefore (2.36) can bere-arranged, using (2.32), as:

Vi(ηn+1i ) +

Np∑i=1

TNDij ηn+1j = bi −

Np∑i=1

TDij ηj(tn+1), (2.37)

where ηn+1j , related to DC domain, moves to the right-hand side becauseit is known. The final solver of the BEq is represented by the system (2.37)for all the non-DC. The matrix TND satisfies the appropriate T1 or T2 prop-erties defined in Appendix A and then (2.37) is solved with the proceduredescribed in Appendix A.

31

Page 40: Master thesis Francesco Serafin

the boussinesq’s groundwater equation

2.5 lesson to take home

The physical problem has now been explained, while PDE and numericalmethod have been analyzed in depth. To solve the problem, the domain isdivided in polygons organized in an orthogonal unstructured grid; BCs areevaluated as problem forcings.

The next step (and also the next chapter) is to implement all these featurein an object-oriented code. However, this has to be done through a well-planned structure, to be reused with several equations and eventually to beextended to other types of PDE such as the elliptic, the hyperbolic, etc.

32

Page 41: Master thesis Francesco Serafin

3S O F T WA R E I M P L E M E N TAT I O N

Contents3.1 Object-oriented unstructured mesh 36

3.1.1 First design step: find different ways of imple-mentation 36

3.1.2 Second design step: class hierarchy 37

3.1.3 Third step: the implementation 38

3.2 Object-oriented differential equations 41

3.2.1 First design step: find different implementationways 41

3.2.2 Second design step: class hierarchy 42

3.2.3 Third step: the implementation of the BEq 51

3.3 Input/output management 55

3.4 Conclusions 55

The parabolic PDE to be solved is given in Chapter 2, while the numeri-cal scheme used is summarized in Appendix A. Thus, the purpose of thischapter is to discuss a sensible object-oriented design that will implementthe numerical scheme. This means that a standard object-oriented structurewill be created. For it to become a template for the implementation of everytype of differential equation, the code must be easy to maintain, portableand reusable.

In so doing, it is essential to design a hierarchy of interfaces and abstractclasses that will guide the developer during the implementation of a numer-ical model. In this way, every developer only has to implement the functionsof his or her numerical problem, helped by a prearranged structure of meth-ods and classes.

To achieve all of this, the big problem must be split into three smallerones:

• the problem of the implementation of an unstructured mesh;

• the problem of creating a resolution wizard for any type of differ-ential equation, in particular, one that can implement parabolic PDE

solutions, with BEq as an application example;

• the problem of managing the input/output of scientific software in astandard way.

Definitions of abstract class/abstract method and interface are given here,so as to better understand the sections that follow (the information in thedefinitions is taken from [43, 38, 14]).

An abstract class is a class that contains abstract methods. It cannot be in- The definitions ofAbstract Class andAbstract Method

stantiated directly, and it may provide no implementation, or an incompleteimplementation. An abstract class is created when you want to manipulatea set of classes through their common interface.

33

Page 42: Master thesis Francesco Serafin

software implementation

Using the example about matrices presented in Section 1.2, an abstractclass may be DoubleMatrix2D.java, where it is possible to declare common vari-ables and abstract methods, or implement common methods of classes suchas DelegateDoubleMatrix2D.java, DenseDoubleMatrix2D.java, DiagonalDoubleMatrix2D.java, SelectedDenseDoubleMatrix2D, SparseDoubleMatrix2D.java, WrapperDoubleMatrix2D.java,etc. As a concrete example, the source code of Parallel Colt (see AppendixC on page 75), is shown in Listing 1, while Listing 2 represents the imple-mentation of abstract methods contained in the base class (the concepts ofbase class and derived classes have already been explained in paragraphIheritance of Subsection 1.2.2 on page 13).

Listing 1: Java implementation of the abstract class DoubleMatrix2D, summarized fromthe source code of Parallel Colt

1 /*2 Copyright (C) 1999 CERN - European Organization for Nuclear Research.

3 Permission to use, copy, modify, distribute and sell this software and

4 its documentation for any purpose is hereby granted without fee, provided

5 that the above copyright notice appear in all copies and that both that

6 copyright notice and this permission notice appear in supporting documentation.

7 CERN makes no representations about the suitability of this software for any

8 purpose. It is provided "as is" without expressed or implied warranty.

9 */

10 package cern.colt.matrix.tdouble;

11

12 public abstract class DoubleMatrix2D

13

14 /**15 * Return the maximum value of this matrix together with its location

16 *17 * @return maximum_value, row_location, column_location;

18 */

19 public double[] getMaxLocation()

20 int rowLocation = 0;

21 int columnLocation = 0;

22 double maxValue = 0;

23

24 // implementation omitted

25

26 return new double[] maxValue, rowLocation, columnLocation ;

27

28

29 /**30 * Construct and returns a new empty matrix of the same dynamic type

31 * as the receiver, having the specified number of rows and columns. For

32 * example, if the receiver is an instance of type

33 * DenseDoubleMatrix2D the new matrix must also be of type

34 * DenseDoubleMatrix2D, if the receiver is an instance of type

35 * SparseDoubleMatrix2D the new matrix must also be of type

36 * SparseDoubleMatrix2D, etc. In general, the new matrix should

37 * have internal parametrization as similar as possible.

38 *39 * @param rows

40 * the number of rows the matrix shall have.

41 * @param columns

42 * the number of columns the matrix shall have.

43 * @return a new empty matrix of the same dynamic type.

44 */

45 public abstract DoubleMatrix2D like(int rows, int columns);

46

47

It is easy to understand that Listing 1 is an abstract class, from the syntaxabstract at line 12. In this code there are two methods: the first (at lineThe sintax abstract

19) is an implemented method because the algorithm to find the location

34

Page 43: Master thesis Francesco Serafin

software implementation

of maximum value is the same for any type of matrix; the second (at line45) is an abstract method because no algorithm is given, rather it must beimplemented in the derived class. In this base class no variable has beeninstantiated.

Listing 2: Java implementation of the derived class DenseDoubleMatrix2D, summarizedfrom the source code of Parallel Colt

1 /*2 Copyright (C) 1999 CERN - European Organization for Nuclear Research.

3 Permission to use, copy, modify, distribute and sell this software and

4 its documentation for any purpose is hereby granted without fee, provided

5 that the above copyright notice appear in all copies and that both that

6 copyright notice and this permission notice appear in supporting documentation.

7 CERN makes no representations about the suitability of this software for any

8 purpose. It is provided "as is" without expressed or implied warranty.

9 */

10 package cern.colt.matrix.tdouble.impl;

11

12 public class DenseDoubleMatrix2D extends DoubleMatrix2D

13

14 protected double[] elements;

15

16 /**17 * this method is a builder: it constructs and returns a new empty matrix

18 * of type DoubleMatrix2D, having the specified number of rows and columns.

19 *20 * @param rows

21 * the number of rows the matrix shall have.

22 * @param columns

23 * the number of columns the matrix shall have.

24 * @return a new empty matrix of the same dynamic type

25 */

26 public DoubleMatrix2D like(int rows, int columns)

27 return new DenseDoubleMatrix2D(rows, columns);

28

29

30

It is easy to understand that Listing 2 is a derived class from the syntaxextends at line 12. This means that the class DenseDoubleMatrix2D.java is an The sintax extends

extension of DoubleMatrix2D.java because it can use all of the implementedmethods of the super class, and it has to implement those methods that aredeclared in the super class. Indeed, the method like(int rows, int columns)

is abstract in the super class, and it must be implemented here, returninga new DenseDoubleMatrix2D. In particular, the latter method is a builder [18].Quoting Wikipedia (2014b) [39] - The builder pattern is an object creation soft-ware design pattern. Unlike the abstract factory pattern and the factory methodpattern, whose intention is to enable polymorphism, the intention of the builder pat-tern is to find a solution to the telescoping constructor anti-pattern. The telescoping The Builder Pattern:

object creationsoftware designpattern

constructor anti-pattern occurs when the increase of object constructor parametercombination leads to an exponential list of constructors. Instead of using numerousconstructors, the builder pattern uses another object, a builder, that receives eachinitialization parameter step by step and the returns the resulting constructed objectat once-. The builder usually builds a class, but here the designer of ParallelColt thought it was better to operate in this way. At the same time, everyobject of type DenseDoubleMatrix2D.java has the method getMaxLocation().

The keyword interface takes the concept of abstractness one step further.While in an abstract class it is possible to implement a method, it is not Interface,

how to use itpossible in an interface, which allows the developer to determine method

35

Page 44: Master thesis Francesco Serafin

names, argument lists, and return types, but no method bodies. A classthat implements an interface must implement all the methods described inthe interface, only abstract class is not forced to implement all methods.Interfaces are a way to achieve polymorphism.

3.1 object-oriented unstructured mesh

A mesh to discretize the integration domain can be structured or unstruc-tured. The unstructured mesh is used in this work and is now analyzed indepth. However, an empty interface has been created providing a hierarchyin which one can include a structured mesh if desired (see Figure 7).

3.1.1 First design step: find different ways of implementation

This step allows the creation of the most general and basic structure,before implementing a class hierarchy for an object-oriented unstructuredmesh. Observing Figure 7, this elementary structure is created by findingall the possible ways to implement every element of the diagram.

MESH forNUMERICAL

METHOD

Structuredmesh

Unstructuredmesh

AdjacencyMatrix Based

NeighbourMatrices Based

Columncompressed

format

Rowcompressed

format

Tripletformat

Figure 7.: Basic structure of the class hierarchy to create a mesh for numerical meth-ods

In other words, if the behaviour of an element of the diagram, e.g. thestorage of the adjacency matrix, can be implemented in three different ways,Unstructured Mesh:

the idea behind thebasic structure of a

class hierarchy

then the same number of branches must start from the element. For exam-ple, still referring to Figure 7, an unstructured mesh can be implemented inat least in two ways: by adjacency matrix or by neighbour matrices1. This

1 The topological connection of the geometrical elements of an unstructured mesh can be de-scribed by neighbour matrices. In this manner, the elements of the grid are tagged with abso-

Page 45: Master thesis Francesco Serafin

3.1 object-oriented unstructured mesh

means that the “topological connection” behaviour of an unstructured meshcan be described in two different manners, thus two new branches have tostart from the Unstructured Mesh class.

The red arrows mark the choices made for this work: an unstructuredmesh to discretize the integration domain, using an adjacency matrix to Unstructured Mesh:

the branch developedin this work

describe the topological connection of the geometric elements, and storingthe matrix in row-compressed format. Obviously, just as the topologicalconnections can be described in different ways, the same adjacency matrixcan be stored in different compressed formats, e.g. column-compressed ortriplet format.

3.1.2 Second design step: class hierarchy

The next step is to fill the basic diagram in Figure 7 with abstract andimplemented methods to describe the behaviours of each element and thento assign the appropriate labels (interface or abstract class). The result is a Unstructured Mesh:

the design of theClass Hierarchy

class diagram that highlights the class hierarchy.Starting from the highest level of the diagram, the methods to describe

the features of an unstructured mesh are three:

• getGridProperties(): This method is useful in describing features strictlyrelated to the partition of the domain. This can be the number of poly-gons that cover the domain, the length of their edges, the euclideandistance between the barycentres of adjacent cells, etc. However, thismethod cannot be implemented yet, because the properties of a gridcan be computed by an algorithm or read from files received as outputfrom a mesh generator. These informations are typical of the problemanalyzed, so this method can be implemented only in derived classes,during the implementation of the mathematical model.

• getPolygonsProperties(): Surely, the physical problem to be solved hassome features that are discretized as properties of each polygon of themesh (e.g. piezometric head in a phreatic aquifer studied with thefinite volume method). However, this depends on which problem youare solving. Thus, this method can only be implemented in the codeof the model in analysis.

• getSidesProperties(): This method is like the previous method, but in-volves features that are discretized as properties of sides of each poly-gon of the mesh.

Thus, the behaviours of this class are known, but it is not possible to imple-ment them. UnstructuredMesh has to be an interface and, once implemented, itcan completely describe the physical properties of the integration domain.

Furthermore, there is the necessity to describe which polygons are con-nected to each other to simulate the evolution of the solution within thesystem. There are different ways to do that; here, adjacency matrix andneighbour matrices are quoted.

lute numbering, while the sides are tagged with local counter-clockwise numbering for eachpolygon. Thus, every edge has a double label, one for each neighbouring cell. The only way todescribe the topological connections is with two matrices with polygon numbers as columns,and side numbers as rows. The first matrix contains the polygon number which is adjacent tothe i-th polygon through the j-th side of the i-th polygon. The second matrix contains the sidenumber of the polygon which is adjacent to the i-th polygon through the j-th side of the i-thpolygon.

37

Page 46: Master thesis Francesco Serafin

software implementation

Thus, it is not possible to add a method directly into the UnstructuredMesh

interface to describe the topological connection, because the developer hasto have the opportunity to chose which is the best way to implement thisfeature within his model. It is better to create two other interfaces whichextend UntructuredMesh, inheriting all its methods. Then

• AdjacencyMatrixBased has the additional method getAdjacencyMatrix();

• NeighborMatricesBased has the additional methods getNeighborCell() andgetNeighborSide();

in order to describe the topological connections.The last and lowest level of the diagram in Figure 7 shows those elements

(Column compressed format, Row compressed format, Triplet format) thatcan be implemented as abstract classes:

• AbstractCCAdjacencyMatrixBasedMesh;

• AbstractRCAdjacencyMatrixBasedMesh;

• AbstractTripletAdjacencyMatrixBasedMesh;

Indeed, these inherit all the methods of the interface AdjacencyMatrixBased andcontain the declaration of the grid variables and those related to the adja-cency matrix, once the store format has been decided. For example, theclass Abstract TripletAdjacencyMatrixBasedMesh contains the integer Np as num-ber of polygons and the arrays lengthSides, euclideanDistance and planArea todescribe respectively the length of the sides of each polygon, the euclideandistance between the barycentres of adjacent cells, and the planimetric areaof each polygon; it contains the array Ti, Tj and Tl to describe the topologicalconnections in the triplet format (see Appendix B, Section B.1 on page 71).

However, the methods inherited from AdjacencyMatrixBasedInterface are stillabstract (without implementation). The reason for this is given in the nextparagraph. The resulting class diagram is shown in Figure 8.

3.1.3 Third step: the implementation

Now, to implement an unstructured mesh, you have to create a derivedclass, by extending the AbstractRCAdjacencyMatrixBased, and implement the in-Unstructured Mesh:

the implementationof the class hierarchy

herited methods inside it, declaring the new variables that you need.In this work, the derived class is still an abstract class due to the need

to implement a one-dimensional mesh and a two-dimensional mesh withinthe same code. Thus, as shown in Figure 9, all the variables used to definethe domain of a phreatic aquifer are declared in AbstractDomain.

In this way, you have the following advantages:

• writing as little code as possible because the derived classes containonly the implementation of the methods;

• dynamic binding because you can declare the object mesh as typeAbstractDomain, deciding which type of mesh to allocate only at run-time.

The two derived classes only contain the implementation of the methods:

38

Page 47: Master thesis Francesco Serafin

3.1 object-oriented unstructured mesh

Figure 8.: Abstract class hierarchy for unstructured meshes

39

Page 48: Master thesis Francesco Serafin

software implementation

Figure 9.: Class diagram for unstructured meshes in the BEq implementation

40

Page 49: Master thesis Francesco Serafin

3.2 object-oriented differential equations

• OneDimensionalDomain produces a one-dimensional mesh based on theadjacency matrix and stored in row-compressed format; the methodgetAdjacencyMatrix() computes three arrays, Mp, Mi, Ml, with an algorithm,while the other methods are used to compute the arrays of the domainproperties, assigning values manually.

• TwoDimensionalDomain produces a two-dimensional mesh by reading datafrom files. A more in-depth analysis of input data is done in Section3.3.

3.2 object-oriented differential equations

3.2.1 First design step: find different implementation ways

Realizing a standard structure to solve differential equations in OOP ismore complex than the work done in the previous section. By all means,it is equally possible to create a general and basic structure through the OO Differential

Equations: the ideabehind the basicstructure of the classhierarchy

research of all possible ways to implement every element of the diagram,shown in Figure 10. The red arrows mark the choices made in this work.

The first branch distinguishes between ODE and PDE:

• ODE is an equation containing a function of one independent variableand its derivatives;

• PDE is an equation containing unknown multivariable functions andtheir partial derivatives.

Focusing on second-order PDEs, these can be time dependent (parabolic and OO DifferentialEquations: thebranch developed inthis work

hyperbolic ones) or independent (elliptic one)2. Thus, only parabolic andhyperbolic PDEs have to be discretized in time, and to find the solutions ofthese equations a temporal loop and nested domain loop are required. Tofind the solution of an elliptic PDE, only a domain loop is required. So, thedifference in solving parabolic/hyperbolic equations rather than an ellipticone can be found in the necessity to implement a dynamic resolution, witha space-time evolution of the solution, rather than a static resolution, with asimple space evolution of the solution.

These three archetypal second-order PDEs can be written as:

2 Consider a second-order partial differential equation of the form

C :D2u+b ·Du+au = f in Ω,

with a symmetric coefficient matrix C(x); then the equation is said to be

a. elliptic at x ∈Ω if C(x) is positive definite, i.e., if for all v 6= 0 ∈ Rd, vTCv > 0.

b. parabolic at x ∈ Ω if C(x) is positive semidefinite (vTCv 6 0, for all v ∈ Rd) andnot positive definite and the rank of (C(x),b(x),a(x) is equal to d).

c. hyperbolic at x ∈Ω if C(x) has one negative and n− 1 positive eigenvalues.

By extension, an equation will be called elliptic, parabolic or hyperbolic in the open set Ω if it iselliptic, parabolic or hyperbolic everywhere in Ω.The terminology elliptic, parabolic and hyperbolic has also a geometric interpretation involvingplanar conics. Let us consider a linear second-order partial differential equation with constantcoefficients in R2 of the general form:

a∂2u

∂x2+b

∂2u

∂x∂y+ c

∂2

∂y2+d

∂u

∂x+ e

∂u

∂y+ fu = g in Ω.

The equation is said to be elliptic if b2− 4ac < 0, parabolic if b2− 4ac = 0 and hyperbolicif b2−4ac > 0. In practice, it is a distinction between time-dependent and time-independentPDEs. Often, elliptic equations are time-independent equations.

41

Page 50: Master thesis Francesco Serafin

software implementation

• elliptic PDE: ∇ ·D~∇u = f;

• parabolic PDE: αut = ∇ ·D~∇u+ f;

• hyperbolic PDE: αutt = ∇ ·D~∇u+ f;

where D is the diffusion tensor, f is the force term, u is the unknown term,ut is the first-order time derivative of the unknown term, utt is the second-order time derivative of the unknown term, α is the coefficient that multi-plies the time derivative of the unkown term.

Once defined the different types of second-order PDEs, the diagram inFigure 10 follows the development for resolving the parabolic PDE, becauseof the requirements of this work.

A parabolic PDE can be linear or non linear. This means that the matrixand array terms that compose the PDE (keeping out the array of unknowns)can be computed in two different manners:

• as a function of space and time in a linear equation;

• as a function of space, time and the unknown term, in a non linearequation.

The BEq is a parabolic non linear PDE. The integration domain is coveredby an unstructured grid – this offers more flexibility than structured gridbecause it is simpler to cover irregular shapes and beside, numerics in anunstructured grid are written independently from the shape of the mesh.

The three most widely used numerical methods to solve PDEs are theFinite Element Method (FEM), Finite Volume Methods (FVM) and Finite Dif-ference Methods (FDM).

Each method has typical features that are different from the others, thusit is necessary to follow different branches in the diagram 10.

Time dependence approaches can be explicit, semi-implicit or implicit andthis implies different ways to compute matrix and array terms as well as thesolution.

Finally, it is useful to establish in which format matrices have to be stored.Clearly, the format has to be the same chosen for the mesh, i.e. if the adja-cency matrix is stored in row-compressed format, then this is the format tobe used as standard to store every matrix computed within the code.

3.2.2 Second design step: class hierarchy

Implementing a class hierarchy from the diagram in Figure 10 is a longand complex work, which is beyond the scope of this thesis. This part, there-fore,remains incomplete, but the basic structure in Figure 10 is a good start-ing point from which to realize an operating package/library like ParallelColt (see Appendix C), to develop all different branches and to implementevery possible record. Obviously, this requires team work and much time,especially if you want also to implement complete numerical methods inabstract classes.

However, as an example of the benefits induced by a similar work, a draftOO DifferentialEquations: design ofthe Class Hierarchy

of a lower level of class hierarchy can be done for a non-linear parabolicPDE, discretized with an unstructured mesh and solved with a semi-implicitfinite volume method.

42

Page 51: Master thesis Francesco Serafin

3.2 object-oriented differential equations

PHYSICALPROBLEMS

ODEPDEDifferentialEquation

Time coordi-nate depen-dence

TIME INDE-PENDENT

(staticresolution)

ELLIPTIC∇ ·D~∇u = f

TIME DE-PENDENT(dynamicresolution)

HYPERBOLICαutt = ∇ ·D~∇u + f

PARABOLICαut = ∇ ·D~∇u+ f

Type of PDE

EquationLinearity Linear Non linear

Type of Mesh UnstructuredMesh

StructuredMesh

NumericalMethod

FiniteDifference

FiniteVolume

FiniteElement

Time depen-dent approach

Explicitmethod

Semi-implicitmethod

Implicitmethod

Compressionformat of Ma-trix

Denseformat

RowCompressed

format

ColumnCompressed

format

Tripletformat

Figure 10.: Basic structure of class hierarchy to solve differential equation

43

Page 52: Master thesis Francesco Serafin

software implementation

The elementary steps for the resolution of the PDE just described followsalgorithm 1.

Algorithm 1: Algorithm to implement a non-linear parabolic PDE

solved with a semi-implicit finite volume methodInput: initial conditionsOutput: solution to the physical problem

1 for time = 0 to endTime do

2 building of the PDE terms

3 while newton iteration convergence do

4 building of the linear system5 solve the linear system

6 end7 end

1. Building of the PDE terms: in a non-linear PDE, the terms are functionof the unknown term, so they have to be computed within the tem-poral loop. For a semi-implicit method, the PDE terms are built withthe solution computed at the preceding time step (they are built withinitial conditions at the first time step). Thus, the PDE is built at everytime step.

2. Building of the linear system: using an iterative method to solve theThe three elementarysteps for the

resolution of the PDElinear system, this has to be rebuilt at every iteration of the conver-gence method. So, this step is the second one met in the temporalloop, but the first in the nested solution convergence loop.

3. Implementation of the linear system solver: this is the last step ofthe algorithm. Once the solution of the linear system is found, if theresidual (computed as the modulus of the subtraction of the previoussolution and new solution) is less than the tolerance, the next time stepstarts; otherwise the convergence loop starts another iteration.

Building the PDE terms

Starting from the general form of a parabolic PDE

αut = ∇ ·D~∇u+ f, (3.1)

the result after spatial discretization can be like

MdU

dt+KU = L, (3.2)

where M results from the spatial integration of α, K results from the spatialintegration of D, applying the divergence theorem, and L is the result ofthe spatial integration of f. For example, the time discretization for a semi-implicit method gives:

MUn+1 −Un

∆t+KnUn+1 = ln, (3.3)

44

Page 53: Master thesis Francesco Serafin

3.2 object-oriented differential equations

MUn+1 +∆tKnUn+1 =MUn +∆tln, (3.4)

MUn+1 + TnUn+1 = bn. (3.5)

Therefore one has to compute three terms to build the PDE: two matrices(M, T ) and an array (b).

Storing matrices in row compressed form is an advantage because itmeans you can process matrices and arrays in almost the same way (asmatrices are stored as arrays). Thus, it is possible to create an abstract class The standard object

AbstractPdeTermAbstractPdeTerm as a standard object to build matrices and arrays indiscrimi-nately. In this class a boolean variable matrix is declared with two methods:

• computeArrayTerm(double[] u, AbstractRCAdjacencyMatrixBased mesh, int poly-

gonIndex): where it is possible to implement the function to build everyelement of the array term;

• computeMatrixTerm(double[] u, AbstractRCAdjacencyMatrixBased mesh, int poly-

gonIndex, int sideIndex) where it is possible to implement the functionto build every element of the matrix term.

For a better understanding, the code is shown in Listing 3.

Listing 3: Abstract class to build a PDE term

1 /*2 This class allows to initialize the object to fill the terms of the

3 matrices or arrays of the PDE. The boolean variable matrix has to be set

4 true for a matrix term, false for an array term. The function to compute

5 every element of an array has to be write inside the method computeArrayTerm.

6 Otherwise, the function to compute every element of a matrix has to be write

7 inside the method computeMatrixTerm.

8

9 @author: Francesco Serafin - 14 june 2014

10 @licence: GPL v 3.0

11 */

12 public abstract class AbstractPdeTerm

13

14 /**15 * this variable is true if the derived class is implemented for

16 * a matrix, otherwise it has to be false

17 */

18 public boolean matrix;

19

20 /**21 * this method has to be implemented with the function to compute

22 * every term of an array if the derived class is implemented for

23 * an array term

24 *25 * @param u

26 * array of unkown variable at the previous time step

27 * @param mesh

28 * the object of type AbstractRCAdjacencyMatrixBased

29 * @param polygonIndex

30 * the index of the polygon on which the term is computed

31 *32 * @return the computed term of the PDE

33 */

34 public abstract double computeArrayTerm(double[] u,

AbstractRCAdjacencyMatrixBased mesh, int polygonIndex);

45

Page 54: Master thesis Francesco Serafin

software implementation

35

36 /**37 * this method has to be implemented with the function to compute

38 * every term of a matrix if the derived class is implemented for

39 * a matrix term

40 *41 * @param u

42 * array of unkown variable at the previous time step

43 * @param mesh

44 * the object of type AbstractRCAdjacencyMatrixBased

45 * @param polygonIndex

46 * the index of the polygon on which the term is computed

47 * @param sideIndex

48 * the index of the side shared between the polygon

49 * polygonIndex and the adjacent polygon

50 *51 * @return the computed term of the PDE

52 */

53 public abstract double computeMatrixTerm(double[] u,

AbstractRCAdjacencyMatrixBased mesh, int polygonIndex, int sideIndex);

54

55

Thus, this class has to be extended as many time as the number of array ormatrix terms in the PDE. In this case, there are three derived classes: PdeTermM,PdeTermT, and PdeTermb. In the class PdeTermb, the variable matrix is false and theHow to use the

standard objectAbstractPdeTerm

function that describes the behaviour of b is implemented in computeArrayTerm

(), while computeMatrixTerm() remains empty or it even may return an errormessage if it is used accidentally. The opposite is true for classes PdeTermM

and PdeTermT. A matrix term is implemented as an example in Listing 4

because we are dealing with matrices.

Listing 4: Example of a class derived from AbstractPdeTerm to compute a matrix term

1 /*2 This class allows to initialize the object to fill the terms of the

3 matrices or arrays of the PDE. The boolean variable matrix has to be set

4 true for a matrix term, false for an array term. The function to compute

5 every element of an array has to be write inside the method computeArrayTerm.

6 Otherwise, the function to compute every element of a matrix has to be write

7 inside the method computeMatrixTerm.

8

9 @author: Francesco Serafin - 14 june 2014

10 @licence: GPL v 3.0

11 */

12 public class PdeTermT extends AbstractPdeTerm

13

14 /**15 * This constructor allows to define the type of the pdeTerm, by

16 * setting of the boolean variable matrix

17 *18 * It has to be set TRUE, if the derived class is a matrix,

19 * it has to be set FALSE, if the derived class is an array.

20 */

21 PdeTermT()

22 // this class is for a matrix term

23 matrix = true;

24

25

26 /**27 * this method has to be implemented with the function to compute

28 * every term of an array if the derived class is implemented for

29 * an array term

30 *31 * @param u

32 * array of unkown variable at the previous time step

46

Page 55: Master thesis Francesco Serafin

3.2 object-oriented differential equations

33 * @param mesh

34 * the object of type AbstractRCAdjacencyMatrixBased

35 * @param polygonIndex

36 * the index of the polygon on which the term is computed

37 *38 * @return the computed term of the PDE

39 */

40 public abstract double computeArrayTerm(double[] u,

AbstracRCAdjacencyMatrixBased mesh, int polygonIndex);

41

42 /**43 * this method has to be implemented with the function to compute

44 * every term of a matrix if the derived class is implemented for

45 * a matrix term

46 *47 * @param u

48 * array of unkown variable at the previous time step

49 * @param mesh

50 * the object of type AbstractRCAdjacencyMatrixBased

51 * @param polygonIndex

52 * the index of the polygon on which the term is computed

53 * @param sideIndex

54 * the index of the side shared between the polygon

55 * polygonIndex and the adjacent polygon

56 *57 * @return the computed term of the PDE

58 */

59 public abstract double computeMatrixTerm(double[] u,

AbstractRCAdjacencyMatrixBased mesh, int polygonIndex, int sideIndex)

60

61 // implementation of function to compute every single matrix entry

62

63

64

65

The resulting UML is shown in Figure 11.Therefore, in taking advantage of the dynamic binding and the row com- The advantage of the

Dynamic Bindingand of the RC-format

pressed format, any type of parabolic PDE term can be computed with afew lines of code. Indeed, to build the entire PDE, only one abstract class isnecessary, with four methods within it:

• temporalLoop(AbstractRCAdjacencyMatrixBased mesh): this method is the loopover simulation time and is not implemented in the abstract class;

• assemblePdeTerm(double[] u, AbstractRCAdjacencyMatrixBased mesh,AbstractPde-

Term pdeTerm): this method implements and calls the method assemble

Matrix() or assemblyArray() on the basis of the boolean matrix declaredwithin the object to process; this is possible thanks to polymorphism,because AbstractPdeTerm is the argument of the method and it can re-ceive a type PdeTermM, PdeTermT or PdeTermb without problems;

• assembleArray(double[] u, AbstractRCAdjacencyMatrixBased mesh, AbstractPde-

Term pdeTerm): this method is implemented and includes loop over poly-gons and then the call to computeArrayTerm();

• assembleMatrix(double[] u, AbstractRCAdjacencyMatrixBased mesh, AbstractPde-

Term pdeTerm): this method is implemented and includes loop over poly-gons, nested loop over adjacent polygons and then the call to compute

MatrixTerm().

The example code is shown in Listing 5.

47

Page 56: Master thesis Francesco Serafin

software implementation

Figure 11.: Class hierarchy to build the terms of the PDE (3.5)

48

Page 57: Master thesis Francesco Serafin

3.2 object-oriented differential equations

Listing 5: Abstract class AbstractPde, with implemented methods

1 /*2 This class allows to building the PDE.

3 The methods assembleArray and assembleMatrix are called in the method

4 assemblePdeTerm on the basis of the boolean variable matrix.

5 The method assemblePdeTerm is called inside the method temporalLoop

6 when a term of the PDE has to be assembled.

7

8 @author: Francesco Serafin - 14 june 2014

9 @licence: GPL v 3.0

10 */

11 public abstract class AbstractPde

12

13 /**14 * This method allows to assemble the arrays of the PDE. The for-loop calls

15 * the method computeArrayTerm to compute the terms of the array one for each

16 * polygon.

17 *18 * @param u

19 * array of unkown variable at the previous time step

20 * @param mesh

21 * the object of type AbstractRCAdjacencyMatrixBased

22 * @param pdeTerm

23 * the object for the term of the PDE

24 *25 * @return the filled array of the term of the PDE

26 */

27 public double[] assembleArray(double[] u, AbstractRCAdjacencyMatrixBased mesh,

AbstractPdeTerm pdeTerm)

28

29 double[] term = new double[mesh.polygonsNumber];

30

31 for (int i = 0; i < mesh.polygonsNumber; i++)

32 term[i] = pdeTerm.computeArrayTerm(u, mesh, i);

33

34

35 return term;

36

37

38 /**39 * This method allows to assemble the matrices of the PDE. The for-loop cycles

40 * through all polygons, the nested for-loop cycles through all the sides of

41 * i-th polygon. The nested loop is written in RC-form.

42 *43 * @param u

44 * array of unkown variable at the previous time step

45 * @param mesh

46 * the object of type AbstractRCAdjacencyMatrixBased

47 * @param pdeTerm

48 * the object for the term of the PDE

49 *50 * @return the filled matrix in RC-form of the PDE

51 */

52 public double[] assembleMatrix(double[] u, AbstractRCAdjacencyMatrixBased

mesh, AbstractPdeTerm pdeTerm)

53

54 double[] term = new double[mesh.Ml.length];

55

56 for (int i = 0; i < mesh.polygonsNumber; i++)

57 for (int j = mesh.Mp[i]; j < mesh.Mp[i + 1]; j++)

58 term[j] = pdeTerm.computeMatrixTerm(u, mesh, i, j);

59

60

61

62 return term;

63

49

Page 58: Master thesis Francesco Serafin

software implementation

64

65 /**66 * This method calls the method assembleMatrix or assemblyArray on the basis

67 * of the value of the boolean variable matrix of the object pdeTerm.

68 *69 * @param u

70 * array of unkown variable at the previous time step

71 * @param mesh

72 * the object of type AbstractRCAdjacencyMatrixBased

73 * @param pdeTerm

74 * the object for the term of the PDE

75 *76 * @return the filled term of the PDE (matrix or array independently)

77 */

78 public double[] assemblePdeTerm(double[] u, AbstractRCAdjacencyMatrixBased

mesh, AbstractPdeTerm pdeTerm)

79

80 double[] term;

81

82 if (term.matrix)

83 term = assembleMatrix(u, mesh, pdeTerm);

84 else

85 term = assemblyArray(u, mesh, pdeTerm);

86

87

88 return term;

89

90

91

92 /**93 * This method is an abstract one, because the temporal loop has to be

94 * implemented on the basis of the numerical method.

95 *96 * @param mesh

97 * the object of type AbstractRCAdjacencyMatrixBased

98 */

99 public abstract void temporalLoop(mesh);

100

101

Building of the linear system

To create an interface that assembles a linear system is quite difficult becauseyou need to know which terms fill the matrix of coefficients A and the arrayof solution b, in the form:

Ax = b. (3.6)

However, thanks to the row compressed format, the code is based on arrays,thus the methods can be:

• computeCoefficientsMatrix(double[] T, double[] u);

• computeSolutionArray(double[] T, double[] b, double[] u).

These two methods are called from inside a convergence method convergence

Method(double[] b, double[] T, double[] u, double tolerance), normally based onNewton’s method, which also calls the iterative linear system solver untilthe residual of the solution is less than the tolerance.

50

Page 59: Master thesis Francesco Serafin

3.2 object-oriented differential equations

Implementation of the linear system solver

There are several algorithms for solving a system of linear equations. Thereare direct methods, which solve the problem directly using A and b andproduce some intermediate matrices, and iterative methods, which solve theproblem starting with an initial guess and generating a sequence of iterativesolutions.

These algorithms are usually already implemented in open-source libraries,thus no specific interfaces are normally required.

3.2.3 Third step: the implementation of the BEq

OO DifferentialEquations: theimplementation ofthe class hierarchy

Here, the BEq developed in Chapter 2 is implemented, following the threesteps described in general form in the previous section.

Building of the BEq terms

As just shown in Section 2.3, after spatial and time discretization, theparabolic non linear BEq is written in the form:

V(ηn+1) + Tnηn+1 = bn. (3.7)

To solve equation (3.7), algorithm 1 becomes algorithm 2.

Algorithm 2: Algorithm to implement the non-linear parabolicBEq solved with a semi-implicit finite volume method withoutDirichlet BC

Input: initial conditions of the piezometric headOutput: piezometric head at the end of the simulation

1 for time = 0 to endTime do

2 building of T3 building of b

4 while newton iteration convergence do

5 building of Jr6 building of r

7 conjugate gradient method

8 end9 end

Matrix T and array b are built as functions of the solution computed at thepreceding time step (they are built with initial conditions at the first timestep). Thus, they are computed at the start of every temporary loop; thismeans that the BEq is rebuilt at every time step.

However, the implementation of the Dirichlet BCs in this numerical method The implementationof the Dirichlet BCs[5] requires a special treatise invented by Cordano and Rigon in [10] to fol-

low what is written in [3].As shown in equations (2.33), (2.34), and (2.35), you have to compute T

and then split it in two matrices TND and TD, which means that to assemblethe PDE you have to compute three matrix terms (T , TND and TD) and one

51

Page 60: Master thesis Francesco Serafin

software implementation

array term (b), as shown in the modified algorithm 3. This means that youhave to create four derived classes extending AbstractPdeTerm.

Algorithm 3: Modified algorithm to implement the non-linearparabolic BEq solved by a semi-implicit finite volume methodwith Dirichlet BC

Input: initial conditions of the piezometric headOutput: piezometric head at the end of the simulation

1 for time = 0 to endTime do

2 building of T

3 building of TND

4 building of TD

5 building of b

6 while newton iteration convergence do

7 building of Jr8 building of r

9 conjugate gradient method

10 end11 end

The method computeMatrixTerm() for the class PdeTermT has the array η as first in-put argument.Instead, the method computeMatrixTerm() for the classes PdeTermTnd

and PdeTermTd has T as first input argument, and not η, because they arecomputed by splitting T on the basis of the position of Dirichlet cells. How-ever, the type of the first argument used in method computeMatrixTerm() (seeListing 3) has not to changed, because T is also an array, thanks to the row-compressed storage format.

On the off chance that the problem studied does not present Dirichlet BCs,for time constraints, the simpler algorithm 2 is implemented in a separatecode. In this case, only the matrix term T and the array term b are computed.The resulting UML is shown in Figure 12.

Building of the BEq linear system

To assemble the linear system, you have to compute the matrix term A

and the array term b, that are respectively matrix term Jr and array term r

in the algorithms 2 and 3.Thus, in the inherited method computeCoefficientMatrix() the equation (A.6)

is implemented, while in computesolutionArray() the equation (A.3) is imple-mented. The resulting UML is shown in Figure 13.

Parallelized conjugate gradient as iterative linear system solver

This class is simply a call to the parallelized Conjugate Gradient (CG)method implemented in Parallel Colt [37].Parallelized

Conjugate Gradientand Preconditioner

A peculiarity of this library is the presence of different types of ready-to-use preconditioners. Usually, a preconditioning techniques greatly im-proves the convergence behaviour of the CG method because they reducethe number of iteration steps required (and in this work we tested the needto implement an available preconditioner: for example, the duration of asimulation changed from one day to about the time of a coffee break).

52

Page 61: Master thesis Francesco Serafin

3.2 object-oriented differential equations

Figure 12.: UML of the PDE assembly

53

Page 62: Master thesis Francesco Serafin

software implementation

Figure 13.: UML of linear system assembly

A preconditioned system, applied to a CG method, becomes:

C−1Ax = C−1b (3.8)

where C is the non singular matrix called the preconditioner. In general,this matrix should have the following properties:

• it should be a proper approximation of A, so that C−1A resemblesthe identity matrix (the most important quality of a preconditioner isto reduce the spectral condition number of the preconditioned matrixC−1A).

The properties of apreconditioner • The preconditioner should be cheap to compute.

• It should not require a large amount of storage.

In general, the application of the preconditioner will increase both the stor-age requirements and the computational labour in each iteration step. Nev-ertheless, it is often possible to solve the preconditioned system in far feweriteration steps than the unpreconditioned system, so that the total amountof the computational work is lowered [35].

The preconditioners implemented are:

• Double Diagonal preconditioner;

• Incomplete Cholesky Decomposition (ICC) preconditioner;

• Incomplete LU factorization (ILU) preconditioner;

• Incomplete LU Transpose factorization (ILUT) preconditioner.

54

Page 63: Master thesis Francesco Serafin

3.3 input/output management

3.3 input/output management

Input and output are managed through the OMS3 framework. Input dataare set up by a mesh generator, written in OMS3, that reads an .ascii filewith spatial distribution of the physical properties and returns the adjacencymatrix in row-compressed form and the problem features divided into gridproperties (length of each side of a polygon, euclidean distance betweenthe barycentres of adjacent cells), polygon properties (initial piezometrichead, Dirichlet boundary conditions, porosity, planar area, sources, bedrockelevation) and side properties (hydraulic conductivity). The output maps ofthe new piezometric head field are managed through JGrass Tools.

3.4 conclusions

In this chapter, it has been shown how important it is to have an abstractstructure that guides the developer during his work.

In fact, thanks to the class hierarchy developed here, if an environmen-tal engineer wants to implement a model involving the integration of aparabolic PDE (e.g. non linear heat conduction), he only has to focus onthe numerical discretization of the equation and on the writing of the dis-cretized functions inside the preimplemented structure. In a other words, itis almost like filling the empty spaces of a prescribed form.

Obviously, every model and numerical scheme have their peculiarities,but nothing stops the developer from overwriting a particular method orimplementing that specific part in a different manner.

55

Page 64: Master thesis Francesco Serafin
Page 65: Master thesis Francesco Serafin

4T E S T C A S E

Contents4.1 Analytical Non-linear Solution with planar topography 57

4.1.1 Analytical non-linear one-dimensional BoussinesqEquation 57

4.1.2 Comparison between analytical and numerical so-lution 59

4.1.3 Nondimensionalization & maximum norm com-putation 63

4.2 Conclusions 65

The best way to validate a numerical model is through the comparison ofthe numerical solution with an exact one.

Analytical solutions of the general non-linear Boussinesq Equation do notexist. Existing solutions are either approximated, usually by a linearizationof the flux term [4, 34], which corresponds to assuming a suitable, constant,value of the hydraulic transmissivity Ksh, or they are related to particu-lar cases. For instance, in the case of one-dimensional wetting processes anon-linear analytical solution exists based on similarity analysis [1, 26] andpower series expansion [32]. An implementation of these analytical solutionis available as an R package [8].

There are also two-dimensional analytical solutions for the linearizedBoussinesq Equation, obtained according to Hantush’s approximation, whichconsiders water table dynamics in a two-dimensional rectangular domainwith horizontal bedrock and pumping and/or bottom leakage processes [27,29]. However, in order to assess the performance of this solver, a one-dimensional solution on planar topography developed by Song et al. [32]is chosen. This is a one-dimensional time variable analytical solution of thefully non-linear equation on planar horizontal topography with a suddenincrease of water head at the boundary together with the exact steady-statesolution relative to the same problem.

4.1 analytical non-linear solution with planar topography

4.1.1 Analytical non-linear one-dimensional Boussinesq Equation

In this example, a horizontal one-dimensional unconfined aquifer, whichis initially dry, is analyzed with a head (Dirichlet) boundary condition ap-plied to the left border, where the pressure is assumed to increase suddenlyto a constant value η1, generating a wave which moves to the opposite bor-der (see Figure 14).

The Boussinesq Equation (2.4) can be written as:

s∂η

∂t=∂

∂x

[Ksh

∂η

∂x

], (4.1)

57

Page 66: Master thesis Francesco Serafin

test case

Figure 14.: Illustration of the physical problem [26]

with the following boundary condition:

η = η1 at x = 0, (4.2)

and the initial condition:

η(x) = 0, (4.3)

considering the domain infinite.The coexistence of wet and dry zones imposes solving equation (4.1) with-

out linearization. In order to obtain the solution, Song et al. [32] and Lock-ington et al. [26] defined a new spatial-temporal coordinate:

ξ = x

√2s

η1Kst. (4.4)

With this coordinate, the analytical solution obtained with equation (10) ofSong et al.’s paper becomes:

η =

η1∑∞n=0 an

(1− ξ

ξ0

)ηξ < ξ0

0 ξ > ξ0, (4.5)

where an is an infinite sequence of real numbers with the following proper-ties:

a0 = 0, (4.6)

and

∞∑n=0

an = 1, (4.7)

and the values of an are calculated with the following recurseve form:

(η+ 1)(η+ 2)

ξ20

n+2∑k=0

akan+2−k −n+ 1

2an+1 +

n

2an = 0, (4.8)

where ξ0 is a constant, related to the displacement of the wetting front,which is estimated such that (4.7) is verified. Equation (4.8) corresponds toequation (16) of Song et al.’s paper. Song et al. [32] gave an explicit form of(4.8) and fully described how to get the numerical values of the ξ0 and anterms.

58

Page 67: Master thesis Francesco Serafin

4.1 analytical non-linear solution with planar topography

4.1.2 Comparison between analytical and numerical solution

The comparison of the above solution with BEq is shown at different timesteps and for different values of the hydraulic conductivity. The left bound-ary condition η1 (x = 0) was set equal to 1 m, while the length of the domainwas set L = 1 000 m and the cell size of side 1 m. The porosity was set tos = 0.4, whereas four different values of saturated hydraulic conductivitywere tested: Ks = 10

−4 m/s; Ks = 10−3 m/s; Ks = 10

−2 m/s; Ks = 10−1 m/s.

The numerical time steps used were 360 s, 900 s, 1 800 s and 3 600 s. To sim-ulate an indefinitely long domain, a Neumann boundary condition was im-posed in the last cell (x = L) of the domain of the numerical model. Theassigned coefficients of the rating curve are:

c = 1; m = 1. (4.9)

The graphs shown from Figure 15 to 22 have to be seen in pairs: foreach pair, the first graph compares all numerical solutions, computed withdifferent time steps, with the analytical one, having fixed the duration ofthe simulation and the hydraulic conductivity; instead, the second graphcompares the single solutions for each time step, with analytical one.

In this chapter, the water surface profile is illustrated at 10 and 20 days,however the same graphs are shown in Appendix D for 5 and 15 days. Allgraphs from Figures 15 to 18 show that the numerical solutions are verysimilar to the analytical one, whatever time step you choose. In general,this is verified for the lower hydraulic conductivities (Ks = 10

−4, 10−3 m/s),

which happen to be the closest to real values of Ks. This feature can beobserved in graphs also in Appendix D in graphs 24, 26, 32, 34, 40 and 42.

0.00

0.25

0.50

0.75

1.00

0 10 20 30 40

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 10 days − KS = 0.0001 m s−1, s = 0.4

Figure 15.: Comparison between the numerical water tables computed with differenttime steps and with Ks = 10

−4 m/s and the analytical solution

It is possible to observe that the numerical wetting front anticipates theanalytical one (in red in Figure 16) only in the first wet cells at the boundarywith the dry domain. In general, after ten days with hydraulic conductivity

59

Page 68: Master thesis Francesco Serafin

test case

equal to 10−4 m/s , the numerical front comes to wet cell 26, while the

analytical front comes to wet the cell 24, with an admissible lag of 2 cells.

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 10 20 30 40 0 10 20 30 40

0 10 20 30 40 0 10 20 30 40

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 10 days − KS = 0.0001 m s−1, s = 0.4

Figure 16.: The numerical solutions computed with Ks = 10−4 m/s for each time

step are individually compared with the analytical solution

In the simulation with Ks = 10−3 m/s, shown in Figure 17 and 18, the

analytical solution corresponds to the numerical one. The lag between thewetting front of the analytical solution and the numerical one is computableat about 1 cell.

0.00

0.25

0.50

0.75

1.00

0 25 50 75

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 10 days − KS = 0.001 m s−1, s = 0.4

Figure 17.: Comparison between the numerical water tables computed with differenttime steps and with Ks = 10

−3 m/s and the analytical solution

60

Page 69: Master thesis Francesco Serafin

4.1 analytical non-linear solution with planar topography

In Figure 18, the perfect correspondence of every numerical simulationwith the exact analytical one is evident . In fact, it is difficult to distinguishthe two different lines in each plot.

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 25 50 75 0 25 50 75

0 25 50 75 0 25 50 75

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 10 days − KS = 0.001 m s−1, s = 0.4

Figure 18.: The numerical solutions computed with Ks = 10−3 m/s for each time

step are individually compared with the analytical solution

However, there are disagreements between numerical and exact analyticalsolutions with higher hydraulic conductivity (Ks = 10

−2 m/s and especiallywith Ks = 10

−1 m/s, an unrealistically high conductivity chosen to test alimit case), especially for higher time steps (3 600 s, 1 800 s) (see Figure 19).

0.00

0.25

0.50

0.75

1.00

0 50 100 150 200

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 10 days − KS = 0.01 m s−1, s = 0.4

Figure 19.: Comparison between the numerical water tables computed with differenttime steps and with Ks = 10

−2 m/s and the analytical solution

61

Page 70: Master thesis Francesco Serafin

test case

This is due to the fact that, according to the numerical scheme, the wettingfront can advance into one initially dry cell no more than once per time stepand, therefore, if the time step is relatively long, the displacement of thewetting front could be underestimated [10]. If the time step is not sufficientlyshort, the analytical wetting front anticipates the numerical one.

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 50 100 150 200 0 50 100 150 200

0 50 100 150 200 0 50 100 150 200

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 10 days − KS = 0.01 m s−1, s = 0.4

Figure 20.: The numerical solutions computed with Ks = 10−2 m/s for each time

step are individually compared with the analytical solution

All of this is very clear in Figure 20, with time step 3 600 s (the lag betweenthe two wet fronts is about 20 cells), but even moreso in Figures 21 and 22

in the simulations with time steps 900 s, 1 800 s and 3 600 s.

0.00

0.25

0.50

0.75

1.00

0 200 400 600

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 10 days − KS = 0.1 m s−1, s = 0.4

Figure 21.: Comparison between the numerical water tables computed with differenttime steps and with Ks = 10

−1 m/s and the analytical solution

62

Page 71: Master thesis Francesco Serafin

4.1 analytical non-linear solution with planar topography

In fact, the lag between the wet fronts of exact analytical solution and thenumerical one is almost null with time step 360 s, but it increases with timestep 900 s (39 cells), time step 1 800 s (270 cells) up to come to 510 cells withtime step 3 600 s.

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 200 400 600 0 200 400 600

0 200 400 600 0 200 400 600

Domain [m]

Pie

zo

me

tric

He

ad

[m

]Comparison between Song and Boussinesq solution

Simulation time: 10 days − KS = 0.1 m s−1, s = 0.4

Figure 22.: The numerical solutions computed with Ks = 10−1 m/s for each time

step are individually compared with the analytical solution

4.1.3 Nondimensionalization & maximum norm computation

A nondimensionalization of the one-dimensional BEq (4.1) is done in orderto realize an in-depth investigation of the maximum norm of the numericalsimulation.

Nondimensionalization is the partial or full removal of units from anequation involving physical quantities by a suitable substitution of vari-ables [46].

Thus, to fully remove the units from the equation (4.1), it is necessary todefine three physical quantities:

• a suitable time scale Ts;

• a suitable horizontal length scale Ls;

• a suitable vertical length scale η1.

The independent and dependent variables that have to be scaled are the timet, the length x, the piezometric head η and the aquifer thickness h. Thus,each of them has to be replaced with a quantity scaled towards the physicalquantities defined above:

t ′ =t

Ts; x ′ =

x

Ls; η ′ =

η

η1; h ′ =

f

η1. (4.10)

63

Page 72: Master thesis Francesco Serafin

test case

It is possible to obtain the independent and dependent variables throughinverting each equation in (4.10):

t = t ′ Ts; x = x ′ Ls; η = η ′ η1; h = h ′ η1. (4.11)

By applying definitions (4.11) the one-dimensional BEq is written in scaledform:

sη1Ts

∂η ′

∂t ′=1

Ls

∂x ′

[Ks h

′ η1η1Ls

∂η ′

∂x ′

], (4.12)

with constant hydraulic conductivity:

sη1Ts

∂η ′

∂t ′=Ks

Ls

η21Ls

∂x ′

[h ′∂η ′

∂x ′

](4.13)

sL2s

TsKsη1

∂η ′

∂t ′=

∂x ′

[h ′∂η ′

∂x ′

]. (4.14)

Now, it is necessary to choose Ls and Ts so that

sL2s

TsKsη1= 1. (4.15)

Imposing

Ls = η1, (4.16)

because the constant value at the left border is the unique reference as scalelength, it is possible to compute Ts from (4.15) as function of Ls:

Ts =η1Kss. (4.17)

By definition, Ts is the hydraulic response time. So, from this definition,what is the relation between time step and hydraulic response time to getthe optimal solution? The time step can be at most equal to the hydraulicresponse time.

Thus, imposing porosity s = 1 and hydraulic conductivity Ks = 1 m/s,with boundary condition η1 = 1 m, from equation (4.17) it is possibile tochose a time step

∆t 6 Ts = 1. (4.18)

In order to evaluate the error of the numerical method, the analytical andnumerical solutions are computed with time step ∆t = 1, ∆t = 0.1 and ∆t =0.01 in three different, non-dimensional, simulations of five days durationeach.

The error for each time step is computed as L∞ − norm (also called themaximum norm):

‖En‖∞ = max−∞6i6∞ |qni − q(xi, tn)|, (4.19)

64

Page 73: Master thesis Francesco Serafin

4.2 conclusions

where En is the global error computed as L∞ −norm, qni is the the approx-imation to the exact solution q(xi, tn) at time tn in the i-th cell.

0.0

0.1

0.2

0.3

0e+00 1e+05 2e+05 3e+05 4e+05

Time [s]

Lin

f−n

orm

[−

]

SimulationType

TIME STEP 0.01

TIME STEP 0.1

TIME STEP 1

Maximum norm between analytical and numerical solution

Error computed like maximum norm in nondimensional simulations

Figure 23.: Global error trend with time step ∆t = 1, ∆t = 0.1 and ∆t = 0.01

In Figure 23, it is possible to observe the global error trend as function ofthe simulation time. It is time-step independent and it is asymptotic to aconstant value equal to 0.003, ignoring the initial error which tends quicklyto the asymptote.

The result may seem unsatisfactory, in fact 3 mm over 1 m (this is thevalue of the left border Dirichlet BC) is an important error. However, thedisagreement between the numerical and analytical solution can be due tothe fact that the analytical solution is in fact not an exact one. Indeed, it isbased on similarity analysis (Barenblatt et al. [1] and Lockington et al. [26])and power series expansion (Song et al. [32]). Since the most important errorbetween numerical and analytical solution (visible in Figures 15 and 17) iscomputed in the incidence point of the wet fronts, this may be reduced byincreasing the terms computed in the Lockington et al. [26] series.

4.2 conclusions

In this chapter, the goodness of the implemented numerical method isshown through the comparison with an analytical solution. We obtain anerror of 0.003. However, we suppose that the global error might be smallerif the numerical solution is compared with a more accurate Lockington et al.[26] series expansion. In this case, this test proves that the “wetting-and-

65

Page 74: Master thesis Francesco Serafin

test case

drying” problem is solved rigorously, without the introduction of ad hocinternal iteration schemes.

The next goal is the application of this model to a real two-dimensionalcase, and the evaluation of the computational speed even using multipleprocessor machines.

66

Page 75: Master thesis Francesco Serafin

5S U M M A RY

The main purpose of this work was to apply modern informatics to theimplementation of numerical models which solve PDEs, in order to createshort, easily implementable, robust, manageable and portable codes.

In the first chapter, the most suitable base IT tools for the development ofmodern codes have been chosen and analyzed in depth. These tools allowto:

• work in teams, splitting the work to be done (UML) and sharing thework already done (DVCS);

• write short, readable, robust, correct, manageable, and documentedprograms (OOP & Java);

• have total control over previous tools using only one program (IDE &Eclipse).

To prove the advantages given by these tools, this complete environmenthas been applied to solve the PDE that describes an environmental phe-nomenon: the Boussinesq’s groundwater equation.

In the second chapter, the physical problem has been explained, whilePDE and numerical method have been analyzed in depth. To solve the prob-lem, the domain has been divided in polygons organized in an orthogonalunstructured grid; BCs have been evaluated as problem forcings.

In the third chapter, it has been shown how important it is to have anabstract structure that guides the developer during his work.

In fact, thanks to the class hierarchy developed here, if an environmen-tal engineer wants to implement a model involving the integration of aparabolic PDE (e.g. non linear heat conduction), he only has to focus onthe numerical discretization of the equation and on the writing of the dis-cretized functions inside the preimplemented structure.

Obviously, every model and numerical scheme have their peculiarities,but nothing stops the developer from overwriting a particular method orimplementing that specific part in a different manner.

For greater completeness, in the fourth chapter, the numerical methodhas been tested and the results have been shown through the comparisonwith an analytical solution. The error obtained was satisfactory. However,we suppose that the global error might be smaller if the numerical solu-tion is compared with a more accurate Lockington et al. [26] series expan-sion. In this case, this test proves that the “wetting-and-drying” problem hasbeen solved rigorously, without the introduction of ad hoc internal iterationschemes.

This is an open source project released under General Public License (GPL)v3, thus the entire code is available on-line in GitHub repositories.

The abstract class hierarchy designed to implement an unstructured meshdescribing topological connection through adjacency matrix can be found on

67

Page 76: Master thesis Francesco Serafin

summary

https://github.com/francescoS/ClassHierarchy_MeshNumericalMethods, whilethe abstract class hierarchy designed to implement a non linear parabolicPDE with a semi-implicit finite volume method can be found on https:

//github.com/francescoS/ClassHierarchy_NonLinearParabolicPDE.The example implemented to test the work realized can be found on

https://github.com/francescoS/javaBoussinesqEquation.

68

Page 77: Master thesis Francesco Serafin

AT H E S T R U C T U R E O F T H E N U M E R I C A L S O LV E RU T I L I Z E D

As derived in section 2.3, the spatial and temporal discretization methodconsists in reducing the free-surface hydrodynamic problem to an algebraicsystem of the following form:

V (

ξ ) + T ·

ξ =

b , (A.1)

whereξ = [ξ1, . . . , ξi, . . . , ξNp ]

T is the array of the unknown quantities

(one for each of the Np grid cells),b = [b1, . . . ,bi, . . . ,bNp ]

T is the array

of known parameters, andV (

ξ ) = [V1(ξ1), . . . ,Vi(ξi), . . . ,VNp(ξNp)]

T arethe values of the field conserved quantity, i.e. the water volume stored in thei-th cell. All of these “vectors” are denoted by the symbol · , or harpoon, todistinguish them from space vectors, denoted by ~· . T is a Np x Np matrixwhich satisfies one of the following properties [3]:

• T1: a Stieltjes matrix, i.e., a symmetric M-matrix;

• T2: a symmetric positive semidefinite matrix such that Ti,j 6 0 foreach i 6= j and

∑Npi=1 Ti,j = 0 [5];

System (A.1) can also be written with the following index notation:

Vi(ξi) +

Np∑j=1

Tijξj = bi (A.2)

for every i-th cell of the domain. This notation highlights that the i-th com-

ponent, Vi, of the conserved quantity vector,V , is solely a function of the

component ξi and, in the case analyzed in this paper, related to the i-th cellitself.

If the following residual function is defined:

R (

ξ ) :=

V (

ξ ) + T ·

ξ −

b (A.3)

solving (A.1) corresponds to seeking the zeros of the residual functionR (

ξ ).

Furthermore, when the Jacobian matrix of the residualR (

ξ ) is locally a

continuous, non-singular, Lipschitz matrix around the solutionξ , e.g. [23],

then the zeros of the residual function (i.e the solution of (A.1)) can be foundwith a Newton-like iterative method:

ξ

;m=

ξ

;m−1

− J−1R (

ξ

;m−1

) ·R (

ξ

;m−1

), (A.4)

where JR is the Jacobian matrix of the residual function, defined as:

J;mRlk:=∂Rl∂ξj

∣∣∣∣;m, (A.5)

69

Page 78: Master thesis Francesco Serafin

the structure of the numerical solver utilized

where l,k = 1, . . . ,Np and m (preceded by a semicolon) is the iteration levelof Newton’s method. An explicit calculation shows that JR is the sum of T ,which is symmetric and positive by definition, and the Jacobian matrix ofV (

ξ ), i.e.:

JR = T +P, (A.6)

with

Plk :=∂Vl∂ξj

∣∣∣∣;m, (A.7)

where “:=” indicates a definition (rather than an equality).If the volume Vi(ξi) (the conserved quantity) of a generic i-th grid ele-

ment is a non-decreasing function of the unknown variable ξi, and doesnot depend on the values of ξ in neighboring cells, then it can be shownthat P is a diagonal matrix with non-null entries that are all positive, whichcorrespond to the horizontal wet area of each cell, as will be shown in thenext section. In pratical applications, it is not computationally convenientto use (A.4) and then find the inverse of the Jacobian matrix, whose storagein memory can be overwhelming and time-expensive. Thus, equation (A.4)is usually solved by finding the solution fo r the associated linear system:

JR(ξ

;mN−1

) ·[ξ

;mN−1

−ξ

;mN]=

R (

ξ

;mN−1

), (A.8)

where the sparse Jacobian matrix, JR, can be used in a, so called, matrix-free implementation that is much less demanding, both computationallyand on storage. Given the symmetry of JR, the linear system (A.8) can beefficiently sloved with a preconditioned conjugate gradient method, e.g. [31].Under the conditions described above, the solution (A.1) is unique and itcan be proved that (A.4) converges to such solution with few iterations. Inparticular, when T is irreducible and satisfies the T2 property, the followingcondition needs to be satisfied [5]:

Np∑i=1

bi =

Np∑i=1

Vi(ξi) > 0, (A.9)

which means that no more water mass can be abstracted through sinks thanis present in the domain [3]. If T is reducible (i.e. not irreducible, the“wet” domain is decomposed into disconnected parts) and satisfies the T2

property, then (A.9) must be changed into the following scalar product [3]:

v ·

b =

Np∑i=1

vibi > 0, (A.10)

for eachv , eigenvector T , giving a null eigenvalue:

T ·v = 0 (A.11)

70

Page 79: Master thesis Francesco Serafin

BH O W T O S T O R E S PA R S E M AT R I C E S

A sparse matrix is a matrix mostly composed by zeros as elements of thetable. The fraction of zero elements in a matrix is called sparsity [49].

The adjacency topological matrix Mij, used in this work, is a sparse ma-trix because entries are mostly zero.

Mij =

Np x Np 0 1 2 3 4 5 6 7

0 −1 1 0 0 0 0 0 9

1 1 −1 2 0 0 0 0 0

2 0 2 −1 3 0 0 8 0

3 0 0 3 −1 4 0 0 0

4 0 0 0 4 −1 5 0 0

5 0 0 0 0 5 −1 6 0

6 0 0 8 0 0 6 −1 7

7 9 0 0 0 0 0 7 −1

. (B.1)

Therefore, it’s necessary a specialized compact data structure that allowsto avoid to store the numerically zero entries of the matrix. The main reasonis the growth of computational time, because dense-matrix structures andalgorithms are relatively slow and consume large amounts of memory whenapplied to large sparse matrices [49].

There are several ways to compress sparse data, and these are well de-scribed in [13, 19]. All of this need to be simple and flexible to be used in awide range of matrix operations.

The two most important matrix data structures are the triplet form and thecompressed-row form1.

b.1 triplet form

As reported in [13], this is the simplest sparse matrix data structure andconsists of two integer arrays Ti and Tj and one real array Tl of length equalto the number of non-zero entries in the matrix.

To allocate a sparse matrix, the k-th entry has row index ik = Ti[k], col-umn index jk = Tj[k], and numerical value mij = Tl[k]. The entries canappear in arbitrary order. Following, the example related to matrix (B.1).

Ti =[0, 1, 7, 0, 1, 2, 1, 2, 3, 6, 2, 3, 4, 3, 4, 5, 4, 5, 6, 2, 5, 6, 7, 0, 6, 7

](B.2)

Tj =[0, 1, 7, 0, 1, 2, 1, 2, 3, 6, 2, 3, 4, 3, 4, 5, 4, 5, 6, 2, 5, 6, 7, 0, 6, 7

](B.3)

Tl =[−1, 1, 9, 1,−1, 2, 2,−1, 3, 8, 3,−1, 4, 4,−1, 5, 5,−1, 6, 8, 6,−1, 7, 9, 7,−1

](B.4)

1 There is also the compressed-column form: it’s equal to the compressed-row form, but the columnsare compressed and not the rows.

71

Page 80: Master thesis Francesco Serafin

how to store sparse matrices

b.2 compressed-row form

As seen in the previuos section, triplet form is very simple to create, butit’s difficult to use in most sparse matrix algoriths.

The best alternative is the Compressed-Row form, that can be more com-pressed and faster during the computation. In this case, the data structureconsists of two integer arrays Mp and Mj and one real array Ml. Consider-ing an m-by-n sparse matrix that can contain up nzmax entries:

• the array Mp of length m+ 1 contains the row pointers, the first entryp[0] is always zero, and p[n] 6 nzmax is the number of actual entriesin the matrix;

• the array Mi of length nzmax contains column indices of entries inrow i, stored in Mi[Mp[i]] through Mi[Mp[i+ 1] − 1];

• the array Ml of length nzmax contains the numerical values stored inthe corresponding location of Mi;

Thus, converting the sparse adjacency topological matrix in this format, youget this result:

Mp =[0, 3, 6, 10, 13, 16, 19, 23, 26

](B.5)

Mi =[0, 1, 7, 0, 1, 2, 1, 2, 3, 6, 2, 3, 4, 3, 4, 5, 4, 5, 6, 2, 5, 6, 7, 0, 6, 7

](B.6)

Ml =[−1, 1, 9, 1,−1, 2, 2,−1, 3, 8, 3,−1, 4, 4,−1, 5, 5,−1, 6, 8, 6,−1, 7, 9, 7,−1

](B.7)

b.3 matrix-vector multiplication

Obviously, the choice between the two formats fells on the last presented,due both to the lower memory consumption in storing the sparse matrixand both in time a loop takes to scroll all the matrix entries.

In this work is used only one of the simplest sparse matrix algorithms:the matrix-vector multiplication, y = Ax, where x,y are dense vectors andA is sparse. Considering the compressed-row form, this product involves onlytwo arrays, so results like:

y =[A∗1 . . . A∗n

]x1...

xn

(B.8)

The pseudocode to compute this operation is the following. It easy tounderstand that it’s unuseful multiplicate a null entry of sparse matrix for

72

Page 81: Master thesis Francesco Serafin

B.3 matrix-vector multiplication

the corresponding value in dense array. Thus, the product occurs only whenthe elements of the sparse matrix are non-zeros.

Algorithm 4: Matrix-vector multiplicationInput: dense array x with n-1 rows, sparse matrix A with

nzmax entriesOutput: dense array y with n-1 rows

1 for i = 0 to n − 1 do2 foreach j for which aij 6= 0 do3 yj = yj + aijxi4 end5 end

What is need to transform Algorithm 4 in a functioning code are thetwo dense arrays Mp and Mi, closely related to the sparse matrix Ml incompressed-row form; thus in Java language becomes:

Listing 6: Java code for matrix-vector multiplication

1 // cicle through all elements of dense arrays

2 for (int i = 0; i < Np; i++)

3

4 //cicle through all elements of sparse matrix

5 for (int j = Mp[i]; j < Mp[i+1]; j++)

6

7 // storing values in right position of the dense array of solution

8 y[Mi[j]] += Ml[j] * x[i];

9

10

11

12

73

Page 82: Master thesis Francesco Serafin
Page 83: Master thesis Francesco Serafin

CA B O U T O P E N S O U R C E J AVA M AT R I C E S L I B R A R I E S -F O C U S I N G O N PA R A L L E L C O LT

Before Java 5, this language was ignored by the scientific community,above all for its limits of youth and for its primitive version of compilersand JVM, which made it unsuitable to numerical models. The launch of Java5 (September 30, 2004) drew the attention of the scientific community, thusmathematical libraries grew in number and computational efficiency.

The most famous numerical libraries are listed in [45], here reported forcompleteness:

• Apache Commons: an open source library for creating reusable javacomponents, it includes numerical packages for linear algebra andnon-linear optimization;

• Colt: an open source libraries for High Performance Scientific andTechnical Computing;

• Efficient Java Matrix Library (EJML): an open source linear algebralibrary for manipulating dense matrices;

• JAMA: a numerical linear algebra toolkit for the Java programminglanguage;

• Jblas: a linear algebra library which is an easy to use wrapper aroundBLAS and LAPACK;

• Parallel Colt: an open source library for scientific computing (parallelextension of Colt);

• SCaVIS: an open source libraries for numerical calculationss, data I/Oand visualisation of scientif results (to use together with Jython);

• JMSL Numerical Libraries: a comprehensive set of mathematical, sta-tistical, data mining, financial and 2D/3D charting classes;

• Matrix Toolkit Java: a linear algebra library based on BLAS and LA-PACK;

• Universal Java Matrix Package (UJM): a library which provides im-plementations for sparse and dense matrices, as well as linear algebracalculations such as matrix decomposition, inverse, multiply, mean,correlation, standard deviation, etc.

• Java Matrix Library: a thoughfully designed Java library for dealingwith matrices;

• JDistLib Java Statistical Distribution Library: provides routines forvarious statistical distribtuions.

The most interesting set of libraries is Parallel Colt, mainly for the followingtwo reasons:

1. they implement the theory explained in two cornerstones like [13, 19];

75

Page 84: Master thesis Francesco Serafin

about open source java matrices libraries - focusing on parallel colt

2. this type of library is designed to exploit the all-potential of today’sCPU1.

Examine in depth the first item, Parallel Colt are the multithreaded versionof Colt2, thus it contains all the original capabilities of the library fromwhich to hail from and adds several new ones. The original capabilitiesare among other, usable data structures algorithms for off-line and on-linedata analysis, statistics, histogramming, Monte Carlo simulation, but aboveall [41]:

• multi-dimensional matrices: dense and sparse fixed sized (non-resizable)1,2,3 and d-dimensional matrices, holding objects or primitive datatypes such as int, double, etc.;

• linear algebra: standard matrix operations and decompositions.

The newer capabilities are strongly related to the second point of the numer-ical list, because the most important concern multi-threaded algorithms:

• specialized matrix data structures;

• JPlasma: java port of PLASMA (Parallel Linear Algebra for ScalableMulti-core Architectures);

• CSparseJ: java port of CSparse (a Concise Sparse matrix package);

• solvers and preconditioners; mostly adapted from matrix toolkit Java;

• parallel quicksort algorithm.

Finally, Parallel Colt is a set of multithreaded library very interesting, espe-cially in scientific field. The fact that it is an open source project, it givesthe chance to develop and to extend the library to everyone. More infor-mations and source code are available on Parallel Colt official site https:

//sites.google.com/site/piotrwendykier/software/parallelcolt.

1 As reported in [37], until few years ago, there was a real clock race in order to improve CPUperformance increasing clock speed, execution optimization, and the size of on-chip cache.However, in 2003, chip manufacturers realized that physical limit was reached due to increasingheat generation, power consumption and lack of suitable cooling hardware. Thus, a new erain CPU manufacturing begun in October 2001, when IBM releas the POWER4 micro-processor,the first multi-core processor ever. Since then, all new processors have been designed to consistof two or more indipendent cores on a single die. So, the best way to maximize the use ofmodern hardware architectures is parallelizing software, above to reduce computational timein numerical simulation.

2 Colt is a set of open source libraries for High Performance Scientific and Technical Computingwritten in Java and developed at Cern

76

Page 85: Master thesis Francesco Serafin

DO T H E R C O M PA R I S O N S B E T W E E N A N A LY T I C A L A N DN U M E R I C A L S I M U L AT I O N S

77

Page 86: Master thesis Francesco Serafin

other comparisons between analytical and numerical simulations

d.1 simulations at 5 days

0.00

0.25

0.50

0.75

1.00

0 10 20

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 5 days − KS = 0.0001 m s−1, s = 0.4

Figure 24.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−4 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 10 20 0 10 20

0 10 20 0 10 20

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 5 days − KS = 0.0001 m s−1, s = 0.4

Figure 25.: The numerical solution computed with Ks = 10−4 m/s for every time

step is individually compared with the analytic solution

78

Page 87: Master thesis Francesco Serafin

D.1 simulations at 5 days

0.00

0.25

0.50

0.75

1.00

0 25 50 75

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 5 days − KS = 0.001 m s−1, s = 0.4

Figure 26.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−3 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 25 50 75 0 25 50 75

0 25 50 75 0 25 50 75

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 5 days − KS = 0.001 m s−1, s = 0.4

Figure 27.: The numerical solution computed with Ks = 10−3 m/s for every time

step is individually compared with the analytic solution

79

Page 88: Master thesis Francesco Serafin

other comparisons between analytical and numerical simulations

0.00

0.25

0.50

0.75

1.00

0 50 100 150

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 5 days − KS = 0.01 m s−1, s = 0.4

Figure 28.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−2 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 50 100 150 0 50 100 150

0 50 100 150 0 50 100 150

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 5 days − KS = 0.01 m s−1, s = 0.4

Figure 29.: The numerical solution computed with Ks = 10−2 m/s for every time

step is individually compared with the analytic solution

80

Page 89: Master thesis Francesco Serafin

D.1 simulations at 5 days

0.00

0.25

0.50

0.75

1.00

0 100 200 300 400 500

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 5 days − KS = 0.1 m s−1, s = 0.4

Figure 30.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−1 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 100 200 300 400 500 0 100 200 300 400 500

0 100 200 300 400 500 0 100 200 300 400 500

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 5 days − KS = 0.1 m s−1, s = 0.4

Figure 31.: The numerical solution computed with Ks = 10−1 m/s for every time

step is individually compared with the analytic solution

81

Page 90: Master thesis Francesco Serafin

other comparisons between analytical and numerical simulations

d.2 simulations at 15 days

0.00

0.25

0.50

0.75

1.00

0 10 20 30

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 15 days − KS = 0.0001 m s−1, s = 0.4

Figure 32.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−4 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 10 20 30 0 10 20 30

0 10 20 30 0 10 20 30

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 15 days − KS = 0.0001 m s−1, s = 0.4

Figure 33.: The numerical solution computed with Ks = 10−4 m/s for every time

step is individually compared with the analytic solution

82

Page 91: Master thesis Francesco Serafin

D.2 simulations at 15 days

0.00

0.25

0.50

0.75

1.00

0 25 50 75

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 15 days − KS = 0.001 m s−1, s = 0.4

Figure 34.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−3 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 25 50 75 0 25 50 75

0 25 50 75 0 25 50 75

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 15 days − KS = 0.001 m s−1, s = 0.4

Figure 35.: The numerical solution computed with Ks = 10−3 m/s for every time

step is individually compared with the analytic solution

83

Page 92: Master thesis Francesco Serafin

other comparisons between analytical and numerical simulations

0.00

0.25

0.50

0.75

1.00

0 100 200

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 15 days − KS = 0.01 m s−1, s = 0.4

Figure 36.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−2 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 100 200 0 100 200

0 100 200 0 100 200

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 15 days − KS = 0.01 m s−1, s = 0.4

Figure 37.: The numerical solution computed with Ks = 10−2 m/s for every time

step is individually compared with the analytic solution

84

Page 93: Master thesis Francesco Serafin

D.2 simulations at 15 days

0.00

0.25

0.50

0.75

1.00

0 250 500 750

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 15 days − KS = 0.1 m s−1, s = 0.4

Figure 38.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−1 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 250 500 750 0 250 500 750

0 250 500 750 0 250 500 750

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 15 days − KS = 0.1 m s−1, s = 0.4

Figure 39.: The numerical solution computed with Ks = 10−1 m/s for every time

step is individually compared with the analytic solution

85

Page 94: Master thesis Francesco Serafin

other comparisons between analytical and numerical simulations

d.3 simulations at 20 days

0.00

0.25

0.50

0.75

1.00

0 10 20 30

Domain [m]

Pie

zo

me

tric

He

ad

[m

]simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 20 days − KS = 0.0001 m s−1, s = 0.4

Figure 40.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−4 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 10 20 30 0 10 20 30

0 10 20 30 0 10 20 30

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 20 days − KS = 0.0001 m s−1, s = 0.4

Figure 41.: The numerical solution computed with Ks = 10−4 m/s for every time

step is individually compared with the analytic solution

86

Page 95: Master thesis Francesco Serafin

D.3 simulations at 20 days

0.00

0.25

0.50

0.75

1.00

0 30 60 90

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 20 days − KS = 0.001 m s−1, s = 0.4

Figure 42.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−3 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 30 60 90 0 30 60 90

0 30 60 90 0 30 60 90

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 20 days − KS = 0.001 m s−1, s = 0.4

Figure 43.: The numerical solution computed with Ks = 10−3 m/s for every time

step is individually compared with the analytic solution

87

Page 96: Master thesis Francesco Serafin

other comparisons between analytical and numerical simulations

0.00

0.25

0.50

0.75

1.00

0 100 200 300

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 20 days − KS = 0.01 m s−1, s = 0.4

Figure 44.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−2 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 100 200 300 0 100 200 300

0 100 200 300 0 100 200 300

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 20 days − KS = 0.01 m s−1, s = 0.4

Figure 45.: The numerical solution computed with Ks = 10−2 m/s for every time

step is individually compared with the analytic solution

88

Page 97: Master thesis Francesco Serafin

D.3 simulations at 20 days

0.00

0.25

0.50

0.75

1.00

0 250 500 750 1000

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

simulationTimeStep

0360.txt

0900.txt

1800.txt

3600.txt

song.txt

Comparison between Song and Boussinesq solution

Simulation time: 20 days − KS = 0.1 m s−1, s = 0.4

Figure 46.: Comparison between the numerical water table computed at several timesteps with Ks = 10

−1 m/s and the analytical solution

0360.txt 0900.txt

1800.txt 3600.txt

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0.00

0.25

0.50

0.75

1.00

0 250 500 750 1000 0 250 500 750 1000

0 250 500 750 1000 0 250 500 750 1000

Domain [m]

Pie

zo

me

tric

He

ad

[m

]

Comparison between Song and Boussinesq solution

Simulation time: 20 days − KS = 0.1 m s−1, s = 0.4

Figure 47.: The numerical solution computed with Ks = 10−1 m/s for every time

step is individually compared with the analytic solution

89

Page 98: Master thesis Francesco Serafin
Page 99: Master thesis Francesco Serafin

B I B L I O G R A P H Y

[1] Barenblatt, G. I., Entov, V. M., and Ryzhik, V. (1989). Theory of fluidflows through natural rocks.

[2] Bear, J. (1988). Dynamics of fluids in porous media. American ElsevierPublishing Company.

[3] Brugnano, L. and Casulli, V. (2008). Iterative solution of piecewise linearsystems. SIAM Journal on Scientific Computing, 30(1):463–472.

[4] Brutsaert, W. (1994). The unit response of groundwater outflow from ahillslope. Water Resources Research, 30(10):2759–2763.

[5] Casulli, V. (2009). A high-resolution wetting and drying algorithm forfree-surface hydrodynamics. International Journal for Numerical Methods inFluids, 60(4):391–408.

[6] Casulli, V. and Walters, R. A. (2000). An unstructured grid, three-dimensional model based on the shallow water equations. InternationalJournal for Numerical Methods in Fluids, 32(3):331–348.

[7] Chacon, S. (2009). Pro Git. Books for professionals by professionals.Apress.

[8] Cordano, E. (2011). boussinesq: Analytic solutions for (ground-water)boussinesq equation.

[9] Cordano, E. and Rigon, R. (2008). A perturbative view on the subsur-face water pressure response at hillsplope scale. Water Resources Research,W05407(44).

[10] Cordano, E. and Rigon, R. (2013). A mass-conservative method for theintegration of the two-dimensional groundwater (boussinesq) equation.Water Resources Research, 49(2):1058–1078.

[11] Dagan, G. (1989). Flow and transport in porous formations. Springer-Verlag.

[12] David, O., Ascough Ii, J., Lloyd, W., Green, T., Rojas, K., Leavesley, G.,and Ahuja, L. (2013). A software engineering perspective on environmen-tal modeling framework design: The object modeling system. Environ-mental Modelling & Software, 39:201–213.

[13] Davis, T. (2006). Direct Methods for Sparse Linear Systems. Fundamentalsof Algorithms. Society for Industrial and Applied Mathematics.

[14] Eckel, B. (2003). Thinking in JAVA. Prentice Hall Professional.

[15] Formetta, G. (2013). Hydrological modelling with components: the OMS3NewAge-JGrass system. PhD thesis, University of Trento.

[16] Formetta, G., Antonello, A., Franceschi, S., David, O., and Rigon, R.(2014). Hydrological modelling with components: A gis-based open-source framework. Environmental Modelling & Software, 55:190–200.

91

Page 100: Master thesis Francesco Serafin

Bibliography

[17] Fowler, M. (2004). UML Distilled: A Brief Guide to the Standard ObjectModeling Language. Addison-Wesley object technology series. Addison-Wesley.

[18] Gamma, E., Helm, R., Johnson, R., and Vlissides, J. (1994). Designpatterns: elements of reusable object-oriented software. Pearson Education.

[19] Golub, G. and Van Loan, C. (2012). Matrix Computations. Matrix Com-putations. Johns Hopkins University Press.

[20] Hale, D. (2006). The java and cpp platforms for scientific computing.

[21] Harbaugh, A. W., Banta, E. R., Hill, M. C., and McDonald, M. G.(2000). MODFLOW-2000, the US Geological Survey modular ground-watermodel: User guide to modularization concepts and the ground-water flow pro-cess. US Geological Survey Denver, CO, Reston, VA.

[22] Harman, C. and Sivapalan, M. (2009). Effects of hydraulic conductiv-ity variability on hillslope-scale shallow subsurface flow response andstorage-discharge relations. Water resources research, 45(1).

[23] Kelley, C. (2003). Solving Nonlinear Equations with Newton’s Method. Fun-damentals of Algorithms. Society for Industrial and Applied Mathemat-ics.

[24] Lanni, C., Borga, M., Rigon, R., and Tarolli, P. (2012). Modelling shallowlandslide susceptibility by means of a subsurface flow path connectivityindex and estimates of soil depth spatial distribution. Hydrology and EarthSystem Sciences, 16(11):3959–3971.

[25] Lanni, C., McDonnell, J., and Rigon, R. (2011). On the relative role of up-slope and downslope topography for describing water flow path and stor-age dynamics: a theoretical analysis. Hydrological Processes, 25(25):3909–3923.

[26] Lockington, D., Parlange, J.-Y., Parlange, M., and Selker, J. (2000). Sim-ilarity solution of the boussinesq equation. Advances in water resources,23(7):725–729.

[27] Manglik, A. and Rai, S. (2000). Modeling of water table fluctuationsin response to time-varying recharge and withdrawal. Water resourcesmanagement, 14(5):339–347.

[28] Painter, S., Basagaoglu, H., and Liu, A. (2008). Robust representationof dry cells in single-layer modflow models. Ground water, 46(6):873–881.

[29] Rai, S., Manglik, A., and Singh, V. (2006). Water table fluctuation ow-ing to time-varying recharge, pumping and leakage. Journal of hydrology,324(1):350–358.

[30] Reitbauer, A., Enzenhofer, K., Grabner, A., Kopp, M., Pierzchala, S.,and Wilson, S. (2012). Java enterprise performance - the impact of garbagecollection on application performance. http://javabook.compuware.com/content/start.aspx.

[31] Shewchuk, J. R. (1994). An introduction to the conjugate gradientmethod without the agonizing pain. Technical report, Pittsburgh, PA,USA.

92

Page 101: Master thesis Francesco Serafin

Bibliography

[32] Song, Z.-y., Li, L., and David, L. (2007). Note on barenblatt powerseries solution to boussinesq equation. Applied Mathematics and Mechanics,28(6):823–828.

[33] Text Analysis Internation, I. (2001). Integrated development environmentsfor natural language processing.

[34] Troch, P. A., Van Loon, A. H., and Hilberts, A. G. (2004). Analyticalsolution of the linearized hillslope-storage boussinesq equation for expo-nential hillslope width functions. Water resources research, 40(8).

[35] van der Ploeg, A. (1994). Preconditioning for sparse matrices withapplications. Master’s thesis, Rijksuniversiteit Groningen.

[36] Vogel, L. (2013). Eclipse IDE: Java Programming, Debugging, Unit Test-ing, Task Management and Git Version Control with Eclipse. vogella series.Vogella.

[37] Wendykier, P. and Nagy, J. G. (2010). Parallel colt: A high-performancejava library for scientific computing and image processing. ACM Transac-tions on Mathematical Software (TOMS), 37(3):31.

[38] Wikipedia (2014a). Abstract type. http://en.wikipedia.org/wiki/

Abstract_type.

[39] Wikipedia (2014b). Builder pattern. http://en.wikipedia.org/wiki/

Builder_pattern.

[40] Wikipedia (2014c). Class diagram. http://en.wikipedia.org/wiki/

Class_diagram.

[41] Wikipedia (2014d). Colt (libraries). http://en.wikipedia.org/wiki/

Colt_(libraries).

[42] Wikipedia (2014e). Integrated development environment. http://en.

wikipedia.org/wiki/Integrated_development_environment.

[43] Wikipedia (2014f). Interface (java). http://en.wikipedia.org/wiki/

Interface_(Java).

[44] Wikipedia (2014g). Just-in-time compilation. http://en.wikipedia.

org/wiki/JIT_compiler.

[45] Wikipedia (2014h). List of numerical libraries. http://en.wikipedia.

org/wiki/List_of_numerical_libraries.

[46] Wikipedia (2014i). Nondimensionalization. http://en.wikipedia.org/wiki/Nondimensionalization.

[47] Wikipedia (2014j). Revision control. http://en.wikipedia.org/wiki/

Revision_control.

[48] Wikipedia (2014k). Software engineer. http://en.wikipedia.org/

wiki/Software_engineer.

[49] Wikipedia (2014l). Sparse matrix. http://en.wikipedia.org/wiki/

Sparse_matrix.

[50] Wikipedia (2014m). Unified modeling language (uml). http://en.

wikipedia.org/wiki/Unified_Modeling_Language.

93

Page 102: Master thesis Francesco Serafin