Chapter 2
Review of vector calculus
In this section we will review the necessary concepts from vector calculus that we will use in this course. These include: scalars, vectors and tensors; gradient, divergence, and curl; line, surface, and volume integrals; and the Gauss and Stokes theorems.
Scalars, vectors, and tensors
In this book we will use three types of quantities to describe fluid properties: scalars, vectors, and tensors.
Scalars are completely described by their magnitude. Examples of scalars are temperature, pressure, or density. A value of 290 K, for example, completely describes the temperature of a fluid at some point in space and time. The fundamental scalar fields in fluid mechanics are the pressure, density, and in some derivations, the velocity potential. In the atmosphere, density is often represented with the air temperature and humidity scalars through the ideal gas law. In the ocean, density if typically represented with the water temperature and salinity scalars through the equation of state. The fundamental scalars for us are then, in this approximate order, pressure, density, temperature, water salinity, and air humidity. In equations, we will write scalars using italics, e.g. , , or .
Vectors have a magnitude and a direction. Examples of vectors are velocity, acceleration, or force. In 3-dimensional Cartesian space with coordinates , for example, vector can be described by its components
where , , and (each a scalar) are the components of in the , , and directions, respectively. This is the general conventional notation, however, we will often write vectors inline as . The fundamental vector field of fluid mechanics is the velocity. Many other vector fields are derived from velocity, such as vorticity, acceleration, and force. In equations, we will write vectors using boldface, e.g. , , or .
The magnitude, or norm, of a vector is written as and calculated as
Here we’re working in 3-dimensional Cartesian space, but vectors can be defined in any number of dimensions, and the above definitions generalize exactly how you’d expect them to. The most ubiquitous vector field in fluid mechanics is the velocity. In atmospheres and oceans, we will often refer to the velocity as wind and current, respectively. Wind speed is thus the magnitude (norm) of the wind vector, and likewise for the current speed.
Tensors have magnitude, direction, and orientation. They are vectors that act on each respective surface orthogonal to the direction of the tensor. Arguably the most important tensor in fluid mechanics is the stress tensor. In 3-dimensional space, for example, a stress tensor can be described as:
In this notation and index ordering, i.e. , the first index () refers to the direction of the stress component, and the second index () refers to the direction of the normal to the surface. In other words, each row of the tensor contains the three components of a vector, and each column contains the three surface normals that the stress component is acting on. For example, is the stress in the x-direction and is acting on the surface whose normal is in the y-direction (and which lies in the x-z plane).
One special type of tensor is the identity tensor , which is a tensor that maps a vector onto itself. In Cartesian coordinates, it is given by:
It may be useful to think of scalars as 0-order tensors, vectors as 1-order tensors, and tensors as 2-order tensors.
Unit vectors
Unit vectors are vectors with magnitude of 1. A popular notation for unit vectors in Cartesian coordinates is , , and , which point in the , , and directions, respectively. So, a vector can be written as
Notice that you can get the unit vector by dividing any vector by its magnitude, i.e. .
Vector operations
Two vectors can be added, subtracted, or multiplied. Although vector addition and subtraction are straightforward (simply add or subtract each of their respective scalar components), vector multiplication is more interesting. There are many ways to multiply two vectors, but the two most important ones for us are the dot product and the cross product.
Dot product
The dot product of two 3-dimensional Cartesian vectors and is an element-wise sum of their components (and thus, a scalar!):
More generally, the dot product of two n-dimensional vectors and is
The dot product is commutative, meaning that .
The magnitude of a dot product of two vectors is equal to the product of their magnitudes and the cosine of the angle between them:
To visualize this relationship, take one vector and project it onto the other. This projection is the magnitude of the vector times the cosine of the angle between them. Now, one vector and the projection of the other onto the first vector are pointing in the same direction, so their dot product is the product of their magnitudes. It can be useful to think of a dot product as collapsing the two vectors into a single scalar that contains contributions from each of their components.
The following listing shows how to manually compute the dot product of two vectors in Python using the built-in arithmetic operators:
import numpy as np
# initialize two vectors; specific values are arbitrary.
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = 0 # initialize the result variable
for i in range(a.size): # loop over indices of the vector
c += a[i] * b[i] # multiply elements and add to the result
Notice that this an exact implementation of the right-hand side of Eq. (2.7). The NumPy library, however, allows element-wise multiplication of vectors, which is both more computationally efficient and more concise:
c = np.sum(a * b) # multiply element-wise and sum up the components
Notice that this is an exact implementation of the middle part of Eq. (2.7). Even though the dot product is simple to implement, as we did above, NumPy provides a function that is even more concise, and likely the most efficient way to compute the dot product:
c = np.dot(a, b)
Although it’s important to understand how to implement the fundamental vector operations by hand, and do it yourself at least once, in practice it’s best to use established libraries such as NumPy, as they are well tested and optimized for computational efficiency.
Cross product
The cross product of two vectors and is defined as:
where means the determinant of matrix .
Using the so-called rule of Sarrus, the cross product can be calculated as:
or:
The result of a cross product is a vector that is orthogonal to both and . Its orientation in space is determined by the right-hand rule: if you point your right thumb in the direction of and your index finger in the direction of , then your middle finger will point in the direction of .
The magnitude of the cross product is equal to the product of the magnitudes of the two vectors times the sine of the angle between them:
So, the magnitude of the cross product is largest when the two vectors are orthogonal. Unlike the dot product, the cross product is anticommutative, meaning that .
In fluid mechanics, a cross product will often come up when we are interested in the rotation of a vector field. For example, vorticity is the curl of the velocity field.
Matrix multiplication
Occasionally, we will need to multiply a vector by a matrix, or, a matrix by a matrix. As a vector is a special case of a matrix in which either the number of rows or columns is 1, the same rules of matrix multiplication will apply when we multiply a vector by a matrix or a matrix by a matrix. These operations are not commutative, meaning that the order of multiplication matters.
Take two matrices and such that
and:
The result of their multiplication is a matrix given by:
That is, the entry of the product is obtained by multiplying term-by-term the entries of the -th row of and the -th column of , and summing these products. In other words, is the dot product of the -th row of and the -th column of . Although the matrices are not required to be square, the number of columns of must be equal to the number of rows of .
Total and partial derivatives
We will denote total and partial derivative operators (for example, in time ) as and . Scalars, vectors, and tensors alike can be differentiated with respect to any variable. A derivative of a vector is simply a vector of derivatives of its components:
and likewise for tensors.
Gradient, divergence, and curl
Now, we introduce another operator that builds on top of previous concepts to describe how scalar and vector fields vary in space. This operator is called del and is denoted by the symbol (pronounced “nabla”):
Written as above, cannot stand on its own but must be applied as an operator to a field. A good way to think about is as of a differential operator, which itself is a 3-dimensional vector that can operate on scalars or vectors. Specifically:
-
is as vector that is a gradient of a scalar field ; it quantifies how changes in space.
-
is a scalar that is the divergence of a vector field ; it quantifies how flows out of a point.
-
is a vector that is the curl of a vector field ; it quantifies how rotates around a point.
Although, strictly speaking, one is a symbol and the other is an operator, (“nabla”) and “del” are often used interchangeably when reading equations out loud.
Gradient
The gradient of a scalar field is a vector field that points in the direction of the greatest rate of increase of . It is denoted by and is defined as
Gradient of a scalar field is a vector that points in the direction of the steepest increase of that field, and its magnitude is the rate of that increase. Imagine hiking up a hill; the gradient of the terrain is a vector that is pointing toward the steepest incline, and its magnitude is the steepness of that incline.
Divergence
The divergence of a vector field is a scalar field that describes the rate at which the vector field flows out of a point. It is denoted by and is defined as
Divergence of a vector field is a scalar that describes how much the vector field is expanding or contracting at a point. Negative divergence is called convergence.
Curl
The curl of a vector field is a vector field that describes the rotation of the vector field. It is denoted by and is defined as
Curl of a vector field is another vector that is orthogonal to the original vector field and quantifies how much the vector field is rotating around a point. When curl is zero, the vector field is said to be irrotational.
Laplacian
The Laplacian is a second-order differential operator that can be applied to both scalar and vector fields. It measures the rate at which field varies in space and is defined as:
Applied to a scalar field , it is:
Applied to a vector , it is applied to each component:
The Laplacian of a scalar is thus a scalar and the Laplacian of a vector is a vector. In some literature you will see the Laplacian written as , but here we will use to avoid confusion with the that we use to denote a finite increment.
Useful vector identities
Curl of a gradient of a scalar field is always zero:
Further, divergence of a curl of a vector field is always zero:
Finally, curl of a curl of a vector field is:
Some of these identities will come handy when we derive the conservation of vorticity laws.
Computing and visualizing gradient, divergence, and curl
WIP
Gauss and Stokes theorems
The most useful in our work will be variants of the Gauss and Stokes theorems. The Gauss theorem relates a volume integral of a divergence of a vector field to a surface integral of that vector field. The Stokes theorem relates a surface integral of the curl of a vector field to a line integral of that vector field. Here, they are stated for reference, and we’ll explore their meaning and application in more detail as we use them to derive the fundamental equations for fluid flows.
Gauss theorem
The Gauss theorem states that the volume integral of the divergence of a vector field over a volume is equal to the surface integral of over the surface that encloses :
In other words, the rate of change of the fluid mass within a volume is equal to the flow normal through the surface that encloses that volume. This form of Gauss’s theorem is also known as the divergence theorem. It will come in handy when we derive the conservation of mass (continuity) equation.
Stokes theorem
The Stokes theorem states that the surface integral of the curl of a vector field over a surface is equal to the line integral of over the boundary of :
In other words, the rotation rate of the fluid over a surface area is equal to the flow velocity integrated around the boundary of that surface.
Summary
In this chapter, we reviewed:
-
Scalars, vectors, and tensors;
-
Vector algebra: dot product () and cross product ();
-
Derivatives: total () and partial ();
-
Gradient, divergence (), and curl ();
-
Gauss theorem that relates volume and surface integrals: ;
-
Stokes theorem that relates surface and line integrals: .
These concepts will serve as the basic building blocks for everything that follows in the remainder of this course.
Exercises
-
Pick your favorite programming language (or ask for a recommendation for one). Write a program that defines a scalar, a vector, and a tensor, and assign numerical values to them. Print the values to the screen. Is there a difference in how you define them in your program?
-
What is the dot product of two orthogonal vectors? How about the dot product of a vector with itself? Please write out the solution step by step.
-
Write a program that calculates the cross product of two vectors. Please implement your solution using the basic arithmetic operations such as addition and multiplication. Then, see if your programming language or one of its software libraries provides a function to do this. Can you verify your implementation by comparing its output to that of the library function?
-
How would you calculate a derivative of a quantity (scalar, for example) in a computer program, e.g. ? Consider that you can approximate a derivative as a difference between two values of the quantity at two points in space. In other words, assume , and similar for .
-
Write a computer program that calculates the gradient of a scalar field, and the divergence and curl of a vector field.
-
Draw example vector fields that are: (a) non-divergent and irrotational, (b) divergent and irrotational, (c) non-divergent and rotational, and (d) divergent and rotational.