simulation of fluid flow through porous media · simulation of fluid flow through porous media juan...

56
Universidad Nacional de Colombia Facultad de Ciencias, Departamento de Matem´ aticas Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc´ ıa Osorio Orientador: Juan Galvis Bogot´ a - Diciembre de 2015

Upload: buimien

Post on 20-May-2018

229 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Universidad Nacional de Colombia

Facultad de Ciencias, Departamentode Matematicas

Simulation of Fluid FlowThrough Porous Media

Juan Gabriel Garcıa Osorio

Orientador: Juan Galvis

Bogota - Diciembre de 2015

Page 2: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

2

Page 3: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Contents

1 Introduction 5

2 The Finite Element Method 112.1 The Galerkind Method . . . . . . . . . . . . . . . . . . . . . . 112.2 FEM for Second Order PDE . . . . . . . . . . . . . . . . . . . 132.3 FEM and FreeFem++ . . . . . . . . . . . . . . . . . . . . . . 16

3 Fluids in Porous Materials 213.1 A Review on Fluid Dynamics . . . . . . . . . . . . . . . . . . 213.2 Darcy’s Law . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.3 Velocity Potential and the Ideal Gas . . . . . . . . . . . . . . 27

4 Two Immiscible Fluids in a Porous Material 334.1 Physical Theory for Two Fluids Inside a Porous Material . . . 334.2 Weak Formulation for Two Immiscible Fluids . . . . . . . . . 39

5 Conclusions and Future Work 45

Appendices 47

A Freefem++ Codes of the Simulations 49

3

Page 4: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

4 CONTENTS

Page 5: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Chapter 1

Introduction

In this work we are going to focus on reviewing some aspects of the theoryand simulation of fluid flow through porous media. This theory is rich andmany issues and problems are still open ended. This theory relies heavily ontwo fields: Fluid Dynamics, which is a branch of physics that still has someopen problems and important issues waiting for better understanding. Andpartial differential equations (PDEs) which is a branch of mathematics inwhich there are still some important open issues. The situation is even morecomplicated because, in general, the equations that come up in the theoryof fluid flow through porous media are coupled systems of nonlinear partialdifferential equations.

It is also known that general linear or nonlinear PDEs cannot be solvedin an analytic way, except for some simple geometries and boundary condi-tions (BCs). In practical situations the geometries and BCs involved in thePDE are fairly arbitrary, so little hope is put in to solving them analitically.For that reason several numerical methods have been developed in order toovercome the lack of analitical solutions.

Let us look at three key equations in the theory of fluid flow throughporous media. First the so-called Darcy’s law [1,2]. This law states a consti-tutive equation that relates the fluid velocity to the pressure. Mathematically

~v = −Kµ∇(p+ ρgx3). (1.1)

Here, K is a physical property of the porous medium, called permeability and

5

Page 6: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

6 CHAPTER 1. INTRODUCTION

it has units of length squared. This variable is a measure of how easy a fluidcan flow through the porous material. The parameter µ is the viscosity ofthe fluid under study, and has units of pressure times units of time. Viscosityis a measure of the fluid resistance to flow. The variable p is the pressureinside the medium and has units of force divided by length squared. Finally,ρ and g are the fluid density (units of mass divided by length cubed) andgravity acceleration, repectively.

The equation (1.1) relates four variables, the three components of thevelocity and the pressure. However, the velocity field ~v must fulfill an ad-ditional restriction: the continuity equation, which is the statement of theconservation of mass. Mathematically:

∇ · (ρ~v) +∂ρ

∂t= 0, (1.2)

where ∂∂t

is the partial derivative with respect to time. The continuity equa-tion relates the three components of the velocity with the fluid density. Thetwo equations above are linear partial differential equations (in each variable).However there is one single equation that relates all of the above variables,this equation is at the core of fluid dynamics and it is the Navier-Stokes(NS) [3] equation. This equation is nonlinear and only for a very few specialcases, an analytic solution is can be obtained. This is an important problembecause NS equation encodes the physical behavior of a fluid under diferentcircumstances, and describes a wide range of phenomena. From complicatedmodels of weather prediction to the behavior of a backyard pool. NS equa-tion is a restatement of Newton’s seconds law i.e., force equals mass timesacceleration. For an incompressible fluid, NS equation reads as follows:

∂~v

∂t+ (~v · ∇)~v = ~g − 1

ρ∇p+

µ

ρ∇2~v. (1.3)

Because of the importance of NS equation, Darcy’s law and many otherPDEs, it was necessary to find out a way to solve them under differentBCs and geometries. To overcome this problem, some numerical methodshave been proposed [4, 5]. The one we are going to use in this work is TheFinite Element Method (FEM). For the sake of simplicity we will work in onedimension, i.e., n = 11. The idea of this method is the following. Considera domain in R1, say Ω. Now take this domain and construct a partition

1The case n = 2 will be considered in more detail in the next chapter.

Page 7: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

7

Ωimi=1. This partition must fulfill some technical requirements that will beexamined in the next chapter. Now, on this partition, the vertices, are thenodal points2. Finally over each element of the partition define a suitable setof linearly independet functions that span some finite dimensional space thatwill approximate the solution to the PDE. We illustrate this approximationin the case of piecewise linear functions in Figure 1.1. This gives us theframework to start solving numerically different kind of PDEs. To illustratehow this can be done, take

−d2u(x)

dx2= f(x), x ∈ [0, 1], (1.4)

along with homogeneous Dirichlet boundadary conditions,

u(0) = u(1) = 0. (1.5)

We multiply (1.4) by an arbitrary function v, whose derivative is a piecewisecontinous function that vanishes over the boundary of Ω. The function v iscalled a test or admissible function (the set of functions with this propertywill be represented by the letter V ). Integrating (1.4) we obtain

−∫

[0,1]

d2u

dx2vdx =

∫[0,1]

fvdx. (1.6)

To make notation simpler we will use the prime notation to denote functionderivatives. Also we are going to use the inner product notation 〈 , 〉, insteadof explicit integrals. This inner product is defined by

〈f, g〉 =

∫[0,1]

f(x)g(x)dx. (1.7)

Now we integrate by parts (1.6) and use the fact that the derivative of vvanishes over the boundary to get

〈u′, v′〉 = 〈f, v〉. (1.8)

It is not hard to see that any solution of (1.4) is also a solution of thislast equation, for all v ∈ V (see [4]). The problem is that V is an infinite

2Nodal points need not to be only the ones at the vertex interception, they can also bepoints inside any set of the partition

Page 8: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

8 CHAPTER 1. INTRODUCTION

Figure 1.1: Partition and approximation to the solution.

dimensional space, so we need to construct finite dimensional approximationsto V . To this end, lets take a partition of [0, 1], say, 0 < x1 < x2 < . . . <xn−1 < 1. The finite dimensional approximation (that will be representedby the letter Vh) consists of the set of functions v that are linear on eachsubinterval of the partition, but vanish on the boundary, and are continous.Now we define the basis functions as

φj(xi) =

1 : i = j0 : i 6= j.

and extended as being piecewise linear and continue to the rest of the domain.The name of basis functions is because any function v in Vh can be expressedas

v =n∑i=1

aiφi(x), (1.9)

where ai = v(xi). The set φini=1 is linearly independent. Hence, Vh is ann-dimensional vector space. With this construction we can now state (1.6)as: Find uh ∈ Vh such that for all v ∈ Vh, the following holds

〈u′h, v′〉 = 〈f, v〉. (1.10)

Expanding both sides of the equations in the basis functions by using uh =∑ni=1 biφi(x). We arrive to a set of linear equations whose unknowns are

the coefficients of the expansion of uh in the basis functions. After we solve

Page 9: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

9

the linear systems and find the coefficients we obtain a finite dimensionalapproximation for the solution of the equation u′′ = −f . For details seechapter 2.

Figure 1.1, suggest the following fact. If we refine the partition of theinterval then the error between the piecewise linear approximation u and ubecomes smaller. This can be used (see [4]) to show that the error betweenthe computed solution and the exact solution is

|u(x)− uh(x)| ≤ h maxy∈[0,1]|u′′(y)|, (1.11)

Here h = maxi∈1,...,n|xi−xi−1|, so h is a measure of the size of the partition.Obviously when h → 0 then uh → u (see [4], page 15). The above exampleshows the escence of the FEM procedures. The reason to introduced earlythis topic is because in this work we are going to use the FEM procedures inorder to model different physical variables, such as density and pressure, ofa fluid flowing through a porous material. This modelling will be done withthe aid of a software named Freefem++. A deeper study of the FEM and anexample developed using Freefem++ will be presented in the next chapter.

Page 10: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

10 CHAPTER 1. INTRODUCTION

Page 11: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Chapter 2

The Finite Element Method

