curl {oce}R Documentation

Curl of 2D Vector Field

Description

Calculate the z component of the curl of an x-y vector field.

Usage

curl(u, v, x, y, geographical = FALSE, method = 1)

Arguments

u

matrix containing the 'x' component of a vector field

v

matrix containing the 'y' component of a vector field

x

the x values for the matrices, a vector of length equal to the number of rows in u and v.

y

the y values for the matrices, a vector of length equal to the number of cols in u and v.

geographical

logical value indicating whether x and y are longitude and latitude, in which case spherical trigonometry is used.

method

A number indicating the method to be used to calculate the first-difference approximations to the derivatives. See “Details”.

Details

The computed component of the curl is defined by \partial v/\partial x - \partial u/\partial y and the estimate is made using first-difference approximations to the derivatives. Two methods are provided, selected by the value of method.

Value

A list containing vectors x and y, along with matrix curl. See “Details” for the lengths and dimensions, for various values of method.

Development status.

This function is under active development as of December 2014 and is unlikely to be stabilized until February 2015.

Author(s)

Dan Kelley and Chantelle Layton

See Also

Other things relating to vector calculus: grad()

Examples

library(oce)
# 1. Shear flow with uniform curl.
x <- 1:4
y <- 1:10
u <- outer(x, y, function(x, y) y / 2)
v <- outer(x, y, function(x, y) -x / 2)
C <- curl(u, v, x, y, FALSE)

# 2. Rankine vortex: constant curl inside circle, zero outside
rankine <- function(x, y) {
    r <- sqrt(x^2 + y^2)
    theta <- atan2(y, x)
    speed <- ifelse(r < 1, 0.5 * r, 0.5 / r)
    list(u = -speed * sin(theta), v = speed * cos(theta))
}
x <- seq(-2, 2, length.out = 100)
y <- seq(-2, 2, length.out = 50)
u <- outer(x, y, function(x, y) rankine(x, y)$u)
v <- outer(x, y, function(x, y) rankine(x, y)$v)
C <- curl(u, v, x, y, FALSE)
# plot results
par(mfrow = c(2, 2))
imagep(x, y, u, zlab = "u", asp = 1)
imagep(x, y, v, zlab = "v", asp = 1)
imagep(x, y, C$curl, zlab = "curl", asp = 1)
hist(C$curl, breaks = 100)

[Package oce version 1.8-2 Index]