Skip to content

Commit 9b439ed

Browse files
update exports and docs
1 parent 8b085fb commit 9b439ed

17 files changed

Lines changed: 299 additions & 19 deletions

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export("%_%")
1616
export(.)
1717
export(as_a)
1818
export(asym)
19+
export(christoffel)
1920
export(d)
2021
export(e)
2122
export(expect_tensor_equal)
@@ -24,7 +25,11 @@ export(g_eucl_sph)
2425
export(g_mink)
2526
export(kron)
2627
export(l)
28+
export(metric_field)
2729
export(r)
30+
export(ricci)
31+
export(ricci_sc)
32+
export(riemann)
2833
export(subst)
2934
export(sym)
3035
export(tensor)

R/covd.R

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
# used indices
22
globalVariables(c("i", "j", "k", "l", "i2"))
33

4-
4+
#' Christoffel symbols
5+
#'
6+
#' Provides the Christoffel symbols of the first kind \eqn{Gamma_{ijk}} with
7+
#' respect to the Levi Civita connection for a given metric tensor.
8+
#'
9+
#' The Christoffel symbols are a rank 3 array of numbers.
10+
#'
11+
#' @param g
12+
#' A covariant metric tensor, a "metric_field" object. See [metric_field()]
13+
#' to create a new metric tensor, or use predefined metrics,
14+
#' e.g. [g_eucl_cart()].
15+
#' @return
16+
#' Returns the Christoffel symbols of the first kind \eqn{Gamma_{ijk}}
17+
#' as rank 3 [array()].
18+
#'
19+
#' @examples
20+
#' christoffel(g_eucl_sph(3))
21+
#' @seealso Wikipedia: [Christoffel symbols](https://en.wikipedia.org/wiki/Christoffel_symbols])
22+
#' @export
23+
#' @concept geom_tensors
24+
#' @family geometric tensors
525
christoffel <- function(g) {
626
stopifnot(inherits(g, "metric_field"))
727

@@ -12,6 +32,21 @@ christoffel <- function(g) {
1232
as_a(i, k, l)
1333
}
1434

35+
#' Riemann curvature tensor
36+
#'
37+
#' Provides the covariant Riemann curvature tensor \eqn{R_{ijkl}}.
38+
#'
39+
#' @inheritParams christoffel
40+
#' @return
41+
#' Returns the covariant Riemann curvature tensor \eqn{R_{ijkl}}
42+
#' as rank 4 [array()].
43+
#'
44+
#' @examples
45+
#' riemann(g_eucl_sph(3))
46+
#' @seealso Wikipedia: [Riemann curvature tensor](https://en.wikipedia.org/wiki/Riemann_curvature_tensor)
47+
#' @export
48+
#' @concept geom_tensors
49+
#' @family geometric tensors
1550
riemann <- function(g) {
1651
stopifnot(inherits(g, "metric_field"))
1752

@@ -24,11 +59,40 @@ riemann <- function(g) {
2459
as_a(i2, k, j, l)
2560
}
2661

62+
#' Ricci curvature tensor
63+
#'
64+
#' Provides the covariant Ricci curvature tensor \eqn{R_{ij}=R^{s}_{i s j}}.
65+
#'
66+
#' @inheritParams christoffel
67+
#' @return
68+
#' Returns the covariant Ricci curvature tensor \eqn{R_{ij}}
69+
#' as rank 2 [array()].
70+
#'
71+
#' @examples
72+
#' ricci(g_eucl_sph(3))
73+
#' @seealso Wikipedia: [Ricci curvature tensor](https://en.wikipedia.org/wiki/Riemann_curvature_tensor#Ricci_curvature)
74+
#' @export
75+
#' @concept geom_tensors
76+
#' @family geometric tensors
2777
ricci <- function(g) {
2878
(riemann(g) %_% .(i, j, k, l) * g %_% .(+i, +k)) |>
2979
as_a(j, l)
3080
}
3181

82+
#' Ricci scalar
83+
#'
84+
#' Provides the Ricci scalar \eqn{R}.
85+
#'
86+
#' @inheritParams christoffel
87+
#' @return
88+
#' Returns the Ricci scalar \eqn{R} as single number/expression.
89+
#'
90+
#' @examples
91+
#' ricci_sc(g_eucl_sph(3))
92+
#' @seealso Wikipedia: [Ricci scalar](https://en.wikipedia.org/wiki/Scalar_curvature)
93+
#' @export
94+
#' @concept geom_tensors
95+
#' @family geometric tensors
3296
ricci_sc <- function(g) {
3397
(ricci(g) %_% .(i, j) * g %_% .(+i, +j)) |> as_a()
3498
}

R/metric_field.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ new_metric_field <- function(metric, coords, metric_inv) {
99
)
1010
}
1111

12+
#' Create a metric tensor field
13+
#'
14+
#' Metric tensors are an essential ingredient of (Pseudo-) Riemannian
15+
#' manifolds and define distance relations between points.
16+
#' They are used to define geometric tensors such as e.g. the Ricci curvature
17+
#' [ricci()], and a metric connection, i.e. a covariant derivative.
18+
#' They are also essential for raising and lowering indices of tensor fields
19+
#' correctly when using non-flat coordinates.
20+
#'
21+
#' @param metric
22+
#' A `nxn` matrix / array representing the covariant metric tensor components.
23+
#' The components are usually expressions as character strings formed from
24+
#' coordinates, since numeric values can only represent constant tensor fields.
25+
#'
26+
#' @param metric_inv
27+
#' A `nxn` matrix / array representing the contraviant metric tensor components,
28+
#' i.e. the inverse matrix of the covariant metric tensor component matrix.
29+
#'
30+
#' @param coords
31+
#' A character vector of `n` coordinate names that are used in the component
32+
#' expressions. This information is essential
33+
#' for forming symbolic derivatives.
34+
#'
35+
#' @seealso Wikipedia: [Metric tensor](https://en.wikipedia.org/wiki/Metric_tensor)
36+
#' @concept metric_tensors
37+
#' @family metric tensors
38+
#'
39+
#' @export
1240
metric_field <- function(metric, metric_inv, coords) {
1341
stopifnot(is.array(metric))
1442
stopifnot(is.character(coords))

R/tensor_instances.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#'
1919
#' d(3)(i, j, +k, +l)
2020
#' @export
21-
#' @concept tensor_instance
21+
#' @concept tensor_symbols
2222
#' @family tensor symbols
2323
d <- function(n) {
2424
function(...) {
@@ -59,7 +59,7 @@ d <- function(n) {
5959
#' e(i, j, k)
6060
#' @seealso Wikipedia: [Levi-Civita symbol](https://en.wikipedia.org/wiki/Levi-Civita_symbol)
6161
#' @export
62-
#' @concept tensor_instance
62+
#' @concept tensor_symbols
6363
#' @family tensor symbols
6464
e <- function(...) {
6565
i <- .(...)
@@ -90,7 +90,7 @@ e <- function(...) {
9090
#' g_mink(4)
9191
#' g_mink(4) %_% .(+i, +j)
9292
#' @export
93-
#' @concept tensor_instance
93+
#' @concept metric_tensors
9494
#' @family metric tensors
9595
g_mink <- function(n, coords = paste0("x", 1:n - 1)) {
9696
metric_field(
@@ -124,7 +124,7 @@ g_mink <- function(n, coords = paste0("x", 1:n - 1)) {
124124
#' g_eucl_cart(3)
125125
#' g_eucl_cart(3) %_% .(+i, +j)
126126
#' @export
127-
#' @concept tensor_instance
127+
#' @concept metric_tensors
128128
#' @family metric tensors
129129
#' @rdname g_eucl
130130
g_eucl_cart <- function(n, coords = paste0("x", 1:n)) {

R/tensor_ops.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#'
99
#' @param x A labeled tensor object, created by [`%_%`] or [tensor()].
1010
#' @param g
11-
#' An (unlabeled) covariant metric tensor as array used for raising and
12-
#' lowering indices.
11+
#' A covariant metric tensor, a "metric_field" object. See [metric_field()]
12+
#' to create a new metric tensor, or use predefined metrics,
13+
#' e.g. [g_eucl_cart()].
1314
#' If no metric tensor is provided, indices are raised/lowered with
1415
#' the identity matrix.
1516
#' @param ... Any number of index expressions. The indices need to occur

_pkgdown.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ reference:
1010
- title: "Tensor operations"
1111
contents:
1212
- has_concept("tensor_ops")
13-
- title: "Predefined tensors"
13+
- title: "Tensor symbols"
1414
contents:
15-
- has_concept("tensor_instance")
15+
- has_concept("tensor_symbols")
16+
- title: "Metrics tensor fields"
17+
contents:
18+
- has_concept("metric_tensors")
19+
- title: "Geometric tensor fields"
20+
contents:
21+
- has_concept("geom_tensors")
1622
- title: "Testthat expectation"
1723
contents:
1824
- expect_tensor_equal

man/christoffel.Rd

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/d.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/e.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/g_eucl.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)