The idea of this chapter is to give a brief introduction to the Finite ElementMethod (FEM), which is a method for simlulating partial differential equa-tions (PDEs). Since the solution of a PDE generally belongs to an infinitedimensional space, this makes dealing with them not and easy task. Theidea of the FEM is to approximate the solution of the PDE, by constructinga finite dimensional approximations. The starting point to construct theseapproximations is the so-called Galerkind Method [6], which is explainednext.

2.1 The Galerkind Method

Let a : V ×V → R be a bilinear form, from a subset V of a Hilbert space H.We want to find a function u ∈ V such that for a given l and all admissiblefunctions v ∈ V , the following holds

a(u, v) = 〈l, v〉 . (2.1)

Here 〈·, ·〉 represents the inner product of H. Because generally V is infinitedimensional, it is very difficult to solve (2.1). Instead of trying to solvedirectly (2.1), we approximate V by finite dimensional vector spaces V h,where h is a parameter that somehow measures how close is V h to V .

As in the introduction chapter, the problem in the finite dimensionalspace V h now reads as follows: Find a function uh ∈ V h such that for a givenl and for all vh ∈ V h the following is true

a(uh, vh) = 〈l, vh〉 . (2.2)

11

Page 12: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

12 CHAPTER 2. THE FINITE ELEMENT METHOD

This is the Galerkind formulation. Let φiNi=1 be a basis for V h. Then, allof V h elements can be written as a linear combination of such basis. Foruh ∈ V h we can write,

uh =N∑i=1

ciφi, (2.3)

and also for vh ∈ V h we can write

vh =N∑i=1

djφj. (2.4)

Since, a and the inner product are bilinear forms, the following is obtainedwhen replacing the above expansions into (2.2)

N∑i=1

N∑j=1

a(φi, φj)cidj =N∑j=1

〈l, φj〉 dj. (2.5)

This equation looks like a matrix equation. To see this more clear, let usname Kij = a(φi, φj) and Fj = 〈l, φj〉. Then we have the following equation

N∑j=1

(N∑i=1

Kijci − Fj

)dj = 0. (2.6)

Because the dj are the coefficients of vh and (2.1) must hold for all vh, then(2.6) must hold for all dj. This is true if and only if(

N∑i=1

Kijci − Fj

)= 0, (2.7)

for j = 1, . . . , N . More compactly in matrix notation we can write

KTc = F, (2.8)

where K and F are elements with entries Kij and Fj, respectively. Aftersolving (2.8) the coefficients ci are obtained and the approximation to thesolution is assembled as

uh =N∑i=1

ciφi. (2.9)

Page 13: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

2.2. FEM FOR SECOND ORDER PDE 13

Now we are going to describe how this works for second order PDEs.

2.2 FEM for Second Order PDE

Now that the Galerkind formalism has been introduced, it is time to introducethe FEM for second order problems. Second order problems, among manyother applications, describe the dynamics of a fluid flow through a porousmedium, which is the main topic of this work.

The starting point is equation (2.1) and the approximation (2.2). In thiscase the Hilbert space is V = H1(Ω), where Ω is the domain of definitionof (2.1). This is the Sobolev space of functions whose generalized derivativebelongs to the space of square integrable functions, L2(Ω) [7]. Again theapproximation to V is a finite dimensional space V h. The question is: Howcan we choose the basis for V h?. To answer this question a few definitionsmust be done.

The Finite Element Mesh

Let Ω1, . . . ,Ωs be a partition of a domain Ω ⊂ R2 (for simplicity we chooseΩ to be a polygonal domain), into triangles (called elements). This partitionmust fulfill some conditions. In particular, it is required that every side of theboundary of an element in the partition to be either, part of the boundaryof Ω, that is ∂Ω, or the side of another element. A typical triangulation isshown below.

Page 14: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

14 CHAPTER 2. THE FINITE ELEMENT METHOD

Figure 2.1: Typical triangulation of a polygonal subset of R2, with elementsΩi

Nodal Points

The nodes are the vertices of the elements in the partition. It is importantto note that it may be required to work with more nodes that the vertices ofthe elements. We define

Definition 2.2.1. The partition of Ω and the nodes are called a finite elementmesh or triangulation.

Now we need to construct a basis for V h. We are going to consider only abasic finite element method that uses piecewise polynomials. For simplicitywe present some of the requirements that the basis functions satisfy in thiscase. These are considered only for this basic finite element method and maynot be necessary in general finite element methods. We make the followingrequirements,

1. The functions φi are bounded and continous over the closure of Ω.

2. We have φi = 1 at the node i and 0 at the other nodes.

3. If we define φ(k)i = φi|Ωk

then φ(k)i must be a polynomial in Ωk. These

φ(k)i are called local basis functions.

Page 15: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

2.2. FEM FOR SECOND ORDER PDE 15

Finally, in case we are dealing with essential boundary conditions, thebasis must satisfy those. An example of a typical basis function in R1 isshown in the figure below.

Figure 2.2: Typical basis piecewise linear basis function in R1

After the above discussion it is easy to find how the linear system (2.8)looks like. We need to compute how the bilinear form and the inner productbehaves when using the local basis functions. Recall that we are dealing withsecond order PDEs in its weak form, so in general the bilinear form is theintegral of a funcion B over Ω. With this in mind we get:

a(φi, φj) =

∫Ω

B(φi, φj)dx

=M∑k=1

∫Ωk

B(φ(k)i , φ

(k)j )dx

=M∑k=1

a(k)(φ(k)i , φ

(k)j ).

Using the same steps for the inner product, we get

Page 16: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

16 CHAPTER 2. THE FINITE ELEMENT METHOD

〈l, φj〉 =

∫Ω

G(φj)dx

=M∑k=1

∫Ωk

G(φ(k)j )dx

=M∑k=1

⟨lk, φ

(k)j

⟩.

The above development shows that we get the exact same result of theGalerkind method, except that we have a subassembling of these local pro-cedures over each one of the elements of the finite element mesh. After theassembling we obtain the same result as (2.8). By solving this system weget an approximation for the exact solution of the problem (2.1). This is theescense of the FEM procedure.

2.3 FEM and FreeFem++

Writting the code from scratch for the mesh and the basis functions is areally lengthy task, specially taking into account that the shapes of the do-main Ω can be fairly arbitrary. For this reason, in this work we decided touse a software that makes the construction of the finite element spaces au-thomatically. This software is named Freefem++ and its sintaxis is based onthe sintaxis of C++ [8]. Thanks to Freefem++ it is possible to solve partialPDEs numerically using FEM on fairly irregular domains and making thecode really short. We present some examples next.

PDE for the Density of an Ideal Gas in a Porous Mate-rial

We are going to develop a basic example. Imagine an ideal gas on a porousmaterial, Ω, for simplicity take Ω to be the disk of radius one. Since the gasis a compressible fluid, the fluid density is non-constant. After some analysisof the physics of the situation (see Chapter 3 for a glimpse on the theory offluid through porous media) we deduce that the density of the gas, denotedby ρ, must obey the following PDE,

Page 17: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

2.3. FEM AND FREEFEM++ 17

∇2ρ = α∂ρ

∂t. (2.10)

Where α is a constant that depends on different parameters of the porousmaterial. We postpone a detailed description of α for later and for now onwe assume is constant. For the boundary condition we are goning to use aDirichlet boundary condition specified by 1

ρ|∂Ω = 1, (2.11)

and the initial condition

ρ(x, y, 0) = x2 + y2. (2.12)

With the specifications of the PDE, the idea is to find a bilinear form and alinear form that resembles (2.1). To do this, first we multiply by an admissiblefunction v, that belongs to the same vector space the solution belongs. Withthis multiplication (2.10) becomes

(∇2ρ)v = α∂ρ

∂tv. (2.13)

The next step is to integrate both sides over the domain Ω. We have∫Ω

(∇2ρ)vdx−∫

Ω

α∂ρ

∂tvdx = 0. (2.14)

Now we make a pause to recall that

∇ · ((∇ρ)v) = (∇2ρ)v +∇ρ · ∇v, (2.15)

implies ∫Ω

∇ · ((∇ρ)v)dx−∫

Ω

∇ρ · ∇vdx−∫

Ω

α∂ρ

∂tvdx = 0. (2.16)

Applying the divergence theorem to the first member of the left hand side of(2.16), we have ∫

Ω

∇ρ · ∇vdx+

∫Ω

α∂ρ

∂tvdx = 0. (2.17)

1this is because in the SI units system, air density is almost 1

Page 18: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

18 CHAPTER 2. THE FINITE ELEMENT METHOD

Note that the boundary integral vanishes because we select v to be 0 on∂Ω This is the weak form of the equation (2.17). Now we take care of thetemporal derivative. There are many ways to deal with this. Here we aregoing to use finite differences in time. The idea of finite differences is thefollowing: any derivative can be approximated by a quotient of diferences.For example, if we want to evaluate the derivative with respect to time of afunction f at time t and position x, we can approximate it by

∂f(x, t)

∂t≈ f(x, t)− f(x, t∗)

t− t∗, (2.18)

when |t − t∗| is small. Using finite differences in (2.17) we get the approxi-mation ∫

