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

Network advanced - connected components #320

Merged
merged 8 commits into from
Oct 20, 2021
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 src/Circuitscape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
module Circuitscape
using AlgebraicMultigrid
using ArchGDAL
using SimpleWeightedGraphs
using Graphs
using SimpleWeightedGraphs
using IterativeSolvers
using GZip
using Pardiso
Expand Down
25 changes: 13 additions & 12 deletions src/raster/advanced.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct AdvancedProblem{T,V,W}
sources::Vector{T}
grounds::Vector{T}
source_map::Matrix{T} # Needed for one to all mode
finite_grounds::Vector{T}
finitegrounds::Vector{T}
check_node::V
src::V
cellmap::Matrix{T}
Expand Down Expand Up @@ -59,14 +59,14 @@ function compute_advanced_data(data::RasterData{T,V},
cc = connected_components(SimpleWeightedGraph(G))

# Advanced mode specific stuff
sources, grounds, finite_grounds =
sources, grounds, finitegrounds =
get_sources_and_grounds(data, flags, G, nodemap)

solver = get_solver(cfg)

AdvancedProblem(G, cc, nodemap, polymap, hbmeta,
sources, grounds, source_map,
finite_grounds, V(-1), V(0), cellmap, solver)
finitegrounds, V(-1), V(0), cellmap, solver)

end

Expand Down Expand Up @@ -119,7 +119,6 @@ end
function resolve_conflicts(sources::Vector{T},
grounds::Vector{T}, policy) where T

finitegrounds = similar(sources)
l = size(sources, 1)

finitegrounds = map(x -> x < T(Inf) ? x : T(0.), grounds)
Expand Down Expand Up @@ -158,7 +157,7 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix
hbmeta = prob.hbmeta
sources = prob.sources
grounds = prob.grounds
finitegrounds = prob.finite_grounds
finitegrounds = prob.finitegrounds
cc = prob.cc
src = prob.src
check_node = prob.check_node
Expand All @@ -178,7 +177,7 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix
ind = findall(x->x!=0,nodemap)
f_local = Vector{eltype(G)}()
solver_called = false
voltages = Vector{eltype(G)}()
voltages = zeros(eltype(G), size(G, 1))
outvolt = alloc_map(hbmeta)
outcurr = alloc_map(hbmeta)

Expand All @@ -203,21 +202,23 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix
f_local = finitegrounds
end

voltages = multiple_solver(cfg, prob.solver, a_local, s_local, g_local, f_local)
voltages[c] .+= multiple_solver(cfg, prob.solver, a_local, s_local, g_local, f_local)

local_nodemap = construct_local_node_map(nodemap, c, polymap)
solver_called = true

if write_v_maps && is_raster
accum_voltages!(outvolt, voltages, local_nodemap, hbmeta)
if write_v_maps
is_raster ? accum_voltages!(outvolt, voltages[c], local_nodemap, hbmeta) :
accum_voltages!(outvolt, voltages, local_nodemap, hbmeta)
end
if write_c_maps && is_raster
accum_currents!(outcurr, voltages, cfg, a_local, voltages, f_local, local_nodemap, hbmeta)
if write_c_maps
is_raster ? accum_currents!(outcurr, voltages[c], cfg, a_local, voltages[c], f_local, local_nodemap, hbmeta) :
accum_currents!(outcurr, voltages, cfg, G, voltages, finitegrounds, local_nodemap, hbmeta)
end

for i in eachindex(volt)
_i = Int(local_nodemap[i])
_i != 0 && (volt[i] = voltages[_i])
_i != 0 && (volt[i] = voltages[c][_i])
end
end

Expand Down
3 changes: 2 additions & 1 deletion test/input/network/mgNetworkVerify3_graph_resistances.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
1.000000000000000 2.000000000000000 1
1.000000000000000 3.000000000000000 1
2.000000000000000 4.000000000000000 1
3.000000000000000 4.000000000000000 1
3.000000000000000 4.000000000000000 1
5.000000000000000 6.000000000000000 1
2 changes: 2 additions & 0 deletions test/output_verify/mgNetworkVerify3_node_currents.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
2 6.221873918
3 6.221873918
4 12.19733699
5 0
6 0
2 changes: 2 additions & 0 deletions test/output_verify/mgNetworkVerify3_voltages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
2 6.098668494
3 6.098668494
4 0
5 0
6 0