SciML / MultiScaleArrays.jl

A framework for developing multi-scale arrays for use in scientific machine learning (SciML) simulations
https://docs.sciml.ai/MultiScaleArrays/stable/
Other
73 stars 16 forks source link

add_node! not outputting expected result with integrator input #48

Closed RobertGregg closed 4 years ago

RobertGregg commented 4 years ago

First off, this framework for multi-scale modeling is fantastic. A lot of the software I've tried does not have an adequate ODE solver suite for complex simulations.

I was writing a callback event that adds a cell to a population using the add_nodes! function and it added a cell with different values than what I gave it. My best guess for the cause is using the similar function in the diffeq.jl file. Here is a minimal working example of what I mean:

using DifferentialEquations, MultiScaleArrays

# Create Structures that define a Cell and Population
struct Cell{B} <: AbstractMultiScaleArrayLeaf{B}
    values::Vector{B}
end

struct Population{T<:AbstractMultiScaleArray,B<:Number} <: AbstractMultiScaleArrayHead{B}
    nodes::Vector{T}
    values::Vector{B}
    end_idxs::Vector{Int}
end

nCells=2
cellConstructor = [Cell([1.0, 2.0]) for i=1:nCells]
cellPop = construct(Population, deepcopy(cellConstructor))

function StateModel(dpop,pop,p,t) #This is arbitrary
    for (cell,dcell) in LevelIter(1,pop,dpop)
        dcell = 1.0
    end
end

prob = ODEProblem(StateModel,cellPop,(0.0,1.0))

integrator = init(prob,Tsit5())

add_node!(integrator,Cell([5.0, 20.0]))

integrator.u.nodes[end].values .== [5.0, 20.0] #Both false
ChrisRackauckas commented 4 years ago

Sorry it took awhile to get to this, but it's fixed now and a tag will go out in about 30 minutes.