1bc952696SBarry Smith 2af0996ceSBarry Smith #include <petsc/private/tsimpl.h> /*I "petscts.h" I*/ 3bc952696SBarry Smith 4bc952696SBarry Smith PetscFunctionList TSTrajectoryList = NULL; 5bc952696SBarry Smith PetscBool TSTrajectoryRegisterAllCalled = PETSC_FALSE; 6bc952696SBarry Smith PetscClassId TSTRAJECTORY_CLASSID; 7bc952696SBarry Smith 8bc952696SBarry Smith #undef __FUNCT__ 9bc952696SBarry Smith #define __FUNCT__ "TSTrajectoryRegister" 10bc952696SBarry Smith /*@C 11bc952696SBarry Smith TSTrajectoryRegister - Adds a way of storing trajectories to the TS package 12bc952696SBarry Smith 13bc952696SBarry Smith Not Collective 14bc952696SBarry Smith 15bc952696SBarry Smith Input Parameters: 16bc952696SBarry Smith + name - The name of a new user-defined creation routine 17bc952696SBarry Smith - create_func - The creation routine itself 18bc952696SBarry Smith 19bc952696SBarry Smith Notes: 20bc952696SBarry Smith TSTrajectoryRegister() may be called multiple times to add several user-defined tses. 21bc952696SBarry Smith 22bc952696SBarry Smith Level: advanced 23bc952696SBarry Smith 24bc952696SBarry Smith .keywords: TS, register 25bc952696SBarry Smith 26bc952696SBarry Smith .seealso: TSTrajectoryRegisterAll(), TSTrajectoryRegisterDestroy() 27bc952696SBarry Smith @*/ 28bc952696SBarry Smith PetscErrorCode TSTrajectoryRegister(const char sname[], PetscErrorCode (*function)(TSTrajectory)) 29bc952696SBarry Smith { 30bc952696SBarry Smith PetscErrorCode ierr; 31bc952696SBarry Smith 32bc952696SBarry Smith PetscFunctionBegin; 33bc952696SBarry Smith ierr = PetscFunctionListAdd(&TSTrajectoryList,sname,function);CHKERRQ(ierr); 34bc952696SBarry Smith PetscFunctionReturn(0); 35bc952696SBarry Smith } 36bc952696SBarry Smith 37bc952696SBarry Smith #undef __FUNCT__ 38bc952696SBarry Smith #define __FUNCT__ "TSTrajectorySet" 39bc952696SBarry Smith PetscErrorCode TSTrajectorySet(TSTrajectory tj,TS ts,PetscInt stepnum,PetscReal time,Vec X) 40bc952696SBarry Smith { 41bc952696SBarry Smith PetscErrorCode ierr; 42bc952696SBarry Smith 43bc952696SBarry Smith PetscFunctionBegin; 44bc952696SBarry Smith if (!tj) PetscFunctionReturn(0); 45bc952696SBarry Smith ierr = (*tj->ops->set)(tj,ts,stepnum,time,X);CHKERRQ(ierr); 46bc952696SBarry Smith PetscFunctionReturn(0); 47bc952696SBarry Smith } 48bc952696SBarry Smith 49bc952696SBarry Smith #undef __FUNCT__ 50bc952696SBarry Smith #define __FUNCT__ "TSTrajectoryGet" 51bc952696SBarry Smith PetscErrorCode TSTrajectoryGet(TSTrajectory tj,TS ts,PetscInt stepnum,PetscReal time) 52bc952696SBarry Smith { 53bc952696SBarry Smith PetscErrorCode ierr; 54bc952696SBarry Smith 55bc952696SBarry Smith PetscFunctionBegin; 56bc952696SBarry Smith if (!tj) SETERRQ(PetscObjectComm((PetscObject)ts),PETSC_ERR_ARG_WRONGSTATE,"TS solver did not save trajectory"); 57bc952696SBarry Smith ierr = (*tj->ops->get)(tj,ts,stepnum,time);CHKERRQ(ierr); 58bc952696SBarry Smith PetscFunctionReturn(0); 59bc952696SBarry Smith } 60bc952696SBarry Smith 61bc952696SBarry Smith #undef __FUNCT__ 62bc952696SBarry Smith #define __FUNCT__ "TSTrajectoryView" 63bc952696SBarry Smith /*@C 64bc952696SBarry Smith TSTrajectoryView - Prints information about the trajectory object 65bc952696SBarry Smith 66bc952696SBarry Smith Collective on TSTrajectory 67bc952696SBarry Smith 68bc952696SBarry Smith Input Parameters: 69bc952696SBarry Smith + ts - the TSTrajectory context obtained from TSTrajectoryCreate() 70bc952696SBarry Smith - viewer - visualization context 71bc952696SBarry Smith 72bc952696SBarry Smith Options Database Key: 73bc952696SBarry Smith . -ts_view - calls TSView() at end of TSStep() 74bc952696SBarry Smith 75bc952696SBarry Smith Notes: 76bc952696SBarry Smith The available visualization contexts include 77bc952696SBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 78bc952696SBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 79bc952696SBarry Smith output where only the first processor opens 80bc952696SBarry Smith the file. All other processors send their 81bc952696SBarry Smith data to the first processor to print. 82bc952696SBarry Smith 83bc952696SBarry Smith The user can open an alternative visualization context with 84bc952696SBarry Smith PetscViewerASCIIOpen() - output to a specified file. 85bc952696SBarry Smith 86bc952696SBarry Smith Level: beginner 87bc952696SBarry Smith 88bc952696SBarry Smith .keywords: TS, timestep, view 89bc952696SBarry Smith 90bc952696SBarry Smith .seealso: PetscViewerASCIIOpen() 91bc952696SBarry Smith @*/ 92bc952696SBarry Smith PetscErrorCode TSTrajectoryView(TSTrajectory ts,PetscViewer viewer) 93bc952696SBarry Smith { 94bc952696SBarry Smith PetscErrorCode ierr; 95bc952696SBarry Smith PetscBool iascii; 96bc952696SBarry Smith 97bc952696SBarry Smith PetscFunctionBegin; 98bc952696SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 99bc952696SBarry Smith if (!viewer) { 100bc952696SBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)ts),&viewer);CHKERRQ(ierr); 101bc952696SBarry Smith } 102bc952696SBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 103bc952696SBarry Smith PetscCheckSameComm(ts,1,viewer,2); 104bc952696SBarry Smith 105bc952696SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 106bc952696SBarry Smith if (iascii) { 107bc952696SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)ts,viewer);CHKERRQ(ierr); 108bc952696SBarry Smith if (ts->ops->view) { 109bc952696SBarry Smith ierr = (*ts->ops->view)(ts,viewer);CHKERRQ(ierr); 110bc952696SBarry Smith } 111bc952696SBarry Smith } 112bc952696SBarry Smith PetscFunctionReturn(0); 113bc952696SBarry Smith } 114bc952696SBarry Smith 115bc952696SBarry Smith #undef __FUNCT__ 116bc952696SBarry Smith #define __FUNCT__ "TSTrajectoryCreate" 117bc952696SBarry Smith /*@C 118bc952696SBarry Smith TSTrajectoryCreate - This function creates an empty trajectory object used to store the time dependent solution of an ODE/DAE 119bc952696SBarry Smith 120bc952696SBarry Smith Collective on MPI_Comm 121bc952696SBarry Smith 122bc952696SBarry Smith Input Parameter: 123bc952696SBarry Smith . comm - The communicator 124bc952696SBarry Smith 125bc952696SBarry Smith Output Parameter: 126bc952696SBarry Smith . tstra - The trajectory object 127bc952696SBarry Smith 128bc952696SBarry Smith Level: advanced 129bc952696SBarry Smith 130bc952696SBarry Smith Notes: Usually one does not call this routine, it is called automatically when one calls TSSetSaveTrajectory(). One can call 131bc952696SBarry Smith TSGetTrajectory() to access the created trajectory. 132bc952696SBarry Smith 133bc952696SBarry Smith .keywords: TS, create 134bc952696SBarry Smith .seealso: TSSetType(), TSSetUp(), TSDestroy(), TSSetProblemType(), TSGetTrajectory() 135bc952696SBarry Smith @*/ 136bc952696SBarry Smith PetscErrorCode TSTrajectoryCreate(MPI_Comm comm, TSTrajectory *tstra) 137bc952696SBarry Smith { 138bc952696SBarry Smith TSTrajectory t; 139bc952696SBarry Smith PetscErrorCode ierr; 140bc952696SBarry Smith 141bc952696SBarry Smith PetscFunctionBegin; 142bc952696SBarry Smith PetscValidPointer(tstra,1); 143bc952696SBarry Smith *tstra = NULL; 144bc952696SBarry Smith ierr = TSInitializePackage();CHKERRQ(ierr); 145bc952696SBarry Smith 146*73107ff1SLisandro Dalcin ierr = PetscHeaderCreate(t, TSTRAJECTORY_CLASSID, "TSTrajectory", "Time stepping", "TS", comm, TSTrajectoryDestroy, TSTrajectoryView);CHKERRQ(ierr); 147bc952696SBarry Smith *tstra = t; 148bc952696SBarry Smith PetscFunctionReturn(0); 149bc952696SBarry Smith } 150bc952696SBarry Smith 151bc952696SBarry Smith #undef __FUNCT__ 152bc952696SBarry Smith #define __FUNCT__ "TSTrajectorySetType" 153bc952696SBarry Smith /*@C 154bc952696SBarry Smith TSTrajectorySetType - Sets the storage method to be used as in a trajectory 155bc952696SBarry Smith 156bc952696SBarry Smith Collective on TS 157bc952696SBarry Smith 158bc952696SBarry Smith Input Parameters: 159bc952696SBarry Smith + ts - The TS context 160bc952696SBarry Smith - type - A known method 161bc952696SBarry Smith 162bc952696SBarry Smith Options Database Command: 163bc952696SBarry Smith . -tstrajectory_type <type> - Sets the method; use -help for a list of available methods (for instance, basic) 164bc952696SBarry Smith 165bc952696SBarry Smith Level: intermediate 166bc952696SBarry Smith 167bc952696SBarry Smith .keywords: TS, set, type 168bc952696SBarry Smith 169bc952696SBarry Smith .seealso: TS, TSSolve(), TSCreate(), TSSetFromOptions(), TSDestroy(), TSType 170bc952696SBarry Smith 171bc952696SBarry Smith @*/ 17239408270SBarry Smith PetscErrorCode TSTrajectorySetType(TSTrajectory ts,const TSTrajectoryType type) 173bc952696SBarry Smith { 174bc952696SBarry Smith PetscErrorCode (*r)(TSTrajectory); 175bc952696SBarry Smith PetscBool match; 176bc952696SBarry Smith PetscErrorCode ierr; 177bc952696SBarry Smith 178bc952696SBarry Smith PetscFunctionBegin; 179bc952696SBarry Smith PetscValidHeaderSpecific(ts, TSTRAJECTORY_CLASSID,1); 180bc952696SBarry Smith ierr = PetscObjectTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr); 181bc952696SBarry Smith if (match) PetscFunctionReturn(0); 182bc952696SBarry Smith 183bc952696SBarry Smith ierr = PetscFunctionListFind(TSTrajectoryList,type,&r);CHKERRQ(ierr); 184bc952696SBarry Smith if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TSTrajectory type: %s", type); 185bc952696SBarry Smith if (ts->ops->destroy) { 186bc952696SBarry Smith ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr); 187bc952696SBarry Smith 188bc952696SBarry Smith ts->ops->destroy = NULL; 189bc952696SBarry Smith } 190bc952696SBarry Smith ierr = PetscMemzero(ts->ops,sizeof(*ts->ops));CHKERRQ(ierr); 191bc952696SBarry Smith 192bc952696SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr); 193bc952696SBarry Smith ierr = (*r)(ts);CHKERRQ(ierr); 194bc952696SBarry Smith PetscFunctionReturn(0); 195bc952696SBarry Smith } 196bc952696SBarry Smith 197bc952696SBarry Smith PETSC_EXTERN PetscErrorCode TSTrajectoryCreate_Basic(TSTrajectory); 1981c8c567eSBarry Smith PETSC_EXTERN PetscErrorCode TSTrajectoryCreate_Singlefile(TSTrajectory); 199bc952696SBarry Smith 200bc952696SBarry Smith #undef __FUNCT__ 201bc952696SBarry Smith #define __FUNCT__ "TSTrajectoryRegisterAll" 202bc952696SBarry Smith /*@C 203bc952696SBarry Smith TSTrajectoryRegisterAll - Registers all of the trajectory storage schecmes in the TS package. 204bc952696SBarry Smith 205bc952696SBarry Smith Not Collective 206bc952696SBarry Smith 207bc952696SBarry Smith Level: advanced 208bc952696SBarry Smith 209bc952696SBarry Smith .keywords: TS, timestepper, register, all 210bc952696SBarry Smith .seealso: TSCreate(), TSRegister(), TSRegisterDestroy() 211bc952696SBarry Smith @*/ 212bc952696SBarry Smith PetscErrorCode TSTrajectoryRegisterAll(void) 213bc952696SBarry Smith { 214bc952696SBarry Smith PetscErrorCode ierr; 215bc952696SBarry Smith 216bc952696SBarry Smith PetscFunctionBegin; 217bc952696SBarry Smith TSTrajectoryRegisterAllCalled = PETSC_TRUE; 218bc952696SBarry Smith 219bc952696SBarry Smith ierr = TSTrajectoryRegister(TSTRAJECTORYBASIC,TSTrajectoryCreate_Basic);CHKERRQ(ierr); 2201c8c567eSBarry Smith ierr = TSTrajectoryRegister(TSTRAJECTORYSINGLEFILE,TSTrajectoryCreate_Singlefile);CHKERRQ(ierr); 221bc952696SBarry Smith PetscFunctionReturn(0); 222bc952696SBarry Smith } 223bc952696SBarry Smith 224bc952696SBarry Smith #undef __FUNCT__ 225bc952696SBarry Smith #define __FUNCT__ "TSTrajectoryDestroy" 226bc952696SBarry Smith /*@ 227bc952696SBarry Smith TSTrajectoryDestroy - Destroys a trajectory context 228bc952696SBarry Smith 229bc952696SBarry Smith Collective on TSTrajectory 230bc952696SBarry Smith 231bc952696SBarry Smith Input Parameter: 232bc952696SBarry Smith . ts - the TSTrajectory context obtained from TSTrajectoryCreate() 233bc952696SBarry Smith 234bc952696SBarry Smith Level: advanced 235bc952696SBarry Smith 236bc952696SBarry Smith .keywords: TS, timestepper, destroy 237bc952696SBarry Smith 238bc952696SBarry Smith .seealso: TSCreate(), TSSetUp(), TSSolve() 239bc952696SBarry Smith @*/ 240bc952696SBarry Smith PetscErrorCode TSTrajectoryDestroy(TSTrajectory *ts) 241bc952696SBarry Smith { 242bc952696SBarry Smith PetscErrorCode ierr; 243bc952696SBarry Smith 244bc952696SBarry Smith PetscFunctionBegin; 245bc952696SBarry Smith if (!*ts) PetscFunctionReturn(0); 246bc952696SBarry Smith PetscValidHeaderSpecific((*ts),TSTRAJECTORY_CLASSID,1); 247bc952696SBarry Smith if (--((PetscObject)(*ts))->refct > 0) {*ts = 0; PetscFunctionReturn(0);} 248bc952696SBarry Smith 249bc952696SBarry Smith if ((*ts)->ops->destroy) {ierr = (*(*ts)->ops->destroy)((*ts));CHKERRQ(ierr);} 250bc952696SBarry Smith ierr = PetscHeaderDestroy(ts);CHKERRQ(ierr); 251bc952696SBarry Smith PetscFunctionReturn(0); 252bc952696SBarry Smith } 253bc952696SBarry Smith 254bc952696SBarry Smith #undef __FUNCT__ 255772b2523SBarry Smith #define __FUNCT__ "TSTrajectorySetTypeFromOptions_Private" 256bc952696SBarry Smith /* 257772b2523SBarry Smith TSTrajectorySetTypeFromOptions_Private - Sets the type of ts from user options. 258bc952696SBarry Smith 259bc952696SBarry Smith Collective on TSTrajectory 260bc952696SBarry Smith 261bc952696SBarry Smith Input Parameter: 262bc952696SBarry Smith . ts - The ts 263bc952696SBarry Smith 264bc952696SBarry Smith Level: intermediate 265bc952696SBarry Smith 266bc952696SBarry Smith .keywords: TS, set, options, database, type 267bc952696SBarry Smith .seealso: TSSetFromOptions(), TSSetType() 268bc952696SBarry Smith */ 269772b2523SBarry Smith static PetscErrorCode TSTrajectorySetTypeFromOptions_Private(PetscOptions *PetscOptionsObject,TSTrajectory ts) 270bc952696SBarry Smith { 271bc952696SBarry Smith PetscBool opt; 272bc952696SBarry Smith const char *defaultType; 273bc952696SBarry Smith char typeName[256]; 274bc952696SBarry Smith PetscErrorCode ierr; 275bc952696SBarry Smith 276bc952696SBarry Smith PetscFunctionBegin; 277bc952696SBarry Smith if (((PetscObject)ts)->type_name) defaultType = ((PetscObject)ts)->type_name; 278bc952696SBarry Smith else defaultType = TSTRAJECTORYBASIC; 279bc952696SBarry Smith 280bc952696SBarry Smith if (!TSRegisterAllCalled) {ierr = TSTrajectoryRegisterAll();CHKERRQ(ierr);} 281bc952696SBarry Smith ierr = PetscOptionsFList("-tstrajectory_type", "TSTrajectory method"," TSTrajectorySetType", TSTrajectoryList, defaultType, typeName, 256, &opt);CHKERRQ(ierr); 282bc952696SBarry Smith if (opt) { 283bc952696SBarry Smith ierr = TSTrajectorySetType(ts, typeName);CHKERRQ(ierr); 284bc952696SBarry Smith } else { 285bc952696SBarry Smith ierr = TSTrajectorySetType(ts, defaultType);CHKERRQ(ierr); 286bc952696SBarry Smith } 287bc952696SBarry Smith PetscFunctionReturn(0); 288bc952696SBarry Smith } 289bc952696SBarry Smith 290bc952696SBarry Smith #undef __FUNCT__ 291bc952696SBarry Smith #define __FUNCT__ "TSTrajectorySetFromOptions" 292bc952696SBarry Smith /*@ 293bc952696SBarry Smith TSTrajectorySetFromOptions - Sets various TSTrajectory parameters from user options. 294bc952696SBarry Smith 295bc952696SBarry Smith Collective on TSTrajectory 296bc952696SBarry Smith 297bc952696SBarry Smith Input Parameter: 298bc952696SBarry Smith . ts - the TSTrajectory context obtained from TSTrajectoryCreate() 299bc952696SBarry Smith 300bc952696SBarry Smith Options Database Keys: 301bc952696SBarry Smith . -tstrajectory_type <type> - TSTRAJECTORYBASIC 302bc952696SBarry Smith 303bc952696SBarry Smith Level: advanced 304bc952696SBarry Smith 305bc952696SBarry Smith Notes: This is not normally called directly by users, instead it is called by TSSetFromOptions() after a call to 306bc952696SBarry Smith TSSetSaveTrajectory() 307bc952696SBarry Smith 308bc952696SBarry Smith .keywords: TS, timestep, set, options, database 309bc952696SBarry Smith 310bc952696SBarry Smith .seealso: TSGetType(), TSSetSaveTrajectory(), TSGetTrajectory() 311bc952696SBarry Smith @*/ 312bc952696SBarry Smith PetscErrorCode TSTrajectorySetFromOptions(TSTrajectory ts) 313bc952696SBarry Smith { 314bc952696SBarry Smith PetscErrorCode ierr; 315bc952696SBarry Smith 316bc952696SBarry Smith PetscFunctionBegin; 317bc952696SBarry Smith PetscValidHeaderSpecific(ts, TSTRAJECTORY_CLASSID,1); 318bc952696SBarry Smith ierr = PetscObjectOptionsBegin((PetscObject)ts);CHKERRQ(ierr); 319772b2523SBarry Smith ierr = TSTrajectorySetTypeFromOptions_Private(PetscOptionsObject,ts);CHKERRQ(ierr); 320bc952696SBarry Smith ierr = PetscOptionsEnd();CHKERRQ(ierr); 321bc952696SBarry Smith PetscFunctionReturn(0); 322bc952696SBarry Smith } 323