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 59dce8aebaSBarry Smith PetscFERegister - Adds a new `PetscFEType` 6020cf1dd8SToby Isaac 6120cf1dd8SToby Isaac Not Collective 6220cf1dd8SToby Isaac 6320cf1dd8SToby Isaac Input Parameters: 642fe279fdSBarry Smith + sname - The name of a new user-defined creation routine 652fe279fdSBarry Smith - function - The creation routine 6620cf1dd8SToby Isaac 6760225df5SJacob Faibussowitsch Example Usage: 6820cf1dd8SToby Isaac .vb 6920cf1dd8SToby Isaac PetscFERegister("my_fe", MyPetscFECreate); 7020cf1dd8SToby Isaac .ve 7120cf1dd8SToby Isaac 7220cf1dd8SToby Isaac Then, your PetscFE type can be chosen with the procedural interface via 7320cf1dd8SToby Isaac .vb 7420cf1dd8SToby Isaac PetscFECreate(MPI_Comm, PetscFE *); 7520cf1dd8SToby Isaac PetscFESetType(PetscFE, "my_fe"); 7620cf1dd8SToby Isaac .ve 7720cf1dd8SToby Isaac or at runtime via the option 7820cf1dd8SToby Isaac .vb 7920cf1dd8SToby Isaac -petscfe_type my_fe 8020cf1dd8SToby Isaac .ve 8120cf1dd8SToby Isaac 8220cf1dd8SToby Isaac Level: advanced 8320cf1dd8SToby Isaac 84dce8aebaSBarry Smith Note: 85dce8aebaSBarry Smith `PetscFERegister()` may be called multiple times to add several user-defined `PetscFE`s 8620cf1dd8SToby Isaac 87dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFEType`, `PetscFERegisterAll()`, `PetscFERegisterDestroy()` 8820cf1dd8SToby Isaac @*/ 89d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFERegister(const char sname[], PetscErrorCode (*function)(PetscFE)) 90d71ae5a4SJacob Faibussowitsch { 9120cf1dd8SToby Isaac PetscFunctionBegin; 929566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&PetscFEList, sname, function)); 933ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 9420cf1dd8SToby Isaac } 9520cf1dd8SToby Isaac 9620cf1dd8SToby Isaac /*@C 97dce8aebaSBarry Smith PetscFESetType - Builds a particular `PetscFE` 9820cf1dd8SToby Isaac 9920f4b53cSBarry Smith Collective 10020cf1dd8SToby Isaac 10120cf1dd8SToby Isaac Input Parameters: 102dce8aebaSBarry Smith + fem - The `PetscFE` object 10320cf1dd8SToby Isaac - name - The kind of FEM space 10420cf1dd8SToby Isaac 10520cf1dd8SToby Isaac Options Database Key: 10620f4b53cSBarry Smith . -petscfe_type <type> - Sets the `PetscFE` type; use -help for a list of available types 10720cf1dd8SToby Isaac 10820cf1dd8SToby Isaac Level: intermediate 10920cf1dd8SToby Isaac 110dce8aebaSBarry Smith .seealso: `PetscFEType`, `PetscFE`, `PetscFEGetType()`, `PetscFECreate()` 11120cf1dd8SToby Isaac @*/ 112d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetType(PetscFE fem, PetscFEType name) 113d71ae5a4SJacob Faibussowitsch { 11420cf1dd8SToby Isaac PetscErrorCode (*r)(PetscFE); 11520cf1dd8SToby Isaac PetscBool match; 11620cf1dd8SToby Isaac 11720cf1dd8SToby Isaac PetscFunctionBegin; 11820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 1199566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)fem, name, &match)); 1203ba16761SJacob Faibussowitsch if (match) PetscFunctionReturn(PETSC_SUCCESS); 12120cf1dd8SToby Isaac 1229566063dSJacob Faibussowitsch if (!PetscFERegisterAllCalled) PetscCall(PetscFERegisterAll()); 1239566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(PetscFEList, name, &r)); 12428b400f6SJacob Faibussowitsch PetscCheck(r, PetscObjectComm((PetscObject)fem), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscFE type: %s", name); 12520cf1dd8SToby Isaac 126dbbe0bcdSBarry Smith PetscTryTypeMethod(fem, destroy); 12720cf1dd8SToby Isaac fem->ops->destroy = NULL; 128dbbe0bcdSBarry Smith 1299566063dSJacob Faibussowitsch PetscCall((*r)(fem)); 1309566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)fem, name)); 1313ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 13220cf1dd8SToby Isaac } 13320cf1dd8SToby Isaac 13420cf1dd8SToby Isaac /*@C 135dce8aebaSBarry Smith PetscFEGetType - Gets the `PetscFEType` (as a string) from the `PetscFE` object. 13620cf1dd8SToby Isaac 13720cf1dd8SToby Isaac Not Collective 13820cf1dd8SToby Isaac 13920cf1dd8SToby Isaac Input Parameter: 140dce8aebaSBarry Smith . fem - The `PetscFE` 14120cf1dd8SToby Isaac 14220cf1dd8SToby Isaac Output Parameter: 143dce8aebaSBarry Smith . name - The `PetscFEType` name 14420cf1dd8SToby Isaac 14520cf1dd8SToby Isaac Level: intermediate 14620cf1dd8SToby Isaac 147dce8aebaSBarry Smith .seealso: `PetscFEType`, `PetscFE`, `PetscFESetType()`, `PetscFECreate()` 14820cf1dd8SToby Isaac @*/ 149d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetType(PetscFE fem, PetscFEType *name) 150d71ae5a4SJacob Faibussowitsch { 15120cf1dd8SToby Isaac PetscFunctionBegin; 15220cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 1534f572ea9SToby Isaac PetscAssertPointer(name, 2); 15448a46eb9SPierre Jolivet if (!PetscFERegisterAllCalled) PetscCall(PetscFERegisterAll()); 15520cf1dd8SToby Isaac *name = ((PetscObject)fem)->type_name; 1563ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 15720cf1dd8SToby Isaac } 15820cf1dd8SToby Isaac 15920cf1dd8SToby Isaac /*@C 160dce8aebaSBarry Smith PetscFEViewFromOptions - View from a `PetscFE` based on values in the options database 161fe2efc57SMark 16220f4b53cSBarry Smith Collective 163fe2efc57SMark 164fe2efc57SMark Input Parameters: 165dce8aebaSBarry Smith + A - the `PetscFE` object 166dce8aebaSBarry Smith . obj - Optional object that provides the options prefix 167dce8aebaSBarry Smith - name - command line option name 168fe2efc57SMark 169fe2efc57SMark Level: intermediate 170dce8aebaSBarry Smith 171dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFEView()`, `PetscObjectViewFromOptions()`, `PetscFECreate()` 172fe2efc57SMark @*/ 173d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEViewFromOptions(PetscFE A, PetscObject obj, const char name[]) 174d71ae5a4SJacob Faibussowitsch { 175fe2efc57SMark PetscFunctionBegin; 176fe2efc57SMark PetscValidHeaderSpecific(A, PETSCFE_CLASSID, 1); 1779566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name)); 1783ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 179fe2efc57SMark } 180fe2efc57SMark 181fe2efc57SMark /*@C 182dce8aebaSBarry Smith PetscFEView - Views a `PetscFE` 18320cf1dd8SToby Isaac 18420f4b53cSBarry Smith Collective 18520cf1dd8SToby Isaac 186d8d19677SJose E. Roman Input Parameters: 187dce8aebaSBarry Smith + fem - the `PetscFE` object to view 188d9bac1caSLisandro Dalcin - viewer - the viewer 18920cf1dd8SToby Isaac 1902b99622eSMatthew G. Knepley Level: beginner 19120cf1dd8SToby Isaac 192dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscViewer`, `PetscFEDestroy()`, `PetscFEViewFromOptions()` 19320cf1dd8SToby Isaac @*/ 194d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEView(PetscFE fem, PetscViewer viewer) 195d71ae5a4SJacob 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); 2053ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 20620cf1dd8SToby Isaac } 20720cf1dd8SToby Isaac 20820cf1dd8SToby Isaac /*@ 209dce8aebaSBarry Smith PetscFESetFromOptions - sets parameters in a `PetscFE` from the options database 21020cf1dd8SToby Isaac 21120f4b53cSBarry Smith Collective 21220cf1dd8SToby Isaac 21320cf1dd8SToby Isaac Input Parameter: 214dce8aebaSBarry Smith . fem - the `PetscFE` object to set options for 21520cf1dd8SToby Isaac 216dce8aebaSBarry Smith Options Database Keys: 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 222dce8aebaSBarry Smith .seealso: `PetscFEV`, `PetscFEView()` 22320cf1dd8SToby Isaac @*/ 224d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetFromOptions(PetscFE fem) 225d71ae5a4SJacob 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")); 2533ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 25420cf1dd8SToby Isaac } 25520cf1dd8SToby Isaac 25620cf1dd8SToby Isaac /*@C 257dce8aebaSBarry Smith PetscFESetUp - Construct data structures for the `PetscFE` after the `PetscFEType` has been set 25820cf1dd8SToby Isaac 25920f4b53cSBarry Smith Collective 26020cf1dd8SToby Isaac 26120cf1dd8SToby Isaac Input Parameter: 262dce8aebaSBarry Smith . fem - the `PetscFE` object to setup 26320cf1dd8SToby Isaac 2642b99622eSMatthew G. Knepley Level: intermediate 26520cf1dd8SToby Isaac 266dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFEView()`, `PetscFEDestroy()` 26720cf1dd8SToby Isaac @*/ 268d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetUp(PetscFE fem) 269d71ae5a4SJacob Faibussowitsch { 27020cf1dd8SToby Isaac PetscFunctionBegin; 27120cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 2723ba16761SJacob Faibussowitsch if (fem->setupcalled) PetscFunctionReturn(PETSC_SUCCESS); 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)); 2773ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 27820cf1dd8SToby Isaac } 27920cf1dd8SToby Isaac 28020cf1dd8SToby Isaac /*@ 281dce8aebaSBarry Smith PetscFEDestroy - Destroys a `PetscFE` object 28220cf1dd8SToby Isaac 28320f4b53cSBarry Smith Collective 28420cf1dd8SToby Isaac 28520cf1dd8SToby Isaac Input Parameter: 286dce8aebaSBarry Smith . fem - the `PetscFE` object to destroy 28720cf1dd8SToby Isaac 2882b99622eSMatthew G. Knepley Level: beginner 28920cf1dd8SToby Isaac 290dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFEView()` 29120cf1dd8SToby Isaac @*/ 292d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEDestroy(PetscFE *fem) 293d71ae5a4SJacob Faibussowitsch { 29420cf1dd8SToby Isaac PetscFunctionBegin; 2953ba16761SJacob Faibussowitsch if (!*fem) PetscFunctionReturn(PETSC_SUCCESS); 29620cf1dd8SToby Isaac PetscValidHeaderSpecific((*fem), PETSCFE_CLASSID, 1); 29720cf1dd8SToby Isaac 2989371c9d4SSatish Balay if (--((PetscObject)(*fem))->refct > 0) { 2999371c9d4SSatish Balay *fem = NULL; 3003ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 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)); 3263ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 32720cf1dd8SToby Isaac } 32820cf1dd8SToby Isaac 32920cf1dd8SToby Isaac /*@ 330dce8aebaSBarry Smith 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: 335dce8aebaSBarry Smith . comm - The communicator for the `PetscFE` object 33620cf1dd8SToby Isaac 33720cf1dd8SToby Isaac Output Parameter: 338dce8aebaSBarry Smith . fem - The `PetscFE` object 33920cf1dd8SToby Isaac 34020cf1dd8SToby Isaac Level: beginner 34120cf1dd8SToby Isaac 342a01caf64Smarkadams4 .seealso: `PetscFE`, `PetscFEType`, `PetscFESetType()`, `PetscFECreateDefault()`, `PETSCFEGALERKIN` 34320cf1dd8SToby Isaac @*/ 344d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreate(MPI_Comm comm, PetscFE *fem) 345d71ae5a4SJacob Faibussowitsch { 34620cf1dd8SToby Isaac PetscFE f; 34720cf1dd8SToby Isaac 34820cf1dd8SToby Isaac PetscFunctionBegin; 3494f572ea9SToby Isaac PetscAssertPointer(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; 3723ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 37320cf1dd8SToby Isaac } 37420cf1dd8SToby Isaac 37520cf1dd8SToby Isaac /*@ 37620cf1dd8SToby Isaac PetscFEGetSpatialDimension - Returns the spatial dimension of the element 37720cf1dd8SToby Isaac 37820f4b53cSBarry Smith Not Collective 37920cf1dd8SToby Isaac 38020cf1dd8SToby Isaac Input Parameter: 381dce8aebaSBarry Smith . fem - The `PetscFE` object 38220cf1dd8SToby Isaac 38320cf1dd8SToby Isaac Output Parameter: 38420cf1dd8SToby Isaac . dim - The spatial dimension 38520cf1dd8SToby Isaac 38620cf1dd8SToby Isaac Level: intermediate 38720cf1dd8SToby Isaac 388dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFECreate()` 38920cf1dd8SToby Isaac @*/ 390d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetSpatialDimension(PetscFE fem, PetscInt *dim) 391d71ae5a4SJacob Faibussowitsch { 39220cf1dd8SToby Isaac DM dm; 39320cf1dd8SToby Isaac 39420cf1dd8SToby Isaac PetscFunctionBegin; 39520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 3964f572ea9SToby Isaac PetscAssertPointer(dim, 2); 3979566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(fem->dualSpace, &dm)); 3989566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, dim)); 3993ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 40020cf1dd8SToby Isaac } 40120cf1dd8SToby Isaac 40220cf1dd8SToby Isaac /*@ 403dce8aebaSBarry Smith PetscFESetNumComponents - Sets the number of field components in the element 40420cf1dd8SToby Isaac 40520f4b53cSBarry Smith Not Collective 40620cf1dd8SToby Isaac 40720cf1dd8SToby Isaac Input Parameters: 408dce8aebaSBarry Smith + fem - The `PetscFE` object 40920cf1dd8SToby Isaac - comp - The number of field components 41020cf1dd8SToby Isaac 41120cf1dd8SToby Isaac Level: intermediate 41220cf1dd8SToby Isaac 413dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFECreate()`, `PetscFEGetSpatialDimension()`, `PetscFEGetNumComponents()` 41420cf1dd8SToby Isaac @*/ 415d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetNumComponents(PetscFE fem, PetscInt comp) 416d71ae5a4SJacob Faibussowitsch { 41720cf1dd8SToby Isaac PetscFunctionBegin; 41820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 41920cf1dd8SToby Isaac fem->numComponents = comp; 4203ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 42120cf1dd8SToby Isaac } 42220cf1dd8SToby Isaac 42320cf1dd8SToby Isaac /*@ 42420cf1dd8SToby Isaac PetscFEGetNumComponents - Returns the number of components in the element 42520cf1dd8SToby Isaac 42620f4b53cSBarry Smith Not Collective 42720cf1dd8SToby Isaac 42820cf1dd8SToby Isaac Input Parameter: 429dce8aebaSBarry Smith . 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 43642747ad1SJacob Faibussowitsch .seealso: `PetscFE`, `PetscFECreate()`, `PetscFEGetSpatialDimension()` 43720cf1dd8SToby Isaac @*/ 438d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetNumComponents(PetscFE fem, PetscInt *comp) 439d71ae5a4SJacob Faibussowitsch { 44020cf1dd8SToby Isaac PetscFunctionBegin; 44120cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 4424f572ea9SToby Isaac PetscAssertPointer(comp, 2); 44320cf1dd8SToby Isaac *comp = fem->numComponents; 4443ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 44520cf1dd8SToby Isaac } 44620cf1dd8SToby Isaac 44720cf1dd8SToby Isaac /*@ 44820cf1dd8SToby Isaac PetscFESetTileSizes - Sets the tile sizes for evaluation 44920cf1dd8SToby Isaac 45020f4b53cSBarry Smith Not Collective 45120cf1dd8SToby Isaac 45220cf1dd8SToby Isaac Input Parameters: 453dce8aebaSBarry Smith + 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 461dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFECreate()`, `PetscFEGetTileSizes()` 46220cf1dd8SToby Isaac @*/ 463d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetTileSizes(PetscFE fem, PetscInt blockSize, PetscInt numBlocks, PetscInt batchSize, PetscInt numBatches) 464d71ae5a4SJacob 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; 4713ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 47220cf1dd8SToby Isaac } 47320cf1dd8SToby Isaac 47420cf1dd8SToby Isaac /*@ 47520cf1dd8SToby Isaac PetscFEGetTileSizes - Returns the tile sizes for evaluation 47620cf1dd8SToby Isaac 47720f4b53cSBarry Smith Not Collective 47820cf1dd8SToby Isaac 47920cf1dd8SToby Isaac Input Parameter: 480dce8aebaSBarry Smith . 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 490dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFECreate()`, `PetscFESetTileSizes()` 49120cf1dd8SToby Isaac @*/ 492d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetTileSizes(PetscFE fem, PetscInt *blockSize, PetscInt *numBlocks, PetscInt *batchSize, PetscInt *numBatches) 493d71ae5a4SJacob Faibussowitsch { 49420cf1dd8SToby Isaac PetscFunctionBegin; 49520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 4964f572ea9SToby Isaac if (blockSize) PetscAssertPointer(blockSize, 2); 4974f572ea9SToby Isaac if (numBlocks) PetscAssertPointer(numBlocks, 3); 4984f572ea9SToby Isaac if (batchSize) PetscAssertPointer(batchSize, 4); 4994f572ea9SToby Isaac if (numBatches) PetscAssertPointer(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; 5043ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 50520cf1dd8SToby Isaac } 50620cf1dd8SToby Isaac 50720cf1dd8SToby Isaac /*@ 508dce8aebaSBarry Smith PetscFEGetBasisSpace - Returns the `PetscSpace` used for the approximation of the solution for the `PetscFE` 50920cf1dd8SToby Isaac 51020f4b53cSBarry Smith Not Collective 51120cf1dd8SToby Isaac 51220cf1dd8SToby Isaac Input Parameter: 513dce8aebaSBarry Smith . fem - The `PetscFE` object 51420cf1dd8SToby Isaac 51520cf1dd8SToby Isaac Output Parameter: 516dce8aebaSBarry Smith . sp - The `PetscSpace` object 51720cf1dd8SToby Isaac 51820cf1dd8SToby Isaac Level: intermediate 51920cf1dd8SToby Isaac 520dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscFECreate()` 52120cf1dd8SToby Isaac @*/ 522d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetBasisSpace(PetscFE fem, PetscSpace *sp) 523d71ae5a4SJacob Faibussowitsch { 52420cf1dd8SToby Isaac PetscFunctionBegin; 52520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 5264f572ea9SToby Isaac PetscAssertPointer(sp, 2); 52720cf1dd8SToby Isaac *sp = fem->basisSpace; 5283ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 52920cf1dd8SToby Isaac } 53020cf1dd8SToby Isaac 53120cf1dd8SToby Isaac /*@ 532dce8aebaSBarry Smith PetscFESetBasisSpace - Sets the `PetscSpace` used for the approximation of the solution 53320cf1dd8SToby Isaac 53420f4b53cSBarry Smith Not Collective 53520cf1dd8SToby Isaac 53620cf1dd8SToby Isaac Input Parameters: 537dce8aebaSBarry Smith + fem - The `PetscFE` object 538dce8aebaSBarry Smith - sp - The `PetscSpace` object 53920cf1dd8SToby Isaac 54020cf1dd8SToby Isaac Level: intermediate 54120cf1dd8SToby Isaac 54260225df5SJacob Faibussowitsch Developer Notes: 543dce8aebaSBarry Smith There is `PetscFESetBasisSpace()` but the `PetscFESetDualSpace()`, likely the Basis is unneeded in the function name 544dce8aebaSBarry Smith 545dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscFECreate()`, `PetscFESetDualSpace()` 54620cf1dd8SToby Isaac @*/ 547d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetBasisSpace(PetscFE fem, PetscSpace sp) 548d71ae5a4SJacob Faibussowitsch { 54920cf1dd8SToby Isaac PetscFunctionBegin; 55020cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 55120cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 2); 5529566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&fem->basisSpace)); 55320cf1dd8SToby Isaac fem->basisSpace = sp; 5549566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)fem->basisSpace)); 5553ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 55620cf1dd8SToby Isaac } 55720cf1dd8SToby Isaac 55820cf1dd8SToby Isaac /*@ 559dce8aebaSBarry Smith PetscFEGetDualSpace - Returns the `PetscDualSpace` used to define the inner product for a `PetscFE` 56020cf1dd8SToby Isaac 56120f4b53cSBarry Smith Not Collective 56220cf1dd8SToby Isaac 56320cf1dd8SToby Isaac Input Parameter: 564dce8aebaSBarry Smith . fem - The `PetscFE` object 56520cf1dd8SToby Isaac 56620cf1dd8SToby Isaac Output Parameter: 567dce8aebaSBarry Smith . sp - The `PetscDualSpace` object 56820cf1dd8SToby Isaac 56920cf1dd8SToby Isaac Level: intermediate 57020cf1dd8SToby Isaac 571dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscFECreate()` 57220cf1dd8SToby Isaac @*/ 573d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetDualSpace(PetscFE fem, PetscDualSpace *sp) 574d71ae5a4SJacob Faibussowitsch { 57520cf1dd8SToby Isaac PetscFunctionBegin; 57620cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 5774f572ea9SToby Isaac PetscAssertPointer(sp, 2); 57820cf1dd8SToby Isaac *sp = fem->dualSpace; 5793ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 58020cf1dd8SToby Isaac } 58120cf1dd8SToby Isaac 58220cf1dd8SToby Isaac /*@ 583dce8aebaSBarry Smith PetscFESetDualSpace - Sets the `PetscDualSpace` used to define the inner product 58420cf1dd8SToby Isaac 58520f4b53cSBarry Smith Not Collective 58620cf1dd8SToby Isaac 58720cf1dd8SToby Isaac Input Parameters: 588dce8aebaSBarry Smith + fem - The `PetscFE` object 589dce8aebaSBarry Smith - sp - The `PetscDualSpace` object 59020cf1dd8SToby Isaac 59120cf1dd8SToby Isaac Level: intermediate 59220cf1dd8SToby Isaac 593dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscFECreate()`, `PetscFESetBasisSpace()` 59420cf1dd8SToby Isaac @*/ 595d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetDualSpace(PetscFE fem, PetscDualSpace sp) 596d71ae5a4SJacob Faibussowitsch { 59720cf1dd8SToby Isaac PetscFunctionBegin; 59820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 59920cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 2); 6009566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&fem->dualSpace)); 60120cf1dd8SToby Isaac fem->dualSpace = sp; 6029566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)fem->dualSpace)); 6033ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 60420cf1dd8SToby Isaac } 60520cf1dd8SToby Isaac 60620cf1dd8SToby Isaac /*@ 607dce8aebaSBarry Smith PetscFEGetQuadrature - Returns the `PetscQuadrature` used to calculate inner products 60820cf1dd8SToby Isaac 60920f4b53cSBarry Smith Not Collective 61020cf1dd8SToby Isaac 61120cf1dd8SToby Isaac Input Parameter: 612dce8aebaSBarry Smith . fem - The `PetscFE` object 61320cf1dd8SToby Isaac 61420cf1dd8SToby Isaac Output Parameter: 615dce8aebaSBarry Smith . q - The `PetscQuadrature` object 61620cf1dd8SToby Isaac 61720cf1dd8SToby Isaac Level: intermediate 61820cf1dd8SToby Isaac 619dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscQuadrature`, `PetscFECreate()` 62020cf1dd8SToby Isaac @*/ 621d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetQuadrature(PetscFE fem, PetscQuadrature *q) 622d71ae5a4SJacob Faibussowitsch { 62320cf1dd8SToby Isaac PetscFunctionBegin; 62420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 6254f572ea9SToby Isaac PetscAssertPointer(q, 2); 62620cf1dd8SToby Isaac *q = fem->quadrature; 6273ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 62820cf1dd8SToby Isaac } 62920cf1dd8SToby Isaac 63020cf1dd8SToby Isaac /*@ 631dce8aebaSBarry Smith PetscFESetQuadrature - Sets the `PetscQuadrature` used to calculate inner products 63220cf1dd8SToby Isaac 63320f4b53cSBarry Smith Not Collective 63420cf1dd8SToby Isaac 63520cf1dd8SToby Isaac Input Parameters: 636dce8aebaSBarry Smith + fem - The `PetscFE` object 637dce8aebaSBarry Smith - q - The `PetscQuadrature` object 63820cf1dd8SToby Isaac 63920cf1dd8SToby Isaac Level: intermediate 64020cf1dd8SToby Isaac 641dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscQuadrature`, `PetscFECreate()`, `PetscFEGetFaceQuadrature()` 64220cf1dd8SToby Isaac @*/ 643d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetQuadrature(PetscFE fem, PetscQuadrature q) 644d71ae5a4SJacob Faibussowitsch { 64520cf1dd8SToby Isaac PetscInt Nc, qNc; 64620cf1dd8SToby Isaac 64720cf1dd8SToby Isaac PetscFunctionBegin; 64820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 6493ba16761SJacob Faibussowitsch if (q == fem->quadrature) PetscFunctionReturn(PETSC_SUCCESS); 6509566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 6519566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetNumComponents(q, &qNc)); 65263a3b9bcSJacob 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); 6539566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&fem->T)); 6549566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&fem->Tc)); 6559566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)q)); 6569566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&fem->quadrature)); 65720cf1dd8SToby Isaac fem->quadrature = q; 6583ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 65920cf1dd8SToby Isaac } 66020cf1dd8SToby Isaac 66120cf1dd8SToby Isaac /*@ 662dce8aebaSBarry Smith PetscFEGetFaceQuadrature - Returns the `PetscQuadrature` used to calculate inner products on faces 66320cf1dd8SToby Isaac 66420f4b53cSBarry Smith Not Collective 66520cf1dd8SToby Isaac 66620cf1dd8SToby Isaac Input Parameter: 667dce8aebaSBarry Smith . fem - The `PetscFE` object 66820cf1dd8SToby Isaac 66920cf1dd8SToby Isaac Output Parameter: 670dce8aebaSBarry Smith . q - The `PetscQuadrature` object 67120cf1dd8SToby Isaac 67220cf1dd8SToby Isaac Level: intermediate 67320cf1dd8SToby Isaac 67460225df5SJacob Faibussowitsch Developer Notes: 67535cb6cd3SPierre Jolivet There is a special face quadrature but not edge, likely this API would benefit from a refactorization 676dce8aebaSBarry Smith 677dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscQuadrature`, `PetscFECreate()`, `PetscFESetQuadrature()`, `PetscFESetFaceQuadrature()` 67820cf1dd8SToby Isaac @*/ 679d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetFaceQuadrature(PetscFE fem, PetscQuadrature *q) 680d71ae5a4SJacob Faibussowitsch { 68120cf1dd8SToby Isaac PetscFunctionBegin; 68220cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 6834f572ea9SToby Isaac PetscAssertPointer(q, 2); 68420cf1dd8SToby Isaac *q = fem->faceQuadrature; 6853ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 68620cf1dd8SToby Isaac } 68720cf1dd8SToby Isaac 68820cf1dd8SToby Isaac /*@ 689dce8aebaSBarry Smith PetscFESetFaceQuadrature - Sets the `PetscQuadrature` used to calculate inner products on faces 69020cf1dd8SToby Isaac 69120f4b53cSBarry Smith Not Collective 69220cf1dd8SToby Isaac 69320cf1dd8SToby Isaac Input Parameters: 694dce8aebaSBarry Smith + fem - The `PetscFE` object 695dce8aebaSBarry Smith - q - The `PetscQuadrature` object 69620cf1dd8SToby Isaac 69720cf1dd8SToby Isaac Level: intermediate 69820cf1dd8SToby Isaac 69942747ad1SJacob Faibussowitsch .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscQuadrature`, `PetscFECreate()`, `PetscFESetQuadrature()` 70020cf1dd8SToby Isaac @*/ 701d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetFaceQuadrature(PetscFE fem, PetscQuadrature q) 702d71ae5a4SJacob Faibussowitsch { 703ef0bb6c7SMatthew G. Knepley PetscInt Nc, qNc; 70420cf1dd8SToby Isaac 70520cf1dd8SToby Isaac PetscFunctionBegin; 70620cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 70726add6b9SMatthew G. Knepley if (q == fem->faceQuadrature) PetscFunctionReturn(PETSC_SUCCESS); 7089566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 7099566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetNumComponents(q, &qNc)); 71063a3b9bcSJacob 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); 7119566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&fem->Tf)); 71226add6b9SMatthew G. Knepley PetscCall(PetscObjectReference((PetscObject)q)); 7139566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&fem->faceQuadrature)); 71420cf1dd8SToby Isaac fem->faceQuadrature = q; 7153ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 71620cf1dd8SToby Isaac } 71720cf1dd8SToby Isaac 7185dc5c000SMatthew G. Knepley /*@ 719dce8aebaSBarry Smith PetscFECopyQuadrature - Copy both volumetric and surface quadrature to a new `PetscFE` 7205dc5c000SMatthew G. Knepley 72120f4b53cSBarry Smith Not Collective 7225dc5c000SMatthew G. Knepley 7235dc5c000SMatthew G. Knepley Input Parameters: 724dce8aebaSBarry Smith + sfe - The `PetscFE` source for the quadratures 725dce8aebaSBarry Smith - tfe - The `PetscFE` target for the quadratures 7265dc5c000SMatthew G. Knepley 7275dc5c000SMatthew G. Knepley Level: intermediate 7285dc5c000SMatthew G. Knepley 729dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscQuadrature`, `PetscFECreate()`, `PetscFESetQuadrature()`, `PetscFESetFaceQuadrature()` 7305dc5c000SMatthew G. Knepley @*/ 731d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECopyQuadrature(PetscFE sfe, PetscFE tfe) 732d71ae5a4SJacob Faibussowitsch { 7335dc5c000SMatthew G. Knepley PetscQuadrature q; 7345dc5c000SMatthew G. Knepley 7355dc5c000SMatthew G. Knepley PetscFunctionBegin; 7365dc5c000SMatthew G. Knepley PetscValidHeaderSpecific(sfe, PETSCFE_CLASSID, 1); 7375dc5c000SMatthew G. Knepley PetscValidHeaderSpecific(tfe, PETSCFE_CLASSID, 2); 7389566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(sfe, &q)); 7399566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(tfe, q)); 7409566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(sfe, &q)); 7419566063dSJacob Faibussowitsch PetscCall(PetscFESetFaceQuadrature(tfe, q)); 7423ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 7435dc5c000SMatthew G. Knepley } 7445dc5c000SMatthew G. Knepley 74520cf1dd8SToby Isaac /*@C 74620cf1dd8SToby Isaac PetscFEGetNumDof - Returns the number of dofs (dual basis vectors) associated to mesh points on the reference cell of a given dimension 74720cf1dd8SToby Isaac 74820f4b53cSBarry Smith Not Collective 74920cf1dd8SToby Isaac 75020cf1dd8SToby Isaac Input Parameter: 751dce8aebaSBarry Smith . fem - The `PetscFE` object 75220cf1dd8SToby Isaac 75320cf1dd8SToby Isaac Output Parameter: 75420cf1dd8SToby Isaac . numDof - Array with the number of dofs per dimension 75520cf1dd8SToby Isaac 75620cf1dd8SToby Isaac Level: intermediate 75720cf1dd8SToby Isaac 758dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscFECreate()` 75920cf1dd8SToby Isaac @*/ 760d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetNumDof(PetscFE fem, const PetscInt **numDof) 761d71ae5a4SJacob Faibussowitsch { 76220cf1dd8SToby Isaac PetscFunctionBegin; 76320cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 7644f572ea9SToby Isaac PetscAssertPointer(numDof, 2); 7659566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetNumDof(fem->dualSpace, numDof)); 7663ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 76720cf1dd8SToby Isaac } 76820cf1dd8SToby Isaac 76920cf1dd8SToby Isaac /*@C 770ef0bb6c7SMatthew G. Knepley PetscFEGetCellTabulation - Returns the tabulation of the basis functions at the quadrature points on the reference cell 77120cf1dd8SToby Isaac 77220f4b53cSBarry Smith Not Collective 77320cf1dd8SToby Isaac 774d8d19677SJose E. Roman Input Parameters: 775dce8aebaSBarry Smith + fem - The `PetscFE` object 776f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate, very often 1 77720cf1dd8SToby Isaac 778ef0bb6c7SMatthew G. Knepley Output Parameter: 779ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at quadrature points 78020cf1dd8SToby Isaac 78120cf1dd8SToby Isaac Level: intermediate 78220cf1dd8SToby Isaac 783dce8aebaSBarry Smith Note: 784dce8aebaSBarry Smith .vb 785dce8aebaSBarry Smith T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 786dce8aebaSBarry Smith 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 787dce8aebaSBarry Smith 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 788dce8aebaSBarry Smith .ve 789dce8aebaSBarry Smith 790dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscTabulation`, `PetscFECreateTabulation()`, `PetscTabulationDestroy()` 79120cf1dd8SToby Isaac @*/ 792d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetCellTabulation(PetscFE fem, PetscInt k, PetscTabulation *T) 793d71ae5a4SJacob Faibussowitsch { 79420cf1dd8SToby Isaac PetscInt npoints; 79520cf1dd8SToby Isaac const PetscReal *points; 79620cf1dd8SToby Isaac 79720cf1dd8SToby Isaac PetscFunctionBegin; 79820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 7994f572ea9SToby Isaac PetscAssertPointer(T, 3); 8009566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(fem->quadrature, NULL, NULL, &npoints, &points, NULL)); 8019566063dSJacob Faibussowitsch if (!fem->T) PetscCall(PetscFECreateTabulation(fem, 1, npoints, points, k, &fem->T)); 802aa9788aaSMatthew G. Knepley PetscCheck(!fem->T || k <= fem->T->K || (!fem->T->cdim && !fem->T->K), PetscObjectComm((PetscObject)fem), PETSC_ERR_ARG_OUTOFRANGE, "Requested %" PetscInt_FMT " derivatives, but only tabulated %" PetscInt_FMT, k, fem->T->K); 803ef0bb6c7SMatthew G. Knepley *T = fem->T; 8043ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 80520cf1dd8SToby Isaac } 80620cf1dd8SToby Isaac 8072b99622eSMatthew G. Knepley /*@C 808ef0bb6c7SMatthew G. Knepley PetscFEGetFaceTabulation - Returns the tabulation of the basis functions at the face quadrature points for each face of the reference cell 8092b99622eSMatthew G. Knepley 81020f4b53cSBarry Smith Not Collective 8112b99622eSMatthew G. Knepley 812d8d19677SJose E. Roman Input Parameters: 813dce8aebaSBarry Smith + fem - The `PetscFE` object 814f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate, very often 1 8152b99622eSMatthew G. Knepley 8162fe279fdSBarry Smith Output Parameter: 817a5b23f4aSJose E. Roman . Tf - The basis function values and derivatives at face quadrature points 8182b99622eSMatthew G. Knepley 8192b99622eSMatthew G. Knepley Level: intermediate 8202b99622eSMatthew G. Knepley 821dce8aebaSBarry Smith Note: 822dce8aebaSBarry Smith .vb 823dce8aebaSBarry Smith 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 824dce8aebaSBarry Smith 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 825dce8aebaSBarry Smith 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 826dce8aebaSBarry Smith .ve 827dce8aebaSBarry Smith 828dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscTabulation`, `PetscFEGetCellTabulation()`, `PetscFECreateTabulation()`, `PetscTabulationDestroy()` 8292b99622eSMatthew G. Knepley @*/ 830d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetFaceTabulation(PetscFE fem, PetscInt k, PetscTabulation *Tf) 831d71ae5a4SJacob Faibussowitsch { 83220cf1dd8SToby Isaac PetscFunctionBegin; 83320cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 8344f572ea9SToby Isaac PetscAssertPointer(Tf, 3); 835ef0bb6c7SMatthew G. Knepley if (!fem->Tf) { 83620cf1dd8SToby Isaac const PetscReal xi0[3] = {-1., -1., -1.}; 83720cf1dd8SToby Isaac PetscReal v0[3], J[9], detJ; 83820cf1dd8SToby Isaac PetscQuadrature fq; 83920cf1dd8SToby Isaac PetscDualSpace sp; 84020cf1dd8SToby Isaac DM dm; 84120cf1dd8SToby Isaac const PetscInt *faces; 84220cf1dd8SToby Isaac PetscInt dim, numFaces, f, npoints, q; 84320cf1dd8SToby Isaac const PetscReal *points; 84420cf1dd8SToby Isaac PetscReal *facePoints; 84520cf1dd8SToby Isaac 8469566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &sp)); 8479566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(sp, &dm)); 8489566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 8499566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, 0, &numFaces)); 8509566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(dm, 0, &faces)); 8519566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(fem, &fq)); 85220cf1dd8SToby Isaac if (fq) { 8539566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(fq, NULL, NULL, &npoints, &points, NULL)); 8549566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numFaces * npoints * dim, &facePoints)); 85520cf1dd8SToby Isaac for (f = 0; f < numFaces; ++f) { 8569566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm, faces[f], NULL, v0, J, NULL, &detJ)); 85720cf1dd8SToby Isaac for (q = 0; q < npoints; ++q) CoordinatesRefToReal(dim, dim - 1, xi0, v0, J, &points[q * (dim - 1)], &facePoints[(f * npoints + q) * dim]); 85820cf1dd8SToby Isaac } 8599566063dSJacob Faibussowitsch PetscCall(PetscFECreateTabulation(fem, numFaces, npoints, facePoints, k, &fem->Tf)); 8609566063dSJacob Faibussowitsch PetscCall(PetscFree(facePoints)); 86120cf1dd8SToby Isaac } 86220cf1dd8SToby Isaac } 8631dca8a05SBarry 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); 864ef0bb6c7SMatthew G. Knepley *Tf = fem->Tf; 8653ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 86620cf1dd8SToby Isaac } 86720cf1dd8SToby Isaac 8682b99622eSMatthew G. Knepley /*@C 869ef0bb6c7SMatthew G. Knepley PetscFEGetFaceCentroidTabulation - Returns the tabulation of the basis functions at the face centroid points 8702b99622eSMatthew G. Knepley 87120f4b53cSBarry Smith Not Collective 8722b99622eSMatthew G. Knepley 8732b99622eSMatthew G. Knepley Input Parameter: 874dce8aebaSBarry Smith . fem - The `PetscFE` object 8752b99622eSMatthew G. Knepley 8762fe279fdSBarry Smith Output Parameter: 877ef0bb6c7SMatthew G. Knepley . Tc - The basis function values at face centroid points 8782b99622eSMatthew G. Knepley 8792b99622eSMatthew G. Knepley Level: intermediate 8802b99622eSMatthew G. Knepley 881dce8aebaSBarry Smith Note: 882dce8aebaSBarry Smith .vb 883dce8aebaSBarry Smith T->T[0] = Bf[(f*pdim + i)*Nc + c] is the value at point f for basis function i and component c 884dce8aebaSBarry Smith .ve 885dce8aebaSBarry Smith 886dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscTabulation`, `PetscFEGetFaceTabulation()`, `PetscFEGetCellTabulation()`, `PetscFECreateTabulation()`, `PetscTabulationDestroy()` 8872b99622eSMatthew G. Knepley @*/ 888d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetFaceCentroidTabulation(PetscFE fem, PetscTabulation *Tc) 889d71ae5a4SJacob Faibussowitsch { 89020cf1dd8SToby Isaac PetscFunctionBegin; 89120cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 8924f572ea9SToby Isaac PetscAssertPointer(Tc, 2); 893ef0bb6c7SMatthew G. Knepley if (!fem->Tc) { 89420cf1dd8SToby Isaac PetscDualSpace sp; 89520cf1dd8SToby Isaac DM dm; 89620cf1dd8SToby Isaac const PetscInt *cone; 89720cf1dd8SToby Isaac PetscReal *centroids; 89820cf1dd8SToby Isaac PetscInt dim, numFaces, f; 89920cf1dd8SToby Isaac 9009566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &sp)); 9019566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(sp, &dm)); 9029566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 9039566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, 0, &numFaces)); 9049566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(dm, 0, &cone)); 9059566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numFaces * dim, ¢roids)); 9069566063dSJacob Faibussowitsch for (f = 0; f < numFaces; ++f) PetscCall(DMPlexComputeCellGeometryFVM(dm, cone[f], NULL, ¢roids[f * dim], NULL)); 9079566063dSJacob Faibussowitsch PetscCall(PetscFECreateTabulation(fem, 1, numFaces, centroids, 0, &fem->Tc)); 9089566063dSJacob Faibussowitsch PetscCall(PetscFree(centroids)); 90920cf1dd8SToby Isaac } 910ef0bb6c7SMatthew G. Knepley *Tc = fem->Tc; 9113ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 91220cf1dd8SToby Isaac } 91320cf1dd8SToby Isaac 91420cf1dd8SToby Isaac /*@C 915ef0bb6c7SMatthew G. Knepley PetscFECreateTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided. 91620cf1dd8SToby Isaac 91720f4b53cSBarry Smith Not Collective 91820cf1dd8SToby Isaac 91920cf1dd8SToby Isaac Input Parameters: 920dce8aebaSBarry Smith + fem - The `PetscFE` object 921ef0bb6c7SMatthew G. Knepley . nrepl - The number of replicas 922ef0bb6c7SMatthew G. Knepley . npoints - The number of tabulation points in a replica 923ef0bb6c7SMatthew G. Knepley . points - The tabulation point coordinates 924ef0bb6c7SMatthew G. Knepley - K - The number of derivatives calculated 92520cf1dd8SToby Isaac 926ef0bb6c7SMatthew G. Knepley Output Parameter: 927ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at tabulation points 92820cf1dd8SToby Isaac 92920cf1dd8SToby Isaac Level: intermediate 93020cf1dd8SToby Isaac 931dce8aebaSBarry Smith Note: 932dce8aebaSBarry Smith .vb 933dce8aebaSBarry Smith T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 934dce8aebaSBarry Smith 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 935a4e35b19SJacob Faibussowitsch T->T[2] = H[(((p*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point p for basis 936a4e35b19SJacob Faibussowitsch T->function i, component c, in directions d and e 937a4e35b19SJacob Faibussowitsch .ve 938dce8aebaSBarry Smith 939dce8aebaSBarry Smith .seealso: `PetscTabulation`, `PetscFEGetCellTabulation()`, `PetscTabulationDestroy()` 94020cf1dd8SToby Isaac @*/ 941d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateTabulation(PetscFE fem, PetscInt nrepl, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation *T) 942d71ae5a4SJacob Faibussowitsch { 94320cf1dd8SToby Isaac DM dm; 944ef0bb6c7SMatthew G. Knepley PetscDualSpace Q; 945ef0bb6c7SMatthew G. Knepley PetscInt Nb; /* Dimension of FE space P */ 946ef0bb6c7SMatthew G. Knepley PetscInt Nc; /* Field components */ 947ef0bb6c7SMatthew G. Knepley PetscInt cdim; /* Reference coordinate dimension */ 948ef0bb6c7SMatthew G. Knepley PetscInt k; 94920cf1dd8SToby Isaac 95020cf1dd8SToby Isaac PetscFunctionBegin; 951ef0bb6c7SMatthew G. Knepley if (!npoints || !fem->dualSpace || K < 0) { 952ef0bb6c7SMatthew G. Knepley *T = NULL; 9533ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 95420cf1dd8SToby Isaac } 95520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 9564f572ea9SToby Isaac PetscAssertPointer(points, 4); 9574f572ea9SToby Isaac PetscAssertPointer(T, 6); 9589566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &Q)); 9599566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &dm)); 9609566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &cdim)); 9619566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &Nb)); 9629566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 9639566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(1, T)); 964ef0bb6c7SMatthew G. Knepley (*T)->K = !cdim ? 0 : K; 965ef0bb6c7SMatthew G. Knepley (*T)->Nr = nrepl; 966ef0bb6c7SMatthew G. Knepley (*T)->Np = npoints; 967ef0bb6c7SMatthew G. Knepley (*T)->Nb = Nb; 968ef0bb6c7SMatthew G. Knepley (*T)->Nc = Nc; 969ef0bb6c7SMatthew G. Knepley (*T)->cdim = cdim; 9709566063dSJacob Faibussowitsch PetscCall(PetscMalloc1((*T)->K + 1, &(*T)->T)); 9712dce792eSToby Isaac for (k = 0; k <= (*T)->K; ++k) PetscCall(PetscCalloc1(nrepl * npoints * Nb * Nc * PetscPowInt(cdim, k), &(*T)->T[k])); 972dbbe0bcdSBarry Smith PetscUseTypeMethod(fem, createtabulation, nrepl * npoints, points, K, *T); 9733ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 97420cf1dd8SToby Isaac } 97520cf1dd8SToby Isaac 9762b99622eSMatthew G. Knepley /*@C 977ef0bb6c7SMatthew G. Knepley PetscFEComputeTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided. 9782b99622eSMatthew G. Knepley 97920f4b53cSBarry Smith Not Collective 9802b99622eSMatthew G. Knepley 9812b99622eSMatthew G. Knepley Input Parameters: 982dce8aebaSBarry Smith + fem - The `PetscFE` object 9832b99622eSMatthew G. Knepley . npoints - The number of tabulation points 9842b99622eSMatthew G. Knepley . points - The tabulation point coordinates 985ef0bb6c7SMatthew G. Knepley . K - The number of derivatives calculated 986ef0bb6c7SMatthew G. Knepley - T - An existing tabulation object with enough allocated space 987ef0bb6c7SMatthew G. Knepley 988ef0bb6c7SMatthew G. Knepley Output Parameter: 989ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at tabulation points 9902b99622eSMatthew G. Knepley 9912b99622eSMatthew G. Knepley Level: intermediate 9922b99622eSMatthew G. Knepley 993dce8aebaSBarry Smith Note: 994dce8aebaSBarry Smith .vb 995dce8aebaSBarry Smith T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 996dce8aebaSBarry Smith 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 997dce8aebaSBarry Smith 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 998dce8aebaSBarry Smith .ve 999dce8aebaSBarry Smith 1000dce8aebaSBarry Smith .seealso: `PetscTabulation`, `PetscFEGetCellTabulation()`, `PetscTabulationDestroy()` 10012b99622eSMatthew G. Knepley @*/ 1002d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEComputeTabulation(PetscFE fem, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation T) 1003d71ae5a4SJacob Faibussowitsch { 1004ef0bb6c7SMatthew G. Knepley PetscFunctionBeginHot; 10053ba16761SJacob Faibussowitsch if (!npoints || !fem->dualSpace || K < 0) PetscFunctionReturn(PETSC_SUCCESS); 1006ef0bb6c7SMatthew G. Knepley PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 10074f572ea9SToby Isaac PetscAssertPointer(points, 3); 10084f572ea9SToby Isaac PetscAssertPointer(T, 5); 100976bd3646SJed Brown if (PetscDefined(USE_DEBUG)) { 101020cf1dd8SToby Isaac DM dm; 1011ef0bb6c7SMatthew G. Knepley PetscDualSpace Q; 1012ef0bb6c7SMatthew G. Knepley PetscInt Nb; /* Dimension of FE space P */ 1013ef0bb6c7SMatthew G. Knepley PetscInt Nc; /* Field components */ 1014ef0bb6c7SMatthew G. Knepley PetscInt cdim; /* Reference coordinate dimension */ 1015ef0bb6c7SMatthew G. Knepley 10169566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fem, &Q)); 10179566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &dm)); 10189566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &cdim)); 10199566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &Nb)); 10209566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fem, &Nc)); 102163a3b9bcSJacob 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); 102263a3b9bcSJacob 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); 102363a3b9bcSJacob 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); 102463a3b9bcSJacob 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); 1025ef0bb6c7SMatthew G. Knepley } 1026ef0bb6c7SMatthew G. Knepley T->Nr = 1; 1027ef0bb6c7SMatthew G. Knepley T->Np = npoints; 1028dbbe0bcdSBarry Smith PetscUseTypeMethod(fem, createtabulation, npoints, points, K, T); 10293ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1030ef0bb6c7SMatthew G. Knepley } 1031ef0bb6c7SMatthew G. Knepley 1032ef0bb6c7SMatthew G. Knepley /*@C 1033ef0bb6c7SMatthew G. Knepley PetscTabulationDestroy - Frees memory from the associated tabulation. 1034ef0bb6c7SMatthew G. Knepley 103520f4b53cSBarry Smith Not Collective 1036ef0bb6c7SMatthew G. Knepley 1037ef0bb6c7SMatthew G. Knepley Input Parameter: 1038ef0bb6c7SMatthew G. Knepley . T - The tabulation 1039ef0bb6c7SMatthew G. Knepley 1040ef0bb6c7SMatthew G. Knepley Level: intermediate 1041ef0bb6c7SMatthew G. Knepley 1042dce8aebaSBarry Smith .seealso: `PetscTabulation`, `PetscFECreateTabulation()`, `PetscFEGetCellTabulation()` 1043ef0bb6c7SMatthew G. Knepley @*/ 1044d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscTabulationDestroy(PetscTabulation *T) 1045d71ae5a4SJacob Faibussowitsch { 1046ef0bb6c7SMatthew G. Knepley PetscInt k; 104720cf1dd8SToby Isaac 104820cf1dd8SToby Isaac PetscFunctionBegin; 10494f572ea9SToby Isaac PetscAssertPointer(T, 1); 10503ba16761SJacob Faibussowitsch if (!T || !(*T)) PetscFunctionReturn(PETSC_SUCCESS); 10519566063dSJacob Faibussowitsch for (k = 0; k <= (*T)->K; ++k) PetscCall(PetscFree((*T)->T[k])); 10529566063dSJacob Faibussowitsch PetscCall(PetscFree((*T)->T)); 10539566063dSJacob Faibussowitsch PetscCall(PetscFree(*T)); 1054ef0bb6c7SMatthew G. Knepley *T = NULL; 10553ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 105620cf1dd8SToby Isaac } 105720cf1dd8SToby Isaac 10582dce792eSToby Isaac static PetscErrorCode PetscFECreatePointTraceDefault_Internal(PetscFE fe, PetscInt refPoint, PetscFE *trFE) 1059d71ae5a4SJacob Faibussowitsch { 106020cf1dd8SToby Isaac PetscSpace bsp, bsubsp; 106120cf1dd8SToby Isaac PetscDualSpace dsp, dsubsp; 106220cf1dd8SToby Isaac PetscInt dim, depth, numComp, i, j, coneSize, order; 106320cf1dd8SToby Isaac DM dm; 106420cf1dd8SToby Isaac DMLabel label; 106520cf1dd8SToby Isaac PetscReal *xi, *v, *J, detJ; 1066db11e2ebSMatthew G. Knepley const char *name; 106720cf1dd8SToby Isaac PetscQuadrature origin, fullQuad, subQuad; 106820cf1dd8SToby Isaac 106920cf1dd8SToby Isaac PetscFunctionBegin; 10709566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &bsp)); 10719566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &dsp)); 10729566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp, &dm)); 10739566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 10749566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthLabel(dm, &label)); 10759566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(label, refPoint, &depth)); 10769566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(depth, &xi)); 10779566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dim, &v)); 10789566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dim * dim, &J)); 107920cf1dd8SToby Isaac for (i = 0; i < depth; i++) xi[i] = 0.; 10809566063dSJacob Faibussowitsch PetscCall(PetscQuadratureCreate(PETSC_COMM_SELF, &origin)); 10819566063dSJacob Faibussowitsch PetscCall(PetscQuadratureSetData(origin, depth, 0, 1, xi, NULL)); 10829566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm, refPoint, origin, v, J, NULL, &detJ)); 108320cf1dd8SToby Isaac /* CellGeometryFEM computes the expanded Jacobian, we want the true jacobian */ 108420cf1dd8SToby Isaac for (i = 1; i < dim; i++) { 1085ad540459SPierre Jolivet for (j = 0; j < depth; j++) J[i * depth + j] = J[i * dim + j]; 108620cf1dd8SToby Isaac } 10879566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&origin)); 10889566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetPointSubspace(dsp, refPoint, &dsubsp)); 10899566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreateSubspace(bsp, dsubsp, v, J, NULL, NULL, PETSC_OWN_POINTER, &bsubsp)); 10909566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetUp(bsubsp)); 10919566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject)fe), trFE)); 10922dce792eSToby Isaac PetscCall(PetscFESetType(*trFE, PETSCFEBASIC)); 10939566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &numComp)); 10949566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(*trFE, numComp)); 10959566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(*trFE, bsubsp)); 10969566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(*trFE, dsubsp)); 10979566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject)fe, &name)); 10989566063dSJacob Faibussowitsch if (name) PetscCall(PetscFESetName(*trFE, name)); 10999566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &fullQuad)); 11009566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetOrder(fullQuad, &order)); 11019566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, refPoint, &coneSize)); 11028b6ef6a4SJed Brown if (coneSize == 2 * depth) PetscCall(PetscDTGaussTensorQuadrature(depth, 1, (order + 2) / 2, -1., 1., &subQuad)); 11038b6ef6a4SJed Brown else PetscCall(PetscDTSimplexQuadrature(depth, order, PETSCDTSIMPLEXQUAD_DEFAULT, &subQuad)); 11049566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(*trFE, subQuad)); 11059566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(*trFE)); 11069566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&subQuad)); 11079566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&bsubsp)); 11083ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 110920cf1dd8SToby Isaac } 111020cf1dd8SToby Isaac 11112dce792eSToby Isaac PETSC_EXTERN PetscErrorCode PetscFECreatePointTrace(PetscFE fe, PetscInt refPoint, PetscFE *trFE) 11122dce792eSToby Isaac { 11132dce792eSToby Isaac PetscErrorCode (*createpointtrace)(PetscFE, PetscInt, PetscFE *); 11142dce792eSToby Isaac 11152dce792eSToby Isaac PetscFunctionBegin; 11162dce792eSToby Isaac PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1); 11172dce792eSToby Isaac PetscAssertPointer(trFE, 3); 11182dce792eSToby Isaac createpointtrace = fe->ops->createpointtrace; 11192dce792eSToby Isaac if (createpointtrace) { 11202dce792eSToby Isaac PetscCall((*createpointtrace)(fe, refPoint, trFE)); 11212dce792eSToby Isaac } else { 11222dce792eSToby Isaac PetscCall(PetscFECreatePointTraceDefault_Internal(fe, refPoint, trFE)); 11232dce792eSToby Isaac } 11242dce792eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 11252dce792eSToby Isaac } 11262dce792eSToby Isaac 1127d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateHeightTrace(PetscFE fe, PetscInt height, PetscFE *trFE) 1128d71ae5a4SJacob Faibussowitsch { 112920cf1dd8SToby Isaac PetscInt hStart, hEnd; 113020cf1dd8SToby Isaac PetscDualSpace dsp; 113120cf1dd8SToby Isaac DM dm; 113220cf1dd8SToby Isaac 113320cf1dd8SToby Isaac PetscFunctionBegin; 113420cf1dd8SToby Isaac PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1); 11354f572ea9SToby Isaac PetscAssertPointer(trFE, 3); 113620cf1dd8SToby Isaac *trFE = NULL; 11379566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &dsp)); 11389566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp, &dm)); 11399566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(dm, height, &hStart, &hEnd)); 11403ba16761SJacob Faibussowitsch if (hEnd <= hStart) PetscFunctionReturn(PETSC_SUCCESS); 11419566063dSJacob Faibussowitsch PetscCall(PetscFECreatePointTrace(fe, hStart, trFE)); 11423ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 114320cf1dd8SToby Isaac } 114420cf1dd8SToby Isaac 114520cf1dd8SToby Isaac /*@ 114620cf1dd8SToby Isaac PetscFEGetDimension - Get the dimension of the finite element space on a cell 114720cf1dd8SToby Isaac 114820f4b53cSBarry Smith Not Collective 114920cf1dd8SToby Isaac 115020cf1dd8SToby Isaac Input Parameter: 115160225df5SJacob Faibussowitsch . fem - The `PetscFE` 115220cf1dd8SToby Isaac 115320cf1dd8SToby Isaac Output Parameter: 115420cf1dd8SToby Isaac . dim - The dimension 115520cf1dd8SToby Isaac 115620cf1dd8SToby Isaac Level: intermediate 115720cf1dd8SToby Isaac 1158dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFECreate()`, `PetscSpaceGetDimension()`, `PetscDualSpaceGetDimension()` 115920cf1dd8SToby Isaac @*/ 1160d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetDimension(PetscFE fem, PetscInt *dim) 1161d71ae5a4SJacob Faibussowitsch { 116220cf1dd8SToby Isaac PetscFunctionBegin; 116320cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 11644f572ea9SToby Isaac PetscAssertPointer(dim, 2); 1165dbbe0bcdSBarry Smith PetscTryTypeMethod(fem, getdimension, dim); 11663ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 116720cf1dd8SToby Isaac } 116820cf1dd8SToby Isaac 11694bee2e38SMatthew G. Knepley /*@C 11704bee2e38SMatthew G. Knepley PetscFEPushforward - Map the reference element function to real space 11714bee2e38SMatthew G. Knepley 11724bee2e38SMatthew G. Knepley Input Parameters: 1173dce8aebaSBarry Smith + fe - The `PetscFE` 11744bee2e38SMatthew G. Knepley . fegeom - The cell geometry 11754bee2e38SMatthew G. Knepley . Nv - The number of function values 11764bee2e38SMatthew G. Knepley - vals - The function values 11774bee2e38SMatthew G. Knepley 11784bee2e38SMatthew G. Knepley Output Parameter: 11794bee2e38SMatthew G. Knepley . vals - The transformed function values 11804bee2e38SMatthew G. Knepley 11814bee2e38SMatthew G. Knepley Level: advanced 11824bee2e38SMatthew G. Knepley 1183dce8aebaSBarry Smith Notes: 1184dce8aebaSBarry Smith This just forwards the call onto `PetscDualSpacePushforward()`. 11854bee2e38SMatthew G. Knepley 1186dce8aebaSBarry Smith It only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 11872edcad52SToby Isaac 1188dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFEGeom`, `PetscDualSpace`, `PetscDualSpacePushforward()` 11894bee2e38SMatthew G. Knepley @*/ 1190d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEPushforward(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 1191d71ae5a4SJacob Faibussowitsch { 11922ae266adSMatthew G. Knepley PetscFunctionBeginHot; 11939566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforward(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 11943ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 11954bee2e38SMatthew G. Knepley } 11964bee2e38SMatthew G. Knepley 11974bee2e38SMatthew G. Knepley /*@C 11984bee2e38SMatthew G. Knepley PetscFEPushforwardGradient - Map the reference element function gradient to real space 11994bee2e38SMatthew G. Knepley 12004bee2e38SMatthew G. Knepley Input Parameters: 1201dce8aebaSBarry Smith + fe - The `PetscFE` 12024bee2e38SMatthew G. Knepley . fegeom - The cell geometry 12034bee2e38SMatthew G. Knepley . Nv - The number of function gradient values 12044bee2e38SMatthew G. Knepley - vals - The function gradient values 12054bee2e38SMatthew G. Knepley 12064bee2e38SMatthew G. Knepley Output Parameter: 12074bee2e38SMatthew G. Knepley . vals - The transformed function gradient values 12084bee2e38SMatthew G. Knepley 12094bee2e38SMatthew G. Knepley Level: advanced 12104bee2e38SMatthew G. Knepley 1211dce8aebaSBarry Smith Notes: 1212dce8aebaSBarry Smith This just forwards the call onto `PetscDualSpacePushforwardGradient()`. 12134bee2e38SMatthew G. Knepley 1214dce8aebaSBarry Smith It only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 12152edcad52SToby Isaac 1216dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFEGeom`, `PetscDualSpace`, `PetscFEPushforward()`, `PetscDualSpacePushforwardGradient()`, `PetscDualSpacePushforward()` 12174bee2e38SMatthew G. Knepley @*/ 1218d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEPushforwardGradient(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 1219d71ae5a4SJacob Faibussowitsch { 12202ae266adSMatthew G. Knepley PetscFunctionBeginHot; 12219566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforwardGradient(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 12223ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 12234bee2e38SMatthew G. Knepley } 12244bee2e38SMatthew G. Knepley 1225f9244615SMatthew G. Knepley /*@C 1226f9244615SMatthew G. Knepley PetscFEPushforwardHessian - Map the reference element function Hessian to real space 1227f9244615SMatthew G. Knepley 1228f9244615SMatthew G. Knepley Input Parameters: 1229dce8aebaSBarry Smith + fe - The `PetscFE` 1230f9244615SMatthew G. Knepley . fegeom - The cell geometry 1231f9244615SMatthew G. Knepley . Nv - The number of function Hessian values 1232f9244615SMatthew G. Knepley - vals - The function Hessian values 1233f9244615SMatthew G. Knepley 1234f9244615SMatthew G. Knepley Output Parameter: 1235f9244615SMatthew G. Knepley . vals - The transformed function Hessian values 1236f9244615SMatthew G. Knepley 1237f9244615SMatthew G. Knepley Level: advanced 1238f9244615SMatthew G. Knepley 1239dce8aebaSBarry Smith Notes: 1240dce8aebaSBarry Smith This just forwards the call onto `PetscDualSpacePushforwardHessian()`. 1241f9244615SMatthew G. Knepley 1242dce8aebaSBarry Smith It only handles transformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension. 1243f9244615SMatthew G. Knepley 124460225df5SJacob Faibussowitsch Developer Notes: 1245dce8aebaSBarry Smith It is unclear why all these one line convenience routines are desirable 1246dce8aebaSBarry Smith 1247dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscFEGeom`, `PetscDualSpace`, `PetscFEPushforward()`, `PetscDualSpacePushforwardHessian()`, `PetscDualSpacePushforward()` 1248f9244615SMatthew G. Knepley @*/ 1249d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEPushforwardHessian(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 1250d71ae5a4SJacob Faibussowitsch { 1251f9244615SMatthew G. Knepley PetscFunctionBeginHot; 12529566063dSJacob Faibussowitsch PetscCall(PetscDualSpacePushforwardHessian(fe->dualSpace, fegeom, Nv, fe->numComponents, vals)); 12533ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1254f9244615SMatthew G. Knepley } 1255f9244615SMatthew G. Knepley 125620cf1dd8SToby Isaac /* 125720cf1dd8SToby Isaac Purpose: Compute element vector for chunk of elements 125820cf1dd8SToby Isaac 125920cf1dd8SToby Isaac Input: 126020cf1dd8SToby Isaac Sizes: 126120cf1dd8SToby Isaac Ne: number of elements 126220cf1dd8SToby Isaac Nf: number of fields 126320cf1dd8SToby Isaac PetscFE 126420cf1dd8SToby Isaac dim: spatial dimension 126520cf1dd8SToby Isaac Nb: number of basis functions 126620cf1dd8SToby Isaac Nc: number of field components 126720cf1dd8SToby Isaac PetscQuadrature 126820cf1dd8SToby Isaac Nq: number of quadrature points 126920cf1dd8SToby Isaac 127020cf1dd8SToby Isaac Geometry: 127120cf1dd8SToby Isaac PetscFEGeom[Ne] possibly *Nq 127220cf1dd8SToby Isaac PetscReal v0s[dim] 127320cf1dd8SToby Isaac PetscReal n[dim] 127420cf1dd8SToby Isaac PetscReal jacobians[dim*dim] 127520cf1dd8SToby Isaac PetscReal jacobianInverses[dim*dim] 127620cf1dd8SToby Isaac PetscReal jacobianDeterminants 127720cf1dd8SToby Isaac FEM: 127820cf1dd8SToby Isaac PetscFE 127920cf1dd8SToby Isaac PetscQuadrature 128020cf1dd8SToby Isaac PetscReal quadPoints[Nq*dim] 128120cf1dd8SToby Isaac PetscReal quadWeights[Nq] 128220cf1dd8SToby Isaac PetscReal basis[Nq*Nb*Nc] 128320cf1dd8SToby Isaac PetscReal basisDer[Nq*Nb*Nc*dim] 128420cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 128520cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 128620cf1dd8SToby Isaac 128720cf1dd8SToby Isaac Problem: 128820cf1dd8SToby Isaac PetscInt f: the active field 128920cf1dd8SToby Isaac f0, f1 129020cf1dd8SToby Isaac 129120cf1dd8SToby Isaac Work Space: 129220cf1dd8SToby Isaac PetscFE 129320cf1dd8SToby Isaac PetscScalar f0[Nq*dim]; 129420cf1dd8SToby Isaac PetscScalar f1[Nq*dim*dim]; 129520cf1dd8SToby Isaac PetscScalar u[Nc]; 129620cf1dd8SToby Isaac PetscScalar gradU[Nc*dim]; 129720cf1dd8SToby Isaac PetscReal x[dim]; 129820cf1dd8SToby Isaac PetscScalar realSpaceDer[dim]; 129920cf1dd8SToby Isaac 130020cf1dd8SToby Isaac Purpose: Compute element vector for N_cb batches of elements 130120cf1dd8SToby Isaac 130220cf1dd8SToby Isaac Input: 130320cf1dd8SToby Isaac Sizes: 130420cf1dd8SToby Isaac N_cb: Number of serial cell batches 130520cf1dd8SToby Isaac 130620cf1dd8SToby Isaac Geometry: 130720cf1dd8SToby Isaac PetscReal v0s[Ne*dim] 130820cf1dd8SToby Isaac PetscReal jacobians[Ne*dim*dim] possibly *Nq 130920cf1dd8SToby Isaac PetscReal jacobianInverses[Ne*dim*dim] possibly *Nq 131020cf1dd8SToby Isaac PetscReal jacobianDeterminants[Ne] possibly *Nq 131120cf1dd8SToby Isaac FEM: 131220cf1dd8SToby Isaac static PetscReal quadPoints[Nq*dim] 131320cf1dd8SToby Isaac static PetscReal quadWeights[Nq] 131420cf1dd8SToby Isaac static PetscReal basis[Nq*Nb*Nc] 131520cf1dd8SToby Isaac static PetscReal basisDer[Nq*Nb*Nc*dim] 131620cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 131720cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 131820cf1dd8SToby Isaac 131920cf1dd8SToby Isaac ex62.c: 132020cf1dd8SToby Isaac PetscErrorCode PetscFEIntegrateResidualBatch(PetscInt Ne, PetscInt numFields, PetscInt field, PetscQuadrature quad[], const PetscScalar coefficients[], 132120cf1dd8SToby Isaac const PetscReal v0s[], const PetscReal jacobians[], const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], 132220cf1dd8SToby Isaac void (*f0_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f0[]), 132320cf1dd8SToby Isaac void (*f1_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f1[]), PetscScalar elemVec[]) 132420cf1dd8SToby Isaac 132520cf1dd8SToby Isaac ex52.c: 132620cf1dd8SToby 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) 132720cf1dd8SToby 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) 132820cf1dd8SToby Isaac 132920cf1dd8SToby Isaac ex52_integrateElement.cu 133020cf1dd8SToby Isaac __global__ void integrateElementQuadrature(int N_cb, realType *coefficients, realType *jacobianInverses, realType *jacobianDeterminants, realType *elemVec) 133120cf1dd8SToby Isaac 133220cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt Nbl, const PetscScalar coefficients[], 133320cf1dd8SToby Isaac const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[], 133420cf1dd8SToby Isaac PetscLogEvent event, PetscInt debug, PetscInt pde_op) 133520cf1dd8SToby Isaac 133620cf1dd8SToby Isaac ex52_integrateElementOpenCL.c: 133720cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt N_bl, const PetscScalar coefficients[], 133820cf1dd8SToby Isaac const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[], 133920cf1dd8SToby Isaac PetscLogEvent event, PetscInt debug, PetscInt pde_op) 134020cf1dd8SToby Isaac 134120cf1dd8SToby Isaac __kernel void integrateElementQuadrature(int N_cb, __global float *coefficients, __global float *jacobianInverses, __global float *jacobianDeterminants, __global float *elemVec) 134220cf1dd8SToby Isaac */ 134320cf1dd8SToby Isaac 134420cf1dd8SToby Isaac /*@C 134520cf1dd8SToby Isaac PetscFEIntegrate - Produce the integral for the given field for a chunk of elements by quadrature integration 134620cf1dd8SToby Isaac 134720f4b53cSBarry Smith Not Collective 134820cf1dd8SToby Isaac 134920cf1dd8SToby Isaac Input Parameters: 1350dce8aebaSBarry Smith + prob - The `PetscDS` specifying the discretizations and continuum functions 135120cf1dd8SToby Isaac . field - The field being integrated 135220cf1dd8SToby Isaac . Ne - The number of elements in the chunk 135320cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 135420cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 1355dce8aebaSBarry Smith . probAux - The `PetscDS` specifying the auxiliary discretizations 135620cf1dd8SToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 135720cf1dd8SToby Isaac 13587a7aea1fSJed Brown Output Parameter: 135920cf1dd8SToby Isaac . integral - the integral for this field 136020cf1dd8SToby Isaac 13612b99622eSMatthew G. Knepley Level: intermediate 136220cf1dd8SToby Isaac 136360225df5SJacob Faibussowitsch Developer Notes: 1364dce8aebaSBarry Smith The function name begins with `PetscFE` and yet the first argument is `PetscDS` and it has no `PetscFE` arguments. 1365dce8aebaSBarry Smith 1366dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscDS`, `PetscFEIntegrateResidual()`, `PetscFEIntegrateBd()` 136720cf1dd8SToby Isaac @*/ 1368d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEIntegrate(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom, const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 1369d71ae5a4SJacob Faibussowitsch { 13704bee2e38SMatthew G. Knepley PetscFE fe; 137120cf1dd8SToby Isaac 137220cf1dd8SToby Isaac PetscFunctionBegin; 13734bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13749566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *)&fe)); 13759566063dSJacob Faibussowitsch if (fe->ops->integrate) PetscCall((*fe->ops->integrate)(prob, field, Ne, cgeom, coefficients, probAux, coefficientsAux, integral)); 13763ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 137720cf1dd8SToby Isaac } 137820cf1dd8SToby Isaac 137920cf1dd8SToby Isaac /*@C 1380afe6d6adSToby Isaac PetscFEIntegrateBd - Produce the integral for the given field for a chunk of elements by quadrature integration 1381afe6d6adSToby Isaac 138220f4b53cSBarry Smith Not Collective 1383afe6d6adSToby Isaac 1384afe6d6adSToby Isaac Input Parameters: 1385dce8aebaSBarry Smith + prob - The `PetscDS` specifying the discretizations and continuum functions 1386afe6d6adSToby Isaac . field - The field being integrated 1387afe6d6adSToby Isaac . obj_func - The function to be integrated 1388afe6d6adSToby Isaac . Ne - The number of elements in the chunk 138960225df5SJacob Faibussowitsch . geom - The face geometry for each face in the chunk 1390afe6d6adSToby Isaac . coefficients - The array of FEM basis coefficients for the elements 1391dce8aebaSBarry Smith . probAux - The `PetscDS` specifying the auxiliary discretizations 1392afe6d6adSToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 1393afe6d6adSToby Isaac 13947a7aea1fSJed Brown Output Parameter: 1395afe6d6adSToby Isaac . integral - the integral for this field 1396afe6d6adSToby Isaac 13972b99622eSMatthew G. Knepley Level: intermediate 1398afe6d6adSToby Isaac 139960225df5SJacob Faibussowitsch Developer Notes: 1400dce8aebaSBarry Smith The function name begins with `PetscFE` and yet the first argument is `PetscDS` and it has no `PetscFE` arguments. 1401dce8aebaSBarry Smith 1402dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscDS`, `PetscFEIntegrateResidual()`, `PetscFEIntegrate()` 1403afe6d6adSToby Isaac @*/ 1404d71ae5a4SJacob 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[]) 1405d71ae5a4SJacob Faibussowitsch { 14064bee2e38SMatthew G. Knepley PetscFE fe; 1407afe6d6adSToby Isaac 1408afe6d6adSToby Isaac PetscFunctionBegin; 14094bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 14109566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *)&fe)); 14119566063dSJacob Faibussowitsch if (fe->ops->integratebd) PetscCall((*fe->ops->integratebd)(prob, field, obj_func, Ne, geom, coefficients, probAux, coefficientsAux, integral)); 14123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1413afe6d6adSToby Isaac } 1414afe6d6adSToby Isaac 1415afe6d6adSToby Isaac /*@C 141620cf1dd8SToby Isaac PetscFEIntegrateResidual - Produce the element residual vector for a chunk of elements by quadrature integration 141720cf1dd8SToby Isaac 141820f4b53cSBarry Smith Not Collective 141920cf1dd8SToby Isaac 142020cf1dd8SToby Isaac Input Parameters: 142120f4b53cSBarry Smith + ds - The `PetscDS` specifying the discretizations and continuum functions 14226528b96dSMatthew G. Knepley . key - The (label+value, field) being integrated 142320cf1dd8SToby Isaac . Ne - The number of elements in the chunk 142420cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 142520cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 142620cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 142720f4b53cSBarry Smith . probAux - The `PetscDS` specifying the auxiliary discretizations 142820cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 142920cf1dd8SToby Isaac - t - The time 143020cf1dd8SToby Isaac 14317a7aea1fSJed Brown Output Parameter: 143220cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 143320cf1dd8SToby Isaac 14342b99622eSMatthew G. Knepley Level: intermediate 143520cf1dd8SToby Isaac 1436dce8aebaSBarry Smith Note: 1437dce8aebaSBarry Smith .vb 1438dce8aebaSBarry Smith Loop over batch of elements (e): 1439dce8aebaSBarry Smith Loop over quadrature points (q): 1440dce8aebaSBarry Smith Make u_q and gradU_q (loops over fields,Nb,Ncomp) and x_q 1441dce8aebaSBarry Smith Call f_0 and f_1 1442dce8aebaSBarry Smith Loop over element vector entries (f,fc --> i): 1443dce8aebaSBarry Smith elemVec[i] += \psi^{fc}_f(q) f0_{fc}(u, \nabla u) + \nabla\psi^{fc}_f(q) \cdot f1_{fc,df}(u, \nabla u) 1444dce8aebaSBarry Smith .ve 1445dce8aebaSBarry Smith 144642747ad1SJacob Faibussowitsch .seealso: `PetscFEIntegrateBdResidual()` 144720cf1dd8SToby Isaac @*/ 1448d71ae5a4SJacob 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[]) 1449d71ae5a4SJacob Faibussowitsch { 14504bee2e38SMatthew G. Knepley PetscFE fe; 145120cf1dd8SToby Isaac 14526528b96dSMatthew G. Knepley PetscFunctionBeginHot; 14536528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14549566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field, (PetscObject *)&fe)); 14559566063dSJacob Faibussowitsch if (fe->ops->integrateresidual) PetscCall((*fe->ops->integrateresidual)(ds, key, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 14563ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 145720cf1dd8SToby Isaac } 145820cf1dd8SToby Isaac 145920cf1dd8SToby Isaac /*@C 146020cf1dd8SToby Isaac PetscFEIntegrateBdResidual - Produce the element residual vector for a chunk of elements by quadrature integration over a boundary 146120cf1dd8SToby Isaac 146220f4b53cSBarry Smith Not Collective 146320cf1dd8SToby Isaac 146420cf1dd8SToby Isaac Input Parameters: 146520f4b53cSBarry Smith + ds - The `PetscDS` specifying the discretizations and continuum functions 146645480ffeSMatthew G. Knepley . wf - The PetscWeakForm object holding the pointwise functions 146706d8a0d3SMatthew G. Knepley . key - The (label+value, field) being integrated 146820cf1dd8SToby Isaac . Ne - The number of elements in the chunk 146920cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 147020cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 147120cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 147220f4b53cSBarry Smith . probAux - The `PetscDS` specifying the auxiliary discretizations 147320cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 147420cf1dd8SToby Isaac - t - The time 147520cf1dd8SToby Isaac 14767a7aea1fSJed Brown Output Parameter: 147720cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 147820cf1dd8SToby Isaac 14792b99622eSMatthew G. Knepley Level: intermediate 148020cf1dd8SToby Isaac 1481db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 148220cf1dd8SToby Isaac @*/ 1483d71ae5a4SJacob 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[]) 1484d71ae5a4SJacob Faibussowitsch { 14854bee2e38SMatthew G. Knepley PetscFE fe; 148620cf1dd8SToby Isaac 148720cf1dd8SToby Isaac PetscFunctionBegin; 148806d8a0d3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14899566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field, (PetscObject *)&fe)); 14909566063dSJacob Faibussowitsch if (fe->ops->integratebdresidual) PetscCall((*fe->ops->integratebdresidual)(ds, wf, key, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 14913ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 149220cf1dd8SToby Isaac } 149320cf1dd8SToby Isaac 149420cf1dd8SToby Isaac /*@C 149527f02ce8SMatthew G. Knepley PetscFEIntegrateHybridResidual - Produce the element residual vector for a chunk of hybrid element faces by quadrature integration 149627f02ce8SMatthew G. Knepley 149720f4b53cSBarry Smith Not Collective 149827f02ce8SMatthew G. Knepley 149927f02ce8SMatthew G. Knepley Input Parameters: 150007218a29SMatthew G. Knepley + ds - The `PetscDS` specifying the discretizations and continuum functions 150107218a29SMatthew G. Knepley . dsIn - The `PetscDS` specifying the discretizations and continuum functions for input 15026528b96dSMatthew G. Knepley . key - The (label+value, field) being integrated 1503c2b7495fSMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 150427f02ce8SMatthew G. Knepley . Ne - The number of elements in the chunk 150527f02ce8SMatthew G. Knepley . fgeom - The face geometry for each cell in the chunk 150627f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements 150727f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements 150820f4b53cSBarry Smith . probAux - The `PetscDS` specifying the auxiliary discretizations 150927f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 151027f02ce8SMatthew G. Knepley - t - The time 151127f02ce8SMatthew G. Knepley 1512a4e35b19SJacob Faibussowitsch Output Parameter: 151327f02ce8SMatthew G. Knepley . elemVec - the element residual vectors from each element 151427f02ce8SMatthew G. Knepley 151527f02ce8SMatthew G. Knepley Level: developer 151627f02ce8SMatthew G. Knepley 1517db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 151827f02ce8SMatthew G. Knepley @*/ 151907218a29SMatthew G. Knepley PetscErrorCode PetscFEIntegrateHybridResidual(PetscDS ds, PetscDS dsIn, PetscFormKey key, PetscInt s, PetscInt Ne, PetscFEGeom *fgeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 1520d71ae5a4SJacob Faibussowitsch { 152127f02ce8SMatthew G. Knepley PetscFE fe; 152227f02ce8SMatthew G. Knepley 152327f02ce8SMatthew G. Knepley PetscFunctionBegin; 152407218a29SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 152507218a29SMatthew G. Knepley PetscValidHeaderSpecific(dsIn, PETSCDS_CLASSID, 2); 152607218a29SMatthew G. Knepley PetscCall(PetscDSGetDiscretization(ds, key.field, (PetscObject *)&fe)); 152707218a29SMatthew G. Knepley if (fe->ops->integratehybridresidual) PetscCall((*fe->ops->integratehybridresidual)(ds, dsIn, key, s, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec)); 15283ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 152927f02ce8SMatthew G. Knepley } 153027f02ce8SMatthew G. Knepley 153127f02ce8SMatthew G. Knepley /*@C 153220cf1dd8SToby Isaac PetscFEIntegrateJacobian - Produce the element Jacobian for a chunk of elements by quadrature integration 153320cf1dd8SToby Isaac 153420f4b53cSBarry Smith Not Collective 153520cf1dd8SToby Isaac 153620cf1dd8SToby Isaac Input Parameters: 153720f4b53cSBarry Smith + ds - The `PetscDS` specifying the discretizations and continuum functions 153820cf1dd8SToby Isaac . jtype - The type of matrix pointwise functions that should be used 15396528b96dSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 154020cf1dd8SToby Isaac . Ne - The number of elements in the chunk 154120cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 154220cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 154320cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 154420f4b53cSBarry Smith . probAux - The `PetscDS` specifying the auxiliary discretizations 154520cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 154620cf1dd8SToby Isaac . t - The time 154760225df5SJacob Faibussowitsch - u_tshift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 154820cf1dd8SToby Isaac 15497a7aea1fSJed Brown Output Parameter: 155020cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 155120cf1dd8SToby Isaac 15522b99622eSMatthew G. Knepley Level: intermediate 155320cf1dd8SToby Isaac 1554dce8aebaSBarry Smith Note: 1555dce8aebaSBarry Smith .vb 1556dce8aebaSBarry Smith Loop over batch of elements (e): 1557dce8aebaSBarry Smith Loop over element matrix entries (f,fc,g,gc --> i,j): 1558dce8aebaSBarry Smith Loop over quadrature points (q): 1559dce8aebaSBarry Smith Make u_q and gradU_q (loops over fields,Nb,Ncomp) 1560dce8aebaSBarry Smith elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 1561dce8aebaSBarry Smith + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 1562dce8aebaSBarry Smith + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 1563dce8aebaSBarry Smith + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 1564dce8aebaSBarry Smith .ve 1565dce8aebaSBarry Smith 1566db781477SPatrick Sanan .seealso: `PetscFEIntegrateResidual()` 156720cf1dd8SToby Isaac @*/ 1568d71ae5a4SJacob 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[]) 1569d71ae5a4SJacob Faibussowitsch { 15704bee2e38SMatthew G. Knepley PetscFE fe; 15716528b96dSMatthew G. Knepley PetscInt Nf; 157220cf1dd8SToby Isaac 157320cf1dd8SToby Isaac PetscFunctionBegin; 15746528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 15759566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 15769566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *)&fe)); 15779566063dSJacob Faibussowitsch if (fe->ops->integratejacobian) PetscCall((*fe->ops->integratejacobian)(ds, jtype, key, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 15783ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 157920cf1dd8SToby Isaac } 158020cf1dd8SToby Isaac 158120cf1dd8SToby Isaac /*@C 158220cf1dd8SToby Isaac PetscFEIntegrateBdJacobian - Produce the boundary element Jacobian for a chunk of elements by quadrature integration 158320cf1dd8SToby Isaac 158420f4b53cSBarry Smith Not Collective 158520cf1dd8SToby Isaac 158620cf1dd8SToby Isaac Input Parameters: 158720f4b53cSBarry Smith + ds - The `PetscDS` specifying the discretizations and continuum functions 158845480ffeSMatthew G. Knepley . wf - The PetscWeakForm holding the pointwise functions 158945480ffeSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 159020cf1dd8SToby Isaac . Ne - The number of elements in the chunk 159120cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 159220cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 159320cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 159420f4b53cSBarry Smith . probAux - The `PetscDS` specifying the auxiliary discretizations 159520cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 159620cf1dd8SToby Isaac . t - The time 159760225df5SJacob Faibussowitsch - u_tshift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 159820cf1dd8SToby Isaac 15997a7aea1fSJed Brown Output Parameter: 160020cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 160120cf1dd8SToby Isaac 16022b99622eSMatthew G. Knepley Level: intermediate 160320cf1dd8SToby Isaac 1604dce8aebaSBarry Smith Note: 1605dce8aebaSBarry Smith .vb 1606dce8aebaSBarry Smith Loop over batch of elements (e): 1607dce8aebaSBarry Smith Loop over element matrix entries (f,fc,g,gc --> i,j): 1608dce8aebaSBarry Smith Loop over quadrature points (q): 1609dce8aebaSBarry Smith Make u_q and gradU_q (loops over fields,Nb,Ncomp) 1610dce8aebaSBarry Smith elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 1611dce8aebaSBarry Smith + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 1612dce8aebaSBarry Smith + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 1613dce8aebaSBarry Smith + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 1614dce8aebaSBarry Smith .ve 1615dce8aebaSBarry Smith 1616db781477SPatrick Sanan .seealso: `PetscFEIntegrateJacobian()`, `PetscFEIntegrateResidual()` 161720cf1dd8SToby Isaac @*/ 1618d71ae5a4SJacob 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[]) 1619d71ae5a4SJacob Faibussowitsch { 16204bee2e38SMatthew G. Knepley PetscFE fe; 162145480ffeSMatthew G. Knepley PetscInt Nf; 162220cf1dd8SToby Isaac 162320cf1dd8SToby Isaac PetscFunctionBegin; 162445480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 16259566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 16269566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *)&fe)); 16279566063dSJacob Faibussowitsch if (fe->ops->integratebdjacobian) PetscCall((*fe->ops->integratebdjacobian)(ds, wf, key, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 16283ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 162920cf1dd8SToby Isaac } 163020cf1dd8SToby Isaac 163127f02ce8SMatthew G. Knepley /*@C 163227f02ce8SMatthew G. Knepley PetscFEIntegrateHybridJacobian - Produce the boundary element Jacobian for a chunk of hybrid elements by quadrature integration 163327f02ce8SMatthew G. Knepley 163420f4b53cSBarry Smith Not Collective 163527f02ce8SMatthew G. Knepley 163627f02ce8SMatthew G. Knepley Input Parameters: 163707218a29SMatthew G. Knepley + ds - The `PetscDS` specifying the discretizations and continuum functions for the output 163807218a29SMatthew G. Knepley . dsIn - The `PetscDS` specifying the discretizations and continuum functions for the input 163927f02ce8SMatthew G. Knepley . jtype - The type of matrix pointwise functions that should be used 164045480ffeSMatthew G. Knepley . key - The (label+value, fieldI*Nf + fieldJ) being integrated 16415fedec97SMatthew G. Knepley . s - The side of the cell being integrated, 0 for negative and 1 for positive 164227f02ce8SMatthew G. Knepley . Ne - The number of elements in the chunk 164327f02ce8SMatthew G. Knepley . fgeom - The face geometry for each cell in the chunk 164427f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 164527f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements 164620f4b53cSBarry Smith . probAux - The `PetscDS` specifying the auxiliary discretizations 164727f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 164827f02ce8SMatthew G. Knepley . t - The time 164960225df5SJacob Faibussowitsch - u_tshift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 165027f02ce8SMatthew G. Knepley 1651a4e35b19SJacob Faibussowitsch Output Parameter: 165227f02ce8SMatthew G. Knepley . elemMat - the element matrices for the Jacobian from each element 165327f02ce8SMatthew G. Knepley 165427f02ce8SMatthew G. Knepley Level: developer 165527f02ce8SMatthew G. Knepley 1656dce8aebaSBarry Smith Note: 1657dce8aebaSBarry Smith .vb 1658dce8aebaSBarry Smith Loop over batch of elements (e): 1659dce8aebaSBarry Smith Loop over element matrix entries (f,fc,g,gc --> i,j): 1660dce8aebaSBarry Smith Loop over quadrature points (q): 1661dce8aebaSBarry Smith Make u_q and gradU_q (loops over fields,Nb,Ncomp) 1662dce8aebaSBarry Smith elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 1663dce8aebaSBarry Smith + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 1664dce8aebaSBarry Smith + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 1665dce8aebaSBarry Smith + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 1666dce8aebaSBarry Smith .ve 1667dce8aebaSBarry Smith 1668db781477SPatrick Sanan .seealso: `PetscFEIntegrateJacobian()`, `PetscFEIntegrateResidual()` 166927f02ce8SMatthew G. Knepley @*/ 167007218a29SMatthew G. Knepley PetscErrorCode PetscFEIntegrateHybridJacobian(PetscDS ds, PetscDS dsIn, 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[]) 1671d71ae5a4SJacob Faibussowitsch { 167227f02ce8SMatthew G. Knepley PetscFE fe; 167345480ffeSMatthew G. Knepley PetscInt Nf; 167427f02ce8SMatthew G. Knepley 167527f02ce8SMatthew G. Knepley PetscFunctionBegin; 167645480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 16779566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 16789566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, key.field / Nf, (PetscObject *)&fe)); 167907218a29SMatthew G. Knepley if (fe->ops->integratehybridjacobian) PetscCall((*fe->ops->integratehybridjacobian)(ds, dsIn, jtype, key, s, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat)); 16803ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 168127f02ce8SMatthew G. Knepley } 168227f02ce8SMatthew G. Knepley 16832b99622eSMatthew G. Knepley /*@ 16842b99622eSMatthew G. Knepley PetscFEGetHeightSubspace - Get the subspace of this space for a mesh point of a given height 16852b99622eSMatthew G. Knepley 16862b99622eSMatthew G. Knepley Input Parameters: 16872b99622eSMatthew G. Knepley + fe - The finite element space 168820f4b53cSBarry Smith - height - The height of the `DMPLEX` point 16892b99622eSMatthew G. Knepley 16902b99622eSMatthew G. Knepley Output Parameter: 169120f4b53cSBarry Smith . subfe - The subspace of this `PetscFE` space 16922b99622eSMatthew G. Knepley 16932b99622eSMatthew G. Knepley Level: advanced 16942b99622eSMatthew G. Knepley 1695dce8aebaSBarry Smith Note: 1696dce8aebaSBarry Smith For example, if we want the subspace of this space for a face, we would choose height = 1. 1697dce8aebaSBarry Smith 1698db781477SPatrick Sanan .seealso: `PetscFECreateDefault()` 16992b99622eSMatthew G. Knepley @*/ 1700d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEGetHeightSubspace(PetscFE fe, PetscInt height, PetscFE *subfe) 1701d71ae5a4SJacob Faibussowitsch { 170220cf1dd8SToby Isaac PetscSpace P, subP; 170320cf1dd8SToby Isaac PetscDualSpace Q, subQ; 170420cf1dd8SToby Isaac PetscQuadrature subq; 170520cf1dd8SToby Isaac PetscInt dim, Nc; 170620cf1dd8SToby Isaac 170720cf1dd8SToby Isaac PetscFunctionBegin; 170820cf1dd8SToby Isaac PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1); 17094f572ea9SToby Isaac PetscAssertPointer(subfe, 3); 171020cf1dd8SToby Isaac if (height == 0) { 171120cf1dd8SToby Isaac *subfe = fe; 17123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 171320cf1dd8SToby Isaac } 17149566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 17159566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 17169566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &Nc)); 17179566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceQuadrature(fe, &subq)); 17189566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDimension(Q, &dim)); 17191dca8a05SBarry 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); 17209566063dSJacob Faibussowitsch if (!fe->subspaces) PetscCall(PetscCalloc1(dim, &fe->subspaces)); 172120cf1dd8SToby Isaac if (height <= dim) { 172220cf1dd8SToby Isaac if (!fe->subspaces[height - 1]) { 1723665f567fSMatthew G. Knepley PetscFE sub = NULL; 17243f6b16c7SMatthew G. Knepley const char *name; 172520cf1dd8SToby Isaac 17269566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetHeightSubspace(P, height, &subP)); 17279566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetHeightSubspace(Q, height, &subQ)); 1728665f567fSMatthew G. Knepley if (subQ) { 17292dce792eSToby Isaac PetscCall(PetscObjectReference((PetscObject)subP)); 17302dce792eSToby Isaac PetscCall(PetscObjectReference((PetscObject)subQ)); 17312dce792eSToby Isaac PetscCall(PetscObjectReference((PetscObject)subq)); 17322dce792eSToby Isaac PetscCall(PetscFECreateFromSpaces(subP, subQ, subq, NULL, &sub)); 17332dce792eSToby Isaac } 17342dce792eSToby Isaac if (sub) { 17359566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject)fe, &name)); 17362dce792eSToby Isaac if (name) PetscCall(PetscFESetName(sub, name)); 1737665f567fSMatthew G. Knepley } 173820cf1dd8SToby Isaac fe->subspaces[height - 1] = sub; 173920cf1dd8SToby Isaac } 174020cf1dd8SToby Isaac *subfe = fe->subspaces[height - 1]; 174120cf1dd8SToby Isaac } else { 174220cf1dd8SToby Isaac *subfe = NULL; 174320cf1dd8SToby Isaac } 17443ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 174520cf1dd8SToby Isaac } 174620cf1dd8SToby Isaac 174720cf1dd8SToby Isaac /*@ 1748a4e35b19SJacob Faibussowitsch PetscFERefine - Create a "refined" `PetscFE` object that refines the reference cell into 1749a4e35b19SJacob Faibussowitsch smaller copies. 175020cf1dd8SToby Isaac 175120f4b53cSBarry Smith Collective 175220cf1dd8SToby Isaac 175320cf1dd8SToby Isaac Input Parameter: 175420f4b53cSBarry Smith . fe - The initial `PetscFE` 175520cf1dd8SToby Isaac 175620cf1dd8SToby Isaac Output Parameter: 175720f4b53cSBarry Smith . feRef - The refined `PetscFE` 175820cf1dd8SToby Isaac 17592b99622eSMatthew G. Knepley Level: advanced 176020cf1dd8SToby Isaac 1761a4e35b19SJacob Faibussowitsch Notes: 1762a4e35b19SJacob Faibussowitsch This is typically used to generate a preconditioner for a higher order method from a lower order method on a 1763a4e35b19SJacob Faibussowitsch refined mesh having the same number of dofs (but more sparsity). It is also used to create an 1764a4e35b19SJacob Faibussowitsch interpolation between regularly refined meshes. 1765a4e35b19SJacob Faibussowitsch 1766db781477SPatrick Sanan .seealso: `PetscFEType`, `PetscFECreate()`, `PetscFESetType()` 176720cf1dd8SToby Isaac @*/ 1768d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFERefine(PetscFE fe, PetscFE *feRef) 1769d71ae5a4SJacob Faibussowitsch { 177020cf1dd8SToby Isaac PetscSpace P, Pref; 177120cf1dd8SToby Isaac PetscDualSpace Q, Qref; 177220cf1dd8SToby Isaac DM K, Kref; 177320cf1dd8SToby Isaac PetscQuadrature q, qref; 177420cf1dd8SToby Isaac const PetscReal *v0, *jac; 177520cf1dd8SToby Isaac PetscInt numComp, numSubelements; 17761ac17e89SToby Isaac PetscInt cStart, cEnd, c; 17771ac17e89SToby Isaac PetscDualSpace *cellSpaces; 177820cf1dd8SToby Isaac 177920cf1dd8SToby Isaac PetscFunctionBegin; 17809566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 17819566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 17829566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &q)); 17839566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(Q, &K)); 178420cf1dd8SToby Isaac /* Create space */ 17859566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)P)); 178620cf1dd8SToby Isaac Pref = P; 178720cf1dd8SToby Isaac /* Create dual space */ 17889566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDuplicate(Q, &Qref)); 17899566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetType(Qref, PETSCDUALSPACEREFINED)); 17909566063dSJacob Faibussowitsch PetscCall(DMRefine(K, PetscObjectComm((PetscObject)fe), &Kref)); 1791*e44f6aebSMatthew G. Knepley PetscCall(DMGetCoordinatesLocalSetUp(Kref)); 17929566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetDM(Qref, Kref)); 17939566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(Kref, 0, &cStart, &cEnd)); 17949566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(cEnd - cStart, &cellSpaces)); 17951ac17e89SToby Isaac /* TODO: fix for non-uniform refinement */ 17961ac17e89SToby Isaac for (c = 0; c < cEnd - cStart; c++) cellSpaces[c] = Q; 17979566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceRefinedSetCellSpaces(Qref, cellSpaces)); 17989566063dSJacob Faibussowitsch PetscCall(PetscFree(cellSpaces)); 17999566063dSJacob Faibussowitsch PetscCall(DMDestroy(&Kref)); 18009566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetUp(Qref)); 180120cf1dd8SToby Isaac /* Create element */ 18029566063dSJacob Faibussowitsch PetscCall(PetscFECreate(PetscObjectComm((PetscObject)fe), feRef)); 18039566063dSJacob Faibussowitsch PetscCall(PetscFESetType(*feRef, PETSCFECOMPOSITE)); 18049566063dSJacob Faibussowitsch PetscCall(PetscFESetBasisSpace(*feRef, Pref)); 18059566063dSJacob Faibussowitsch PetscCall(PetscFESetDualSpace(*feRef, Qref)); 18069566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &numComp)); 18079566063dSJacob Faibussowitsch PetscCall(PetscFESetNumComponents(*feRef, numComp)); 18089566063dSJacob Faibussowitsch PetscCall(PetscFESetUp(*feRef)); 18099566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pref)); 18109566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceDestroy(&Qref)); 181120cf1dd8SToby Isaac /* Create quadrature */ 18129566063dSJacob Faibussowitsch PetscCall(PetscFECompositeGetMapping(*feRef, &numSubelements, &v0, &jac, NULL)); 18139566063dSJacob Faibussowitsch PetscCall(PetscQuadratureExpandComposite(q, numSubelements, v0, jac, &qref)); 18149566063dSJacob Faibussowitsch PetscCall(PetscFESetQuadrature(*feRef, qref)); 18159566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&qref)); 18163ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 181720cf1dd8SToby Isaac } 181820cf1dd8SToby Isaac 1819d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscFESetDefaultName_Private(PetscFE fe) 1820d71ae5a4SJacob Faibussowitsch { 18217c48043bSMatthew G. Knepley PetscSpace P; 18227c48043bSMatthew G. Knepley PetscDualSpace Q; 18237c48043bSMatthew G. Knepley DM K; 18247c48043bSMatthew G. Knepley DMPolytopeType ct; 18257c48043bSMatthew G. Knepley PetscInt degree; 18267c48043bSMatthew G. Knepley char name[64]; 18277c48043bSMatthew G. Knepley 18287c48043bSMatthew G. Knepley PetscFunctionBegin; 18297c48043bSMatthew G. Knepley PetscCall(PetscFEGetBasisSpace(fe, &P)); 18307c48043bSMatthew G. Knepley PetscCall(PetscSpaceGetDegree(P, °ree, NULL)); 18317c48043bSMatthew G. Knepley PetscCall(PetscFEGetDualSpace(fe, &Q)); 18327c48043bSMatthew G. Knepley PetscCall(PetscDualSpaceGetDM(Q, &K)); 18337c48043bSMatthew G. Knepley PetscCall(DMPlexGetCellType(K, 0, &ct)); 18347c48043bSMatthew G. Knepley switch (ct) { 18357c48043bSMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 18367c48043bSMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 18377c48043bSMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 18387c48043bSMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 18397c48043bSMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 1840d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_QUAD_PRISM_TENSOR: 1841d71ae5a4SJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "Q%" PetscInt_FMT, degree)); 1842d71ae5a4SJacob Faibussowitsch break; 18437c48043bSMatthew G. Knepley case DM_POLYTOPE_TRIANGLE: 1844d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_TETRAHEDRON: 1845d71ae5a4SJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "P%" PetscInt_FMT, degree)); 1846d71ae5a4SJacob Faibussowitsch break; 18477c48043bSMatthew G. Knepley case DM_POLYTOPE_TRI_PRISM: 1848d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_TRI_PRISM_TENSOR: 1849d71ae5a4SJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "P%" PetscInt_FMT "xQ%" PetscInt_FMT, degree, degree)); 1850d71ae5a4SJacob Faibussowitsch break; 1851d71ae5a4SJacob Faibussowitsch default: 1852d71ae5a4SJacob Faibussowitsch PetscCall(PetscSNPrintf(name, sizeof(name), "FE")); 18537c48043bSMatthew G. Knepley } 18547c48043bSMatthew G. Knepley PetscCall(PetscFESetName(fe, name)); 18553ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 18567c48043bSMatthew G. Knepley } 18577c48043bSMatthew G. Knepley 18587c48043bSMatthew G. Knepley /*@ 1859dce8aebaSBarry Smith PetscFECreateFromSpaces - Create a `PetscFE` from the basis and dual spaces 18607c48043bSMatthew G. Knepley 18617c48043bSMatthew G. Knepley Collective 18627c48043bSMatthew G. Knepley 18637c48043bSMatthew G. Knepley Input Parameters: 18647c48043bSMatthew G. Knepley + P - The basis space 18657c48043bSMatthew G. Knepley . Q - The dual space 18667c48043bSMatthew G. Knepley . q - The cell quadrature 18677c48043bSMatthew G. Knepley - fq - The face quadrature 18687c48043bSMatthew G. Knepley 18697c48043bSMatthew G. Knepley Output Parameter: 187020f4b53cSBarry Smith . fem - The `PetscFE` object 18717c48043bSMatthew G. Knepley 18727c48043bSMatthew G. Knepley Level: beginner 18737c48043bSMatthew G. Knepley 1874dce8aebaSBarry Smith Note: 1875dce8aebaSBarry Smith 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. 1876dce8aebaSBarry Smith 1877dce8aebaSBarry Smith .seealso: `PetscFE`, `PetscSpace`, `PetscDualSpace`, `PetscQuadrature`, 1878dce8aebaSBarry Smith `PetscFECreateLagrangeByCell()`, `PetscFECreateDefault()`, `PetscFECreateByCell()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 18797c48043bSMatthew G. Knepley @*/ 1880d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateFromSpaces(PetscSpace P, PetscDualSpace Q, PetscQuadrature q, PetscQuadrature fq, PetscFE *fem) 1881d71ae5a4SJacob Faibussowitsch { 18827c48043bSMatthew G. Knepley PetscInt Nc; 18832dce792eSToby Isaac PetscInt p_Ns = -1, p_Nc = -1, q_Ns = -1, q_Nc = -1; 18842dce792eSToby Isaac PetscBool p_is_uniform_sum = PETSC_FALSE, p_interleave_basis = PETSC_FALSE, p_interleave_components = PETSC_FALSE; 18852dce792eSToby Isaac PetscBool q_is_uniform_sum = PETSC_FALSE, q_interleave_basis = PETSC_FALSE, q_interleave_components = PETSC_FALSE; 18867c48043bSMatthew G. Knepley const char *prefix; 18877c48043bSMatthew G. Knepley 18887c48043bSMatthew G. Knepley PetscFunctionBegin; 18892dce792eSToby Isaac PetscCall(PetscObjectTypeCompare((PetscObject)P, PETSCSPACESUM, &p_is_uniform_sum)); 18902dce792eSToby Isaac if (p_is_uniform_sum) { 18912dce792eSToby Isaac PetscSpace subsp_0 = NULL; 18922dce792eSToby Isaac PetscCall(PetscSpaceSumGetNumSubspaces(P, &p_Ns)); 18932dce792eSToby Isaac PetscCall(PetscSpaceGetNumComponents(P, &p_Nc)); 18942dce792eSToby Isaac PetscCall(PetscSpaceSumGetConcatenate(P, &p_is_uniform_sum)); 18952dce792eSToby Isaac PetscCall(PetscSpaceSumGetInterleave(P, &p_interleave_basis, &p_interleave_components)); 18962dce792eSToby Isaac for (PetscInt s = 0; s < p_Ns; s++) { 18972dce792eSToby Isaac PetscSpace subsp; 18982dce792eSToby Isaac 18992dce792eSToby Isaac PetscCall(PetscSpaceSumGetSubspace(P, s, &subsp)); 19002dce792eSToby Isaac if (!s) { 19012dce792eSToby Isaac subsp_0 = subsp; 19022dce792eSToby Isaac } else if (subsp != subsp_0) { 19032dce792eSToby Isaac p_is_uniform_sum = PETSC_FALSE; 19042dce792eSToby Isaac } 19052dce792eSToby Isaac } 19062dce792eSToby Isaac } 19072dce792eSToby Isaac PetscCall(PetscObjectTypeCompare((PetscObject)Q, PETSCDUALSPACESUM, &q_is_uniform_sum)); 19082dce792eSToby Isaac if (q_is_uniform_sum) { 19092dce792eSToby Isaac PetscDualSpace subsp_0 = NULL; 19102dce792eSToby Isaac PetscCall(PetscDualSpaceSumGetNumSubspaces(Q, &q_Ns)); 19112dce792eSToby Isaac PetscCall(PetscDualSpaceGetNumComponents(Q, &q_Nc)); 19122dce792eSToby Isaac PetscCall(PetscDualSpaceSumGetConcatenate(Q, &q_is_uniform_sum)); 19132dce792eSToby Isaac PetscCall(PetscDualSpaceSumGetInterleave(Q, &q_interleave_basis, &q_interleave_components)); 19142dce792eSToby Isaac for (PetscInt s = 0; s < q_Ns; s++) { 19152dce792eSToby Isaac PetscDualSpace subsp; 19162dce792eSToby Isaac 19172dce792eSToby Isaac PetscCall(PetscDualSpaceSumGetSubspace(Q, s, &subsp)); 19182dce792eSToby Isaac if (!s) { 19192dce792eSToby Isaac subsp_0 = subsp; 19202dce792eSToby Isaac } else if (subsp != subsp_0) { 19212dce792eSToby Isaac q_is_uniform_sum = PETSC_FALSE; 19222dce792eSToby Isaac } 19232dce792eSToby Isaac } 19242dce792eSToby Isaac } 19252dce792eSToby Isaac if (p_is_uniform_sum && q_is_uniform_sum && (p_interleave_basis == q_interleave_basis) && (p_interleave_components == q_interleave_components) && (p_Ns == q_Ns) && (p_Nc == q_Nc)) { 19262dce792eSToby Isaac PetscSpace scalar_space; 19272dce792eSToby Isaac PetscDualSpace scalar_dspace; 19282dce792eSToby Isaac PetscFE scalar_fe; 19292dce792eSToby Isaac 19302dce792eSToby Isaac PetscCall(PetscSpaceSumGetSubspace(P, 0, &scalar_space)); 19312dce792eSToby Isaac PetscCall(PetscDualSpaceSumGetSubspace(Q, 0, &scalar_dspace)); 19322dce792eSToby Isaac PetscCall(PetscObjectReference((PetscObject)scalar_space)); 19332dce792eSToby Isaac PetscCall(PetscObjectReference((PetscObject)scalar_dspace)); 19342dce792eSToby Isaac PetscCall(PetscObjectReference((PetscObject)q)); 19352dce792eSToby Isaac PetscCall(PetscObjectReference((PetscObject)fq)); 19362dce792eSToby Isaac PetscCall(PetscFECreateFromSpaces(scalar_space, scalar_dspace, q, fq, &scalar_fe)); 19372dce792eSToby Isaac PetscCall(PetscFECreateVector(scalar_fe, p_Ns, p_interleave_basis, p_interleave_components, fem)); 19382dce792eSToby Isaac PetscCall(PetscFEDestroy(&scalar_fe)); 19392dce792eSToby Isaac } else { 19407c48043bSMatthew G. Knepley PetscCall(PetscFECreate(PetscObjectComm((PetscObject)P), fem)); 19417c48043bSMatthew G. Knepley PetscCall(PetscFESetType(*fem, PETSCFEBASIC)); 19422dce792eSToby Isaac } 19437c48043bSMatthew G. Knepley PetscCall(PetscSpaceGetNumComponents(P, &Nc)); 19447c48043bSMatthew G. Knepley PetscCall(PetscFESetNumComponents(*fem, Nc)); 19452dce792eSToby Isaac PetscCall(PetscFESetBasisSpace(*fem, P)); 19462dce792eSToby Isaac PetscCall(PetscFESetDualSpace(*fem, Q)); 19472dce792eSToby Isaac PetscCall(PetscObjectGetOptionsPrefix((PetscObject)P, &prefix)); 19482dce792eSToby Isaac PetscCall(PetscObjectSetOptionsPrefix((PetscObject)*fem, prefix)); 19497c48043bSMatthew G. Knepley PetscCall(PetscFESetUp(*fem)); 19507c48043bSMatthew G. Knepley PetscCall(PetscSpaceDestroy(&P)); 19517c48043bSMatthew G. Knepley PetscCall(PetscDualSpaceDestroy(&Q)); 19527c48043bSMatthew G. Knepley PetscCall(PetscFESetQuadrature(*fem, q)); 19537c48043bSMatthew G. Knepley PetscCall(PetscFESetFaceQuadrature(*fem, fq)); 19547c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&q)); 19557c48043bSMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&fq)); 19567c48043bSMatthew G. Knepley PetscCall(PetscFESetDefaultName_Private(*fem)); 19573ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 19587c48043bSMatthew G. Knepley } 19597c48043bSMatthew G. Knepley 1960d71ae5a4SJacob 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) 1961d71ae5a4SJacob Faibussowitsch { 19622df84da0SMatthew G. Knepley DM K; 19632df84da0SMatthew G. Knepley PetscSpace P; 19642df84da0SMatthew G. Knepley PetscDualSpace Q; 19657c48043bSMatthew G. Knepley PetscQuadrature q, fq; 19662df84da0SMatthew G. Knepley PetscBool tensor; 19672df84da0SMatthew G. Knepley 19682df84da0SMatthew G. Knepley PetscFunctionBegin; 19694f572ea9SToby Isaac if (prefix) PetscAssertPointer(prefix, 5); 19704f572ea9SToby Isaac PetscAssertPointer(fem, 9); 19712df84da0SMatthew G. Knepley switch (ct) { 19722df84da0SMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 19732df84da0SMatthew G. Knepley case DM_POLYTOPE_POINT_PRISM_TENSOR: 19742df84da0SMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 19752df84da0SMatthew G. Knepley case DM_POLYTOPE_SEG_PRISM_TENSOR: 19762df84da0SMatthew G. Knepley case DM_POLYTOPE_HEXAHEDRON: 1977d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_QUAD_PRISM_TENSOR: 1978d71ae5a4SJacob Faibussowitsch tensor = PETSC_TRUE; 1979d71ae5a4SJacob Faibussowitsch break; 1980d71ae5a4SJacob Faibussowitsch default: 1981d71ae5a4SJacob Faibussowitsch tensor = PETSC_FALSE; 19822df84da0SMatthew G. Knepley } 19832df84da0SMatthew G. Knepley /* Create space */ 19849566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &P)); 19859566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(P, PETSCSPACEPOLYNOMIAL)); 19869566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject)P, prefix)); 19879566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(P, tensor)); 19889566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(P, Nc)); 19899566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(P, dim)); 19902df84da0SMatthew G. Knepley if (degree >= 0) { 19919566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(P, degree, PETSC_DETERMINE)); 1992cfd33b42SLisandro Dalcin if (ct == DM_POLYTOPE_TRI_PRISM || ct == DM_POLYTOPE_TRI_PRISM_TENSOR) { 19932df84da0SMatthew G. Knepley PetscSpace Pend, Pside; 19942df84da0SMatthew G. Knepley 19952dce792eSToby Isaac PetscCall(PetscSpaceSetNumComponents(P, 1)); 19969566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &Pend)); 19979566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(Pend, PETSCSPACEPOLYNOMIAL)); 19989566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(Pend, PETSC_FALSE)); 19992dce792eSToby Isaac PetscCall(PetscSpaceSetNumComponents(Pend, 1)); 20009566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(Pend, dim - 1)); 20019566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(Pend, degree, PETSC_DETERMINE)); 20029566063dSJacob Faibussowitsch PetscCall(PetscSpaceCreate(comm, &Pside)); 20039566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(Pside, PETSCSPACEPOLYNOMIAL)); 20049566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialSetTensor(Pside, PETSC_FALSE)); 20059566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumComponents(Pside, 1)); 20069566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetNumVariables(Pside, 1)); 20079566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetDegree(Pside, degree, PETSC_DETERMINE)); 20089566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetType(P, PETSCSPACETENSOR)); 20099566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetNumSubspaces(P, 2)); 20109566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetSubspace(P, 0, Pend)); 20119566063dSJacob Faibussowitsch PetscCall(PetscSpaceTensorSetSubspace(P, 1, Pside)); 20129566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pend)); 20139566063dSJacob Faibussowitsch PetscCall(PetscSpaceDestroy(&Pside)); 20142dce792eSToby Isaac 20152dce792eSToby Isaac if (Nc > 1) { 20162dce792eSToby Isaac PetscSpace scalar_P = P; 20172dce792eSToby Isaac 20182dce792eSToby Isaac PetscCall(PetscSpaceCreate(comm, &P)); 20192dce792eSToby Isaac PetscCall(PetscSpaceSetNumVariables(P, dim)); 20202dce792eSToby Isaac PetscCall(PetscSpaceSetNumComponents(P, Nc)); 20212dce792eSToby Isaac PetscCall(PetscSpaceSetType(P, PETSCSPACESUM)); 20222dce792eSToby Isaac PetscCall(PetscSpaceSumSetNumSubspaces(P, Nc)); 20232dce792eSToby Isaac PetscCall(PetscSpaceSumSetConcatenate(P, PETSC_TRUE)); 20242dce792eSToby Isaac PetscCall(PetscSpaceSumSetInterleave(P, PETSC_TRUE, PETSC_FALSE)); 20252dce792eSToby Isaac for (PetscInt i = 0; i < Nc; i++) PetscCall(PetscSpaceSumSetSubspace(P, i, scalar_P)); 20262dce792eSToby Isaac PetscCall(PetscSpaceDestroy(&scalar_P)); 20272dce792eSToby Isaac } 20282df84da0SMatthew G. Knepley } 20292df84da0SMatthew G. Knepley } 20309566063dSJacob Faibussowitsch if (setFromOptions) PetscCall(PetscSpaceSetFromOptions(P)); 20319566063dSJacob Faibussowitsch PetscCall(PetscSpaceSetUp(P)); 20329566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetDegree(P, °ree, NULL)); 20339566063dSJacob Faibussowitsch PetscCall(PetscSpacePolynomialGetTensor(P, &tensor)); 20349566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetNumComponents(P, &Nc)); 20352df84da0SMatthew G. Knepley /* Create dual space */ 20369566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceCreate(comm, &Q)); 20379566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetType(Q, PETSCDUALSPACELAGRANGE)); 20389566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject)Q, prefix)); 20399566063dSJacob Faibussowitsch PetscCall(DMPlexCreateReferenceCell(PETSC_COMM_SELF, ct, &K)); 20409566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetDM(Q, K)); 20419566063dSJacob Faibussowitsch PetscCall(DMDestroy(&K)); 20429566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetNumComponents(Q, Nc)); 20439566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetOrder(Q, degree)); 20449566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceLagrangeSetTensor(Q, (tensor || (ct == DM_POLYTOPE_TRI_PRISM)) ? PETSC_TRUE : PETSC_FALSE)); 20459566063dSJacob Faibussowitsch if (setFromOptions) PetscCall(PetscDualSpaceSetFromOptions(Q)); 20469566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceSetUp(Q)); 20477c48043bSMatthew G. Knepley /* Create quadrature */ 20482df84da0SMatthew G. Knepley qorder = qorder >= 0 ? qorder : degree; 20492df84da0SMatthew G. Knepley if (setFromOptions) { 20507c48043bSMatthew G. Knepley PetscObjectOptionsBegin((PetscObject)P); 20519566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-petscfe_default_quadrature_order", "Quadrature order is one less than quadrature points per edge", "PetscFECreateDefault", qorder, &qorder, NULL, 0)); 2052d0609cedSBarry Smith PetscOptionsEnd(); 20532df84da0SMatthew G. Knepley } 20544366bac7SMatthew G. Knepley PetscCall(PetscDTCreateDefaultQuadrature(ct, qorder, &q, &fq)); 20557c48043bSMatthew G. Knepley /* Create finite element */ 20567c48043bSMatthew G. Knepley PetscCall(PetscFECreateFromSpaces(P, Q, q, fq, fem)); 20577c48043bSMatthew G. Knepley if (setFromOptions) PetscCall(PetscFESetFromOptions(*fem)); 20583ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 20592df84da0SMatthew G. Knepley } 20602df84da0SMatthew G. Knepley 206120cf1dd8SToby Isaac /*@C 206220f4b53cSBarry Smith PetscFECreateDefault - Create a `PetscFE` for basic FEM computation 206320cf1dd8SToby Isaac 2064d083f849SBarry Smith Collective 206520cf1dd8SToby Isaac 206620cf1dd8SToby Isaac Input Parameters: 20677be5e748SToby Isaac + comm - The MPI comm 206820cf1dd8SToby Isaac . dim - The spatial dimension 206920cf1dd8SToby Isaac . Nc - The number of components 207020cf1dd8SToby Isaac . isSimplex - Flag for simplex reference cell, otherwise its a tensor product 207120f4b53cSBarry Smith . prefix - The options prefix, or `NULL` 207220f4b53cSBarry Smith - qorder - The quadrature order or `PETSC_DETERMINE` to use `PetscSpace` polynomial degree 207320cf1dd8SToby Isaac 207420cf1dd8SToby Isaac Output Parameter: 207520f4b53cSBarry Smith . fem - The `PetscFE` object 207620cf1dd8SToby Isaac 2077dce8aebaSBarry Smith Level: beginner 2078dce8aebaSBarry Smith 2079e703855dSMatthew G. Knepley Note: 20808f2aacc6SMatthew 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. 2081e703855dSMatthew G. Knepley 2082db781477SPatrick Sanan .seealso: `PetscFECreateLagrange()`, `PetscFECreateByCell()`, `PetscSpaceSetFromOptions()`, `PetscDualSpaceSetFromOptions()`, `PetscFESetFromOptions()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 208320cf1dd8SToby Isaac @*/ 2084d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateDefault(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, const char prefix[], PetscInt qorder, PetscFE *fem) 2085d71ae5a4SJacob Faibussowitsch { 208620cf1dd8SToby Isaac PetscFunctionBegin; 20879566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, DMPolytopeTypeSimpleShape(dim, isSimplex), prefix, PETSC_DECIDE, qorder, PETSC_TRUE, fem)); 20883ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 208920cf1dd8SToby Isaac } 20902df84da0SMatthew G. Knepley 20912df84da0SMatthew G. Knepley /*@C 209220f4b53cSBarry Smith PetscFECreateByCell - Create a `PetscFE` for basic FEM computation 20932df84da0SMatthew G. Knepley 20942df84da0SMatthew G. Knepley Collective 20952df84da0SMatthew G. Knepley 20962df84da0SMatthew G. Knepley Input Parameters: 20972df84da0SMatthew G. Knepley + comm - The MPI comm 20982df84da0SMatthew G. Knepley . dim - The spatial dimension 20992df84da0SMatthew G. Knepley . Nc - The number of components 21002df84da0SMatthew G. Knepley . ct - The celltype of the reference cell 210120f4b53cSBarry Smith . prefix - The options prefix, or `NULL` 210220f4b53cSBarry Smith - qorder - The quadrature order or `PETSC_DETERMINE` to use `PetscSpace` polynomial degree 21032df84da0SMatthew G. Knepley 21042df84da0SMatthew G. Knepley Output Parameter: 210520f4b53cSBarry Smith . fem - The `PetscFE` object 21062df84da0SMatthew G. Knepley 2107dce8aebaSBarry Smith Level: beginner 2108dce8aebaSBarry Smith 21092df84da0SMatthew G. Knepley Note: 21102df84da0SMatthew 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. 21112df84da0SMatthew G. Knepley 2112db781477SPatrick Sanan .seealso: `PetscFECreateDefault()`, `PetscFECreateLagrange()`, `PetscSpaceSetFromOptions()`, `PetscDualSpaceSetFromOptions()`, `PetscFESetFromOptions()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 21132df84da0SMatthew G. Knepley @*/ 2114d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateByCell(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, const char prefix[], PetscInt qorder, PetscFE *fem) 2115d71ae5a4SJacob Faibussowitsch { 21162df84da0SMatthew G. Knepley PetscFunctionBegin; 21179566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, ct, prefix, PETSC_DECIDE, qorder, PETSC_TRUE, fem)); 21183ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 211920cf1dd8SToby Isaac } 21203f6b16c7SMatthew G. Knepley 2121e703855dSMatthew G. Knepley /*@ 212220f4b53cSBarry Smith PetscFECreateLagrange - Create a `PetscFE` for the basic Lagrange space of degree k 2123e703855dSMatthew G. Knepley 2124e703855dSMatthew G. Knepley Collective 2125e703855dSMatthew G. Knepley 2126e703855dSMatthew G. Knepley Input Parameters: 2127e703855dSMatthew G. Knepley + comm - The MPI comm 2128e703855dSMatthew G. Knepley . dim - The spatial dimension 2129e703855dSMatthew G. Knepley . Nc - The number of components 2130e703855dSMatthew G. Knepley . isSimplex - Flag for simplex reference cell, otherwise its a tensor product 2131e703855dSMatthew G. Knepley . k - The degree k of the space 213220f4b53cSBarry Smith - qorder - The quadrature order or `PETSC_DETERMINE` to use `PetscSpace` polynomial degree 2133e703855dSMatthew G. Knepley 2134e703855dSMatthew G. Knepley Output Parameter: 213520f4b53cSBarry Smith . fem - The `PetscFE` object 2136e703855dSMatthew G. Knepley 2137e703855dSMatthew G. Knepley Level: beginner 2138e703855dSMatthew G. Knepley 2139dce8aebaSBarry Smith Note: 2140e703855dSMatthew 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. 2141e703855dSMatthew G. Knepley 2142db781477SPatrick Sanan .seealso: `PetscFECreateLagrangeByCell()`, `PetscFECreateDefault()`, `PetscFECreateByCell()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 2143e703855dSMatthew G. Knepley @*/ 2144d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateLagrange(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, PetscInt k, PetscInt qorder, PetscFE *fem) 2145d71ae5a4SJacob Faibussowitsch { 2146e703855dSMatthew G. Knepley PetscFunctionBegin; 21479566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, DMPolytopeTypeSimpleShape(dim, isSimplex), NULL, k, qorder, PETSC_FALSE, fem)); 21483ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2149e703855dSMatthew G. Knepley } 21502df84da0SMatthew G. Knepley 21512df84da0SMatthew G. Knepley /*@ 215220f4b53cSBarry Smith PetscFECreateLagrangeByCell - Create a `PetscFE` for the basic Lagrange space of degree k 21532df84da0SMatthew G. Knepley 21542df84da0SMatthew G. Knepley Collective 21552df84da0SMatthew G. Knepley 21562df84da0SMatthew G. Knepley Input Parameters: 21572df84da0SMatthew G. Knepley + comm - The MPI comm 21582df84da0SMatthew G. Knepley . dim - The spatial dimension 21592df84da0SMatthew G. Knepley . Nc - The number of components 21602df84da0SMatthew G. Knepley . ct - The celltype of the reference cell 21612df84da0SMatthew G. Knepley . k - The degree k of the space 216220f4b53cSBarry Smith - qorder - The quadrature order or `PETSC_DETERMINE` to use `PetscSpace` polynomial degree 21632df84da0SMatthew G. Knepley 21642df84da0SMatthew G. Knepley Output Parameter: 216520f4b53cSBarry Smith . fem - The `PetscFE` object 21662df84da0SMatthew G. Knepley 21672df84da0SMatthew G. Knepley Level: beginner 21682df84da0SMatthew G. Knepley 2169dce8aebaSBarry Smith Note: 21702df84da0SMatthew 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. 21712df84da0SMatthew G. Knepley 2172db781477SPatrick Sanan .seealso: `PetscFECreateLagrange()`, `PetscFECreateDefault()`, `PetscFECreateByCell()`, `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 21732df84da0SMatthew G. Knepley @*/ 2174d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateLagrangeByCell(MPI_Comm comm, PetscInt dim, PetscInt Nc, DMPolytopeType ct, PetscInt k, PetscInt qorder, PetscFE *fem) 2175d71ae5a4SJacob Faibussowitsch { 21762df84da0SMatthew G. Knepley PetscFunctionBegin; 21779566063dSJacob Faibussowitsch PetscCall(PetscFECreate_Internal(comm, dim, Nc, ct, NULL, k, qorder, PETSC_FALSE, fem)); 21783ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2179e703855dSMatthew G. Knepley } 2180e703855dSMatthew G. Knepley 21813f6b16c7SMatthew G. Knepley /*@C 218220f4b53cSBarry Smith PetscFESetName - Names the `PetscFE` and its subobjects 21833f6b16c7SMatthew G. Knepley 218420f4b53cSBarry Smith Not Collective 21853f6b16c7SMatthew G. Knepley 21863f6b16c7SMatthew G. Knepley Input Parameters: 218720f4b53cSBarry Smith + fe - The `PetscFE` 21883f6b16c7SMatthew G. Knepley - name - The name 21893f6b16c7SMatthew G. Knepley 21902b99622eSMatthew G. Knepley Level: intermediate 21913f6b16c7SMatthew G. Knepley 2192db781477SPatrick Sanan .seealso: `PetscFECreate()`, `PetscSpaceCreate()`, `PetscDualSpaceCreate()` 21933f6b16c7SMatthew G. Knepley @*/ 2194d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFESetName(PetscFE fe, const char name[]) 2195d71ae5a4SJacob Faibussowitsch { 21963f6b16c7SMatthew G. Knepley PetscSpace P; 21973f6b16c7SMatthew G. Knepley PetscDualSpace Q; 21983f6b16c7SMatthew G. Knepley 21993f6b16c7SMatthew G. Knepley PetscFunctionBegin; 22009566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &P)); 22019566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &Q)); 22029566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject)fe, name)); 22039566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject)P, name)); 22049566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject)Q, name)); 22053ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 22063f6b16c7SMatthew G. Knepley } 2207a8f1f9e5SMatthew G. Knepley 2208d71ae5a4SJacob 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[]) 2209d71ae5a4SJacob Faibussowitsch { 2210f9244615SMatthew G. Knepley PetscInt dOffset = 0, fOffset = 0, f, g; 2211a8f1f9e5SMatthew G. Knepley 2212a8f1f9e5SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 221326add6b9SMatthew G. Knepley PetscCheck(r < T[f]->Nr, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Replica number %" PetscInt_FMT " should be in [0, %" PetscInt_FMT ")", r, T[f]->Nr); 221426add6b9SMatthew G. Knepley PetscCheck(q < T[f]->Np, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Point number %" PetscInt_FMT " should be in [0, %" PetscInt_FMT ")", q, T[f]->Np); 2215a8f1f9e5SMatthew G. Knepley PetscFE fe; 2216f9244615SMatthew G. Knepley const PetscInt k = ds->jetDegree[f]; 2217ef0bb6c7SMatthew G. Knepley const PetscInt cdim = T[f]->cdim; 22182b6f951bSStefano Zampini const PetscInt dE = fegeom->dimEmbed; 2219ef0bb6c7SMatthew G. Knepley const PetscInt Nq = T[f]->Np; 2220ef0bb6c7SMatthew G. Knepley const PetscInt Nbf = T[f]->Nb; 2221ef0bb6c7SMatthew G. Knepley const PetscInt Ncf = T[f]->Nc; 2222ef0bb6c7SMatthew G. Knepley const PetscReal *Bq = &T[f]->T[0][(r * Nq + q) * Nbf * Ncf]; 2223ef0bb6c7SMatthew G. Knepley const PetscReal *Dq = &T[f]->T[1][(r * Nq + q) * Nbf * Ncf * cdim]; 2224f9244615SMatthew G. Knepley const PetscReal *Hq = k > 1 ? &T[f]->T[2][(r * Nq + q) * Nbf * Ncf * cdim * cdim] : NULL; 2225f9244615SMatthew G. Knepley PetscInt hOffset = 0, b, c, d; 2226a8f1f9e5SMatthew G. Knepley 22279566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, f, (PetscObject *)&fe)); 2228a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u[fOffset + c] = 0.0; 22292b6f951bSStefano Zampini for (d = 0; d < dE * Ncf; ++d) u_x[fOffset * dE + d] = 0.0; 2230a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2231a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2232a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 2233a8f1f9e5SMatthew G. Knepley 2234a8f1f9e5SMatthew G. Knepley u[fOffset + c] += Bq[cidx] * coefficients[dOffset + b]; 22352b6f951bSStefano Zampini for (d = 0; d < cdim; ++d) u_x[(fOffset + c) * dE + d] += Dq[cidx * cdim + d] * coefficients[dOffset + b]; 2236a8f1f9e5SMatthew G. Knepley } 2237a8f1f9e5SMatthew G. Knepley } 2238f9244615SMatthew G. Knepley if (k > 1) { 22392b6f951bSStefano Zampini for (g = 0; g < Nf; ++g) hOffset += T[g]->Nc * dE; 22402b6f951bSStefano Zampini for (d = 0; d < dE * dE * Ncf; ++d) u_x[hOffset + fOffset * dE * dE + d] = 0.0; 2241f9244615SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2242f9244615SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2243f9244615SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 2244f9244615SMatthew G. Knepley 22452b6f951bSStefano Zampini for (d = 0; d < cdim * cdim; ++d) u_x[hOffset + (fOffset + c) * dE * dE + d] += Hq[cidx * cdim * cdim + d] * coefficients[dOffset + b]; 2246f9244615SMatthew G. Knepley } 2247f9244615SMatthew G. Knepley } 22482b6f951bSStefano Zampini PetscCall(PetscFEPushforwardHessian(fe, fegeom, 1, &u_x[hOffset + fOffset * dE * dE])); 2249f9244615SMatthew G. Knepley } 22509566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u[fOffset])); 22512b6f951bSStefano Zampini PetscCall(PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset * dE])); 2252a8f1f9e5SMatthew G. Knepley if (u_t) { 2253a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u_t[fOffset + c] = 0.0; 2254a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 2255a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 2256a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 2257a8f1f9e5SMatthew G. Knepley 2258a8f1f9e5SMatthew G. Knepley u_t[fOffset + c] += Bq[cidx] * coefficients_t[dOffset + b]; 2259a8f1f9e5SMatthew G. Knepley } 2260a8f1f9e5SMatthew G. Knepley } 22619566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset])); 2262a8f1f9e5SMatthew G. Knepley } 2263a8f1f9e5SMatthew G. Knepley fOffset += Ncf; 2264a8f1f9e5SMatthew G. Knepley dOffset += Nbf; 2265a8f1f9e5SMatthew G. Knepley } 22663ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 2267a8f1f9e5SMatthew G. Knepley } 2268a8f1f9e5SMatthew G. Knepley 226907218a29SMatthew G. Knepley PetscErrorCode PetscFEEvaluateFieldJets_Hybrid_Internal(PetscDS ds, PetscInt Nf, PetscInt rc, PetscInt qc, PetscTabulation Tab[], const PetscInt rf[], const PetscInt qf[], PetscTabulation Tabf[], PetscFEGeom *fegeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscScalar u[], PetscScalar u_x[], PetscScalar u_t[]) 2270d71ae5a4SJacob Faibussowitsch { 22715fedec97SMatthew G. Knepley PetscInt dOffset = 0, fOffset = 0, f, g; 227227f02ce8SMatthew G. Knepley 22735fedec97SMatthew G. Knepley /* f is the field number in the DS, g is the field number in u[] */ 22745fedec97SMatthew G. Knepley for (f = 0, g = 0; f < Nf; ++f) { 22755fedec97SMatthew G. Knepley PetscBool isCohesive; 22765fedec97SMatthew G. Knepley PetscInt Ns, s; 22775fedec97SMatthew G. Knepley 227807218a29SMatthew G. Knepley if (!Tab[f]) continue; 22799566063dSJacob Faibussowitsch PetscCall(PetscDSGetCohesive(ds, f, &isCohesive)); 22805fedec97SMatthew G. Knepley Ns = isCohesive ? 1 : 2; 228107218a29SMatthew G. Knepley { 228207218a29SMatthew G. Knepley PetscTabulation T = isCohesive ? Tab[f] : Tabf[f]; 228307218a29SMatthew G. Knepley PetscFE fe = (PetscFE)ds->disc[f]; 228407218a29SMatthew G. Knepley const PetscInt dEt = T->cdim; 228507218a29SMatthew G. Knepley const PetscInt dE = fegeom->dimEmbed; 228607218a29SMatthew G. Knepley const PetscInt Nq = T->Np; 228707218a29SMatthew G. Knepley const PetscInt Nbf = T->Nb; 228807218a29SMatthew G. Knepley const PetscInt Ncf = T->Nc; 228907218a29SMatthew G. Knepley 22905fedec97SMatthew G. Knepley for (s = 0; s < Ns; ++s, ++g) { 229107218a29SMatthew G. Knepley const PetscInt r = isCohesive ? rc : rf[s]; 229207218a29SMatthew G. Knepley const PetscInt q = isCohesive ? qc : qf[s]; 229307218a29SMatthew G. Knepley const PetscReal *Bq = &T->T[0][(r * Nq + q) * Nbf * Ncf]; 229407218a29SMatthew G. Knepley const PetscReal *Dq = &T->T[1][(r * Nq + q) * Nbf * Ncf * dEt]; 229527f02ce8SMatthew G. Knepley PetscInt b, c, d; 229627f02ce8SMatthew G. Knepley 229707218a29SMatthew G. Knepley PetscCheck(r < T->Nr, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field %" PetscInt_FMT " Side %" PetscInt_FMT " Replica number %" PetscInt_FMT " should be in [0, %" PetscInt_FMT ")", f, s, r, T->Nr); 229807218a29SMatthew G. Knepley PetscCheck(q < T->Np, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field %" PetscInt_FMT " Side %" PetscInt_FMT " Point number %" PetscInt_FMT " should be in [0, %" PetscInt_FMT ")", f, s, q, T->Np); 229927f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u[fOffset + c] = 0.0; 23009ee2af8cSMatthew G. Knepley for (d = 0; d < dE * Ncf; ++d) u_x[fOffset * dE + d] = 0.0; 230127f02ce8SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 230227f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 230327f02ce8SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 230427f02ce8SMatthew G. Knepley 230527f02ce8SMatthew G. Knepley u[fOffset + c] += Bq[cidx] * coefficients[dOffset + b]; 23069ee2af8cSMatthew G. Knepley for (d = 0; d < dEt; ++d) u_x[(fOffset + c) * dE + d] += Dq[cidx * dEt + d] * coefficients[dOffset + b]; 230727f02ce8SMatthew G. Knepley } 230827f02ce8SMatthew G. Knepley } 23099566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u[fOffset])); 23109566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset * dE])); 231127f02ce8SMatthew G. Knepley if (u_t) { 231227f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u_t[fOffset + c] = 0.0; 231327f02ce8SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 231427f02ce8SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 231527f02ce8SMatthew G. Knepley const PetscInt cidx = b * Ncf + c; 231627f02ce8SMatthew G. Knepley 231727f02ce8SMatthew G. Knepley u_t[fOffset + c] += Bq[cidx] * coefficients_t[dOffset + b]; 231827f02ce8SMatthew G. Knepley } 231927f02ce8SMatthew G. Knepley } 23209566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset])); 232127f02ce8SMatthew G. Knepley } 232227f02ce8SMatthew G. Knepley fOffset += Ncf; 232327f02ce8SMatthew G. Knepley dOffset += Nbf; 232427f02ce8SMatthew G. Knepley } 2325665f567fSMatthew G. Knepley } 232607218a29SMatthew G. Knepley } 23273ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 232827f02ce8SMatthew G. Knepley } 232927f02ce8SMatthew G. Knepley 2330d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEEvaluateFaceFields_Internal(PetscDS prob, PetscInt field, PetscInt faceLoc, const PetscScalar coefficients[], PetscScalar u[]) 2331d71ae5a4SJacob Faibussowitsch { 2332a8f1f9e5SMatthew G. Knepley PetscFE fe; 2333ef0bb6c7SMatthew G. Knepley PetscTabulation Tc; 2334ef0bb6c7SMatthew G. Knepley PetscInt b, c; 2335a8f1f9e5SMatthew G. Knepley 23363ba16761SJacob Faibussowitsch if (!prob) return PETSC_SUCCESS; 23379566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, field, (PetscObject *)&fe)); 23389566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceCentroidTabulation(fe, &Tc)); 2339ef0bb6c7SMatthew G. Knepley { 2340ef0bb6c7SMatthew G. Knepley const PetscReal *faceBasis = Tc->T[0]; 2341ef0bb6c7SMatthew G. Knepley const PetscInt Nb = Tc->Nb; 2342ef0bb6c7SMatthew G. Knepley const PetscInt Nc = Tc->Nc; 2343ef0bb6c7SMatthew G. Knepley 2344ad540459SPierre Jolivet for (c = 0; c < Nc; ++c) u[c] = 0.0; 2345a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2346ad540459SPierre Jolivet for (c = 0; c < Nc; ++c) u[c] += coefficients[b] * faceBasis[(faceLoc * Nb + b) * Nc + c]; 2347a8f1f9e5SMatthew G. Knepley } 2348ef0bb6c7SMatthew G. Knepley } 23493ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 2350a8f1f9e5SMatthew G. Knepley } 2351a8f1f9e5SMatthew G. Knepley 2352d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEUpdateElementVec_Internal(PetscFE fe, PetscTabulation T, PetscInt r, PetscScalar tmpBasis[], PetscScalar tmpBasisDer[], PetscInt e, PetscFEGeom *fegeom, PetscScalar f0[], PetscScalar f1[], PetscScalar elemVec[]) 2353d71ae5a4SJacob Faibussowitsch { 23546587ee25SMatthew G. Knepley PetscFEGeom pgeom; 2355bc3a64adSMatthew G. Knepley const PetscInt dEt = T->cdim; 2356bc3a64adSMatthew G. Knepley const PetscInt dE = fegeom->dimEmbed; 2357ef0bb6c7SMatthew G. Knepley const PetscInt Nq = T->Np; 2358ef0bb6c7SMatthew G. Knepley const PetscInt Nb = T->Nb; 2359ef0bb6c7SMatthew G. Knepley const PetscInt Nc = T->Nc; 2360ef0bb6c7SMatthew G. Knepley const PetscReal *basis = &T->T[0][r * Nq * Nb * Nc]; 2361bc3a64adSMatthew G. Knepley const PetscReal *basisDer = &T->T[1][r * Nq * Nb * Nc * dEt]; 2362a8f1f9e5SMatthew G. Knepley PetscInt q, b, c, d; 2363a8f1f9e5SMatthew G. Knepley 2364a8f1f9e5SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 2365a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2366a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2367a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b * Nc + c; 2368a8f1f9e5SMatthew G. Knepley 2369a8f1f9e5SMatthew G. Knepley tmpBasis[bcidx] = basis[q * Nb * Nc + bcidx]; 2370bc3a64adSMatthew G. Knepley for (d = 0; d < dEt; ++d) tmpBasisDer[bcidx * dE + d] = basisDer[q * Nb * Nc * dEt + bcidx * dEt + d]; 23719ee2af8cSMatthew G. Knepley for (d = dEt; d < dE; ++d) tmpBasisDer[bcidx * dE + d] = 0.0; 2372a8f1f9e5SMatthew G. Knepley } 2373a8f1f9e5SMatthew G. Knepley } 23749566063dSJacob Faibussowitsch PetscCall(PetscFEGeomGetCellPoint(fegeom, e, q, &pgeom)); 23759566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, &pgeom, Nb, tmpBasis)); 23769566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(fe, &pgeom, Nb, tmpBasisDer)); 2377a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 2378a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 2379a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b * Nc + c; 2380a8f1f9e5SMatthew G. Knepley const PetscInt qcidx = q * Nc + c; 2381a8f1f9e5SMatthew G. Knepley 2382a8f1f9e5SMatthew G. Knepley elemVec[b] += tmpBasis[bcidx] * f0[qcidx]; 238327f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) elemVec[b] += tmpBasisDer[bcidx * dE + d] * f1[qcidx * dE + d]; 238427f02ce8SMatthew G. Knepley } 238527f02ce8SMatthew G. Knepley } 238627f02ce8SMatthew G. Knepley } 23873ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 238827f02ce8SMatthew G. Knepley } 238927f02ce8SMatthew G. Knepley 2390d71ae5a4SJacob 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[]) 2391d71ae5a4SJacob Faibussowitsch { 239227f02ce8SMatthew G. Knepley const PetscInt dE = T->cdim; 239327f02ce8SMatthew G. Knepley const PetscInt Nq = T->Np; 239427f02ce8SMatthew G. Knepley const PetscInt Nb = T->Nb; 239527f02ce8SMatthew G. Knepley const PetscInt Nc = T->Nc; 239627f02ce8SMatthew G. Knepley const PetscReal *basis = &T->T[0][r * Nq * Nb * Nc]; 239727f02ce8SMatthew G. Knepley const PetscReal *basisDer = &T->T[1][r * Nq * Nb * Nc * dE]; 2398c2b7495fSMatthew G. Knepley PetscInt q, b, c, d; 239927f02ce8SMatthew G. Knepley 240027f02ce8SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 240127f02ce8SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 240227f02ce8SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 240327f02ce8SMatthew G. Knepley const PetscInt bcidx = b * Nc + c; 240427f02ce8SMatthew G. Knepley 240527f02ce8SMatthew G. Knepley tmpBasis[bcidx] = basis[q * Nb * Nc + bcidx]; 240627f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) tmpBasisDer[bcidx * dE + d] = basisDer[q * Nb * Nc * dE + bcidx * dE + d]; 240727f02ce8SMatthew G. Knepley } 240827f02ce8SMatthew G. Knepley } 24099566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(fe, fegeom, Nb, tmpBasis)); 24102b6f951bSStefano Zampini // TODO This is currently broken since we do not pull the geometry down to the lower dimension 24112b6f951bSStefano Zampini // PetscCall(PetscFEPushforwardGradient(fe, fegeom, Nb, tmpBasisDer)); 241227f02ce8SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 241327f02ce8SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 241427f02ce8SMatthew G. Knepley const PetscInt bcidx = b * Nc + c; 2415c2b7495fSMatthew G. Knepley const PetscInt qcidx = q * Nc + c; 241627f02ce8SMatthew G. Knepley 241727f02ce8SMatthew G. Knepley elemVec[Nb * s + b] += tmpBasis[bcidx] * f0[qcidx]; 241827f02ce8SMatthew G. Knepley for (d = 0; d < dE; ++d) elemVec[Nb * s + b] += tmpBasisDer[bcidx * dE + d] * f1[qcidx * dE + d]; 241927f02ce8SMatthew G. Knepley } 2420a8f1f9e5SMatthew G. Knepley } 2421a8f1f9e5SMatthew G. Knepley } 24223ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 2423a8f1f9e5SMatthew G. Knepley } 2424a8f1f9e5SMatthew G. Knepley 2425d71ae5a4SJacob 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[]) 2426d71ae5a4SJacob Faibussowitsch { 24272b6f951bSStefano Zampini const PetscInt cdim = TI->cdim; 24282b6f951bSStefano Zampini const PetscInt dE = fegeom->dimEmbed; 2429ef0bb6c7SMatthew G. Knepley const PetscInt NqI = TI->Np; 2430ef0bb6c7SMatthew G. Knepley const PetscInt NbI = TI->Nb; 2431ef0bb6c7SMatthew G. Knepley const PetscInt NcI = TI->Nc; 2432ef0bb6c7SMatthew G. Knepley const PetscReal *basisI = &TI->T[0][(r * NqI + q) * NbI * NcI]; 24332b6f951bSStefano Zampini const PetscReal *basisDerI = &TI->T[1][(r * NqI + q) * NbI * NcI * cdim]; 2434ef0bb6c7SMatthew G. Knepley const PetscInt NqJ = TJ->Np; 2435ef0bb6c7SMatthew G. Knepley const PetscInt NbJ = TJ->Nb; 2436ef0bb6c7SMatthew G. Knepley const PetscInt NcJ = TJ->Nc; 2437ef0bb6c7SMatthew G. Knepley const PetscReal *basisJ = &TJ->T[0][(r * NqJ + q) * NbJ * NcJ]; 24382b6f951bSStefano Zampini const PetscReal *basisDerJ = &TJ->T[1][(r * NqJ + q) * NbJ * NcJ * cdim]; 2439a8f1f9e5SMatthew G. Knepley PetscInt f, fc, g, gc, df, dg; 2440a8f1f9e5SMatthew G. Knepley 2441a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 2442a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 2443a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f * NcI + fc; /* Test function basis index */ 2444a8f1f9e5SMatthew G. Knepley 2445a8f1f9e5SMatthew G. Knepley tmpBasisI[fidx] = basisI[fidx]; 24462b6f951bSStefano Zampini for (df = 0; df < cdim; ++df) tmpBasisDerI[fidx * dE + df] = basisDerI[fidx * cdim + df]; 2447a8f1f9e5SMatthew G. Knepley } 2448a8f1f9e5SMatthew G. Knepley } 24499566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feI, fegeom, NbI, tmpBasisI)); 24509566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI)); 2451a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 2452a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 2453a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g * NcJ + gc; /* Trial function basis index */ 2454a8f1f9e5SMatthew G. Knepley 2455a8f1f9e5SMatthew G. Knepley tmpBasisJ[gidx] = basisJ[gidx]; 24562b6f951bSStefano Zampini for (dg = 0; dg < cdim; ++dg) tmpBasisDerJ[gidx * dE + dg] = basisDerJ[gidx * cdim + dg]; 2457a8f1f9e5SMatthew G. Knepley } 2458a8f1f9e5SMatthew G. Knepley } 24599566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ)); 24609566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ)); 2461a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 2462a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 2463a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f * NcI + fc; /* Test function basis index */ 2464a8f1f9e5SMatthew G. Knepley const PetscInt i = offsetI + f; /* Element matrix row */ 2465a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 2466a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 2467a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g * NcJ + gc; /* Trial function basis index */ 2468a8f1f9e5SMatthew G. Knepley const PetscInt j = offsetJ + g; /* Element matrix column */ 2469a8f1f9e5SMatthew G. Knepley const PetscInt fOff = eOffset + i * totDim + j; 2470a8f1f9e5SMatthew G. Knepley 2471a8f1f9e5SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx] * g0[fc * NcJ + gc] * tmpBasisJ[gidx]; 247227f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) { 247327f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx] * g1[(fc * NcJ + gc) * dE + df] * tmpBasisDerJ[gidx * dE + df]; 247427f02ce8SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx * dE + df] * g2[(fc * NcJ + gc) * dE + df] * tmpBasisJ[gidx]; 2475ad540459SPierre 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]; 247627f02ce8SMatthew G. Knepley } 247727f02ce8SMatthew G. Knepley } 247827f02ce8SMatthew G. Knepley } 247927f02ce8SMatthew G. Knepley } 248027f02ce8SMatthew G. Knepley } 24813ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 248227f02ce8SMatthew G. Knepley } 248327f02ce8SMatthew G. Knepley 2484d71ae5a4SJacob 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[]) 2485d71ae5a4SJacob Faibussowitsch { 2486665f567fSMatthew G. Knepley const PetscInt dE = TI->cdim; 2487665f567fSMatthew G. Knepley const PetscInt NqI = TI->Np; 2488665f567fSMatthew G. Knepley const PetscInt NbI = TI->Nb; 2489665f567fSMatthew G. Knepley const PetscInt NcI = TI->Nc; 2490665f567fSMatthew G. Knepley const PetscReal *basisI = &TI->T[0][(r * NqI + q) * NbI * NcI]; 2491665f567fSMatthew G. Knepley const PetscReal *basisDerI = &TI->T[1][(r * NqI + q) * NbI * NcI * dE]; 2492665f567fSMatthew G. Knepley const PetscInt NqJ = TJ->Np; 2493665f567fSMatthew G. Knepley const PetscInt NbJ = TJ->Nb; 2494665f567fSMatthew G. Knepley const PetscInt NcJ = TJ->Nc; 2495665f567fSMatthew G. Knepley const PetscReal *basisJ = &TJ->T[0][(r * NqJ + q) * NbJ * NcJ]; 2496665f567fSMatthew G. Knepley const PetscReal *basisDerJ = &TJ->T[1][(r * NqJ + q) * NbJ * NcJ * dE]; 24975fedec97SMatthew G. Knepley const PetscInt so = isHybridI ? 0 : s; 24985fedec97SMatthew G. Knepley const PetscInt to = isHybridJ ? 0 : s; 24995fedec97SMatthew G. Knepley PetscInt f, fc, g, gc, df, dg; 250027f02ce8SMatthew G. Knepley 250127f02ce8SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 250227f02ce8SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 250327f02ce8SMatthew G. Knepley const PetscInt fidx = f * NcI + fc; /* Test function basis index */ 250427f02ce8SMatthew G. Knepley 250527f02ce8SMatthew G. Knepley tmpBasisI[fidx] = basisI[fidx]; 2506665f567fSMatthew G. Knepley for (df = 0; df < dE; ++df) tmpBasisDerI[fidx * dE + df] = basisDerI[fidx * dE + df]; 250727f02ce8SMatthew G. Knepley } 250827f02ce8SMatthew G. Knepley } 25099566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feI, fegeom, NbI, tmpBasisI)); 25109566063dSJacob Faibussowitsch PetscCall(PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI)); 251127f02ce8SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 251227f02ce8SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 251327f02ce8SMatthew G. Knepley const PetscInt gidx = g * NcJ + gc; /* Trial function basis index */ 251427f02ce8SMatthew G. Knepley 251527f02ce8SMatthew G. Knepley tmpBasisJ[gidx] = basisJ[gidx]; 2516665f567fSMatthew G. Knepley for (dg = 0; dg < dE; ++dg) tmpBasisDerJ[gidx * dE + dg] = basisDerJ[gidx * dE + dg]; 251727f02ce8SMatthew G. Knepley } 251827f02ce8SMatthew G. Knepley } 25199566063dSJacob Faibussowitsch PetscCall(PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ)); 25202b6f951bSStefano Zampini // TODO This is currently broken since we do not pull the geometry down to the lower dimension 25212b6f951bSStefano Zampini // PetscCall(PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ)); 252227f02ce8SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 252327f02ce8SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 252427f02ce8SMatthew G. Knepley const PetscInt fidx = f * NcI + fc; /* Test function basis index */ 25255fedec97SMatthew G. Knepley const PetscInt i = offsetI + NbI * so + f; /* Element matrix row */ 252627f02ce8SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 252727f02ce8SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 252827f02ce8SMatthew G. Knepley const PetscInt gidx = g * NcJ + gc; /* Trial function basis index */ 25295fedec97SMatthew G. Knepley const PetscInt j = offsetJ + NbJ * to + g; /* Element matrix column */ 253027f02ce8SMatthew G. Knepley const PetscInt fOff = eOffset + i * totDim + j; 253127f02ce8SMatthew G. Knepley 25325fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx] * g0[fc * NcJ + gc] * tmpBasisJ[gidx]; 253327f02ce8SMatthew G. Knepley for (df = 0; df < dE; ++df) { 25345fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx] * g1[(fc * NcJ + gc) * dE + df] * tmpBasisDerJ[gidx * dE + df]; 25355fedec97SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx * dE + df] * g2[(fc * NcJ + gc) * dE + df] * tmpBasisJ[gidx]; 2536ad540459SPierre 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]; 2537a8f1f9e5SMatthew G. Knepley } 2538a8f1f9e5SMatthew G. Knepley } 2539a8f1f9e5SMatthew G. Knepley } 2540a8f1f9e5SMatthew G. Knepley } 2541a8f1f9e5SMatthew G. Knepley } 25423ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 2543a8f1f9e5SMatthew G. Knepley } 2544c9ba7969SMatthew G. Knepley 2545d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFECreateCellGeometry(PetscFE fe, PetscQuadrature quad, PetscFEGeom *cgeom) 2546d71ae5a4SJacob Faibussowitsch { 2547c9ba7969SMatthew G. Knepley PetscDualSpace dsp; 2548c9ba7969SMatthew G. Knepley DM dm; 2549c9ba7969SMatthew G. Knepley PetscQuadrature quadDef; 2550c9ba7969SMatthew G. Knepley PetscInt dim, cdim, Nq; 2551c9ba7969SMatthew G. Knepley 2552c9ba7969SMatthew G. Knepley PetscFunctionBegin; 25539566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(fe, &dsp)); 25549566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp, &dm)); 25559566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 25569566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDim(dm, &cdim)); 25579566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &quadDef)); 2558c9ba7969SMatthew G. Knepley quad = quad ? quad : quadDef; 25599566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(quad, NULL, NULL, &Nq, NULL, NULL)); 25609566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq * cdim, &cgeom->v)); 25619566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq * cdim * cdim, &cgeom->J)); 25629566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq * cdim * cdim, &cgeom->invJ)); 25639566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq, &cgeom->detJ)); 2564c9ba7969SMatthew G. Knepley cgeom->dim = dim; 2565c9ba7969SMatthew G. Knepley cgeom->dimEmbed = cdim; 2566c9ba7969SMatthew G. Knepley cgeom->numCells = 1; 2567c9ba7969SMatthew G. Knepley cgeom->numPoints = Nq; 25689566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(dm, 0, quad, cgeom->v, cgeom->J, cgeom->invJ, cgeom->detJ)); 25693ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2570c9ba7969SMatthew G. Knepley } 2571c9ba7969SMatthew G. Knepley 2572d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscFEDestroyCellGeometry(PetscFE fe, PetscFEGeom *cgeom) 2573d71ae5a4SJacob Faibussowitsch { 2574c9ba7969SMatthew G. Knepley PetscFunctionBegin; 25759566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->v)); 25769566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->J)); 25779566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->invJ)); 25789566063dSJacob Faibussowitsch PetscCall(PetscFree(cgeom->detJ)); 25793ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2580c9ba7969SMatthew G. Knepley } 2581