On 05/13/2015 03:20 PM, Garth N. Wells wrote:
On 12 May 2015 at 04:40, Marco Morandini <[email protected]> wrote:
Currently only GenericMatrix::set_diagonal is defined and implemented
for most of the la backends.
Would you object to a patch introducing get_diagonal ?
What data structure do you suggest the function returns, e.g. a
std::vector, local GenericVector or a distributed GenericVector? The
follow on question is what will it return in parallel, e.g. would it
include ghost values?
This is what I have in mind. Do you think it is ok?
1) Implementation:
void PETScMatrix::get_diagonal(GenericVector& x) const
{
dolfin_assert(_matA);
PETScVector& xx = x.down_cast<PETScVector>();
if (size(1) != size(0) || size(0) != xx.size())
{
dolfin_error("PETScMatrix.cpp",
"get diagonal of a PETSc matrix",
"Matrix and vector dimensions don't match for
matrix-vector set");
}
PetscErrorCode ierr = MatGetDiagonal(_matA, xx.vec());
if (ierr != 0) petsc_error(ierr, __FILE__, "MatGetDiagonal");
xx.update_ghost_values();
}
2) Usage:
u = Function(V);
A.get_diagonal(u.vector());
Marco
Garth
Thanks,
Marco
_______________________________________________
fenics mailing list
[email protected]
http://fenicsproject.org/mailman/listinfo/fenics
.
_______________________________________________
fenics mailing list
[email protected]
http://fenicsproject.org/mailman/listinfo/fenics