trixi-framework / trixi-framework/Trixi.jl
Allow different numbers of variables in `PlotData2D`
- Dominant language
- Julia
- Stars
- 731
- Forks
- 167
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 25
Description
With StructArrays.jl v0.6.8:
```julia
julia> using Trixi, OrdinaryDiffEq, Plots
julia> trixi_include("examples/structured_2d_dgsem/elixir_advection_extended.jl")
julia> PlotData2D(sol) # fine
PlotData2DTriangulated{Matrix{Float64}, StructArray{SVector{1, Float64}, 2, Tuple{Matrix{Float64}}, Int64}, Matrix{Float64}, StructArray{SVector{1, Float64}, 2, Tuple{Matrix{Float64}}, Int64}, SVector{1, String}}(, , , , , , , )
julia> cons2strange(u, ::LinearScalarAdvectionEquation2D) = SVector(u[1], u[1])
cons2strange (generic function with 1 method)
julia> Trixi.varnames(::typeof(cons2strange), ::LinearScalarAdvectionEquation2D) = ("a", "b")
julia> PlotData2D(sol; solution_variables=cons2strange) # fails
ERROR: MethodError: Cannot `convert` an object of type Tuple{Float64, Float64} to an object of type Float64
Closest candidates are:
convert(::Type{T}, ::Static.StaticFloat64) where T<:AbstractFloat at ~/.julia/packages/Static/NDBmr/src/float.jl:22
convert(::Type{T}, ::LLVM.GenericValue, ::LLVM.LLVMType) where T<:AbstractFloat at ~/.julia/packages/LLVM/szqwr/src/execution.jl:39
convert(::Type{T}, ::LLVM.ConstantFP) where T<:AbstractFloat at ~/.julia/packages/LLVM/szqwr/src/core/value/constant.jl:111
...
Stacktrace:
[1] macro expansion
@ ~/.julia/packages/StaticArrays/58yy1/src/util.jl:17 [inlined]
[2] convert_ntuple
@ ~/.julia/packages/StaticArrays/58yy1/src/util.jl:13 [inlined]
[3] SVector{1, Float64}(x::Tuple{Tuple{Float64, Float64}})
@ StaticArrays ~/.julia/packages/StaticArrays/58yy1/src/SArray.jl:28
[4] StaticArray
@ ~/.julia/packages/StaticArrays/58yy1/src/convert.jl:4 [inlined]
[5] convert
@ ~/.julia/packages/StaticArrays/58yy1/src/convert.jl:10 [inlined]
[6] maybe_convert_elt(#unused#::Type{SVector{1, Float64}}, vals::SVector{2, Float64})
@ StructArrays ~/.julia/packages/StructArrays/rICDm/src/utils.jl:197
[7] setindex!
@ ~/.julia/packages/StructArrays/rICDm/src/structarray.jl:363 [inlined]
[8] transform_to_solution_variables!(u::StructArray{SVector{1, Float64}, 2, Tuple{Matrix{Float64}}, Int64}, solution_variables::typeof(cons2strange), equations::LinearScalarAdvectionEquation2D{Float64})
@ Trixi ~/.julia/dev/Trixi/src/visualization/utilities.jl:53
[9] Trixi.PlotData2DTriangulated(u::Array{Float64, 4}, mesh::StructuredMesh{2, Float64}, equations::LinearScalarAdvectionEquation2D{Float64}, dg::DGSEM{LobattoLegendreBasis{Float64, 4, SVector{4, Float64}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}, Trixi.LobattoLegendreMortarL2{Float64, 4, Matrix{Float64}, Matrix{Float64}}, SurfaceIntegralWeakForm{FluxLaxFriedrichs{typeof(max_abs_speed_naive)}}, VolumeIntegralWeakForm}, cache::NamedTuple{(:elements,), Tuple{Trixi.ElementContainer{2, Float64, Float64, 3, 4, 5}}}; solution_variables::Function, nvisnodes::Int64)
@ Trixi ~/.julia/dev/Trixi/src/visualization/types.jl:398
[10] #PlotData2D#1103
@ ~/.julia/dev/Trixi/src/visualization/types.jl:242 [inlined]
[11] PlotData2D(u_ode::Vector{Float64}, semi::SemidiscretizationHyperbolic{StructuredMesh{2, Float64}, LinearScalarAdvectionEquation2D{Float64}, typeof(initial_condition_convergence_test), Trixi.BoundaryConditionPeriodic, Nothing, DGSEM{LobattoLegendreBasis{Float64, 4, SVector{4, Float64}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}, Trixi.LobattoLegendreMortarL2{Float64, 4, Matrix{Float64}, Matrix{Float64}}, SurfaceIntegralWeakForm{FluxLaxFriedrichs{typeof(max_abs_speed_naive)}}, VolumeIntegralWeakForm}, NamedTuple{(:elements,), Tuple{Trixi.ElementContainer{2, Float64, Float64, 3, 4, 5}}}}; kwargs::Base.Pairs{Symbol, typeof(cons2strange), Tuple{Symbol}, NamedTuple{(:solution_variables,), Tuple{typeof(cons2strange)}}})
@ Trixi ~/.julia/dev/Trixi/src/visualization/types.jl:229
[12] #PlotData2D#1105
@ ~/.julia/dev/Trixi/src/visualization/types.jl:285 [inlined]
[13] top-level scope
@ REPL[7]:1
```
With StructArrays.jl v0.6.7:
```julia
julia> using Trixi, OrdinaryDiffEq, Plots
julia> trixi_include("examples/structured_2d_dgsem/elixir_advection_extended.jl")
julia> PlotData2D(sol) # fine
PlotData2DTriangulated{Matrix{Float64}, StructArray{SVector{1, Float64}, 2, Tuple{Matrix{Float64}}, Int64}, Matrix{Float64}, StructArray{SVector{1, Float64}, 2, Tuple{Matrix{Float64}}, Int64}, SVector{1, String}}(, , , , , , , )
julia> cons2strange(u, ::LinearScalarAdvectionEquation2D) = SVector(u[1], u[1])
cons2strange (generic function with 1 method)
julia> Trixi.varnames(::typeof(cons2strange), ::LinearScalarAdvectionEquation2D) = ("a", "b")
julia> pd = PlotData2D(sol; solution_variables=cons2strange) # works now
PlotData2DTriangulated{Matrix{Float64}, StructArray{SVector{1, Float64}, 2, Tuple{Matrix{Float64}}, Int64}, Matrix{Float64}, StructArray{SVector{1, Float64}, 2, Tuple{Matrix{Float64}}, Int64}, SVector{2, String}}(, , , , , , , )
julia> plot(pd["a"]) # fine, as in our tutorial
```
This let's our CI of [tutorial 8](https://trixi-framework.github.io/Trixi.jl/stable/tutorials/structured_mesh_mapping/) fail right now, e.g. https://github.com/trixi-framework/Trixi.jl/pull/1140
CC @jlchan
Contributor guide
Research direction
Reproduce the failure with PlotData2D(sol; solution_variables=cons2strange) from the issue, then inspect src/visualization/utilities.jl and src/visualization/types.jl at the reported entry points. Done means PlotData2D accepts a different number of variables without the StructArrays conversion error, and tutorial 8 CI passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100