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 72d083f849SBarry 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); 97*4c8fdceaSLisandro Dalcin newpf->data = NULL; 98*4c8fdceaSLisandro Dalcin newpf->ops->destroy = NULL; 99*4c8fdceaSLisandro Dalcin newpf->ops->apply = NULL; 100*4c8fdceaSLisandro Dalcin newpf->ops->applyvec = NULL; 101*4c8fdceaSLisandro Dalcin newpf->ops->view = NULL; 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 216fe2efc57SMark /*@C 217fe2efc57SMark PFViewFromOptions - View from Options 218fe2efc57SMark 219fe2efc57SMark Collective on PF 220fe2efc57SMark 221fe2efc57SMark Input Parameters: 222fe2efc57SMark + A - the PF context 223736c3998SJose E. Roman . obj - Optional object 224736c3998SJose E. Roman - name - command line option 225fe2efc57SMark 226fe2efc57SMark Level: intermediate 227fe2efc57SMark .seealso: PF, PFView, PetscObjectViewFromOptions(), PFCreate() 228fe2efc57SMark @*/ 229fe2efc57SMark PetscErrorCode PFViewFromOptions(PF A,PetscObject obj,const char name[]) 230fe2efc57SMark { 231fe2efc57SMark PetscErrorCode ierr; 232fe2efc57SMark 233fe2efc57SMark PetscFunctionBegin; 234fe2efc57SMark PetscValidHeaderSpecific(A,PF_CLASSID,1); 235fe2efc57SMark ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr); 236fe2efc57SMark PetscFunctionReturn(0); 237fe2efc57SMark } 238fe2efc57SMark 239292f8084SBarry Smith /*@ 240292f8084SBarry Smith PFView - Prints information about a mathematical function 241292f8084SBarry Smith 242292f8084SBarry Smith Collective on PF unless PetscViewer is PETSC_VIEWER_STDOUT_SELF 243292f8084SBarry Smith 244292f8084SBarry Smith Input Parameters: 245292f8084SBarry Smith + PF - the PF context 246292f8084SBarry Smith - viewer - optional visualization context 247292f8084SBarry Smith 248292f8084SBarry Smith Note: 249292f8084SBarry Smith The available visualization contexts include 250292f8084SBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 251292f8084SBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 252292f8084SBarry Smith output where only the first processor opens 253292f8084SBarry Smith the file. All other processors send their 254292f8084SBarry Smith data to the first processor to print. 255292f8084SBarry Smith 256292f8084SBarry Smith The user can open an alternative visualization contexts with 257292f8084SBarry Smith PetscViewerASCIIOpen() (output to a specified file). 258292f8084SBarry Smith 259292f8084SBarry Smith Level: developer 260292f8084SBarry Smith 261292f8084SBarry Smith .seealso: PetscViewerCreate(), PetscViewerASCIIOpen() 262292f8084SBarry Smith @*/ 2637087cfbeSBarry Smith PetscErrorCode PFView(PF pf,PetscViewer viewer) 264292f8084SBarry Smith { 265292f8084SBarry Smith PetscErrorCode ierr; 266ace3abfcSBarry Smith PetscBool iascii; 267292f8084SBarry Smith PetscViewerFormat format; 268292f8084SBarry Smith 269292f8084SBarry Smith PetscFunctionBegin; 2700700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 2713050cee2SBarry Smith if (!viewer) { 272ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)pf),&viewer);CHKERRQ(ierr); 2733050cee2SBarry Smith } 2740700a824SBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 275292f8084SBarry Smith PetscCheckSameComm(pf,1,viewer,2); 276292f8084SBarry Smith 277251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 278292f8084SBarry Smith if (iascii) { 279292f8084SBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 280dae58748SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)pf,viewer);CHKERRQ(ierr); 281292f8084SBarry Smith if (pf->ops->view) { 282292f8084SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 283292f8084SBarry Smith ierr = (*pf->ops->view)(pf->data,viewer);CHKERRQ(ierr); 284292f8084SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 285292f8084SBarry Smith } 286292f8084SBarry Smith } 287292f8084SBarry Smith PetscFunctionReturn(0); 288292f8084SBarry Smith } 289292f8084SBarry Smith 290292f8084SBarry Smith 291bdf89e91SBarry Smith /*@C 292bdf89e91SBarry Smith PFRegister - Adds a method to the mathematical function package. 293292f8084SBarry Smith 294292f8084SBarry Smith Not collective 295292f8084SBarry Smith 296292f8084SBarry Smith Input Parameters: 297292f8084SBarry Smith + name_solver - name of a new user-defined solver 298292f8084SBarry Smith - routine_create - routine to create method context 299292f8084SBarry Smith 300292f8084SBarry Smith Notes: 3011c84c290SBarry Smith PFRegister() may be called multiple times to add several user-defined functions 302292f8084SBarry Smith 303292f8084SBarry Smith Sample usage: 304292f8084SBarry Smith .vb 305bdf89e91SBarry Smith PFRegister("my_function",MyFunctionSetCreate); 306292f8084SBarry Smith .ve 307292f8084SBarry Smith 308292f8084SBarry Smith Then, your solver can be chosen with the procedural interface via 309292f8084SBarry Smith $ PFSetType(pf,"my_function") 310292f8084SBarry Smith or at runtime via the option 311292f8084SBarry Smith $ -pf_type my_function 312292f8084SBarry Smith 313292f8084SBarry Smith Level: advanced 314292f8084SBarry Smith 315292f8084SBarry Smith .seealso: PFRegisterAll(), PFRegisterDestroy(), PFRegister() 316bdf89e91SBarry Smith @*/ 317bdf89e91SBarry Smith PetscErrorCode PFRegister(const char sname[],PetscErrorCode (*function)(PF,void*)) 318292f8084SBarry Smith { 319292f8084SBarry Smith PetscErrorCode ierr; 320292f8084SBarry Smith 321292f8084SBarry Smith PetscFunctionBegin; 3221d36bdfdSBarry Smith ierr = PFInitializePackage();CHKERRQ(ierr); 32337e93019SBarry Smith ierr = PetscFunctionListAdd(&PFList,sname,function);CHKERRQ(ierr); 324292f8084SBarry Smith PetscFunctionReturn(0); 325292f8084SBarry Smith } 326292f8084SBarry Smith 327292f8084SBarry Smith /*@C 328292f8084SBarry Smith PFGetType - Gets the PF method type and name (as a string) from the PF 329292f8084SBarry Smith context. 330292f8084SBarry Smith 331292f8084SBarry Smith Not Collective 332292f8084SBarry Smith 333292f8084SBarry Smith Input Parameter: 334292f8084SBarry Smith . pf - the function context 335292f8084SBarry Smith 336292f8084SBarry Smith Output Parameter: 337c4e43342SLisandro Dalcin . type - name of function 338292f8084SBarry Smith 339292f8084SBarry Smith Level: intermediate 340292f8084SBarry Smith 341292f8084SBarry Smith .seealso: PFSetType() 342292f8084SBarry Smith 343292f8084SBarry Smith @*/ 34419fd82e9SBarry Smith PetscErrorCode PFGetType(PF pf,PFType *type) 345292f8084SBarry Smith { 346292f8084SBarry Smith PetscFunctionBegin; 3470700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 348c4e43342SLisandro Dalcin PetscValidPointer(type,2); 349c4e43342SLisandro Dalcin *type = ((PetscObject)pf)->type_name; 350292f8084SBarry Smith PetscFunctionReturn(0); 351292f8084SBarry Smith } 352292f8084SBarry Smith 353292f8084SBarry Smith 354292f8084SBarry Smith /*@C 355292f8084SBarry Smith PFSetType - Builds PF for a particular function 356292f8084SBarry Smith 357292f8084SBarry Smith Collective on PF 358292f8084SBarry Smith 359292f8084SBarry Smith Input Parameter: 360292f8084SBarry Smith + pf - the function context. 361292f8084SBarry Smith . type - a known method 362292f8084SBarry Smith - ctx - optional type dependent context 363292f8084SBarry Smith 364292f8084SBarry Smith Options Database Key: 365292f8084SBarry Smith . -pf_type <type> - Sets PF type 366292f8084SBarry Smith 367292f8084SBarry Smith 368292f8084SBarry Smith Notes: 369292f8084SBarry Smith See "petsc/include/petscpf.h" for available methods (for instance, 370292f8084SBarry Smith PFCONSTANT) 371292f8084SBarry Smith 372292f8084SBarry Smith Level: intermediate 373292f8084SBarry Smith 3741c84c290SBarry Smith .seealso: PFSet(), PFRegister(), PFCreate(), DMDACreatePF() 375292f8084SBarry Smith 376292f8084SBarry Smith @*/ 37719fd82e9SBarry Smith PetscErrorCode PFSetType(PF pf,PFType type,void *ctx) 378292f8084SBarry Smith { 379292f8084SBarry Smith PetscErrorCode ierr,(*r)(PF,void*); 380ace3abfcSBarry Smith PetscBool match; 381292f8084SBarry Smith 382292f8084SBarry Smith PetscFunctionBegin; 3830700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 384292f8084SBarry Smith PetscValidCharPointer(type,2); 385292f8084SBarry Smith 386251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)pf,type,&match);CHKERRQ(ierr); 387292f8084SBarry Smith if (match) PetscFunctionReturn(0); 388292f8084SBarry Smith 389292f8084SBarry Smith if (pf->ops->destroy) {ierr = (*pf->ops->destroy)(pf);CHKERRQ(ierr);} 390*4c8fdceaSLisandro Dalcin pf->data = NULL; 391292f8084SBarry Smith 392292f8084SBarry Smith /* Determine the PFCreateXXX routine for a particular function */ 39337e93019SBarry Smith ierr = PetscFunctionListFind(PFList,type,&r);CHKERRQ(ierr); 394e32f2f54SBarry Smith if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested PF type %s",type); 395*4c8fdceaSLisandro Dalcin pf->ops->destroy = NULL; 396*4c8fdceaSLisandro Dalcin pf->ops->view = NULL; 397*4c8fdceaSLisandro Dalcin pf->ops->apply = NULL; 398*4c8fdceaSLisandro Dalcin pf->ops->applyvec = NULL; 399292f8084SBarry Smith 400292f8084SBarry Smith /* Call the PFCreateXXX routine for this particular function */ 401292f8084SBarry Smith ierr = (*r)(pf,ctx);CHKERRQ(ierr); 402292f8084SBarry Smith 403292f8084SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)pf,type);CHKERRQ(ierr); 404292f8084SBarry Smith PetscFunctionReturn(0); 405292f8084SBarry Smith } 406292f8084SBarry Smith 407292f8084SBarry Smith /*@ 408292f8084SBarry Smith PFSetFromOptions - Sets PF options from the options database. 409292f8084SBarry Smith 410292f8084SBarry Smith Collective on PF 411292f8084SBarry Smith 412292f8084SBarry Smith Input Parameters: 413292f8084SBarry Smith . pf - the mathematical function context 414292f8084SBarry Smith 415292f8084SBarry Smith Options Database Keys: 416292f8084SBarry Smith 417292f8084SBarry Smith Notes: 418292f8084SBarry Smith To see all options, run your program with the -help option 419292f8084SBarry Smith or consult the users manual. 420292f8084SBarry Smith 421292f8084SBarry Smith Level: intermediate 422292f8084SBarry Smith 423292f8084SBarry Smith .seealso: 424292f8084SBarry Smith @*/ 4257087cfbeSBarry Smith PetscErrorCode PFSetFromOptions(PF pf) 426292f8084SBarry Smith { 427292f8084SBarry Smith PetscErrorCode ierr; 428292f8084SBarry Smith char type[256]; 429ace3abfcSBarry Smith PetscBool flg; 430292f8084SBarry Smith 431292f8084SBarry Smith PetscFunctionBegin; 4320700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 433292f8084SBarry Smith 4343194b578SJed Brown ierr = PetscObjectOptionsBegin((PetscObject)pf);CHKERRQ(ierr); 435*4c8fdceaSLisandro Dalcin ierr = PetscOptionsFList("-pf_type","Type of function","PFSetType",PFList,NULL,type,256,&flg);CHKERRQ(ierr); 436292f8084SBarry Smith if (flg) { 4370298fd71SBarry Smith ierr = PFSetType(pf,type,NULL);CHKERRQ(ierr); 438292f8084SBarry Smith } 439292f8084SBarry Smith if (pf->ops->setfromoptions) { 440e55864a3SBarry Smith ierr = (*pf->ops->setfromoptions)(PetscOptionsObject,pf);CHKERRQ(ierr); 441292f8084SBarry Smith } 4425d973c19SBarry Smith 4435d973c19SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 4440633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject)pf);CHKERRQ(ierr); 445292f8084SBarry Smith ierr = PetscOptionsEnd();CHKERRQ(ierr); 446292f8084SBarry Smith PetscFunctionReturn(0); 447292f8084SBarry Smith } 448292f8084SBarry Smith 449ace3abfcSBarry Smith static PetscBool PFPackageInitialized = PETSC_FALSE; 450b022a5c1SBarry Smith /*@C 451b022a5c1SBarry Smith PFFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is 452b022a5c1SBarry Smith called from PetscFinalize(). 453b022a5c1SBarry Smith 454b022a5c1SBarry Smith Level: developer 455b022a5c1SBarry Smith 456b022a5c1SBarry Smith .seealso: PetscFinalize() 457b022a5c1SBarry Smith @*/ 4587087cfbeSBarry Smith PetscErrorCode PFFinalizePackage(void) 459b022a5c1SBarry Smith { 46037e93019SBarry Smith PetscErrorCode ierr; 46137e93019SBarry Smith 462b022a5c1SBarry Smith PetscFunctionBegin; 46337e93019SBarry Smith ierr = PetscFunctionListDestroy(&PFList);CHKERRQ(ierr); 464b022a5c1SBarry Smith PFPackageInitialized = PETSC_FALSE; 465b022a5c1SBarry Smith PFRegisterAllCalled = PETSC_FALSE; 466b022a5c1SBarry Smith PetscFunctionReturn(0); 467b022a5c1SBarry Smith } 468b022a5c1SBarry Smith 4699877f0dbSBarry Smith /*@C 4709877f0dbSBarry Smith PFInitializePackage - This function initializes everything in the PF package. It is called 4718a690491SBarry Smith from PetscDLLibraryRegister_petscvec() when using dynamic libraries, and on the first call to PFCreate() 4728a690491SBarry Smith when using shared or static libraries. 4739877f0dbSBarry Smith 4749877f0dbSBarry Smith Level: developer 4759877f0dbSBarry Smith 4769877f0dbSBarry Smith .seealso: PetscInitialize() 4779877f0dbSBarry Smith @*/ 478607a6623SBarry Smith PetscErrorCode PFInitializePackage(void) 4799877f0dbSBarry Smith { 4809877f0dbSBarry Smith char logList[256]; 4818e81d068SLisandro Dalcin PetscBool opt,pkg; 4829877f0dbSBarry Smith PetscErrorCode ierr; 4839877f0dbSBarry Smith 4849877f0dbSBarry Smith PetscFunctionBegin; 485b022a5c1SBarry Smith if (PFPackageInitialized) PetscFunctionReturn(0); 486b022a5c1SBarry Smith PFPackageInitialized = PETSC_TRUE; 4879877f0dbSBarry Smith /* Register Classes */ 4880700a824SBarry Smith ierr = PetscClassIdRegister("PointFunction",&PF_CLASSID);CHKERRQ(ierr); 4899877f0dbSBarry Smith /* Register Constructors */ 490607a6623SBarry Smith ierr = PFRegisterAll();CHKERRQ(ierr); 491e94e781bSJacob Faibussowitsch /* Process Info */ 492e94e781bSJacob Faibussowitsch { 493e94e781bSJacob Faibussowitsch PetscClassId classids[1]; 494e94e781bSJacob Faibussowitsch 495e94e781bSJacob Faibussowitsch classids[0] = PF_CLASSID; 496e94e781bSJacob Faibussowitsch ierr = PetscInfoProcessClass("pf", 1, classids);CHKERRQ(ierr); 4979877f0dbSBarry Smith } 4989877f0dbSBarry Smith /* Process summary exclusions */ 4998e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 5009877f0dbSBarry Smith if (opt) { 5018e81d068SLisandro Dalcin ierr = PetscStrInList("pf",logList,',',&pkg);CHKERRQ(ierr); 502fa2bb9feSLisandro Dalcin if (pkg) {ierr = PetscLogEventExcludeClass(PF_CLASSID);CHKERRQ(ierr);} 5039877f0dbSBarry Smith } 5048e81d068SLisandro Dalcin /* Register package finalizer */ 505b022a5c1SBarry Smith ierr = PetscRegisterFinalize(PFFinalizePackage);CHKERRQ(ierr); 5069877f0dbSBarry Smith PetscFunctionReturn(0); 5079877f0dbSBarry Smith } 508292f8084SBarry Smith 509292f8084SBarry Smith 510292f8084SBarry Smith 511292f8084SBarry Smith 512292f8084SBarry Smith 513292f8084SBarry Smith 514292f8084SBarry Smith 515292f8084SBarry Smith 516292f8084SBarry Smith 517