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