1bdad233fSMatthew Knepley 2*c6db04a5SJed Brown #include <private/tsimpl.h> /*I "petscts.h" I*/ 3bdad233fSMatthew Knepley 47adad957SLisandro Dalcin #if 0 5bdad233fSMatthew Knepley #undef __FUNCT__ 6bdad233fSMatthew Knepley #define __FUNCT__ "TSPublish_Petsc" 76849ba73SBarry Smith static PetscErrorCode TSPublish_Petsc(PetscObject obj) 8bdad233fSMatthew Knepley { 9bdad233fSMatthew Knepley PetscFunctionBegin; 10bdad233fSMatthew Knepley PetscFunctionReturn(0); 11bdad233fSMatthew Knepley } 127adad957SLisandro Dalcin #endif 13bdad233fSMatthew Knepley 14bdad233fSMatthew Knepley #undef __FUNCT__ 15bdad233fSMatthew Knepley #define __FUNCT__ "TSCreate" 1660893bc3SSatish Balay /*@C 17bd6a702fSBarry Smith TSCreate - This function creates an empty timestepper. The problem type can then be set with TSSetProblemType() and the 18bd6a702fSBarry Smith type of solver can then be set with TSSetType(). 19bdad233fSMatthew Knepley 20bdad233fSMatthew Knepley Collective on MPI_Comm 21bdad233fSMatthew Knepley 22bdad233fSMatthew Knepley Input Parameter: 23bdad233fSMatthew Knepley . comm - The communicator 24bdad233fSMatthew Knepley 25bdad233fSMatthew Knepley Output Parameter: 26bdad233fSMatthew Knepley . ts - The TS 27bdad233fSMatthew Knepley 28bdad233fSMatthew Knepley Level: beginner 29bdad233fSMatthew Knepley 30bdad233fSMatthew Knepley .keywords: TS, create 31bd6a702fSBarry Smith .seealso: TSSetType(), TSSetUp(), TSDestroy(), MeshCreate(), TSSetProblemType() 32bdad233fSMatthew Knepley @*/ 337087cfbeSBarry Smith PetscErrorCode TSCreate(MPI_Comm comm, TS *ts) { 34bdad233fSMatthew Knepley TS t; 35dfbe8321SBarry Smith PetscErrorCode ierr; 36bdad233fSMatthew Knepley 37bdad233fSMatthew Knepley PetscFunctionBegin; 384482741eSBarry Smith PetscValidPointer(ts,1); 39bdad233fSMatthew Knepley *ts = PETSC_NULL; 40bdad233fSMatthew Knepley #ifndef PETSC_USE_DYNAMIC_LIBRARIES 41bdad233fSMatthew Knepley ierr = TSInitializePackage(PETSC_NULL);CHKERRQ(ierr); 42bdad233fSMatthew Knepley #endif 43bdad233fSMatthew Knepley 440700a824SBarry Smith ierr = PetscHeaderCreate(t, _p_TS, struct _TSOps, TS_CLASSID, -1, "TS", comm, TSDestroy, TSView);CHKERRQ(ierr); 45bdad233fSMatthew Knepley ierr = PetscMemzero(t->ops, sizeof(struct _TSOps));CHKERRQ(ierr); 46bdad233fSMatthew Knepley 47bdad233fSMatthew Knepley t->ops->prestep = TSDefaultPreStep; 48bdad233fSMatthew Knepley t->ops->poststep = TSDefaultPostStep; 49bdad233fSMatthew Knepley 50bdad233fSMatthew Knepley /* General TS description */ 51bdad233fSMatthew Knepley t->problem_type = TS_LINEAR; 52bdad233fSMatthew Knepley t->vec_sol = PETSC_NULL; 53bdad233fSMatthew Knepley t->vec_sol_always = PETSC_NULL; 54bdad233fSMatthew Knepley t->numbermonitors = 0; 5594b7f48cSBarry Smith t->ksp = PETSC_NULL; 56bdad233fSMatthew Knepley t->A = PETSC_NULL; 57bdad233fSMatthew Knepley t->B = PETSC_NULL; 588beb423aSHong Zhang t->Arhs = PETSC_NULL; 59aa644b49SHong Zhang t->Alhs = PETSC_NULL; 6095f0b562SHong Zhang t->matflg = DIFFERENT_NONZERO_PATTERN; 61bdad233fSMatthew Knepley t->snes = PETSC_NULL; 62bdad233fSMatthew Knepley t->funP = PETSC_NULL; 63bdad233fSMatthew Knepley t->jacP = PETSC_NULL; 64bdad233fSMatthew Knepley t->setupcalled = 0; 65bdad233fSMatthew Knepley t->data = PETSC_NULL; 66bdad233fSMatthew Knepley t->user = PETSC_NULL; 67bdad233fSMatthew Knepley t->max_steps = 5000; 68bdad233fSMatthew Knepley t->max_time = 5.0; 69bdad233fSMatthew Knepley t->time_step = .1; 70bdad233fSMatthew Knepley t->time_step_old = t->time_step; 71bdad233fSMatthew Knepley t->initial_time_step = t->time_step; 72bdad233fSMatthew Knepley t->steps = 0; 73bdad233fSMatthew Knepley t->ptime = 0.0; 74bdad233fSMatthew Knepley t->linear_its = 0; 75bdad233fSMatthew Knepley t->nonlinear_its = 0; 76bdad233fSMatthew Knepley t->work = PETSC_NULL; 77bdad233fSMatthew Knepley t->nwork = 0; 78bdad233fSMatthew Knepley 79bdad233fSMatthew Knepley *ts = t; 80bdad233fSMatthew Knepley PetscFunctionReturn(0); 81bdad233fSMatthew Knepley } 82bdad233fSMatthew Knepley 83aa644b49SHong Zhang /* Set A = 1/dt*Alhs - A, B = 1/dt*Blhs - B */ 84b0f6e734SBarry Smith #undef __FUNCT__ 85b0f6e734SBarry Smith #define __FUNCT__ "TSScaleShiftMatrices" 86b0f6e734SBarry Smith PetscErrorCode TSScaleShiftMatrices(TS ts,Mat A,Mat B,MatStructure str) 87b0f6e734SBarry Smith { 88ace3abfcSBarry Smith PetscBool flg; 89b0f6e734SBarry Smith PetscErrorCode ierr; 90efb30889SBarry Smith PetscScalar mdt = 1.0/ts->time_step; 91b0f6e734SBarry Smith 92b0f6e734SBarry Smith PetscFunctionBegin; 936e07ea4bSHong Zhang /* this function requires additional work! */ 948beb423aSHong Zhang ierr = PetscTypeCompare((PetscObject)A,MATMFFD,&flg);CHKERRQ(ierr); 95b0f6e734SBarry Smith if (!flg) { 968beb423aSHong Zhang ierr = MatScale(A,-1.0);CHKERRQ(ierr); 97aa644b49SHong Zhang if (ts->Alhs){ 988beb423aSHong Zhang ierr = MatAXPY(A,mdt,ts->Alhs,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr); 99aa644b49SHong Zhang } else { 1008beb423aSHong Zhang ierr = MatShift(A,mdt);CHKERRQ(ierr); 101b0f6e734SBarry Smith } 102aa644b49SHong Zhang } 1038beb423aSHong Zhang if (B != A && str != SAME_PRECONDITIONER) { 1048beb423aSHong Zhang ierr = MatScale(B,-1.0);CHKERRQ(ierr); 1058beb423aSHong Zhang ierr = MatShift(B,mdt);CHKERRQ(ierr); 106b0f6e734SBarry Smith } 107b0f6e734SBarry Smith PetscFunctionReturn(0); 108b0f6e734SBarry Smith } 109