systems of · pdf filehydrology program quantitative methods in hydrology 154 systems of odes...

13
New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs Chapter 4 your textbook introduces systems of first order ODES. In general, these can be represented by the matrix expression y’=f(t,y), where y = {y 1 , y 2 , y 3 , …, y n-1 , y n } T is a column vector of unknows, t is a scalar independent variable, and the prime indicates differentiation wrt to t. Typically for us the independent variable t is time. This can also be written as shown below, taken from p. 134 (§4.2) of the text: on a t b that satisfy (1) on this interval. In vector form y=h(t) = {h 1 , h 2 , h 3 , …, h n-1 , h n } T . An initial value problem for (1) consists of (1) and n ICs y 1 (t 0 )= K 1 , y 2 (t 0 )= K 2 , y 3 (t 0 )= K 3 , , …, y n (t 0 )= K n , where the K’s are constants, or y(t 0 )=K = {K 1 , K 2 , K 3 , …, K n-1 , K n } T . In all cases that you will see in hydrology, systems of equations, like that in (1) are IVPs (after all, it is a system of 1 st order ODEs). Coupling Equation (1) represents n coupled equations, which can be linear or non-linear. Reasons for coupling. You are likely to run into two cases of coupled equations, and their combination.

Upload: haxuyen

Post on 18-Mar-2018

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

154

Systems of ODEs Chapter 4 your textbook introduces systems of first order ODES. In general, these can be represented by the matrix expression y’=f(t,y), where y = {y1 , y2, y3, …, yn-1, yn}T is a column vector of unknows, t is a scalar independent variable, and the prime indicates differentiation wrt to t. Typically for us the independent variable t is time. This can also be written as shown below, taken from p. 134 (§4.2) of the text:

on a ≤ t ≤ b that satisfy (1) on this interval. In vector form y=h(t) = {h1 , h2, h3, …, hn-1, hn}T. An initial value problem for (1) consists of (1) and n ICs y1(t0)= K1, y2(t0)= K2, y3(t0)= K3, , …, yn(t0)= Kn, where the K’s are constants, or y(t0)=K = {K1, K2, K 3, …, K n-1, K n}T . In all cases that you will see in hydrology, systems of equations, like that in (1) are IVPs (after all, it is a system of 1st order ODEs).

Coupling Equation (1) represents n coupled equations, which can be linear or non-linear. Reasons for coupling. You are likely to run into two cases of coupled equations, and their combination.

Page 2: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

155

• In the first case the y’s represent different, but coupled processes. For example, consider fluid flow in a porous media and coupled heat transport. There are two coupled equations (n=2). y1 would represent temperature and y2 hydraulic head. Add in a solute and you get a third equation (since now n=3) that represents solute concentration, y3. The equations are coupled since both temperature and solute affect fluid density and viscosity, while fluid flow advects heat and solute.

• In the second case the y’s represent discrete nodal values of a spatially distributed unknown,

such as concentration, where the spatial domain that has been numerically approximated by finite differences, finite elements or some other method, where there are n such node points. In this case a time-space PDE (like time dependent advection-diffusion) has been reduced to a set of n time dependent ODEs, one for each node, and space no longer exists. That is, y remains continuous in time t, but discretized in space. Thus y23(t) would represent the value of y (e.g., concentration) at spatial node 23 at time t.

