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 87db781477SPatrick Sanan .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 111db781477SPatrick Sanan .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 149db781477SPatrick Sanan .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 174db781477SPatrick Sanan .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 195db781477SPatrick Sanan .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 225db781477SPatrick Sanan .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)); 2511baa6e33SBarry Smith if (fem->ops->setfromoptions) PetscCall((*fem->ops->setfromoptions)(PetscOptionsObject,fem)); 25220cf1dd8SToby Isaac /* process any options handlers added with PetscObjectAddOptionsHandler() */ 2539566063dSJacob Faibussowitsch PetscCall(PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) fem)); 254d0609cedSBarry Smith PetscOptionsEnd(); 2559566063dSJacob Faibussowitsch PetscCall(PetscFEViewFromOptions(fem, NULL, "-petscfe_view")); 25620cf1dd8SToby Isaac PetscFunctionReturn(0); 25720cf1dd8SToby Isaac } 25820cf1dd8SToby Isaac 25920cf1dd8SToby Isaac /*@C 26020cf1dd8SToby Isaac PetscFESetUp - Construct data structures for the PetscFE 26120cf1dd8SToby Isaac 262d083f849SBarry Smith Collective on fem 26320cf1dd8SToby Isaac 26420cf1dd8SToby Isaac Input Parameter: 26520cf1dd8SToby Isaac . fem - the PetscFE object to setup 26620cf1dd8SToby Isaac 2672b99622eSMatthew G. Knepley Level: intermediate 26820cf1dd8SToby Isaac 269db781477SPatrick Sanan .seealso `PetscFEView()`, `PetscFEDestroy()` 27020cf1dd8SToby Isaac @*/ 27120cf1dd8SToby Isaac PetscErrorCode PetscFESetUp(PetscFE fem) 27220cf1dd8SToby Isaac { 27320cf1dd8SToby Isaac PetscFunctionBegin; 27420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 27520cf1dd8SToby Isaac if (fem->setupcalled) PetscFunctionReturn(0); 2769566063dSJacob Faibussowitsch PetscCall(PetscLogEventBegin(PETSCFE_SetUp, fem, 0, 0, 0)); 27720cf1dd8SToby Isaac fem->setupcalled = PETSC_TRUE; 2789566063dSJacob Faibussowitsch if (fem->ops->setup) PetscCall((*fem->ops->setup)(fem)); 2799566063dSJacob Faibussowitsch PetscCall(PetscLogEventEnd(PETSCFE_SetUp, fem, 0, 0, 0)); 28020cf1dd8SToby Isaac PetscFunctionReturn(0); 28120cf1dd8SToby Isaac } 28220cf1dd8SToby Isaac 28320cf1dd8SToby Isaac /*@ 28420cf1dd8SToby Isaac PetscFEDestroy - Destroys a PetscFE object 28520cf1dd8SToby Isaac 286d083f849SBarry Smith Collective on fem 28720cf1dd8SToby Isaac 28820cf1dd8SToby Isaac Input Parameter: 28920cf1dd8SToby Isaac . fem - the PetscFE object to destroy 29020cf1dd8SToby Isaac 2912b99622eSMatthew G. Knepley Level: beginner 29220cf1dd8SToby Isaac 293db781477SPatrick Sanan .seealso `PetscFEView()` 29420cf1dd8SToby Isaac @*/ 29520cf1dd8SToby Isaac PetscErrorCode PetscFEDestroy(PetscFE *fem) 29620cf1dd8SToby Isaac { 29720cf1dd8SToby Isaac PetscFunctionBegin; 29820cf1dd8SToby Isaac if (!*fem) PetscFunctionReturn(0); 29920cf1dd8SToby Isaac PetscValidHeaderSpecific((*fem), PETSCFE_CLASSID, 1); 30020cf1dd8SToby Isaac 301ea78f98cSLisandro Dalcin if (--((PetscObject)(*fem))->refct > 0) {*fem = NULL; PetscFunctionReturn(0);} 30220cf1dd8SToby Isaac ((PetscObject) (*fem))->refct = 0; 30320cf1dd8SToby Isaac 30420cf1dd8SToby Isaac if ((*fem)->subspaces) { 30520cf1dd8SToby Isaac PetscInt dim, d; 30620cf1dd8SToby Isaac 3079566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension((*fem)->dualSpace, &dim)); 3089566063dSJacob Faibussowitsch for (d = 0; d < dim; ++d) PetscCall(PetscFEDestroy(&(*fem)->subspaces[d])); 30920cf1dd8SToby Isaac } 3109566063dSJacob Faibussowitsch PetscCall(PetscFree((*fem)->subspaces)); 3119566063dSJacob Faibussowitsch PetscCall(PetscFree((*fem)->invV)); 3129566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&(*fem)->T)); 3139566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&(*fem)->Tf)); 3149566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&(*fem)->Tc)); 3159566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&(*fem)->basisSpace)); 3169566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&(*fem)->dualSpace)); 3179566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&(*fem)->quadrature)); 3189566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&(*fem)->faceQuadrature)); 319f918ec44SMatthew G. Knepley #ifdef PETSC_HAVE_LIBCEED 3209566063dSJacob Faibussowitsch PetscCallCEED(CeedBasisDestroy(&(*fem)->ceedBasis)); 3219566063dSJacob Faibussowitsch PetscCallCEED(CeedDestroy(&(*fem)->ceed)); 322f918ec44SMatthew G. Knepley #endif 32320cf1dd8SToby Isaac 3249566063dSJacob Faibussowitsch if ((*fem)->ops->destroy) PetscCall((*(*fem)->ops->destroy)(*fem)); 3259566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(fem)); 32620cf1dd8SToby Isaac PetscFunctionReturn(0); 32720cf1dd8SToby Isaac } 32820cf1dd8SToby Isaac 32920cf1dd8SToby Isaac /*@ 33020cf1dd8SToby Isaac PetscFECreate - Creates an empty PetscFE object. The type can then be set with PetscFESetType(). 33120cf1dd8SToby Isaac 332d083f849SBarry Smith Collective 33320cf1dd8SToby Isaac 33420cf1dd8SToby Isaac Input Parameter: 33520cf1dd8SToby Isaac . comm - The communicator for the PetscFE object 33620cf1dd8SToby Isaac 33720cf1dd8SToby Isaac Output Parameter: 33820cf1dd8SToby Isaac . fem - The PetscFE object 33920cf1dd8SToby Isaac 34020cf1dd8SToby Isaac Level: beginner 34120cf1dd8SToby Isaac 342db781477SPatrick Sanan .seealso: `PetscFESetType()`, `PETSCFEGALERKIN` 34320cf1dd8SToby Isaac @*/ 34420cf1dd8SToby Isaac PetscErrorCode PetscFECreate(MPI_Comm comm, PetscFE *fem) 34520cf1dd8SToby Isaac { 34620cf1dd8SToby Isaac PetscFE f; 34720cf1dd8SToby Isaac 34820cf1dd8SToby Isaac PetscFunctionBegin; 34920cf1dd8SToby Isaac PetscValidPointer(fem, 2); 3509566063dSJacob Faibussowitsch PetscCall(PetscCitationsRegister(FECitation,&FEcite)); 35120cf1dd8SToby Isaac *fem = NULL; 3529566063dSJacob Faibussowitsch PetscCall(PetscFEInitializePackage()); 35320cf1dd8SToby Isaac 3549566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(f, PETSCFE_CLASSID, "PetscFE", "Finite Element", "PetscFE", comm, PetscFEDestroy, PetscFEView)); 35520cf1dd8SToby Isaac 35620cf1dd8SToby Isaac f->basisSpace = NULL; 35720cf1dd8SToby Isaac f->dualSpace = NULL; 35820cf1dd8SToby Isaac f->numComponents = 1; 35920cf1dd8SToby Isaac f->subspaces = NULL; 36020cf1dd8SToby Isaac f->invV = NULL; 361ef0bb6c7SMatthew G. Knepley f->T = NULL; 362ef0bb6c7SMatthew G. Knepley f->Tf = NULL; 363ef0bb6c7SMatthew G. Knepley f->Tc = NULL; 3649566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(&f->quadrature, 1)); 3659566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(&f->faceQuadrature, 1)); 36620cf1dd8SToby Isaac f->blockSize = 0; 36720cf1dd8SToby Isaac f->numBlocks = 1; 36820cf1dd8SToby Isaac f->batchSize = 0; 36920cf1dd8SToby Isaac f->numBatches = 1; 37020cf1dd8SToby Isaac 37120cf1dd8SToby Isaac *fem = f; 37220cf1dd8SToby Isaac PetscFunctionReturn(0); 37320cf1dd8SToby Isaac } 37420cf1dd8SToby Isaac 37520cf1dd8SToby Isaac /*@ 37620cf1dd8SToby Isaac PetscFEGetSpatialDimension - Returns the spatial dimension of the element 37720cf1dd8SToby Isaac 37820cf1dd8SToby Isaac Not collective 37920cf1dd8SToby Isaac 38020cf1dd8SToby Isaac Input Parameter: 38120cf1dd8SToby Isaac . fem - The PetscFE object 38220cf1dd8SToby Isaac 38320cf1dd8SToby Isaac Output Parameter: 38420cf1dd8SToby Isaac . dim - The spatial dimension 38520cf1dd8SToby Isaac 38620cf1dd8SToby Isaac Level: intermediate 38720cf1dd8SToby Isaac 388db781477SPatrick Sanan .seealso: `PetscFECreate()` 38920cf1dd8SToby Isaac @*/ 39020cf1dd8SToby Isaac PetscErrorCode PetscFEGetSpatialDimension(PetscFE fem, PetscInt *dim) 39120cf1dd8SToby Isaac { 39220cf1dd8SToby Isaac DM dm; 39320cf1dd8SToby Isaac 39420cf1dd8SToby Isaac PetscFunctionBegin; 39520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 396dadcf809SJacob Faibussowitsch PetscValidIntPointer(dim, 2); 3979566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(fem->dualSpace, &dm)); 3989566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, dim)); 39920cf1dd8SToby Isaac PetscFunctionReturn(0); 40020cf1dd8SToby Isaac } 40120cf1dd8SToby Isaac 40220cf1dd8SToby Isaac /*@ 40320cf1dd8SToby Isaac PetscFESetNumComponents - Sets the number of components in the element 40420cf1dd8SToby Isaac 40520cf1dd8SToby Isaac Not collective 40620cf1dd8SToby Isaac 40720cf1dd8SToby Isaac Input Parameters: 40820cf1dd8SToby Isaac + fem - The PetscFE object 40920cf1dd8SToby Isaac - comp - The number of field components 41020cf1dd8SToby Isaac 41120cf1dd8SToby Isaac Level: intermediate 41220cf1dd8SToby Isaac 413db781477SPatrick Sanan .seealso: `PetscFECreate()` 41420cf1dd8SToby Isaac @*/ 41520cf1dd8SToby Isaac PetscErrorCode PetscFESetNumComponents(PetscFE fem, PetscInt comp) 41620cf1dd8SToby Isaac { 41720cf1dd8SToby Isaac PetscFunctionBegin; 41820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 41920cf1dd8SToby Isaac fem->numComponents = comp; 42020cf1dd8SToby Isaac PetscFunctionReturn(0); 42120cf1dd8SToby Isaac } 42220cf1dd8SToby Isaac 42320cf1dd8SToby Isaac /*@ 42420cf1dd8SToby Isaac PetscFEGetNumComponents - Returns the number of components in the element 42520cf1dd8SToby Isaac 42620cf1dd8SToby Isaac Not collective 42720cf1dd8SToby Isaac 42820cf1dd8SToby Isaac Input Parameter: 42920cf1dd8SToby Isaac . fem - The PetscFE object 43020cf1dd8SToby Isaac 43120cf1dd8SToby Isaac Output Parameter: 43220cf1dd8SToby Isaac . comp - The number of field components 43320cf1dd8SToby Isaac 43420cf1dd8SToby Isaac Level: intermediate 43520cf1dd8SToby Isaac 436db781477SPatrick Sanan .seealso: `PetscFECreate()` 43720cf1dd8SToby Isaac @*/ 43820cf1dd8SToby Isaac PetscErrorCode PetscFEGetNumComponents(PetscFE fem, PetscInt *comp) 43920cf1dd8SToby Isaac { 44020cf1dd8SToby Isaac PetscFunctionBegin; 44120cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 442dadcf809SJacob Faibussowitsch PetscValidIntPointer(comp, 2); 44320cf1dd8SToby Isaac *comp = fem->numComponents; 44420cf1dd8SToby Isaac PetscFunctionReturn(0); 44520cf1dd8SToby Isaac } 44620cf1dd8SToby Isaac 44720cf1dd8SToby Isaac /*@ 44820cf1dd8SToby Isaac PetscFESetTileSizes - Sets the tile sizes for evaluation 44920cf1dd8SToby Isaac 45020cf1dd8SToby Isaac Not collective 45120cf1dd8SToby Isaac 45220cf1dd8SToby Isaac Input Parameters: 45320cf1dd8SToby Isaac + fem - The PetscFE object 45420cf1dd8SToby Isaac . blockSize - The number of elements in a block 45520cf1dd8SToby Isaac . numBlocks - The number of blocks in a batch 45620cf1dd8SToby Isaac . batchSize - The number of elements in a batch 45720cf1dd8SToby Isaac - numBatches - The number of batches in a chunk 45820cf1dd8SToby Isaac 45920cf1dd8SToby Isaac Level: intermediate 46020cf1dd8SToby Isaac 461db781477SPatrick Sanan .seealso: `PetscFECreate()` 46220cf1dd8SToby Isaac @*/ 46320cf1dd8SToby Isaac PetscErrorCode PetscFESetTileSizes(PetscFE fem, PetscInt blockSize, PetscInt numBlocks, PetscInt batchSize, PetscInt numBatches) 46420cf1dd8SToby Isaac { 46520cf1dd8SToby Isaac PetscFunctionBegin; 46620cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 46720cf1dd8SToby Isaac fem->blockSize = blockSize; 46820cf1dd8SToby Isaac fem->numBlocks = numBlocks; 46920cf1dd8SToby Isaac fem->batchSize = batchSize; 47020cf1dd8SToby Isaac fem->numBatches = numBatches; 47120cf1dd8SToby Isaac PetscFunctionReturn(0); 47220cf1dd8SToby Isaac } 47320cf1dd8SToby Isaac 47420cf1dd8SToby Isaac /*@ 47520cf1dd8SToby Isaac PetscFEGetTileSizes - Returns the tile sizes for evaluation 47620cf1dd8SToby Isaac 47720cf1dd8SToby Isaac Not collective 47820cf1dd8SToby Isaac 47920cf1dd8SToby Isaac Input Parameter: 48020cf1dd8SToby Isaac . fem - The PetscFE object 48120cf1dd8SToby Isaac 48220cf1dd8SToby Isaac Output Parameters: 48320cf1dd8SToby Isaac + blockSize - The number of elements in a block 48420cf1dd8SToby Isaac . numBlocks - The number of blocks in a batch 48520cf1dd8SToby Isaac . batchSize - The number of elements in a batch 48620cf1dd8SToby Isaac - numBatches - The number of batches in a chunk 48720cf1dd8SToby Isaac 48820cf1dd8SToby Isaac Level: intermediate 48920cf1dd8SToby Isaac 490db781477SPatrick Sanan .seealso: `PetscFECreate()` 49120cf1dd8SToby Isaac @*/ 49220cf1dd8SToby Isaac PetscErrorCode PetscFEGetTileSizes(PetscFE fem, PetscInt *blockSize, PetscInt *numBlocks, PetscInt *batchSize, PetscInt *numBatches) 49320cf1dd8SToby Isaac { 49420cf1dd8SToby Isaac PetscFunctionBegin; 49520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 496dadcf809SJacob Faibussowitsch if (blockSize) PetscValidIntPointer(blockSize, 2); 497dadcf809SJacob Faibussowitsch if (numBlocks) PetscValidIntPointer(numBlocks, 3); 498dadcf809SJacob Faibussowitsch if (batchSize) PetscValidIntPointer(batchSize, 4); 499dadcf809SJacob Faibussowitsch if (numBatches) PetscValidIntPointer(numBatches, 5); 50020cf1dd8SToby Isaac if (blockSize) *blockSize = fem->blockSize; 50120cf1dd8SToby Isaac if (numBlocks) *numBlocks = fem->numBlocks; 50220cf1dd8SToby Isaac if (batchSize) *batchSize = fem->batchSize; 50320cf1dd8SToby Isaac if (numBatches) *numBatches = fem->numBatches; 50420cf1dd8SToby Isaac PetscFunctionReturn(0); 50520cf1dd8SToby Isaac } 50620cf1dd8SToby Isaac 50720cf1dd8SToby Isaac /*@ 50820cf1dd8SToby Isaac PetscFEGetBasisSpace - Returns the PetscSpace used for approximation of the solution 50920cf1dd8SToby Isaac 51020cf1dd8SToby Isaac Not collective 51120cf1dd8SToby Isaac 51220cf1dd8SToby Isaac Input Parameter: 51320cf1dd8SToby Isaac . fem - The PetscFE object 51420cf1dd8SToby Isaac 51520cf1dd8SToby Isaac Output Parameter: 51620cf1dd8SToby Isaac . sp - The PetscSpace object 51720cf1dd8SToby Isaac 51820cf1dd8SToby Isaac Level: intermediate 51920cf1dd8SToby Isaac 520db781477SPatrick Sanan .seealso: `PetscFECreate()` 52120cf1dd8SToby Isaac @*/ 52220cf1dd8SToby Isaac PetscErrorCode PetscFEGetBasisSpace(PetscFE fem, PetscSpace *sp) 52320cf1dd8SToby Isaac { 52420cf1dd8SToby Isaac PetscFunctionBegin; 52520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 52620cf1dd8SToby Isaac PetscValidPointer(sp, 2); 52720cf1dd8SToby Isaac *sp = fem->basisSpace; 52820cf1dd8SToby Isaac PetscFunctionReturn(0); 52920cf1dd8SToby Isaac } 53020cf1dd8SToby Isaac 53120cf1dd8SToby Isaac /*@ 53220cf1dd8SToby Isaac PetscFESetBasisSpace - Sets the PetscSpace used for approximation of the solution 53320cf1dd8SToby Isaac 53420cf1dd8SToby Isaac Not collective 53520cf1dd8SToby Isaac 53620cf1dd8SToby Isaac Input Parameters: 53720cf1dd8SToby Isaac + fem - The PetscFE object 53820cf1dd8SToby Isaac - sp - The PetscSpace object 53920cf1dd8SToby Isaac 54020cf1dd8SToby Isaac Level: intermediate 54120cf1dd8SToby Isaac 542db781477SPatrick Sanan .seealso: `PetscFECreate()` 54320cf1dd8SToby Isaac @*/ 54420cf1dd8SToby Isaac PetscErrorCode PetscFESetBasisSpace(PetscFE fem, PetscSpace sp) 54520cf1dd8SToby Isaac { 54620cf1dd8SToby Isaac PetscFunctionBegin; 54720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 54820cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 2); 5499566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&fem->basisSpace)); 55020cf1dd8SToby Isaac fem->basisSpace = sp; 5519566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) fem->basisSpace)); 55220cf1dd8SToby Isaac PetscFunctionReturn(0); 55320cf1dd8SToby Isaac } 55420cf1dd8SToby Isaac 55520cf1dd8SToby Isaac /*@ 55620cf1dd8SToby Isaac PetscFEGetDualSpace - Returns the PetscDualSpace used to define the inner product 55720cf1dd8SToby Isaac 55820cf1dd8SToby Isaac Not collective 55920cf1dd8SToby Isaac 56020cf1dd8SToby Isaac Input Parameter: 56120cf1dd8SToby Isaac . fem - The PetscFE object 56220cf1dd8SToby Isaac 56320cf1dd8SToby Isaac Output Parameter: 56420cf1dd8SToby Isaac . sp - The PetscDualSpace object 56520cf1dd8SToby Isaac 56620cf1dd8SToby Isaac Level: intermediate 56720cf1dd8SToby Isaac 568db781477SPatrick Sanan .seealso: `PetscFECreate()` 56920cf1dd8SToby Isaac @*/ 57020cf1dd8SToby Isaac PetscErrorCode PetscFEGetDualSpace(PetscFE fem, PetscDualSpace *sp) 57120cf1dd8SToby Isaac { 57220cf1dd8SToby Isaac PetscFunctionBegin; 57320cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 57420cf1dd8SToby Isaac PetscValidPointer(sp, 2); 57520cf1dd8SToby Isaac *sp = fem->dualSpace; 57620cf1dd8SToby Isaac PetscFunctionReturn(0); 57720cf1dd8SToby Isaac } 57820cf1dd8SToby Isaac 57920cf1dd8SToby Isaac /*@ 58020cf1dd8SToby Isaac PetscFESetDualSpace - Sets the PetscDualSpace used to define the inner product 58120cf1dd8SToby Isaac 58220cf1dd8SToby Isaac Not collective 58320cf1dd8SToby Isaac 58420cf1dd8SToby Isaac Input Parameters: 58520cf1dd8SToby Isaac + fem - The PetscFE object 58620cf1dd8SToby Isaac - sp - The PetscDualSpace object 58720cf1dd8SToby Isaac 58820cf1dd8SToby Isaac Level: intermediate 58920cf1dd8SToby Isaac 590db781477SPatrick Sanan .seealso: `PetscFECreate()` 59120cf1dd8SToby Isaac @*/ 59220cf1dd8SToby Isaac PetscErrorCode PetscFESetDualSpace(PetscFE fem, PetscDualSpace sp) 59320cf1dd8SToby Isaac { 59420cf1dd8SToby Isaac PetscFunctionBegin; 59520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 59620cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 2); 5979566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&fem->dualSpace)); 59820cf1dd8SToby Isaac fem->dualSpace = sp; 5999566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) fem->dualSpace)); 60020cf1dd8SToby Isaac PetscFunctionReturn(0); 60120cf1dd8SToby Isaac } 60220cf1dd8SToby Isaac 60320cf1dd8SToby Isaac /*@ 60420cf1dd8SToby Isaac PetscFEGetQuadrature - Returns the PetscQuadrature used to calculate inner products 60520cf1dd8SToby Isaac 60620cf1dd8SToby Isaac Not collective 60720cf1dd8SToby Isaac 60820cf1dd8SToby Isaac Input Parameter: 60920cf1dd8SToby Isaac . fem - The PetscFE object 61020cf1dd8SToby Isaac 61120cf1dd8SToby Isaac Output Parameter: 61220cf1dd8SToby Isaac . q - The PetscQuadrature object 61320cf1dd8SToby Isaac 61420cf1dd8SToby Isaac Level: intermediate 61520cf1dd8SToby Isaac 616db781477SPatrick Sanan .seealso: `PetscFECreate()` 61720cf1dd8SToby Isaac @*/ 61820cf1dd8SToby Isaac PetscErrorCode PetscFEGetQuadrature(PetscFE fem, PetscQuadrature *q) 61920cf1dd8SToby Isaac { 62020cf1dd8SToby Isaac PetscFunctionBegin; 62120cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 62220cf1dd8SToby Isaac PetscValidPointer(q, 2); 62320cf1dd8SToby Isaac *q = fem->quadrature; 62420cf1dd8SToby Isaac PetscFunctionReturn(0); 62520cf1dd8SToby Isaac } 62620cf1dd8SToby Isaac 62720cf1dd8SToby Isaac /*@ 62820cf1dd8SToby Isaac PetscFESetQuadrature - Sets the PetscQuadrature used to calculate inner products 62920cf1dd8SToby Isaac 63020cf1dd8SToby Isaac Not collective 63120cf1dd8SToby Isaac 63220cf1dd8SToby Isaac Input Parameters: 63320cf1dd8SToby Isaac + fem - The PetscFE object 63420cf1dd8SToby Isaac - q - The PetscQuadrature object 63520cf1dd8SToby Isaac 63620cf1dd8SToby Isaac Level: intermediate 63720cf1dd8SToby Isaac 638db781477SPatrick Sanan .seealso: `PetscFECreate()` 63920cf1dd8SToby Isaac @*/ 64020cf1dd8SToby Isaac PetscErrorCode PetscFESetQuadrature(PetscFE fem, PetscQuadrature q) 64120cf1dd8SToby Isaac { 64220cf1dd8SToby Isaac PetscInt Nc, qNc; 64320cf1dd8SToby Isaac 64420cf1dd8SToby Isaac PetscFunctionBegin; 64520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 646fd2fdbddSMatthew G. Knepley if (q == fem->quadrature) PetscFunctionReturn(0); 6479566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 6489566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetNumComponents(q, &qNc)); 64963a3b9bcSJacob 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); 6509566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&fem->T)); 6519566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&fem->Tc)); 6529566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) q)); 6539566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&fem->quadrature)); 65420cf1dd8SToby Isaac fem->quadrature = q; 65520cf1dd8SToby Isaac PetscFunctionReturn(0); 65620cf1dd8SToby Isaac } 65720cf1dd8SToby Isaac 65820cf1dd8SToby Isaac /*@ 65920cf1dd8SToby Isaac PetscFEGetFaceQuadrature - Returns the PetscQuadrature used to calculate inner products on faces 66020cf1dd8SToby Isaac 66120cf1dd8SToby Isaac Not collective 66220cf1dd8SToby Isaac 66320cf1dd8SToby Isaac Input Parameter: 66420cf1dd8SToby Isaac . fem - The PetscFE object 66520cf1dd8SToby Isaac 66620cf1dd8SToby Isaac Output Parameter: 66720cf1dd8SToby Isaac . q - The PetscQuadrature object 66820cf1dd8SToby Isaac 66920cf1dd8SToby Isaac Level: intermediate 67020cf1dd8SToby Isaac 671db781477SPatrick Sanan .seealso: `PetscFECreate()` 67220cf1dd8SToby Isaac @*/ 67320cf1dd8SToby Isaac PetscErrorCode PetscFEGetFaceQuadrature(PetscFE fem, PetscQuadrature *q) 67420cf1dd8SToby Isaac { 67520cf1dd8SToby Isaac PetscFunctionBegin; 67620cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 67720cf1dd8SToby Isaac PetscValidPointer(q, 2); 67820cf1dd8SToby Isaac *q = fem->faceQuadrature; 67920cf1dd8SToby Isaac PetscFunctionReturn(0); 68020cf1dd8SToby Isaac } 68120cf1dd8SToby Isaac 68220cf1dd8SToby Isaac /*@ 68320cf1dd8SToby Isaac PetscFESetFaceQuadrature - Sets the PetscQuadrature used to calculate inner products on faces 68420cf1dd8SToby Isaac 68520cf1dd8SToby Isaac Not collective 68620cf1dd8SToby Isaac 68720cf1dd8SToby Isaac Input Parameters: 68820cf1dd8SToby Isaac + fem - The PetscFE object 68920cf1dd8SToby Isaac - q - The PetscQuadrature object 69020cf1dd8SToby Isaac 69120cf1dd8SToby Isaac Level: intermediate 69220cf1dd8SToby Isaac 693db781477SPatrick Sanan .seealso: `PetscFECreate()` 69420cf1dd8SToby Isaac @*/ 69520cf1dd8SToby Isaac PetscErrorCode PetscFESetFaceQuadrature(PetscFE fem, PetscQuadrature q) 69620cf1dd8SToby Isaac { 697ef0bb6c7SMatthew G. Knepley PetscInt Nc, qNc; 69820cf1dd8SToby Isaac 69920cf1dd8SToby Isaac PetscFunctionBegin; 70020cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 7019566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 7029566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetNumComponents(q, &qNc)); 70363a3b9bcSJacob 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); 7049566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&fem->Tf)); 7059566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&fem->faceQuadrature)); 70620cf1dd8SToby Isaac fem->faceQuadrature = q; 7079566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) q)); 70820cf1dd8SToby Isaac PetscFunctionReturn(0); 70920cf1dd8SToby Isaac } 71020cf1dd8SToby Isaac 7115dc5c000SMatthew G. Knepley /*@ 7125dc5c000SMatthew G. Knepley PetscFECopyQuadrature - Copy both volumetric and surface quadrature 7135dc5c000SMatthew G. Knepley 7145dc5c000SMatthew G. Knepley Not collective 7155dc5c000SMatthew G. Knepley 7165dc5c000SMatthew G. Knepley Input Parameters: 7175dc5c000SMatthew G. Knepley + sfe - The PetscFE source for the quadratures 7185dc5c000SMatthew G. Knepley - tfe - The PetscFE target for the quadratures 7195dc5c000SMatthew G. Knepley 7205dc5c000SMatthew G. Knepley Level: intermediate 7215dc5c000SMatthew G. Knepley 722db781477SPatrick Sanan .seealso: `PetscFECreate()`, `PetscFESetQuadrature()`, `PetscFESetFaceQuadrature()` 7235dc5c000SMatthew G. Knepley @*/ 7245dc5c000SMatthew G. Knepley PetscErrorCode PetscFECopyQuadrature(PetscFE sfe, PetscFE tfe) 7255dc5c000SMatthew G. Knepley { 7265dc5c000SMatthew G. Knepley PetscQuadrature q; 7275dc5c000SMatthew G. Knepley 7285dc5c000SMatthew G. Knepley PetscFunctionBegin; 7295dc5c000SMatthew G. Knepley PetscValidHeaderSpecific(sfe, PETSCFE_CLASSID, 1); 7305dc5c000SMatthew G. Knepley PetscValidHeaderSpecific(tfe, PETSCFE_CLASSID, 2); 7319566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(sfe, &q)); 7329566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(tfe, q)); 7339566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(sfe, &q)); 7349566063dSJacob Faibussowitsch PetscCall(PetscFESetFaceQuadrature(tfe, q)); 7355dc5c000SMatthew G. Knepley PetscFunctionReturn(0); 7365dc5c000SMatthew G. Knepley } 7375dc5c000SMatthew G. Knepley 73820cf1dd8SToby Isaac /*@C 73920cf1dd8SToby Isaac PetscFEGetNumDof - Returns the number of dofs (dual basis vectors) associated to mesh points on the reference cell of a given dimension 74020cf1dd8SToby Isaac 74120cf1dd8SToby Isaac Not collective 74220cf1dd8SToby Isaac 74320cf1dd8SToby Isaac Input Parameter: 74420cf1dd8SToby Isaac . fem - The PetscFE object 74520cf1dd8SToby Isaac 74620cf1dd8SToby Isaac Output Parameter: 74720cf1dd8SToby Isaac . numDof - Array with the number of dofs per dimension 74820cf1dd8SToby Isaac 74920cf1dd8SToby Isaac Level: intermediate 75020cf1dd8SToby Isaac 751db781477SPatrick Sanan .seealso: `PetscFECreate()` 75220cf1dd8SToby Isaac @*/ 75320cf1dd8SToby Isaac PetscErrorCode PetscFEGetNumDof(PetscFE fem, const PetscInt **numDof) 75420cf1dd8SToby Isaac { 75520cf1dd8SToby Isaac PetscFunctionBegin; 75620cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 75720cf1dd8SToby Isaac PetscValidPointer(numDof, 2); 7589566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetNumDof(fem->dualSpace, numDof)); 75920cf1dd8SToby Isaac PetscFunctionReturn(0); 76020cf1dd8SToby Isaac } 76120cf1dd8SToby Isaac 76220cf1dd8SToby Isaac /*@C 763ef0bb6c7SMatthew G. Knepley PetscFEGetCellTabulation - Returns the tabulation of the basis functions at the quadrature points on the reference cell 76420cf1dd8SToby Isaac 76520cf1dd8SToby Isaac Not collective 76620cf1dd8SToby Isaac 767d8d19677SJose E. Roman Input Parameters: 768f9244615SMatthew G. Knepley + fem - The PetscFE object 769f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate, very often 1 77020cf1dd8SToby Isaac 771ef0bb6c7SMatthew G. Knepley Output Parameter: 772ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at quadrature points 77320cf1dd8SToby Isaac 77420cf1dd8SToby Isaac Note: 775ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 776ef0bb6c7SMatthew 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 777ef0bb6c7SMatthew 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 77820cf1dd8SToby Isaac 77920cf1dd8SToby Isaac Level: intermediate 78020cf1dd8SToby Isaac 781db781477SPatrick Sanan .seealso: `PetscFECreateTabulation()`, `PetscTabulationDestroy()` 78220cf1dd8SToby Isaac @*/ 783f9244615SMatthew G. Knepley PetscErrorCode PetscFEGetCellTabulation(PetscFE fem, PetscInt k, PetscTabulation *T) 78420cf1dd8SToby Isaac { 78520cf1dd8SToby Isaac PetscInt npoints; 78620cf1dd8SToby Isaac const PetscReal *points; 78720cf1dd8SToby Isaac 78820cf1dd8SToby Isaac PetscFunctionBegin; 78920cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 790064a246eSJacob Faibussowitsch PetscValidPointer(T, 3); 7919566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(fem->quadrature, NULL, NULL, &npoints, &points, NULL)); 7929566063dSJacob Faibussowitsch if (!fem->T) PetscCall(PetscFECreateTabulation(fem, 1, npoints, points, k, &fem->T)); 7931dca8a05SBarry 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); 794ef0bb6c7SMatthew G. Knepley *T = fem->T; 79520cf1dd8SToby Isaac PetscFunctionReturn(0); 79620cf1dd8SToby Isaac } 79720cf1dd8SToby Isaac 7982b99622eSMatthew G. Knepley /*@C 799ef0bb6c7SMatthew G. Knepley PetscFEGetFaceTabulation - Returns the tabulation of the basis functions at the face quadrature points for each face of the reference cell 8002b99622eSMatthew G. Knepley 8012b99622eSMatthew G. Knepley Not collective 8022b99622eSMatthew G. Knepley 803d8d19677SJose E. Roman Input Parameters: 804f9244615SMatthew G. Knepley + fem - The PetscFE object 805f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate, very often 1 8062b99622eSMatthew G. Knepley 8072b99622eSMatthew G. Knepley Output Parameters: 808a5b23f4aSJose E. Roman . Tf - The basis function values and derivatives at face quadrature points 8092b99622eSMatthew G. Knepley 8102b99622eSMatthew G. Knepley Note: 811ef0bb6c7SMatthew 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 812ef0bb6c7SMatthew 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 813ef0bb6c7SMatthew 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 8142b99622eSMatthew G. Knepley 8152b99622eSMatthew G. Knepley Level: intermediate 8162b99622eSMatthew G. Knepley 817db781477SPatrick Sanan .seealso: `PetscFEGetCellTabulation()`, `PetscFECreateTabulation()`, `PetscTabulationDestroy()` 8182b99622eSMatthew G. Knepley @*/ 819f9244615SMatthew G. Knepley PetscErrorCode PetscFEGetFaceTabulation(PetscFE fem, PetscInt k, PetscTabulation *Tf) 82020cf1dd8SToby Isaac { 82120cf1dd8SToby Isaac PetscFunctionBegin; 82220cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 823064a246eSJacob Faibussowitsch PetscValidPointer(Tf, 3); 824ef0bb6c7SMatthew G. Knepley if (!fem->Tf) { 82520cf1dd8SToby Isaac const PetscReal xi0[3] = {-1., -1., -1.}; 82620cf1dd8SToby Isaac PetscReal v0[3], J[9], detJ; 82720cf1dd8SToby Isaac PetscQuadrature fq; 82820cf1dd8SToby Isaac PetscDualSpace sp; 82920cf1dd8SToby Isaac DM dm; 83020cf1dd8SToby Isaac const PetscInt *faces; 83120cf1dd8SToby Isaac PetscInt dim, numFaces, f, npoints, q; 83220cf1dd8SToby Isaac const PetscReal *points; 83320cf1dd8SToby Isaac PetscReal *facePoints; 83420cf1dd8SToby Isaac 8359566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &sp)); 8369566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(sp, &dm)); 8379566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 8389566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, 0, &numFaces)); 8399566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(dm, 0, &faces)); 8409566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(fem, &fq)); 84120cf1dd8SToby Isaac if (fq) { 8429566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(fq, NULL, NULL, &npoints, &points, NULL)); 8439566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numFaces*npoints*dim, &facePoints)); 84420cf1dd8SToby Isaac for (f = 0; f < numFaces; ++f) { 8459566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm, faces[f], NULL, v0, J, NULL, &detJ)); 84620cf1dd8SToby Isaac for (q = 0; q < npoints; ++q) CoordinatesRefToReal(dim, dim-1, xi0, v0, J, &points[q*(dim-1)], &facePoints[(f*npoints+q)*dim]); 84720cf1dd8SToby Isaac } 8489566063dSJacob Faibussowitsch PetscCall(PetscFECreateTabulation(fem, numFaces, npoints, facePoints, k, &fem->Tf)); 8499566063dSJacob Faibussowitsch PetscCall(PetscFree(facePoints)); 85020cf1dd8SToby Isaac } 85120cf1dd8SToby Isaac } 8521dca8a05SBarry 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); 853ef0bb6c7SMatthew G. Knepley *Tf = fem->Tf; 85420cf1dd8SToby Isaac PetscFunctionReturn(0); 85520cf1dd8SToby Isaac } 85620cf1dd8SToby Isaac 8572b99622eSMatthew G. Knepley /*@C 858ef0bb6c7SMatthew G. Knepley PetscFEGetFaceCentroidTabulation - Returns the tabulation of the basis functions at the face centroid points 8592b99622eSMatthew G. Knepley 8602b99622eSMatthew G. Knepley Not collective 8612b99622eSMatthew G. Knepley 8622b99622eSMatthew G. Knepley Input Parameter: 8632b99622eSMatthew G. Knepley . fem - The PetscFE object 8642b99622eSMatthew G. Knepley 8652b99622eSMatthew G. Knepley Output Parameters: 866ef0bb6c7SMatthew G. Knepley . Tc - The basis function values at face centroid points 8672b99622eSMatthew G. Knepley 8682b99622eSMatthew G. Knepley Note: 869ef0bb6c7SMatthew G. Knepley $ T->T[0] = Bf[(f*pdim + i)*Nc + c] is the value at point f for basis function i and component c 8702b99622eSMatthew G. Knepley 8712b99622eSMatthew G. Knepley Level: intermediate 8722b99622eSMatthew G. Knepley 873db781477SPatrick Sanan .seealso: `PetscFEGetFaceTabulation()`, `PetscFEGetCellTabulation()`, `PetscFECreateTabulation()`, `PetscTabulationDestroy()` 8742b99622eSMatthew G. Knepley @*/ 875ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEGetFaceCentroidTabulation(PetscFE fem, PetscTabulation *Tc) 87620cf1dd8SToby Isaac { 87720cf1dd8SToby Isaac PetscFunctionBegin; 87820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 879ef0bb6c7SMatthew G. Knepley PetscValidPointer(Tc, 2); 880ef0bb6c7SMatthew G. Knepley if (!fem->Tc) { 88120cf1dd8SToby Isaac PetscDualSpace sp; 88220cf1dd8SToby Isaac DM dm; 88320cf1dd8SToby Isaac const PetscInt *cone; 88420cf1dd8SToby Isaac PetscReal *centroids; 88520cf1dd8SToby Isaac PetscInt dim, numFaces, f; 88620cf1dd8SToby Isaac 8879566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &sp)); 8889566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(sp, &dm)); 8899566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 8909566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, 0, &numFaces)); 8919566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(dm, 0, &cone)); 8929566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numFaces*dim, ¢roids)); 8939566063dSJacob Faibussowitsch for (f = 0; f < numFaces; ++f) PetscCall(DMPlexComputeCellGeometryFVM(dm, cone[f], NULL, ¢roids[f*dim], NULL)); 8949566063dSJacob Faibussowitsch PetscCall(PetscFECreateTabulation(fem, 1, numFaces, centroids, 0, &fem->Tc)); 8959566063dSJacob Faibussowitsch PetscCall(PetscFree(centroids)); 89620cf1dd8SToby Isaac } 897ef0bb6c7SMatthew G. Knepley *Tc = fem->Tc; 89820cf1dd8SToby Isaac PetscFunctionReturn(0); 89920cf1dd8SToby Isaac } 90020cf1dd8SToby Isaac 90120cf1dd8SToby Isaac /*@C 902ef0bb6c7SMatthew G. Knepley PetscFECreateTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided. 90320cf1dd8SToby Isaac 90420cf1dd8SToby Isaac Not collective 90520cf1dd8SToby Isaac 90620cf1dd8SToby Isaac Input Parameters: 90720cf1dd8SToby Isaac + fem - The PetscFE object 908ef0bb6c7SMatthew G. Knepley . nrepl - The number of replicas 909ef0bb6c7SMatthew G. Knepley . npoints - The number of tabulation points in a replica 910ef0bb6c7SMatthew G. Knepley . points - The tabulation point coordinates 911ef0bb6c7SMatthew G. Knepley - K - The number of derivatives calculated 91220cf1dd8SToby Isaac 913ef0bb6c7SMatthew G. Knepley Output Parameter: 914ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at tabulation points 91520cf1dd8SToby Isaac 91620cf1dd8SToby Isaac Note: 917ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 918ef0bb6c7SMatthew 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 919ef0bb6c7SMatthew 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 92020cf1dd8SToby Isaac 92120cf1dd8SToby Isaac Level: intermediate 92220cf1dd8SToby Isaac 923db781477SPatrick Sanan .seealso: `PetscFEGetCellTabulation()`, `PetscTabulationDestroy()` 92420cf1dd8SToby Isaac @*/ 925ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFECreateTabulation(PetscFE fem, PetscInt nrepl, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation *T) 92620cf1dd8SToby Isaac { 92720cf1dd8SToby Isaac DM dm; 928ef0bb6c7SMatthew G. Knepley PetscDualSpace Q; 929ef0bb6c7SMatthew G. Knepley PetscInt Nb; /* Dimension of FE space P */ 930ef0bb6c7SMatthew G. Knepley PetscInt Nc; /* Field components */ 931ef0bb6c7SMatthew G. Knepley PetscInt cdim; /* Reference coordinate dimension */ 932ef0bb6c7SMatthew G. Knepley PetscInt k; 93320cf1dd8SToby Isaac 93420cf1dd8SToby Isaac PetscFunctionBegin; 935ef0bb6c7SMatthew G. Knepley if (!npoints || !fem->dualSpace || K < 0) { 936ef0bb6c7SMatthew G. Knepley *T = NULL; 93720cf1dd8SToby Isaac PetscFunctionReturn(0); 93820cf1dd8SToby Isaac } 93920cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 940dadcf809SJacob Faibussowitsch PetscValidRealPointer(points, 4); 94140a2aa30SMatthew G. Knepley PetscValidPointer(T, 6); 9429566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &Q)); 9439566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &dm)); 9449566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &cdim)); 9459566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &Nb)); 9469566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 9479566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(1, T)); 948ef0bb6c7SMatthew G. Knepley (*T)->K = !cdim ? 0 : K; 949ef0bb6c7SMatthew G. Knepley (*T)->Nr = nrepl; 950ef0bb6c7SMatthew G. Knepley (*T)->Np = npoints; 951ef0bb6c7SMatthew G. Knepley (*T)->Nb = Nb; 952ef0bb6c7SMatthew G. Knepley (*T)->Nc = Nc; 953ef0bb6c7SMatthew G. Knepley (*T)->cdim = cdim; 9549566063dSJacob Faibussowitsch PetscCall(PetscMalloc1((*T)->K+1, &(*T)->T)); 955ef0bb6c7SMatthew G. Knepley for (k = 0; k <= (*T)->K; ++k) { 9569566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(nrepl*npoints*Nb*Nc*PetscPowInt(cdim, k), &(*T)->T[k])); 95720cf1dd8SToby Isaac } 9589566063dSJacob Faibussowitsch PetscCall((*fem->ops->createtabulation)(fem, nrepl*npoints, points, K, *T)); 95920cf1dd8SToby Isaac PetscFunctionReturn(0); 96020cf1dd8SToby Isaac } 96120cf1dd8SToby Isaac 9622b99622eSMatthew G. Knepley /*@C 963ef0bb6c7SMatthew G. Knepley PetscFEComputeTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided. 9642b99622eSMatthew G. Knepley 9652b99622eSMatthew G. Knepley Not collective 9662b99622eSMatthew G. Knepley 9672b99622eSMatthew G. Knepley Input Parameters: 9682b99622eSMatthew G. Knepley + fem - The PetscFE object 9692b99622eSMatthew G. Knepley . npoints - The number of tabulation points 9702b99622eSMatthew G. Knepley . points - The tabulation point coordinates 971ef0bb6c7SMatthew G. Knepley . K - The number of derivatives calculated 972ef0bb6c7SMatthew G. Knepley - T - An existing tabulation object with enough allocated space 973ef0bb6c7SMatthew G. Knepley 974ef0bb6c7SMatthew G. Knepley Output Parameter: 975ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at tabulation points 9762b99622eSMatthew G. Knepley 9772b99622eSMatthew G. Knepley Note: 978ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 979ef0bb6c7SMatthew 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 980ef0bb6c7SMatthew 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 9812b99622eSMatthew G. Knepley 9822b99622eSMatthew G. Knepley Level: intermediate 9832b99622eSMatthew G. Knepley 984db781477SPatrick Sanan .seealso: `PetscFEGetCellTabulation()`, `PetscTabulationDestroy()` 9852b99622eSMatthew G. Knepley @*/ 986ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEComputeTabulation(PetscFE fem, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation T) 987ef0bb6c7SMatthew G. Knepley { 988ef0bb6c7SMatthew G. Knepley PetscFunctionBeginHot; 989ef0bb6c7SMatthew G. Knepley if (!npoints || !fem->dualSpace || K < 0) PetscFunctionReturn(0); 990ef0bb6c7SMatthew G. Knepley PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 991dadcf809SJacob Faibussowitsch PetscValidRealPointer(points, 3); 992ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 5); 99376bd3646SJed Brown if (PetscDefined(USE_DEBUG)) { 99420cf1dd8SToby Isaac DM dm; 995ef0bb6c7SMatthew G. Knepley PetscDualSpace Q; 996ef0bb6c7SMatthew G. Knepley PetscInt Nb; /* Dimension of FE space P */ 997ef0bb6c7SMatthew G. Knepley PetscInt Nc; /* Field components */ 998ef0bb6c7SMatthew G. Knepley PetscInt cdim; /* Reference coordinate dimension */ 999ef0bb6c7SMatthew G. Knepley 10009566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &Q)); 10019566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &dm)); 10029566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &cdim)); 10039566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &Nb)); 10049566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 100563a3b9bcSJacob 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); 100663a3b9bcSJacob 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); 100763a3b9bcSJacob 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); 100863a3b9bcSJacob 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); 1009ef0bb6c7SMatthew G. Knepley } 1010ef0bb6c7SMatthew G. Knepley T->Nr = 1; 1011ef0bb6c7SMatthew G. Knepley T->Np = npoints; 10129566063dSJacob Faibussowitsch PetscCall((*fem->ops->createtabulation)(fem, npoints, points, K, T)); 1013ef0bb6c7SMatthew G. Knepley PetscFunctionReturn(0); 1014ef0bb6c7SMatthew G. Knepley } 1015ef0bb6c7SMatthew G. Knepley 1016ef0bb6c7SMatthew G. Knepley /*@C 1017ef0bb6c7SMatthew G. Knepley PetscTabulationDestroy - Frees memory from the associated tabulation. 1018ef0bb6c7SMatthew G. Knepley 1019ef0bb6c7SMatthew G. Knepley Not collective 1020ef0bb6c7SMatthew G. Knepley 1021ef0bb6c7SMatthew G. Knepley Input Parameter: 1022ef0bb6c7SMatthew G. Knepley . T - The tabulation 1023ef0bb6c7SMatthew G. Knepley 1024ef0bb6c7SMatthew G. Knepley Level: intermediate 1025ef0bb6c7SMatthew G. Knepley 1026db781477SPatrick Sanan .seealso: `PetscFECreateTabulation()`, `PetscFEGetCellTabulation()` 1027ef0bb6c7SMatthew G. Knepley @*/ 1028ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscTabulationDestroy(PetscTabulation *T) 1029ef0bb6c7SMatthew G. Knepley { 1030ef0bb6c7SMatthew G. Knepley PetscInt k; 103120cf1dd8SToby Isaac 103220cf1dd8SToby Isaac PetscFunctionBegin; 1033ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 1); 1034ef0bb6c7SMatthew G. Knepley if (!T || !(*T)) PetscFunctionReturn(0); 10359566063dSJacob Faibussowitsch for (k = 0; k <= (*T)->K; ++k) PetscCall(PetscFree((*T)->T[k])); 10369566063dSJacob Faibussowitsch PetscCall(PetscFree((*T)->T)); 10379566063dSJacob Faibussowitsch PetscCall(PetscFree(*T)); 1038ef0bb6c7SMatthew G. Knepley *T = NULL; 103920cf1dd8SToby Isaac PetscFunctionReturn(0); 104020cf1dd8SToby Isaac } 104120cf1dd8SToby Isaac 104220cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode PetscFECreatePointTrace(PetscFE fe, PetscInt refPoint, PetscFE *trFE) 104320cf1dd8SToby Isaac { 104420cf1dd8SToby Isaac PetscSpace bsp, bsubsp; 104520cf1dd8SToby Isaac PetscDualSpace dsp, dsubsp; 104620cf1dd8SToby Isaac PetscInt dim, depth, numComp, i, j, coneSize, order; 104720cf1dd8SToby Isaac PetscFEType type; 104820cf1dd8SToby Isaac DM dm; 104920cf1dd8SToby Isaac DMLabel label; 105020cf1dd8SToby Isaac PetscReal *xi, *v, *J, detJ; 1051db11e2ebSMatthew G. Knepley const char *name; 105220cf1dd8SToby Isaac PetscQuadrature origin, fullQuad, subQuad; 105320cf1dd8SToby Isaac 105420cf1dd8SToby Isaac PetscFunctionBegin; 105520cf1dd8SToby Isaac PetscValidHeaderSpecific(fe,PETSCFE_CLASSID,1); 105620cf1dd8SToby Isaac PetscValidPointer(trFE,3); 10579566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe,&bsp)); 10589566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe,&dsp)); 10599566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp,&dm)); 10609566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm,&dim)); 10619566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthLabel(dm,&label)); 10629566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(label,refPoint,&depth)); 10639566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(depth,&xi)); 10649566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dim,&v)); 10659566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dim*dim,&J)); 106620cf1dd8SToby Isaac for (i = 0; i < depth; i++) xi[i] = 0.; 10679566063dSJacob Faibussowitsch PetscCall(PetscQuadratureCreate(PETSC_COMM_SELF,&origin)); 10689566063dSJacob Faibussowitsch PetscCall(PetscQuadratureSetData(origin,depth,0,1,xi,NULL)); 10699566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm,refPoint,origin,v,J,NULL,&detJ)); 107020cf1dd8SToby Isaac /* CellGeometryFEM computes the expanded Jacobian, we want the true jacobian */ 107120cf1dd8SToby Isaac for (i = 1; i < dim; i++) { 107220cf1dd8SToby Isaac for (j = 0; j < depth; j++) { 107320cf1dd8SToby Isaac J[i * depth + j] = J[i * dim + j]; 107420cf1dd8SToby Isaac } 107520cf1dd8SToby Isaac } 10769566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&origin)); 10779566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetPointSubspace(dsp,refPoint,&dsubsp)); 10789566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreateSubspace(bsp,dsubsp,v,J,NULL,NULL,PETSC_OWN_POINTER,&bsubsp)); 10799566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetUp(bsubsp)); 10809566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject)fe),trFE)); 10819566063dSJacob Faibussowitsch PetscCall(PetscFEGetType(fe,&type)); 10829566063dSJacob Faibussowitsch PetscCall(PetscFESetType(*trFE,type)); 10839566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe,&numComp)); 10849566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(*trFE,numComp)); 10859566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(*trFE,bsubsp)); 10869566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(*trFE,dsubsp)); 10879566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject) fe, &name)); 10889566063dSJacob Faibussowitsch if (name) PetscCall(PetscFESetName(*trFE, name)); 10899566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe,&fullQuad)); 10909566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetOrder(fullQuad,&order)); 10919566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm,refPoint,&coneSize)); 10921baa6e33SBarry Smith if (coneSize == 2 * depth) PetscCall(PetscDTGaussTensorQuadrature(depth,1,(order + 1)/2,-1.,1.,&subQuad)); 10931baa6e33SBarry Smith else PetscCall(PetscDTStroudConicalQuadrature(depth,1,(order + 1)/2,-1.,1.,&subQuad)); 10949566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(*trFE,subQuad)); 10959566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(*trFE)); 10969566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&subQuad)); 10979566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&bsubsp)); 109820cf1dd8SToby Isaac PetscFunctionReturn(0); 109920cf1dd8SToby Isaac } 110020cf1dd8SToby Isaac 110120cf1dd8SToby Isaac PetscErrorCode PetscFECreateHeightTrace(PetscFE fe, PetscInt height, PetscFE *trFE) 110220cf1dd8SToby Isaac { 110320cf1dd8SToby Isaac PetscInt hStart, hEnd; 110420cf1dd8SToby Isaac PetscDualSpace dsp; 110520cf1dd8SToby Isaac DM dm; 110620cf1dd8SToby Isaac 110720cf1dd8SToby Isaac PetscFunctionBegin; 110820cf1dd8SToby Isaac PetscValidHeaderSpecific(fe,PETSCFE_CLASSID,1); 110920cf1dd8SToby Isaac PetscValidPointer(trFE,3); 111020cf1dd8SToby Isaac *trFE = NULL; 11119566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe,&dsp)); 11129566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp,&dm)); 11139566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(dm,height,&hStart,&hEnd)); 111420cf1dd8SToby Isaac if (hEnd <= hStart) PetscFunctionReturn(0); 11159566063dSJacob Faibussowitsch PetscCall(PetscFECreatePointTrace(fe,hStart,trFE)); 111620cf1dd8SToby Isaac PetscFunctionReturn(0); 111720cf1dd8SToby Isaac } 111820cf1dd8SToby Isaac 111920cf1dd8SToby Isaac /*@ 112020cf1dd8SToby Isaac PetscFEGetDimension - Get the dimension of the finite element space on a cell 112120cf1dd8SToby Isaac 112220cf1dd8SToby Isaac Not collective 112320cf1dd8SToby Isaac 112420cf1dd8SToby Isaac Input Parameter: 112520cf1dd8SToby Isaac . fe - The PetscFE 112620cf1dd8SToby Isaac 112720cf1dd8SToby Isaac Output Parameter: 112820cf1dd8SToby Isaac . dim - The dimension 112920cf1dd8SToby Isaac 113020cf1dd8SToby Isaac Level: intermediate 113120cf1dd8SToby Isaac 1132db781477SPatrick Sanan .seealso: `PetscFECreate()`, `PetscSpaceGetDimension()`, `PetscDualSpaceGetDimension()` 113320cf1dd8SToby Isaac @*/ 113420cf1dd8SToby Isaac PetscErrorCode PetscFEGetDimension(PetscFE fem, PetscInt *dim) 113520cf1dd8SToby Isaac { 113620cf1dd8SToby Isaac PetscFunctionBegin; 113720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 1138dadcf809SJacob Faibussowitsch PetscValidIntPointer(dim, 2); 11399566063dSJacob Faibussowitsch if (fem->ops->getdimension) PetscCall((*fem->ops->getdimension)(fem, dim)); 114020cf1dd8SToby Isaac PetscFunctionReturn(0); 114120cf1dd8SToby Isaac } 114220cf1dd8SToby Isaac 11434bee2e38SMatthew G. Knepley /*@C 11444bee2e38SMatthew G. Knepley PetscFEPushforward - Map the reference element function to real space 11454bee2e38SMatthew G. Knepley 11464bee2e38SMatthew G. Knepley Input Parameters: 11474bee2e38SMatthew G. Knepley + fe - The PetscFE 11484bee2e38SMatthew G. Knepley . fegeom - The cell geometry 11494bee2e38SMatthew G. Knepley . Nv - The number of function values 11504bee2e38SMatthew G. Knepley - vals - The function values 11514bee2e38SMatthew G. Knepley 11524bee2e38SMatthew G. Knepley Output Parameter: 11534bee2e38SMatthew G. Knepley . vals - The transformed function values 11544bee2e38SMatthew G. Knepley 11554bee2e38SMatthew G. Knepley Level: advanced 11564bee2e38SMatthew G. Knepley 11574bee2e38SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforward(). 11584bee2e38SMatthew G. Knepley 1159f9244615SMatthew G. Knepley Note: This only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 11602edcad52SToby Isaac 1161db781477SPatrick Sanan .seealso: `PetscDualSpacePushforward()` 11624bee2e38SMatthew G. Knepley @*/ 11632edcad52SToby Isaac PetscErrorCode PetscFEPushforward(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 11644bee2e38SMatthew G. Knepley { 11652ae266adSMatthew G. Knepley PetscFunctionBeginHot; 11669566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforward(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 11674bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 11684bee2e38SMatthew G. Knepley } 11694bee2e38SMatthew G. Knepley 11704bee2e38SMatthew G. Knepley /*@C 11714bee2e38SMatthew G. Knepley PetscFEPushforwardGradient - Map the reference element function gradient to real space 11724bee2e38SMatthew G. Knepley 11734bee2e38SMatthew G. Knepley Input Parameters: 11744bee2e38SMatthew G. Knepley + fe - The PetscFE 11754bee2e38SMatthew G. Knepley . fegeom - The cell geometry 11764bee2e38SMatthew G. Knepley . Nv - The number of function gradient values 11774bee2e38SMatthew G. Knepley - vals - The function gradient values 11784bee2e38SMatthew G. Knepley 11794bee2e38SMatthew G. Knepley Output Parameter: 11804bee2e38SMatthew G. Knepley . vals - The transformed function gradient values 11814bee2e38SMatthew G. Knepley 11824bee2e38SMatthew G. Knepley Level: advanced 11834bee2e38SMatthew G. Knepley 11844bee2e38SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforwardGradient(). 11854bee2e38SMatthew G. Knepley 1186f9244615SMatthew G. Knepley Note: This only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 11872edcad52SToby Isaac 1188db781477SPatrick Sanan .seealso: `PetscFEPushforward()`, `PetscDualSpacePushforwardGradient()`, `PetscDualSpacePushforward()` 11894bee2e38SMatthew G. Knepley @*/ 11902edcad52SToby Isaac PetscErrorCode PetscFEPushforwardGradient(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 11914bee2e38SMatthew G. Knepley { 11922ae266adSMatthew G. Knepley PetscFunctionBeginHot; 11939566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforwardGradient(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 11944bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 11954bee2e38SMatthew G. Knepley } 11964bee2e38SMatthew G. Knepley 1197f9244615SMatthew G. Knepley /*@C 1198f9244615SMatthew G. Knepley PetscFEPushforwardHessian - Map the reference element function Hessian to real space 1199f9244615SMatthew G. Knepley 1200f9244615SMatthew G. Knepley Input Parameters: 1201f9244615SMatthew G. Knepley + fe - The PetscFE 1202f9244615SMatthew G. Knepley . fegeom - The cell geometry 1203f9244615SMatthew G. Knepley . Nv - The number of function Hessian values 1204f9244615SMatthew G. Knepley - vals - The function Hessian values 1205f9244615SMatthew G. Knepley 1206f9244615SMatthew G. Knepley Output Parameter: 1207f9244615SMatthew G. Knepley . vals - The transformed function Hessian values 1208f9244615SMatthew G. Knepley 1209f9244615SMatthew G. Knepley Level: advanced 1210f9244615SMatthew G. Knepley 1211f9244615SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforwardHessian(). 1212f9244615SMatthew G. Knepley 1213f9244615SMatthew G. Knepley Note: This only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 1214f9244615SMatthew G. Knepley 1215db781477SPatrick Sanan .seealso: `PetscFEPushforward()`, `PetscDualSpacePushforwardHessian()`, `PetscDualSpacePushforward()` 1216f9244615SMatthew G. Knepley @*/ 1217f9244615SMatthew G. Knepley PetscErrorCode PetscFEPushforwardHessian(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 1218f9244615SMatthew G. Knepley { 1219f9244615SMatthew G. Knepley PetscFunctionBeginHot; 12209566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforwardHessian(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 1221f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1222f9244615SMatthew G. Knepley } 1223f9244615SMatthew G. Knepley 122420cf1dd8SToby Isaac /* 122520cf1dd8SToby Isaac Purpose: Compute element vector for chunk of elements 122620cf1dd8SToby Isaac 122720cf1dd8SToby Isaac Input: 122820cf1dd8SToby Isaac Sizes: 122920cf1dd8SToby Isaac Ne: number of elements 123020cf1dd8SToby Isaac Nf: number of fields 123120cf1dd8SToby Isaac PetscFE 123220cf1dd8SToby Isaac dim: spatial dimension 123320cf1dd8SToby Isaac Nb: number of basis functions 123420cf1dd8SToby Isaac Nc: number of field components 123520cf1dd8SToby Isaac PetscQuadrature 123620cf1dd8SToby Isaac Nq: number of quadrature points 123720cf1dd8SToby Isaac 123820cf1dd8SToby Isaac Geometry: 123920cf1dd8SToby Isaac PetscFEGeom[Ne] possibly *Nq 124020cf1dd8SToby Isaac PetscReal v0s[dim] 124120cf1dd8SToby Isaac PetscReal n[dim] 124220cf1dd8SToby Isaac PetscReal jacobians[dim*dim] 124320cf1dd8SToby Isaac PetscReal jacobianInverses[dim*dim] 124420cf1dd8SToby Isaac PetscReal jacobianDeterminants 124520cf1dd8SToby Isaac FEM: 124620cf1dd8SToby Isaac PetscFE 124720cf1dd8SToby Isaac PetscQuadrature 124820cf1dd8SToby Isaac PetscReal quadPoints[Nq*dim] 124920cf1dd8SToby Isaac PetscReal quadWeights[Nq] 125020cf1dd8SToby Isaac PetscReal basis[Nq*Nb*Nc] 125120cf1dd8SToby Isaac PetscReal basisDer[Nq*Nb*Nc*dim] 125220cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 125320cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 125420cf1dd8SToby Isaac 125520cf1dd8SToby Isaac Problem: 125620cf1dd8SToby Isaac PetscInt f: the active field 125720cf1dd8SToby Isaac f0, f1 125820cf1dd8SToby Isaac 125920cf1dd8SToby Isaac Work Space: 126020cf1dd8SToby Isaac PetscFE 126120cf1dd8SToby Isaac PetscScalar f0[Nq*dim]; 126220cf1dd8SToby Isaac PetscScalar f1[Nq*dim*dim]; 126320cf1dd8SToby Isaac PetscScalar u[Nc]; 126420cf1dd8SToby Isaac PetscScalar gradU[Nc*dim]; 126520cf1dd8SToby Isaac PetscReal x[dim]; 126620cf1dd8SToby Isaac PetscScalar realSpaceDer[dim]; 126720cf1dd8SToby Isaac 126820cf1dd8SToby Isaac Purpose: Compute element vector for N_cb batches of elements 126920cf1dd8SToby Isaac 127020cf1dd8SToby Isaac Input: 127120cf1dd8SToby Isaac Sizes: 127220cf1dd8SToby Isaac N_cb: Number of serial cell batches 127320cf1dd8SToby Isaac 127420cf1dd8SToby Isaac Geometry: 127520cf1dd8SToby Isaac PetscReal v0s[Ne*dim] 127620cf1dd8SToby Isaac PetscReal jacobians[Ne*dim*dim] possibly *Nq 127720cf1dd8SToby Isaac PetscReal jacobianInverses[Ne*dim*dim] possibly *Nq 127820cf1dd8SToby Isaac PetscReal jacobianDeterminants[Ne] possibly *Nq 127920cf1dd8SToby Isaac FEM: 128020cf1dd8SToby Isaac static PetscReal quadPoints[Nq*dim] 128120cf1dd8SToby Isaac static PetscReal quadWeights[Nq] 128220cf1dd8SToby Isaac static PetscReal basis[Nq*Nb*Nc] 128320cf1dd8SToby Isaac static PetscReal basisDer[Nq*Nb*Nc*dim] 128420cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 128520cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 128620cf1dd8SToby Isaac 128720cf1dd8SToby Isaac ex62.c: 128820cf1dd8SToby Isaac PetscErrorCode PetscFEIntegrateResidualBatch(PetscInt Ne, PetscInt numFields, PetscInt field, PetscQuadrature quad[], const PetscScalar coefficients[], 128920cf1dd8SToby Isaac const PetscReal v0s[], const PetscReal jacobians[], const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], 129020cf1dd8SToby Isaac void (*f0_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f0[]), 129120cf1dd8SToby Isaac void (*f1_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f1[]), PetscScalar elemVec[]) 129220cf1dd8SToby Isaac 129320cf1dd8SToby Isaac ex52.c: 129420cf1dd8SToby 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) 129520cf1dd8SToby 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) 129620cf1dd8SToby Isaac 129720cf1dd8SToby Isaac ex52_integrateElement.cu 129820cf1dd8SToby Isaac __global__ void integrateElementQuadrature(int N_cb, realType *coefficients, realType *jacobianInverses, realType *jacobianDeterminants, realType *elemVec) 129920cf1dd8SToby Isaac 130020cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt Nbl, const PetscScalar coefficients[], 130120cf1dd8SToby Isaac const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[], 130220cf1dd8SToby Isaac PetscLogEvent event, PetscInt debug, PetscInt pde_op) 130320cf1dd8SToby Isaac 130420cf1dd8SToby Isaac ex52_integrateElementOpenCL.c: 130520cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt N_bl, 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 __kernel void integrateElementQuadrature(int N_cb, __global float *coefficients, __global float *jacobianInverses, __global float *jacobianDeterminants, __global float *elemVec) 131020cf1dd8SToby Isaac */ 131120cf1dd8SToby Isaac 131220cf1dd8SToby Isaac /*@C 131320cf1dd8SToby Isaac PetscFEIntegrate - Produce the integral for the given field for a chunk of elements by quadrature integration 131420cf1dd8SToby Isaac 131520cf1dd8SToby Isaac Not collective 131620cf1dd8SToby Isaac 131720cf1dd8SToby Isaac Input Parameters: 1318360cf244SMatthew G. Knepley + prob - The PetscDS specifying the discretizations and continuum functions 131920cf1dd8SToby Isaac . field - The field being integrated 132020cf1dd8SToby Isaac . Ne - The number of elements in the chunk 132120cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 132220cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 132320cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 132420cf1dd8SToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 132520cf1dd8SToby Isaac 13267a7aea1fSJed Brown Output Parameter: 132720cf1dd8SToby Isaac . integral - the integral for this field 132820cf1dd8SToby Isaac 13292b99622eSMatthew G. Knepley Level: intermediate 133020cf1dd8SToby Isaac 1331db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 133220cf1dd8SToby Isaac @*/ 13334bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrate(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom, 133420cf1dd8SToby Isaac const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 133520cf1dd8SToby Isaac { 13364bee2e38SMatthew G. Knepley PetscFE fe; 133720cf1dd8SToby Isaac 133820cf1dd8SToby Isaac PetscFunctionBegin; 13394bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13409566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *) &fe)); 13419566063dSJacob Faibussowitsch if (fe->ops->integrate) PetscCall((*fe->ops->integrate)(prob, field, Ne, cgeom, coefficients, probAux, coefficientsAux, integral)); 134220cf1dd8SToby Isaac PetscFunctionReturn(0); 134320cf1dd8SToby Isaac } 134420cf1dd8SToby Isaac 134520cf1dd8SToby Isaac /*@C 1346afe6d6adSToby Isaac PetscFEIntegrateBd - Produce the integral for the given field for a chunk of elements by quadrature integration 1347afe6d6adSToby Isaac 1348afe6d6adSToby Isaac Not collective 1349afe6d6adSToby Isaac 1350afe6d6adSToby Isaac Input Parameters: 1351360cf244SMatthew G. Knepley + prob - The PetscDS specifying the discretizations and continuum functions 1352afe6d6adSToby Isaac . field - The field being integrated 1353afe6d6adSToby Isaac . obj_func - The function to be integrated 1354afe6d6adSToby Isaac . Ne - The number of elements in the chunk 1355afe6d6adSToby Isaac . fgeom - The face geometry for each face in the chunk 1356afe6d6adSToby Isaac . coefficients - The array of FEM basis coefficients for the elements 1357afe6d6adSToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 1358afe6d6adSToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 1359afe6d6adSToby Isaac 13607a7aea1fSJed Brown Output Parameter: 1361afe6d6adSToby Isaac . integral - the integral for this field 1362afe6d6adSToby Isaac 13632b99622eSMatthew G. Knepley Level: intermediate 1364afe6d6adSToby Isaac 1365db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 1366afe6d6adSToby Isaac @*/ 13674bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBd(PetscDS prob, PetscInt field, 1368afe6d6adSToby Isaac void (*obj_func)(PetscInt, PetscInt, PetscInt, 1369afe6d6adSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 1370afe6d6adSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 1371afe6d6adSToby Isaac PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]), 1372afe6d6adSToby Isaac PetscInt Ne, PetscFEGeom *geom, const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 1373afe6d6adSToby Isaac { 13744bee2e38SMatthew G. Knepley PetscFE fe; 1375afe6d6adSToby Isaac 1376afe6d6adSToby Isaac PetscFunctionBegin; 13774bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13789566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *) &fe)); 13799566063dSJacob Faibussowitsch if (fe->ops->integratebd) PetscCall((*fe->ops->integratebd)(prob, field, obj_func, Ne, geom, coefficients, probAux, coefficientsAux, integral)); 1380afe6d6adSToby Isaac PetscFunctionReturn(0); 1381afe6d6adSToby Isaac } 1382afe6d6adSToby Isaac 1383afe6d6adSToby Isaac /*@C 138420cf1dd8SToby Isaac PetscFEIntegrateResidual - Produce the element residual vector for a chunk of elements by quadrature integration 138520cf1dd8SToby Isaac 138620cf1dd8SToby Isaac Not collective 138720cf1dd8SToby Isaac 138820cf1dd8SToby Isaac Input Parameters: 13896528b96dSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 13906528b96dSMatthew G. Knepley . key - The (label+value, field) being integrated 139120cf1dd8SToby Isaac . Ne - The number of elements in the chunk 139220cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 139320cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 139420cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 139520cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 139620cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 139720cf1dd8SToby Isaac - t - The time 139820cf1dd8SToby Isaac 13997a7aea1fSJed Brown Output Parameter: 140020cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 140120cf1dd8SToby Isaac 140220cf1dd8SToby Isaac Note: 140320cf1dd8SToby Isaac $ Loop over batch of elements (e): 140420cf1dd8SToby Isaac $ Loop over quadrature points (q): 140520cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) and x_q 140620cf1dd8SToby Isaac $ Call f_0 and f_1 140720cf1dd8SToby Isaac $ Loop over element vector entries (f,fc --> i): 140820cf1dd8SToby Isaac $ elemVec[i] += \psi^{fc}_f(q) f0_{fc}(u, \nabla u) + \nabla\psi^{fc}_f(q) \cdot f1_{fc,df}(u, \nabla u) 140920cf1dd8SToby Isaac 14102b99622eSMatthew G. Knepley Level: intermediate 141120cf1dd8SToby Isaac 1412db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 141320cf1dd8SToby Isaac @*/ 141406ad1575SMatthew G. Knepley PetscErrorCode PetscFEIntegrateResidual(PetscDS ds, PetscFormKey key, PetscInt Ne, PetscFEGeom *cgeom, 141520cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 141620cf1dd8SToby Isaac { 14174bee2e38SMatthew G. Knepley PetscFE fe; 141820cf1dd8SToby Isaac 14196528b96dSMatthew G. Knepley PetscFunctionBeginHot; 14206528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14219566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field, (PetscObject *) &fe)); 14229566063dSJacob Faibussowitsch if (fe->ops->integrateresidual) PetscCall((*fe->ops->integrateresidual)(ds, key, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 142320cf1dd8SToby Isaac PetscFunctionReturn(0); 142420cf1dd8SToby Isaac } 142520cf1dd8SToby Isaac 142620cf1dd8SToby Isaac /*@C 142720cf1dd8SToby Isaac PetscFEIntegrateBdResidual - Produce the element residual vector for a chunk of elements by quadrature integration over a boundary 142820cf1dd8SToby Isaac 142920cf1dd8SToby Isaac Not collective 143020cf1dd8SToby Isaac 143120cf1dd8SToby Isaac Input Parameters: 143206d8a0d3SMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 143345480ffeSMatthew G. Knepley . wf - The PetscWeakForm object holding the pointwise functions 143406d8a0d3SMatthew G. Knepley . key - The (label+value, field) being integrated 143520cf1dd8SToby Isaac . Ne - The number of elements in the chunk 143620cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 143720cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 143820cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 143920cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 144020cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 144120cf1dd8SToby Isaac - t - The time 144220cf1dd8SToby Isaac 14437a7aea1fSJed Brown Output Parameter: 144420cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 144520cf1dd8SToby Isaac 14462b99622eSMatthew G. Knepley Level: intermediate 144720cf1dd8SToby Isaac 1448db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 144920cf1dd8SToby Isaac @*/ 145006ad1575SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdResidual(PetscDS ds, PetscWeakForm wf, PetscFormKey key, PetscInt Ne, PetscFEGeom *fgeom, 145120cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 145220cf1dd8SToby Isaac { 14534bee2e38SMatthew G. Knepley PetscFE fe; 145420cf1dd8SToby Isaac 145520cf1dd8SToby Isaac PetscFunctionBegin; 145606d8a0d3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14579566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field, (PetscObject *) &fe)); 14589566063dSJacob Faibussowitsch if (fe->ops->integratebdresidual) PetscCall((*fe->ops->integratebdresidual)(ds, wf, key, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 145920cf1dd8SToby Isaac PetscFunctionReturn(0); 146020cf1dd8SToby Isaac } 146120cf1dd8SToby Isaac 146220cf1dd8SToby Isaac /*@C 146327f02ce8SMatthew G. Knepley PetscFEIntegrateHybridResidual - Produce the element residual vector for a chunk of hybrid element faces by quadrature integration 146427f02ce8SMatthew G. Knepley 146527f02ce8SMatthew G. Knepley Not collective 146627f02ce8SMatthew G. Knepley 146727f02ce8SMatthew G. Knepley Input Parameters: 146827f02ce8SMatthew G. Knepley + prob - The PetscDS specifying the discretizations and continuum functions 14696528b96dSMatthew G. Knepley . key - The (label+value, field) being integrated 1470c2b7495fSMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 147127f02ce8SMatthew G. Knepley . Ne - The number of elements in the chunk 147227f02ce8SMatthew G. Knepley . fgeom - The face geometry for each cell in the chunk 147327f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements 147427f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements 147527f02ce8SMatthew G. Knepley . probAux - The PetscDS specifying the auxiliary discretizations 147627f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 147727f02ce8SMatthew G. Knepley - t - The time 147827f02ce8SMatthew G. Knepley 147927f02ce8SMatthew G. Knepley Output Parameter 148027f02ce8SMatthew G. Knepley . elemVec - the element residual vectors from each element 148127f02ce8SMatthew G. Knepley 148227f02ce8SMatthew G. Knepley Level: developer 148327f02ce8SMatthew G. Knepley 1484db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 148527f02ce8SMatthew G. Knepley @*/ 1486c2b7495fSMatthew G. Knepley PetscErrorCode PetscFEIntegrateHybridResidual(PetscDS prob, PetscFormKey key, PetscInt s, PetscInt Ne, PetscFEGeom *fgeom, 148727f02ce8SMatthew G. Knepley const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 148827f02ce8SMatthew G. Knepley { 148927f02ce8SMatthew G. Knepley PetscFE fe; 149027f02ce8SMatthew G. Knepley 149127f02ce8SMatthew G. Knepley PetscFunctionBegin; 149227f02ce8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 14939566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, key.field, (PetscObject *) &fe)); 14949566063dSJacob Faibussowitsch if (fe->ops->integratehybridresidual) PetscCall((*fe->ops->integratehybridresidual)(prob, key, s, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 149527f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 149627f02ce8SMatthew G. Knepley } 149727f02ce8SMatthew G. Knepley 149827f02ce8SMatthew G. Knepley /*@C 149920cf1dd8SToby Isaac PetscFEIntegrateJacobian - Produce the element Jacobian for a chunk of elements by quadrature integration 150020cf1dd8SToby Isaac 150120cf1dd8SToby Isaac Not collective 150220cf1dd8SToby Isaac 150320cf1dd8SToby Isaac Input Parameters: 15046528b96dSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 150520cf1dd8SToby Isaac . jtype - The type of matrix pointwise functions that should be used 15066528b96dSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 15075fedec97SMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 150820cf1dd8SToby Isaac . Ne - The number of elements in the chunk 150920cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 151020cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 151120cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 151220cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 151320cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 151420cf1dd8SToby Isaac . t - The time 151520cf1dd8SToby Isaac - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 151620cf1dd8SToby Isaac 15177a7aea1fSJed Brown Output Parameter: 151820cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 151920cf1dd8SToby Isaac 152020cf1dd8SToby Isaac Note: 152120cf1dd8SToby Isaac $ Loop over batch of elements (e): 152220cf1dd8SToby Isaac $ Loop over element matrix entries (f,fc,g,gc --> i,j): 152320cf1dd8SToby Isaac $ Loop over quadrature points (q): 152420cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 152520cf1dd8SToby Isaac $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 152620cf1dd8SToby Isaac $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 152720cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 152820cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 15292b99622eSMatthew G. Knepley Level: intermediate 153020cf1dd8SToby Isaac 1531db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 153220cf1dd8SToby Isaac @*/ 153306ad1575SMatthew G. Knepley PetscErrorCode PetscFEIntegrateJacobian(PetscDS ds, PetscFEJacobianType jtype, PetscFormKey key, PetscInt Ne, PetscFEGeom *cgeom, 153420cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 153520cf1dd8SToby Isaac { 15364bee2e38SMatthew G. Knepley PetscFE fe; 15376528b96dSMatthew G. Knepley PetscInt Nf; 153820cf1dd8SToby Isaac 153920cf1dd8SToby Isaac PetscFunctionBegin; 15406528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 15419566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 15429566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *) &fe)); 15439566063dSJacob Faibussowitsch if (fe->ops->integratejacobian) PetscCall((*fe->ops->integratejacobian)(ds, jtype, key, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 154420cf1dd8SToby Isaac PetscFunctionReturn(0); 154520cf1dd8SToby Isaac } 154620cf1dd8SToby Isaac 154720cf1dd8SToby Isaac /*@C 154820cf1dd8SToby Isaac PetscFEIntegrateBdJacobian - Produce the boundary element Jacobian for a chunk of elements by quadrature integration 154920cf1dd8SToby Isaac 155020cf1dd8SToby Isaac Not collective 155120cf1dd8SToby Isaac 155220cf1dd8SToby Isaac Input Parameters: 155345480ffeSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 155445480ffeSMatthew G. Knepley . wf - The PetscWeakForm holding the pointwise functions 155545480ffeSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 155620cf1dd8SToby Isaac . Ne - The number of elements in the chunk 155720cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 155820cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 155920cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 156020cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 156120cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 156220cf1dd8SToby Isaac . t - The time 156320cf1dd8SToby Isaac - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 156420cf1dd8SToby Isaac 15657a7aea1fSJed Brown Output Parameter: 156620cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 156720cf1dd8SToby Isaac 156820cf1dd8SToby Isaac Note: 156920cf1dd8SToby Isaac $ Loop over batch of elements (e): 157020cf1dd8SToby Isaac $ Loop over element matrix entries (f,fc,g,gc --> i,j): 157120cf1dd8SToby Isaac $ Loop over quadrature points (q): 157220cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 157320cf1dd8SToby Isaac $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 157420cf1dd8SToby Isaac $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 157520cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 157620cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 15772b99622eSMatthew G. Knepley Level: intermediate 157820cf1dd8SToby Isaac 1579db781477SPatrick Sanan .seealso: `PetscFEIntegrateJacobian()`, `PetscFEIntegrateResidual()` 158020cf1dd8SToby Isaac @*/ 158106ad1575SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdJacobian(PetscDS ds, PetscWeakForm wf, PetscFormKey key, PetscInt Ne, PetscFEGeom *fgeom, 158220cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 158320cf1dd8SToby Isaac { 15844bee2e38SMatthew G. Knepley PetscFE fe; 158545480ffeSMatthew G. Knepley PetscInt Nf; 158620cf1dd8SToby Isaac 158720cf1dd8SToby Isaac PetscFunctionBegin; 158845480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 15899566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 15909566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *) &fe)); 15919566063dSJacob Faibussowitsch if (fe->ops->integratebdjacobian) PetscCall((*fe->ops->integratebdjacobian)(ds, wf, key, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 159220cf1dd8SToby Isaac PetscFunctionReturn(0); 159320cf1dd8SToby Isaac } 159420cf1dd8SToby Isaac 159527f02ce8SMatthew G. Knepley /*@C 159627f02ce8SMatthew G. Knepley PetscFEIntegrateHybridJacobian - Produce the boundary element Jacobian for a chunk of hybrid elements by quadrature integration 159727f02ce8SMatthew G. Knepley 159827f02ce8SMatthew G. Knepley Not collective 159927f02ce8SMatthew G. Knepley 160027f02ce8SMatthew G. Knepley Input Parameters: 160145480ffeSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 160227f02ce8SMatthew G. Knepley . jtype - The type of matrix pointwise functions that should be used 160345480ffeSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 16045fedec97SMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 160527f02ce8SMatthew G. Knepley . Ne - The number of elements in the chunk 160627f02ce8SMatthew G. Knepley . fgeom - The face geometry for each cell in the chunk 160727f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 160827f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements 160927f02ce8SMatthew G. Knepley . probAux - The PetscDS specifying the auxiliary discretizations 161027f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 161127f02ce8SMatthew G. Knepley . t - The time 161227f02ce8SMatthew G. Knepley - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 161327f02ce8SMatthew G. Knepley 161427f02ce8SMatthew G. Knepley Output Parameter 161527f02ce8SMatthew G. Knepley . elemMat - the element matrices for the Jacobian from each element 161627f02ce8SMatthew G. Knepley 161727f02ce8SMatthew G. Knepley Note: 161827f02ce8SMatthew G. Knepley $ Loop over batch of elements (e): 161927f02ce8SMatthew G. Knepley $ Loop over element matrix entries (f,fc,g,gc --> i,j): 162027f02ce8SMatthew G. Knepley $ Loop over quadrature points (q): 162127f02ce8SMatthew G. Knepley $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 162227f02ce8SMatthew G. Knepley $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 162327f02ce8SMatthew G. Knepley $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 162427f02ce8SMatthew G. Knepley $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 162527f02ce8SMatthew G. Knepley $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 162627f02ce8SMatthew G. Knepley Level: developer 162727f02ce8SMatthew G. Knepley 1628db781477SPatrick Sanan .seealso: `PetscFEIntegrateJacobian()`, `PetscFEIntegrateResidual()` 162927f02ce8SMatthew G. Knepley @*/ 16305fedec97SMatthew G. Knepley PetscErrorCode PetscFEIntegrateHybridJacobian(PetscDS ds, PetscFEJacobianType jtype, PetscFormKey key, PetscInt s, PetscInt Ne, PetscFEGeom *fgeom, 163127f02ce8SMatthew G. Knepley const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 163227f02ce8SMatthew G. Knepley { 163327f02ce8SMatthew G. Knepley PetscFE fe; 163445480ffeSMatthew G. Knepley PetscInt Nf; 163527f02ce8SMatthew G. Knepley 163627f02ce8SMatthew G. Knepley PetscFunctionBegin; 163745480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 16389566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 16399566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *) &fe)); 16409566063dSJacob Faibussowitsch if (fe->ops->integratehybridjacobian) PetscCall((*fe->ops->integratehybridjacobian)(ds, jtype, key, s, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 164127f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 164227f02ce8SMatthew G. Knepley } 164327f02ce8SMatthew G. Knepley 16442b99622eSMatthew G. Knepley /*@ 16452b99622eSMatthew G. Knepley PetscFEGetHeightSubspace - Get the subspace of this space for a mesh point of a given height 16462b99622eSMatthew G. Knepley 16472b99622eSMatthew G. Knepley Input Parameters: 16482b99622eSMatthew G. Knepley + fe - The finite element space 16492b99622eSMatthew G. Knepley - height - The height of the Plex point 16502b99622eSMatthew G. Knepley 16512b99622eSMatthew G. Knepley Output Parameter: 16522b99622eSMatthew G. Knepley . subfe - The subspace of this FE space 16532b99622eSMatthew G. Knepley 16542b99622eSMatthew G. Knepley Note: For example, if we want the subspace of this space for a face, we would choose height = 1. 16552b99622eSMatthew G. Knepley 16562b99622eSMatthew G. Knepley Level: advanced 16572b99622eSMatthew G. Knepley 1658db781477SPatrick Sanan .seealso: `PetscFECreateDefault()` 16592b99622eSMatthew G. Knepley @*/ 166020cf1dd8SToby Isaac PetscErrorCode PetscFEGetHeightSubspace(PetscFE fe, PetscInt height, PetscFE *subfe) 166120cf1dd8SToby Isaac { 166220cf1dd8SToby Isaac PetscSpace P, subP; 166320cf1dd8SToby Isaac PetscDualSpace Q, subQ; 166420cf1dd8SToby Isaac PetscQuadrature subq; 166520cf1dd8SToby Isaac PetscFEType fetype; 166620cf1dd8SToby Isaac PetscInt dim, Nc; 166720cf1dd8SToby Isaac 166820cf1dd8SToby Isaac PetscFunctionBegin; 166920cf1dd8SToby Isaac PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1); 167020cf1dd8SToby Isaac PetscValidPointer(subfe, 3); 167120cf1dd8SToby Isaac if (height == 0) { 167220cf1dd8SToby Isaac *subfe = fe; 167320cf1dd8SToby Isaac PetscFunctionReturn(0); 167420cf1dd8SToby Isaac } 16759566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 16769566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 16779566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &Nc)); 16789566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(fe, &subq)); 16799566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &dim)); 16801dca8a05SBarry 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); 16819566063dSJacob Faibussowitsch if (!fe->subspaces) PetscCall(PetscCalloc1(dim, &fe->subspaces)); 168220cf1dd8SToby Isaac if (height <= dim) { 168320cf1dd8SToby Isaac if (!fe->subspaces[height-1]) { 1684665f567fSMatthew G. Knepley PetscFE sub = NULL; 16853f6b16c7SMatthew G. Knepley const char *name; 168620cf1dd8SToby Isaac 16879566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetHeightSubspace(P, height, &subP)); 16889566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetHeightSubspace(Q, height, &subQ)); 1689665f567fSMatthew G. Knepley if (subQ) { 16909566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject) fe), &sub)); 16919566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject) fe, &name)); 16929566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject) sub, name)); 16939566063dSJacob Faibussowitsch PetscCall(PetscFEGetType(fe, &fetype)); 16949566063dSJacob Faibussowitsch PetscCall(PetscFESetType(sub, fetype)); 16959566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(sub, subP)); 16969566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(sub, subQ)); 16979566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(sub, Nc)); 16989566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(sub)); 16999566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(sub, subq)); 1700665f567fSMatthew G. Knepley } 170120cf1dd8SToby Isaac fe->subspaces[height-1] = sub; 170220cf1dd8SToby Isaac } 170320cf1dd8SToby Isaac *subfe = fe->subspaces[height-1]; 170420cf1dd8SToby Isaac } else { 170520cf1dd8SToby Isaac *subfe = NULL; 170620cf1dd8SToby Isaac } 170720cf1dd8SToby Isaac PetscFunctionReturn(0); 170820cf1dd8SToby Isaac } 170920cf1dd8SToby Isaac 171020cf1dd8SToby Isaac /*@ 171120cf1dd8SToby Isaac PetscFERefine - Create a "refined" PetscFE object that refines the reference cell into smaller copies. This is typically used 171220cf1dd8SToby Isaac to precondition a higher order method with a lower order method on a refined mesh having the same number of dofs (but more 171320cf1dd8SToby Isaac sparsity). It is also used to create an interpolation between regularly refined meshes. 171420cf1dd8SToby Isaac 1715d083f849SBarry Smith Collective on fem 171620cf1dd8SToby Isaac 171720cf1dd8SToby Isaac Input Parameter: 171820cf1dd8SToby Isaac . fe - The initial PetscFE 171920cf1dd8SToby Isaac 172020cf1dd8SToby Isaac Output Parameter: 172120cf1dd8SToby Isaac . feRef - The refined PetscFE 172220cf1dd8SToby Isaac 17232b99622eSMatthew G. Knepley Level: advanced 172420cf1dd8SToby Isaac 1725db781477SPatrick Sanan .seealso: `PetscFEType`, `PetscFECreate()`, `PetscFESetType()` 172620cf1dd8SToby Isaac @*/ 172720cf1dd8SToby Isaac PetscErrorCode PetscFERefine(PetscFE fe, PetscFE *feRef) 172820cf1dd8SToby Isaac { 172920cf1dd8SToby Isaac PetscSpace P, Pref; 173020cf1dd8SToby Isaac PetscDualSpace Q, Qref; 173120cf1dd8SToby Isaac DM K, Kref; 173220cf1dd8SToby Isaac PetscQuadrature q, qref; 173320cf1dd8SToby Isaac const PetscReal *v0, *jac; 173420cf1dd8SToby Isaac PetscInt numComp, numSubelements; 17351ac17e89SToby Isaac PetscInt cStart, cEnd, c; 17361ac17e89SToby Isaac PetscDualSpace *cellSpaces; 173720cf1dd8SToby Isaac 173820cf1dd8SToby Isaac PetscFunctionBegin; 17399566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 17409566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 17419566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &q)); 17429566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &K)); 174320cf1dd8SToby Isaac /* Create space */ 17449566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) P)); 174520cf1dd8SToby Isaac Pref = P; 174620cf1dd8SToby Isaac /* Create dual space */ 17479566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDuplicate(Q, &Qref)); 17489566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetType(Qref, PETSCDUALSPACEREFINED)); 17499566063dSJacob Faibussowitsch PetscCall(DMRefine(K, PetscObjectComm((PetscObject) fe), &Kref)); 17509566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetDM(Qref, Kref)); 17519566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(Kref, 0, &cStart, &cEnd)); 17529566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(cEnd - cStart, &cellSpaces)); 17531ac17e89SToby Isaac /* TODO: fix for non-uniform refinement */ 17541ac17e89SToby Isaac for (c = 0; c < cEnd - cStart; c++) cellSpaces[c] = Q; 17559566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceRefinedSetCellSpaces(Qref, cellSpaces)); 17569566063dSJacob Faibussowitsch PetscCall(PetscFree(cellSpaces)); 17579566063dSJacob Faibussowitsch PetscCall(DMDestroy(&Kref)); 17589566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetUp(Qref)); 175920cf1dd8SToby Isaac /* Create element */ 17609566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject) fe), feRef)); 17619566063dSJacob Faibussowitsch PetscCall(PetscFESetType(*feRef, PETSCFECOMPOSITE)); 17629566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(*feRef, Pref)); 17639566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(*feRef, Qref)); 17649566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &numComp)); 17659566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(*feRef, numComp)); 17669566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(*feRef)); 17679566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pref)); 17689566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&Qref)); 176920cf1dd8SToby Isaac /* Create quadrature */ 17709566063dSJacob Faibussowitsch PetscCall(PetscFECompositeGetMapping(*feRef, &numSubelements, &v0, &jac, NULL)); 17719566063dSJacob Faibussowitsch PetscCall(PetscQuadratureExpandComposite(q, numSubelements, v0, jac, &qref)); 17729566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(*feRef, qref)); 17739566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&qref)); 177420cf1dd8SToby Isaac PetscFunctionReturn(0); 177520cf1dd8SToby Isaac } 177620cf1dd8SToby Isaac 1777*7c48043bSMatthew G. Knepley static PetscErrorCode PetscFESetDefaultName_Private(PetscFE fe) 1778*7c48043bSMatthew G. Knepley { 1779*7c48043bSMatthew G. Knepley PetscSpace P; 1780*7c48043bSMatthew G. Knepley PetscDualSpace Q; 1781*7c48043bSMatthew G. Knepley DM K; 1782*7c48043bSMatthew G. Knepley DMPolytopeType ct; 1783*7c48043bSMatthew G. Knepley PetscInt degree; 1784*7c48043bSMatthew G. Knepley char name[64]; 1785*7c48043bSMatthew G. Knepley 1786*7c48043bSMatthew G. Knepley PetscFunctionBegin; 1787*7c48043bSMatthew G. Knepley PetscCall(PetscFEGetBasisSpace(fe, &P)); 1788*7c48043bSMatthew G. Knepley PetscCall(PetscSpaceGetDegree(P, °ree, NULL)); 1789*7c48043bSMatthew G. Knepley PetscCall(PetscFEGetDualSpace(fe, &Q)); 1790*7c48043bSMatthew G. Knepley PetscCall(PetscDualSpaceGetDM(Q, &K)); 1791*7c48043bSMatthew G. Knepley PetscCall(DMPlexGetCellType(K, 0, &ct)); 1792*7c48043bSMatthew G. Knepley switch (ct) { 1793*7c48043bSMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 1794*7c48043bSMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 1795*7c48043bSMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 1796*7c48043bSMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 1797*7c48043bSMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 1798*7c48043bSMatthew G. Knepley case DM_POLYTOPE_QUAD_PRISM_TENSOR: 1799*7c48043bSMatthew G. Knepley PetscCall(PetscSNPrintf(name, sizeof(name), "Q%" PetscInt_FMT, degree)); 1800*7c48043bSMatthew G. Knepley break; 1801*7c48043bSMatthew G. Knepley case DM_POLYTOPE_TRIANGLE: 1802*7c48043bSMatthew G. Knepley case DM_POLYTOPE_TETRAHEDRON: 1803*7c48043bSMatthew G. Knepley PetscCall(PetscSNPrintf(name, sizeof(name), "P%" PetscInt_FMT, degree)); 1804*7c48043bSMatthew G. Knepley break; 1805*7c48043bSMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM: 1806*7c48043bSMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM_TENSOR: 1807*7c48043bSMatthew G. Knepley PetscCall(PetscSNPrintf(name, sizeof(name), "P%" PetscInt_FMT "xQ%" PetscInt_FMT, degree, degree)); 1808*7c48043bSMatthew G. Knepley break; 1809*7c48043bSMatthew G. Knepley default: 1810*7c48043bSMatthew G. Knepley PetscCall(PetscSNPrintf(name, sizeof(name), "FE")); 1811*7c48043bSMatthew G. Knepley } 1812*7c48043bSMatthew G. Knepley PetscCall(PetscFESetName(fe, name)); 1813*7c48043bSMatthew G. Knepley PetscFunctionReturn(0); 1814*7c48043bSMatthew G. Knepley } 1815*7c48043bSMatthew G. Knepley 1816*7c48043bSMatthew G. Knepley static PetscErrorCode PetscFECreateDefaultQuadrature_Private(PetscInt dim, DMPolytopeType ct, PetscInt qorder, PetscQuadrature *q, PetscQuadrature *fq) 1817*7c48043bSMatthew G. Knepley { 1818*7c48043bSMatthew G. Knepley const PetscInt quadPointsPerEdge = PetscMax(qorder + 1, 1); 1819*7c48043bSMatthew G. Knepley 1820*7c48043bSMatthew G. Knepley PetscFunctionBegin; 1821*7c48043bSMatthew G. Knepley switch (ct) { 1822*7c48043bSMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 1823*7c48043bSMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 1824*7c48043bSMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 1825*7c48043bSMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 1826*7c48043bSMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 1827*7c48043bSMatthew G. Knepley case DM_POLYTOPE_QUAD_PRISM_TENSOR: 1828*7c48043bSMatthew G. Knepley PetscCall(PetscDTGaussTensorQuadrature(dim, 1, quadPointsPerEdge, -1.0, 1.0, q)); 1829*7c48043bSMatthew G. Knepley PetscCall(PetscDTGaussTensorQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, fq)); 1830*7c48043bSMatthew G. Knepley break; 1831*7c48043bSMatthew G. Knepley case DM_POLYTOPE_TRIANGLE: 1832*7c48043bSMatthew G. Knepley case DM_POLYTOPE_TETRAHEDRON: 1833*7c48043bSMatthew G. Knepley PetscCall(PetscDTStroudConicalQuadrature(dim, 1, quadPointsPerEdge, -1.0, 1.0, q)); 1834*7c48043bSMatthew G. Knepley PetscCall(PetscDTStroudConicalQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, fq)); 1835*7c48043bSMatthew G. Knepley break; 1836*7c48043bSMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM: 1837*7c48043bSMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM_TENSOR: 1838*7c48043bSMatthew G. Knepley { 1839*7c48043bSMatthew G. Knepley PetscQuadrature q1, q2; 1840*7c48043bSMatthew G. Knepley 1841*7c48043bSMatthew G. Knepley PetscCall(PetscDTStroudConicalQuadrature(2, 1, quadPointsPerEdge, -1.0, 1.0, &q1)); 1842*7c48043bSMatthew G. Knepley PetscCall(PetscDTGaussTensorQuadrature(1, 1, quadPointsPerEdge, -1.0, 1.0, &q2)); 1843*7c48043bSMatthew G. Knepley PetscCall(PetscDTTensorQuadratureCreate(q1, q2, q)); 1844*7c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&q1)); 1845*7c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&q2)); 1846*7c48043bSMatthew G. Knepley } 1847*7c48043bSMatthew G. Knepley PetscCall(PetscDTStroudConicalQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, fq)); 1848*7c48043bSMatthew G. Knepley /* TODO Need separate quadratures for each face */ 1849*7c48043bSMatthew G. Knepley break; 1850*7c48043bSMatthew G. Knepley default: SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "No quadrature for celltype %s", DMPolytopeTypes[PetscMin(ct, DM_POLYTOPE_UNKNOWN)]); 1851*7c48043bSMatthew G. Knepley } 1852*7c48043bSMatthew G. Knepley PetscFunctionReturn(0); 1853*7c48043bSMatthew G. Knepley } 1854*7c48043bSMatthew G. Knepley 1855*7c48043bSMatthew G. Knepley /*@ 1856*7c48043bSMatthew G. Knepley PetscFECreateFromSpaces - Create a PetscFE from the basis and dual spaces 1857*7c48043bSMatthew G. Knepley 1858*7c48043bSMatthew G. Knepley Collective 1859*7c48043bSMatthew G. Knepley 1860*7c48043bSMatthew G. Knepley Input Parameters: 1861*7c48043bSMatthew G. Knepley + P - The basis space 1862*7c48043bSMatthew G. Knepley . Q - The dual space 1863*7c48043bSMatthew G. Knepley . q - The cell quadrature 1864*7c48043bSMatthew G. Knepley - fq - The face quadrature 1865*7c48043bSMatthew G. Knepley 1866*7c48043bSMatthew G. Knepley Output Parameter: 1867*7c48043bSMatthew G. Knepley . fem - The PetscFE object 1868*7c48043bSMatthew G. Knepley 1869*7c48043bSMatthew G. Knepley Note: 1870*7c48043bSMatthew G. Knepley The PetscFE takes ownership of these spaces by calling destroy on each. They should not be used after this call, and for borrowed references from `PetscFEGetSpace()` and the like, the caller must use `PetscObjectReference` before this call. 1871*7c48043bSMatthew G. Knepley 1872*7c48043bSMatthew G. Knepley Level: beginner 1873*7c48043bSMatthew G. Knepley 1874*7c48043bSMatthew G. Knepley .seealso: `PetscFECreateLagrangeByCell()`, `PetscFECreateDefault()`, `PetscFECreateByCell()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 1875*7c48043bSMatthew G. Knepley @*/ 1876*7c48043bSMatthew G. Knepley PetscErrorCode PetscFECreateFromSpaces(PetscSpace P, PetscDualSpace Q, PetscQuadrature q, PetscQuadrature fq, PetscFE *fem) 1877*7c48043bSMatthew G. Knepley { 1878*7c48043bSMatthew G. Knepley PetscInt Nc; 1879*7c48043bSMatthew G. Knepley const char *prefix; 1880*7c48043bSMatthew G. Knepley 1881*7c48043bSMatthew G. Knepley PetscFunctionBegin; 1882*7c48043bSMatthew G. Knepley PetscCall(PetscFECreate(PetscObjectComm((PetscObject) P), fem)); 1883*7c48043bSMatthew G. Knepley PetscCall(PetscObjectGetOptionsPrefix((PetscObject) P, &prefix)); 1884*7c48043bSMatthew G. Knepley PetscCall(PetscObjectSetOptionsPrefix((PetscObject) *fem, prefix)); 1885*7c48043bSMatthew G. Knepley PetscCall(PetscFESetType(*fem, PETSCFEBASIC)); 1886*7c48043bSMatthew G. Knepley PetscCall(PetscFESetBasisSpace(*fem, P)); 1887*7c48043bSMatthew G. Knepley PetscCall(PetscFESetDualSpace(*fem, Q)); 1888*7c48043bSMatthew G. Knepley PetscCall(PetscSpaceGetNumComponents(P, &Nc)); 1889*7c48043bSMatthew G. Knepley PetscCall(PetscFESetNumComponents(*fem, Nc)); 1890*7c48043bSMatthew G. Knepley PetscCall(PetscFESetUp(*fem)); 1891*7c48043bSMatthew G. Knepley PetscCall(PetscSpaceDestroy(&P)); 1892*7c48043bSMatthew G. Knepley PetscCall(PetscDualSpaceDestroy(&Q)); 1893*7c48043bSMatthew G. Knepley PetscCall(PetscFESetQuadrature(*fem, q)); 1894*7c48043bSMatthew G. Knepley PetscCall(PetscFESetFaceQuadrature(*fem, fq)); 1895*7c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&q)); 1896*7c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&fq)); 1897*7c48043bSMatthew G. Knepley PetscCall(PetscFESetDefaultName_Private(*fem)); 1898*7c48043bSMatthew G. Knepley PetscFunctionReturn(0); 1899*7c48043bSMatthew G. Knepley } 1900*7c48043bSMatthew G. Knepley 19012df84da0SMatthew 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) 19022df84da0SMatthew G. Knepley { 19032df84da0SMatthew G. Knepley DM K; 19042df84da0SMatthew G. Knepley PetscSpace P; 19052df84da0SMatthew G. Knepley PetscDualSpace Q; 1906*7c48043bSMatthew G. Knepley PetscQuadrature q, fq; 19072df84da0SMatthew G. Knepley PetscBool tensor; 19082df84da0SMatthew G. Knepley 19092df84da0SMatthew G. Knepley PetscFunctionBegin; 19102df84da0SMatthew G. Knepley if (prefix) PetscValidCharPointer(prefix, 5); 19112df84da0SMatthew G. Knepley PetscValidPointer(fem, 9); 19122df84da0SMatthew G. Knepley switch (ct) { 19132df84da0SMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 19142df84da0SMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 19152df84da0SMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 19162df84da0SMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 19172df84da0SMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 19182df84da0SMatthew G. Knepley case DM_POLYTOPE_QUAD_PRISM_TENSOR: 19192df84da0SMatthew G. Knepley tensor = PETSC_TRUE; 19202df84da0SMatthew G. Knepley break; 19212df84da0SMatthew G. Knepley default: tensor = PETSC_FALSE; 19222df84da0SMatthew G. Knepley } 19232df84da0SMatthew G. Knepley /* Create space */ 19249566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &P)); 19259566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(P, PETSCSPACEPOLYNOMIAL)); 19269566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject) P, prefix)); 19279566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(P, tensor)); 19289566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(P, Nc)); 19299566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(P, dim)); 19302df84da0SMatthew G. Knepley if (degree >= 0) { 19319566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(P, degree, PETSC_DETERMINE)); 1932cfd33b42SLisandro Dalcin if (ct == DM_POLYTOPE_TRI_PRISM || ct == DM_POLYTOPE_TRI_PRISM_TENSOR) { 19332df84da0SMatthew G. Knepley PetscSpace Pend, Pside; 19342df84da0SMatthew G. Knepley 19359566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &Pend)); 19369566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(Pend, PETSCSPACEPOLYNOMIAL)); 19379566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(Pend, PETSC_FALSE)); 19389566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(Pend, Nc)); 19399566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(Pend, dim-1)); 19409566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(Pend, degree, PETSC_DETERMINE)); 19419566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &Pside)); 19429566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(Pside, PETSCSPACEPOLYNOMIAL)); 19439566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(Pside, PETSC_FALSE)); 19449566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(Pside, 1)); 19459566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(Pside, 1)); 19469566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(Pside, degree, PETSC_DETERMINE)); 19479566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(P, PETSCSPACETENSOR)); 19489566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetNumSubspaces(P, 2)); 19499566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetSubspace(P, 0, Pend)); 19509566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetSubspace(P, 1, Pside)); 19519566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pend)); 19529566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pside)); 19532df84da0SMatthew G. Knepley } 19542df84da0SMatthew G. Knepley } 19559566063dSJacob Faibussowitsch if (setFromOptions) PetscCall(PetscSpaceSetFromOptions(P)); 19569566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetUp(P)); 19579566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetDegree(P, °ree, NULL)); 19589566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialGetTensor(P, &tensor)); 19599566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetNumComponents(P, &Nc)); 19602df84da0SMatthew G. Knepley /* Create dual space */ 19619566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceCreate(comm, &Q)); 19629566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetType(Q,PETSCDUALSPACELAGRANGE)); 19639566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject) Q, prefix)); 19649566063dSJacob Faibussowitsch PetscCall(DMPlexCreateReferenceCell(PETSC_COMM_SELF, ct, &K)); 19659566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetDM(Q, K)); 19669566063dSJacob Faibussowitsch PetscCall(DMDestroy(&K)); 19679566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetNumComponents(Q, Nc)); 19689566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetOrder(Q, degree)); 19692df84da0SMatthew G. Knepley /* TODO For some reason, we need a tensor dualspace with wedges */ 19709566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceLagrangeSetTensor(Q, (tensor || (ct == DM_POLYTOPE_TRI_PRISM)) ? PETSC_TRUE : PETSC_FALSE)); 19719566063dSJacob Faibussowitsch if (setFromOptions) PetscCall(PetscDualSpaceSetFromOptions(Q)); 19729566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetUp(Q)); 1973*7c48043bSMatthew G. Knepley /* Create quadrature */ 19742df84da0SMatthew G. Knepley qorder = qorder >= 0 ? qorder : degree; 19752df84da0SMatthew G. Knepley if (setFromOptions) { 1976*7c48043bSMatthew G. Knepley PetscObjectOptionsBegin((PetscObject) P); 19779566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-petscfe_default_quadrature_order", "Quadrature order is one less than quadrature points per edge", "PetscFECreateDefault", qorder, &qorder, NULL, 0)); 1978d0609cedSBarry Smith PetscOptionsEnd(); 19792df84da0SMatthew G. Knepley } 1980*7c48043bSMatthew G. Knepley PetscCall(PetscFECreateDefaultQuadrature_Private(dim, ct, qorder, &q, &fq)); 1981*7c48043bSMatthew G. Knepley /* Create finite element */ 1982*7c48043bSMatthew G. Knepley PetscCall(PetscFECreateFromSpaces(P, Q, q, fq, fem)); 1983*7c48043bSMatthew G. Knepley if (setFromOptions) PetscCall(PetscFESetFromOptions(*fem)); 19842df84da0SMatthew G. Knepley PetscFunctionReturn(0); 19852df84da0SMatthew G. Knepley } 19862df84da0SMatthew G. Knepley 198720cf1dd8SToby Isaac /*@C 198820cf1dd8SToby Isaac PetscFECreateDefault - Create a PetscFE for basic FEM computation 198920cf1dd8SToby Isaac 1990d083f849SBarry Smith Collective 199120cf1dd8SToby Isaac 199220cf1dd8SToby Isaac Input Parameters: 19937be5e748SToby Isaac + comm - The MPI comm 199420cf1dd8SToby Isaac . dim - The spatial dimension 199520cf1dd8SToby Isaac . Nc - The number of components 199620cf1dd8SToby Isaac . isSimplex - Flag for simplex reference cell, otherwise its a tensor product 199720cf1dd8SToby Isaac . prefix - The options prefix, or NULL 1998727cddd5SJacob Faibussowitsch - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 199920cf1dd8SToby Isaac 200020cf1dd8SToby Isaac Output Parameter: 200120cf1dd8SToby Isaac . fem - The PetscFE object 200220cf1dd8SToby Isaac 2003e703855dSMatthew G. Knepley Note: 20048f2aacc6SMatthew 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. 2005e703855dSMatthew G. Knepley 200620cf1dd8SToby Isaac Level: beginner 200720cf1dd8SToby Isaac 2008db781477SPatrick Sanan .seealso: `PetscFECreateLagrange()`, `PetscFECreateByCell()`, `PetscSpaceSetFromOptions()`, `PetscDualSpaceSetFromOptions()`, `PetscFESetFromOptions()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 200920cf1dd8SToby Isaac @*/ 20107be5e748SToby Isaac PetscErrorCode PetscFECreateDefault(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, const char prefix[], PetscInt qorder, PetscFE *fem) 201120cf1dd8SToby Isaac { 201220cf1dd8SToby Isaac PetscFunctionBegin; 20139566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, DMPolytopeTypeSimpleShape(dim, isSimplex), prefix, PETSC_DECIDE, qorder, PETSC_TRUE, fem)); 20142df84da0SMatthew G. Knepley PetscFunctionReturn(0); 201520cf1dd8SToby Isaac } 20162df84da0SMatthew G. Knepley 20172df84da0SMatthew G. Knepley /*@C 20182df84da0SMatthew G. Knepley PetscFECreateByCell - Create a PetscFE for basic FEM computation 20192df84da0SMatthew G. Knepley 20202df84da0SMatthew G. Knepley Collective 20212df84da0SMatthew G. Knepley 20222df84da0SMatthew G. Knepley Input Parameters: 20232df84da0SMatthew G. Knepley + comm - The MPI comm 20242df84da0SMatthew G. Knepley . dim - The spatial dimension 20252df84da0SMatthew G. Knepley . Nc - The number of components 20262df84da0SMatthew G. Knepley . ct - The celltype of the reference cell 20272df84da0SMatthew G. Knepley . prefix - The options prefix, or NULL 20282df84da0SMatthew G. Knepley - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 20292df84da0SMatthew G. Knepley 20302df84da0SMatthew G. Knepley Output Parameter: 20312df84da0SMatthew G. Knepley . fem - The PetscFE object 20322df84da0SMatthew G. Knepley 20332df84da0SMatthew G. Knepley Note: 20342df84da0SMatthew 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. 20352df84da0SMatthew G. Knepley 20362df84da0SMatthew G. Knepley Level: beginner 20372df84da0SMatthew G. Knepley 2038db781477SPatrick Sanan .seealso: `PetscFECreateDefault()`, `PetscFECreateLagrange()`, `PetscSpaceSetFromOptions()`, `PetscDualSpaceSetFromOptions()`, `PetscFESetFromOptions()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 20392df84da0SMatthew G. Knepley @*/ 20402df84da0SMatthew G. Knepley PetscErrorCode PetscFECreateByCell(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, const char prefix[], PetscInt qorder, PetscFE *fem) 20412df84da0SMatthew G. Knepley { 20422df84da0SMatthew G. Knepley PetscFunctionBegin; 20439566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, ct, prefix, PETSC_DECIDE, qorder, PETSC_TRUE, fem)); 204420cf1dd8SToby Isaac PetscFunctionReturn(0); 204520cf1dd8SToby Isaac } 20463f6b16c7SMatthew G. Knepley 2047e703855dSMatthew G. Knepley /*@ 2048e703855dSMatthew G. Knepley PetscFECreateLagrange - Create a PetscFE for the basic Lagrange space of degree k 2049e703855dSMatthew G. Knepley 2050e703855dSMatthew G. Knepley Collective 2051e703855dSMatthew G. Knepley 2052e703855dSMatthew G. Knepley Input Parameters: 2053e703855dSMatthew G. Knepley + comm - The MPI comm 2054e703855dSMatthew G. Knepley . dim - The spatial dimension 2055e703855dSMatthew G. Knepley . Nc - The number of components 2056e703855dSMatthew G. Knepley . isSimplex - Flag for simplex reference cell, otherwise its a tensor product 2057e703855dSMatthew G. Knepley . k - The degree k of the space 2058e703855dSMatthew G. Knepley - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 2059e703855dSMatthew G. Knepley 2060e703855dSMatthew G. Knepley Output Parameter: 2061e703855dSMatthew G. Knepley . fem - The PetscFE object 2062e703855dSMatthew G. Knepley 2063e703855dSMatthew G. Knepley Level: beginner 2064e703855dSMatthew G. Knepley 2065e703855dSMatthew G. Knepley Notes: 2066e703855dSMatthew 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. 2067e703855dSMatthew G. Knepley 2068db781477SPatrick Sanan .seealso: `PetscFECreateLagrangeByCell()`, `PetscFECreateDefault()`, `PetscFECreateByCell()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 2069e703855dSMatthew G. Knepley @*/ 2070e703855dSMatthew G. Knepley PetscErrorCode PetscFECreateLagrange(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, PetscInt k, PetscInt qorder, PetscFE *fem) 2071e703855dSMatthew G. Knepley { 2072e703855dSMatthew G. Knepley PetscFunctionBegin; 20739566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, DMPolytopeTypeSimpleShape(dim, isSimplex), NULL, k, qorder, PETSC_FALSE, fem)); 20742df84da0SMatthew G. Knepley PetscFunctionReturn(0); 2075e703855dSMatthew G. Knepley } 20762df84da0SMatthew G. Knepley 20772df84da0SMatthew G. Knepley /*@ 20782df84da0SMatthew G. Knepley PetscFECreateLagrangeByCell - Create a PetscFE for the basic Lagrange space of degree k 20792df84da0SMatthew G. Knepley 20802df84da0SMatthew G. Knepley Collective 20812df84da0SMatthew G. Knepley 20822df84da0SMatthew G. Knepley Input Parameters: 20832df84da0SMatthew G. Knepley + comm - The MPI comm 20842df84da0SMatthew G. Knepley . dim - The spatial dimension 20852df84da0SMatthew G. Knepley . Nc - The number of components 20862df84da0SMatthew G. Knepley . ct - The celltype of the reference cell 20872df84da0SMatthew G. Knepley . k - The degree k of the space 20882df84da0SMatthew G. Knepley - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 20892df84da0SMatthew G. Knepley 20902df84da0SMatthew G. Knepley Output Parameter: 20912df84da0SMatthew G. Knepley . fem - The PetscFE object 20922df84da0SMatthew G. Knepley 20932df84da0SMatthew G. Knepley Level: beginner 20942df84da0SMatthew G. Knepley 20952df84da0SMatthew G. Knepley Notes: 20962df84da0SMatthew 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. 20972df84da0SMatthew G. Knepley 2098db781477SPatrick Sanan .seealso: `PetscFECreateLagrange()`, `PetscFECreateDefault()`, `PetscFECreateByCell()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 20992df84da0SMatthew G. Knepley @*/ 21002df84da0SMatthew G. Knepley PetscErrorCode PetscFECreateLagrangeByCell(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, PetscInt k, PetscInt qorder, PetscFE *fem) 21012df84da0SMatthew G. Knepley { 21022df84da0SMatthew G. Knepley PetscFunctionBegin; 21039566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, ct, NULL, k, qorder, PETSC_FALSE, fem)); 2104e703855dSMatthew G. Knepley PetscFunctionReturn(0); 2105e703855dSMatthew G. Knepley } 2106e703855dSMatthew G. Knepley 21073f6b16c7SMatthew G. Knepley /*@C 21083f6b16c7SMatthew G. Knepley PetscFESetName - Names the FE and its subobjects 21093f6b16c7SMatthew G. Knepley 21103f6b16c7SMatthew G. Knepley Not collective 21113f6b16c7SMatthew G. Knepley 21123f6b16c7SMatthew G. Knepley Input Parameters: 21133f6b16c7SMatthew G. Knepley + fe - The PetscFE 21143f6b16c7SMatthew G. Knepley - name - The name 21153f6b16c7SMatthew G. Knepley 21162b99622eSMatthew G. Knepley Level: intermediate 21173f6b16c7SMatthew G. Knepley 2118db781477SPatrick Sanan .seealso: `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 21193f6b16c7SMatthew G. Knepley @*/ 21203f6b16c7SMatthew G. Knepley PetscErrorCode PetscFESetName(PetscFE fe, const char name[]) 21213f6b16c7SMatthew G. Knepley { 21223f6b16c7SMatthew G. Knepley PetscSpace P; 21233f6b16c7SMatthew G. Knepley PetscDualSpace Q; 21243f6b16c7SMatthew G. Knepley 21253f6b16c7SMatthew G. Knepley PetscFunctionBegin; 21269566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 21279566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 21289566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject) fe, name)); 21299566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject) P, name)); 21309566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject) Q, name)); 21313f6b16c7SMatthew G. Knepley PetscFunctionReturn(0); 21323f6b16c7SMatthew G. Knepley } 2133a8f1f9e5SMatthew G. Knepley 2134ef0bb6c7SMatthew 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[]) 2135a8f1f9e5SMatthew G. Knepley { 2136f9244615SMatthew G. Knepley PetscInt dOffset = 0, fOffset = 0, f, g; 2137a8f1f9e5SMatthew G. Knepley 2138a8f1f9e5SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 2139a8f1f9e5SMatthew G. Knepley PetscFE fe; 2140f9244615SMatthew G. Knepley const PetscInt k = ds->jetDegree[f]; 2141ef0bb6c7SMatthew G. Knepley const PetscInt cdim = T[f]->cdim; 2142ef0bb6c7SMatthew G. Knepley const PetscInt Nq = T[f]->Np; 2143ef0bb6c7SMatthew G. Knepley const PetscInt Nbf = T[f]->Nb; 2144ef0bb6c7SMatthew G. Knepley const PetscInt Ncf = T[f]->Nc; 2145ef0bb6c7SMatthew G. Knepley const PetscReal *Bq = &T[f]->T[0][(r*Nq+q)*Nbf*Ncf]; 2146ef0bb6c7SMatthew G. Knepley const PetscReal *Dq = &T[f]->T[1][(r*Nq+q)*Nbf*Ncf*cdim]; 2147f9244615SMatthew G. Knepley const PetscReal *Hq = k > 1 ? &T[f]->T[2][(r*Nq+q)*Nbf*Ncf*cdim*cdim] : NULL; 2148f9244615SMatthew G. Knepley PetscInt hOffset = 0, b, c, d; 2149a8f1f9e5SMatthew G. Knepley 21509566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, f, (PetscObject *) &fe)); 2151a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u[fOffset+c] = 0.0; 2152ef0bb6c7SMatthew G. Knepley for (d = 0; d < cdim*Ncf; ++d) u_x[fOffset*cdim+d] = 0.0; 2153a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2154a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2155a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 2156a8f1f9e5SMatthew G. Knepley 2157a8f1f9e5SMatthew G. Knepley u[fOffset+c] += Bq[cidx]*coefficients[dOffset+b]; 2158ef0bb6c7SMatthew G. Knepley for (d = 0; d < cdim; ++d) u_x[(fOffset+c)*cdim+d] += Dq[cidx*cdim+d]*coefficients[dOffset+b]; 2159a8f1f9e5SMatthew G. Knepley } 2160a8f1f9e5SMatthew G. Knepley } 2161f9244615SMatthew G. Knepley if (k > 1) { 2162f9244615SMatthew G. Knepley for (g = 0; g < Nf; ++g) hOffset += T[g]->Nc*cdim; 2163f9244615SMatthew G. Knepley for (d = 0; d < cdim*cdim*Ncf; ++d) u_x[hOffset+fOffset*cdim*cdim+d] = 0.0; 2164f9244615SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2165f9244615SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2166f9244615SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 2167f9244615SMatthew G. Knepley 2168f9244615SMatthew 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]; 2169f9244615SMatthew G. Knepley } 2170f9244615SMatthew G. Knepley } 21719566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardHessian(fe, fegeom, 1, &u_x[hOffset+fOffset*cdim*cdim])); 2172f9244615SMatthew G. Knepley } 21739566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u[fOffset])); 21749566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset*cdim])); 2175a8f1f9e5SMatthew G. Knepley if (u_t) { 2176a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u_t[fOffset+c] = 0.0; 2177a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2178a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2179a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 2180a8f1f9e5SMatthew G. Knepley 2181a8f1f9e5SMatthew G. Knepley u_t[fOffset+c] += Bq[cidx]*coefficients_t[dOffset+b]; 2182a8f1f9e5SMatthew G. Knepley } 2183a8f1f9e5SMatthew G. Knepley } 21849566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset])); 2185a8f1f9e5SMatthew G. Knepley } 2186a8f1f9e5SMatthew G. Knepley fOffset += Ncf; 2187a8f1f9e5SMatthew G. Knepley dOffset += Nbf; 2188a8f1f9e5SMatthew G. Knepley } 2189a8f1f9e5SMatthew G. Knepley return 0; 2190a8f1f9e5SMatthew G. Knepley } 2191a8f1f9e5SMatthew G. Knepley 2192665f567fSMatthew 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[]) 219327f02ce8SMatthew G. Knepley { 21945fedec97SMatthew G. Knepley PetscInt dOffset = 0, fOffset = 0, f, g; 219527f02ce8SMatthew G. Knepley 21965fedec97SMatthew G. Knepley /* f is the field number in the DS, g is the field number in u[] */ 21975fedec97SMatthew G. Knepley for (f = 0, g = 0; f < Nf; ++f) { 21985fedec97SMatthew G. Knepley PetscFE fe = (PetscFE) ds->disc[f]; 21999ee2af8cSMatthew G. Knepley const PetscInt dEt = T[f]->cdim; 22009ee2af8cSMatthew G. Knepley const PetscInt dE = fegeom->dimEmbed; 2201665f567fSMatthew G. Knepley const PetscInt Nq = T[f]->Np; 2202665f567fSMatthew G. Knepley const PetscInt Nbf = T[f]->Nb; 2203665f567fSMatthew G. Knepley const PetscInt Ncf = T[f]->Nc; 2204665f567fSMatthew G. Knepley const PetscReal *Bq = &T[f]->T[0][(r*Nq+q)*Nbf*Ncf]; 22059ee2af8cSMatthew G. Knepley const PetscReal *Dq = &T[f]->T[1][(r*Nq+q)*Nbf*Ncf*dEt]; 22065fedec97SMatthew G. Knepley PetscBool isCohesive; 22075fedec97SMatthew G. Knepley PetscInt Ns, s; 22085fedec97SMatthew G. Knepley 22095fedec97SMatthew G. Knepley if (!T[f]) continue; 22109566063dSJacob Faibussowitsch PetscCall(PetscDSGetCohesive(ds, f, &isCohesive)); 22115fedec97SMatthew G. Knepley Ns = isCohesive ? 1 : 2; 22125fedec97SMatthew G. Knepley for (s = 0; s < Ns; ++s, ++g) { 221327f02ce8SMatthew G. Knepley PetscInt b, c, d; 221427f02ce8SMatthew G. Knepley 221527f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u[fOffset+c] = 0.0; 22169ee2af8cSMatthew G. Knepley for (d = 0; d < dE*Ncf; ++d) u_x[fOffset*dE+d] = 0.0; 221727f02ce8SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 221827f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 221927f02ce8SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 222027f02ce8SMatthew G. Knepley 222127f02ce8SMatthew G. Knepley u[fOffset+c] += Bq[cidx]*coefficients[dOffset+b]; 22229ee2af8cSMatthew G. Knepley for (d = 0; d < dEt; ++d) u_x[(fOffset+c)*dE+d] += Dq[cidx*dEt+d]*coefficients[dOffset+b]; 222327f02ce8SMatthew G. Knepley } 222427f02ce8SMatthew G. Knepley } 22259566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u[fOffset])); 22269566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset*dE])); 222727f02ce8SMatthew G. Knepley if (u_t) { 222827f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u_t[fOffset+c] = 0.0; 222927f02ce8SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 223027f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 223127f02ce8SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 223227f02ce8SMatthew G. Knepley 223327f02ce8SMatthew G. Knepley u_t[fOffset+c] += Bq[cidx]*coefficients_t[dOffset+b]; 223427f02ce8SMatthew G. Knepley } 223527f02ce8SMatthew G. Knepley } 22369566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset])); 223727f02ce8SMatthew G. Knepley } 223827f02ce8SMatthew G. Knepley fOffset += Ncf; 223927f02ce8SMatthew G. Knepley dOffset += Nbf; 224027f02ce8SMatthew G. Knepley } 2241665f567fSMatthew G. Knepley } 224227f02ce8SMatthew G. Knepley return 0; 224327f02ce8SMatthew G. Knepley } 224427f02ce8SMatthew G. Knepley 2245a8f1f9e5SMatthew G. Knepley PetscErrorCode PetscFEEvaluateFaceFields_Internal(PetscDS prob, PetscInt field, PetscInt faceLoc, const PetscScalar coefficients[], PetscScalar u[]) 2246a8f1f9e5SMatthew G. Knepley { 2247a8f1f9e5SMatthew G. Knepley PetscFE fe; 2248ef0bb6c7SMatthew G. Knepley PetscTabulation Tc; 2249ef0bb6c7SMatthew G. Knepley PetscInt b, c; 2250a8f1f9e5SMatthew G. Knepley 2251a8f1f9e5SMatthew G. Knepley if (!prob) return 0; 22529566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *) &fe)); 22539566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceCentroidTabulation(fe, &Tc)); 2254ef0bb6c7SMatthew G. Knepley { 2255ef0bb6c7SMatthew G. Knepley const PetscReal *faceBasis = Tc->T[0]; 2256ef0bb6c7SMatthew G. Knepley const PetscInt Nb = Tc->Nb; 2257ef0bb6c7SMatthew G. Knepley const PetscInt Nc = Tc->Nc; 2258ef0bb6c7SMatthew G. Knepley 2259a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) {u[c] = 0.0;} 2260a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2261a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2262813a933aSJed Brown u[c] += coefficients[b] * faceBasis[(faceLoc*Nb + b)*Nc + c]; 2263a8f1f9e5SMatthew G. Knepley } 2264a8f1f9e5SMatthew G. Knepley } 2265ef0bb6c7SMatthew G. Knepley } 2266a8f1f9e5SMatthew G. Knepley return 0; 2267a8f1f9e5SMatthew G. Knepley } 2268a8f1f9e5SMatthew G. Knepley 22696587ee25SMatthew 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[]) 2270a8f1f9e5SMatthew G. Knepley { 22716587ee25SMatthew G. Knepley PetscFEGeom pgeom; 2272bc3a64adSMatthew G. Knepley const PetscInt dEt = T->cdim; 2273bc3a64adSMatthew G. Knepley const PetscInt dE = fegeom->dimEmbed; 2274ef0bb6c7SMatthew G. Knepley const PetscInt Nq = T->Np; 2275ef0bb6c7SMatthew G. Knepley const PetscInt Nb = T->Nb; 2276ef0bb6c7SMatthew G. Knepley const PetscInt Nc = T->Nc; 2277ef0bb6c7SMatthew G. Knepley const PetscReal *basis = &T->T[0][r*Nq*Nb*Nc]; 2278bc3a64adSMatthew G. Knepley const PetscReal *basisDer = &T->T[1][r*Nq*Nb*Nc*dEt]; 2279a8f1f9e5SMatthew G. Knepley PetscInt q, b, c, d; 2280a8f1f9e5SMatthew G. Knepley 2281a8f1f9e5SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 2282a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2283a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2284a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 2285a8f1f9e5SMatthew G. Knepley 2286a8f1f9e5SMatthew G. Knepley tmpBasis[bcidx] = basis[q*Nb*Nc+bcidx]; 2287bc3a64adSMatthew G. Knepley for (d = 0; d < dEt; ++d) tmpBasisDer[bcidx*dE+d] = basisDer[q*Nb*Nc*dEt+bcidx*dEt+d]; 22889ee2af8cSMatthew G. Knepley for (d = dEt; d < dE; ++d) tmpBasisDer[bcidx*dE+d] = 0.0; 2289a8f1f9e5SMatthew G. Knepley } 2290a8f1f9e5SMatthew G. Knepley } 22919566063dSJacob Faibussowitsch PetscCall(PetscFEGeomGetCellPoint(fegeom, e, q, &pgeom)); 22929566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, &pgeom, Nb, tmpBasis)); 22939566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, &pgeom, Nb, tmpBasisDer)); 2294a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2295a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2296a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 2297a8f1f9e5SMatthew G. Knepley const PetscInt qcidx = q*Nc+c; 2298a8f1f9e5SMatthew G. Knepley 2299a8f1f9e5SMatthew G. Knepley elemVec[b] += tmpBasis[bcidx]*f0[qcidx]; 230027f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) elemVec[b] += tmpBasisDer[bcidx*dE+d]*f1[qcidx*dE+d]; 230127f02ce8SMatthew G. Knepley } 230227f02ce8SMatthew G. Knepley } 230327f02ce8SMatthew G. Knepley } 230427f02ce8SMatthew G. Knepley return(0); 230527f02ce8SMatthew G. Knepley } 230627f02ce8SMatthew G. Knepley 2307c2b7495fSMatthew 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[]) 230827f02ce8SMatthew G. Knepley { 230927f02ce8SMatthew G. Knepley const PetscInt dE = T->cdim; 231027f02ce8SMatthew G. Knepley const PetscInt Nq = T->Np; 231127f02ce8SMatthew G. Knepley const PetscInt Nb = T->Nb; 231227f02ce8SMatthew G. Knepley const PetscInt Nc = T->Nc; 231327f02ce8SMatthew G. Knepley const PetscReal *basis = &T->T[0][r*Nq*Nb*Nc]; 231427f02ce8SMatthew G. Knepley const PetscReal *basisDer = &T->T[1][r*Nq*Nb*Nc*dE]; 2315c2b7495fSMatthew G. Knepley PetscInt q, b, c, d; 231627f02ce8SMatthew G. Knepley 231727f02ce8SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 231827f02ce8SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 231927f02ce8SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 232027f02ce8SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 232127f02ce8SMatthew G. Knepley 232227f02ce8SMatthew G. Knepley tmpBasis[bcidx] = basis[q*Nb*Nc+bcidx]; 232327f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) tmpBasisDer[bcidx*dE+d] = basisDer[q*Nb*Nc*dE+bcidx*dE+d]; 232427f02ce8SMatthew G. Knepley } 232527f02ce8SMatthew G. Knepley } 23269566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, Nb, tmpBasis)); 23279566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, Nb, tmpBasisDer)); 232827f02ce8SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 232927f02ce8SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 233027f02ce8SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 2331c2b7495fSMatthew G. Knepley const PetscInt qcidx = q*Nc+c; 233227f02ce8SMatthew G. Knepley 233327f02ce8SMatthew G. Knepley elemVec[Nb*s+b] += tmpBasis[bcidx]*f0[qcidx]; 233427f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) elemVec[Nb*s+b] += tmpBasisDer[bcidx*dE+d]*f1[qcidx*dE+d]; 233527f02ce8SMatthew G. Knepley } 2336a8f1f9e5SMatthew G. Knepley } 2337a8f1f9e5SMatthew G. Knepley } 2338a8f1f9e5SMatthew G. Knepley return(0); 2339a8f1f9e5SMatthew G. Knepley } 2340a8f1f9e5SMatthew G. Knepley 2341ef0bb6c7SMatthew 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[]) 2342a8f1f9e5SMatthew G. Knepley { 234327f02ce8SMatthew G. Knepley const PetscInt dE = TI->cdim; 2344ef0bb6c7SMatthew G. Knepley const PetscInt NqI = TI->Np; 2345ef0bb6c7SMatthew G. Knepley const PetscInt NbI = TI->Nb; 2346ef0bb6c7SMatthew G. Knepley const PetscInt NcI = TI->Nc; 2347ef0bb6c7SMatthew G. Knepley const PetscReal *basisI = &TI->T[0][(r*NqI+q)*NbI*NcI]; 2348665f567fSMatthew G. Knepley const PetscReal *basisDerI = &TI->T[1][(r*NqI+q)*NbI*NcI*dE]; 2349ef0bb6c7SMatthew G. Knepley const PetscInt NqJ = TJ->Np; 2350ef0bb6c7SMatthew G. Knepley const PetscInt NbJ = TJ->Nb; 2351ef0bb6c7SMatthew G. Knepley const PetscInt NcJ = TJ->Nc; 2352ef0bb6c7SMatthew G. Knepley const PetscReal *basisJ = &TJ->T[0][(r*NqJ+q)*NbJ*NcJ]; 2353665f567fSMatthew G. Knepley const PetscReal *basisDerJ = &TJ->T[1][(r*NqJ+q)*NbJ*NcJ*dE]; 2354a8f1f9e5SMatthew G. Knepley PetscInt f, fc, g, gc, df, dg; 2355a8f1f9e5SMatthew G. Knepley 2356a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 2357a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 2358a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 2359a8f1f9e5SMatthew G. Knepley 2360a8f1f9e5SMatthew G. Knepley tmpBasisI[fidx] = basisI[fidx]; 236127f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) tmpBasisDerI[fidx*dE+df] = basisDerI[fidx*dE+df]; 2362a8f1f9e5SMatthew G. Knepley } 2363a8f1f9e5SMatthew G. Knepley } 23649566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feI, fegeom, NbI, tmpBasisI)); 23659566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI)); 2366a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 2367a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 2368a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 2369a8f1f9e5SMatthew G. Knepley 2370a8f1f9e5SMatthew G. Knepley tmpBasisJ[gidx] = basisJ[gidx]; 237127f02ce8SMatthew G. Knepley for (dg = 0; dg < dE; ++dg) tmpBasisDerJ[gidx*dE+dg] = basisDerJ[gidx*dE+dg]; 2372a8f1f9e5SMatthew G. Knepley } 2373a8f1f9e5SMatthew G. Knepley } 23749566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ)); 23759566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ)); 2376a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 2377a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 2378a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 2379a8f1f9e5SMatthew G. Knepley const PetscInt i = offsetI+f; /* Element matrix row */ 2380a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 2381a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 2382a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 2383a8f1f9e5SMatthew G. Knepley const PetscInt j = offsetJ+g; /* Element matrix column */ 2384a8f1f9e5SMatthew G. Knepley const PetscInt fOff = eOffset+i*totDim+j; 2385a8f1f9e5SMatthew G. Knepley 2386a8f1f9e5SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g0[fc*NcJ+gc]*tmpBasisJ[gidx]; 238727f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) { 238827f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g1[(fc*NcJ+gc)*dE+df]*tmpBasisDerJ[gidx*dE+df]; 238927f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g2[(fc*NcJ+gc)*dE+df]*tmpBasisJ[gidx]; 239027f02ce8SMatthew G. Knepley for (dg = 0; dg < dE; ++dg) { 239127f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g3[((fc*NcJ+gc)*dE+df)*dE+dg]*tmpBasisDerJ[gidx*dE+dg]; 239227f02ce8SMatthew G. Knepley } 239327f02ce8SMatthew G. Knepley } 239427f02ce8SMatthew G. Knepley } 239527f02ce8SMatthew G. Knepley } 239627f02ce8SMatthew G. Knepley } 239727f02ce8SMatthew G. Knepley } 239827f02ce8SMatthew G. Knepley return(0); 239927f02ce8SMatthew G. Knepley } 240027f02ce8SMatthew G. Knepley 24015fedec97SMatthew 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[]) 240227f02ce8SMatthew G. Knepley { 2403665f567fSMatthew G. Knepley const PetscInt dE = TI->cdim; 2404665f567fSMatthew G. Knepley const PetscInt NqI = TI->Np; 2405665f567fSMatthew G. Knepley const PetscInt NbI = TI->Nb; 2406665f567fSMatthew G. Knepley const PetscInt NcI = TI->Nc; 2407665f567fSMatthew G. Knepley const PetscReal *basisI = &TI->T[0][(r*NqI+q)*NbI*NcI]; 2408665f567fSMatthew G. Knepley const PetscReal *basisDerI = &TI->T[1][(r*NqI+q)*NbI*NcI*dE]; 2409665f567fSMatthew G. Knepley const PetscInt NqJ = TJ->Np; 2410665f567fSMatthew G. Knepley const PetscInt NbJ = TJ->Nb; 2411665f567fSMatthew G. Knepley const PetscInt NcJ = TJ->Nc; 2412665f567fSMatthew G. Knepley const PetscReal *basisJ = &TJ->T[0][(r*NqJ+q)*NbJ*NcJ]; 2413665f567fSMatthew G. Knepley const PetscReal *basisDerJ = &TJ->T[1][(r*NqJ+q)*NbJ*NcJ*dE]; 24145fedec97SMatthew G. Knepley const PetscInt so = isHybridI ? 0 : s; 24155fedec97SMatthew G. Knepley const PetscInt to = isHybridJ ? 0 : s; 24165fedec97SMatthew G. Knepley PetscInt f, fc, g, gc, df, dg; 241727f02ce8SMatthew G. Knepley 241827f02ce8SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 241927f02ce8SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 242027f02ce8SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 242127f02ce8SMatthew G. Knepley 242227f02ce8SMatthew G. Knepley tmpBasisI[fidx] = basisI[fidx]; 2423665f567fSMatthew G. Knepley for (df = 0; df < dE; ++df) tmpBasisDerI[fidx*dE+df] = basisDerI[fidx*dE+df]; 242427f02ce8SMatthew G. Knepley } 242527f02ce8SMatthew G. Knepley } 24269566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feI, fegeom, NbI, tmpBasisI)); 24279566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI)); 242827f02ce8SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 242927f02ce8SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 243027f02ce8SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 243127f02ce8SMatthew G. Knepley 243227f02ce8SMatthew G. Knepley tmpBasisJ[gidx] = basisJ[gidx]; 2433665f567fSMatthew G. Knepley for (dg = 0; dg < dE; ++dg) tmpBasisDerJ[gidx*dE+dg] = basisDerJ[gidx*dE+dg]; 243427f02ce8SMatthew G. Knepley } 243527f02ce8SMatthew G. Knepley } 24369566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ)); 24379566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ)); 243827f02ce8SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 243927f02ce8SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 244027f02ce8SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 24415fedec97SMatthew G. Knepley const PetscInt i = offsetI+NbI*so+f; /* Element matrix row */ 244227f02ce8SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 244327f02ce8SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 244427f02ce8SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 24455fedec97SMatthew G. Knepley const PetscInt j = offsetJ+NbJ*to+g; /* Element matrix column */ 244627f02ce8SMatthew G. Knepley const PetscInt fOff = eOffset+i*totDim+j; 244727f02ce8SMatthew G. Knepley 24485fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g0[fc*NcJ+gc]*tmpBasisJ[gidx]; 244927f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) { 24505fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g1[(fc*NcJ+gc)*dE+df]*tmpBasisDerJ[gidx*dE+df]; 24515fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g2[(fc*NcJ+gc)*dE+df]*tmpBasisJ[gidx]; 245227f02ce8SMatthew G. Knepley for (dg = 0; dg < dE; ++dg) { 24535fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g3[((fc*NcJ+gc)*dE+df)*dE+dg]*tmpBasisDerJ[gidx*dE+dg]; 2454a8f1f9e5SMatthew G. Knepley } 2455a8f1f9e5SMatthew G. Knepley } 2456a8f1f9e5SMatthew G. Knepley } 2457a8f1f9e5SMatthew G. Knepley } 2458a8f1f9e5SMatthew G. Knepley } 2459a8f1f9e5SMatthew G. Knepley } 2460a8f1f9e5SMatthew G. Knepley return(0); 2461a8f1f9e5SMatthew G. Knepley } 2462c9ba7969SMatthew G. Knepley 2463c9ba7969SMatthew G. Knepley PetscErrorCode PetscFECreateCellGeometry(PetscFE fe, PetscQuadrature quad, PetscFEGeom *cgeom) 2464c9ba7969SMatthew G. Knepley { 2465c9ba7969SMatthew G. Knepley PetscDualSpace dsp; 2466c9ba7969SMatthew G. Knepley DM dm; 2467c9ba7969SMatthew G. Knepley PetscQuadrature quadDef; 2468c9ba7969SMatthew G. Knepley PetscInt dim, cdim, Nq; 2469c9ba7969SMatthew G. Knepley 2470c9ba7969SMatthew G. Knepley PetscFunctionBegin; 24719566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &dsp)); 24729566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp, &dm)); 24739566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 24749566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDim(dm, &cdim)); 24759566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &quadDef)); 2476c9ba7969SMatthew G. Knepley quad = quad ? quad : quadDef; 24779566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(quad, NULL, NULL, &Nq, NULL, NULL)); 24789566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq*cdim, &cgeom->v)); 24799566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq*cdim*cdim, &cgeom->J)); 24809566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq*cdim*cdim, &cgeom->invJ)); 24819566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq, &cgeom->detJ)); 2482c9ba7969SMatthew G. Knepley cgeom->dim = dim; 2483c9ba7969SMatthew G. Knepley cgeom->dimEmbed = cdim; 2484c9ba7969SMatthew G. Knepley cgeom->numCells = 1; 2485c9ba7969SMatthew G. Knepley cgeom->numPoints = Nq; 24869566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm, 0, quad, cgeom->v, cgeom->J, cgeom->invJ, cgeom->detJ)); 2487c9ba7969SMatthew G. Knepley PetscFunctionReturn(0); 2488c9ba7969SMatthew G. Knepley } 2489c9ba7969SMatthew G. Knepley 2490c9ba7969SMatthew G. Knepley PetscErrorCode PetscFEDestroyCellGeometry(PetscFE fe, PetscFEGeom *cgeom) 2491c9ba7969SMatthew G. Knepley { 2492c9ba7969SMatthew G. Knepley PetscFunctionBegin; 24939566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->v)); 24949566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->J)); 24959566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->invJ)); 24969566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->detJ)); 2497c9ba7969SMatthew G. Knepley PetscFunctionReturn(0); 2498c9ba7969SMatthew G. Knepley } 2499