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