Actual source code: tscreate.c

  1: #define PETSCTS_DLL

 3:  #include src/ts/tsimpl.h

  7: static PetscErrorCode TSPublish_Petsc(PetscObject obj)
  8: {
 10:   return(0);
 11: }

 13: #undef  __FUNCT__
 15: /*@C
 16:   TSCreate - This function creates an empty timestepper. The problem type can then be set with TSSetProblemType() and the 
 17:        type of solver can then be set with TSSetType().

 19:   Collective on MPI_Comm

 21:   Input Parameter:
 22: . comm - The communicator

 24:   Output Parameter:
 25: . ts   - The TS

 27:   Level: beginner

 29: .keywords: TS, create
 30: .seealso: TSSetType(), TSSetUp(), TSDestroy(), MeshCreate(), TSSetProblemType()
 31: @*/
 32: PetscErrorCode  TSCreate(MPI_Comm comm, TS *ts) {
 33:   TS             t;

 38:   *ts = PETSC_NULL;
 39: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
 40:   TSInitializePackage(PETSC_NULL);
 41: #endif

 43:   PetscHeaderCreate(t, _p_TS, struct _TSOps, TS_COOKIE, -1, "TS", comm, TSDestroy, TSView);
 44:   PetscLogObjectMemory(t, sizeof(struct _p_TS));
 45:   PetscMemzero(t->ops, sizeof(struct _TSOps));
 46:   t->bops->publish    = TSPublish_Petsc;
 47:   t->type_name        = PETSC_NULL;

 49:   t->ops->prestep       = TSDefaultPreStep;
 50:   t->ops->update        = TSDefaultUpdate;
 51:   t->ops->poststep      = TSDefaultPostStep;

 53:   /* General TS description */
 54:   t->problem_type       = TS_LINEAR;
 55:   t->vec_sol            = PETSC_NULL;
 56:   t->vec_sol_always     = PETSC_NULL;
 57:   t->numbermonitors     = 0;
 58:   t->isExplicit         = PETSC_NULL;
 59:   t->Iindex             = PETSC_NULL;
 60:   t->ksp                = PETSC_NULL;
 61:   t->A                  = PETSC_NULL;
 62:   t->B                  = PETSC_NULL;
 63:   t->Alhs               = PETSC_NULL;
 64:   t->Blhs               = PETSC_NULL;
 65:   t->snes               = PETSC_NULL;
 66:   t->funP               = PETSC_NULL;
 67:   t->jacP               = PETSC_NULL;
 68:   t->setupcalled        = 0;
 69:   t->data               = PETSC_NULL;
 70:   t->user               = PETSC_NULL;
 71:   t->max_steps          = 5000;
 72:   t->max_time           = 5.0;
 73:   t->time_step          = .1;
 74:   t->time_step_old      = t->time_step;
 75:   t->initial_time_step  = t->time_step;
 76:   t->steps              = 0;
 77:   t->ptime              = 0.0;
 78:   t->linear_its         = 0;
 79:   t->nonlinear_its      = 0;
 80:   t->work               = PETSC_NULL;
 81:   t->nwork              = 0;

 83:   *ts = t;
 84:   return(0);
 85: }

 87: /* Set A = 1/dt*Alhs - A, B = 1/dt*Blhs - B */
 90: PetscErrorCode TSScaleShiftMatrices(TS ts,Mat A,Mat B,MatStructure str)
 91: {
 92:   PetscTruth     flg;
 94:   PetscScalar    mdt = 1.0/ts->time_step;

 97:   PetscTypeCompare((PetscObject)ts->A,MATMFFD,&flg);
 98:   if (!flg) {
 99:     MatScale(ts->A,-1.0);
100:     if (ts->Alhs){
101:       MatAXPY(ts->A,mdt,ts->Alhs,DIFFERENT_NONZERO_PATTERN);
102:     } else {
103:       MatShift(ts->A,mdt);
104:     }
105:   }
106:   if (ts->B != ts->A && str != SAME_PRECONDITIONER) {
107:     MatScale(ts->B,-1.0);
108:     if (ts->Blhs){
109:       MatAXPY(ts->B,mdt,ts->Blhs,DIFFERENT_NONZERO_PATTERN);
110:     } else {
111:       MatShift(ts->B,mdt);
112:     }
113:   }
114:   return(0);
115: }