Skip to content

Jf/fix bnodeunknowns #165

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

Merged
merged 6 commits into from
Dec 23, 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "VoronoiFVM"
uuid = "82b139dc-5afc-11e9-35da-9b9bdfd336f3"
authors = ["Jürgen Fuhrmann <[email protected]>", "Patrick Jaap", "Daniel Runge", "Dilara Abdel", "Jan Weidner", "Alexander Seiler", "Patricio Farrell", "Matthias Liero"]
version = "2.6.2"
version = "2.6.3"

[deps]
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
Expand Down
44 changes: 24 additions & 20 deletions src/vfvm_geometryitems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Abstract type for data on nodes.
`u[ispec]` accesses value of species at this node.
"""
abstract type AbstractNodeData{Tv <: Number} <: AbstractVector{Tv} end
Base.size(u::AbstractNodeData) = (u.nspec, 1)
Base.size(u::AbstractNodeData) = (u.nspec,)
Base.getindex(u::AbstractNodeData, i) = @inbounds u.val[i]
Base.setindex!(f::AbstractNodeData, v, i) = @inbounds f.val[i] = v

Expand Down Expand Up @@ -207,7 +207,7 @@ Structure holding local boundary node information.

$(TYPEDFIELDS)
"""
mutable struct BNode{Tv, Tc, Tp, Ti} <: AbstractNode{Tc, Tp, Ti}
mutable struct BNode{Td, Tc, Tp, Ti} <: AbstractNode{Tc, Tp, Ti}
"""
Index in grid
"""
Expand Down Expand Up @@ -248,7 +248,7 @@ mutable struct BNode{Tv, Tc, Tp, Ti} <: AbstractNode{Tc, Tp, Ti}

bfacecells::ExtendableGrids.Adjacency{Ti}

Dirichlet::Tv
Dirichlet::Td

"""
System time
Expand All @@ -265,14 +265,14 @@ mutable struct BNode{Tv, Tc, Tp, Ti} <: AbstractNode{Tc, Tp, Ti}
"""
params::Vector{Tp}

dirichlet_value::Vector{Tv}
dirichlet_value::Vector{Td}

fac::Float64

function BNode{Tv, Tc, Tp, Ti}(
sys::AbstractSystem{Tv, Tc, Ti, Tm}, time, embedparam,
function BNode{Td, Tc, Tp, Ti}(
sys::Ts, time, embedparam,
params::Vector{Tp}
) where {Tv, Tc, Tp, Ti, Tm}
) where {Td, Tc, Tp, Ti, Ts <: AbstractSystem}
return new(
0, 0, 0, 0, zeros(Ti, 2),
num_species(sys),
Expand All @@ -281,34 +281,38 @@ mutable struct BNode{Tv, Tc, Tp, Ti} <: AbstractNode{Tc, Tp, Ti}
sys.grid[BFaceRegions],
sys.grid[CellRegions],
sys.grid[BFaceCells],
Dirichlet(Tv), time, embedparam, params,
zeros(Tv, num_species(sys)), 0.0
Dirichlet(Td), time, embedparam, params,
zeros(Td, num_species(sys)), 0.0
)
end
end

# JF: We need to be able to distinguish bwetween dirichlet type and value type.
# So far we will use Tp for the dirichlet type instead of the valuetype.
# Maybe this even allows derivatives wrt. Dirichlet data.
function BNode(sys::AbstractSystem{Tv, Tc, Ti, Tm}, time, embedparam, params::Vector{Tp}) where {Tv, Tc, Tp, Ti, Tm}
return BNode{Tv, Tc, Tp, Ti}(sys, time, embedparam, params)
return BNode{Tp, Tc, Tp, Ti}(sys, time, embedparam, params)
end
BNode(sys) = BNode(sys, 0, 0, zeros(0))

struct BNodeUnknowns{Tval, Tv, Tc, Tp, Ti} <: AbstractNodeData{Tv}
val::Vector{Tval}
struct BNodeUnknowns{Tv, Td, Tc, Tp, Ti} <: AbstractNodeData{Tv}
val::Vector{Tv}
nspec::Ti
geom::BNode{Tv, Tc, Tp, Ti}
geom::BNode{Td, Tc, Tp, Ti}
end

