Actual source code: dlregissnes.c


  2: #include <petsc/private/snesimpl.h>
  3: #include <petsc/private/linesearchimpl.h>

  5: static PetscBool SNESPackageInitialized = PETSC_FALSE;

  7: /*@C
  8:   SNESFinalizePackage - This function destroys everything in the Petsc interface to the `SNES` package. It is
  9:   called from `PetscFinalize()`.

 11:   Level: developer

 13: .seealso: `SNES`, `PetscFinalize()`
 14: @*/
 15: PetscErrorCode SNESFinalizePackage(void)
 16: {
 17:   PetscFunctionBegin;
 18:   PetscCall(PetscFunctionListDestroy(&SNESList));
 19:   PetscCall(PetscFunctionListDestroy(&SNESLineSearchList));
 20:   SNESPackageInitialized          = PETSC_FALSE;
 21:   SNESRegisterAllCalled           = PETSC_FALSE;
 22:   SNESLineSearchRegisterAllCalled = PETSC_FALSE;
 23:   PetscFunctionReturn(PETSC_SUCCESS);
 24: }

 26: /*@C
 27:   SNESInitializePackage - This function initializes everything in the `SNES` package. It is called
 28:   from PetscDLLibraryRegister_petscsnes() when using dynamic libraries, and on the first call to `SNESCreate()`
 29:   when using shared or static libraries.

 31:   Level: developer

 33: .seealso: `SNES`, `PetscInitialize()`
 34: @*/
 35: PetscErrorCode SNESInitializePackage(void)
 36: {
 37:   char      logList[256];
 38:   PetscBool opt, pkg, cls;

 40:   PetscFunctionBegin;
 41:   if (SNESPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
 42:   SNESPackageInitialized = PETSC_TRUE;
 43:   /* Initialize subpackages */
 44:   PetscCall(SNESMSInitializePackage());
 45:   /* Register Classes */
 46:   PetscCall(PetscClassIdRegister("SNES", &SNES_CLASSID));
 47:   PetscCall(PetscClassIdRegister("DMSNES", &DMSNES_CLASSID));
 48:   PetscCall(PetscClassIdRegister("SNESLineSearch", &SNESLINESEARCH_CLASSID));
 49:   /* Register Constructors */
 50:   PetscCall(SNESRegisterAll());
 51:   PetscCall(SNESLineSearchRegisterAll());
 52:   /* Register Events */
 53:   PetscCall(PetscLogEventRegister("SNESSolve", SNES_CLASSID, &SNES_Solve));
 54:   PetscCall(PetscLogEventRegister("SNESSetUp", SNES_CLASSID, &SNES_SetUp));
 55:   PetscCall(PetscLogEventRegister("SNESFunctionEval", SNES_CLASSID, &SNES_FunctionEval));
 56:   PetscCall(PetscLogEventRegister("SNESObjectiveEval", SNES_CLASSID, &SNES_ObjectiveEval));
 57:   PetscCall(PetscLogEventRegister("SNESNGSEval", SNES_CLASSID, &SNES_NGSEval));
 58:   PetscCall(PetscLogEventRegister("SNESNGSFuncEval", SNES_CLASSID, &SNES_NGSFuncEval));
 59:   PetscCall(PetscLogEventRegister("SNESJacobianEval", SNES_CLASSID, &SNES_JacobianEval));
 60:   PetscCall(PetscLogEventRegister("SNESNPCSolve", SNES_CLASSID, &SNES_NPCSolve));
 61:   PetscCall(PetscLogEventRegister("SNESLineSearch", SNESLINESEARCH_CLASSID, &SNESLINESEARCH_Apply));
 62:   /* Process Info */
 63:   {
 64:     PetscClassId classids[3];

 66:     classids[0] = SNES_CLASSID;
 67:     classids[1] = DMSNES_CLASSID;
 68:     classids[2] = SNESLINESEARCH_CLASSID;
 69:     PetscCall(PetscInfoProcessClass("snes", 1, classids));
 70:     PetscCall(PetscInfoProcessClass("dm", 1, &classids[1]));
 71:     PetscCall(PetscInfoProcessClass("sneslinesearch", 1, &classids[2]));
 72:   }
 73:   /* Process summary exclusions */
 74:   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
 75:   if (opt) {
 76:     PetscCall(PetscStrInList("snes", logList, ',', &pkg));
 77:     if (pkg) PetscCall(PetscLogEventExcludeClass(SNES_CLASSID));
 78:     PetscCall(PetscStrInList("dm", logList, ',', &cls));
 79:     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(DMSNES_CLASSID));
 80:     PetscCall(PetscStrInList("sneslinesearch", logList, ',', &cls));
 81:     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(SNESLINESEARCH_CLASSID));
 82:   }
 83:   /* Register package finalizer */
 84:   PetscCall(PetscRegisterFinalize(SNESFinalizePackage));
 85:   PetscFunctionReturn(PETSC_SUCCESS);
 86: }

 88: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
 89: /*
 90:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

 92:   This registers all of the SNES methods that are in the basic PETSc libpetscsnes library.

 94:  */
 95: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscsnes(void)
 96: {
 97:   PetscFunctionBegin;
 98:   PetscCall(SNESInitializePackage());
 99:   PetscFunctionReturn(PETSC_SUCCESS);
100: }

102: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */