Actual source code: dlregissnes.c

      1: #include <petsc/private/snesimpl.h>
      2: #include <petsc/private/linesearchimpl.h>
      3: #include <petsc/private/dmadaptorimpl.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: [](ch_snes), `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:   Note:
     34:   This function never needs to be called by PETSc users.

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

     43:   PetscFunctionBegin;
     44:   if (SNESPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
     45:   SNESPackageInitialized = PETSC_TRUE;
     46:   /* Initialize subpackages */
     47:   PetscCall(SNESMSInitializePackage());
     48:   /* Register Classes */
     49:   PetscCall(PetscClassIdRegister("SNES", &SNES_CLASSID));
     50:   PetscCall(PetscClassIdRegister("DMSNES", &DMSNES_CLASSID));
     51:   PetscCall(PetscClassIdRegister("SNESLineSearch", &SNESLINESEARCH_CLASSID));
     52:   PetscCall(PetscClassIdRegister("DM Adaptor", &DMADAPTOR_CLASSID));
     53:   /* Register Constructors */
     54:   PetscCall(SNESRegisterAll());
     55:   PetscCall(SNESLineSearchRegisterAll());
     56:   PetscCall(DMAdaptorRegisterAll());
     57:   PetscCall(PetscRegisterFinalize(DMAdaptorRegisterDestroy));
     58:   PetscCall(DMAdaptorMonitorRegisterAll());
     59:   PetscCall(PetscRegisterFinalize(DMAdaptorMonitorRegisterDestroy));
     60:   /* Register Events */
     61:   PetscCall(PetscLogEventRegister("SNESSolve", SNES_CLASSID, &SNES_Solve));
     62:   PetscCall(PetscLogEventRegister("SNESSetUp", SNES_CLASSID, &SNES_SetUp));
     63:   PetscCall(PetscLogEventRegister("SNESFunctionEval", SNES_CLASSID, &SNES_FunctionEval));
     64:   PetscCall(PetscLogEventRegister("SNESObjectiveEval", SNES_CLASSID, &SNES_ObjectiveEval));
     65:   PetscCall(PetscLogEventRegister("SNESNGSEval", SNES_CLASSID, &SNES_NGSEval));
     66:   PetscCall(PetscLogEventRegister("SNESNGSFuncEval", SNES_CLASSID, &SNES_NGSFuncEval));
     67:   PetscCall(PetscLogEventRegister("SNESNewtonALEval", SNES_CLASSID, &SNES_NewtonALEval));
     68:   PetscCall(PetscLogEventRegister("SNESJacobianEval", SNES_CLASSID, &SNES_JacobianEval));
     69:   PetscCall(PetscLogEventRegister("SNESNPCSolve", SNES_CLASSID, &SNES_NPCSolve));
     70:   PetscCall(PetscLogEventRegister("SNESLineSearch", SNESLINESEARCH_CLASSID, &SNESLINESEARCH_Apply));
     71:   /* Process Info */
     72:   {
     73:     PetscClassId classids[3];

     75:     classids[0] = SNES_CLASSID;
     76:     classids[1] = DMSNES_CLASSID;
     77:     classids[2] = SNESLINESEARCH_CLASSID;
     78:     PetscCall(PetscInfoProcessClass("snes", 1, classids));
     79:     PetscCall(PetscInfoProcessClass("dm", 1, &classids[1]));
     80:     PetscCall(PetscInfoProcessClass("sneslinesearch", 1, &classids[2]));
     81:   }
     82:   /* Process summary exclusions */
     83:   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
     84:   if (opt) {
     85:     PetscCall(PetscStrInList("snes", logList, ',', &pkg));
     86:     if (pkg) PetscCall(PetscLogEventExcludeClass(SNES_CLASSID));
     87:     PetscCall(PetscStrInList("dm", logList, ',', &cls));
     88:     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(DMSNES_CLASSID));
     89:     PetscCall(PetscStrInList("sneslinesearch", logList, ',', &cls));
     90:     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(SNESLINESEARCH_CLASSID));
     91:   }
     92:   /* Register package finalizer */
     93:   PetscCall(PetscRegisterFinalize(SNESFinalizePackage));
     94:   PetscFunctionReturn(PETSC_SUCCESS);
     95: }

     97: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
     98: /*
     99:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

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

    103:  */
    104: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscsnes(void)
    105: {
    106:   PetscFunctionBegin;
    107:   PetscCall(SNESInitializePackage());
    108:   PetscFunctionReturn(PETSC_SUCCESS);
    109: }

    111: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */