Skip to content

Adding Covariant/Contravariant Vector Documentation and Visualization #2295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,11 @@ @article{Wiin1967
year = {1967},
publisher = {Wiley Online Library}
}

@article{Yatunin2025,
title = {The Climate Modeling Alliance Atmosphere Dynamical Core: Concepts, Numerics, and Scaling},
author = {Dennis Yatunin, Simon Byrne, Charles Kawczynski, Sriharsha Kandala, Gabriele Bozzola, Akshay Sridhar, Zhaoyi Shen, Anna Jaruga, Julia Sloan, Jia He, Daniel Zhengyu Huang, Valeria Barra, Oswald Knoth, Paul Ullrich, Tapio Schneider},
doi = {10.22541/essoar.173940262.23304403/v1},
year = {2025},
publisher = {ESS Open Archive}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to also add a journal entry, otherwise when building the docs, we get the following error:

┌ Error: Entry Yatunin2025 is missing the journal field(s).
└ @ BibInternal ~/.julia/packages/BibInternal/2EG8G/src/bibtex.jl:89

Add:

Suggested change
publisher = {ESS Open Archive}
publisher = {ESS Open Archive},
journal = {Journal of Advances in Modeling Earth Systems}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

}
Binary file added docs/src/contrava_cova.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions docs/src/math_framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ then may want to consider different bases, as not all operators accept all bases
_Covariance_ and _contravariance_ describe how the quantitative description of
certain geometric or physical entities changes with a change of basis.

More specifically,

__Covariant objects__ —whether you mean covariant components (the coefficients that sit in front of the basis)
or the covariant basis vectors themselves—co-vary with the coordinate grid. In other words, when you change coordinates,
these quantities transform in the same way as the coordinate differentials. By convention they carry lower indices (subscripts).

__Contravariant objects__—whether you mean contravariant components or the contravariant basis vectors—vary contra
to the coordinate grid. That is, they transform in the opposite way to the coordinate differentials so as to keep
tensorial expressions invariant. By convention they carry upper indices (superscripts).

In ClimaCore.jl, `CovariantVector`s are aligned with the _contravariant basis vectors_, but have _covariant components_.
Conversely, `ContravariantVector`s are aligned with the _covariant basis vectors_, but have _contravariant components_.

In ClimaCore.jl, the _covariant basis_ is specified by the partial derivative
of the transformation from the reference element ``\xi \in [-1,1]^d`` (where ``d``
is the dimensionality of the domain ``\Omega``) to ``x`` in the physical space:
Expand All @@ -74,6 +87,48 @@ while the _contravariant basis_ is the opposite: gradient in ``x`` of the coordi
\mathbf{e}^i = \nabla_x \xi^i
```

If we plot these bases in a curvilinear space, _covariant basis_ vectors “ride along” the coordinate surface liness (parallel), while _contravariant basis_ vectors “stick out” of those surface lines (perpendicular). See the plot from [Yatunin2025](@cite) below:

![normal and tangent](normal_tangent.png)

Here is a visual representation of how vectors can be represented in _contravariant_ and _covariant_ components.

![Different bases](contrava_cova.png)

From the above two figures, we can see that parallel projections would lead to contravariant components $a^{1}$ and $a^{2}$,
while perpendicular projections would lead to covariant components $b_{1} = \vec{b}\cdot \vec{e_{1}}$ and $b_{2} = \vec{b}\cdot \vec{e_{2}}$.

As to better connect the original idea of _covariant components_ / _contravariant components_ with the real application in ClimaCore.jl,
we bring the case of __polar coordinates__ -- a classic example of a __curvilinear coordinate system__.

First of all, we have the Polar‐to‐Cartesian mapping as following:
```math
\vec{r} (r,\theta ) = (r \cos \theta, r \sin \theta)
```

Then we have the _covariant basis_:
```math
\vec{e_{r} } = \frac{\partial \vec{r} }{\partial r} = \frac{\partial (r \cos \theta, r \sin \theta) }{\partial r} = (\cos \theta, \sin \theta)
```
```math
\vec{e_{\theta} } = \frac{\partial \vec{r} }{\partial \theta } = \frac{\partial (r \cos \theta, r \sin \theta) }{\partial \theta } = (-r\sin \theta,r \cos \theta)
```

$\vec{e_{r} }$ represents the direction that is tangent to the "radius direction", and $\vec{e_{\theta} }$ is tangent to the circle curve itself.

And the _contravariant basis_:

since we have $r(x,y) = \sqrt{x^{2} +y^{2} }$ and $\theta (x,y) = \arctan (\frac{y}{x} )$. Thus,

```math
\vec{e^{r} } = \nabla r(x,y) = (\frac{x}{\sqrt{x^{2} +y^{2} }}, \frac{y}{\sqrt{x^{2} +y^{2} }}) = (\frac{x}{r},\frac{y}{r} ) = (\cos \theta, \sin \theta)
```
```math
\vec{e^{\theta } } = \nabla \theta(x,y) = (\frac{-y}{x^{2} +y^{2}}, \frac{x}{x^{2} +y^{2}}) = (\frac{-\sin \theta}{r} , \frac{\cos \theta}{r})
```

$\vec{e^{r} }$ represents the direction that is perpendicular to the circle curve, and $\vec{e^{\theta} }$ is perpendicular to the "radius direction".


**Note**:

Expand All @@ -85,6 +140,9 @@ while the _contravariant basis_ is the opposite: gradient in ``x`` of the coordi

* things get a little more complicated in the presence of terrain, but ``\xi^3`` is radially aligned
- the 3rd covariant component is aligned with W, but the 3rd contravariant component may not be (e.g. at the surface it is normal to the boundary).




### Cartesian bases
Analogously to `CartesianPoint`s, in ClimaCore, there are also `CartesianVector`s:
Expand Down
Binary file added docs/src/normal_tangent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.