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