Earth and Space Sciences ESS 590 B
Introduction to Heat and Mass Flow Modelling in Earth Sciences

Sample codes

This page links to sample matlab codes that illustrate ideas in class on heat and mass flow.

Steady Heat Flow - I

These m-files find 2-D steady-state temperature using the Finite-Volume method.

  • Temperature is specified on 1 boundary, flux on other 3 boundaries.
  • Volume dimensions (dx,dz) are uniform throughout the solution domain.
  • Boundary conditions are applied to volume interfaces.

Steady Heat Flow - II

Updated steady-state 2-D heat flow and both Finite Volumes and Finite Difference solutions are implemented (choice based on value of variable "fvm").

  • Boundary conditions are applied at volume centers on the boundaries,as described in Patankar.
  • volume dimensions dX and dZ can differ spatially.
  • Includes analytical solution in 1-D using polynomials to represent conductivity K(z) and source term S_C(z). These solutions can be compared against numerical solutions.

Transient Heat Flow - I

2-D transient diffusion with implicit time stepping.

  • fvm_soln_transient_bdry_nodes.m sets up parameters a_P etc and includes time-stepping loop.
  • includes a (kludged) variable mixing factor "0<=theta<=1" to allow exploration of implicit, Crank-Nicolson, and explicit schemes.
  • uses same old "solver.m" to solve matrix equation at each time step.
SS Centered-difference Advection

This code solves steady advective-diffusion in 1-D using a central-difference representation of advection. This method can have negative coefficients when F=F/D>2. Don't use it for real problems!

  • 1 row of finite volumes
  • zero flux out transverse sides
  • specified values at top and bottom

m-file diffusion_SS_1D_adv.m runs several different values of nz, number of finite volumes in z direction. Different Peclet numbers are associated with each dz. Some are >2, some are <2.

Execution "Pauses" after each nz is selected. Press any key to continue.

SS 1-D Advective Diffusion, Power-Law scheme

Solves steady 1-D advective diffusion for a series of models with various Peclet numbers and grid sizes. and for either central-difference scheme (bad) or power-law scheme (good).

Hits "pause" after each plot - press any key to resume.

SS 2-D Advective Diffusion

This code puts finite-volume edges on boundaries, but also includes extra nodes on those boundaries to facilitate incorporation of eithe phi-value or phi-gradient Boundary Conditions at every boundary node. (Patankar Practice B, p. 69).

Patankar's Power-law advective scheme is used.

SS Illustration of False Diffusion in 2-D

SS 2-D Adv-Diff code above is used to run a sequence of models illustrating false diffusion when strong flow is not aligned with coordinate axes.

Transient 2-D Advective Diffusion

By incorporating minor changes to the SS 2-D Advective Diffusion code above, this code solves transient problems.

phi-Dependent Coefficients

This variation on 2-D advective diffusive code solves a steady 1-D problem where teh coefficient Gamma depends on solution phi

Internal BC

Sometimes you may want to fix the value of phi at volumes remote from the actual domain boundary. Following Patankar (1980) p. 145, this can be done with the source term. The example uses the 2-D transient advective diffusive code, with a block of volumes held at a constant value of phi.

SH Wave Propagation

By converting the first tme derivative into a second time derivative, the diffusion equation can be transformed into a wave equation, applicable to SH waves traveling through the Earth.

phi becomes displacement u, and Gamma becomes shear modulus.

1D Stability Analysis

This code finds wavenumber transfer functions for 1D transient diffusion, for specified kappa, dx, and dt. It then carries out a corresponding 1D time-domain finite difference simulation. Users can see how the transfer functions are useful.

One-point Transient Response

Code evaluates the response of a single node when adjacent points are held fixed. Solutions are shown for 3 levels of discretization: 

  • no discretization
  • only space discretized
  • space and time discretized

Steady Heat Flow - I
Steady Heat Flow - II
Transient Heat Flow - I
SS 1-D Advective Diffusion, central difference
SS 1-D Advective Diffusion, power-law scheme
SS 2-D Advective Diffusion
False Diffusion
Transient 2-D advective diffusion
phi-Dependent coefficients
Internal Boundary Conditions
SH Wave propagation
1D Stability analysis
One-point Transient response