120cf1dd8SToby Isaac #include <petsc/private/petscfeimpl.h> /*I "petscfe.h" I*/ 220cf1dd8SToby Isaac #include <petscdmplex.h> 320cf1dd8SToby Isaac 420cf1dd8SToby Isaac PetscClassId PETSCDUALSPACE_CLASSID = 0; 520cf1dd8SToby Isaac 620cf1dd8SToby Isaac PetscFunctionList PetscDualSpaceList = NULL; 720cf1dd8SToby Isaac PetscBool PetscDualSpaceRegisterAllCalled = PETSC_FALSE; 820cf1dd8SToby Isaac 955cc6565SMatthew G. Knepley const char *const PetscDualSpaceReferenceCells[] = {"SIMPLEX", "TENSOR", "PetscDualSpaceReferenceCell", "PETSCDUALSPACE_REFCELL_",0}; 1055cc6565SMatthew G. Knepley 116f905325SMatthew G. Knepley /* 126f905325SMatthew G. Knepley PetscDualSpaceLatticePointLexicographic_Internal - Returns all tuples of size 'len' with nonnegative integers that sum up to at most 'max'. 136f905325SMatthew G. Knepley Ordering is lexicographic with lowest index as least significant in ordering. 146f905325SMatthew G. Knepley e.g. for len == 2 and max == 2, this will return, in order, {0,0}, {1,0}, {2,0}, {0,1}, {1,1}, {2,0}. 156f905325SMatthew G. Knepley 166f905325SMatthew G. Knepley Input Parameters: 176f905325SMatthew G. Knepley + len - The length of the tuple 186f905325SMatthew G. Knepley . max - The maximum sum 196f905325SMatthew G. Knepley - tup - A tuple of length len+1: tup[len] > 0 indicates a stopping condition 206f905325SMatthew G. Knepley 216f905325SMatthew G. Knepley Output Parameter: 226f905325SMatthew G. Knepley . tup - A tuple of len integers whos sum is at most 'max' 236f905325SMatthew G. Knepley 246f905325SMatthew G. Knepley Level: developer 256f905325SMatthew G. Knepley 266f905325SMatthew G. Knepley .seealso: PetscDualSpaceTensorPointLexicographic_Internal() 276f905325SMatthew G. Knepley */ 286f905325SMatthew G. Knepley PetscErrorCode PetscDualSpaceLatticePointLexicographic_Internal(PetscInt len, PetscInt max, PetscInt tup[]) 296f905325SMatthew G. Knepley { 306f905325SMatthew G. Knepley PetscFunctionBegin; 316f905325SMatthew G. Knepley while (len--) { 326f905325SMatthew G. Knepley max -= tup[len]; 336f905325SMatthew G. Knepley if (!max) { 346f905325SMatthew G. Knepley tup[len] = 0; 356f905325SMatthew G. Knepley break; 366f905325SMatthew G. Knepley } 376f905325SMatthew G. Knepley } 386f905325SMatthew G. Knepley tup[++len]++; 396f905325SMatthew G. Knepley PetscFunctionReturn(0); 406f905325SMatthew G. Knepley } 416f905325SMatthew G. Knepley 426f905325SMatthew G. Knepley /* 436f905325SMatthew G. Knepley PetscDualSpaceTensorPointLexicographic_Internal - Returns all tuples of size 'len' with nonnegative integers that are all less than or equal to 'max'. 446f905325SMatthew G. Knepley Ordering is lexicographic with lowest index as least significant in ordering. 456f905325SMatthew G. Knepley e.g. for len == 2 and max == 2, this will return, in order, {0,0}, {1,0}, {2,0}, {0,1}, {1,1}, {2,1}, {0,2}, {1,2}, {2,2}. 466f905325SMatthew G. Knepley 476f905325SMatthew G. Knepley Input Parameters: 486f905325SMatthew G. Knepley + len - The length of the tuple 496f905325SMatthew G. Knepley . max - The maximum value 506f905325SMatthew G. Knepley - tup - A tuple of length len+1: tup[len] > 0 indicates a stopping condition 516f905325SMatthew G. Knepley 526f905325SMatthew G. Knepley Output Parameter: 536f905325SMatthew G. Knepley . tup - A tuple of len integers whos sum is at most 'max' 546f905325SMatthew G. Knepley 556f905325SMatthew G. Knepley Level: developer 566f905325SMatthew G. Knepley 576f905325SMatthew G. Knepley .seealso: PetscDualSpaceLatticePointLexicographic_Internal() 586f905325SMatthew G. Knepley */ 596f905325SMatthew G. Knepley PetscErrorCode PetscDualSpaceTensorPointLexicographic_Internal(PetscInt len, PetscInt max, PetscInt tup[]) 606f905325SMatthew G. Knepley { 616f905325SMatthew G. Knepley PetscInt i; 626f905325SMatthew G. Knepley 636f905325SMatthew G. Knepley PetscFunctionBegin; 646f905325SMatthew G. Knepley for (i = 0; i < len; i++) { 656f905325SMatthew G. Knepley if (tup[i] < max) { 666f905325SMatthew G. Knepley break; 676f905325SMatthew G. Knepley } else { 686f905325SMatthew G. Knepley tup[i] = 0; 696f905325SMatthew G. Knepley } 706f905325SMatthew G. Knepley } 716f905325SMatthew G. Knepley tup[i]++; 726f905325SMatthew G. Knepley PetscFunctionReturn(0); 736f905325SMatthew G. Knepley } 746f905325SMatthew G. Knepley 7520cf1dd8SToby Isaac /*@C 7620cf1dd8SToby Isaac PetscDualSpaceRegister - Adds a new PetscDualSpace implementation 7720cf1dd8SToby Isaac 7820cf1dd8SToby Isaac Not Collective 7920cf1dd8SToby Isaac 8020cf1dd8SToby Isaac Input Parameters: 8120cf1dd8SToby Isaac + name - The name of a new user-defined creation routine 8220cf1dd8SToby Isaac - create_func - The creation routine itself 8320cf1dd8SToby Isaac 8420cf1dd8SToby Isaac Notes: 8520cf1dd8SToby Isaac PetscDualSpaceRegister() may be called multiple times to add several user-defined PetscDualSpaces 8620cf1dd8SToby Isaac 8720cf1dd8SToby Isaac Sample usage: 8820cf1dd8SToby Isaac .vb 8920cf1dd8SToby Isaac PetscDualSpaceRegister("my_space", MyPetscDualSpaceCreate); 9020cf1dd8SToby Isaac .ve 9120cf1dd8SToby Isaac 9220cf1dd8SToby Isaac Then, your PetscDualSpace type can be chosen with the procedural interface via 9320cf1dd8SToby Isaac .vb 9420cf1dd8SToby Isaac PetscDualSpaceCreate(MPI_Comm, PetscDualSpace *); 9520cf1dd8SToby Isaac PetscDualSpaceSetType(PetscDualSpace, "my_dual_space"); 9620cf1dd8SToby Isaac .ve 9720cf1dd8SToby Isaac or at runtime via the option 9820cf1dd8SToby Isaac .vb 9920cf1dd8SToby Isaac -petscdualspace_type my_dual_space 10020cf1dd8SToby Isaac .ve 10120cf1dd8SToby Isaac 10220cf1dd8SToby Isaac Level: advanced 10320cf1dd8SToby Isaac 10420cf1dd8SToby Isaac .keywords: PetscDualSpace, register 10520cf1dd8SToby Isaac .seealso: PetscDualSpaceRegisterAll(), PetscDualSpaceRegisterDestroy() 10620cf1dd8SToby Isaac 10720cf1dd8SToby Isaac @*/ 10820cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceRegister(const char sname[], PetscErrorCode (*function)(PetscDualSpace)) 10920cf1dd8SToby Isaac { 11020cf1dd8SToby Isaac PetscErrorCode ierr; 11120cf1dd8SToby Isaac 11220cf1dd8SToby Isaac PetscFunctionBegin; 11320cf1dd8SToby Isaac ierr = PetscFunctionListAdd(&PetscDualSpaceList, sname, function);CHKERRQ(ierr); 11420cf1dd8SToby Isaac PetscFunctionReturn(0); 11520cf1dd8SToby Isaac } 11620cf1dd8SToby Isaac 11720cf1dd8SToby Isaac /*@C 11820cf1dd8SToby Isaac PetscDualSpaceSetType - Builds a particular PetscDualSpace 11920cf1dd8SToby Isaac 12020cf1dd8SToby Isaac Collective on PetscDualSpace 12120cf1dd8SToby Isaac 12220cf1dd8SToby Isaac Input Parameters: 12320cf1dd8SToby Isaac + sp - The PetscDualSpace object 12420cf1dd8SToby Isaac - name - The kind of space 12520cf1dd8SToby Isaac 12620cf1dd8SToby Isaac Options Database Key: 12720cf1dd8SToby Isaac . -petscdualspace_type <type> - Sets the PetscDualSpace type; use -help for a list of available types 12820cf1dd8SToby Isaac 12920cf1dd8SToby Isaac Level: intermediate 13020cf1dd8SToby Isaac 13120cf1dd8SToby Isaac .keywords: PetscDualSpace, set, type 13220cf1dd8SToby Isaac .seealso: PetscDualSpaceGetType(), PetscDualSpaceCreate() 13320cf1dd8SToby Isaac @*/ 13420cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceSetType(PetscDualSpace sp, PetscDualSpaceType name) 13520cf1dd8SToby Isaac { 13620cf1dd8SToby Isaac PetscErrorCode (*r)(PetscDualSpace); 13720cf1dd8SToby Isaac PetscBool match; 13820cf1dd8SToby Isaac PetscErrorCode ierr; 13920cf1dd8SToby Isaac 14020cf1dd8SToby Isaac PetscFunctionBegin; 14120cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 14220cf1dd8SToby Isaac ierr = PetscObjectTypeCompare((PetscObject) sp, name, &match);CHKERRQ(ierr); 14320cf1dd8SToby Isaac if (match) PetscFunctionReturn(0); 14420cf1dd8SToby Isaac 14520cf1dd8SToby Isaac if (!PetscDualSpaceRegisterAllCalled) {ierr = PetscDualSpaceRegisterAll();CHKERRQ(ierr);} 14620cf1dd8SToby Isaac ierr = PetscFunctionListFind(PetscDualSpaceList, name, &r);CHKERRQ(ierr); 14720cf1dd8SToby Isaac if (!r) SETERRQ1(PetscObjectComm((PetscObject) sp), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDualSpace type: %s", name); 14820cf1dd8SToby Isaac 14920cf1dd8SToby Isaac if (sp->ops->destroy) { 15020cf1dd8SToby Isaac ierr = (*sp->ops->destroy)(sp);CHKERRQ(ierr); 15120cf1dd8SToby Isaac sp->ops->destroy = NULL; 15220cf1dd8SToby Isaac } 15320cf1dd8SToby Isaac ierr = (*r)(sp);CHKERRQ(ierr); 15420cf1dd8SToby Isaac ierr = PetscObjectChangeTypeName((PetscObject) sp, name);CHKERRQ(ierr); 15520cf1dd8SToby Isaac PetscFunctionReturn(0); 15620cf1dd8SToby Isaac } 15720cf1dd8SToby Isaac 15820cf1dd8SToby Isaac /*@C 15920cf1dd8SToby Isaac PetscDualSpaceGetType - Gets the PetscDualSpace type name (as a string) from the object. 16020cf1dd8SToby Isaac 16120cf1dd8SToby Isaac Not Collective 16220cf1dd8SToby Isaac 16320cf1dd8SToby Isaac Input Parameter: 16420cf1dd8SToby Isaac . sp - The PetscDualSpace 16520cf1dd8SToby Isaac 16620cf1dd8SToby Isaac Output Parameter: 16720cf1dd8SToby Isaac . name - The PetscDualSpace type name 16820cf1dd8SToby Isaac 16920cf1dd8SToby Isaac Level: intermediate 17020cf1dd8SToby Isaac 17120cf1dd8SToby Isaac .keywords: PetscDualSpace, get, type, name 17220cf1dd8SToby Isaac .seealso: PetscDualSpaceSetType(), PetscDualSpaceCreate() 17320cf1dd8SToby Isaac @*/ 17420cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetType(PetscDualSpace sp, PetscDualSpaceType *name) 17520cf1dd8SToby Isaac { 17620cf1dd8SToby Isaac PetscErrorCode ierr; 17720cf1dd8SToby Isaac 17820cf1dd8SToby Isaac PetscFunctionBegin; 17920cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 18020cf1dd8SToby Isaac PetscValidPointer(name, 2); 18120cf1dd8SToby Isaac if (!PetscDualSpaceRegisterAllCalled) { 18220cf1dd8SToby Isaac ierr = PetscDualSpaceRegisterAll();CHKERRQ(ierr); 18320cf1dd8SToby Isaac } 18420cf1dd8SToby Isaac *name = ((PetscObject) sp)->type_name; 18520cf1dd8SToby Isaac PetscFunctionReturn(0); 18620cf1dd8SToby Isaac } 18720cf1dd8SToby Isaac 188221d6281SMatthew G. Knepley static PetscErrorCode PetscDualSpaceView_ASCII(PetscDualSpace sp, PetscViewer v) 189221d6281SMatthew G. Knepley { 190221d6281SMatthew G. Knepley PetscViewerFormat format; 191221d6281SMatthew G. Knepley PetscInt pdim, f; 192221d6281SMatthew G. Knepley PetscErrorCode ierr; 193221d6281SMatthew G. Knepley 194221d6281SMatthew G. Knepley PetscFunctionBegin; 195221d6281SMatthew G. Knepley ierr = PetscDualSpaceGetDimension(sp, &pdim);CHKERRQ(ierr); 196221d6281SMatthew G. Knepley ierr = PetscObjectPrintClassNamePrefixType((PetscObject) sp, v);CHKERRQ(ierr); 197221d6281SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(v);CHKERRQ(ierr); 198221d6281SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(v, "Dual space with %D components, size %D\n", sp->Nc, pdim);CHKERRQ(ierr); 199221d6281SMatthew G. Knepley if (sp->ops->view) {ierr = (*sp->ops->view)(sp, v);CHKERRQ(ierr);} 200221d6281SMatthew G. Knepley ierr = PetscViewerGetFormat(v, &format);CHKERRQ(ierr); 201221d6281SMatthew G. Knepley if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 202221d6281SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(v);CHKERRQ(ierr); 203221d6281SMatthew G. Knepley for (f = 0; f < pdim; ++f) { 204221d6281SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(v, "Dual basis vector %D\n", f);CHKERRQ(ierr); 205221d6281SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(v);CHKERRQ(ierr); 206221d6281SMatthew G. Knepley ierr = PetscQuadratureView(sp->functional[f], v);CHKERRQ(ierr); 207221d6281SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(v);CHKERRQ(ierr); 208221d6281SMatthew G. Knepley } 209221d6281SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(v);CHKERRQ(ierr); 210221d6281SMatthew G. Knepley } 211221d6281SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(v);CHKERRQ(ierr); 212221d6281SMatthew G. Knepley PetscFunctionReturn(0); 213221d6281SMatthew G. Knepley } 214221d6281SMatthew G. Knepley 21520cf1dd8SToby Isaac /*@ 21620cf1dd8SToby Isaac PetscDualSpaceView - Views a PetscDualSpace 21720cf1dd8SToby Isaac 21820cf1dd8SToby Isaac Collective on PetscDualSpace 21920cf1dd8SToby Isaac 22020cf1dd8SToby Isaac Input Parameter: 22120cf1dd8SToby Isaac + sp - the PetscDualSpace object to view 22220cf1dd8SToby Isaac - v - the viewer 22320cf1dd8SToby Isaac 22420cf1dd8SToby Isaac Level: developer 22520cf1dd8SToby Isaac 22620cf1dd8SToby Isaac .seealso PetscDualSpaceDestroy() 22720cf1dd8SToby Isaac @*/ 22820cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceView(PetscDualSpace sp, PetscViewer v) 22920cf1dd8SToby Isaac { 230d9bac1caSLisandro Dalcin PetscBool iascii; 23120cf1dd8SToby Isaac PetscErrorCode ierr; 23220cf1dd8SToby Isaac 23320cf1dd8SToby Isaac PetscFunctionBegin; 23420cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 235d9bac1caSLisandro Dalcin if (v) PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2); 23620cf1dd8SToby Isaac if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) sp), &v);CHKERRQ(ierr);} 237d9bac1caSLisandro Dalcin ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 238221d6281SMatthew G. Knepley if (iascii) {ierr = PetscDualSpaceView_ASCII(sp, v);CHKERRQ(ierr);} 23920cf1dd8SToby Isaac PetscFunctionReturn(0); 24020cf1dd8SToby Isaac } 24120cf1dd8SToby Isaac 24220cf1dd8SToby Isaac /*@ 24320cf1dd8SToby Isaac PetscDualSpaceSetFromOptions - sets parameters in a PetscDualSpace from the options database 24420cf1dd8SToby Isaac 24520cf1dd8SToby Isaac Collective on PetscDualSpace 24620cf1dd8SToby Isaac 24720cf1dd8SToby Isaac Input Parameter: 24820cf1dd8SToby Isaac . sp - the PetscDualSpace object to set options for 24920cf1dd8SToby Isaac 25020cf1dd8SToby Isaac Options Database: 2517be5e748SToby Isaac . -petscspace_degree the approximation order of the space 25220cf1dd8SToby Isaac 25320cf1dd8SToby Isaac Level: developer 25420cf1dd8SToby Isaac 25520cf1dd8SToby Isaac .seealso PetscDualSpaceView() 25620cf1dd8SToby Isaac @*/ 25720cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceSetFromOptions(PetscDualSpace sp) 25820cf1dd8SToby Isaac { 259063ee4adSMatthew G. Knepley PetscDualSpaceReferenceCell refCell = PETSCDUALSPACE_REFCELL_SIMPLEX; 260063ee4adSMatthew G. Knepley PetscInt refDim = 0; 261063ee4adSMatthew G. Knepley PetscBool flg; 26220cf1dd8SToby Isaac const char *defaultType; 26320cf1dd8SToby Isaac char name[256]; 26420cf1dd8SToby Isaac PetscErrorCode ierr; 26520cf1dd8SToby Isaac 26620cf1dd8SToby Isaac PetscFunctionBegin; 26720cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 26820cf1dd8SToby Isaac if (!((PetscObject) sp)->type_name) { 26920cf1dd8SToby Isaac defaultType = PETSCDUALSPACELAGRANGE; 27020cf1dd8SToby Isaac } else { 27120cf1dd8SToby Isaac defaultType = ((PetscObject) sp)->type_name; 27220cf1dd8SToby Isaac } 27320cf1dd8SToby Isaac if (!PetscSpaceRegisterAllCalled) {ierr = PetscSpaceRegisterAll();CHKERRQ(ierr);} 27420cf1dd8SToby Isaac 27520cf1dd8SToby Isaac ierr = PetscObjectOptionsBegin((PetscObject) sp);CHKERRQ(ierr); 27620cf1dd8SToby Isaac ierr = PetscOptionsFList("-petscdualspace_type", "Dual space", "PetscDualSpaceSetType", PetscDualSpaceList, defaultType, name, 256, &flg);CHKERRQ(ierr); 27720cf1dd8SToby Isaac if (flg) { 27820cf1dd8SToby Isaac ierr = PetscDualSpaceSetType(sp, name);CHKERRQ(ierr); 27920cf1dd8SToby Isaac } else if (!((PetscObject) sp)->type_name) { 28020cf1dd8SToby Isaac ierr = PetscDualSpaceSetType(sp, defaultType);CHKERRQ(ierr); 28120cf1dd8SToby Isaac } 2827be5e748SToby Isaac ierr = PetscOptionsInt("-petscdualspace_degree", "The approximation order", "PetscDualSpaceSetOrder", sp->order, &sp->order, NULL);CHKERRQ(ierr); 28320cf1dd8SToby Isaac ierr = PetscOptionsInt("-petscdualspace_components", "The number of components", "PetscDualSpaceSetNumComponents", sp->Nc, &sp->Nc, NULL);CHKERRQ(ierr); 28420cf1dd8SToby Isaac if (sp->ops->setfromoptions) { 28520cf1dd8SToby Isaac ierr = (*sp->ops->setfromoptions)(PetscOptionsObject,sp);CHKERRQ(ierr); 28620cf1dd8SToby Isaac } 287063ee4adSMatthew G. Knepley ierr = PetscOptionsInt("-petscdualspace_refdim", "The spatial dimension of the reference cell", "PetscDualSpaceSetReferenceCell", refDim, &refDim, NULL);CHKERRQ(ierr); 288063ee4adSMatthew G. Knepley ierr = PetscOptionsEnum("-petscdualspace_refcell", "Reference cell", "PetscDualSpaceSetReferenceCell", PetscDualSpaceReferenceCells, (PetscEnum) refCell, (PetscEnum *) &refCell, &flg);CHKERRQ(ierr); 289063ee4adSMatthew G. Knepley if (flg) { 290063ee4adSMatthew G. Knepley DM K; 291063ee4adSMatthew G. Knepley 292063ee4adSMatthew G. Knepley if (!refDim) SETERRQ(PetscObjectComm((PetscObject) sp), PETSC_ERR_ARG_INCOMP, "Reference cell specified without a dimension. Use -petscdualspace_refdim."); 293063ee4adSMatthew G. Knepley ierr = PetscDualSpaceCreateReferenceCell(sp, refDim, refCell == PETSCDUALSPACE_REFCELL_SIMPLEX ? PETSC_TRUE : PETSC_FALSE, &K);CHKERRQ(ierr); 294063ee4adSMatthew G. Knepley ierr = PetscDualSpaceSetDM(sp, K);CHKERRQ(ierr); 295063ee4adSMatthew G. Knepley ierr = DMDestroy(&K);CHKERRQ(ierr); 296063ee4adSMatthew G. Knepley } 297063ee4adSMatthew G. Knepley 29820cf1dd8SToby Isaac /* process any options handlers added with PetscObjectAddOptionsHandler() */ 29920cf1dd8SToby Isaac ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) sp);CHKERRQ(ierr); 30020cf1dd8SToby Isaac ierr = PetscOptionsEnd();CHKERRQ(ierr); 301063ee4adSMatthew G. Knepley sp->setfromoptionscalled = PETSC_TRUE; 30220cf1dd8SToby Isaac PetscFunctionReturn(0); 30320cf1dd8SToby Isaac } 30420cf1dd8SToby Isaac 30520cf1dd8SToby Isaac /*@ 30620cf1dd8SToby Isaac PetscDualSpaceSetUp - Construct a basis for the PetscDualSpace 30720cf1dd8SToby Isaac 30820cf1dd8SToby Isaac Collective on PetscDualSpace 30920cf1dd8SToby Isaac 31020cf1dd8SToby Isaac Input Parameter: 31120cf1dd8SToby Isaac . sp - the PetscDualSpace object to setup 31220cf1dd8SToby Isaac 31320cf1dd8SToby Isaac Level: developer 31420cf1dd8SToby Isaac 31520cf1dd8SToby Isaac .seealso PetscDualSpaceView(), PetscDualSpaceDestroy() 31620cf1dd8SToby Isaac @*/ 31720cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceSetUp(PetscDualSpace sp) 31820cf1dd8SToby Isaac { 31920cf1dd8SToby Isaac PetscErrorCode ierr; 32020cf1dd8SToby Isaac 32120cf1dd8SToby Isaac PetscFunctionBegin; 32220cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 32320cf1dd8SToby Isaac if (sp->setupcalled) PetscFunctionReturn(0); 32420cf1dd8SToby Isaac sp->setupcalled = PETSC_TRUE; 32520cf1dd8SToby Isaac if (sp->ops->setup) {ierr = (*sp->ops->setup)(sp);CHKERRQ(ierr);} 326063ee4adSMatthew G. Knepley if (sp->setfromoptionscalled) {ierr = PetscDualSpaceViewFromOptions(sp, NULL, "-petscdualspace_view");CHKERRQ(ierr);} 32720cf1dd8SToby Isaac PetscFunctionReturn(0); 32820cf1dd8SToby Isaac } 32920cf1dd8SToby Isaac 33020cf1dd8SToby Isaac /*@ 33120cf1dd8SToby Isaac PetscDualSpaceDestroy - Destroys a PetscDualSpace object 33220cf1dd8SToby Isaac 33320cf1dd8SToby Isaac Collective on PetscDualSpace 33420cf1dd8SToby Isaac 33520cf1dd8SToby Isaac Input Parameter: 33620cf1dd8SToby Isaac . sp - the PetscDualSpace object to destroy 33720cf1dd8SToby Isaac 33820cf1dd8SToby Isaac Level: developer 33920cf1dd8SToby Isaac 34020cf1dd8SToby Isaac .seealso PetscDualSpaceView() 34120cf1dd8SToby Isaac @*/ 34220cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceDestroy(PetscDualSpace *sp) 34320cf1dd8SToby Isaac { 34420cf1dd8SToby Isaac PetscInt dim, f; 34520cf1dd8SToby Isaac PetscErrorCode ierr; 34620cf1dd8SToby Isaac 34720cf1dd8SToby Isaac PetscFunctionBegin; 34820cf1dd8SToby Isaac if (!*sp) PetscFunctionReturn(0); 34920cf1dd8SToby Isaac PetscValidHeaderSpecific((*sp), PETSCDUALSPACE_CLASSID, 1); 35020cf1dd8SToby Isaac 35120cf1dd8SToby Isaac if (--((PetscObject)(*sp))->refct > 0) {*sp = 0; PetscFunctionReturn(0);} 35220cf1dd8SToby Isaac ((PetscObject) (*sp))->refct = 0; 35320cf1dd8SToby Isaac 35420cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension(*sp, &dim);CHKERRQ(ierr); 35520cf1dd8SToby Isaac for (f = 0; f < dim; ++f) { 35620cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&(*sp)->functional[f]);CHKERRQ(ierr); 35720cf1dd8SToby Isaac } 35820cf1dd8SToby Isaac ierr = PetscFree((*sp)->functional);CHKERRQ(ierr); 35920cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&(*sp)->allPoints);CHKERRQ(ierr); 36020cf1dd8SToby Isaac ierr = DMDestroy(&(*sp)->dm);CHKERRQ(ierr); 36120cf1dd8SToby Isaac 36220cf1dd8SToby Isaac if ((*sp)->ops->destroy) {ierr = (*(*sp)->ops->destroy)(*sp);CHKERRQ(ierr);} 36320cf1dd8SToby Isaac ierr = PetscHeaderDestroy(sp);CHKERRQ(ierr); 36420cf1dd8SToby Isaac PetscFunctionReturn(0); 36520cf1dd8SToby Isaac } 36620cf1dd8SToby Isaac 36720cf1dd8SToby Isaac /*@ 36820cf1dd8SToby Isaac PetscDualSpaceCreate - Creates an empty PetscDualSpace object. The type can then be set with PetscDualSpaceSetType(). 36920cf1dd8SToby Isaac 37020cf1dd8SToby Isaac Collective on MPI_Comm 37120cf1dd8SToby Isaac 37220cf1dd8SToby Isaac Input Parameter: 37320cf1dd8SToby Isaac . comm - The communicator for the PetscDualSpace object 37420cf1dd8SToby Isaac 37520cf1dd8SToby Isaac Output Parameter: 37620cf1dd8SToby Isaac . sp - The PetscDualSpace object 37720cf1dd8SToby Isaac 37820cf1dd8SToby Isaac Level: beginner 37920cf1dd8SToby Isaac 38020cf1dd8SToby Isaac .seealso: PetscDualSpaceSetType(), PETSCDUALSPACELAGRANGE 38120cf1dd8SToby Isaac @*/ 38220cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceCreate(MPI_Comm comm, PetscDualSpace *sp) 38320cf1dd8SToby Isaac { 38420cf1dd8SToby Isaac PetscDualSpace s; 38520cf1dd8SToby Isaac PetscErrorCode ierr; 38620cf1dd8SToby Isaac 38720cf1dd8SToby Isaac PetscFunctionBegin; 38820cf1dd8SToby Isaac PetscValidPointer(sp, 2); 38920cf1dd8SToby Isaac ierr = PetscCitationsRegister(FECitation,&FEcite);CHKERRQ(ierr); 39020cf1dd8SToby Isaac *sp = NULL; 39120cf1dd8SToby Isaac ierr = PetscFEInitializePackage();CHKERRQ(ierr); 39220cf1dd8SToby Isaac 39320cf1dd8SToby Isaac ierr = PetscHeaderCreate(s, PETSCDUALSPACE_CLASSID, "PetscDualSpace", "Dual Space", "PetscDualSpace", comm, PetscDualSpaceDestroy, PetscDualSpaceView);CHKERRQ(ierr); 39420cf1dd8SToby Isaac 39520cf1dd8SToby Isaac s->order = 0; 39620cf1dd8SToby Isaac s->Nc = 1; 397*4bee2e38SMatthew G. Knepley s->k = 0; 39820cf1dd8SToby Isaac s->setupcalled = PETSC_FALSE; 39920cf1dd8SToby Isaac 40020cf1dd8SToby Isaac *sp = s; 40120cf1dd8SToby Isaac PetscFunctionReturn(0); 40220cf1dd8SToby Isaac } 40320cf1dd8SToby Isaac 40420cf1dd8SToby Isaac /*@ 40520cf1dd8SToby Isaac PetscDualSpaceDuplicate - Creates a duplicate PetscDualSpace object, however it is not setup. 40620cf1dd8SToby Isaac 40720cf1dd8SToby Isaac Collective on PetscDualSpace 40820cf1dd8SToby Isaac 40920cf1dd8SToby Isaac Input Parameter: 41020cf1dd8SToby Isaac . sp - The original PetscDualSpace 41120cf1dd8SToby Isaac 41220cf1dd8SToby Isaac Output Parameter: 41320cf1dd8SToby Isaac . spNew - The duplicate PetscDualSpace 41420cf1dd8SToby Isaac 41520cf1dd8SToby Isaac Level: beginner 41620cf1dd8SToby Isaac 41720cf1dd8SToby Isaac .seealso: PetscDualSpaceCreate(), PetscDualSpaceSetType() 41820cf1dd8SToby Isaac @*/ 41920cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceDuplicate(PetscDualSpace sp, PetscDualSpace *spNew) 42020cf1dd8SToby Isaac { 42120cf1dd8SToby Isaac PetscErrorCode ierr; 42220cf1dd8SToby Isaac 42320cf1dd8SToby Isaac PetscFunctionBegin; 42420cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 42520cf1dd8SToby Isaac PetscValidPointer(spNew, 2); 42620cf1dd8SToby Isaac ierr = (*sp->ops->duplicate)(sp, spNew);CHKERRQ(ierr); 42720cf1dd8SToby Isaac PetscFunctionReturn(0); 42820cf1dd8SToby Isaac } 42920cf1dd8SToby Isaac 43020cf1dd8SToby Isaac /*@ 43120cf1dd8SToby Isaac PetscDualSpaceGetDM - Get the DM representing the reference cell 43220cf1dd8SToby Isaac 43320cf1dd8SToby Isaac Not collective 43420cf1dd8SToby Isaac 43520cf1dd8SToby Isaac Input Parameter: 43620cf1dd8SToby Isaac . sp - The PetscDualSpace 43720cf1dd8SToby Isaac 43820cf1dd8SToby Isaac Output Parameter: 43920cf1dd8SToby Isaac . dm - The reference cell 44020cf1dd8SToby Isaac 44120cf1dd8SToby Isaac Level: intermediate 44220cf1dd8SToby Isaac 44320cf1dd8SToby Isaac .seealso: PetscDualSpaceSetDM(), PetscDualSpaceCreate() 44420cf1dd8SToby Isaac @*/ 44520cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetDM(PetscDualSpace sp, DM *dm) 44620cf1dd8SToby Isaac { 44720cf1dd8SToby Isaac PetscFunctionBegin; 44820cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 44920cf1dd8SToby Isaac PetscValidPointer(dm, 2); 45020cf1dd8SToby Isaac *dm = sp->dm; 45120cf1dd8SToby Isaac PetscFunctionReturn(0); 45220cf1dd8SToby Isaac } 45320cf1dd8SToby Isaac 45420cf1dd8SToby Isaac /*@ 45520cf1dd8SToby Isaac PetscDualSpaceSetDM - Get the DM representing the reference cell 45620cf1dd8SToby Isaac 45720cf1dd8SToby Isaac Not collective 45820cf1dd8SToby Isaac 45920cf1dd8SToby Isaac Input Parameters: 46020cf1dd8SToby Isaac + sp - The PetscDualSpace 46120cf1dd8SToby Isaac - dm - The reference cell 46220cf1dd8SToby Isaac 46320cf1dd8SToby Isaac Level: intermediate 46420cf1dd8SToby Isaac 46520cf1dd8SToby Isaac .seealso: PetscDualSpaceGetDM(), PetscDualSpaceCreate() 46620cf1dd8SToby Isaac @*/ 46720cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceSetDM(PetscDualSpace sp, DM dm) 46820cf1dd8SToby Isaac { 46920cf1dd8SToby Isaac PetscErrorCode ierr; 47020cf1dd8SToby Isaac 47120cf1dd8SToby Isaac PetscFunctionBegin; 47220cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 47320cf1dd8SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 2); 47420cf1dd8SToby Isaac ierr = DMDestroy(&sp->dm);CHKERRQ(ierr); 47520cf1dd8SToby Isaac ierr = PetscObjectReference((PetscObject) dm);CHKERRQ(ierr); 47620cf1dd8SToby Isaac sp->dm = dm; 47720cf1dd8SToby Isaac PetscFunctionReturn(0); 47820cf1dd8SToby Isaac } 47920cf1dd8SToby Isaac 48020cf1dd8SToby Isaac /*@ 48120cf1dd8SToby Isaac PetscDualSpaceGetOrder - Get the order of the dual space 48220cf1dd8SToby Isaac 48320cf1dd8SToby Isaac Not collective 48420cf1dd8SToby Isaac 48520cf1dd8SToby Isaac Input Parameter: 48620cf1dd8SToby Isaac . sp - The PetscDualSpace 48720cf1dd8SToby Isaac 48820cf1dd8SToby Isaac Output Parameter: 48920cf1dd8SToby Isaac . order - The order 49020cf1dd8SToby Isaac 49120cf1dd8SToby Isaac Level: intermediate 49220cf1dd8SToby Isaac 49320cf1dd8SToby Isaac .seealso: PetscDualSpaceSetOrder(), PetscDualSpaceCreate() 49420cf1dd8SToby Isaac @*/ 49520cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetOrder(PetscDualSpace sp, PetscInt *order) 49620cf1dd8SToby Isaac { 49720cf1dd8SToby Isaac PetscFunctionBegin; 49820cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 49920cf1dd8SToby Isaac PetscValidPointer(order, 2); 50020cf1dd8SToby Isaac *order = sp->order; 50120cf1dd8SToby Isaac PetscFunctionReturn(0); 50220cf1dd8SToby Isaac } 50320cf1dd8SToby Isaac 50420cf1dd8SToby Isaac /*@ 50520cf1dd8SToby Isaac PetscDualSpaceSetOrder - Set the order of the dual space 50620cf1dd8SToby Isaac 50720cf1dd8SToby Isaac Not collective 50820cf1dd8SToby Isaac 50920cf1dd8SToby Isaac Input Parameters: 51020cf1dd8SToby Isaac + sp - The PetscDualSpace 51120cf1dd8SToby Isaac - order - The order 51220cf1dd8SToby Isaac 51320cf1dd8SToby Isaac Level: intermediate 51420cf1dd8SToby Isaac 51520cf1dd8SToby Isaac .seealso: PetscDualSpaceGetOrder(), PetscDualSpaceCreate() 51620cf1dd8SToby Isaac @*/ 51720cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceSetOrder(PetscDualSpace sp, PetscInt order) 51820cf1dd8SToby Isaac { 51920cf1dd8SToby Isaac PetscFunctionBegin; 52020cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 52120cf1dd8SToby Isaac sp->order = order; 52220cf1dd8SToby Isaac PetscFunctionReturn(0); 52320cf1dd8SToby Isaac } 52420cf1dd8SToby Isaac 52520cf1dd8SToby Isaac /*@ 52620cf1dd8SToby Isaac PetscDualSpaceGetNumComponents - Return the number of components for this space 52720cf1dd8SToby Isaac 52820cf1dd8SToby Isaac Input Parameter: 52920cf1dd8SToby Isaac . sp - The PetscDualSpace 53020cf1dd8SToby Isaac 53120cf1dd8SToby Isaac Output Parameter: 53220cf1dd8SToby Isaac . Nc - The number of components 53320cf1dd8SToby Isaac 53420cf1dd8SToby Isaac Note: A vector space, for example, will have d components, where d is the spatial dimension 53520cf1dd8SToby Isaac 53620cf1dd8SToby Isaac Level: intermediate 53720cf1dd8SToby Isaac 53820cf1dd8SToby Isaac .seealso: PetscDualSpaceSetNumComponents(), PetscDualSpaceGetDimension(), PetscDualSpaceCreate(), PetscDualSpace 53920cf1dd8SToby Isaac @*/ 54020cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetNumComponents(PetscDualSpace sp, PetscInt *Nc) 54120cf1dd8SToby Isaac { 54220cf1dd8SToby Isaac PetscFunctionBegin; 54320cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 54420cf1dd8SToby Isaac PetscValidPointer(Nc, 2); 54520cf1dd8SToby Isaac *Nc = sp->Nc; 54620cf1dd8SToby Isaac PetscFunctionReturn(0); 54720cf1dd8SToby Isaac } 54820cf1dd8SToby Isaac 54920cf1dd8SToby Isaac /*@ 55020cf1dd8SToby Isaac PetscDualSpaceSetNumComponents - Set the number of components for this space 55120cf1dd8SToby Isaac 55220cf1dd8SToby Isaac Input Parameters: 55320cf1dd8SToby Isaac + sp - The PetscDualSpace 55420cf1dd8SToby Isaac - order - The number of components 55520cf1dd8SToby Isaac 55620cf1dd8SToby Isaac Level: intermediate 55720cf1dd8SToby Isaac 55820cf1dd8SToby Isaac .seealso: PetscDualSpaceGetNumComponents(), PetscDualSpaceCreate(), PetscDualSpace 55920cf1dd8SToby Isaac @*/ 56020cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceSetNumComponents(PetscDualSpace sp, PetscInt Nc) 56120cf1dd8SToby Isaac { 56220cf1dd8SToby Isaac PetscFunctionBegin; 56320cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 56420cf1dd8SToby Isaac sp->Nc = Nc; 56520cf1dd8SToby Isaac PetscFunctionReturn(0); 56620cf1dd8SToby Isaac } 56720cf1dd8SToby Isaac 56820cf1dd8SToby Isaac /*@ 56920cf1dd8SToby Isaac PetscDualSpaceGetFunctional - Get the i-th basis functional in the dual space 57020cf1dd8SToby Isaac 57120cf1dd8SToby Isaac Not collective 57220cf1dd8SToby Isaac 57320cf1dd8SToby Isaac Input Parameters: 57420cf1dd8SToby Isaac + sp - The PetscDualSpace 57520cf1dd8SToby Isaac - i - The basis number 57620cf1dd8SToby Isaac 57720cf1dd8SToby Isaac Output Parameter: 57820cf1dd8SToby Isaac . functional - The basis functional 57920cf1dd8SToby Isaac 58020cf1dd8SToby Isaac Level: intermediate 58120cf1dd8SToby Isaac 58220cf1dd8SToby Isaac .seealso: PetscDualSpaceGetDimension(), PetscDualSpaceCreate() 58320cf1dd8SToby Isaac @*/ 58420cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetFunctional(PetscDualSpace sp, PetscInt i, PetscQuadrature *functional) 58520cf1dd8SToby Isaac { 58620cf1dd8SToby Isaac PetscInt dim; 58720cf1dd8SToby Isaac PetscErrorCode ierr; 58820cf1dd8SToby Isaac 58920cf1dd8SToby Isaac PetscFunctionBegin; 59020cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 59120cf1dd8SToby Isaac PetscValidPointer(functional, 3); 59220cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension(sp, &dim);CHKERRQ(ierr); 59320cf1dd8SToby Isaac if ((i < 0) || (i >= dim)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Functional index %d must be in [0, %d)", i, dim); 59420cf1dd8SToby Isaac *functional = sp->functional[i]; 59520cf1dd8SToby Isaac PetscFunctionReturn(0); 59620cf1dd8SToby Isaac } 59720cf1dd8SToby Isaac 59820cf1dd8SToby Isaac /*@ 59920cf1dd8SToby Isaac PetscDualSpaceGetDimension - Get the dimension of the dual space, i.e. the number of basis functionals 60020cf1dd8SToby Isaac 60120cf1dd8SToby Isaac Not collective 60220cf1dd8SToby Isaac 60320cf1dd8SToby Isaac Input Parameter: 60420cf1dd8SToby Isaac . sp - The PetscDualSpace 60520cf1dd8SToby Isaac 60620cf1dd8SToby Isaac Output Parameter: 60720cf1dd8SToby Isaac . dim - The dimension 60820cf1dd8SToby Isaac 60920cf1dd8SToby Isaac Level: intermediate 61020cf1dd8SToby Isaac 61120cf1dd8SToby Isaac .seealso: PetscDualSpaceGetFunctional(), PetscDualSpaceCreate() 61220cf1dd8SToby Isaac @*/ 61320cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetDimension(PetscDualSpace sp, PetscInt *dim) 61420cf1dd8SToby Isaac { 61520cf1dd8SToby Isaac PetscErrorCode ierr; 61620cf1dd8SToby Isaac 61720cf1dd8SToby Isaac PetscFunctionBegin; 61820cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 61920cf1dd8SToby Isaac PetscValidPointer(dim, 2); 62020cf1dd8SToby Isaac *dim = 0; 62120cf1dd8SToby Isaac if (sp->ops->getdimension) {ierr = (*sp->ops->getdimension)(sp, dim);CHKERRQ(ierr);} 62220cf1dd8SToby Isaac PetscFunctionReturn(0); 62320cf1dd8SToby Isaac } 62420cf1dd8SToby Isaac 62520cf1dd8SToby Isaac /*@C 62620cf1dd8SToby Isaac PetscDualSpaceGetNumDof - Get the number of degrees of freedom for each spatial (topological) dimension 62720cf1dd8SToby Isaac 62820cf1dd8SToby Isaac Not collective 62920cf1dd8SToby Isaac 63020cf1dd8SToby Isaac Input Parameter: 63120cf1dd8SToby Isaac . sp - The PetscDualSpace 63220cf1dd8SToby Isaac 63320cf1dd8SToby Isaac Output Parameter: 63420cf1dd8SToby Isaac . numDof - An array of length dim+1 which holds the number of dofs for each dimension 63520cf1dd8SToby Isaac 63620cf1dd8SToby Isaac Level: intermediate 63720cf1dd8SToby Isaac 63820cf1dd8SToby Isaac .seealso: PetscDualSpaceGetFunctional(), PetscDualSpaceCreate() 63920cf1dd8SToby Isaac @*/ 64020cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetNumDof(PetscDualSpace sp, const PetscInt **numDof) 64120cf1dd8SToby Isaac { 64220cf1dd8SToby Isaac PetscErrorCode ierr; 64320cf1dd8SToby Isaac 64420cf1dd8SToby Isaac PetscFunctionBegin; 64520cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 64620cf1dd8SToby Isaac PetscValidPointer(numDof, 2); 64720cf1dd8SToby Isaac ierr = (*sp->ops->getnumdof)(sp, numDof);CHKERRQ(ierr); 64820cf1dd8SToby Isaac if (!*numDof) SETERRQ(PetscObjectComm((PetscObject) sp), PETSC_ERR_LIB, "Empty numDof[] returned from dual space implementation"); 64920cf1dd8SToby Isaac PetscFunctionReturn(0); 65020cf1dd8SToby Isaac } 65120cf1dd8SToby Isaac 65220cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceCreateSection(PetscDualSpace sp, PetscSection *section) 65320cf1dd8SToby Isaac { 65420cf1dd8SToby Isaac DM dm; 65520cf1dd8SToby Isaac PetscInt pStart, pEnd, depth, h, offset; 65620cf1dd8SToby Isaac const PetscInt *numDof; 65720cf1dd8SToby Isaac PetscErrorCode ierr; 65820cf1dd8SToby Isaac 65920cf1dd8SToby Isaac PetscFunctionBegin; 66020cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(sp,&dm);CHKERRQ(ierr); 66120cf1dd8SToby Isaac ierr = DMPlexGetChart(dm,&pStart,&pEnd);CHKERRQ(ierr); 66220cf1dd8SToby Isaac ierr = PetscSectionCreate(PetscObjectComm((PetscObject)sp),section);CHKERRQ(ierr); 66320cf1dd8SToby Isaac ierr = PetscSectionSetChart(*section,pStart,pEnd);CHKERRQ(ierr); 66420cf1dd8SToby Isaac ierr = DMPlexGetDepth(dm,&depth);CHKERRQ(ierr); 66520cf1dd8SToby Isaac ierr = PetscDualSpaceGetNumDof(sp,&numDof);CHKERRQ(ierr); 66620cf1dd8SToby Isaac for (h = 0; h <= depth; h++) { 66720cf1dd8SToby Isaac PetscInt hStart, hEnd, p, dof; 66820cf1dd8SToby Isaac 66920cf1dd8SToby Isaac ierr = DMPlexGetHeightStratum(dm,h,&hStart,&hEnd);CHKERRQ(ierr); 67020cf1dd8SToby Isaac dof = numDof[depth - h]; 67120cf1dd8SToby Isaac for (p = hStart; p < hEnd; p++) { 67220cf1dd8SToby Isaac ierr = PetscSectionSetDof(*section,p,dof);CHKERRQ(ierr); 67320cf1dd8SToby Isaac } 67420cf1dd8SToby Isaac } 67520cf1dd8SToby Isaac ierr = PetscSectionSetUp(*section);CHKERRQ(ierr); 67620cf1dd8SToby Isaac for (h = 0, offset = 0; h <= depth; h++) { 67720cf1dd8SToby Isaac PetscInt hStart, hEnd, p, dof; 67820cf1dd8SToby Isaac 67920cf1dd8SToby Isaac ierr = DMPlexGetHeightStratum(dm,h,&hStart,&hEnd);CHKERRQ(ierr); 68020cf1dd8SToby Isaac dof = numDof[depth - h]; 68120cf1dd8SToby Isaac for (p = hStart; p < hEnd; p++) { 68220cf1dd8SToby Isaac ierr = PetscSectionGetDof(*section,p,&dof);CHKERRQ(ierr); 68320cf1dd8SToby Isaac ierr = PetscSectionSetOffset(*section,p,offset);CHKERRQ(ierr); 68420cf1dd8SToby Isaac offset += dof; 68520cf1dd8SToby Isaac } 68620cf1dd8SToby Isaac } 68720cf1dd8SToby Isaac PetscFunctionReturn(0); 68820cf1dd8SToby Isaac } 68920cf1dd8SToby Isaac 69020cf1dd8SToby Isaac /*@ 69120cf1dd8SToby Isaac PetscDualSpaceCreateReferenceCell - Create a DMPLEX with the appropriate FEM reference cell 69220cf1dd8SToby Isaac 69320cf1dd8SToby Isaac Collective on PetscDualSpace 69420cf1dd8SToby Isaac 69520cf1dd8SToby Isaac Input Parameters: 69620cf1dd8SToby Isaac + sp - The PetscDualSpace 69720cf1dd8SToby Isaac . dim - The spatial dimension 69820cf1dd8SToby Isaac - simplex - Flag for simplex, otherwise use a tensor-product cell 69920cf1dd8SToby Isaac 70020cf1dd8SToby Isaac Output Parameter: 70120cf1dd8SToby Isaac . refdm - The reference cell 70220cf1dd8SToby Isaac 70320cf1dd8SToby Isaac Level: advanced 70420cf1dd8SToby Isaac 70520cf1dd8SToby Isaac .keywords: PetscDualSpace, reference cell 70620cf1dd8SToby Isaac .seealso: PetscDualSpaceCreate(), DMPLEX 70720cf1dd8SToby Isaac @*/ 70820cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceCreateReferenceCell(PetscDualSpace sp, PetscInt dim, PetscBool simplex, DM *refdm) 70920cf1dd8SToby Isaac { 71020cf1dd8SToby Isaac PetscErrorCode ierr; 71120cf1dd8SToby Isaac 71220cf1dd8SToby Isaac PetscFunctionBeginUser; 71320cf1dd8SToby Isaac ierr = DMPlexCreateReferenceCell(PetscObjectComm((PetscObject) sp), dim, simplex, refdm);CHKERRQ(ierr); 71420cf1dd8SToby Isaac PetscFunctionReturn(0); 71520cf1dd8SToby Isaac } 71620cf1dd8SToby Isaac 71720cf1dd8SToby Isaac /*@C 71820cf1dd8SToby Isaac PetscDualSpaceApply - Apply a functional from the dual space basis to an input function 71920cf1dd8SToby Isaac 72020cf1dd8SToby Isaac Input Parameters: 72120cf1dd8SToby Isaac + sp - The PetscDualSpace object 72220cf1dd8SToby Isaac . f - The basis functional index 72320cf1dd8SToby Isaac . time - The time 72420cf1dd8SToby Isaac . cgeom - A context with geometric information for this cell, we use v0 (the initial vertex) and J (the Jacobian) (or evaluated at the coordinates of the functional) 72520cf1dd8SToby Isaac . numComp - The number of components for the function 72620cf1dd8SToby Isaac . func - The input function 72720cf1dd8SToby Isaac - ctx - A context for the function 72820cf1dd8SToby Isaac 72920cf1dd8SToby Isaac Output Parameter: 73020cf1dd8SToby Isaac . value - numComp output values 73120cf1dd8SToby Isaac 73220cf1dd8SToby Isaac Note: The calling sequence for the callback func is given by: 73320cf1dd8SToby Isaac 73420cf1dd8SToby Isaac $ func(PetscInt dim, PetscReal time, const PetscReal x[], 73520cf1dd8SToby Isaac $ PetscInt numComponents, PetscScalar values[], void *ctx) 73620cf1dd8SToby Isaac 73720cf1dd8SToby Isaac Level: developer 73820cf1dd8SToby Isaac 73920cf1dd8SToby Isaac .seealso: PetscDualSpaceCreate() 74020cf1dd8SToby Isaac @*/ 74120cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceApply(PetscDualSpace sp, PetscInt f, PetscReal time, PetscFEGeom *cgeom, PetscInt numComp, PetscErrorCode (*func)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void *ctx, PetscScalar *value) 74220cf1dd8SToby Isaac { 74320cf1dd8SToby Isaac PetscErrorCode ierr; 74420cf1dd8SToby Isaac 74520cf1dd8SToby Isaac PetscFunctionBegin; 74620cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 74720cf1dd8SToby Isaac PetscValidPointer(cgeom, 4); 74820cf1dd8SToby Isaac PetscValidPointer(value, 8); 74920cf1dd8SToby Isaac ierr = (*sp->ops->apply)(sp, f, time, cgeom, numComp, func, ctx, value);CHKERRQ(ierr); 75020cf1dd8SToby Isaac PetscFunctionReturn(0); 75120cf1dd8SToby Isaac } 75220cf1dd8SToby Isaac 75320cf1dd8SToby Isaac /*@C 75420cf1dd8SToby Isaac PetscDualSpaceApplyAll - Apply all functionals from the dual space basis to the result of an evaluation at the points returned by PetscDualSpaceGetAllPoints() 75520cf1dd8SToby Isaac 75620cf1dd8SToby Isaac Input Parameters: 75720cf1dd8SToby Isaac + sp - The PetscDualSpace object 75820cf1dd8SToby Isaac - pointEval - Evaluation at the points returned by PetscDualSpaceGetAllPoints() 75920cf1dd8SToby Isaac 76020cf1dd8SToby Isaac Output Parameter: 76120cf1dd8SToby Isaac . spValue - The values of all dual space functionals 76220cf1dd8SToby Isaac 76320cf1dd8SToby Isaac Level: developer 76420cf1dd8SToby Isaac 76520cf1dd8SToby Isaac .seealso: PetscDualSpaceCreate() 76620cf1dd8SToby Isaac @*/ 76720cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceApplyAll(PetscDualSpace sp, const PetscScalar *pointEval, PetscScalar *spValue) 76820cf1dd8SToby Isaac { 76920cf1dd8SToby Isaac PetscErrorCode ierr; 77020cf1dd8SToby Isaac 77120cf1dd8SToby Isaac PetscFunctionBegin; 77220cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 77320cf1dd8SToby Isaac ierr = (*sp->ops->applyall)(sp, pointEval, spValue);CHKERRQ(ierr); 77420cf1dd8SToby Isaac PetscFunctionReturn(0); 77520cf1dd8SToby Isaac } 77620cf1dd8SToby Isaac 77720cf1dd8SToby Isaac /*@C 77820cf1dd8SToby Isaac PetscDualSpaceApplyDefault - Apply a functional from the dual space basis to an input function by assuming a point evaluation functional. 77920cf1dd8SToby Isaac 78020cf1dd8SToby Isaac Input Parameters: 78120cf1dd8SToby Isaac + sp - The PetscDualSpace object 78220cf1dd8SToby Isaac . f - The basis functional index 78320cf1dd8SToby Isaac . time - The time 78420cf1dd8SToby Isaac . cgeom - A context with geometric information for this cell, we use v0 (the initial vertex) and J (the Jacobian) 78520cf1dd8SToby Isaac . Nc - The number of components for the function 78620cf1dd8SToby Isaac . func - The input function 78720cf1dd8SToby Isaac - ctx - A context for the function 78820cf1dd8SToby Isaac 78920cf1dd8SToby Isaac Output Parameter: 79020cf1dd8SToby Isaac . value - The output value 79120cf1dd8SToby Isaac 79220cf1dd8SToby Isaac Note: The calling sequence for the callback func is given by: 79320cf1dd8SToby Isaac 79420cf1dd8SToby Isaac $ func(PetscInt dim, PetscReal time, const PetscReal x[], 79520cf1dd8SToby Isaac $ PetscInt numComponents, PetscScalar values[], void *ctx) 79620cf1dd8SToby Isaac 79720cf1dd8SToby Isaac and the idea is to evaluate the functional as an integral 79820cf1dd8SToby Isaac 79920cf1dd8SToby Isaac $ n(f) = int dx n(x) . f(x) 80020cf1dd8SToby Isaac 80120cf1dd8SToby Isaac where both n and f have Nc components. 80220cf1dd8SToby Isaac 80320cf1dd8SToby Isaac Level: developer 80420cf1dd8SToby Isaac 80520cf1dd8SToby Isaac .seealso: PetscDualSpaceCreate() 80620cf1dd8SToby Isaac @*/ 80720cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceApplyDefault(PetscDualSpace sp, PetscInt f, PetscReal time, PetscFEGeom *cgeom, PetscInt Nc, PetscErrorCode (*func)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void *ctx, PetscScalar *value) 80820cf1dd8SToby Isaac { 80920cf1dd8SToby Isaac DM dm; 81020cf1dd8SToby Isaac PetscQuadrature n; 81120cf1dd8SToby Isaac const PetscReal *points, *weights; 81220cf1dd8SToby Isaac PetscReal x[3]; 81320cf1dd8SToby Isaac PetscScalar *val; 81420cf1dd8SToby Isaac PetscInt dim, dE, qNc, c, Nq, q; 81520cf1dd8SToby Isaac PetscBool isAffine; 81620cf1dd8SToby Isaac PetscErrorCode ierr; 81720cf1dd8SToby Isaac 81820cf1dd8SToby Isaac PetscFunctionBegin; 81920cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 82020cf1dd8SToby Isaac PetscValidPointer(value, 5); 82120cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(sp, &dm);CHKERRQ(ierr); 82220cf1dd8SToby Isaac ierr = PetscDualSpaceGetFunctional(sp, f, &n);CHKERRQ(ierr); 82320cf1dd8SToby Isaac ierr = PetscQuadratureGetData(n, &dim, &qNc, &Nq, &points, &weights);CHKERRQ(ierr); 82420cf1dd8SToby Isaac if (dim != cgeom->dim) SETERRQ2(PetscObjectComm((PetscObject) sp), PETSC_ERR_ARG_SIZ, "The quadrature spatial dimension %D != cell geometry dimension %D", dim, cgeom->dim); 82520cf1dd8SToby Isaac if (qNc != Nc) SETERRQ2(PetscObjectComm((PetscObject) sp), PETSC_ERR_ARG_SIZ, "The quadrature components %D != function components %D", qNc, Nc); 82620cf1dd8SToby Isaac ierr = DMGetWorkArray(dm, Nc, MPIU_SCALAR, &val);CHKERRQ(ierr); 82720cf1dd8SToby Isaac *value = 0.0; 82820cf1dd8SToby Isaac isAffine = cgeom->isAffine; 82920cf1dd8SToby Isaac dE = cgeom->dimEmbed; 83020cf1dd8SToby Isaac for (q = 0; q < Nq; ++q) { 83120cf1dd8SToby Isaac if (isAffine) { 83220cf1dd8SToby Isaac CoordinatesRefToReal(dE, cgeom->dim, cgeom->xi, cgeom->v, cgeom->J, &points[q*dim], x); 83320cf1dd8SToby Isaac ierr = (*func)(dE, time, x, Nc, val, ctx);CHKERRQ(ierr); 83420cf1dd8SToby Isaac } else { 83520cf1dd8SToby Isaac ierr = (*func)(dE, time, &cgeom->v[dE*q], Nc, val, ctx);CHKERRQ(ierr); 83620cf1dd8SToby Isaac } 83720cf1dd8SToby Isaac for (c = 0; c < Nc; ++c) { 83820cf1dd8SToby Isaac *value += val[c]*weights[q*Nc+c]; 83920cf1dd8SToby Isaac } 84020cf1dd8SToby Isaac } 84120cf1dd8SToby Isaac ierr = DMRestoreWorkArray(dm, Nc, MPIU_SCALAR, &val);CHKERRQ(ierr); 84220cf1dd8SToby Isaac PetscFunctionReturn(0); 84320cf1dd8SToby Isaac } 84420cf1dd8SToby Isaac 84520cf1dd8SToby Isaac /*@C 84620cf1dd8SToby Isaac PetscDualSpaceApplyAllDefault - Apply all functionals from the dual space basis to the result of an evaluation at the points returned by PetscDualSpaceGetAllPoints() 84720cf1dd8SToby Isaac 84820cf1dd8SToby Isaac Input Parameters: 84920cf1dd8SToby Isaac + sp - The PetscDualSpace object 85020cf1dd8SToby Isaac - pointEval - Evaluation at the points returned by PetscDualSpaceGetAllPoints() 85120cf1dd8SToby Isaac 85220cf1dd8SToby Isaac Output Parameter: 85320cf1dd8SToby Isaac . spValue - The values of all dual space functionals 85420cf1dd8SToby Isaac 85520cf1dd8SToby Isaac Level: developer 85620cf1dd8SToby Isaac 85720cf1dd8SToby Isaac .seealso: PetscDualSpaceCreate() 85820cf1dd8SToby Isaac @*/ 85920cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceApplyAllDefault(PetscDualSpace sp, const PetscScalar *pointEval, PetscScalar *spValue) 86020cf1dd8SToby Isaac { 86120cf1dd8SToby Isaac PetscQuadrature n; 86220cf1dd8SToby Isaac const PetscReal *points, *weights; 86320cf1dd8SToby Isaac PetscInt qNc, c, Nq, q, f, spdim, Nc; 86420cf1dd8SToby Isaac PetscInt offset; 86520cf1dd8SToby Isaac PetscErrorCode ierr; 86620cf1dd8SToby Isaac 86720cf1dd8SToby Isaac PetscFunctionBegin; 86820cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 86920cf1dd8SToby Isaac PetscValidScalarPointer(pointEval, 2); 87020cf1dd8SToby Isaac PetscValidScalarPointer(spValue, 5); 87120cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension(sp, &spdim);CHKERRQ(ierr); 87220cf1dd8SToby Isaac ierr = PetscDualSpaceGetNumComponents(sp, &Nc);CHKERRQ(ierr); 87320cf1dd8SToby Isaac for (f = 0, offset = 0; f < spdim; f++) { 87420cf1dd8SToby Isaac ierr = PetscDualSpaceGetFunctional(sp, f, &n);CHKERRQ(ierr); 87520cf1dd8SToby Isaac ierr = PetscQuadratureGetData(n, NULL, &qNc, &Nq, &points, &weights);CHKERRQ(ierr); 87620cf1dd8SToby Isaac if (qNc != Nc) SETERRQ2(PetscObjectComm((PetscObject) sp), PETSC_ERR_ARG_SIZ, "The quadrature components %D != function components %D", qNc, Nc); 87720cf1dd8SToby Isaac spValue[f] = 0.0; 87820cf1dd8SToby Isaac for (q = 0; q < Nq; ++q) { 87920cf1dd8SToby Isaac for (c = 0; c < Nc; ++c) { 88020cf1dd8SToby Isaac spValue[f] += pointEval[offset++]*weights[q*Nc+c]; 88120cf1dd8SToby Isaac } 88220cf1dd8SToby Isaac } 88320cf1dd8SToby Isaac } 88420cf1dd8SToby Isaac PetscFunctionReturn(0); 88520cf1dd8SToby Isaac } 88620cf1dd8SToby Isaac 88720cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetAllPoints(PetscDualSpace sp, PetscQuadrature *allPoints) 88820cf1dd8SToby Isaac { 88920cf1dd8SToby Isaac PetscErrorCode ierr; 89020cf1dd8SToby Isaac 89120cf1dd8SToby Isaac PetscFunctionBegin; 89220cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 89320cf1dd8SToby Isaac PetscValidPointer(allPoints,2); 89420cf1dd8SToby Isaac if (!sp->allPoints && sp->ops->createallpoints) { 89520cf1dd8SToby Isaac ierr = (*sp->ops->createallpoints)(sp,&sp->allPoints);CHKERRQ(ierr); 89620cf1dd8SToby Isaac } 89720cf1dd8SToby Isaac *allPoints = sp->allPoints; 89820cf1dd8SToby Isaac PetscFunctionReturn(0); 89920cf1dd8SToby Isaac } 90020cf1dd8SToby Isaac 90120cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceCreateAllPointsDefault(PetscDualSpace sp, PetscQuadrature *allPoints) 90220cf1dd8SToby Isaac { 90320cf1dd8SToby Isaac PetscInt spdim; 90420cf1dd8SToby Isaac PetscInt numPoints, offset; 90520cf1dd8SToby Isaac PetscReal *points; 90620cf1dd8SToby Isaac PetscInt f, dim; 90720cf1dd8SToby Isaac PetscQuadrature q; 90820cf1dd8SToby Isaac PetscErrorCode ierr; 90920cf1dd8SToby Isaac 91020cf1dd8SToby Isaac PetscFunctionBegin; 91120cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension(sp,&spdim);CHKERRQ(ierr); 91220cf1dd8SToby Isaac if (!spdim) { 91320cf1dd8SToby Isaac ierr = PetscQuadratureCreate(PETSC_COMM_SELF,allPoints);CHKERRQ(ierr); 91420cf1dd8SToby Isaac ierr = PetscQuadratureSetData(*allPoints,0,0,0,NULL,NULL);CHKERRQ(ierr); 91520cf1dd8SToby Isaac } 91620cf1dd8SToby Isaac ierr = PetscDualSpaceGetFunctional(sp,0,&q);CHKERRQ(ierr); 91720cf1dd8SToby Isaac ierr = PetscQuadratureGetData(q,&dim,NULL,&numPoints,NULL,NULL);CHKERRQ(ierr); 91820cf1dd8SToby Isaac for (f = 1; f < spdim; f++) { 91920cf1dd8SToby Isaac PetscInt Np; 92020cf1dd8SToby Isaac 92120cf1dd8SToby Isaac ierr = PetscDualSpaceGetFunctional(sp,f,&q);CHKERRQ(ierr); 92220cf1dd8SToby Isaac ierr = PetscQuadratureGetData(q,NULL,NULL,&Np,NULL,NULL);CHKERRQ(ierr); 92320cf1dd8SToby Isaac numPoints += Np; 92420cf1dd8SToby Isaac } 92520cf1dd8SToby Isaac ierr = PetscMalloc1(dim*numPoints,&points);CHKERRQ(ierr); 92620cf1dd8SToby Isaac for (f = 0, offset = 0; f < spdim; f++) { 92720cf1dd8SToby Isaac const PetscReal *p; 92820cf1dd8SToby Isaac PetscInt Np, i; 92920cf1dd8SToby Isaac 93020cf1dd8SToby Isaac ierr = PetscDualSpaceGetFunctional(sp,f,&q);CHKERRQ(ierr); 93120cf1dd8SToby Isaac ierr = PetscQuadratureGetData(q,NULL,NULL,&Np,&p,NULL);CHKERRQ(ierr); 93220cf1dd8SToby Isaac for (i = 0; i < Np * dim; i++) { 93320cf1dd8SToby Isaac points[offset + i] = p[i]; 93420cf1dd8SToby Isaac } 93520cf1dd8SToby Isaac offset += Np * dim; 93620cf1dd8SToby Isaac } 93720cf1dd8SToby Isaac ierr = PetscQuadratureCreate(PETSC_COMM_SELF,allPoints);CHKERRQ(ierr); 93820cf1dd8SToby Isaac ierr = PetscQuadratureSetData(*allPoints,dim,0,numPoints,points,NULL);CHKERRQ(ierr); 93920cf1dd8SToby Isaac PetscFunctionReturn(0); 94020cf1dd8SToby Isaac } 94120cf1dd8SToby Isaac 94220cf1dd8SToby Isaac /*@C 94320cf1dd8SToby Isaac PetscDualSpaceApplyFVM - Apply a functional from the dual space basis to an input function by assuming a point evaluation functional at the cell centroid. 94420cf1dd8SToby Isaac 94520cf1dd8SToby Isaac Input Parameters: 94620cf1dd8SToby Isaac + sp - The PetscDualSpace object 94720cf1dd8SToby Isaac . f - The basis functional index 94820cf1dd8SToby Isaac . time - The time 94920cf1dd8SToby Isaac . cgeom - A context with geometric information for this cell, we currently just use the centroid 95020cf1dd8SToby Isaac . Nc - The number of components for the function 95120cf1dd8SToby Isaac . func - The input function 95220cf1dd8SToby Isaac - ctx - A context for the function 95320cf1dd8SToby Isaac 95420cf1dd8SToby Isaac Output Parameter: 95520cf1dd8SToby Isaac . value - The output value (scalar) 95620cf1dd8SToby Isaac 95720cf1dd8SToby Isaac Note: The calling sequence for the callback func is given by: 95820cf1dd8SToby Isaac 95920cf1dd8SToby Isaac $ func(PetscInt dim, PetscReal time, const PetscReal x[], 96020cf1dd8SToby Isaac $ PetscInt numComponents, PetscScalar values[], void *ctx) 96120cf1dd8SToby Isaac 96220cf1dd8SToby Isaac and the idea is to evaluate the functional as an integral 96320cf1dd8SToby Isaac 96420cf1dd8SToby Isaac $ n(f) = int dx n(x) . f(x) 96520cf1dd8SToby Isaac 96620cf1dd8SToby Isaac where both n and f have Nc components. 96720cf1dd8SToby Isaac 96820cf1dd8SToby Isaac Level: developer 96920cf1dd8SToby Isaac 97020cf1dd8SToby Isaac .seealso: PetscDualSpaceCreate() 97120cf1dd8SToby Isaac @*/ 97220cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceApplyFVM(PetscDualSpace sp, PetscInt f, PetscReal time, PetscFVCellGeom *cgeom, PetscInt Nc, PetscErrorCode (*func)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void *ctx, PetscScalar *value) 97320cf1dd8SToby Isaac { 97420cf1dd8SToby Isaac DM dm; 97520cf1dd8SToby Isaac PetscQuadrature n; 97620cf1dd8SToby Isaac const PetscReal *points, *weights; 97720cf1dd8SToby Isaac PetscScalar *val; 97820cf1dd8SToby Isaac PetscInt dimEmbed, qNc, c, Nq, q; 97920cf1dd8SToby Isaac PetscErrorCode ierr; 98020cf1dd8SToby Isaac 98120cf1dd8SToby Isaac PetscFunctionBegin; 98220cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 98320cf1dd8SToby Isaac PetscValidPointer(value, 5); 98420cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(sp, &dm);CHKERRQ(ierr); 98520cf1dd8SToby Isaac ierr = DMGetCoordinateDim(dm, &dimEmbed);CHKERRQ(ierr); 98620cf1dd8SToby Isaac ierr = PetscDualSpaceGetFunctional(sp, f, &n);CHKERRQ(ierr); 98720cf1dd8SToby Isaac ierr = PetscQuadratureGetData(n, NULL, &qNc, &Nq, &points, &weights);CHKERRQ(ierr); 98820cf1dd8SToby Isaac if (qNc != Nc) SETERRQ2(PetscObjectComm((PetscObject) sp), PETSC_ERR_ARG_SIZ, "The quadrature components %D != function components %D", qNc, Nc); 98920cf1dd8SToby Isaac ierr = DMGetWorkArray(dm, Nc, MPIU_SCALAR, &val);CHKERRQ(ierr); 99020cf1dd8SToby Isaac *value = 0.; 99120cf1dd8SToby Isaac for (q = 0; q < Nq; ++q) { 99220cf1dd8SToby Isaac ierr = (*func)(dimEmbed, time, cgeom->centroid, Nc, val, ctx);CHKERRQ(ierr); 99320cf1dd8SToby Isaac for (c = 0; c < Nc; ++c) { 99420cf1dd8SToby Isaac *value += val[c]*weights[q*Nc+c]; 99520cf1dd8SToby Isaac } 99620cf1dd8SToby Isaac } 99720cf1dd8SToby Isaac ierr = DMRestoreWorkArray(dm, Nc, MPIU_SCALAR, &val);CHKERRQ(ierr); 99820cf1dd8SToby Isaac PetscFunctionReturn(0); 99920cf1dd8SToby Isaac } 100020cf1dd8SToby Isaac 100120cf1dd8SToby Isaac /*@ 100220cf1dd8SToby Isaac PetscDualSpaceGetHeightSubspace - Get the subset of the dual space basis that is supported on a mesh point of a 100320cf1dd8SToby Isaac given height. This assumes that the reference cell is symmetric over points of this height. 100420cf1dd8SToby Isaac 100520cf1dd8SToby Isaac If the dual space is not defined on mesh points of the given height (e.g. if the space is discontinuous and 100620cf1dd8SToby Isaac pointwise values are not defined on the element boundaries), or if the implementation of PetscDualSpace does not 100720cf1dd8SToby Isaac support extracting subspaces, then NULL is returned. 100820cf1dd8SToby Isaac 100920cf1dd8SToby Isaac This does not increment the reference count on the returned dual space, and the user should not destroy it. 101020cf1dd8SToby Isaac 101120cf1dd8SToby Isaac Not collective 101220cf1dd8SToby Isaac 101320cf1dd8SToby Isaac Input Parameters: 101420cf1dd8SToby Isaac + sp - the PetscDualSpace object 101520cf1dd8SToby Isaac - height - the height of the mesh point for which the subspace is desired 101620cf1dd8SToby Isaac 101720cf1dd8SToby Isaac Output Parameter: 101820cf1dd8SToby Isaac . subsp - the subspace. Note that the functionals in the subspace are with respect to the intrinsic geometry of the 101920cf1dd8SToby Isaac point, which will be of lesser dimension if height > 0. 102020cf1dd8SToby Isaac 102120cf1dd8SToby Isaac Level: advanced 102220cf1dd8SToby Isaac 102320cf1dd8SToby Isaac .seealso: PetscSpaceGetHeightSubspace(), PetscDualSpace 102420cf1dd8SToby Isaac @*/ 102520cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetHeightSubspace(PetscDualSpace sp, PetscInt height, PetscDualSpace *subsp) 102620cf1dd8SToby Isaac { 102720cf1dd8SToby Isaac PetscErrorCode ierr; 102820cf1dd8SToby Isaac 102920cf1dd8SToby Isaac PetscFunctionBegin; 103020cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 103120cf1dd8SToby Isaac PetscValidPointer(subsp, 3); 103220cf1dd8SToby Isaac *subsp = NULL; 1033aa545514SMatthew G. Knepley if (sp->ops->getheightsubspace) {ierr = (*sp->ops->getheightsubspace)(sp, height, subsp);CHKERRQ(ierr);} 103420cf1dd8SToby Isaac PetscFunctionReturn(0); 103520cf1dd8SToby Isaac } 103620cf1dd8SToby Isaac 103720cf1dd8SToby Isaac /*@ 103820cf1dd8SToby Isaac PetscDualSpaceGetPointSubspace - Get the subset of the dual space basis that is supported on a particular mesh point. 103920cf1dd8SToby Isaac 104020cf1dd8SToby Isaac If the dual space is not defined on the mesh point (e.g. if the space is discontinuous and pointwise values are not 104120cf1dd8SToby Isaac defined on the element boundaries), or if the implementation of PetscDualSpace does not support extracting 104220cf1dd8SToby Isaac subspaces, then NULL is returned. 104320cf1dd8SToby Isaac 104420cf1dd8SToby Isaac This does not increment the reference count on the returned dual space, and the user should not destroy it. 104520cf1dd8SToby Isaac 104620cf1dd8SToby Isaac Not collective 104720cf1dd8SToby Isaac 104820cf1dd8SToby Isaac Input Parameters: 104920cf1dd8SToby Isaac + sp - the PetscDualSpace object 105020cf1dd8SToby Isaac - point - the point (in the dual space's DM) for which the subspace is desired 105120cf1dd8SToby Isaac 105220cf1dd8SToby Isaac Output Parameters: 105320cf1dd8SToby Isaac bdsp - the subspace. Note that the functionals in the subspace are with respect to the intrinsic geometry of the 105420cf1dd8SToby Isaac point, which will be of lesser dimension if height > 0. 105520cf1dd8SToby Isaac 105620cf1dd8SToby Isaac Level: advanced 105720cf1dd8SToby Isaac 105820cf1dd8SToby Isaac .seealso: PetscDualSpace 105920cf1dd8SToby Isaac @*/ 106020cf1dd8SToby Isaac PetscErrorCode PetscDualSpaceGetPointSubspace(PetscDualSpace sp, PetscInt point, PetscDualSpace *bdsp) 106120cf1dd8SToby Isaac { 106220cf1dd8SToby Isaac PetscErrorCode ierr; 106320cf1dd8SToby Isaac 106420cf1dd8SToby Isaac PetscFunctionBegin; 106520cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 1); 106620cf1dd8SToby Isaac PetscValidPointer(bdsp,2); 106720cf1dd8SToby Isaac *bdsp = NULL; 106820cf1dd8SToby Isaac if (sp->ops->getpointsubspace) { 106920cf1dd8SToby Isaac ierr = (*sp->ops->getpointsubspace)(sp,point,bdsp);CHKERRQ(ierr); 107020cf1dd8SToby Isaac } else if (sp->ops->getheightsubspace) { 107120cf1dd8SToby Isaac DM dm; 107220cf1dd8SToby Isaac DMLabel label; 107320cf1dd8SToby Isaac PetscInt dim, depth, height; 107420cf1dd8SToby Isaac 107520cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(sp,&dm);CHKERRQ(ierr); 107620cf1dd8SToby Isaac ierr = DMPlexGetDepth(dm,&dim);CHKERRQ(ierr); 107720cf1dd8SToby Isaac ierr = DMPlexGetDepthLabel(dm,&label);CHKERRQ(ierr); 107820cf1dd8SToby Isaac ierr = DMLabelGetValue(label,point,&depth);CHKERRQ(ierr); 107920cf1dd8SToby Isaac height = dim - depth; 108020cf1dd8SToby Isaac ierr = (*sp->ops->getheightsubspace)(sp,height,bdsp);CHKERRQ(ierr); 108120cf1dd8SToby Isaac } 108220cf1dd8SToby Isaac PetscFunctionReturn(0); 108320cf1dd8SToby Isaac } 108420cf1dd8SToby Isaac 10856f905325SMatthew G. Knepley /*@C 10866f905325SMatthew G. Knepley PetscDualSpaceGetSymmetries - Returns a description of the symmetries of this basis 10876f905325SMatthew G. Knepley 10886f905325SMatthew G. Knepley Not collective 10896f905325SMatthew G. Knepley 10906f905325SMatthew G. Knepley Input Parameter: 10916f905325SMatthew G. Knepley . sp - the PetscDualSpace object 10926f905325SMatthew G. Knepley 10936f905325SMatthew G. Knepley Output Parameters: 10946f905325SMatthew G. Knepley + perms - Permutations of the local degrees of freedom, parameterized by the point orientation 10956f905325SMatthew G. Knepley - flips - Sign reversal of the local degrees of freedom, parameterized by the point orientation 10966f905325SMatthew G. Knepley 10976f905325SMatthew G. Knepley Note: The permutation and flip arrays are organized in the following way 10986f905325SMatthew G. Knepley $ perms[p][ornt][dof # on point] = new local dof # 10996f905325SMatthew G. Knepley $ flips[p][ornt][dof # on point] = reversal or not 11006f905325SMatthew G. Knepley 11016f905325SMatthew G. Knepley Level: developer 11026f905325SMatthew G. Knepley 11036f905325SMatthew G. Knepley .seealso: PetscDualSpaceSetSymmetries() 11046f905325SMatthew G. Knepley @*/ 11056f905325SMatthew G. Knepley PetscErrorCode PetscDualSpaceGetSymmetries(PetscDualSpace sp, const PetscInt ****perms, const PetscScalar ****flips) 11066f905325SMatthew G. Knepley { 11076f905325SMatthew G. Knepley PetscErrorCode ierr; 11086f905325SMatthew G. Knepley 11096f905325SMatthew G. Knepley PetscFunctionBegin; 11106f905325SMatthew G. Knepley PetscValidHeaderSpecific(sp,PETSCDUALSPACE_CLASSID,1); 11116f905325SMatthew G. Knepley if (perms) {PetscValidPointer(perms,2); *perms = NULL;} 11126f905325SMatthew G. Knepley if (flips) {PetscValidPointer(flips,3); *flips = NULL;} 11136f905325SMatthew G. Knepley if (sp->ops->getsymmetries) {ierr = (sp->ops->getsymmetries)(sp,perms,flips);CHKERRQ(ierr);} 11146f905325SMatthew G. Knepley PetscFunctionReturn(0); 11156f905325SMatthew G. Knepley } 1116*4bee2e38SMatthew G. Knepley 1117*4bee2e38SMatthew G. Knepley /*@ 1118*4bee2e38SMatthew G. Knepley PetscDualSpaceGetDeRahm - Get the k-simplex associated with the functionals in this dual space 1119*4bee2e38SMatthew G. Knepley 1120*4bee2e38SMatthew G. Knepley Input Parameter: 1121*4bee2e38SMatthew G. Knepley . dsp - The PetscDualSpace 1122*4bee2e38SMatthew G. Knepley 1123*4bee2e38SMatthew G. Knepley Output Parameter: 1124*4bee2e38SMatthew G. Knepley . k - The simplex dimension 1125*4bee2e38SMatthew G. Knepley 1126*4bee2e38SMatthew G. Knepley Level: advanced 1127*4bee2e38SMatthew G. Knepley 1128*4bee2e38SMatthew G. Knepley Note: Currently supported values are 1129*4bee2e38SMatthew G. Knepley $ 0: These are H_1 methods that only transform coordinates 1130*4bee2e38SMatthew G. Knepley $ 1: These are Hcurl methods that transform functions using the covariant Piola transform (COVARIANT_PIOLA_TRANSFORM) 1131*4bee2e38SMatthew G. Knepley $ 2: These are the same as 1 1132*4bee2e38SMatthew G. Knepley $ 3: These are Hdiv methods that transform functions using the contravariant Piola transform (CONTRAVARIANT_PIOLA_TRANSFORM) 1133*4bee2e38SMatthew G. Knepley 1134*4bee2e38SMatthew G. Knepley .seealso: PetscDualSpacePullback(), PetscDualSpacePushforward(), PetscDualSpaceTransform(), PetscDualSpaceTransformType 1135*4bee2e38SMatthew G. Knepley @*/ 1136*4bee2e38SMatthew G. Knepley PetscErrorCode PetscDualSpaceGetDeRahm(PetscDualSpace dsp, PetscInt *k) 1137*4bee2e38SMatthew G. Knepley { 1138*4bee2e38SMatthew G. Knepley PetscFunctionBeginHot; 1139*4bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(dsp, PETSCDUALSPACE_CLASSID, 1); 1140*4bee2e38SMatthew G. Knepley PetscValidPointer(k, 2); 1141*4bee2e38SMatthew G. Knepley *k = dsp->k; 1142*4bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 1143*4bee2e38SMatthew G. Knepley } 1144*4bee2e38SMatthew G. Knepley 1145*4bee2e38SMatthew G. Knepley /*@C 1146*4bee2e38SMatthew G. Knepley PetscDualSpaceTransform - Transform the function values 1147*4bee2e38SMatthew G. Knepley 1148*4bee2e38SMatthew G. Knepley Input Parameters: 1149*4bee2e38SMatthew G. Knepley + dsp - The PetscDualSpace 1150*4bee2e38SMatthew G. Knepley . trans - The type of transform 1151*4bee2e38SMatthew G. Knepley . isInverse - Flag to invert the transform 1152*4bee2e38SMatthew G. Knepley . fegeom - The cell geometry 1153*4bee2e38SMatthew G. Knepley . Nv - The number of function samples 1154*4bee2e38SMatthew G. Knepley . Nc - The number of function components 1155*4bee2e38SMatthew G. Knepley - vals - The function values 1156*4bee2e38SMatthew G. Knepley 1157*4bee2e38SMatthew G. Knepley Output Parameter: 1158*4bee2e38SMatthew G. Knepley . vals - The transformed function values 1159*4bee2e38SMatthew G. Knepley 1160*4bee2e38SMatthew G. Knepley Level: developer 1161*4bee2e38SMatthew G. Knepley 1162*4bee2e38SMatthew G. Knepley .seealso: PetscDualSpaceTransformGradient(), PetscDualSpacePullback(), PetscDualSpacePushforward(), PetscDualSpaceTransform 1163*4bee2e38SMatthew G. Knepley @*/ 1164*4bee2e38SMatthew G. Knepley PetscErrorCode PetscDualSpaceTransform(PetscDualSpace dsp, PetscDualSpaceTransformType trans, PetscBool isInverse, PetscFEGeom *fegeom, PetscInt Nv, PetscInt Nc, PetscScalar vals[]) 1165*4bee2e38SMatthew G. Knepley { 1166*4bee2e38SMatthew G. Knepley DM dm; 1167*4bee2e38SMatthew G. Knepley PetscInt dim, v, c; 1168*4bee2e38SMatthew G. Knepley PetscErrorCode ierr; 1169*4bee2e38SMatthew G. Knepley 1170*4bee2e38SMatthew G. Knepley PetscFunctionBeginHot; 1171*4bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(dsp, PETSCDUALSPACE_CLASSID, 1); 1172*4bee2e38SMatthew G. Knepley PetscValidPointer(fegeom, 4); 1173*4bee2e38SMatthew G. Knepley PetscValidPointer(vals, 7); 1174*4bee2e38SMatthew G. Knepley ierr = PetscDualSpaceGetDM(dsp, &dm);CHKERRQ(ierr); 1175*4bee2e38SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 1176*4bee2e38SMatthew G. Knepley /* Assume its a vector, otherwise assume its a bunch of scalars */ 1177*4bee2e38SMatthew G. Knepley if (Nc == 1 || Nc != dim) PetscFunctionReturn(0); 1178*4bee2e38SMatthew G. Knepley switch (trans) { 1179*4bee2e38SMatthew G. Knepley case IDENTITY_TRANSFORM: break; 1180*4bee2e38SMatthew G. Knepley case COVARIANT_PIOLA_TRANSFORM: /* Covariant Piola mapping $\sigma^*(F) = J^{-T} F \circ \phi^{-1)$ */ 1181*4bee2e38SMatthew G. Knepley if (isInverse) { 1182*4bee2e38SMatthew G. Knepley for (v = 0; v < Nv; ++v) { 1183*4bee2e38SMatthew G. Knepley switch (dim) 1184*4bee2e38SMatthew G. Knepley { 1185*4bee2e38SMatthew G. Knepley case 2: DMPlex_MultTranspose2D_Internal(fegeom->J, 1, &vals[v*Nc], &vals[v*Nc]);break; 1186*4bee2e38SMatthew G. Knepley case 3: DMPlex_MultTranspose3D_Internal(fegeom->J, 1, &vals[v*Nc], &vals[v*Nc]);break; 1187*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dim %D for transformation", dim); 1188*4bee2e38SMatthew G. Knepley } 1189*4bee2e38SMatthew G. Knepley } 1190*4bee2e38SMatthew G. Knepley } else { 1191*4bee2e38SMatthew G. Knepley for (v = 0; v < Nv; ++v) { 1192*4bee2e38SMatthew G. Knepley switch (dim) 1193*4bee2e38SMatthew G. Knepley { 1194*4bee2e38SMatthew G. Knepley case 2: DMPlex_MultTranspose2D_Internal(fegeom->invJ, 1, &vals[v*Nc], &vals[v*Nc]);break; 1195*4bee2e38SMatthew G. Knepley case 3: DMPlex_MultTranspose3D_Internal(fegeom->invJ, 1, &vals[v*Nc], &vals[v*Nc]);break; 1196*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dim %D for transformation", dim); 1197*4bee2e38SMatthew G. Knepley } 1198*4bee2e38SMatthew G. Knepley } 1199*4bee2e38SMatthew G. Knepley } 1200*4bee2e38SMatthew G. Knepley break; 1201*4bee2e38SMatthew G. Knepley case CONTRAVARIANT_PIOLA_TRANSFORM: /* Contravariant Piola mapping $\sigma^*(F) = \frac{1}{|\det J|} J F \circ \phi^{-1}$ */ 1202*4bee2e38SMatthew G. Knepley if (isInverse) { 1203*4bee2e38SMatthew G. Knepley for (v = 0; v < Nv; ++v) { 1204*4bee2e38SMatthew G. Knepley switch (dim) 1205*4bee2e38SMatthew G. Knepley { 1206*4bee2e38SMatthew G. Knepley case 2: DMPlex_Mult2D_Internal(fegeom->invJ, 1, &vals[v*Nc], &vals[v*Nc]);break; 1207*4bee2e38SMatthew G. Knepley case 3: DMPlex_Mult3D_Internal(fegeom->invJ, 1, &vals[v*Nc], &vals[v*Nc]);break; 1208*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dim %D for transformation", dim); 1209*4bee2e38SMatthew G. Knepley } 1210*4bee2e38SMatthew G. Knepley for (c = 0; c < Nc; ++c) vals[v*Nc+c] *= fegeom->detJ[0]; 1211*4bee2e38SMatthew G. Knepley } 1212*4bee2e38SMatthew G. Knepley } else { 1213*4bee2e38SMatthew G. Knepley for (v = 0; v < Nv; ++v) { 1214*4bee2e38SMatthew G. Knepley switch (dim) 1215*4bee2e38SMatthew G. Knepley { 1216*4bee2e38SMatthew G. Knepley case 2: DMPlex_Mult2D_Internal(fegeom->J, 1, &vals[v*Nc], &vals[v*Nc]);break; 1217*4bee2e38SMatthew G. Knepley case 3: DMPlex_Mult3D_Internal(fegeom->J, 1, &vals[v*Nc], &vals[v*Nc]);break; 1218*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dim %D for transformation", dim); 1219*4bee2e38SMatthew G. Knepley } 1220*4bee2e38SMatthew G. Knepley for (c = 0; c < Nc; ++c) vals[v*Nc+c] /= fegeom->detJ[0]; 1221*4bee2e38SMatthew G. Knepley } 1222*4bee2e38SMatthew G. Knepley } 1223*4bee2e38SMatthew G. Knepley break; 1224*4bee2e38SMatthew G. Knepley } 1225*4bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 1226*4bee2e38SMatthew G. Knepley } 1227*4bee2e38SMatthew G. Knepley /*@C 1228*4bee2e38SMatthew G. Knepley PetscDualSpaceTransformGradient - Transform the function gradient values 1229*4bee2e38SMatthew G. Knepley 1230*4bee2e38SMatthew G. Knepley Input Parameters: 1231*4bee2e38SMatthew G. Knepley + dsp - The PetscDualSpace 1232*4bee2e38SMatthew G. Knepley . trans - The type of transform 1233*4bee2e38SMatthew G. Knepley . isInverse - Flag to invert the transform 1234*4bee2e38SMatthew G. Knepley . fegeom - The cell geometry 1235*4bee2e38SMatthew G. Knepley . Nv - The number of function gradient samples 1236*4bee2e38SMatthew G. Knepley . Nc - The number of function components 1237*4bee2e38SMatthew G. Knepley - vals - The function gradient values 1238*4bee2e38SMatthew G. Knepley 1239*4bee2e38SMatthew G. Knepley Output Parameter: 1240*4bee2e38SMatthew G. Knepley . vals - The transformed function values 1241*4bee2e38SMatthew G. Knepley 1242*4bee2e38SMatthew G. Knepley Level: developer 1243*4bee2e38SMatthew G. Knepley 1244*4bee2e38SMatthew G. Knepley .seealso: PetscDualSpaceTransform(), PetscDualSpacePullback(), PetscDualSpacePushforward(), PetscDualSpaceTransform 1245*4bee2e38SMatthew G. Knepley @*/ 1246*4bee2e38SMatthew G. Knepley PetscErrorCode PetscDualSpaceTransformGradient(PetscDualSpace dsp, PetscDualSpaceTransformType trans, PetscBool isInverse, PetscFEGeom *fegeom, PetscInt Nv, PetscInt Nc, PetscScalar vals[]) 1247*4bee2e38SMatthew G. Knepley { 1248*4bee2e38SMatthew G. Knepley DM dm; 1249*4bee2e38SMatthew G. Knepley PetscInt dim, v, c, d; 1250*4bee2e38SMatthew G. Knepley PetscErrorCode ierr; 1251*4bee2e38SMatthew G. Knepley 1252*4bee2e38SMatthew G. Knepley PetscFunctionBeginHot; 1253*4bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(dsp, PETSCDUALSPACE_CLASSID, 1); 1254*4bee2e38SMatthew G. Knepley PetscValidPointer(fegeom, 4); 1255*4bee2e38SMatthew G. Knepley PetscValidPointer(vals, 7); 1256*4bee2e38SMatthew G. Knepley ierr = PetscDualSpaceGetDM(dsp, &dm);CHKERRQ(ierr); 1257*4bee2e38SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 1258*4bee2e38SMatthew G. Knepley /* Transform gradient */ 1259*4bee2e38SMatthew G. Knepley for (v = 0; v < Nv; ++v) { 1260*4bee2e38SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 1261*4bee2e38SMatthew G. Knepley switch (dim) 1262*4bee2e38SMatthew G. Knepley { 1263*4bee2e38SMatthew G. Knepley case 2: DMPlex_MultTranspose2D_Internal(fegeom->invJ, 1, &vals[(v*Nc+c)*dim], &vals[(v*Nc+c)*dim]);break; 1264*4bee2e38SMatthew G. Knepley case 3: DMPlex_MultTranspose3D_Internal(fegeom->invJ, 1, &vals[(v*Nc+c)*dim], &vals[(v*Nc+c)*dim]);break; 1265*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dim %D for transformation", dim); 1266*4bee2e38SMatthew G. Knepley } 1267*4bee2e38SMatthew G. Knepley } 1268*4bee2e38SMatthew G. Knepley } 1269*4bee2e38SMatthew G. Knepley /* Assume its a vector, otherwise assume its a bunch of scalars */ 1270*4bee2e38SMatthew G. Knepley if (Nc == 1 || Nc != dim) PetscFunctionReturn(0); 1271*4bee2e38SMatthew G. Knepley switch (trans) { 1272*4bee2e38SMatthew G. Knepley case IDENTITY_TRANSFORM: break; 1273*4bee2e38SMatthew G. Knepley case COVARIANT_PIOLA_TRANSFORM: /* Covariant Piola mapping $\sigma^*(F) = J^{-T} F \circ \phi^{-1)$ */ 1274*4bee2e38SMatthew G. Knepley if (isInverse) { 1275*4bee2e38SMatthew G. Knepley for (v = 0; v < Nv; ++v) { 1276*4bee2e38SMatthew G. Knepley for (d = 0; d < dim; ++d) { 1277*4bee2e38SMatthew G. Knepley switch (dim) 1278*4bee2e38SMatthew G. Knepley { 1279*4bee2e38SMatthew G. Knepley case 2: DMPlex_MultTranspose2D_Internal(fegeom->J, dim, &vals[v*Nc*dim+d], &vals[v*Nc*dim+d]);break; 1280*4bee2e38SMatthew G. Knepley case 3: DMPlex_MultTranspose3D_Internal(fegeom->J, dim, &vals[v*Nc*dim+d], &vals[v*Nc*dim+d]);break; 1281*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dim %D for transformation", dim); 1282*4bee2e38SMatthew G. Knepley } 1283*4bee2e38SMatthew G. Knepley } 1284*4bee2e38SMatthew G. Knepley } 1285*4bee2e38SMatthew G. Knepley } else { 1286*4bee2e38SMatthew G. Knepley for (v = 0; v < Nv; ++v) { 1287*4bee2e38SMatthew G. Knepley for (d = 0; d < dim; ++d) { 1288*4bee2e38SMatthew G. Knepley switch (dim) 1289*4bee2e38SMatthew G. Knepley { 1290*4bee2e38SMatthew G. Knepley case 2: DMPlex_MultTranspose2D_Internal(fegeom->invJ, dim, &vals[v*Nc*dim+d], &vals[v*Nc*dim+d]);break; 1291*4bee2e38SMatthew G. Knepley case 3: DMPlex_MultTranspose3D_Internal(fegeom->invJ, dim, &vals[v*Nc*dim+d], &vals[v*Nc*dim+d]);break; 1292*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dim %D for transformation", dim); 1293*4bee2e38SMatthew G. Knepley } 1294*4bee2e38SMatthew G. Knepley } 1295*4bee2e38SMatthew G. Knepley } 1296*4bee2e38SMatthew G. Knepley } 1297*4bee2e38SMatthew G. Knepley break; 1298*4bee2e38SMatthew G. Knepley case CONTRAVARIANT_PIOLA_TRANSFORM: /* Contravariant Piola mapping $\sigma^*(F) = \frac{1}{|\det J|} J F \circ \phi^{-1}$ */ 1299*4bee2e38SMatthew G. Knepley if (isInverse) { 1300*4bee2e38SMatthew G. Knepley for (v = 0; v < Nv; ++v) { 1301*4bee2e38SMatthew G. Knepley for (d = 0; d < dim; ++d) { 1302*4bee2e38SMatthew G. Knepley switch (dim) 1303*4bee2e38SMatthew G. Knepley { 1304*4bee2e38SMatthew G. Knepley case 2: DMPlex_Mult2D_Internal(fegeom->invJ, dim, &vals[v*Nc*dim+d], &vals[v*Nc*dim+d]);break; 1305*4bee2e38SMatthew G. Knepley case 3: DMPlex_Mult3D_Internal(fegeom->invJ, dim, &vals[v*Nc*dim+d], &vals[v*Nc*dim+d]);break; 1306*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dim %D for transformation", dim); 1307*4bee2e38SMatthew G. Knepley } 1308*4bee2e38SMatthew G. Knepley for (c = 0; c < Nc; ++c) vals[(v*Nc+c)*dim+d] *= fegeom->detJ[0]; 1309*4bee2e38SMatthew G. Knepley } 1310*4bee2e38SMatthew G. Knepley } 1311*4bee2e38SMatthew G. Knepley } else { 1312*4bee2e38SMatthew G. Knepley for (v = 0; v < Nv; ++v) { 1313*4bee2e38SMatthew G. Knepley for (d = 0; d < dim; ++d) { 1314*4bee2e38SMatthew G. Knepley switch (dim) 1315*4bee2e38SMatthew G. Knepley { 1316*4bee2e38SMatthew G. Knepley case 2: DMPlex_Mult2D_Internal(fegeom->J, dim, &vals[v*Nc*dim+d], &vals[v*Nc*dim+d]);break; 1317*4bee2e38SMatthew G. Knepley case 3: DMPlex_Mult3D_Internal(fegeom->J, dim, &vals[v*Nc*dim+d], &vals[v*Nc*dim+d]);break; 1318*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported dim %D for transformation", dim); 1319*4bee2e38SMatthew G. Knepley } 1320*4bee2e38SMatthew G. Knepley for (c = 0; c < Nc; ++c) vals[(v*Nc+c)*dim+d] /= fegeom->detJ[0]; 1321*4bee2e38SMatthew G. Knepley } 1322*4bee2e38SMatthew G. Knepley } 1323*4bee2e38SMatthew G. Knepley } 1324*4bee2e38SMatthew G. Knepley break; 1325*4bee2e38SMatthew G. Knepley } 1326*4bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 1327*4bee2e38SMatthew G. Knepley } 1328*4bee2e38SMatthew G. Knepley 1329*4bee2e38SMatthew G. Knepley /*@C 1330*4bee2e38SMatthew G. Knepley PetscDualSpacePullback - Transform the given functional so that it operates on real space, rather than the reference element. Operationally, this means that we map the function evaluations depending on continuity requirements of our finite element method. 1331*4bee2e38SMatthew G. Knepley 1332*4bee2e38SMatthew G. Knepley Input Parameters: 1333*4bee2e38SMatthew G. Knepley + dsp - The PetscDualSpace 1334*4bee2e38SMatthew G. Knepley . fegeom - The geometry for this cell 1335*4bee2e38SMatthew G. Knepley . Nq - The number of function samples 1336*4bee2e38SMatthew G. Knepley . Nc - The number of function components 1337*4bee2e38SMatthew G. Knepley - pointEval - The function values 1338*4bee2e38SMatthew G. Knepley 1339*4bee2e38SMatthew G. Knepley Output Parameter: 1340*4bee2e38SMatthew G. Knepley . pointEval - The transformed function values 1341*4bee2e38SMatthew G. Knepley 1342*4bee2e38SMatthew G. Knepley Level: advanced 1343*4bee2e38SMatthew G. Knepley 1344*4bee2e38SMatthew G. Knepley Note: Functions transform in a complementary way (pushforward) to functionals, so that the scalar product is invariant. The type of transform is dependent on the associated k-simplex from the DeRahm complex. 1345*4bee2e38SMatthew G. Knepley 1346*4bee2e38SMatthew G. Knepley .seealso: PetscDualSpacePushforward(), PetscDualSpaceTransform(), PetscDualSpaceGetDeRahm() 1347*4bee2e38SMatthew G. Knepley @*/ 1348*4bee2e38SMatthew G. Knepley PetscErrorCode PetscDualSpacePullback(PetscDualSpace dsp, PetscFEGeom *fegeom, PetscInt Nq, PetscInt Nc, PetscScalar pointEval[]) 1349*4bee2e38SMatthew G. Knepley { 1350*4bee2e38SMatthew G. Knepley PetscDualSpaceTransformType trans; 1351*4bee2e38SMatthew G. Knepley PetscInt k; 1352*4bee2e38SMatthew G. Knepley PetscErrorCode ierr; 1353*4bee2e38SMatthew G. Knepley 1354*4bee2e38SMatthew G. Knepley PetscFunctionBeginHot; 1355*4bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(dsp, PETSCDUALSPACE_CLASSID, 1); 1356*4bee2e38SMatthew G. Knepley PetscValidPointer(fegeom, 2); 1357*4bee2e38SMatthew G. Knepley PetscValidPointer(pointEval, 5); 1358*4bee2e38SMatthew G. Knepley /* The dualspace dofs correspond to some simplex in the DeRahm complex, which we label by k. 1359*4bee2e38SMatthew G. Knepley This determines their transformation properties. */ 1360*4bee2e38SMatthew G. Knepley ierr = PetscDualSpaceGetDeRahm(dsp, &k);CHKERRQ(ierr); 1361*4bee2e38SMatthew G. Knepley switch (k) 1362*4bee2e38SMatthew G. Knepley { 1363*4bee2e38SMatthew G. Knepley case 0: /* H^1 point evaluations */ 1364*4bee2e38SMatthew G. Knepley trans = IDENTITY_TRANSFORM;break; 1365*4bee2e38SMatthew G. Knepley case 1: /* Hcurl preserves tangential edge traces */ 1366*4bee2e38SMatthew G. Knepley case 2: 1367*4bee2e38SMatthew G. Knepley trans = COVARIANT_PIOLA_TRANSFORM;break; 1368*4bee2e38SMatthew G. Knepley case 3: /* Hdiv preserve normal traces */ 1369*4bee2e38SMatthew G. Knepley trans = CONTRAVARIANT_PIOLA_TRANSFORM;break; 1370*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported simplex dim %D for transformation", k); 1371*4bee2e38SMatthew G. Knepley } 1372*4bee2e38SMatthew G. Knepley ierr = PetscDualSpaceTransform(dsp, trans, PETSC_TRUE, fegeom, Nq, Nc, pointEval);CHKERRQ(ierr); 1373*4bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 1374*4bee2e38SMatthew G. Knepley } 1375*4bee2e38SMatthew G. Knepley 1376*4bee2e38SMatthew G. Knepley /*@C 1377*4bee2e38SMatthew G. Knepley PetscDualSpacePushforward - Transform the given function so that it operates on real space, rather than the reference element. Operationally, this means that we map the function evaluations depending on continuity requirements of our finite element method. 1378*4bee2e38SMatthew G. Knepley 1379*4bee2e38SMatthew G. Knepley Input Parameters: 1380*4bee2e38SMatthew G. Knepley + dsp - The PetscDualSpace 1381*4bee2e38SMatthew G. Knepley . fegeom - The geometry for this cell 1382*4bee2e38SMatthew G. Knepley . Nq - The number of function samples 1383*4bee2e38SMatthew G. Knepley . Nc - The number of function components 1384*4bee2e38SMatthew G. Knepley - pointEval - The function values 1385*4bee2e38SMatthew G. Knepley 1386*4bee2e38SMatthew G. Knepley Output Parameter: 1387*4bee2e38SMatthew G. Knepley . pointEval - The transformed function values 1388*4bee2e38SMatthew G. Knepley 1389*4bee2e38SMatthew G. Knepley Level: advanced 1390*4bee2e38SMatthew G. Knepley 1391*4bee2e38SMatthew G. Knepley Note: Functionals transform in a complementary way (pullback) to functions, so that the scalar product is invariant. The type of transform is dependent on the associated k-simplex from the DeRahm complex. 1392*4bee2e38SMatthew G. Knepley 1393*4bee2e38SMatthew G. Knepley .seealso: PetscDualSpacePullback(), PetscDualSpaceTransform(), PetscDualSpaceGetDeRahm() 1394*4bee2e38SMatthew G. Knepley @*/ 1395*4bee2e38SMatthew G. Knepley PetscErrorCode PetscDualSpacePushforward(PetscDualSpace dsp, PetscFEGeom *fegeom, PetscInt Nq, PetscInt Nc, PetscScalar pointEval[]) 1396*4bee2e38SMatthew G. Knepley { 1397*4bee2e38SMatthew G. Knepley PetscDualSpaceTransformType trans; 1398*4bee2e38SMatthew G. Knepley PetscInt k; 1399*4bee2e38SMatthew G. Knepley PetscErrorCode ierr; 1400*4bee2e38SMatthew G. Knepley 1401*4bee2e38SMatthew G. Knepley PetscFunctionBeginHot; 1402*4bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(dsp, PETSCDUALSPACE_CLASSID, 1); 1403*4bee2e38SMatthew G. Knepley PetscValidPointer(fegeom, 2); 1404*4bee2e38SMatthew G. Knepley PetscValidPointer(pointEval, 5); 1405*4bee2e38SMatthew G. Knepley /* The dualspace dofs correspond to some simplex in the DeRahm complex, which we label by k. 1406*4bee2e38SMatthew G. Knepley This determines their transformation properties. */ 1407*4bee2e38SMatthew G. Knepley ierr = PetscDualSpaceGetDeRahm(dsp, &k);CHKERRQ(ierr); 1408*4bee2e38SMatthew G. Knepley switch (k) 1409*4bee2e38SMatthew G. Knepley { 1410*4bee2e38SMatthew G. Knepley case 0: /* H^1 point evaluations */ 1411*4bee2e38SMatthew G. Knepley trans = IDENTITY_TRANSFORM;break; 1412*4bee2e38SMatthew G. Knepley case 1: /* Hcurl preserves tangential edge traces */ 1413*4bee2e38SMatthew G. Knepley case 2: 1414*4bee2e38SMatthew G. Knepley trans = COVARIANT_PIOLA_TRANSFORM;break; 1415*4bee2e38SMatthew G. Knepley case 3: /* Hdiv preserve normal traces */ 1416*4bee2e38SMatthew G. Knepley trans = CONTRAVARIANT_PIOLA_TRANSFORM;break; 1417*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported simplex dim %D for transformation", k); 1418*4bee2e38SMatthew G. Knepley } 1419*4bee2e38SMatthew G. Knepley ierr = PetscDualSpaceTransform(dsp, trans, PETSC_FALSE, fegeom, Nq, Nc, pointEval);CHKERRQ(ierr); 1420*4bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 1421*4bee2e38SMatthew G. Knepley } 1422*4bee2e38SMatthew G. Knepley 1423*4bee2e38SMatthew G. Knepley /*@C 1424*4bee2e38SMatthew G. Knepley PetscDualSpacePushforwardGradient - Transform the given function gradient so that it operates on real space, rather than the reference element. Operationally, this means that we map the function evaluations depending on continuity requirements of our finite element method. 1425*4bee2e38SMatthew G. Knepley 1426*4bee2e38SMatthew G. Knepley Input Parameters: 1427*4bee2e38SMatthew G. Knepley + dsp - The PetscDualSpace 1428*4bee2e38SMatthew G. Knepley . fegeom - The geometry for this cell 1429*4bee2e38SMatthew G. Knepley . Nq - The number of function gradient samples 1430*4bee2e38SMatthew G. Knepley . Nc - The number of function components 1431*4bee2e38SMatthew G. Knepley - pointEval - The function gradient values 1432*4bee2e38SMatthew G. Knepley 1433*4bee2e38SMatthew G. Knepley Output Parameter: 1434*4bee2e38SMatthew G. Knepley . pointEval - The transformed function gradient values 1435*4bee2e38SMatthew G. Knepley 1436*4bee2e38SMatthew G. Knepley Level: advanced 1437*4bee2e38SMatthew G. Knepley 1438*4bee2e38SMatthew G. Knepley Note: Functionals transform in a complementary way (pullback) to functions, so that the scalar product is invariant. The type of transform is dependent on the associated k-simplex from the DeRahm complex. 1439*4bee2e38SMatthew G. Knepley 1440*4bee2e38SMatthew G. Knepley .seealso: PetscDualSpacePushforward(), PPetscDualSpacePullback(), PetscDualSpaceTransform(), PetscDualSpaceGetDeRahm() 1441*4bee2e38SMatthew G. Knepley @*/PetscErrorCode PetscDualSpacePushforwardGradient(PetscDualSpace dsp, PetscFEGeom *fegeom, PetscInt Nq, PetscInt Nc, PetscScalar pointEval[]) 1442*4bee2e38SMatthew G. Knepley { 1443*4bee2e38SMatthew G. Knepley PetscDualSpaceTransformType trans; 1444*4bee2e38SMatthew G. Knepley PetscInt k; 1445*4bee2e38SMatthew G. Knepley PetscErrorCode ierr; 1446*4bee2e38SMatthew G. Knepley 1447*4bee2e38SMatthew G. Knepley PetscFunctionBeginHot; 1448*4bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(dsp, PETSCDUALSPACE_CLASSID, 1); 1449*4bee2e38SMatthew G. Knepley PetscValidPointer(fegeom, 2); 1450*4bee2e38SMatthew G. Knepley PetscValidPointer(pointEval, 5); 1451*4bee2e38SMatthew G. Knepley /* The dualspace dofs correspond to some simplex in the DeRahm complex, which we label by k. 1452*4bee2e38SMatthew G. Knepley This determines their transformation properties. */ 1453*4bee2e38SMatthew G. Knepley ierr = PetscDualSpaceGetDeRahm(dsp, &k);CHKERRQ(ierr); 1454*4bee2e38SMatthew G. Knepley switch (k) 1455*4bee2e38SMatthew G. Knepley { 1456*4bee2e38SMatthew G. Knepley case 0: /* H^1 point evaluations */ 1457*4bee2e38SMatthew G. Knepley trans = IDENTITY_TRANSFORM;break; 1458*4bee2e38SMatthew G. Knepley case 1: /* Hcurl preserves tangential edge traces */ 1459*4bee2e38SMatthew G. Knepley case 2: 1460*4bee2e38SMatthew G. Knepley trans = COVARIANT_PIOLA_TRANSFORM;break; 1461*4bee2e38SMatthew G. Knepley case 3: /* Hdiv preserve normal traces */ 1462*4bee2e38SMatthew G. Knepley trans = CONTRAVARIANT_PIOLA_TRANSFORM;break; 1463*4bee2e38SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dsp), PETSC_ERR_ARG_OUTOFRANGE, "Unsupported simplex dim %D for transformation", k); 1464*4bee2e38SMatthew G. Knepley } 1465*4bee2e38SMatthew G. Knepley ierr = PetscDualSpaceTransformGradient(dsp, trans, PETSC_FALSE, fegeom, Nq, Nc, pointEval);CHKERRQ(ierr); 1466*4bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 1467*4bee2e38SMatthew G. Knepley } 1468