@inline function unknowns(bnode::BNode{Tv, Tc, Tp, Ti}, u::AbstractVector{Tval}) where {Tval, Tv, Tc, Tp, Ti}
return BNodeUnknowns{Tval, Tv, Tc, Tp, Ti}(u, bnode.nspec, bnode)
@inline function unknowns(bnode::BNode{Td, Tc, Tp, Ti}, u::AbstractVector{Tv}) where {Tv, Td, Tc, Tp, Ti}
return BNodeUnknowns{Tv, Td, Tc, Tp, Ti}(u, bnode.nspec, bnode)
end

struct BNodeRHS{Tval, Tv, Tc, Tp, Ti} <: AbstractNodeData{Tv}
val::Vector{Tval}
struct BNodeRHS{Tv, Td, Tc, Tp, Ti} <: AbstractNodeData{Tv}
val::Vector{Tv}
nspec::Ti
geom::BNode{Tv, Tc, Tp, Ti}
geom::BNode{Td, Tc, Tp, Ti}
end

@inline function rhs(bnode::BNode{Tv, Tc, Tp, Ti}, f::AbstractVector{Tval}) where {Tval, Tv, Tc, Tp, Ti}
return BNodeRHS{Tval, Tv, Tc, Tp, Ti}(f, bnode.nspec, bnode)
@inline function rhs(bnode::BNode{Td, Tc, Tp, Ti}, f::AbstractVector{Tv}) where {Tv, Td, Tc, Tp, Ti}
return BNodeRHS{Tv, Td, Tc, Tp, Ti}(f, bnode.nspec, bnode)
end

##################################################################
Expand Down
85 changes: 85 additions & 0 deletions test/test_geomitems.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module test_geomitems
using VoronoiFVM
using ExtendableGrids
using ForwardDiff
using Test

const Dual64 = ForwardDiff.Dual{Float64, Float64, 1}

flux(y, u, edge, data) = y[1] = u[1, 1] - u[1, 2]


function main(; n = 3)
g = simplexgrid(0:0.1:1)
sys = VoronoiFVM.System(g; flux, species = 1:n)
time = 0.0
λ = 0.0
params = zeros(3)

utest = zeros(Dual64, 2 * n)
node = VoronoiFVM.Node(sys, time, λ, params)
u = unknowns(node, utest)
@test typeof(u[1]) == eltype(u)
@test typeof(copy(u)[1]) == eltype(u)
@test length(u) == n
@test size(u) == (n,)

bnode = VoronoiFVM.BNode(sys, time, λ, params)
u = unknowns(bnode, utest)
@test typeof(u[1]) == eltype(u)
@test typeof(copy(u)[1]) == eltype(u)
@test length(u) == n
@test size(u) == (n,)

edge = VoronoiFVM.Edge(sys, time, λ, params)
u = unknowns(edge, utest)
@test typeof(u[1]) == eltype(u)
@test typeof(copy(u)[1]) == eltype(u)
@test length(u) == 2 * n
@test size(u) == (n, 2)

bedge = VoronoiFVM.BEdge(sys, time, λ, params)
u = unknowns(bedge, utest)
@test typeof(u[1]) == eltype(u)
@test typeof(copy(u)[1]) == eltype(u)
@test length(u) == 2 * n
@test size(u) == (n, 2)


ftest = zeros(Dual64, 2 * n)
node = VoronoiFVM.Node(sys, time, λ, params)
f = VoronoiFVM.rhs(node, ftest)
@test typeof(f[1]) == eltype(f)
@test typeof(copy(f)[1]) == eltype(f)
@test length(f) == n
@test size(f) == (n,)

bnode = VoronoiFVM.BNode(sys, time, λ, params)
f = VoronoiFVM.rhs(bnode, ftest)
@test typeof(f[1]) == eltype(f)
@test typeof(copy(f)[1]) == eltype(f)
@test length(f) == n
@test size(f) == (n,)

edge = VoronoiFVM.Edge(sys, time, λ, params)
f = VoronoiFVM.rhs(edge, ftest)
@test typeof(f[1]) == eltype(f)
@test typeof(copy(f)[1]) == eltype(f)
@test length(f) == n
@test size(f) == (n,)

bedge = VoronoiFVM.BEdge(sys, time, λ, params)
f = VoronoiFVM.rhs(bedge, ftest)
@test typeof(f[1]) == eltype(f)
@test typeof(copy(f)[1]) == eltype(f)
@test length(f) == n
return @test size(f) == (n,)


end

function runtests()
main()
return nothing
end
end
Loading