My Project
programmer's documentation
Typedefs | Functions
cs_sles_petsc.h File Reference
#include <petscviewer.h>
#include <petscksp.h>
#include "cs_base.h"
#include "cs_halo_perio.h"
#include "cs_matrix.h"
#include "cs_time_plot.h"
Include dependency graph for cs_sles_petsc.h:

Go to the source code of this file.

Typedefs

typedef void() cs_sles_petsc_setup_hook_t(void *context, Mat a, KSP ksp)
 Function pointer for user settings of a PETSc KSP solver setup. More...
 
typedef struct _cs_sles_petsc_t cs_sles_petsc_t
 

Functions

void cs_user_sles_petsc_hook (void *context, Mat a, KSP ksp)
 
static void cs_sles_petsc_init (void)
 
static void cs_sles_petsc_log_setup (KSP ksp)
 
cs_sles_petsc_tcs_sles_petsc_define (int f_id, const char *name, MatType matrix_type, cs_sles_petsc_setup_hook_t *setup_hook, void *context)
 Define and associate a PETSc linear system solver for a given field or equation name. More...
 
cs_sles_petsc_tcs_sles_petsc_create (MatType matrix_type, cs_sles_petsc_setup_hook_t *setup_hook, void *context)
 Create PETSc linear system solver info and context. More...
 
void * cs_sles_petsc_copy (const void *context)
 Create PETSc linear system solver info and context based on existing info and context. More...
 
void cs_sles_petsc_destroy (void **context)
 Destroy PETSc linear system solver info and context. More...
 
void cs_sles_petsc_setup (void *context, const char *name, const cs_matrix_t *a, int verbosity)
 Setup PETSc linear equation solver. More...
 
cs_sles_convergence_state_t cs_sles_petsc_solve (void *context, const char *name, const cs_matrix_t *a, int verbosity, cs_halo_rotation_t rotation_mode, double precision, double r_norm, int *n_iter, double *residue, const cs_real_t *rhs, cs_real_t *vx, size_t aux_size, void *aux_vectors)
 Call PETSc linear equation solver. More...
 
void cs_sles_petsc_free (void *context)
 Free PETSc linear equation solver setup context. More...
 
bool cs_sles_petsc_error_post_and_abort (cs_sles_t *sles, cs_sles_convergence_state_t state, const cs_matrix_t *a, cs_halo_rotation_t rotation_mode, const cs_real_t *rhs, cs_real_t *vx)
 Error handler for PETSc solver. More...
 
void cs_sles_petsc_log (const void *context, cs_log_t log_type)
 Log sparse linear equation solver info. More...
 

Typedef Documentation

◆ cs_sles_petsc_setup_hook_t

cs_sles_petsc_setup_hook_t

Function pointer for user settings of a PETSc KSP solver setup.

This function is called the end of the setup stage for a KSP solver.

Note that using the advanced KSPSetPostSolve and KSPSetPreSolve functions, this also allows setting furthur function pointers for pre and post-solve operations (see the PETSc documentation).

Note: if the context pointer is non-NULL, it must point to valid data when the selection function is called so that value or structure should not be temporary (i.e. local);

Parameters
[in,out]contextpointer to optional (untyped) value or structure
[in,out]ksppointer to PETSc KSP context

◆ cs_sles_petsc_t

typedef struct _cs_sles_petsc_t cs_sles_petsc_t

Function Documentation

◆ cs_sles_petsc_copy()

void* cs_sles_petsc_copy ( const void *  context)

Create PETSc linear system solver info and context based on existing info and context.

Parameters
[in]contextpointer to reference info and context (actual type: cs_sles_petsc_t *)
Returns
pointer to newly created solver info object. (actual type: cs_sles_petsc_t *)

◆ cs_sles_petsc_create()

cs_sles_petsc_t* cs_sles_petsc_create ( MatType  matrix_type,
cs_sles_petsc_setup_hook_t setup_hook,
void *  context 
)

Create PETSc linear system solver info and context.

In case of rotational periodicity for a block (non-scalar) matrix, the matrix type will be forced to MATSHELL ("shell") regardless of the option used.

Parameters
[in]matrix_typePETSc matrix type
[in]setup_hookpointer to optional setup epilogue function
[in,out]contextpointer to optional (untyped) value or structure for setup_hook, or NULL
Returns
pointer to associated linear system object.

◆ cs_sles_petsc_define()

cs_sles_petsc_t* cs_sles_petsc_define ( int  f_id,
const char *  name,
MatType  matrix_type,
cs_sles_petsc_setup_hook_t setup_hook,
void *  context 
)