(If (1) is solved numerically, say via the backward Euler method, the system of simultaneous ODEs becomes a system of simultaneous (coupled) algebraic equations that march forward in time.) Simultaneous or sequential coupling In practice coupling can be sequential or simultaneous. Another set of equivalent terms is explicit or implicit coupling. In simultaneous coupling equations (1) are solved together, simultaneously, or at least approximately so. If (1) is linear this is done using linear matrix algebra with a matrix equation solver like Gaussian Elimination. It is implicitly realized that each y depends on the others. In sequential coupling one equation (one line of (1)) is solved and fed into the next, and so on. The assumption is that y2 depends on y1 but not the other way around. This works perfectly well for systems which are truly sequentially coupled, but is a very crude way (and often inaccurate or even unstable way) of handling problems that are actually simultaneously coupled. Nevertheless, it is sometimes employed in hydrology. Consider, as an example, the common assumption that flow does not depend on temperature (i.e., ignore the dependence of fluid viscosity and density on temperature), but heat transport and temperature depend on flow. Solve the flow problem then use that solution to advect heat. Mixed sequential/simultaneous solutions are sometimes used. For example, a common approach to solving coupled multiphase flow (oil, water and gas) is to use an IMPES scheme, meaning implicit (IMP) pressure, explicit (ES) saturation. If it fails to work then most codes give you the choice to use a full simultaneous solution approach. In any event, your book focuses on true simultaneous coupling, as will I. Linear Systems (text, §s 4.2, 4.3, 4.4, 4.6) First, carefully read Example 1 in §4.1 on p. 130 of the text, before continuing. It describes a linear problem with two coupled equations describing solute mixing between two tanks. This has applications in hydrology, for example mixing of a tracer in two tanks prior to injection in an aquifer or stream. More commonly, this is analogous to mixing between two hydrologic reservoirs, such as wind driven circulation mixing of two portions of a lake.

Page 3: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

156

Or eqn. (a) on p. 162 of these notes.

Page 4: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

157

Let’s explore the mathematics behind this solution. The system of equations in (1) on p. 154 of these notes is y’=f(t,y). It represents any system of 1st order ODEs. If, however, the system of equations is linear it can be simplified to y’=Ay + g, as

Questions:

Page 5: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

158

described below, and as taken from the text p. 137 and §4.6 …

The linear matrix equation (1) can be rewritten as a set of simultaneous (linear) algebraic equations. For example, if there are two unknowns, y1(t) and y2(t), then these equations are

[ASIDE: Recall the 2nd order ODE BVP finite difference numerical solution where we wrote, Ay=b, where b was the load vector. The sign on either the coefficient matrix or the load vector must be changed to be consistent with the signs in Chapter 4 of the text. Or just let g = -b.] Matrix Vector Notation We’ve previously introduced and used matrix-vector notation. In any event, our text reviews this in §4.0 and gets into more detail in Chapter 7. However, our previous discussion in class was limited to matrix algebra. We needed to define y’ in (1) (p. 125 and 126 of the text) to get the result above. Page 127 of our text extends the discussion to include:

+g1

+g2

+g1

+g2

+gn

+2

+1

The full

The entries aij’s represent links between two dependent variables, yi and yj.. When n is large, A is usually very sparse, as each yi is connected or coupled to relatively few of the other states yj (j≠i).

load

Page 6: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

159

Superposition Principle We set g=0 in the linear equation (1), on p. 126, to get the homogenous equation y’=Ay.

Homogeneous Solution (text, p. 137-139) When the text refers to equation (4) it is referring to the homogeneous equation (4) y’=Ay From p. 138 the text:

We can write n solutions y(1), y(2), y(2), … y(n-1), y(n) of (4) on some interval J as columns of an nxn matrix, Y (6) Y = { y(1), y(2), y(2), … y(n-1), y(n) }

for g=0 and n=2, as

Differentiation.

Page 7: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

160

Method of Constant-Coefficients and Eigenvalue Problems §4.3 Reconsider the linear, homogeneous matrix ODE equation (1) y’=Ay where t is the independent variable. By definition it has constant coefficients iff the ai,j entries do not depend on t (they already don’t depend on y, as the system is linear). A single ODE of the form y’=ay has a solution of the form y=C eat. This suggests a form for the solution of the matrix equation. (2) y =x eλt where x is a vector of constants, and λ is a scalar “decay or growth coefficient” of some kind. Substitute (2) into (1) to get y’= λ x eλt = Ay = A x eλt Divide by eλt (you can’t divide by x, it’s a vector) to get (3) Ax = λx If we solve this problem for λ and x we can substitute into (2) and have the solution for (1).

W=|Y|

Page 8: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

161

For every λ there is a trivial solution, x=0 (a vector of n zeros). But there are λ values for which the solution is non-trivial, x≠0. These λ values are called eigenvalues of A, and corresponding to each is a vector x called the eigenvector of the eigenvalue λ. Equation (3) is an eigenvalue problem (see text, p. 129). There are n linearly independent eigenvectors x(1), x(2), … x(n), and corresponding eigenvalues λ(1), λ(2), … λ(n).

