Skip to content

Commit

Permalink
Merge pull request #2459 from boutproject/master-beuler-backport
Browse files Browse the repository at this point in the history
Back-port beuler/snes improvements to master
  • Loading branch information
ZedThree authored Jan 12, 2022
2 parents 66206b8 + 149877d commit ecced94
Show file tree
Hide file tree
Showing 8 changed files with 775 additions and 80 deletions.
7 changes: 7 additions & 0 deletions include/bout/petsclib.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public:
/// was passed to the constructor.
void setOptionsFromInputFile(KSP& ksp);

/// Set options for a SNES linear solver that uses the options specific to this PetscLib,
/// by setting an options prefix for the SNES, and adding that prefix to all the options
/// set in the [petsc] section, or [petsc] subsection of the options, if non-null 'opt'
/// was passed to the constructor.
void setOptionsFromInputFile(SNES& snes);

/*!
* Force cleanup. This will call PetscFinalize, printing a warning
* if any instances of PetscLib still exist
Expand Down Expand Up @@ -132,6 +138,7 @@ public:
static void setArgs(int &UNUSED(c), char** &UNUSED(v)) {}

void setOptionsFromInputFile(KSP& UNUSED(ksp)) {}
void setOptionsFromInputFile(SNES& UNUSED(snes)) {}

static void cleanup() {}
};
Expand Down
3 changes: 1 addition & 2 deletions src/invert/laplace/impls/petsc/petsc_laplace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
#define KSP_BICG "bicg"
#define KSP_PREONLY "preonly"

#undef __FUNCT__
#define __FUNCT__ "laplacePCapply"

static PetscErrorCode laplacePCapply(PC pc,Vec x,Vec y) {
int ierr;

Expand Down
3 changes: 1 addition & 2 deletions src/invert/laplacexy/laplacexy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

#include <cmath>

#undef __FUNCT__
#define __FUNCT__ "laplacePCapply"

static PetscErrorCode laplacePCapply(PC pc,Vec x,Vec y) {
int ierr;

Expand Down
8 changes: 0 additions & 8 deletions src/solver/impls/imex-bdf2/imex-bdf2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ IMEXBDF2::~IMEXBDF2() {
* This function assumes the context void pointer is a pointer
* to an IMEXBDF2 object.
*/
#undef __FUNCT__
#define __FUNCT__ "FormFunction"
static PetscErrorCode FormFunction(SNES UNUSED(snes), Vec x, Vec f, void *ctx) {
return static_cast<IMEXBDF2 *>(ctx)->snes_function(x, f, false);
}
Expand All @@ -51,8 +49,6 @@ static PetscErrorCode FormFunction(SNES UNUSED(snes), Vec x, Vec f, void *ctx) {
*
* This function can be a linearised form of FormFunction
*/
#undef __FUNCT__
#define __FUNCT__ "FormFunctionForDifferencing"
static PetscErrorCode FormFunctionForDifferencing(void* ctx, Vec x, Vec f) {
return static_cast<IMEXBDF2*>(ctx)->snes_function(x, f, true);
}
Expand All @@ -62,15 +58,11 @@ static PetscErrorCode FormFunctionForDifferencing(void* ctx, Vec x, Vec f) {
*
* This can be a linearised and simplified form of FormFunction
*/
#undef __FUNCT__
#define __FUNCT__ "FormFunctionForColoring"
static PetscErrorCode FormFunctionForColoring(SNES UNUSED(snes), Vec x, Vec f,
void *ctx) {
return static_cast<IMEXBDF2 *>(ctx)->snes_function(x, f, true);
}

#undef __FUNCT__
#define __FUNCT__ "imexbdf2PCapply"
static PetscErrorCode imexbdf2PCapply(PC pc,Vec x,Vec y) {
int ierr;

Expand Down
22 changes: 1 addition & 21 deletions src/solver/impls/petsc/petsc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,7 @@ PetscErrorCode PetscSolver::jac(Vec x, Vec y) {
/**************************************************************************
* Static functions which can be used for PETSc callbacks
**************************************************************************/
#undef __FUNCT__
#define __FUNCT__ "solver_f"

PetscErrorCode solver_f(TS ts, BoutReal t, Vec globalin, Vec globalout, void *f_data) {
PetscFunctionBegin;
auto* s = static_cast<PetscSolver*>(f_data);
Expand All @@ -643,8 +642,6 @@ PetscErrorCode solver_f(TS ts, BoutReal t, Vec globalin, Vec globalout, void *f_
/*
FormIFunction = Udot - RHSFunction
*/
#undef __FUNCT__
#define __FUNCT__ "solver_if"
PetscErrorCode solver_if(TS ts, BoutReal t, Vec globalin,Vec globalindot, Vec globalout, void *f_data) {
PetscErrorCode ierr;

Expand All @@ -655,8 +652,6 @@ PetscErrorCode solver_if(TS ts, BoutReal t, Vec globalin,Vec globalindot, Vec gl
PetscFunctionReturn(0);
}

#undef __FUNCT__
#define __FUNCT__ "solver_rhsjacobian"
#if PETSC_VERSION_GE(3,5,0)
PetscErrorCode solver_rhsjacobian(TS UNUSED(ts), BoutReal UNUSED(t), Vec UNUSED(globalin),
Mat J, Mat Jpre, void *UNUSED(f_data)) {
Expand Down Expand Up @@ -692,8 +687,6 @@ PetscErrorCode solver_rhsjacobian(MAYBE_UNUSED(TS ts), MAYBE_UNUSED(BoutReal t),
/*
solver_ijacobian - Compute IJacobian = dF/dU + a dF/dUdot - a dummy matrix used for pc=none
*/
#undef __FUNCT__
#define __FUNCT__ "solver_ijacobian"
#if PETSC_VERSION_GE(3,5,0)
PetscErrorCode solver_ijacobian(TS ts, BoutReal t, Vec globalin, Vec UNUSED(globalindot),
PetscReal a, Mat J, Mat Jpre, void *f_data) {
Expand Down Expand Up @@ -740,8 +733,6 @@ PetscErrorCode solver_ijacobian(TS ts, BoutReal t, Vec globalin,
/*
solver_ijacobianfd - Compute IJacobian = dF/dU + a dF/dUdot using finite deference - not implemented yet
*/
#undef __FUNCT__
#define __FUNCT__ "solver_ijacobianfd"
#if PETSC_VERSION_GE(3,5,0)
PetscErrorCode solver_ijacobianfd(TS ts, BoutReal t, Vec globalin,
Vec UNUSED(globalindot), PetscReal UNUSED(a), Mat J, Mat Jpre,
Expand All @@ -765,8 +756,6 @@ PetscErrorCode solver_ijacobianfd(TS ts,BoutReal t,Vec globalin,Vec globalindot,
#endif
//-----------------------------------------

#undef __FUNCT__
#define __FUNCT__ "PhysicsSNESApply"
PetscErrorCode PhysicsSNESApply(SNES snes, Vec x) {
PetscErrorCode ierr;
Vec F,Fout;
Expand Down Expand Up @@ -809,9 +798,6 @@ PetscErrorCode PhysicsSNESApply(SNES snes, Vec x) {
PetscFunctionReturn(0);
}


#undef __FUNCT__
#define __FUNCT__ "PhysicsPCApply"
PetscErrorCode PhysicsPCApply(PC pc,Vec x,Vec y) {
int ierr;

Expand All @@ -822,17 +808,13 @@ PetscErrorCode PhysicsPCApply(PC pc,Vec x,Vec y) {
PetscFunctionReturn(s->pre(pc, x, y));
}

#undef __FUNCT__
#define __FUNCT__ "PhysicsJacobianApply"
PetscErrorCode PhysicsJacobianApply(Mat J, Vec x, Vec y) {
// Get the context
PetscSolver *s;
int ierr = MatShellGetContext(J, (void**)&s); CHKERRQ(ierr);
PetscFunctionReturn(s->jac(x, y));
}

#undef __FUNCT__
#define __FUNCT__ "PetscMonitor"
PetscErrorCode PetscMonitor(TS ts, PetscInt UNUSED(step), PetscReal t, Vec X, void *ctx) {
PetscErrorCode ierr;
auto* s = static_cast<PetscSolver*>(ctx);
Expand Down Expand Up @@ -874,8 +856,6 @@ PetscErrorCode PetscMonitor(TS ts, PetscInt UNUSED(step), PetscReal t, Vec X, vo
PetscFunctionReturn(0);
}

#undef __FUNCT__
#define __FUNCT__ "PetscSNESMonitor"
PetscErrorCode PetscSNESMonitor(SNES snes, PetscInt its, PetscReal norm, void *ctx)
{
PetscErrorCode ierr;
Expand Down
Loading

0 comments on commit ecced94

Please sign in to comment.