Mauro A. Werder · Modelling conduits in 1D ThisafternoonIwilltrytoshowyouhowtomodelaconduitin1D...

Post on 06-Oct-2020

5 views 0 download

Transcript of Mauro A. Werder · Modelling conduits in 1D ThisafternoonIwilltrytoshowyouhowtomodelaconduitin1D...

Modelling subglacial hydrology

Mauro A. Werder

University of Bristol

Modelling conduits in 1DThis afternoon I will try to show you how to model a conduit in 1D(Kessler & Anderson 2004, Schoof 2010)

(Schoof 2010)

1) mass conservation∂S

∂t+∂Q

∂s= M

2) turbulent flow Q = −kSα∣∣∣∣∂φ∂s

∣∣∣∣β−2 ∂φ

∂s

3) opening and closure∂S

∂t=−Q∂φ

∂s

ρiL−AS|N |n−1N + uh

(slightly simplified notation, corresponding to notation in code)

Getting side-tracked

First some remarks about numerical modelling in general:• discretisation: space, time• solving ODE/DEA

Discretisation in space

Many possibilities: finite differences, finite volumes, spectralmethods, finite elements

Finite elements:• Who has used them?• More complicated than finite difference & volume• But more flexible

Discretisation in space: weak formThe strong form of the Poisson equation is

∂2u

∂x2− f = 0

For the weak form, multiply by a test function θ and integrate∫ x1

x0

θ

(∂2u

∂x2− f

)dx = 0

integrating by parts∫ x1

x0

(−∂θ∂x

∂u

∂x− θf

)dx+

[θ∂u

∂x

]x1x0

= 0

The finite element method is based on the weak form, so we’ll needto put our hydro-equations into this form.

Discretisation in time

Usually the spatial discretisation using for instance finite elements isnot used for the time discretisation.

This is called Method of lines.

Thus the spatial discretisation turns the PDEs into a set of coupledODEs, which are then solved with a ODE solver.

Here we’ll use Matlab’s ode15s.

Exercise: rearrange equations

Make two equations for φ and S by eliminating Q and SS :

1) mass conservation∂S

∂t+∂Ss∂t

+∂Q

∂s= M

2) turbulent flow Q = −kSα∣∣∣∣∂φ∂s

∣∣∣∣β−2 ∂φ

∂s

3) opening and closure∂S

∂t=

Ξ

ρiL−AS|N |n−1N + uh

where the stored volume water per unit length is

Ss = σpw = σ(φ− φm)

with φm = ρwgH and Ξ = −Q∂φ∂s .

Exercise: weak form

Make the weak form of

φ equation σ∂φ

∂t+∂Q

∂s+

Ξ

ρiL−AS|N |n−1N + uh−M = 0

S equation∂S

∂t=

Ξ

ρiL−AS|N |n−1N + uh

Exercise: weak form

Weak form of φ equation∫ x1

x0

[θσ∂φ

∂t− ∂θ

∂xQ+ θ

ρiL−AS|N |n−1N + uh−M

)]dx

+ [θQ]x1x0 = 0

The S equation is left as is as it is only an ODE in S and not aPDE, thus does not need spatial discretisation.

Exercise: basic outline of program

Using a methods of lines strategy and ode15s, what is the basiclayout of program to solve the conduit equations.

It should be super brief and contain function calls to handle:• parameter handling• objective function evaluating ∂y

∂t

• call to ode15s

Exercise: basic outline of program:a solution

% get pa ramete r spara = model_para ( ) ;

% o b j e c t i v e f u n c t i o n hand l eob j f un = @( t , y ) o b j e c t i v e f u n ( t , y , para ) ;

% s o l v e w i th ode15s[ t , out ] = ode15s ( ob j fun , para . tspan , para . IC , para .

odeopt s ) ;

It’s good to think about basic structure of code first

Objective function

f u n c t i o n dydt = o b j e c t i v e f u n ( t , y , p ) ;. . .

%% c a l c u l a t e dphi_dtgrad_phi = p . Dx_en ∗ ph i ;

Q = − p . k ∗ S .^p . a l pha .∗ ( grad_phi .^2+p . t i n y ^2) . ^ ( ( p . beta −2)/2) . . ..∗ grad_phi ;

dphi_dt = −p . Dx_en ( : , p . anodes ) ’ ∗p . in t_ee∗ Q + . . .p . int_ne ( p . anodes , : ) ∗ ( Xi /p . L ∗ (1/p . rho_i − 1/p . rho_w) . . .

+ p . u∗p . h − p .A∗S .∗N.^p . n − p . mean_en∗M) ;

% s e t Neumann BCdphi_dt = dphi_dt + p . int_ne_bdy ( p . anodes , : ) ∗ p . BCval ( p . BCtype==2) ;

%% c a l c u l a t e dS/ dtdS_dt = Xi /( p . rho_i∗p . L) + p . u∗p . h − p .A∗S .∗N.^p . n ;% Note , no boundary c o n d i t i o n s a r e needed as t h i s i s an ODE

Note how it mirrors the weak form of the φ equation.

Download example code

Download code from:https://bitbucket.org/maurow/1dhydro/overviewand unzip.

Or:git clone https://maurow@bitbucket.org/maurow/1dhydro.git

Exercise:Make residual for Poisson equation

Open ex_poisson/poisson_exercise.m and add the residualcalculation. (ex_poisson/poisson_solution.m contains the solution, no cheating though!)

The weak form of the Poisson equation is given by∫ x1

x0

(k∂θ

∂x

∂u

∂x− θf

)dx = 0

The boundary term[θ ∂u∂x

]x1x0

drops out because of the choice ofboundary conditions: φ = 0 at x0, x1.

Check whether it works by running the script.(make sure to execute startup.m first)

ODE solving

For time dependent problems, after discretising in space we’re leftwith a system of coupled ODEs (or DAEs).

The solution of the resulting ODEs/DAEs is fairly easy thanks toMatlab’s solvers.

ob j f un = @( t , y ) o b j e c t i v e f u n ( t , y , para ) ;

%% s o l v e[ t , out ] = ode15s ( ob j fun , para . tspan , para . IC , para . odeopts ) ;

Exercise: dissect 1Dhydro code

Have a look at the code in ex_schoof/.

Start with runner.m and dig down.

Exercise: run 1Dhydro examples

Run the four examples by executing runner.m.(make sure startup.m is executed first).

Visualise the solutions with:

>> p l o t ( x , para .H) % p l o t geometry>> an i %animate>> p l o t_ t im e s e r i e s% animate wi th v a r i a b l e s o f you cho i c e :>> animate ( para , { phi , S,−Q} , 0 . 0 5 , [ ] , { ’ \ ph i ’ , ’ S ’ , ’Q ’ })

Exercise: run 1Dhydro examples

Think about:

• realistic results?• how does the seasonal forcing work?• how do the boundary conditions work?• what trick is used to make the lake in the jökulhlaup example?

Exercise: run 1Dhydro examples

Think about:

• realistic results?The transition from cavity to R-channel seems too fast. Ismass conserved?

• how does the seasonal forcing work?p.M is turned into a function of time, c.f.seasonal_source.m.

• how do the boundary conditions work?They can be set in the model_para*.m files.

• what trick is used to make the lake in the jökulhlaup example?The storage sigma is set to a very high value at theuppermost node, thus simulating a lake.

Tips and tricks

• spend time looking after your code: refactor• never copy-paste code: make functions instead• document code• document model runs:self-documentingmake reproducable model runs

• use version control to keep track of your code changes