10c735eedSKris Buschelman #define PETSCVEC_DLL 2292f8084SBarry Smith /* 3292f8084SBarry Smith The PF mathematical functions interface routines, callable by users. 4292f8084SBarry Smith */ 57c4f633dSBarry Smith #include "../src/vec/pf/pfimpl.h" /*I "petscpf.h" I*/ 6292f8084SBarry Smith 7292f8084SBarry Smith /* Logging support */ 80700a824SBarry Smith PetscClassId PF_CLASSID = 0; 9292f8084SBarry Smith 101d280d73SBarry Smith PetscFList PFList = PETSC_NULL; /* list of all registered PD functions */ 11ace3abfcSBarry Smith PetscBool PFRegisterAllCalled = PETSC_FALSE; 12292f8084SBarry Smith 13292f8084SBarry Smith #undef __FUNCT__ 14292f8084SBarry Smith #define __FUNCT__ "PFSet" 15292f8084SBarry Smith /*@C 16292f8084SBarry Smith PFSet - Sets the C/C++/Fortran functions to be used by the PF function 17292f8084SBarry Smith 18292f8084SBarry Smith Collective on PF 19292f8084SBarry Smith 20292f8084SBarry Smith Input Parameter: 21292f8084SBarry Smith + pf - the function context 22292f8084SBarry Smith . apply - function to apply to an array 23292f8084SBarry Smith . applyvec - function to apply to a Vec 24292f8084SBarry Smith . view - function that prints information about the PF 25292f8084SBarry Smith . destroy - function to free the private function context 26292f8084SBarry Smith - ctx - private function context 27292f8084SBarry Smith 28292f8084SBarry Smith Level: beginner 29292f8084SBarry Smith 30292f8084SBarry Smith .keywords: PF, setting 31292f8084SBarry Smith 32292f8084SBarry Smith .seealso: PFCreate(), PFDestroy(), PFSetType(), PFApply(), PFApplyVec() 33292f8084SBarry Smith @*/ 34dd394643SJed Brown PetscErrorCode PETSCVEC_DLLEXPORT PFSet(PF pf,PetscErrorCode (*apply)(void*,PetscInt,const PetscScalar*,PetscScalar*),PetscErrorCode (*applyvec)(void*,Vec,Vec),PetscErrorCode (*view)(void*,PetscViewer),PetscErrorCode (*destroy)(void*),void*ctx) 35292f8084SBarry Smith { 36292f8084SBarry Smith PetscFunctionBegin; 370700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 38292f8084SBarry Smith pf->data = ctx; 39292f8084SBarry Smith 40292f8084SBarry Smith pf->ops->destroy = destroy; 41292f8084SBarry Smith pf->ops->apply = apply; 42292f8084SBarry Smith pf->ops->applyvec = applyvec; 43292f8084SBarry Smith pf->ops->view = view; 44292f8084SBarry Smith 45292f8084SBarry Smith PetscFunctionReturn(0); 46292f8084SBarry Smith } 47292f8084SBarry Smith 48292f8084SBarry Smith #undef __FUNCT__ 49292f8084SBarry Smith #define __FUNCT__ "PFDestroy" 50292f8084SBarry Smith /*@C 51292f8084SBarry Smith PFDestroy - Destroys PF context that was created with PFCreate(). 52292f8084SBarry Smith 53292f8084SBarry Smith Collective on PF 54292f8084SBarry Smith 55292f8084SBarry Smith Input Parameter: 56292f8084SBarry Smith . pf - the function context 57292f8084SBarry Smith 58292f8084SBarry Smith Level: beginner 59292f8084SBarry Smith 60292f8084SBarry Smith .keywords: PF, destroy 61292f8084SBarry Smith 62292f8084SBarry Smith .seealso: PFCreate(), PFSet(), PFSetType() 63292f8084SBarry Smith @*/ 640c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT PFDestroy(PF pf) 65292f8084SBarry Smith { 66292f8084SBarry Smith PetscErrorCode ierr; 67ace3abfcSBarry Smith PetscBool flg = PETSC_FALSE; 68292f8084SBarry Smith 69292f8084SBarry Smith PetscFunctionBegin; 700700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 717adad957SLisandro Dalcin if (--((PetscObject)pf)->refct > 0) PetscFunctionReturn(0); 72292f8084SBarry Smith 73*acfcf0e5SJed Brown ierr = PetscOptionsGetBool(((PetscObject)pf)->prefix,"-pf_view",&flg,PETSC_NULL);CHKERRQ(ierr); 74292f8084SBarry Smith if (flg) { 753050cee2SBarry Smith PetscViewer viewer; 767adad957SLisandro Dalcin ierr = PetscViewerASCIIGetStdout(((PetscObject)pf)->comm,&viewer);CHKERRQ(ierr); 773050cee2SBarry Smith ierr = PFView(pf,viewer);CHKERRQ(ierr); 78292f8084SBarry Smith } 79292f8084SBarry Smith 80292f8084SBarry Smith /* if memory was published with AMS then destroy it */ 81292f8084SBarry Smith ierr = PetscObjectDepublish(pf);CHKERRQ(ierr); 82292f8084SBarry Smith 83292f8084SBarry Smith if (pf->ops->destroy) {ierr = (*pf->ops->destroy)(pf->data);CHKERRQ(ierr);} 84d38fa0fbSBarry Smith ierr = PetscHeaderDestroy(pf);CHKERRQ(ierr); 85292f8084SBarry Smith PetscFunctionReturn(0); 86292f8084SBarry Smith } 87292f8084SBarry Smith 88292f8084SBarry Smith #undef __FUNCT__ 89292f8084SBarry Smith #define __FUNCT__ "PFCreate" 90292f8084SBarry Smith /*@C 91292f8084SBarry Smith PFCreate - Creates a mathematical function context. 92292f8084SBarry Smith 93292f8084SBarry Smith Collective on MPI_Comm 94292f8084SBarry Smith 95292f8084SBarry Smith Input Parameter: 96292f8084SBarry Smith + comm - MPI communicator 97292f8084SBarry Smith . dimin - dimension of the space you are mapping from 98292f8084SBarry Smith - dimout - dimension of the space you are mapping to 99292f8084SBarry Smith 100292f8084SBarry Smith Output Parameter: 101292f8084SBarry Smith . pf - the function context 102292f8084SBarry Smith 103292f8084SBarry Smith Level: developer 104292f8084SBarry Smith 105292f8084SBarry Smith .keywords: PF, create, context 106292f8084SBarry Smith 107292f8084SBarry Smith .seealso: PFSetUp(), PFApply(), PFDestroy(), PFApplyVec() 108292f8084SBarry Smith @*/ 1090c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT PFCreate(MPI_Comm comm,PetscInt dimin,PetscInt dimout,PF *pf) 110292f8084SBarry Smith { 111292f8084SBarry Smith PF newpf; 112292f8084SBarry Smith PetscErrorCode ierr; 113292f8084SBarry Smith 114292f8084SBarry Smith PetscFunctionBegin; 115292f8084SBarry Smith PetscValidPointer(pf,1); 116292f8084SBarry Smith *pf = PETSC_NULL; 117292f8084SBarry Smith #ifndef PETSC_USE_DYNAMIC_LIBRARIES 1189877f0dbSBarry Smith ierr = PFInitializePackage(PETSC_NULL);CHKERRQ(ierr); 119292f8084SBarry Smith #endif 120292f8084SBarry Smith 1210700a824SBarry Smith ierr = PetscHeaderCreate(newpf,_p_PF,struct _PFOps,PF_CLASSID,-1,"PF",comm,PFDestroy,PFView);CHKERRQ(ierr); 122292f8084SBarry Smith newpf->data = 0; 123292f8084SBarry Smith 124292f8084SBarry Smith newpf->ops->destroy = 0; 125292f8084SBarry Smith newpf->ops->apply = 0; 126292f8084SBarry Smith newpf->ops->applyvec = 0; 127292f8084SBarry Smith newpf->ops->view = 0; 128292f8084SBarry Smith newpf->dimin = dimin; 129292f8084SBarry Smith newpf->dimout = dimout; 130292f8084SBarry Smith 131292f8084SBarry Smith *pf = newpf; 132292f8084SBarry Smith PetscFunctionReturn(0); 133292f8084SBarry Smith 134292f8084SBarry Smith } 135292f8084SBarry Smith 136292f8084SBarry Smith /* -------------------------------------------------------------------------------*/ 137292f8084SBarry Smith 138292f8084SBarry Smith #undef __FUNCT__ 139292f8084SBarry Smith #define __FUNCT__ "PFApplyVec" 140292f8084SBarry Smith /*@ 141292f8084SBarry Smith PFApplyVec - Applies the mathematical function to a vector 142292f8084SBarry Smith 143292f8084SBarry Smith Collective on PF 144292f8084SBarry Smith 145292f8084SBarry Smith Input Parameters: 146292f8084SBarry Smith + pf - the function context 147292f8084SBarry Smith - x - input vector (or PETSC_NULL for the vector (0,1, .... N-1) 148292f8084SBarry Smith 149292f8084SBarry Smith Output Parameter: 150292f8084SBarry Smith . y - output vector 151292f8084SBarry Smith 152292f8084SBarry Smith Level: beginner 153292f8084SBarry Smith 154292f8084SBarry Smith .keywords: PF, apply 155292f8084SBarry Smith 156292f8084SBarry Smith .seealso: PFApply(), PFCreate(), PFDestroy(), PFSetType(), PFSet() 157292f8084SBarry Smith @*/ 1580c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT PFApplyVec(PF pf,Vec x,Vec y) 159292f8084SBarry Smith { 160292f8084SBarry Smith PetscErrorCode ierr; 161292f8084SBarry Smith PetscInt i,rstart,rend,n,p; 162ace3abfcSBarry Smith PetscBool nox = PETSC_FALSE; 163292f8084SBarry Smith 164292f8084SBarry Smith PetscFunctionBegin; 1650700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 1660700a824SBarry Smith PetscValidHeaderSpecific(y,VEC_CLASSID,3); 167292f8084SBarry Smith if (x) { 1680700a824SBarry Smith PetscValidHeaderSpecific(x,VEC_CLASSID,2); 169e32f2f54SBarry Smith if (x == y) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_IDN,"x and y must be different vectors"); 170292f8084SBarry Smith } else { 171292f8084SBarry Smith PetscScalar *xx; 172292f8084SBarry Smith 173292f8084SBarry Smith ierr = VecDuplicate(y,&x);CHKERRQ(ierr); 174292f8084SBarry Smith nox = PETSC_TRUE; 175292f8084SBarry Smith ierr = VecGetOwnershipRange(x,&rstart,&rend);CHKERRQ(ierr); 176292f8084SBarry Smith ierr = VecGetArray(x,&xx);CHKERRQ(ierr); 177292f8084SBarry Smith for (i=rstart; i<rend; i++) { 178292f8084SBarry Smith xx[i-rstart] = (PetscScalar)i; 179292f8084SBarry Smith } 180292f8084SBarry Smith ierr = VecRestoreArray(x,&xx);CHKERRQ(ierr); 181292f8084SBarry Smith } 182292f8084SBarry Smith 183292f8084SBarry Smith ierr = VecGetLocalSize(x,&n);CHKERRQ(ierr); 184292f8084SBarry Smith ierr = VecGetLocalSize(y,&p);CHKERRQ(ierr); 185e32f2f54SBarry 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); 186e32f2f54SBarry 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); 187e32f2f54SBarry 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); 188292f8084SBarry Smith 189292f8084SBarry Smith if (pf->ops->applyvec) { 190292f8084SBarry Smith ierr = (*pf->ops->applyvec)(pf->data,x,y);CHKERRQ(ierr); 191292f8084SBarry Smith } else { 192292f8084SBarry Smith PetscScalar *xx,*yy; 193292f8084SBarry Smith 194292f8084SBarry Smith ierr = VecGetLocalSize(x,&n);CHKERRQ(ierr); 195292f8084SBarry Smith n = n/pf->dimin; 196292f8084SBarry Smith ierr = VecGetArray(x,&xx);CHKERRQ(ierr); 197292f8084SBarry Smith ierr = VecGetArray(y,&yy);CHKERRQ(ierr); 198e32f2f54SBarry Smith if (!pf->ops->apply) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"No function has been provided for this PF"); 199292f8084SBarry Smith ierr = (*pf->ops->apply)(pf->data,n,xx,yy);CHKERRQ(ierr); 200292f8084SBarry Smith ierr = VecRestoreArray(x,&xx);CHKERRQ(ierr); 201292f8084SBarry Smith ierr = VecRestoreArray(y,&yy);CHKERRQ(ierr); 202292f8084SBarry Smith } 203292f8084SBarry Smith if (nox) { 204292f8084SBarry Smith ierr = VecDestroy(x);CHKERRQ(ierr); 205292f8084SBarry Smith } 206292f8084SBarry Smith PetscFunctionReturn(0); 207292f8084SBarry Smith } 208292f8084SBarry Smith 209292f8084SBarry Smith #undef __FUNCT__ 210292f8084SBarry Smith #define __FUNCT__ "PFApply" 211292f8084SBarry Smith /*@ 212292f8084SBarry Smith PFApply - Applies the mathematical function to an array of values. 213292f8084SBarry Smith 214292f8084SBarry Smith Collective on PF 215292f8084SBarry Smith 216292f8084SBarry Smith Input Parameters: 217292f8084SBarry Smith + pf - the function context 218292f8084SBarry Smith . n - number of pointwise function evaluations to perform, each pointwise function evaluation 219292f8084SBarry Smith is a function of dimin variables and computes dimout variables where dimin and dimout are defined 220292f8084SBarry Smith in the call to PFCreate() 221292f8084SBarry Smith - x - input array 222292f8084SBarry Smith 223292f8084SBarry Smith Output Parameter: 224292f8084SBarry Smith . y - output array 225292f8084SBarry Smith 226292f8084SBarry Smith Level: beginner 227292f8084SBarry Smith 228292f8084SBarry Smith Notes: 229292f8084SBarry Smith 230292f8084SBarry Smith .keywords: PF, apply 231292f8084SBarry Smith 232292f8084SBarry Smith .seealso: PFApplyVec(), PFCreate(), PFDestroy(), PFSetType(), PFSet() 233292f8084SBarry Smith @*/ 234dd394643SJed Brown PetscErrorCode PETSCVEC_DLLEXPORT PFApply(PF pf,PetscInt n,const PetscScalar* x,PetscScalar* y) 235292f8084SBarry Smith { 236292f8084SBarry Smith PetscErrorCode ierr; 237292f8084SBarry Smith 238292f8084SBarry Smith PetscFunctionBegin; 2390700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 240292f8084SBarry Smith PetscValidScalarPointer(x,2); 241292f8084SBarry Smith PetscValidScalarPointer(y,3); 242e32f2f54SBarry Smith if (x == y) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_IDN,"x and y must be different arrays"); 243e32f2f54SBarry Smith if (!pf->ops->apply) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"No function has been provided for this PF"); 244292f8084SBarry Smith 245292f8084SBarry Smith ierr = (*pf->ops->apply)(pf->data,n,x,y);CHKERRQ(ierr); 246292f8084SBarry Smith PetscFunctionReturn(0); 247292f8084SBarry Smith } 248292f8084SBarry Smith 249292f8084SBarry Smith #undef __FUNCT__ 250292f8084SBarry Smith #define __FUNCT__ "PFView" 251292f8084SBarry Smith /*@ 252292f8084SBarry Smith PFView - Prints information about a mathematical function 253292f8084SBarry Smith 254292f8084SBarry Smith Collective on PF unless PetscViewer is PETSC_VIEWER_STDOUT_SELF 255292f8084SBarry Smith 256292f8084SBarry Smith Input Parameters: 257292f8084SBarry Smith + PF - the PF context 258292f8084SBarry Smith - viewer - optional visualization context 259292f8084SBarry Smith 260292f8084SBarry Smith Note: 261292f8084SBarry Smith The available visualization contexts include 262292f8084SBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 263292f8084SBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 264292f8084SBarry Smith output where only the first processor opens 265292f8084SBarry Smith the file. All other processors send their 266292f8084SBarry Smith data to the first processor to print. 267292f8084SBarry Smith 268292f8084SBarry Smith The user can open an alternative visualization contexts with 269292f8084SBarry Smith PetscViewerASCIIOpen() (output to a specified file). 270292f8084SBarry Smith 271292f8084SBarry Smith Level: developer 272292f8084SBarry Smith 273292f8084SBarry Smith .keywords: PF, view 274292f8084SBarry Smith 275292f8084SBarry Smith .seealso: PetscViewerCreate(), PetscViewerASCIIOpen() 276292f8084SBarry Smith @*/ 2770c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT PFView(PF pf,PetscViewer viewer) 278292f8084SBarry Smith { 279292f8084SBarry Smith PetscErrorCode ierr; 280ace3abfcSBarry Smith PetscBool iascii; 281292f8084SBarry Smith PetscViewerFormat format; 282292f8084SBarry Smith 283292f8084SBarry Smith PetscFunctionBegin; 2840700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 2853050cee2SBarry Smith if (!viewer) { 2867adad957SLisandro Dalcin ierr = PetscViewerASCIIGetStdout(((PetscObject)pf)->comm,&viewer);CHKERRQ(ierr); 2873050cee2SBarry Smith } 2880700a824SBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 289292f8084SBarry Smith PetscCheckSameComm(pf,1,viewer,2); 290292f8084SBarry Smith 2912692d6eeSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 292292f8084SBarry Smith if (iascii) { 293292f8084SBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 294317d6ea6SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)pf,viewer,"PF Object");CHKERRQ(ierr); 295292f8084SBarry Smith if (pf->ops->view) { 296292f8084SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 297292f8084SBarry Smith ierr = (*pf->ops->view)(pf->data,viewer);CHKERRQ(ierr); 298292f8084SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 299292f8084SBarry Smith } 300292f8084SBarry Smith } else { 301e32f2f54SBarry Smith SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported by PF",((PetscObject)viewer)->type_name); 302292f8084SBarry Smith } 303292f8084SBarry Smith PetscFunctionReturn(0); 304292f8084SBarry Smith } 305292f8084SBarry Smith 306292f8084SBarry Smith /*MC 307292f8084SBarry Smith PFRegisterDynamic - Adds a method to the mathematical function package. 308292f8084SBarry Smith 309292f8084SBarry Smith Synopsis: 310d360dc6fSBarry Smith PetscErrorCode PFRegisterDynamic(char *name_solver,char *path,char *name_create,PetscErrorCode (*routine_create)(PF)) 311292f8084SBarry Smith 312292f8084SBarry Smith Not collective 313292f8084SBarry Smith 314292f8084SBarry Smith Input Parameters: 315292f8084SBarry Smith + name_solver - name of a new user-defined solver 316292f8084SBarry Smith . path - path (either absolute or relative) the library containing this solver 317292f8084SBarry Smith . name_create - name of routine to create method context 318292f8084SBarry Smith - routine_create - routine to create method context 319292f8084SBarry Smith 320292f8084SBarry Smith Notes: 321292f8084SBarry Smith PFRegisterDynamic() may be called multiple times to add several user-defined functions 322292f8084SBarry Smith 323292f8084SBarry Smith If dynamic libraries are used, then the fourth input argument (routine_create) 324292f8084SBarry Smith is ignored. 325292f8084SBarry Smith 326292f8084SBarry Smith Sample usage: 327292f8084SBarry Smith .vb 328292f8084SBarry Smith PFRegisterDynamic("my_function","/home/username/my_lib/lib/libO/solaris/mylib", 329292f8084SBarry Smith "MyFunctionCreate",MyFunctionSetCreate); 330292f8084SBarry Smith .ve 331292f8084SBarry Smith 332292f8084SBarry Smith Then, your solver can be chosen with the procedural interface via 333292f8084SBarry Smith $ PFSetType(pf,"my_function") 334292f8084SBarry Smith or at runtime via the option 335292f8084SBarry Smith $ -pf_type my_function 336292f8084SBarry Smith 337292f8084SBarry Smith Level: advanced 338292f8084SBarry Smith 339ab901514SBarry Smith ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, or ${any environmental variable} 340292f8084SBarry Smith occuring in pathname will be replaced with appropriate values. 341292f8084SBarry Smith 342292f8084SBarry Smith .keywords: PF, register 343292f8084SBarry Smith 344292f8084SBarry Smith .seealso: PFRegisterAll(), PFRegisterDestroy(), PFRegister() 345292f8084SBarry Smith M*/ 346292f8084SBarry Smith 347292f8084SBarry Smith #undef __FUNCT__ 348292f8084SBarry Smith #define __FUNCT__ "PFRegister" 3490c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT PFRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(PF,void*)) 350292f8084SBarry Smith { 351292f8084SBarry Smith PetscErrorCode ierr; 352292f8084SBarry Smith char fullname[PETSC_MAX_PATH_LEN]; 353292f8084SBarry Smith 354292f8084SBarry Smith PetscFunctionBegin; 355292f8084SBarry Smith ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr); 3561d280d73SBarry Smith ierr = PetscFListAdd(&PFList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr); 357292f8084SBarry Smith PetscFunctionReturn(0); 358292f8084SBarry Smith } 359292f8084SBarry Smith 360292f8084SBarry Smith #undef __FUNCT__ 361292f8084SBarry Smith #define __FUNCT__ "PFGetType" 362292f8084SBarry Smith /*@C 363292f8084SBarry Smith PFGetType - Gets the PF method type and name (as a string) from the PF 364292f8084SBarry Smith context. 365292f8084SBarry Smith 366292f8084SBarry Smith Not Collective 367292f8084SBarry Smith 368292f8084SBarry Smith Input Parameter: 369292f8084SBarry Smith . pf - the function context 370292f8084SBarry Smith 371292f8084SBarry Smith Output Parameter: 372c4e43342SLisandro Dalcin . type - name of function 373292f8084SBarry Smith 374292f8084SBarry Smith Level: intermediate 375292f8084SBarry Smith 376292f8084SBarry Smith .keywords: PF, get, method, name, type 377292f8084SBarry Smith 378292f8084SBarry Smith .seealso: PFSetType() 379292f8084SBarry Smith 380292f8084SBarry Smith @*/ 381c4e43342SLisandro Dalcin PetscErrorCode PETSCVEC_DLLEXPORT PFGetType(PF pf,const PFType *type) 382292f8084SBarry Smith { 383292f8084SBarry Smith PetscFunctionBegin; 3840700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 385c4e43342SLisandro Dalcin PetscValidPointer(type,2); 386c4e43342SLisandro Dalcin *type = ((PetscObject)pf)->type_name; 387292f8084SBarry Smith PetscFunctionReturn(0); 388292f8084SBarry Smith } 389292f8084SBarry Smith 390292f8084SBarry Smith 391292f8084SBarry Smith #undef __FUNCT__ 392292f8084SBarry Smith #define __FUNCT__ "PFSetType" 393292f8084SBarry Smith /*@C 394292f8084SBarry Smith PFSetType - Builds PF for a particular function 395292f8084SBarry Smith 396292f8084SBarry Smith Collective on PF 397292f8084SBarry Smith 398292f8084SBarry Smith Input Parameter: 399292f8084SBarry Smith + pf - the function context. 400292f8084SBarry Smith . type - a known method 401292f8084SBarry Smith - ctx - optional type dependent context 402292f8084SBarry Smith 403292f8084SBarry Smith Options Database Key: 404292f8084SBarry Smith . -pf_type <type> - Sets PF type 405292f8084SBarry Smith 406292f8084SBarry Smith 407292f8084SBarry Smith Notes: 408292f8084SBarry Smith See "petsc/include/petscpf.h" for available methods (for instance, 409292f8084SBarry Smith PFCONSTANT) 410292f8084SBarry Smith 411292f8084SBarry Smith Level: intermediate 412292f8084SBarry Smith 413292f8084SBarry Smith .keywords: PF, set, method, type 414292f8084SBarry Smith 415292f8084SBarry Smith .seealso: PFSet(), PFRegisterDynamic(), PFCreate(), DACreatePF() 416292f8084SBarry Smith 417292f8084SBarry Smith @*/ 418a313700dSBarry Smith PetscErrorCode PETSCVEC_DLLEXPORT PFSetType(PF pf,const PFType type,void *ctx) 419292f8084SBarry Smith { 420292f8084SBarry Smith PetscErrorCode ierr,(*r)(PF,void*); 421ace3abfcSBarry Smith PetscBool match; 422292f8084SBarry Smith 423292f8084SBarry Smith PetscFunctionBegin; 4240700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 425292f8084SBarry Smith PetscValidCharPointer(type,2); 426292f8084SBarry Smith 427292f8084SBarry Smith ierr = PetscTypeCompare((PetscObject)pf,type,&match);CHKERRQ(ierr); 428292f8084SBarry Smith if (match) PetscFunctionReturn(0); 429292f8084SBarry Smith 430292f8084SBarry Smith if (pf->ops->destroy) {ierr = (*pf->ops->destroy)(pf);CHKERRQ(ierr);} 431292f8084SBarry Smith pf->data = 0; 432292f8084SBarry Smith 433292f8084SBarry Smith /* Determine the PFCreateXXX routine for a particular function */ 4347adad957SLisandro Dalcin ierr = PetscFListFind(PFList,((PetscObject)pf)->comm,type,(void (**)(void)) &r);CHKERRQ(ierr); 435e32f2f54SBarry Smith if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested PF type %s",type); 436292f8084SBarry Smith pf->ops->destroy = 0; 437292f8084SBarry Smith pf->ops->view = 0; 438292f8084SBarry Smith pf->ops->apply = 0; 439292f8084SBarry Smith pf->ops->applyvec = 0; 440292f8084SBarry Smith 441292f8084SBarry Smith /* Call the PFCreateXXX routine for this particular function */ 442292f8084SBarry Smith ierr = (*r)(pf,ctx);CHKERRQ(ierr); 443292f8084SBarry Smith 444292f8084SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)pf,type);CHKERRQ(ierr); 445292f8084SBarry Smith PetscFunctionReturn(0); 446292f8084SBarry Smith } 447292f8084SBarry Smith 448292f8084SBarry Smith #undef __FUNCT__ 449292f8084SBarry Smith #define __FUNCT__ "PFSetFromOptions" 450292f8084SBarry Smith /*@ 451292f8084SBarry Smith PFSetFromOptions - Sets PF options from the options database. 452292f8084SBarry Smith 453292f8084SBarry Smith Collective on PF 454292f8084SBarry Smith 455292f8084SBarry Smith Input Parameters: 456292f8084SBarry Smith . pf - the mathematical function context 457292f8084SBarry Smith 458292f8084SBarry Smith Options Database Keys: 459292f8084SBarry Smith 460292f8084SBarry Smith Notes: 461292f8084SBarry Smith To see all options, run your program with the -help option 462292f8084SBarry Smith or consult the users manual. 463292f8084SBarry Smith 464292f8084SBarry Smith Level: intermediate 465292f8084SBarry Smith 466292f8084SBarry Smith .keywords: PF, set, from, options, database 467292f8084SBarry Smith 468292f8084SBarry Smith .seealso: 469292f8084SBarry Smith @*/ 4700c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT PFSetFromOptions(PF pf) 471292f8084SBarry Smith { 472292f8084SBarry Smith PetscErrorCode ierr; 473292f8084SBarry Smith char type[256]; 474ace3abfcSBarry Smith PetscBool flg; 475292f8084SBarry Smith 476292f8084SBarry Smith PetscFunctionBegin; 4770700a824SBarry Smith PetscValidHeaderSpecific(pf,PF_CLASSID,1); 478292f8084SBarry Smith 4797adad957SLisandro Dalcin ierr = PetscOptionsBegin(((PetscObject)pf)->comm,((PetscObject)pf)->prefix,"Mathematical functions options","Vec");CHKERRQ(ierr); 4801d280d73SBarry Smith ierr = PetscOptionsList("-pf_type","Type of function","PFSetType",PFList,0,type,256,&flg);CHKERRQ(ierr); 481292f8084SBarry Smith if (flg) { 482292f8084SBarry Smith ierr = PFSetType(pf,type,PETSC_NULL);CHKERRQ(ierr); 483292f8084SBarry Smith } 484292f8084SBarry Smith if (pf->ops->setfromoptions) { 485292f8084SBarry Smith ierr = (*pf->ops->setfromoptions)(pf);CHKERRQ(ierr); 486292f8084SBarry Smith } 4875d973c19SBarry Smith 4885d973c19SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 4895d973c19SBarry Smith ierr = PetscObjectProcessOptionsHandlers((PetscObject)pf);CHKERRQ(ierr); 490292f8084SBarry Smith ierr = PetscOptionsEnd();CHKERRQ(ierr); 491292f8084SBarry Smith 492292f8084SBarry Smith PetscFunctionReturn(0); 493292f8084SBarry Smith } 494292f8084SBarry Smith 495ace3abfcSBarry Smith static PetscBool PFPackageInitialized = PETSC_FALSE; 496b022a5c1SBarry Smith #undef __FUNCT__ 497b022a5c1SBarry Smith #define __FUNCT__ "PFFinalizePackage" 498b022a5c1SBarry Smith /*@C 499b022a5c1SBarry Smith PFFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is 500b022a5c1SBarry Smith called from PetscFinalize(). 501b022a5c1SBarry Smith 502b022a5c1SBarry Smith Level: developer 503b022a5c1SBarry Smith 504b022a5c1SBarry Smith .keywords: Petsc, destroy, package, mathematica 505b022a5c1SBarry Smith .seealso: PetscFinalize() 506b022a5c1SBarry Smith @*/ 507cfb32e20SJed Brown PetscErrorCode PETSCVEC_DLLEXPORT PFFinalizePackage(void) 508b022a5c1SBarry Smith { 509b022a5c1SBarry Smith PetscFunctionBegin; 510b022a5c1SBarry Smith PFPackageInitialized = PETSC_FALSE; 511b022a5c1SBarry Smith PFList = PETSC_NULL; 512b022a5c1SBarry Smith PFRegisterAllCalled = PETSC_FALSE; 513b022a5c1SBarry Smith PetscFunctionReturn(0); 514b022a5c1SBarry Smith } 515b022a5c1SBarry Smith 5169877f0dbSBarry Smith #undef __FUNCT__ 5179877f0dbSBarry Smith #define __FUNCT__ "PFInitializePackage" 5189877f0dbSBarry Smith /*@C 5199877f0dbSBarry Smith PFInitializePackage - This function initializes everything in the PF package. It is called 5209877f0dbSBarry Smith from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to PFCreate() 5219877f0dbSBarry Smith when using static libraries. 5229877f0dbSBarry Smith 5239877f0dbSBarry Smith Input Parameter: 5249877f0dbSBarry Smith . path - The dynamic library path, or PETSC_NULL 5259877f0dbSBarry Smith 5269877f0dbSBarry Smith Level: developer 5279877f0dbSBarry Smith 5289877f0dbSBarry Smith .keywords: Vec, initialize, package 5299877f0dbSBarry Smith .seealso: PetscInitialize() 5309877f0dbSBarry Smith @*/ 5319877f0dbSBarry Smith PetscErrorCode PETSCVEC_DLLEXPORT PFInitializePackage(const char path[]) 5329877f0dbSBarry Smith { 5339877f0dbSBarry Smith char logList[256]; 5349877f0dbSBarry Smith char *className; 535ace3abfcSBarry Smith PetscBool opt; 5369877f0dbSBarry Smith PetscErrorCode ierr; 5379877f0dbSBarry Smith 5389877f0dbSBarry Smith PetscFunctionBegin; 539b022a5c1SBarry Smith if (PFPackageInitialized) PetscFunctionReturn(0); 540b022a5c1SBarry Smith PFPackageInitialized = PETSC_TRUE; 5419877f0dbSBarry Smith /* Register Classes */ 5420700a824SBarry Smith ierr = PetscClassIdRegister("PointFunction",&PF_CLASSID);CHKERRQ(ierr); 5439877f0dbSBarry Smith /* Register Constructors */ 5449877f0dbSBarry Smith ierr = PFRegisterAll(path);CHKERRQ(ierr); 5459877f0dbSBarry Smith /* Process info exclusions */ 5469877f0dbSBarry Smith ierr = PetscOptionsGetString(PETSC_NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); 5479877f0dbSBarry Smith if (opt) { 5489877f0dbSBarry Smith ierr = PetscStrstr(logList, "pf", &className);CHKERRQ(ierr); 5499877f0dbSBarry Smith if (className) { 5500700a824SBarry Smith ierr = PetscInfoDeactivateClass(PF_CLASSID);CHKERRQ(ierr); 5519877f0dbSBarry Smith } 5529877f0dbSBarry Smith } 5539877f0dbSBarry Smith /* Process summary exclusions */ 5549877f0dbSBarry Smith ierr = PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr); 5559877f0dbSBarry Smith if (opt) { 5569877f0dbSBarry Smith ierr = PetscStrstr(logList, "pf", &className);CHKERRQ(ierr); 5579877f0dbSBarry Smith if (className) { 5580700a824SBarry Smith ierr = PetscLogEventDeactivateClass(PF_CLASSID);CHKERRQ(ierr); 5599877f0dbSBarry Smith } 5609877f0dbSBarry Smith } 561b022a5c1SBarry Smith ierr = PetscRegisterFinalize(PFFinalizePackage);CHKERRQ(ierr); 5629877f0dbSBarry Smith PetscFunctionReturn(0); 5639877f0dbSBarry Smith } 564292f8084SBarry Smith 565292f8084SBarry Smith 566292f8084SBarry Smith 567292f8084SBarry Smith 568292f8084SBarry Smith 569292f8084SBarry Smith 570292f8084SBarry Smith 571292f8084SBarry Smith 572292f8084SBarry Smith 573