~fluidity-core/fluidity/sea-ice-branch

« back to all changes in this revision

Viewing changes to tools/petsc_readnsolve.F90

  • Committer: Simon Mouradian
  • Date: 2012-10-19 10:35:59 UTC
  • mfrom: (3520.32.371 fluidity)
  • Revision ID: simon.mouradian06@imperial.ac.uk-20121019103559-y36qa47phc69q8sc
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
use parallel_tools
40
40
#ifdef HAVE_PETSC_MODULES
41
41
  use petsc 
42
 
#if PETSC_VERSION_MINOR==0
43
 
  use petscvec 
44
 
  use petscmat 
45
 
  use petscksp 
46
 
  use petscpc 
47
 
  use petscis 
48
 
  use petscmg  
49
 
#endif
50
42
#endif
51
43
implicit none
52
44
#ifdef HAVE_PETSC_MODULES
58
50
#include "finclude/petscisdef.h"
59
51
#else
60
52
#include "finclude/petsc.h"
61
 
#if PETSC_VERSION_MINOR==0
62
 
#include "finclude/petscmat.h"
63
 
#include "finclude/petscvec.h"
64
 
#include "finclude/petscviewer.h"
65
 
#include "finclude/petscksp.h"
66
 
#include "finclude/petscpc.h"
67
 
#include "finclude/petscmg.h"
68
 
#include "finclude/petscis.h"
69
 
#include "finclude/petscsys.h"
70
 
#endif
71
53
#endif
72
54
! hack around PetscTruth->PetscBool change in petsc 3.2
73
 
#if PETSC_VERSION_MINOR==2
 
55
#if PETSC_VERSION_MINOR>=2
74
56
#define PetscTruth PetscBool
75
57
#endif
76
58
  ! options read from command-line (-prns_... options)
93
75
  ! read in the matrix equation and init. guess:
94
76
  call PetscViewerBinaryOpen(MPI_COMM_FEMTOOLS, trim(filename), &
95
77
     FILE_MODE_READ, viewer, ierr)
96
 
#if PETSC_VERSION_MINOR==2
 
78
#if PETSC_VERSION_MINOR>=2
97
79
  ! in petsc 3.2 MatLoad and VecLoad do no longer create a new vector
98
80
  call MatCreate(MPI_COMM_FEMTOOLS, matrix, ierr)
99
81
  call VecCreate(MPI_COMM_FEMTOOLS, rhs, ierr)
753
735
    ncomponents=size(petsc_numbering%gnn2unn, 2)
754
736
    allocate(unns(1:n*ncomponents))
755
737
    unns=reshape( petsc_numbering%gnn2unn(1:n,:), (/ n*ncomponents /))
756
 
#if PETSC_VERSION_MINOR==2
 
738
#if PETSC_VERSION_MINOR>=2
757
739
    ! for petsc 3.2 we have an extra PetscCopyMode argument
758
740
    call ISCreateGeneral(MPI_COMM_FEMTOOLS, &
759
741
       size(unns), unns, PETSC_COPY_VALUES, row_indexset, ierr)
764
746
       
765
747
    m=petsc_numbering%universal_length ! global length
766
748
       
767
 
#if PETSC_VERSION_MINOR==0    
768
 
    ! in petsc 3.0 we have to ask for all columns
769
 
    ! so we need to create an index set with all universal node numbers(!)    
770
 
    allocate( allcols(1:m) )
771
 
    allcols=(/ ( i, i=0, m-1) /)
772
 
    call ISCreateGeneral(MPI_COMM_FEMTOOLS, &
773
 
       m, allcols, col_indexset, ierr)
774
 
    call ISSetIdentity(col_indexset, ierr)
775
 
       
776
 
    ! redistribute matrix by asking for owned rows and all columns
777
 
    ! n*components is the number of columns we own
778
 
    call MatGetSubMatrix(matrix, row_indexset, col_indexset, n*ncomponents, &
779
 
       MAT_INITIAL_MATRIX, new_matrix, ierr)
780
 
    call ISDestroy(col_indexset, ierr)
781
 
#else
782
 
    ! in petsc 3.1 we only ask for owned columns (although presumably
 
749
    ! we only ask for owned columns (although presumably
783
750
    ! still all columns of owned rows are stored locally)
784
751
    ! we only deal with square matrices (same d.o.f. for rows and columns)
785
752
    ! in fluidity, so we can simply reuse row_indexset as the col_indexset
786
753
    call MatGetSubMatrix(matrix, row_indexset, row_indexset, &
787
754
       MAT_INITIAL_MATRIX, new_matrix, ierr)
788
 
#endif
 
755
 
789
756
    ! destroy the old read-in matrix and replace by the new one
790
757
    call MatDestroy(matrix, ierr)
791
758
    matrix=new_matrix