∂Ω

∇ρ · ~nvdx−∫

Ω

∇ρ · ∇vdx−∫

Ω

αρ− ρn−1

∆tvdx = 0. (2.19)

Here ρn−1 = ρ(x, t − ∆t). Note that we decided to keep ρ (instead of ρn−1

in the other integrals. This is an implicit method). With this, the problemcan now be solved by the FEM procedure. Note that we have to iterate overtime steps ∆t. The details of the simulation of (2.10) are in Appendix A.Here we are going to show the results for different steps of time and meshsizes, and study the behaviour of the solution.

First we are going to see how the simulation behaves under differentpartitions of the domain Ω. The results are shown in the figure below.

Figure 2.3: Results obtained using Freefem++. Using the code showed inAppendix A for the equation (2.11). We discretized using time steps of∆t = 0.1 in (2.19) with Dirichlet boundary condition (2.11) and initial timecondition (2.12). From left to right we show the approximation the resultsat time t = 1 for 50, 100 and 300 vertices respectively.

We can see that in the three cases the solutions converges to the samevalues at time t = 1, no matter the mesh sizes. However, we can see that the

Page 19: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

2.3. FEM AND FREEFEM++ 19

smoothness of the solution is different when we use a poor refinement using50 vertices instead of 300.

For the second part of the numerical experiment, we are now change thesize of the time steps, and leave the number of vertices fixed. The approxi-mations to the solution of (2.10) are shown below

Figure 2.4: Results obtained using Freefem++. Using the code showed inAppendix A for the equation (2.11). We left fixed the number of verticesover the boundary of Ω in 300 in equation (2.19) with Dirichlet boundarycondition (2.11) and initial time condition (2.12). We use different time steps∆t. From left to right we show the approximation the results at time t = 1for ∆t = 0.5, 0.05, 0.005 respectively.

Again solution converges to the same value, irrespectively of the time stepused. This are good news because this results, gives evidence to believe thatthe problem of calculating the density of a gas inside a porous material iswell posed.

On the following chapters we are going to explore nonlinear problems,and simulate them with the aid of Freefem++. Then we’ll explore throughnumerical experiments the performance of the simulation when the systemis nonlinear.

Page 20: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

20 CHAPTER 2. THE FINITE ELEMENT METHOD

Page 21: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Chapter 3

Fluids in Porous Materials

In this chapter we are going to explain the physics behind the fluid flowthrough a porous material. We will begin with a little but necessary reviewon fluid mechanics [3, 9].

3.1 A Review on Fluid Dynamics

The central topic of this work is fluid flow through porous media. Therefore,it is necesary to make a little review on fluid dynamics. This is mainly donein order to give a good rationale for Darcy’s law.

When dealing with fluids, it is assumed the continuum assumption. Thisassumption takes the matter as continous. This, off course, is contrary tothe physical reallity, where as far as it is known, matter consists mainly ofvoid. As long as the dimension of the control volume of the fluid is smallenough compared to it bulk volume, but large enough so it contains a largenumber of molecules, the continuum assumption works fine.

Once the continuum assumption in fluid mechanics has been accepted, thenext step is to find a way to describe the motion of the fluid. There existstwo ways of describing fluid motion: The first one is the so-called Lagrangiandescription. Here we describe each particle’s position as a function of itsinitial position. The second one is the Eulerian description, where the fluidvariables are determined as a function of the position ~x and time [3].

Using the Eulerian description, it is assumed that there is a velocity vectorfield associated to the motion of the fluid. This vector field is a functionof position and time. This field describes the velocity of a point particle

21

Page 22: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

22 CHAPTER 3. FLUIDS IN POROUS MATERIALS

passing through the position ~x = (x, y, z) at time t. Simbolically velocitywill be denoted by ~v(x, y, z, t) = (v1(x, y, z, t), v2(x, y, z, t), v3(x, y, z, t)) or ina more compact notation ~v(~x, t) = (v1(~x, t), v2(~x, t), v3(~x, t)). Having thisvector field (assume to be at least C1, i.e., with continous partial derivativesof the first order) the question to ask is: How this vector field change frompoint to point, and how can this change be described?. Since the field isdifferentiable, we can use a Taylor expansion of the first order around thepoint ~x, in the direction ∆~h. We have,

~v(~x+ ∆~h) = ~v(~x, t) +∇~v∆~h+ o(h2). (3.1)

Here, ∇~v is the Jacobian of the field. Using the symmetric and antisymetricpart of ∇~v, we define:

S =1

2

(∇~v +∇~vT

), (3.2)

and

W =1

2

(∇~v −∇~vT

). (3.3)

The matrix S is the rate of strain tensor. It is related with the deformation ofthe fluid due to the velocity field [9]. The next step is to find a way to relatehow the fluid change its shape when an external stress is applied. We assumea linear relation between applied stress and deformation. Matematically wehave,

P = aS + bI, (3.4)

where a and b are constant. Here P is known as the stress tensor. Flu-ids that satisfies this relations are called Newtonian fluids. From physicalconsiderations it can be found that

a = 2µ, (3.5)

and

b = −(p+2

3µ∇ · ~v). (3.6)

Hence, writting explicitly the components for the stress tensor, we obtain

pij = µ(∂ui∂xj

+∂uj∂xi

)− (p+2

3µ∇ · ~v)δij, (3.7)

where p is the arithmetic mean of the pressure over the boundary of the fluidand µ is the fluid viscosity. The stress tensor represents the force per unit

Page 23: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

3.1. A REVIEW ON FLUID DYNAMICS 23

Figure 3.1: Two dimensional laminar fluid flow in the x− z direction over adomain Ω.

area over the fluid. Therefore, if a fluid is in contact with a solid surface Ω,then, the total force excerted due to the contact of the fluid with the surfaceof Ω is ∫

∂Ω

P~ndA, (3.8)

Where ~n is the outer normal unit vector of Ω. For example if there is a fluidmoving over a pipe in the x − z plane in the x direction (see figure 3.1),then the force excerted by the boundary over the fluid can be calculated incartesian coordinates as:

F =

∫ ∫p13dydz +

∫ ∫p21dydz. (3.9)

Under the assumption of laminar flow, the only nonzero component ofthe velocity is v1, therefore replacing (3.7) in (3.9) we get

F = µ∂v1

∂z. (3.10)

Page 24: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

24 CHAPTER 3. FLUIDS IN POROUS MATERIALS

This last equation is important when finding how the flow of a fluid behavesin a porous medium.

3.2 Darcy’s Law

A porous medium is by definition an object with voids in it [1]. For example,clay, carbon or even a pile of sand grains is a porous material, where fluidscan flow through its voids. The proportion of void volume in the material isa very important characteristic, this characteristic is named porisity and isdenoted by the letter φ. Mathematically:

φ =Void Volume/Bulk Volume.

To give an heuristical deduction of Darcy’s law, imagine an small elementof volume of a fluid flowing through a porous material (see Figure 3.2). Inorder to describe the motion of the fluid we must use Newton’s second law.In Figure 3.2 we can see that there are basically 4 forces acting over thevolume element, this forces are: The viscous force (Fµ), the force due to thepressure gradient (Fp) and the weight(Fg). There are also forces due to thechange of momentum of the fluid particles every time they collide a solidpart of the material. However we will assume that we are dealing with aporous material with random pore structure (e.g., Piece of carbon), so, therandom variations of the velocity due to collisions, are considered to be zeroon average. Now let us analyze how to find each of the nonzero forces actingover the fluid volume element.

Viscous force

Every Newtonian fluid must fullfil the constitutive equation between shearand stress, therefore the force per unit area due to the viscosity of the fluidand the walls of the porous material is given by (3.8). If the fluid is followingthe same path as shown in figure 3.2. then the force per unit area is given by(3.9). The area of the volume element, dA, is proportional to the volume ofthat element, dA×ds. Also the change in the velocity ~v in the d~s direction isexpected to be proportional to the negative of the velocity component that isparallel d~s direction and also proportional to the viscosity. Mathematically:

Fµ = −µB~v · d~sdA. (3.11)

Page 25: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

3.2. DARCY’S LAW 25

Figure 3.2: Volume element with area dA and length ds of a fluid on a porousmedium, in the x− z direction.

Page 26: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

26 CHAPTER 3. FLUIDS IN POROUS MATERIALS

Where B is the constant of proportionality and is related to the geometry ofthe porous material.

Pressure Gradient

The force due to the pressure is applied in the opposite direction of thepressure gradient. Since the force is only acting over the fluid and the fluid isonly occupying the void volume, we got that the effective area where pressureacts is φ× dA. Hence the force is

Fp = −φdA∇p · d~s. (3.12)

Weight

By definition, the weight of a body is its mass times gravity. Since we aredealing with a fluid, it is more convinient to express mass as density timesvolume. It is assumed that the fluid fills all the voids in the medium, thereforethe volume of the fluid over the control volume is φ× dA× ds, this gives usthe weight as

Fg = −ρgφdAd~s · k, (3.13)

where k is the unit vector in the z direction.

Having all the forces defined, it is straightforwad to apply Newton’s sec-ond law (steady state is assumed, hence no acceleration) to get

Fg + Fp + Fµ = −(∇p+ µB

φ~v + ρgk) · d~sdAφ = 0. (3.14)

Since this is true for any d~s we conclude that the term inside parenthesismust vanish. Solving for ~v:

~v = −Kµ

(∇p+ pgk), (3.15)

where K = Bφ

is called the permeability of the material where the fluid isflowing. Roughly speaking is a measure of the mean pore diameter of thismaterial. Equation (3.15) is the famous Darcy’s law and is the foundationof the study of flow through porous media.

Page 27: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

3.3. VELOCITY POTENTIAL AND THE IDEAL GAS 27

3.3 Velocity Potential and the Ideal Gas

To illustrate the physics and mathematics that has been discused so far.Let us derive and simulate the equations of motion of an ideal gas in aporous medium. For starters, imagine a two dimensional sample of coal withpermeability of 108 darcys (This is a massive permeability, however this willallow the simulation to fully evolve in virtually no time). Mathematicallythe two dimensional sample can be represented by the disk of unit radius.Since inside the sample there are no sources or sinks for gas, the equation ofcontiuity for the velocity field becomes

∇ · (ρ~v) + φ∂ρ

∂t= 0. (3.16)

The reason for the porosity φ to appear, is because the density of the gasis nonzero only in the void volume of the porous material. On the otherhand, according to Darcy’s law (neglecting gravity), for compressible fluids,the relation between the pressure and the velocity is

~v = −Kρµ∇p. (3.17)

Finally the relation between the pressure and the density can be calculatedusing the equation of state for an ideal gas (PV = nRT where V is the gasvolume, n is the number of moles, R is the universal constant of gases and Tis the absolute temperature), and the definition of compressibilty, c = 1

ρdρdp

.

Applying this the definition to an ideal gas we get c = 1p. Replacing this

result in (3.15) we get

~v = −Kµp∇p. (3.18)

Inserting (3.18) in (3.16) and using that for an ideal gas ρ = MpRT

, where Mis the molecular weight of the gas, we obtain

∇ · (Kµp∇p) = φ

∂p

∂t. (3.19)

Assuming K and µ constants, we have the PDE

∇ · (∇p2) =2µφ

K

∂p

∂t. (3.20)

Page 28: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

28 CHAPTER 3. FLUIDS IN POROUS MATERIALS

Equation (3.20) is a second order nonlinear partial differential equation. Thisequation describes the dynamic of the gas inside the porous medium. Solving(3.20) numerically can be done using the FEM procedure technique withthe aid of the software FreeFem++. First it is necessary to specify theboundary and initial conditions. The boundary condition can be easily setup by observing that the gradient of the pressure is proportional to thevelocity of the field, so, in the boundary of Ω the velocity at which the gasis leaving is proportional to the difference of pressures in and outside Ω, thisis called Robin or Newton boundary condition. Mathematically

∇p2 · ~n = β(p2 − p0p). (3.21)

Here β is a proportionality constant, ~n is the vector that is normal to theboundary of Ω and p0 is the pressure outside Ω. For the initial condition wehave

p(x, y, 0) = g(x, y). (3.22)

Where g(x, y) is a a suitable function that will be defined in the next section.Now the problem can be solved (numerically). The first thing to do is to findthe weak formulation of (3.20). After some calculations we get

∫∂Ω

2µφ

K(∇p2 · ~n)vdx−

∫Ω

(2µφ

K∇p2 · ∇v − ∂p

∂tv)dx = 0. (3.23)

Multiplying (3.21) by p on both sides, we get∇p2·~n = 2β(p2+pp0). Replacingthis result into (3.23) and again using finite differences for time, the weakvariational form becomes

∫∂Ω

2µφ

Kβ(p2 − p0p)vdx−

∫Ω

2µφ

K∇p2 · ∇vdx−

∫Ω

p− pn−1

∆tvdx = 0. (3.24)

Where pn−1 is the pressure one step of time in behind p. The equation(3.24) is nonlinear in p, therefore is necessary to linearize it in order toapply the FEM. We use Newton’s method for the linearization. The ideaof the method is the following: We want to solve the functional equationF (u) = 0 by choosing an arbitrary point u∗ and finding a correction h suchthat F (u∗+ h) = 0. This is equivalent to F (u∗+ h)−F (u∗) = −F (u∗). Thereason to add −F (u∗), is the Taylor formula of order one, which states that

Page 29: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

3.3. VELOCITY POTENTIAL AND THE IDEAL GAS 29

F (u∗ + h) − F (u∗) ≈ F (u∗) + F ′(u∗)h. Applying Newton’s method to thefunctional

F (p) =

∫∂Ω

2µφ

Kβ(p2−p0p)vdx−

∫Ω

2µφ

K∇p2·∇vdx−

∫Ω

p− pn−1

∆tvdx, (3.25)

we get

F (p+ h) =

∫∂Ω

2µφ

Kβ((p+ h)2 − p0(p+ h))vdx−

∫Ω

2µφ

K∇(p+ h)2 · ∇vdx

−∫

Ω

(p+ h)− pn−1

∆tvdx. (3.26)

Hence linearization becomes

F (p+h)−F (p) ≈∫∂Ω

2µφ

Kβ(2p+p0)vhdx+

∫Ω

2µφ

K∇(2ph)·∇vdx−

∫Ω

hv

∆tdx.

(3.27)Using Newton method in (3.25) and (3.27) we can solve for h. This will enableus to find the approximate solution for p. The details of the algorithm forsolving (3.27) are in Appendix A.

Results of the Simulation Using Freefem++

Applying the algorithm in the appendix A it is possible to find a numericalsolution for (3.20). Here we are going to show the results obtained doing thesimulation for the following values.

Variable Value Units

Porosity (φ) 0.5 No units

Viscosity(µ) 1.846 Kgms

Permeability (K) 1 m2

β -1 No unitsp0 101300 Pascal

g(x, y) (p0 + exp(−√x2 + y2))2 Pascal

Table 3.1: Values of the parameters for the simulation of equation (3.20).

Page 30: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

30 CHAPTER 3. FLUIDS IN POROUS MATERIALS

After solving (3.20) for p, we find the velocity field using (3.15). We dothe analysis to the approximation to the solution using different mesh sizesand different time steps. First we show the results of the approximationusing different mesh sizes in the figures below.

Figure 3.3: Results obtained using Freefem++. Using the code showed inAppendix A for the equation (3.20). We discretized using time steps of∆t = 0.1 in (3.24) with Robin boundary condition (3.21) and initial timecondition (2.12). From left to right we show the approximation the resultsat time t = 1 for 50, 100 and 300 vertices respectively.

As we can see the solution is stable under change of mesh sizes. We getin the three figures the same distribution for the values of the norm of thevelocity field. The only difference is that the number of arrows is increased asthe number of vertices grows. A situation very different is experienced whenwe fixed the number of vertices over the boundary of Ω at 300, and changethe length of the time step. The results are shown in the figures below

Figure 3.4: Results obtained using Freefem++. Using the code showed inAppendix A for the equation (3.20). We discretized using 300 vertices over∂Ω in (3.24) with Robin boundary condition (3.21) and initial time condition(2.12). From left to right we show the approximation the results at time t = 1for ∆t = 0.5, 0.05, 0.005 respectively.

As we can see the simulation is sensitive to the choice of the time step.

Page 31: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

3.3. VELOCITY POTENTIAL AND THE IDEAL GAS 31

Getting different values for the approximation to the solution for each ofthe time steps. It is interesting to note that even with the simplest set ofequations, Freefem++ does not give an accurate convergence to the solution.An example of this situation is the following, take the function f and g to besuch that they obey the following set of PDEs over the disk of unit radius Ω:

fg +∇2f = 4 + x4 + y4, (3.28)

and

fg +∇2g = x4 + y4. (3.29)

Along with a Dirichlet boundary condition for f

f |∂Ω = 1, (3.30)

and a Neumann boundary condition for g

∇g · ~n = −4xy. (3.31)

A solution that satisfies (3.28) and (3.29) is

f = x2 + y2, (3.32)

and

g = x2 − y2. (3.33)

The weak formulation for the system of PDEs is found to be (multiplying bytest functions u and v)

∫Ω

(fg−4+x4−y4)udx−∫

Ω

(∇f ·∇u)dx+

∫Ω

(fg−x4+y4)vdx−∫∂Ω

4xyvdx

−∫

Ω

(∇g · ∇v)dx = 0. (3.34)

After linearization of (3.34) and appliying Newton’s method we obtain thefollowing approximation to the solution shown in the figures below.

Page 32: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

32 CHAPTER 3. FLUIDS IN POROUS MATERIALS

Figure 3.5: Approximation to the solution of the coupled PDEs (3.28) and(3.29) with boundary condtions (3.30) and (3.31). From left to right we havethe approximation to the solution for f and g respectively.

The approximation to the solution that appears in Figure 3.5, looks likethe solution (3.32) and (3.33). However computations shows that if uh rep-resents the approximate solution to f = x2 + y2 in (3.28) and (3.29), wehave

‖uh − (x2 + y2)‖L2(Ω) = 1.024, (3.35)

regardless of the mesh size, i.e., Freefem++ is not converging to the solution.We will not make any attempt to explain the possible reasons for the lackof convergence. We showed this last example, in order to convey the ideathat convergence in the solution for nonlinear PDEs is not an easy task, anddespite the fact that the algorithm to solve the equation for pressure (3.20)was revised several times, we fail to assure stability of the algorithm withrespect to change in step sizes.

On the next chapter we are going to deal with a more difficult problem, acoupled set of nonlinear PDEs that describes the dynamics of two immisciblefluids inside a porous material.

Page 33: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Chapter 4

Two Immiscible Fluids in aPorous Material

In this chapter we are going to put togheter some of the discussion presentedbefore and apply them to the modelling of flow of two immiscible fluidsin a coal sample. The aim of this excercise is to replicate experimentaldata obtained perfoming measures of methane released from a coal samplesubmerged in water. This implies that the two immiscible fluids that we aregoing to model are methane and water. Using the reservoir engineering slang,methane will be the nonwetting phase (nw) and water the wetting phase (w)(see [10]). In order to develop the theory, it’s necessary to introduce someconcepts and definitions. We are going to do this next.

4.1 Physical Theory for Two Fluids Inside a

Porous Material

As defined in Chapter 3, a porous medium is an object with voids inside ofit. We assume that the fluids under study fully fills that voids. If Vv denotesthe total void volume of the porous medium, we define the fraction of volumeoccupied by a fluid volume Vi by the name of saturation and the forumula

Si =ViVv, (4.1)

33

Page 34: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

34CHAPTER 4. TWO IMMISCIBLE FLUIDS IN A POROUS MATERIAL

Figure 4.1: Relative permeability curves of oil and water as a function ofsaturation of oil

where i = w or i = nw and Vi is the volume occupied by the ith component.This definition implies that

Sw + Snw = 1. (4.2)

As disscused before, the permeability of a porous meaterial, measureshow easy a fluid can flow inside it. It is an intrinsic feature of the material.However imagine that the porous medium is a coal sample, and this samplealready have some fluid inside it. Then, if another fluid is going to enter insidethe coal sample, this fluid must displace the fluid that was already inside thesample. This extra work, makes that the permeability of the sample lookssmaller. This motivates the definition of a new kind of permeability, thephase permeability of the fluid and is represented by the letter ki. In our casei = w, nw. With the phase permeability we define the relative permeabilityby

Ki =kiK. (4.3)

The above suggest that the relative permeability is a function of the sat-uration. Turns out that this is actually true. A typical relation betweenpermeability and saturation is shown in Figure 4.1 (see [11]).

To continue with the definitions, imagine a coal sample with one fluidinside (e.g., oil). Another fluid (e.g., water) gets inside the sample. Whenthe outside fluid goes into the sample, it must displace the fluid that was

Page 35: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

4.1. PHYSICAL THEORY FOR TWOFLUIDS INSIDE A POROUSMATERIAL35

Figure 4.2: Typical curve for the capillary pressure

already in. In the case of water and oil, this displacement is called imbibi-tion. Imbibition is a phenomenon driven by the capillary pressure (see [12]).Capillary pressure, denoted by the letter pc, is the difference of pressures atthe interface of two fluids. Mathematically

pc = pnw − pw. (4.4)

It is clear that capillary pressure depends on the relative amount present ofeach phase inside the medium. Hence the capillary pressure is also a functionof saturation. A typical curve for the capillary pressure as a function ofsaturation is shown in Figure 4.2 (see [13]).

It is worth noting that the capillary pressure depends on what fluid entersfirst into the sample. For example if we are dealing with water and oil, andwater enters first and then is displaced by oil, we get the drainage curve. Ifoil enters first and water displace it, we get the imbibition curve. These twocurves are diferent. Then capillary pressure has the property of hysteresis.

With the concepts above, it is time to do the mathematical modelling.The system that we want to simulate is the following: We have a piece ofcoal, that is represented by the letter Ω. Inside the sample there is methane.We want to know how much methane is inside. In order to do this, wesubmerge the sample in water, the water permeates the sample, displacingthe gas (see Figure bla). After the displacement starts, we perform a measureof the volume of gas that has gone out the sample, as a function of time. Tosimulate this situation, and replicate the experimental data of the volumeobtained experimentally, is what we want to do. As a first step we proposea system of PDEs to model this experiments.

Page 36: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

36CHAPTER 4. TWO IMMISCIBLE FLUIDS IN A POROUS MATERIAL

Figure 4.3: Schematic representation of the coal sample submerged in water.For simplicity the water only enters on ∂Ω2. While ∂Ω1 is isolated.

The starting point for the mathematical modeling is Darcy’s law. Bothphases w and nw must fulfill (3.15). However there is an important difference,water is incompressible, this means that water density is constant. Hence thecontinuity equation for water reads as follows

∇ · (~vw) + φ∂Sw∂t

= 0. (4.5)

For methane, which is a compressible fluid we have

∇ · (ρnw~vnw) + φ∂(ρnwSnw)

∂t. (4.6)

The reason for the saturation and the porosity to appear in the continuityequation is very simple. In general terms the continuity equation over acontrol volume of a fluid, is just the mathematical statement of the fact thatover the control volume (CV) we have

(Amount in over CV)-(Amount out over CV)+(Amount generated inCV)=(Increase in content).

The increase in content is the rate of change of the concentration timesvolume. In the limit when the CV approaches to zero, the rate of change of

Page 37: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

4.1. PHYSICAL THEORY FOR TWOFLUIDS INSIDE A POROUSMATERIAL37

the concentration, measures the rate of increase in content in the CV. Hencethis concentration is what goes inside the time partial derivative symbol.However in a porous medium, the concentration is nonzero only in its voids.Hence we can say that there exists an effective density φρ. Taking intoaccount that there is more than one fluid in the porous medium, the truedensity, must be scaled up to the relative amount of the fluid of interest thatis in the sample. The relative amount of fluid is by definition the saturation.We conclude that the concentration is φρS. This is the reason why, for twofluids in a porous medium, the continiuty equation has the terms S and φ.

We have two continuity equations, and seven unknown functions, namely,the four components of the velocity fields for gas and water, gas and watersaturation, and gas density. We need to find five more relations if we wantto solve the problem. First of all, we use Sw + Snw = 1, so we get

Sw = 1− Snw. (4.7)

Second, we have that both phases must fulfill (3.15). Observe that (3.15)can be written as

~v = −Kµ∇(p+ ρgz), (4.8)

where z is the z coordinate. The quatinty p + ρgz is named the velocitypotential ψ, hence Darcy’s law for incompressible fluids can be written as

~v = −Kµ∇ψ. (4.9)

On the other hand in [14] it is shown that for a compressible fluid the potentialis given by

ψ = gz +

∫ p

p0

dp

ρ(p), (4.10)

and the velocity field is given by

~v = −Kρµ∇ψ. (4.11)

To find explictly this potential, we need to relate ρ with the pressure p. If weconsider the compressible fluid as an ideal gas, it is straightforward to showthat ( [15]),

ρ =M

RTp. (4.12)

Page 38: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

38CHAPTER 4. TWO IMMISCIBLE FLUIDS IN A POROUS MATERIAL

Here M is the molecular weight of the gas. Now we can integrate (4.10).Doing this we get

ψ = gz +RT

Mln(

p

p0

), (4.13)

and neglecting gravity

∇ψ =RT

Mp∇p. (4.14)

Neglecting gravity in (4.8) aswell, Darcy’s law for nw and nw becomes

~vnw = −KnwRTρ

µnwMp∇pnw = −Knw

µnw∇pnw, (4.15)

and

~vw = −Kw

µw∇pw. (4.16)

Inserting these two equations in (4.6) and (4.5) respectively, we have

∇ · (−Kw

µw∇pw)− φ∂Snw

∂t= 0 (4.17)

and

∇ · (−Knw

µnw∇pnw) +

φM

RT

∂(pnwSnw)

∂t= 0. (4.18)

Finally we need to relate pw and pnw. The equation that is needed to relatethem is ( [1])

pnw − pw = pc. (4.19)

Also we need to find how pc, and the relative permeabilities are related tothe saturation Snw. According to [16,17], a very commonly used relation forpc is given by [18]

pc =1

α

(S

1ne − 1

) 1m

, (4.20)

and for the saturation is

Knw = (1− Se)1/3(1− S1/m

e

)2m(4.21)

along with

Kw = S1/2e

(1−

(1− S1/m

e

)m)2

(4.22)

Page 39: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

4.2. WEAK FORMULATION FOR TWO IMMISCIBLE FLUIDS 39

