trixi-framework / Trixi.jl

Trixi.jl: Adaptive high-order numerical simulations of conservation laws in Julia
https://trixi-framework.github.io/Trixi.jl
MIT License
522 stars 102 forks source link

StructuredMesh with CodeTracking does not seem to work in Jupyter notebooks #931

Open xzczd opened 2 years ago

xzczd commented 2 years ago

In the example file IAU6j\examples\structured_1d_dgsem\elixir_euler_source_terms_nonperiodic.jl, the following lines

f1() = SVector(0.0)
f2() = SVector(2.0)
mesh = StructuredMesh((16,), (f1, f2), periodicity=false)

cause the error

MethodError: no method matching getindex(::Nothing, ::Int64)

Modifying the code to

mesh = StructuredMesh((16,),(0.0,), (2.0,), periodicity=false)

seems to fix the problem. (I found the syntax in examples\structured_1d_dgsem\elixir_euler_source_terms.jl BTW. )

ranocha commented 2 years ago
xzczd commented 2 years ago

@ranocha I'm using Trixi v0.4.2 (Checked with using Pkg;Pkg.status("Trixi")).

The complete error message is as follows:

MethodError: no method matching getindex(::Nothing, ::Int64)
Closest candidates are:
  getindex(::Any, ::Unrolled.FixedRange{A, B}) where {A, B} at C:\Users\xzczd\.julia\packages\Unrolled\26uDc\src\range.jl:23

Stacktrace:
  [1] code_string(f::Function, t::Tuple{})
    @ CodeTracking C:\Users\xzczd\.julia\packages\CodeTracking\15lQK\src\CodeTracking.jl:299
  [2] (::Trixi.var"#face2substring#211"{Int64})(face::Function)
    @ Trixi C:\Users\xzczd\.julia\packages\Trixi\IAU6j\src\meshes\structured_mesh.jl:95
  [3] |>
    @ .\operators.jl:858 [inlined]
  [4] _broadcast_getindex_evalf
    @ .\broadcast.jl:648 [inlined]
  [5] _broadcast_getindex
    @ .\broadcast.jl:621 [inlined]
  [6] _getindex
    @ .\broadcast.jl:644 [inlined]
  [7] _broadcast_getindex
    @ .\broadcast.jl:620 [inlined]
  [8] (::Base.Broadcast.var"#19#20"{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(|>), Tuple{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(|>), Tuple{Tuple{typeof(f1), typeof(f2)}, Base.RefValue{Trixi.var"#face2substring#211"{Int64}}}}, Base.RefValue{typeof(string)}}}})(k::Int64)
    @ Base.Broadcast .\broadcast.jl:1098
  [9] ntuple
    @ .\ntuple.jl:49 [inlined]
 [10] copy
    @ .\broadcast.jl:1098 [inlined]
 [11] materialize
    @ .\broadcast.jl:883 [inlined]
 [12] StructuredMesh(cells_per_dimension::Tuple{Int64}, faces::Tuple{typeof(f1), typeof(f2)}; RealT::Type, periodicity::Bool)
    @ Trixi C:\Users\xzczd\.julia\packages\Trixi\IAU6j\src\meshes\structured_mesh.jl:98
 [13] top-level scope
    @ In[51]:3
 [14] eval
    @ .\boot.jl:360 [inlined]
 [15] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:1116
ranocha commented 2 years ago

For me,

julia> using Trixi

julia> include(joinpath(examples_dir(), "structured_1d_dgsem", "elixir_euler_source_terms_nonperiodic.jl"))

works fine using Trixi v0.4.2.

xzczd commented 2 years ago

@ranocha …This is strange. Seems that it's related to jupyter notebook! (Yeah I was testing with IJulia. ) When I tested the example in command-line REPL, the sample just works well. Why?

FWIW, I'm using IJulia v1.23.2, notebook v6.0.3.

ranocha commented 2 years ago

Strange... Did you ever experiment with CodeTracking in Jupyter notebooks, @efaulhaber?

ranocha commented 2 years ago

A possible first step to debug this seems to be to try experimenting with CodeTracking and Jupyter notebooks...

ranocha commented 2 years ago

Maybe related to https://github.com/timholy/CodeTracking.jl/issues/51?

efaulhaber commented 2 years ago

No, I never experimented with experiment with Jupyter notebooks.

This is related to #541, as storing an interpolation of the mapping (just like the P4estMesh) would solve this issue as well.