Define and associate a PETSc linear system solver for a given field or equation name.

If this system did not previously exist, it is added to the list of "known" systems. Otherwise, its definition is replaced by the one defined here.

This is a utility function: if finer control is needed, see cs_sles_define and cs_sles_petsc_create.

In case of rotational periodicity for a block (non-scalar) matrix, the matrix type will be forced to MATSHELL ("shell") regardless of the option used.

Note that this function returns a pointer directly to the iterative solver management structure. This may be used to set further options. If needed, cs_sles_find may be used to obtain a pointer to the matching cs_sles_t container.

Parameters
[in]f_idassociated field id, or < 0
[in]nameassociated name if f_id < 0, or NULL
[in]matrix_typePETSc matrix type
[in]setup_hookpointer to optional setup epilogue function
[in,out]contextpointer to optional (untyped) value or structure for setup_hook, or NULL
Returns
pointer to newly created iterative solver info object.

◆ cs_sles_petsc_destroy()

void cs_sles_petsc_destroy ( void **  context)

Destroy PETSc linear system solver info and context.

Parameters
[in,out]contextpointer to iterative solver info and context (actual type: cs_sles_petsc_t **)

◆ cs_sles_petsc_error_post_and_abort()

bool cs_sles_petsc_error_post_and_abort ( cs_sles_t sles,
cs_sles_convergence_state_t  state,
const cs_matrix_t a,
cs_halo_rotation_t  rotation_mode,
const cs_real_t rhs,
cs_real_t vx 
)

Error handler for PETSc solver.

In case of divergence or breakdown, this error handler outputs an error message It does nothing in case the maximum iteration count is reached.

Parameters
[in,out]slespointer to solver object
[in]stateconvergence state
[in]amatrix
[in]rotation_modehalo update option for rotational periodicity
[in]rhsright hand side
[in,out]vxsystem solution
Returns
false (do not attempt new solve)

◆ cs_sles_petsc_free()

void cs_sles_petsc_free ( void *  context)

Free PETSc linear equation solver setup context.

This function frees resolution-related data, such as buffers and preconditioning but does not free the whole context, as info used for logging (especially performance data) is maintained.

Parameters
[in,out]contextpointer to iterative solver info and context (actual type: cs_sles_petsc_t *)

◆ cs_sles_petsc_init()

static void cs_sles_petsc_init ( void  )
inlinestatic

◆ cs_sles_petsc_log()

void cs_sles_petsc_log ( const void *  context,
cs_log_t  log_type 
)

Log sparse linear equation solver info.

Parameters
[in]contextpointer to iterative solver info and context (actual type: cs_sles_petsc_t *)
[in]log_typelog type

◆ cs_sles_petsc_log_setup()

static void cs_sles_petsc_log_setup ( KSP  ksp)
inlinestatic

◆ cs_sles_petsc_setup()

void cs_sles_petsc_setup ( void *  context,
const char *  name,
const cs_matrix_t a,
int  verbosity 
)

Setup PETSc linear equation solver.

Parameters
[in,out]contextpointer to iterative solver info and context (actual type: cs_sles_petsc_t *)
[in]namepointer to system name
[in]aassociated matrix
[in]verbosityassociated verbosity

◆ cs_sles_petsc_solve()

cs_sles_convergence_state_t cs_sles_petsc_solve ( void *  context,
const char *  name,
const cs_matrix_t a,
int  verbosity,
cs_halo_rotation_t  rotation_mode,
double  precision,
double  r_norm,
int *  n_iter,
double *  residue,
const cs_real_t rhs,
cs_real_t vx,
size_t  aux_size,
void *  aux_vectors 
)

Call PETSc linear equation solver.

Parameters
[in,out]contextpointer to iterative solver info and context (actual type: cs_sles_petsc_t *)
[in]namepointer to system name
[in]amatrix
[in]verbosityassociated verbosity
[in]rotation_modehalo update option for rotational periodicity
[in]precisionsolver precision
[in]r_normresidue normalization
[out]n_iternumber of "equivalent" iterations
[out]residueresidue
[in]rhsright hand side
[in,out]vxsystem solution
[in]aux_sizenumber of elements in aux_vectors (in bytes)
aux_vectorsoptional working area (internal allocation if NULL)
Returns
convergence state

◆ cs_user_sles_petsc_hook()

void cs_user_sles_petsc_hook ( void *  context,
Mat  a,
KSP  ksp 
)