Skip to content

Commit

Permalink
Merge pull request #116 from j-fu/integrate_solution
Browse files Browse the repository at this point in the history
Integrate solution
  • Loading branch information
j-fu authored Aug 1, 2024
2 parents 7d21857 + aa403cc commit 196148a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/VoronoiFVM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export coordinates

"""
$(TYPEDEF)
Abstract type for finite volume system structure.
"""
abstract type AbstractSystem{Tv <: Number, Tc <: Number, Ti <: Integer, Tm <: Integer} end
Expand All @@ -105,6 +105,7 @@ export edgelength
export viewK, viewL, data
export hasoutflownode, isoutflownode, outflownode


@compat public System, AbstractSystem

# export to be deprecated
Expand Down
18 changes: 16 additions & 2 deletions src/vfvm_postprocess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Base.setindex!(I::SolutionIntegral, v, ispec::Integer, ireg) = I.value[ispec, ir
Integrate node function (same signature as reaction or storage)
`F` of solution vector region-wise over domain or boundary.
The result is an `nspec x nregion` vector.
The result is an `nspec x nregion` matrix.
"""
function integrate(system::AbstractSystem{Tv, Tc, Ti, Tm}, F::Function, U::AbstractMatrix{Tu};
boundary = false) where {Tu, Tv, Tc, Ti, Tm}
Expand Down Expand Up @@ -69,12 +69,26 @@ function integrate(system::AbstractSystem{Tv, Tc, Ti, Tm}, F::Function, U::Abstr
return SolutionIntegral(integral)
end

"""
integrate(system,F,U; boundary=false)
Integrate solution vector region-wise over domain or boundary.
The result is an `nspec x nregion` matrix.
"""
function integrate(system::AbstractSystem,U::AbstractMatrix)
function f(f,u,node,data=nothing)
f.=u
end
integrate(system,f,U)
end


"""
edgeintegrate(system,F,U; boundary=false)
Integrate edge function (same signature as flux function)
`F` of solution vector region-wise over domain or boundary.
The result is an `nspec x nregion` vector.
The result is an `nspec x nregion` matrix.
"""
function edgeintegrate(system::AbstractSystem{Tv, Tc, Ti, Tm}, F::Function, U::AbstractMatrix{Tu};
boundary = false) where {Tu, Tv, Tc, Ti, Tm}
Expand Down
11 changes: 11 additions & 0 deletions test/test_norms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ function grid(X, dim)
end
end

function test_solint(; dim = 2, c = 1.0, assembly = :edgewise, h = 0.1)
X = 0:h:1
g = grid(X, dim)
sys = VoronoiFVM.System(g; species = [1], assembly)
VoronoiFVM._complete!(sys)
u = map(c, sys)
VoronoiFVM.integrate(sys, u)[1, 1]
end


function test_edgeint(; dim = 2, c = 1.0, assembly = :edgewise, h = 0.1)
X = 0:h:1
g = grid(X, dim)
Expand Down Expand Up @@ -97,6 +107,7 @@ function runtests()
for assembly in (:edgewise, :cellwise)
for dim = 1:3
for c in [0.5, 1, 2.0]
@test test_solint(; dim, c, assembly) c
@test test_edgeint(; dim, c, assembly) c
@test test_const(; nrm = l2norm, dim, c, assembly) c
@test test_const(; nrm = h1seminorm, dim, c, assembly) 0
Expand Down

0 comments on commit 196148a

Please sign in to comment.