#include <PetscSolver.H>
Public Member Functions | |
PetscSolver () | |
virtual | ~PetscSolver () |
void | destroy () |
virtual void | setHomogeneous (bool a_homogeneous) |
virtual void | setFunctionAndJacobian (PetscErrorCode(*f)(SNES, Vec, Vec, void *), PetscErrorCode(*j)(SNES, Vec, Mat *, Mat *, MatStructure *, void *)) |
virtual void | define (Real a_dx, bool a_homogeneous=true) |
virtual void | define (LinearOp< T > *, bool a_homogeneous=true) |
virtual void | solve (T &a_phi, const T &a_rhs) |
int | solve_private (T &a_phi, const T &a_rhs) |
virtual void | solve_mfree (T &a_phi, const T &a_rhs, LinearOp< T > *a_op) |
int | solve_mfree_private (T &a_phi, const T &a_rhs, LinearOp< T > *a_op) |
Real | computeResidual () |
virtual int | applyOp (T &a_phi, const T &a_rhs) |
void | setInitialGuessNonzero (bool b=true) |
void | setOptionsPrefix (const char prefix[]) |
KSP | getKSP () |
virtual int | getNNZPerRow () const |
virtual bool | supportNNZExact () const |
virtual void | rhsOperation (const T &a_rhs) |
virtual Real | addBCdiagValue (const IntVect &a_iv, const IntVect &a_jv, const T &a_rhs, const DataIndex &a_datInd, const Real coeff=1) |
int | resetOperator () |
Real | normInfinity (const T &a_phi) const |
int | setup_solver (const T &a_phi) |
int | create_mat_vec (const T &a_phi) |
PetscErrorCode | putPetscInChombo (T &a_phi, const Vec xx) |
PetscErrorCode | putChomboInPetsc (Vec out, const T &a_phi) |
virtual int | formMatrix (Mat, const T *=0, PetscInt my0=0, PetscInt nloc=0, PetscInt *d=0, PetscInt *o=0)=0 |
virtual BaseFab< Real > & | getRegFab (T &a_fab, const DataIndex &a_datInd)=0 |
virtual const BaseFab< Real > & | getRegFab (const T &a_fab, const DataIndex &a_datInd) const =0 |
virtual const BaseFab< Real > & | getRegFab (const T &a_fab, const DataIndex &a_datInd, Box &a_box) const =0 |
void | setNull (bool n=true) |
Static Public Member Functions | |
static PetscErrorCode | ksp_monitor_pout (KSP ksp, PetscInt it, PetscReal rnorm, void *ctx) |
static PetscErrorCode | apply_mfree (Mat A, Vec x, Vec f) |
Public Attributes | |
LinearOp< T > * | m_op_mfree |
T | m_phi_mfree |
T | m_Lphi_mfree |
bool | m_mfree_homogeneous |
bool | m_homogeneous |
Real | m_dx |
Mat | m_mat |
void * | m_ctx |
Vec | m_xx |
Vec | m_rr |
Vec | m_bb |
SNES | m_snes |
KSP | m_ksp |
LevelData< BaseFab< PetscInt > > | m_gids |
PetscInt | m_gid0 |
Protected Member Functions | |
virtual Real | addBCrhsValue (const IntVect &a_iv, const T &a_phi, const DataIndex &a_datInd, const Real &coeff=1) |
Protected Attributes | |
PetscInt | m_defined |
PetscErrorCode(* | m_function )(SNES, Vec, Vec, void *) |
PetscErrorCode(* | m_jacobian )(SNES, Vec, Mat *, Mat *, MatStructure *, void *) |
char | m_prestring [32] |
bool | m_null |
bool | m_nz_init_guess |
LevelData< BaseFab< bool > > | m_bccode |
PetscSolver< T >::PetscSolver | ( | ) | [inline] |
References PetscSolver< T >::m_dx, and PetscSolver< T >::m_prestring.
PetscSolver< T >::~PetscSolver | ( | ) | [inline, virtual] |
References PetscSolver< T >::destroy().
void PetscSolver< T >::destroy | ( | ) | [inline] |
virtual void PetscSolver< T >::setHomogeneous | ( | bool | a_homogeneous | ) | [inline, virtual] |
Set whether the solver uses only homogeneous boundary conditions
Implements LinearSolver< T >.
virtual void PetscSolver< T >::setFunctionAndJacobian | ( | PetscErrorCode(*)(SNES, Vec, Vec, void *) | f, | |
PetscErrorCode(*)(SNES, Vec, Mat *, Mat *, MatStructure *, void *) | j | |||
) | [inline, virtual] |
Set Function F(u) = 0 and Jacobian dF(u)/du for nonlinear solves
static PetscErrorCode PetscSolver< T >::ksp_monitor_pout | ( | KSP | ksp, | |
PetscInt | it, | |||
PetscReal | rnorm, | |||
void * | ctx | |||
) | [inline, static] |
Referenced by PetscSolver< T >::setup_solver(), and PetscSolver< T >::solve_mfree_private().
void PetscSolver< T >::define | ( | Real | a_dx, | |
bool | a_homogeneous = true | |||
) | [inline, virtual] |
Reimplemented in PetscSolverPoisson< T >.
References CH_assert, PetscSolver< T >::m_dx, and PetscSolver< T >::m_homogeneous.
Referenced by PetscSolver< T >::define(), and PetscSolverPoisson< T >::define().
void PetscSolver< T >::define | ( | LinearOp< T > * | a_operator, | |
bool | a_homogeneous = true | |||
) | [inline, virtual] |
Define the operator and whether it is a homogeneous solver or not. The LinearSolver does not take over ownership of this a_operator object. It does not call delete on it when the LinearSolver is deleted. It is meant to be like a late-binding reference. If you created a_operator with new, you should call delete on it after LinearSolver is deleted if you want to avoid memory leaks.
Implements LinearSolver< T >.
Reimplemented in PetscSolverPoisson< T >.
References PetscSolver< T >::define(), and LinearOp< T >::dx().
void PetscSolver< T >::solve | ( | T & | a_phi, | |
const T & | a_rhs | |||
) | [inline, virtual] |
int PetscSolver< T >::solve_private | ( | T & | a_phi, | |
const T & | a_rhs | |||
) | [inline] |
References PetscSolver< T >::addBCrhsValue(), BaseFabRealSetVal, BoxIterator::begin(), CH_assert, CH_START, CH_STOP, CH_TIMER, CH_TIMERS, BoxLayout::get(), PetscSolver< T >::getRegFab(), PetscSolver< T >::m_bb, PetscSolver< T >::m_dx, PetscSolver< T >::m_gids, PetscSolver< T >::m_ksp, PetscSolver< T >::m_mat, PetscSolver< T >::m_null, PetscSolver< T >::m_snes, PetscSolver< T >::m_xx, BoxIterator::next(), BoxIterator::ok(), PetscSolver< T >::putPetscInChombo(), PetscSolver< T >::setup_solver(), and DataIterator::size().
Referenced by PetscSolver< T >::solve().
void PetscSolver< T >::solve_mfree | ( | T & | a_phi, | |
const T & | a_rhs, | |||
LinearOp< T > * | a_op | |||
) | [inline, virtual] |
Solve a_op*a_phi = a_rhs using the PETSC matrix free functions The preconditioner (for which a matrix is formed) need not be the same as the actual operator.
References PetscSolver< T >::solve_mfree_private().
int PetscSolver< T >::solve_mfree_private | ( | T & | a_phi, | |
const T & | a_rhs, | |||
LinearOp< T > * | a_op | |||
) | [inline] |
References PetscSolver< T >::addBCrhsValue(), PetscSolver< T >::apply_mfree(), BaseFabRealSetVal, BoxIterator::begin(), CH_assert, CH_SPACEDIM, CH_TIME, LinearOp< T >::clear(), LinearOp< T >::create(), BoxLayout::get(), PetscSolver< T >::getRegFab(), PetscSolver< T >::ksp_monitor_pout(), M, PetscSolver< T >::m_bb, PetscSolver< T >::m_dx, PetscSolver< T >::m_gids, PetscSolver< T >::m_ksp, PetscSolver< T >::m_Lphi_mfree, PetscSolver< T >::m_mat, PetscSolver< T >::m_nz_init_guess, PetscSolver< T >::m_op_mfree, PetscSolver< T >::m_phi_mfree, PetscSolver< T >::m_prestring, PetscSolver< T >::m_xx, N, BoxIterator::next(), LayoutIterator::ok(), BoxIterator::ok(), PetscSolver< T >::putPetscInChombo(), PetscSolver< T >::setup_solver(), and DataIterator::size().
Referenced by PetscSolver< T >::solve_mfree().
PetscErrorCode PetscSolver< T >::apply_mfree | ( | Mat | A, | |
Vec | x, | |||
Vec | f | |||
) | [inline, static] |
Real PetscSolver< T >::computeResidual | ( | ) | [inline] |
int PetscSolver< T >::applyOp | ( | T & | a_phi, | |
const T & | a_rhs | |||
) | [inline, virtual] |
void PetscSolver< T >::setInitialGuessNonzero | ( | bool | b = true |
) | [inline] |
set initial guess non-zero
void PetscSolver< T >::setOptionsPrefix | ( | const char | prefix[] | ) | [inline] |
set initial guess non-zero
KSP PetscSolver< T >::getKSP | ( | ) | [inline] |
virtual int PetscSolver< T >::getNNZPerRow | ( | ) | const [inline, virtual] |
get an estimate of the number of nnz/row for matrix allocation
Reimplemented in PetscSolverViscousTensor< T >.
Referenced by PetscSolver< T >::create_mat_vec().
virtual bool PetscSolver< T >::supportNNZExact | ( | ) | const [inline, virtual] |
do I support having formMatrix precompute exact NNZ/row
Referenced by PetscSolver< T >::create_mat_vec().
virtual void PetscSolver< T >::rhsOperation | ( | const T & | a_rhs | ) | [inline, virtual] |
virtual Real PetscSolver< T >::addBCdiagValue | ( | const IntVect & | a_iv, | |
const IntVect & | a_jv, | |||
const T & | a_rhs, | |||
const DataIndex & | a_datInd, | |||
const Real | coeff = 1 | |||
) | [inline, virtual] |
handling boundary conditions, turn it into a term to be added to the diag term this function coordinates with addBCrhsValue for Dirichlet BC for Neumann BC no RHS modification is required
int PetscSolver< T >::resetOperator | ( | ) | [inline] |
Real PetscSolver< T >::normInfinity | ( | const T & | a_phi | ) | const [inline] |
Infinity norm
References PetscSolver< T >::m_rr, norm(), and PetscSolver< T >::putPetscInChombo().
virtual Real PetscSolver< T >::addBCrhsValue | ( | const IntVect & | a_iv, | |
const T & | a_phi, | |||
const DataIndex & | a_datInd, | |||
const Real & | coeff = 1 | |||
) | [inline, protected, virtual] |
handling boundary conditions, turn it into a term to be added to the RHS this function coordinates with addBCdiagValue for Dirichlet BC, should return a term that is to be added to RHS
Referenced by PetscSolver< T >::putChomboInPetsc(), PetscSolver< T >::solve_mfree_private(), and PetscSolver< T >::solve_private().
int PetscSolver< T >::setup_solver | ( | const T & | a_phi | ) | [inline] |
References BoxIterator::begin(), CH_assert, CH_SPACEDIM, CH_START, CH_STOP, CH_TIMER, CH_TIMERS, PetscSolver< T >::create_mat_vec(), PetscSolver< T >::formMatrix(), PetscSolver< T >::ksp_monitor_pout(), PetscSolver< T >::m_defined, PetscSolver< T >::m_function, PetscSolver< T >::m_jacobian, PetscSolver< T >::m_ksp, PetscSolver< T >::m_mat, PetscSolver< T >::m_nz_init_guess, PetscSolver< T >::m_prestring, PetscSolver< T >::m_rr, PetscSolver< T >::m_snes, BoxIterator::next(), BoxIterator::ok(), and LayoutIterator::ok().
Referenced by PetscSolver< T >::solve_mfree_private(), and PetscSolver< T >::solve_private().
int PetscSolver< T >::create_mat_vec | ( | const T & | a_phi | ) | [inline] |
References BoxIterator::begin(), CH_assert, CH_TIME, LevelData< T >::define(), MayDay::Error(), LevelData< T >::exchange(), PetscSolver< T >::formMatrix(), BoxLayout::get(), PetscSolver< T >::getNNZPerRow(), PetscSolver< T >::m_bb, PetscSolver< T >::m_bccode, PetscSolver< T >::m_defined, PetscSolver< T >::m_gid0, PetscSolver< T >::m_gids, PetscSolver< T >::m_mat, PetscSolver< T >::m_rr, PetscSolver< T >::m_xx, BoxIterator::next(), Box::numPts(), BoxIterator::ok(), LayoutIterator::ok(), BaseFab< T >::setVal(), PetscSolver< T >::supportNNZExact(), and IntVect::Zero.
Referenced by PetscSolver< T >::applyOp(), and PetscSolver< T >::setup_solver().
PetscErrorCode PetscSolver< T >::putPetscInChombo | ( | T & | a_phi, | |
const Vec | xx | |||
) | [inline] |
References BoxIterator::begin(), BoxLayout::get(), PetscSolver< T >::getRegFab(), PetscSolver< T >::m_gid0, PetscSolver< T >::m_gids, BoxIterator::next(), BoxIterator::ok(), and DataIterator::size().
Referenced by PetscSolver< T >::apply_mfree(), PetscSolver< T >::applyOp(), PetscSolver< T >::computeResidual(), PetscSolver< T >::normInfinity(), PetscSolver< T >::solve_mfree_private(), and PetscSolver< T >::solve_private().
PetscErrorCode PetscSolver< T >::putChomboInPetsc | ( | Vec | out, | |
const T & | a_phi | |||
) | [inline] |
References PetscSolver< T >::addBCrhsValue(), BoxIterator::begin(), CH_TIME, BoxLayout::get(), PetscSolver< T >::getRegFab(), PetscSolver< T >::m_dx, PetscSolver< T >::m_gids, BoxIterator::next(), BoxIterator::ok(), and DataIterator::size().
Referenced by PetscSolver< T >::apply_mfree(), and PetscSolver< T >::applyOp().
virtual int PetscSolver< T >::formMatrix | ( | Mat | , | |
const T * | = 0 , |
|||
PetscInt | my0 = 0 , |
|||
PetscInt | nloc = 0 , |
|||
PetscInt * | d = 0 , |
|||
PetscInt * | o = 0 | |||
) | [pure virtual] |
Implemented in PetscSolverViscousTensor< T >.
Referenced by PetscSolver< T >::create_mat_vec(), and PetscSolver< T >::setup_solver().
virtual BaseFab<Real>& PetscSolver< T >::getRegFab | ( | T & | a_fab, | |
const DataIndex & | a_datInd | |||
) | [pure virtual] |
virtual const BaseFab<Real>& PetscSolver< T >::getRegFab | ( | const T & | a_fab, | |
const DataIndex & | a_datInd | |||
) | const [pure virtual] |
Implemented in PetscSolverFAB< LevelData< FArrayBox > >.
virtual const BaseFab<Real>& PetscSolver< T >::getRegFab | ( | const T & | a_fab, | |
const DataIndex & | a_datInd, | |||
Box & | a_box | |||
) | const [pure virtual] |
Implemented in PetscSolverFAB< LevelData< FArrayBox > >.
void PetscSolver< T >::setNull | ( | bool | n = true |
) | [inline] |
References CH_assert, and PetscSolver< T >::m_null.
LinearOp<T>* PetscSolver< T >::m_op_mfree |
Referenced by PetscSolver< T >::apply_mfree(), and PetscSolver< T >::solve_mfree_private().
T PetscSolver< T >::m_phi_mfree |
Referenced by PetscSolver< T >::apply_mfree(), and PetscSolver< T >::solve_mfree_private().
T PetscSolver< T >::m_Lphi_mfree |
Referenced by PetscSolver< T >::apply_mfree(), and PetscSolver< T >::solve_mfree_private().
bool PetscSolver< T >::m_mfree_homogeneous |
bool PetscSolver< T >::m_homogeneous |
public member data: whether or not to use inhomogeneous boundary conditions.
Referenced by PetscSolver< T >::apply_mfree(), PetscSolver< T >::define(), and PetscSolver< LevelData< FArrayBox > >::setHomogeneous().
Real PetscSolver< T >::m_dx |
member data: grid spacing
Referenced by PetscSolver< T >::define(), PetscSolver< T >::PetscSolver(), PetscSolver< T >::putChomboInPetsc(), PetscSolver< T >::solve_mfree_private(), and PetscSolver< T >::solve_private().
Mat PetscSolver< T >::m_mat |
void* PetscSolver< T >::m_ctx |
Vec PetscSolver< T >::m_xx |
Vec PetscSolver< T >::m_rr |
Vec PetscSolver< T >::m_bb |
SNES PetscSolver< T >::m_snes |
Referenced by PetscSolver< T >::destroy(), PetscSolver< T >::setup_solver(), and PetscSolver< T >::solve_private().
KSP PetscSolver< T >::m_ksp |
PetscInt PetscSolver< T >::m_defined [protected] |
PetscErrorCode(* PetscSolver< T >::m_function)(SNES, Vec, Vec, void *) [protected] |
PetscErrorCode(* PetscSolver< T >::m_jacobian)(SNES, Vec, Mat *, Mat *, MatStructure *, void *) [protected] |
char PetscSolver< T >::m_prestring[32] [protected] |
bool PetscSolver< T >::m_null [protected] |
Referenced by PetscSolver< T >::setNull(), and PetscSolver< T >::solve_private().
bool PetscSolver< T >::m_nz_init_guess [protected] |
LevelData<BaseFab<bool> > PetscSolver< T >::m_bccode [protected] |
Referenced by PetscSolver< T >::create_mat_vec().
LevelData<BaseFab<PetscInt> > PetscSolver< T >::m_gids |
PetscInt PetscSolver< T >::m_gid0 |
Referenced by PetscSolver< T >::create_mat_vec(), and PetscSolver< T >::putPetscInChombo().