Skip to content

Commit 31f6436

Browse files
authored
NamedCoordinate -> NamedDiscretization (#4672)
* NamedCoordinate -> NamedDiscretization * NamedCoordinate -> NamedDiscretization * no mutable kwarg yet * fix bug * give some space * rename ConstantToStretched to ReferenceToStretched * alignment * bump minor release * add mutable kwarg + tests
1 parent bed34ae commit 31f6436

File tree

10 files changed

+219
-168
lines changed

10 files changed

+219
-168
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Oceananigans"
22
uuid = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
33
authors = ["Climate Modeling Alliance and contributors"]
4-
version = "0.99.2"
4+
version = "0.100.0"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

docs/src/grids.md

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,14 @@ fig
551551
As described above, to construct grids with stretched coordinates we need to provide as input
552552
either a function the returns the coordinate's interfaces or an array with the interfaces.
553553

554-
Here we further showcase some helper utilities that can be used to define few special types of
555-
coordinates with variable spacings.
554+
Here we showcase some helper utilities that can be used to define few special types of
555+
discretizations with variable spacings.
556556

557-
### Exponential coordinate
557+
### Exponential discretization
558558

559-
[`ExponentialCoordinate`](@ref) returns a coordinate with interfaces that lie on an exponential profile.
560-
By that, we mean that a uniformly discretized domain in the range ``[l, r]`` is mapped back onto itself via either
559+
[`ExponentialDiscretization`](@ref) returns a discretization with interfaces that lie on an
560+
exponential profile. By that, we mean that a uniformly discretized domain in the range ``[l, r]``
561+
is mapped back onto itself via either
561562

562563
```math
563564
ξ \mapsto w(ξ) = r - (r - l) \frac{\exp{[(r - ξ) / h]} - 1}{\exp{[(r - l) / h]} - 1} \quad \text{(right biased)}
@@ -570,16 +571,20 @@ or
570571
```
571572

572573
The exponential mappings above have an e-folding controlled by scale ``h``.
573-
It's worth noting that the exponential maps imply that the cell widths (distances between interfaces) grow linearly at a rate inversely proportional to ``h / (r - l)``.
574+
It's worth noting that the exponential maps imply that the cell widths (distances between interfaces)
575+
grow linearly at a rate inversely proportional to ``h / (r - l)``.
574576

575-
The right-biased map biases the interfaces being closer towards ``r``; the left-biased map biases the interfaces towards ``l``.
577+
The right-biased map biases the interfaces being closer towards ``r``; the left-biased map biases
578+
the interfaces towards ``l``.
576579

577-
At the limit ``h / (r - l) \to \infty`` both mappings reduce to identity (``w \to ξ``) and thus the grid becomes uniformly spaced.
580+
At the limit ``h / (r - l) \to \infty`` both mappings reduce to identity (``w \to ξ``) and thus the
581+
discretization becomes uniformly spaced.
578582

579583
!!! note "Oceanography-related bias"
580-
For vertical coordinates fit for oceanographic purposes, the right-biased mapping is usually more relevant as it implies finer vertical resolution closer to the ocean's surface.
584+
For vertical coordinates fit for oceanographic purposes, the right-biased mapping is usually more
585+
relevant as it implies finer vertical resolution near the ocean's surface.
581586

582-
```@example exponentialcoord
587+
```@example exponentialdiscretization
583588
using Oceananigans.Grids: rightbiased_exponential_mapping, leftbiased_exponential_mapping
584589
585590
using CairoMakie
@@ -591,8 +596,8 @@ l, r = 0, 1
591596
592597
fig = Figure(size=(1200, 550))
593598
594-
axis_labels = (xlabel="uniform coordinate ξ / (r-l)",
595-
ylabel="mapped coordinate w / (r-l)")
599+
axis_labels = (xlabel="uniform ξ / (r - l)",
600+
ylabel="mapped w / (r - l)")
596601
597602
axl = Axis(fig[1, 1]; title="left-biased map", axis_labels...)
598603
axr = Axis(fig[1, 2]; title="right-biased map", axis_labels...)
@@ -612,34 +617,36 @@ Legend(fig[2, :], axl, orientation = :horizontal)
612617
fig
613618
```
614619

615-
Note that the smallest the ratio ``h / (r - l)`` is, the more finely-packed are the mapped points towards the left or right side of the domain.
620+
Note that the smallest the ratio ``h / (r - l)`` is, the more finely-packed are the mapped points
621+
towards the left or right side of the domain.
616622

617-
Let's see how we use [`ExponentialCoordinate`](@ref). Below we construct a coordinate with 10 cells that spans the range ``[-700, 300]``. By default, the `ExponentialCoordinate` is right-biased.
623+
Let's see how we use [`ExponentialDiscretization`](@ref). Below we construct a coordinate with 10 cells
624+
that spans the range ``[-700, 300]``. By default, the `ExponentialDiscretization` is right-biased.
618625

619-
```@example exponentialcoord
626+
```@example exponentialdiscretization
620627
using Oceananigans
621628
622629
N = 10
623630
l = -700
624631
r = 300
625632
626-
x = ExponentialCoordinate(N, l, r)
633+
x = ExponentialDiscretization(N, l, r)
627634
```
628635

629636
Note that above, the default e-folding scale (`scale = (r - l) / 5`) was used.
630637

631638
We can inspect the interfaces of the coordinate via
632639

633-
```@example exponentialcoord
640+
```@example exponentialdiscretization
634641
[x(i) for i in 1:N+1]
635642
```
636643

637644
Being right-biased, note above how the interfaces are closer together near ``r``.
638645

639-
To demonstrate how the scale ``h`` affects the coordinate, we construct below two such exponential
640-
coordinates: the first with ``h / (r - l) = 1/5`` and the second with ``h / (r - l) = 1/2``.
646+
To demonstrate how the scale ``h`` affects the discretization, we construct below two such exponential
647+
discretizations: the first with ``h / (r - l) = 1/5`` and the second with ``h / (r - l) = 1/2``.
641648

642-
```@example exponentialcoord
649+
```@example exponentialdiscretization
643650
using Oceananigans
644651
645652
N = 10
@@ -652,7 +659,7 @@ using CairoMakie
652659
fig = Figure(size=(1000, 1000))
653660
654661
scale = extent / 5
655-
x = ExponentialCoordinate(N, l, r; scale)
662+
x = ExponentialDiscretization(N, l, r; scale)
656663
grid = RectilinearGrid(; size=N, x, topology=(Bounded, Flat, Flat))
657664
xc = xnodes(grid, Center())
658665
xf = xnodes(grid, Face())
@@ -668,7 +675,7 @@ scatter!(axΔx1, xc, Δx)
668675
669676
670677
scale = extent / 2
671-
x = ExponentialCoordinate(N, l, r; scale)
678+
x = ExponentialDiscretization(N, l, r; scale)
672679
grid = RectilinearGrid(; size=N, x, topology=(Bounded, Flat, Flat))
673680
xc = xnodes(grid, Center())
674681
xf = xnodes(grid, Face())
@@ -700,42 +707,46 @@ rowsize!(fig.layout, 3, Relative(0.1))
700707
fig
701708
```
702709

703-
A downside of [`ExponentialCoordinate`](@ref) coordinate is that we don't have tight control on the minimum spacing at the biased edge.
704-
To obtain a coordinate with a certain minimum spacing we need to play around with the scale ``h`` and the number of cells.
710+
A downside of [`ExponentialDiscretization`](@ref) discretization is that we don't have tight control
711+
on the minimum spacing at the biased edge.
712+
To obtain a discretization with a certain minimum spacing we need to play around with the scale ``h``
713+
and the number of cells.
705714

706715

707-
### Constant-to-stretched-spacing coordinate
716+
### Constant-to-stretched-spacing discretization
708717

709-
[`ConstantToStretchedCoordinate`](@ref) returns a coordinate with constant spacing over some extent and beyond
710-
which the spacing increases with a prescribed stretching law; this allows a tighter control on the spacing at the biased edge.
718+
[`ReferenceToStretchedDiscretization`](@ref) returns a discretization with a constant reference spacing over
719+
some extent and beyond which the spacing increases with a prescribed stretching law; this allows a tighter
720+
control on the spacing at the biased edge.
711721
That is, we can prescribe a constant spacing over the top `surface_layer_height` below which the grid spacing
712722
increases following a prescribed stretching law.
713-
The downside here is that neither the final coordinate extent nor the total number of cells can be prescribed.
714-
The coordinate's extent is greater or equal from what we prescribe via the keyword argument `extent`.
723+
The downside here is that neither the final discretization extent nor the total number of cells can be prescribed.
724+
The discretization's extent is greater or equal from what we prescribe via the keyword argument `extent`.
715725
Also, the total number of cells we end up with depends on the stretching law.
716726

717727
As an example, we build three single-column vertical grids.
718-
We use right-biased coordinate (i.e., `bias = :right`) since this way we can have tight control of the spacing at the ocean's surface (`bias_edge = 0`).
728+
We use right-biased discretization (i.e., `bias = :right`) since this way we can have tight control of the spacing
729+
at the ocean's surface (`bias_edge = 0`).
719730
The three grids below have constant 30-meter spacing for the top 180 meters.
720731
We prescribe to all three a `extent = 800` meters and we apply power-law stretching for depths below 120 meters.
721732
The bigger the power-law stretching factor is, the further the last interface goes beyond the prescribed depth and/or with less total number of cells.
722733

723-
```@setup ConstantToStretchedCoordinate
734+
```@setup ReferenceToStretchedDiscretization
724735
using Oceananigans
725736
using CairoMakie
726737
set_theme!(Theme(fontsize=16))
727738
```
728739

729-
```@example ConstantToStretchedCoordinate
740+
```@example ReferenceToStretchedDiscretization
730741
bias = :right
731742
bias_edge = 0
732743
extent = 800
733744
constant_spacing = 25
734745
constant_spacing_extent = 160
735746
736-
z = ConstantToStretchedCoordinate(; extent, bias, bias_edge,
737-
constant_spacing, constant_spacing_extent,
738-
stretching = PowerLawStretching(1.06))
747+
z = ReferenceToStretchedDiscretization(; extent, bias, bias_edge,
748+
constant_spacing, constant_spacing_extent,
749+
stretching = PowerLawStretching(1.06))
739750
grid = RectilinearGrid(; size=length(z), z, topology=(Flat, Flat, Bounded))
740751
zf = znodes(grid, Face())
741752
zc = znodes(grid, Center())
@@ -763,9 +774,9 @@ hidedecorations!(axz1)
763774
hidespines!(axz1)
764775
765776
766-
z = ConstantToStretchedCoordinate(; extent, bias, bias_edge,
767-
constant_spacing, constant_spacing_extent,
768-
stretching = PowerLawStretching(1.03))
777+
z = ReferenceToStretchedDiscretization(; extent, bias, bias_edge,
778+
constant_spacing, constant_spacing_extent,
779+
stretching = PowerLawStretching(1.03))
769780
grid = RectilinearGrid(; size=length(z), z, topology=(Flat, Flat, Bounded))
770781
zf = znodes(grid, Face())
771782
zc = znodes(grid, Center())
@@ -789,10 +800,10 @@ scatter!(axz2, 0 * zc, zc)
789800
hidedecorations!(axz2)
790801
hidespines!(axz2)
791802
792-
z = ConstantToStretchedCoordinate(; extent, bias, bias_edge,
793-
constant_spacing, constant_spacing_extent,
794-
stretching = PowerLawStretching(1.03),
795-
maximum_stretching_extent = 500)
803+
z = ReferenceToStretchedDiscretization(; extent, bias, bias_edge,
804+
constant_spacing, constant_spacing_extent,
805+
stretching = PowerLawStretching(1.03),
806+
maximum_stretching_extent = 500)
796807
797808
grid = RectilinearGrid(; size=length(z), z, topology=(Flat, Flat, Bounded))
798809
zf = znodes(grid, Face())

src/Grids/Grids.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export XRegularRG, YRegularRG, ZRegularRG, XYRegularRG, XYZRegularRG
1111
export LatitudeLongitudeGrid, XRegularLLG, YRegularLLG, ZRegularLLG
1212
export OrthogonalSphericalShellGrid, ZRegOrthogonalSphericalShellGrid
1313
export MutableVerticalDiscretization
14-
export ExponentialCoordinate, ConstantToStretchedCoordinate, PowerLawStretching, LinearStretching
14+
export ExponentialDiscretization, ReferenceToStretchedDiscretization, PowerLawStretching, LinearStretching
1515
export node, nodes
1616
export ξnode, ηnode, rnode
1717
export xnode, ynode, znode, λnode, φnode

0 commit comments

Comments
 (0)