xref: /petsc/src/snes/interface/dlregissnes.c (revision 58d68138c660dfb4e9f5b03334792cd4f2ffd7cc)
1 
2 #include <petsc/private/snesimpl.h>
3 #include <petsc/private/linesearchimpl.h>
4 
5 static PetscBool SNESPackageInitialized = PETSC_FALSE;
6 
7 /*@C
8   SNESFinalizePackage - This function destroys everything in the Petsc interface to the SNES package. It is
9   called from PetscFinalize().
10 
11   Level: developer
12 
13 .seealso: `PetscFinalize()`
14 @*/
15 PetscErrorCode SNESFinalizePackage(void) {
16   PetscFunctionBegin;
17   PetscCall(PetscFunctionListDestroy(&SNESList));
18   PetscCall(PetscFunctionListDestroy(&SNESLineSearchList));
19   SNESPackageInitialized          = PETSC_FALSE;
20   SNESRegisterAllCalled           = PETSC_FALSE;
21   SNESLineSearchRegisterAllCalled = PETSC_FALSE;
22   PetscFunctionReturn(0);
23 }
24 
25 /*@C
26   SNESInitializePackage - This function initializes everything in the SNES package. It is called
27   from PetscDLLibraryRegister_petscsnes() when using dynamic libraries, and on the first call to SNESCreate()
28   when using shared or static libraries.
29 
30   Level: developer
31 
32 .seealso: `PetscInitialize()`
33 @*/
34 PetscErrorCode SNESInitializePackage(void) {
35   char      logList[256];
36   PetscBool opt, pkg, cls;
37 
38   PetscFunctionBegin;
39   if (SNESPackageInitialized) PetscFunctionReturn(0);
40   SNESPackageInitialized = PETSC_TRUE;
41   /* Initialize subpackages */
42   PetscCall(SNESMSInitializePackage());
43   /* Register Classes */
44   PetscCall(PetscClassIdRegister("SNES", &SNES_CLASSID));
45   PetscCall(PetscClassIdRegister("DMSNES", &DMSNES_CLASSID));
46   PetscCall(PetscClassIdRegister("SNESLineSearch", &SNESLINESEARCH_CLASSID));
47   /* Register Constructors */
48   PetscCall(SNESRegisterAll());
49   PetscCall(SNESLineSearchRegisterAll());
50   /* Register Events */
51   PetscCall(PetscLogEventRegister("SNESSolve", SNES_CLASSID, &SNES_Solve));
52   PetscCall(PetscLogEventRegister("SNESSetUp", SNES_CLASSID, &SNES_Setup));
53   PetscCall(PetscLogEventRegister("SNESFunctionEval", SNES_CLASSID, &SNES_FunctionEval));
54   PetscCall(PetscLogEventRegister("SNESObjectiveEval", SNES_CLASSID, &SNES_ObjectiveEval));
55   PetscCall(PetscLogEventRegister("SNESNGSEval", SNES_CLASSID, &SNES_NGSEval));
56   PetscCall(PetscLogEventRegister("SNESNGSFuncEval", SNES_CLASSID, &SNES_NGSFuncEval));
57   PetscCall(PetscLogEventRegister("SNESJacobianEval", SNES_CLASSID, &SNES_JacobianEval));
58   PetscCall(PetscLogEventRegister("SNESNPCSolve", SNES_CLASSID, &SNES_NPCSolve));
59   PetscCall(PetscLogEventRegister("SNESLineSearch", SNESLINESEARCH_CLASSID, &SNESLINESEARCH_Apply));
60   /* Process Info */
61   {
62     PetscClassId classids[3];
63 
64     classids[0] = SNES_CLASSID;
65     classids[1] = DMSNES_CLASSID;
66     classids[2] = SNESLINESEARCH_CLASSID;
67     PetscCall(PetscInfoProcessClass("snes", 1, classids));
68     PetscCall(PetscInfoProcessClass("dm", 1, &classids[1]));
69     PetscCall(PetscInfoProcessClass("sneslinesearch", 1, &classids[2]));
70   }
71   /* Process summary exclusions */
72   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
73   if (opt) {
74     PetscCall(PetscStrInList("snes", logList, ',', &pkg));
75     if (pkg) PetscCall(PetscLogEventExcludeClass(SNES_CLASSID));
76     PetscCall(PetscStrInList("dm", logList, ',', &cls));
77     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(DMSNES_CLASSID));
78     PetscCall(PetscStrInList("sneslinesearch", logList, ',', &cls));
79     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(SNESLINESEARCH_CLASSID));
80   }
81   /* Register package finalizer */
82   PetscCall(PetscRegisterFinalize(SNESFinalizePackage));
83   PetscFunctionReturn(0);
84 }
85 
86 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
87 /*
88   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.
89 
90   This registers all of the SNES methods that are in the basic PETSc libpetscsnes library.
91 
92  */
93 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscsnes(void) {
94   PetscFunctionBegin;
95   PetscCall(SNESInitializePackage());
96   PetscFunctionReturn(0);
97 }
98 
99 #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */
100