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 5320cf1dd8SToby Isaac PetscFunctionList PetscFEList = NULL; 5420cf1dd8SToby Isaac PetscBool PetscFERegisterAllCalled = PETSC_FALSE; 5520cf1dd8SToby Isaac 5620cf1dd8SToby Isaac /*@C 5720cf1dd8SToby Isaac PetscFERegister - Adds a new PetscFE implementation 5820cf1dd8SToby Isaac 5920cf1dd8SToby Isaac Not Collective 6020cf1dd8SToby Isaac 6120cf1dd8SToby Isaac Input Parameters: 6220cf1dd8SToby Isaac + name - The name of a new user-defined creation routine 6320cf1dd8SToby Isaac - create_func - The creation routine itself 6420cf1dd8SToby Isaac 6520cf1dd8SToby Isaac Notes: 6620cf1dd8SToby Isaac PetscFERegister() may be called multiple times to add several user-defined PetscFEs 6720cf1dd8SToby Isaac 6820cf1dd8SToby Isaac Sample usage: 6920cf1dd8SToby Isaac .vb 7020cf1dd8SToby Isaac PetscFERegister("my_fe", MyPetscFECreate); 7120cf1dd8SToby Isaac .ve 7220cf1dd8SToby Isaac 7320cf1dd8SToby Isaac Then, your PetscFE type can be chosen with the procedural interface via 7420cf1dd8SToby Isaac .vb 7520cf1dd8SToby Isaac PetscFECreate(MPI_Comm, PetscFE *); 7620cf1dd8SToby Isaac PetscFESetType(PetscFE, "my_fe"); 7720cf1dd8SToby Isaac .ve 7820cf1dd8SToby Isaac or at runtime via the option 7920cf1dd8SToby Isaac .vb 8020cf1dd8SToby Isaac -petscfe_type my_fe 8120cf1dd8SToby Isaac .ve 8220cf1dd8SToby Isaac 8320cf1dd8SToby Isaac Level: advanced 8420cf1dd8SToby Isaac 8520cf1dd8SToby Isaac .seealso: PetscFERegisterAll(), PetscFERegisterDestroy() 8620cf1dd8SToby Isaac 8720cf1dd8SToby Isaac @*/ 8820cf1dd8SToby Isaac PetscErrorCode PetscFERegister(const char sname[], PetscErrorCode (*function)(PetscFE)) 8920cf1dd8SToby Isaac { 9020cf1dd8SToby Isaac PetscErrorCode ierr; 9120cf1dd8SToby Isaac 9220cf1dd8SToby Isaac PetscFunctionBegin; 9320cf1dd8SToby Isaac ierr = PetscFunctionListAdd(&PetscFEList, sname, function);CHKERRQ(ierr); 9420cf1dd8SToby Isaac PetscFunctionReturn(0); 9520cf1dd8SToby Isaac } 9620cf1dd8SToby Isaac 9720cf1dd8SToby Isaac /*@C 9820cf1dd8SToby Isaac PetscFESetType - Builds a particular PetscFE 9920cf1dd8SToby Isaac 100d083f849SBarry Smith Collective on fem 10120cf1dd8SToby Isaac 10220cf1dd8SToby Isaac Input Parameters: 10320cf1dd8SToby Isaac + fem - The PetscFE object 10420cf1dd8SToby Isaac - name - The kind of FEM space 10520cf1dd8SToby Isaac 10620cf1dd8SToby Isaac Options Database Key: 10720cf1dd8SToby Isaac . -petscfe_type <type> - Sets the PetscFE type; use -help for a list of available types 10820cf1dd8SToby Isaac 10920cf1dd8SToby Isaac Level: intermediate 11020cf1dd8SToby Isaac 11120cf1dd8SToby Isaac .seealso: PetscFEGetType(), PetscFECreate() 11220cf1dd8SToby Isaac @*/ 11320cf1dd8SToby Isaac PetscErrorCode PetscFESetType(PetscFE fem, PetscFEType name) 11420cf1dd8SToby Isaac { 11520cf1dd8SToby Isaac PetscErrorCode (*r)(PetscFE); 11620cf1dd8SToby Isaac PetscBool match; 11720cf1dd8SToby Isaac PetscErrorCode ierr; 11820cf1dd8SToby Isaac 11920cf1dd8SToby Isaac PetscFunctionBegin; 12020cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 12120cf1dd8SToby Isaac ierr = PetscObjectTypeCompare((PetscObject) fem, name, &match);CHKERRQ(ierr); 12220cf1dd8SToby Isaac if (match) PetscFunctionReturn(0); 12320cf1dd8SToby Isaac 12420cf1dd8SToby Isaac if (!PetscFERegisterAllCalled) {ierr = PetscFERegisterAll();CHKERRQ(ierr);} 12520cf1dd8SToby Isaac ierr = PetscFunctionListFind(PetscFEList, name, &r);CHKERRQ(ierr); 12620cf1dd8SToby Isaac if (!r) SETERRQ1(PetscObjectComm((PetscObject) fem), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscFE type: %s", name); 12720cf1dd8SToby Isaac 12820cf1dd8SToby Isaac if (fem->ops->destroy) { 12920cf1dd8SToby Isaac ierr = (*fem->ops->destroy)(fem);CHKERRQ(ierr); 13020cf1dd8SToby Isaac fem->ops->destroy = NULL; 13120cf1dd8SToby Isaac } 13220cf1dd8SToby Isaac ierr = (*r)(fem);CHKERRQ(ierr); 13320cf1dd8SToby Isaac ierr = PetscObjectChangeTypeName((PetscObject) fem, name);CHKERRQ(ierr); 13420cf1dd8SToby Isaac PetscFunctionReturn(0); 13520cf1dd8SToby Isaac } 13620cf1dd8SToby Isaac 13720cf1dd8SToby Isaac /*@C 13820cf1dd8SToby Isaac PetscFEGetType - Gets the PetscFE type name (as a string) from the object. 13920cf1dd8SToby Isaac 14020cf1dd8SToby Isaac Not Collective 14120cf1dd8SToby Isaac 14220cf1dd8SToby Isaac Input Parameter: 14320cf1dd8SToby Isaac . fem - The PetscFE 14420cf1dd8SToby Isaac 14520cf1dd8SToby Isaac Output Parameter: 14620cf1dd8SToby Isaac . name - The PetscFE type name 14720cf1dd8SToby Isaac 14820cf1dd8SToby Isaac Level: intermediate 14920cf1dd8SToby Isaac 15020cf1dd8SToby Isaac .seealso: PetscFESetType(), PetscFECreate() 15120cf1dd8SToby Isaac @*/ 15220cf1dd8SToby Isaac PetscErrorCode PetscFEGetType(PetscFE fem, PetscFEType *name) 15320cf1dd8SToby Isaac { 15420cf1dd8SToby Isaac PetscErrorCode ierr; 15520cf1dd8SToby Isaac 15620cf1dd8SToby Isaac PetscFunctionBegin; 15720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 15820cf1dd8SToby Isaac PetscValidPointer(name, 2); 15920cf1dd8SToby Isaac if (!PetscFERegisterAllCalled) { 16020cf1dd8SToby Isaac ierr = PetscFERegisterAll();CHKERRQ(ierr); 16120cf1dd8SToby Isaac } 16220cf1dd8SToby Isaac *name = ((PetscObject) fem)->type_name; 16320cf1dd8SToby Isaac PetscFunctionReturn(0); 16420cf1dd8SToby Isaac } 16520cf1dd8SToby Isaac 16620cf1dd8SToby Isaac /*@C 16720cf1dd8SToby Isaac PetscFEView - Views a PetscFE 16820cf1dd8SToby Isaac 169d083f849SBarry Smith Collective on fem 17020cf1dd8SToby Isaac 17120cf1dd8SToby Isaac Input Parameter: 17220cf1dd8SToby Isaac + fem - the PetscFE object to view 173d9bac1caSLisandro Dalcin - viewer - the viewer 17420cf1dd8SToby Isaac 1752b99622eSMatthew G. Knepley Level: beginner 17620cf1dd8SToby Isaac 17720cf1dd8SToby Isaac .seealso PetscFEDestroy() 17820cf1dd8SToby Isaac @*/ 179d9bac1caSLisandro Dalcin PetscErrorCode PetscFEView(PetscFE fem, PetscViewer viewer) 18020cf1dd8SToby Isaac { 181d9bac1caSLisandro Dalcin PetscBool iascii; 18220cf1dd8SToby Isaac PetscErrorCode ierr; 18320cf1dd8SToby Isaac 18420cf1dd8SToby Isaac PetscFunctionBegin; 18520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 186d9bac1caSLisandro Dalcin if (viewer) PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 187d9bac1caSLisandro Dalcin if (!viewer) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) fem), &viewer);CHKERRQ(ierr);} 188d9bac1caSLisandro Dalcin ierr = PetscObjectPrintClassNamePrefixType((PetscObject)fem, viewer);CHKERRQ(ierr); 189d9bac1caSLisandro Dalcin ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 190d9bac1caSLisandro Dalcin if (fem->ops->view) {ierr = (*fem->ops->view)(fem, viewer);CHKERRQ(ierr);} 19120cf1dd8SToby Isaac PetscFunctionReturn(0); 19220cf1dd8SToby Isaac } 19320cf1dd8SToby Isaac 19420cf1dd8SToby Isaac /*@ 19520cf1dd8SToby Isaac PetscFESetFromOptions - sets parameters in a PetscFE from the options database 19620cf1dd8SToby Isaac 197d083f849SBarry Smith Collective on fem 19820cf1dd8SToby Isaac 19920cf1dd8SToby Isaac Input Parameter: 20020cf1dd8SToby Isaac . fem - the PetscFE object to set options for 20120cf1dd8SToby Isaac 20220cf1dd8SToby Isaac Options Database: 203a2b725a8SWilliam Gropp + -petscfe_num_blocks - the number of cell blocks to integrate concurrently 204a2b725a8SWilliam Gropp - -petscfe_num_batches - the number of cell batches to integrate serially 20520cf1dd8SToby Isaac 2062b99622eSMatthew G. Knepley Level: intermediate 20720cf1dd8SToby Isaac 20820cf1dd8SToby Isaac .seealso PetscFEView() 20920cf1dd8SToby Isaac @*/ 21020cf1dd8SToby Isaac PetscErrorCode PetscFESetFromOptions(PetscFE fem) 21120cf1dd8SToby Isaac { 21220cf1dd8SToby Isaac const char *defaultType; 21320cf1dd8SToby Isaac char name[256]; 21420cf1dd8SToby Isaac PetscBool flg; 21520cf1dd8SToby Isaac PetscErrorCode ierr; 21620cf1dd8SToby Isaac 21720cf1dd8SToby Isaac PetscFunctionBegin; 21820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 21920cf1dd8SToby Isaac if (!((PetscObject) fem)->type_name) { 22020cf1dd8SToby Isaac defaultType = PETSCFEBASIC; 22120cf1dd8SToby Isaac } else { 22220cf1dd8SToby Isaac defaultType = ((PetscObject) fem)->type_name; 22320cf1dd8SToby Isaac } 22420cf1dd8SToby Isaac if (!PetscFERegisterAllCalled) {ierr = PetscFERegisterAll();CHKERRQ(ierr);} 22520cf1dd8SToby Isaac 22620cf1dd8SToby Isaac ierr = PetscObjectOptionsBegin((PetscObject) fem);CHKERRQ(ierr); 22720cf1dd8SToby Isaac ierr = PetscOptionsFList("-petscfe_type", "Finite element space", "PetscFESetType", PetscFEList, defaultType, name, 256, &flg);CHKERRQ(ierr); 22820cf1dd8SToby Isaac if (flg) { 22920cf1dd8SToby Isaac ierr = PetscFESetType(fem, name);CHKERRQ(ierr); 23020cf1dd8SToby Isaac } else if (!((PetscObject) fem)->type_name) { 23120cf1dd8SToby Isaac ierr = PetscFESetType(fem, defaultType);CHKERRQ(ierr); 23220cf1dd8SToby Isaac } 2335a856986SBarry Smith ierr = PetscOptionsBoundedInt("-petscfe_num_blocks", "The number of cell blocks to integrate concurrently", "PetscSpaceSetTileSizes", fem->numBlocks, &fem->numBlocks, NULL,1);CHKERRQ(ierr); 2345a856986SBarry Smith ierr = PetscOptionsBoundedInt("-petscfe_num_batches", "The number of cell batches to integrate serially", "PetscSpaceSetTileSizes", fem->numBatches, &fem->numBatches, NULL,1);CHKERRQ(ierr); 23520cf1dd8SToby Isaac if (fem->ops->setfromoptions) { 23620cf1dd8SToby Isaac ierr = (*fem->ops->setfromoptions)(PetscOptionsObject,fem);CHKERRQ(ierr); 23720cf1dd8SToby Isaac } 23820cf1dd8SToby Isaac /* process any options handlers added with PetscObjectAddOptionsHandler() */ 23920cf1dd8SToby Isaac ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) fem);CHKERRQ(ierr); 24020cf1dd8SToby Isaac ierr = PetscOptionsEnd();CHKERRQ(ierr); 24120cf1dd8SToby Isaac ierr = PetscFEViewFromOptions(fem, NULL, "-petscfe_view");CHKERRQ(ierr); 24220cf1dd8SToby Isaac PetscFunctionReturn(0); 24320cf1dd8SToby Isaac } 24420cf1dd8SToby Isaac 24520cf1dd8SToby Isaac /*@C 24620cf1dd8SToby Isaac PetscFESetUp - Construct data structures for the PetscFE 24720cf1dd8SToby Isaac 248d083f849SBarry Smith Collective on fem 24920cf1dd8SToby Isaac 25020cf1dd8SToby Isaac Input Parameter: 25120cf1dd8SToby Isaac . fem - the PetscFE object to setup 25220cf1dd8SToby Isaac 2532b99622eSMatthew G. Knepley Level: intermediate 25420cf1dd8SToby Isaac 25520cf1dd8SToby Isaac .seealso PetscFEView(), PetscFEDestroy() 25620cf1dd8SToby Isaac @*/ 25720cf1dd8SToby Isaac PetscErrorCode PetscFESetUp(PetscFE fem) 25820cf1dd8SToby Isaac { 25920cf1dd8SToby Isaac PetscErrorCode ierr; 26020cf1dd8SToby Isaac 26120cf1dd8SToby Isaac PetscFunctionBegin; 26220cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 26320cf1dd8SToby Isaac if (fem->setupcalled) PetscFunctionReturn(0); 26420cf1dd8SToby Isaac fem->setupcalled = PETSC_TRUE; 26520cf1dd8SToby Isaac if (fem->ops->setup) {ierr = (*fem->ops->setup)(fem);CHKERRQ(ierr);} 26620cf1dd8SToby Isaac PetscFunctionReturn(0); 26720cf1dd8SToby Isaac } 26820cf1dd8SToby Isaac 26920cf1dd8SToby Isaac /*@ 27020cf1dd8SToby Isaac PetscFEDestroy - Destroys a PetscFE object 27120cf1dd8SToby Isaac 272d083f849SBarry Smith Collective on fem 27320cf1dd8SToby Isaac 27420cf1dd8SToby Isaac Input Parameter: 27520cf1dd8SToby Isaac . fem - the PetscFE object to destroy 27620cf1dd8SToby Isaac 2772b99622eSMatthew G. Knepley Level: beginner 27820cf1dd8SToby Isaac 27920cf1dd8SToby Isaac .seealso PetscFEView() 28020cf1dd8SToby Isaac @*/ 28120cf1dd8SToby Isaac PetscErrorCode PetscFEDestroy(PetscFE *fem) 28220cf1dd8SToby Isaac { 28320cf1dd8SToby Isaac PetscErrorCode ierr; 28420cf1dd8SToby Isaac 28520cf1dd8SToby Isaac PetscFunctionBegin; 28620cf1dd8SToby Isaac if (!*fem) PetscFunctionReturn(0); 28720cf1dd8SToby Isaac PetscValidHeaderSpecific((*fem), PETSCFE_CLASSID, 1); 28820cf1dd8SToby Isaac 28920cf1dd8SToby Isaac if (--((PetscObject)(*fem))->refct > 0) {*fem = 0; PetscFunctionReturn(0);} 29020cf1dd8SToby Isaac ((PetscObject) (*fem))->refct = 0; 29120cf1dd8SToby Isaac 29220cf1dd8SToby Isaac if ((*fem)->subspaces) { 29320cf1dd8SToby Isaac PetscInt dim, d; 29420cf1dd8SToby Isaac 29520cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension((*fem)->dualSpace, &dim);CHKERRQ(ierr); 29620cf1dd8SToby Isaac for (d = 0; d < dim; ++d) {ierr = PetscFEDestroy(&(*fem)->subspaces[d]);CHKERRQ(ierr);} 29720cf1dd8SToby Isaac } 29820cf1dd8SToby Isaac ierr = PetscFree((*fem)->subspaces);CHKERRQ(ierr); 29920cf1dd8SToby Isaac ierr = PetscFree((*fem)->invV);CHKERRQ(ierr); 30020cf1dd8SToby Isaac ierr = PetscFERestoreTabulation((*fem), 0, NULL, &(*fem)->B, &(*fem)->D, NULL /*&(*fem)->H*/);CHKERRQ(ierr); 30120cf1dd8SToby Isaac ierr = PetscFERestoreTabulation((*fem), 0, NULL, &(*fem)->Bf, &(*fem)->Df, NULL /*&(*fem)->Hf*/);CHKERRQ(ierr); 30220cf1dd8SToby Isaac ierr = PetscFERestoreTabulation((*fem), 0, NULL, &(*fem)->F, NULL, NULL);CHKERRQ(ierr); 30320cf1dd8SToby Isaac ierr = PetscSpaceDestroy(&(*fem)->basisSpace);CHKERRQ(ierr); 30420cf1dd8SToby Isaac ierr = PetscDualSpaceDestroy(&(*fem)->dualSpace);CHKERRQ(ierr); 30520cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&(*fem)->quadrature);CHKERRQ(ierr); 30620cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&(*fem)->faceQuadrature);CHKERRQ(ierr); 30720cf1dd8SToby Isaac 30820cf1dd8SToby Isaac if ((*fem)->ops->destroy) {ierr = (*(*fem)->ops->destroy)(*fem);CHKERRQ(ierr);} 30920cf1dd8SToby Isaac ierr = PetscHeaderDestroy(fem);CHKERRQ(ierr); 31020cf1dd8SToby Isaac PetscFunctionReturn(0); 31120cf1dd8SToby Isaac } 31220cf1dd8SToby Isaac 31320cf1dd8SToby Isaac /*@ 31420cf1dd8SToby Isaac PetscFECreate - Creates an empty PetscFE object. The type can then be set with PetscFESetType(). 31520cf1dd8SToby Isaac 316d083f849SBarry Smith Collective 31720cf1dd8SToby Isaac 31820cf1dd8SToby Isaac Input Parameter: 31920cf1dd8SToby Isaac . comm - The communicator for the PetscFE object 32020cf1dd8SToby Isaac 32120cf1dd8SToby Isaac Output Parameter: 32220cf1dd8SToby Isaac . fem - The PetscFE object 32320cf1dd8SToby Isaac 32420cf1dd8SToby Isaac Level: beginner 32520cf1dd8SToby Isaac 32620cf1dd8SToby Isaac .seealso: PetscFESetType(), PETSCFEGALERKIN 32720cf1dd8SToby Isaac @*/ 32820cf1dd8SToby Isaac PetscErrorCode PetscFECreate(MPI_Comm comm, PetscFE *fem) 32920cf1dd8SToby Isaac { 33020cf1dd8SToby Isaac PetscFE f; 33120cf1dd8SToby Isaac PetscErrorCode ierr; 33220cf1dd8SToby Isaac 33320cf1dd8SToby Isaac PetscFunctionBegin; 33420cf1dd8SToby Isaac PetscValidPointer(fem, 2); 33520cf1dd8SToby Isaac ierr = PetscCitationsRegister(FECitation,&FEcite);CHKERRQ(ierr); 33620cf1dd8SToby Isaac *fem = NULL; 33720cf1dd8SToby Isaac ierr = PetscFEInitializePackage();CHKERRQ(ierr); 33820cf1dd8SToby Isaac 33920cf1dd8SToby Isaac ierr = PetscHeaderCreate(f, PETSCFE_CLASSID, "PetscFE", "Finite Element", "PetscFE", comm, PetscFEDestroy, PetscFEView);CHKERRQ(ierr); 34020cf1dd8SToby Isaac 34120cf1dd8SToby Isaac f->basisSpace = NULL; 34220cf1dd8SToby Isaac f->dualSpace = NULL; 34320cf1dd8SToby Isaac f->numComponents = 1; 34420cf1dd8SToby Isaac f->subspaces = NULL; 34520cf1dd8SToby Isaac f->invV = NULL; 34620cf1dd8SToby Isaac f->B = NULL; 34720cf1dd8SToby Isaac f->D = NULL; 34820cf1dd8SToby Isaac f->H = NULL; 34920cf1dd8SToby Isaac f->Bf = NULL; 35020cf1dd8SToby Isaac f->Df = NULL; 35120cf1dd8SToby Isaac f->Hf = NULL; 352580bdb30SBarry Smith ierr = PetscArrayzero(&f->quadrature, 1);CHKERRQ(ierr); 353580bdb30SBarry Smith ierr = PetscArrayzero(&f->faceQuadrature, 1);CHKERRQ(ierr); 35420cf1dd8SToby Isaac f->blockSize = 0; 35520cf1dd8SToby Isaac f->numBlocks = 1; 35620cf1dd8SToby Isaac f->batchSize = 0; 35720cf1dd8SToby Isaac f->numBatches = 1; 35820cf1dd8SToby Isaac 35920cf1dd8SToby Isaac *fem = f; 36020cf1dd8SToby Isaac PetscFunctionReturn(0); 36120cf1dd8SToby Isaac } 36220cf1dd8SToby Isaac 36320cf1dd8SToby Isaac /*@ 36420cf1dd8SToby Isaac PetscFEGetSpatialDimension - Returns the spatial dimension of the element 36520cf1dd8SToby Isaac 36620cf1dd8SToby Isaac Not collective 36720cf1dd8SToby Isaac 36820cf1dd8SToby Isaac Input Parameter: 36920cf1dd8SToby Isaac . fem - The PetscFE object 37020cf1dd8SToby Isaac 37120cf1dd8SToby Isaac Output Parameter: 37220cf1dd8SToby Isaac . dim - The spatial dimension 37320cf1dd8SToby Isaac 37420cf1dd8SToby Isaac Level: intermediate 37520cf1dd8SToby Isaac 37620cf1dd8SToby Isaac .seealso: PetscFECreate() 37720cf1dd8SToby Isaac @*/ 37820cf1dd8SToby Isaac PetscErrorCode PetscFEGetSpatialDimension(PetscFE fem, PetscInt *dim) 37920cf1dd8SToby Isaac { 38020cf1dd8SToby Isaac DM dm; 38120cf1dd8SToby Isaac PetscErrorCode ierr; 38220cf1dd8SToby Isaac 38320cf1dd8SToby Isaac PetscFunctionBegin; 38420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 38520cf1dd8SToby Isaac PetscValidPointer(dim, 2); 38620cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(fem->dualSpace, &dm);CHKERRQ(ierr); 38720cf1dd8SToby Isaac ierr = DMGetDimension(dm, dim);CHKERRQ(ierr); 38820cf1dd8SToby Isaac PetscFunctionReturn(0); 38920cf1dd8SToby Isaac } 39020cf1dd8SToby Isaac 39120cf1dd8SToby Isaac /*@ 39220cf1dd8SToby Isaac PetscFESetNumComponents - Sets the number of components in the element 39320cf1dd8SToby Isaac 39420cf1dd8SToby Isaac Not collective 39520cf1dd8SToby Isaac 39620cf1dd8SToby Isaac Input Parameters: 39720cf1dd8SToby Isaac + fem - The PetscFE object 39820cf1dd8SToby Isaac - comp - The number of field components 39920cf1dd8SToby Isaac 40020cf1dd8SToby Isaac Level: intermediate 40120cf1dd8SToby Isaac 40220cf1dd8SToby Isaac .seealso: PetscFECreate() 40320cf1dd8SToby Isaac @*/ 40420cf1dd8SToby Isaac PetscErrorCode PetscFESetNumComponents(PetscFE fem, PetscInt comp) 40520cf1dd8SToby Isaac { 40620cf1dd8SToby Isaac PetscFunctionBegin; 40720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 40820cf1dd8SToby Isaac fem->numComponents = comp; 40920cf1dd8SToby Isaac PetscFunctionReturn(0); 41020cf1dd8SToby Isaac } 41120cf1dd8SToby Isaac 41220cf1dd8SToby Isaac /*@ 41320cf1dd8SToby Isaac PetscFEGetNumComponents - Returns the number of components in the element 41420cf1dd8SToby Isaac 41520cf1dd8SToby Isaac Not collective 41620cf1dd8SToby Isaac 41720cf1dd8SToby Isaac Input Parameter: 41820cf1dd8SToby Isaac . fem - The PetscFE object 41920cf1dd8SToby Isaac 42020cf1dd8SToby Isaac Output Parameter: 42120cf1dd8SToby Isaac . comp - The number of field components 42220cf1dd8SToby Isaac 42320cf1dd8SToby Isaac Level: intermediate 42420cf1dd8SToby Isaac 42520cf1dd8SToby Isaac .seealso: PetscFECreate() 42620cf1dd8SToby Isaac @*/ 42720cf1dd8SToby Isaac PetscErrorCode PetscFEGetNumComponents(PetscFE fem, PetscInt *comp) 42820cf1dd8SToby Isaac { 42920cf1dd8SToby Isaac PetscFunctionBegin; 43020cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 43120cf1dd8SToby Isaac PetscValidPointer(comp, 2); 43220cf1dd8SToby Isaac *comp = fem->numComponents; 43320cf1dd8SToby Isaac PetscFunctionReturn(0); 43420cf1dd8SToby Isaac } 43520cf1dd8SToby Isaac 43620cf1dd8SToby Isaac /*@ 43720cf1dd8SToby Isaac PetscFESetTileSizes - Sets the tile sizes for evaluation 43820cf1dd8SToby Isaac 43920cf1dd8SToby Isaac Not collective 44020cf1dd8SToby Isaac 44120cf1dd8SToby Isaac Input Parameters: 44220cf1dd8SToby Isaac + fem - The PetscFE object 44320cf1dd8SToby Isaac . blockSize - The number of elements in a block 44420cf1dd8SToby Isaac . numBlocks - The number of blocks in a batch 44520cf1dd8SToby Isaac . batchSize - The number of elements in a batch 44620cf1dd8SToby Isaac - numBatches - The number of batches in a chunk 44720cf1dd8SToby Isaac 44820cf1dd8SToby Isaac Level: intermediate 44920cf1dd8SToby Isaac 45020cf1dd8SToby Isaac .seealso: PetscFECreate() 45120cf1dd8SToby Isaac @*/ 45220cf1dd8SToby Isaac PetscErrorCode PetscFESetTileSizes(PetscFE fem, PetscInt blockSize, PetscInt numBlocks, PetscInt batchSize, PetscInt numBatches) 45320cf1dd8SToby Isaac { 45420cf1dd8SToby Isaac PetscFunctionBegin; 45520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 45620cf1dd8SToby Isaac fem->blockSize = blockSize; 45720cf1dd8SToby Isaac fem->numBlocks = numBlocks; 45820cf1dd8SToby Isaac fem->batchSize = batchSize; 45920cf1dd8SToby Isaac fem->numBatches = numBatches; 46020cf1dd8SToby Isaac PetscFunctionReturn(0); 46120cf1dd8SToby Isaac } 46220cf1dd8SToby Isaac 46320cf1dd8SToby Isaac /*@ 46420cf1dd8SToby Isaac PetscFEGetTileSizes - Returns the tile sizes for evaluation 46520cf1dd8SToby Isaac 46620cf1dd8SToby Isaac Not collective 46720cf1dd8SToby Isaac 46820cf1dd8SToby Isaac Input Parameter: 46920cf1dd8SToby Isaac . fem - The PetscFE object 47020cf1dd8SToby Isaac 47120cf1dd8SToby Isaac Output Parameters: 47220cf1dd8SToby Isaac + blockSize - The number of elements in a block 47320cf1dd8SToby Isaac . numBlocks - The number of blocks in a batch 47420cf1dd8SToby Isaac . batchSize - The number of elements in a batch 47520cf1dd8SToby Isaac - numBatches - The number of batches in a chunk 47620cf1dd8SToby Isaac 47720cf1dd8SToby Isaac Level: intermediate 47820cf1dd8SToby Isaac 47920cf1dd8SToby Isaac .seealso: PetscFECreate() 48020cf1dd8SToby Isaac @*/ 48120cf1dd8SToby Isaac PetscErrorCode PetscFEGetTileSizes(PetscFE fem, PetscInt *blockSize, PetscInt *numBlocks, PetscInt *batchSize, PetscInt *numBatches) 48220cf1dd8SToby Isaac { 48320cf1dd8SToby Isaac PetscFunctionBegin; 48420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 48520cf1dd8SToby Isaac if (blockSize) PetscValidPointer(blockSize, 2); 48620cf1dd8SToby Isaac if (numBlocks) PetscValidPointer(numBlocks, 3); 48720cf1dd8SToby Isaac if (batchSize) PetscValidPointer(batchSize, 4); 48820cf1dd8SToby Isaac if (numBatches) PetscValidPointer(numBatches, 5); 48920cf1dd8SToby Isaac if (blockSize) *blockSize = fem->blockSize; 49020cf1dd8SToby Isaac if (numBlocks) *numBlocks = fem->numBlocks; 49120cf1dd8SToby Isaac if (batchSize) *batchSize = fem->batchSize; 49220cf1dd8SToby Isaac if (numBatches) *numBatches = fem->numBatches; 49320cf1dd8SToby Isaac PetscFunctionReturn(0); 49420cf1dd8SToby Isaac } 49520cf1dd8SToby Isaac 49620cf1dd8SToby Isaac /*@ 49720cf1dd8SToby Isaac PetscFEGetBasisSpace - Returns the PetscSpace used for approximation of the solution 49820cf1dd8SToby Isaac 49920cf1dd8SToby Isaac Not collective 50020cf1dd8SToby Isaac 50120cf1dd8SToby Isaac Input Parameter: 50220cf1dd8SToby Isaac . fem - The PetscFE object 50320cf1dd8SToby Isaac 50420cf1dd8SToby Isaac Output Parameter: 50520cf1dd8SToby Isaac . sp - The PetscSpace object 50620cf1dd8SToby Isaac 50720cf1dd8SToby Isaac Level: intermediate 50820cf1dd8SToby Isaac 50920cf1dd8SToby Isaac .seealso: PetscFECreate() 51020cf1dd8SToby Isaac @*/ 51120cf1dd8SToby Isaac PetscErrorCode PetscFEGetBasisSpace(PetscFE fem, PetscSpace *sp) 51220cf1dd8SToby Isaac { 51320cf1dd8SToby Isaac PetscFunctionBegin; 51420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 51520cf1dd8SToby Isaac PetscValidPointer(sp, 2); 51620cf1dd8SToby Isaac *sp = fem->basisSpace; 51720cf1dd8SToby Isaac PetscFunctionReturn(0); 51820cf1dd8SToby Isaac } 51920cf1dd8SToby Isaac 52020cf1dd8SToby Isaac /*@ 52120cf1dd8SToby Isaac PetscFESetBasisSpace - Sets the PetscSpace used for approximation of the solution 52220cf1dd8SToby Isaac 52320cf1dd8SToby Isaac Not collective 52420cf1dd8SToby Isaac 52520cf1dd8SToby Isaac Input Parameters: 52620cf1dd8SToby Isaac + fem - The PetscFE object 52720cf1dd8SToby Isaac - sp - The PetscSpace object 52820cf1dd8SToby Isaac 52920cf1dd8SToby Isaac Level: intermediate 53020cf1dd8SToby Isaac 53120cf1dd8SToby Isaac .seealso: PetscFECreate() 53220cf1dd8SToby Isaac @*/ 53320cf1dd8SToby Isaac PetscErrorCode PetscFESetBasisSpace(PetscFE fem, PetscSpace sp) 53420cf1dd8SToby Isaac { 53520cf1dd8SToby Isaac PetscErrorCode ierr; 53620cf1dd8SToby Isaac 53720cf1dd8SToby Isaac PetscFunctionBegin; 53820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 53920cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 2); 54020cf1dd8SToby Isaac ierr = PetscSpaceDestroy(&fem->basisSpace);CHKERRQ(ierr); 54120cf1dd8SToby Isaac fem->basisSpace = sp; 54220cf1dd8SToby Isaac ierr = PetscObjectReference((PetscObject) fem->basisSpace);CHKERRQ(ierr); 54320cf1dd8SToby Isaac PetscFunctionReturn(0); 54420cf1dd8SToby Isaac } 54520cf1dd8SToby Isaac 54620cf1dd8SToby Isaac /*@ 54720cf1dd8SToby Isaac PetscFEGetDualSpace - Returns the PetscDualSpace used to define the inner product 54820cf1dd8SToby Isaac 54920cf1dd8SToby Isaac Not collective 55020cf1dd8SToby Isaac 55120cf1dd8SToby Isaac Input Parameter: 55220cf1dd8SToby Isaac . fem - The PetscFE object 55320cf1dd8SToby Isaac 55420cf1dd8SToby Isaac Output Parameter: 55520cf1dd8SToby Isaac . sp - The PetscDualSpace object 55620cf1dd8SToby Isaac 55720cf1dd8SToby Isaac Level: intermediate 55820cf1dd8SToby Isaac 55920cf1dd8SToby Isaac .seealso: PetscFECreate() 56020cf1dd8SToby Isaac @*/ 56120cf1dd8SToby Isaac PetscErrorCode PetscFEGetDualSpace(PetscFE fem, PetscDualSpace *sp) 56220cf1dd8SToby Isaac { 56320cf1dd8SToby Isaac PetscFunctionBegin; 56420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 56520cf1dd8SToby Isaac PetscValidPointer(sp, 2); 56620cf1dd8SToby Isaac *sp = fem->dualSpace; 56720cf1dd8SToby Isaac PetscFunctionReturn(0); 56820cf1dd8SToby Isaac } 56920cf1dd8SToby Isaac 57020cf1dd8SToby Isaac /*@ 57120cf1dd8SToby Isaac PetscFESetDualSpace - Sets the PetscDualSpace used to define the inner product 57220cf1dd8SToby Isaac 57320cf1dd8SToby Isaac Not collective 57420cf1dd8SToby Isaac 57520cf1dd8SToby Isaac Input Parameters: 57620cf1dd8SToby Isaac + fem - The PetscFE object 57720cf1dd8SToby Isaac - sp - The PetscDualSpace object 57820cf1dd8SToby Isaac 57920cf1dd8SToby Isaac Level: intermediate 58020cf1dd8SToby Isaac 58120cf1dd8SToby Isaac .seealso: PetscFECreate() 58220cf1dd8SToby Isaac @*/ 58320cf1dd8SToby Isaac PetscErrorCode PetscFESetDualSpace(PetscFE fem, PetscDualSpace sp) 58420cf1dd8SToby Isaac { 58520cf1dd8SToby Isaac PetscErrorCode ierr; 58620cf1dd8SToby Isaac 58720cf1dd8SToby Isaac PetscFunctionBegin; 58820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 58920cf1dd8SToby Isaac PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 2); 59020cf1dd8SToby Isaac ierr = PetscDualSpaceDestroy(&fem->dualSpace);CHKERRQ(ierr); 59120cf1dd8SToby Isaac fem->dualSpace = sp; 59220cf1dd8SToby Isaac ierr = PetscObjectReference((PetscObject) fem->dualSpace);CHKERRQ(ierr); 59320cf1dd8SToby Isaac PetscFunctionReturn(0); 59420cf1dd8SToby Isaac } 59520cf1dd8SToby Isaac 59620cf1dd8SToby Isaac /*@ 59720cf1dd8SToby Isaac PetscFEGetQuadrature - Returns the PetscQuadrature used to calculate inner products 59820cf1dd8SToby Isaac 59920cf1dd8SToby Isaac Not collective 60020cf1dd8SToby Isaac 60120cf1dd8SToby Isaac Input Parameter: 60220cf1dd8SToby Isaac . fem - The PetscFE object 60320cf1dd8SToby Isaac 60420cf1dd8SToby Isaac Output Parameter: 60520cf1dd8SToby Isaac . q - The PetscQuadrature object 60620cf1dd8SToby Isaac 60720cf1dd8SToby Isaac Level: intermediate 60820cf1dd8SToby Isaac 60920cf1dd8SToby Isaac .seealso: PetscFECreate() 61020cf1dd8SToby Isaac @*/ 61120cf1dd8SToby Isaac PetscErrorCode PetscFEGetQuadrature(PetscFE fem, PetscQuadrature *q) 61220cf1dd8SToby Isaac { 61320cf1dd8SToby Isaac PetscFunctionBegin; 61420cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 61520cf1dd8SToby Isaac PetscValidPointer(q, 2); 61620cf1dd8SToby Isaac *q = fem->quadrature; 61720cf1dd8SToby Isaac PetscFunctionReturn(0); 61820cf1dd8SToby Isaac } 61920cf1dd8SToby Isaac 62020cf1dd8SToby Isaac /*@ 62120cf1dd8SToby Isaac PetscFESetQuadrature - Sets the PetscQuadrature used to calculate inner products 62220cf1dd8SToby Isaac 62320cf1dd8SToby Isaac Not collective 62420cf1dd8SToby Isaac 62520cf1dd8SToby Isaac Input Parameters: 62620cf1dd8SToby Isaac + fem - The PetscFE object 62720cf1dd8SToby Isaac - q - The PetscQuadrature object 62820cf1dd8SToby Isaac 62920cf1dd8SToby Isaac Level: intermediate 63020cf1dd8SToby Isaac 63120cf1dd8SToby Isaac .seealso: PetscFECreate() 63220cf1dd8SToby Isaac @*/ 63320cf1dd8SToby Isaac PetscErrorCode PetscFESetQuadrature(PetscFE fem, PetscQuadrature q) 63420cf1dd8SToby Isaac { 63520cf1dd8SToby Isaac PetscInt Nc, qNc; 63620cf1dd8SToby Isaac PetscErrorCode ierr; 63720cf1dd8SToby Isaac 63820cf1dd8SToby Isaac PetscFunctionBegin; 63920cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 64020cf1dd8SToby Isaac ierr = PetscFEGetNumComponents(fem, &Nc);CHKERRQ(ierr); 64120cf1dd8SToby Isaac ierr = PetscQuadratureGetNumComponents(q, &qNc);CHKERRQ(ierr); 64220cf1dd8SToby Isaac if ((qNc != 1) && (Nc != qNc)) SETERRQ2(PetscObjectComm((PetscObject) fem), PETSC_ERR_ARG_SIZ, "FE components %D != Quadrature components %D and non-scalar quadrature", Nc, qNc); 64320cf1dd8SToby Isaac ierr = PetscFERestoreTabulation(fem, 0, NULL, &fem->B, &fem->D, NULL /*&(*fem)->H*/);CHKERRQ(ierr); 64420cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&fem->quadrature);CHKERRQ(ierr); 64520cf1dd8SToby Isaac fem->quadrature = q; 64620cf1dd8SToby Isaac ierr = PetscObjectReference((PetscObject) q);CHKERRQ(ierr); 64720cf1dd8SToby Isaac PetscFunctionReturn(0); 64820cf1dd8SToby Isaac } 64920cf1dd8SToby Isaac 65020cf1dd8SToby Isaac /*@ 65120cf1dd8SToby Isaac PetscFEGetFaceQuadrature - Returns the PetscQuadrature used to calculate inner products on faces 65220cf1dd8SToby Isaac 65320cf1dd8SToby Isaac Not collective 65420cf1dd8SToby Isaac 65520cf1dd8SToby Isaac Input Parameter: 65620cf1dd8SToby Isaac . fem - The PetscFE object 65720cf1dd8SToby Isaac 65820cf1dd8SToby Isaac Output Parameter: 65920cf1dd8SToby Isaac . q - The PetscQuadrature object 66020cf1dd8SToby Isaac 66120cf1dd8SToby Isaac Level: intermediate 66220cf1dd8SToby Isaac 66320cf1dd8SToby Isaac .seealso: PetscFECreate() 66420cf1dd8SToby Isaac @*/ 66520cf1dd8SToby Isaac PetscErrorCode PetscFEGetFaceQuadrature(PetscFE fem, PetscQuadrature *q) 66620cf1dd8SToby Isaac { 66720cf1dd8SToby Isaac PetscFunctionBegin; 66820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 66920cf1dd8SToby Isaac PetscValidPointer(q, 2); 67020cf1dd8SToby Isaac *q = fem->faceQuadrature; 67120cf1dd8SToby Isaac PetscFunctionReturn(0); 67220cf1dd8SToby Isaac } 67320cf1dd8SToby Isaac 67420cf1dd8SToby Isaac /*@ 67520cf1dd8SToby Isaac PetscFESetFaceQuadrature - Sets the PetscQuadrature used to calculate inner products on faces 67620cf1dd8SToby Isaac 67720cf1dd8SToby Isaac Not collective 67820cf1dd8SToby Isaac 67920cf1dd8SToby Isaac Input Parameters: 68020cf1dd8SToby Isaac + fem - The PetscFE object 68120cf1dd8SToby Isaac - q - The PetscQuadrature object 68220cf1dd8SToby Isaac 68320cf1dd8SToby Isaac Level: intermediate 68420cf1dd8SToby Isaac 68520cf1dd8SToby Isaac .seealso: PetscFECreate() 68620cf1dd8SToby Isaac @*/ 68720cf1dd8SToby Isaac PetscErrorCode PetscFESetFaceQuadrature(PetscFE fem, PetscQuadrature q) 68820cf1dd8SToby Isaac { 68920cf1dd8SToby Isaac PetscErrorCode ierr; 69020cf1dd8SToby Isaac 69120cf1dd8SToby Isaac PetscFunctionBegin; 69220cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 69320cf1dd8SToby Isaac ierr = PetscFERestoreTabulation(fem, 0, NULL, &fem->Bf, &fem->Df, NULL /*&(*fem)->Hf*/);CHKERRQ(ierr); 69420cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&fem->faceQuadrature);CHKERRQ(ierr); 69520cf1dd8SToby Isaac fem->faceQuadrature = q; 69620cf1dd8SToby Isaac ierr = PetscObjectReference((PetscObject) q);CHKERRQ(ierr); 69720cf1dd8SToby Isaac PetscFunctionReturn(0); 69820cf1dd8SToby Isaac } 69920cf1dd8SToby Isaac 7005dc5c000SMatthew G. Knepley /*@ 7015dc5c000SMatthew G. Knepley PetscFECopyQuadrature - Copy both volumetric and surface quadrature 7025dc5c000SMatthew G. Knepley 7035dc5c000SMatthew G. Knepley Not collective 7045dc5c000SMatthew G. Knepley 7055dc5c000SMatthew G. Knepley Input Parameters: 7065dc5c000SMatthew G. Knepley + sfe - The PetscFE source for the quadratures 7075dc5c000SMatthew G. Knepley - tfe - The PetscFE target for the quadratures 7085dc5c000SMatthew G. Knepley 7095dc5c000SMatthew G. Knepley Level: intermediate 7105dc5c000SMatthew G. Knepley 7115dc5c000SMatthew G. Knepley .seealso: PetscFECreate(), PetscFESetQuadrature(), PetscFESetFaceQuadrature() 7125dc5c000SMatthew G. Knepley @*/ 7135dc5c000SMatthew G. Knepley PetscErrorCode PetscFECopyQuadrature(PetscFE sfe, PetscFE tfe) 7145dc5c000SMatthew G. Knepley { 7155dc5c000SMatthew G. Knepley PetscQuadrature q; 7165dc5c000SMatthew G. Knepley PetscErrorCode ierr; 7175dc5c000SMatthew G. Knepley 7185dc5c000SMatthew G. Knepley PetscFunctionBegin; 7195dc5c000SMatthew G. Knepley PetscValidHeaderSpecific(sfe, PETSCFE_CLASSID, 1); 7205dc5c000SMatthew G. Knepley PetscValidHeaderSpecific(tfe, PETSCFE_CLASSID, 2); 7215dc5c000SMatthew G. Knepley ierr = PetscFEGetQuadrature(sfe, &q);CHKERRQ(ierr); 7225dc5c000SMatthew G. Knepley ierr = PetscFESetQuadrature(tfe, q);CHKERRQ(ierr); 7235dc5c000SMatthew G. Knepley ierr = PetscFEGetFaceQuadrature(sfe, &q);CHKERRQ(ierr); 7245dc5c000SMatthew G. Knepley ierr = PetscFESetFaceQuadrature(tfe, q);CHKERRQ(ierr); 7255dc5c000SMatthew G. Knepley PetscFunctionReturn(0); 7265dc5c000SMatthew G. Knepley } 7275dc5c000SMatthew G. Knepley 72820cf1dd8SToby Isaac /*@C 72920cf1dd8SToby Isaac PetscFEGetNumDof - Returns the number of dofs (dual basis vectors) associated to mesh points on the reference cell of a given dimension 73020cf1dd8SToby Isaac 73120cf1dd8SToby Isaac Not collective 73220cf1dd8SToby Isaac 73320cf1dd8SToby Isaac Input Parameter: 73420cf1dd8SToby Isaac . fem - The PetscFE object 73520cf1dd8SToby Isaac 73620cf1dd8SToby Isaac Output Parameter: 73720cf1dd8SToby Isaac . numDof - Array with the number of dofs per dimension 73820cf1dd8SToby Isaac 73920cf1dd8SToby Isaac Level: intermediate 74020cf1dd8SToby Isaac 74120cf1dd8SToby Isaac .seealso: PetscFECreate() 74220cf1dd8SToby Isaac @*/ 74320cf1dd8SToby Isaac PetscErrorCode PetscFEGetNumDof(PetscFE fem, const PetscInt **numDof) 74420cf1dd8SToby Isaac { 74520cf1dd8SToby Isaac PetscErrorCode ierr; 74620cf1dd8SToby Isaac 74720cf1dd8SToby Isaac PetscFunctionBegin; 74820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 74920cf1dd8SToby Isaac PetscValidPointer(numDof, 2); 75020cf1dd8SToby Isaac ierr = PetscDualSpaceGetNumDof(fem->dualSpace, numDof);CHKERRQ(ierr); 75120cf1dd8SToby Isaac PetscFunctionReturn(0); 75220cf1dd8SToby Isaac } 75320cf1dd8SToby Isaac 75420cf1dd8SToby Isaac /*@C 75520cf1dd8SToby Isaac PetscFEGetDefaultTabulation - Returns the tabulation of the basis functions at the quadrature points 75620cf1dd8SToby Isaac 75720cf1dd8SToby Isaac Not collective 75820cf1dd8SToby Isaac 75920cf1dd8SToby Isaac Input Parameter: 76020cf1dd8SToby Isaac . fem - The PetscFE object 76120cf1dd8SToby Isaac 76220cf1dd8SToby Isaac Output Parameters: 76320cf1dd8SToby Isaac + B - The basis function values at quadrature points 76420cf1dd8SToby Isaac . D - The basis function derivatives at quadrature points 76520cf1dd8SToby Isaac - H - The basis function second derivatives at quadrature points 76620cf1dd8SToby Isaac 76720cf1dd8SToby Isaac Note: 76820cf1dd8SToby Isaac $ B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 76920cf1dd8SToby Isaac $ D[((p*pdim + i)*Nc + c)*dim + d] is the derivative value at point p for basis function i, component c, in direction d 77020cf1dd8SToby Isaac $ 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 77120cf1dd8SToby Isaac 77220cf1dd8SToby Isaac Level: intermediate 77320cf1dd8SToby Isaac 77420cf1dd8SToby Isaac .seealso: PetscFEGetTabulation(), PetscFERestoreTabulation() 77520cf1dd8SToby Isaac @*/ 77620cf1dd8SToby Isaac PetscErrorCode PetscFEGetDefaultTabulation(PetscFE fem, PetscReal **B, PetscReal **D, PetscReal **H) 77720cf1dd8SToby Isaac { 77820cf1dd8SToby Isaac PetscInt npoints; 77920cf1dd8SToby Isaac const PetscReal *points; 78020cf1dd8SToby Isaac PetscErrorCode ierr; 78120cf1dd8SToby Isaac 78220cf1dd8SToby Isaac PetscFunctionBegin; 78320cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 78420cf1dd8SToby Isaac if (B) PetscValidPointer(B, 2); 78520cf1dd8SToby Isaac if (D) PetscValidPointer(D, 3); 78620cf1dd8SToby Isaac if (H) PetscValidPointer(H, 4); 78720cf1dd8SToby Isaac ierr = PetscQuadratureGetData(fem->quadrature, NULL, NULL, &npoints, &points, NULL);CHKERRQ(ierr); 78820cf1dd8SToby Isaac if (!fem->B) {ierr = PetscFEGetTabulation(fem, npoints, points, &fem->B, &fem->D, NULL/*&fem->H*/);CHKERRQ(ierr);} 78920cf1dd8SToby Isaac if (B) *B = fem->B; 79020cf1dd8SToby Isaac if (D) *D = fem->D; 79120cf1dd8SToby Isaac if (H) *H = fem->H; 79220cf1dd8SToby Isaac PetscFunctionReturn(0); 79320cf1dd8SToby Isaac } 79420cf1dd8SToby Isaac 7952b99622eSMatthew G. Knepley /*@C 7962b99622eSMatthew G. Knepley PetscFEGetFaceTabulation - Returns the tabulation of the basis functions at the face quadrature points 7972b99622eSMatthew G. Knepley 7982b99622eSMatthew G. Knepley Not collective 7992b99622eSMatthew G. Knepley 8002b99622eSMatthew G. Knepley Input Parameter: 8012b99622eSMatthew G. Knepley . fem - The PetscFE object 8022b99622eSMatthew G. Knepley 8032b99622eSMatthew G. Knepley Output Parameters: 8042b99622eSMatthew G. Knepley + B - The basis function values at face quadrature points 8052b99622eSMatthew G. Knepley . D - The basis function derivatives at face quadrature points 8062b99622eSMatthew G. Knepley - H - The basis function second derivatives at face quadrature points 8072b99622eSMatthew G. Knepley 8082b99622eSMatthew G. Knepley Note: 8092b99622eSMatthew G. Knepley $ Bf[((f*Nq + q)*pdim + i)*Nc + c] is the value at point f,q for basis function i and component c 8102b99622eSMatthew G. Knepley $ 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 8112b99622eSMatthew G. Knepley $ 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 8122b99622eSMatthew G. Knepley 8132b99622eSMatthew G. Knepley Level: intermediate 8142b99622eSMatthew G. Knepley 8152b99622eSMatthew G. Knepley .seealso: PetscFEGetDefaultTabulation(), PetscFEGetTabulation(), PetscFERestoreTabulation() 8162b99622eSMatthew G. Knepley @*/ 81720cf1dd8SToby Isaac PetscErrorCode PetscFEGetFaceTabulation(PetscFE fem, PetscReal **Bf, PetscReal **Df, PetscReal **Hf) 81820cf1dd8SToby Isaac { 81920cf1dd8SToby Isaac PetscErrorCode ierr; 82020cf1dd8SToby Isaac 82120cf1dd8SToby Isaac PetscFunctionBegin; 82220cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 82320cf1dd8SToby Isaac if (Bf) PetscValidPointer(Bf, 2); 82420cf1dd8SToby Isaac if (Df) PetscValidPointer(Df, 3); 82520cf1dd8SToby Isaac if (Hf) PetscValidPointer(Hf, 4); 82620cf1dd8SToby Isaac if (!fem->Bf) { 82720cf1dd8SToby Isaac const PetscReal xi0[3] = {-1., -1., -1.}; 82820cf1dd8SToby Isaac PetscReal v0[3], J[9], detJ; 82920cf1dd8SToby Isaac PetscQuadrature fq; 83020cf1dd8SToby Isaac PetscDualSpace sp; 83120cf1dd8SToby Isaac DM dm; 83220cf1dd8SToby Isaac const PetscInt *faces; 83320cf1dd8SToby Isaac PetscInt dim, numFaces, f, npoints, q; 83420cf1dd8SToby Isaac const PetscReal *points; 83520cf1dd8SToby Isaac PetscReal *facePoints; 83620cf1dd8SToby Isaac 83720cf1dd8SToby Isaac ierr = PetscFEGetDualSpace(fem, &sp);CHKERRQ(ierr); 83820cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(sp, &dm);CHKERRQ(ierr); 83920cf1dd8SToby Isaac ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 84020cf1dd8SToby Isaac ierr = DMPlexGetConeSize(dm, 0, &numFaces);CHKERRQ(ierr); 84120cf1dd8SToby Isaac ierr = DMPlexGetCone(dm, 0, &faces);CHKERRQ(ierr); 84220cf1dd8SToby Isaac ierr = PetscFEGetFaceQuadrature(fem, &fq);CHKERRQ(ierr); 84320cf1dd8SToby Isaac if (fq) { 84420cf1dd8SToby Isaac ierr = PetscQuadratureGetData(fq, NULL, NULL, &npoints, &points, NULL);CHKERRQ(ierr); 84520cf1dd8SToby Isaac ierr = PetscMalloc1(numFaces*npoints*dim, &facePoints);CHKERRQ(ierr); 84620cf1dd8SToby Isaac for (f = 0; f < numFaces; ++f) { 84720cf1dd8SToby Isaac ierr = DMPlexComputeCellGeometryFEM(dm, faces[f], NULL, v0, J, NULL, &detJ);CHKERRQ(ierr); 84820cf1dd8SToby Isaac for (q = 0; q < npoints; ++q) CoordinatesRefToReal(dim, dim-1, xi0, v0, J, &points[q*(dim-1)], &facePoints[(f*npoints+q)*dim]); 84920cf1dd8SToby Isaac } 85020cf1dd8SToby Isaac ierr = PetscFEGetTabulation(fem, numFaces*npoints, facePoints, &fem->Bf, &fem->Df, NULL/*&fem->Hf*/);CHKERRQ(ierr); 85120cf1dd8SToby Isaac ierr = PetscFree(facePoints);CHKERRQ(ierr); 85220cf1dd8SToby Isaac } 85320cf1dd8SToby Isaac } 85420cf1dd8SToby Isaac if (Bf) *Bf = fem->Bf; 85520cf1dd8SToby Isaac if (Df) *Df = fem->Df; 85620cf1dd8SToby Isaac if (Hf) *Hf = fem->Hf; 85720cf1dd8SToby Isaac PetscFunctionReturn(0); 85820cf1dd8SToby Isaac } 85920cf1dd8SToby Isaac 8602b99622eSMatthew G. Knepley /*@C 8612b99622eSMatthew G. Knepley PetscFEGetFaceTabulation - Returns the tabulation of the basis functions at the face centroid points 8622b99622eSMatthew G. Knepley 8632b99622eSMatthew G. Knepley Not collective 8642b99622eSMatthew G. Knepley 8652b99622eSMatthew G. Knepley Input Parameter: 8662b99622eSMatthew G. Knepley . fem - The PetscFE object 8672b99622eSMatthew G. Knepley 8682b99622eSMatthew G. Knepley Output Parameters: 8692b99622eSMatthew G. Knepley + B - The basis function values at face centroid points 8702b99622eSMatthew G. Knepley . D - The basis function derivatives at face centroid points 8712b99622eSMatthew G. Knepley - H - The basis function second derivatives at face centroid points 8722b99622eSMatthew G. Knepley 8732b99622eSMatthew G. Knepley Note: 8742b99622eSMatthew G. Knepley $ Bf[(f*pdim + i)*Nc + c] is the value at point f for basis function i and component c 8752b99622eSMatthew G. Knepley $ Df[((f*pdim + i)*Nc + c)*dim + d] is the derivative value at point f for basis function i, component c, in direction d 8762b99622eSMatthew G. Knepley $ Hf[(((f*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point f for basis function i, component c, in directions d and e 8772b99622eSMatthew G. Knepley 8782b99622eSMatthew G. Knepley Level: intermediate 8792b99622eSMatthew G. Knepley 8802b99622eSMatthew G. Knepley .seealso: PetscFEGetFaceTabulation(), PetscFEGetDefaultTabulation(), PetscFEGetTabulation(), PetscFERestoreTabulation() 8812b99622eSMatthew G. Knepley @*/ 88220cf1dd8SToby Isaac PetscErrorCode PetscFEGetFaceCentroidTabulation(PetscFE fem, PetscReal **F) 88320cf1dd8SToby Isaac { 88420cf1dd8SToby Isaac PetscErrorCode ierr; 88520cf1dd8SToby Isaac 88620cf1dd8SToby Isaac PetscFunctionBegin; 88720cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 88820cf1dd8SToby Isaac PetscValidPointer(F, 2); 88920cf1dd8SToby Isaac if (!fem->F) { 89020cf1dd8SToby Isaac PetscDualSpace sp; 89120cf1dd8SToby Isaac DM dm; 89220cf1dd8SToby Isaac const PetscInt *cone; 89320cf1dd8SToby Isaac PetscReal *centroids; 89420cf1dd8SToby Isaac PetscInt dim, numFaces, f; 89520cf1dd8SToby Isaac 89620cf1dd8SToby Isaac ierr = PetscFEGetDualSpace(fem, &sp);CHKERRQ(ierr); 89720cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(sp, &dm);CHKERRQ(ierr); 89820cf1dd8SToby Isaac ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 89920cf1dd8SToby Isaac ierr = DMPlexGetConeSize(dm, 0, &numFaces);CHKERRQ(ierr); 90020cf1dd8SToby Isaac ierr = DMPlexGetCone(dm, 0, &cone);CHKERRQ(ierr); 90120cf1dd8SToby Isaac ierr = PetscMalloc1(numFaces*dim, ¢roids);CHKERRQ(ierr); 90220cf1dd8SToby Isaac for (f = 0; f < numFaces; ++f) {ierr = DMPlexComputeCellGeometryFVM(dm, cone[f], NULL, ¢roids[f*dim], NULL);CHKERRQ(ierr);} 90320cf1dd8SToby Isaac ierr = PetscFEGetTabulation(fem, numFaces, centroids, &fem->F, NULL, NULL);CHKERRQ(ierr); 90420cf1dd8SToby Isaac ierr = PetscFree(centroids);CHKERRQ(ierr); 90520cf1dd8SToby Isaac } 90620cf1dd8SToby Isaac *F = fem->F; 90720cf1dd8SToby Isaac PetscFunctionReturn(0); 90820cf1dd8SToby Isaac } 90920cf1dd8SToby Isaac 91020cf1dd8SToby Isaac /*@C 91120cf1dd8SToby Isaac PetscFEGetTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided. 91220cf1dd8SToby Isaac 91320cf1dd8SToby Isaac Not collective 91420cf1dd8SToby Isaac 91520cf1dd8SToby Isaac Input Parameters: 91620cf1dd8SToby Isaac + fem - The PetscFE object 91720cf1dd8SToby Isaac . npoints - The number of tabulation points 91820cf1dd8SToby Isaac - points - The tabulation point coordinates 91920cf1dd8SToby Isaac 92020cf1dd8SToby Isaac Output Parameters: 92120cf1dd8SToby Isaac + B - The basis function values at tabulation points 92220cf1dd8SToby Isaac . D - The basis function derivatives at tabulation points 92320cf1dd8SToby Isaac - H - The basis function second derivatives at tabulation points 92420cf1dd8SToby Isaac 92520cf1dd8SToby Isaac Note: 92620cf1dd8SToby Isaac $ B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 92720cf1dd8SToby Isaac $ D[((p*pdim + i)*Nc + c)*dim + d] is the derivative value at point p for basis function i, component c, in direction d 92820cf1dd8SToby Isaac $ 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 92920cf1dd8SToby Isaac 93020cf1dd8SToby Isaac Level: intermediate 93120cf1dd8SToby Isaac 93220cf1dd8SToby Isaac .seealso: PetscFERestoreTabulation(), PetscFEGetDefaultTabulation() 93320cf1dd8SToby Isaac @*/ 93420cf1dd8SToby Isaac PetscErrorCode PetscFEGetTabulation(PetscFE fem, PetscInt npoints, const PetscReal points[], PetscReal **B, PetscReal **D, PetscReal **H) 93520cf1dd8SToby Isaac { 93620cf1dd8SToby Isaac DM dm; 93720cf1dd8SToby Isaac PetscInt pdim; /* Dimension of FE space P */ 93820cf1dd8SToby Isaac PetscInt dim; /* Spatial dimension */ 93920cf1dd8SToby Isaac PetscInt comp; /* Field components */ 94020cf1dd8SToby Isaac PetscErrorCode ierr; 94120cf1dd8SToby Isaac 94220cf1dd8SToby Isaac PetscFunctionBegin; 94320cf1dd8SToby Isaac if (!npoints) { 94420cf1dd8SToby Isaac if (B) *B = NULL; 94520cf1dd8SToby Isaac if (D) *D = NULL; 94620cf1dd8SToby Isaac if (H) *H = NULL; 94720cf1dd8SToby Isaac PetscFunctionReturn(0); 94820cf1dd8SToby Isaac } 94920cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 95020cf1dd8SToby Isaac PetscValidPointer(points, 3); 95120cf1dd8SToby Isaac if (B) PetscValidPointer(B, 4); 95220cf1dd8SToby Isaac if (D) PetscValidPointer(D, 5); 95320cf1dd8SToby Isaac if (H) PetscValidPointer(H, 6); 95420cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(fem->dualSpace, &dm);CHKERRQ(ierr); 95520cf1dd8SToby Isaac ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 95620cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension(fem->dualSpace, &pdim);CHKERRQ(ierr); 95720cf1dd8SToby Isaac ierr = PetscFEGetNumComponents(fem, &comp);CHKERRQ(ierr); 95820cf1dd8SToby Isaac if (B) {ierr = DMGetWorkArray(dm, npoints*pdim*comp, MPIU_REAL, B);CHKERRQ(ierr);} 95920cf1dd8SToby Isaac if (!dim) { 96020cf1dd8SToby Isaac if (D) *D = NULL; 96120cf1dd8SToby Isaac if (H) *H = NULL; 96220cf1dd8SToby Isaac } else { 96320cf1dd8SToby Isaac if (D) {ierr = DMGetWorkArray(dm, npoints*pdim*comp*dim, MPIU_REAL, D);CHKERRQ(ierr);} 96420cf1dd8SToby Isaac if (H) {ierr = DMGetWorkArray(dm, npoints*pdim*comp*dim*dim, MPIU_REAL, H);CHKERRQ(ierr);} 96520cf1dd8SToby Isaac } 96620cf1dd8SToby Isaac ierr = (*fem->ops->gettabulation)(fem, npoints, points, B ? *B : NULL, D ? *D : NULL, H ? *H : NULL);CHKERRQ(ierr); 96720cf1dd8SToby Isaac PetscFunctionReturn(0); 96820cf1dd8SToby Isaac } 96920cf1dd8SToby Isaac 9702b99622eSMatthew G. Knepley /*@C 9712b99622eSMatthew G. Knepley PetscFERestoreTabulation - Frees memory from the associated tabulation. 9722b99622eSMatthew G. Knepley 9732b99622eSMatthew G. Knepley Not collective 9742b99622eSMatthew G. Knepley 9752b99622eSMatthew G. Knepley Input Parameters: 9762b99622eSMatthew G. Knepley + fem - The PetscFE object 9772b99622eSMatthew G. Knepley . npoints - The number of tabulation points 9782b99622eSMatthew G. Knepley . points - The tabulation point coordinates 9792b99622eSMatthew G. Knepley . B - The basis function values at tabulation points 9802b99622eSMatthew G. Knepley . D - The basis function derivatives at tabulation points 9812b99622eSMatthew G. Knepley - H - The basis function second derivatives at tabulation points 9822b99622eSMatthew G. Knepley 9832b99622eSMatthew G. Knepley Note: 9842b99622eSMatthew G. Knepley $ B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c 9852b99622eSMatthew G. Knepley $ D[((p*pdim + i)*Nc + c)*dim + d] is the derivative value at point p for basis function i, component c, in direction d 9862b99622eSMatthew G. Knepley $ 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 9872b99622eSMatthew G. Knepley 9882b99622eSMatthew G. Knepley Level: intermediate 9892b99622eSMatthew G. Knepley 9902b99622eSMatthew G. Knepley .seealso: PetscFEGetTabulation(), PetscFEGetDefaultTabulation() 9912b99622eSMatthew G. Knepley @*/ 99220cf1dd8SToby Isaac PetscErrorCode PetscFERestoreTabulation(PetscFE fem, PetscInt npoints, const PetscReal points[], PetscReal **B, PetscReal **D, PetscReal **H) 99320cf1dd8SToby Isaac { 99420cf1dd8SToby Isaac DM dm; 99520cf1dd8SToby Isaac PetscErrorCode ierr; 99620cf1dd8SToby Isaac 99720cf1dd8SToby Isaac PetscFunctionBegin; 99820cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 99920cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(fem->dualSpace, &dm);CHKERRQ(ierr); 100020cf1dd8SToby Isaac if (B && *B) {ierr = DMRestoreWorkArray(dm, 0, MPIU_REAL, B);CHKERRQ(ierr);} 100120cf1dd8SToby Isaac if (D && *D) {ierr = DMRestoreWorkArray(dm, 0, MPIU_REAL, D);CHKERRQ(ierr);} 100220cf1dd8SToby Isaac if (H && *H) {ierr = DMRestoreWorkArray(dm, 0, MPIU_REAL, H);CHKERRQ(ierr);} 100320cf1dd8SToby Isaac PetscFunctionReturn(0); 100420cf1dd8SToby Isaac } 100520cf1dd8SToby Isaac 100620cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode PetscFECreatePointTrace(PetscFE fe, PetscInt refPoint, PetscFE *trFE) 100720cf1dd8SToby Isaac { 100820cf1dd8SToby Isaac PetscSpace bsp, bsubsp; 100920cf1dd8SToby Isaac PetscDualSpace dsp, dsubsp; 101020cf1dd8SToby Isaac PetscInt dim, depth, numComp, i, j, coneSize, order; 101120cf1dd8SToby Isaac PetscFEType type; 101220cf1dd8SToby Isaac DM dm; 101320cf1dd8SToby Isaac DMLabel label; 101420cf1dd8SToby Isaac PetscReal *xi, *v, *J, detJ; 1015db11e2ebSMatthew G. Knepley const char *name; 101620cf1dd8SToby Isaac PetscQuadrature origin, fullQuad, subQuad; 101720cf1dd8SToby Isaac PetscErrorCode ierr; 101820cf1dd8SToby Isaac 101920cf1dd8SToby Isaac PetscFunctionBegin; 102020cf1dd8SToby Isaac PetscValidHeaderSpecific(fe,PETSCFE_CLASSID,1); 102120cf1dd8SToby Isaac PetscValidPointer(trFE,3); 102220cf1dd8SToby Isaac ierr = PetscFEGetBasisSpace(fe,&bsp);CHKERRQ(ierr); 102320cf1dd8SToby Isaac ierr = PetscFEGetDualSpace(fe,&dsp);CHKERRQ(ierr); 102420cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(dsp,&dm);CHKERRQ(ierr); 102520cf1dd8SToby Isaac ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr); 102620cf1dd8SToby Isaac ierr = DMPlexGetDepthLabel(dm,&label);CHKERRQ(ierr); 102720cf1dd8SToby Isaac ierr = DMLabelGetValue(label,refPoint,&depth);CHKERRQ(ierr); 102820cf1dd8SToby Isaac ierr = PetscCalloc1(depth,&xi);CHKERRQ(ierr); 102920cf1dd8SToby Isaac ierr = PetscMalloc1(dim,&v);CHKERRQ(ierr); 103020cf1dd8SToby Isaac ierr = PetscMalloc1(dim*dim,&J);CHKERRQ(ierr); 103120cf1dd8SToby Isaac for (i = 0; i < depth; i++) xi[i] = 0.; 103220cf1dd8SToby Isaac ierr = PetscQuadratureCreate(PETSC_COMM_SELF,&origin);CHKERRQ(ierr); 103320cf1dd8SToby Isaac ierr = PetscQuadratureSetData(origin,depth,0,1,xi,NULL);CHKERRQ(ierr); 103420cf1dd8SToby Isaac ierr = DMPlexComputeCellGeometryFEM(dm,refPoint,origin,v,J,NULL,&detJ);CHKERRQ(ierr); 103520cf1dd8SToby Isaac /* CellGeometryFEM computes the expanded Jacobian, we want the true jacobian */ 103620cf1dd8SToby Isaac for (i = 1; i < dim; i++) { 103720cf1dd8SToby Isaac for (j = 0; j < depth; j++) { 103820cf1dd8SToby Isaac J[i * depth + j] = J[i * dim + j]; 103920cf1dd8SToby Isaac } 104020cf1dd8SToby Isaac } 104120cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&origin);CHKERRQ(ierr); 104220cf1dd8SToby Isaac ierr = PetscDualSpaceGetPointSubspace(dsp,refPoint,&dsubsp);CHKERRQ(ierr); 104320cf1dd8SToby Isaac ierr = PetscSpaceCreateSubspace(bsp,dsubsp,v,J,NULL,NULL,PETSC_OWN_POINTER,&bsubsp);CHKERRQ(ierr); 104420cf1dd8SToby Isaac ierr = PetscSpaceSetUp(bsubsp);CHKERRQ(ierr); 104520cf1dd8SToby Isaac ierr = PetscFECreate(PetscObjectComm((PetscObject)fe),trFE);CHKERRQ(ierr); 104620cf1dd8SToby Isaac ierr = PetscFEGetType(fe,&type);CHKERRQ(ierr); 104720cf1dd8SToby Isaac ierr = PetscFESetType(*trFE,type);CHKERRQ(ierr); 104820cf1dd8SToby Isaac ierr = PetscFEGetNumComponents(fe,&numComp);CHKERRQ(ierr); 104920cf1dd8SToby Isaac ierr = PetscFESetNumComponents(*trFE,numComp);CHKERRQ(ierr); 105020cf1dd8SToby Isaac ierr = PetscFESetBasisSpace(*trFE,bsubsp);CHKERRQ(ierr); 105120cf1dd8SToby Isaac ierr = PetscFESetDualSpace(*trFE,dsubsp);CHKERRQ(ierr); 1052db11e2ebSMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) fe, &name);CHKERRQ(ierr); 1053db11e2ebSMatthew G. Knepley if (name) {ierr = PetscFESetName(*trFE, name);CHKERRQ(ierr);} 105420cf1dd8SToby Isaac ierr = PetscFEGetQuadrature(fe,&fullQuad);CHKERRQ(ierr); 105520cf1dd8SToby Isaac ierr = PetscQuadratureGetOrder(fullQuad,&order);CHKERRQ(ierr); 105620cf1dd8SToby Isaac ierr = DMPlexGetConeSize(dm,refPoint,&coneSize);CHKERRQ(ierr); 105720cf1dd8SToby Isaac if (coneSize == 2 * depth) { 105820cf1dd8SToby Isaac ierr = PetscDTGaussTensorQuadrature(depth,1,(order + 1)/2,-1.,1.,&subQuad);CHKERRQ(ierr); 105920cf1dd8SToby Isaac } else { 106020cf1dd8SToby Isaac ierr = PetscDTGaussJacobiQuadrature(depth,1,(order + 1)/2,-1.,1.,&subQuad);CHKERRQ(ierr); 106120cf1dd8SToby Isaac } 106220cf1dd8SToby Isaac ierr = PetscFESetQuadrature(*trFE,subQuad);CHKERRQ(ierr); 106320cf1dd8SToby Isaac ierr = PetscFESetUp(*trFE);CHKERRQ(ierr); 106420cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&subQuad);CHKERRQ(ierr); 106520cf1dd8SToby Isaac ierr = PetscSpaceDestroy(&bsubsp);CHKERRQ(ierr); 106620cf1dd8SToby Isaac PetscFunctionReturn(0); 106720cf1dd8SToby Isaac } 106820cf1dd8SToby Isaac 106920cf1dd8SToby Isaac PetscErrorCode PetscFECreateHeightTrace(PetscFE fe, PetscInt height, PetscFE *trFE) 107020cf1dd8SToby Isaac { 107120cf1dd8SToby Isaac PetscInt hStart, hEnd; 107220cf1dd8SToby Isaac PetscDualSpace dsp; 107320cf1dd8SToby Isaac DM dm; 107420cf1dd8SToby Isaac PetscErrorCode ierr; 107520cf1dd8SToby Isaac 107620cf1dd8SToby Isaac PetscFunctionBegin; 107720cf1dd8SToby Isaac PetscValidHeaderSpecific(fe,PETSCFE_CLASSID,1); 107820cf1dd8SToby Isaac PetscValidPointer(trFE,3); 107920cf1dd8SToby Isaac *trFE = NULL; 108020cf1dd8SToby Isaac ierr = PetscFEGetDualSpace(fe,&dsp);CHKERRQ(ierr); 108120cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(dsp,&dm);CHKERRQ(ierr); 108220cf1dd8SToby Isaac ierr = DMPlexGetHeightStratum(dm,height,&hStart,&hEnd);CHKERRQ(ierr); 108320cf1dd8SToby Isaac if (hEnd <= hStart) PetscFunctionReturn(0); 108420cf1dd8SToby Isaac ierr = PetscFECreatePointTrace(fe,hStart,trFE);CHKERRQ(ierr); 108520cf1dd8SToby Isaac PetscFunctionReturn(0); 108620cf1dd8SToby Isaac } 108720cf1dd8SToby Isaac 108820cf1dd8SToby Isaac 108920cf1dd8SToby Isaac /*@ 109020cf1dd8SToby Isaac PetscFEGetDimension - Get the dimension of the finite element space on a cell 109120cf1dd8SToby Isaac 109220cf1dd8SToby Isaac Not collective 109320cf1dd8SToby Isaac 109420cf1dd8SToby Isaac Input Parameter: 109520cf1dd8SToby Isaac . fe - The PetscFE 109620cf1dd8SToby Isaac 109720cf1dd8SToby Isaac Output Parameter: 109820cf1dd8SToby Isaac . dim - The dimension 109920cf1dd8SToby Isaac 110020cf1dd8SToby Isaac Level: intermediate 110120cf1dd8SToby Isaac 110220cf1dd8SToby Isaac .seealso: PetscFECreate(), PetscSpaceGetDimension(), PetscDualSpaceGetDimension() 110320cf1dd8SToby Isaac @*/ 110420cf1dd8SToby Isaac PetscErrorCode PetscFEGetDimension(PetscFE fem, PetscInt *dim) 110520cf1dd8SToby Isaac { 110620cf1dd8SToby Isaac PetscErrorCode ierr; 110720cf1dd8SToby Isaac 110820cf1dd8SToby Isaac PetscFunctionBegin; 110920cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 111020cf1dd8SToby Isaac PetscValidPointer(dim, 2); 111120cf1dd8SToby Isaac if (fem->ops->getdimension) {ierr = (*fem->ops->getdimension)(fem, dim);CHKERRQ(ierr);} 111220cf1dd8SToby Isaac PetscFunctionReturn(0); 111320cf1dd8SToby Isaac } 111420cf1dd8SToby Isaac 11154bee2e38SMatthew G. Knepley /*@C 11164bee2e38SMatthew G. Knepley PetscFEPushforward - Map the reference element function to real space 11174bee2e38SMatthew G. Knepley 11184bee2e38SMatthew G. Knepley Input Parameters: 11194bee2e38SMatthew G. Knepley + fe - The PetscFE 11204bee2e38SMatthew G. Knepley . fegeom - The cell geometry 11214bee2e38SMatthew G. Knepley . Nv - The number of function values 11224bee2e38SMatthew G. Knepley - vals - The function values 11234bee2e38SMatthew G. Knepley 11244bee2e38SMatthew G. Knepley Output Parameter: 11254bee2e38SMatthew G. Knepley . vals - The transformed function values 11264bee2e38SMatthew G. Knepley 11274bee2e38SMatthew G. Knepley Level: advanced 11284bee2e38SMatthew G. Knepley 11294bee2e38SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforward(). 11304bee2e38SMatthew G. Knepley 11314bee2e38SMatthew G. Knepley .seealso: PetscDualSpacePushforward() 11324bee2e38SMatthew G. Knepley @*/ 11334bee2e38SMatthew G. Knepley PetscErrorCode PetscFEPushforward(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 11344bee2e38SMatthew G. Knepley { 11354bee2e38SMatthew G. Knepley PetscErrorCode ierr; 11364bee2e38SMatthew G. Knepley 11372ae266adSMatthew G. Knepley PetscFunctionBeginHot; 11382ae266adSMatthew G. Knepley ierr = PetscDualSpacePushforward(fe->dualSpace, fegeom, Nv, fe->numComponents, vals);CHKERRQ(ierr); 11394bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 11404bee2e38SMatthew G. Knepley } 11414bee2e38SMatthew G. Knepley 11424bee2e38SMatthew G. Knepley /*@C 11434bee2e38SMatthew G. Knepley PetscFEPushforwardGradient - Map the reference element function gradient to real space 11444bee2e38SMatthew G. Knepley 11454bee2e38SMatthew G. Knepley Input Parameters: 11464bee2e38SMatthew G. Knepley + fe - The PetscFE 11474bee2e38SMatthew G. Knepley . fegeom - The cell geometry 11484bee2e38SMatthew G. Knepley . Nv - The number of function gradient values 11494bee2e38SMatthew G. Knepley - vals - The function gradient values 11504bee2e38SMatthew G. Knepley 11514bee2e38SMatthew G. Knepley Output Parameter: 11524bee2e38SMatthew G. Knepley . vals - The transformed function gradient values 11534bee2e38SMatthew G. Knepley 11544bee2e38SMatthew G. Knepley Level: advanced 11554bee2e38SMatthew G. Knepley 11564bee2e38SMatthew G. Knepley Note: This just forwards the call onto PetscDualSpacePushforwardGradient(). 11574bee2e38SMatthew G. Knepley 11584bee2e38SMatthew G. Knepley .seealso: PetscFEPushforward(), PetscDualSpacePushforwardGradient(), PetscDualSpacePushforward() 11594bee2e38SMatthew G. Knepley @*/ 11604bee2e38SMatthew G. Knepley PetscErrorCode PetscFEPushforwardGradient(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[]) 11614bee2e38SMatthew G. Knepley { 11624bee2e38SMatthew G. Knepley PetscErrorCode ierr; 11634bee2e38SMatthew G. Knepley 11642ae266adSMatthew G. Knepley PetscFunctionBeginHot; 11652ae266adSMatthew G. Knepley ierr = PetscDualSpacePushforwardGradient(fe->dualSpace, fegeom, Nv, fe->numComponents, vals);CHKERRQ(ierr); 11664bee2e38SMatthew G. Knepley PetscFunctionReturn(0); 11674bee2e38SMatthew G. Knepley } 11684bee2e38SMatthew G. Knepley 116920cf1dd8SToby Isaac /* 117020cf1dd8SToby Isaac Purpose: Compute element vector for chunk of elements 117120cf1dd8SToby Isaac 117220cf1dd8SToby Isaac Input: 117320cf1dd8SToby Isaac Sizes: 117420cf1dd8SToby Isaac Ne: number of elements 117520cf1dd8SToby Isaac Nf: number of fields 117620cf1dd8SToby Isaac PetscFE 117720cf1dd8SToby Isaac dim: spatial dimension 117820cf1dd8SToby Isaac Nb: number of basis functions 117920cf1dd8SToby Isaac Nc: number of field components 118020cf1dd8SToby Isaac PetscQuadrature 118120cf1dd8SToby Isaac Nq: number of quadrature points 118220cf1dd8SToby Isaac 118320cf1dd8SToby Isaac Geometry: 118420cf1dd8SToby Isaac PetscFEGeom[Ne] possibly *Nq 118520cf1dd8SToby Isaac PetscReal v0s[dim] 118620cf1dd8SToby Isaac PetscReal n[dim] 118720cf1dd8SToby Isaac PetscReal jacobians[dim*dim] 118820cf1dd8SToby Isaac PetscReal jacobianInverses[dim*dim] 118920cf1dd8SToby Isaac PetscReal jacobianDeterminants 119020cf1dd8SToby Isaac FEM: 119120cf1dd8SToby Isaac PetscFE 119220cf1dd8SToby Isaac PetscQuadrature 119320cf1dd8SToby Isaac PetscReal quadPoints[Nq*dim] 119420cf1dd8SToby Isaac PetscReal quadWeights[Nq] 119520cf1dd8SToby Isaac PetscReal basis[Nq*Nb*Nc] 119620cf1dd8SToby Isaac PetscReal basisDer[Nq*Nb*Nc*dim] 119720cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 119820cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 119920cf1dd8SToby Isaac 120020cf1dd8SToby Isaac Problem: 120120cf1dd8SToby Isaac PetscInt f: the active field 120220cf1dd8SToby Isaac f0, f1 120320cf1dd8SToby Isaac 120420cf1dd8SToby Isaac Work Space: 120520cf1dd8SToby Isaac PetscFE 120620cf1dd8SToby Isaac PetscScalar f0[Nq*dim]; 120720cf1dd8SToby Isaac PetscScalar f1[Nq*dim*dim]; 120820cf1dd8SToby Isaac PetscScalar u[Nc]; 120920cf1dd8SToby Isaac PetscScalar gradU[Nc*dim]; 121020cf1dd8SToby Isaac PetscReal x[dim]; 121120cf1dd8SToby Isaac PetscScalar realSpaceDer[dim]; 121220cf1dd8SToby Isaac 121320cf1dd8SToby Isaac Purpose: Compute element vector for N_cb batches of elements 121420cf1dd8SToby Isaac 121520cf1dd8SToby Isaac Input: 121620cf1dd8SToby Isaac Sizes: 121720cf1dd8SToby Isaac N_cb: Number of serial cell batches 121820cf1dd8SToby Isaac 121920cf1dd8SToby Isaac Geometry: 122020cf1dd8SToby Isaac PetscReal v0s[Ne*dim] 122120cf1dd8SToby Isaac PetscReal jacobians[Ne*dim*dim] possibly *Nq 122220cf1dd8SToby Isaac PetscReal jacobianInverses[Ne*dim*dim] possibly *Nq 122320cf1dd8SToby Isaac PetscReal jacobianDeterminants[Ne] possibly *Nq 122420cf1dd8SToby Isaac FEM: 122520cf1dd8SToby Isaac static PetscReal quadPoints[Nq*dim] 122620cf1dd8SToby Isaac static PetscReal quadWeights[Nq] 122720cf1dd8SToby Isaac static PetscReal basis[Nq*Nb*Nc] 122820cf1dd8SToby Isaac static PetscReal basisDer[Nq*Nb*Nc*dim] 122920cf1dd8SToby Isaac PetscScalar coefficients[Ne*Nb*Nc] 123020cf1dd8SToby Isaac PetscScalar elemVec[Ne*Nb*Nc] 123120cf1dd8SToby Isaac 123220cf1dd8SToby Isaac ex62.c: 123320cf1dd8SToby Isaac PetscErrorCode PetscFEIntegrateResidualBatch(PetscInt Ne, PetscInt numFields, PetscInt field, PetscQuadrature quad[], const PetscScalar coefficients[], 123420cf1dd8SToby Isaac const PetscReal v0s[], const PetscReal jacobians[], const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], 123520cf1dd8SToby Isaac void (*f0_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f0[]), 123620cf1dd8SToby Isaac void (*f1_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f1[]), PetscScalar elemVec[]) 123720cf1dd8SToby Isaac 123820cf1dd8SToby Isaac ex52.c: 123920cf1dd8SToby 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) 124020cf1dd8SToby 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) 124120cf1dd8SToby Isaac 124220cf1dd8SToby Isaac ex52_integrateElement.cu 124320cf1dd8SToby Isaac __global__ void integrateElementQuadrature(int N_cb, realType *coefficients, realType *jacobianInverses, realType *jacobianDeterminants, realType *elemVec) 124420cf1dd8SToby Isaac 124520cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt Nbl, const PetscScalar coefficients[], 124620cf1dd8SToby Isaac const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[], 124720cf1dd8SToby Isaac PetscLogEvent event, PetscInt debug, PetscInt pde_op) 124820cf1dd8SToby Isaac 124920cf1dd8SToby Isaac ex52_integrateElementOpenCL.c: 125020cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt N_bl, const PetscScalar coefficients[], 125120cf1dd8SToby Isaac const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[], 125220cf1dd8SToby Isaac PetscLogEvent event, PetscInt debug, PetscInt pde_op) 125320cf1dd8SToby Isaac 125420cf1dd8SToby Isaac __kernel void integrateElementQuadrature(int N_cb, __global float *coefficients, __global float *jacobianInverses, __global float *jacobianDeterminants, __global float *elemVec) 125520cf1dd8SToby Isaac */ 125620cf1dd8SToby Isaac 125720cf1dd8SToby Isaac /*@C 125820cf1dd8SToby Isaac PetscFEIntegrate - Produce the integral for the given field for a chunk of elements by quadrature integration 125920cf1dd8SToby Isaac 126020cf1dd8SToby Isaac Not collective 126120cf1dd8SToby Isaac 126220cf1dd8SToby Isaac Input Parameters: 126320cf1dd8SToby Isaac + fem - The PetscFE object for the field being integrated 126420cf1dd8SToby Isaac . prob - The PetscDS specifying the discretizations and continuum functions 126520cf1dd8SToby Isaac . field - The field being integrated 126620cf1dd8SToby Isaac . Ne - The number of elements in the chunk 126720cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 126820cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 126920cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 127020cf1dd8SToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 127120cf1dd8SToby Isaac 127220cf1dd8SToby Isaac Output Parameter 127320cf1dd8SToby Isaac . integral - the integral for this field 127420cf1dd8SToby Isaac 12752b99622eSMatthew G. Knepley Level: intermediate 127620cf1dd8SToby Isaac 127720cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual() 127820cf1dd8SToby Isaac @*/ 12794bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrate(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom, 128020cf1dd8SToby Isaac const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 128120cf1dd8SToby Isaac { 12824bee2e38SMatthew G. Knepley PetscFE fe; 128320cf1dd8SToby Isaac PetscErrorCode ierr; 128420cf1dd8SToby Isaac 128520cf1dd8SToby Isaac PetscFunctionBegin; 12864bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 12874bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr); 12884bee2e38SMatthew G. Knepley if (fe->ops->integrate) {ierr = (*fe->ops->integrate)(prob, field, Ne, cgeom, coefficients, probAux, coefficientsAux, integral);CHKERRQ(ierr);} 128920cf1dd8SToby Isaac PetscFunctionReturn(0); 129020cf1dd8SToby Isaac } 129120cf1dd8SToby Isaac 129220cf1dd8SToby Isaac /*@C 1293afe6d6adSToby Isaac PetscFEIntegrateBd - Produce the integral for the given field for a chunk of elements by quadrature integration 1294afe6d6adSToby Isaac 1295afe6d6adSToby Isaac Not collective 1296afe6d6adSToby Isaac 1297afe6d6adSToby Isaac Input Parameters: 1298afe6d6adSToby Isaac + fem - The PetscFE object for the field being integrated 1299afe6d6adSToby Isaac . prob - The PetscDS specifying the discretizations and continuum functions 1300afe6d6adSToby Isaac . field - The field being integrated 1301afe6d6adSToby Isaac . obj_func - The function to be integrated 1302afe6d6adSToby Isaac . Ne - The number of elements in the chunk 1303afe6d6adSToby Isaac . fgeom - The face geometry for each face in the chunk 1304afe6d6adSToby Isaac . coefficients - The array of FEM basis coefficients for the elements 1305afe6d6adSToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 1306afe6d6adSToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 1307afe6d6adSToby Isaac 1308afe6d6adSToby Isaac Output Parameter 1309afe6d6adSToby Isaac . integral - the integral for this field 1310afe6d6adSToby Isaac 13112b99622eSMatthew G. Knepley Level: intermediate 1312afe6d6adSToby Isaac 1313afe6d6adSToby Isaac .seealso: PetscFEIntegrateResidual() 1314afe6d6adSToby Isaac @*/ 13154bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBd(PetscDS prob, PetscInt field, 1316afe6d6adSToby Isaac void (*obj_func)(PetscInt, PetscInt, PetscInt, 1317afe6d6adSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 1318afe6d6adSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 1319afe6d6adSToby Isaac PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]), 1320afe6d6adSToby Isaac PetscInt Ne, PetscFEGeom *geom, const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 1321afe6d6adSToby Isaac { 13224bee2e38SMatthew G. Knepley PetscFE fe; 1323afe6d6adSToby Isaac PetscErrorCode ierr; 1324afe6d6adSToby Isaac 1325afe6d6adSToby Isaac PetscFunctionBegin; 13264bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13274bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr); 13284bee2e38SMatthew G. Knepley if (fe->ops->integratebd) {ierr = (*fe->ops->integratebd)(prob, field, obj_func, Ne, geom, coefficients, probAux, coefficientsAux, integral);CHKERRQ(ierr);} 1329afe6d6adSToby Isaac PetscFunctionReturn(0); 1330afe6d6adSToby Isaac } 1331afe6d6adSToby Isaac 1332afe6d6adSToby Isaac /*@C 133320cf1dd8SToby Isaac PetscFEIntegrateResidual - Produce the element residual vector for a chunk of elements by quadrature integration 133420cf1dd8SToby Isaac 133520cf1dd8SToby Isaac Not collective 133620cf1dd8SToby Isaac 133720cf1dd8SToby Isaac Input Parameters: 133820cf1dd8SToby Isaac + fem - The PetscFE object for the field being integrated 133920cf1dd8SToby Isaac . prob - The PetscDS specifying the discretizations and continuum functions 134020cf1dd8SToby Isaac . field - The field being integrated 134120cf1dd8SToby Isaac . Ne - The number of elements in the chunk 134220cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 134320cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 134420cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 134520cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 134620cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 134720cf1dd8SToby Isaac - t - The time 134820cf1dd8SToby Isaac 134920cf1dd8SToby Isaac Output Parameter 135020cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 135120cf1dd8SToby Isaac 135220cf1dd8SToby Isaac Note: 135320cf1dd8SToby Isaac $ Loop over batch of elements (e): 135420cf1dd8SToby Isaac $ Loop over quadrature points (q): 135520cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) and x_q 135620cf1dd8SToby Isaac $ Call f_0 and f_1 135720cf1dd8SToby Isaac $ Loop over element vector entries (f,fc --> i): 135820cf1dd8SToby Isaac $ elemVec[i] += \psi^{fc}_f(q) f0_{fc}(u, \nabla u) + \nabla\psi^{fc}_f(q) \cdot f1_{fc,df}(u, \nabla u) 135920cf1dd8SToby Isaac 13602b99622eSMatthew G. Knepley Level: intermediate 136120cf1dd8SToby Isaac 136220cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual() 136320cf1dd8SToby Isaac @*/ 13644bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateResidual(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom, 136520cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 136620cf1dd8SToby Isaac { 13674bee2e38SMatthew G. Knepley PetscFE fe; 136820cf1dd8SToby Isaac PetscErrorCode ierr; 136920cf1dd8SToby Isaac 137020cf1dd8SToby Isaac PetscFunctionBegin; 13714bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13724bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr); 13734bee2e38SMatthew G. Knepley if (fe->ops->integrateresidual) {ierr = (*fe->ops->integrateresidual)(prob, field, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec);CHKERRQ(ierr);} 137420cf1dd8SToby Isaac PetscFunctionReturn(0); 137520cf1dd8SToby Isaac } 137620cf1dd8SToby Isaac 137720cf1dd8SToby Isaac /*@C 137820cf1dd8SToby Isaac PetscFEIntegrateBdResidual - Produce the element residual vector for a chunk of elements by quadrature integration over a boundary 137920cf1dd8SToby Isaac 138020cf1dd8SToby Isaac Not collective 138120cf1dd8SToby Isaac 138220cf1dd8SToby Isaac Input Parameters: 138320cf1dd8SToby Isaac + fem - The PetscFE object for the field being integrated 138420cf1dd8SToby Isaac . prob - The PetscDS specifying the discretizations and continuum functions 138520cf1dd8SToby Isaac . field - The field being integrated 138620cf1dd8SToby Isaac . Ne - The number of elements in the chunk 138720cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 138820cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements 138920cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 139020cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 139120cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 139220cf1dd8SToby Isaac - t - The time 139320cf1dd8SToby Isaac 139420cf1dd8SToby Isaac Output Parameter 139520cf1dd8SToby Isaac . elemVec - the element residual vectors from each element 139620cf1dd8SToby Isaac 13972b99622eSMatthew G. Knepley Level: intermediate 139820cf1dd8SToby Isaac 139920cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual() 140020cf1dd8SToby Isaac @*/ 14014bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdResidual(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *fgeom, 140220cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 140320cf1dd8SToby Isaac { 14044bee2e38SMatthew G. Knepley PetscFE fe; 140520cf1dd8SToby Isaac PetscErrorCode ierr; 140620cf1dd8SToby Isaac 140720cf1dd8SToby Isaac PetscFunctionBegin; 14084bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 14094bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr); 14104bee2e38SMatthew G. Knepley if (fe->ops->integratebdresidual) {ierr = (*fe->ops->integratebdresidual)(prob, field, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec);CHKERRQ(ierr);} 141120cf1dd8SToby Isaac PetscFunctionReturn(0); 141220cf1dd8SToby Isaac } 141320cf1dd8SToby Isaac 141420cf1dd8SToby Isaac /*@C 141520cf1dd8SToby Isaac PetscFEIntegrateJacobian - Produce the element Jacobian for a chunk of elements by quadrature integration 141620cf1dd8SToby Isaac 141720cf1dd8SToby Isaac Not collective 141820cf1dd8SToby Isaac 141920cf1dd8SToby Isaac Input Parameters: 142020cf1dd8SToby Isaac + fem - The PetscFE object for the field being integrated 142120cf1dd8SToby Isaac . prob - The PetscDS specifying the discretizations and continuum functions 142220cf1dd8SToby Isaac . jtype - The type of matrix pointwise functions that should be used 142320cf1dd8SToby Isaac . fieldI - The test field being integrated 142420cf1dd8SToby Isaac . fieldJ - The basis field being integrated 142520cf1dd8SToby Isaac . Ne - The number of elements in the chunk 142620cf1dd8SToby Isaac . cgeom - The cell geometry for each cell in the chunk 142720cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 142820cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 142920cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 143020cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 143120cf1dd8SToby Isaac . t - The time 143220cf1dd8SToby Isaac - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 143320cf1dd8SToby Isaac 143420cf1dd8SToby Isaac Output Parameter 143520cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 143620cf1dd8SToby Isaac 143720cf1dd8SToby Isaac Note: 143820cf1dd8SToby Isaac $ Loop over batch of elements (e): 143920cf1dd8SToby Isaac $ Loop over element matrix entries (f,fc,g,gc --> i,j): 144020cf1dd8SToby Isaac $ Loop over quadrature points (q): 144120cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 144220cf1dd8SToby Isaac $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 144320cf1dd8SToby Isaac $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 144420cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 144520cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 14462b99622eSMatthew G. Knepley Level: intermediate 144720cf1dd8SToby Isaac 144820cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual() 144920cf1dd8SToby Isaac @*/ 14504bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateJacobian(PetscDS prob, PetscFEJacobianType jtype, PetscInt fieldI, PetscInt fieldJ, PetscInt Ne, PetscFEGeom *cgeom, 145120cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 145220cf1dd8SToby Isaac { 14534bee2e38SMatthew G. Knepley PetscFE fe; 145420cf1dd8SToby Isaac PetscErrorCode ierr; 145520cf1dd8SToby Isaac 145620cf1dd8SToby Isaac PetscFunctionBegin; 14574bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 14584bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, fieldI, (PetscObject *) &fe);CHKERRQ(ierr); 14594bee2e38SMatthew G. Knepley if (fe->ops->integratejacobian) {ierr = (*fe->ops->integratejacobian)(prob, jtype, fieldI, fieldJ, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat);CHKERRQ(ierr);} 146020cf1dd8SToby Isaac PetscFunctionReturn(0); 146120cf1dd8SToby Isaac } 146220cf1dd8SToby Isaac 146320cf1dd8SToby Isaac /*@C 146420cf1dd8SToby Isaac PetscFEIntegrateBdJacobian - Produce the boundary element Jacobian for a chunk of elements by quadrature integration 146520cf1dd8SToby Isaac 146620cf1dd8SToby Isaac Not collective 146720cf1dd8SToby Isaac 146820cf1dd8SToby Isaac Input Parameters: 146920cf1dd8SToby Isaac . prob - The PetscDS specifying the discretizations and continuum functions 147020cf1dd8SToby Isaac . fieldI - The test field being integrated 147120cf1dd8SToby Isaac . fieldJ - The basis field being integrated 147220cf1dd8SToby Isaac . Ne - The number of elements in the chunk 147320cf1dd8SToby Isaac . fgeom - The face geometry for each cell in the chunk 147420cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point 147520cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements 147620cf1dd8SToby Isaac . probAux - The PetscDS specifying the auxiliary discretizations 147720cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements 147820cf1dd8SToby Isaac . t - The time 147920cf1dd8SToby Isaac - u_tShift - A multiplier for the dF/du_t term (as opposed to the dF/du term) 148020cf1dd8SToby Isaac 148120cf1dd8SToby Isaac Output Parameter 148220cf1dd8SToby Isaac . elemMat - the element matrices for the Jacobian from each element 148320cf1dd8SToby Isaac 148420cf1dd8SToby Isaac Note: 148520cf1dd8SToby Isaac $ Loop over batch of elements (e): 148620cf1dd8SToby Isaac $ Loop over element matrix entries (f,fc,g,gc --> i,j): 148720cf1dd8SToby Isaac $ Loop over quadrature points (q): 148820cf1dd8SToby Isaac $ Make u_q and gradU_q (loops over fields,Nb,Ncomp) 148920cf1dd8SToby Isaac $ elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q) 149020cf1dd8SToby Isaac $ + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 149120cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q) 149220cf1dd8SToby Isaac $ + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q) 14932b99622eSMatthew G. Knepley Level: intermediate 149420cf1dd8SToby Isaac 149520cf1dd8SToby Isaac .seealso: PetscFEIntegrateJacobian(), PetscFEIntegrateResidual() 149620cf1dd8SToby Isaac @*/ 14974bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdJacobian(PetscDS prob, PetscInt fieldI, PetscInt fieldJ, PetscInt Ne, PetscFEGeom *fgeom, 149820cf1dd8SToby Isaac const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 149920cf1dd8SToby Isaac { 15004bee2e38SMatthew G. Knepley PetscFE fe; 150120cf1dd8SToby Isaac PetscErrorCode ierr; 150220cf1dd8SToby Isaac 150320cf1dd8SToby Isaac PetscFunctionBegin; 15044bee2e38SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 15054bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, fieldI, (PetscObject *) &fe);CHKERRQ(ierr); 15064bee2e38SMatthew G. Knepley if (fe->ops->integratebdjacobian) {ierr = (*fe->ops->integratebdjacobian)(prob, fieldI, fieldJ, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat);CHKERRQ(ierr);} 150720cf1dd8SToby Isaac PetscFunctionReturn(0); 150820cf1dd8SToby Isaac } 150920cf1dd8SToby Isaac 15102b99622eSMatthew G. Knepley /*@ 15112b99622eSMatthew G. Knepley PetscFEGetHeightSubspace - Get the subspace of this space for a mesh point of a given height 15122b99622eSMatthew G. Knepley 15132b99622eSMatthew G. Knepley Input Parameters: 15142b99622eSMatthew G. Knepley + fe - The finite element space 15152b99622eSMatthew G. Knepley - height - The height of the Plex point 15162b99622eSMatthew G. Knepley 15172b99622eSMatthew G. Knepley Output Parameter: 15182b99622eSMatthew G. Knepley . subfe - The subspace of this FE space 15192b99622eSMatthew G. Knepley 15202b99622eSMatthew G. Knepley Note: For example, if we want the subspace of this space for a face, we would choose height = 1. 15212b99622eSMatthew G. Knepley 15222b99622eSMatthew G. Knepley Level: advanced 15232b99622eSMatthew G. Knepley 15242b99622eSMatthew G. Knepley .seealso: PetscFECreateDefault() 15252b99622eSMatthew G. Knepley @*/ 152620cf1dd8SToby Isaac PetscErrorCode PetscFEGetHeightSubspace(PetscFE fe, PetscInt height, PetscFE *subfe) 152720cf1dd8SToby Isaac { 152820cf1dd8SToby Isaac PetscSpace P, subP; 152920cf1dd8SToby Isaac PetscDualSpace Q, subQ; 153020cf1dd8SToby Isaac PetscQuadrature subq; 153120cf1dd8SToby Isaac PetscFEType fetype; 153220cf1dd8SToby Isaac PetscInt dim, Nc; 153320cf1dd8SToby Isaac PetscErrorCode ierr; 153420cf1dd8SToby Isaac 153520cf1dd8SToby Isaac PetscFunctionBegin; 153620cf1dd8SToby Isaac PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1); 153720cf1dd8SToby Isaac PetscValidPointer(subfe, 3); 153820cf1dd8SToby Isaac if (height == 0) { 153920cf1dd8SToby Isaac *subfe = fe; 154020cf1dd8SToby Isaac PetscFunctionReturn(0); 154120cf1dd8SToby Isaac } 154220cf1dd8SToby Isaac ierr = PetscFEGetBasisSpace(fe, &P);CHKERRQ(ierr); 154320cf1dd8SToby Isaac ierr = PetscFEGetDualSpace(fe, &Q);CHKERRQ(ierr); 154420cf1dd8SToby Isaac ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 154520cf1dd8SToby Isaac ierr = PetscFEGetFaceQuadrature(fe, &subq);CHKERRQ(ierr); 154620cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension(Q, &dim);CHKERRQ(ierr); 154720cf1dd8SToby Isaac if (height > dim || height < 0) {SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Asked for space at height %D for dimension %D space", height, dim);} 154820cf1dd8SToby Isaac if (!fe->subspaces) {ierr = PetscCalloc1(dim, &fe->subspaces);CHKERRQ(ierr);} 154920cf1dd8SToby Isaac if (height <= dim) { 155020cf1dd8SToby Isaac if (!fe->subspaces[height-1]) { 155120cf1dd8SToby Isaac PetscFE sub; 15523f6b16c7SMatthew G. Knepley const char *name; 155320cf1dd8SToby Isaac 155420cf1dd8SToby Isaac ierr = PetscSpaceGetHeightSubspace(P, height, &subP);CHKERRQ(ierr); 155520cf1dd8SToby Isaac ierr = PetscDualSpaceGetHeightSubspace(Q, height, &subQ);CHKERRQ(ierr); 155620cf1dd8SToby Isaac ierr = PetscFECreate(PetscObjectComm((PetscObject) fe), &sub);CHKERRQ(ierr); 15573f6b16c7SMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) fe, &name);CHKERRQ(ierr); 15583f6b16c7SMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) sub, name);CHKERRQ(ierr); 155920cf1dd8SToby Isaac ierr = PetscFEGetType(fe, &fetype);CHKERRQ(ierr); 156020cf1dd8SToby Isaac ierr = PetscFESetType(sub, fetype);CHKERRQ(ierr); 156120cf1dd8SToby Isaac ierr = PetscFESetBasisSpace(sub, subP);CHKERRQ(ierr); 156220cf1dd8SToby Isaac ierr = PetscFESetDualSpace(sub, subQ);CHKERRQ(ierr); 156320cf1dd8SToby Isaac ierr = PetscFESetNumComponents(sub, Nc);CHKERRQ(ierr); 156420cf1dd8SToby Isaac ierr = PetscFESetUp(sub);CHKERRQ(ierr); 156520cf1dd8SToby Isaac ierr = PetscFESetQuadrature(sub, subq);CHKERRQ(ierr); 156620cf1dd8SToby Isaac fe->subspaces[height-1] = sub; 156720cf1dd8SToby Isaac } 156820cf1dd8SToby Isaac *subfe = fe->subspaces[height-1]; 156920cf1dd8SToby Isaac } else { 157020cf1dd8SToby Isaac *subfe = NULL; 157120cf1dd8SToby Isaac } 157220cf1dd8SToby Isaac PetscFunctionReturn(0); 157320cf1dd8SToby Isaac } 157420cf1dd8SToby Isaac 157520cf1dd8SToby Isaac /*@ 157620cf1dd8SToby Isaac PetscFERefine - Create a "refined" PetscFE object that refines the reference cell into smaller copies. This is typically used 157720cf1dd8SToby Isaac to precondition a higher order method with a lower order method on a refined mesh having the same number of dofs (but more 157820cf1dd8SToby Isaac sparsity). It is also used to create an interpolation between regularly refined meshes. 157920cf1dd8SToby Isaac 1580d083f849SBarry Smith Collective on fem 158120cf1dd8SToby Isaac 158220cf1dd8SToby Isaac Input Parameter: 158320cf1dd8SToby Isaac . fe - The initial PetscFE 158420cf1dd8SToby Isaac 158520cf1dd8SToby Isaac Output Parameter: 158620cf1dd8SToby Isaac . feRef - The refined PetscFE 158720cf1dd8SToby Isaac 15882b99622eSMatthew G. Knepley Level: advanced 158920cf1dd8SToby Isaac 159020cf1dd8SToby Isaac .seealso: PetscFEType, PetscFECreate(), PetscFESetType() 159120cf1dd8SToby Isaac @*/ 159220cf1dd8SToby Isaac PetscErrorCode PetscFERefine(PetscFE fe, PetscFE *feRef) 159320cf1dd8SToby Isaac { 159420cf1dd8SToby Isaac PetscSpace P, Pref; 159520cf1dd8SToby Isaac PetscDualSpace Q, Qref; 159620cf1dd8SToby Isaac DM K, Kref; 159720cf1dd8SToby Isaac PetscQuadrature q, qref; 159820cf1dd8SToby Isaac const PetscReal *v0, *jac; 159920cf1dd8SToby Isaac PetscInt numComp, numSubelements; 160020cf1dd8SToby Isaac PetscErrorCode ierr; 160120cf1dd8SToby Isaac 160220cf1dd8SToby Isaac PetscFunctionBegin; 160320cf1dd8SToby Isaac ierr = PetscFEGetBasisSpace(fe, &P);CHKERRQ(ierr); 160420cf1dd8SToby Isaac ierr = PetscFEGetDualSpace(fe, &Q);CHKERRQ(ierr); 160520cf1dd8SToby Isaac ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr); 160620cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(Q, &K);CHKERRQ(ierr); 160720cf1dd8SToby Isaac /* Create space */ 160820cf1dd8SToby Isaac ierr = PetscObjectReference((PetscObject) P);CHKERRQ(ierr); 160920cf1dd8SToby Isaac Pref = P; 161020cf1dd8SToby Isaac /* Create dual space */ 161120cf1dd8SToby Isaac ierr = PetscDualSpaceDuplicate(Q, &Qref);CHKERRQ(ierr); 161220cf1dd8SToby Isaac ierr = DMRefine(K, PetscObjectComm((PetscObject) fe), &Kref);CHKERRQ(ierr); 161320cf1dd8SToby Isaac ierr = PetscDualSpaceSetDM(Qref, Kref);CHKERRQ(ierr); 161420cf1dd8SToby Isaac ierr = DMDestroy(&Kref);CHKERRQ(ierr); 161520cf1dd8SToby Isaac ierr = PetscDualSpaceSetUp(Qref);CHKERRQ(ierr); 161620cf1dd8SToby Isaac /* Create element */ 161720cf1dd8SToby Isaac ierr = PetscFECreate(PetscObjectComm((PetscObject) fe), feRef);CHKERRQ(ierr); 161820cf1dd8SToby Isaac ierr = PetscFESetType(*feRef, PETSCFECOMPOSITE);CHKERRQ(ierr); 161920cf1dd8SToby Isaac ierr = PetscFESetBasisSpace(*feRef, Pref);CHKERRQ(ierr); 162020cf1dd8SToby Isaac ierr = PetscFESetDualSpace(*feRef, Qref);CHKERRQ(ierr); 162120cf1dd8SToby Isaac ierr = PetscFEGetNumComponents(fe, &numComp);CHKERRQ(ierr); 162220cf1dd8SToby Isaac ierr = PetscFESetNumComponents(*feRef, numComp);CHKERRQ(ierr); 162320cf1dd8SToby Isaac ierr = PetscFESetUp(*feRef);CHKERRQ(ierr); 162420cf1dd8SToby Isaac ierr = PetscSpaceDestroy(&Pref);CHKERRQ(ierr); 162520cf1dd8SToby Isaac ierr = PetscDualSpaceDestroy(&Qref);CHKERRQ(ierr); 162620cf1dd8SToby Isaac /* Create quadrature */ 162720cf1dd8SToby Isaac ierr = PetscFECompositeGetMapping(*feRef, &numSubelements, &v0, &jac, NULL);CHKERRQ(ierr); 162820cf1dd8SToby Isaac ierr = PetscQuadratureExpandComposite(q, numSubelements, v0, jac, &qref);CHKERRQ(ierr); 162920cf1dd8SToby Isaac ierr = PetscFESetQuadrature(*feRef, qref);CHKERRQ(ierr); 163020cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&qref);CHKERRQ(ierr); 163120cf1dd8SToby Isaac PetscFunctionReturn(0); 163220cf1dd8SToby Isaac } 163320cf1dd8SToby Isaac 163420cf1dd8SToby Isaac /*@C 163520cf1dd8SToby Isaac PetscFECreateDefault - Create a PetscFE for basic FEM computation 163620cf1dd8SToby Isaac 1637d083f849SBarry Smith Collective 163820cf1dd8SToby Isaac 163920cf1dd8SToby Isaac Input Parameters: 16407be5e748SToby Isaac + comm - The MPI comm 164120cf1dd8SToby Isaac . dim - The spatial dimension 164220cf1dd8SToby Isaac . Nc - The number of components 164320cf1dd8SToby Isaac . isSimplex - Flag for simplex reference cell, otherwise its a tensor product 164420cf1dd8SToby Isaac . prefix - The options prefix, or NULL 1645*727cddd5SJacob Faibussowitsch - qorder - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree 164620cf1dd8SToby Isaac 164720cf1dd8SToby Isaac Output Parameter: 164820cf1dd8SToby Isaac . fem - The PetscFE object 164920cf1dd8SToby Isaac 165020cf1dd8SToby Isaac Level: beginner 165120cf1dd8SToby Isaac 165220cf1dd8SToby Isaac .seealso: PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate() 165320cf1dd8SToby Isaac @*/ 16547be5e748SToby Isaac PetscErrorCode PetscFECreateDefault(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, const char prefix[], PetscInt qorder, PetscFE *fem) 165520cf1dd8SToby Isaac { 165620cf1dd8SToby Isaac PetscQuadrature q, fq; 165720cf1dd8SToby Isaac DM K; 165820cf1dd8SToby Isaac PetscSpace P; 165920cf1dd8SToby Isaac PetscDualSpace Q; 166020cf1dd8SToby Isaac PetscInt order, quadPointsPerEdge; 166120cf1dd8SToby Isaac PetscBool tensor = isSimplex ? PETSC_FALSE : PETSC_TRUE; 166220cf1dd8SToby Isaac PetscErrorCode ierr; 166320cf1dd8SToby Isaac 166420cf1dd8SToby Isaac PetscFunctionBegin; 166520cf1dd8SToby Isaac /* Create space */ 16667be5e748SToby Isaac ierr = PetscSpaceCreate(comm, &P);CHKERRQ(ierr); 166720cf1dd8SToby Isaac ierr = PetscObjectSetOptionsPrefix((PetscObject) P, prefix);CHKERRQ(ierr); 166820cf1dd8SToby Isaac ierr = PetscSpacePolynomialSetTensor(P, tensor);CHKERRQ(ierr); 166920cf1dd8SToby Isaac ierr = PetscSpaceSetNumComponents(P, Nc);CHKERRQ(ierr); 167020cf1dd8SToby Isaac ierr = PetscSpaceSetNumVariables(P, dim);CHKERRQ(ierr); 1671028afddaSToby Isaac ierr = PetscSpaceSetFromOptions(P);CHKERRQ(ierr); 167220cf1dd8SToby Isaac ierr = PetscSpaceSetUp(P);CHKERRQ(ierr); 167320cf1dd8SToby Isaac ierr = PetscSpaceGetDegree(P, &order, NULL);CHKERRQ(ierr); 167420cf1dd8SToby Isaac ierr = PetscSpacePolynomialGetTensor(P, &tensor);CHKERRQ(ierr); 167520cf1dd8SToby Isaac /* Create dual space */ 16767be5e748SToby Isaac ierr = PetscDualSpaceCreate(comm, &Q);CHKERRQ(ierr); 167720cf1dd8SToby Isaac ierr = PetscDualSpaceSetType(Q,PETSCDUALSPACELAGRANGE);CHKERRQ(ierr); 167820cf1dd8SToby Isaac ierr = PetscObjectSetOptionsPrefix((PetscObject) Q, prefix);CHKERRQ(ierr); 167920cf1dd8SToby Isaac ierr = PetscDualSpaceCreateReferenceCell(Q, dim, isSimplex, &K);CHKERRQ(ierr); 168020cf1dd8SToby Isaac ierr = PetscDualSpaceSetDM(Q, K);CHKERRQ(ierr); 168120cf1dd8SToby Isaac ierr = DMDestroy(&K);CHKERRQ(ierr); 168220cf1dd8SToby Isaac ierr = PetscDualSpaceSetNumComponents(Q, Nc);CHKERRQ(ierr); 168320cf1dd8SToby Isaac ierr = PetscDualSpaceSetOrder(Q, order);CHKERRQ(ierr); 168420cf1dd8SToby Isaac ierr = PetscDualSpaceLagrangeSetTensor(Q, tensor);CHKERRQ(ierr); 168520cf1dd8SToby Isaac ierr = PetscDualSpaceSetFromOptions(Q);CHKERRQ(ierr); 168620cf1dd8SToby Isaac ierr = PetscDualSpaceSetUp(Q);CHKERRQ(ierr); 168720cf1dd8SToby Isaac /* Create element */ 16887be5e748SToby Isaac ierr = PetscFECreate(comm, fem);CHKERRQ(ierr); 168920cf1dd8SToby Isaac ierr = PetscObjectSetOptionsPrefix((PetscObject) *fem, prefix);CHKERRQ(ierr); 169020cf1dd8SToby Isaac ierr = PetscFESetBasisSpace(*fem, P);CHKERRQ(ierr); 169120cf1dd8SToby Isaac ierr = PetscFESetDualSpace(*fem, Q);CHKERRQ(ierr); 169220cf1dd8SToby Isaac ierr = PetscFESetNumComponents(*fem, Nc);CHKERRQ(ierr); 169391e89cf0SMatthew G. Knepley ierr = PetscFESetFromOptions(*fem);CHKERRQ(ierr); 169420cf1dd8SToby Isaac ierr = PetscFESetUp(*fem);CHKERRQ(ierr); 169520cf1dd8SToby Isaac ierr = PetscSpaceDestroy(&P);CHKERRQ(ierr); 169620cf1dd8SToby Isaac ierr = PetscDualSpaceDestroy(&Q);CHKERRQ(ierr); 169720cf1dd8SToby Isaac /* Create quadrature (with specified order if given) */ 169820cf1dd8SToby Isaac qorder = qorder >= 0 ? qorder : order; 169920cf1dd8SToby Isaac ierr = PetscObjectOptionsBegin((PetscObject)*fem);CHKERRQ(ierr); 17005a856986SBarry Smith ierr = PetscOptionsBoundedInt("-petscfe_default_quadrature_order","Quadrature order is one less than quadrature points per edge","PetscFECreateDefault",qorder,&qorder,NULL,0);CHKERRQ(ierr); 170120cf1dd8SToby Isaac ierr = PetscOptionsEnd();CHKERRQ(ierr); 170220cf1dd8SToby Isaac quadPointsPerEdge = PetscMax(qorder + 1,1); 170320cf1dd8SToby Isaac if (isSimplex) { 170420cf1dd8SToby Isaac ierr = PetscDTGaussJacobiQuadrature(dim, 1, quadPointsPerEdge, -1.0, 1.0, &q);CHKERRQ(ierr); 170520cf1dd8SToby Isaac ierr = PetscDTGaussJacobiQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, &fq);CHKERRQ(ierr); 17064ccfa306SStefano Zampini } else { 170720cf1dd8SToby Isaac ierr = PetscDTGaussTensorQuadrature(dim, 1, quadPointsPerEdge, -1.0, 1.0, &q);CHKERRQ(ierr); 170820cf1dd8SToby Isaac ierr = PetscDTGaussTensorQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, &fq);CHKERRQ(ierr); 170920cf1dd8SToby Isaac } 171020cf1dd8SToby Isaac ierr = PetscFESetQuadrature(*fem, q);CHKERRQ(ierr); 171120cf1dd8SToby Isaac ierr = PetscFESetFaceQuadrature(*fem, fq);CHKERRQ(ierr); 171220cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&q);CHKERRQ(ierr); 171320cf1dd8SToby Isaac ierr = PetscQuadratureDestroy(&fq);CHKERRQ(ierr); 171420cf1dd8SToby Isaac PetscFunctionReturn(0); 171520cf1dd8SToby Isaac } 17163f6b16c7SMatthew G. Knepley 17173f6b16c7SMatthew G. Knepley /*@C 17183f6b16c7SMatthew G. Knepley PetscFESetName - Names the FE and its subobjects 17193f6b16c7SMatthew G. Knepley 17203f6b16c7SMatthew G. Knepley Not collective 17213f6b16c7SMatthew G. Knepley 17223f6b16c7SMatthew G. Knepley Input Parameters: 17233f6b16c7SMatthew G. Knepley + fe - The PetscFE 17243f6b16c7SMatthew G. Knepley - name - The name 17253f6b16c7SMatthew G. Knepley 17262b99622eSMatthew G. Knepley Level: intermediate 17273f6b16c7SMatthew G. Knepley 17283f6b16c7SMatthew G. Knepley .seealso: PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate() 17293f6b16c7SMatthew G. Knepley @*/ 17303f6b16c7SMatthew G. Knepley PetscErrorCode PetscFESetName(PetscFE fe, const char name[]) 17313f6b16c7SMatthew G. Knepley { 17323f6b16c7SMatthew G. Knepley PetscSpace P; 17333f6b16c7SMatthew G. Knepley PetscDualSpace Q; 17343f6b16c7SMatthew G. Knepley PetscErrorCode ierr; 17353f6b16c7SMatthew G. Knepley 17363f6b16c7SMatthew G. Knepley PetscFunctionBegin; 17373f6b16c7SMatthew G. Knepley ierr = PetscFEGetBasisSpace(fe, &P);CHKERRQ(ierr); 17383f6b16c7SMatthew G. Knepley ierr = PetscFEGetDualSpace(fe, &Q);CHKERRQ(ierr); 17393f6b16c7SMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) fe, name);CHKERRQ(ierr); 17403f6b16c7SMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) P, name);CHKERRQ(ierr); 17413f6b16c7SMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) Q, name);CHKERRQ(ierr); 17423f6b16c7SMatthew G. Knepley PetscFunctionReturn(0); 17433f6b16c7SMatthew G. Knepley } 1744a8f1f9e5SMatthew G. Knepley 1745a8f1f9e5SMatthew G. Knepley PetscErrorCode PetscFEEvaluateFieldJets_Internal(PetscDS ds, PetscInt dim, PetscInt Nf, const PetscInt Nb[], const PetscInt Nc[], PetscInt q, PetscReal *basisField[], PetscReal *basisFieldDer[], PetscFEGeom *fegeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscScalar u[], PetscScalar u_x[], PetscScalar u_t[]) 1746a8f1f9e5SMatthew G. Knepley { 1747a8f1f9e5SMatthew G. Knepley PetscInt dOffset = 0, fOffset = 0, f; 1748a8f1f9e5SMatthew G. Knepley PetscErrorCode ierr; 1749a8f1f9e5SMatthew G. Knepley 1750a8f1f9e5SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 1751a8f1f9e5SMatthew G. Knepley PetscFE fe; 1752a8f1f9e5SMatthew G. Knepley const PetscInt Nbf = Nb[f], Ncf = Nc[f]; 1753a8f1f9e5SMatthew G. Knepley const PetscReal *Bq = &basisField[f][q*Nbf*Ncf]; 1754a8f1f9e5SMatthew G. Knepley const PetscReal *Dq = &basisFieldDer[f][q*Nbf*Ncf*dim]; 1755a8f1f9e5SMatthew G. Knepley PetscInt b, c, d; 1756a8f1f9e5SMatthew G. Knepley 1757a8f1f9e5SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, f, (PetscObject *) &fe);CHKERRQ(ierr); 1758a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u[fOffset+c] = 0.0; 1759a8f1f9e5SMatthew G. Knepley for (d = 0; d < dim*Ncf; ++d) u_x[fOffset*dim+d] = 0.0; 1760a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 1761a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 1762a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 1763a8f1f9e5SMatthew G. Knepley 1764a8f1f9e5SMatthew G. Knepley u[fOffset+c] += Bq[cidx]*coefficients[dOffset+b]; 1765a8f1f9e5SMatthew G. Knepley for (d = 0; d < dim; ++d) u_x[(fOffset+c)*dim+d] += Dq[cidx*dim+d]*coefficients[dOffset+b]; 1766a8f1f9e5SMatthew G. Knepley } 1767a8f1f9e5SMatthew G. Knepley } 1768a8f1f9e5SMatthew G. Knepley ierr = PetscFEPushforward(fe, fegeom, 1, &u[fOffset]);CHKERRQ(ierr); 1769a8f1f9e5SMatthew G. Knepley ierr = PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset*dim]);CHKERRQ(ierr); 1770a8f1f9e5SMatthew G. Knepley if (u_t) { 1771a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) u_t[fOffset+c] = 0.0; 1772a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nbf; ++b) { 1773a8f1f9e5SMatthew G. Knepley for (c = 0; c < Ncf; ++c) { 1774a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b*Ncf+c; 1775a8f1f9e5SMatthew G. Knepley 1776a8f1f9e5SMatthew G. Knepley u_t[fOffset+c] += Bq[cidx]*coefficients_t[dOffset+b]; 1777a8f1f9e5SMatthew G. Knepley } 1778a8f1f9e5SMatthew G. Knepley } 1779a8f1f9e5SMatthew G. Knepley ierr = PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset]);CHKERRQ(ierr); 1780a8f1f9e5SMatthew G. Knepley } 1781a8f1f9e5SMatthew G. Knepley fOffset += Ncf; 1782a8f1f9e5SMatthew G. Knepley dOffset += Nbf; 1783a8f1f9e5SMatthew G. Knepley } 1784a8f1f9e5SMatthew G. Knepley return 0; 1785a8f1f9e5SMatthew G. Knepley } 1786a8f1f9e5SMatthew G. Knepley 1787a8f1f9e5SMatthew G. Knepley PetscErrorCode PetscFEEvaluateFaceFields_Internal(PetscDS prob, PetscInt field, PetscInt faceLoc, const PetscScalar coefficients[], PetscScalar u[]) 1788a8f1f9e5SMatthew G. Knepley { 1789a8f1f9e5SMatthew G. Knepley PetscFE fe; 1790a8f1f9e5SMatthew G. Knepley PetscReal *faceBasis; 1791a8f1f9e5SMatthew G. Knepley PetscInt Nb, Nc, b, c; 1792a8f1f9e5SMatthew G. Knepley PetscErrorCode ierr; 1793a8f1f9e5SMatthew G. Knepley 1794a8f1f9e5SMatthew G. Knepley if (!prob) return 0; 1795a8f1f9e5SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr); 1796a8f1f9e5SMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 1797a8f1f9e5SMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 1798a8f1f9e5SMatthew G. Knepley ierr = PetscFEGetFaceCentroidTabulation(fe, &faceBasis);CHKERRQ(ierr); 1799a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) {u[c] = 0.0;} 1800a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 1801a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 1802a8f1f9e5SMatthew G. Knepley const PetscInt cidx = b*Nc+c; 1803a8f1f9e5SMatthew G. Knepley 1804a8f1f9e5SMatthew G. Knepley u[c] += coefficients[cidx]*faceBasis[faceLoc*Nb*Nc+cidx]; 1805a8f1f9e5SMatthew G. Knepley } 1806a8f1f9e5SMatthew G. Knepley } 1807a8f1f9e5SMatthew G. Knepley return 0; 1808a8f1f9e5SMatthew G. Knepley } 1809a8f1f9e5SMatthew G. Knepley 18106142fa51SMatthew G. Knepley PetscErrorCode PetscFEUpdateElementVec_Internal(PetscFE fe, PetscInt dim, PetscInt Nq, PetscInt Nb, PetscInt Nc, PetscReal basis[], PetscReal basisDer[], PetscScalar tmpBasis[], PetscScalar tmpBasisDer[], PetscFEGeom *fegeom, PetscScalar f0[], PetscScalar f1[], PetscScalar elemVec[]) 1811a8f1f9e5SMatthew G. Knepley { 1812a8f1f9e5SMatthew G. Knepley PetscInt q, b, c, d; 1813a8f1f9e5SMatthew G. Knepley PetscErrorCode ierr; 1814a8f1f9e5SMatthew G. Knepley 1815a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) elemVec[b] = 0.0; 1816a8f1f9e5SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 1817a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 1818a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 1819a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 1820a8f1f9e5SMatthew G. Knepley 1821a8f1f9e5SMatthew G. Knepley tmpBasis[bcidx] = basis[q*Nb*Nc+bcidx]; 1822a8f1f9e5SMatthew G. Knepley for (d = 0; d < dim; ++d) tmpBasisDer[bcidx*dim+d] = basisDer[q*Nb*Nc*dim+bcidx*dim+d]; 1823a8f1f9e5SMatthew G. Knepley } 1824a8f1f9e5SMatthew G. Knepley } 1825a8f1f9e5SMatthew G. Knepley ierr = PetscFEPushforward(fe, fegeom, Nb, tmpBasis);CHKERRQ(ierr); 1826a8f1f9e5SMatthew G. Knepley ierr = PetscFEPushforwardGradient(fe, fegeom, Nb, tmpBasisDer);CHKERRQ(ierr); 1827a8f1f9e5SMatthew G. Knepley for (b = 0; b < Nb; ++b) { 1828a8f1f9e5SMatthew G. Knepley for (c = 0; c < Nc; ++c) { 1829a8f1f9e5SMatthew G. Knepley const PetscInt bcidx = b*Nc+c; 1830a8f1f9e5SMatthew G. Knepley const PetscInt qcidx = q*Nc+c; 1831a8f1f9e5SMatthew G. Knepley 1832a8f1f9e5SMatthew G. Knepley elemVec[b] += tmpBasis[bcidx]*f0[qcidx]; 1833a8f1f9e5SMatthew G. Knepley for (d = 0; d < dim; ++d) elemVec[b] += tmpBasisDer[bcidx*dim+d]*f1[qcidx*dim+d]; 1834a8f1f9e5SMatthew G. Knepley } 1835a8f1f9e5SMatthew G. Knepley } 1836a8f1f9e5SMatthew G. Knepley } 1837a8f1f9e5SMatthew G. Knepley return(0); 1838a8f1f9e5SMatthew G. Knepley } 1839a8f1f9e5SMatthew G. Knepley 18406142fa51SMatthew G. Knepley PetscErrorCode PetscFEUpdateElementMat_Internal(PetscFE feI, PetscFE feJ, PetscInt dim, PetscInt NbI, PetscInt NcI, const PetscReal basisI[], const PetscReal basisDerI[], PetscScalar tmpBasisI[], PetscScalar tmpBasisDerI[], PetscInt NbJ, PetscInt NcJ, const PetscReal basisJ[], const PetscReal basisDerJ[], 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[]) 1841a8f1f9e5SMatthew G. Knepley { 1842a8f1f9e5SMatthew G. Knepley PetscInt f, fc, g, gc, df, dg; 1843a8f1f9e5SMatthew G. Knepley PetscErrorCode ierr; 1844a8f1f9e5SMatthew G. Knepley 1845a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 1846a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 1847a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 1848a8f1f9e5SMatthew G. Knepley 1849a8f1f9e5SMatthew G. Knepley tmpBasisI[fidx] = basisI[fidx]; 1850a8f1f9e5SMatthew G. Knepley for (df = 0; df < dim; ++df) tmpBasisDerI[fidx*dim+df] = basisDerI[fidx*dim+df]; 1851a8f1f9e5SMatthew G. Knepley } 1852a8f1f9e5SMatthew G. Knepley } 1853a8f1f9e5SMatthew G. Knepley ierr = PetscFEPushforward(feI, fegeom, NbI, tmpBasisI);CHKERRQ(ierr); 1854a8f1f9e5SMatthew G. Knepley ierr = PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI);CHKERRQ(ierr); 1855a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 1856a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 1857a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 1858a8f1f9e5SMatthew G. Knepley 1859a8f1f9e5SMatthew G. Knepley tmpBasisJ[gidx] = basisJ[gidx]; 1860a8f1f9e5SMatthew G. Knepley for (dg = 0; dg < dim; ++dg) tmpBasisDerJ[gidx*dim+dg] = basisDerJ[gidx*dim+dg]; 1861a8f1f9e5SMatthew G. Knepley } 1862a8f1f9e5SMatthew G. Knepley } 1863a8f1f9e5SMatthew G. Knepley ierr = PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ);CHKERRQ(ierr); 1864a8f1f9e5SMatthew G. Knepley ierr = PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ);CHKERRQ(ierr); 1865a8f1f9e5SMatthew G. Knepley for (f = 0; f < NbI; ++f) { 1866a8f1f9e5SMatthew G. Knepley for (fc = 0; fc < NcI; ++fc) { 1867a8f1f9e5SMatthew G. Knepley const PetscInt fidx = f*NcI+fc; /* Test function basis index */ 1868a8f1f9e5SMatthew G. Knepley const PetscInt i = offsetI+f; /* Element matrix row */ 1869a8f1f9e5SMatthew G. Knepley for (g = 0; g < NbJ; ++g) { 1870a8f1f9e5SMatthew G. Knepley for (gc = 0; gc < NcJ; ++gc) { 1871a8f1f9e5SMatthew G. Knepley const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */ 1872a8f1f9e5SMatthew G. Knepley const PetscInt j = offsetJ+g; /* Element matrix column */ 1873a8f1f9e5SMatthew G. Knepley const PetscInt fOff = eOffset+i*totDim+j; 1874a8f1f9e5SMatthew G. Knepley 1875a8f1f9e5SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g0[fc*NcJ+gc]*tmpBasisJ[gidx]; 1876a8f1f9e5SMatthew G. Knepley for (df = 0; df < dim; ++df) { 1877a8f1f9e5SMatthew G. Knepley elemMat[fOff] += tmpBasisI[fidx]*g1[(fc*NcJ+gc)*dim+df]*tmpBasisDerJ[gidx*dim+df]; 1878a8f1f9e5SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dim+df]*g2[(fc*NcJ+gc)*dim+df]*tmpBasisJ[gidx]; 1879a8f1f9e5SMatthew G. Knepley for (dg = 0; dg < dim; ++dg) { 1880a8f1f9e5SMatthew G. Knepley elemMat[fOff] += tmpBasisDerI[fidx*dim+df]*g3[((fc*NcJ+gc)*dim+df)*dim+dg]*tmpBasisDerJ[gidx*dim+dg]; 1881a8f1f9e5SMatthew G. Knepley } 1882a8f1f9e5SMatthew G. Knepley } 1883a8f1f9e5SMatthew G. Knepley } 1884a8f1f9e5SMatthew G. Knepley } 1885a8f1f9e5SMatthew G. Knepley } 1886a8f1f9e5SMatthew G. Knepley } 1887a8f1f9e5SMatthew G. Knepley return(0); 1888a8f1f9e5SMatthew G. Knepley } 1889c9ba7969SMatthew G. Knepley 1890c9ba7969SMatthew G. Knepley PetscErrorCode PetscFECreateCellGeometry(PetscFE fe, PetscQuadrature quad, PetscFEGeom *cgeom) 1891c9ba7969SMatthew G. Knepley { 1892c9ba7969SMatthew G. Knepley PetscDualSpace dsp; 1893c9ba7969SMatthew G. Knepley DM dm; 1894c9ba7969SMatthew G. Knepley PetscQuadrature quadDef; 1895c9ba7969SMatthew G. Knepley PetscInt dim, cdim, Nq; 1896c9ba7969SMatthew G. Knepley PetscErrorCode ierr; 1897c9ba7969SMatthew G. Knepley 1898c9ba7969SMatthew G. Knepley PetscFunctionBegin; 1899c9ba7969SMatthew G. Knepley ierr = PetscFEGetDualSpace(fe, &dsp);CHKERRQ(ierr); 1900c9ba7969SMatthew G. Knepley ierr = PetscDualSpaceGetDM(dsp, &dm);CHKERRQ(ierr); 1901c9ba7969SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 1902c9ba7969SMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &cdim);CHKERRQ(ierr); 1903c9ba7969SMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &quadDef);CHKERRQ(ierr); 1904c9ba7969SMatthew G. Knepley quad = quad ? quad : quadDef; 1905c9ba7969SMatthew G. Knepley ierr = PetscQuadratureGetData(quad, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr); 1906c9ba7969SMatthew G. Knepley ierr = PetscMalloc1(Nq*cdim, &cgeom->v);CHKERRQ(ierr); 1907c9ba7969SMatthew G. Knepley ierr = PetscMalloc1(Nq*cdim*cdim, &cgeom->J);CHKERRQ(ierr); 1908c9ba7969SMatthew G. Knepley ierr = PetscMalloc1(Nq*cdim*cdim, &cgeom->invJ);CHKERRQ(ierr); 1909c9ba7969SMatthew G. Knepley ierr = PetscMalloc1(Nq, &cgeom->detJ);CHKERRQ(ierr); 1910c9ba7969SMatthew G. Knepley cgeom->dim = dim; 1911c9ba7969SMatthew G. Knepley cgeom->dimEmbed = cdim; 1912c9ba7969SMatthew G. Knepley cgeom->numCells = 1; 1913c9ba7969SMatthew G. Knepley cgeom->numPoints = Nq; 1914c9ba7969SMatthew G. Knepley ierr = DMPlexComputeCellGeometryFEM(dm, 0, quad, cgeom->v, cgeom->J, cgeom->invJ, cgeom->detJ);CHKERRQ(ierr); 1915c9ba7969SMatthew G. Knepley PetscFunctionReturn(0); 1916c9ba7969SMatthew G. Knepley } 1917c9ba7969SMatthew G. Knepley 1918c9ba7969SMatthew G. Knepley PetscErrorCode PetscFEDestroyCellGeometry(PetscFE fe, PetscFEGeom *cgeom) 1919c9ba7969SMatthew G. Knepley { 1920c9ba7969SMatthew G. Knepley PetscErrorCode ierr; 1921c9ba7969SMatthew G. Knepley 1922c9ba7969SMatthew G. Knepley PetscFunctionBegin; 1923c9ba7969SMatthew G. Knepley ierr = PetscFree(cgeom->v);CHKERRQ(ierr); 1924c9ba7969SMatthew G. Knepley ierr = PetscFree(cgeom->J);CHKERRQ(ierr); 1925c9ba7969SMatthew G. Knepley ierr = PetscFree(cgeom->invJ);CHKERRQ(ierr); 1926c9ba7969SMatthew G. Knepley ierr = PetscFree(cgeom->detJ);CHKERRQ(ierr); 1927c9ba7969SMatthew G. Knepley PetscFunctionReturn(0); 1928c9ba7969SMatthew G. Knepley } 1929