Where α and n are constants to be fixed and m = 1 − 1n. Here Se =

1−Snw−Sw,r

1−Sw,rand Sw, r is the so-called connate residual water saturation. This

connate water saturation measures the relative ammount left of water insidethe porous medium that is imposible to displace. With (4.17), (4.18), (4.19)and (4.20) we have four equations and four unknown. The only thing left todo is to impose are the boundary and initial conditions.

Based on physical considerations (using Bernoulli equation and the ex-pected behavior of the fluids inside the porous material) we can propose thefollowing BCs:

∇pnw · ~n|∂Ω2 = ∇pc · ~n−√

2gρwx3 − pnwρw

, (4.23)

and for ∂Ω1 we propose

∇pnw · ~n = 0, ∇Snw · ~n = c, (4.24)

where c is a positive constant. For the initial condition we propose

Snw(x, y, 0) = 1− Sw(x, y, 0) = f(x, y), (4.25)

p(x, y, 0) = g(x, y). (4.26)

Where f and g are suitable function that are compatible with the problem.We now develop the weak variational form for the problem. This is going tobe done next.

4.2 Weak Formulation for Two Immiscible Flu-

ids

We take equations (4.17), (4.18) and cast them as a function of pwn and Snw.This can be done by replacing pw by pnw − pc. Using that pc is a function ofsaturation, we get

