1 2 #include <private/tsimpl.h> /*I "petscts.h" I*/ 3 4 #if 0 5 #undef __FUNCT__ 6 #define __FUNCT__ "TSPublish_Petsc" 7 static PetscErrorCode TSPublish_Petsc(PetscObject obj) 8 { 9 PetscFunctionBegin; 10 PetscFunctionReturn(0); 11 } 12 #endif 13 14 #undef __FUNCT__ 15 #define __FUNCT__ "TSCreate" 16 /*@C 17 TSCreate - This function creates an empty timestepper. The problem type can then be set with TSSetProblemType() and the 18 type of solver can then be set with TSSetType(). 19 20 Collective on MPI_Comm 21 22 Input Parameter: 23 . comm - The communicator 24 25 Output Parameter: 26 . ts - The TS 27 28 Level: beginner 29 30 .keywords: TS, create 31 .seealso: TSSetType(), TSSetUp(), TSDestroy(), MeshCreate(), TSSetProblemType() 32 @*/ 33 PetscErrorCode TSCreate(MPI_Comm comm, TS *ts) { 34 TS t; 35 PetscErrorCode ierr; 36 37 PetscFunctionBegin; 38 PetscValidPointer(ts,1); 39 *ts = PETSC_NULL; 40 #ifndef PETSC_USE_DYNAMIC_LIBRARIES 41 ierr = TSInitializePackage(PETSC_NULL);CHKERRQ(ierr); 42 #endif 43 44 ierr = PetscHeaderCreate(t, _p_TS, struct _TSOps, TS_CLASSID, -1, "TS", comm, TSDestroy, TSView);CHKERRQ(ierr); 45 ierr = PetscMemzero(t->ops, sizeof(struct _TSOps));CHKERRQ(ierr); 46 47 t->ops->prestep = TSDefaultPreStep; 48 t->ops->poststep = TSDefaultPostStep; 49 50 /* General TS description */ 51 t->problem_type = TS_LINEAR; 52 t->vec_sol = PETSC_NULL; 53 t->numbermonitors = 0; 54 t->ksp = PETSC_NULL; 55 t->A = PETSC_NULL; 56 t->B = PETSC_NULL; 57 t->Arhs = PETSC_NULL; 58 t->Alhs = PETSC_NULL; 59 t->matflg = DIFFERENT_NONZERO_PATTERN; 60 t->snes = PETSC_NULL; 61 t->funP = PETSC_NULL; 62 t->jacP = PETSC_NULL; 63 t->setupcalled = 0; 64 t->data = PETSC_NULL; 65 t->user = PETSC_NULL; 66 t->max_steps = 5000; 67 t->max_time = 5.0; 68 t->time_step = .1; 69 t->time_step_old = t->time_step; 70 t->initial_time_step = t->time_step; 71 t->steps = 0; 72 t->ptime = 0.0; 73 t->linear_its = 0; 74 t->nonlinear_its = 0; 75 t->work = PETSC_NULL; 76 t->nwork = 0; 77 78 *ts = t; 79 PetscFunctionReturn(0); 80 } 81 82 /* Set A = 1/dt*Alhs - A, B = 1/dt*Blhs - B */ 83 #undef __FUNCT__ 84 #define __FUNCT__ "TSScaleShiftMatrices" 85 PetscErrorCode TSScaleShiftMatrices(TS ts,Mat A,Mat B,MatStructure str) 86 { 87 PetscBool flg; 88 PetscErrorCode ierr; 89 PetscScalar mdt = 1.0/ts->time_step; 90 91 PetscFunctionBegin; 92 /* this function requires additional work! */ 93 ierr = PetscTypeCompare((PetscObject)A,MATMFFD,&flg);CHKERRQ(ierr); 94 if (!flg) { 95 ierr = MatScale(A,-1.0);CHKERRQ(ierr); 96 if (ts->Alhs){ 97 ierr = MatAXPY(A,mdt,ts->Alhs,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr); 98 } else { 99 ierr = MatShift(A,mdt);CHKERRQ(ierr); 100 } 101 } 102 if (B != A && str != SAME_PRECONDITIONER) { 103 ierr = MatScale(B,-1.0);CHKERRQ(ierr); 104 ierr = MatShift(B,mdt);CHKERRQ(ierr); 105 } 106 PetscFunctionReturn(0); 107 } 108