Skip to content

Commit

Permalink
Move patch for AxisTensor component conversion from ClimaAtmos
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisYatunin committed Sep 26, 2023
1 parent 5215d8d commit fa1306c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Geometry/axistensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ AxisTensor(axes::Tuple{Vararg{AbstractAxis}}, components) =
components::AbstractArray{<:Any, N},
) where {N, A} = AxisTensor(A.instance, components)

# conversion of components
AxisTensor{T, N, A, S}(a::AxisTensor{<:Any, N, A, <:Any}) where {T, N, A, S} =
AxisTensor(axes(a), S(components(a)))
Base.convert(::Type{T}, a::AxisTensor) where {T <: AxisTensor} = T(a)

Base.axes(a::AxisTensor) = getfield(a, :axes)
Base.axes(::Type{AxisTensor{T, N, A, S}}) where {T, N, A, S} = A.instance
Expand Down
4 changes: 4 additions & 0 deletions test/Geometry/axistensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ ClimaCore.Geometry.assert_exact_transform() = true
f(x) = x.u₁ + x.u₂ + x.u₃
@test_opt f(x)

ref = Ref(zero(x))
ref[] = Geometry.Covariant12Vector(1, 2) # Int components instead of Float64
@test ref[] == x

M = Geometry.Axis2Tensor(
(Geometry.Cartesian12Axis(), Geometry.Covariant12Axis()),
[1.0 0.0; 0.5 2.0],
Expand Down

0 comments on commit fa1306c

Please sign in to comment.