Actual source code: itcl.c

  1: /*
  2:     Code for setting KSP options from the options database.
  3: */

 5:  #include src/ksp/ksp/kspimpl.h
 6:  #include petscsys.h

  8: /*
  9:        We retain a list of functions that also take KSP command 
 10:     line options. These are called at the end KSPSetFromOptions()
 11: */
 12: #define MAXSETFROMOPTIONS 5
 13: PetscInt numberofsetfromoptions = 0;
 14: PetscErrorCode (*othersetfromoptions[MAXSETFROMOPTIONS])(KSP) = {0};

 18: /*@C
 19:     KSPAddOptionsChecker - Adds an additional function to check for KSP options.

 21:     Not Collective

 23:     Input Parameter:
 24: .   kspcheck - function that checks for options

 26:     Level: developer

 28: .keywords: KSP, add, options, checker

 30: .seealso: KSPSetFromOptions()
 31: @*/
 32: PetscErrorCode KSPAddOptionsChecker(PetscErrorCode (*kspcheck)(KSP))
 33: {
 35:   if (numberofsetfromoptions >= MAXSETFROMOPTIONS) {
 36:     SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many options checkers, only 5 allowed");
 37:   }

 39:   othersetfromoptions[numberofsetfromoptions++] = kspcheck;
 40:   return(0);
 41: }

 45: /*@C
 46:    KSPSetOptionsPrefix - Sets the prefix used for searching for all 
 47:    KSP options in the database.

 49:    Collective on KSP

 51:    Input Parameters:
 52: +  ksp - the Krylov context
 53: -  prefix - the prefix string to prepend to all KSP option requests

 55:    Notes:
 56:    A hyphen (-) must NOT be given at the beginning of the prefix name.
 57:    The first character of all runtime options is AUTOMATICALLY the
 58:    hyphen.

 60:    For example, to distinguish between the runtime options for two
 61:    different KSP contexts, one could call
 62: .vb
 63:       KSPSetOptionsPrefix(ksp1,"sys1_")
 64:       KSPSetOptionsPrefix(ksp2,"sys2_")
 65: .ve

 67:    This would enable use of different options for each system, such as
 68: .vb
 69:       -sys1_ksp_type gmres -sys1_ksp_rtol 1.e-3
 70:       -sys2_ksp_type bcgs  -sys2_ksp_rtol 1.e-4
 71: .ve

 73:    Level: advanced

 75: .keywords: KSP, set, options, prefix, database

 77: .seealso: KSPAppendOptionsPrefix(), KSPGetOptionsPrefix()
 78: @*/
 79: PetscErrorCode KSPSetOptionsPrefix(KSP ksp,const char prefix[])
 80: {
 84:   PCSetOptionsPrefix(ksp->pc,prefix);
 85:   PetscObjectSetOptionsPrefix((PetscObject)ksp,prefix);
 86:   return(0);
 87: }
 88: 
 91: /*@C
 92:    KSPAppendOptionsPrefix - Appends to the prefix used for searching for all 
 93:    KSP options in the database.

 95:    Collective on KSP

 97:    Input Parameters:
 98: +  ksp - the Krylov context
 99: -  prefix - the prefix string to prepend to all KSP option requests

101:    Notes:
102:    A hyphen (-) must NOT be given at the beginning of the prefix name.
103:    The first character of all runtime options is AUTOMATICALLY the hyphen.

105:    Level: advanced

107: .keywords: KSP, append, options, prefix, database

109: .seealso: KSPSetOptionsPrefix(), KSPGetOptionsPrefix()
110: @*/
111: PetscErrorCode KSPAppendOptionsPrefix(KSP ksp,const char prefix[])
112: {
116:   PCAppendOptionsPrefix(ksp->pc,prefix);
117:   PetscObjectAppendOptionsPrefix((PetscObject)ksp,prefix);
118:   return(0);
119: }

123: /*@C
124:    KSPGetOptionsPrefix - Gets the prefix used for searching for all 
125:    KSP options in the database.

127:    Not Collective

129:    Input Parameters:
130: .  ksp - the Krylov context

132:    Output Parameters:
133: .  prefix - pointer to the prefix string used is returned

135:    Notes: On the fortran side, the user should pass in a string 'prifix' of
136:    sufficient length to hold the prefix.

138:    Level: advanced

140: .keywords: KSP, set, options, prefix, database

142: .seealso: KSPSetOptionsPrefix(), KSPAppendOptionsPrefix()
143: @*/
144: PetscErrorCode KSPGetOptionsPrefix(KSP ksp,char *prefix[])
145: {
149:   PetscObjectGetOptionsPrefix((PetscObject)ksp,prefix);
150:   return(0);
151: }

153: