j-fu / VoronoiFVM.jl

Solution of nonlinear multiphysics partial differential equation systems using the Voronoi finite volume method
MIT License
183 stars 33 forks source link

Error with user-defined data #18

Closed mjyshin closed 2 years ago

mjyshin commented 2 years ago

I wanted to pass parameters with something like

data = (D=1.0,)
phys = VoronoiFVM.Physics(flux=flux!,data=data)

but I get an error

MethodError: no method matching isdata(::NamedTuple{(:D,), Tuple{Float64}})
Closest candidates are:
  isdata(::VoronoiFVM.NoData) at /home/mjyshin/.julia/packages/VoronoiFVM/sd93r/src/vfvm_physics.jl:28
  isdata(::VoronoiFVM.AbstractData) at /home/mjyshin/.julia/packages/VoronoiFVM/sd93r/src/vfvm_physics.jl:29

Stacktrace:
 [1] VoronoiFVM.Physics(; num_species::Int64, data::NamedTuple{(:D,), Tuple{Float64}}, flux::Function, reaction::Function, storage::Function, source::Function, breaction::Function, bstorage::Function)
   @ VoronoiFVM ~/.julia/packages/VoronoiFVM/sd93r/src/vfvm_physics.jl:121
 [2] top-level scope
   @ In[77]:1
 [3] eval
   @ ./boot.jl:360 [inlined]
 [4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1094

I have not gotten this error before, so I was wondering if there's something with a recent update that might have prompted it. Thank you in advance!

j-fu commented 2 years ago

There have been some consolidations internally. Are you on the current version, 0.12.6 ? There, the isdata method is different from what you see in the error message.

mjyshin commented 2 years ago

Yes I am using 0.12.6.

(fvm) pkg> status
      Status `~/fvm/Project.toml`
  [cfc395e8] ExtendableGrids v0.7.9
  [5eed8a63] GridVisualize v0.2.12
  [91a5bcdd] Plots v1.21.2
  [d330b81b] PyPlot v2.9.0
  [82b139dc] VoronoiFVM v0.12.6
j-fu commented 2 years ago

I am getting (in a fresh directory):

julia> using VoronoiFVM

(vvv) pkg> status
      Status `~/Wias/work/julia/test/vvv/Project.toml`
  [82b139dc] VoronoiFVM v0.12.6

julia> flux!(y,f,edge,data)=nothing
flux! (generic function with 1 method)

julia> data = (D=1.0,)
(D = 1.0,)

julia> phys = VoronoiFVM.Physics(flux=flux!,data=data)
VoronoiFVM.Physics(num_species=0, data=NamedTuple{(:D,), Tuple{Float64}}, flux=flux!, storage=default_storage, source=nosrc, bsource=nosrc, generic_operator=nofunc_generic, generic_operator_sparsity=nofunc_generic_sparsity)

The isdata(::VoronoiFVM.AbstractData) definition is very old and outdated. Are you sure that you are using the right environment etc. ? An explanation could be that you ran that code in the global environment which still uses an very old version...

mjyshin commented 2 years ago

Ahh it looks like the problem was because I didn't have IJulia added to the environment and I was using a Jupyter notebook and it must have defaulted to the base environment with an older version of VoronoiFVM.

On an unrelated note, is there an easy way to make flux/reaction/storage space- and/or time-dependent?

j-fu commented 2 years ago

As for space dependency:

You can access the i-th coordinate(s) of a node as node[i] and of an edge as edge[i,1] resp. edge[i,2]. I see that this is not well documented.

As for time dependency: I put this on my todo list. It is easy to pass the current time in the node/edge struct, however I need to think about how to make this compatible with DifferentialEquations.jl.

Can you say more about the problem you are trying to solve ?

j-fu commented 2 years ago

Let us continue the discussion in #19