Numerical Simulation Basics: Part II – Boundary Conditions & Numerical Stability

Jim Boyle, Western Connecticut State University, Physics, Meteorology and Physical Oceanography

Author Profile
Initial Publication Date: January 29, 2025

Summary

This is the second and last activity teaching numerical simulation basics to students in a junior-level physical oceanography course. In the first activity students program solutions for a 1st order differential equation in MATLAB, then characterize the accuracy of these solutions considering various time steps and both first order and second-order accurate finite-differencing schemes. This second activity extends student knowledge by introducing numerical boundary conditions and numerical stability criteria. This is implemented using the law of conservation of energy for a fluid, including one-dimensional advection and parameterized turbulent diffusion. With some modification, this activity could be used in a physics of fluids course or an introductory engineering fluids course.

Share your modifications and improvements to this activity through the Community Contribution Tool »

Learning Goals

1. Primary goal is to have students gain more experience in methods to convert a theoretical equation characterizing a physical process into a finite-difference equation,
2. Students learn numerical simulation models in the geosciences represent physical processes which will evolve in time within a spatial domain.
3. Students learn numerical simulation models must incorporate boundary conditions which are applied at the edges of the model domain,
4. Students learn about numerical stability and how numerical stability criteria relate to simulation model parameters such as time step size and spatial grid size.
5. Students learn numerical simulation models can be a useful tool to investigate the influence of physical quantities on a system, such as advection and turbulent diffusion.

Context for Use

This activity is taught as part of the laboratory component for a junior-level physical oceanography course with class sizes up to 20 students. Pre-requisites for this class include calculus-based physics, introductory statistics, and introductory computer science. The students have one semester experience with programming typically in the Java or Python languages. Overall, the laboratory includes three modules: (1) introduction to scientific computer programming in MATLAB, (2) hands-on experiments in physical oceanography and (3) web-based activities associated with physical oceanography. Data processing, analysis and visualization using MATLAB are introduced in module one and reinforced in modules two and three.

This is the second and last activity in a set introducing students to rudimentary numerical simulation methods; it occurs in the last weeks of the course, so students have good basic programming skills. While the first activity focuses on numerical accuracy and model validation, this activity introduces the concepts of boundary conditions and numerical stability.
This second activity incorporates the physical processes of advection and diffusion (learned earlier in the course) into a hypothetical start for an El Nino event thereby keeping students' attention on oceanography.

During the first 20 minutes of the laboratory period the instructor reviews a 3-page handout document (attached) and a partially complete M-file (attached) with the students. Each group of two students has the remainder of the laboratory period (90 minutes) and the following week to complete the assignment. The instructor circulates during the 90-minute time providing guidance to students and answering questions. The second laboratory session allotted for this activity can be spent by the students using their functioning code to investigate model parameters and to complete the assigned deliverables, especially the two-page worksheet. The deadline to submit all deliverables (see assessment) is the end of the second laboratory period.

Description and Teaching Materials

This activity is the second part of a three week-long assignment in a junior-level physical oceanography course.

The primary focus of the physical oceanography laboratory is introducing students to scientific computer programming in MATLAB, so the first six weeks of laboratory sessions are used to teach MATLAB basics. During this period, we review the first two-thirds of the textbook "Essential MATLAB for Scientists and Engineers" B. Hahn and D. Valentine (see references). The last eight weeks of the course are used to apply computational methods towards solving problems in physical oceanography, including data processing, analysis and visualization (e.g., two- and three-dimensional graphics) using MATLAB as well as numerical simulation basics.

The first activity introduces students to rudimentary numerical simulation methods. It establishes a numerical model for a freely falling object – a concept students are familiar with from prerequisite courses and from life experience. Its focus is to teach about numerical accuracy (1st and 2nd order schemes) and that all numerical simulation models should be validated. The first activity is stand-alone and can be used in a variety of science and engineering courses. It is available at: https://serc.carleton.edu/teaching_computation/workshop_2023/activities/279846.html

This second activity (Part II) develops a more complex numerical model directly related to physical oceanography. The physical process of interest is a hypothetical migration of the western tropical Pacific warm pool eastward along the equator in association with an incipient El Nino event. This situation is modeled using a partial differential equation – a simple one-dimensional temperature advection process with diffusion, it is not intended to capture the features of an equatorial Kelvin wave. Numerical simulation concepts introduced in Part II include generating a uniform spatial grid in geophysical coordinates, developing open boundary conditions and investigation of numerical stability criteria. This Part II assignment is taught during the subsequent two laboratory periods.


Part II Laboratory Activity Discussion (Acrobat (PDF) 233kB Nov8 24)
Written Assignment for Students (with solutions) (Microsoft Word 2007 (.docx) 27kB Nov8 24) 
M-file Script for One Dimensional Advection (Matlab File 6kB Nov8 24) 
M-file Script for One Dimensional Advection with Diffusion (Matlab File 6kB Nov8 24) 

Teaching Notes and Tips

It is important to have the students start work on the assignment by completing the initial questions (A.1, A.2 and B.1) in the hand-written assignment. These questions focus student attention on the recursion relations for advection, diffusion, and the boundary conditions. This will allow a significant portion of the programming to be completed efficiently during the initial laboratory session when the instructor is available to answer questions as the students write code.

It should be stressed to the students they must get their programs to function during the week-long period between laboratory sessions. Then the second laboratory session allotted for this activity can be spent by the students using their functioning code to investigate the model parameter (e.g., eddy diffusivity, time-step size, grid-space size) influences on numerical stability and to complete the assigned deliverables.

Detailed comments relevant to Programming

For the centered-difference (2nd order accurate) and Adams-Bashforth (3rd order accurate) numerical schemes, students typically have difficulty starting the for loop index at n = 2 and n = 3, respectively. Students can also be confused about coding the left-hand boundary condition because MATLAB indexing starts at 1 (not 0).


Assessment

For each MATLAB activity, students are given a list of Deliverables. Completion of these deliverables should ensure students meet the goals for the activity. The deliverables for the activity include submittal of:

1. individually hand-written answers to questions posed in a two-page handout,
2. an M-file script for each group of two students, [Learning Outcome # 1]
3. a two-dimensional graphic, properly annotated with titles and axis labels. This graphic is a longitude-time Hovmoller diagram. [Learning Goal # 5]

The hand-written questionnaires (attached) and the Hovmoller diagram (figure 1 in the discussion attachment) are manually graded, with scores based on points for each answer. The instructor has access to and runs the M-file script from each group of two students – this script must function properly.

Assessment Rubric  compare student answers in their two-page handout with answer key:

Questions: A (page 1), B (page 2)
A.1, A.2, A3(a), (b), (c), (d)
B.1, B.2(a), (b), (c), (d), B.3

1. Learning Goal # 1; Questions: A.1, B.1
2. Learning Goal # 2; Questions: A.3a, A.3b, B.2a
3. Learning Goal # 3; Questions: A.2, A.3c, B.2c
4. Learning Goal # 4; Questions: A.3d, B.2d
5. Learning Goal # 5; Questions: A.3a, A.3b, B.2b, B.3

References and Resources

This is Part II of a two-part activity wherein students learn the basic concepts and methods of numerical simulation. Part I is available at:

https://serc.carleton.edu/teaching_computation/workshop_2023/activities/279846.html

Textbook: "Essential MATLAB for Scientists and Engineers", Fifth Edition, Chapter 12 and Chapter 14; B. Hahn and D. Valentine, ISBN-13 978-0123943989

Reference: "A First Course in Atmospheric Numerical Modeling", First Edition; A. DeCaria and G. Van Knowe, ISBN-13 978-0972903349