Skip to content
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

bug in divergence_result_type #2208

Closed
szy21 opened this issue Mar 5, 2025 · 5 comments · Fixed by #2210
Closed

bug in divergence_result_type #2208

szy21 opened this issue Mar 5, 2025 · 5 comments · Fixed by #2210
Labels
bug Something isn't working

Comments

@szy21
Copy link
Member

szy21 commented Mar 5, 2025

Describe the bug

When calling the following function

function boundary_tendency_momentum(ᶜρ, ᶜuₕ, ρ_flux_uₕ)
    FT = eltype(ᶜρ)
    ᶠgradᵥ = Operators.GradientC2F()
    ᶜdivᵥ_uₕ = Operators.DivergenceF2C(
        top = Operators.SetValue(C3(FT(0)) ⊗ C12(FT(0), FT(0))),
        bottom = Operators.SetValue(ρ_flux_uₕ),
    )
    return @.  ᶜdivᵥ_uₕ((0 * ᶠgradᵥ(ᶜuₕ))) / ᶜρ
end

it results in an error

ERROR: LoadError: MethodError: no method matching divergence_result_type(::Type{ClimaCore.Geometry.AxisTensor{Float32, 2, Tuple{…}, StaticArraysCore.SMatrix{…}}})
The function `divergence_result_type` exists, but no method is defined for this combination of argument types.

Changing @. ᶜdivᵥ_uₕ((0 * ᶠgradᵥ(ᶜuₕ))) / ᶜρ to @. lazy(ᶜdivᵥ_uₕ((0 * ᶠgradᵥ(ᶜuₕ))) / ᶜρ) fixes the issue.

To Reproduce

I'll try to make a minimal working example later.

@szy21 szy21 added the bug Something isn't working label Mar 5, 2025
@charleskawczynski
Copy link
Member

I think I ran into this in #2184, and fixed it by defining

@inline divergence_result_type(
    ::Type{AxisTensor{FT, 2, Tuple{A1, A2}, S}},
) where {
    FT,
    A1 <: CovariantAxis{(3,)},
    A2 <: CovariantAxis{(1, 2)},
    S <: SMatrix{1, 2, FT, 2},
} = Covariant12Vector{FT}

(xref).

@szy21
Copy link
Member Author

szy21 commented Mar 5, 2025

Oh, thank you!

@charleskawczynski
Copy link
Member

Actually, I'm a bit confused how I even found this issue, now that I think about it-- I think I grabbed the example from our test suite. Maybe it was a matter of combining operations? Thoughts, @dennisYatunin?

@dennisYatunin
Copy link
Member

You might have tried calling an @. expression without its left-hand side, resulting in an invalid call to divergence_result_type for Axis2Tensors. That's how we found it.

@charleskawczynski
Copy link
Member

That would make sense. Could you review #2210?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants