From 4cffb0fa3d4530b49fad5ade9dcc632916bde021 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sun, 24 Jul 2022 00:59:24 +0200 Subject: [PATCH] NFC: Source code organization --- src/HYPRE.jl | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/HYPRE.jl b/src/HYPRE.jl index 294ded2..dc4d997 100644 --- a/src/HYPRE.jl +++ b/src/HYPRE.jl @@ -19,9 +19,9 @@ using .LibHYPRE: @check # Internal namespace to hide utility functions include("Internals.jl") -############################### -# HYPREMatrix and HYPREVector # -############################### +############### +# HYPREMatrix # +############### mutable struct HYPREMatrix # <: AbstractMatrix{HYPRE_Complex} #= const =# comm::MPI.Comm @@ -49,6 +49,22 @@ function HYPREMatrix(comm::MPI.Comm, ilower::Integer, iupper::Integer, return A end +# Finalize the matrix and fetch the assembled matrix +# This should be called after setting all the values +function Internals.assemble_matrix(A::HYPREMatrix) + # Finalize after setting all values + @check HYPRE_IJMatrixAssemble(A.IJMatrix) + # Fetch the assembled CSR matrix + ParCSRMatrixRef = Ref{Ptr{Cvoid}}(C_NULL) + @check HYPRE_IJMatrixGetObject(A.IJMatrix, ParCSRMatrixRef) + A.ParCSRMatrix = convert(Ptr{HYPRE_ParCSRMatrix}, ParCSRMatrixRef[]) + return A +end + +############### +# HYPREVector # +############### + mutable struct HYPREVector # <: AbstractVector{HYPRE_Complex} #= const =# comm::MPI.Comm #= const =# ilower::HYPRE_BigInt @@ -72,18 +88,6 @@ function HYPREVector(comm::MPI.Comm, ilower::Integer, iupper::Integer) return b end -# Finalize the matrix and fetch the assembled matrix -# This should be called after setting all the values -function Internals.assemble_matrix(A::HYPREMatrix) - # Finalize after setting all values - @check HYPRE_IJMatrixAssemble(A.IJMatrix) - # Fetch the assembled CSR matrix - ParCSRMatrixRef = Ref{Ptr{Cvoid}}(C_NULL) - @check HYPRE_IJMatrixGetObject(A.IJMatrix, ParCSRMatrixRef) - A.ParCSRMatrix = convert(Ptr{HYPRE_ParCSRMatrix}, ParCSRMatrixRef[]) - return A -end - function Internals.assemble_vector(b::HYPREVector) # Finalize after setting all values @check HYPRE_IJVectorAssemble(b.IJVector)