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

Remove data deprecation #125

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
solve!(solution,inival, system::VoronoiFVM.AbstractSystem; kwargs...)
````
- History is now a field of the solution but not system, to be accessed with ``history(sol)``, both for stationary and transient solutions
- [`VoronoiFVM.Physics`](@ref) callbacks (`flux`, `storage`, etc.) need a provided `data` argument

### Added
- Introduced ``SystemState`` which contains entries (matrix, residuals) which before were
part of ``System``
- Introduced `solve!(state::SystemState)` method
- Stationary solutions are now subtypes of AbstractNoTimeSolution
- Changelog now in package root

## upcoming release
## v1.25.0, Sept 9, 2024
- [`VoronoiFVM.Physics`](@ref) callbacks (`flux`, `storage`, etc.) without `data` argument are now deprecated

## v1.24.0 August 20, 2024
Expand Down
95 changes: 17 additions & 78 deletions src/vfvm_physics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ function nofunc_generic_sparsity(sys)
end


#
# Dummy data type that represents data or not
# We need this for the `data` deprecation phase
#
@kwdef mutable struct MaybeData
isdata=false
end

##########################################################
"""
````
Expand Down Expand Up @@ -200,7 +192,6 @@ end
##########################################################

isdata(::Nothing) = false
isdata(d::MaybeData) = d.isdata
isdata(::Any) = true

"""
Expand All @@ -224,7 +215,7 @@ Physics(;num_species=0,
Constructor for physics data. For the meaning of the optional keyword arguments, see [`VoronoiFVM.System(grid::ExtendableGrid; kwargs...)`](@ref).
"""
function Physics(; num_species = 0,
data = MaybeData(isdata=false),
data = nothing,
flux::Function = nofunc,
reaction::Function = nofunc,
edgereaction::Function = nofunc,
Expand All @@ -239,30 +230,6 @@ function Physics(; num_species = 0,
generic::Function = nofunc_generic,
generic_sparsity::Function = nofunc_generic_sparsity,
kwargs...)
if !isdata(data)
# deprecation check: callbacks without a `data` argument are not supported in future versions
callbacks = [flux, reaction, edgereaction, storage, source, bflux, breaction, bsource, bstorage, boutflow]
callbacks_seem_fine = true
for f in callbacks
# ignore dummy functions
if !(f in [nofunc, default_storage, nosrc])
# check whether the callbacks have a method with 3 or 4 arguments, respectively
nn = nothing
if ( f in [flux, reaction, edgereaction, storage, bflux, breaction, bstorage, boutflow] && applicable(f,nn,nn,nn) ) ||
( f in [source, bsource] && applicable(f,nn,nn) )
@warn "using VoronoiFVM.Physics callback $(nameof(f)) without a `data` argument is now deprecated"
callbacks_seem_fine = false
end
end
end

# it looks like all callbacks can be called with a `data` argument ⇒ enable a dummy data attribute
if callbacks_seem_fine
data.isdata = true
end

end

return Physics(flux,
storage,
reaction,
Expand Down Expand Up @@ -376,36 +343,18 @@ function ResEvaluator(physics, data, symb::Symbol, uproto::Vector{Tv}, geom, nsp

# source functions need special handling here
if symb == :source || symb == :bsource
if isdata(physics.data)
fwrap = function (y)
y .= 0
func(rhs(geom, y), geom, data)
nothing
end
else
fwrap = function (y)
y .= 0
func(rhs(geom, y), geom)
nothing
end
fwrap = function (y)
y .= 0
func(rhs(geom, y), geom, data)
nothing
end
else # Normal functions wihth u as parameter
if isdata(physics.data)
fwrap = function (y, u)
y .= 0
## for ii in .. uu[geom.speclist[ii]]=u[ii]
func(rhs(geom, y), unknowns(geom, u), geom, data)
## for ii in .. y[ii]=y[geom.speclist[ii]]
nothing
end
else
fwrap = function (y, u)
y .= 0
## for ii in .. uu[geom.speclist[ii]]=u[ii]
func(rhs(geom, y), unknowns(geom, u), geom)
## for ii in .. y[ii]=y[geom.speclist[ii]]
nothing
end
fwrap = function (y, u)
y .= 0
## for ii in .. uu[geom.speclist[ii]]=u[ii]
func(rhs(geom, y), unknowns(geom, u), geom, data)
## for ii in .. y[ii]=y[geom.speclist[ii]]
nothing
end
end
isnontrivial = (func != nofunc)
Expand Down Expand Up @@ -478,22 +427,12 @@ Constructor for ResJEvaluator
function ResJacEvaluator(physics, data, symb::Symbol, uproto::Vector{Tv}, geom, nspec) where {Tv}
func = getproperty(physics, symb)

if isdata(physics.data)
fwrap = function (y, u)
y .= 0
## for ii in .. uu[geom.speclist[ii]]=u[ii]
func(rhs(geom, y), unknowns(geom, u), geom, data)
## for ii in .. y[ii]=y[geom.speclist[ii]]
nothing
end
else
fwrap = function (y, u)
y .= 0
## for ii in .. uu[geom.speclist[ii]]=u[ii]
func(rhs(geom, y), unknowns(geom, u), geom)
## for ii in .. y[ii]=y[geom.speclist[ii]]
nothing
end
fwrap = function (y, u)
y .= 0
## for ii in .. uu[geom.speclist[ii]]=u[ii]
func(rhs(geom, y), unknowns(geom, u), geom, data)
## for ii in .. y[ii]=y[geom.speclist[ii]]
nothing
end

isnontrivial = (func != nofunc)
Expand Down
18 changes: 3 additions & 15 deletions src/vfvm_postprocess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ function integrate(system::AbstractSystem{Tv, Tc, Ti, Tm}, F::Function, U::Abstr

if boundary
bnode = BNode(system)
bnodeparams = (bnode,)
if isdata(data)
bnodeparams = (bnode, data)
end
#!!! bnode.time=time
#!!! bnode.embedparam=embedparam

Expand All @@ -38,17 +34,13 @@ function integrate(system::AbstractSystem{Tv, Tc, Ti, Tm}, F::Function, U::Abstr
for ibnode in noderange(system.boundary_assembly_data, item)
_fill!(bnode, system.boundary_assembly_data, ibnode, item)
res .= zero(Tv)
@views F(rhs(bnode, res), unknowns(bnode, U[:, bnode.index]), bnodeparams...)
@views F(rhs(bnode, res), unknowns(bnode, U[:, bnode.index]), bnode, data)
asm_res(idof, ispec) = integral[ispec, bnode.region] += bnode.fac * res[ispec]
assemble_res(bnode, system, asm_res)
end
end
else
node = Node(system)
nodeparams = (node,)
if isdata(data)
nodeparams = (node, data)
end
#!!! node.time=time
#!!! node.embedparam=embedparam
cellregions = grid[CellRegions]
Expand All @@ -58,7 +50,7 @@ function integrate(system::AbstractSystem{Tv, Tc, Ti, Tm}, F::Function, U::Abstr
for inode in noderange(system.assembly_data, item)
_fill!(node, system.assembly_data, inode, item)
res .= zero(Tv)
@views F(rhs(node, res), unknowns(node, U[:, node.index]), nodeparams...)
@views F(rhs(node, res), unknowns(node, U[:, node.index]), node, data)
asm_res(idof, ispec) = integral[ispec, node.region] += node.fac * res[ispec]
assemble_res(node, system, asm_res)
end
Expand Down Expand Up @@ -104,10 +96,6 @@ function edgeintegrate(system::AbstractSystem{Tv, Tc, Ti, Tm}, F::Function, U::A
error("missing implementation of boundary edge integrals")
else
edge = Edge(system)
edgeparams = (edge,)
if isdata(data)
edgeparams = (edge, data)
end
cellregions = grid[CellRegions]
ncellregions = maximum(cellregions)
integral = zeros(Tu, nspecies, ncellregions)
Expand All @@ -117,7 +105,7 @@ function edgeintegrate(system::AbstractSystem{Tv, Tc, Ti, Tm}, F::Function, U::A
@views UKL[1:nspecies] .= U[:, edge.node[1]]
@views UKL[(nspecies + 1):(2 * nspecies)] .= U[:, edge.node[2]]
res .= zero(Tv)
@views F(rhs(edge, res), unknowns(edge, UKL), edgeparams...)
@views F(rhs(edge, res), unknowns(edge, UKL), edge, data)
function asm_res(idofK, idofL, ispec)
h = meas(edge)
# This corresponds to the multiplication with the diamond volume.
Expand Down
6 changes: 1 addition & 5 deletions src/vfvm_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -975,11 +975,7 @@ function _initialize_dirichlet!(U::AbstractMatrix, system::AbstractSystem{Tv, Tc

# set up bnode
bnode = BNode(system, time, λ, params)
bnodeparams = (bnode,)
data = system.physics.data
if isdata(data)
bnodeparams = (bnode, data)
end

# setup unknowns to be passed
UK = zeros(Tv, num_species(system) + length(params))
Expand All @@ -999,7 +995,7 @@ function _initialize_dirichlet!(U::AbstractMatrix, system::AbstractSystem{Tv, Tc
bnode.dirichlet_value .= Inf
# set up solution vector, call boundary reaction
@views UK[1:nspecies] .= U[:, bnode.index]
system.physics.breaction(y, u, bnodeparams...)
system.physics.breaction(y, u, bnode, data)

# Check for Dirichlet bc
for ispec = 1:nspecies
Expand Down
Loading