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 @*/ 90*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFERegister(const char sname[], PetscErrorCode (*function)(PetscFE)) 91*d71ae5a4SJacob Faibussowitsch { 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 @*/ 113*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetType(PetscFE fem, PetscFEType name) 114*d71ae5a4SJacob Faibussowitsch { 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 127dbbe0bcdSBarry Smith PetscTryTypeMethod(fem, destroy); 12820cf1dd8SToby Isaac fem->ops->destroy = NULL; 129dbbe0bcdSBarry Smith 1309566063dSJacob Faibussowitsch PetscCall((*r)(fem)); 1319566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)fem, name)); 13220cf1dd8SToby Isaac PetscFunctionReturn(0); 13320cf1dd8SToby Isaac } 13420cf1dd8SToby Isaac 13520cf1dd8SToby Isaac /*@C 13620cf1dd8SToby Isaac PetscFEGetType - Gets the PetscFE type name (as a string) from the object. 13720cf1dd8SToby Isaac 13820cf1dd8SToby Isaac Not Collective 13920cf1dd8SToby Isaac 14020cf1dd8SToby Isaac Input Parameter: 14120cf1dd8SToby Isaac . fem - The PetscFE 14220cf1dd8SToby Isaac 14320cf1dd8SToby Isaac Output Parameter: 14420cf1dd8SToby Isaac . name - The PetscFE type name 14520cf1dd8SToby Isaac 14620cf1dd8SToby Isaac Level: intermediate 14720cf1dd8SToby Isaac 148db781477SPatrick Sanan .seealso: `PetscFESetType()`, `PetscFECreate()` 14920cf1dd8SToby Isaac @*/ 150*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetType(PetscFE fem, PetscFEType *name) 151*d71ae5a4SJacob Faibussowitsch { 15220cf1dd8SToby Isaac PetscFunctionBegin; 15320cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 15420cf1dd8SToby Isaac PetscValidPointer(name, 2); 15548a46eb9SPierre Jolivet if (!PetscFERegisterAllCalled) PetscCall(PetscFERegisterAll()); 15620cf1dd8SToby Isaac *name = ((PetscObject)fem)->type_name; 15720cf1dd8SToby Isaac PetscFunctionReturn(0); 15820cf1dd8SToby Isaac } 15920cf1dd8SToby Isaac 16020cf1dd8SToby Isaac /*@C 161fe2efc57SMark PetscFEViewFromOptions - View from Options 162fe2efc57SMark 163fe2efc57SMark Collective on PetscFE 164fe2efc57SMark 165fe2efc57SMark Input Parameters: 166fe2efc57SMark + A - the PetscFE object 167fe2efc57SMark . obj - Optional object 168fe2efc57SMark - name - command line option 169fe2efc57SMark 170fe2efc57SMark Level: intermediate 171db781477SPatrick Sanan .seealso: `PetscFE()`, `PetscFEView()`, `PetscObjectViewFromOptions()`, `PetscFECreate()` 172fe2efc57SMark @*/ 173*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEViewFromOptions(PetscFE A, PetscObject obj, const char name[]) 174*d71ae5a4SJacob Faibussowitsch { 175fe2efc57SMark PetscFunctionBegin; 176fe2efc57SMark PetscValidHeaderSpecific(A, PETSCFE_CLASSID, 1); 1779566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name)); 178fe2efc57SMark PetscFunctionReturn(0); 179fe2efc57SMark } 180fe2efc57SMark 181fe2efc57SMark /*@C 18220cf1dd8SToby Isaac PetscFEView - Views a PetscFE 18320cf1dd8SToby Isaac 184d083f849SBarry Smith Collective on fem 18520cf1dd8SToby Isaac 186d8d19677SJose E. Roman Input Parameters: 18720cf1dd8SToby Isaac + fem - the PetscFE object to view 188d9bac1caSLisandro Dalcin - viewer - the viewer 18920cf1dd8SToby Isaac 1902b99622eSMatthew G. Knepley Level: beginner 19120cf1dd8SToby Isaac 192db781477SPatrick Sanan .seealso `PetscFEDestroy()` 19320cf1dd8SToby Isaac @*/ 194*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEView(PetscFE fem, PetscViewer viewer) 195*d71ae5a4SJacob Faibussowitsch { 196d9bac1caSLisandro Dalcin PetscBool iascii; 19720cf1dd8SToby Isaac 19820cf1dd8SToby Isaac PetscFunctionBegin; 19920cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 200d9bac1caSLisandro Dalcin if (viewer) PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 2019566063dSJacob Faibussowitsch if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)fem), &viewer)); 2029566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)fem, viewer)); 2039566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &iascii)); 204dbbe0bcdSBarry Smith PetscTryTypeMethod(fem, view, viewer); 20520cf1dd8SToby Isaac PetscFunctionReturn(0); 20620cf1dd8SToby Isaac } 20720cf1dd8SToby Isaac 20820cf1dd8SToby Isaac /*@ 20920cf1dd8SToby Isaac PetscFESetFromOptions - sets parameters in a PetscFE from the options database 21020cf1dd8SToby Isaac 211d083f849SBarry Smith Collective on fem 21220cf1dd8SToby Isaac 21320cf1dd8SToby Isaac Input Parameter: 21420cf1dd8SToby Isaac . fem - the PetscFE object to set options for 21520cf1dd8SToby Isaac 21620cf1dd8SToby Isaac Options Database: 217a2b725a8SWilliam Gropp + -petscfe_num_blocks - the number of cell blocks to integrate concurrently 218a2b725a8SWilliam Gropp - -petscfe_num_batches - the number of cell batches to integrate serially 21920cf1dd8SToby Isaac 2202b99622eSMatthew G. Knepley Level: intermediate 22120cf1dd8SToby Isaac 222db781477SPatrick Sanan .seealso `PetscFEView()` 22320cf1dd8SToby Isaac @*/ 224*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetFromOptions(PetscFE fem) 225*d71ae5a4SJacob Faibussowitsch { 22620cf1dd8SToby Isaac const char *defaultType; 22720cf1dd8SToby Isaac char name[256]; 22820cf1dd8SToby Isaac PetscBool flg; 22920cf1dd8SToby Isaac 23020cf1dd8SToby Isaac PetscFunctionBegin; 23120cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 23220cf1dd8SToby Isaac if (!((PetscObject)fem)->type_name) { 23320cf1dd8SToby Isaac defaultType = PETSCFEBASIC; 23420cf1dd8SToby Isaac } else { 23520cf1dd8SToby Isaac defaultType = ((PetscObject)fem)->type_name; 23620cf1dd8SToby Isaac } 2379566063dSJacob Faibussowitsch if (!PetscFERegisterAllCalled) PetscCall(PetscFERegisterAll()); 23820cf1dd8SToby Isaac 239d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject)fem); 2409566063dSJacob Faibussowitsch PetscCall(PetscOptionsFList("-petscfe_type", "Finite element space", "PetscFESetType", PetscFEList, defaultType, name, 256, &flg)); 24120cf1dd8SToby Isaac if (flg) { 2429566063dSJacob Faibussowitsch PetscCall(PetscFESetType(fem, name)); 24320cf1dd8SToby Isaac } else if (!((PetscObject)fem)->type_name) { 2449566063dSJacob Faibussowitsch PetscCall(PetscFESetType(fem, defaultType)); 24520cf1dd8SToby Isaac } 2469566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-petscfe_num_blocks", "The number of cell blocks to integrate concurrently", "PetscSpaceSetTileSizes", fem->numBlocks, &fem->numBlocks, NULL, 1)); 2479566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-petscfe_num_batches", "The number of cell batches to integrate serially", "PetscSpaceSetTileSizes", fem->numBatches, &fem->numBatches, NULL, 1)); 248dbbe0bcdSBarry Smith PetscTryTypeMethod(fem, setfromoptions, PetscOptionsObject); 24920cf1dd8SToby Isaac /* process any options handlers added with PetscObjectAddOptionsHandler() */ 250dbbe0bcdSBarry Smith PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)fem, PetscOptionsObject)); 251d0609cedSBarry Smith PetscOptionsEnd(); 2529566063dSJacob Faibussowitsch PetscCall(PetscFEViewFromOptions(fem, NULL, "-petscfe_view")); 25320cf1dd8SToby Isaac PetscFunctionReturn(0); 25420cf1dd8SToby Isaac } 25520cf1dd8SToby Isaac 25620cf1dd8SToby Isaac /*@C 25720cf1dd8SToby Isaac PetscFESetUp - Construct data structures for the PetscFE 25820cf1dd8SToby Isaac 259d083f849SBarry Smith Collective on fem 26020cf1dd8SToby Isaac 26120cf1dd8SToby Isaac Input Parameter: 26220cf1dd8SToby Isaac . fem - the PetscFE object to setup 26320cf1dd8SToby Isaac 2642b99622eSMatthew G. Knepley Level: intermediate 26520cf1dd8SToby Isaac 266db781477SPatrick Sanan .seealso `PetscFEView()`, `PetscFEDestroy()` 26720cf1dd8SToby Isaac @*/ 268*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetUp(PetscFE fem) 269*d71ae5a4SJacob Faibussowitsch { 27020cf1dd8SToby Isaac PetscFunctionBegin; 27120cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 27220cf1dd8SToby Isaac if (fem->setupcalled) PetscFunctionReturn(0); 2739566063dSJacob Faibussowitsch PetscCall(PetscLogEventBegin(PETSCFE_SetUp, fem, 0, 0, 0)); 27420cf1dd8SToby Isaac fem->setupcalled = PETSC_TRUE; 275dbbe0bcdSBarry Smith PetscTryTypeMethod(fem, setup); 2769566063dSJacob Faibussowitsch PetscCall(PetscLogEventEnd(PETSCFE_SetUp, fem, 0, 0, 0)); 27720cf1dd8SToby Isaac PetscFunctionReturn(0); 27820cf1dd8SToby Isaac } 27920cf1dd8SToby Isaac 28020cf1dd8SToby Isaac /*@ 28120cf1dd8SToby Isaac PetscFEDestroy - Destroys a PetscFE object 28220cf1dd8SToby Isaac 283d083f849SBarry Smith Collective on fem 28420cf1dd8SToby Isaac 28520cf1dd8SToby Isaac Input Parameter: 28620cf1dd8SToby Isaac . fem - the PetscFE object to destroy 28720cf1dd8SToby Isaac 2882b99622eSMatthew G. Knepley Level: beginner 28920cf1dd8SToby Isaac 290db781477SPatrick Sanan .seealso `PetscFEView()` 29120cf1dd8SToby Isaac @*/ 292*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEDestroy(PetscFE *fem) 293*d71ae5a4SJacob Faibussowitsch { 29420cf1dd8SToby Isaac PetscFunctionBegin; 29520cf1dd8SToby Isaac if (!*fem) PetscFunctionReturn(0); 29620cf1dd8SToby Isaac PetscValidHeaderSpecific((*fem), PETSCFE_CLASSID, 1); 29720cf1dd8SToby Isaac 2989371c9d4SSatish Balay if (--((PetscObject)(*fem))->refct > 0) { 2999371c9d4SSatish Balay *fem = NULL; 3009371c9d4SSatish Balay PetscFunctionReturn(0); 3019371c9d4SSatish Balay } 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 324dbbe0bcdSBarry Smith PetscTryTypeMethod((*fem), destroy); 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 @*/ 344*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreate(MPI_Comm comm, PetscFE *fem) 345*d71ae5a4SJacob Faibussowitsch { 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 @*/ 390*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetSpatialDimension(PetscFE fem, PetscInt *dim) 391*d71ae5a4SJacob Faibussowitsch { 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 @*/ 415*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetNumComponents(PetscFE fem, PetscInt comp) 416*d71ae5a4SJacob Faibussowitsch { 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 @*/ 438*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetNumComponents(PetscFE fem, PetscInt *comp) 439*d71ae5a4SJacob Faibussowitsch { 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 @*/ 463*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetTileSizes(PetscFE fem, PetscInt blockSize, PetscInt numBlocks, PetscInt batchSize, PetscInt numBatches) 464*d71ae5a4SJacob Faibussowitsch { 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 @*/ 492*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetTileSizes(PetscFE fem, PetscInt *blockSize, PetscInt *numBlocks, PetscInt *batchSize, PetscInt *numBatches) 493*d71ae5a4SJacob Faibussowitsch { 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 @*/ 522*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetBasisSpace(PetscFE fem, PetscSpace *sp) 523*d71ae5a4SJacob Faibussowitsch { 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 @*/ 544*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetBasisSpace(PetscFE fem, PetscSpace sp) 545*d71ae5a4SJacob Faibussowitsch { 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 @*/ 570*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetDualSpace(PetscFE fem, PetscDualSpace *sp) 571*d71ae5a4SJacob Faibussowitsch { 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 @*/ 592*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetDualSpace(PetscFE fem, PetscDualSpace sp) 593*d71ae5a4SJacob Faibussowitsch { 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 @*/ 618*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetQuadrature(PetscFE fem, PetscQuadrature *q) 619*d71ae5a4SJacob Faibussowitsch { 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 @*/ 640*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetQuadrature(PetscFE fem, PetscQuadrature q) 641*d71ae5a4SJacob Faibussowitsch { 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 @*/ 673*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetFaceQuadrature(PetscFE fem, PetscQuadrature *q) 674*d71ae5a4SJacob Faibussowitsch { 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 @*/ 695*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetFaceQuadrature(PetscFE fem, PetscQuadrature q) 696*d71ae5a4SJacob Faibussowitsch { 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 @*/ 724*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECopyQuadrature(PetscFE sfe, PetscFE tfe) 725*d71ae5a4SJacob Faibussowitsch { 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 @*/ 753*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetNumDof(PetscFE fem, const PetscInt **numDof) 754*d71ae5a4SJacob Faibussowitsch { 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 @*/ 783*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetCellTabulation(PetscFE fem, PetscInt k, PetscTabulation *T) 784*d71ae5a4SJacob Faibussowitsch { 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 @*/ 819*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetFaceTabulation(PetscFE fem, PetscInt k, PetscTabulation *Tf) 820*d71ae5a4SJacob Faibussowitsch { 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 @*/ 875*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetFaceCentroidTabulation(PetscFE fem, PetscTabulation *Tc) 876*d71ae5a4SJacob Faibussowitsch { 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 @*/ 925*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateTabulation(PetscFE fem, PetscInt nrepl, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation *T) 926*d71ae5a4SJacob Faibussowitsch { 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)); 95548a46eb9SPierre Jolivet for (k = 0; k <= (*T)->K; ++k) PetscCall(PetscMalloc1(nrepl * npoints * Nb * Nc * PetscPowInt(cdim, k), &(*T)->T[k])); 956dbbe0bcdSBarry Smith PetscUseTypeMethod(fem, createtabulation, nrepl * npoints, points, K, *T); 95720cf1dd8SToby Isaac PetscFunctionReturn(0); 95820cf1dd8SToby Isaac } 95920cf1dd8SToby Isaac 9602b99622eSMatthew G. Knepley /*@C 961ef0bb6c7SMatthew G. Knepley PetscFEComputeTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided. 9622b99622eSMatthew G. Knepley 9632b99622eSMatthew G. Knepley Not collective 9642b99622eSMatthew G. Knepley 9652b99622eSMatthew G. Knepley Input Parameters: 9662b99622eSMatthew G. Knepley + fem - The PetscFE object 9672b99622eSMatthew G. Knepley . npoints - The number of tabulation points 9682b99622eSMatthew G. Knepley . points - The tabulation point coordinates 969ef0bb6c7SMatthew G. Knepley . K - The number of derivatives calculated 970ef0bb6c7SMatthew G. Knepley - T - An existing tabulation object with enough allocated space 971ef0bb6c7SMatthew G. Knepley 972ef0bb6c7SMatthew G. Knepley Output Parameter: 973ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at tabulation points 9742b99622eSMatthew G. Knepley 9752b99622eSMatthew G. Knepley Note: 976ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 977ef0bb6c7SMatthew 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 978ef0bb6c7SMatthew 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 9792b99622eSMatthew G. Knepley 9802b99622eSMatthew G. Knepley Level: intermediate 9812b99622eSMatthew G. Knepley 982db781477SPatrick Sanan .seealso: `PetscFEGetCellTabulation()`, `PetscTabulationDestroy()` 9832b99622eSMatthew G. Knepley @*/ 984*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEComputeTabulation(PetscFE fem, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation T) 985*d71ae5a4SJacob Faibussowitsch { 986ef0bb6c7SMatthew G. Knepley PetscFunctionBeginHot; 987ef0bb6c7SMatthew G. Knepley if (!npoints || !fem->dualSpace || K < 0) PetscFunctionReturn(0); 988ef0bb6c7SMatthew G. Knepley PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 989dadcf809SJacob Faibussowitsch PetscValidRealPointer(points, 3); 990ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 5); 99176bd3646SJed Brown if (PetscDefined(USE_DEBUG)) { 99220cf1dd8SToby Isaac DM dm; 993ef0bb6c7SMatthew G. Knepley PetscDualSpace Q; 994ef0bb6c7SMatthew G. Knepley PetscInt Nb; /* Dimension of FE space P */ 995ef0bb6c7SMatthew G. Knepley PetscInt Nc; /* Field components */ 996ef0bb6c7SMatthew G. Knepley PetscInt cdim; /* Reference coordinate dimension */ 997ef0bb6c7SMatthew G. Knepley 9989566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &Q)); 9999566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &dm)); 10009566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &cdim)); 10019566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &Nb)); 10029566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 100363a3b9bcSJacob 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); 100463a3b9bcSJacob 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); 100563a3b9bcSJacob 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); 100663a3b9bcSJacob 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); 1007ef0bb6c7SMatthew G. Knepley } 1008ef0bb6c7SMatthew G. Knepley T->Nr = 1; 1009ef0bb6c7SMatthew G. Knepley T->Np = npoints; 1010dbbe0bcdSBarry Smith PetscUseTypeMethod(fem, createtabulation, npoints, points, K, T); 1011ef0bb6c7SMatthew G. Knepley PetscFunctionReturn(0); 1012ef0bb6c7SMatthew G. Knepley } 1013ef0bb6c7SMatthew G. Knepley 1014ef0bb6c7SMatthew G. Knepley /*@C 1015ef0bb6c7SMatthew G. Knepley PetscTabulationDestroy - Frees memory from the associated tabulation. 1016ef0bb6c7SMatthew G. Knepley 1017ef0bb6c7SMatthew G. Knepley Not collective 1018ef0bb6c7SMatthew G. Knepley 1019ef0bb6c7SMatthew G. Knepley Input Parameter: 1020ef0bb6c7SMatthew G. Knepley . T - The tabulation 1021ef0bb6c7SMatthew G. Knepley 1022ef0bb6c7SMatthew G. Knepley Level: intermediate 1023ef0bb6c7SMatthew G. Knepley 1024db781477SPatrick Sanan .seealso: `PetscFECreateTabulation()`, `PetscFEGetCellTabulation()` 1025ef0bb6c7SMatthew G. Knepley @*/ 1026*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscTabulationDestroy(PetscTabulation *T) 1027*d71ae5a4SJacob Faibussowitsch { 1028ef0bb6c7SMatthew G. Knepley PetscInt k; 102920cf1dd8SToby Isaac 103020cf1dd8SToby Isaac PetscFunctionBegin; 1031ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 1); 1032ef0bb6c7SMatthew G. Knepley if (!T || !(*T)) PetscFunctionReturn(0); 10339566063dSJacob Faibussowitsch for (k = 0; k <= (*T)->K; ++k) PetscCall(PetscFree((*T)->T[k])); 10349566063dSJacob Faibussowitsch PetscCall(PetscFree((*T)->T)); 10359566063dSJacob Faibussowitsch PetscCall(PetscFree(*T)); 1036ef0bb6c7SMatthew G. Knepley *T = NULL; 103720cf1dd8SToby Isaac PetscFunctionReturn(0); 103820cf1dd8SToby Isaac } 103920cf1dd8SToby Isaac 1040*d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFECreatePointTrace(PetscFE fe, PetscInt refPoint, PetscFE *trFE) 1041*d71ae5a4SJacob Faibussowitsch { 104220cf1dd8SToby Isaac PetscSpace bsp, bsubsp; 104320cf1dd8SToby Isaac PetscDualSpace dsp, dsubsp; 104420cf1dd8SToby Isaac PetscInt dim, depth, numComp, i, j, coneSize, order; 104520cf1dd8SToby Isaac PetscFEType type; 104620cf1dd8SToby Isaac DM dm; 104720cf1dd8SToby Isaac DMLabel label; 104820cf1dd8SToby Isaac PetscReal *xi, *v, *J, detJ; 1049db11e2ebSMatthew G. Knepley const char *name; 105020cf1dd8SToby Isaac PetscQuadrature origin, fullQuad, subQuad; 105120cf1dd8SToby Isaac 105220cf1dd8SToby Isaac PetscFunctionBegin; 105320cf1dd8SToby Isaac PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1); 105420cf1dd8SToby Isaac PetscValidPointer(trFE, 3); 10559566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &bsp)); 10569566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &dsp)); 10579566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp, &dm)); 10589566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 10599566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthLabel(dm, &label)); 10609566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(label, refPoint, &depth)); 10619566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(depth, &xi)); 10629566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dim, &v)); 10639566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dim * dim, &J)); 106420cf1dd8SToby Isaac for (i = 0; i < depth; i++) xi[i] = 0.; 10659566063dSJacob Faibussowitsch PetscCall(PetscQuadratureCreate(PETSC_COMM_SELF, &origin)); 10669566063dSJacob Faibussowitsch PetscCall(PetscQuadratureSetData(origin, depth, 0, 1, xi, NULL)); 10679566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm, refPoint, origin, v, J, NULL, &detJ)); 106820cf1dd8SToby Isaac /* CellGeometryFEM computes the expanded Jacobian, we want the true jacobian */ 106920cf1dd8SToby Isaac for (i = 1; i < dim; i++) { 1070ad540459SPierre Jolivet for (j = 0; j < depth; j++) J[i * depth + j] = J[i * dim + j]; 107120cf1dd8SToby Isaac } 10729566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&origin)); 10739566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetPointSubspace(dsp, refPoint, &dsubsp)); 10749566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreateSubspace(bsp, dsubsp, v, J, NULL, NULL, PETSC_OWN_POINTER, &bsubsp)); 10759566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetUp(bsubsp)); 10769566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject)fe), trFE)); 10779566063dSJacob Faibussowitsch PetscCall(PetscFEGetType(fe, &type)); 10789566063dSJacob Faibussowitsch PetscCall(PetscFESetType(*trFE, type)); 10799566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &numComp)); 10809566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(*trFE, numComp)); 10819566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(*trFE, bsubsp)); 10829566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(*trFE, dsubsp)); 10839566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject)fe, &name)); 10849566063dSJacob Faibussowitsch if (name) PetscCall(PetscFESetName(*trFE, name)); 10859566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &fullQuad)); 10869566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetOrder(fullQuad, &order)); 10879566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, refPoint, &coneSize)); 10881baa6e33SBarry Smith if (coneSize == 2 * depth) PetscCall(PetscDTGaussTensorQuadrature(depth, 1, (order + 1) / 2, -1., 1., &subQuad)); 10891baa6e33SBarry Smith else PetscCall(PetscDTStroudConicalQuadrature(depth, 1, (order + 1) / 2, -1., 1., &subQuad)); 10909566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(*trFE, subQuad)); 10919566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(*trFE)); 10929566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&subQuad)); 10939566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&bsubsp)); 109420cf1dd8SToby Isaac PetscFunctionReturn(0); 109520cf1dd8SToby Isaac } 109620cf1dd8SToby Isaac 1097*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateHeightTrace(PetscFE fe, PetscInt height, PetscFE *trFE) 1098*d71ae5a4SJacob Faibussowitsch { 109920cf1dd8SToby Isaac PetscInt hStart, hEnd; 110020cf1dd8SToby Isaac PetscDualSpace dsp; 110120cf1dd8SToby Isaac DM dm; 110220cf1dd8SToby Isaac 110320cf1dd8SToby Isaac PetscFunctionBegin; 110420cf1dd8SToby Isaac PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1); 110520cf1dd8SToby Isaac PetscValidPointer(trFE, 3); 110620cf1dd8SToby Isaac *trFE = NULL; 11079566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &dsp)); 11089566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp, &dm)); 11099566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(dm, height, &hStart, &hEnd)); 111020cf1dd8SToby Isaac if (hEnd <= hStart) PetscFunctionReturn(0); 11119566063dSJacob Faibussowitsch PetscCall(PetscFECreatePointTrace(fe, hStart, trFE)); 111220cf1dd8SToby Isaac PetscFunctionReturn(0); 111320cf1dd8SToby Isaac } 111420cf1dd8SToby Isaac 111520cf1dd8SToby Isaac /*@ 111620cf1dd8SToby Isaac PetscFEGetDimension - Get the dimension of the finite element space on a cell 111720cf1dd8SToby Isaac 111820cf1dd8SToby Isaac Not collective 111920cf1dd8SToby Isaac 112020cf1dd8SToby Isaac Input Parameter: 112120cf1dd8SToby Isaac . fe - The PetscFE 112220cf1dd8SToby Isaac 112320cf1dd8SToby Isaac Output Parameter: 112420cf1dd8SToby Isaac . dim - The dimension 112520cf1dd8SToby Isaac 112620cf1dd8SToby Isaac Level: intermediate 112720cf1dd8SToby Isaac 1128db781477SPatrick Sanan .seealso: `PetscFECreate()`, `PetscSpaceGetDimension()`, `PetscDualSpaceGetDimension()` 112920cf1dd8SToby Isaac @*/ 1130*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetDimension(PetscFE fem, PetscInt *dim) 1131*d71ae5a4SJacob Faibussowitsch { 113220cf1dd8SToby Isaac PetscFunctionBegin; 113320cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 1134dadcf809SJacob Faibussowitsch PetscValidIntPointer(dim, 2); 1135dbbe0bcdSBarry Smith PetscTryTypeMethod(fem, getdimension, dim); 113620cf1dd8SToby Isaac PetscFunctionReturn(0); 113720cf1dd8SToby Isaac } 113820cf1dd8SToby Isaac 11394bee2e38SMatthew G. Knepley /*@C 11404bee2e38SMatthew G. Knepley PetscFEPushforward - Map the reference element function to real space 11414bee2e38SMatthew G. Knepley 11424bee2e38SMatthew G. Knepley Input Parameters: 11434bee2e38SMatthew G. Knepley + fe - The PetscFE 11444bee2e38SMatthew G. Knepley . fegeom - The cell geometry 11454bee2e38SMatthew G. Knepley . Nv - The number of function values 11464bee2e38SMatthew G. Knepley - vals - The function values 11474bee2e38SMatthew G. Knepley 11484bee2e38SMatthew G. Knepley Output Parameter: 11494bee2e38SMatthew G. Knepley . vals - The transformed function values 11504bee2e38SMatthew G. Knepley 11514bee2e38SMatthew G. Knepley Level: advanced 11524bee2e38SMatthew G. Knepley 11534bee2e38SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforward(). 11544bee2e38SMatthew G. Knepley 1155f9244615SMatthew G. Knepley Note: This only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 11562edcad52SToby Isaac 1157db781477SPatrick Sanan .seealso: `PetscDualSpacePushforward()` 11584bee2e38SMatthew G. Knepley @*/ 1159*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEPushforward(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 1160*d71ae5a4SJacob Faibussowitsch { 11612ae266adSMatthew G. Knepley PetscFunctionBeginHot; 11629566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforward(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 11634bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 11644bee2e38SMatthew G. Knepley } 11654bee2e38SMatthew G. Knepley 11664bee2e38SMatthew G. Knepley /*@C 11674bee2e38SMatthew G. Knepley PetscFEPushforwardGradient - Map the reference element function gradient to real space 11684bee2e38SMatthew G. Knepley 11694bee2e38SMatthew G. Knepley Input Parameters: 11704bee2e38SMatthew G. Knepley + fe - The PetscFE 11714bee2e38SMatthew G. Knepley . fegeom - The cell geometry 11724bee2e38SMatthew G. Knepley . Nv - The number of function gradient values 11734bee2e38SMatthew G. Knepley - vals - The function gradient values 11744bee2e38SMatthew G. Knepley 11754bee2e38SMatthew G. Knepley Output Parameter: 11764bee2e38SMatthew G. Knepley . vals - The transformed function gradient values 11774bee2e38SMatthew G. Knepley 11784bee2e38SMatthew G. Knepley Level: advanced 11794bee2e38SMatthew G. Knepley 11804bee2e38SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforwardGradient(). 11814bee2e38SMatthew G. Knepley 1182f9244615SMatthew G. Knepley Note: This only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 11832edcad52SToby Isaac 1184db781477SPatrick Sanan .seealso: `PetscFEPushforward()`, `PetscDualSpacePushforwardGradient()`, `PetscDualSpacePushforward()` 11854bee2e38SMatthew G. Knepley @*/ 1186*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEPushforwardGradient(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 1187*d71ae5a4SJacob Faibussowitsch { 11882ae266adSMatthew G. Knepley PetscFunctionBeginHot; 11899566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforwardGradient(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 11904bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 11914bee2e38SMatthew G. Knepley } 11924bee2e38SMatthew G. Knepley 1193f9244615SMatthew G. Knepley /*@C 1194f9244615SMatthew G. Knepley PetscFEPushforwardHessian - Map the reference element function Hessian to real space 1195f9244615SMatthew G. Knepley 1196f9244615SMatthew G. Knepley Input Parameters: 1197f9244615SMatthew G. Knepley + fe - The PetscFE 1198f9244615SMatthew G. Knepley . fegeom - The cell geometry 1199f9244615SMatthew G. Knepley . Nv - The number of function Hessian values 1200f9244615SMatthew G. Knepley - vals - The function Hessian values 1201f9244615SMatthew G. Knepley 1202f9244615SMatthew G. Knepley Output Parameter: 1203f9244615SMatthew G. Knepley . vals - The transformed function Hessian values 1204f9244615SMatthew G. Knepley 1205f9244615SMatthew G. Knepley Level: advanced 1206f9244615SMatthew G. Knepley 1207f9244615SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforwardHessian(). 1208f9244615SMatthew G. Knepley 1209f9244615SMatthew G. Knepley Note: This only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 1210f9244615SMatthew G. Knepley 1211db781477SPatrick Sanan .seealso: `PetscFEPushforward()`, `PetscDualSpacePushforwardHessian()`, `PetscDualSpacePushforward()` 1212f9244615SMatthew G. Knepley @*/ 1213*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEPushforwardHessian(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 1214*d71ae5a4SJacob Faibussowitsch { 1215f9244615SMatthew G. Knepley PetscFunctionBeginHot; 12169566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforwardHessian(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 1217f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1218f9244615SMatthew G. Knepley } 1219f9244615SMatthew G. Knepley 122020cf1dd8SToby Isaac /* 122120cf1dd8SToby Isaac Purpose: Compute element vector for chunk of elements 122220cf1dd8SToby Isaac 122320cf1dd8SToby Isaac Input: 122420cf1dd8SToby Isaac Sizes: 122520cf1dd8SToby Isaac Ne: number of elements 122620cf1dd8SToby Isaac Nf: number of fields 122720cf1dd8SToby Isaac PetscFE 122820cf1dd8SToby Isaac dim: spatial dimension 122920cf1dd8SToby Isaac Nb: number of basis functions 123020cf1dd8SToby Isaac Nc: number of field components 123120cf1dd8SToby Isaac PetscQuadrature 123220cf1dd8SToby Isaac Nq: number of quadrature points 123320cf1dd8SToby Isaac 123420cf1dd8SToby Isaac Geometry: 123520cf1dd8SToby Isaac PetscFEGeom[Ne] possibly *Nq 123620cf1dd8SToby Isaac PetscReal v0s[dim] 123720cf1dd8SToby Isaac PetscReal n[dim] 123820cf1dd8SToby Isaac PetscReal jacobians[dim*dim] 123920cf1dd8SToby Isaac PetscReal jacobianInverses[dim*dim] 124020cf1dd8SToby Isaac PetscReal jacobianDeterminants 124120cf1dd8SToby Isaac FEM: 124220cf1dd8SToby Isaac PetscFE 124320cf1dd8SToby Isaac PetscQuadrature 124420cf1dd8SToby Isaac PetscReal quadPoints[Nq*dim] 124520cf1dd8SToby Isaac PetscReal quadWeights[Nq] 124620cf1dd8SToby Isaac PetscReal basis[Nq*Nb*Nc] 124720cf1dd8SToby Isaac PetscReal basisDer[Nq*Nb*Nc*dim] 124820cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 124920cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 125020cf1dd8SToby Isaac 125120cf1dd8SToby Isaac Problem: 125220cf1dd8SToby Isaac PetscInt f: the active field 125320cf1dd8SToby Isaac f0, f1 125420cf1dd8SToby Isaac 125520cf1dd8SToby Isaac Work Space: 125620cf1dd8SToby Isaac PetscFE 125720cf1dd8SToby Isaac PetscScalar f0[Nq*dim]; 125820cf1dd8SToby Isaac PetscScalar f1[Nq*dim*dim]; 125920cf1dd8SToby Isaac PetscScalar u[Nc]; 126020cf1dd8SToby Isaac PetscScalar gradU[Nc*dim]; 126120cf1dd8SToby Isaac PetscReal x[dim]; 126220cf1dd8SToby Isaac PetscScalar realSpaceDer[dim]; 126320cf1dd8SToby Isaac 126420cf1dd8SToby Isaac Purpose: Compute element vector for N_cb batches of elements 126520cf1dd8SToby Isaac 126620cf1dd8SToby Isaac Input: 126720cf1dd8SToby Isaac Sizes: 126820cf1dd8SToby Isaac N_cb: Number of serial cell batches 126920cf1dd8SToby Isaac 127020cf1dd8SToby Isaac Geometry: 127120cf1dd8SToby Isaac PetscReal v0s[Ne*dim] 127220cf1dd8SToby Isaac PetscReal jacobians[Ne*dim*dim] possibly *Nq 127320cf1dd8SToby Isaac PetscReal jacobianInverses[Ne*dim*dim] possibly *Nq 127420cf1dd8SToby Isaac PetscReal jacobianDeterminants[Ne] possibly *Nq 127520cf1dd8SToby Isaac FEM: 127620cf1dd8SToby Isaac static PetscReal quadPoints[Nq*dim] 127720cf1dd8SToby Isaac static PetscReal quadWeights[Nq] 127820cf1dd8SToby Isaac static PetscReal basis[Nq*Nb*Nc] 127920cf1dd8SToby Isaac static PetscReal basisDer[Nq*Nb*Nc*dim] 128020cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 128120cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 128220cf1dd8SToby Isaac 128320cf1dd8SToby Isaac ex62.c: 128420cf1dd8SToby Isaac PetscErrorCode PetscFEIntegrateResidualBatch(PetscInt Ne, PetscInt numFields, PetscInt field, PetscQuadrature quad[], const PetscScalar coefficients[], 128520cf1dd8SToby Isaac const PetscReal v0s[], const PetscReal jacobians[], const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], 128620cf1dd8SToby Isaac void (*f0_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f0[]), 128720cf1dd8SToby Isaac void (*f1_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f1[]), PetscScalar elemVec[]) 128820cf1dd8SToby Isaac 128920cf1dd8SToby Isaac ex52.c: 129020cf1dd8SToby 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) 129120cf1dd8SToby 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) 129220cf1dd8SToby Isaac 129320cf1dd8SToby Isaac ex52_integrateElement.cu 129420cf1dd8SToby Isaac __global__ void integrateElementQuadrature(int N_cb, realType *coefficients, realType *jacobianInverses, realType *jacobianDeterminants, realType *elemVec) 129520cf1dd8SToby Isaac 129620cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt Nbl, const PetscScalar coefficients[], 129720cf1dd8SToby Isaac const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[], 129820cf1dd8SToby Isaac PetscLogEvent event, PetscInt debug, PetscInt pde_op) 129920cf1dd8SToby Isaac 130020cf1dd8SToby Isaac ex52_integrateElementOpenCL.c: 130120cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt N_bl, const PetscScalar coefficients[], 130220cf1dd8SToby Isaac const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[], 130320cf1dd8SToby Isaac PetscLogEvent event, PetscInt debug, PetscInt pde_op) 130420cf1dd8SToby Isaac 130520cf1dd8SToby Isaac __kernel void integrateElementQuadrature(int N_cb, __global float *coefficients, __global float *jacobianInverses, __global float *jacobianDeterminants, __global float *elemVec) 130620cf1dd8SToby Isaac */ 130720cf1dd8SToby Isaac 130820cf1dd8SToby Isaac /*@C 130920cf1dd8SToby Isaac PetscFEIntegrate - Produce the integral for the given field for a chunk of elements by quadrature integration 131020cf1dd8SToby Isaac 131120cf1dd8SToby Isaac Not collective 131220cf1dd8SToby Isaac 131320cf1dd8SToby Isaac Input Parameters: 1314360cf244SMatthew G. Knepley + prob - The PetscDS specifying the discretizations and continuum functions 131520cf1dd8SToby Isaac . field - The field being integrated 131620cf1dd8SToby Isaac . Ne - The number of elements in the chunk 131720cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 131820cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 131920cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 132020cf1dd8SToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 132120cf1dd8SToby Isaac 13227a7aea1fSJed Brown Output Parameter: 132320cf1dd8SToby Isaac . integral - the integral for this field 132420cf1dd8SToby Isaac 13252b99622eSMatthew G. Knepley Level: intermediate 132620cf1dd8SToby Isaac 1327db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 132820cf1dd8SToby Isaac @*/ 1329*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEIntegrate(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom, const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 1330*d71ae5a4SJacob Faibussowitsch { 13314bee2e38SMatthew G. Knepley PetscFE fe; 133220cf1dd8SToby Isaac 133320cf1dd8SToby Isaac PetscFunctionBegin; 13344bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13359566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *)&fe)); 13369566063dSJacob Faibussowitsch if (fe->ops->integrate) PetscCall((*fe->ops->integrate)(prob, field, Ne, cgeom, coefficients, probAux, coefficientsAux, integral)); 133720cf1dd8SToby Isaac PetscFunctionReturn(0); 133820cf1dd8SToby Isaac } 133920cf1dd8SToby Isaac 134020cf1dd8SToby Isaac /*@C 1341afe6d6adSToby Isaac PetscFEIntegrateBd - Produce the integral for the given field for a chunk of elements by quadrature integration 1342afe6d6adSToby Isaac 1343afe6d6adSToby Isaac Not collective 1344afe6d6adSToby Isaac 1345afe6d6adSToby Isaac Input Parameters: 1346360cf244SMatthew G. Knepley + prob - The PetscDS specifying the discretizations and continuum functions 1347afe6d6adSToby Isaac . field - The field being integrated 1348afe6d6adSToby Isaac . obj_func - The function to be integrated 1349afe6d6adSToby Isaac . Ne - The number of elements in the chunk 1350afe6d6adSToby Isaac . fgeom - The face geometry for each face in the chunk 1351afe6d6adSToby Isaac . coefficients - The array of FEM basis coefficients for the elements 1352afe6d6adSToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 1353afe6d6adSToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 1354afe6d6adSToby Isaac 13557a7aea1fSJed Brown Output Parameter: 1356afe6d6adSToby Isaac . integral - the integral for this field 1357afe6d6adSToby Isaac 13582b99622eSMatthew G. Knepley Level: intermediate 1359afe6d6adSToby Isaac 1360db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 1361afe6d6adSToby Isaac @*/ 1362*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEIntegrateBd(PetscDS prob, PetscInt field, void (*obj_func)(PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]), PetscInt Ne, PetscFEGeom *geom, const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 1363*d71ae5a4SJacob Faibussowitsch { 13644bee2e38SMatthew G. Knepley PetscFE fe; 1365afe6d6adSToby Isaac 1366afe6d6adSToby Isaac PetscFunctionBegin; 13674bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13689566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *)&fe)); 13699566063dSJacob Faibussowitsch if (fe->ops->integratebd) PetscCall((*fe->ops->integratebd)(prob, field, obj_func, Ne, geom, coefficients, probAux, coefficientsAux, integral)); 1370afe6d6adSToby Isaac PetscFunctionReturn(0); 1371afe6d6adSToby Isaac } 1372afe6d6adSToby Isaac 1373afe6d6adSToby Isaac /*@C 137420cf1dd8SToby Isaac PetscFEIntegrateResidual - Produce the element residual vector for a chunk of elements by quadrature integration 137520cf1dd8SToby Isaac 137620cf1dd8SToby Isaac Not collective 137720cf1dd8SToby Isaac 137820cf1dd8SToby Isaac Input Parameters: 13796528b96dSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 13806528b96dSMatthew G. Knepley . key - The (label+value, field) being integrated 138120cf1dd8SToby Isaac . Ne - The number of elements in the chunk 138220cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 138320cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 138420cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 138520cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 138620cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 138720cf1dd8SToby Isaac - t - The time 138820cf1dd8SToby Isaac 13897a7aea1fSJed Brown Output Parameter: 139020cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 139120cf1dd8SToby Isaac 139220cf1dd8SToby Isaac Note: 139320cf1dd8SToby Isaac $ Loop over batch of elements (e): 139420cf1dd8SToby Isaac $ Loop over quadrature points (q): 139520cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) and x_q 139620cf1dd8SToby Isaac $ Call f_0 and f_1 139720cf1dd8SToby Isaac $ Loop over element vector entries (f,fc --> i): 139820cf1dd8SToby Isaac $ elemVec[i] += \psi^{fc}_f(q) f0_{fc}(u, \nabla u) + \nabla\psi^{fc}_f(q) \cdot f1_{fc,df}(u, \nabla u) 139920cf1dd8SToby Isaac 14002b99622eSMatthew G. Knepley Level: intermediate 140120cf1dd8SToby Isaac 1402db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 140320cf1dd8SToby Isaac @*/ 1404*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEIntegrateResidual(PetscDS ds, PetscFormKey key, PetscInt Ne, PetscFEGeom *cgeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 1405*d71ae5a4SJacob Faibussowitsch { 14064bee2e38SMatthew G. Knepley PetscFE fe; 140720cf1dd8SToby Isaac 14086528b96dSMatthew G. Knepley PetscFunctionBeginHot; 14096528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14109566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field, (PetscObject *)&fe)); 14119566063dSJacob Faibussowitsch if (fe->ops->integrateresidual) PetscCall((*fe->ops->integrateresidual)(ds, key, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 141220cf1dd8SToby Isaac PetscFunctionReturn(0); 141320cf1dd8SToby Isaac } 141420cf1dd8SToby Isaac 141520cf1dd8SToby Isaac /*@C 141620cf1dd8SToby Isaac PetscFEIntegrateBdResidual - Produce the element residual vector for a chunk of elements by quadrature integration over a boundary 141720cf1dd8SToby Isaac 141820cf1dd8SToby Isaac Not collective 141920cf1dd8SToby Isaac 142020cf1dd8SToby Isaac Input Parameters: 142106d8a0d3SMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 142245480ffeSMatthew G. Knepley . wf - The PetscWeakForm object holding the pointwise functions 142306d8a0d3SMatthew G. Knepley . key - The (label+value, field) being integrated 142420cf1dd8SToby Isaac . Ne - The number of elements in the chunk 142520cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 142620cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 142720cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 142820cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 142920cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 143020cf1dd8SToby Isaac - t - The time 143120cf1dd8SToby Isaac 14327a7aea1fSJed Brown Output Parameter: 143320cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 143420cf1dd8SToby Isaac 14352b99622eSMatthew G. Knepley Level: intermediate 143620cf1dd8SToby Isaac 1437db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 143820cf1dd8SToby Isaac @*/ 1439*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEIntegrateBdResidual(PetscDS ds, PetscWeakForm wf, PetscFormKey key, PetscInt Ne, PetscFEGeom *fgeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 1440*d71ae5a4SJacob Faibussowitsch { 14414bee2e38SMatthew G. Knepley PetscFE fe; 144220cf1dd8SToby Isaac 144320cf1dd8SToby Isaac PetscFunctionBegin; 144406d8a0d3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14459566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field, (PetscObject *)&fe)); 14469566063dSJacob Faibussowitsch if (fe->ops->integratebdresidual) PetscCall((*fe->ops->integratebdresidual)(ds, wf, key, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 144720cf1dd8SToby Isaac PetscFunctionReturn(0); 144820cf1dd8SToby Isaac } 144920cf1dd8SToby Isaac 145020cf1dd8SToby Isaac /*@C 145127f02ce8SMatthew G. Knepley PetscFEIntegrateHybridResidual - Produce the element residual vector for a chunk of hybrid element faces by quadrature integration 145227f02ce8SMatthew G. Knepley 145327f02ce8SMatthew G. Knepley Not collective 145427f02ce8SMatthew G. Knepley 145527f02ce8SMatthew G. Knepley Input Parameters: 145627f02ce8SMatthew G. Knepley + prob - The PetscDS specifying the discretizations and continuum functions 14576528b96dSMatthew G. Knepley . key - The (label+value, field) being integrated 1458c2b7495fSMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 145927f02ce8SMatthew G. Knepley . Ne - The number of elements in the chunk 146027f02ce8SMatthew G. Knepley . fgeom - The face geometry for each cell in the chunk 146127f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements 146227f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements 146327f02ce8SMatthew G. Knepley . probAux - The PetscDS specifying the auxiliary discretizations 146427f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 146527f02ce8SMatthew G. Knepley - t - The time 146627f02ce8SMatthew G. Knepley 146727f02ce8SMatthew G. Knepley Output Parameter 146827f02ce8SMatthew G. Knepley . elemVec - the element residual vectors from each element 146927f02ce8SMatthew G. Knepley 147027f02ce8SMatthew G. Knepley Level: developer 147127f02ce8SMatthew G. Knepley 1472db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 147327f02ce8SMatthew G. Knepley @*/ 1474*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEIntegrateHybridResidual(PetscDS prob, PetscFormKey key, PetscInt s, PetscInt Ne, PetscFEGeom *fgeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 1475*d71ae5a4SJacob Faibussowitsch { 147627f02ce8SMatthew G. Knepley PetscFE fe; 147727f02ce8SMatthew G. Knepley 147827f02ce8SMatthew G. Knepley PetscFunctionBegin; 147927f02ce8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 14809566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, key.field, (PetscObject *)&fe)); 14819566063dSJacob Faibussowitsch if (fe->ops->integratehybridresidual) PetscCall((*fe->ops->integratehybridresidual)(prob, key, s, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 148227f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 148327f02ce8SMatthew G. Knepley } 148427f02ce8SMatthew G. Knepley 148527f02ce8SMatthew G. Knepley /*@C 148620cf1dd8SToby Isaac PetscFEIntegrateJacobian - Produce the element Jacobian for a chunk of elements by quadrature integration 148720cf1dd8SToby Isaac 148820cf1dd8SToby Isaac Not collective 148920cf1dd8SToby Isaac 149020cf1dd8SToby Isaac Input Parameters: 14916528b96dSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 149220cf1dd8SToby Isaac . jtype - The type of matrix pointwise functions that should be used 14936528b96dSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 14945fedec97SMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 149520cf1dd8SToby Isaac . Ne - The number of elements in the chunk 149620cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 149720cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 149820cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 149920cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 150020cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 150120cf1dd8SToby Isaac . t - The time 150220cf1dd8SToby Isaac - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 150320cf1dd8SToby Isaac 15047a7aea1fSJed Brown Output Parameter: 150520cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 150620cf1dd8SToby Isaac 150720cf1dd8SToby Isaac Note: 150820cf1dd8SToby Isaac $ Loop over batch of elements (e): 150920cf1dd8SToby Isaac $ Loop over element matrix entries (f,fc,g,gc --> i,j): 151020cf1dd8SToby Isaac $ Loop over quadrature points (q): 151120cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 151220cf1dd8SToby Isaac $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 151320cf1dd8SToby Isaac $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 151420cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 151520cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 15162b99622eSMatthew G. Knepley Level: intermediate 151720cf1dd8SToby Isaac 1518db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 151920cf1dd8SToby Isaac @*/ 1520*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEIntegrateJacobian(PetscDS ds, PetscFEJacobianType jtype, PetscFormKey key, PetscInt Ne, PetscFEGeom *cgeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 1521*d71ae5a4SJacob Faibussowitsch { 15224bee2e38SMatthew G. Knepley PetscFE fe; 15236528b96dSMatthew G. Knepley PetscInt Nf; 152420cf1dd8SToby Isaac 152520cf1dd8SToby Isaac PetscFunctionBegin; 15266528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 15279566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 15289566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *)&fe)); 15299566063dSJacob Faibussowitsch if (fe->ops->integratejacobian) PetscCall((*fe->ops->integratejacobian)(ds, jtype, key, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 153020cf1dd8SToby Isaac PetscFunctionReturn(0); 153120cf1dd8SToby Isaac } 153220cf1dd8SToby Isaac 153320cf1dd8SToby Isaac /*@C 153420cf1dd8SToby Isaac PetscFEIntegrateBdJacobian - Produce the boundary element Jacobian for a chunk of elements by quadrature integration 153520cf1dd8SToby Isaac 153620cf1dd8SToby Isaac Not collective 153720cf1dd8SToby Isaac 153820cf1dd8SToby Isaac Input Parameters: 153945480ffeSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 154045480ffeSMatthew G. Knepley . wf - The PetscWeakForm holding the pointwise functions 154145480ffeSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 154220cf1dd8SToby Isaac . Ne - The number of elements in the chunk 154320cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 154420cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 154520cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 154620cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 154720cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 154820cf1dd8SToby Isaac . t - The time 154920cf1dd8SToby Isaac - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 155020cf1dd8SToby Isaac 15517a7aea1fSJed Brown Output Parameter: 155220cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 155320cf1dd8SToby Isaac 155420cf1dd8SToby Isaac Note: 155520cf1dd8SToby Isaac $ Loop over batch of elements (e): 155620cf1dd8SToby Isaac $ Loop over element matrix entries (f,fc,g,gc --> i,j): 155720cf1dd8SToby Isaac $ Loop over quadrature points (q): 155820cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 155920cf1dd8SToby Isaac $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 156020cf1dd8SToby Isaac $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 156120cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 156220cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 15632b99622eSMatthew G. Knepley Level: intermediate 156420cf1dd8SToby Isaac 1565db781477SPatrick Sanan .seealso: `PetscFEIntegrateJacobian()`, `PetscFEIntegrateResidual()` 156620cf1dd8SToby Isaac @*/ 1567*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEIntegrateBdJacobian(PetscDS ds, PetscWeakForm wf, PetscFormKey key, PetscInt Ne, PetscFEGeom *fgeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 1568*d71ae5a4SJacob Faibussowitsch { 15694bee2e38SMatthew G. Knepley PetscFE fe; 157045480ffeSMatthew G. Knepley PetscInt Nf; 157120cf1dd8SToby Isaac 157220cf1dd8SToby Isaac PetscFunctionBegin; 157345480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 15749566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 15759566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *)&fe)); 15769566063dSJacob Faibussowitsch if (fe->ops->integratebdjacobian) PetscCall((*fe->ops->integratebdjacobian)(ds, wf, key, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 157720cf1dd8SToby Isaac PetscFunctionReturn(0); 157820cf1dd8SToby Isaac } 157920cf1dd8SToby Isaac 158027f02ce8SMatthew G. Knepley /*@C 158127f02ce8SMatthew G. Knepley PetscFEIntegrateHybridJacobian - Produce the boundary element Jacobian for a chunk of hybrid elements by quadrature integration 158227f02ce8SMatthew G. Knepley 158327f02ce8SMatthew G. Knepley Not collective 158427f02ce8SMatthew G. Knepley 158527f02ce8SMatthew G. Knepley Input Parameters: 158645480ffeSMatthew G. Knepley + ds - The PetscDS specifying the discretizations and continuum functions 158727f02ce8SMatthew G. Knepley . jtype - The type of matrix pointwise functions that should be used 158845480ffeSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 15895fedec97SMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 159027f02ce8SMatthew G. Knepley . Ne - The number of elements in the chunk 159127f02ce8SMatthew G. Knepley . fgeom - The face geometry for each cell in the chunk 159227f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 159327f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements 159427f02ce8SMatthew G. Knepley . probAux - The PetscDS specifying the auxiliary discretizations 159527f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 159627f02ce8SMatthew G. Knepley . t - The time 159727f02ce8SMatthew G. Knepley - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 159827f02ce8SMatthew G. Knepley 159927f02ce8SMatthew G. Knepley Output Parameter 160027f02ce8SMatthew G. Knepley . elemMat - the element matrices for the Jacobian from each element 160127f02ce8SMatthew G. Knepley 160227f02ce8SMatthew G. Knepley Note: 160327f02ce8SMatthew G. Knepley $ Loop over batch of elements (e): 160427f02ce8SMatthew G. Knepley $ Loop over element matrix entries (f,fc,g,gc --> i,j): 160527f02ce8SMatthew G. Knepley $ Loop over quadrature points (q): 160627f02ce8SMatthew G. Knepley $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 160727f02ce8SMatthew G. Knepley $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 160827f02ce8SMatthew G. Knepley $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 160927f02ce8SMatthew G. Knepley $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 161027f02ce8SMatthew G. Knepley $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 161127f02ce8SMatthew G. Knepley Level: developer 161227f02ce8SMatthew G. Knepley 1613db781477SPatrick Sanan .seealso: `PetscFEIntegrateJacobian()`, `PetscFEIntegrateResidual()` 161427f02ce8SMatthew G. Knepley @*/ 1615*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEIntegrateHybridJacobian(PetscDS ds, PetscFEJacobianType jtype, PetscFormKey key, PetscInt s, PetscInt Ne, PetscFEGeom *fgeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 1616*d71ae5a4SJacob Faibussowitsch { 161727f02ce8SMatthew G. Knepley PetscFE fe; 161845480ffeSMatthew G. Knepley PetscInt Nf; 161927f02ce8SMatthew G. Knepley 162027f02ce8SMatthew G. Knepley PetscFunctionBegin; 162145480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 16229566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 16239566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *)&fe)); 16249566063dSJacob Faibussowitsch if (fe->ops->integratehybridjacobian) PetscCall((*fe->ops->integratehybridjacobian)(ds, jtype, key, s, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 162527f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 162627f02ce8SMatthew G. Knepley } 162727f02ce8SMatthew G. Knepley 16282b99622eSMatthew G. Knepley /*@ 16292b99622eSMatthew G. Knepley PetscFEGetHeightSubspace - Get the subspace of this space for a mesh point of a given height 16302b99622eSMatthew G. Knepley 16312b99622eSMatthew G. Knepley Input Parameters: 16322b99622eSMatthew G. Knepley + fe - The finite element space 16332b99622eSMatthew G. Knepley - height - The height of the Plex point 16342b99622eSMatthew G. Knepley 16352b99622eSMatthew G. Knepley Output Parameter: 16362b99622eSMatthew G. Knepley . subfe - The subspace of this FE space 16372b99622eSMatthew G. Knepley 16382b99622eSMatthew G. Knepley Note: For example, if we want the subspace of this space for a face, we would choose height = 1. 16392b99622eSMatthew G. Knepley 16402b99622eSMatthew G. Knepley Level: advanced 16412b99622eSMatthew G. Knepley 1642db781477SPatrick Sanan .seealso: `PetscFECreateDefault()` 16432b99622eSMatthew G. Knepley @*/ 1644*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetHeightSubspace(PetscFE fe, PetscInt height, PetscFE *subfe) 1645*d71ae5a4SJacob Faibussowitsch { 164620cf1dd8SToby Isaac PetscSpace P, subP; 164720cf1dd8SToby Isaac PetscDualSpace Q, subQ; 164820cf1dd8SToby Isaac PetscQuadrature subq; 164920cf1dd8SToby Isaac PetscFEType fetype; 165020cf1dd8SToby Isaac PetscInt dim, Nc; 165120cf1dd8SToby Isaac 165220cf1dd8SToby Isaac PetscFunctionBegin; 165320cf1dd8SToby Isaac PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1); 165420cf1dd8SToby Isaac PetscValidPointer(subfe, 3); 165520cf1dd8SToby Isaac if (height == 0) { 165620cf1dd8SToby Isaac *subfe = fe; 165720cf1dd8SToby Isaac PetscFunctionReturn(0); 165820cf1dd8SToby Isaac } 16599566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 16609566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 16619566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &Nc)); 16629566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(fe, &subq)); 16639566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &dim)); 16641dca8a05SBarry 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); 16659566063dSJacob Faibussowitsch if (!fe->subspaces) PetscCall(PetscCalloc1(dim, &fe->subspaces)); 166620cf1dd8SToby Isaac if (height <= dim) { 166720cf1dd8SToby Isaac if (!fe->subspaces[height - 1]) { 1668665f567fSMatthew G. Knepley PetscFE sub = NULL; 16693f6b16c7SMatthew G. Knepley const char *name; 167020cf1dd8SToby Isaac 16719566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetHeightSubspace(P, height, &subP)); 16729566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetHeightSubspace(Q, height, &subQ)); 1673665f567fSMatthew G. Knepley if (subQ) { 16749566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject)fe), &sub)); 16759566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject)fe, &name)); 16769566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject)sub, name)); 16779566063dSJacob Faibussowitsch PetscCall(PetscFEGetType(fe, &fetype)); 16789566063dSJacob Faibussowitsch PetscCall(PetscFESetType(sub, fetype)); 16799566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(sub, subP)); 16809566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(sub, subQ)); 16819566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(sub, Nc)); 16829566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(sub)); 16839566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(sub, subq)); 1684665f567fSMatthew G. Knepley } 168520cf1dd8SToby Isaac fe->subspaces[height - 1] = sub; 168620cf1dd8SToby Isaac } 168720cf1dd8SToby Isaac *subfe = fe->subspaces[height - 1]; 168820cf1dd8SToby Isaac } else { 168920cf1dd8SToby Isaac *subfe = NULL; 169020cf1dd8SToby Isaac } 169120cf1dd8SToby Isaac PetscFunctionReturn(0); 169220cf1dd8SToby Isaac } 169320cf1dd8SToby Isaac 169420cf1dd8SToby Isaac /*@ 169520cf1dd8SToby Isaac PetscFERefine - Create a "refined" PetscFE object that refines the reference cell into smaller copies. This is typically used 169620cf1dd8SToby Isaac to precondition a higher order method with a lower order method on a refined mesh having the same number of dofs (but more 169720cf1dd8SToby Isaac sparsity). It is also used to create an interpolation between regularly refined meshes. 169820cf1dd8SToby Isaac 1699d083f849SBarry Smith Collective on fem 170020cf1dd8SToby Isaac 170120cf1dd8SToby Isaac Input Parameter: 170220cf1dd8SToby Isaac . fe - The initial PetscFE 170320cf1dd8SToby Isaac 170420cf1dd8SToby Isaac Output Parameter: 170520cf1dd8SToby Isaac . feRef - The refined PetscFE 170620cf1dd8SToby Isaac 17072b99622eSMatthew G. Knepley Level: advanced 170820cf1dd8SToby Isaac 1709db781477SPatrick Sanan .seealso: `PetscFEType`, `PetscFECreate()`, `PetscFESetType()` 171020cf1dd8SToby Isaac @*/ 1711*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFERefine(PetscFE fe, PetscFE *feRef) 1712*d71ae5a4SJacob Faibussowitsch { 171320cf1dd8SToby Isaac PetscSpace P, Pref; 171420cf1dd8SToby Isaac PetscDualSpace Q, Qref; 171520cf1dd8SToby Isaac DM K, Kref; 171620cf1dd8SToby Isaac PetscQuadrature q, qref; 171720cf1dd8SToby Isaac const PetscReal *v0, *jac; 171820cf1dd8SToby Isaac PetscInt numComp, numSubelements; 17191ac17e89SToby Isaac PetscInt cStart, cEnd, c; 17201ac17e89SToby Isaac PetscDualSpace *cellSpaces; 172120cf1dd8SToby Isaac 172220cf1dd8SToby Isaac PetscFunctionBegin; 17239566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 17249566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 17259566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &q)); 17269566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &K)); 172720cf1dd8SToby Isaac /* Create space */ 17289566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)P)); 172920cf1dd8SToby Isaac Pref = P; 173020cf1dd8SToby Isaac /* Create dual space */ 17319566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDuplicate(Q, &Qref)); 17329566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetType(Qref, PETSCDUALSPACEREFINED)); 17339566063dSJacob Faibussowitsch PetscCall(DMRefine(K, PetscObjectComm((PetscObject)fe), &Kref)); 17349566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetDM(Qref, Kref)); 17359566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(Kref, 0, &cStart, &cEnd)); 17369566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(cEnd - cStart, &cellSpaces)); 17371ac17e89SToby Isaac /* TODO: fix for non-uniform refinement */ 17381ac17e89SToby Isaac for (c = 0; c < cEnd - cStart; c++) cellSpaces[c] = Q; 17399566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceRefinedSetCellSpaces(Qref, cellSpaces)); 17409566063dSJacob Faibussowitsch PetscCall(PetscFree(cellSpaces)); 17419566063dSJacob Faibussowitsch PetscCall(DMDestroy(&Kref)); 17429566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetUp(Qref)); 174320cf1dd8SToby Isaac /* Create element */ 17449566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject)fe), feRef)); 17459566063dSJacob Faibussowitsch PetscCall(PetscFESetType(*feRef, PETSCFECOMPOSITE)); 17469566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(*feRef, Pref)); 17479566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(*feRef, Qref)); 17489566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &numComp)); 17499566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(*feRef, numComp)); 17509566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(*feRef)); 17519566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pref)); 17529566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&Qref)); 175320cf1dd8SToby Isaac /* Create quadrature */ 17549566063dSJacob Faibussowitsch PetscCall(PetscFECompositeGetMapping(*feRef, &numSubelements, &v0, &jac, NULL)); 17559566063dSJacob Faibussowitsch PetscCall(PetscQuadratureExpandComposite(q, numSubelements, v0, jac, &qref)); 17569566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(*feRef, qref)); 17579566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&qref)); 175820cf1dd8SToby Isaac PetscFunctionReturn(0); 175920cf1dd8SToby Isaac } 176020cf1dd8SToby Isaac 1761*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscFESetDefaultName_Private(PetscFE fe) 1762*d71ae5a4SJacob Faibussowitsch { 17637c48043bSMatthew G. Knepley PetscSpace P; 17647c48043bSMatthew G. Knepley PetscDualSpace Q; 17657c48043bSMatthew G. Knepley DM K; 17667c48043bSMatthew G. Knepley DMPolytopeType ct; 17677c48043bSMatthew G. Knepley PetscInt degree; 17687c48043bSMatthew G. Knepley char name[64]; 17697c48043bSMatthew G. Knepley 17707c48043bSMatthew G. Knepley PetscFunctionBegin; 17717c48043bSMatthew G. Knepley PetscCall(PetscFEGetBasisSpace(fe, &P)); 17727c48043bSMatthew G. Knepley PetscCall(PetscSpaceGetDegree(P, °ree, NULL)); 17737c48043bSMatthew G. Knepley PetscCall(PetscFEGetDualSpace(fe, &Q)); 17747c48043bSMatthew G. Knepley PetscCall(PetscDualSpaceGetDM(Q, &K)); 17757c48043bSMatthew G. Knepley PetscCall(DMPlexGetCellType(K, 0, &ct)); 17767c48043bSMatthew G. Knepley switch (ct) { 17777c48043bSMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 17787c48043bSMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 17797c48043bSMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 17807c48043bSMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 17817c48043bSMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 1782*d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_QUAD_PRISM_TENSOR: 1783*d71ae5a4SJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "Q%" PetscInt_FMT, degree)); 1784*d71ae5a4SJacob Faibussowitsch break; 17857c48043bSMatthew G. Knepley case DM_POLYTOPE_TRIANGLE: 1786*d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_TETRAHEDRON: 1787*d71ae5a4SJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "P%" PetscInt_FMT, degree)); 1788*d71ae5a4SJacob Faibussowitsch break; 17897c48043bSMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM: 1790*d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_TRI_PRISM_TENSOR: 1791*d71ae5a4SJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "P%" PetscInt_FMT "xQ%" PetscInt_FMT, degree, degree)); 1792*d71ae5a4SJacob Faibussowitsch break; 1793*d71ae5a4SJacob Faibussowitsch default: 1794*d71ae5a4SJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "FE")); 17957c48043bSMatthew G. Knepley } 17967c48043bSMatthew G. Knepley PetscCall(PetscFESetName(fe, name)); 17977c48043bSMatthew G. Knepley PetscFunctionReturn(0); 17987c48043bSMatthew G. Knepley } 17997c48043bSMatthew G. Knepley 1800*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscFECreateDefaultQuadrature_Private(PetscInt dim, DMPolytopeType ct, PetscInt qorder, PetscQuadrature *q, PetscQuadrature *fq) 1801*d71ae5a4SJacob Faibussowitsch { 18027c48043bSMatthew G. Knepley const PetscInt quadPointsPerEdge = PetscMax(qorder + 1, 1); 18037c48043bSMatthew G. Knepley 18047c48043bSMatthew G. Knepley PetscFunctionBegin; 18057c48043bSMatthew G. Knepley switch (ct) { 18067c48043bSMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 18077c48043bSMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 18087c48043bSMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 18097c48043bSMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 18107c48043bSMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 18117c48043bSMatthew G. Knepley case DM_POLYTOPE_QUAD_PRISM_TENSOR: 18127c48043bSMatthew G. Knepley PetscCall(PetscDTGaussTensorQuadrature(dim, 1, quadPointsPerEdge, -1.0, 1.0, q)); 18137c48043bSMatthew G. Knepley PetscCall(PetscDTGaussTensorQuadrature(dim - 1, 1, quadPointsPerEdge, -1.0, 1.0, fq)); 18147c48043bSMatthew G. Knepley break; 18157c48043bSMatthew G. Knepley case DM_POLYTOPE_TRIANGLE: 18167c48043bSMatthew G. Knepley case DM_POLYTOPE_TETRAHEDRON: 18177c48043bSMatthew G. Knepley PetscCall(PetscDTStroudConicalQuadrature(dim, 1, quadPointsPerEdge, -1.0, 1.0, q)); 18187c48043bSMatthew G. Knepley PetscCall(PetscDTStroudConicalQuadrature(dim - 1, 1, quadPointsPerEdge, -1.0, 1.0, fq)); 18197c48043bSMatthew G. Knepley break; 18207c48043bSMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM: 18219371c9d4SSatish Balay case DM_POLYTOPE_TRI_PRISM_TENSOR: { 18227c48043bSMatthew G. Knepley PetscQuadrature q1, q2; 18237c48043bSMatthew G. Knepley 18247c48043bSMatthew G. Knepley PetscCall(PetscDTStroudConicalQuadrature(2, 1, quadPointsPerEdge, -1.0, 1.0, &q1)); 18257c48043bSMatthew G. Knepley PetscCall(PetscDTGaussTensorQuadrature(1, 1, quadPointsPerEdge, -1.0, 1.0, &q2)); 18267c48043bSMatthew G. Knepley PetscCall(PetscDTTensorQuadratureCreate(q1, q2, q)); 18277c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&q1)); 18287c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&q2)); 18297c48043bSMatthew G. Knepley } 18307c48043bSMatthew G. Knepley PetscCall(PetscDTStroudConicalQuadrature(dim - 1, 1, quadPointsPerEdge, -1.0, 1.0, fq)); 18317c48043bSMatthew G. Knepley /* TODO Need separate quadratures for each face */ 18327c48043bSMatthew G. Knepley break; 1833*d71ae5a4SJacob Faibussowitsch default: 1834*d71ae5a4SJacob Faibussowitsch SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "No quadrature for celltype %s", DMPolytopeTypes[PetscMin(ct, DM_POLYTOPE_UNKNOWN)]); 18357c48043bSMatthew G. Knepley } 18367c48043bSMatthew G. Knepley PetscFunctionReturn(0); 18377c48043bSMatthew G. Knepley } 18387c48043bSMatthew G. Knepley 18397c48043bSMatthew G. Knepley /*@ 18407c48043bSMatthew G. Knepley PetscFECreateFromSpaces - Create a PetscFE from the basis and dual spaces 18417c48043bSMatthew G. Knepley 18427c48043bSMatthew G. Knepley Collective 18437c48043bSMatthew G. Knepley 18447c48043bSMatthew G. Knepley Input Parameters: 18457c48043bSMatthew G. Knepley + P - The basis space 18467c48043bSMatthew G. Knepley . Q - The dual space 18477c48043bSMatthew G. Knepley . q - The cell quadrature 18487c48043bSMatthew G. Knepley - fq - The face quadrature 18497c48043bSMatthew G. Knepley 18507c48043bSMatthew G. Knepley Output Parameter: 18517c48043bSMatthew G. Knepley . fem - The PetscFE object 18527c48043bSMatthew G. Knepley 18537c48043bSMatthew G. Knepley Note: 18547c48043bSMatthew 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. 18557c48043bSMatthew G. Knepley 18567c48043bSMatthew G. Knepley Level: beginner 18577c48043bSMatthew G. Knepley 18587c48043bSMatthew G. Knepley .seealso: `PetscFECreateLagrangeByCell()`, `PetscFECreateDefault()`, `PetscFECreateByCell()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 18597c48043bSMatthew G. Knepley @*/ 1860*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateFromSpaces(PetscSpace P, PetscDualSpace Q, PetscQuadrature q, PetscQuadrature fq, PetscFE *fem) 1861*d71ae5a4SJacob Faibussowitsch { 18627c48043bSMatthew G. Knepley PetscInt Nc; 18637c48043bSMatthew G. Knepley const char *prefix; 18647c48043bSMatthew G. Knepley 18657c48043bSMatthew G. Knepley PetscFunctionBegin; 18667c48043bSMatthew G. Knepley PetscCall(PetscFECreate(PetscObjectComm((PetscObject)P), fem)); 18677c48043bSMatthew G. Knepley PetscCall(PetscObjectGetOptionsPrefix((PetscObject)P, &prefix)); 18687c48043bSMatthew G. Knepley PetscCall(PetscObjectSetOptionsPrefix((PetscObject)*fem, prefix)); 18697c48043bSMatthew G. Knepley PetscCall(PetscFESetType(*fem, PETSCFEBASIC)); 18707c48043bSMatthew G. Knepley PetscCall(PetscFESetBasisSpace(*fem, P)); 18717c48043bSMatthew G. Knepley PetscCall(PetscFESetDualSpace(*fem, Q)); 18727c48043bSMatthew G. Knepley PetscCall(PetscSpaceGetNumComponents(P, &Nc)); 18737c48043bSMatthew G. Knepley PetscCall(PetscFESetNumComponents(*fem, Nc)); 18747c48043bSMatthew G. Knepley PetscCall(PetscFESetUp(*fem)); 18757c48043bSMatthew G. Knepley PetscCall(PetscSpaceDestroy(&P)); 18767c48043bSMatthew G. Knepley PetscCall(PetscDualSpaceDestroy(&Q)); 18777c48043bSMatthew G. Knepley PetscCall(PetscFESetQuadrature(*fem, q)); 18787c48043bSMatthew G. Knepley PetscCall(PetscFESetFaceQuadrature(*fem, fq)); 18797c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&q)); 18807c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&fq)); 18817c48043bSMatthew G. Knepley PetscCall(PetscFESetDefaultName_Private(*fem)); 18827c48043bSMatthew G. Knepley PetscFunctionReturn(0); 18837c48043bSMatthew G. Knepley } 18847c48043bSMatthew G. Knepley 1885*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscFECreate_Internal(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, const char prefix[], PetscInt degree, PetscInt qorder, PetscBool setFromOptions, PetscFE *fem) 1886*d71ae5a4SJacob Faibussowitsch { 18872df84da0SMatthew G. Knepley DM K; 18882df84da0SMatthew G. Knepley PetscSpace P; 18892df84da0SMatthew G. Knepley PetscDualSpace Q; 18907c48043bSMatthew G. Knepley PetscQuadrature q, fq; 18912df84da0SMatthew G. Knepley PetscBool tensor; 18922df84da0SMatthew G. Knepley 18932df84da0SMatthew G. Knepley PetscFunctionBegin; 18942df84da0SMatthew G. Knepley if (prefix) PetscValidCharPointer(prefix, 5); 18952df84da0SMatthew G. Knepley PetscValidPointer(fem, 9); 18962df84da0SMatthew G. Knepley switch (ct) { 18972df84da0SMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 18982df84da0SMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 18992df84da0SMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 19002df84da0SMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 19012df84da0SMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 1902*d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_QUAD_PRISM_TENSOR: 1903*d71ae5a4SJacob Faibussowitsch tensor = PETSC_TRUE; 1904*d71ae5a4SJacob Faibussowitsch break; 1905*d71ae5a4SJacob Faibussowitsch default: 1906*d71ae5a4SJacob Faibussowitsch tensor = PETSC_FALSE; 19072df84da0SMatthew G. Knepley } 19082df84da0SMatthew G. Knepley /* Create space */ 19099566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &P)); 19109566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(P, PETSCSPACEPOLYNOMIAL)); 19119566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject)P, prefix)); 19129566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(P, tensor)); 19139566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(P, Nc)); 19149566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(P, dim)); 19152df84da0SMatthew G. Knepley if (degree >= 0) { 19169566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(P, degree, PETSC_DETERMINE)); 1917cfd33b42SLisandro Dalcin if (ct == DM_POLYTOPE_TRI_PRISM || ct == DM_POLYTOPE_TRI_PRISM_TENSOR) { 19182df84da0SMatthew G. Knepley PetscSpace Pend, Pside; 19192df84da0SMatthew G. Knepley 19209566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &Pend)); 19219566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(Pend, PETSCSPACEPOLYNOMIAL)); 19229566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(Pend, PETSC_FALSE)); 19239566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(Pend, Nc)); 19249566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(Pend, dim - 1)); 19259566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(Pend, degree, PETSC_DETERMINE)); 19269566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &Pside)); 19279566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(Pside, PETSCSPACEPOLYNOMIAL)); 19289566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(Pside, PETSC_FALSE)); 19299566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(Pside, 1)); 19309566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(Pside, 1)); 19319566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(Pside, degree, PETSC_DETERMINE)); 19329566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(P, PETSCSPACETENSOR)); 19339566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetNumSubspaces(P, 2)); 19349566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetSubspace(P, 0, Pend)); 19359566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetSubspace(P, 1, Pside)); 19369566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pend)); 19379566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pside)); 19382df84da0SMatthew G. Knepley } 19392df84da0SMatthew G. Knepley } 19409566063dSJacob Faibussowitsch if (setFromOptions) PetscCall(PetscSpaceSetFromOptions(P)); 19419566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetUp(P)); 19429566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetDegree(P, °ree, NULL)); 19439566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialGetTensor(P, &tensor)); 19449566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetNumComponents(P, &Nc)); 19452df84da0SMatthew G. Knepley /* Create dual space */ 19469566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceCreate(comm, &Q)); 19479566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetType(Q, PETSCDUALSPACELAGRANGE)); 19489566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject)Q, prefix)); 19499566063dSJacob Faibussowitsch PetscCall(DMPlexCreateReferenceCell(PETSC_COMM_SELF, ct, &K)); 19509566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetDM(Q, K)); 19519566063dSJacob Faibussowitsch PetscCall(DMDestroy(&K)); 19529566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetNumComponents(Q, Nc)); 19539566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetOrder(Q, degree)); 19542df84da0SMatthew G. Knepley /* TODO For some reason, we need a tensor dualspace with wedges */ 19559566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceLagrangeSetTensor(Q, (tensor || (ct == DM_POLYTOPE_TRI_PRISM)) ? PETSC_TRUE : PETSC_FALSE)); 19569566063dSJacob Faibussowitsch if (setFromOptions) PetscCall(PetscDualSpaceSetFromOptions(Q)); 19579566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetUp(Q)); 19587c48043bSMatthew G. Knepley /* Create quadrature */ 19592df84da0SMatthew G. Knepley qorder = qorder >= 0 ? qorder : degree; 19602df84da0SMatthew G. Knepley if (setFromOptions) { 19617c48043bSMatthew G. Knepley PetscObjectOptionsBegin((PetscObject)P); 19629566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-petscfe_default_quadrature_order", "Quadrature order is one less than quadrature points per edge", "PetscFECreateDefault", qorder, &qorder, NULL, 0)); 1963d0609cedSBarry Smith PetscOptionsEnd(); 19642df84da0SMatthew G. Knepley } 19657c48043bSMatthew G. Knepley PetscCall(PetscFECreateDefaultQuadrature_Private(dim, ct, qorder, &q, &fq)); 19667c48043bSMatthew G. Knepley /* Create finite element */ 19677c48043bSMatthew G. Knepley PetscCall(PetscFECreateFromSpaces(P, Q, q, fq, fem)); 19687c48043bSMatthew G. Knepley if (setFromOptions) PetscCall(PetscFESetFromOptions(*fem)); 19692df84da0SMatthew G. Knepley PetscFunctionReturn(0); 19702df84da0SMatthew G. Knepley } 19712df84da0SMatthew G. Knepley 197220cf1dd8SToby Isaac /*@C 197320cf1dd8SToby Isaac PetscFECreateDefault - Create a PetscFE for basic FEM computation 197420cf1dd8SToby Isaac 1975d083f849SBarry Smith Collective 197620cf1dd8SToby Isaac 197720cf1dd8SToby Isaac Input Parameters: 19787be5e748SToby Isaac + comm - The MPI comm 197920cf1dd8SToby Isaac . dim - The spatial dimension 198020cf1dd8SToby Isaac . Nc - The number of components 198120cf1dd8SToby Isaac . isSimplex - Flag for simplex reference cell, otherwise its a tensor product 198220cf1dd8SToby Isaac . prefix - The options prefix, or NULL 1983727cddd5SJacob Faibussowitsch - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 198420cf1dd8SToby Isaac 198520cf1dd8SToby Isaac Output Parameter: 198620cf1dd8SToby Isaac . fem - The PetscFE object 198720cf1dd8SToby Isaac 1988e703855dSMatthew G. Knepley Note: 19898f2aacc6SMatthew 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. 1990e703855dSMatthew G. Knepley 199120cf1dd8SToby Isaac Level: beginner 199220cf1dd8SToby Isaac 1993db781477SPatrick Sanan .seealso: `PetscFECreateLagrange()`, `PetscFECreateByCell()`, `PetscSpaceSetFromOptions()`, `PetscDualSpaceSetFromOptions()`, `PetscFESetFromOptions()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 199420cf1dd8SToby Isaac @*/ 1995*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateDefault(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, const char prefix[], PetscInt qorder, PetscFE *fem) 1996*d71ae5a4SJacob Faibussowitsch { 199720cf1dd8SToby Isaac PetscFunctionBegin; 19989566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, DMPolytopeTypeSimpleShape(dim, isSimplex), prefix, PETSC_DECIDE, qorder, PETSC_TRUE, fem)); 19992df84da0SMatthew G. Knepley PetscFunctionReturn(0); 200020cf1dd8SToby Isaac } 20012df84da0SMatthew G. Knepley 20022df84da0SMatthew G. Knepley /*@C 20032df84da0SMatthew G. Knepley PetscFECreateByCell - Create a PetscFE for basic FEM computation 20042df84da0SMatthew G. Knepley 20052df84da0SMatthew G. Knepley Collective 20062df84da0SMatthew G. Knepley 20072df84da0SMatthew G. Knepley Input Parameters: 20082df84da0SMatthew G. Knepley + comm - The MPI comm 20092df84da0SMatthew G. Knepley . dim - The spatial dimension 20102df84da0SMatthew G. Knepley . Nc - The number of components 20112df84da0SMatthew G. Knepley . ct - The celltype of the reference cell 20122df84da0SMatthew G. Knepley . prefix - The options prefix, or NULL 20132df84da0SMatthew G. Knepley - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 20142df84da0SMatthew G. Knepley 20152df84da0SMatthew G. Knepley Output Parameter: 20162df84da0SMatthew G. Knepley . fem - The PetscFE object 20172df84da0SMatthew G. Knepley 20182df84da0SMatthew G. Knepley Note: 20192df84da0SMatthew 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. 20202df84da0SMatthew G. Knepley 20212df84da0SMatthew G. Knepley Level: beginner 20222df84da0SMatthew G. Knepley 2023db781477SPatrick Sanan .seealso: `PetscFECreateDefault()`, `PetscFECreateLagrange()`, `PetscSpaceSetFromOptions()`, `PetscDualSpaceSetFromOptions()`, `PetscFESetFromOptions()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 20242df84da0SMatthew G. Knepley @*/ 2025*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateByCell(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, const char prefix[], PetscInt qorder, PetscFE *fem) 2026*d71ae5a4SJacob Faibussowitsch { 20272df84da0SMatthew G. Knepley PetscFunctionBegin; 20289566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, ct, prefix, PETSC_DECIDE, qorder, PETSC_TRUE, fem)); 202920cf1dd8SToby Isaac PetscFunctionReturn(0); 203020cf1dd8SToby Isaac } 20313f6b16c7SMatthew G. Knepley 2032e703855dSMatthew G. Knepley /*@ 2033e703855dSMatthew G. Knepley PetscFECreateLagrange - Create a PetscFE for the basic Lagrange space of degree k 2034e703855dSMatthew G. Knepley 2035e703855dSMatthew G. Knepley Collective 2036e703855dSMatthew G. Knepley 2037e703855dSMatthew G. Knepley Input Parameters: 2038e703855dSMatthew G. Knepley + comm - The MPI comm 2039e703855dSMatthew G. Knepley . dim - The spatial dimension 2040e703855dSMatthew G. Knepley . Nc - The number of components 2041e703855dSMatthew G. Knepley . isSimplex - Flag for simplex reference cell, otherwise its a tensor product 2042e703855dSMatthew G. Knepley . k - The degree k of the space 2043e703855dSMatthew G. Knepley - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 2044e703855dSMatthew G. Knepley 2045e703855dSMatthew G. Knepley Output Parameter: 2046e703855dSMatthew G. Knepley . fem - The PetscFE object 2047e703855dSMatthew G. Knepley 2048e703855dSMatthew G. Knepley Level: beginner 2049e703855dSMatthew G. Knepley 2050e703855dSMatthew G. Knepley Notes: 2051e703855dSMatthew 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. 2052e703855dSMatthew G. Knepley 2053db781477SPatrick Sanan .seealso: `PetscFECreateLagrangeByCell()`, `PetscFECreateDefault()`, `PetscFECreateByCell()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 2054e703855dSMatthew G. Knepley @*/ 2055*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateLagrange(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, PetscInt k, PetscInt qorder, PetscFE *fem) 2056*d71ae5a4SJacob Faibussowitsch { 2057e703855dSMatthew G. Knepley PetscFunctionBegin; 20589566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, DMPolytopeTypeSimpleShape(dim, isSimplex), NULL, k, qorder, PETSC_FALSE, fem)); 20592df84da0SMatthew G. Knepley PetscFunctionReturn(0); 2060e703855dSMatthew G. Knepley } 20612df84da0SMatthew G. Knepley 20622df84da0SMatthew G. Knepley /*@ 20632df84da0SMatthew G. Knepley PetscFECreateLagrangeByCell - Create a PetscFE for the basic Lagrange space of degree k 20642df84da0SMatthew G. Knepley 20652df84da0SMatthew G. Knepley Collective 20662df84da0SMatthew G. Knepley 20672df84da0SMatthew G. Knepley Input Parameters: 20682df84da0SMatthew G. Knepley + comm - The MPI comm 20692df84da0SMatthew G. Knepley . dim - The spatial dimension 20702df84da0SMatthew G. Knepley . Nc - The number of components 20712df84da0SMatthew G. Knepley . ct - The celltype of the reference cell 20722df84da0SMatthew G. Knepley . k - The degree k of the space 20732df84da0SMatthew G. Knepley - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 20742df84da0SMatthew G. Knepley 20752df84da0SMatthew G. Knepley Output Parameter: 20762df84da0SMatthew G. Knepley . fem - The PetscFE object 20772df84da0SMatthew G. Knepley 20782df84da0SMatthew G. Knepley Level: beginner 20792df84da0SMatthew G. Knepley 20802df84da0SMatthew G. Knepley Notes: 20812df84da0SMatthew 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. 20822df84da0SMatthew G. Knepley 2083db781477SPatrick Sanan .seealso: `PetscFECreateLagrange()`, `PetscFECreateDefault()`, `PetscFECreateByCell()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 20842df84da0SMatthew G. Knepley @*/ 2085*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateLagrangeByCell(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, PetscInt k, PetscInt qorder, PetscFE *fem) 2086*d71ae5a4SJacob Faibussowitsch { 20872df84da0SMatthew G. Knepley PetscFunctionBegin; 20889566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, ct, NULL, k, qorder, PETSC_FALSE, fem)); 2089e703855dSMatthew G. Knepley PetscFunctionReturn(0); 2090e703855dSMatthew G. Knepley } 2091e703855dSMatthew G. Knepley 20923f6b16c7SMatthew G. Knepley /*@C 20933f6b16c7SMatthew G. Knepley PetscFESetName - Names the FE and its subobjects 20943f6b16c7SMatthew G. Knepley 20953f6b16c7SMatthew G. Knepley Not collective 20963f6b16c7SMatthew G. Knepley 20973f6b16c7SMatthew G. Knepley Input Parameters: 20983f6b16c7SMatthew G. Knepley + fe - The PetscFE 20993f6b16c7SMatthew G. Knepley - name - The name 21003f6b16c7SMatthew G. Knepley 21012b99622eSMatthew G. Knepley Level: intermediate 21023f6b16c7SMatthew G. Knepley 2103db781477SPatrick Sanan .seealso: `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 21043f6b16c7SMatthew G. Knepley @*/ 2105*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetName(PetscFE fe, const char name[]) 2106*d71ae5a4SJacob Faibussowitsch { 21073f6b16c7SMatthew G. Knepley PetscSpace P; 21083f6b16c7SMatthew G. Knepley PetscDualSpace Q; 21093f6b16c7SMatthew G. Knepley 21103f6b16c7SMatthew G. Knepley PetscFunctionBegin; 21119566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 21129566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 21139566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject)fe, name)); 21149566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject)P, name)); 21159566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject)Q, name)); 21163f6b16c7SMatthew G. Knepley PetscFunctionReturn(0); 21173f6b16c7SMatthew G. Knepley } 2118a8f1f9e5SMatthew G. Knepley 2119*d71ae5a4SJacob Faibussowitsch 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[]) 2120*d71ae5a4SJacob Faibussowitsch { 2121f9244615SMatthew G. Knepley PetscInt dOffset = 0, fOffset = 0, f, g; 2122a8f1f9e5SMatthew G. Knepley 2123a8f1f9e5SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 2124a8f1f9e5SMatthew G. Knepley PetscFE fe; 2125f9244615SMatthew G. Knepley const PetscInt k = ds->jetDegree[f]; 2126ef0bb6c7SMatthew G. Knepley const PetscInt cdim = T[f]->cdim; 2127ef0bb6c7SMatthew G. Knepley const PetscInt Nq = T[f]->Np; 2128ef0bb6c7SMatthew G. Knepley const PetscInt Nbf = T[f]->Nb; 2129ef0bb6c7SMatthew G. Knepley const PetscInt Ncf = T[f]->Nc; 2130ef0bb6c7SMatthew G. Knepley const PetscReal *Bq = &T[f]->T[0][(r * Nq + q) * Nbf * Ncf]; 2131ef0bb6c7SMatthew G. Knepley const PetscReal *Dq = &T[f]->T[1][(r * Nq + q) * Nbf * Ncf * cdim]; 2132f9244615SMatthew G. Knepley const PetscReal *Hq = k > 1 ? &T[f]->T[2][(r * Nq + q) * Nbf * Ncf * cdim * cdim] : NULL; 2133f9244615SMatthew G. Knepley PetscInt hOffset = 0, b, c, d; 2134a8f1f9e5SMatthew G. Knepley 21359566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, f, (PetscObject *)&fe)); 2136a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u[fOffset + c] = 0.0; 2137ef0bb6c7SMatthew G. Knepley for (d = 0; d < cdim * Ncf; ++d) u_x[fOffset * cdim + d] = 0.0; 2138a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2139a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2140a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 2141a8f1f9e5SMatthew G. Knepley 2142a8f1f9e5SMatthew G. Knepley u[fOffset + c] += Bq[cidx] * coefficients[dOffset + b]; 2143ef0bb6c7SMatthew G. Knepley for (d = 0; d < cdim; ++d) u_x[(fOffset + c) * cdim + d] += Dq[cidx * cdim + d] * coefficients[dOffset + b]; 2144a8f1f9e5SMatthew G. Knepley } 2145a8f1f9e5SMatthew G. Knepley } 2146f9244615SMatthew G. Knepley if (k > 1) { 2147f9244615SMatthew G. Knepley for (g = 0; g < Nf; ++g) hOffset += T[g]->Nc * cdim; 2148f9244615SMatthew G. Knepley for (d = 0; d < cdim * cdim * Ncf; ++d) u_x[hOffset + fOffset * cdim * cdim + d] = 0.0; 2149f9244615SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2150f9244615SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2151f9244615SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 2152f9244615SMatthew G. Knepley 2153f9244615SMatthew 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]; 2154f9244615SMatthew G. Knepley } 2155f9244615SMatthew G. Knepley } 21569566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardHessian(fe, fegeom, 1, &u_x[hOffset + fOffset * cdim * cdim])); 2157f9244615SMatthew G. Knepley } 21589566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u[fOffset])); 21599566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset * cdim])); 2160a8f1f9e5SMatthew G. Knepley if (u_t) { 2161a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u_t[fOffset + c] = 0.0; 2162a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2163a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2164a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 2165a8f1f9e5SMatthew G. Knepley 2166a8f1f9e5SMatthew G. Knepley u_t[fOffset + c] += Bq[cidx] * coefficients_t[dOffset + b]; 2167a8f1f9e5SMatthew G. Knepley } 2168a8f1f9e5SMatthew G. Knepley } 21699566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset])); 2170a8f1f9e5SMatthew G. Knepley } 2171a8f1f9e5SMatthew G. Knepley fOffset += Ncf; 2172a8f1f9e5SMatthew G. Knepley dOffset += Nbf; 2173a8f1f9e5SMatthew G. Knepley } 2174a8f1f9e5SMatthew G. Knepley return 0; 2175a8f1f9e5SMatthew G. Knepley } 2176a8f1f9e5SMatthew G. Knepley 2177*d71ae5a4SJacob Faibussowitsch 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[]) 2178*d71ae5a4SJacob Faibussowitsch { 21795fedec97SMatthew G. Knepley PetscInt dOffset = 0, fOffset = 0, f, g; 218027f02ce8SMatthew G. Knepley 21815fedec97SMatthew G. Knepley /* f is the field number in the DS, g is the field number in u[] */ 21825fedec97SMatthew G. Knepley for (f = 0, g = 0; f < Nf; ++f) { 21835fedec97SMatthew G. Knepley PetscFE fe = (PetscFE)ds->disc[f]; 21849ee2af8cSMatthew G. Knepley const PetscInt dEt = T[f]->cdim; 21859ee2af8cSMatthew G. Knepley const PetscInt dE = fegeom->dimEmbed; 2186665f567fSMatthew G. Knepley const PetscInt Nq = T[f]->Np; 2187665f567fSMatthew G. Knepley const PetscInt Nbf = T[f]->Nb; 2188665f567fSMatthew G. Knepley const PetscInt Ncf = T[f]->Nc; 2189665f567fSMatthew G. Knepley const PetscReal *Bq = &T[f]->T[0][(r * Nq + q) * Nbf * Ncf]; 21909ee2af8cSMatthew G. Knepley const PetscReal *Dq = &T[f]->T[1][(r * Nq + q) * Nbf * Ncf * dEt]; 21915fedec97SMatthew G. Knepley PetscBool isCohesive; 21925fedec97SMatthew G. Knepley PetscInt Ns, s; 21935fedec97SMatthew G. Knepley 21945fedec97SMatthew G. Knepley if (!T[f]) continue; 21959566063dSJacob Faibussowitsch PetscCall(PetscDSGetCohesive(ds, f, &isCohesive)); 21965fedec97SMatthew G. Knepley Ns = isCohesive ? 1 : 2; 21975fedec97SMatthew G. Knepley for (s = 0; s < Ns; ++s, ++g) { 219827f02ce8SMatthew G. Knepley PetscInt b, c, d; 219927f02ce8SMatthew G. Knepley 220027f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u[fOffset + c] = 0.0; 22019ee2af8cSMatthew G. Knepley for (d = 0; d < dE * Ncf; ++d) u_x[fOffset * dE + d] = 0.0; 220227f02ce8SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 220327f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 220427f02ce8SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 220527f02ce8SMatthew G. Knepley 220627f02ce8SMatthew G. Knepley u[fOffset + c] += Bq[cidx] * coefficients[dOffset + b]; 22079ee2af8cSMatthew G. Knepley for (d = 0; d < dEt; ++d) u_x[(fOffset + c) * dE + d] += Dq[cidx * dEt + d] * coefficients[dOffset + b]; 220827f02ce8SMatthew G. Knepley } 220927f02ce8SMatthew G. Knepley } 22109566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u[fOffset])); 22119566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset * dE])); 221227f02ce8SMatthew G. Knepley if (u_t) { 221327f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u_t[fOffset + c] = 0.0; 221427f02ce8SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 221527f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 221627f02ce8SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 221727f02ce8SMatthew G. Knepley 221827f02ce8SMatthew G. Knepley u_t[fOffset + c] += Bq[cidx] * coefficients_t[dOffset + b]; 221927f02ce8SMatthew G. Knepley } 222027f02ce8SMatthew G. Knepley } 22219566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset])); 222227f02ce8SMatthew G. Knepley } 222327f02ce8SMatthew G. Knepley fOffset += Ncf; 222427f02ce8SMatthew G. Knepley dOffset += Nbf; 222527f02ce8SMatthew G. Knepley } 2226665f567fSMatthew G. Knepley } 222727f02ce8SMatthew G. Knepley return 0; 222827f02ce8SMatthew G. Knepley } 222927f02ce8SMatthew G. Knepley 2230*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEEvaluateFaceFields_Internal(PetscDS prob, PetscInt field, PetscInt faceLoc, const PetscScalar coefficients[], PetscScalar u[]) 2231*d71ae5a4SJacob Faibussowitsch { 2232a8f1f9e5SMatthew G. Knepley PetscFE fe; 2233ef0bb6c7SMatthew G. Knepley PetscTabulation Tc; 2234ef0bb6c7SMatthew G. Knepley PetscInt b, c; 2235a8f1f9e5SMatthew G. Knepley 2236a8f1f9e5SMatthew G. Knepley if (!prob) return 0; 22379566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *)&fe)); 22389566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceCentroidTabulation(fe, &Tc)); 2239ef0bb6c7SMatthew G. Knepley { 2240ef0bb6c7SMatthew G. Knepley const PetscReal *faceBasis = Tc->T[0]; 2241ef0bb6c7SMatthew G. Knepley const PetscInt Nb = Tc->Nb; 2242ef0bb6c7SMatthew G. Knepley const PetscInt Nc = Tc->Nc; 2243ef0bb6c7SMatthew G. Knepley 2244ad540459SPierre Jolivet for (c = 0; c < Nc; ++c) u[c] = 0.0; 2245a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2246ad540459SPierre Jolivet for (c = 0; c < Nc; ++c) u[c] += coefficients[b] * faceBasis[(faceLoc * Nb + b) * Nc + c]; 2247a8f1f9e5SMatthew G. Knepley } 2248ef0bb6c7SMatthew G. Knepley } 2249a8f1f9e5SMatthew G. Knepley return 0; 2250a8f1f9e5SMatthew G. Knepley } 2251a8f1f9e5SMatthew G. Knepley 2252*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEUpdateElementVec_Internal(PetscFE fe, PetscTabulation T, PetscInt r, PetscScalar tmpBasis[], PetscScalar tmpBasisDer[], PetscInt e, PetscFEGeom *fegeom, PetscScalar f0[], PetscScalar f1[], PetscScalar elemVec[]) 2253*d71ae5a4SJacob Faibussowitsch { 22546587ee25SMatthew G. Knepley PetscFEGeom pgeom; 2255bc3a64adSMatthew G. Knepley const PetscInt dEt = T->cdim; 2256bc3a64adSMatthew G. Knepley const PetscInt dE = fegeom->dimEmbed; 2257ef0bb6c7SMatthew G. Knepley const PetscInt Nq = T->Np; 2258ef0bb6c7SMatthew G. Knepley const PetscInt Nb = T->Nb; 2259ef0bb6c7SMatthew G. Knepley const PetscInt Nc = T->Nc; 2260ef0bb6c7SMatthew G. Knepley const PetscReal *basis = &T->T[0][r * Nq * Nb * Nc]; 2261bc3a64adSMatthew G. Knepley const PetscReal *basisDer = &T->T[1][r * Nq * Nb * Nc * dEt]; 2262a8f1f9e5SMatthew G. Knepley PetscInt q, b, c, d; 2263a8f1f9e5SMatthew G. Knepley 2264a8f1f9e5SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 2265a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2266a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2267a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b * Nc + c; 2268a8f1f9e5SMatthew G. Knepley 2269a8f1f9e5SMatthew G. Knepley tmpBasis[bcidx] = basis[q * Nb * Nc + bcidx]; 2270bc3a64adSMatthew G. Knepley for (d = 0; d < dEt; ++d) tmpBasisDer[bcidx * dE + d] = basisDer[q * Nb * Nc * dEt + bcidx * dEt + d]; 22719ee2af8cSMatthew G. Knepley for (d = dEt; d < dE; ++d) tmpBasisDer[bcidx * dE + d] = 0.0; 2272a8f1f9e5SMatthew G. Knepley } 2273a8f1f9e5SMatthew G. Knepley } 22749566063dSJacob Faibussowitsch PetscCall(PetscFEGeomGetCellPoint(fegeom, e, q, &pgeom)); 22759566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, &pgeom, Nb, tmpBasis)); 22769566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, &pgeom, Nb, tmpBasisDer)); 2277a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2278a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2279a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b * Nc + c; 2280a8f1f9e5SMatthew G. Knepley const PetscInt qcidx = q * Nc + c; 2281a8f1f9e5SMatthew G. Knepley 2282a8f1f9e5SMatthew G. Knepley elemVec[b] += tmpBasis[bcidx] * f0[qcidx]; 228327f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) elemVec[b] += tmpBasisDer[bcidx * dE + d] * f1[qcidx * dE + d]; 228427f02ce8SMatthew G. Knepley } 228527f02ce8SMatthew G. Knepley } 228627f02ce8SMatthew G. Knepley } 228727f02ce8SMatthew G. Knepley return (0); 228827f02ce8SMatthew G. Knepley } 228927f02ce8SMatthew G. Knepley 2290*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEUpdateElementVec_Hybrid_Internal(PetscFE fe, PetscTabulation T, PetscInt r, PetscInt s, PetscScalar tmpBasis[], PetscScalar tmpBasisDer[], PetscFEGeom *fegeom, PetscScalar f0[], PetscScalar f1[], PetscScalar elemVec[]) 2291*d71ae5a4SJacob Faibussowitsch { 229227f02ce8SMatthew G. Knepley const PetscInt dE = T->cdim; 229327f02ce8SMatthew G. Knepley const PetscInt Nq = T->Np; 229427f02ce8SMatthew G. Knepley const PetscInt Nb = T->Nb; 229527f02ce8SMatthew G. Knepley const PetscInt Nc = T->Nc; 229627f02ce8SMatthew G. Knepley const PetscReal *basis = &T->T[0][r * Nq * Nb * Nc]; 229727f02ce8SMatthew G. Knepley const PetscReal *basisDer = &T->T[1][r * Nq * Nb * Nc * dE]; 2298c2b7495fSMatthew G. Knepley PetscInt q, b, c, d; 229927f02ce8SMatthew G. Knepley 230027f02ce8SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 230127f02ce8SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 230227f02ce8SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 230327f02ce8SMatthew G. Knepley const PetscInt bcidx = b * Nc + c; 230427f02ce8SMatthew G. Knepley 230527f02ce8SMatthew G. Knepley tmpBasis[bcidx] = basis[q * Nb * Nc + bcidx]; 230627f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) tmpBasisDer[bcidx * dE + d] = basisDer[q * Nb * Nc * dE + bcidx * dE + d]; 230727f02ce8SMatthew G. Knepley } 230827f02ce8SMatthew G. Knepley } 23099566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, Nb, tmpBasis)); 23109566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, Nb, tmpBasisDer)); 231127f02ce8SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 231227f02ce8SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 231327f02ce8SMatthew G. Knepley const PetscInt bcidx = b * Nc + c; 2314c2b7495fSMatthew G. Knepley const PetscInt qcidx = q * Nc + c; 231527f02ce8SMatthew G. Knepley 231627f02ce8SMatthew G. Knepley elemVec[Nb * s + b] += tmpBasis[bcidx] * f0[qcidx]; 231727f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) elemVec[Nb * s + b] += tmpBasisDer[bcidx * dE + d] * f1[qcidx * dE + d]; 231827f02ce8SMatthew G. Knepley } 2319a8f1f9e5SMatthew G. Knepley } 2320a8f1f9e5SMatthew G. Knepley } 2321a8f1f9e5SMatthew G. Knepley return (0); 2322a8f1f9e5SMatthew G. Knepley } 2323a8f1f9e5SMatthew G. Knepley 2324*d71ae5a4SJacob Faibussowitsch 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[]) 2325*d71ae5a4SJacob Faibussowitsch { 232627f02ce8SMatthew G. Knepley const PetscInt dE = TI->cdim; 2327ef0bb6c7SMatthew G. Knepley const PetscInt NqI = TI->Np; 2328ef0bb6c7SMatthew G. Knepley const PetscInt NbI = TI->Nb; 2329ef0bb6c7SMatthew G. Knepley const PetscInt NcI = TI->Nc; 2330ef0bb6c7SMatthew G. Knepley const PetscReal *basisI = &TI->T[0][(r * NqI + q) * NbI * NcI]; 2331665f567fSMatthew G. Knepley const PetscReal *basisDerI = &TI->T[1][(r * NqI + q) * NbI * NcI * dE]; 2332ef0bb6c7SMatthew G. Knepley const PetscInt NqJ = TJ->Np; 2333ef0bb6c7SMatthew G. Knepley const PetscInt NbJ = TJ->Nb; 2334ef0bb6c7SMatthew G. Knepley const PetscInt NcJ = TJ->Nc; 2335ef0bb6c7SMatthew G. Knepley const PetscReal *basisJ = &TJ->T[0][(r * NqJ + q) * NbJ * NcJ]; 2336665f567fSMatthew G. Knepley const PetscReal *basisDerJ = &TJ->T[1][(r * NqJ + q) * NbJ * NcJ * dE]; 2337a8f1f9e5SMatthew G. Knepley PetscInt f, fc, g, gc, df, dg; 2338a8f1f9e5SMatthew G. Knepley 2339a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 2340a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 2341a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f * NcI + fc; /* Test function basis index */ 2342a8f1f9e5SMatthew G. Knepley 2343a8f1f9e5SMatthew G. Knepley tmpBasisI[fidx] = basisI[fidx]; 234427f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) tmpBasisDerI[fidx * dE + df] = basisDerI[fidx * dE + df]; 2345a8f1f9e5SMatthew G. Knepley } 2346a8f1f9e5SMatthew G. Knepley } 23479566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feI, fegeom, NbI, tmpBasisI)); 23489566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI)); 2349a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 2350a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 2351a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g * NcJ + gc; /* Trial function basis index */ 2352a8f1f9e5SMatthew G. Knepley 2353a8f1f9e5SMatthew G. Knepley tmpBasisJ[gidx] = basisJ[gidx]; 235427f02ce8SMatthew G. Knepley for (dg = 0; dg < dE; ++dg) tmpBasisDerJ[gidx * dE + dg] = basisDerJ[gidx * dE + dg]; 2355a8f1f9e5SMatthew G. Knepley } 2356a8f1f9e5SMatthew G. Knepley } 23579566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ)); 23589566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ)); 2359a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 2360a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 2361a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f * NcI + fc; /* Test function basis index */ 2362a8f1f9e5SMatthew G. Knepley const PetscInt i = offsetI + f; /* Element matrix row */ 2363a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 2364a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 2365a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g * NcJ + gc; /* Trial function basis index */ 2366a8f1f9e5SMatthew G. Knepley const PetscInt j = offsetJ + g; /* Element matrix column */ 2367a8f1f9e5SMatthew G. Knepley const PetscInt fOff = eOffset + i * totDim + j; 2368a8f1f9e5SMatthew G. Knepley 2369a8f1f9e5SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx] * g0[fc * NcJ + gc] * tmpBasisJ[gidx]; 237027f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) { 237127f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx] * g1[(fc * NcJ + gc) * dE + df] * tmpBasisDerJ[gidx * dE + df]; 237227f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx * dE + df] * g2[(fc * NcJ + gc) * dE + df] * tmpBasisJ[gidx]; 2373ad540459SPierre Jolivet for (dg = 0; dg < dE; ++dg) elemMat[fOff] += tmpBasisDerI[fidx * dE + df] * g3[((fc * NcJ + gc) * dE + df) * dE + dg] * tmpBasisDerJ[gidx * dE + dg]; 237427f02ce8SMatthew G. Knepley } 237527f02ce8SMatthew G. Knepley } 237627f02ce8SMatthew G. Knepley } 237727f02ce8SMatthew G. Knepley } 237827f02ce8SMatthew G. Knepley } 237927f02ce8SMatthew G. Knepley return (0); 238027f02ce8SMatthew G. Knepley } 238127f02ce8SMatthew G. Knepley 2382*d71ae5a4SJacob Faibussowitsch 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[]) 2383*d71ae5a4SJacob Faibussowitsch { 2384665f567fSMatthew G. Knepley const PetscInt dE = TI->cdim; 2385665f567fSMatthew G. Knepley const PetscInt NqI = TI->Np; 2386665f567fSMatthew G. Knepley const PetscInt NbI = TI->Nb; 2387665f567fSMatthew G. Knepley const PetscInt NcI = TI->Nc; 2388665f567fSMatthew G. Knepley const PetscReal *basisI = &TI->T[0][(r * NqI + q) * NbI * NcI]; 2389665f567fSMatthew G. Knepley const PetscReal *basisDerI = &TI->T[1][(r * NqI + q) * NbI * NcI * dE]; 2390665f567fSMatthew G. Knepley const PetscInt NqJ = TJ->Np; 2391665f567fSMatthew G. Knepley const PetscInt NbJ = TJ->Nb; 2392665f567fSMatthew G. Knepley const PetscInt NcJ = TJ->Nc; 2393665f567fSMatthew G. Knepley const PetscReal *basisJ = &TJ->T[0][(r * NqJ + q) * NbJ * NcJ]; 2394665f567fSMatthew G. Knepley const PetscReal *basisDerJ = &TJ->T[1][(r * NqJ + q) * NbJ * NcJ * dE]; 23955fedec97SMatthew G. Knepley const PetscInt so = isHybridI ? 0 : s; 23965fedec97SMatthew G. Knepley const PetscInt to = isHybridJ ? 0 : s; 23975fedec97SMatthew G. Knepley PetscInt f, fc, g, gc, df, dg; 239827f02ce8SMatthew G. Knepley 239927f02ce8SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 240027f02ce8SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 240127f02ce8SMatthew G. Knepley const PetscInt fidx = f * NcI + fc; /* Test function basis index */ 240227f02ce8SMatthew G. Knepley 240327f02ce8SMatthew G. Knepley tmpBasisI[fidx] = basisI[fidx]; 2404665f567fSMatthew G. Knepley for (df = 0; df < dE; ++df) tmpBasisDerI[fidx * dE + df] = basisDerI[fidx * dE + df]; 240527f02ce8SMatthew G. Knepley } 240627f02ce8SMatthew G. Knepley } 24079566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feI, fegeom, NbI, tmpBasisI)); 24089566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI)); 240927f02ce8SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 241027f02ce8SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 241127f02ce8SMatthew G. Knepley const PetscInt gidx = g * NcJ + gc; /* Trial function basis index */ 241227f02ce8SMatthew G. Knepley 241327f02ce8SMatthew G. Knepley tmpBasisJ[gidx] = basisJ[gidx]; 2414665f567fSMatthew G. Knepley for (dg = 0; dg < dE; ++dg) tmpBasisDerJ[gidx * dE + dg] = basisDerJ[gidx * dE + dg]; 241527f02ce8SMatthew G. Knepley } 241627f02ce8SMatthew G. Knepley } 24179566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ)); 24189566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ)); 241927f02ce8SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 242027f02ce8SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 242127f02ce8SMatthew G. Knepley const PetscInt fidx = f * NcI + fc; /* Test function basis index */ 24225fedec97SMatthew G. Knepley const PetscInt i = offsetI + NbI * so + f; /* Element matrix row */ 242327f02ce8SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 242427f02ce8SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 242527f02ce8SMatthew G. Knepley const PetscInt gidx = g * NcJ + gc; /* Trial function basis index */ 24265fedec97SMatthew G. Knepley const PetscInt j = offsetJ + NbJ * to + g; /* Element matrix column */ 242727f02ce8SMatthew G. Knepley const PetscInt fOff = eOffset + i * totDim + j; 242827f02ce8SMatthew G. Knepley 24295fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx] * g0[fc * NcJ + gc] * tmpBasisJ[gidx]; 243027f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) { 24315fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx] * g1[(fc * NcJ + gc) * dE + df] * tmpBasisDerJ[gidx * dE + df]; 24325fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx * dE + df] * g2[(fc * NcJ + gc) * dE + df] * tmpBasisJ[gidx]; 2433ad540459SPierre Jolivet for (dg = 0; dg < dE; ++dg) elemMat[fOff] += tmpBasisDerI[fidx * dE + df] * g3[((fc * NcJ + gc) * dE + df) * dE + dg] * tmpBasisDerJ[gidx * dE + dg]; 2434a8f1f9e5SMatthew G. Knepley } 2435a8f1f9e5SMatthew G. Knepley } 2436a8f1f9e5SMatthew G. Knepley } 2437a8f1f9e5SMatthew G. Knepley } 2438a8f1f9e5SMatthew G. Knepley } 2439a8f1f9e5SMatthew G. Knepley return (0); 2440a8f1f9e5SMatthew G. Knepley } 2441c9ba7969SMatthew G. Knepley 2442*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateCellGeometry(PetscFE fe, PetscQuadrature quad, PetscFEGeom *cgeom) 2443*d71ae5a4SJacob Faibussowitsch { 2444c9ba7969SMatthew G. Knepley PetscDualSpace dsp; 2445c9ba7969SMatthew G. Knepley DM dm; 2446c9ba7969SMatthew G. Knepley PetscQuadrature quadDef; 2447c9ba7969SMatthew G. Knepley PetscInt dim, cdim, Nq; 2448c9ba7969SMatthew G. Knepley 2449c9ba7969SMatthew G. Knepley PetscFunctionBegin; 24509566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &dsp)); 24519566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp, &dm)); 24529566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 24539566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDim(dm, &cdim)); 24549566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &quadDef)); 2455c9ba7969SMatthew G. Knepley quad = quad ? quad : quadDef; 24569566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(quad, NULL, NULL, &Nq, NULL, NULL)); 24579566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq * cdim, &cgeom->v)); 24589566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq * cdim * cdim, &cgeom->J)); 24599566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq * cdim * cdim, &cgeom->invJ)); 24609566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq, &cgeom->detJ)); 2461c9ba7969SMatthew G. Knepley cgeom->dim = dim; 2462c9ba7969SMatthew G. Knepley cgeom->dimEmbed = cdim; 2463c9ba7969SMatthew G. Knepley cgeom->numCells = 1; 2464c9ba7969SMatthew G. Knepley cgeom->numPoints = Nq; 24659566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm, 0, quad, cgeom->v, cgeom->J, cgeom->invJ, cgeom->detJ)); 2466c9ba7969SMatthew G. Knepley PetscFunctionReturn(0); 2467c9ba7969SMatthew G. Knepley } 2468c9ba7969SMatthew G. Knepley 2469*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEDestroyCellGeometry(PetscFE fe, PetscFEGeom *cgeom) 2470*d71ae5a4SJacob Faibussowitsch { 2471c9ba7969SMatthew G. Knepley PetscFunctionBegin; 24729566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->v)); 24739566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->J)); 24749566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->invJ)); 24759566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->detJ)); 2476c9ba7969SMatthew G. Knepley PetscFunctionReturn(0); 2477c9ba7969SMatthew G. Knepley } 2478