∇ · (Kw

µw∇(pc(Snw))−∇ · (Kw

µw∇pnw)− φ∂Snw

∂t= 0, (4.27)

phiM

RTSnw

∂pmw∂t

+φM

RTpnw

∂Sw∂t−∇ · (Kg

µg∇pnw) = 0. (4.28)

Page 40: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

40CHAPTER 4. TWO IMMISCIBLE FLUIDS IN A POROUS MATERIAL

From now on, to keep the notation simpler we are going to drop the sub-script nw on pnw and Snw. Also we define λ = φM

RT. Note that according to

equation (4.20) the capillary pressure is a function of the efective saturation,hence it will be more consistent to write pc(Se(S)). Again for the sake ofsimplicity everytime the term pc appears in equations, it will be understoodas pc(Se(S)).

In order to apply the differential operators in (4.27) and (4.28), we needto apply three known vector identities, namely

∇(pc(Se(S)) =dpcdSe

dSedS∇S, (4.29)

∇(Kw(S)

µw) =

1

µw

dKw

dS∇S, (4.30)

and∇2pc(Se(S)) = g(s)‖∇S‖2 + j(s)∇2S, (4.31)

where1

g(s) =d2pcdS2

e

(dSedS

)2

(4.32)

and

j(s) =dpcdSe

dSedS

. (4.33)

Multiplying (4.27) by an admissible function v, integrating by parts overΩ, and including the boundary conditions (4.23) and (4.24), equation (4.27)becomes∫

Ω

j(s)

µw

dKw

dS‖∇S‖2vdx+

∫Ω

Kwg(s)

µw‖∇S‖2vdx−

∫Ω

Kwj(s)

µw∇S · ∇vdx

−∫

Ω

1

µw

dKw

dS∇S · ∇pvdx−

∫∂Ω

Kwα

µw(p− p0)vdx

+

∫Ω

Kw

µw∇p · ∇vdx−

∫Ω

φS − Sn−1

∆tvdx = 0. (4.34)

To make notation simpler, we will drop the differential dx on the integrals.In (4.34) we already apply the finite difference scheme for the time variable.Equation (4.34) is the weak variational formulation for (4.27).

1Taking into account that d2Se

dS2 = 0

Page 41: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

4.2. WEAK FORMULATION FOR TWO IMMISCIBLE FLUIDS 41

For (4.28) we use the product rule for derivatives to the term ∂(pS)∂t

. Then

we use the chain and product rule to the term ∇ · (−Kg

µg) to obtain

λS∂p

∂t+ λp

∂S

∂t− 1

µg

dKg

dS∇S · ∇p− Kg

µg∇2p = 0. (4.35)

Finally we multiply by an admissible function w. Taking into account theboundary conditions and integrating by parts over Ω, we get

∫Ω

λp− pn−1

∆tSw +

∫Ω

λS − Sn−1

∆tpw −

∫Ω

1

µg

dKg

dS(∇S · ∇p)w

−∫∂Ω

αKg

µg(p− p0)w +

∫Ω

Kg

µg∇p · ∇w = 0. (4.36)

We have two equations and two unknowns. To solve these equations usingthe FEM procedure, we need to apply mixed finite element method [10]. Theidea is very simple, in the language developed in Chapter 2, suppose we havethe following set of equations

a(p, v) = 〈f, v〉, (4.37)

b(S,w) = 〈g, w〉. (4.38)

Where a and b are bilinear forms. Here p, S are the unknowns that belongsto an inifinte dimensional vector space V . Making the approximation to Vby the finite dimensional spaces V h, we recast the set of equations to looklike

a(ph, v) = 〈f, v〉, (4.39)

b(Sh, w) = 〈g, w〉, (4.40)

for all v,w in V h. It can be proved (see [10]) that these equations have aunique solution under appropiate conditions.

Observing (4.34) and (4.36), it is clear that the mixed finite elementmethod is what we need to solve the system of PDEs. The way the mixedfinite element method is used in Freefem++ is very simple. First, we combineboth equations (4.34) and (4.36) into a single one. Doing this we get the

Page 42: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

42CHAPTER 4. TWO IMMISCIBLE FLUIDS IN A POROUS MATERIAL

definition of the functional N(p, S):

〈N(p, S)v, w〉 =

∫Ω

(j(s)

µw

dKw

dS+Kwg(s)

µw)‖∇S‖2v −

∫Ω

Kwj(s)

µw∇S · ∇v

−∫

Ω

1

µw

dKw

dS(∇S · ∇p)v −

∫∂Ω

Kwα

µw(p− p0)v

+

∫Ω

Kw

µw∇p · ∇v −

∫Ω

φS − Sn−1

∆tv

+

∫Ω

λp− pn−1

∆tSw +

∫Ω

λS − Sn−1

∆tpw −

∫Ω

1

µg

dKg

dS(∇S · ∇p)w

−∫∂Ω

αKg

µg(p− p0)w +

∫Ω

Kg

µg∇p · ∇w = 0. (4.41)

In theory finding the functions p and S that fulfills 〈N(p, S)v, w〉 = 0 forall w,v, is the solution to the set of PDEs (4.17) and (4.18). Observe thatN(p, S) is a nonlinear functional, hence, we need to linearize it. In orderto do so, we apply the Newton’s method, i.e, we need to solve the equationN(p + h, S + k) − N(p, S) = −N(p, S) for an arbitrary increment (h, k).To start Newton’s method, we first, need to find the increment functionalN(p+ h, S + k).

〈N(p+ h, S + k)v, w〉 =

∫Ω

j(S + k)

µw

dKw(S + k)

dS‖∇(S + k)‖2v

+

∫Ω

Kw(S + k)g(S + k)

µw‖∇(S + k)‖2v

−∫

Ω

Kw(S)j(S)

µw∇(S + k) · ∇v −

∫Ω

1

µw

dKw(S + k)

dS∇(S + k) · ∇(p+ h)v

−∫∂Ω

Kw(S + k)α

µw(p+ h− p0)v +

∫Ω

Kw(S + k)

µw∇(p+ h) · ∇v

−∫

Ω

φS + k − Sn−1

∆tv+

∫Ω

λp+ h− pn−1

∆t(S+k)w+

∫Ω

λS + k − Sn−1

∆t(p+h)w

−∫

Ω

1

µg

dKg(S + k)

dS∇(S + k) · ∇(p+ h)w

−∫∂Ω

αKg(S + k)

µg(p+ h− p0)w +

∫Ω

Kg(S + k)

µg∇(p+ h) · ∇w. (4.42)

Page 43: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

4.2. WEAK FORMULATION FOR TWO IMMISCIBLE FLUIDS 43

Now we linearized N(p + h, S + k) −N(p, S). To do so, first recall that fora function of two variables f(x, y) the best linear approximation is given by

f(x+ h, y + k)− f(x, y) ≈ ∂f

∂xh+

∂f

∂yk. (4.43)

Using this, we get

N(p+ h, S + k)−N(p, S) ≈∫

Ω

dG

dS‖∇S‖2kv +

∫Ω

2G(S)∇S · ∇(k)v

−∫

Ω

j(S)

µw

dKw

dS(∇S ·∇v)k−

∫Ω

Kw(S)

µw

dj

dS(∇S ·∇v)k−

∫Ω

Kw(S)j(S)

µw∇v ·∇k

−∫

Ω

1

µw

dKw

dS(∇S ·∇h)v−

∫Ω

1

µw

d2Kw(S)

dS2(∇p·∇S)kv−

∫Ω

1

µw

dKw

dS(∇p·∇k)v

−∫∂Ω

α

µw

dKw

dS(p− p0)vk −

∫Ω

αKw(S)

µwvh+

∫Ω

1

µw

dKw

dS(∇p · ∇v)k

+

∫Ω

Kw(S)

µw∇v · ∇h−

∫Ω

φvk

∆t+

∫Ω

λShw

∆t+

∫Ω

λ(p− pn−1)wk

∆t

+

∫Ω

λ(S − Sn−1)wh

∆t+

∫Ω

λpkw

∆t−∫

Ω

1

µg

d2Kg

dS2(∇S · ∇p)wk

−∫

Ω

1

µg

dKg

dS(∇p · ∇k)w−

∫Ω

1

µg

dKg

dS(∇S · ∇h)wdx−

∫∂Ω

α

µg

dKg

dS(p− p0)wk

−∫∂Ω

αKg(S)

µgwhdx+

∫Ω

1

µg

dKg

dS(∇p · ∇w)k +

∫Ω

Kg(S)

µg(∇w · ∇h).

(4.44)

Finally, we consider the equation N(p + h, S + k) − N(p, S) = −N(p, S),where we replace N(p+ h, S + k)−N(p, S) by the approximation above.

At the deadline to finish this work, the simulation of (4.17) and (4.18)was not finish. The reason is that the FEM is not converging, this might bebecause the equations are very complicated and the most tiny error propa-gates very fast in the algorithm. Or in general the expression are two longand hard to compute and it is necessary to develop the FEM procedure us-ing a high level programming language, like C++ or Python. However thealgorithm used so far for this simulation is showed in appendix A. Now inthe next chapter we are going to show the concluisions for this work.

Page 44: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

44CHAPTER 4. TWO IMMISCIBLE FLUIDS IN A POROUS MATERIAL

Page 45: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Chapter 5

Conclusions and Future Work

Fluid flow through porous media is a rich topic, no matter if it is lookedfrom the physical point of view or from the mathematical point of view.Mathematically speaking is a very challenging task to simulate the equationsthat naturally appears in these kind of systems, yet obtaining a succefulsimulation worths the effort, because of the great applicability of this theory.

From this work we can conclude two important things. First, simulationof physical real life systems (like the one we attempt to simulate here) requiresvery good knowledge of physics and math. The former is needed in orderto understand the system to simulate and set the adecuate boundary andinitial conditions, that trully resembles the reality we want to model. Thelatter is needed when we realize that even the tiniest mistake can bring someserious convergence problems. Hence a deep mathematical understanding ofthe methods needed to simulate are mandatory. The second thing we canconclude is that fluid simulation, in particular, needs very fine algorithms inorder to converge to the solution, hence it takes lots of time to obtain goodsimulations of even relatively simple systems.

As a future work we may consider to perform numerical experimentssimulation on the system of PDEs (4.17) and (4.18) and compare to theexperimental data of the experiment described in chapter four. In order toachieve this goal, it is necessary to start studying in great depth, the topicsof PDEs and the FEM procedures.

45

Page 46: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

46 CHAPTER 5. CONCLUSIONS AND FUTURE WORK

Page 47: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Appendices

47

Page 48: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled
Page 49: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Appendix A

Freefem++ Codes of theSimulations

In this appendix are the codes used in the simulations that were done in thiswork.

Code for Gas Density

The equation we want to simulate is

∇2ρ = α∂ρ

∂t. (A.1)

with the boundary conditionρ|∂Ω = 1, (A.2)

and the initial condition

ρ(x, y, 0) = x2 + y2. (A.3)

Below we show the code used to do the simulation with coments that explaineach line of code.

Code

verbosity=0;border circle(t=0,2*pi)x=cos(t);y=sin(t); //We define the border, a circleof radius one.

49

Page 50: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

50 APPENDIX A. FREEFEM++ CODES OF THE SIMULATIONS

real alpha=1; // We set the value of alpha.real dt=0.03; // The time step using in finite difference for time.real T=1; //Simulation end time.mesh Th = buildmesh(circle(100)); //We build the mesh with 100 vertices.fespace Vh(Th,P1); Vh u,v,uold=x2+y2; // Here we define the finite elementspace, and set the initial condition for rho.problem rho(u,v)=int2d(Th)(alpha*uold*v/dt)-int2d(Th)(alpha*u*v/dt)-int2d(Th)(dx(u)*dx(v)+dy(u)*dy(v))+on(circle,u=1);// Solve for rho

for (real t=dt;t≤T;t+=dt) // Iteration over the time steps dt, to obtainthe time evolution of the equation.rho;plot(u,value=1,fill=1,wait=1);uold=u;

Code for Modelling the Gas Pressure

The equation we want to simulate is

∇ · (∇p2) =2µφ

K

∂p

∂t. (A.4)

With∇p · ~n = β(p− p0). (A.5)

Here β is a proportionality constant, ~n is the vector that is normal to theboundary of Ω and p0 is the pressure outside Ω. For the initial condition wehave

p(x, y, 0) = λ. (A.6)

Where λ is a constant. The code used for the simulation is displayed below

Code

verbosity=0;real dt=0.00001; //Time step in finite differencereal T=5; //Final time that we want to simulatereal a=260 // Value of the constant that multiplies the time derivativereal b=1 // Value of beta

Page 51: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

51

real u0=101300 // Value of p0

real z=0; // Variable that will store the value in the error in the Newtonmethodmesh Th=square(60,60); // Boundary of the domainfespace Vh(Th,P1); Vh u=u0,uold=u0,h,v,ux,uy; // Finite element spacemacro dot(a,b) (dx(a)*dx(b)+dy(a)*dy(b)) // A macro for the dot productof gradientsproblem lineal(h,v)=-int1d(Th,1,2,3,4)(b*2*u*h*v-b*h*u0*v)-int2d(Th)(a*2*h*dot(u,v))+int2d(Th)(a*2*u*dot(h,v))+int2d(Th)(a*h*v/dt)-int1d(Th,1,2,3,4)(b*(u2-u0*u)*v)+int2d(Th)(a*2*u*dot(u,v))+int2d(Th)(u*v/dt)+int2d(Th)(uold*v/dt)+on(1,2,3,4,h=0); //Newton methodfor (real t=0;t¡T;t+=dt) // Iteration for timefor (int n=0; n¡30;n++) // Iteration for the newton methodlineal;u=u+h;z=int2d(Th)(h*h);cout<<”Error of h = ”<< z << endl; // Print the squared norm of h.ux=-dx(u); //partial derivative with respect to x for the pressureuy=-dy(u); //partial derivative with respecto to y for the preesureplot([ux,uy],wait=1,value=true,fill=1); //Plot the velocity fielduold=u;

Code for Two Immiscible Fluids

Here we are going to present the code for the simulation of two immisciblefluids. So far the code run but does not converge. The equation we are tryingto simulate are

∇ · (Kw

µw∇(pc(Snw))−∇ · (Kw

µw∇pnw)− φ∂Snw

∂t= 0, (A.7)

phiM

RTSnw

∂pmw∂t

+φM

RTpnw

∂Sw∂t−∇ · (Kg

µg∇pnw) = 0. (A.8)

Recall from chapter four, that formulas were too long. In the freefem codemost of the formulas used are under the comment section ’//Now we aregoing to define the relevant functions that we are going to need through thesimulation’. Without further adeu we present the code below

Page 52: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

52 APPENDIX A. FREEFEM++ CODES OF THE SIMULATIONS

Code

verbosity=0;mesh Th=square(50,50); //We first take an easy domain, in this case ansquare of 1 by 1real n=1.43, m=1-1/n; // parameter m and n for the relative permeabilitiesreal b=1e-4; //Parameter alpha for the capillary pressurereal muw=8.94e-02; //Viscosity of water. Units: Pascal*secondsreal mug=1.024e-02;//Viscosity of methane. Units: Pascal*secondsreal Swr=0.01;//Residual water saturationreal phi=0.6;//Porosotiy of the materialreal M=0.0164;//Molar mass of methane. Units: Kg/molreal R=8.314;//Universal constant of gases J/(mol*K)real T=300; // Absolute temperature (Kelvin)real alpha=1; // Proportionality constant on Robin’s boundary condition forthe pressurereal p0=101300; // Reference pressure for the Robin boundary condition forthe pressure. Units: Pascalreal dt=0.01; //Time step of the finite difference in timereal Tao=5; // Final time where the simulation ends.z1=0,z2=0; //Variables that will store the error in the convergence of theNewton method.fespace Vh(Th,P1); // Finite element space for the pressureVh p,v,pold=190000-(x-0.5)-(y-0.5),h;fespace Uh(Th,P1); // Finite element space for the saturationUh S,w,Sold=(Swr)*(1-x*y*(x-1)*(y-1)),k;

//Now we are going to define the relevant functions that we are going toneed through the simulationfunc f=1-S/(1-Swr); //Auxiliary functionfunc fprima=1/(m*n*b)*(f (−1/m)−1)(1/n−1)∗f (−1/m−1); //Auxiliaryfunctionfunc fdprima=1/(m2 ∗ n ∗ b) ∗ (1/n − 1) ∗ (f ( − 1/m − 1))2 ∗ (f ( − 1/m) −1)(1/n−2)+1/(m∗n∗b)∗(1/m+1)∗f (−1/m−2)∗(f (−1/m)−1)(1/n−1);// Auxiliary functionfunc ftprima=−2/((1− Swr) ∗m2 ∗ n ∗ b) ∗ (1/n− 1) ∗ f (− 1/m− 1) ∗ (f (−1/m)−1)(1/n−2)+1/(m3∗n∗b∗(1−Swr))∗(1/n−1)∗(1/n−2)∗(f (1/m−1))2 ∗ (f ( − 1/m)− 1)(1/n− 3) ∗ f ( − 1/m− 1) + 1/(m ∗ n ∗ b ∗ (1− Swr)) ∗

Page 53: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

53

(1/m+ 1)∗ (1/m+ 2)∗ f (− 1/m− 3)∗ (f (− 1/m)− 1)(1/n− 1) + 1/(m2 ∗n∗b∗ (1−Swr))∗ (1/m+1)∗ (1/n−1)∗f (−2/m−3)∗ (f (−1/m)−1)(1/n−2);func g=fdprima/(1 − Swr)2;// g function that goes in the laplacian of thecapillary pressurefunc j=-fprima/(1-Swr);// j function that goes in the laplacian of the capil-lary pressurefunc gprima=ftprima/(1− Swr)2; //The derivative of gfunc jprima=-fdprima/(1-Swr); //Derivative of jfunc Kw=f 0.5 ∗ (1− (1− f (1/m))m)2; //This is the relative permeability forwaterfunc Kg=(1−f)(1/3)∗(1−f (1/m))(2∗m); //This is the relative permeabilityfor the methanefunc Kwprima=−1/(2∗ (1−Swr))∗f (−0.5)∗ (1− (1−f (1/m))m)2−2/(1−Swr) ∗ f 0.5 ∗ (1− (1− f (1/m))m) ∗ (1− f (1/m))(m− 1) ∗ f (1/m− 1); //Thederivative of the relative permeability for waterfunc Kgprima=1/(3 ∗ (1 − Swr)) ∗ (1 − f)( − 2/3) ∗ (1 − f (1/m))(2 ∗m) +2/(1−Swr)∗ (1−f)(1/3)∗ (1−f (1/m))(2∗m−1)∗f (1/m−1); //Derivativeof the relative permeability for gasfunc Kwdprima=1/(2 ∗ (1−Swr)) ∗ (0.5 ∗ f (− 3/2) ∗ (1− (1− f (1/m))m)2−2∗f (1/m−3/2)∗ (1−f (1/m))(m−1)∗ (1− (1−f (1/m))m))−2/(1−Swr)2 ∗((1/m− 0.5) ∗ f (1/m− 3/2) ∗ (1− f (1/m))(m− 1) ∗ (1− (1− f (1/m))m)−f (2/m− 3/2) ∗ (1− f (1/m))(2 ∗m− 2) + (m− 1)/m ∗ f (2/m− 3/2) ∗ (1−f (1/m))(m− 2) ∗ (1− (1− f (1/m))m));func G=fprima*(1/(1-Swr))*Kwprima/muw+Kw*g/muw; //Auxiliary func-tionfunc Gprima=fdprima*(1/(1−Swr)2)*Kwprima/muw-fprima*(1/(1-Swr))*Kwdprima*muw+Kwprima*g/muw+Kw*gprima/muw;//auxiliary function 2//Define some useful macrosmacro dot(a,b) (dx(a)*dx(b)+dy(a)*dy(b))// Dot product between 2 gradi-ents

macro n(a) (dx(a)2 + dy(a)2) // Squared norm of the gradient of a func-tion

//Here comes the linearized problem problem linear([h,k],[v,w], solver=GMRES)=int2d(Th)(Gprima*n(S)*v*k)+int2d(Th)(2*G*dot(S,k)*v)-int2d(Th)(Kwprima*j*dot(S,v)*k/muw)-int2d(Th)(Kw*jprima*dot(S,v)*k/muw)-int2d(Th)(Kw*j*dot(v,k)/muw)-int2d(Th)(Kwprima*dot(S,h)*v/muw)-int2d(Th)(Kwdprima*dot(p,S)*k*v/muw)-

Page 54: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

54 APPENDIX A. FREEFEM++ CODES OF THE SIMULATIONS

int2d(Th)(Kwprima*dot(p,k)*v/muw) -int1d(Th,1,2,3,4)(alpha*Kwprima*(p-p0)*v*k/muw)-int1d(Th,1,2,3,4)(alpha*Kw*v*h/muw)+int2d(Th)(Kwprima*dot(p,v)*k/muw)+int2d(Th)(Kw*dot(v,h)/muw)-int2d(Th)(phi*v*k/dt)+int2d(Th)(phi*M*S*h*w/(R*T*dt))+int2d(Th)(phi*M*(p-pold)*w*k/(R*T*dt))+int2d(Th)(phi*M*(S-Sold)*w*h/(R*T*dt)) +int2d(Th)(phi*M*p*k*w/(R*T*dt))-int2d(Th)(Kwdprima*dot(S,p)*w*k/mug)-int2d(Th)(Kgprima*dot(p,k)*w/mug)-int2d(Th)(Kgprima*dot(S,h)*w/mug) -int1d(Th,1,2,3,4)(alpha*Kgprima*(p-p0)*w*k/mug)-int1d(Th,1,2,3,4)(alpha*Kg*w*h/mug)+int2d(Th)(Kgprima*dot(p,w)*k/mug)+int2d(Th)(Kg*dot(w,h)/mug)+on(1,2,3,4, h=0)+on(1,2,3,4, k=0); //Newton method in two

S=Sold; //Initial value for Sp=pold; // Initial value for pfor (real t=dt;t¡Tao;t+=dt) //Iteration for the time evolutionfor (int i=0;i¡10;i++) //Iteration for the Newton methodlinear;S=S+k;p=p+h;z1=int2d(Th)(h*h);z2=int2d(Th)(k*k);cout<<”Error h = ”<< z1 <<endl; //Print the error in the linearizationfor pcout<<”Error k = ”<< z2 <<endl; // Print the error in the linearizationfor S Sold=S;pold=p;plot(S,fill=1,value=1,wait=1,dim=3); //Plot the saturationplot(p,fill=1,value=1,wait=1,dim=3); // Plot the pressure

Page 55: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

Bibliography

[1] Royal Eugene Collins. Flow of fluids through porous materials. 1976.

[2] George F Pinder and William G Gray. Essentials of multiphase flow inporous media. John Wiley & Sons, 2008.

[3] PK Kundu and IM Cohen. Fluid mechanics. 2004, 2008.

[4] Claes Johnson. Numerical solution of partial differential equations bythe finite element method. Courier Dover Publications, 2012.

[5] S Succi. The lattice boltzmann equation for fluid dynamics and beyond,clarendon, 2001.

[6] JN Reddy. Applied functional analysis and variational methods in en-gineering author: Jn reddy, publisher: Mcgraw-hill college pa. 1986.

[7] Eberhard Zeidler. Applied functional analysis, volume 108. Springer,1995.

[8] Frederic Hecht, Olivier Pironneau, A Le Hyaric, and K Ohtsuka.Freefem++. Laboratoire JL Lions, University of Paris VI, France, 70,2007.

[9] George Keith Batchelor. An introduction to fluid dynamics. Cambridgeuniversity press, 2000.

[10] Zhangxin Chen. Finite element methods and their applications, vol-ume 5. Springer, 2005.

[11] http://petrowiki.org/PEH%3ARelative_Permeability_and_

Capillary_Pressure. Accessed: 2014-09-30.

55

Page 56: Simulation of Fluid Flow Through Porous Media · Simulation of Fluid Flow Through Porous Media Juan Gabriel Garc a Osorio Orientador: Juan Galvis ... ow through porous media are coupled

56 BIBLIOGRAPHY

[12] Jan Dirk Jansen. A systems description of flow through porous media.Springer, 2013.

[13] http://www.petrocenter.com/reservoir/re02.htm. Accessed: 2014-10-01.

[14] M King Hubbert et al. Darcy’s law and the field equations of the flowof underground fluids. 1956.

[15] E Fermi. Thermodynamics, 1936. Thermodynamics, 1936, 1956.

[16] Yechezkel Mualem. A new model for predicting the hydraulic conductiv-ity of unsaturated porous media. Water resources research, 12(3):513–522, 1976.

[17] JC Parker, RJ Lenhard, and T Kuppusamy. A parametric model for con-stitutive properties governing multiphase flow in porous media. WaterResources Research, 23(4):618–624, 1987.

[18] M Th Van Genuchten. A closed-form equation for predicting the hy-draulic conductivity of unsaturated soils. Soil science society of Americajournal, 44(5):892–898, 1980.