xref: /petsc/src/ts/interface/tscreate.c (revision 2423ceccb24e7c4e920586461c18d276a9f3c5ae)
1 #define PETSCTS_DLL
2 
3 #include "include/private/tsimpl.h"      /*I "petscts.h"  I*/
4 
5 #undef __FUNCT__
6 #define __FUNCT__ "TSPublish_Petsc"
7 static PetscErrorCode TSPublish_Petsc(PetscObject obj)
8 {
9   PetscFunctionBegin;
10   PetscFunctionReturn(0);
11 }
12 
13 #undef  __FUNCT__
14 #define __FUNCT__ "TSCreate"
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().
18 
19   Collective on MPI_Comm
20 
21   Input Parameter:
22 . comm - The communicator
23 
24   Output Parameter:
25 . ts   - The TS
26 
27   Level: beginner
28 
29 .keywords: TS, create
30 .seealso: TSSetType(), TSSetUp(), TSDestroy(), MeshCreate(), TSSetProblemType()
31 @*/
32 PetscErrorCode PETSCTS_DLLEXPORT TSCreate(MPI_Comm comm, TS *ts) {
33   TS             t;
34   PetscErrorCode ierr;
35 
36   PetscFunctionBegin;
37   PetscValidPointer(ts,1);
38   *ts = PETSC_NULL;
39 #ifndef PETSC_USE_DYNAMIC_LIBRARIES
40   ierr = TSInitializePackage(PETSC_NULL);CHKERRQ(ierr);
41 #endif
42 
43   ierr = PetscHeaderCreate(t, _p_TS, struct _TSOps, TS_COOKIE, -1, "TS", comm, TSDestroy, TSView);CHKERRQ(ierr);
44   ierr = PetscLogObjectMemory(t, sizeof(struct _p_TS));CHKERRQ(ierr);
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->prestep       = TSDefaultPreStep;
50   t->ops->update        = TSDefaultUpdate;
51   t->ops->poststep      = TSDefaultPostStep;
52 
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->Arhs               = PETSC_NULL;
64   t->Alhs               = PETSC_NULL;
65   t->matflg             = DIFFERENT_NONZERO_PATTERN;
66   t->snes               = PETSC_NULL;
67   t->funP               = PETSC_NULL;
68   t->jacP               = PETSC_NULL;
69   t->setupcalled        = 0;
70   t->data               = PETSC_NULL;
71   t->user               = PETSC_NULL;
72   t->max_steps          = 5000;
73   t->max_time           = 5.0;
74   t->time_step          = .1;
75   t->time_step_old      = t->time_step;
76   t->initial_time_step  = t->time_step;
77   t->steps              = 0;
78   t->ptime              = 0.0;
79   t->linear_its         = 0;
80   t->nonlinear_its      = 0;
81   t->work               = PETSC_NULL;
82   t->nwork              = 0;
83 
84   *ts = t;
85   PetscFunctionReturn(0);
86 }
87 
88 /* Set A = 1/dt*Alhs - A, B = 1/dt*Blhs - B */
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    mdt = 1.0/ts->time_step;
96 
97   PetscFunctionBegin;
98   /* this function requires additional work! */
99   ierr = PetscTypeCompare((PetscObject)A,MATMFFD,&flg);CHKERRQ(ierr);
100   if (!flg) {
101     ierr = MatScale(A,-1.0);CHKERRQ(ierr);
102     if (ts->Alhs){
103       ierr = MatAXPY(A,mdt,ts->Alhs,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);
104     } else {
105       ierr = MatShift(A,mdt);CHKERRQ(ierr);
106     }
107   }
108   if (B != A && str != SAME_PRECONDITIONER) {
109     ierr = MatScale(B,-1.0);CHKERRQ(ierr);
110     ierr = MatShift(B,mdt);CHKERRQ(ierr);
111   }
112   PetscFunctionReturn(0);
113 }
114