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