[petsc-dev] on the usage of PetscTryMethod() and PetscUseMethod()
bsmith at mcs.anl.gov
Sun Apr 10 22:01:16 CDT 2016
PetscTryMethod() and PetscUseMethod() are used to run functions that have been attached to PETSc objects with PetscObjectComposeFunction().
PetscTryMethod() is usually used with routines that have Set in the name, this is for when the function is to be ignored when the object does not have the method attached. For example KSPGMRESSetRestart() uses PetscTryMethod() because if the object is not a gmres method the restart should be ignored. This functionality is so that we can write code that has many Set functions but we don't need to check each one with an ugly if test to see if the object is the appropriate type.
PetscUseMethod() is used when the object MUST have the function composed with it, otherwise an error will be generated. For example KSPGMRESGetRestart() uses PetscUseMethod() because it is an error to call this routine on an object that is not a gmres object.
Please make sure you use PetscUseMethod() it the user is always expecting a value returned from your function,
I just fixed a bunch of TryMethods that should have been UseMethods in master.
More information about the petsc-dev