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; 70298fd71SBarry Smith PetscFunctionList PFunctionList = NULL; /* list of all registered PD functions */ 8ace3abfcSBarry Smith PetscBool PFRegisterAllCalled = PETSC_FALSE; 9292f8084SBarry Smith 10292f8084SBarry Smith #undef __FUNCT__ 11292f8084SBarry Smith #define __FUNCT__ "PFSet" 12292f8084SBarry Smith /*@C 13292f8084SBarry Smith PFSet - Sets the C/C++/Fortran functions to be used by the PF function 14292f8084SBarry Smith 15292f8084SBarry Smith Collective on PF 16292f8084SBarry Smith 17292f8084SBarry Smith Input Parameter: 18292f8084SBarry Smith + pf - the function context 19292f8084SBarry Smith . apply - function to apply to an array 20292f8084SBarry Smith . applyvec - function to apply to a Vec 21292f8084SBarry Smith . view - function that prints information about the PF 22292f8084SBarry Smith . destroy - function to free the private function context 23292f8084SBarry Smith - ctx - private function context 24292f8084SBarry Smith 25292f8084SBarry Smith Level: beginner 26292f8084SBarry Smith 27292f8084SBarry Smith .keywords: PF, setting 28292f8084SBarry Smith 29292f8084SBarry Smith .seealso: PFCreate(), PFDestroy(), PFSetType(), PFApply(), PFApplyVec() 30292f8084SBarry Smith @*/ 317087cfbeSBarry 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) 32292f8084SBarry Smith { 33292f8084SBarry Smith PetscFunctionBegin; 340700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 35292f8084SBarry Smith pf->data = ctx; 36292f8084SBarry Smith pf->ops->destroy = destroy; 37292f8084SBarry Smith pf->ops->apply = apply; 38292f8084SBarry Smith pf->ops->applyvec = applyvec; 39292f8084SBarry Smith pf->ops->view = view; 40292f8084SBarry Smith PetscFunctionReturn(0); 41292f8084SBarry Smith } 42292f8084SBarry Smith 43292f8084SBarry Smith #undef __FUNCT__ 44292f8084SBarry Smith #define __FUNCT__ "PFDestroy" 45292f8084SBarry Smith /*@C 46292f8084SBarry Smith PFDestroy - Destroys PF context that was created with PFCreate(). 47292f8084SBarry Smith 48292f8084SBarry Smith Collective on PF 49292f8084SBarry Smith 50292f8084SBarry Smith Input Parameter: 51292f8084SBarry Smith . pf - the function context 52292f8084SBarry Smith 53292f8084SBarry Smith Level: beginner 54292f8084SBarry Smith 55292f8084SBarry Smith .keywords: PF, destroy 56292f8084SBarry Smith 57292f8084SBarry Smith .seealso: PFCreate(), PFSet(), PFSetType() 58292f8084SBarry Smith @*/ 596bf464f9SBarry Smith PetscErrorCode PFDestroy(PF *pf) 60292f8084SBarry Smith { 61292f8084SBarry Smith PetscErrorCode ierr; 62ace3abfcSBarry Smith PetscBool flg = PETSC_FALSE; 63292f8084SBarry Smith 64292f8084SBarry Smith PetscFunctionBegin; 656bf464f9SBarry Smith if (!*pf) PetscFunctionReturn(0); 666bf464f9SBarry Smith PetscValidHeaderSpecific((*pf),PF_CLASSID,1); 676bf464f9SBarry Smith if (--((PetscObject)(*pf))->refct > 0) PetscFunctionReturn(0); 68292f8084SBarry Smith 690298fd71SBarry Smith ierr = PetscOptionsGetBool(((PetscObject)(*pf))->prefix,"-pf_view",&flg,NULL);CHKERRQ(ierr); 70292f8084SBarry Smith if (flg) { 713050cee2SBarry Smith PetscViewer viewer; 726bf464f9SBarry Smith ierr = PetscViewerASCIIGetStdout(((PetscObject)(*pf))->comm,&viewer);CHKERRQ(ierr); 736bf464f9SBarry Smith ierr = PFView((*pf),viewer);CHKERRQ(ierr); 74292f8084SBarry Smith } 75292f8084SBarry Smith 76292f8084SBarry Smith /* if memory was published with AMS then destroy it */ 776bf464f9SBarry Smith ierr = PetscObjectDepublish((*pf));CHKERRQ(ierr); 78292f8084SBarry Smith 796bf464f9SBarry Smith if ((*pf)->ops->destroy) {ierr = (*(*pf)->ops->destroy)((*pf)->data);CHKERRQ(ierr);} 80d38fa0fbSBarry Smith ierr = PetscHeaderDestroy(pf);CHKERRQ(ierr); 81292f8084SBarry Smith PetscFunctionReturn(0); 82292f8084SBarry Smith } 83292f8084SBarry Smith 84292f8084SBarry Smith #undef __FUNCT__ 85292f8084SBarry Smith #define __FUNCT__ "PFCreate" 86292f8084SBarry Smith /*@C 87292f8084SBarry Smith PFCreate - Creates a mathematical function context. 88292f8084SBarry Smith 89292f8084SBarry Smith Collective on MPI_Comm 90292f8084SBarry Smith 91292f8084SBarry Smith Input Parameter: 92292f8084SBarry Smith + comm - MPI communicator 93292f8084SBarry Smith . dimin - dimension of the space you are mapping from 94292f8084SBarry Smith - dimout - dimension of the space you are mapping to 95292f8084SBarry Smith 96292f8084SBarry Smith Output Parameter: 97292f8084SBarry Smith . pf - the function context 98292f8084SBarry Smith 99292f8084SBarry Smith Level: developer 100292f8084SBarry Smith 101292f8084SBarry Smith .keywords: PF, create, context 102292f8084SBarry Smith 10303193ff8SBarry Smith .seealso: PFSet(), PFApply(), PFDestroy(), PFApplyVec() 104292f8084SBarry Smith @*/ 1057087cfbeSBarry Smith PetscErrorCode PFCreate(MPI_Comm comm,PetscInt dimin,PetscInt dimout,PF *pf) 106292f8084SBarry Smith { 107292f8084SBarry Smith PF newpf; 108292f8084SBarry Smith PetscErrorCode ierr; 109292f8084SBarry Smith 110292f8084SBarry Smith PetscFunctionBegin; 111292f8084SBarry Smith PetscValidPointer(pf,1); 1120298fd71SBarry Smith *pf = NULL; 113519f805aSKarl Rupp #if !defined(PETSC_USE_DYNAMIC_LIBRARIES) 1140298fd71SBarry Smith ierr = PFInitializePackage(NULL);CHKERRQ(ierr); 115292f8084SBarry Smith #endif 116292f8084SBarry Smith 11767c2884eSBarry Smith ierr = PetscHeaderCreate(newpf,_p_PF,struct _PFOps,PF_CLASSID,"PF","Mathematical functions","Vec",comm,PFDestroy,PFView);CHKERRQ(ierr); 118292f8084SBarry Smith newpf->data = 0; 119292f8084SBarry Smith newpf->ops->destroy = 0; 120292f8084SBarry Smith newpf->ops->apply = 0; 121292f8084SBarry Smith newpf->ops->applyvec = 0; 122292f8084SBarry Smith newpf->ops->view = 0; 123292f8084SBarry Smith newpf->dimin = dimin; 124292f8084SBarry Smith newpf->dimout = dimout; 125292f8084SBarry Smith 126292f8084SBarry Smith *pf = newpf; 127292f8084SBarry Smith PetscFunctionReturn(0); 128292f8084SBarry Smith 129292f8084SBarry Smith } 130292f8084SBarry Smith 131292f8084SBarry Smith /* -------------------------------------------------------------------------------*/ 132292f8084SBarry Smith 133292f8084SBarry Smith #undef __FUNCT__ 134292f8084SBarry Smith #define __FUNCT__ "PFApplyVec" 135292f8084SBarry Smith /*@ 136292f8084SBarry Smith PFApplyVec - Applies the mathematical function to a vector 137292f8084SBarry Smith 138292f8084SBarry Smith Collective on PF 139292f8084SBarry Smith 140292f8084SBarry Smith Input Parameters: 141292f8084SBarry Smith + pf - the function context 1420298fd71SBarry Smith - x - input vector (or NULL for the vector (0,1, .... N-1) 143292f8084SBarry Smith 144292f8084SBarry Smith Output Parameter: 145292f8084SBarry Smith . y - output vector 146292f8084SBarry Smith 147292f8084SBarry Smith Level: beginner 148292f8084SBarry Smith 149292f8084SBarry Smith .keywords: PF, apply 150292f8084SBarry Smith 151292f8084SBarry Smith .seealso: PFApply(), PFCreate(), PFDestroy(), PFSetType(), PFSet() 152292f8084SBarry Smith @*/ 1537087cfbeSBarry Smith PetscErrorCode PFApplyVec(PF pf,Vec x,Vec y) 154292f8084SBarry Smith { 155292f8084SBarry Smith PetscErrorCode ierr; 156292f8084SBarry Smith PetscInt i,rstart,rend,n,p; 157ace3abfcSBarry Smith PetscBool nox = PETSC_FALSE; 158292f8084SBarry Smith 159292f8084SBarry Smith PetscFunctionBegin; 1600700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 1610700a824SBarry Smith PetscValidHeaderSpecific(y,VEC_CLASSID,3); 162292f8084SBarry Smith if (x) { 1630700a824SBarry Smith PetscValidHeaderSpecific(x,VEC_CLASSID,2); 164e32f2f54SBarry Smith if (x == y) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_IDN,"x and y must be different vectors"); 165292f8084SBarry Smith } else { 166292f8084SBarry Smith PetscScalar *xx; 16703193ff8SBarry Smith PetscInt lsize; 168292f8084SBarry Smith 16903193ff8SBarry Smith ierr = VecGetLocalSize(y,&lsize);CHKERRQ(ierr); 17003193ff8SBarry Smith lsize = pf->dimin*lsize/pf->dimout; 171*ce94432eSBarry Smith ierr = VecCreateMPI(PetscObjectComm((PetscObject)y),lsize,PETSC_DETERMINE,&x);CHKERRQ(ierr); 172292f8084SBarry Smith nox = PETSC_TRUE; 173292f8084SBarry Smith ierr = VecGetOwnershipRange(x,&rstart,&rend);CHKERRQ(ierr); 174292f8084SBarry Smith ierr = VecGetArray(x,&xx);CHKERRQ(ierr); 175f6e5521dSKarl Rupp for (i=rstart; i<rend; i++) xx[i-rstart] = (PetscScalar)i; 176292f8084SBarry Smith ierr = VecRestoreArray(x,&xx);CHKERRQ(ierr); 177292f8084SBarry Smith } 178292f8084SBarry Smith 179292f8084SBarry Smith ierr = VecGetLocalSize(x,&n);CHKERRQ(ierr); 180292f8084SBarry Smith ierr = VecGetLocalSize(y,&p);CHKERRQ(ierr); 181e32f2f54SBarry 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); 182e32f2f54SBarry 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); 183e32f2f54SBarry 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); 184292f8084SBarry Smith 185292f8084SBarry Smith if (pf->ops->applyvec) { 186292f8084SBarry Smith ierr = (*pf->ops->applyvec)(pf->data,x,y);CHKERRQ(ierr); 187292f8084SBarry Smith } else { 188292f8084SBarry Smith PetscScalar *xx,*yy; 189292f8084SBarry Smith 190292f8084SBarry Smith ierr = VecGetLocalSize(x,&n);CHKERRQ(ierr); 191292f8084SBarry Smith n = n/pf->dimin; 192292f8084SBarry Smith ierr = VecGetArray(x,&xx);CHKERRQ(ierr); 193292f8084SBarry Smith ierr = VecGetArray(y,&yy);CHKERRQ(ierr); 194e32f2f54SBarry Smith if (!pf->ops->apply) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"No function has been provided for this PF"); 195292f8084SBarry Smith ierr = (*pf->ops->apply)(pf->data,n,xx,yy);CHKERRQ(ierr); 196292f8084SBarry Smith ierr = VecRestoreArray(x,&xx);CHKERRQ(ierr); 197292f8084SBarry Smith ierr = VecRestoreArray(y,&yy);CHKERRQ(ierr); 198292f8084SBarry Smith } 199292f8084SBarry Smith if (nox) { 2006bf464f9SBarry Smith ierr = VecDestroy(&x);CHKERRQ(ierr); 201292f8084SBarry Smith } 202292f8084SBarry Smith PetscFunctionReturn(0); 203292f8084SBarry Smith } 204292f8084SBarry Smith 205292f8084SBarry Smith #undef __FUNCT__ 206292f8084SBarry Smith #define __FUNCT__ "PFApply" 207292f8084SBarry Smith /*@ 208292f8084SBarry Smith PFApply - Applies the mathematical function to an array of values. 209292f8084SBarry Smith 210292f8084SBarry Smith Collective on PF 211292f8084SBarry Smith 212292f8084SBarry Smith Input Parameters: 213292f8084SBarry Smith + pf - the function context 214292f8084SBarry Smith . n - number of pointwise function evaluations to perform, each pointwise function evaluation 215292f8084SBarry Smith is a function of dimin variables and computes dimout variables where dimin and dimout are defined 216292f8084SBarry Smith in the call to PFCreate() 217292f8084SBarry Smith - x - input array 218292f8084SBarry Smith 219292f8084SBarry Smith Output Parameter: 220292f8084SBarry Smith . y - output array 221292f8084SBarry Smith 222292f8084SBarry Smith Level: beginner 223292f8084SBarry Smith 224292f8084SBarry Smith Notes: 225292f8084SBarry Smith 226292f8084SBarry Smith .keywords: PF, apply 227292f8084SBarry Smith 228292f8084SBarry Smith .seealso: PFApplyVec(), PFCreate(), PFDestroy(), PFSetType(), PFSet() 229292f8084SBarry Smith @*/ 2307087cfbeSBarry Smith PetscErrorCode PFApply(PF pf,PetscInt n,const PetscScalar *x,PetscScalar *y) 231292f8084SBarry Smith { 232292f8084SBarry Smith PetscErrorCode ierr; 233292f8084SBarry Smith 234292f8084SBarry Smith PetscFunctionBegin; 2350700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 236292f8084SBarry Smith PetscValidScalarPointer(x,2); 237292f8084SBarry Smith PetscValidScalarPointer(y,3); 238e32f2f54SBarry Smith if (x == y) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_IDN,"x and y must be different arrays"); 239e32f2f54SBarry Smith if (!pf->ops->apply) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"No function has been provided for this PF"); 240292f8084SBarry Smith 241292f8084SBarry Smith ierr = (*pf->ops->apply)(pf->data,n,x,y);CHKERRQ(ierr); 242292f8084SBarry Smith PetscFunctionReturn(0); 243292f8084SBarry Smith } 244292f8084SBarry Smith 245292f8084SBarry Smith #undef __FUNCT__ 246292f8084SBarry Smith #define __FUNCT__ "PFView" 247292f8084SBarry Smith /*@ 248292f8084SBarry Smith PFView - Prints information about a mathematical function 249292f8084SBarry Smith 250292f8084SBarry Smith Collective on PF unless PetscViewer is PETSC_VIEWER_STDOUT_SELF 251292f8084SBarry Smith 252292f8084SBarry Smith Input Parameters: 253292f8084SBarry Smith + PF - the PF context 254292f8084SBarry Smith - viewer - optional visualization context 255292f8084SBarry Smith 256292f8084SBarry Smith Note: 257292f8084SBarry Smith The available visualization contexts include 258292f8084SBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 259292f8084SBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 260292f8084SBarry Smith output where only the first processor opens 261292f8084SBarry Smith the file. All other processors send their 262292f8084SBarry Smith data to the first processor to print. 263292f8084SBarry Smith 264292f8084SBarry Smith The user can open an alternative visualization contexts with 265292f8084SBarry Smith PetscViewerASCIIOpen() (output to a specified file). 266292f8084SBarry Smith 267292f8084SBarry Smith Level: developer 268292f8084SBarry Smith 269292f8084SBarry Smith .keywords: PF, view 270292f8084SBarry Smith 271292f8084SBarry Smith .seealso: PetscViewerCreate(), PetscViewerASCIIOpen() 272292f8084SBarry Smith @*/ 2737087cfbeSBarry Smith PetscErrorCode PFView(PF pf,PetscViewer viewer) 274292f8084SBarry Smith { 275292f8084SBarry Smith PetscErrorCode ierr; 276ace3abfcSBarry Smith PetscBool iascii; 277292f8084SBarry Smith PetscViewerFormat format; 278292f8084SBarry Smith 279292f8084SBarry Smith PetscFunctionBegin; 2800700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 2813050cee2SBarry Smith if (!viewer) { 282*ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)pf),&viewer);CHKERRQ(ierr); 2833050cee2SBarry Smith } 2840700a824SBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 285292f8084SBarry Smith PetscCheckSameComm(pf,1,viewer,2); 286292f8084SBarry Smith 287251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 288292f8084SBarry Smith if (iascii) { 289292f8084SBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 290317d6ea6SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)pf,viewer,"PF Object");CHKERRQ(ierr); 291292f8084SBarry Smith if (pf->ops->view) { 292292f8084SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 293292f8084SBarry Smith ierr = (*pf->ops->view)(pf->data,viewer);CHKERRQ(ierr); 294292f8084SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 295292f8084SBarry Smith } 296292f8084SBarry Smith } 297292f8084SBarry Smith PetscFunctionReturn(0); 298292f8084SBarry Smith } 299292f8084SBarry Smith 300292f8084SBarry Smith /*MC 301292f8084SBarry Smith PFRegisterDynamic - Adds a method to the mathematical function package. 302292f8084SBarry Smith 303292f8084SBarry Smith Synopsis: 304f2ba6396SBarry Smith #include "petscpf.h" 305d360dc6fSBarry Smith PetscErrorCode PFRegisterDynamic(char *name_solver,char *path,char *name_create,PetscErrorCode (*routine_create)(PF)) 306292f8084SBarry Smith 307292f8084SBarry Smith Not collective 308292f8084SBarry Smith 309292f8084SBarry Smith Input Parameters: 310292f8084SBarry Smith + name_solver - name of a new user-defined solver 311292f8084SBarry Smith . path - path (either absolute or relative) the library containing this solver 312292f8084SBarry Smith . name_create - name of routine to create method context 313292f8084SBarry Smith - routine_create - routine to create method context 314292f8084SBarry Smith 315292f8084SBarry Smith Notes: 316292f8084SBarry Smith PFRegisterDynamic() may be called multiple times to add several user-defined functions 317292f8084SBarry Smith 318292f8084SBarry Smith If dynamic libraries are used, then the fourth input argument (routine_create) 319292f8084SBarry Smith is ignored. 320292f8084SBarry Smith 321292f8084SBarry Smith Sample usage: 322292f8084SBarry Smith .vb 323292f8084SBarry Smith PFRegisterDynamic("my_function","/home/username/my_lib/lib/libO/solaris/mylib", 324292f8084SBarry Smith "MyFunctionCreate",MyFunctionSetCreate); 325292f8084SBarry Smith .ve 326292f8084SBarry Smith 327292f8084SBarry Smith Then, your solver can be chosen with the procedural interface via 328292f8084SBarry Smith $ PFSetType(pf,"my_function") 329292f8084SBarry Smith or at runtime via the option 330292f8084SBarry Smith $ -pf_type my_function 331292f8084SBarry Smith 332292f8084SBarry Smith Level: advanced 333292f8084SBarry Smith 334ab901514SBarry Smith ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, or ${any environmental variable} 335292f8084SBarry Smith occuring in pathname will be replaced with appropriate values. 336292f8084SBarry Smith 337292f8084SBarry Smith .keywords: PF, register 338292f8084SBarry Smith 339292f8084SBarry Smith .seealso: PFRegisterAll(), PFRegisterDestroy(), PFRegister() 340292f8084SBarry Smith M*/ 341292f8084SBarry Smith 342292f8084SBarry Smith #undef __FUNCT__ 343292f8084SBarry Smith #define __FUNCT__ "PFRegister" 3447087cfbeSBarry Smith PetscErrorCode PFRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(PF,void*)) 345292f8084SBarry Smith { 346292f8084SBarry Smith PetscErrorCode ierr; 347292f8084SBarry Smith char fullname[PETSC_MAX_PATH_LEN]; 348292f8084SBarry Smith 349292f8084SBarry Smith PetscFunctionBegin; 350140e18c1SBarry Smith ierr = PetscFunctionListConcat(path,name,fullname);CHKERRQ(ierr); 351140e18c1SBarry Smith ierr = PetscFunctionListAdd(PETSC_COMM_WORLD,&PFunctionList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr); 352292f8084SBarry Smith PetscFunctionReturn(0); 353292f8084SBarry Smith } 354292f8084SBarry Smith 355292f8084SBarry Smith #undef __FUNCT__ 356292f8084SBarry Smith #define __FUNCT__ "PFGetType" 357292f8084SBarry Smith /*@C 358292f8084SBarry Smith PFGetType - Gets the PF method type and name (as a string) from the PF 359292f8084SBarry Smith context. 360292f8084SBarry Smith 361292f8084SBarry Smith Not Collective 362292f8084SBarry Smith 363292f8084SBarry Smith Input Parameter: 364292f8084SBarry Smith . pf - the function context 365292f8084SBarry Smith 366292f8084SBarry Smith Output Parameter: 367c4e43342SLisandro Dalcin . type - name of function 368292f8084SBarry Smith 369292f8084SBarry Smith Level: intermediate 370292f8084SBarry Smith 371292f8084SBarry Smith .keywords: PF, get, method, name, type 372292f8084SBarry Smith 373292f8084SBarry Smith .seealso: PFSetType() 374292f8084SBarry Smith 375292f8084SBarry Smith @*/ 37619fd82e9SBarry Smith PetscErrorCode PFGetType(PF pf,PFType *type) 377292f8084SBarry Smith { 378292f8084SBarry Smith PetscFunctionBegin; 3790700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 380c4e43342SLisandro Dalcin PetscValidPointer(type,2); 381c4e43342SLisandro Dalcin *type = ((PetscObject)pf)->type_name; 382292f8084SBarry Smith PetscFunctionReturn(0); 383292f8084SBarry Smith } 384292f8084SBarry Smith 385292f8084SBarry Smith 386292f8084SBarry Smith #undef __FUNCT__ 387292f8084SBarry Smith #define __FUNCT__ "PFSetType" 388292f8084SBarry Smith /*@C 389292f8084SBarry Smith PFSetType - Builds PF for a particular function 390292f8084SBarry Smith 391292f8084SBarry Smith Collective on PF 392292f8084SBarry Smith 393292f8084SBarry Smith Input Parameter: 394292f8084SBarry Smith + pf - the function context. 395292f8084SBarry Smith . type - a known method 396292f8084SBarry Smith - ctx - optional type dependent context 397292f8084SBarry Smith 398292f8084SBarry Smith Options Database Key: 399292f8084SBarry Smith . -pf_type <type> - Sets PF type 400292f8084SBarry Smith 401292f8084SBarry Smith 402292f8084SBarry Smith Notes: 403292f8084SBarry Smith See "petsc/include/petscpf.h" for available methods (for instance, 404292f8084SBarry Smith PFCONSTANT) 405292f8084SBarry Smith 406292f8084SBarry Smith Level: intermediate 407292f8084SBarry Smith 408292f8084SBarry Smith .keywords: PF, set, method, type 409292f8084SBarry Smith 410aa219208SBarry Smith .seealso: PFSet(), PFRegisterDynamic(), PFCreate(), DMDACreatePF() 411292f8084SBarry Smith 412292f8084SBarry Smith @*/ 41319fd82e9SBarry Smith PetscErrorCode PFSetType(PF pf,PFType type,void *ctx) 414292f8084SBarry Smith { 415292f8084SBarry Smith PetscErrorCode ierr,(*r)(PF,void*); 416ace3abfcSBarry Smith PetscBool match; 417292f8084SBarry Smith 418292f8084SBarry Smith PetscFunctionBegin; 4190700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 420292f8084SBarry Smith PetscValidCharPointer(type,2); 421292f8084SBarry Smith 422251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)pf,type,&match);CHKERRQ(ierr); 423292f8084SBarry Smith if (match) PetscFunctionReturn(0); 424292f8084SBarry Smith 425292f8084SBarry Smith if (pf->ops->destroy) {ierr = (*pf->ops->destroy)(pf);CHKERRQ(ierr);} 426292f8084SBarry Smith pf->data = 0; 427292f8084SBarry Smith 428292f8084SBarry Smith /* Determine the PFCreateXXX routine for a particular function */ 429*ce94432eSBarry Smith ierr = PetscFunctionListFind(PetscObjectComm((PetscObject)pf),PFunctionList,type,PETSC_TRUE,(void (**)(void)) &r);CHKERRQ(ierr); 430e32f2f54SBarry Smith if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested PF type %s",type); 431292f8084SBarry Smith pf->ops->destroy = 0; 432292f8084SBarry Smith pf->ops->view = 0; 433292f8084SBarry Smith pf->ops->apply = 0; 434292f8084SBarry Smith pf->ops->applyvec = 0; 435292f8084SBarry Smith 436292f8084SBarry Smith /* Call the PFCreateXXX routine for this particular function */ 437292f8084SBarry Smith ierr = (*r)(pf,ctx);CHKERRQ(ierr); 438292f8084SBarry Smith 439292f8084SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)pf,type);CHKERRQ(ierr); 440292f8084SBarry Smith PetscFunctionReturn(0); 441292f8084SBarry Smith } 442292f8084SBarry Smith 443292f8084SBarry Smith #undef __FUNCT__ 444292f8084SBarry Smith #define __FUNCT__ "PFSetFromOptions" 445292f8084SBarry Smith /*@ 446292f8084SBarry Smith PFSetFromOptions - Sets PF options from the options database. 447292f8084SBarry Smith 448292f8084SBarry Smith Collective on PF 449292f8084SBarry Smith 450292f8084SBarry Smith Input Parameters: 451292f8084SBarry Smith . pf - the mathematical function context 452292f8084SBarry Smith 453292f8084SBarry Smith Options Database Keys: 454292f8084SBarry Smith 455292f8084SBarry Smith Notes: 456292f8084SBarry Smith To see all options, run your program with the -help option 457292f8084SBarry Smith or consult the users manual. 458292f8084SBarry Smith 459292f8084SBarry Smith Level: intermediate 460292f8084SBarry Smith 461292f8084SBarry Smith .keywords: PF, set, from, options, database 462292f8084SBarry Smith 463292f8084SBarry Smith .seealso: 464292f8084SBarry Smith @*/ 4657087cfbeSBarry Smith PetscErrorCode PFSetFromOptions(PF pf) 466292f8084SBarry Smith { 467292f8084SBarry Smith PetscErrorCode ierr; 468292f8084SBarry Smith char type[256]; 469ace3abfcSBarry Smith PetscBool flg; 470292f8084SBarry Smith 471292f8084SBarry Smith PetscFunctionBegin; 4720700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 473292f8084SBarry Smith 4743194b578SJed Brown ierr = PetscObjectOptionsBegin((PetscObject)pf);CHKERRQ(ierr); 475140e18c1SBarry Smith ierr = PetscOptionsList("-pf_type","Type of function","PFSetType",PFunctionList,0,type,256,&flg);CHKERRQ(ierr); 476292f8084SBarry Smith if (flg) { 4770298fd71SBarry Smith ierr = PFSetType(pf,type,NULL);CHKERRQ(ierr); 478292f8084SBarry Smith } 479292f8084SBarry Smith if (pf->ops->setfromoptions) { 480292f8084SBarry Smith ierr = (*pf->ops->setfromoptions)(pf);CHKERRQ(ierr); 481292f8084SBarry Smith } 4825d973c19SBarry Smith 4835d973c19SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 4845d973c19SBarry Smith ierr = PetscObjectProcessOptionsHandlers((PetscObject)pf);CHKERRQ(ierr); 485292f8084SBarry Smith ierr = PetscOptionsEnd();CHKERRQ(ierr); 486292f8084SBarry Smith PetscFunctionReturn(0); 487292f8084SBarry Smith } 488292f8084SBarry Smith 489ace3abfcSBarry Smith static PetscBool PFPackageInitialized = PETSC_FALSE; 490b022a5c1SBarry Smith #undef __FUNCT__ 491b022a5c1SBarry Smith #define __FUNCT__ "PFFinalizePackage" 492b022a5c1SBarry Smith /*@C 493b022a5c1SBarry Smith PFFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is 494b022a5c1SBarry Smith called from PetscFinalize(). 495b022a5c1SBarry Smith 496b022a5c1SBarry Smith Level: developer 497b022a5c1SBarry Smith 498b022a5c1SBarry Smith .keywords: Petsc, destroy, package, mathematica 499b022a5c1SBarry Smith .seealso: PetscFinalize() 500b022a5c1SBarry Smith @*/ 5017087cfbeSBarry Smith PetscErrorCode PFFinalizePackage(void) 502b022a5c1SBarry Smith { 503b022a5c1SBarry Smith PetscFunctionBegin; 504b022a5c1SBarry Smith PFPackageInitialized = PETSC_FALSE; 5050298fd71SBarry Smith PFunctionList = NULL; 506b022a5c1SBarry Smith PFRegisterAllCalled = PETSC_FALSE; 507b022a5c1SBarry Smith PetscFunctionReturn(0); 508b022a5c1SBarry Smith } 509b022a5c1SBarry Smith 5109877f0dbSBarry Smith #undef __FUNCT__ 5119877f0dbSBarry Smith #define __FUNCT__ "PFInitializePackage" 5129877f0dbSBarry Smith /*@C 5139877f0dbSBarry Smith PFInitializePackage - This function initializes everything in the PF package. It is called 5149877f0dbSBarry Smith from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to PFCreate() 5159877f0dbSBarry Smith when using static libraries. 5169877f0dbSBarry Smith 5179877f0dbSBarry Smith Input Parameter: 5180298fd71SBarry Smith . path - The dynamic library path, or NULL 5199877f0dbSBarry Smith 5209877f0dbSBarry Smith Level: developer 5219877f0dbSBarry Smith 5229877f0dbSBarry Smith .keywords: Vec, initialize, package 5239877f0dbSBarry Smith .seealso: PetscInitialize() 5249877f0dbSBarry Smith @*/ 5257087cfbeSBarry Smith PetscErrorCode PFInitializePackage(const char path[]) 5269877f0dbSBarry Smith { 5279877f0dbSBarry Smith char logList[256]; 5289877f0dbSBarry Smith char *className; 529ace3abfcSBarry Smith PetscBool opt; 5309877f0dbSBarry Smith PetscErrorCode ierr; 5319877f0dbSBarry Smith 5329877f0dbSBarry Smith PetscFunctionBegin; 533b022a5c1SBarry Smith if (PFPackageInitialized) PetscFunctionReturn(0); 534b022a5c1SBarry Smith PFPackageInitialized = PETSC_TRUE; 5359877f0dbSBarry Smith /* Register Classes */ 5360700a824SBarry Smith ierr = PetscClassIdRegister("PointFunction",&PF_CLASSID);CHKERRQ(ierr); 5379877f0dbSBarry Smith /* Register Constructors */ 5389877f0dbSBarry Smith ierr = PFRegisterAll(path);CHKERRQ(ierr); 5399877f0dbSBarry Smith /* Process info exclusions */ 5400298fd71SBarry Smith ierr = PetscOptionsGetString(NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); 5419877f0dbSBarry Smith if (opt) { 5429877f0dbSBarry Smith ierr = PetscStrstr(logList, "pf", &className);CHKERRQ(ierr); 5439877f0dbSBarry Smith if (className) { 5440700a824SBarry Smith ierr = PetscInfoDeactivateClass(PF_CLASSID);CHKERRQ(ierr); 5459877f0dbSBarry Smith } 5469877f0dbSBarry Smith } 5479877f0dbSBarry Smith /* Process summary exclusions */ 5480298fd71SBarry Smith ierr = PetscOptionsGetString(NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr); 5499877f0dbSBarry Smith if (opt) { 5509877f0dbSBarry Smith ierr = PetscStrstr(logList, "pf", &className);CHKERRQ(ierr); 5519877f0dbSBarry Smith if (className) { 5520700a824SBarry Smith ierr = PetscLogEventDeactivateClass(PF_CLASSID);CHKERRQ(ierr); 5539877f0dbSBarry Smith } 5549877f0dbSBarry Smith } 555b022a5c1SBarry Smith ierr = PetscRegisterFinalize(PFFinalizePackage);CHKERRQ(ierr); 5569877f0dbSBarry Smith PetscFunctionReturn(0); 5579877f0dbSBarry Smith } 558292f8084SBarry Smith 559292f8084SBarry Smith 560292f8084SBarry Smith 561292f8084SBarry Smith 562292f8084SBarry Smith 563292f8084SBarry Smith 564292f8084SBarry Smith 565292f8084SBarry Smith 566292f8084SBarry Smith 567