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