Skip to content
Snippets Groups Projects
Commit b61bab96 authored by stefano zampini's avatar stefano zampini Committed by Mark OLESEN
Browse files

Support older versions of PETSc

parent 90134581
Branches
Tags v2012
1 merge request!8Support for fast GPU matrix assembly
...@@ -263,38 +263,42 @@ Foam::solverPerformance Foam::petscSolver::scalarSolve ...@@ -263,38 +263,42 @@ Foam::solverPerformance Foam::petscSolver::scalarSolve
} }
// Convergence testing // Convergence testing
if (usePetscResidualNorm) if (firsttimein)
{
// Add monitor to record initial residual computed by PETSc
KSPMonitorSet
(
ksp,
PetscUtils::foamKSPMonitorRecordInit,
&ctx,
NULL
);
}
else
{ {
KSPSetConvergenceTest if (usePetscResidualNorm)
( {
ksp, // Add monitor to record initial residual computed by PETSc
PetscUtils::foamKSPConverge, KSPMonitorSet
&ctx, (
NULL ksp,
); PetscUtils::foamKSPMonitorRecordInit,
} &ctx,
NULL
);
}
else
{
ctx.useFoamTest = true;
KSPSetConvergenceTest
(
ksp,
PetscUtils::foamKSPConverge,
&ctx,
NULL
);
}
// Monitoring (print to stdout) residual reduction in OpenFOAM norm // Monitoring (print to stdout) residual reduction in OpenFOAM norm
if (monitorFoamResidualNorm) if (monitorFoamResidualNorm)
{ {
KSPMonitorSet KSPMonitorSet
( (
ksp, ksp,
PetscUtils::foamKSPMonitorFoam, PetscUtils::foamKSPMonitorFoam,
&ctx, &ctx,
NULL NULL
); );
}
} }
// Geometric multigrid support // Geometric multigrid support
......
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
Mat Amat; Mat Amat;
KSP ksp; KSP ksp;
// Auxiliary vectors for the OpenFOAM-PETSc L1-norm bool useFoamTest;
Vec ArowsSum; Vec ArowsSum;
Vec *res_l1_w; Vec *res_l1_w;
...@@ -95,6 +95,7 @@ public: ...@@ -95,6 +95,7 @@ public:
init_aux_vectors_(false), init_aux_vectors_(false),
Amat(nullptr), Amat(nullptr),
ksp(nullptr), ksp(nullptr),
useFoamTest(false),
ArowsSum(nullptr), ArowsSum(nullptr),
res_l1_w(nullptr) res_l1_w(nullptr)
{} {}
......
...@@ -160,12 +160,10 @@ PetscErrorCode Foam::PetscUtils::foamKSPMonitorFoam ...@@ -160,12 +160,10 @@ PetscErrorCode Foam::PetscUtils::foamKSPMonitorFoam
if (ntype != KSP_NORM_NONE) // Print both norms, KSP built-in and OpenFOAM built-in if (ntype != KSP_NORM_NONE) // Print both norms, KSP built-in and OpenFOAM built-in
{ {
char normtype[256]; char normtype[256];
PetscErrorCode (*converge)(KSP,PetscInt,PetscReal,KSPConvergedReason*,void*);
ierr = PetscStrncpy(normtype,KSPNormTypes[ntype],sizeof(normtype));CHKERRQ(ierr); ierr = PetscStrncpy(normtype,KSPNormTypes[ntype],sizeof(normtype));CHKERRQ(ierr);
ierr = PetscStrtolower(normtype);CHKERRQ(ierr); ierr = PetscStrtolower(normtype);CHKERRQ(ierr);
ierr = KSPGetConvergenceTest(ksp, &converge, NULL, NULL);CHKERRQ(ierr); if (ctx->useFoamTest) // we are using foam convergence testing, list foam norm first
if (converge == Foam::PetscUtils::foamKSPConverge) // we are using foam convergence testing, list foam norm first
{ {
ierr = PetscViewerASCIIPrintf(viewer, "%3D KSP Residual foam norm %14.12e (PETSc %s norm %14.12e)\n", it, (double)fnorm, normtype, (double)rnorm);CHKERRQ(ierr); ierr = PetscViewerASCIIPrintf(viewer, "%3D KSP Residual foam norm %14.12e (PETSc %s norm %14.12e)\n", it, (double)fnorm, normtype, (double)rnorm);CHKERRQ(ierr);
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment