xref: /petsc/src/ts/interface/tscreate.c (revision 7b23a99a4cafc5f74ba930d377af92d6b7c0a4c1)
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   /* General TS description */
48   t->problem_type       = TS_LINEAR;
49   t->vec_sol            = PETSC_NULL;
50   t->numbermonitors     = 0;
51   t->ksp                = PETSC_NULL;
52   t->A                  = PETSC_NULL;
53   t->B                  = PETSC_NULL;
54   t->Arhs               = PETSC_NULL;
55   t->Alhs               = PETSC_NULL;
56   t->matflg             = DIFFERENT_NONZERO_PATTERN;
57   t->snes               = PETSC_NULL;
58   t->funP               = PETSC_NULL;
59   t->jacP               = PETSC_NULL;
60   t->setupcalled        = 0;
61   t->data               = PETSC_NULL;
62   t->user               = PETSC_NULL;
63   t->max_steps          = 5000;
64   t->max_time           = 5.0;
65   t->time_step          = .1;
66   t->time_step_old      = t->time_step;
67   t->initial_time_step  = t->time_step;
68   t->steps              = 0;
69   t->ptime              = 0.0;
70   t->linear_its         = 0;
71   t->nonlinear_its      = 0;
72   t->work               = PETSC_NULL;
73   t->nwork              = 0;
74 
75   *ts = t;
76   PetscFunctionReturn(0);
77 }
78 
79 /* Set A = 1/dt*Alhs - A, B = 1/dt*Blhs - B */
80 #undef __FUNCT__
81 #define __FUNCT__ "TSScaleShiftMatrices"
82 PetscErrorCode TSScaleShiftMatrices(TS ts,Mat A,Mat B,MatStructure str)
83 {
84   PetscBool      flg;
85   PetscErrorCode ierr;
86   PetscScalar    mdt = 1.0/ts->time_step;
87 
88   PetscFunctionBegin;
89   /* this function requires additional work! */
90   ierr = PetscTypeCompare((PetscObject)A,MATMFFD,&flg);CHKERRQ(ierr);
91   if (!flg) {
92     ierr = MatScale(A,-1.0);CHKERRQ(ierr);
93     if (ts->Alhs){
94       ierr = MatAXPY(A,mdt,ts->Alhs,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);
95     } else {
96       ierr = MatShift(A,mdt);CHKERRQ(ierr);
97     }
98   }
99   if (B != A && str != SAME_PRECONDITIONER) {
100     ierr = MatScale(B,-1.0);CHKERRQ(ierr);
101     ierr = MatShift(B,mdt);CHKERRQ(ierr);
102   }
103   PetscFunctionReturn(0);
104 }
105