xref: /petsc/src/ts/interface/dlregists.c (revision e91c04dfc8a52dee1965211bb1cc8e5bf775178f)
1 #include <petsc/private/tsimpl.h>
2 
3 static PetscBool TSPackageInitialized = PETSC_FALSE;
4 /*@C
5   TSFinalizePackage - This function destroys everything in the Petsc interface to `TS`. It is
6   called from `PetscFinalize()`.
7 
8   Level: developer
9 
10 .seealso: [](ch_ts), `TS`, `PetscFinalize()`, `TSInitializePackage()`
11 @*/
12 PetscErrorCode TSFinalizePackage(void)
13 {
14   PetscFunctionBegin;
15   PetscCall(PetscFunctionListDestroy(&TSList));
16   PetscCall(PetscFunctionListDestroy(&TSTrajectoryList));
17   TSPackageInitialized = PETSC_FALSE;
18   TSRegisterAllCalled  = PETSC_FALSE;
19   PetscFunctionReturn(PETSC_SUCCESS);
20 }
21 
22 /*@C
23   TSInitializePackage - This function initializes everything in the `TS` package. It is called
24   from `PetscDLLibraryRegister_petscts()` when using dynamic libraries, and on the first call to `TSCreate()`
25   when using shared or static libraries.
26 
27   Level: developer
28 
29   Note:
30   This function never needs to be called by PETSc users.
31 
32 .seealso: [](ch_ts), `TS`, `PetscInitialize()`, `TSFinalizePackage()`
33 @*/
34 PetscErrorCode TSInitializePackage(void)
35 {
36   char      logList[256];
37   PetscBool opt, pkg, cls;
38 
39   PetscFunctionBegin;
40   if (TSPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
41   TSPackageInitialized = PETSC_TRUE;
42   /* Initialize subpackages */
43   PetscCall(TSAdaptInitializePackage());
44   PetscCall(TSGLLEInitializePackage());
45   PetscCall(TSRKInitializePackage());
46   PetscCall(TSGLEEInitializePackage());
47   PetscCall(TSARKIMEXInitializePackage());
48   PetscCall(TSRosWInitializePackage());
49   PetscCall(TSSSPInitializePackage());
50   PetscCall(TSGLLEAdaptInitializePackage());
51   PetscCall(TSBasicSymplecticInitializePackage());
52   /* Register Classes */
53   PetscCall(PetscClassIdRegister("TS", &TS_CLASSID));
54   PetscCall(PetscClassIdRegister("DMTS", &DMTS_CLASSID));
55   PetscCall(PetscClassIdRegister("TSTrajectory", &TSTRAJECTORY_CLASSID));
56 
57   /* Register Constructors */
58   PetscCall(TSRegisterAll());
59   PetscCall(TSTrajectoryRegisterAll());
60   /* Register Events */
61   PetscCall(PetscLogEventRegister("TSStep", TS_CLASSID, &TS_Step));
62   PetscCall(PetscLogEventRegister("TSFunctionEval", TS_CLASSID, &TS_FunctionEval));
63   PetscCall(PetscLogEventRegister("TSJacobianEval", TS_CLASSID, &TS_JacobianEval));
64   PetscCall(PetscLogEventRegister("TSForwardStep", TS_CLASSID, &TS_ForwardStep));
65   PetscCall(PetscLogEventRegister("TSAdjointStep", TS_CLASSID, &TS_AdjointStep));
66   PetscCall(PetscLogEventRegister("TSTrajectorySet", TSTRAJECTORY_CLASSID, &TSTrajectory_Set));
67   PetscCall(PetscLogEventRegister("TSTrajectoryGet", TSTRAJECTORY_CLASSID, &TSTrajectory_Get));
68   PetscCall(PetscLogEventRegister("TSTrajGetVecs", TSTRAJECTORY_CLASSID, &TSTrajectory_GetVecs));
69   PetscCall(PetscLogEventRegister("TSTrajSetUp", TSTRAJECTORY_CLASSID, &TSTrajectory_SetUp));
70   PetscCall(PetscLogEventRegister("TSTrajDiskWrite", TSTRAJECTORY_CLASSID, &TSTrajectory_DiskWrite));
71   PetscCall(PetscLogEventRegister("TSTrajDiskRead", TSTRAJECTORY_CLASSID, &TSTrajectory_DiskRead));
72   PetscCall(PetscLogEventRegister("TSPseudoCmptTStp", TS_CLASSID, &TS_PseudoComputeTimeStep));
73   /* Process Info */
74   {
75     PetscClassId classids[4];
76 
77     classids[0] = TS_CLASSID;
78     classids[1] = DMTS_CLASSID;
79     classids[2] = TSADAPT_CLASSID;
80     classids[3] = TSTRAJECTORY_CLASSID;
81     PetscCall(PetscInfoProcessClass("ts", 1, classids));
82     PetscCall(PetscInfoProcessClass("dm", 1, &classids[1]));
83     PetscCall(PetscInfoProcessClass("tsadapt", 1, &classids[2]));
84     PetscCall(PetscInfoProcessClass("tstrajectory", 1, &classids[3]));
85   }
86   /* Process summary exclusions */
87   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
88   if (opt) {
89     PetscCall(PetscStrInList("ts", logList, ',', &pkg));
90     if (pkg) PetscCall(PetscLogEventExcludeClass(TS_CLASSID));
91     PetscCall(PetscStrInList("dm", logList, ',', &cls));
92     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(DMTS_CLASSID));
93     PetscCall(PetscStrInList("tsadapt", logList, ',', &cls));
94     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(TSADAPT_CLASSID));
95     PetscCall(PetscStrInList("tstrajectory", logList, ',', &cls));
96     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(TSTRAJECTORY_CLASSID));
97   }
98   /* Register package finalizer */
99   PetscCall(PetscRegisterFinalize(TSFinalizePackage));
100   PetscFunctionReturn(PETSC_SUCCESS);
101 }
102 
103 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
104 /*
105   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.
106 
107   This one registers all the TS methods that are in the basic PETSc libpetscts library.
108 
109  */
110 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscts(void); /*prototype*/
111 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscts(void)
112 {
113   PetscFunctionBegin;
114   PetscCall(TSInitializePackage());
115   PetscFunctionReturn(PETSC_SUCCESS);
116 }
117 #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */
118