aboutsummaryrefslogtreecommitdiff
path: root/src/petsc_flat_solver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/petsc_flat_solver.c')
-rw-r--r--src/petsc_flat_solver.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/petsc_flat_solver.c b/src/petsc_flat_solver.c
index 0a8ec9e..5f5172d 100644
--- a/src/petsc_flat_solver.c
+++ b/src/petsc_flat_solver.c
@@ -8,14 +8,19 @@
@version $Header$
@@*/
-#include "cctk.h"
+#include <stdlib.h>
+#include "cctk.h"
#include "cctk_CommandLine.h"
-
#include "cctk_Parameters.h"
-#include "mpi.h"
+#include "petscversion.h"
+#if PETSC_VERSION_MAJOR < 2 || (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 0)
+#include "sles.h"
+#else
#include "petscsles.h"
+#endif
+
#include "ellpetsc.h"
#include "CactusPUGH/PUGH/src/include/pugh.h"
@@ -46,8 +51,10 @@ static Mat *A; /* linear system matrix */
static Vec soln, b; /* approx solution, RHS */
static SLES sles; /* linear solver context */
+int petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
+ int *AbsTol, int *RelTol);
-void petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
+int petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
int *AbsTol, int *RelTol)
{
@@ -78,7 +85,7 @@ void petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
pConnectivity *pCon;
/* Tolerances */
- CCTK_REAL rtol, atol, tolerance;
+ CCTK_REAL rtol=0, atolerance=0, tolerance;
/* Values to assemble the matrix */
CCTK_REAL *values;
@@ -106,6 +113,8 @@ void petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
/* flags to signal if storage is ON or OFF (used/not-used) for M/N*/
int Mstorage=0, Nstorage=0;
+ RelTol = RelTol;
+
octant = CCTK_Equals(domain,"octant");
verbose = CCTK_Equals(petsc_verbose,"yes")||
CCTK_Equals(petsc_verbose,"debug");
@@ -247,7 +256,7 @@ void petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
/* So now each point has a unique index of its own. If we
do a sync that means each processor knows the indiced
in the ghost zones (eg, on its neighbors) in a FD stencil of 1 */
- retcode = PUGH_SyncGroup(GH,"ellpetsc::petscworkspace");
+ retcode = CCTK_SyncGroup(GH,"ellpetsc::petscworkspace");
if (retcode<0)
{
CCTK_WARN(1,"Synchronization failed");
@@ -567,17 +576,17 @@ void petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
if (PetscTolStyle == ELLCONV_ABSOLUTE)
{
rtol = 1.0e-15;
- atol = tolerance;
+ atolerance = tolerance;
}
else if (PetscTolStyle == ELLCONV_RELATIVE)
{
rtol = tolerance;
- atol = 1.0e-15;
+ atolerance = 1.0e-15;
}
else if (PetscTolStyle == ELLCONV_EITHER)
{
rtol = tolerance;
- atol = tolerance;
+ atolerance = tolerance;
}
else
{
@@ -585,14 +594,18 @@ void petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
PetscTolStyle);
}
- ierr = KSPSetTolerances(ksp, rtol, atol, PETSC_DEFAULT, PETSC_DEFAULT);
+ ierr = KSPSetTolerances(ksp, rtol, atolerance, PETSC_DEFAULT, PETSC_DEFAULT);
CHKERRQ(ierr);
if (verbose)
{
CCTK_INFO("KSPSetInitialGuess");
}
+#if PETSC_VERSION_MAJOR < 2 || (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 0)
ierr = KSPSetInitialGuessNonzero(ksp);
+#else
+ ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
+#endif
CHKERRQ(ierr);
/*
@@ -653,7 +666,7 @@ void petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
VecRestoreArray(soln,&values);
- PUGH_SyncGroup(GH,"ellpetsc::petscworkspace");
+ CCTK_SyncGroup(GH,"ellpetsc::petscworkspace");
/* And finally free up the matrix memory */
/*$ierr = MatReleaseValuesMemory(A); CHKERRQ(ierr);$*/
@@ -676,6 +689,7 @@ void petsc_flat(cGH *GH, int FieldIndex, int MIndex, int NIndex,
CCTK_INFO("LEAVING ELLPETSC");
}
+ return (0);
}