xref: /petsc/src/ksp/pc/impls/spai/dspai.c (revision ce94432eddcd14845bc7e8083b7f8ea723b9bf7d)
101a81e61SBarry Smith 
2c6db04a5SJed Brown #include <petscmat.h>
3afcb2eb5SJed Brown #include <petsc-private/petscimpl.h>
401a81e61SBarry Smith 
501a81e61SBarry Smith /*
601a81e61SBarry Smith      MatDumpSPAI - Dumps a PETSc matrix to a file in an ASCII format
701a81e61SBarry Smith   suitable for the SPAI code of Stephen Barnard to solve. This routine
801a81e61SBarry Smith   is simply here to allow testing of matrices directly with the SPAI
901a81e61SBarry Smith   code, rather then through the PETSc interface.
1001a81e61SBarry Smith 
1101a81e61SBarry Smith */
127087cfbeSBarry Smith PetscErrorCode  MatDumpSPAI(Mat A,FILE *file)
1301a81e61SBarry Smith {
1401a81e61SBarry Smith   const PetscScalar *vals;
1501a81e61SBarry Smith   PetscErrorCode    ierr;
1601a81e61SBarry Smith   int               i,j,n,size,nz;
1701a81e61SBarry Smith   const int         *cols;
1801a81e61SBarry Smith   MPI_Comm          comm;
1901a81e61SBarry Smith 
2001a81e61SBarry Smith   PetscObjectGetComm((PetscObject)A,&comm);
2101a81e61SBarry Smith 
2201a81e61SBarry Smith   MPI_Comm_size(comm,&size);
23*ce94432eSBarry Smith   if (size > 1) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_SUP,"Only single processor dumps");
2401a81e61SBarry Smith 
2501a81e61SBarry Smith   ierr = MatGetSize(A,&n,&n);CHKERRQ(ierr);
2601a81e61SBarry Smith 
2701a81e61SBarry Smith   /* print the matrix */
2801a81e61SBarry Smith   fprintf(file,"%d\n",n);
2901a81e61SBarry Smith   for (i=0; i<n; i++) {
3001a81e61SBarry Smith     ierr = MatGetRow(A,i,&nz,&cols,&vals);CHKERRQ(ierr);
312fa5cd67SKarl Rupp     for (j=0; j<nz; j++) fprintf(file,"%d %d %16.14e\n",i+1,cols[j]+1,vals[j]);
3201a81e61SBarry Smith     ierr = MatRestoreRow(A,i,&nz,&cols,&vals);CHKERRQ(ierr);
3301a81e61SBarry Smith   }
3401a81e61SBarry Smith   PetscFunctionReturn(0);
3501a81e61SBarry Smith }
3601a81e61SBarry Smith 
377087cfbeSBarry Smith PetscErrorCode  VecDumpSPAI(Vec b,FILE *file)
3801a81e61SBarry Smith {
3901a81e61SBarry Smith   PetscErrorCode ierr;
4001a81e61SBarry Smith   int            n,i;
4101a81e61SBarry Smith   PetscScalar    *array;
4201a81e61SBarry Smith 
4301a81e61SBarry Smith   ierr = VecGetSize(b,&n);CHKERRQ(ierr);
4401a81e61SBarry Smith   ierr = VecGetArray(b,&array);CHKERRQ(ierr);
4501a81e61SBarry Smith 
4601a81e61SBarry Smith   fprintf(file,"%d\n",n);
472fa5cd67SKarl Rupp   for (i=0; i<n; i++) fprintf(file,"%d %16.14e\n",i+1,array[i]);
4801a81e61SBarry Smith   PetscFunctionReturn(0);
4901a81e61SBarry Smith }
50