From 742e18245cfbb437fed8b0d13250a4b0f666afd9 Mon Sep 17 00:00:00 2001 From: Ranjan Anantharaman Date: Mon, 18 Oct 2021 00:07:01 -0400 Subject: [PATCH 1/7] Check if this fixes cc issue in net adv --- src/raster/advanced.jl | 4 ++-- test/input/network/mgNetworkVerify3_graph_resistances.txt | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/raster/advanced.jl b/src/raster/advanced.jl index 24b615af..3bbe1aff 100644 --- a/src/raster/advanced.jl +++ b/src/raster/advanced.jl @@ -208,10 +208,10 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix local_nodemap = construct_local_node_map(nodemap, c, polymap) solver_called = true - if write_v_maps && is_raster + if write_v_maps # && is_raster accum_voltages!(outvolt, voltages, local_nodemap, hbmeta) end - if write_c_maps && is_raster + if write_c_maps # && is_raster accum_currents!(outcurr, voltages, cfg, a_local, voltages, f_local, local_nodemap, hbmeta) end diff --git a/test/input/network/mgNetworkVerify3_graph_resistances.txt b/test/input/network/mgNetworkVerify3_graph_resistances.txt index 089a95c5..c27693d8 100644 --- a/test/input/network/mgNetworkVerify3_graph_resistances.txt +++ b/test/input/network/mgNetworkVerify3_graph_resistances.txt @@ -2,4 +2,5 @@ 1.000000000000000 2.000000000000000 1 1.000000000000000 3.000000000000000 1 2.000000000000000 4.000000000000000 1 -3.000000000000000 4.000000000000000 1 \ No newline at end of file +3.000000000000000 4.000000000000000 1 +5.000000000000000 6.000000000000000 1 \ No newline at end of file From 429c20ebc9d816e81d07c597f1bad7e6e52dd055 Mon Sep 17 00:00:00 2001 From: Ranjan Anantharaman Date: Mon, 18 Oct 2021 00:19:22 -0400 Subject: [PATCH 2/7] Try --- src/raster/advanced.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/raster/advanced.jl b/src/raster/advanced.jl index 3bbe1aff..2ec85041 100644 --- a/src/raster/advanced.jl +++ b/src/raster/advanced.jl @@ -224,7 +224,7 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix name = src == 0 ? "" : "_$(V(src))" if write_v_maps if !is_raster - write_volt_maps(name, voltages, FullGraph(G, cellmap), flags, cfg) + write_volt_maps(name, outvolt, FullGraph(G, cellmap), flags, cfg) else write_grid(outvolt, name, cfg, hbmeta, cellmap, voltage = true) end @@ -232,7 +232,7 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix if write_c_maps && !write_cum_cur_map_only if !is_raster - write_cur_maps(name, voltages, FullGraph(G, cellmap), finitegrounds, flags, cfg) + write_cur_maps(name, outcurr, FullGraph(G, cellmap), finitegrounds, flags, cfg) else write_grid(outcurr, name, cfg, hbmeta, cellmap) end From 1fc2058ad6a435980c7322a9af399701517b0bcb Mon Sep 17 00:00:00 2001 From: Ranjan Anantharaman Date: Mon, 18 Oct 2021 12:26:36 -0400 Subject: [PATCH 3/7] Accumulate voltages across connected components --- src/Circuitscape.jl | 2 +- src/raster/advanced.jl | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Circuitscape.jl b/src/Circuitscape.jl index 1d07eb82..1bc7fbeb 100644 --- a/src/Circuitscape.jl +++ b/src/Circuitscape.jl @@ -2,8 +2,8 @@ module Circuitscape using AlgebraicMultigrid using ArchGDAL -using SimpleWeightedGraphs using Graphs +using SimpleWeightedGraphs using IterativeSolvers using GZip using Pardiso diff --git a/src/raster/advanced.jl b/src/raster/advanced.jl index 2ec85041..d09db27b 100644 --- a/src/raster/advanced.jl +++ b/src/raster/advanced.jl @@ -178,7 +178,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) @@ -203,7 +203,7 @@ 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 @@ -224,7 +224,7 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix name = src == 0 ? "" : "_$(V(src))" if write_v_maps if !is_raster - write_volt_maps(name, outvolt, FullGraph(G, cellmap), flags, cfg) + write_volt_maps(name, voltages, FullGraph(G, cellmap), flags, cfg) else write_grid(outvolt, name, cfg, hbmeta, cellmap, voltage = true) end @@ -232,7 +232,7 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix if write_c_maps && !write_cum_cur_map_only if !is_raster - write_cur_maps(name, outcurr, FullGraph(G, cellmap), finitegrounds, flags, cfg) + write_cur_maps(name, voltages, FullGraph(G, cellmap), finitegrounds, flags, cfg) else write_grid(outcurr, name, cfg, hbmeta, cellmap) end From 9d154893cf8b611d014d41bf8ee96b4b04a4056f Mon Sep 17 00:00:00 2001 From: Ranjan Anantharaman Date: Tue, 19 Oct 2021 14:09:03 -0400 Subject: [PATCH 4/7] Get network advanced to support different cc --- src/raster/advanced.jl | 12 ++++++------ .../output_verify/mgNetworkVerify3_node_currents.txt | 2 ++ test/output_verify/mgNetworkVerify3_voltages.txt | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/raster/advanced.jl b/src/raster/advanced.jl index d09db27b..d932dfba 100644 --- a/src/raster/advanced.jl +++ b/src/raster/advanced.jl @@ -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} @@ -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 @@ -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) @@ -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 @@ -212,7 +211,8 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix 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) + # accum_currents!(outcurr, voltages, cfg, a_local, voltages, f_local, local_nodemap, hbmeta) + accum_currents!(outcurr, voltages, cfg, G, voltages, finitegrounds, local_nodemap, hbmeta) end for i in eachindex(volt) diff --git a/test/output_verify/mgNetworkVerify3_node_currents.txt b/test/output_verify/mgNetworkVerify3_node_currents.txt index 91480a5f..473e19de 100644 --- a/test/output_verify/mgNetworkVerify3_node_currents.txt +++ b/test/output_verify/mgNetworkVerify3_node_currents.txt @@ -3,3 +3,5 @@ 2 6.221873918 3 6.221873918 4 12.19733699 +5 0 +6 0 diff --git a/test/output_verify/mgNetworkVerify3_voltages.txt b/test/output_verify/mgNetworkVerify3_voltages.txt index 8b2dafd7..181bb038 100644 --- a/test/output_verify/mgNetworkVerify3_voltages.txt +++ b/test/output_verify/mgNetworkVerify3_voltages.txt @@ -3,3 +3,5 @@ 2 6.098668494 3 6.098668494 4 0 +5 0 +6 0 From af54a215f3df4bb51b15b70cc3941f16d879abcb Mon Sep 17 00:00:00 2001 From: Ranjan Anantharaman Date: Tue, 19 Oct 2021 16:21:47 -0400 Subject: [PATCH 5/7] Pass incremental voltage --- src/raster/advanced.jl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/raster/advanced.jl b/src/raster/advanced.jl index d932dfba..56fabe44 100644 --- a/src/raster/advanced.jl +++ b/src/raster/advanced.jl @@ -202,17 +202,20 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix f_local = finitegrounds end - voltages[c] .+= 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) + _v = multiple_solver(cfg, prob.solver, a_local, s_local, g_local, f_local) + voltages[c] .+= _v 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, _v, local_nodemap, hbmeta) + !is_raster && 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) - accum_currents!(outcurr, voltages, cfg, G, voltages, finitegrounds, local_nodemap, hbmeta) + if write_c_maps + is_raster && accum_currents!(outcurr, _v, cfg, a_local, _v, f_local, local_nodemap, hbmeta) + !is_raster && accum_currents!(outcurr, voltages, cfg, G, voltages, finitegrounds, local_nodemap, hbmeta) end for i in eachindex(volt) From 3685c8854417bc88f8af70ffea61e75fa3585af7 Mon Sep 17 00:00:00 2001 From: Ranjan Anantharaman Date: Tue, 19 Oct 2021 16:39:29 -0400 Subject: [PATCH 6/7] Cleanup --- src/raster/advanced.jl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/raster/advanced.jl b/src/raster/advanced.jl index 56fabe44..fc454c0f 100644 --- a/src/raster/advanced.jl +++ b/src/raster/advanced.jl @@ -202,25 +202,21 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix f_local = finitegrounds end - # voltages[c] .+= multiple_solver(cfg, prob.solver, a_local, s_local, g_local, f_local) - _v = multiple_solver(cfg, prob.solver, a_local, s_local, g_local, f_local) - voltages[c] .+= _v + 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, _v, local_nodemap, hbmeta) - !is_raster && accum_voltages!(outvolt, voltages, local_nodemap, hbmeta) + accum_voltages!(outvolt, voltages, local_nodemap, hbmeta) end if write_c_maps - is_raster && accum_currents!(outcurr, _v, cfg, a_local, _v, f_local, local_nodemap, hbmeta) - !is_raster && accum_currents!(outcurr, voltages, cfg, G, voltages, finitegrounds, 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 From ddc1207c18834e227482824d51da424f1b8054c8 Mon Sep 17 00:00:00 2001 From: Ranjan Anantharaman Date: Tue, 19 Oct 2021 17:23:56 -0400 Subject: [PATCH 7/7] Fix one to all tests --- src/raster/advanced.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/raster/advanced.jl b/src/raster/advanced.jl index fc454c0f..34ef1f8a 100644 --- a/src/raster/advanced.jl +++ b/src/raster/advanced.jl @@ -208,10 +208,12 @@ function advanced_kernel(prob::AdvancedProblem{T,V,S}, flags, cfg)::Tuple{Matrix solver_called = true if write_v_maps - accum_voltages!(outvolt, voltages, local_nodemap, hbmeta) + is_raster ? accum_voltages!(outvolt, voltages[c], local_nodemap, hbmeta) : + accum_voltages!(outvolt, voltages, local_nodemap, hbmeta) end if write_c_maps - accum_currents!(outcurr, voltages, cfg, G, voltages, finitegrounds, local_nodemap, hbmeta) + 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)