Skip to content

Commit

Permalink
Added code for Jacobian decompression
Browse files Browse the repository at this point in the history
Added code block to decompress Jacobian by
exploiting the property that all columns of
the same color are mutually orthogonal and
hence do not share non-zero elements at a
common row.
  • Loading branch information
pkj-m committed Jun 12, 2019
1 parent fa1248b commit f29bcaf
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/jacobians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ function finite_difference_jacobian!(
# J is a sparse matrix, so decompress on the fly
@. vfx1 = (vfx1 - vfx) / epsilon
# vfx1 is the compressed Jacobian column
# TODO
(rows_index, cols_index, val) = findnz(SparseMatrix)

for i in 1:length(cols_index)
if color[cols_index[i]] == color_i
J[rows_index[i],cols_index[i]] = vfx1[rows_index[i]]
end
end
end
else
fx1 .= f(x1)
Expand All @@ -185,7 +191,13 @@ function finite_difference_jacobian!(
# J is a sparse matrix, so decompress on the fly
vfx1 = (vfx1 - vfx) / epsilon
# vfx1 is the compressed Jacobian column
# TODO
(rows_index, cols_index, val) = findnz(SparseMatrix)

for i in 1:length(cols_index)
if color[cols_index[i]] == color_i
J[rows_index[i],cols_index[i]] = vfx1[rows_index[i]]
end
end
end
end

Expand All @@ -196,7 +208,7 @@ function finite_difference_jacobian!(
for i in 1:n
color[i] == color_i && (x1[i] -= epsilon)
end
end
end #for ends here

end
elseif fdtype == Val{:central}
Expand Down

0 comments on commit f29bcaf

Please sign in to comment.