1292f8084SBarry Smith /* 2292f8084SBarry Smith The PF mathematical functions interface routines, callable by users. 3292f8084SBarry Smith */ 4c6db04a5SJed Brown #include <../src/vec/pf/pfimpl.h> /*I "petscpf.h" I*/ 5292f8084SBarry Smith 60700a824SBarry Smith PetscClassId PF_CLASSID = 0; 737e93019SBarry Smith PetscFunctionList PFList = NULL; /* list of all registered PD functions */ 8ace3abfcSBarry Smith PetscBool PFRegisterAllCalled = PETSC_FALSE; 9292f8084SBarry Smith 10292f8084SBarry Smith /*@C 11292f8084SBarry Smith PFSet - Sets the C/C++/Fortran functions to be used by the PF function 12292f8084SBarry Smith 13292f8084SBarry Smith Collective on PF 14292f8084SBarry Smith 15292f8084SBarry Smith Input Parameter: 16292f8084SBarry Smith + pf - the function context 17292f8084SBarry Smith . apply - function to apply to an array 18292f8084SBarry Smith . applyvec - function to apply to a Vec 19292f8084SBarry Smith . view - function that prints information about the PF 20292f8084SBarry Smith . destroy - function to free the private function context 21292f8084SBarry Smith - ctx - private function context 22292f8084SBarry Smith 23292f8084SBarry Smith Level: beginner 24292f8084SBarry Smith 25292f8084SBarry Smith .seealso: PFCreate(), PFDestroy(), PFSetType(), PFApply(), PFApplyVec() 26292f8084SBarry Smith @*/ 277087cfbeSBarry Smith PetscErrorCode PFSet(PF pf,PetscErrorCode (*apply)(void*,PetscInt,const PetscScalar*,PetscScalar*),PetscErrorCode (*applyvec)(void*,Vec,Vec),PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*destroy)(void*),void*ctx) 28292f8084SBarry Smith { 29292f8084SBarry Smith PetscFunctionBegin; 300700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 31292f8084SBarry Smith pf->data = ctx; 32292f8084SBarry Smith pf->ops->destroy = destroy; 33292f8084SBarry Smith pf->ops->apply = apply; 34292f8084SBarry Smith pf->ops->applyvec = applyvec; 35292f8084SBarry Smith pf->ops->view = view; 36292f8084SBarry Smith PetscFunctionReturn(0); 37292f8084SBarry Smith } 38292f8084SBarry Smith 39292f8084SBarry Smith /*@C 40292f8084SBarry Smith PFDestroy - Destroys PF context that was created with PFCreate(). 41292f8084SBarry Smith 42292f8084SBarry Smith Collective on PF 43292f8084SBarry Smith 44292f8084SBarry Smith Input Parameter: 45292f8084SBarry Smith . pf - the function context 46292f8084SBarry Smith 47292f8084SBarry Smith Level: beginner 48292f8084SBarry Smith 49292f8084SBarry Smith .seealso: PFCreate(), PFSet(), PFSetType() 50292f8084SBarry Smith @*/ 516bf464f9SBarry Smith PetscErrorCode PFDestroy(PF *pf) 52292f8084SBarry Smith { 53292f8084SBarry Smith PetscErrorCode ierr; 54292f8084SBarry Smith 55292f8084SBarry Smith PetscFunctionBegin; 566bf464f9SBarry Smith if (!*pf) PetscFunctionReturn(0); 576bf464f9SBarry Smith PetscValidHeaderSpecific((*pf),PF_CLASSID,1); 586bf464f9SBarry Smith if (--((PetscObject)(*pf))->refct > 0) PetscFunctionReturn(0); 59292f8084SBarry Smith 60ce1779c8SBarry Smith ierr = PFViewFromOptions(*pf,NULL,"-pf_view");CHKERRQ(ierr); 61e04113cfSBarry Smith /* if memory was published with SAWs then destroy it */ 62e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*pf);CHKERRQ(ierr); 63292f8084SBarry Smith 646bf464f9SBarry Smith if ((*pf)->ops->destroy) {ierr = (*(*pf)->ops->destroy)((*pf)->data);CHKERRQ(ierr);} 65d38fa0fbSBarry Smith ierr = PetscHeaderDestroy(pf);CHKERRQ(ierr); 66292f8084SBarry Smith PetscFunctionReturn(0); 67292f8084SBarry Smith } 68292f8084SBarry Smith 69292f8084SBarry Smith /*@C 70292f8084SBarry Smith PFCreate - Creates a mathematical function context. 71292f8084SBarry Smith 72*d083f849SBarry Smith Collective 73292f8084SBarry Smith 74292f8084SBarry Smith Input Parameter: 75292f8084SBarry Smith + comm - MPI communicator 76292f8084SBarry Smith . dimin - dimension of the space you are mapping from 77292f8084SBarry Smith - dimout - dimension of the space you are mapping to 78292f8084SBarry Smith 79292f8084SBarry Smith Output Parameter: 80292f8084SBarry Smith . pf - the function context 81292f8084SBarry Smith 82292f8084SBarry Smith Level: developer 83292f8084SBarry Smith 8403193ff8SBarry Smith .seealso: PFSet(), PFApply(), PFDestroy(), PFApplyVec() 85292f8084SBarry Smith @*/ 867087cfbeSBarry Smith PetscErrorCode PFCreate(MPI_Comm comm,PetscInt dimin,PetscInt dimout,PF *pf) 87292f8084SBarry Smith { 88292f8084SBarry Smith PF newpf; 89292f8084SBarry Smith PetscErrorCode ierr; 90292f8084SBarry Smith 91292f8084SBarry Smith PetscFunctionBegin; 92292f8084SBarry Smith PetscValidPointer(pf,1); 930298fd71SBarry Smith *pf = NULL; 94607a6623SBarry Smith ierr = PFInitializePackage();CHKERRQ(ierr); 95292f8084SBarry Smith 9673107ff1SLisandro Dalcin ierr = PetscHeaderCreate(newpf,PF_CLASSID,"PF","Mathematical functions","Vec",comm,PFDestroy,PFView);CHKERRQ(ierr); 97292f8084SBarry Smith newpf->data = 0; 98292f8084SBarry Smith newpf->ops->destroy = 0; 99292f8084SBarry Smith newpf->ops->apply = 0; 100292f8084SBarry Smith newpf->ops->applyvec = 0; 101292f8084SBarry Smith newpf->ops->view = 0; 102292f8084SBarry Smith newpf->dimin = dimin; 103292f8084SBarry Smith newpf->dimout = dimout; 104292f8084SBarry Smith 105292f8084SBarry Smith *pf = newpf; 106292f8084SBarry Smith PetscFunctionReturn(0); 107292f8084SBarry Smith 108292f8084SBarry Smith } 109292f8084SBarry Smith 110292f8084SBarry Smith /* -------------------------------------------------------------------------------*/ 111292f8084SBarry Smith 112292f8084SBarry Smith /*@ 113292f8084SBarry Smith PFApplyVec - Applies the mathematical function to a vector 114292f8084SBarry Smith 115292f8084SBarry Smith Collective on PF 116292f8084SBarry Smith 117292f8084SBarry Smith Input Parameters: 118292f8084SBarry Smith + pf - the function context 1190298fd71SBarry Smith - x - input vector (or NULL for the vector (0,1, .... N-1) 120292f8084SBarry Smith 121292f8084SBarry Smith Output Parameter: 122292f8084SBarry Smith . y - output vector 123292f8084SBarry Smith 124292f8084SBarry Smith Level: beginner 125292f8084SBarry Smith 126292f8084SBarry Smith .seealso: PFApply(), PFCreate(), PFDestroy(), PFSetType(), PFSet() 127292f8084SBarry Smith @*/ 1287087cfbeSBarry Smith PetscErrorCode PFApplyVec(PF pf,Vec x,Vec y) 129292f8084SBarry Smith { 130292f8084SBarry Smith PetscErrorCode ierr; 131292f8084SBarry Smith PetscInt i,rstart,rend,n,p; 132ace3abfcSBarry Smith PetscBool nox = PETSC_FALSE; 133292f8084SBarry Smith 134292f8084SBarry Smith PetscFunctionBegin; 1350700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 1360700a824SBarry Smith PetscValidHeaderSpecific(y,VEC_CLASSID,3); 137292f8084SBarry Smith if (x) { 1380700a824SBarry Smith PetscValidHeaderSpecific(x,VEC_CLASSID,2); 139e32f2f54SBarry Smith if (x == y) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_IDN,"x and y must be different vectors"); 140292f8084SBarry Smith } else { 141292f8084SBarry Smith PetscScalar *xx; 14203193ff8SBarry Smith PetscInt lsize; 143292f8084SBarry Smith 14403193ff8SBarry Smith ierr = VecGetLocalSize(y,&lsize);CHKERRQ(ierr); 14503193ff8SBarry Smith lsize = pf->dimin*lsize/pf->dimout; 146ce94432eSBarry Smith ierr = VecCreateMPI(PetscObjectComm((PetscObject)y),lsize,PETSC_DETERMINE,&x);CHKERRQ(ierr); 147292f8084SBarry Smith nox = PETSC_TRUE; 148292f8084SBarry Smith ierr = VecGetOwnershipRange(x,&rstart,&rend);CHKERRQ(ierr); 149292f8084SBarry Smith ierr = VecGetArray(x,&xx);CHKERRQ(ierr); 150f6e5521dSKarl Rupp for (i=rstart; i<rend; i++) xx[i-rstart] = (PetscScalar)i; 151292f8084SBarry Smith ierr = VecRestoreArray(x,&xx);CHKERRQ(ierr); 152292f8084SBarry Smith } 153292f8084SBarry Smith 154292f8084SBarry Smith ierr = VecGetLocalSize(x,&n);CHKERRQ(ierr); 155292f8084SBarry Smith ierr = VecGetLocalSize(y,&p);CHKERRQ(ierr); 156e32f2f54SBarry Smith if ((pf->dimin*(n/pf->dimin)) != n) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"Local input vector length %D not divisible by dimin %D of function",n,pf->dimin); 157e32f2f54SBarry Smith if ((pf->dimout*(p/pf->dimout)) != p) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"Local output vector length %D not divisible by dimout %D of function",p,pf->dimout); 158e32f2f54SBarry Smith if ((n/pf->dimin) != (p/pf->dimout)) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"Local vector lengths %D %D are wrong for dimin and dimout %D %D of function",n,p,pf->dimin,pf->dimout); 159292f8084SBarry Smith 160292f8084SBarry Smith if (pf->ops->applyvec) { 161292f8084SBarry Smith ierr = (*pf->ops->applyvec)(pf->data,x,y);CHKERRQ(ierr); 162292f8084SBarry Smith } else { 163292f8084SBarry Smith PetscScalar *xx,*yy; 164292f8084SBarry Smith 165292f8084SBarry Smith ierr = VecGetLocalSize(x,&n);CHKERRQ(ierr); 166292f8084SBarry Smith n = n/pf->dimin; 167292f8084SBarry Smith ierr = VecGetArray(x,&xx);CHKERRQ(ierr); 168292f8084SBarry Smith ierr = VecGetArray(y,&yy);CHKERRQ(ierr); 169e32f2f54SBarry Smith if (!pf->ops->apply) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"No function has been provided for this PF"); 170292f8084SBarry Smith ierr = (*pf->ops->apply)(pf->data,n,xx,yy);CHKERRQ(ierr); 171292f8084SBarry Smith ierr = VecRestoreArray(x,&xx);CHKERRQ(ierr); 172292f8084SBarry Smith ierr = VecRestoreArray(y,&yy);CHKERRQ(ierr); 173292f8084SBarry Smith } 174292f8084SBarry Smith if (nox) { 1756bf464f9SBarry Smith ierr = VecDestroy(&x);CHKERRQ(ierr); 176292f8084SBarry Smith } 177292f8084SBarry Smith PetscFunctionReturn(0); 178292f8084SBarry Smith } 179292f8084SBarry Smith 180292f8084SBarry Smith /*@ 181292f8084SBarry Smith PFApply - Applies the mathematical function to an array of values. 182292f8084SBarry Smith 183292f8084SBarry Smith Collective on PF 184292f8084SBarry Smith 185292f8084SBarry Smith Input Parameters: 186292f8084SBarry Smith + pf - the function context 187292f8084SBarry Smith . n - number of pointwise function evaluations to perform, each pointwise function evaluation 188292f8084SBarry Smith is a function of dimin variables and computes dimout variables where dimin and dimout are defined 189292f8084SBarry Smith in the call to PFCreate() 190292f8084SBarry Smith - x - input array 191292f8084SBarry Smith 192292f8084SBarry Smith Output Parameter: 193292f8084SBarry Smith . y - output array 194292f8084SBarry Smith 195292f8084SBarry Smith Level: beginner 196292f8084SBarry Smith 197292f8084SBarry Smith Notes: 198292f8084SBarry Smith 199292f8084SBarry Smith .seealso: PFApplyVec(), PFCreate(), PFDestroy(), PFSetType(), PFSet() 200292f8084SBarry Smith @*/ 2017087cfbeSBarry Smith PetscErrorCode PFApply(PF pf,PetscInt n,const PetscScalar *x,PetscScalar *y) 202292f8084SBarry Smith { 203292f8084SBarry Smith PetscErrorCode ierr; 204292f8084SBarry Smith 205292f8084SBarry Smith PetscFunctionBegin; 2060700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 207292f8084SBarry Smith PetscValidScalarPointer(x,2); 208292f8084SBarry Smith PetscValidScalarPointer(y,3); 209e32f2f54SBarry Smith if (x == y) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_IDN,"x and y must be different arrays"); 210e32f2f54SBarry Smith if (!pf->ops->apply) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"No function has been provided for this PF"); 211292f8084SBarry Smith 212292f8084SBarry Smith ierr = (*pf->ops->apply)(pf->data,n,x,y);CHKERRQ(ierr); 213292f8084SBarry Smith PetscFunctionReturn(0); 214292f8084SBarry Smith } 215292f8084SBarry Smith 216292f8084SBarry Smith /*@ 217292f8084SBarry Smith PFView - Prints information about a mathematical function 218292f8084SBarry Smith 219292f8084SBarry Smith Collective on PF unless PetscViewer is PETSC_VIEWER_STDOUT_SELF 220292f8084SBarry Smith 221292f8084SBarry Smith Input Parameters: 222292f8084SBarry Smith + PF - the PF context 223292f8084SBarry Smith - viewer - optional visualization context 224292f8084SBarry Smith 225292f8084SBarry Smith Note: 226292f8084SBarry Smith The available visualization contexts include 227292f8084SBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 228292f8084SBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 229292f8084SBarry Smith output where only the first processor opens 230292f8084SBarry Smith the file. All other processors send their 231292f8084SBarry Smith data to the first processor to print. 232292f8084SBarry Smith 233292f8084SBarry Smith The user can open an alternative visualization contexts with 234292f8084SBarry Smith PetscViewerASCIIOpen() (output to a specified file). 235292f8084SBarry Smith 236292f8084SBarry Smith Level: developer 237292f8084SBarry Smith 238292f8084SBarry Smith .seealso: PetscViewerCreate(), PetscViewerASCIIOpen() 239292f8084SBarry Smith @*/ 2407087cfbeSBarry Smith PetscErrorCode PFView(PF pf,PetscViewer viewer) 241292f8084SBarry Smith { 242292f8084SBarry Smith PetscErrorCode ierr; 243ace3abfcSBarry Smith PetscBool iascii; 244292f8084SBarry Smith PetscViewerFormat format; 245292f8084SBarry Smith 246292f8084SBarry Smith PetscFunctionBegin; 2470700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 2483050cee2SBarry Smith if (!viewer) { 249ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)pf),&viewer);CHKERRQ(ierr); 2503050cee2SBarry Smith } 2510700a824SBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 252292f8084SBarry Smith PetscCheckSameComm(pf,1,viewer,2); 253292f8084SBarry Smith 254251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 255292f8084SBarry Smith if (iascii) { 256292f8084SBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 257dae58748SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)pf,viewer);CHKERRQ(ierr); 258292f8084SBarry Smith if (pf->ops->view) { 259292f8084SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 260292f8084SBarry Smith ierr = (*pf->ops->view)(pf->data,viewer);CHKERRQ(ierr); 261292f8084SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 262292f8084SBarry Smith } 263292f8084SBarry Smith } 264292f8084SBarry Smith PetscFunctionReturn(0); 265292f8084SBarry Smith } 266292f8084SBarry Smith 267292f8084SBarry Smith 268bdf89e91SBarry Smith /*@C 269bdf89e91SBarry Smith PFRegister - Adds a method to the mathematical function package. 270292f8084SBarry Smith 271292f8084SBarry Smith Not collective 272292f8084SBarry Smith 273292f8084SBarry Smith Input Parameters: 274292f8084SBarry Smith + name_solver - name of a new user-defined solver 275292f8084SBarry Smith - routine_create - routine to create method context 276292f8084SBarry Smith 277292f8084SBarry Smith Notes: 2781c84c290SBarry Smith PFRegister() may be called multiple times to add several user-defined functions 279292f8084SBarry Smith 280292f8084SBarry Smith Sample usage: 281292f8084SBarry Smith .vb 282bdf89e91SBarry Smith PFRegister("my_function",MyFunctionSetCreate); 283292f8084SBarry Smith .ve 284292f8084SBarry Smith 285292f8084SBarry Smith Then, your solver can be chosen with the procedural interface via 286292f8084SBarry Smith $ PFSetType(pf,"my_function") 287292f8084SBarry Smith or at runtime via the option 288292f8084SBarry Smith $ -pf_type my_function 289292f8084SBarry Smith 290292f8084SBarry Smith Level: advanced 291292f8084SBarry Smith 292292f8084SBarry Smith .seealso: PFRegisterAll(), PFRegisterDestroy(), PFRegister() 293bdf89e91SBarry Smith @*/ 294bdf89e91SBarry Smith PetscErrorCode PFRegister(const char sname[],PetscErrorCode (*function)(PF,void*)) 295292f8084SBarry Smith { 296292f8084SBarry Smith PetscErrorCode ierr; 297292f8084SBarry Smith 298292f8084SBarry Smith PetscFunctionBegin; 2991d36bdfdSBarry Smith ierr = PFInitializePackage();CHKERRQ(ierr); 30037e93019SBarry Smith ierr = PetscFunctionListAdd(&PFList,sname,function);CHKERRQ(ierr); 301292f8084SBarry Smith PetscFunctionReturn(0); 302292f8084SBarry Smith } 303292f8084SBarry Smith 304292f8084SBarry Smith /*@C 305292f8084SBarry Smith PFGetType - Gets the PF method type and name (as a string) from the PF 306292f8084SBarry Smith context. 307292f8084SBarry Smith 308292f8084SBarry Smith Not Collective 309292f8084SBarry Smith 310292f8084SBarry Smith Input Parameter: 311292f8084SBarry Smith . pf - the function context 312292f8084SBarry Smith 313292f8084SBarry Smith Output Parameter: 314c4e43342SLisandro Dalcin . type - name of function 315292f8084SBarry Smith 316292f8084SBarry Smith Level: intermediate 317292f8084SBarry Smith 318292f8084SBarry Smith .seealso: PFSetType() 319292f8084SBarry Smith 320292f8084SBarry Smith @*/ 32119fd82e9SBarry Smith PetscErrorCode PFGetType(PF pf,PFType *type) 322292f8084SBarry Smith { 323292f8084SBarry Smith PetscFunctionBegin; 3240700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 325c4e43342SLisandro Dalcin PetscValidPointer(type,2); 326c4e43342SLisandro Dalcin *type = ((PetscObject)pf)->type_name; 327292f8084SBarry Smith PetscFunctionReturn(0); 328292f8084SBarry Smith } 329292f8084SBarry Smith 330292f8084SBarry Smith 331292f8084SBarry Smith /*@C 332292f8084SBarry Smith PFSetType - Builds PF for a particular function 333292f8084SBarry Smith 334292f8084SBarry Smith Collective on PF 335292f8084SBarry Smith 336292f8084SBarry Smith Input Parameter: 337292f8084SBarry Smith + pf - the function context. 338292f8084SBarry Smith . type - a known method 339292f8084SBarry Smith - ctx - optional type dependent context 340292f8084SBarry Smith 341292f8084SBarry Smith Options Database Key: 342292f8084SBarry Smith . -pf_type <type> - Sets PF type 343292f8084SBarry Smith 344292f8084SBarry Smith 345292f8084SBarry Smith Notes: 346292f8084SBarry Smith See "petsc/include/petscpf.h" for available methods (for instance, 347292f8084SBarry Smith PFCONSTANT) 348292f8084SBarry Smith 349292f8084SBarry Smith Level: intermediate 350292f8084SBarry Smith 3511c84c290SBarry Smith .seealso: PFSet(), PFRegister(), PFCreate(), DMDACreatePF() 352292f8084SBarry Smith 353292f8084SBarry Smith @*/ 35419fd82e9SBarry Smith PetscErrorCode PFSetType(PF pf,PFType type,void *ctx) 355292f8084SBarry Smith { 356292f8084SBarry Smith PetscErrorCode ierr,(*r)(PF,void*); 357ace3abfcSBarry Smith PetscBool match; 358292f8084SBarry Smith 359292f8084SBarry Smith PetscFunctionBegin; 3600700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 361292f8084SBarry Smith PetscValidCharPointer(type,2); 362292f8084SBarry Smith 363251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)pf,type,&match);CHKERRQ(ierr); 364292f8084SBarry Smith if (match) PetscFunctionReturn(0); 365292f8084SBarry Smith 366292f8084SBarry Smith if (pf->ops->destroy) {ierr = (*pf->ops->destroy)(pf);CHKERRQ(ierr);} 367292f8084SBarry Smith pf->data = 0; 368292f8084SBarry Smith 369292f8084SBarry Smith /* Determine the PFCreateXXX routine for a particular function */ 37037e93019SBarry Smith ierr = PetscFunctionListFind(PFList,type,&r);CHKERRQ(ierr); 371e32f2f54SBarry Smith if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested PF type %s",type); 372292f8084SBarry Smith pf->ops->destroy = 0; 373292f8084SBarry Smith pf->ops->view = 0; 374292f8084SBarry Smith pf->ops->apply = 0; 375292f8084SBarry Smith pf->ops->applyvec = 0; 376292f8084SBarry Smith 377292f8084SBarry Smith /* Call the PFCreateXXX routine for this particular function */ 378292f8084SBarry Smith ierr = (*r)(pf,ctx);CHKERRQ(ierr); 379292f8084SBarry Smith 380292f8084SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)pf,type);CHKERRQ(ierr); 381292f8084SBarry Smith PetscFunctionReturn(0); 382292f8084SBarry Smith } 383292f8084SBarry Smith 384292f8084SBarry Smith /*@ 385292f8084SBarry Smith PFSetFromOptions - Sets PF options from the options database. 386292f8084SBarry Smith 387292f8084SBarry Smith Collective on PF 388292f8084SBarry Smith 389292f8084SBarry Smith Input Parameters: 390292f8084SBarry Smith . pf - the mathematical function context 391292f8084SBarry Smith 392292f8084SBarry Smith Options Database Keys: 393292f8084SBarry Smith 394292f8084SBarry Smith Notes: 395292f8084SBarry Smith To see all options, run your program with the -help option 396292f8084SBarry Smith or consult the users manual. 397292f8084SBarry Smith 398292f8084SBarry Smith Level: intermediate 399292f8084SBarry Smith 400292f8084SBarry Smith .seealso: 401292f8084SBarry Smith @*/ 4027087cfbeSBarry Smith PetscErrorCode PFSetFromOptions(PF pf) 403292f8084SBarry Smith { 404292f8084SBarry Smith PetscErrorCode ierr; 405292f8084SBarry Smith char type[256]; 406ace3abfcSBarry Smith PetscBool flg; 407292f8084SBarry Smith 408292f8084SBarry Smith PetscFunctionBegin; 4090700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 410292f8084SBarry Smith 4113194b578SJed Brown ierr = PetscObjectOptionsBegin((PetscObject)pf);CHKERRQ(ierr); 412a264d7a6SBarry Smith ierr = PetscOptionsFList("-pf_type","Type of function","PFSetType",PFList,0,type,256,&flg);CHKERRQ(ierr); 413292f8084SBarry Smith if (flg) { 4140298fd71SBarry Smith ierr = PFSetType(pf,type,NULL);CHKERRQ(ierr); 415292f8084SBarry Smith } 416292f8084SBarry Smith if (pf->ops->setfromoptions) { 417e55864a3SBarry Smith ierr = (*pf->ops->setfromoptions)(PetscOptionsObject,pf);CHKERRQ(ierr); 418292f8084SBarry Smith } 4195d973c19SBarry Smith 4205d973c19SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 4210633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject)pf);CHKERRQ(ierr); 422292f8084SBarry Smith ierr = PetscOptionsEnd();CHKERRQ(ierr); 423292f8084SBarry Smith PetscFunctionReturn(0); 424292f8084SBarry Smith } 425292f8084SBarry Smith 426ace3abfcSBarry Smith static PetscBool PFPackageInitialized = PETSC_FALSE; 427b022a5c1SBarry Smith /*@C 428b022a5c1SBarry Smith PFFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is 429b022a5c1SBarry Smith called from PetscFinalize(). 430b022a5c1SBarry Smith 431b022a5c1SBarry Smith Level: developer 432b022a5c1SBarry Smith 433b022a5c1SBarry Smith .seealso: PetscFinalize() 434b022a5c1SBarry Smith @*/ 4357087cfbeSBarry Smith PetscErrorCode PFFinalizePackage(void) 436b022a5c1SBarry Smith { 43737e93019SBarry Smith PetscErrorCode ierr; 43837e93019SBarry Smith 439b022a5c1SBarry Smith PetscFunctionBegin; 44037e93019SBarry Smith ierr = PetscFunctionListDestroy(&PFList);CHKERRQ(ierr); 441b022a5c1SBarry Smith PFPackageInitialized = PETSC_FALSE; 442b022a5c1SBarry Smith PFRegisterAllCalled = PETSC_FALSE; 443b022a5c1SBarry Smith PetscFunctionReturn(0); 444b022a5c1SBarry Smith } 445b022a5c1SBarry Smith 4469877f0dbSBarry Smith /*@C 4479877f0dbSBarry Smith PFInitializePackage - This function initializes everything in the PF package. It is called 4488a690491SBarry Smith from PetscDLLibraryRegister_petscvec() when using dynamic libraries, and on the first call to PFCreate() 4498a690491SBarry Smith when using shared or static libraries. 4509877f0dbSBarry Smith 4519877f0dbSBarry Smith Level: developer 4529877f0dbSBarry Smith 4539877f0dbSBarry Smith .seealso: PetscInitialize() 4549877f0dbSBarry Smith @*/ 455607a6623SBarry Smith PetscErrorCode PFInitializePackage(void) 4569877f0dbSBarry Smith { 4579877f0dbSBarry Smith char logList[256]; 4588e81d068SLisandro Dalcin PetscBool opt,pkg; 4599877f0dbSBarry Smith PetscErrorCode ierr; 4609877f0dbSBarry Smith 4619877f0dbSBarry Smith PetscFunctionBegin; 462b022a5c1SBarry Smith if (PFPackageInitialized) PetscFunctionReturn(0); 463b022a5c1SBarry Smith PFPackageInitialized = PETSC_TRUE; 4649877f0dbSBarry Smith /* Register Classes */ 4650700a824SBarry Smith ierr = PetscClassIdRegister("PointFunction",&PF_CLASSID);CHKERRQ(ierr); 4669877f0dbSBarry Smith /* Register Constructors */ 467607a6623SBarry Smith ierr = PFRegisterAll();CHKERRQ(ierr); 4689877f0dbSBarry Smith /* Process info exclusions */ 4698e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 4709877f0dbSBarry Smith if (opt) { 4718e81d068SLisandro Dalcin ierr = PetscStrInList("pf",logList,',',&pkg);CHKERRQ(ierr); 4728e81d068SLisandro Dalcin if (pkg) {ierr = PetscInfoDeactivateClass(PF_CLASSID);CHKERRQ(ierr);} 4739877f0dbSBarry Smith } 4749877f0dbSBarry Smith /* Process summary exclusions */ 4758e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 4769877f0dbSBarry Smith if (opt) { 4778e81d068SLisandro Dalcin ierr = PetscStrInList("pf",logList,',',&pkg);CHKERRQ(ierr); 478fa2bb9feSLisandro Dalcin if (pkg) {ierr = PetscLogEventExcludeClass(PF_CLASSID);CHKERRQ(ierr);} 4799877f0dbSBarry Smith } 4808e81d068SLisandro Dalcin /* Register package finalizer */ 481b022a5c1SBarry Smith ierr = PetscRegisterFinalize(PFFinalizePackage);CHKERRQ(ierr); 4829877f0dbSBarry Smith PetscFunctionReturn(0); 4839877f0dbSBarry Smith } 484292f8084SBarry Smith 485292f8084SBarry Smith 486292f8084SBarry Smith 487292f8084SBarry Smith 488292f8084SBarry Smith 489292f8084SBarry Smith 490292f8084SBarry Smith 491292f8084SBarry Smith 492292f8084SBarry Smith 493