120cf1dd8SToby Isaac /* Basis Jet Tabulation 220cf1dd8SToby Isaac 320cf1dd8SToby Isaac We would like to tabulate the nodal basis functions and derivatives at a set of points, usually quadrature points. We 420cf1dd8SToby Isaac follow here the derviation in http://www.math.ttu.edu/~kirby/papers/fiat-toms-2004.pdf. The nodal basis $\psi_i$ can 520cf1dd8SToby Isaac be expressed in terms of a prime basis $\phi_i$ which can be stably evaluated. In PETSc, we will use the Legendre basis 620cf1dd8SToby Isaac as a prime basis. 720cf1dd8SToby Isaac 820cf1dd8SToby Isaac \psi_i = \sum_k \alpha_{ki} \phi_k 920cf1dd8SToby Isaac 1020cf1dd8SToby Isaac Our nodal basis is defined in terms of the dual basis $n_j$ 1120cf1dd8SToby Isaac 1220cf1dd8SToby Isaac n_j \cdot \psi_i = \delta_{ji} 1320cf1dd8SToby Isaac 1420cf1dd8SToby Isaac and we may act on the first equation to obtain 1520cf1dd8SToby Isaac 1620cf1dd8SToby Isaac n_j \cdot \psi_i = \sum_k \alpha_{ki} n_j \cdot \phi_k 1720cf1dd8SToby Isaac \delta_{ji} = \sum_k \alpha_{ki} V_{jk} 1820cf1dd8SToby Isaac I = V \alpha 1920cf1dd8SToby Isaac 2020cf1dd8SToby Isaac so the coefficients of the nodal basis in the prime basis are 2120cf1dd8SToby Isaac 2220cf1dd8SToby Isaac \alpha = V^{-1} 2320cf1dd8SToby Isaac 2420cf1dd8SToby Isaac We will define the dual basis vectors $n_j$ using a quadrature rule. 2520cf1dd8SToby Isaac 2620cf1dd8SToby Isaac Right now, we will just use the polynomial spaces P^k. I know some elements use the space of symmetric polynomials 2720cf1dd8SToby Isaac (I think Nedelec), but we will neglect this for now. Constraints in the space, e.g. Arnold-Winther elements, can 2820cf1dd8SToby Isaac be implemented exactly as in FIAT using functionals $L_j$. 2920cf1dd8SToby Isaac 3020cf1dd8SToby Isaac I will have to count the degrees correctly for the Legendre product when we are on simplices. 3120cf1dd8SToby Isaac 3220cf1dd8SToby Isaac We will have three objects: 3320cf1dd8SToby Isaac - Space, P: this just need point evaluation I think 3420cf1dd8SToby Isaac - Dual Space, P'+K: This looks like a set of functionals that can act on members of P, each n is defined by a Q 3520cf1dd8SToby Isaac - FEM: This keeps {P, P', Q} 3620cf1dd8SToby Isaac */ 3720cf1dd8SToby Isaac #include <petsc/private/petscfeimpl.h> /*I "petscfe.h" I*/ 3820cf1dd8SToby Isaac #include <petscdmplex.h> 3920cf1dd8SToby Isaac 4020cf1dd8SToby Isaac PetscBool FEcite = PETSC_FALSE; 4120cf1dd8SToby Isaac const char FECitation[] = "@article{kirby2004,\n" 4220cf1dd8SToby Isaac " title = {Algorithm 839: FIAT, a New Paradigm for Computing Finite Element Basis Functions},\n" 4320cf1dd8SToby Isaac " journal = {ACM Transactions on Mathematical Software},\n" 4420cf1dd8SToby Isaac " author = {Robert C. Kirby},\n" 4520cf1dd8SToby Isaac " volume = {30},\n" 4620cf1dd8SToby Isaac " number = {4},\n" 4720cf1dd8SToby Isaac " pages = {502--516},\n" 4820cf1dd8SToby Isaac " doi = {10.1145/1039813.1039820},\n" 4920cf1dd8SToby Isaac " year = {2004}\n}\n"; 5020cf1dd8SToby Isaac 5120cf1dd8SToby Isaac PetscClassId PETSCFE_CLASSID = 0; 5220cf1dd8SToby Isaac 53ead873ccSMatthew G. Knepley PetscLogEvent PETSCFE_SetUp; 54ead873ccSMatthew G. Knepley 5520cf1dd8SToby Isaac PetscFunctionList PetscFEList = NULL; 5620cf1dd8SToby Isaac PetscBool PetscFERegisterAllCalled = PETSC_FALSE; 5720cf1dd8SToby Isaac 5820cf1dd8SToby Isaac /*@C 5920cf1dd8SToby Isaac PetscFERegister - Adds a new PetscFE implementation 6020cf1dd8SToby Isaac 6120cf1dd8SToby Isaac Not Collective 6220cf1dd8SToby Isaac 6320cf1dd8SToby Isaac Input Parameters: 6420cf1dd8SToby Isaac + name - The name of a new user-defined creation routine 6520cf1dd8SToby Isaac - create_func - The creation routine itself 6620cf1dd8SToby Isaac 6720cf1dd8SToby Isaac Notes: 6820cf1dd8SToby Isaac PetscFERegister() may be called multiple times to add several user-defined PetscFEs 6920cf1dd8SToby Isaac 7020cf1dd8SToby Isaac Sample usage: 7120cf1dd8SToby Isaac .vb 7220cf1dd8SToby Isaac PetscFERegister("my_fe", MyPetscFECreate); 7320cf1dd8SToby Isaac .ve 7420cf1dd8SToby Isaac 7520cf1dd8SToby Isaac Then, your PetscFE type can be chosen with the procedural interface via 7620cf1dd8SToby Isaac .vb 7720cf1dd8SToby Isaac PetscFECreate(MPI_Comm, PetscFE *); 7820cf1dd8SToby Isaac PetscFESetType(PetscFE, "my_fe"); 7920cf1dd8SToby Isaac .ve 8020cf1dd8SToby Isaac or at runtime via the option 8120cf1dd8SToby Isaac .vb 8220cf1dd8SToby Isaac -petscfe_type my_fe 8320cf1dd8SToby Isaac .ve 8420cf1dd8SToby Isaac 8520cf1dd8SToby Isaac Level: advanced 8620cf1dd8SToby Isaac 8720cf1dd8SToby Isaac .seealso: PetscFERegisterAll(), PetscFERegisterDestroy() 8820cf1dd8SToby Isaac 8920cf1dd8SToby Isaac @*/ 9020cf1dd8SToby Isaac PetscErrorCode PetscFERegister(const char sname[], PetscErrorCode (*function)(PetscFE)) 9120cf1dd8SToby Isaac { 9220cf1dd8SToby Isaac PetscFunctionBegin; 939566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&PetscFEList, sname, function)); 9420cf1dd8SToby Isaac PetscFunctionReturn(0); 9520cf1dd8SToby Isaac } 9620cf1dd8SToby Isaac 9720cf1dd8SToby Isaac /*@C 9820cf1dd8SToby Isaac PetscFESetType - Builds a particular PetscFE 9920cf1dd8SToby Isaac 100d083f849SBarry Smith Collective on fem 10120cf1dd8SToby Isaac 10220cf1dd8SToby Isaac Input Parameters: 10320cf1dd8SToby Isaac + fem - The PetscFE object 10420cf1dd8SToby Isaac - name - The kind of FEM space 10520cf1dd8SToby Isaac 10620cf1dd8SToby Isaac Options Database Key: 10720cf1dd8SToby Isaac . -petscfe_type <type> - Sets the PetscFE type; use -help for a list of available types 10820cf1dd8SToby Isaac 10920cf1dd8SToby Isaac Level: intermediate 11020cf1dd8SToby Isaac 11120cf1dd8SToby Isaac .seealso: PetscFEGetType(), PetscFECreate() 11220cf1dd8SToby Isaac @*/ 11320cf1dd8SToby Isaac PetscErrorCode PetscFESetType(PetscFE fem, PetscFEType name) 11420cf1dd8SToby Isaac { 11520cf1dd8SToby Isaac PetscErrorCode (*r)(PetscFE); 11620cf1dd8SToby Isaac PetscBool match; 11720cf1dd8SToby Isaac 11820cf1dd8SToby Isaac PetscFunctionBegin; 11920cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 1209566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject) fem, name, &match)); 12120cf1dd8SToby Isaac if (match) PetscFunctionReturn(0); 12220cf1dd8SToby Isaac 1239566063dSJacob Faibussowitsch if (!PetscFERegisterAllCalled) PetscCall(PetscFERegisterAll()); 1249566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(PetscFEList, name, &r)); 12528b400f6SJacob Faibussowitsch PetscCheck(r,PetscObjectComm((PetscObject) fem), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscFE type: %s", name); 12620cf1dd8SToby Isaac 12720cf1dd8SToby Isaac if (fem->ops->destroy) { 1289566063dSJacob Faibussowitsch PetscCall((*fem->ops->destroy)(fem)); 12920cf1dd8SToby Isaac fem->ops->destroy = NULL; 13020cf1dd8SToby Isaac } 1319566063dSJacob Faibussowitsch PetscCall((*r)(fem)); 1329566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject) fem, name)); 13320cf1dd8SToby Isaac PetscFunctionReturn(0); 13420cf1dd8SToby Isaac } 13520cf1dd8SToby Isaac 13620cf1dd8SToby Isaac /*@C 13720cf1dd8SToby Isaac PetscFEGetType - Gets the PetscFE type name (as a string) from the object. 13820cf1dd8SToby Isaac 13920cf1dd8SToby Isaac Not Collective 14020cf1dd8SToby Isaac 14120cf1dd8SToby Isaac Input Parameter: 14220cf1dd8SToby Isaac . fem - The PetscFE 14320cf1dd8SToby Isaac 14420cf1dd8SToby Isaac Output Parameter: 14520cf1dd8SToby Isaac . name - The PetscFE type name 14620cf1dd8SToby Isaac 14720cf1dd8SToby Isaac Level: intermediate 14820cf1dd8SToby Isaac 14920cf1dd8SToby Isaac .seealso: PetscFESetType(), PetscFECreate() 15020cf1dd8SToby Isaac @*/ 15120cf1dd8SToby Isaac PetscErrorCode PetscFEGetType(PetscFE fem, PetscFEType *name) 15220cf1dd8SToby Isaac { 15320cf1dd8SToby Isaac PetscFunctionBegin; 15420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 15520cf1dd8SToby Isaac PetscValidPointer(name, 2); 15620cf1dd8SToby Isaac if (!PetscFERegisterAllCalled) { 1579566063dSJacob Faibussowitsch PetscCall(PetscFERegisterAll()); 15820cf1dd8SToby Isaac } 15920cf1dd8SToby Isaac *name = ((PetscObject) fem)->type_name; 16020cf1dd8SToby Isaac PetscFunctionReturn(0); 16120cf1dd8SToby Isaac } 16220cf1dd8SToby Isaac 16320cf1dd8SToby Isaac /*@C 164fe2efc57SMark PetscFEViewFromOptions - View from Options 165fe2efc57SMark 166fe2efc57SMark Collective on PetscFE 167fe2efc57SMark 168fe2efc57SMark Input Parameters: 169fe2efc57SMark + A - the PetscFE object 170fe2efc57SMark . obj - Optional object 171fe2efc57SMark - name - command line option 172fe2efc57SMark 173fe2efc57SMark Level: intermediate 174fe2efc57SMark .seealso: PetscFE(), PetscFEView(), PetscObjectViewFromOptions(), PetscFECreate() 175fe2efc57SMark @*/ 176fe2efc57SMark PetscErrorCode PetscFEViewFromOptions(PetscFE A,PetscObject obj,const char name[]) 177fe2efc57SMark { 178fe2efc57SMark PetscFunctionBegin; 179fe2efc57SMark PetscValidHeaderSpecific(A,PETSCFE_CLASSID,1); 1809566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)A,obj,name)); 181fe2efc57SMark PetscFunctionReturn(0); 182fe2efc57SMark } 183fe2efc57SMark 184fe2efc57SMark /*@C 18520cf1dd8SToby Isaac PetscFEView - Views a PetscFE 18620cf1dd8SToby Isaac 187d083f849SBarry Smith Collective on fem 18820cf1dd8SToby Isaac 189d8d19677SJose E. Roman Input Parameters: 19020cf1dd8SToby Isaac + fem - the PetscFE object to view 191d9bac1caSLisandro Dalcin - viewer - the viewer 19220cf1dd8SToby Isaac 1932b99622eSMatthew G. Knepley Level: beginner 19420cf1dd8SToby Isaac 19520cf1dd8SToby Isaac .seealso PetscFEDestroy() 19620cf1dd8SToby Isaac @*/ 197d9bac1caSLisandro Dalcin PetscErrorCode PetscFEView(PetscFE fem, PetscViewer viewer) 19820cf1dd8SToby Isaac { 199d9bac1caSLisandro Dalcin PetscBool iascii; 20020cf1dd8SToby Isaac 20120cf1dd8SToby Isaac PetscFunctionBegin; 20220cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 203d9bac1caSLisandro Dalcin if (viewer) PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 2049566063dSJacob Faibussowitsch if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) fem), &viewer)); 2059566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)fem, viewer)); 2069566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERASCII, &iascii)); 2079566063dSJacob Faibussowitsch if (fem->ops->view) PetscCall((*fem->ops->view)(fem, viewer)); 20820cf1dd8SToby Isaac PetscFunctionReturn(0); 20920cf1dd8SToby Isaac } 21020cf1dd8SToby Isaac 21120cf1dd8SToby Isaac /*@ 21220cf1dd8SToby Isaac PetscFESetFromOptions - sets parameters in a PetscFE from the options database 21320cf1dd8SToby Isaac 214d083f849SBarry Smith Collective on fem 21520cf1dd8SToby Isaac 21620cf1dd8SToby Isaac Input Parameter: 21720cf1dd8SToby Isaac . fem - the PetscFE object to set options for 21820cf1dd8SToby Isaac 21920cf1dd8SToby Isaac Options Database: 220a2b725a8SWilliam Gropp + -petscfe_num_blocks - the number of cell blocks to integrate concurrently 221a2b725a8SWilliam Gropp - -petscfe_num_batches - the number of cell batches to integrate serially 22220cf1dd8SToby Isaac 2232b99622eSMatthew G. Knepley Level: intermediate 22420cf1dd8SToby Isaac 22520cf1dd8SToby Isaac .seealso PetscFEView() 22620cf1dd8SToby Isaac @*/ 22720cf1dd8SToby Isaac PetscErrorCode PetscFESetFromOptions(PetscFE fem) 22820cf1dd8SToby Isaac { 22920cf1dd8SToby Isaac const char *defaultType; 23020cf1dd8SToby Isaac char name[256]; 23120cf1dd8SToby Isaac PetscBool flg; 23220cf1dd8SToby Isaac 23320cf1dd8SToby Isaac PetscFunctionBegin; 23420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 23520cf1dd8SToby Isaac if (!((PetscObject) fem)->type_name) { 23620cf1dd8SToby Isaac defaultType = PETSCFEBASIC; 23720cf1dd8SToby Isaac } else { 23820cf1dd8SToby Isaac defaultType = ((PetscObject) fem)->type_name; 23920cf1dd8SToby Isaac } 2409566063dSJacob Faibussowitsch if (!PetscFERegisterAllCalled) PetscCall(PetscFERegisterAll()); 24120cf1dd8SToby Isaac 242d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject) fem); 2439566063dSJacob Faibussowitsch PetscCall(PetscOptionsFList("-petscfe_type", "Finite element space", "PetscFESetType", PetscFEList, defaultType, name, 256, &flg)); 24420cf1dd8SToby Isaac if (flg) { 2459566063dSJacob Faibussowitsch PetscCall(PetscFESetType(fem, name)); 24620cf1dd8SToby Isaac } else if (!((PetscObject) fem)->type_name) { 2479566063dSJacob Faibussowitsch PetscCall(PetscFESetType(fem, defaultType)); 24820cf1dd8SToby Isaac } 2499566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-petscfe_num_blocks", "The number of cell blocks to integrate concurrently", "PetscSpaceSetTileSizes", fem->numBlocks, &fem->numBlocks, NULL,1)); 2509566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-petscfe_num_batches", "The number of cell batches to integrate serially", "PetscSpaceSetTileSizes", fem->numBatches, &fem->numBatches, NULL,1)); 25120cf1dd8SToby Isaac if (fem->ops->setfromoptions) { 2529566063dSJacob Faibussowitsch PetscCall((*fem->ops->setfromoptions)(PetscOptionsObject,fem)); 25320cf1dd8SToby Isaac } 25420cf1dd8SToby Isaac /* process any options handlers added with PetscObjectAddOptionsHandler() */ 2559566063dSJacob Faibussowitsch PetscCall(PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) fem)); 256d0609cedSBarry Smith PetscOptionsEnd(); 2579566063dSJacob Faibussowitsch PetscCall(PetscFEViewFromOptions(fem, NULL, "-petscfe_view")); 25820cf1dd8SToby Isaac PetscFunctionReturn(0); 25920cf1dd8SToby Isaac } 26020cf1dd8SToby Isaac 26120cf1dd8SToby Isaac /*@C 26220cf1dd8SToby Isaac PetscFESetUp - Construct data structures for the PetscFE 26320cf1dd8SToby Isaac 264d083f849SBarry Smith Collective on fem 26520cf1dd8SToby Isaac 26620cf1dd8SToby Isaac Input Parameter: 26720cf1dd8SToby Isaac . fem - the PetscFE object to setup 26820cf1dd8SToby Isaac 2692b99622eSMatthew G. Knepley Level: intermediate 27020cf1dd8SToby Isaac 27120cf1dd8SToby Isaac .seealso PetscFEView(), PetscFEDestroy() 27220cf1dd8SToby Isaac @*/ 27320cf1dd8SToby Isaac PetscErrorCode PetscFESetUp(PetscFE fem) 27420cf1dd8SToby Isaac { 27520cf1dd8SToby Isaac PetscFunctionBegin; 27620cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 27720cf1dd8SToby Isaac if (fem->setupcalled) PetscFunctionReturn(0); 2789566063dSJacob Faibussowitsch PetscCall(PetscLogEventBegin(PETSCFE_SetUp, fem, 0, 0, 0)); 27920cf1dd8SToby Isaac fem->setupcalled = PETSC_TRUE; 2809566063dSJacob Faibussowitsch if (fem->ops->setup) PetscCall((*fem->ops->setup)(fem)); 2819566063dSJacob Faibussowitsch PetscCall(PetscLogEventEnd(PETSCFE_SetUp, fem, 0, 0, 0)); 28220cf1dd8SToby Isaac PetscFunctionReturn(0); 28320cf1dd8SToby Isaac } 28420cf1dd8SToby Isaac 28520cf1dd8SToby Isaac /*@ 28620cf1dd8SToby Isaac PetscFEDestroy - Destroys a PetscFE object 28720cf1dd8SToby Isaac 288d083f849SBarry Smith Collective on fem 28920cf1dd8SToby Isaac 29020cf1dd8SToby Isaac Input Parameter: 29120cf1dd8SToby Isaac . fem - the PetscFE object to destroy 29220cf1dd8SToby Isaac 2932b99622eSMatthew G. Knepley Level: beginner 29420cf1dd8SToby Isaac 29520cf1dd8SToby Isaac .seealso PetscFEView() 29620cf1dd8SToby Isaac @*/ 29720cf1dd8SToby Isaac PetscErrorCode PetscFEDestroy(PetscFE *fem) 29820cf1dd8SToby Isaac { 29920cf1dd8SToby Isaac PetscFunctionBegin; 30020cf1dd8SToby Isaac if (!*fem) PetscFunctionReturn(0); 30120cf1dd8SToby Isaac PetscValidHeaderSpecific((*fem), PETSCFE_CLASSID, 1); 30220cf1dd8SToby Isaac 303ea78f98cSLisandro Dalcin if (--((PetscObject)(*fem))->refct > 0) {*fem = NULL; PetscFunctionReturn(0);} 30420cf1dd8SToby Isaac ((PetscObject) (*fem))->refct = 0; 30520cf1dd8SToby Isaac 30620cf1dd8SToby Isaac if ((*fem)->subspaces) { 30720cf1dd8SToby Isaac PetscInt dim, d; 30820cf1dd8SToby Isaac 3099566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension((*fem)->dualSpace, &dim)); 3109566063dSJacob Faibussowitsch for (d = 0; d < dim; ++d) PetscCall(PetscFEDestroy(&(*fem)->subspaces[d])); 31120cf1dd8SToby Isaac } 3129566063dSJacob Faibussowitsch PetscCall(PetscFree((*fem)->subspaces)); 3139566063dSJacob Faibussowitsch PetscCall(PetscFree((*fem)->invV)); 3149566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&(*fem)->T)); 3159566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&(*fem)->Tf)); 3169566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&(*fem)->Tc)); 3179566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&(*fem)->basisSpace)); 3189566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&(*fem)->dualSpace)); 3199566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&(*fem)->quadrature)); 3209566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&(*fem)->faceQuadrature)); 321f918ec44SMatthew G. Knepley #ifdef PETSC_HAVE_LIBCEED 3229566063dSJacob Faibussowitsch PetscCallCEED(CeedBasisDestroy(&(*fem)->ceedBasis)); 3239566063dSJacob Faibussowitsch PetscCallCEED(CeedDestroy(&(*fem)->ceed)); 324f918ec44SMatthew G. Knepley #endif 32520cf1dd8SToby Isaac 3269566063dSJacob Faibussowitsch if ((*fem)->ops->destroy) PetscCall((*(*fem)->ops->destroy)(*fem)); 3279566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(fem)); 32820cf1dd8SToby Isaac PetscFunctionReturn(0); 32920cf1dd8SToby Isaac } 33020cf1dd8SToby Isaac 33120cf1dd8SToby Isaac /*@ 33220cf1dd8SToby Isaac PetscFECreate - Creates an empty PetscFE object. The type can then be set with PetscFESetType(). 33320cf1dd8SToby Isaac 334d083f849SBarry Smith Collective 33520cf1dd8SToby Isaac 33620cf1dd8SToby Isaac Input Parameter: 33720cf1dd8SToby Isaac . comm - The communicator for the PetscFE object 33820cf1dd8SToby Isaac 33920cf1dd8SToby Isaac Output Parameter: 34020cf1dd8SToby Isaac . fem - The PetscFE object 34120cf1dd8SToby Isaac 34220cf1dd8SToby Isaac Level: beginner 34320cf1dd8SToby Isaac 34420cf1dd8SToby Isaac .seealso: PetscFESetType(), PETSCFEGALERKIN 34520cf1dd8SToby Isaac @*/ 34620cf1dd8SToby Isaac PetscErrorCode PetscFECreate(MPI_Comm comm, PetscFE *fem) 34720cf1dd8SToby Isaac { 34820cf1dd8SToby Isaac PetscFE f; 34920cf1dd8SToby Isaac 35020cf1dd8SToby Isaac PetscFunctionBegin; 35120cf1dd8SToby Isaac PetscValidPointer(fem, 2); 3529566063dSJacob Faibussowitsch PetscCall(PetscCitationsRegister(FECitation,&FEcite)); 35320cf1dd8SToby Isaac *fem = NULL; 3549566063dSJacob Faibussowitsch PetscCall(PetscFEInitializePackage()); 35520cf1dd8SToby Isaac 3569566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(f, PETSCFE_CLASSID, "PetscFE", "Finite Element", "PetscFE", comm, PetscFEDestroy, PetscFEView)); 35720cf1dd8SToby Isaac 35820cf1dd8SToby Isaac f->basisSpace = NULL; 35920cf1dd8SToby Isaac f->dualSpace = NULL; 36020cf1dd8SToby Isaac f->numComponents = 1; 36120cf1dd8SToby Isaac f->subspaces = NULL; 36220cf1dd8SToby Isaac f->invV = NULL; 363ef0bb6c7SMatthew G. Knepley f->T = NULL; 364ef0bb6c7SMatthew G. Knepley f->Tf = NULL; 365ef0bb6c7SMatthew G. Knepley f->Tc = NULL; 3669566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(&f->quadrature, 1)); 3679566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(&f->faceQuadrature, 1)); 36820cf1dd8SToby Isaac f->blockSize = 0; 36920cf1dd8SToby Isaac f->numBlocks = 1; 37020cf1dd8SToby Isaac f->batchSize = 0; 37120cf1dd8SToby Isaac f->numBatches = 1; 37220cf1dd8SToby Isaac 37320cf1dd8SToby Isaac *fem = f; 37420cf1dd8SToby Isaac PetscFunctionReturn(0); 37520cf1dd8SToby Isaac } 37620cf1dd8SToby Isaac 37720cf1dd8SToby Isaac /*@ 37820cf1dd8SToby Isaac PetscFEGetSpatialDimension - Returns the spatial dimension of the element 37920cf1dd8SToby Isaac 38020cf1dd8SToby Isaac Not collective 38120cf1dd8SToby Isaac 38220cf1dd8SToby Isaac Input Parameter: 38320cf1dd8SToby Isaac . fem - The PetscFE object 38420cf1dd8SToby Isaac 38520cf1dd8SToby Isaac Output Parameter: 38620cf1dd8SToby Isaac . dim - The spatial dimension 38720cf1dd8SToby Isaac 38820cf1dd8SToby Isaac Level: intermediate 38920cf1dd8SToby Isaac 39020cf1dd8SToby Isaac .seealso: PetscFECreate() 39120cf1dd8SToby Isaac @*/ 39220cf1dd8SToby Isaac PetscErrorCode PetscFEGetSpatialDimension(PetscFE fem, PetscInt *dim) 39320cf1dd8SToby Isaac { 39420cf1dd8SToby Isaac DM dm; 39520cf1dd8SToby Isaac 39620cf1dd8SToby Isaac PetscFunctionBegin; 39720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 398dadcf809SJacob Faibussowitsch PetscValidIntPointer(dim, 2); 3999566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(fem->dualSpace, &dm)); 4009566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, dim)); 40120cf1dd8SToby Isaac PetscFunctionReturn(0); 40220cf1dd8SToby Isaac } 40320cf1dd8SToby Isaac 40420cf1dd8SToby Isaac /*@ 40520cf1dd8SToby Isaac PetscFESetNumComponents - Sets the number of components in the element 40620cf1dd8SToby Isaac 40720cf1dd8SToby Isaac Not collective 40820cf1dd8SToby Isaac 40920cf1dd8SToby Isaac Input Parameters: 41020cf1dd8SToby Isaac + fem - The PetscFE object 41120cf1dd8SToby Isaac - comp - The number of field components 41220cf1dd8SToby Isaac 41320cf1dd8SToby Isaac Level: intermediate 41420cf1dd8SToby Isaac 41520cf1dd8SToby Isaac .seealso: PetscFECreate() 41620cf1dd8SToby Isaac @*/ 41720cf1dd8SToby Isaac PetscErrorCode PetscFESetNumComponents(PetscFE fem, PetscInt comp) 41820cf1dd8SToby Isaac { 41920cf1dd8SToby Isaac PetscFunctionBegin; 42020cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 42120cf1dd8SToby Isaac fem->numComponents = comp; 42220cf1dd8SToby Isaac PetscFunctionReturn(0); 42320cf1dd8SToby Isaac } 42420cf1dd8SToby Isaac 42520cf1dd8SToby Isaac /*@ 42620cf1dd8SToby Isaac PetscFEGetNumComponents - Returns the number of components in the element 42720cf1dd8SToby Isaac 42820cf1dd8SToby Isaac Not collective 42920cf1dd8SToby Isaac 43020cf1dd8SToby Isaac Input Parameter: 43120cf1dd8SToby Isaac . fem - The PetscFE object 43220cf1dd8SToby Isaac 43320cf1dd8SToby Isaac Output Parameter: 43420cf1dd8SToby Isaac . comp - The number of field components 43520cf1dd8SToby Isaac 43620cf1dd8SToby Isaac Level: intermediate 43720cf1dd8SToby Isaac 43820cf1dd8SToby Isaac .seealso: PetscFECreate() 43920cf1dd8SToby Isaac @*/ 44020cf1dd8SToby Isaac PetscErrorCode PetscFEGetNumComponents(PetscFE fem, PetscInt *comp) 44120cf1dd8SToby Isaac { 44220cf1dd8SToby Isaac PetscFunctionBegin; 44320cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 444dadcf809SJacob Faibussowitsch PetscValidIntPointer(comp, 2); 44520cf1dd8SToby Isaac *comp = fem->numComponents; 44620cf1dd8SToby Isaac PetscFunctionReturn(0); 44720cf1dd8SToby Isaac } 44820cf1dd8SToby Isaac 44920cf1dd8SToby Isaac /*@ 45020cf1dd8SToby Isaac PetscFESetTileSizes - Sets the tile sizes for evaluation 45120cf1dd8SToby Isaac 45220cf1dd8SToby Isaac Not collective 45320cf1dd8SToby Isaac 45420cf1dd8SToby Isaac Input Parameters: 45520cf1dd8SToby Isaac + fem - The PetscFE object 45620cf1dd8SToby Isaac . blockSize - The number of elements in a block 45720cf1dd8SToby Isaac . numBlocks - The number of blocks in a batch 45820cf1dd8SToby Isaac . batchSize - The number of elements in a batch 45920cf1dd8SToby Isaac - numBatches - The number of batches in a chunk 46020cf1dd8SToby Isaac 46120cf1dd8SToby Isaac Level: intermediate 46220cf1dd8SToby Isaac 46320cf1dd8SToby Isaac .seealso: PetscFECreate() 46420cf1dd8SToby Isaac @*/ 46520cf1dd8SToby Isaac PetscErrorCode PetscFESetTileSizes(PetscFE fem, PetscInt blockSize, PetscInt numBlocks, PetscInt batchSize, PetscInt numBatches) 46620cf1dd8SToby Isaac { 46720cf1dd8SToby Isaac PetscFunctionBegin; 46820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 46920cf1dd8SToby Isaac fem->blockSize = blockSize; 47020cf1dd8SToby Isaac fem->numBlocks = numBlocks; 47120cf1dd8SToby Isaac fem->batchSize = batchSize; 47220cf1dd8SToby Isaac fem->numBatches = numBatches; 47320cf1dd8SToby Isaac PetscFunctionReturn(0); 47420cf1dd8SToby Isaac } 47520cf1dd8SToby Isaac 47620cf1dd8SToby Isaac /*@ 47720cf1dd8SToby Isaac PetscFEGetTileSizes - Returns the tile sizes for evaluation 47820cf1dd8SToby Isaac 47920cf1dd8SToby Isaac Not collective 48020cf1dd8SToby Isaac 48120cf1dd8SToby Isaac Input Parameter: 48220cf1dd8SToby Isaac . fem - The PetscFE object 48320cf1dd8SToby Isaac 48420cf1dd8SToby Isaac Output Parameters: 48520cf1dd8SToby Isaac + blockSize - The number of elements in a block 48620cf1dd8SToby Isaac . numBlocks - The number of blocks in a batch 48720cf1dd8SToby Isaac . batchSize - The number of elements in a batch 48820cf1dd8SToby Isaac - numBatches - The number of batches in a chunk 48920cf1dd8SToby Isaac 49020cf1dd8SToby Isaac Level: intermediate 49120cf1dd8SToby Isaac 49220cf1dd8SToby Isaac .seealso: PetscFECreate() 49320cf1dd8SToby Isaac @*/ 49420cf1dd8SToby Isaac PetscErrorCode PetscFEGetTileSizes(PetscFE fem, PetscInt *blockSize, PetscInt *numBlocks, PetscInt *batchSize, PetscInt *numBatches) 49520cf1dd8SToby Isaac { 49620cf1dd8SToby Isaac PetscFunctionBegin; 49720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 498dadcf809SJacob Faibussowitsch if (blockSize) PetscValidIntPointer(blockSize, 2); 499dadcf809SJacob Faibussowitsch if (numBlocks) PetscValidIntPointer(numBlocks, 3); 500dadcf809SJacob Faibussowitsch if (batchSize) PetscValidIntPointer(batchSize, 4); 501dadcf809SJacob Faibussowitsch if (numBatches) PetscValidIntPointer(numBatches, 5); 50220cf1dd8SToby Isaac if (blockSize) *blockSize = fem->blockSize; 50320cf1dd8SToby Isaac if (numBlocks) *numBlocks = fem->numBlocks; 50420cf1dd8SToby Isaac if (batchSize) *batchSize = fem->batchSize; 50520cf1dd8SToby Isaac if (numBatches) *numBatches = fem->numBatches; 50620cf1dd8SToby Isaac PetscFunctionReturn(0); 50720cf1dd8SToby Isaac } 50820cf1dd8SToby Isaac 50920cf1dd8SToby Isaac /*@ 51020cf1dd8SToby Isaac PetscFEGetBasisSpace - Returns the PetscSpace used for approximation of the solution 51120cf1dd8SToby Isaac 51220cf1dd8SToby Isaac Not collective 51320cf1dd8SToby Isaac 51420cf1dd8SToby Isaac Input Parameter: 51520cf1dd8SToby Isaac . fem - The PetscFE object 51620cf1dd8SToby Isaac 51720cf1dd8SToby Isaac Output Parameter: 51820cf1dd8SToby Isaac . sp - The PetscSpace object 51920cf1dd8SToby Isaac 52020cf1dd8SToby Isaac Level: intermediate 52120cf1dd8SToby Isaac 52220cf1dd8SToby Isaac .seealso: PetscFECreate() 52320cf1dd8SToby Isaac @*/ 52420cf1dd8SToby Isaac PetscErrorCode PetscFEGetBasisSpace(PetscFE fem, PetscSpace *sp) 52520cf1dd8SToby Isaac { 52620cf1dd8SToby Isaac PetscFunctionBegin; 52720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 52820cf1dd8SToby Isaac PetscValidPointer(sp, 2); 52920cf1dd8SToby Isaac *sp = fem->basisSpace; 53020cf1dd8SToby Isaac PetscFunctionReturn(0); 53120cf1dd8SToby Isaac } 53220cf1dd8SToby Isaac 53320cf1dd8SToby Isaac /*@ 53420cf1dd8SToby Isaac PetscFESetBasisSpace - Sets the PetscSpace used for approximation of the solution 53520cf1dd8SToby Isaac 53620cf1dd8SToby Isaac Not collective 53720cf1dd8SToby Isaac 53820cf1dd8SToby Isaac Input Parameters: 53920cf1dd8SToby Isaac + fem - The PetscFE object 54020cf1dd8SToby Isaac - sp - The PetscSpace object 54120cf1dd8SToby Isaac 54220cf1dd8SToby Isaac Level: intermediate 54320cf1dd8SToby Isaac 54420cf1dd8SToby Isaac .seealso: PetscFECreate() 54520cf1dd8SToby Isaac @*/ 54620cf1dd8SToby Isaac PetscErrorCode PetscFESetBasisSpace(PetscFE fem, PetscSpace sp) 54720cf1dd8SToby Isaac { 54820cf1dd8SToby Isaac PetscFunctionBegin; 54920cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 55020cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 2); 5519566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&fem->basisSpace)); 55220cf1dd8SToby Isaac fem->basisSpace = sp; 5539566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) fem->basisSpace)); 55420cf1dd8SToby Isaac PetscFunctionReturn(0); 55520cf1dd8SToby Isaac } 55620cf1dd8SToby Isaac 55720cf1dd8SToby Isaac /*@ 55820cf1dd8SToby Isaac PetscFEGetDualSpace - Returns the PetscDualSpace used to define the inner product 55920cf1dd8SToby Isaac 56020cf1dd8SToby Isaac Not collective 56120cf1dd8SToby Isaac 56220cf1dd8SToby Isaac Input Parameter: 56320cf1dd8SToby Isaac . fem - The PetscFE object 56420cf1dd8SToby Isaac 56520cf1dd8SToby Isaac Output Parameter: 56620cf1dd8SToby Isaac . sp - The PetscDualSpace object 56720cf1dd8SToby Isaac 56820cf1dd8SToby Isaac Level: intermediate 56920cf1dd8SToby Isaac 57020cf1dd8SToby Isaac .seealso: PetscFECreate() 57120cf1dd8SToby Isaac @*/ 57220cf1dd8SToby Isaac PetscErrorCode PetscFEGetDualSpace(PetscFE fem, PetscDualSpace *sp) 57320cf1dd8SToby Isaac { 57420cf1dd8SToby Isaac PetscFunctionBegin; 57520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 57620cf1dd8SToby Isaac PetscValidPointer(sp, 2); 57720cf1dd8SToby Isaac *sp = fem->dualSpace; 57820cf1dd8SToby Isaac PetscFunctionReturn(0); 57920cf1dd8SToby Isaac } 58020cf1dd8SToby Isaac 58120cf1dd8SToby Isaac /*@ 58220cf1dd8SToby Isaac PetscFESetDualSpace - Sets the PetscDualSpace used to define the inner product 58320cf1dd8SToby Isaac 58420cf1dd8SToby Isaac Not collective 58520cf1dd8SToby Isaac 58620cf1dd8SToby Isaac Input Parameters: 58720cf1dd8SToby Isaac + fem - The PetscFE object 58820cf1dd8SToby Isaac - sp - The PetscDualSpace object 58920cf1dd8SToby Isaac 59020cf1dd8SToby Isaac Level: intermediate 59120cf1dd8SToby Isaac 59220cf1dd8SToby Isaac .seealso: PetscFECreate() 59320cf1dd8SToby Isaac @*/ 59420cf1dd8SToby Isaac PetscErrorCode PetscFESetDualSpace(PetscFE fem, PetscDualSpace sp) 59520cf1dd8SToby Isaac { 59620cf1dd8SToby Isaac PetscFunctionBegin; 59720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 59820cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 2); 5999566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&fem->dualSpace)); 60020cf1dd8SToby Isaac fem->dualSpace = sp; 6019566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) fem->dualSpace)); 60220cf1dd8SToby Isaac PetscFunctionReturn(0); 60320cf1dd8SToby Isaac } 60420cf1dd8SToby Isaac 60520cf1dd8SToby Isaac /*@ 60620cf1dd8SToby Isaac PetscFEGetQuadrature - Returns the PetscQuadrature used to calculate inner products 60720cf1dd8SToby Isaac 60820cf1dd8SToby Isaac Not collective 60920cf1dd8SToby Isaac 61020cf1dd8SToby Isaac Input Parameter: 61120cf1dd8SToby Isaac . fem - The PetscFE object 61220cf1dd8SToby Isaac 61320cf1dd8SToby Isaac Output Parameter: 61420cf1dd8SToby Isaac . q - The PetscQuadrature object 61520cf1dd8SToby Isaac 61620cf1dd8SToby Isaac Level: intermediate 61720cf1dd8SToby Isaac 61820cf1dd8SToby Isaac .seealso: PetscFECreate() 61920cf1dd8SToby Isaac @*/ 62020cf1dd8SToby Isaac PetscErrorCode PetscFEGetQuadrature(PetscFE fem, PetscQuadrature *q) 62120cf1dd8SToby Isaac { 62220cf1dd8SToby Isaac PetscFunctionBegin; 62320cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 62420cf1dd8SToby Isaac PetscValidPointer(q, 2); 62520cf1dd8SToby Isaac *q = fem->quadrature; 62620cf1dd8SToby Isaac PetscFunctionReturn(0); 62720cf1dd8SToby Isaac } 62820cf1dd8SToby Isaac 62920cf1dd8SToby Isaac /*@ 63020cf1dd8SToby Isaac PetscFESetQuadrature - Sets the PetscQuadrature used to calculate inner products 63120cf1dd8SToby Isaac 63220cf1dd8SToby Isaac Not collective 63320cf1dd8SToby Isaac 63420cf1dd8SToby Isaac Input Parameters: 63520cf1dd8SToby Isaac + fem - The PetscFE object 63620cf1dd8SToby Isaac - q - The PetscQuadrature object 63720cf1dd8SToby Isaac 63820cf1dd8SToby Isaac Level: intermediate 63920cf1dd8SToby Isaac 64020cf1dd8SToby Isaac .seealso: PetscFECreate() 64120cf1dd8SToby Isaac @*/ 64220cf1dd8SToby Isaac PetscErrorCode PetscFESetQuadrature(PetscFE fem, PetscQuadrature q) 64320cf1dd8SToby Isaac { 64420cf1dd8SToby Isaac PetscInt Nc, qNc; 64520cf1dd8SToby Isaac 64620cf1dd8SToby Isaac PetscFunctionBegin; 64720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 648fd2fdbddSMatthew G. Knepley if (q == fem->quadrature) PetscFunctionReturn(0); 6499566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 6509566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetNumComponents(q, &qNc)); 65163a3b9bcSJacob Faibussowitsch PetscCheck(!(qNc != 1) || !(Nc != qNc),PetscObjectComm((PetscObject) fem), PETSC_ERR_ARG_SIZ, "FE components %" PetscInt_FMT " != Quadrature components %" PetscInt_FMT " and non-scalar quadrature", Nc, qNc); 6529566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&fem->T)); 6539566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&fem->Tc)); 6549566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) q)); 6559566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&fem->quadrature)); 65620cf1dd8SToby Isaac fem->quadrature = q; 65720cf1dd8SToby Isaac PetscFunctionReturn(0); 65820cf1dd8SToby Isaac } 65920cf1dd8SToby Isaac 66020cf1dd8SToby Isaac /*@ 66120cf1dd8SToby Isaac PetscFEGetFaceQuadrature - Returns the PetscQuadrature used to calculate inner products on faces 66220cf1dd8SToby Isaac 66320cf1dd8SToby Isaac Not collective 66420cf1dd8SToby Isaac 66520cf1dd8SToby Isaac Input Parameter: 66620cf1dd8SToby Isaac . fem - The PetscFE object 66720cf1dd8SToby Isaac 66820cf1dd8SToby Isaac Output Parameter: 66920cf1dd8SToby Isaac . q - The PetscQuadrature object 67020cf1dd8SToby Isaac 67120cf1dd8SToby Isaac Level: intermediate 67220cf1dd8SToby Isaac 67320cf1dd8SToby Isaac .seealso: PetscFECreate() 67420cf1dd8SToby Isaac @*/ 67520cf1dd8SToby Isaac PetscErrorCode PetscFEGetFaceQuadrature(PetscFE fem, PetscQuadrature *q) 67620cf1dd8SToby Isaac { 67720cf1dd8SToby Isaac PetscFunctionBegin; 67820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 67920cf1dd8SToby Isaac PetscValidPointer(q, 2); 68020cf1dd8SToby Isaac *q = fem->faceQuadrature; 68120cf1dd8SToby Isaac PetscFunctionReturn(0); 68220cf1dd8SToby Isaac } 68320cf1dd8SToby Isaac 68420cf1dd8SToby Isaac /*@ 68520cf1dd8SToby Isaac PetscFESetFaceQuadrature - Sets the PetscQuadrature used to calculate inner products on faces 68620cf1dd8SToby Isaac 68720cf1dd8SToby Isaac Not collective 68820cf1dd8SToby Isaac 68920cf1dd8SToby Isaac Input Parameters: 69020cf1dd8SToby Isaac + fem - The PetscFE object 69120cf1dd8SToby Isaac - q - The PetscQuadrature object 69220cf1dd8SToby Isaac 69320cf1dd8SToby Isaac Level: intermediate 69420cf1dd8SToby Isaac 69520cf1dd8SToby Isaac .seealso: PetscFECreate() 69620cf1dd8SToby Isaac @*/ 69720cf1dd8SToby Isaac PetscErrorCode PetscFESetFaceQuadrature(PetscFE fem, PetscQuadrature q) 69820cf1dd8SToby Isaac { 699ef0bb6c7SMatthew G. Knepley PetscInt Nc, qNc; 70020cf1dd8SToby Isaac 70120cf1dd8SToby Isaac PetscFunctionBegin; 70220cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 7039566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 7049566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetNumComponents(q, &qNc)); 70563a3b9bcSJacob Faibussowitsch PetscCheck(!(qNc != 1) || !(Nc != qNc),PetscObjectComm((PetscObject) fem), PETSC_ERR_ARG_SIZ, "FE components %" PetscInt_FMT " != Quadrature components %" PetscInt_FMT " and non-scalar quadrature", Nc, qNc); 7069566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&fem->Tf)); 7079566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&fem->faceQuadrature)); 70820cf1dd8SToby Isaac fem->faceQuadrature = q; 7099566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) q)); 71020cf1dd8SToby Isaac PetscFunctionReturn(0); 71120cf1dd8SToby Isaac } 71220cf1dd8SToby Isaac 7135dc5c000SMatthew G. Knepley /*@ 7145dc5c000SMatthew G. Knepley PetscFECopyQuadrature - Copy both volumetric and surface quadrature 7155dc5c000SMatthew G. Knepley 7165dc5c000SMatthew G. Knepley Not collective 7175dc5c000SMatthew G. Knepley 7185dc5c000SMatthew G. Knepley Input Parameters: 7195dc5c000SMatthew G. Knepley + sfe - The PetscFE source for the quadratures 7205dc5c000SMatthew G. Knepley - tfe - The PetscFE target for the quadratures 7215dc5c000SMatthew G. Knepley 7225dc5c000SMatthew G. Knepley Level: intermediate 7235dc5c000SMatthew G. Knepley 7245dc5c000SMatthew G. Knepley .seealso: PetscFECreate(), PetscFESetQuadrature(), PetscFESetFaceQuadrature() 7255dc5c000SMatthew G. Knepley @*/ 7265dc5c000SMatthew G. Knepley PetscErrorCode PetscFECopyQuadrature(PetscFE sfe, PetscFE tfe) 7275dc5c000SMatthew G. Knepley { 7285dc5c000SMatthew G. Knepley PetscQuadrature q; 7295dc5c000SMatthew G. Knepley 7305dc5c000SMatthew G. Knepley PetscFunctionBegin; 7315dc5c000SMatthew G. Knepley PetscValidHeaderSpecific(sfe, PETSCFE_CLASSID, 1); 7325dc5c000SMatthew G. Knepley PetscValidHeaderSpecific(tfe, PETSCFE_CLASSID, 2); 7339566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(sfe, &q)); 7349566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(tfe, q)); 7359566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(sfe, &q)); 7369566063dSJacob Faibussowitsch PetscCall(PetscFESetFaceQuadrature(tfe, q)); 7375dc5c000SMatthew G. Knepley PetscFunctionReturn(0); 7385dc5c000SMatthew G. Knepley } 7395dc5c000SMatthew G. Knepley 74020cf1dd8SToby Isaac /*@C 74120cf1dd8SToby Isaac PetscFEGetNumDof - Returns the number of dofs (dual basis vectors) associated to mesh points on the reference cell of a given dimension 74220cf1dd8SToby Isaac 74320cf1dd8SToby Isaac Not collective 74420cf1dd8SToby Isaac 74520cf1dd8SToby Isaac Input Parameter: 74620cf1dd8SToby Isaac . fem - The PetscFE object 74720cf1dd8SToby Isaac 74820cf1dd8SToby Isaac Output Parameter: 74920cf1dd8SToby Isaac . numDof - Array with the number of dofs per dimension 75020cf1dd8SToby Isaac 75120cf1dd8SToby Isaac Level: intermediate 75220cf1dd8SToby Isaac 75320cf1dd8SToby Isaac .seealso: PetscFECreate() 75420cf1dd8SToby Isaac @*/ 75520cf1dd8SToby Isaac PetscErrorCode PetscFEGetNumDof(PetscFE fem, const PetscInt **numDof) 75620cf1dd8SToby Isaac { 75720cf1dd8SToby Isaac PetscFunctionBegin; 75820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 75920cf1dd8SToby Isaac PetscValidPointer(numDof, 2); 7609566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetNumDof(fem->dualSpace, numDof)); 76120cf1dd8SToby Isaac PetscFunctionReturn(0); 76220cf1dd8SToby Isaac } 76320cf1dd8SToby Isaac 76420cf1dd8SToby Isaac /*@C 765ef0bb6c7SMatthew G. Knepley PetscFEGetCellTabulation - Returns the tabulation of the basis functions at the quadrature points on the reference cell 76620cf1dd8SToby Isaac 76720cf1dd8SToby Isaac Not collective 76820cf1dd8SToby Isaac 769d8d19677SJose E. Roman Input Parameters: 770f9244615SMatthew G. Knepley + fem - The PetscFE object 771f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate, very often 1 77220cf1dd8SToby Isaac 773ef0bb6c7SMatthew G. Knepley Output Parameter: 774ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at quadrature points 77520cf1dd8SToby Isaac 77620cf1dd8SToby Isaac Note: 777ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 778ef0bb6c7SMatthew G. Knepley $ T->T[1] = D[((p*pdim + i)*Nc + c)*dim + d] is the derivative value at point p for basis function i, component c, in direction d 779ef0bb6c7SMatthew G. Knepley $ T->T[2] = H[(((p*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point p for basis function i, component c, in directions d and e 78020cf1dd8SToby Isaac 78120cf1dd8SToby Isaac Level: intermediate 78220cf1dd8SToby Isaac 783ef0bb6c7SMatthew G. Knepley .seealso: PetscFECreateTabulation(), PetscTabulationDestroy() 78420cf1dd8SToby Isaac @*/ 785f9244615SMatthew G. Knepley PetscErrorCode PetscFEGetCellTabulation(PetscFE fem, PetscInt k, PetscTabulation *T) 78620cf1dd8SToby Isaac { 78720cf1dd8SToby Isaac PetscInt npoints; 78820cf1dd8SToby Isaac const PetscReal *points; 78920cf1dd8SToby Isaac 79020cf1dd8SToby Isaac PetscFunctionBegin; 79120cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 792064a246eSJacob Faibussowitsch PetscValidPointer(T, 3); 7939566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(fem->quadrature, NULL, NULL, &npoints, &points, NULL)); 7949566063dSJacob Faibussowitsch if (!fem->T) PetscCall(PetscFECreateTabulation(fem, 1, npoints, points, k, &fem->T)); 795*1dca8a05SBarry Smith PetscCheck(!fem->T || k <= fem->T->K,PetscObjectComm((PetscObject) fem), PETSC_ERR_ARG_OUTOFRANGE, "Requested %" PetscInt_FMT " derivatives, but only tabulated %" PetscInt_FMT, k, fem->T->K); 796ef0bb6c7SMatthew G. Knepley *T = fem->T; 79720cf1dd8SToby Isaac PetscFunctionReturn(0); 79820cf1dd8SToby Isaac } 79920cf1dd8SToby Isaac 8002b99622eSMatthew G. Knepley /*@C 801ef0bb6c7SMatthew G. Knepley PetscFEGetFaceTabulation - Returns the tabulation of the basis functions at the face quadrature points for each face of the reference cell 8022b99622eSMatthew G. Knepley 8032b99622eSMatthew G. Knepley Not collective 8042b99622eSMatthew G. Knepley 805d8d19677SJose E. Roman Input Parameters: 806f9244615SMatthew G. Knepley + fem - The PetscFE object 807f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate, very often 1 8082b99622eSMatthew G. Knepley 8092b99622eSMatthew G. Knepley Output Parameters: 810a5b23f4aSJose E. Roman . Tf - The basis function values and derivatives at face quadrature points 8112b99622eSMatthew G. Knepley 8122b99622eSMatthew G. Knepley Note: 813ef0bb6c7SMatthew G. Knepley $ T->T[0] = Bf[((f*Nq + q)*pdim + i)*Nc + c] is the value at point f,q for basis function i and component c 814ef0bb6c7SMatthew G. Knepley $ T->T[1] = Df[(((f*Nq + q)*pdim + i)*Nc + c)*dim + d] is the derivative value at point f,q for basis function i, component c, in direction d 815ef0bb6c7SMatthew G. Knepley $ T->T[2] = Hf[((((f*Nq + q)*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point f,q for basis function i, component c, in directions d and e 8162b99622eSMatthew G. Knepley 8172b99622eSMatthew G. Knepley Level: intermediate 8182b99622eSMatthew G. Knepley 819ef0bb6c7SMatthew G. Knepley .seealso: PetscFEGetCellTabulation(), PetscFECreateTabulation(), PetscTabulationDestroy() 8202b99622eSMatthew G. Knepley @*/ 821f9244615SMatthew G. Knepley PetscErrorCode PetscFEGetFaceTabulation(PetscFE fem, PetscInt k, PetscTabulation *Tf) 82220cf1dd8SToby Isaac { 82320cf1dd8SToby Isaac PetscFunctionBegin; 82420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 825064a246eSJacob Faibussowitsch PetscValidPointer(Tf, 3); 826ef0bb6c7SMatthew G. Knepley if (!fem->Tf) { 82720cf1dd8SToby Isaac const PetscReal xi0[3] = {-1., -1., -1.}; 82820cf1dd8SToby Isaac PetscReal v0[3], J[9], detJ; 82920cf1dd8SToby Isaac PetscQuadrature fq; 83020cf1dd8SToby Isaac PetscDualSpace sp; 83120cf1dd8SToby Isaac DM dm; 83220cf1dd8SToby Isaac const PetscInt *faces; 83320cf1dd8SToby Isaac PetscInt dim, numFaces, f, npoints, q; 83420cf1dd8SToby Isaac const PetscReal *points; 83520cf1dd8SToby Isaac PetscReal *facePoints; 83620cf1dd8SToby Isaac 8379566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &sp)); 8389566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(sp, &dm)); 8399566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 8409566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, 0, &numFaces)); 8419566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(dm, 0, &faces)); 8429566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(fem, &fq)); 84320cf1dd8SToby Isaac if (fq) { 8449566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(fq, NULL, NULL, &npoints, &points, NULL)); 8459566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numFaces*npoints*dim, &facePoints)); 84620cf1dd8SToby Isaac for (f = 0; f < numFaces; ++f) { 8479566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm, faces[f], NULL, v0, J, NULL, &detJ)); 84820cf1dd8SToby Isaac for (q = 0; q < npoints; ++q) CoordinatesRefToReal(dim, dim-1, xi0, v0, J, &points[q*(dim-1)], &facePoints[(f*npoints+q)*dim]); 84920cf1dd8SToby Isaac } 8509566063dSJacob Faibussowitsch PetscCall(PetscFECreateTabulation(fem, numFaces, npoints, facePoints, k, &fem->Tf)); 8519566063dSJacob Faibussowitsch PetscCall(PetscFree(facePoints)); 85220cf1dd8SToby Isaac } 85320cf1dd8SToby Isaac } 854*1dca8a05SBarry Smith PetscCheck(!fem->Tf || k <= fem->Tf->K,PetscObjectComm((PetscObject) fem), PETSC_ERR_ARG_OUTOFRANGE, "Requested %" PetscInt_FMT " derivatives, but only tabulated %" PetscInt_FMT, k, fem->Tf->K); 855ef0bb6c7SMatthew G. Knepley *Tf = fem->Tf; 85620cf1dd8SToby Isaac PetscFunctionReturn(0); 85720cf1dd8SToby Isaac } 85820cf1dd8SToby Isaac 8592b99622eSMatthew G. Knepley /*@C 860ef0bb6c7SMatthew G. Knepley PetscFEGetFaceCentroidTabulation - Returns the tabulation of the basis functions at the face centroid points 8612b99622eSMatthew G. Knepley 8622b99622eSMatthew G. Knepley Not collective 8632b99622eSMatthew G. Knepley 8642b99622eSMatthew G. Knepley Input Parameter: 8652b99622eSMatthew G. Knepley . fem - The PetscFE object 8662b99622eSMatthew G. Knepley 8672b99622eSMatthew G. Knepley Output Parameters: 868ef0bb6c7SMatthew G. Knepley . Tc - The basis function values at face centroid points 8692b99622eSMatthew G. Knepley 8702b99622eSMatthew G. Knepley Note: 871ef0bb6c7SMatthew G. Knepley $ T->T[0] = Bf[(f*pdim + i)*Nc + c] is the value at point f for basis function i and component c 8722b99622eSMatthew G. Knepley 8732b99622eSMatthew G. Knepley Level: intermediate 8742b99622eSMatthew G. Knepley 875ef0bb6c7SMatthew G. Knepley .seealso: PetscFEGetFaceTabulation(), PetscFEGetCellTabulation(), PetscFECreateTabulation(), PetscTabulationDestroy() 8762b99622eSMatthew G. Knepley @*/ 877ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEGetFaceCentroidTabulation(PetscFE fem, PetscTabulation *Tc) 87820cf1dd8SToby Isaac { 87920cf1dd8SToby Isaac PetscFunctionBegin; 88020cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 881ef0bb6c7SMatthew G. Knepley PetscValidPointer(Tc, 2); 882ef0bb6c7SMatthew G. Knepley if (!fem->Tc) { 88320cf1dd8SToby Isaac PetscDualSpace sp; 88420cf1dd8SToby Isaac DM dm; 88520cf1dd8SToby Isaac const PetscInt *cone; 88620cf1dd8SToby Isaac PetscReal *centroids; 88720cf1dd8SToby Isaac PetscInt dim, numFaces, f; 88820cf1dd8SToby Isaac 8899566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &sp)); 8909566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(sp, &dm)); 8919566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 8929566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, 0, &numFaces)); 8939566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(dm, 0, &cone)); 8949566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numFaces*dim, ¢roids)); 8959566063dSJacob Faibussowitsch for (f = 0; f < numFaces; ++f) PetscCall(DMPlexComputeCellGeometryFVM(dm, cone[f], NULL, ¢roids[f*dim], NULL)); 8969566063dSJacob Faibussowitsch PetscCall(PetscFECreateTabulation(fem, 1, numFaces, centroids, 0, &fem->Tc)); 8979566063dSJacob Faibussowitsch PetscCall(PetscFree(centroids)); 89820cf1dd8SToby Isaac } 899ef0bb6c7SMatthew G. Knepley *Tc = fem->Tc; 90020cf1dd8SToby Isaac PetscFunctionReturn(0); 90120cf1dd8SToby Isaac } 90220cf1dd8SToby Isaac 90320cf1dd8SToby Isaac /*@C 904ef0bb6c7SMatthew G. Knepley PetscFECreateTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided. 90520cf1dd8SToby Isaac 90620cf1dd8SToby Isaac Not collective 90720cf1dd8SToby Isaac 90820cf1dd8SToby Isaac Input Parameters: 90920cf1dd8SToby Isaac + fem - The PetscFE object 910ef0bb6c7SMatthew G. Knepley . nrepl - The number of replicas 911ef0bb6c7SMatthew G. Knepley . npoints - The number of tabulation points in a replica 912ef0bb6c7SMatthew G. Knepley . points - The tabulation point coordinates 913ef0bb6c7SMatthew G. Knepley - K - The number of derivatives calculated 91420cf1dd8SToby Isaac 915ef0bb6c7SMatthew G. Knepley Output Parameter: 916ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at tabulation points 91720cf1dd8SToby Isaac 91820cf1dd8SToby Isaac Note: 919ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 920ef0bb6c7SMatthew G. Knepley $ T->T[1] = D[((p*pdim + i)*Nc + c)*dim + d] is the derivative value at point p for basis function i, component c, in direction d 921ef0bb6c7SMatthew G. Knepley $ T->T[2] = H[(((p*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point p for basis function i, component c, in directions d and e 92220cf1dd8SToby Isaac 92320cf1dd8SToby Isaac Level: intermediate 92420cf1dd8SToby Isaac 925ef0bb6c7SMatthew G. Knepley .seealso: PetscFEGetCellTabulation(), PetscTabulationDestroy() 92620cf1dd8SToby Isaac @*/ 927ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFECreateTabulation(PetscFE fem, PetscInt nrepl, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation *T) 92820cf1dd8SToby Isaac { 92920cf1dd8SToby Isaac DM dm; 930ef0bb6c7SMatthew G. Knepley PetscDualSpace Q; 931ef0bb6c7SMatthew G. Knepley PetscInt Nb; /* Dimension of FE space P */ 932ef0bb6c7SMatthew G. Knepley PetscInt Nc; /* Field components */ 933ef0bb6c7SMatthew G. Knepley PetscInt cdim; /* Reference coordinate dimension */ 934ef0bb6c7SMatthew G. Knepley PetscInt k; 93520cf1dd8SToby Isaac 93620cf1dd8SToby Isaac PetscFunctionBegin; 937ef0bb6c7SMatthew G. Knepley if (!npoints || !fem->dualSpace || K < 0) { 938ef0bb6c7SMatthew G. Knepley *T = NULL; 93920cf1dd8SToby Isaac PetscFunctionReturn(0); 94020cf1dd8SToby Isaac } 94120cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 942dadcf809SJacob Faibussowitsch PetscValidRealPointer(points, 4); 94340a2aa30SMatthew G. Knepley PetscValidPointer(T, 6); 9449566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &Q)); 9459566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &dm)); 9469566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &cdim)); 9479566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &Nb)); 9489566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 9499566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(1, T)); 950ef0bb6c7SMatthew G. Knepley (*T)->K = !cdim ? 0 : K; 951ef0bb6c7SMatthew G. Knepley (*T)->Nr = nrepl; 952ef0bb6c7SMatthew G. Knepley (*T)->Np = npoints; 953ef0bb6c7SMatthew G. Knepley (*T)->Nb = Nb; 954ef0bb6c7SMatthew G. Knepley (*T)->Nc = Nc; 955ef0bb6c7SMatthew G. Knepley (*T)->cdim = cdim; 9569566063dSJacob Faibussowitsch PetscCall(PetscMalloc1((*T)->K+1, &(*T)->T)); 957ef0bb6c7SMatthew G. Knepley for (k = 0; k <= (*T)->K; ++k) { 9589566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(nrepl*npoints*Nb*Nc*PetscPowInt(cdim, k), &(*T)->T[k])); 95920cf1dd8SToby Isaac } 9609566063dSJacob Faibussowitsch PetscCall((*fem->ops->createtabulation)(fem, nrepl*npoints, points, K, *T)); 96120cf1dd8SToby Isaac PetscFunctionReturn(0); 96220cf1dd8SToby Isaac } 96320cf1dd8SToby Isaac 9642b99622eSMatthew G. Knepley /*@C 965ef0bb6c7SMatthew G. Knepley PetscFEComputeTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided. 9662b99622eSMatthew G. Knepley 9672b99622eSMatthew G. Knepley Not collective 9682b99622eSMatthew G. Knepley 9692b99622eSMatthew G. Knepley Input Parameters: 9702b99622eSMatthew G. Knepley + fem - The PetscFE object 9712b99622eSMatthew G. Knepley . npoints - The number of tabulation points 9722b99622eSMatthew G. Knepley . points - The tabulation point coordinates 973ef0bb6c7SMatthew G. Knepley . K - The number of derivatives calculated 974ef0bb6c7SMatthew G. Knepley - T - An existing tabulation object with enough allocated space 975ef0bb6c7SMatthew G. Knepley 976ef0bb6c7SMatthew G. Knepley Output Parameter: 977ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at tabulation points 9782b99622eSMatthew G. Knepley 9792b99622eSMatthew G. Knepley Note: 980ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 981ef0bb6c7SMatthew G. Knepley $ T->T[1] = D[((p*pdim + i)*Nc + c)*dim + d] is the derivative value at point p for basis function i, component c, in direction d 982ef0bb6c7SMatthew G. Knepley $ T->T[2] = H[(((p*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point p for basis function i, component c, in directions d and e 9832b99622eSMatthew G. Knepley 9842b99622eSMatthew G. Knepley Level: intermediate 9852b99622eSMatthew G. Knepley 986ef0bb6c7SMatthew G. Knepley .seealso: PetscFEGetCellTabulation(), PetscTabulationDestroy() 9872b99622eSMatthew G. Knepley @*/ 988ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEComputeTabulation(PetscFE fem, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation T) 989ef0bb6c7SMatthew G. Knepley { 990ef0bb6c7SMatthew G. Knepley PetscFunctionBeginHot; 991ef0bb6c7SMatthew G. Knepley if (!npoints || !fem->dualSpace || K < 0) PetscFunctionReturn(0); 992ef0bb6c7SMatthew G. Knepley PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 993dadcf809SJacob Faibussowitsch PetscValidRealPointer(points, 3); 994ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 5); 99576bd3646SJed Brown if (PetscDefined(USE_DEBUG)) { 99620cf1dd8SToby Isaac DM dm; 997ef0bb6c7SMatthew G. Knepley PetscDualSpace Q; 998ef0bb6c7SMatthew G. Knepley PetscInt Nb; /* Dimension of FE space P */ 999ef0bb6c7SMatthew G. Knepley PetscInt Nc; /* Field components */ 1000ef0bb6c7SMatthew G. Knepley PetscInt cdim; /* Reference coordinate dimension */ 1001ef0bb6c7SMatthew G. Knepley 10029566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &Q)); 10039566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &dm)); 10049566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &cdim)); 10059566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &Nb)); 10069566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 100763a3b9bcSJacob Faibussowitsch PetscCheck(T->K == (!cdim ? 0 : K),PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Tabulation K %" PetscInt_FMT " must match requested K %" PetscInt_FMT, T->K, !cdim ? 0 : K); 100863a3b9bcSJacob Faibussowitsch PetscCheck(T->Nb == Nb,PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Tabulation Nb %" PetscInt_FMT " must match requested Nb %" PetscInt_FMT, T->Nb, Nb); 100963a3b9bcSJacob Faibussowitsch PetscCheck(T->Nc == Nc,PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Tabulation Nc %" PetscInt_FMT " must match requested Nc %" PetscInt_FMT, T->Nc, Nc); 101063a3b9bcSJacob Faibussowitsch PetscCheck(T->cdim == cdim,PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Tabulation cdim %" PetscInt_FMT " must match requested cdim %" PetscInt_FMT, T->cdim, cdim); 1011ef0bb6c7SMatthew G. Knepley } 1012ef0bb6c7SMatthew G. Knepley T->Nr = 1; 1013ef0bb6c7SMatthew G. Knepley T->Np = npoints; 10149566063dSJacob Faibussowitsch PetscCall((*fem->ops->createtabulation)(fem, npoints, points, K, T)); 1015ef0bb6c7SMatthew G. Knepley PetscFunctionReturn(0); 1016ef0bb6c7SMatthew G. Knepley } 1017ef0bb6c7SMatthew G. Knepley 1018ef0bb6c7SMatthew G. Knepley /*@C 1019ef0bb6c7SMatthew G. Knepley PetscTabulationDestroy - Frees memory from the associated tabulation. 1020ef0bb6c7SMatthew G. Knepley 1021ef0bb6c7SMatthew G. Knepley Not collective 1022ef0bb6c7SMatthew G. Knepley 1023ef0bb6c7SMatthew G. Knepley Input Parameter: 1024ef0bb6c7SMatthew G. Knepley . T - The tabulation 1025ef0bb6c7SMatthew G. Knepley 1026ef0bb6c7SMatthew G. Knepley Level: intermediate 1027ef0bb6c7SMatthew G. Knepley 1028ef0bb6c7SMatthew G. Knepley .seealso: PetscFECreateTabulation(), PetscFEGetCellTabulation() 1029ef0bb6c7SMatthew G. Knepley @*/ 1030ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscTabulationDestroy(PetscTabulation *T) 1031ef0bb6c7SMatthew G. Knepley { 1032ef0bb6c7SMatthew G. Knepley PetscInt k; 103320cf1dd8SToby Isaac 103420cf1dd8SToby Isaac PetscFunctionBegin; 1035ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 1); 1036ef0bb6c7SMatthew G. Knepley if (!T || !(*T)) PetscFunctionReturn(0); 10379566063dSJacob Faibussowitsch for (k = 0; k <= (*T)->K; ++k) PetscCall(PetscFree((*T)->T[k])); 10389566063dSJacob Faibussowitsch PetscCall(PetscFree((*T)->T)); 10399566063dSJacob Faibussowitsch PetscCall(PetscFree(*T)); 1040ef0bb6c7SMatthew G. Knepley *T = NULL; 104120cf1dd8SToby Isaac PetscFunctionReturn(0); 104220cf1dd8SToby Isaac } 104320cf1dd8SToby Isaac 104420cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode PetscFECreatePointTrace(PetscFE fe, PetscInt refPoint, PetscFE *trFE) 104520cf1dd8SToby Isaac { 104620cf1dd8SToby Isaac PetscSpace bsp, bsubsp; 104720cf1dd8SToby Isaac PetscDualSpace dsp, dsubsp; 104820cf1dd8SToby Isaac PetscInt dim, depth, numComp, i, j, coneSize, order; 104920cf1dd8SToby Isaac PetscFEType type; 105020cf1dd8SToby Isaac DM dm; 105120cf1dd8SToby Isaac DMLabel label; 105220cf1dd8SToby Isaac PetscReal *xi, *v, *J, detJ; 1053db11e2ebSMatthew G. Knepley const char *name; 105420cf1dd8SToby Isaac PetscQuadrature origin, fullQuad, subQuad; 105520cf1dd8SToby Isaac 105620cf1dd8SToby Isaac PetscFunctionBegin; 105720cf1dd8SToby Isaac PetscValidHeaderSpecific(fe,PETSCFE_CLASSID,1); 105820cf1dd8SToby Isaac PetscValidPointer(trFE,3); 10599566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe,&bsp)); 10609566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe,&dsp)); 10619566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp,&dm)); 10629566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm,&dim)); 10639566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthLabel(dm,&label)); 10649566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(label,refPoint,&depth)); 10659566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(depth,&xi)); 10669566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dim,&v)); 10679566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dim*dim,&J)); 106820cf1dd8SToby Isaac for (i = 0; i < depth; i++) xi[i] = 0.; 10699566063dSJacob Faibussowitsch PetscCall(PetscQuadratureCreate(PETSC_COMM_SELF,&origin)); 10709566063dSJacob Faibussowitsch PetscCall(PetscQuadratureSetData(origin,depth,0,1,xi,NULL)); 10719566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm,refPoint,origin,v,J,NULL,&detJ)); 107220cf1dd8SToby Isaac /* CellGeometryFEM computes the expanded Jacobian, we want the true jacobian */ 107320cf1dd8SToby Isaac for (i = 1; i < dim; i++) { 107420cf1dd8SToby Isaac for (j = 0; j < depth; j++) { 107520cf1dd8SToby Isaac J[i * depth + j] = J[i * dim + j]; 107620cf1dd8SToby Isaac } 107720cf1dd8SToby Isaac } 10789566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&origin)); 10799566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetPointSubspace(dsp,refPoint,&dsubsp)); 10809566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreateSubspace(bsp,dsubsp,v,J,NULL,NULL,PETSC_OWN_POINTER,&bsubsp)); 10819566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetUp(bsubsp)); 10829566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject)fe),trFE)); 10839566063dSJacob Faibussowitsch PetscCall(PetscFEGetType(fe,&type)); 10849566063dSJacob Faibussowitsch PetscCall(PetscFESetType(*trFE,type)); 10859566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe,&numComp)); 10869566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(*trFE,numComp)); 10879566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(*trFE,bsubsp)); 10889566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(*trFE,dsubsp)); 10899566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject) fe, &name)); 10909566063dSJacob Faibussowitsch if (name) PetscCall(PetscFESetName(*trFE, name)); 10919566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe,&fullQuad)); 10929566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetOrder(fullQuad,&order)); 10939566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm,refPoint,&coneSize)); 109420cf1dd8SToby Isaac if (coneSize == 2 * depth) { 10959566063dSJacob Faibussowitsch PetscCall(PetscDTGaussTensorQuadrature(depth,1,(order + 1)/2,-1.,1.,&subQuad)); 109620cf1dd8SToby Isaac } else { 10979566063dSJacob Faibussowitsch PetscCall(PetscDTStroudConicalQuadrature(depth,1,(order + 1)/2,-1.,1.,&subQuad)); 109820cf1dd8SToby Isaac } 10999566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(*trFE,subQuad)); 11009566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(*trFE)); 11019566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&subQuad)); 11029566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&bsubsp)); 110320cf1dd8SToby Isaac PetscFunctionReturn(0); 110420cf1dd8SToby Isaac } 110520cf1dd8SToby Isaac 110620cf1dd8SToby Isaac PetscErrorCode PetscFECreateHeightTrace(PetscFE fe, PetscInt height, PetscFE *trFE) 110720cf1dd8SToby Isaac { 110820cf1dd8SToby Isaac PetscInt hStart, hEnd; 110920cf1dd8SToby Isaac PetscDualSpace dsp; 111020cf1dd8SToby Isaac DM dm; 111120cf1dd8SToby Isaac 111220cf1dd8SToby Isaac PetscFunctionBegin; 111320cf1dd8SToby Isaac PetscValidHeaderSpecific(fe,PETSCFE_CLASSID,1); 111420cf1dd8SToby Isaac PetscValidPointer(trFE,3); 111520cf1dd8SToby Isaac *trFE = NULL; 11169566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe,&dsp)); 11179566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp,&dm)); 11189566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(dm,height,&hStart,&hEnd)); 111920cf1dd8SToby Isaac if (hEnd <= hStart) PetscFunctionReturn(0); 11209566063dSJacob Faibussowitsch PetscCall(PetscFECreatePointTrace(fe,hStart,trFE)); 112120cf1dd8SToby Isaac PetscFunctionReturn(0); 112220cf1dd8SToby Isaac } 112320cf1dd8SToby Isaac 112420cf1dd8SToby Isaac /*@ 112520cf1dd8SToby Isaac PetscFEGetDimension - Get the dimension of the finite element space on a cell 112620cf1dd8SToby Isaac 112720cf1dd8SToby Isaac Not collective 112820cf1dd8SToby Isaac 112920cf1dd8SToby Isaac Input Parameter: 113020cf1dd8SToby Isaac . fe - The PetscFE 113120cf1dd8SToby Isaac 113220cf1dd8SToby Isaac Output Parameter: 113320cf1dd8SToby Isaac . dim - The dimension 113420cf1dd8SToby Isaac 113520cf1dd8SToby Isaac Level: intermediate 113620cf1dd8SToby Isaac 113720cf1dd8SToby Isaac .seealso: PetscFECreate(), PetscSpaceGetDimension(), PetscDualSpaceGetDimension() 113820cf1dd8SToby Isaac @*/ 113920cf1dd8SToby Isaac PetscErrorCode PetscFEGetDimension(PetscFE fem, PetscInt *dim) 114020cf1dd8SToby Isaac { 114120cf1dd8SToby Isaac PetscFunctionBegin; 114220cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 1143dadcf809SJacob Faibussowitsch PetscValidIntPointer(dim, 2); 11449566063dSJacob Faibussowitsch if (fem->ops->getdimension) PetscCall((*fem->ops->getdimension)(fem, dim)); 114520cf1dd8SToby Isaac PetscFunctionReturn(0); 114620cf1dd8SToby Isaac } 114720cf1dd8SToby Isaac 11484bee2e38SMatthew G. Knepley /*@C 11494bee2e38SMatthew G. Knepley PetscFEPushforward - Map the reference element function to real space 11504bee2e38SMatthew G. Knepley 11514bee2e38SMatthew G. Knepley Input Parameters: 11524bee2e38SMatthew G. Knepley + fe - The PetscFE 11534bee2e38SMatthew G. Knepley . fegeom - The cell geometry 11544bee2e38SMatthew G. Knepley . Nv - The number of function values 11554bee2e38SMatthew G. Knepley - vals - The function values 11564bee2e38SMatthew G. Knepley 11574bee2e38SMatthew G. Knepley Output Parameter: 11584bee2e38SMatthew G. Knepley . vals - The transformed function values 11594bee2e38SMatthew G. Knepley 11604bee2e38SMatthew G. Knepley Level: advanced 11614bee2e38SMatthew G. Knepley 11624bee2e38SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforward(). 11634bee2e38SMatthew G. Knepley 1164f9244615SMatthew G. Knepley Note: This only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 11652edcad52SToby Isaac 11664bee2e38SMatthew G. Knepley .seealso: PetscDualSpacePushforward() 11674bee2e38SMatthew G. Knepley @*/ 11682edcad52SToby Isaac PetscErrorCode PetscFEPushforward(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 11694bee2e38SMatthew G. Knepley { 11702ae266adSMatthew G. Knepley PetscFunctionBeginHot; 11719566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforward(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 11724bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 11734bee2e38SMatthew G. Knepley } 11744bee2e38SMatthew G. Knepley 11754bee2e38SMatthew G. Knepley /*@C 11764bee2e38SMatthew G. Knepley PetscFEPushforwardGradient - Map the reference element function gradient to real space 11774bee2e38SMatthew G. Knepley 11784bee2e38SMatthew G. Knepley Input Parameters: 11794bee2e38SMatthew G. Knepley + fe - The PetscFE 11804bee2e38SMatthew G. Knepley . fegeom - The cell geometry 11814bee2e38SMatthew G. Knepley . Nv - The number of function gradient values 11824bee2e38SMatthew G. Knepley - vals - The function gradient values 11834bee2e38SMatthew G. Knepley 11844bee2e38SMatthew G. Knepley Output Parameter: 11854bee2e38SMatthew G. Knepley . vals - The transformed function gradient values 11864bee2e38SMatthew G. Knepley 11874bee2e38SMatthew G. Knepley Level: advanced 11884bee2e38SMatthew G. Knepley 11894bee2e38SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforwardGradient(). 11904bee2e38SMatthew G. Knepley 1191f9244615SMatthew G. Knepley Note: This only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 11922edcad52SToby Isaac 11934bee2e38SMatthew G. Knepley .seealso: PetscFEPushforward(), PetscDualSpacePushforwardGradient(), PetscDualSpacePushforward() 11944bee2e38SMatthew G. Knepley @*/ 11952edcad52SToby Isaac PetscErrorCode PetscFEPushforwardGradient(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 11964bee2e38SMatthew G. Knepley { 11972ae266adSMatthew G. Knepley PetscFunctionBeginHot; 11989566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforwardGradient(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 11994bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 12004bee2e38SMatthew G. Knepley } 12014bee2e38SMatthew G. Knepley 1202f9244615SMatthew G. Knepley /*@C 1203f9244615SMatthew G. Knepley PetscFEPushforwardHessian - Map the reference element function Hessian to real space 1204f9244615SMatthew G. Knepley 1205f9244615SMatthew G. Knepley Input Parameters: 1206f9244615SMatthew G. Knepley + fe - The PetscFE 1207f9244615SMatthew G. Knepley . fegeom - The cell geometry 1208f9244615SMatthew G. Knepley . Nv - The number of function Hessian values 1209f9244615SMatthew G. Knepley - vals - The function Hessian values 1210f9244615SMatthew G. Knepley 1211f9244615SMatthew G. Knepley Output Parameter: 1212f9244615SMatthew G. Knepley . vals - The transformed function Hessian values 1213f9244615SMatthew G. Knepley 1214f9244615SMatthew G. Knepley Level: advanced 1215f9244615SMatthew G. Knepley 1216f9244615SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforwardHessian(). 1217f9244615SMatthew G. Knepley 1218f9244615SMatthew G. Knepley Note: This only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 1219f9244615SMatthew G. Knepley 1220f9244615SMatthew G. Knepley .seealso: PetscFEPushforward(), PetscDualSpacePushforwardHessian(), PetscDualSpacePushforward() 1221f9244615SMatthew G. Knepley @*/ 1222f9244615SMatthew G. Knepley PetscErrorCode PetscFEPushforwardHessian(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 1223f9244615SMatthew G. Knepley { 1224f9244615SMatthew G. Knepley PetscFunctionBeginHot; 12259566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforwardHessian(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 1226f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1227f9244615SMatthew G. Knepley } 1228f9244615SMatthew G. Knepley 122920cf1dd8SToby Isaac /* 123020cf1dd8SToby Isaac Purpose: Compute element vector for chunk of elements 123120cf1dd8SToby Isaac 123220cf1dd8SToby Isaac Input: 123320cf1dd8SToby Isaac Sizes: 123420cf1dd8SToby Isaac Ne: number of elements 123520cf1dd8SToby Isaac Nf: number of fields 123620cf1dd8SToby Isaac PetscFE 123720cf1dd8SToby Isaac dim: spatial dimension 123820cf1dd8SToby Isaac Nb: number of basis functions 123920cf1dd8SToby Isaac Nc: number of field components 124020cf1dd8SToby Isaac PetscQuadrature 124120cf1dd8SToby Isaac Nq: number of quadrature points 124220cf1dd8SToby Isaac 124320cf1dd8SToby Isaac Geometry: 124420cf1dd8SToby Isaac PetscFEGeom[Ne] possibly *Nq 124520cf1dd8SToby Isaac PetscReal v0s[dim] 124620cf1dd8SToby Isaac PetscReal n[dim] 124720cf1dd8SToby Isaac PetscReal jacobians[dim*dim] 124820cf1dd8SToby Isaac PetscReal jacobianInverses[dim*dim] 124920cf1dd8SToby Isaac PetscReal jacobianDeterminants 125020cf1dd8SToby Isaac FEM: 125120cf1dd8SToby Isaac PetscFE 125220cf1dd8SToby Isaac PetscQuadrature 125320cf1dd8SToby Isaac PetscReal quadPoints[Nq*dim] 125420cf1dd8SToby Isaac PetscReal quadWeights[Nq] 125520cf1dd8SToby Isaac PetscReal basis[Nq*Nb*Nc] 125620cf1dd8SToby Isaac PetscReal basisDer[Nq*Nb*Nc*dim] 125720cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 125820cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 125920cf1dd8SToby Isaac 126020cf1dd8SToby Isaac Problem: 126120cf1dd8SToby Isaac PetscInt f: the active field 126220cf1dd8SToby Isaac f0, f1 126320cf1dd8SToby Isaac 126420cf1dd8SToby Isaac Work Space: 126520cf1dd8SToby Isaac PetscFE 126620cf1dd8SToby Isaac PetscScalar f0[Nq*dim]; 126720cf1dd8SToby Isaac PetscScalar f1[Nq*dim*dim]; 126820cf1dd8SToby Isaac PetscScalar u[Nc]; 126920cf1dd8SToby Isaac PetscScalar gradU[Nc*dim]; 127020cf1dd8SToby Isaac PetscReal x[dim]; 127120cf1dd8SToby Isaac PetscScalar realSpaceDer[dim]; 127220cf1dd8SToby Isaac 127320cf1dd8SToby Isaac Purpose: Compute element vector for N_cb batches of elements 127420cf1dd8SToby Isaac 127520cf1dd8SToby Isaac Input: 127620cf1dd8SToby Isaac Sizes: 127720cf1dd8SToby Isaac N_cb: Number of serial cell batches 127820cf1dd8SToby Isaac 127920cf1dd8SToby Isaac Geometry: 128020cf1dd8SToby Isaac PetscReal v0s[Ne*dim] 128120cf1dd8SToby Isaac PetscReal jacobians[Ne*dim*dim] possibly *Nq 128220cf1dd8SToby Isaac PetscReal jacobianInverses[Ne*dim*dim] possibly *Nq 128320cf1dd8SToby Isaac PetscReal jacobianDeterminants[Ne] possibly *Nq 128420cf1dd8SToby Isaac FEM: 128520cf1dd8SToby Isaac static PetscReal quadPoints[Nq*dim] 128620cf1dd8SToby Isaac static PetscReal quadWeights[Nq] 128720cf1dd8SToby Isaac static PetscReal basis[Nq*Nb*Nc] 128820cf1dd8SToby Isaac static PetscReal basisDer[Nq*Nb*Nc*dim] 128920cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 129020cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 129120cf1dd8SToby Isaac 129220cf1dd8SToby Isaac ex62.c: 129320cf1dd8SToby Isaac PetscErrorCode PetscFEIntegrateResidualBatch(PetscInt Ne, PetscInt numFields, PetscInt field, PetscQuadrature quad[], const PetscScalar coefficients[], 129420cf1dd8SToby Isaac const PetscReal v0s[], const PetscReal jacobians[], const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], 129520cf1dd8SToby Isaac void (*f0_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f0[]), 129620cf1dd8SToby Isaac void (*f1_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f1[]), PetscScalar elemVec[]) 129720cf1dd8SToby Isaac 129820cf1dd8SToby Isaac ex52.c: 129920cf1dd8SToby Isaac PetscErrorCode IntegrateLaplacianBatchCPU(PetscInt Ne, PetscInt Nb, const PetscScalar coefficients[], const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscInt Nq, const PetscReal quadPoints[], const PetscReal quadWeights[], const PetscReal basisTabulation[], const PetscReal basisDerTabulation[], PetscScalar elemVec[], AppCtx *user) 130020cf1dd8SToby Isaac PetscErrorCode IntegrateElasticityBatchCPU(PetscInt Ne, PetscInt Nb, PetscInt Ncomp, const PetscScalar coefficients[], const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscInt Nq, const PetscReal quadPoints[], const PetscReal quadWeights[], const PetscReal basisTabulation[], const PetscReal basisDerTabulation[], PetscScalar elemVec[], AppCtx *user) 130120cf1dd8SToby Isaac 130220cf1dd8SToby Isaac ex52_integrateElement.cu 130320cf1dd8SToby Isaac __global__ void integrateElementQuadrature(int N_cb, realType *coefficients, realType *jacobianInverses, realType *jacobianDeterminants, realType *elemVec) 130420cf1dd8SToby Isaac 130520cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt Nbl, const PetscScalar coefficients[], 130620cf1dd8SToby Isaac const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[], 130720cf1dd8SToby Isaac PetscLogEvent event, PetscInt debug, PetscInt pde_op) 130820cf1dd8SToby Isaac 130920cf1dd8SToby Isaac ex52_integrateElementOpenCL.c: 131020cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt N_bl, const PetscScalar coefficients[], 131120cf1dd8SToby Isaac const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[], 131220cf1dd8SToby Isaac PetscLogEvent event, PetscInt debug, PetscInt pde_op) 131320cf1dd8SToby Isaac 131420cf1dd8SToby Isaac __kernel void integrateElementQuadrature(int N_cb, __global float *coefficients, __global float *jacobianInverses, __global float *jacobianDeterminants, __global float *elemVec) 131520cf1dd8SToby Isaac */ 131620cf1dd8SToby Isaac 131720cf1dd8SToby Isaac /*@C 131820cf1dd8SToby Isaac PetscFEIntegrate - Produce the integral for the given field for a chunk of elements by quadrature integration 131920cf1dd8SToby Isaac 132020cf1dd8SToby Isaac Not collective 132120cf1dd8SToby Isaac 132220cf1dd8SToby Isaac Input Parameters: 1323360cf244SMatthew G. Knepley + prob - The PetscDS specifying the discretizations and continuum functions 132420cf1dd8SToby Isaac . field - The field being integrated 132520cf1dd8SToby Isaac . Ne - The number of elements in the chunk 132620cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 132720cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 132820cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 132920cf1dd8SToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 133020cf1dd8SToby Isaac 13317a7aea1fSJed Brown Output Parameter: 133220cf1dd8SToby Isaac . integral - the integral for this field 133320cf1dd8SToby Isaac 13342b99622eSMatthew G. Knepley Level: intermediate 133520cf1dd8SToby Isaac 133620cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual() 133720cf1dd8SToby Isaac @*/ 13384bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrate(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom, 133920cf1dd8SToby Isaac const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 134020cf1dd8SToby Isaac { 13414bee2e38SMatthew G. Knepley PetscFE fe; 134220cf1dd8SToby Isaac 134320cf1dd8SToby Isaac PetscFunctionBegin; 13444bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13459566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *) &fe)); 13469566063dSJacob Faibussowitsch if (fe->ops->integrate) PetscCall((*fe->ops->integrate)(prob, field, Ne, cgeom, coefficients, probAux, coefficientsAux, integral)); 134720cf1dd8SToby Isaac PetscFunctionReturn(0); 134820cf1dd8SToby Isaac } 134920cf1dd8SToby Isaac 135020cf1dd8SToby Isaac /*@C 1351afe6d6adSToby Isaac PetscFEIntegrateBd - Produce the integral for the given field for a chunk of elements by quadrature integration 1352afe6d6adSToby Isaac 1353afe6d6adSToby Isaac Not collective 1354afe6d6adSToby Isaac 1355afe6d6adSToby Isaac Input Parameters: 1356360cf244SMatthew G. Knepley + prob - The PetscDS specifying the discretizations and continuum functions 1357afe6d6adSToby Isaac . field - The field being integrated 1358afe6d6adSToby Isaac . obj_func - The function to be integrated 1359afe6d6adSToby Isaac . Ne - The number of elements in the chunk 1360afe6d6adSToby Isaac . fgeom - The face geometry for each face in the chunk 1361afe6d6adSToby Isaac . coefficients - The array of FEM basis coefficients for the elements 1362afe6d6adSToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 1363afe6d6adSToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 1364afe6d6adSToby Isaac 13657a7aea1fSJed Brown Output Parameter: 1366afe6d6adSToby Isaac . integral - the integral for this field 1367afe6d6adSToby Isaac 13682b99622eSMatthew G. Knepley Level: intermediate 1369afe6d6adSToby Isaac 1370afe6d6adSToby Isaac .seealso: PetscFEIntegrateResidual() 1371afe6d6adSToby Isaac @*/ 13724bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBd(PetscDS prob, PetscInt field, 1373afe6d6adSToby Isaac void (*obj_func)(PetscInt, PetscInt, PetscInt, 1374afe6d6adSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 1375afe6d6adSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 1376afe6d6adSToby Isaac PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]), 1377afe6d6adSToby Isaac PetscInt Ne, PetscFEGeom *geom, const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 1378afe6d6adSToby Isaac { 13794bee2e38SMatthew G. Knepley PetscFE fe; 1380afe6d6adSToby Isaac 1381afe6d6adSToby Isaac PetscFunctionBegin; 13824bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13839566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *) &fe)); 13849566063dSJacob Faibussowitsch if (fe->ops->integratebd) PetscCall((*fe->ops->integratebd)(prob, field, obj_func, Ne, geom, coefficients, probAux, coefficientsAux, integral)); 1385afe6d6adSToby Isaac PetscFunctionReturn(0); 1386afe6d6adSToby Isaac } 1387afe6d6adSToby Isaac 1388afe6d6adSToby Isaac /*@C 138920cf1dd8SToby Isaac PetscFEIntegrateResidual - Produce the element residual vector for a chunk of elements by quadrature integration 139020cf1dd8SToby Isaac 139120cf1dd8SToby Isaac Not collective 139220cf1dd8SToby Isaac 139320cf1dd8SToby Isaac Input Parameters: 13946528b96dSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 13956528b96dSMatthew G. Knepley . key - The (label+value, field) being integrated 139620cf1dd8SToby Isaac . Ne - The number of elements in the chunk 139720cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 139820cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 139920cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 140020cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 140120cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 140220cf1dd8SToby Isaac - t - The time 140320cf1dd8SToby Isaac 14047a7aea1fSJed Brown Output Parameter: 140520cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 140620cf1dd8SToby Isaac 140720cf1dd8SToby Isaac Note: 140820cf1dd8SToby Isaac $ Loop over batch of elements (e): 140920cf1dd8SToby Isaac $ Loop over quadrature points (q): 141020cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) and x_q 141120cf1dd8SToby Isaac $ Call f_0 and f_1 141220cf1dd8SToby Isaac $ Loop over element vector entries (f,fc --> i): 141320cf1dd8SToby Isaac $ elemVec[i] += \psi^{fc}_f(q) f0_{fc}(u, \nabla u) + \nabla\psi^{fc}_f(q) \cdot f1_{fc,df}(u, \nabla u) 141420cf1dd8SToby Isaac 14152b99622eSMatthew G. Knepley Level: intermediate 141620cf1dd8SToby Isaac 141720cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual() 141820cf1dd8SToby Isaac @*/ 141906ad1575SMatthew G. Knepley PetscErrorCode PetscFEIntegrateResidual(PetscDS ds, PetscFormKey key, PetscInt Ne, PetscFEGeom *cgeom, 142020cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 142120cf1dd8SToby Isaac { 14224bee2e38SMatthew G. Knepley PetscFE fe; 142320cf1dd8SToby Isaac 14246528b96dSMatthew G. Knepley PetscFunctionBeginHot; 14256528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14269566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field, (PetscObject *) &fe)); 14279566063dSJacob Faibussowitsch if (fe->ops->integrateresidual) PetscCall((*fe->ops->integrateresidual)(ds, key, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 142820cf1dd8SToby Isaac PetscFunctionReturn(0); 142920cf1dd8SToby Isaac } 143020cf1dd8SToby Isaac 143120cf1dd8SToby Isaac /*@C 143220cf1dd8SToby Isaac PetscFEIntegrateBdResidual - Produce the element residual vector for a chunk of elements by quadrature integration over a boundary 143320cf1dd8SToby Isaac 143420cf1dd8SToby Isaac Not collective 143520cf1dd8SToby Isaac 143620cf1dd8SToby Isaac Input Parameters: 143706d8a0d3SMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 143845480ffeSMatthew G. Knepley . wf - The PetscWeakForm object holding the pointwise functions 143906d8a0d3SMatthew G. Knepley . key - The (label+value, field) being integrated 144020cf1dd8SToby Isaac . Ne - The number of elements in the chunk 144120cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 144220cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 144320cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 144420cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 144520cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 144620cf1dd8SToby Isaac - t - The time 144720cf1dd8SToby Isaac 14487a7aea1fSJed Brown Output Parameter: 144920cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 145020cf1dd8SToby Isaac 14512b99622eSMatthew G. Knepley Level: intermediate 145220cf1dd8SToby Isaac 145320cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual() 145420cf1dd8SToby Isaac @*/ 145506ad1575SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdResidual(PetscDS ds, PetscWeakForm wf, PetscFormKey key, PetscInt Ne, PetscFEGeom *fgeom, 145620cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 145720cf1dd8SToby Isaac { 14584bee2e38SMatthew G. Knepley PetscFE fe; 145920cf1dd8SToby Isaac 146020cf1dd8SToby Isaac PetscFunctionBegin; 146106d8a0d3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14629566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field, (PetscObject *) &fe)); 14639566063dSJacob Faibussowitsch if (fe->ops->integratebdresidual) PetscCall((*fe->ops->integratebdresidual)(ds, wf, key, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 146420cf1dd8SToby Isaac PetscFunctionReturn(0); 146520cf1dd8SToby Isaac } 146620cf1dd8SToby Isaac 146720cf1dd8SToby Isaac /*@C 146827f02ce8SMatthew G. Knepley PetscFEIntegrateHybridResidual - Produce the element residual vector for a chunk of hybrid element faces by quadrature integration 146927f02ce8SMatthew G. Knepley 147027f02ce8SMatthew G. Knepley Not collective 147127f02ce8SMatthew G. Knepley 147227f02ce8SMatthew G. Knepley Input Parameters: 147327f02ce8SMatthew G. Knepley + prob - The PetscDS specifying the discretizations and continuum functions 14746528b96dSMatthew G. Knepley . key - The (label+value, field) being integrated 1475c2b7495fSMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 147627f02ce8SMatthew G. Knepley . Ne - The number of elements in the chunk 147727f02ce8SMatthew G. Knepley . fgeom - The face geometry for each cell in the chunk 147827f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements 147927f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements 148027f02ce8SMatthew G. Knepley . probAux - The PetscDS specifying the auxiliary discretizations 148127f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 148227f02ce8SMatthew G. Knepley - t - The time 148327f02ce8SMatthew G. Knepley 148427f02ce8SMatthew G. Knepley Output Parameter 148527f02ce8SMatthew G. Knepley . elemVec - the element residual vectors from each element 148627f02ce8SMatthew G. Knepley 148727f02ce8SMatthew G. Knepley Level: developer 148827f02ce8SMatthew G. Knepley 148927f02ce8SMatthew G. Knepley .seealso: PetscFEIntegrateResidual() 149027f02ce8SMatthew G. Knepley @*/ 1491c2b7495fSMatthew G. Knepley PetscErrorCode PetscFEIntegrateHybridResidual(PetscDS prob, PetscFormKey key, PetscInt s, PetscInt Ne, PetscFEGeom *fgeom, 149227f02ce8SMatthew G. Knepley const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 149327f02ce8SMatthew G. Knepley { 149427f02ce8SMatthew G. Knepley PetscFE fe; 149527f02ce8SMatthew G. Knepley 149627f02ce8SMatthew G. Knepley PetscFunctionBegin; 149727f02ce8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 14989566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, key.field, (PetscObject *) &fe)); 14999566063dSJacob Faibussowitsch if (fe->ops->integratehybridresidual) PetscCall((*fe->ops->integratehybridresidual)(prob, key, s, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 150027f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 150127f02ce8SMatthew G. Knepley } 150227f02ce8SMatthew G. Knepley 150327f02ce8SMatthew G. Knepley /*@C 150420cf1dd8SToby Isaac PetscFEIntegrateJacobian - Produce the element Jacobian for a chunk of elements by quadrature integration 150520cf1dd8SToby Isaac 150620cf1dd8SToby Isaac Not collective 150720cf1dd8SToby Isaac 150820cf1dd8SToby Isaac Input Parameters: 15096528b96dSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 151020cf1dd8SToby Isaac . jtype - The type of matrix pointwise functions that should be used 15116528b96dSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 15125fedec97SMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 151320cf1dd8SToby Isaac . Ne - The number of elements in the chunk 151420cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 151520cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 151620cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 151720cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 151820cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 151920cf1dd8SToby Isaac . t - The time 152020cf1dd8SToby Isaac - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 152120cf1dd8SToby Isaac 15227a7aea1fSJed Brown Output Parameter: 152320cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 152420cf1dd8SToby Isaac 152520cf1dd8SToby Isaac Note: 152620cf1dd8SToby Isaac $ Loop over batch of elements (e): 152720cf1dd8SToby Isaac $ Loop over element matrix entries (f,fc,g,gc --> i,j): 152820cf1dd8SToby Isaac $ Loop over quadrature points (q): 152920cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 153020cf1dd8SToby Isaac $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 153120cf1dd8SToby Isaac $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 153220cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 153320cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 15342b99622eSMatthew G. Knepley Level: intermediate 153520cf1dd8SToby Isaac 153620cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual() 153720cf1dd8SToby Isaac @*/ 153806ad1575SMatthew G. Knepley PetscErrorCode PetscFEIntegrateJacobian(PetscDS ds, PetscFEJacobianType jtype, PetscFormKey key, PetscInt Ne, PetscFEGeom *cgeom, 153920cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 154020cf1dd8SToby Isaac { 15414bee2e38SMatthew G. Knepley PetscFE fe; 15426528b96dSMatthew G. Knepley PetscInt Nf; 154320cf1dd8SToby Isaac 154420cf1dd8SToby Isaac PetscFunctionBegin; 15456528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 15469566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 15479566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *) &fe)); 15489566063dSJacob Faibussowitsch if (fe->ops->integratejacobian) PetscCall((*fe->ops->integratejacobian)(ds, jtype, key, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 154920cf1dd8SToby Isaac PetscFunctionReturn(0); 155020cf1dd8SToby Isaac } 155120cf1dd8SToby Isaac 155220cf1dd8SToby Isaac /*@C 155320cf1dd8SToby Isaac PetscFEIntegrateBdJacobian - Produce the boundary element Jacobian for a chunk of elements by quadrature integration 155420cf1dd8SToby Isaac 155520cf1dd8SToby Isaac Not collective 155620cf1dd8SToby Isaac 155720cf1dd8SToby Isaac Input Parameters: 155845480ffeSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 155945480ffeSMatthew G. Knepley . wf - The PetscWeakForm holding the pointwise functions 156045480ffeSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 156120cf1dd8SToby Isaac . Ne - The number of elements in the chunk 156220cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 156320cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 156420cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 156520cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 156620cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 156720cf1dd8SToby Isaac . t - The time 156820cf1dd8SToby Isaac - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 156920cf1dd8SToby Isaac 15707a7aea1fSJed Brown Output Parameter: 157120cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 157220cf1dd8SToby Isaac 157320cf1dd8SToby Isaac Note: 157420cf1dd8SToby Isaac $ Loop over batch of elements (e): 157520cf1dd8SToby Isaac $ Loop over element matrix entries (f,fc,g,gc --> i,j): 157620cf1dd8SToby Isaac $ Loop over quadrature points (q): 157720cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 157820cf1dd8SToby Isaac $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 157920cf1dd8SToby Isaac $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 158020cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 158120cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 15822b99622eSMatthew G. Knepley Level: intermediate 158320cf1dd8SToby Isaac 158420cf1dd8SToby Isaac .seealso: PetscFEIntegrateJacobian(), PetscFEIntegrateResidual() 158520cf1dd8SToby Isaac @*/ 158606ad1575SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdJacobian(PetscDS ds, PetscWeakForm wf, PetscFormKey key, PetscInt Ne, PetscFEGeom *fgeom, 158720cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 158820cf1dd8SToby Isaac { 15894bee2e38SMatthew G. Knepley PetscFE fe; 159045480ffeSMatthew G. Knepley PetscInt Nf; 159120cf1dd8SToby Isaac 159220cf1dd8SToby Isaac PetscFunctionBegin; 159345480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 15949566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 15959566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *) &fe)); 15969566063dSJacob Faibussowitsch if (fe->ops->integratebdjacobian) PetscCall((*fe->ops->integratebdjacobian)(ds, wf, key, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 159720cf1dd8SToby Isaac PetscFunctionReturn(0); 159820cf1dd8SToby Isaac } 159920cf1dd8SToby Isaac 160027f02ce8SMatthew G. Knepley /*@C 160127f02ce8SMatthew G. Knepley PetscFEIntegrateHybridJacobian - Produce the boundary element Jacobian for a chunk of hybrid elements by quadrature integration 160227f02ce8SMatthew G. Knepley 160327f02ce8SMatthew G. Knepley Not collective 160427f02ce8SMatthew G. Knepley 160527f02ce8SMatthew G. Knepley Input Parameters: 160645480ffeSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 160727f02ce8SMatthew G. Knepley . jtype - The type of matrix pointwise functions that should be used 160845480ffeSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 16095fedec97SMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 161027f02ce8SMatthew G. Knepley . Ne - The number of elements in the chunk 161127f02ce8SMatthew G. Knepley . fgeom - The face geometry for each cell in the chunk 161227f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 161327f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements 161427f02ce8SMatthew G. Knepley . probAux - The PetscDS specifying the auxiliary discretizations 161527f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 161627f02ce8SMatthew G. Knepley . t - The time 161727f02ce8SMatthew G. Knepley - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 161827f02ce8SMatthew G. Knepley 161927f02ce8SMatthew G. Knepley Output Parameter 162027f02ce8SMatthew G. Knepley . elemMat - the element matrices for the Jacobian from each element 162127f02ce8SMatthew G. Knepley 162227f02ce8SMatthew G. Knepley Note: 162327f02ce8SMatthew G. Knepley $ Loop over batch of elements (e): 162427f02ce8SMatthew G. Knepley $ Loop over element matrix entries (f,fc,g,gc --> i,j): 162527f02ce8SMatthew G. Knepley $ Loop over quadrature points (q): 162627f02ce8SMatthew G. Knepley $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 162727f02ce8SMatthew G. Knepley $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 162827f02ce8SMatthew G. Knepley $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 162927f02ce8SMatthew G. Knepley $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 163027f02ce8SMatthew G. Knepley $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 163127f02ce8SMatthew G. Knepley Level: developer 163227f02ce8SMatthew G. Knepley 163327f02ce8SMatthew G. Knepley .seealso: PetscFEIntegrateJacobian(), PetscFEIntegrateResidual() 163427f02ce8SMatthew G. Knepley @*/ 16355fedec97SMatthew G. Knepley PetscErrorCode PetscFEIntegrateHybridJacobian(PetscDS ds, PetscFEJacobianType jtype, PetscFormKey key, PetscInt s, PetscInt Ne, PetscFEGeom *fgeom, 163627f02ce8SMatthew G. Knepley const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 163727f02ce8SMatthew G. Knepley { 163827f02ce8SMatthew G. Knepley PetscFE fe; 163945480ffeSMatthew G. Knepley PetscInt Nf; 164027f02ce8SMatthew G. Knepley 164127f02ce8SMatthew G. Knepley PetscFunctionBegin; 164245480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 16439566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 16449566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *) &fe)); 16459566063dSJacob Faibussowitsch if (fe->ops->integratehybridjacobian) PetscCall((*fe->ops->integratehybridjacobian)(ds, jtype, key, s, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 164627f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 164727f02ce8SMatthew G. Knepley } 164827f02ce8SMatthew G. Knepley 16492b99622eSMatthew G. Knepley /*@ 16502b99622eSMatthew G. Knepley PetscFEGetHeightSubspace - Get the subspace of this space for a mesh point of a given height 16512b99622eSMatthew G. Knepley 16522b99622eSMatthew G. Knepley Input Parameters: 16532b99622eSMatthew G. Knepley + fe - The finite element space 16542b99622eSMatthew G. Knepley - height - The height of the Plex point 16552b99622eSMatthew G. Knepley 16562b99622eSMatthew G. Knepley Output Parameter: 16572b99622eSMatthew G. Knepley . subfe - The subspace of this FE space 16582b99622eSMatthew G. Knepley 16592b99622eSMatthew G. Knepley Note: For example, if we want the subspace of this space for a face, we would choose height = 1. 16602b99622eSMatthew G. Knepley 16612b99622eSMatthew G. Knepley Level: advanced 16622b99622eSMatthew G. Knepley 16632b99622eSMatthew G. Knepley .seealso: PetscFECreateDefault() 16642b99622eSMatthew G. Knepley @*/ 166520cf1dd8SToby Isaac PetscErrorCode PetscFEGetHeightSubspace(PetscFE fe, PetscInt height, PetscFE *subfe) 166620cf1dd8SToby Isaac { 166720cf1dd8SToby Isaac PetscSpace P, subP; 166820cf1dd8SToby Isaac PetscDualSpace Q, subQ; 166920cf1dd8SToby Isaac PetscQuadrature subq; 167020cf1dd8SToby Isaac PetscFEType fetype; 167120cf1dd8SToby Isaac PetscInt dim, Nc; 167220cf1dd8SToby Isaac 167320cf1dd8SToby Isaac PetscFunctionBegin; 167420cf1dd8SToby Isaac PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1); 167520cf1dd8SToby Isaac PetscValidPointer(subfe, 3); 167620cf1dd8SToby Isaac if (height == 0) { 167720cf1dd8SToby Isaac *subfe = fe; 167820cf1dd8SToby Isaac PetscFunctionReturn(0); 167920cf1dd8SToby Isaac } 16809566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 16819566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 16829566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &Nc)); 16839566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(fe, &subq)); 16849566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &dim)); 1685*1dca8a05SBarry Smith PetscCheck(height <= dim && height >= 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Asked for space at height %" PetscInt_FMT " for dimension %" PetscInt_FMT " space", height, dim); 16869566063dSJacob Faibussowitsch if (!fe->subspaces) PetscCall(PetscCalloc1(dim, &fe->subspaces)); 168720cf1dd8SToby Isaac if (height <= dim) { 168820cf1dd8SToby Isaac if (!fe->subspaces[height-1]) { 1689665f567fSMatthew G. Knepley PetscFE sub = NULL; 16903f6b16c7SMatthew G. Knepley const char *name; 169120cf1dd8SToby Isaac 16929566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetHeightSubspace(P, height, &subP)); 16939566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetHeightSubspace(Q, height, &subQ)); 1694665f567fSMatthew G. Knepley if (subQ) { 16959566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject) fe), &sub)); 16969566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject) fe, &name)); 16979566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject) sub, name)); 16989566063dSJacob Faibussowitsch PetscCall(PetscFEGetType(fe, &fetype)); 16999566063dSJacob Faibussowitsch PetscCall(PetscFESetType(sub, fetype)); 17009566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(sub, subP)); 17019566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(sub, subQ)); 17029566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(sub, Nc)); 17039566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(sub)); 17049566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(sub, subq)); 1705665f567fSMatthew G. Knepley } 170620cf1dd8SToby Isaac fe->subspaces[height-1] = sub; 170720cf1dd8SToby Isaac } 170820cf1dd8SToby Isaac *subfe = fe->subspaces[height-1]; 170920cf1dd8SToby Isaac } else { 171020cf1dd8SToby Isaac *subfe = NULL; 171120cf1dd8SToby Isaac } 171220cf1dd8SToby Isaac PetscFunctionReturn(0); 171320cf1dd8SToby Isaac } 171420cf1dd8SToby Isaac 171520cf1dd8SToby Isaac /*@ 171620cf1dd8SToby Isaac PetscFERefine - Create a "refined" PetscFE object that refines the reference cell into smaller copies. This is typically used 171720cf1dd8SToby Isaac to precondition a higher order method with a lower order method on a refined mesh having the same number of dofs (but more 171820cf1dd8SToby Isaac sparsity). It is also used to create an interpolation between regularly refined meshes. 171920cf1dd8SToby Isaac 1720d083f849SBarry Smith Collective on fem 172120cf1dd8SToby Isaac 172220cf1dd8SToby Isaac Input Parameter: 172320cf1dd8SToby Isaac . fe - The initial PetscFE 172420cf1dd8SToby Isaac 172520cf1dd8SToby Isaac Output Parameter: 172620cf1dd8SToby Isaac . feRef - The refined PetscFE 172720cf1dd8SToby Isaac 17282b99622eSMatthew G. Knepley Level: advanced 172920cf1dd8SToby Isaac 173020cf1dd8SToby Isaac .seealso: PetscFEType, PetscFECreate(), PetscFESetType() 173120cf1dd8SToby Isaac @*/ 173220cf1dd8SToby Isaac PetscErrorCode PetscFERefine(PetscFE fe, PetscFE *feRef) 173320cf1dd8SToby Isaac { 173420cf1dd8SToby Isaac PetscSpace P, Pref; 173520cf1dd8SToby Isaac PetscDualSpace Q, Qref; 173620cf1dd8SToby Isaac DM K, Kref; 173720cf1dd8SToby Isaac PetscQuadrature q, qref; 173820cf1dd8SToby Isaac const PetscReal *v0, *jac; 173920cf1dd8SToby Isaac PetscInt numComp, numSubelements; 17401ac17e89SToby Isaac PetscInt cStart, cEnd, c; 17411ac17e89SToby Isaac PetscDualSpace *cellSpaces; 174220cf1dd8SToby Isaac 174320cf1dd8SToby Isaac PetscFunctionBegin; 17449566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 17459566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 17469566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &q)); 17479566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &K)); 174820cf1dd8SToby Isaac /* Create space */ 17499566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) P)); 175020cf1dd8SToby Isaac Pref = P; 175120cf1dd8SToby Isaac /* Create dual space */ 17529566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDuplicate(Q, &Qref)); 17539566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetType(Qref, PETSCDUALSPACEREFINED)); 17549566063dSJacob Faibussowitsch PetscCall(DMRefine(K, PetscObjectComm((PetscObject) fe), &Kref)); 17559566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetDM(Qref, Kref)); 17569566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(Kref, 0, &cStart, &cEnd)); 17579566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(cEnd - cStart, &cellSpaces)); 17581ac17e89SToby Isaac /* TODO: fix for non-uniform refinement */ 17591ac17e89SToby Isaac for (c = 0; c < cEnd - cStart; c++) cellSpaces[c] = Q; 17609566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceRefinedSetCellSpaces(Qref, cellSpaces)); 17619566063dSJacob Faibussowitsch PetscCall(PetscFree(cellSpaces)); 17629566063dSJacob Faibussowitsch PetscCall(DMDestroy(&Kref)); 17639566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetUp(Qref)); 176420cf1dd8SToby Isaac /* Create element */ 17659566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject) fe), feRef)); 17669566063dSJacob Faibussowitsch PetscCall(PetscFESetType(*feRef, PETSCFECOMPOSITE)); 17679566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(*feRef, Pref)); 17689566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(*feRef, Qref)); 17699566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &numComp)); 17709566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(*feRef, numComp)); 17719566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(*feRef)); 17729566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pref)); 17739566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&Qref)); 177420cf1dd8SToby Isaac /* Create quadrature */ 17759566063dSJacob Faibussowitsch PetscCall(PetscFECompositeGetMapping(*feRef, &numSubelements, &v0, &jac, NULL)); 17769566063dSJacob Faibussowitsch PetscCall(PetscQuadratureExpandComposite(q, numSubelements, v0, jac, &qref)); 17779566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(*feRef, qref)); 17789566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&qref)); 177920cf1dd8SToby Isaac PetscFunctionReturn(0); 178020cf1dd8SToby Isaac } 178120cf1dd8SToby Isaac 17822df84da0SMatthew G. Knepley static PetscErrorCode PetscFECreate_Internal(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, const char prefix[], PetscInt degree, PetscInt qorder, PetscBool setFromOptions, PetscFE *fem) 17832df84da0SMatthew G. Knepley { 17842df84da0SMatthew G. Knepley PetscQuadrature q, fq; 17852df84da0SMatthew G. Knepley DM K; 17862df84da0SMatthew G. Knepley PetscSpace P; 17872df84da0SMatthew G. Knepley PetscDualSpace Q; 17882df84da0SMatthew G. Knepley PetscInt quadPointsPerEdge; 17892df84da0SMatthew G. Knepley PetscBool tensor; 17902df84da0SMatthew G. Knepley char name[64]; 17912df84da0SMatthew G. Knepley 17922df84da0SMatthew G. Knepley PetscFunctionBegin; 17932df84da0SMatthew G. Knepley if (prefix) PetscValidCharPointer(prefix, 5); 17942df84da0SMatthew G. Knepley PetscValidPointer(fem, 9); 17952df84da0SMatthew G. Knepley switch (ct) { 17962df84da0SMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 17972df84da0SMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 17982df84da0SMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 17992df84da0SMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 18002df84da0SMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 18012df84da0SMatthew G. Knepley case DM_POLYTOPE_QUAD_PRISM_TENSOR: 18022df84da0SMatthew G. Knepley tensor = PETSC_TRUE; 18032df84da0SMatthew G. Knepley break; 18042df84da0SMatthew G. Knepley default: tensor = PETSC_FALSE; 18052df84da0SMatthew G. Knepley } 18062df84da0SMatthew G. Knepley /* Create space */ 18079566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &P)); 18089566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(P, PETSCSPACEPOLYNOMIAL)); 18099566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject) P, prefix)); 18109566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(P, tensor)); 18119566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(P, Nc)); 18129566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(P, dim)); 18132df84da0SMatthew G. Knepley if (degree >= 0) { 18149566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(P, degree, PETSC_DETERMINE)); 1815cfd33b42SLisandro Dalcin if (ct == DM_POLYTOPE_TRI_PRISM || ct == DM_POLYTOPE_TRI_PRISM_TENSOR) { 18162df84da0SMatthew G. Knepley PetscSpace Pend, Pside; 18172df84da0SMatthew G. Knepley 18189566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &Pend)); 18199566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(Pend, PETSCSPACEPOLYNOMIAL)); 18209566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(Pend, PETSC_FALSE)); 18219566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(Pend, Nc)); 18229566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(Pend, dim-1)); 18239566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(Pend, degree, PETSC_DETERMINE)); 18249566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &Pside)); 18259566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(Pside, PETSCSPACEPOLYNOMIAL)); 18269566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(Pside, PETSC_FALSE)); 18279566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(Pside, 1)); 18289566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(Pside, 1)); 18299566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(Pside, degree, PETSC_DETERMINE)); 18309566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(P, PETSCSPACETENSOR)); 18319566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetNumSubspaces(P, 2)); 18329566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetSubspace(P, 0, Pend)); 18339566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetSubspace(P, 1, Pside)); 18349566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pend)); 18359566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pside)); 18362df84da0SMatthew G. Knepley } 18372df84da0SMatthew G. Knepley } 18389566063dSJacob Faibussowitsch if (setFromOptions) PetscCall(PetscSpaceSetFromOptions(P)); 18399566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetUp(P)); 18409566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetDegree(P, °ree, NULL)); 18419566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialGetTensor(P, &tensor)); 18429566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetNumComponents(P, &Nc)); 18432df84da0SMatthew G. Knepley /* Create dual space */ 18449566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceCreate(comm, &Q)); 18459566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetType(Q,PETSCDUALSPACELAGRANGE)); 18469566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject) Q, prefix)); 18479566063dSJacob Faibussowitsch PetscCall(DMPlexCreateReferenceCell(PETSC_COMM_SELF, ct, &K)); 18489566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetDM(Q, K)); 18499566063dSJacob Faibussowitsch PetscCall(DMDestroy(&K)); 18509566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetNumComponents(Q, Nc)); 18519566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetOrder(Q, degree)); 18522df84da0SMatthew G. Knepley /* TODO For some reason, we need a tensor dualspace with wedges */ 18539566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceLagrangeSetTensor(Q, (tensor || (ct == DM_POLYTOPE_TRI_PRISM)) ? PETSC_TRUE : PETSC_FALSE)); 18549566063dSJacob Faibussowitsch if (setFromOptions) PetscCall(PetscDualSpaceSetFromOptions(Q)); 18559566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetUp(Q)); 18562df84da0SMatthew G. Knepley /* Create finite element */ 18579566063dSJacob Faibussowitsch PetscCall(PetscFECreate(comm, fem)); 18589566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject) *fem, prefix)); 18599566063dSJacob Faibussowitsch PetscCall(PetscFESetType(*fem, PETSCFEBASIC)); 18609566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(*fem, P)); 18619566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(*fem, Q)); 18629566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(*fem, Nc)); 18639566063dSJacob Faibussowitsch if (setFromOptions) PetscCall(PetscFESetFromOptions(*fem)); 18649566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(*fem)); 18659566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&P)); 18669566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&Q)); 18672df84da0SMatthew G. Knepley /* Create quadrature (with specified order if given) */ 18682df84da0SMatthew G. Knepley qorder = qorder >= 0 ? qorder : degree; 18692df84da0SMatthew G. Knepley if (setFromOptions) { 1870d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject)*fem); 18719566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-petscfe_default_quadrature_order","Quadrature order is one less than quadrature points per edge","PetscFECreateDefault",qorder,&qorder,NULL,0)); 1872d0609cedSBarry Smith PetscOptionsEnd(); 18732df84da0SMatthew G. Knepley } 18742df84da0SMatthew G. Knepley quadPointsPerEdge = PetscMax(qorder + 1,1); 18752df84da0SMatthew G. Knepley switch (ct) { 18762df84da0SMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 18772df84da0SMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 18782df84da0SMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 18792df84da0SMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 18802df84da0SMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 18812df84da0SMatthew G. Knepley case DM_POLYTOPE_QUAD_PRISM_TENSOR: 18829566063dSJacob Faibussowitsch PetscCall(PetscDTGaussTensorQuadrature(dim, 1, quadPointsPerEdge, -1.0, 1.0, &q)); 18839566063dSJacob Faibussowitsch PetscCall(PetscDTGaussTensorQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, &fq)); 18842df84da0SMatthew G. Knepley break; 18852df84da0SMatthew G. Knepley case DM_POLYTOPE_TRIANGLE: 18862df84da0SMatthew G. Knepley case DM_POLYTOPE_TETRAHEDRON: 18879566063dSJacob Faibussowitsch PetscCall(PetscDTStroudConicalQuadrature(dim, 1, quadPointsPerEdge, -1.0, 1.0, &q)); 18889566063dSJacob Faibussowitsch PetscCall(PetscDTStroudConicalQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, &fq)); 18892df84da0SMatthew G. Knepley break; 18902df84da0SMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM: 18912df84da0SMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM_TENSOR: 18922df84da0SMatthew G. Knepley { 18932df84da0SMatthew G. Knepley PetscQuadrature q1, q2; 18942df84da0SMatthew G. Knepley 18959566063dSJacob Faibussowitsch PetscCall(PetscDTStroudConicalQuadrature(2, 1, quadPointsPerEdge, -1.0, 1.0, &q1)); 18969566063dSJacob Faibussowitsch PetscCall(PetscDTGaussTensorQuadrature(1, 1, quadPointsPerEdge, -1.0, 1.0, &q2)); 18979566063dSJacob Faibussowitsch PetscCall(PetscDTTensorQuadratureCreate(q1, q2, &q)); 18989566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&q1)); 18999566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&q2)); 19002df84da0SMatthew G. Knepley } 19019566063dSJacob Faibussowitsch PetscCall(PetscDTStroudConicalQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, &fq)); 19022df84da0SMatthew G. Knepley /* TODO Need separate quadratures for each face */ 19032df84da0SMatthew G. Knepley break; 19042df84da0SMatthew G. Knepley default: SETERRQ(comm, PETSC_ERR_ARG_OUTOFRANGE, "No quadrature for celltype %s", DMPolytopeTypes[PetscMin(ct, DM_POLYTOPE_UNKNOWN)]); 19052df84da0SMatthew G. Knepley } 19069566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(*fem, q)); 19079566063dSJacob Faibussowitsch PetscCall(PetscFESetFaceQuadrature(*fem, fq)); 19089566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&q)); 19099566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&fq)); 19102df84da0SMatthew G. Knepley /* Set finite element name */ 19112df84da0SMatthew G. Knepley switch (ct) { 19122df84da0SMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 19132df84da0SMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 19142df84da0SMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 19152df84da0SMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 19162df84da0SMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 19172df84da0SMatthew G. Knepley case DM_POLYTOPE_QUAD_PRISM_TENSOR: 19189566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "Q%" PetscInt_FMT, degree)); 19192df84da0SMatthew G. Knepley break; 19202df84da0SMatthew G. Knepley case DM_POLYTOPE_TRIANGLE: 19212df84da0SMatthew G. Knepley case DM_POLYTOPE_TETRAHEDRON: 19229566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "P%" PetscInt_FMT, degree)); 19232df84da0SMatthew G. Knepley break; 19242df84da0SMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM: 19252df84da0SMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM_TENSOR: 19269566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "P%" PetscInt_FMT "xQ%" PetscInt_FMT, degree, degree)); 19272df84da0SMatthew G. Knepley break; 19282df84da0SMatthew G. Knepley default: 19299566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "FE")); 19302df84da0SMatthew G. Knepley } 19319566063dSJacob Faibussowitsch PetscCall(PetscFESetName(*fem, name)); 19322df84da0SMatthew G. Knepley PetscFunctionReturn(0); 19332df84da0SMatthew G. Knepley } 19342df84da0SMatthew G. Knepley 193520cf1dd8SToby Isaac /*@C 193620cf1dd8SToby Isaac PetscFECreateDefault - Create a PetscFE for basic FEM computation 193720cf1dd8SToby Isaac 1938d083f849SBarry Smith Collective 193920cf1dd8SToby Isaac 194020cf1dd8SToby Isaac Input Parameters: 19417be5e748SToby Isaac + comm - The MPI comm 194220cf1dd8SToby Isaac . dim - The spatial dimension 194320cf1dd8SToby Isaac . Nc - The number of components 194420cf1dd8SToby Isaac . isSimplex - Flag for simplex reference cell, otherwise its a tensor product 194520cf1dd8SToby Isaac . prefix - The options prefix, or NULL 1946727cddd5SJacob Faibussowitsch - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 194720cf1dd8SToby Isaac 194820cf1dd8SToby Isaac Output Parameter: 194920cf1dd8SToby Isaac . fem - The PetscFE object 195020cf1dd8SToby Isaac 1951e703855dSMatthew G. Knepley Note: 19528f2aacc6SMatthew G. Knepley Each subobject is SetFromOption() during creation, so that the object may be customized from the command line, using the prefix specified above. See the links below for the particular options available. 1953e703855dSMatthew G. Knepley 195420cf1dd8SToby Isaac Level: beginner 195520cf1dd8SToby Isaac 19562df84da0SMatthew G. Knepley .seealso: PetscFECreateLagrange(), PetscFECreateByCell(), PetscSpaceSetFromOptions(), PetscDualSpaceSetFromOptions(), PetscFESetFromOptions(), PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate() 195720cf1dd8SToby Isaac @*/ 19587be5e748SToby Isaac PetscErrorCode PetscFECreateDefault(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, const char prefix[], PetscInt qorder, PetscFE *fem) 195920cf1dd8SToby Isaac { 196020cf1dd8SToby Isaac PetscFunctionBegin; 19619566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, DMPolytopeTypeSimpleShape(dim, isSimplex), prefix, PETSC_DECIDE, qorder, PETSC_TRUE, fem)); 19622df84da0SMatthew G. Knepley PetscFunctionReturn(0); 196320cf1dd8SToby Isaac } 19642df84da0SMatthew G. Knepley 19652df84da0SMatthew G. Knepley /*@C 19662df84da0SMatthew G. Knepley PetscFECreateByCell - Create a PetscFE for basic FEM computation 19672df84da0SMatthew G. Knepley 19682df84da0SMatthew G. Knepley Collective 19692df84da0SMatthew G. Knepley 19702df84da0SMatthew G. Knepley Input Parameters: 19712df84da0SMatthew G. Knepley + comm - The MPI comm 19722df84da0SMatthew G. Knepley . dim - The spatial dimension 19732df84da0SMatthew G. Knepley . Nc - The number of components 19742df84da0SMatthew G. Knepley . ct - The celltype of the reference cell 19752df84da0SMatthew G. Knepley . prefix - The options prefix, or NULL 19762df84da0SMatthew G. Knepley - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 19772df84da0SMatthew G. Knepley 19782df84da0SMatthew G. Knepley Output Parameter: 19792df84da0SMatthew G. Knepley . fem - The PetscFE object 19802df84da0SMatthew G. Knepley 19812df84da0SMatthew G. Knepley Note: 19822df84da0SMatthew G. Knepley Each subobject is SetFromOption() during creation, so that the object may be customized from the command line, using the prefix specified above. See the links below for the particular options available. 19832df84da0SMatthew G. Knepley 19842df84da0SMatthew G. Knepley Level: beginner 19852df84da0SMatthew G. Knepley 19862df84da0SMatthew G. Knepley .seealso: PetscFECreateDefault(), PetscFECreateLagrange(), PetscSpaceSetFromOptions(), PetscDualSpaceSetFromOptions(), PetscFESetFromOptions(), PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate() 19872df84da0SMatthew G. Knepley @*/ 19882df84da0SMatthew G. Knepley PetscErrorCode PetscFECreateByCell(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, const char prefix[], PetscInt qorder, PetscFE *fem) 19892df84da0SMatthew G. Knepley { 19902df84da0SMatthew G. Knepley PetscFunctionBegin; 19919566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, ct, prefix, PETSC_DECIDE, qorder, PETSC_TRUE, fem)); 199220cf1dd8SToby Isaac PetscFunctionReturn(0); 199320cf1dd8SToby Isaac } 19943f6b16c7SMatthew G. Knepley 1995e703855dSMatthew G. Knepley /*@ 1996e703855dSMatthew G. Knepley PetscFECreateLagrange - Create a PetscFE for the basic Lagrange space of degree k 1997e703855dSMatthew G. Knepley 1998e703855dSMatthew G. Knepley Collective 1999e703855dSMatthew G. Knepley 2000e703855dSMatthew G. Knepley Input Parameters: 2001e703855dSMatthew G. Knepley + comm - The MPI comm 2002e703855dSMatthew G. Knepley . dim - The spatial dimension 2003e703855dSMatthew G. Knepley . Nc - The number of components 2004e703855dSMatthew G. Knepley . isSimplex - Flag for simplex reference cell, otherwise its a tensor product 2005e703855dSMatthew G. Knepley . k - The degree k of the space 2006e703855dSMatthew G. Knepley - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 2007e703855dSMatthew G. Knepley 2008e703855dSMatthew G. Knepley Output Parameter: 2009e703855dSMatthew G. Knepley . fem - The PetscFE object 2010e703855dSMatthew G. Knepley 2011e703855dSMatthew G. Knepley Level: beginner 2012e703855dSMatthew G. Knepley 2013e703855dSMatthew G. Knepley Notes: 2014e703855dSMatthew G. Knepley For simplices, this element is the space of maximum polynomial degree k, otherwise it is a tensor product of 1D polynomials, each with maximal degree k. 2015e703855dSMatthew G. Knepley 20162df84da0SMatthew G. Knepley .seealso: PetscFECreateLagrangeByCell(), PetscFECreateDefault(), PetscFECreateByCell(), PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate() 2017e703855dSMatthew G. Knepley @*/ 2018e703855dSMatthew G. Knepley PetscErrorCode PetscFECreateLagrange(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, PetscInt k, PetscInt qorder, PetscFE *fem) 2019e703855dSMatthew G. Knepley { 2020e703855dSMatthew G. Knepley PetscFunctionBegin; 20219566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, DMPolytopeTypeSimpleShape(dim, isSimplex), NULL, k, qorder, PETSC_FALSE, fem)); 20222df84da0SMatthew G. Knepley PetscFunctionReturn(0); 2023e703855dSMatthew G. Knepley } 20242df84da0SMatthew G. Knepley 20252df84da0SMatthew G. Knepley /*@ 20262df84da0SMatthew G. Knepley PetscFECreateLagrangeByCell - Create a PetscFE for the basic Lagrange space of degree k 20272df84da0SMatthew G. Knepley 20282df84da0SMatthew G. Knepley Collective 20292df84da0SMatthew G. Knepley 20302df84da0SMatthew G. Knepley Input Parameters: 20312df84da0SMatthew G. Knepley + comm - The MPI comm 20322df84da0SMatthew G. Knepley . dim - The spatial dimension 20332df84da0SMatthew G. Knepley . Nc - The number of components 20342df84da0SMatthew G. Knepley . ct - The celltype of the reference cell 20352df84da0SMatthew G. Knepley . k - The degree k of the space 20362df84da0SMatthew G. Knepley - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 20372df84da0SMatthew G. Knepley 20382df84da0SMatthew G. Knepley Output Parameter: 20392df84da0SMatthew G. Knepley . fem - The PetscFE object 20402df84da0SMatthew G. Knepley 20412df84da0SMatthew G. Knepley Level: beginner 20422df84da0SMatthew G. Knepley 20432df84da0SMatthew G. Knepley Notes: 20442df84da0SMatthew G. Knepley For simplices, this element is the space of maximum polynomial degree k, otherwise it is a tensor product of 1D polynomials, each with maximal degree k. 20452df84da0SMatthew G. Knepley 20462df84da0SMatthew G. Knepley .seealso: PetscFECreateLagrange(), PetscFECreateDefault(), PetscFECreateByCell(), PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate() 20472df84da0SMatthew G. Knepley @*/ 20482df84da0SMatthew G. Knepley PetscErrorCode PetscFECreateLagrangeByCell(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, PetscInt k, PetscInt qorder, PetscFE *fem) 20492df84da0SMatthew G. Knepley { 20502df84da0SMatthew G. Knepley PetscFunctionBegin; 20519566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, ct, NULL, k, qorder, PETSC_FALSE, fem)); 2052e703855dSMatthew G. Knepley PetscFunctionReturn(0); 2053e703855dSMatthew G. Knepley } 2054e703855dSMatthew G. Knepley 20553f6b16c7SMatthew G. Knepley /*@C 20563f6b16c7SMatthew G. Knepley PetscFESetName - Names the FE and its subobjects 20573f6b16c7SMatthew G. Knepley 20583f6b16c7SMatthew G. Knepley Not collective 20593f6b16c7SMatthew G. Knepley 20603f6b16c7SMatthew G. Knepley Input Parameters: 20613f6b16c7SMatthew G. Knepley + fe - The PetscFE 20623f6b16c7SMatthew G. Knepley - name - The name 20633f6b16c7SMatthew G. Knepley 20642b99622eSMatthew G. Knepley Level: intermediate 20653f6b16c7SMatthew G. Knepley 20663f6b16c7SMatthew G. Knepley .seealso: PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate() 20673f6b16c7SMatthew G. Knepley @*/ 20683f6b16c7SMatthew G. Knepley PetscErrorCode PetscFESetName(PetscFE fe, const char name[]) 20693f6b16c7SMatthew G. Knepley { 20703f6b16c7SMatthew G. Knepley PetscSpace P; 20713f6b16c7SMatthew G. Knepley PetscDualSpace Q; 20723f6b16c7SMatthew G. Knepley 20733f6b16c7SMatthew G. Knepley PetscFunctionBegin; 20749566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 20759566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 20769566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject) fe, name)); 20779566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject) P, name)); 20789566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject) Q, name)); 20793f6b16c7SMatthew G. Knepley PetscFunctionReturn(0); 20803f6b16c7SMatthew G. Knepley } 2081a8f1f9e5SMatthew G. Knepley 2082ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEEvaluateFieldJets_Internal(PetscDS ds, PetscInt Nf, PetscInt r, PetscInt q, PetscTabulation T[], PetscFEGeom *fegeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscScalar u[], PetscScalar u_x[], PetscScalar u_t[]) 2083a8f1f9e5SMatthew G. Knepley { 2084f9244615SMatthew G. Knepley PetscInt dOffset = 0, fOffset = 0, f, g; 2085a8f1f9e5SMatthew G. Knepley 2086a8f1f9e5SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 2087a8f1f9e5SMatthew G. Knepley PetscFE fe; 2088f9244615SMatthew G. Knepley const PetscInt k = ds->jetDegree[f]; 2089ef0bb6c7SMatthew G. Knepley const PetscInt cdim = T[f]->cdim; 2090ef0bb6c7SMatthew G. Knepley const PetscInt Nq = T[f]->Np; 2091ef0bb6c7SMatthew G. Knepley const PetscInt Nbf = T[f]->Nb; 2092ef0bb6c7SMatthew G. Knepley const PetscInt Ncf = T[f]->Nc; 2093ef0bb6c7SMatthew G. Knepley const PetscReal *Bq = &T[f]->T[0][(r*Nq+q)*Nbf*Ncf]; 2094ef0bb6c7SMatthew G. Knepley const PetscReal *Dq = &T[f]->T[1][(r*Nq+q)*Nbf*Ncf*cdim]; 2095f9244615SMatthew G. Knepley const PetscReal *Hq = k > 1 ? &T[f]->T[2][(r*Nq+q)*Nbf*Ncf*cdim*cdim] : NULL; 2096f9244615SMatthew G. Knepley PetscInt hOffset = 0, b, c, d; 2097a8f1f9e5SMatthew G. Knepley 20989566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, f, (PetscObject *) &fe)); 2099a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u[fOffset+c] = 0.0; 2100ef0bb6c7SMatthew G. Knepley for (d = 0; d < cdim*Ncf; ++d) u_x[fOffset*cdim+d] = 0.0; 2101a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2102a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2103a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 2104a8f1f9e5SMatthew G. Knepley 2105a8f1f9e5SMatthew G. Knepley u[fOffset+c] += Bq[cidx]*coefficients[dOffset+b]; 2106ef0bb6c7SMatthew G. Knepley for (d = 0; d < cdim; ++d) u_x[(fOffset+c)*cdim+d] += Dq[cidx*cdim+d]*coefficients[dOffset+b]; 2107a8f1f9e5SMatthew G. Knepley } 2108a8f1f9e5SMatthew G. Knepley } 2109f9244615SMatthew G. Knepley if (k > 1) { 2110f9244615SMatthew G. Knepley for (g = 0; g < Nf; ++g) hOffset += T[g]->Nc*cdim; 2111f9244615SMatthew G. Knepley for (d = 0; d < cdim*cdim*Ncf; ++d) u_x[hOffset+fOffset*cdim*cdim+d] = 0.0; 2112f9244615SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2113f9244615SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2114f9244615SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 2115f9244615SMatthew G. Knepley 2116f9244615SMatthew G. Knepley for (d = 0; d < cdim*cdim; ++d) u_x[hOffset+(fOffset+c)*cdim*cdim+d] += Hq[cidx*cdim*cdim+d]*coefficients[dOffset+b]; 2117f9244615SMatthew G. Knepley } 2118f9244615SMatthew G. Knepley } 21199566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardHessian(fe, fegeom, 1, &u_x[hOffset+fOffset*cdim*cdim])); 2120f9244615SMatthew G. Knepley } 21219566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u[fOffset])); 21229566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset*cdim])); 2123a8f1f9e5SMatthew G. Knepley if (u_t) { 2124a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u_t[fOffset+c] = 0.0; 2125a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2126a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2127a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 2128a8f1f9e5SMatthew G. Knepley 2129a8f1f9e5SMatthew G. Knepley u_t[fOffset+c] += Bq[cidx]*coefficients_t[dOffset+b]; 2130a8f1f9e5SMatthew G. Knepley } 2131a8f1f9e5SMatthew G. Knepley } 21329566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset])); 2133a8f1f9e5SMatthew G. Knepley } 2134a8f1f9e5SMatthew G. Knepley fOffset += Ncf; 2135a8f1f9e5SMatthew G. Knepley dOffset += Nbf; 2136a8f1f9e5SMatthew G. Knepley } 2137a8f1f9e5SMatthew G. Knepley return 0; 2138a8f1f9e5SMatthew G. Knepley } 2139a8f1f9e5SMatthew G. Knepley 2140665f567fSMatthew G. Knepley PetscErrorCode PetscFEEvaluateFieldJets_Hybrid_Internal(PetscDS ds, PetscInt Nf, PetscInt r, PetscInt q, PetscTabulation T[], PetscFEGeom *fegeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscScalar u[], PetscScalar u_x[], PetscScalar u_t[]) 214127f02ce8SMatthew G. Knepley { 21425fedec97SMatthew G. Knepley PetscInt dOffset = 0, fOffset = 0, f, g; 214327f02ce8SMatthew G. Knepley 21445fedec97SMatthew G. Knepley /* f is the field number in the DS, g is the field number in u[] */ 21455fedec97SMatthew G. Knepley for (f = 0, g = 0; f < Nf; ++f) { 21465fedec97SMatthew G. Knepley PetscFE fe = (PetscFE) ds->disc[f]; 21479ee2af8cSMatthew G. Knepley const PetscInt dEt = T[f]->cdim; 21489ee2af8cSMatthew G. Knepley const PetscInt dE = fegeom->dimEmbed; 2149665f567fSMatthew G. Knepley const PetscInt Nq = T[f]->Np; 2150665f567fSMatthew G. Knepley const PetscInt Nbf = T[f]->Nb; 2151665f567fSMatthew G. Knepley const PetscInt Ncf = T[f]->Nc; 2152665f567fSMatthew G. Knepley const PetscReal *Bq = &T[f]->T[0][(r*Nq+q)*Nbf*Ncf]; 21539ee2af8cSMatthew G. Knepley const PetscReal *Dq = &T[f]->T[1][(r*Nq+q)*Nbf*Ncf*dEt]; 21545fedec97SMatthew G. Knepley PetscBool isCohesive; 21555fedec97SMatthew G. Knepley PetscInt Ns, s; 21565fedec97SMatthew G. Knepley 21575fedec97SMatthew G. Knepley if (!T[f]) continue; 21589566063dSJacob Faibussowitsch PetscCall(PetscDSGetCohesive(ds, f, &isCohesive)); 21595fedec97SMatthew G. Knepley Ns = isCohesive ? 1 : 2; 21605fedec97SMatthew G. Knepley for (s = 0; s < Ns; ++s, ++g) { 216127f02ce8SMatthew G. Knepley PetscInt b, c, d; 216227f02ce8SMatthew G. Knepley 216327f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u[fOffset+c] = 0.0; 21649ee2af8cSMatthew G. Knepley for (d = 0; d < dE*Ncf; ++d) u_x[fOffset*dE+d] = 0.0; 216527f02ce8SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 216627f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 216727f02ce8SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 216827f02ce8SMatthew G. Knepley 216927f02ce8SMatthew G. Knepley u[fOffset+c] += Bq[cidx]*coefficients[dOffset+b]; 21709ee2af8cSMatthew G. Knepley for (d = 0; d < dEt; ++d) u_x[(fOffset+c)*dE+d] += Dq[cidx*dEt+d]*coefficients[dOffset+b]; 217127f02ce8SMatthew G. Knepley } 217227f02ce8SMatthew G. Knepley } 21739566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u[fOffset])); 21749566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset*dE])); 217527f02ce8SMatthew G. Knepley if (u_t) { 217627f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u_t[fOffset+c] = 0.0; 217727f02ce8SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 217827f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 217927f02ce8SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 218027f02ce8SMatthew G. Knepley 218127f02ce8SMatthew G. Knepley u_t[fOffset+c] += Bq[cidx]*coefficients_t[dOffset+b]; 218227f02ce8SMatthew G. Knepley } 218327f02ce8SMatthew G. Knepley } 21849566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset])); 218527f02ce8SMatthew G. Knepley } 218627f02ce8SMatthew G. Knepley fOffset += Ncf; 218727f02ce8SMatthew G. Knepley dOffset += Nbf; 218827f02ce8SMatthew G. Knepley } 2189665f567fSMatthew G. Knepley } 219027f02ce8SMatthew G. Knepley return 0; 219127f02ce8SMatthew G. Knepley } 219227f02ce8SMatthew G. Knepley 2193a8f1f9e5SMatthew G. Knepley PetscErrorCode PetscFEEvaluateFaceFields_Internal(PetscDS prob, PetscInt field, PetscInt faceLoc, const PetscScalar coefficients[], PetscScalar u[]) 2194a8f1f9e5SMatthew G. Knepley { 2195a8f1f9e5SMatthew G. Knepley PetscFE fe; 2196ef0bb6c7SMatthew G. Knepley PetscTabulation Tc; 2197ef0bb6c7SMatthew G. Knepley PetscInt b, c; 2198a8f1f9e5SMatthew G. Knepley 2199a8f1f9e5SMatthew G. Knepley if (!prob) return 0; 22009566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *) &fe)); 22019566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceCentroidTabulation(fe, &Tc)); 2202ef0bb6c7SMatthew G. Knepley { 2203ef0bb6c7SMatthew G. Knepley const PetscReal *faceBasis = Tc->T[0]; 2204ef0bb6c7SMatthew G. Knepley const PetscInt Nb = Tc->Nb; 2205ef0bb6c7SMatthew G. Knepley const PetscInt Nc = Tc->Nc; 2206ef0bb6c7SMatthew G. Knepley 2207a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) {u[c] = 0.0;} 2208a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2209a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2210813a933aSJed Brown u[c] += coefficients[b] * faceBasis[(faceLoc*Nb + b)*Nc + c]; 2211a8f1f9e5SMatthew G. Knepley } 2212a8f1f9e5SMatthew G. Knepley } 2213ef0bb6c7SMatthew G. Knepley } 2214a8f1f9e5SMatthew G. Knepley return 0; 2215a8f1f9e5SMatthew G. Knepley } 2216a8f1f9e5SMatthew G. Knepley 22176587ee25SMatthew G. Knepley PetscErrorCode PetscFEUpdateElementVec_Internal(PetscFE fe, PetscTabulation T, PetscInt r, PetscScalar tmpBasis[], PetscScalar tmpBasisDer[], PetscInt e, PetscFEGeom *fegeom, PetscScalar f0[], PetscScalar f1[], PetscScalar elemVec[]) 2218a8f1f9e5SMatthew G. Knepley { 22196587ee25SMatthew G. Knepley PetscFEGeom pgeom; 2220bc3a64adSMatthew G. Knepley const PetscInt dEt = T->cdim; 2221bc3a64adSMatthew G. Knepley const PetscInt dE = fegeom->dimEmbed; 2222ef0bb6c7SMatthew G. Knepley const PetscInt Nq = T->Np; 2223ef0bb6c7SMatthew G. Knepley const PetscInt Nb = T->Nb; 2224ef0bb6c7SMatthew G. Knepley const PetscInt Nc = T->Nc; 2225ef0bb6c7SMatthew G. Knepley const PetscReal *basis = &T->T[0][r*Nq*Nb*Nc]; 2226bc3a64adSMatthew G. Knepley const PetscReal *basisDer = &T->T[1][r*Nq*Nb*Nc*dEt]; 2227a8f1f9e5SMatthew G. Knepley PetscInt q, b, c, d; 2228a8f1f9e5SMatthew G. Knepley 2229a8f1f9e5SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 2230a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2231a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2232a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 2233a8f1f9e5SMatthew G. Knepley 2234a8f1f9e5SMatthew G. Knepley tmpBasis[bcidx] = basis[q*Nb*Nc+bcidx]; 2235bc3a64adSMatthew G. Knepley for (d = 0; d < dEt; ++d) tmpBasisDer[bcidx*dE+d] = basisDer[q*Nb*Nc*dEt+bcidx*dEt+d]; 22369ee2af8cSMatthew G. Knepley for (d = dEt; d < dE; ++d) tmpBasisDer[bcidx*dE+d] = 0.0; 2237a8f1f9e5SMatthew G. Knepley } 2238a8f1f9e5SMatthew G. Knepley } 22399566063dSJacob Faibussowitsch PetscCall(PetscFEGeomGetCellPoint(fegeom, e, q, &pgeom)); 22409566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, &pgeom, Nb, tmpBasis)); 22419566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, &pgeom, Nb, tmpBasisDer)); 2242a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2243a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2244a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 2245a8f1f9e5SMatthew G. Knepley const PetscInt qcidx = q*Nc+c; 2246a8f1f9e5SMatthew G. Knepley 2247a8f1f9e5SMatthew G. Knepley elemVec[b] += tmpBasis[bcidx]*f0[qcidx]; 224827f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) elemVec[b] += tmpBasisDer[bcidx*dE+d]*f1[qcidx*dE+d]; 224927f02ce8SMatthew G. Knepley } 225027f02ce8SMatthew G. Knepley } 225127f02ce8SMatthew G. Knepley } 225227f02ce8SMatthew G. Knepley return(0); 225327f02ce8SMatthew G. Knepley } 225427f02ce8SMatthew G. Knepley 2255c2b7495fSMatthew G. Knepley PetscErrorCode PetscFEUpdateElementVec_Hybrid_Internal(PetscFE fe, PetscTabulation T, PetscInt r, PetscInt s, PetscScalar tmpBasis[], PetscScalar tmpBasisDer[], PetscFEGeom *fegeom, PetscScalar f0[], PetscScalar f1[], PetscScalar elemVec[]) 225627f02ce8SMatthew G. Knepley { 225727f02ce8SMatthew G. Knepley const PetscInt dE = T->cdim; 225827f02ce8SMatthew G. Knepley const PetscInt Nq = T->Np; 225927f02ce8SMatthew G. Knepley const PetscInt Nb = T->Nb; 226027f02ce8SMatthew G. Knepley const PetscInt Nc = T->Nc; 226127f02ce8SMatthew G. Knepley const PetscReal *basis = &T->T[0][r*Nq*Nb*Nc]; 226227f02ce8SMatthew G. Knepley const PetscReal *basisDer = &T->T[1][r*Nq*Nb*Nc*dE]; 2263c2b7495fSMatthew G. Knepley PetscInt q, b, c, d; 226427f02ce8SMatthew G. Knepley 226527f02ce8SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 226627f02ce8SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 226727f02ce8SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 226827f02ce8SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 226927f02ce8SMatthew G. Knepley 227027f02ce8SMatthew G. Knepley tmpBasis[bcidx] = basis[q*Nb*Nc+bcidx]; 227127f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) tmpBasisDer[bcidx*dE+d] = basisDer[q*Nb*Nc*dE+bcidx*dE+d]; 227227f02ce8SMatthew G. Knepley } 227327f02ce8SMatthew G. Knepley } 22749566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, Nb, tmpBasis)); 22759566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, Nb, tmpBasisDer)); 227627f02ce8SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 227727f02ce8SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 227827f02ce8SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 2279c2b7495fSMatthew G. Knepley const PetscInt qcidx = q*Nc+c; 228027f02ce8SMatthew G. Knepley 228127f02ce8SMatthew G. Knepley elemVec[Nb*s+b] += tmpBasis[bcidx]*f0[qcidx]; 228227f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) elemVec[Nb*s+b] += tmpBasisDer[bcidx*dE+d]*f1[qcidx*dE+d]; 228327f02ce8SMatthew G. Knepley } 2284a8f1f9e5SMatthew G. Knepley } 2285a8f1f9e5SMatthew G. Knepley } 2286a8f1f9e5SMatthew G. Knepley return(0); 2287a8f1f9e5SMatthew G. Knepley } 2288a8f1f9e5SMatthew G. Knepley 2289ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEUpdateElementMat_Internal(PetscFE feI, PetscFE feJ, PetscInt r, PetscInt q, PetscTabulation TI, PetscScalar tmpBasisI[], PetscScalar tmpBasisDerI[], PetscTabulation TJ, PetscScalar tmpBasisJ[], PetscScalar tmpBasisDerJ[], PetscFEGeom *fegeom, const PetscScalar g0[], const PetscScalar g1[], const PetscScalar g2[], const PetscScalar g3[], PetscInt eOffset, PetscInt totDim, PetscInt offsetI, PetscInt offsetJ, PetscScalar elemMat[]) 2290a8f1f9e5SMatthew G. Knepley { 229127f02ce8SMatthew G. Knepley const PetscInt dE = TI->cdim; 2292ef0bb6c7SMatthew G. Knepley const PetscInt NqI = TI->Np; 2293ef0bb6c7SMatthew G. Knepley const PetscInt NbI = TI->Nb; 2294ef0bb6c7SMatthew G. Knepley const PetscInt NcI = TI->Nc; 2295ef0bb6c7SMatthew G. Knepley const PetscReal *basisI = &TI->T[0][(r*NqI+q)*NbI*NcI]; 2296665f567fSMatthew G. Knepley const PetscReal *basisDerI = &TI->T[1][(r*NqI+q)*NbI*NcI*dE]; 2297ef0bb6c7SMatthew G. Knepley const PetscInt NqJ = TJ->Np; 2298ef0bb6c7SMatthew G. Knepley const PetscInt NbJ = TJ->Nb; 2299ef0bb6c7SMatthew G. Knepley const PetscInt NcJ = TJ->Nc; 2300ef0bb6c7SMatthew G. Knepley const PetscReal *basisJ = &TJ->T[0][(r*NqJ+q)*NbJ*NcJ]; 2301665f567fSMatthew G. Knepley const PetscReal *basisDerJ = &TJ->T[1][(r*NqJ+q)*NbJ*NcJ*dE]; 2302a8f1f9e5SMatthew G. Knepley PetscInt f, fc, g, gc, df, dg; 2303a8f1f9e5SMatthew G. Knepley 2304a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 2305a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 2306a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 2307a8f1f9e5SMatthew G. Knepley 2308a8f1f9e5SMatthew G. Knepley tmpBasisI[fidx] = basisI[fidx]; 230927f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) tmpBasisDerI[fidx*dE+df] = basisDerI[fidx*dE+df]; 2310a8f1f9e5SMatthew G. Knepley } 2311a8f1f9e5SMatthew G. Knepley } 23129566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feI, fegeom, NbI, tmpBasisI)); 23139566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI)); 2314a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 2315a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 2316a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 2317a8f1f9e5SMatthew G. Knepley 2318a8f1f9e5SMatthew G. Knepley tmpBasisJ[gidx] = basisJ[gidx]; 231927f02ce8SMatthew G. Knepley for (dg = 0; dg < dE; ++dg) tmpBasisDerJ[gidx*dE+dg] = basisDerJ[gidx*dE+dg]; 2320a8f1f9e5SMatthew G. Knepley } 2321a8f1f9e5SMatthew G. Knepley } 23229566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ)); 23239566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ)); 2324a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 2325a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 2326a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 2327a8f1f9e5SMatthew G. Knepley const PetscInt i = offsetI+f; /* Element matrix row */ 2328a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 2329a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 2330a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 2331a8f1f9e5SMatthew G. Knepley const PetscInt j = offsetJ+g; /* Element matrix column */ 2332a8f1f9e5SMatthew G. Knepley const PetscInt fOff = eOffset+i*totDim+j; 2333a8f1f9e5SMatthew G. Knepley 2334a8f1f9e5SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g0[fc*NcJ+gc]*tmpBasisJ[gidx]; 233527f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) { 233627f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g1[(fc*NcJ+gc)*dE+df]*tmpBasisDerJ[gidx*dE+df]; 233727f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g2[(fc*NcJ+gc)*dE+df]*tmpBasisJ[gidx]; 233827f02ce8SMatthew G. Knepley for (dg = 0; dg < dE; ++dg) { 233927f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g3[((fc*NcJ+gc)*dE+df)*dE+dg]*tmpBasisDerJ[gidx*dE+dg]; 234027f02ce8SMatthew G. Knepley } 234127f02ce8SMatthew G. Knepley } 234227f02ce8SMatthew G. Knepley } 234327f02ce8SMatthew G. Knepley } 234427f02ce8SMatthew G. Knepley } 234527f02ce8SMatthew G. Knepley } 234627f02ce8SMatthew G. Knepley return(0); 234727f02ce8SMatthew G. Knepley } 234827f02ce8SMatthew G. Knepley 23495fedec97SMatthew G. Knepley PetscErrorCode PetscFEUpdateElementMat_Hybrid_Internal(PetscFE feI, PetscBool isHybridI, PetscFE feJ, PetscBool isHybridJ, PetscInt r, PetscInt s, PetscInt q, PetscTabulation TI, PetscScalar tmpBasisI[], PetscScalar tmpBasisDerI[], PetscTabulation TJ, PetscScalar tmpBasisJ[], PetscScalar tmpBasisDerJ[], PetscFEGeom *fegeom, const PetscScalar g0[], const PetscScalar g1[], const PetscScalar g2[], const PetscScalar g3[], PetscInt eOffset, PetscInt totDim, PetscInt offsetI, PetscInt offsetJ, PetscScalar elemMat[]) 235027f02ce8SMatthew G. Knepley { 2351665f567fSMatthew G. Knepley const PetscInt dE = TI->cdim; 2352665f567fSMatthew G. Knepley const PetscInt NqI = TI->Np; 2353665f567fSMatthew G. Knepley const PetscInt NbI = TI->Nb; 2354665f567fSMatthew G. Knepley const PetscInt NcI = TI->Nc; 2355665f567fSMatthew G. Knepley const PetscReal *basisI = &TI->T[0][(r*NqI+q)*NbI*NcI]; 2356665f567fSMatthew G. Knepley const PetscReal *basisDerI = &TI->T[1][(r*NqI+q)*NbI*NcI*dE]; 2357665f567fSMatthew G. Knepley const PetscInt NqJ = TJ->Np; 2358665f567fSMatthew G. Knepley const PetscInt NbJ = TJ->Nb; 2359665f567fSMatthew G. Knepley const PetscInt NcJ = TJ->Nc; 2360665f567fSMatthew G. Knepley const PetscReal *basisJ = &TJ->T[0][(r*NqJ+q)*NbJ*NcJ]; 2361665f567fSMatthew G. Knepley const PetscReal *basisDerJ = &TJ->T[1][(r*NqJ+q)*NbJ*NcJ*dE]; 23625fedec97SMatthew G. Knepley const PetscInt so = isHybridI ? 0 : s; 23635fedec97SMatthew G. Knepley const PetscInt to = isHybridJ ? 0 : s; 23645fedec97SMatthew G. Knepley PetscInt f, fc, g, gc, df, dg; 236527f02ce8SMatthew G. Knepley 236627f02ce8SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 236727f02ce8SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 236827f02ce8SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 236927f02ce8SMatthew G. Knepley 237027f02ce8SMatthew G. Knepley tmpBasisI[fidx] = basisI[fidx]; 2371665f567fSMatthew G. Knepley for (df = 0; df < dE; ++df) tmpBasisDerI[fidx*dE+df] = basisDerI[fidx*dE+df]; 237227f02ce8SMatthew G. Knepley } 237327f02ce8SMatthew G. Knepley } 23749566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feI, fegeom, NbI, tmpBasisI)); 23759566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI)); 237627f02ce8SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 237727f02ce8SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 237827f02ce8SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 237927f02ce8SMatthew G. Knepley 238027f02ce8SMatthew G. Knepley tmpBasisJ[gidx] = basisJ[gidx]; 2381665f567fSMatthew G. Knepley for (dg = 0; dg < dE; ++dg) tmpBasisDerJ[gidx*dE+dg] = basisDerJ[gidx*dE+dg]; 238227f02ce8SMatthew G. Knepley } 238327f02ce8SMatthew G. Knepley } 23849566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ)); 23859566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ)); 238627f02ce8SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 238727f02ce8SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 238827f02ce8SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 23895fedec97SMatthew G. Knepley const PetscInt i = offsetI+NbI*so+f; /* Element matrix row */ 239027f02ce8SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 239127f02ce8SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 239227f02ce8SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 23935fedec97SMatthew G. Knepley const PetscInt j = offsetJ+NbJ*to+g; /* Element matrix column */ 239427f02ce8SMatthew G. Knepley const PetscInt fOff = eOffset+i*totDim+j; 239527f02ce8SMatthew G. Knepley 23965fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g0[fc*NcJ+gc]*tmpBasisJ[gidx]; 239727f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) { 23985fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g1[(fc*NcJ+gc)*dE+df]*tmpBasisDerJ[gidx*dE+df]; 23995fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g2[(fc*NcJ+gc)*dE+df]*tmpBasisJ[gidx]; 240027f02ce8SMatthew G. Knepley for (dg = 0; dg < dE; ++dg) { 24015fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g3[((fc*NcJ+gc)*dE+df)*dE+dg]*tmpBasisDerJ[gidx*dE+dg]; 2402a8f1f9e5SMatthew G. Knepley } 2403a8f1f9e5SMatthew G. Knepley } 2404a8f1f9e5SMatthew G. Knepley } 2405a8f1f9e5SMatthew G. Knepley } 2406a8f1f9e5SMatthew G. Knepley } 2407a8f1f9e5SMatthew G. Knepley } 2408a8f1f9e5SMatthew G. Knepley return(0); 2409a8f1f9e5SMatthew G. Knepley } 2410c9ba7969SMatthew G. Knepley 2411c9ba7969SMatthew G. Knepley PetscErrorCode PetscFECreateCellGeometry(PetscFE fe, PetscQuadrature quad, PetscFEGeom *cgeom) 2412c9ba7969SMatthew G. Knepley { 2413c9ba7969SMatthew G. Knepley PetscDualSpace dsp; 2414c9ba7969SMatthew G. Knepley DM dm; 2415c9ba7969SMatthew G. Knepley PetscQuadrature quadDef; 2416c9ba7969SMatthew G. Knepley PetscInt dim, cdim, Nq; 2417c9ba7969SMatthew G. Knepley 2418c9ba7969SMatthew G. Knepley PetscFunctionBegin; 24199566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &dsp)); 24209566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp, &dm)); 24219566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 24229566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDim(dm, &cdim)); 24239566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &quadDef)); 2424c9ba7969SMatthew G. Knepley quad = quad ? quad : quadDef; 24259566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(quad, NULL, NULL, &Nq, NULL, NULL)); 24269566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq*cdim, &cgeom->v)); 24279566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq*cdim*cdim, &cgeom->J)); 24289566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq*cdim*cdim, &cgeom->invJ)); 24299566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq, &cgeom->detJ)); 2430c9ba7969SMatthew G. Knepley cgeom->dim = dim; 2431c9ba7969SMatthew G. Knepley cgeom->dimEmbed = cdim; 2432c9ba7969SMatthew G. Knepley cgeom->numCells = 1; 2433c9ba7969SMatthew G. Knepley cgeom->numPoints = Nq; 24349566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm, 0, quad, cgeom->v, cgeom->J, cgeom->invJ, cgeom->detJ)); 2435c9ba7969SMatthew G. Knepley PetscFunctionReturn(0); 2436c9ba7969SMatthew G. Knepley } 2437c9ba7969SMatthew G. Knepley 2438c9ba7969SMatthew G. Knepley PetscErrorCode PetscFEDestroyCellGeometry(PetscFE fe, PetscFEGeom *cgeom) 2439c9ba7969SMatthew G. Knepley { 2440c9ba7969SMatthew G. Knepley PetscFunctionBegin; 24419566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->v)); 24429566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->J)); 24439566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->invJ)); 24449566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->detJ)); 2445c9ba7969SMatthew G. Knepley PetscFunctionReturn(0); 2446c9ba7969SMatthew G. Knepley } 2447