Skip to content

Commit

Permalink
Merge #853 #909 #910
Browse files Browse the repository at this point in the history
853: add special cases for projection from Covariant => Contravariant r=charleskawczynski a=simonbyrne



909: Fix differentiability of local element map r=simonbyrne a=simonbyrne

I was experimenting with `IntrinsicMap` and noticed some sign errors in the metric terms due to the non-differentiable extra branches for handling of signed zeros. This is a simpler and better approach.

- [X] Code follows the [style guidelines](https://clima.github.io/ClimateMachine.jl/latest/DevDocs/CodeStyle/) OR N/A.
- [X] Unit tests are included OR N/A.
- [X] Code is exercised in an integration test OR N/A.
- [X] Documentation has been added/updated OR N/A.


910: Fix Zalesak FCT docstring and add it to the Docs r=simonbyrne a=valeriabarra

This PR adds the Zalesak FCT operator to the docs since #887  did not include it. Plus some additional doc fixes and improvements.

- [x] Code follows the [style guidelines](https://clima.github.io/ClimateMachine.jl/latest/DevDocs/CodeStyle/) OR N/A.
- [x] Unit tests are included OR N/A.
- [x] Code is exercised in an integration test OR N/A.
- [x] Documentation has been added/updated OR N/A.


Co-authored-by: Simon Byrne <[email protected]>
Co-authored-by: Charles Kawczynski <[email protected]>
Co-authored-by: Valeria Barra <[email protected]>
  • Loading branch information
4 people authored Aug 24, 2022
4 parents b44786c + dc53a36 + 39ffc0d + 174d109 commit 8de4b69
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 173 deletions.
7 changes: 7 additions & 0 deletions docs/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ @article{BorisBook1973
author = {Jay P Boris and David L Book}
}

@book{durran2010,
title={Numerical Methods for Fluid Dynamics},
author={Durran, Dale R},
year={2010},
publisher={Springer New York, NY}
}

@book{durran2013numerical,
title={Numerical methods for wave equations in geophysical fluid dynamics},
author={Durran, Dale R},
Expand Down
1 change: 1 addition & 0 deletions docs/src/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ WeightedInterpolateF2C
UpwindBiasedProductC2F
Upwind3rdOrderBiasedProductC2F
FCTBorisBook
FCTZalesak
LeftBiasedC2F
RightBiasedC2F
LeftBiasedF2C
Expand Down
44 changes: 27 additions & 17 deletions src/Geometry/axistensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,16 @@ const Axis2TensorOrAdj{T, A, S} =

# based on 1st dimension
const Covariant2Tensor{T, A, S} =
Axis2Tensor{T, A, S} where {A <: Tuple{CovariantAxis, AbstractAxis}}
const Contravariant2Tensor{T, A, S} =
Axis2Tensor{T, A, S} where {A <: Tuple{ContravariantAxis, AbstractAxis}}
Axis2Tensor{T, A, S} where {T, A <: Tuple{CovariantAxis, AbstractAxis}, S}
const Contravariant2Tensor{T, A, S} = Axis2Tensor{
T,
A,
S,
} where {T, A <: Tuple{ContravariantAxis, AbstractAxis}, S}
const Cartesian2Tensor{T, A, S} =
Axis2Tensor{T, A, S} where {A <: Tuple{CartesianAxis, AbstractAxis}}
Axis2Tensor{T, A, S} where {T, A <: Tuple{CartesianAxis, AbstractAxis}, S}
const Local2Tensor{T, A, S} =
Axis2Tensor{T, A, S} where {A <: Tuple{LocalAxis, AbstractAxis}}
Axis2Tensor{T, A, S} where {T, A <: Tuple{LocalAxis, AbstractAxis}, S}

const CovariantTensor = Union{CovariantVector, Covariant2Tensor}
const ContravariantTensor = Union{ContravariantVector, Contravariant2Tensor}
Expand Down Expand Up @@ -521,6 +524,9 @@ end
x
end

#= Set `assert_exact_transform() = true` for debugging=#
assert_exact_transform() = false

@generated function _transform(
ato::Ato,
x::Axis2Tensor{T, Tuple{Afrom, A2}},
Expand All @@ -531,12 +537,14 @@ end
} where {Ito, Ifrom, J, T}
N = length(Ifrom)
M = length(J)
errcond = false
for n in 1:N
i = Ifrom[n]
if i Ito
for m in 1:M
errcond = :($errcond || x[$n, $m] != zero(T))
if assert_exact_transform()
errcond = false
for n in 1:N
i = Ifrom[n]
if i Ito
for m in 1:M
errcond = :($errcond || x[$n, $m] != zero(T))
end
end
end
end
Expand All @@ -555,8 +563,10 @@ end
end
quote
Base.@_propagate_inbounds_meta
if $errcond
throw(InexactError(:transform, Ato, x))
if assert_exact_transform()
if $errcond
throw(InexactError(:transform, Ato, x))
end
end
@inbounds Axis2Tensor(
(ato, axes(x, 2)),
Expand Down Expand Up @@ -594,11 +604,11 @@ end
))
end

@inline transform(ato::CovariantAxis, v::CovariantTensor) = _transform(ato, v)
@inline transform(ato::CovariantAxis, v::CovariantTensor) = _project(ato, v)
@inline transform(ato::ContravariantAxis, v::ContravariantTensor) =
_transform(ato, v)
@inline transform(ato::CartesianAxis, v::CartesianTensor) = _transform(ato, v)
@inline transform(ato::LocalAxis, v::LocalTensor) = _transform(ato, v)
_project(ato, v)
@inline transform(ato::CartesianAxis, v::CartesianTensor) = _project(ato, v)
@inline transform(ato::LocalAxis, v::LocalTensor) = _project(ato, v)

@inline project(ato::CovariantAxis, v::CovariantTensor) = _project(ato, v)
@inline project(ato::ContravariantAxis, v::ContravariantTensor) =
Expand Down
Loading

0 comments on commit 8de4b69

Please sign in to comment.