ASIDE: when solving time-space PDEs, some numerical schemes discreteize in space (n nodes points) and then solve in continuous time by assuming a solution of this form. Some fields call this the matrix exponential approach. It is sometimes used in hydrology, especially in so-called data assimilation schemes. We can rewrite the eigenvalue problem (3) as (A- λI)x = 0 For x to be non-trivial the determinant of the coefficient (A- λI) must be zero (see Cramer’s Theorem of linear algebra –next page of these notes- and its proof, pp. 312-314 of the text). If n = 2, then we can solve directly using linear algebra. For n > 2 things quickly become messy (as a student I once required to solved an eigenvalue problem by hand with n=5; it was tedious.). There are very efficient numerical solvers for eigenvalue problems (see text, §s 20.6-20.9), including those in Matlab. For n = 2 the expression (A- λI)x= 0, becomes (see text p. 129)

=

−00

2

1

2221

1211

xx

aaaa

λλ

or 0)(0)(

222121

212111

=−+=+−

xaxaxaxa

λλ

(a)

In this case the determinate of (A- λI) is

Det (A- λI)=| A- λI |=λ

λ−

2221

1211

aaaa

which we set to zero, or 211222112211

2 )( aaaaaa −++− λλ =0 (b)

Page 9: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

162

This quadratic equation is called the characteristic equation of matrix A. It has two roots for a solution, which provide the two eigenvalues, λ(1) and λ(2), for this two unknown (x1, x2) problem. Then, for each root, substitute it into simultaneous equations (a) and solve for the corresponding eigenvector, perhaps by Gaussian Elimination, yielding, respectively, x(1) and x(2). Your textbook has several examples. Cramer’s Rule (pp. 312-314 of text)

Page 10: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

163

Method of Constant-Coefficients: Phase Plane, Critical Points, Stability, Attractors §4.3 and 4.4 The later information in these sections on linear equations, and in the next section (§4.5) on non-linear equations, talks about solutions to coupled problems and introduces phase portraits. It is important, but it is beyond the scope of our effort this semester.

This is the route to looking at chaos theory and limits to prediction (how far into the future is a prediction reliable, limited by coupling and non-linearity) in weather, climate and hydrologic systems. You start out with simple coupled non-linear equations, and they reveal 50% of the issues encountered in large models. If you are interested you can follow up on your own or take a math class; I can also suggest additional reading for the future; or we can also talk about it off line. Method of Undetermined Coefficients: particular solutions §4.6 Recall from notes, p. 156, or text p. 159:

The textbook continues on p. 160, referring to the method of undetermined coefficients as an approach to the particular solution:

Page 11: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

164

See text, p. 160, for example. We could also use the method of variation of parameters, but we skipped that for a single unknown and will skip it again here, for multiple unknowns. Numerical Methods in independent variable t (not in text) Suppose we want to solve the nonhomogeneous, linear model, (1) y’=Ay+g, where t is the scalar independent variable, A is a coefficient matrix (not depending on y) and y is the column vector of unknowns, using a numerical method in t. We simply scale up the 1st order methods introduced before. Euler methods For example, we can use any θ-Euler method, although it is usually a forward, backward or midpoint Euler scheme that is employed. Let’s write the θ-Euler method, from (37) on p. 103 of the notes, changing notation to that of (1). (2) [ ]111 )1(])1([)( +++ +−∆+−∆+≅∆− kkkkkkkkk ttt ggyAIyAI θθθθ where I’ve replaced scale p on p. 3 with matrix –A, the number 1 with the identity matrix I, the load r with the load vector g, the step size ∆x with the time step, ∆t, the step index n with the time step index k. Notice that we’ve maintained a variable step size, ∆tk = tk +1 – tk, and that we’ve allowed A and g to also vary in time. It is easy to simplify (2) for either a constant time step, or to a constant-in-time A and g. Please note that all of the Taylor Series work and other derivation we did for the single ODE applies here, especially truncation and stability analyses. (Aside: Recalling that work, you should also be able to relate (2) to the matrix exponential approach of (5) in §4.3 (and p. 159 of these notes), and see how (2) above represents a truncated series expansions of the matrix exponentials, and that the eigenvalues are essentially like the reciprocal of a time constant – actually n time constants, where n is the number of eigenvalues.) Now you will see how the choice of weight θ influences coding, as well as results. If θ=0, as it is in an explicit forward-in-time (FIT) Euler method, we can easily invert the coefficient matrix on the LHS, as I-1 = I. The result is (3) FIT scheme kkkkkk tt gyAIy ∆+∆+≅+ ][1 As you can see, we don’t need a matrix equation solver. The FIT or explicit method only involves inexpensive matrix-vector multiplication. Notice, too, that having A and g vary in time doesn’t change the matrix math. In fact, A and g can vary with y as well as t and the problem can

Page 12: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

165

be non-linear. The explicit method can handle it. However, the method is only conditionally stable, as we discussed on p. 106 of these notes. The time step, ∆t, is limited by the smallest of the n “time constants” of the system of equations, that is, the largest of the n eigenvectors, λ. Let’s consider the backward-in-time (BIT) scheme, with θ=1. Then (1) becomes (4) BIT scheme 111)( +++ ∆+≅∆− kkkkkk tt gyyAI We have to invert the matrix (I- ∆tk Ak+1), a much more expensive operation, especially as n gets large. Actually, we don’t invert the matrix. Instead, we solve (4) by an equation solver like Gaussian Elimination (depending on the algorithm this has from n2 to n3 operations). Notice in (4), that if A and time step are constant in time, your equation solver only need to decompose the coefficient (I- ∆t A) once, say with LU decomposition. You can then solve (4) at each time step by back substitution, very inexpensively. This is typical of trade-offs in numerical solutions. There is also the popular midpoint (p. 104 of the notes) or Crank-Nicholson scheme, θ=0.5, particularly popular when the y’s represent spatially distributed node points of a space-time PDE. I’ll leave that one as an exercise for you to write out. You’ve already learned how to build A for a finite difference approximation to a 2nd order equation (ODE) in space. Thus you should now be able to set up (3) or (4) for a finite difference method in space and, respectively, a FIT or BIT method in time. From separate presentations on matrix methods, you also know how to solve the matrix problems in (3) and (4). Without having written a PDE you are already set up to solve one. Example: Let’s revisit Example 1 from p. 140 of the text, repeated above on p. 156 of these notes. Recall that it involves two unkowns for solute concentration in each tank, represented by the homogeneous equation y’=Ay, where y is (2x1) vector of unknowns and A is (2x2) coefficient matrix,

−=

02.002.002.002.0

A

Since the equation is homogeneous g = 0. Thus the BIT Euler method (4) becomes kkkt yyAI ≅∆− +1)( where the subscript on A has been dropped, since A remains constant. We can solve this example by the BIT FDM by Gaussian Elimination every time step. Try it and compare to the exact answer. It may help to write it out fully,

kk

k yy

yy

t

=

−∆−

+ 2

1

12

1

02.002.002.002.0

1001

,

or, if you prefer,

Page 13: Systems of · PDF fileHydrology Program Quantitative Methods in Hydrology 154 Systems of ODEs ... Theorem of linear algebra –next page of these notes ... but it is beyond the scope

New Mexico Tech Hyd 510 Hydrology Program Quantitative Methods in Hydrology

166

kkkkk

kkkkk

yyytyyyyty

,21,21,11,2

,11,21,11,1

)02.002.0()02.002.0(=−∆−=+−∆−

+++

+++ .

Gathering terms,

kkkkk

kkkkk

yytytyytyt

,21,21,1

,11,21,1

)02.01(02.002.0)02.01(

=∆++∆−=∆−∆+

++

++ ,

or back to matrix form

=

∆+∆−∆−∆+

+

+

k

k

k

k

kk

kk

yy

yy

tttt

,2

,1

1,2

1,1

02.0102.002.002.01

where it is this latest matrix that you assemble and then use in the Gauss Elimination solution for each time step. Other methods in time You can also use other numerical methods in time. While Euler methods are the most popular, some codes use multistep methods. For various reasons, Runge-Kutta methods are not used to solve (1) for most typical hydrologic models, unless y represents the two or three dimensional spatial coordinates of particle being tracked (Euler Methods are also used). In that case one is solving the more general problem y’=f(t,y), where f is the velocity vector at time t. Runge-Kutta-Fehlberg (p. 893 of text) is popular for this purpose.