xref: /petsc/src/dm/dt/fe/interface/fe.c (revision 27f02ce888cd6d83c79d307cd15e2865fe9f0ab4)
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
167fe2efc57SMark    PetscFEViewFromOptions - View from Options
168fe2efc57SMark 
169fe2efc57SMark    Collective on PetscFE
170fe2efc57SMark 
171fe2efc57SMark    Input Parameters:
172fe2efc57SMark +  A - the PetscFE object
173fe2efc57SMark .  obj - Optional object
174fe2efc57SMark -  name - command line option
175fe2efc57SMark 
176fe2efc57SMark    Level: intermediate
177fe2efc57SMark .seealso:  PetscFE(), PetscFEView(), PetscObjectViewFromOptions(), PetscFECreate()
178fe2efc57SMark @*/
179fe2efc57SMark PetscErrorCode  PetscFEViewFromOptions(PetscFE A,PetscObject obj,const char name[])
180fe2efc57SMark {
181fe2efc57SMark   PetscErrorCode ierr;
182fe2efc57SMark 
183fe2efc57SMark   PetscFunctionBegin;
184fe2efc57SMark   PetscValidHeaderSpecific(A,PETSCFE_CLASSID,1);
185fe2efc57SMark   ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr);
186fe2efc57SMark   PetscFunctionReturn(0);
187fe2efc57SMark }
188fe2efc57SMark 
189fe2efc57SMark /*@C
19020cf1dd8SToby Isaac   PetscFEView - Views a PetscFE
19120cf1dd8SToby Isaac 
192d083f849SBarry Smith   Collective on fem
19320cf1dd8SToby Isaac 
19420cf1dd8SToby Isaac   Input Parameter:
19520cf1dd8SToby Isaac + fem - the PetscFE object to view
196d9bac1caSLisandro Dalcin - viewer   - the viewer
19720cf1dd8SToby Isaac 
1982b99622eSMatthew G. Knepley   Level: beginner
19920cf1dd8SToby Isaac 
20020cf1dd8SToby Isaac .seealso PetscFEDestroy()
20120cf1dd8SToby Isaac @*/
202d9bac1caSLisandro Dalcin PetscErrorCode PetscFEView(PetscFE fem, PetscViewer viewer)
20320cf1dd8SToby Isaac {
204d9bac1caSLisandro Dalcin   PetscBool      iascii;
20520cf1dd8SToby Isaac   PetscErrorCode ierr;
20620cf1dd8SToby Isaac 
20720cf1dd8SToby Isaac   PetscFunctionBegin;
20820cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
209d9bac1caSLisandro Dalcin   if (viewer) PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2);
210d9bac1caSLisandro Dalcin   if (!viewer) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) fem), &viewer);CHKERRQ(ierr);}
211d9bac1caSLisandro Dalcin   ierr = PetscObjectPrintClassNamePrefixType((PetscObject)fem, viewer);CHKERRQ(ierr);
212d9bac1caSLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
213d9bac1caSLisandro Dalcin   if (fem->ops->view) {ierr = (*fem->ops->view)(fem, viewer);CHKERRQ(ierr);}
21420cf1dd8SToby Isaac   PetscFunctionReturn(0);
21520cf1dd8SToby Isaac }
21620cf1dd8SToby Isaac 
21720cf1dd8SToby Isaac /*@
21820cf1dd8SToby Isaac   PetscFESetFromOptions - sets parameters in a PetscFE from the options database
21920cf1dd8SToby Isaac 
220d083f849SBarry Smith   Collective on fem
22120cf1dd8SToby Isaac 
22220cf1dd8SToby Isaac   Input Parameter:
22320cf1dd8SToby Isaac . fem - the PetscFE object to set options for
22420cf1dd8SToby Isaac 
22520cf1dd8SToby Isaac   Options Database:
226a2b725a8SWilliam Gropp + -petscfe_num_blocks  - the number of cell blocks to integrate concurrently
227a2b725a8SWilliam Gropp - -petscfe_num_batches - the number of cell batches to integrate serially
22820cf1dd8SToby Isaac 
2292b99622eSMatthew G. Knepley   Level: intermediate
23020cf1dd8SToby Isaac 
23120cf1dd8SToby Isaac .seealso PetscFEView()
23220cf1dd8SToby Isaac @*/
23320cf1dd8SToby Isaac PetscErrorCode PetscFESetFromOptions(PetscFE fem)
23420cf1dd8SToby Isaac {
23520cf1dd8SToby Isaac   const char    *defaultType;
23620cf1dd8SToby Isaac   char           name[256];
23720cf1dd8SToby Isaac   PetscBool      flg;
23820cf1dd8SToby Isaac   PetscErrorCode ierr;
23920cf1dd8SToby Isaac 
24020cf1dd8SToby Isaac   PetscFunctionBegin;
24120cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
24220cf1dd8SToby Isaac   if (!((PetscObject) fem)->type_name) {
24320cf1dd8SToby Isaac     defaultType = PETSCFEBASIC;
24420cf1dd8SToby Isaac   } else {
24520cf1dd8SToby Isaac     defaultType = ((PetscObject) fem)->type_name;
24620cf1dd8SToby Isaac   }
24720cf1dd8SToby Isaac   if (!PetscFERegisterAllCalled) {ierr = PetscFERegisterAll();CHKERRQ(ierr);}
24820cf1dd8SToby Isaac 
24920cf1dd8SToby Isaac   ierr = PetscObjectOptionsBegin((PetscObject) fem);CHKERRQ(ierr);
25020cf1dd8SToby Isaac   ierr = PetscOptionsFList("-petscfe_type", "Finite element space", "PetscFESetType", PetscFEList, defaultType, name, 256, &flg);CHKERRQ(ierr);
25120cf1dd8SToby Isaac   if (flg) {
25220cf1dd8SToby Isaac     ierr = PetscFESetType(fem, name);CHKERRQ(ierr);
25320cf1dd8SToby Isaac   } else if (!((PetscObject) fem)->type_name) {
25420cf1dd8SToby Isaac     ierr = PetscFESetType(fem, defaultType);CHKERRQ(ierr);
25520cf1dd8SToby Isaac   }
2565a856986SBarry Smith   ierr = PetscOptionsBoundedInt("-petscfe_num_blocks", "The number of cell blocks to integrate concurrently", "PetscSpaceSetTileSizes", fem->numBlocks, &fem->numBlocks, NULL,1);CHKERRQ(ierr);
2575a856986SBarry Smith   ierr = PetscOptionsBoundedInt("-petscfe_num_batches", "The number of cell batches to integrate serially", "PetscSpaceSetTileSizes", fem->numBatches, &fem->numBatches, NULL,1);CHKERRQ(ierr);
25820cf1dd8SToby Isaac   if (fem->ops->setfromoptions) {
25920cf1dd8SToby Isaac     ierr = (*fem->ops->setfromoptions)(PetscOptionsObject,fem);CHKERRQ(ierr);
26020cf1dd8SToby Isaac   }
26120cf1dd8SToby Isaac   /* process any options handlers added with PetscObjectAddOptionsHandler() */
26220cf1dd8SToby Isaac   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) fem);CHKERRQ(ierr);
26320cf1dd8SToby Isaac   ierr = PetscOptionsEnd();CHKERRQ(ierr);
26420cf1dd8SToby Isaac   ierr = PetscFEViewFromOptions(fem, NULL, "-petscfe_view");CHKERRQ(ierr);
26520cf1dd8SToby Isaac   PetscFunctionReturn(0);
26620cf1dd8SToby Isaac }
26720cf1dd8SToby Isaac 
26820cf1dd8SToby Isaac /*@C
26920cf1dd8SToby Isaac   PetscFESetUp - Construct data structures for the PetscFE
27020cf1dd8SToby Isaac 
271d083f849SBarry Smith   Collective on fem
27220cf1dd8SToby Isaac 
27320cf1dd8SToby Isaac   Input Parameter:
27420cf1dd8SToby Isaac . fem - the PetscFE object to setup
27520cf1dd8SToby Isaac 
2762b99622eSMatthew G. Knepley   Level: intermediate
27720cf1dd8SToby Isaac 
27820cf1dd8SToby Isaac .seealso PetscFEView(), PetscFEDestroy()
27920cf1dd8SToby Isaac @*/
28020cf1dd8SToby Isaac PetscErrorCode PetscFESetUp(PetscFE fem)
28120cf1dd8SToby Isaac {
28220cf1dd8SToby Isaac   PetscErrorCode ierr;
28320cf1dd8SToby Isaac 
28420cf1dd8SToby Isaac   PetscFunctionBegin;
28520cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
28620cf1dd8SToby Isaac   if (fem->setupcalled) PetscFunctionReturn(0);
28720cf1dd8SToby Isaac   fem->setupcalled = PETSC_TRUE;
28820cf1dd8SToby Isaac   if (fem->ops->setup) {ierr = (*fem->ops->setup)(fem);CHKERRQ(ierr);}
28920cf1dd8SToby Isaac   PetscFunctionReturn(0);
29020cf1dd8SToby Isaac }
29120cf1dd8SToby Isaac 
29220cf1dd8SToby Isaac /*@
29320cf1dd8SToby Isaac   PetscFEDestroy - Destroys a PetscFE object
29420cf1dd8SToby Isaac 
295d083f849SBarry Smith   Collective on fem
29620cf1dd8SToby Isaac 
29720cf1dd8SToby Isaac   Input Parameter:
29820cf1dd8SToby Isaac . fem - the PetscFE object to destroy
29920cf1dd8SToby Isaac 
3002b99622eSMatthew G. Knepley   Level: beginner
30120cf1dd8SToby Isaac 
30220cf1dd8SToby Isaac .seealso PetscFEView()
30320cf1dd8SToby Isaac @*/
30420cf1dd8SToby Isaac PetscErrorCode PetscFEDestroy(PetscFE *fem)
30520cf1dd8SToby Isaac {
30620cf1dd8SToby Isaac   PetscErrorCode ierr;
30720cf1dd8SToby Isaac 
30820cf1dd8SToby Isaac   PetscFunctionBegin;
30920cf1dd8SToby Isaac   if (!*fem) PetscFunctionReturn(0);
31020cf1dd8SToby Isaac   PetscValidHeaderSpecific((*fem), PETSCFE_CLASSID, 1);
31120cf1dd8SToby Isaac 
31220cf1dd8SToby Isaac   if (--((PetscObject)(*fem))->refct > 0) {*fem = 0; PetscFunctionReturn(0);}
31320cf1dd8SToby Isaac   ((PetscObject) (*fem))->refct = 0;
31420cf1dd8SToby Isaac 
31520cf1dd8SToby Isaac   if ((*fem)->subspaces) {
31620cf1dd8SToby Isaac     PetscInt dim, d;
31720cf1dd8SToby Isaac 
31820cf1dd8SToby Isaac     ierr = PetscDualSpaceGetDimension((*fem)->dualSpace, &dim);CHKERRQ(ierr);
31920cf1dd8SToby Isaac     for (d = 0; d < dim; ++d) {ierr = PetscFEDestroy(&(*fem)->subspaces[d]);CHKERRQ(ierr);}
32020cf1dd8SToby Isaac   }
32120cf1dd8SToby Isaac   ierr = PetscFree((*fem)->subspaces);CHKERRQ(ierr);
32220cf1dd8SToby Isaac   ierr = PetscFree((*fem)->invV);CHKERRQ(ierr);
323ef0bb6c7SMatthew G. Knepley   ierr = PetscTabulationDestroy(&(*fem)->T);CHKERRQ(ierr);
324ef0bb6c7SMatthew G. Knepley   ierr = PetscTabulationDestroy(&(*fem)->Tf);CHKERRQ(ierr);
325ef0bb6c7SMatthew G. Knepley   ierr = PetscTabulationDestroy(&(*fem)->Tc);CHKERRQ(ierr);
32620cf1dd8SToby Isaac   ierr = PetscSpaceDestroy(&(*fem)->basisSpace);CHKERRQ(ierr);
32720cf1dd8SToby Isaac   ierr = PetscDualSpaceDestroy(&(*fem)->dualSpace);CHKERRQ(ierr);
32820cf1dd8SToby Isaac   ierr = PetscQuadratureDestroy(&(*fem)->quadrature);CHKERRQ(ierr);
32920cf1dd8SToby Isaac   ierr = PetscQuadratureDestroy(&(*fem)->faceQuadrature);CHKERRQ(ierr);
33020cf1dd8SToby Isaac 
33120cf1dd8SToby Isaac   if ((*fem)->ops->destroy) {ierr = (*(*fem)->ops->destroy)(*fem);CHKERRQ(ierr);}
33220cf1dd8SToby Isaac   ierr = PetscHeaderDestroy(fem);CHKERRQ(ierr);
33320cf1dd8SToby Isaac   PetscFunctionReturn(0);
33420cf1dd8SToby Isaac }
33520cf1dd8SToby Isaac 
33620cf1dd8SToby Isaac /*@
33720cf1dd8SToby Isaac   PetscFECreate - Creates an empty PetscFE object. The type can then be set with PetscFESetType().
33820cf1dd8SToby Isaac 
339d083f849SBarry Smith   Collective
34020cf1dd8SToby Isaac 
34120cf1dd8SToby Isaac   Input Parameter:
34220cf1dd8SToby Isaac . comm - The communicator for the PetscFE object
34320cf1dd8SToby Isaac 
34420cf1dd8SToby Isaac   Output Parameter:
34520cf1dd8SToby Isaac . fem - The PetscFE object
34620cf1dd8SToby Isaac 
34720cf1dd8SToby Isaac   Level: beginner
34820cf1dd8SToby Isaac 
34920cf1dd8SToby Isaac .seealso: PetscFESetType(), PETSCFEGALERKIN
35020cf1dd8SToby Isaac @*/
35120cf1dd8SToby Isaac PetscErrorCode PetscFECreate(MPI_Comm comm, PetscFE *fem)
35220cf1dd8SToby Isaac {
35320cf1dd8SToby Isaac   PetscFE        f;
35420cf1dd8SToby Isaac   PetscErrorCode ierr;
35520cf1dd8SToby Isaac 
35620cf1dd8SToby Isaac   PetscFunctionBegin;
35720cf1dd8SToby Isaac   PetscValidPointer(fem, 2);
35820cf1dd8SToby Isaac   ierr = PetscCitationsRegister(FECitation,&FEcite);CHKERRQ(ierr);
35920cf1dd8SToby Isaac   *fem = NULL;
36020cf1dd8SToby Isaac   ierr = PetscFEInitializePackage();CHKERRQ(ierr);
36120cf1dd8SToby Isaac 
36220cf1dd8SToby Isaac   ierr = PetscHeaderCreate(f, PETSCFE_CLASSID, "PetscFE", "Finite Element", "PetscFE", comm, PetscFEDestroy, PetscFEView);CHKERRQ(ierr);
36320cf1dd8SToby Isaac 
36420cf1dd8SToby Isaac   f->basisSpace    = NULL;
36520cf1dd8SToby Isaac   f->dualSpace     = NULL;
36620cf1dd8SToby Isaac   f->numComponents = 1;
36720cf1dd8SToby Isaac   f->subspaces     = NULL;
36820cf1dd8SToby Isaac   f->invV          = NULL;
369ef0bb6c7SMatthew G. Knepley   f->T             = NULL;
370ef0bb6c7SMatthew G. Knepley   f->Tf            = NULL;
371ef0bb6c7SMatthew G. Knepley   f->Tc            = NULL;
372580bdb30SBarry Smith   ierr = PetscArrayzero(&f->quadrature, 1);CHKERRQ(ierr);
373580bdb30SBarry Smith   ierr = PetscArrayzero(&f->faceQuadrature, 1);CHKERRQ(ierr);
37420cf1dd8SToby Isaac   f->blockSize     = 0;
37520cf1dd8SToby Isaac   f->numBlocks     = 1;
37620cf1dd8SToby Isaac   f->batchSize     = 0;
37720cf1dd8SToby Isaac   f->numBatches    = 1;
37820cf1dd8SToby Isaac 
37920cf1dd8SToby Isaac   *fem = f;
38020cf1dd8SToby Isaac   PetscFunctionReturn(0);
38120cf1dd8SToby Isaac }
38220cf1dd8SToby Isaac 
38320cf1dd8SToby Isaac /*@
38420cf1dd8SToby Isaac   PetscFEGetSpatialDimension - Returns the spatial dimension of the element
38520cf1dd8SToby Isaac 
38620cf1dd8SToby Isaac   Not collective
38720cf1dd8SToby Isaac 
38820cf1dd8SToby Isaac   Input Parameter:
38920cf1dd8SToby Isaac . fem - The PetscFE object
39020cf1dd8SToby Isaac 
39120cf1dd8SToby Isaac   Output Parameter:
39220cf1dd8SToby Isaac . dim - The spatial dimension
39320cf1dd8SToby Isaac 
39420cf1dd8SToby Isaac   Level: intermediate
39520cf1dd8SToby Isaac 
39620cf1dd8SToby Isaac .seealso: PetscFECreate()
39720cf1dd8SToby Isaac @*/
39820cf1dd8SToby Isaac PetscErrorCode PetscFEGetSpatialDimension(PetscFE fem, PetscInt *dim)
39920cf1dd8SToby Isaac {
40020cf1dd8SToby Isaac   DM             dm;
40120cf1dd8SToby Isaac   PetscErrorCode ierr;
40220cf1dd8SToby Isaac 
40320cf1dd8SToby Isaac   PetscFunctionBegin;
40420cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
40520cf1dd8SToby Isaac   PetscValidPointer(dim, 2);
40620cf1dd8SToby Isaac   ierr = PetscDualSpaceGetDM(fem->dualSpace, &dm);CHKERRQ(ierr);
40720cf1dd8SToby Isaac   ierr = DMGetDimension(dm, dim);CHKERRQ(ierr);
40820cf1dd8SToby Isaac   PetscFunctionReturn(0);
40920cf1dd8SToby Isaac }
41020cf1dd8SToby Isaac 
41120cf1dd8SToby Isaac /*@
41220cf1dd8SToby Isaac   PetscFESetNumComponents - Sets the number of components in the element
41320cf1dd8SToby Isaac 
41420cf1dd8SToby Isaac   Not collective
41520cf1dd8SToby Isaac 
41620cf1dd8SToby Isaac   Input Parameters:
41720cf1dd8SToby Isaac + fem - The PetscFE object
41820cf1dd8SToby Isaac - comp - The number of field components
41920cf1dd8SToby Isaac 
42020cf1dd8SToby Isaac   Level: intermediate
42120cf1dd8SToby Isaac 
42220cf1dd8SToby Isaac .seealso: PetscFECreate()
42320cf1dd8SToby Isaac @*/
42420cf1dd8SToby Isaac PetscErrorCode PetscFESetNumComponents(PetscFE fem, PetscInt comp)
42520cf1dd8SToby Isaac {
42620cf1dd8SToby Isaac   PetscFunctionBegin;
42720cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
42820cf1dd8SToby Isaac   fem->numComponents = comp;
42920cf1dd8SToby Isaac   PetscFunctionReturn(0);
43020cf1dd8SToby Isaac }
43120cf1dd8SToby Isaac 
43220cf1dd8SToby Isaac /*@
43320cf1dd8SToby Isaac   PetscFEGetNumComponents - Returns the number of components in the element
43420cf1dd8SToby Isaac 
43520cf1dd8SToby Isaac   Not collective
43620cf1dd8SToby Isaac 
43720cf1dd8SToby Isaac   Input Parameter:
43820cf1dd8SToby Isaac . fem - The PetscFE object
43920cf1dd8SToby Isaac 
44020cf1dd8SToby Isaac   Output Parameter:
44120cf1dd8SToby Isaac . comp - The number of field components
44220cf1dd8SToby Isaac 
44320cf1dd8SToby Isaac   Level: intermediate
44420cf1dd8SToby Isaac 
44520cf1dd8SToby Isaac .seealso: PetscFECreate()
44620cf1dd8SToby Isaac @*/
44720cf1dd8SToby Isaac PetscErrorCode PetscFEGetNumComponents(PetscFE fem, PetscInt *comp)
44820cf1dd8SToby Isaac {
44920cf1dd8SToby Isaac   PetscFunctionBegin;
45020cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
45120cf1dd8SToby Isaac   PetscValidPointer(comp, 2);
45220cf1dd8SToby Isaac   *comp = fem->numComponents;
45320cf1dd8SToby Isaac   PetscFunctionReturn(0);
45420cf1dd8SToby Isaac }
45520cf1dd8SToby Isaac 
45620cf1dd8SToby Isaac /*@
45720cf1dd8SToby Isaac   PetscFESetTileSizes - Sets the tile sizes for evaluation
45820cf1dd8SToby Isaac 
45920cf1dd8SToby Isaac   Not collective
46020cf1dd8SToby Isaac 
46120cf1dd8SToby Isaac   Input Parameters:
46220cf1dd8SToby Isaac + fem - The PetscFE object
46320cf1dd8SToby Isaac . blockSize - The number of elements in a block
46420cf1dd8SToby Isaac . numBlocks - The number of blocks in a batch
46520cf1dd8SToby Isaac . batchSize - The number of elements in a batch
46620cf1dd8SToby Isaac - numBatches - The number of batches in a chunk
46720cf1dd8SToby Isaac 
46820cf1dd8SToby Isaac   Level: intermediate
46920cf1dd8SToby Isaac 
47020cf1dd8SToby Isaac .seealso: PetscFECreate()
47120cf1dd8SToby Isaac @*/
47220cf1dd8SToby Isaac PetscErrorCode PetscFESetTileSizes(PetscFE fem, PetscInt blockSize, PetscInt numBlocks, PetscInt batchSize, PetscInt numBatches)
47320cf1dd8SToby Isaac {
47420cf1dd8SToby Isaac   PetscFunctionBegin;
47520cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
47620cf1dd8SToby Isaac   fem->blockSize  = blockSize;
47720cf1dd8SToby Isaac   fem->numBlocks  = numBlocks;
47820cf1dd8SToby Isaac   fem->batchSize  = batchSize;
47920cf1dd8SToby Isaac   fem->numBatches = numBatches;
48020cf1dd8SToby Isaac   PetscFunctionReturn(0);
48120cf1dd8SToby Isaac }
48220cf1dd8SToby Isaac 
48320cf1dd8SToby Isaac /*@
48420cf1dd8SToby Isaac   PetscFEGetTileSizes - Returns the tile sizes for evaluation
48520cf1dd8SToby Isaac 
48620cf1dd8SToby Isaac   Not collective
48720cf1dd8SToby Isaac 
48820cf1dd8SToby Isaac   Input Parameter:
48920cf1dd8SToby Isaac . fem - The PetscFE object
49020cf1dd8SToby Isaac 
49120cf1dd8SToby Isaac   Output Parameters:
49220cf1dd8SToby Isaac + blockSize - The number of elements in a block
49320cf1dd8SToby Isaac . numBlocks - The number of blocks in a batch
49420cf1dd8SToby Isaac . batchSize - The number of elements in a batch
49520cf1dd8SToby Isaac - numBatches - The number of batches in a chunk
49620cf1dd8SToby Isaac 
49720cf1dd8SToby Isaac   Level: intermediate
49820cf1dd8SToby Isaac 
49920cf1dd8SToby Isaac .seealso: PetscFECreate()
50020cf1dd8SToby Isaac @*/
50120cf1dd8SToby Isaac PetscErrorCode PetscFEGetTileSizes(PetscFE fem, PetscInt *blockSize, PetscInt *numBlocks, PetscInt *batchSize, PetscInt *numBatches)
50220cf1dd8SToby Isaac {
50320cf1dd8SToby Isaac   PetscFunctionBegin;
50420cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
50520cf1dd8SToby Isaac   if (blockSize)  PetscValidPointer(blockSize,  2);
50620cf1dd8SToby Isaac   if (numBlocks)  PetscValidPointer(numBlocks,  3);
50720cf1dd8SToby Isaac   if (batchSize)  PetscValidPointer(batchSize,  4);
50820cf1dd8SToby Isaac   if (numBatches) PetscValidPointer(numBatches, 5);
50920cf1dd8SToby Isaac   if (blockSize)  *blockSize  = fem->blockSize;
51020cf1dd8SToby Isaac   if (numBlocks)  *numBlocks  = fem->numBlocks;
51120cf1dd8SToby Isaac   if (batchSize)  *batchSize  = fem->batchSize;
51220cf1dd8SToby Isaac   if (numBatches) *numBatches = fem->numBatches;
51320cf1dd8SToby Isaac   PetscFunctionReturn(0);
51420cf1dd8SToby Isaac }
51520cf1dd8SToby Isaac 
51620cf1dd8SToby Isaac /*@
51720cf1dd8SToby Isaac   PetscFEGetBasisSpace - Returns the PetscSpace used for approximation of the solution
51820cf1dd8SToby Isaac 
51920cf1dd8SToby Isaac   Not collective
52020cf1dd8SToby Isaac 
52120cf1dd8SToby Isaac   Input Parameter:
52220cf1dd8SToby Isaac . fem - The PetscFE object
52320cf1dd8SToby Isaac 
52420cf1dd8SToby Isaac   Output Parameter:
52520cf1dd8SToby Isaac . sp - The PetscSpace object
52620cf1dd8SToby Isaac 
52720cf1dd8SToby Isaac   Level: intermediate
52820cf1dd8SToby Isaac 
52920cf1dd8SToby Isaac .seealso: PetscFECreate()
53020cf1dd8SToby Isaac @*/
53120cf1dd8SToby Isaac PetscErrorCode PetscFEGetBasisSpace(PetscFE fem, PetscSpace *sp)
53220cf1dd8SToby Isaac {
53320cf1dd8SToby Isaac   PetscFunctionBegin;
53420cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
53520cf1dd8SToby Isaac   PetscValidPointer(sp, 2);
53620cf1dd8SToby Isaac   *sp = fem->basisSpace;
53720cf1dd8SToby Isaac   PetscFunctionReturn(0);
53820cf1dd8SToby Isaac }
53920cf1dd8SToby Isaac 
54020cf1dd8SToby Isaac /*@
54120cf1dd8SToby Isaac   PetscFESetBasisSpace - Sets the PetscSpace used for approximation of the solution
54220cf1dd8SToby Isaac 
54320cf1dd8SToby Isaac   Not collective
54420cf1dd8SToby Isaac 
54520cf1dd8SToby Isaac   Input Parameters:
54620cf1dd8SToby Isaac + fem - The PetscFE object
54720cf1dd8SToby Isaac - sp - The PetscSpace object
54820cf1dd8SToby Isaac 
54920cf1dd8SToby Isaac   Level: intermediate
55020cf1dd8SToby Isaac 
55120cf1dd8SToby Isaac .seealso: PetscFECreate()
55220cf1dd8SToby Isaac @*/
55320cf1dd8SToby Isaac PetscErrorCode PetscFESetBasisSpace(PetscFE fem, PetscSpace sp)
55420cf1dd8SToby Isaac {
55520cf1dd8SToby Isaac   PetscErrorCode ierr;
55620cf1dd8SToby Isaac 
55720cf1dd8SToby Isaac   PetscFunctionBegin;
55820cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
55920cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 2);
56020cf1dd8SToby Isaac   ierr = PetscSpaceDestroy(&fem->basisSpace);CHKERRQ(ierr);
56120cf1dd8SToby Isaac   fem->basisSpace = sp;
56220cf1dd8SToby Isaac   ierr = PetscObjectReference((PetscObject) fem->basisSpace);CHKERRQ(ierr);
56320cf1dd8SToby Isaac   PetscFunctionReturn(0);
56420cf1dd8SToby Isaac }
56520cf1dd8SToby Isaac 
56620cf1dd8SToby Isaac /*@
56720cf1dd8SToby Isaac   PetscFEGetDualSpace - Returns the PetscDualSpace used to define the inner product
56820cf1dd8SToby Isaac 
56920cf1dd8SToby Isaac   Not collective
57020cf1dd8SToby Isaac 
57120cf1dd8SToby Isaac   Input Parameter:
57220cf1dd8SToby Isaac . fem - The PetscFE object
57320cf1dd8SToby Isaac 
57420cf1dd8SToby Isaac   Output Parameter:
57520cf1dd8SToby Isaac . sp - The PetscDualSpace object
57620cf1dd8SToby Isaac 
57720cf1dd8SToby Isaac   Level: intermediate
57820cf1dd8SToby Isaac 
57920cf1dd8SToby Isaac .seealso: PetscFECreate()
58020cf1dd8SToby Isaac @*/
58120cf1dd8SToby Isaac PetscErrorCode PetscFEGetDualSpace(PetscFE fem, PetscDualSpace *sp)
58220cf1dd8SToby Isaac {
58320cf1dd8SToby Isaac   PetscFunctionBegin;
58420cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
58520cf1dd8SToby Isaac   PetscValidPointer(sp, 2);
58620cf1dd8SToby Isaac   *sp = fem->dualSpace;
58720cf1dd8SToby Isaac   PetscFunctionReturn(0);
58820cf1dd8SToby Isaac }
58920cf1dd8SToby Isaac 
59020cf1dd8SToby Isaac /*@
59120cf1dd8SToby Isaac   PetscFESetDualSpace - Sets the PetscDualSpace used to define the inner product
59220cf1dd8SToby Isaac 
59320cf1dd8SToby Isaac   Not collective
59420cf1dd8SToby Isaac 
59520cf1dd8SToby Isaac   Input Parameters:
59620cf1dd8SToby Isaac + fem - The PetscFE object
59720cf1dd8SToby Isaac - sp - The PetscDualSpace object
59820cf1dd8SToby Isaac 
59920cf1dd8SToby Isaac   Level: intermediate
60020cf1dd8SToby Isaac 
60120cf1dd8SToby Isaac .seealso: PetscFECreate()
60220cf1dd8SToby Isaac @*/
60320cf1dd8SToby Isaac PetscErrorCode PetscFESetDualSpace(PetscFE fem, PetscDualSpace sp)
60420cf1dd8SToby Isaac {
60520cf1dd8SToby Isaac   PetscErrorCode ierr;
60620cf1dd8SToby Isaac 
60720cf1dd8SToby Isaac   PetscFunctionBegin;
60820cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
60920cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCDUALSPACE_CLASSID, 2);
61020cf1dd8SToby Isaac   ierr = PetscDualSpaceDestroy(&fem->dualSpace);CHKERRQ(ierr);
61120cf1dd8SToby Isaac   fem->dualSpace = sp;
61220cf1dd8SToby Isaac   ierr = PetscObjectReference((PetscObject) fem->dualSpace);CHKERRQ(ierr);
61320cf1dd8SToby Isaac   PetscFunctionReturn(0);
61420cf1dd8SToby Isaac }
61520cf1dd8SToby Isaac 
61620cf1dd8SToby Isaac /*@
61720cf1dd8SToby Isaac   PetscFEGetQuadrature - Returns the PetscQuadrature used to calculate inner products
61820cf1dd8SToby Isaac 
61920cf1dd8SToby Isaac   Not collective
62020cf1dd8SToby Isaac 
62120cf1dd8SToby Isaac   Input Parameter:
62220cf1dd8SToby Isaac . fem - The PetscFE object
62320cf1dd8SToby Isaac 
62420cf1dd8SToby Isaac   Output Parameter:
62520cf1dd8SToby Isaac . q - The PetscQuadrature object
62620cf1dd8SToby Isaac 
62720cf1dd8SToby Isaac   Level: intermediate
62820cf1dd8SToby Isaac 
62920cf1dd8SToby Isaac .seealso: PetscFECreate()
63020cf1dd8SToby Isaac @*/
63120cf1dd8SToby Isaac PetscErrorCode PetscFEGetQuadrature(PetscFE fem, PetscQuadrature *q)
63220cf1dd8SToby Isaac {
63320cf1dd8SToby Isaac   PetscFunctionBegin;
63420cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
63520cf1dd8SToby Isaac   PetscValidPointer(q, 2);
63620cf1dd8SToby Isaac   *q = fem->quadrature;
63720cf1dd8SToby Isaac   PetscFunctionReturn(0);
63820cf1dd8SToby Isaac }
63920cf1dd8SToby Isaac 
64020cf1dd8SToby Isaac /*@
64120cf1dd8SToby Isaac   PetscFESetQuadrature - Sets the PetscQuadrature used to calculate inner products
64220cf1dd8SToby Isaac 
64320cf1dd8SToby Isaac   Not collective
64420cf1dd8SToby Isaac 
64520cf1dd8SToby Isaac   Input Parameters:
64620cf1dd8SToby Isaac + fem - The PetscFE object
64720cf1dd8SToby Isaac - q - The PetscQuadrature object
64820cf1dd8SToby Isaac 
64920cf1dd8SToby Isaac   Level: intermediate
65020cf1dd8SToby Isaac 
65120cf1dd8SToby Isaac .seealso: PetscFECreate()
65220cf1dd8SToby Isaac @*/
65320cf1dd8SToby Isaac PetscErrorCode PetscFESetQuadrature(PetscFE fem, PetscQuadrature q)
65420cf1dd8SToby Isaac {
65520cf1dd8SToby Isaac   PetscInt       Nc, qNc;
65620cf1dd8SToby Isaac   PetscErrorCode ierr;
65720cf1dd8SToby Isaac 
65820cf1dd8SToby Isaac   PetscFunctionBegin;
65920cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
660fd2fdbddSMatthew G. Knepley   if (q == fem->quadrature) PetscFunctionReturn(0);
66120cf1dd8SToby Isaac   ierr = PetscFEGetNumComponents(fem, &Nc);CHKERRQ(ierr);
66220cf1dd8SToby Isaac   ierr = PetscQuadratureGetNumComponents(q, &qNc);CHKERRQ(ierr);
66320cf1dd8SToby 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);
664ef0bb6c7SMatthew G. Knepley   ierr = PetscTabulationDestroy(&fem->T);CHKERRQ(ierr);
665ef0bb6c7SMatthew G. Knepley   ierr = PetscTabulationDestroy(&fem->Tc);CHKERRQ(ierr);
666fd2fdbddSMatthew G. Knepley   ierr = PetscObjectReference((PetscObject) q);CHKERRQ(ierr);
66720cf1dd8SToby Isaac   ierr = PetscQuadratureDestroy(&fem->quadrature);CHKERRQ(ierr);
66820cf1dd8SToby Isaac   fem->quadrature = q;
66920cf1dd8SToby Isaac   PetscFunctionReturn(0);
67020cf1dd8SToby Isaac }
67120cf1dd8SToby Isaac 
67220cf1dd8SToby Isaac /*@
67320cf1dd8SToby Isaac   PetscFEGetFaceQuadrature - Returns the PetscQuadrature used to calculate inner products on faces
67420cf1dd8SToby Isaac 
67520cf1dd8SToby Isaac   Not collective
67620cf1dd8SToby Isaac 
67720cf1dd8SToby Isaac   Input Parameter:
67820cf1dd8SToby Isaac . fem - The PetscFE object
67920cf1dd8SToby Isaac 
68020cf1dd8SToby Isaac   Output Parameter:
68120cf1dd8SToby Isaac . q - The PetscQuadrature object
68220cf1dd8SToby Isaac 
68320cf1dd8SToby Isaac   Level: intermediate
68420cf1dd8SToby Isaac 
68520cf1dd8SToby Isaac .seealso: PetscFECreate()
68620cf1dd8SToby Isaac @*/
68720cf1dd8SToby Isaac PetscErrorCode PetscFEGetFaceQuadrature(PetscFE fem, PetscQuadrature *q)
68820cf1dd8SToby Isaac {
68920cf1dd8SToby Isaac   PetscFunctionBegin;
69020cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
69120cf1dd8SToby Isaac   PetscValidPointer(q, 2);
69220cf1dd8SToby Isaac   *q = fem->faceQuadrature;
69320cf1dd8SToby Isaac   PetscFunctionReturn(0);
69420cf1dd8SToby Isaac }
69520cf1dd8SToby Isaac 
69620cf1dd8SToby Isaac /*@
69720cf1dd8SToby Isaac   PetscFESetFaceQuadrature - Sets the PetscQuadrature used to calculate inner products on faces
69820cf1dd8SToby Isaac 
69920cf1dd8SToby Isaac   Not collective
70020cf1dd8SToby Isaac 
70120cf1dd8SToby Isaac   Input Parameters:
70220cf1dd8SToby Isaac + fem - The PetscFE object
70320cf1dd8SToby Isaac - q - The PetscQuadrature object
70420cf1dd8SToby Isaac 
70520cf1dd8SToby Isaac   Level: intermediate
70620cf1dd8SToby Isaac 
70720cf1dd8SToby Isaac .seealso: PetscFECreate()
70820cf1dd8SToby Isaac @*/
70920cf1dd8SToby Isaac PetscErrorCode PetscFESetFaceQuadrature(PetscFE fem, PetscQuadrature q)
71020cf1dd8SToby Isaac {
711ef0bb6c7SMatthew G. Knepley   PetscInt       Nc, qNc;
71220cf1dd8SToby Isaac   PetscErrorCode ierr;
71320cf1dd8SToby Isaac 
71420cf1dd8SToby Isaac   PetscFunctionBegin;
71520cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
716ef0bb6c7SMatthew G. Knepley   ierr = PetscFEGetNumComponents(fem, &Nc);CHKERRQ(ierr);
717ef0bb6c7SMatthew G. Knepley   ierr = PetscQuadratureGetNumComponents(q, &qNc);CHKERRQ(ierr);
718ef0bb6c7SMatthew G. Knepley   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);
719ef0bb6c7SMatthew G. Knepley   ierr = PetscTabulationDestroy(&fem->Tf);CHKERRQ(ierr);
72020cf1dd8SToby Isaac   ierr = PetscQuadratureDestroy(&fem->faceQuadrature);CHKERRQ(ierr);
72120cf1dd8SToby Isaac   fem->faceQuadrature = q;
72220cf1dd8SToby Isaac   ierr = PetscObjectReference((PetscObject) q);CHKERRQ(ierr);
72320cf1dd8SToby Isaac   PetscFunctionReturn(0);
72420cf1dd8SToby Isaac }
72520cf1dd8SToby Isaac 
7265dc5c000SMatthew G. Knepley /*@
7275dc5c000SMatthew G. Knepley   PetscFECopyQuadrature - Copy both volumetric and surface quadrature
7285dc5c000SMatthew G. Knepley 
7295dc5c000SMatthew G. Knepley   Not collective
7305dc5c000SMatthew G. Knepley 
7315dc5c000SMatthew G. Knepley   Input Parameters:
7325dc5c000SMatthew G. Knepley + sfe - The PetscFE source for the quadratures
7335dc5c000SMatthew G. Knepley - tfe - The PetscFE target for the quadratures
7345dc5c000SMatthew G. Knepley 
7355dc5c000SMatthew G. Knepley   Level: intermediate
7365dc5c000SMatthew G. Knepley 
7375dc5c000SMatthew G. Knepley .seealso: PetscFECreate(), PetscFESetQuadrature(), PetscFESetFaceQuadrature()
7385dc5c000SMatthew G. Knepley @*/
7395dc5c000SMatthew G. Knepley PetscErrorCode PetscFECopyQuadrature(PetscFE sfe, PetscFE tfe)
7405dc5c000SMatthew G. Knepley {
7415dc5c000SMatthew G. Knepley   PetscQuadrature q;
7425dc5c000SMatthew G. Knepley   PetscErrorCode  ierr;
7435dc5c000SMatthew G. Knepley 
7445dc5c000SMatthew G. Knepley   PetscFunctionBegin;
7455dc5c000SMatthew G. Knepley   PetscValidHeaderSpecific(sfe, PETSCFE_CLASSID, 1);
7465dc5c000SMatthew G. Knepley   PetscValidHeaderSpecific(tfe, PETSCFE_CLASSID, 2);
7475dc5c000SMatthew G. Knepley   ierr = PetscFEGetQuadrature(sfe, &q);CHKERRQ(ierr);
7485dc5c000SMatthew G. Knepley   ierr = PetscFESetQuadrature(tfe,  q);CHKERRQ(ierr);
7495dc5c000SMatthew G. Knepley   ierr = PetscFEGetFaceQuadrature(sfe, &q);CHKERRQ(ierr);
7505dc5c000SMatthew G. Knepley   ierr = PetscFESetFaceQuadrature(tfe,  q);CHKERRQ(ierr);
7515dc5c000SMatthew G. Knepley   PetscFunctionReturn(0);
7525dc5c000SMatthew G. Knepley }
7535dc5c000SMatthew G. Knepley 
75420cf1dd8SToby Isaac /*@C
75520cf1dd8SToby Isaac   PetscFEGetNumDof - Returns the number of dofs (dual basis vectors) associated to mesh points on the reference cell of a given dimension
75620cf1dd8SToby Isaac 
75720cf1dd8SToby Isaac   Not collective
75820cf1dd8SToby Isaac 
75920cf1dd8SToby Isaac   Input Parameter:
76020cf1dd8SToby Isaac . fem - The PetscFE object
76120cf1dd8SToby Isaac 
76220cf1dd8SToby Isaac   Output Parameter:
76320cf1dd8SToby Isaac . numDof - Array with the number of dofs per dimension
76420cf1dd8SToby Isaac 
76520cf1dd8SToby Isaac   Level: intermediate
76620cf1dd8SToby Isaac 
76720cf1dd8SToby Isaac .seealso: PetscFECreate()
76820cf1dd8SToby Isaac @*/
76920cf1dd8SToby Isaac PetscErrorCode PetscFEGetNumDof(PetscFE fem, const PetscInt **numDof)
77020cf1dd8SToby Isaac {
77120cf1dd8SToby Isaac   PetscErrorCode ierr;
77220cf1dd8SToby Isaac 
77320cf1dd8SToby Isaac   PetscFunctionBegin;
77420cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
77520cf1dd8SToby Isaac   PetscValidPointer(numDof, 2);
77620cf1dd8SToby Isaac   ierr = PetscDualSpaceGetNumDof(fem->dualSpace, numDof);CHKERRQ(ierr);
77720cf1dd8SToby Isaac   PetscFunctionReturn(0);
77820cf1dd8SToby Isaac }
77920cf1dd8SToby Isaac 
78020cf1dd8SToby Isaac /*@C
781ef0bb6c7SMatthew G. Knepley   PetscFEGetCellTabulation - Returns the tabulation of the basis functions at the quadrature points on the reference cell
78220cf1dd8SToby Isaac 
78320cf1dd8SToby Isaac   Not collective
78420cf1dd8SToby Isaac 
78520cf1dd8SToby Isaac   Input Parameter:
78620cf1dd8SToby Isaac . fem - The PetscFE object
78720cf1dd8SToby Isaac 
788ef0bb6c7SMatthew G. Knepley   Output Parameter:
789ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at quadrature points
79020cf1dd8SToby Isaac 
79120cf1dd8SToby Isaac   Note:
792ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c
793ef0bb6c7SMatthew G. Knepley $ T->T[1] = D[((p*pdim + i)*Nc + c)*dim + d] is the derivative value at point p for basis function i, component c, in direction d
794ef0bb6c7SMatthew G. Knepley $ T->T[2] = H[(((p*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point p for basis function i, component c, in directions d and e
79520cf1dd8SToby Isaac 
79620cf1dd8SToby Isaac   Level: intermediate
79720cf1dd8SToby Isaac 
798ef0bb6c7SMatthew G. Knepley .seealso: PetscFECreateTabulation(), PetscTabulationDestroy()
79920cf1dd8SToby Isaac @*/
800ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEGetCellTabulation(PetscFE fem, PetscTabulation *T)
80120cf1dd8SToby Isaac {
80220cf1dd8SToby Isaac   PetscInt         npoints;
80320cf1dd8SToby Isaac   const PetscReal *points;
80420cf1dd8SToby Isaac   PetscErrorCode   ierr;
80520cf1dd8SToby Isaac 
80620cf1dd8SToby Isaac   PetscFunctionBegin;
80720cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
808ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
80920cf1dd8SToby Isaac   ierr = PetscQuadratureGetData(fem->quadrature, NULL, NULL, &npoints, &points, NULL);CHKERRQ(ierr);
810ef0bb6c7SMatthew G. Knepley   if (!fem->T) {ierr = PetscFECreateTabulation(fem, 1, npoints, points, 1, &fem->T);CHKERRQ(ierr);}
811ef0bb6c7SMatthew G. Knepley   *T = fem->T;
81220cf1dd8SToby Isaac   PetscFunctionReturn(0);
81320cf1dd8SToby Isaac }
81420cf1dd8SToby Isaac 
8152b99622eSMatthew G. Knepley /*@C
816ef0bb6c7SMatthew G. Knepley   PetscFEGetFaceTabulation - Returns the tabulation of the basis functions at the face quadrature points for each face of the reference cell
8172b99622eSMatthew G. Knepley 
8182b99622eSMatthew G. Knepley   Not collective
8192b99622eSMatthew G. Knepley 
8202b99622eSMatthew G. Knepley   Input Parameter:
8212b99622eSMatthew G. Knepley . fem - The PetscFE object
8222b99622eSMatthew G. Knepley 
8232b99622eSMatthew G. Knepley   Output Parameters:
824ef0bb6c7SMatthew G. Knepley . Tf - The basis function values and derviatives at face quadrature points
8252b99622eSMatthew G. Knepley 
8262b99622eSMatthew G. Knepley   Note:
827ef0bb6c7SMatthew G. Knepley $ T->T[0] = Bf[((f*Nq + q)*pdim + i)*Nc + c] is the value at point f,q for basis function i and component c
828ef0bb6c7SMatthew G. Knepley $ T->T[1] = Df[(((f*Nq + q)*pdim + i)*Nc + c)*dim + d] is the derivative value at point f,q for basis function i, component c, in direction d
829ef0bb6c7SMatthew G. Knepley $ T->T[2] = Hf[((((f*Nq + q)*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point f,q for basis function i, component c, in directions d and e
8302b99622eSMatthew G. Knepley 
8312b99622eSMatthew G. Knepley   Level: intermediate
8322b99622eSMatthew G. Knepley 
833ef0bb6c7SMatthew G. Knepley .seealso: PetscFEGetCellTabulation(), PetscFECreateTabulation(), PetscTabulationDestroy()
8342b99622eSMatthew G. Knepley @*/
835ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEGetFaceTabulation(PetscFE fem, PetscTabulation *Tf)
83620cf1dd8SToby Isaac {
83720cf1dd8SToby Isaac   PetscErrorCode   ierr;
83820cf1dd8SToby Isaac 
83920cf1dd8SToby Isaac   PetscFunctionBegin;
84020cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
841ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
842ef0bb6c7SMatthew G. Knepley   if (!fem->Tf) {
84320cf1dd8SToby Isaac     const PetscReal  xi0[3] = {-1., -1., -1.};
84420cf1dd8SToby Isaac     PetscReal        v0[3], J[9], detJ;
84520cf1dd8SToby Isaac     PetscQuadrature  fq;
84620cf1dd8SToby Isaac     PetscDualSpace   sp;
84720cf1dd8SToby Isaac     DM               dm;
84820cf1dd8SToby Isaac     const PetscInt  *faces;
84920cf1dd8SToby Isaac     PetscInt         dim, numFaces, f, npoints, q;
85020cf1dd8SToby Isaac     const PetscReal *points;
85120cf1dd8SToby Isaac     PetscReal       *facePoints;
85220cf1dd8SToby Isaac 
85320cf1dd8SToby Isaac     ierr = PetscFEGetDualSpace(fem, &sp);CHKERRQ(ierr);
85420cf1dd8SToby Isaac     ierr = PetscDualSpaceGetDM(sp, &dm);CHKERRQ(ierr);
85520cf1dd8SToby Isaac     ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
85620cf1dd8SToby Isaac     ierr = DMPlexGetConeSize(dm, 0, &numFaces);CHKERRQ(ierr);
85720cf1dd8SToby Isaac     ierr = DMPlexGetCone(dm, 0, &faces);CHKERRQ(ierr);
85820cf1dd8SToby Isaac     ierr = PetscFEGetFaceQuadrature(fem, &fq);CHKERRQ(ierr);
85920cf1dd8SToby Isaac     if (fq) {
86020cf1dd8SToby Isaac       ierr = PetscQuadratureGetData(fq, NULL, NULL, &npoints, &points, NULL);CHKERRQ(ierr);
86120cf1dd8SToby Isaac       ierr = PetscMalloc1(numFaces*npoints*dim, &facePoints);CHKERRQ(ierr);
86220cf1dd8SToby Isaac       for (f = 0; f < numFaces; ++f) {
86320cf1dd8SToby Isaac         ierr = DMPlexComputeCellGeometryFEM(dm, faces[f], NULL, v0, J, NULL, &detJ);CHKERRQ(ierr);
86420cf1dd8SToby Isaac         for (q = 0; q < npoints; ++q) CoordinatesRefToReal(dim, dim-1, xi0, v0, J, &points[q*(dim-1)], &facePoints[(f*npoints+q)*dim]);
86520cf1dd8SToby Isaac       }
866ef0bb6c7SMatthew G. Knepley       ierr = PetscFECreateTabulation(fem, numFaces, npoints, facePoints, 1, &fem->Tf);CHKERRQ(ierr);
86720cf1dd8SToby Isaac       ierr = PetscFree(facePoints);CHKERRQ(ierr);
86820cf1dd8SToby Isaac     }
86920cf1dd8SToby Isaac   }
870ef0bb6c7SMatthew G. Knepley   *Tf = fem->Tf;
87120cf1dd8SToby Isaac   PetscFunctionReturn(0);
87220cf1dd8SToby Isaac }
87320cf1dd8SToby Isaac 
8742b99622eSMatthew G. Knepley /*@C
875ef0bb6c7SMatthew G. Knepley   PetscFEGetFaceCentroidTabulation - Returns the tabulation of the basis functions at the face centroid points
8762b99622eSMatthew G. Knepley 
8772b99622eSMatthew G. Knepley   Not collective
8782b99622eSMatthew G. Knepley 
8792b99622eSMatthew G. Knepley   Input Parameter:
8802b99622eSMatthew G. Knepley . fem - The PetscFE object
8812b99622eSMatthew G. Knepley 
8822b99622eSMatthew G. Knepley   Output Parameters:
883ef0bb6c7SMatthew G. Knepley . Tc - The basis function values at face centroid points
8842b99622eSMatthew G. Knepley 
8852b99622eSMatthew G. Knepley   Note:
886ef0bb6c7SMatthew G. Knepley $ T->T[0] = Bf[(f*pdim + i)*Nc + c] is the value at point f for basis function i and component c
8872b99622eSMatthew G. Knepley 
8882b99622eSMatthew G. Knepley   Level: intermediate
8892b99622eSMatthew G. Knepley 
890ef0bb6c7SMatthew G. Knepley .seealso: PetscFEGetFaceTabulation(), PetscFEGetCellTabulation(), PetscFECreateTabulation(), PetscTabulationDestroy()
8912b99622eSMatthew G. Knepley @*/
892ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEGetFaceCentroidTabulation(PetscFE fem, PetscTabulation *Tc)
89320cf1dd8SToby Isaac {
89420cf1dd8SToby Isaac   PetscErrorCode   ierr;
89520cf1dd8SToby Isaac 
89620cf1dd8SToby Isaac   PetscFunctionBegin;
89720cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
898ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tc, 2);
899ef0bb6c7SMatthew G. Knepley   if (!fem->Tc) {
90020cf1dd8SToby Isaac     PetscDualSpace  sp;
90120cf1dd8SToby Isaac     DM              dm;
90220cf1dd8SToby Isaac     const PetscInt *cone;
90320cf1dd8SToby Isaac     PetscReal      *centroids;
90420cf1dd8SToby Isaac     PetscInt        dim, numFaces, f;
90520cf1dd8SToby Isaac 
90620cf1dd8SToby Isaac     ierr = PetscFEGetDualSpace(fem, &sp);CHKERRQ(ierr);
90720cf1dd8SToby Isaac     ierr = PetscDualSpaceGetDM(sp, &dm);CHKERRQ(ierr);
90820cf1dd8SToby Isaac     ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
90920cf1dd8SToby Isaac     ierr = DMPlexGetConeSize(dm, 0, &numFaces);CHKERRQ(ierr);
91020cf1dd8SToby Isaac     ierr = DMPlexGetCone(dm, 0, &cone);CHKERRQ(ierr);
91120cf1dd8SToby Isaac     ierr = PetscMalloc1(numFaces*dim, &centroids);CHKERRQ(ierr);
91220cf1dd8SToby Isaac     for (f = 0; f < numFaces; ++f) {ierr = DMPlexComputeCellGeometryFVM(dm, cone[f], NULL, &centroids[f*dim], NULL);CHKERRQ(ierr);}
913ef0bb6c7SMatthew G. Knepley     ierr = PetscFECreateTabulation(fem, 1, numFaces, centroids, 0, &fem->Tc);CHKERRQ(ierr);
91420cf1dd8SToby Isaac     ierr = PetscFree(centroids);CHKERRQ(ierr);
91520cf1dd8SToby Isaac   }
916ef0bb6c7SMatthew G. Knepley   *Tc = fem->Tc;
91720cf1dd8SToby Isaac   PetscFunctionReturn(0);
91820cf1dd8SToby Isaac }
91920cf1dd8SToby Isaac 
92020cf1dd8SToby Isaac /*@C
921ef0bb6c7SMatthew G. Knepley   PetscFECreateTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided.
92220cf1dd8SToby Isaac 
92320cf1dd8SToby Isaac   Not collective
92420cf1dd8SToby Isaac 
92520cf1dd8SToby Isaac   Input Parameters:
92620cf1dd8SToby Isaac + fem     - The PetscFE object
927ef0bb6c7SMatthew G. Knepley . nrepl   - The number of replicas
928ef0bb6c7SMatthew G. Knepley . npoints - The number of tabulation points in a replica
929ef0bb6c7SMatthew G. Knepley . points  - The tabulation point coordinates
930ef0bb6c7SMatthew G. Knepley - K       - The number of derivatives calculated
93120cf1dd8SToby Isaac 
932ef0bb6c7SMatthew G. Knepley   Output Parameter:
933ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at tabulation points
93420cf1dd8SToby Isaac 
93520cf1dd8SToby Isaac   Note:
936ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c
937ef0bb6c7SMatthew G. Knepley $ T->T[1] = D[((p*pdim + i)*Nc + c)*dim + d] is the derivative value at point p for basis function i, component c, in direction d
938ef0bb6c7SMatthew G. Knepley $ T->T[2] = H[(((p*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point p for basis function i, component c, in directions d and e
93920cf1dd8SToby Isaac 
94020cf1dd8SToby Isaac   Level: intermediate
94120cf1dd8SToby Isaac 
942ef0bb6c7SMatthew G. Knepley .seealso: PetscFEGetCellTabulation(), PetscTabulationDestroy()
94320cf1dd8SToby Isaac @*/
944ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFECreateTabulation(PetscFE fem, PetscInt nrepl, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation *T)
94520cf1dd8SToby Isaac {
94620cf1dd8SToby Isaac   DM               dm;
947ef0bb6c7SMatthew G. Knepley   PetscDualSpace   Q;
948ef0bb6c7SMatthew G. Knepley   PetscInt         Nb;   /* Dimension of FE space P */
949ef0bb6c7SMatthew G. Knepley   PetscInt         Nc;   /* Field components */
950ef0bb6c7SMatthew G. Knepley   PetscInt         cdim; /* Reference coordinate dimension */
951ef0bb6c7SMatthew G. Knepley   PetscInt         k;
95220cf1dd8SToby Isaac   PetscErrorCode   ierr;
95320cf1dd8SToby Isaac 
95420cf1dd8SToby Isaac   PetscFunctionBegin;
955ef0bb6c7SMatthew G. Knepley   if (!npoints || !fem->dualSpace || K < 0) {
956ef0bb6c7SMatthew G. Knepley     *T = NULL;
95720cf1dd8SToby Isaac     PetscFunctionReturn(0);
95820cf1dd8SToby Isaac   }
95920cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
96040a2aa30SMatthew G. Knepley   PetscValidPointer(points, 4);
96140a2aa30SMatthew G. Knepley   PetscValidPointer(T, 6);
962ef0bb6c7SMatthew G. Knepley   ierr = PetscFEGetDualSpace(fem, &Q);CHKERRQ(ierr);
963ef0bb6c7SMatthew G. Knepley   ierr = PetscDualSpaceGetDM(Q, &dm);CHKERRQ(ierr);
964ef0bb6c7SMatthew G. Knepley   ierr = DMGetDimension(dm, &cdim);CHKERRQ(ierr);
965ef0bb6c7SMatthew G. Knepley   ierr = PetscDualSpaceGetDimension(Q, &Nb);CHKERRQ(ierr);
966ef0bb6c7SMatthew G. Knepley   ierr = PetscFEGetNumComponents(fem, &Nc);CHKERRQ(ierr);
967ef0bb6c7SMatthew G. Knepley   ierr = PetscMalloc1(1, T);CHKERRQ(ierr);
968ef0bb6c7SMatthew G. Knepley   (*T)->K    = !cdim ? 0 : K;
969ef0bb6c7SMatthew G. Knepley   (*T)->Nr   = nrepl;
970ef0bb6c7SMatthew G. Knepley   (*T)->Np   = npoints;
971ef0bb6c7SMatthew G. Knepley   (*T)->Nb   = Nb;
972ef0bb6c7SMatthew G. Knepley   (*T)->Nc   = Nc;
973ef0bb6c7SMatthew G. Knepley   (*T)->cdim = cdim;
974ef0bb6c7SMatthew G. Knepley   ierr = PetscMalloc1((*T)->K+1, &(*T)->T);CHKERRQ(ierr);
975ef0bb6c7SMatthew G. Knepley   for (k = 0; k <= (*T)->K; ++k) {
976ef0bb6c7SMatthew G. Knepley     ierr = PetscMalloc1(nrepl*npoints*Nb*Nc*PetscPowInt(cdim, k), &(*T)->T[k]);CHKERRQ(ierr);
97720cf1dd8SToby Isaac   }
978ef0bb6c7SMatthew G. Knepley   ierr = (*fem->ops->createtabulation)(fem, nrepl*npoints, points, K, *T);CHKERRQ(ierr);
97920cf1dd8SToby Isaac   PetscFunctionReturn(0);
98020cf1dd8SToby Isaac }
98120cf1dd8SToby Isaac 
9822b99622eSMatthew G. Knepley /*@C
983ef0bb6c7SMatthew G. Knepley   PetscFEComputeTabulation - Tabulates the basis functions, and perhaps derivatives, at the points provided.
9842b99622eSMatthew G. Knepley 
9852b99622eSMatthew G. Knepley   Not collective
9862b99622eSMatthew G. Knepley 
9872b99622eSMatthew G. Knepley   Input Parameters:
9882b99622eSMatthew G. Knepley + fem     - The PetscFE object
9892b99622eSMatthew G. Knepley . npoints - The number of tabulation points
9902b99622eSMatthew G. Knepley . points  - The tabulation point coordinates
991ef0bb6c7SMatthew G. Knepley . K       - The number of derivatives calculated
992ef0bb6c7SMatthew G. Knepley - T       - An existing tabulation object with enough allocated space
993ef0bb6c7SMatthew G. Knepley 
994ef0bb6c7SMatthew G. Knepley   Output Parameter:
995ef0bb6c7SMatthew G. Knepley . T - The basis function values and derivatives at tabulation points
9962b99622eSMatthew G. Knepley 
9972b99622eSMatthew G. Knepley   Note:
998ef0bb6c7SMatthew G. Knepley $ T->T[0] = B[(p*pdim + i)*Nc + c] is the value at point p for basis function i and component c
999ef0bb6c7SMatthew G. Knepley $ T->T[1] = D[((p*pdim + i)*Nc + c)*dim + d] is the derivative value at point p for basis function i, component c, in direction d
1000ef0bb6c7SMatthew G. Knepley $ T->T[2] = H[(((p*pdim + i)*Nc + c)*dim + d)*dim + e] is the value at point p for basis function i, component c, in directions d and e
10012b99622eSMatthew G. Knepley 
10022b99622eSMatthew G. Knepley   Level: intermediate
10032b99622eSMatthew G. Knepley 
1004ef0bb6c7SMatthew G. Knepley .seealso: PetscFEGetCellTabulation(), PetscTabulationDestroy()
10052b99622eSMatthew G. Knepley @*/
1006ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEComputeTabulation(PetscFE fem, PetscInt npoints, const PetscReal points[], PetscInt K, PetscTabulation T)
1007ef0bb6c7SMatthew G. Knepley {
1008ef0bb6c7SMatthew G. Knepley   PetscErrorCode ierr;
1009ef0bb6c7SMatthew G. Knepley 
1010ef0bb6c7SMatthew G. Knepley   PetscFunctionBeginHot;
1011ef0bb6c7SMatthew G. Knepley   if (!npoints || !fem->dualSpace || K < 0) PetscFunctionReturn(0);
1012ef0bb6c7SMatthew G. Knepley   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
1013ef0bb6c7SMatthew G. Knepley   PetscValidPointer(points, 3);
1014ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 5);
101576bd3646SJed Brown   if (PetscDefined(USE_DEBUG)) {
101620cf1dd8SToby Isaac     DM               dm;
1017ef0bb6c7SMatthew G. Knepley     PetscDualSpace   Q;
1018ef0bb6c7SMatthew G. Knepley     PetscInt         Nb;   /* Dimension of FE space P */
1019ef0bb6c7SMatthew G. Knepley     PetscInt         Nc;   /* Field components */
1020ef0bb6c7SMatthew G. Knepley     PetscInt         cdim; /* Reference coordinate dimension */
1021ef0bb6c7SMatthew G. Knepley 
1022ef0bb6c7SMatthew G. Knepley     ierr = PetscFEGetDualSpace(fem, &Q);CHKERRQ(ierr);
1023ef0bb6c7SMatthew G. Knepley     ierr = PetscDualSpaceGetDM(Q, &dm);CHKERRQ(ierr);
1024ef0bb6c7SMatthew G. Knepley     ierr = DMGetDimension(dm, &cdim);CHKERRQ(ierr);
1025ef0bb6c7SMatthew G. Knepley     ierr = PetscDualSpaceGetDimension(Q, &Nb);CHKERRQ(ierr);
1026ef0bb6c7SMatthew G. Knepley     ierr = PetscFEGetNumComponents(fem, &Nc);CHKERRQ(ierr);
1027ef0bb6c7SMatthew G. Knepley     if (T->K    != (!cdim ? 0 : K)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Tabulation K %D must match requested K %D", T->K, !cdim ? 0 : K);
1028ef0bb6c7SMatthew G. Knepley     if (T->Nb   != Nb)              SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Tabulation Nb %D must match requested Nb %D", T->Nb, Nb);
1029ef0bb6c7SMatthew G. Knepley     if (T->Nc   != Nc)              SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Tabulation Nc %D must match requested Nc %D", T->Nc, Nc);
1030ef0bb6c7SMatthew G. Knepley     if (T->cdim != cdim)            SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Tabulation cdim %D must match requested cdim %D", T->cdim, cdim);
1031ef0bb6c7SMatthew G. Knepley   }
1032ef0bb6c7SMatthew G. Knepley   T->Nr = 1;
1033ef0bb6c7SMatthew G. Knepley   T->Np = npoints;
1034ef0bb6c7SMatthew G. Knepley   ierr = (*fem->ops->createtabulation)(fem, npoints, points, K, T);CHKERRQ(ierr);
1035ef0bb6c7SMatthew G. Knepley   PetscFunctionReturn(0);
1036ef0bb6c7SMatthew G. Knepley }
1037ef0bb6c7SMatthew G. Knepley 
1038ef0bb6c7SMatthew G. Knepley /*@C
1039ef0bb6c7SMatthew G. Knepley   PetscTabulationDestroy - Frees memory from the associated tabulation.
1040ef0bb6c7SMatthew G. Knepley 
1041ef0bb6c7SMatthew G. Knepley   Not collective
1042ef0bb6c7SMatthew G. Knepley 
1043ef0bb6c7SMatthew G. Knepley   Input Parameter:
1044ef0bb6c7SMatthew G. Knepley . T - The tabulation
1045ef0bb6c7SMatthew G. Knepley 
1046ef0bb6c7SMatthew G. Knepley   Level: intermediate
1047ef0bb6c7SMatthew G. Knepley 
1048ef0bb6c7SMatthew G. Knepley .seealso: PetscFECreateTabulation(), PetscFEGetCellTabulation()
1049ef0bb6c7SMatthew G. Knepley @*/
1050ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscTabulationDestroy(PetscTabulation *T)
1051ef0bb6c7SMatthew G. Knepley {
1052ef0bb6c7SMatthew G. Knepley   PetscInt       k;
105320cf1dd8SToby Isaac   PetscErrorCode ierr;
105420cf1dd8SToby Isaac 
105520cf1dd8SToby Isaac   PetscFunctionBegin;
1056ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 1);
1057ef0bb6c7SMatthew G. Knepley   if (!T || !(*T)) PetscFunctionReturn(0);
1058ef0bb6c7SMatthew G. Knepley   for (k = 0; k <= (*T)->K; ++k) {ierr = PetscFree((*T)->T[k]);CHKERRQ(ierr);}
1059ef0bb6c7SMatthew G. Knepley   ierr = PetscFree((*T)->T);CHKERRQ(ierr);
1060ef0bb6c7SMatthew G. Knepley   ierr = PetscFree(*T);CHKERRQ(ierr);
1061ef0bb6c7SMatthew G. Knepley   *T = NULL;
106220cf1dd8SToby Isaac   PetscFunctionReturn(0);
106320cf1dd8SToby Isaac }
106420cf1dd8SToby Isaac 
106520cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode PetscFECreatePointTrace(PetscFE fe, PetscInt refPoint, PetscFE *trFE)
106620cf1dd8SToby Isaac {
106720cf1dd8SToby Isaac   PetscSpace     bsp, bsubsp;
106820cf1dd8SToby Isaac   PetscDualSpace dsp, dsubsp;
106920cf1dd8SToby Isaac   PetscInt       dim, depth, numComp, i, j, coneSize, order;
107020cf1dd8SToby Isaac   PetscFEType    type;
107120cf1dd8SToby Isaac   DM             dm;
107220cf1dd8SToby Isaac   DMLabel        label;
107320cf1dd8SToby Isaac   PetscReal      *xi, *v, *J, detJ;
1074db11e2ebSMatthew G. Knepley   const char     *name;
107520cf1dd8SToby Isaac   PetscQuadrature origin, fullQuad, subQuad;
107620cf1dd8SToby Isaac   PetscErrorCode ierr;
107720cf1dd8SToby Isaac 
107820cf1dd8SToby Isaac   PetscFunctionBegin;
107920cf1dd8SToby Isaac   PetscValidHeaderSpecific(fe,PETSCFE_CLASSID,1);
108020cf1dd8SToby Isaac   PetscValidPointer(trFE,3);
108120cf1dd8SToby Isaac   ierr = PetscFEGetBasisSpace(fe,&bsp);CHKERRQ(ierr);
108220cf1dd8SToby Isaac   ierr = PetscFEGetDualSpace(fe,&dsp);CHKERRQ(ierr);
108320cf1dd8SToby Isaac   ierr = PetscDualSpaceGetDM(dsp,&dm);CHKERRQ(ierr);
108420cf1dd8SToby Isaac   ierr = DMGetDimension(dm,&dim);CHKERRQ(ierr);
108520cf1dd8SToby Isaac   ierr = DMPlexGetDepthLabel(dm,&label);CHKERRQ(ierr);
108620cf1dd8SToby Isaac   ierr = DMLabelGetValue(label,refPoint,&depth);CHKERRQ(ierr);
108720cf1dd8SToby Isaac   ierr = PetscCalloc1(depth,&xi);CHKERRQ(ierr);
108820cf1dd8SToby Isaac   ierr = PetscMalloc1(dim,&v);CHKERRQ(ierr);
108920cf1dd8SToby Isaac   ierr = PetscMalloc1(dim*dim,&J);CHKERRQ(ierr);
109020cf1dd8SToby Isaac   for (i = 0; i < depth; i++) xi[i] = 0.;
109120cf1dd8SToby Isaac   ierr = PetscQuadratureCreate(PETSC_COMM_SELF,&origin);CHKERRQ(ierr);
109220cf1dd8SToby Isaac   ierr = PetscQuadratureSetData(origin,depth,0,1,xi,NULL);CHKERRQ(ierr);
109320cf1dd8SToby Isaac   ierr = DMPlexComputeCellGeometryFEM(dm,refPoint,origin,v,J,NULL,&detJ);CHKERRQ(ierr);
109420cf1dd8SToby Isaac   /* CellGeometryFEM computes the expanded Jacobian, we want the true jacobian */
109520cf1dd8SToby Isaac   for (i = 1; i < dim; i++) {
109620cf1dd8SToby Isaac     for (j = 0; j < depth; j++) {
109720cf1dd8SToby Isaac       J[i * depth + j] = J[i * dim + j];
109820cf1dd8SToby Isaac     }
109920cf1dd8SToby Isaac   }
110020cf1dd8SToby Isaac   ierr = PetscQuadratureDestroy(&origin);CHKERRQ(ierr);
110120cf1dd8SToby Isaac   ierr = PetscDualSpaceGetPointSubspace(dsp,refPoint,&dsubsp);CHKERRQ(ierr);
110220cf1dd8SToby Isaac   ierr = PetscSpaceCreateSubspace(bsp,dsubsp,v,J,NULL,NULL,PETSC_OWN_POINTER,&bsubsp);CHKERRQ(ierr);
110320cf1dd8SToby Isaac   ierr = PetscSpaceSetUp(bsubsp);CHKERRQ(ierr);
110420cf1dd8SToby Isaac   ierr = PetscFECreate(PetscObjectComm((PetscObject)fe),trFE);CHKERRQ(ierr);
110520cf1dd8SToby Isaac   ierr = PetscFEGetType(fe,&type);CHKERRQ(ierr);
110620cf1dd8SToby Isaac   ierr = PetscFESetType(*trFE,type);CHKERRQ(ierr);
110720cf1dd8SToby Isaac   ierr = PetscFEGetNumComponents(fe,&numComp);CHKERRQ(ierr);
110820cf1dd8SToby Isaac   ierr = PetscFESetNumComponents(*trFE,numComp);CHKERRQ(ierr);
110920cf1dd8SToby Isaac   ierr = PetscFESetBasisSpace(*trFE,bsubsp);CHKERRQ(ierr);
111020cf1dd8SToby Isaac   ierr = PetscFESetDualSpace(*trFE,dsubsp);CHKERRQ(ierr);
1111db11e2ebSMatthew G. Knepley   ierr = PetscObjectGetName((PetscObject) fe, &name);CHKERRQ(ierr);
1112db11e2ebSMatthew G. Knepley   if (name) {ierr = PetscFESetName(*trFE, name);CHKERRQ(ierr);}
111320cf1dd8SToby Isaac   ierr = PetscFEGetQuadrature(fe,&fullQuad);CHKERRQ(ierr);
111420cf1dd8SToby Isaac   ierr = PetscQuadratureGetOrder(fullQuad,&order);CHKERRQ(ierr);
111520cf1dd8SToby Isaac   ierr = DMPlexGetConeSize(dm,refPoint,&coneSize);CHKERRQ(ierr);
111620cf1dd8SToby Isaac   if (coneSize == 2 * depth) {
111720cf1dd8SToby Isaac     ierr = PetscDTGaussTensorQuadrature(depth,1,(order + 1)/2,-1.,1.,&subQuad);CHKERRQ(ierr);
111820cf1dd8SToby Isaac   } else {
1119e6a796c3SToby Isaac     ierr = PetscDTStroudConicalQuadrature(depth,1,(order + 1)/2,-1.,1.,&subQuad);CHKERRQ(ierr);
112020cf1dd8SToby Isaac   }
112120cf1dd8SToby Isaac   ierr = PetscFESetQuadrature(*trFE,subQuad);CHKERRQ(ierr);
112220cf1dd8SToby Isaac   ierr = PetscFESetUp(*trFE);CHKERRQ(ierr);
112320cf1dd8SToby Isaac   ierr = PetscQuadratureDestroy(&subQuad);CHKERRQ(ierr);
112420cf1dd8SToby Isaac   ierr = PetscSpaceDestroy(&bsubsp);CHKERRQ(ierr);
112520cf1dd8SToby Isaac   PetscFunctionReturn(0);
112620cf1dd8SToby Isaac }
112720cf1dd8SToby Isaac 
112820cf1dd8SToby Isaac PetscErrorCode PetscFECreateHeightTrace(PetscFE fe, PetscInt height, PetscFE *trFE)
112920cf1dd8SToby Isaac {
113020cf1dd8SToby Isaac   PetscInt       hStart, hEnd;
113120cf1dd8SToby Isaac   PetscDualSpace dsp;
113220cf1dd8SToby Isaac   DM             dm;
113320cf1dd8SToby Isaac   PetscErrorCode ierr;
113420cf1dd8SToby Isaac 
113520cf1dd8SToby Isaac   PetscFunctionBegin;
113620cf1dd8SToby Isaac   PetscValidHeaderSpecific(fe,PETSCFE_CLASSID,1);
113720cf1dd8SToby Isaac   PetscValidPointer(trFE,3);
113820cf1dd8SToby Isaac   *trFE = NULL;
113920cf1dd8SToby Isaac   ierr = PetscFEGetDualSpace(fe,&dsp);CHKERRQ(ierr);
114020cf1dd8SToby Isaac   ierr = PetscDualSpaceGetDM(dsp,&dm);CHKERRQ(ierr);
114120cf1dd8SToby Isaac   ierr = DMPlexGetHeightStratum(dm,height,&hStart,&hEnd);CHKERRQ(ierr);
114220cf1dd8SToby Isaac   if (hEnd <= hStart) PetscFunctionReturn(0);
114320cf1dd8SToby Isaac   ierr = PetscFECreatePointTrace(fe,hStart,trFE);CHKERRQ(ierr);
114420cf1dd8SToby Isaac   PetscFunctionReturn(0);
114520cf1dd8SToby Isaac }
114620cf1dd8SToby Isaac 
114720cf1dd8SToby Isaac 
114820cf1dd8SToby Isaac /*@
114920cf1dd8SToby Isaac   PetscFEGetDimension - Get the dimension of the finite element space on a cell
115020cf1dd8SToby Isaac 
115120cf1dd8SToby Isaac   Not collective
115220cf1dd8SToby Isaac 
115320cf1dd8SToby Isaac   Input Parameter:
115420cf1dd8SToby Isaac . fe - The PetscFE
115520cf1dd8SToby Isaac 
115620cf1dd8SToby Isaac   Output Parameter:
115720cf1dd8SToby Isaac . dim - The dimension
115820cf1dd8SToby Isaac 
115920cf1dd8SToby Isaac   Level: intermediate
116020cf1dd8SToby Isaac 
116120cf1dd8SToby Isaac .seealso: PetscFECreate(), PetscSpaceGetDimension(), PetscDualSpaceGetDimension()
116220cf1dd8SToby Isaac @*/
116320cf1dd8SToby Isaac PetscErrorCode PetscFEGetDimension(PetscFE fem, PetscInt *dim)
116420cf1dd8SToby Isaac {
116520cf1dd8SToby Isaac   PetscErrorCode ierr;
116620cf1dd8SToby Isaac 
116720cf1dd8SToby Isaac   PetscFunctionBegin;
116820cf1dd8SToby Isaac   PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1);
116920cf1dd8SToby Isaac   PetscValidPointer(dim, 2);
117020cf1dd8SToby Isaac   if (fem->ops->getdimension) {ierr = (*fem->ops->getdimension)(fem, dim);CHKERRQ(ierr);}
117120cf1dd8SToby Isaac   PetscFunctionReturn(0);
117220cf1dd8SToby Isaac }
117320cf1dd8SToby Isaac 
11744bee2e38SMatthew G. Knepley /*@C
11754bee2e38SMatthew G. Knepley   PetscFEPushforward - Map the reference element function to real space
11764bee2e38SMatthew G. Knepley 
11774bee2e38SMatthew G. Knepley   Input Parameters:
11784bee2e38SMatthew G. Knepley + fe     - The PetscFE
11794bee2e38SMatthew G. Knepley . fegeom - The cell geometry
11804bee2e38SMatthew G. Knepley . Nv     - The number of function values
11814bee2e38SMatthew G. Knepley - vals   - The function values
11824bee2e38SMatthew G. Knepley 
11834bee2e38SMatthew G. Knepley   Output Parameter:
11844bee2e38SMatthew G. Knepley . vals   - The transformed function values
11854bee2e38SMatthew G. Knepley 
11864bee2e38SMatthew G. Knepley   Level: advanced
11874bee2e38SMatthew G. Knepley 
11884bee2e38SMatthew G. Knepley   Note: This just forwards the call onto PetscDualSpacePushforward().
11894bee2e38SMatthew G. Knepley 
11902edcad52SToby Isaac   Note: This only handles tranformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension.
11912edcad52SToby Isaac 
11924bee2e38SMatthew G. Knepley .seealso: PetscDualSpacePushforward()
11934bee2e38SMatthew G. Knepley @*/
11942edcad52SToby Isaac PetscErrorCode PetscFEPushforward(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[])
11954bee2e38SMatthew G. Knepley {
11964bee2e38SMatthew G. Knepley   PetscErrorCode ierr;
11974bee2e38SMatthew G. Knepley 
11982ae266adSMatthew G. Knepley   PetscFunctionBeginHot;
11992edcad52SToby Isaac   ierr = PetscDualSpacePushforward(fe->dualSpace, fegeom, Nv, fe->numComponents, vals);CHKERRQ(ierr);
12004bee2e38SMatthew G. Knepley   PetscFunctionReturn(0);
12014bee2e38SMatthew G. Knepley }
12024bee2e38SMatthew G. Knepley 
12034bee2e38SMatthew G. Knepley /*@C
12044bee2e38SMatthew G. Knepley   PetscFEPushforwardGradient - Map the reference element function gradient to real space
12054bee2e38SMatthew G. Knepley 
12064bee2e38SMatthew G. Knepley   Input Parameters:
12074bee2e38SMatthew G. Knepley + fe     - The PetscFE
12084bee2e38SMatthew G. Knepley . fegeom - The cell geometry
12094bee2e38SMatthew G. Knepley . Nv     - The number of function gradient values
12104bee2e38SMatthew G. Knepley - vals   - The function gradient values
12114bee2e38SMatthew G. Knepley 
12124bee2e38SMatthew G. Knepley   Output Parameter:
12134bee2e38SMatthew G. Knepley . vals   - The transformed function gradient values
12144bee2e38SMatthew G. Knepley 
12154bee2e38SMatthew G. Knepley   Level: advanced
12164bee2e38SMatthew G. Knepley 
12174bee2e38SMatthew G. Knepley   Note: This just forwards the call onto PetscDualSpacePushforwardGradient().
12184bee2e38SMatthew G. Knepley 
12192edcad52SToby Isaac   Note: This only handles tranformations when the embedding dimension of the geometry in fegeom is the same as the reference dimension.
12202edcad52SToby Isaac 
12214bee2e38SMatthew G. Knepley .seealso: PetscFEPushforward(), PetscDualSpacePushforwardGradient(), PetscDualSpacePushforward()
12224bee2e38SMatthew G. Knepley @*/
12232edcad52SToby Isaac PetscErrorCode PetscFEPushforwardGradient(PetscFE fe, PetscFEGeom *fegeom, PetscInt Nv, PetscScalar vals[])
12244bee2e38SMatthew G. Knepley {
12254bee2e38SMatthew G. Knepley   PetscErrorCode ierr;
12264bee2e38SMatthew G. Knepley 
12272ae266adSMatthew G. Knepley   PetscFunctionBeginHot;
12282edcad52SToby Isaac   ierr = PetscDualSpacePushforwardGradient(fe->dualSpace, fegeom, Nv, fe->numComponents, vals);CHKERRQ(ierr);
12294bee2e38SMatthew G. Knepley   PetscFunctionReturn(0);
12304bee2e38SMatthew G. Knepley }
12314bee2e38SMatthew G. Knepley 
123220cf1dd8SToby Isaac /*
123320cf1dd8SToby Isaac Purpose: Compute element vector for chunk of elements
123420cf1dd8SToby Isaac 
123520cf1dd8SToby Isaac Input:
123620cf1dd8SToby Isaac   Sizes:
123720cf1dd8SToby Isaac      Ne:  number of elements
123820cf1dd8SToby Isaac      Nf:  number of fields
123920cf1dd8SToby Isaac      PetscFE
124020cf1dd8SToby Isaac        dim: spatial dimension
124120cf1dd8SToby Isaac        Nb:  number of basis functions
124220cf1dd8SToby Isaac        Nc:  number of field components
124320cf1dd8SToby Isaac        PetscQuadrature
124420cf1dd8SToby Isaac          Nq:  number of quadrature points
124520cf1dd8SToby Isaac 
124620cf1dd8SToby Isaac   Geometry:
124720cf1dd8SToby Isaac      PetscFEGeom[Ne] possibly *Nq
124820cf1dd8SToby Isaac        PetscReal v0s[dim]
124920cf1dd8SToby Isaac        PetscReal n[dim]
125020cf1dd8SToby Isaac        PetscReal jacobians[dim*dim]
125120cf1dd8SToby Isaac        PetscReal jacobianInverses[dim*dim]
125220cf1dd8SToby Isaac        PetscReal jacobianDeterminants
125320cf1dd8SToby Isaac   FEM:
125420cf1dd8SToby Isaac      PetscFE
125520cf1dd8SToby Isaac        PetscQuadrature
125620cf1dd8SToby Isaac          PetscReal   quadPoints[Nq*dim]
125720cf1dd8SToby Isaac          PetscReal   quadWeights[Nq]
125820cf1dd8SToby Isaac        PetscReal   basis[Nq*Nb*Nc]
125920cf1dd8SToby Isaac        PetscReal   basisDer[Nq*Nb*Nc*dim]
126020cf1dd8SToby Isaac      PetscScalar coefficients[Ne*Nb*Nc]
126120cf1dd8SToby Isaac      PetscScalar elemVec[Ne*Nb*Nc]
126220cf1dd8SToby Isaac 
126320cf1dd8SToby Isaac   Problem:
126420cf1dd8SToby Isaac      PetscInt f: the active field
126520cf1dd8SToby Isaac      f0, f1
126620cf1dd8SToby Isaac 
126720cf1dd8SToby Isaac   Work Space:
126820cf1dd8SToby Isaac      PetscFE
126920cf1dd8SToby Isaac        PetscScalar f0[Nq*dim];
127020cf1dd8SToby Isaac        PetscScalar f1[Nq*dim*dim];
127120cf1dd8SToby Isaac        PetscScalar u[Nc];
127220cf1dd8SToby Isaac        PetscScalar gradU[Nc*dim];
127320cf1dd8SToby Isaac        PetscReal   x[dim];
127420cf1dd8SToby Isaac        PetscScalar realSpaceDer[dim];
127520cf1dd8SToby Isaac 
127620cf1dd8SToby Isaac Purpose: Compute element vector for N_cb batches of elements
127720cf1dd8SToby Isaac 
127820cf1dd8SToby Isaac Input:
127920cf1dd8SToby Isaac   Sizes:
128020cf1dd8SToby Isaac      N_cb: Number of serial cell batches
128120cf1dd8SToby Isaac 
128220cf1dd8SToby Isaac   Geometry:
128320cf1dd8SToby Isaac      PetscReal v0s[Ne*dim]
128420cf1dd8SToby Isaac      PetscReal jacobians[Ne*dim*dim]        possibly *Nq
128520cf1dd8SToby Isaac      PetscReal jacobianInverses[Ne*dim*dim] possibly *Nq
128620cf1dd8SToby Isaac      PetscReal jacobianDeterminants[Ne]     possibly *Nq
128720cf1dd8SToby Isaac   FEM:
128820cf1dd8SToby Isaac      static PetscReal   quadPoints[Nq*dim]
128920cf1dd8SToby Isaac      static PetscReal   quadWeights[Nq]
129020cf1dd8SToby Isaac      static PetscReal   basis[Nq*Nb*Nc]
129120cf1dd8SToby Isaac      static PetscReal   basisDer[Nq*Nb*Nc*dim]
129220cf1dd8SToby Isaac      PetscScalar coefficients[Ne*Nb*Nc]
129320cf1dd8SToby Isaac      PetscScalar elemVec[Ne*Nb*Nc]
129420cf1dd8SToby Isaac 
129520cf1dd8SToby Isaac ex62.c:
129620cf1dd8SToby Isaac   PetscErrorCode PetscFEIntegrateResidualBatch(PetscInt Ne, PetscInt numFields, PetscInt field, PetscQuadrature quad[], const PetscScalar coefficients[],
129720cf1dd8SToby Isaac                                                const PetscReal v0s[], const PetscReal jacobians[], const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[],
129820cf1dd8SToby Isaac                                                void (*f0_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f0[]),
129920cf1dd8SToby Isaac                                                void (*f1_func)(const PetscScalar u[], const PetscScalar gradU[], const PetscReal x[], PetscScalar f1[]), PetscScalar elemVec[])
130020cf1dd8SToby Isaac 
130120cf1dd8SToby Isaac ex52.c:
130220cf1dd8SToby 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)
130320cf1dd8SToby 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)
130420cf1dd8SToby Isaac 
130520cf1dd8SToby Isaac ex52_integrateElement.cu
130620cf1dd8SToby Isaac __global__ void integrateElementQuadrature(int N_cb, realType *coefficients, realType *jacobianInverses, realType *jacobianDeterminants, realType *elemVec)
130720cf1dd8SToby Isaac 
130820cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt Nbl, const PetscScalar coefficients[],
130920cf1dd8SToby Isaac                                                      const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[],
131020cf1dd8SToby Isaac                                                      PetscLogEvent event, PetscInt debug, PetscInt pde_op)
131120cf1dd8SToby Isaac 
131220cf1dd8SToby Isaac ex52_integrateElementOpenCL.c:
131320cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode IntegrateElementBatchGPU(PetscInt spatial_dim, PetscInt Ne, PetscInt Ncb, PetscInt Nbc, PetscInt N_bl, const PetscScalar coefficients[],
131420cf1dd8SToby Isaac                                                      const PetscReal jacobianInverses[], const PetscReal jacobianDeterminants[], PetscScalar elemVec[],
131520cf1dd8SToby Isaac                                                      PetscLogEvent event, PetscInt debug, PetscInt pde_op)
131620cf1dd8SToby Isaac 
131720cf1dd8SToby Isaac __kernel void integrateElementQuadrature(int N_cb, __global float *coefficients, __global float *jacobianInverses, __global float *jacobianDeterminants, __global float *elemVec)
131820cf1dd8SToby Isaac */
131920cf1dd8SToby Isaac 
132020cf1dd8SToby Isaac /*@C
132120cf1dd8SToby Isaac   PetscFEIntegrate - Produce the integral for the given field for a chunk of elements by quadrature integration
132220cf1dd8SToby Isaac 
132320cf1dd8SToby Isaac   Not collective
132420cf1dd8SToby Isaac 
132520cf1dd8SToby Isaac   Input Parameters:
1326360cf244SMatthew G. Knepley + prob         - The PetscDS specifying the discretizations and continuum functions
132720cf1dd8SToby Isaac . field        - The field being integrated
132820cf1dd8SToby Isaac . Ne           - The number of elements in the chunk
132920cf1dd8SToby Isaac . cgeom        - The cell geometry for each cell in the chunk
133020cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements
133120cf1dd8SToby Isaac . probAux      - The PetscDS specifying the auxiliary discretizations
133220cf1dd8SToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements
133320cf1dd8SToby Isaac 
13347a7aea1fSJed Brown   Output Parameter:
133520cf1dd8SToby Isaac . integral     - the integral for this field
133620cf1dd8SToby Isaac 
13372b99622eSMatthew G. Knepley   Level: intermediate
133820cf1dd8SToby Isaac 
133920cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual()
134020cf1dd8SToby Isaac @*/
13414bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrate(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom,
134220cf1dd8SToby Isaac                                 const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[])
134320cf1dd8SToby Isaac {
13444bee2e38SMatthew G. Knepley   PetscFE        fe;
134520cf1dd8SToby Isaac   PetscErrorCode ierr;
134620cf1dd8SToby Isaac 
134720cf1dd8SToby Isaac   PetscFunctionBegin;
13484bee2e38SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
13494bee2e38SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr);
13504bee2e38SMatthew G. Knepley   if (fe->ops->integrate) {ierr = (*fe->ops->integrate)(prob, field, Ne, cgeom, coefficients, probAux, coefficientsAux, integral);CHKERRQ(ierr);}
135120cf1dd8SToby Isaac   PetscFunctionReturn(0);
135220cf1dd8SToby Isaac }
135320cf1dd8SToby Isaac 
135420cf1dd8SToby Isaac /*@C
1355afe6d6adSToby Isaac   PetscFEIntegrateBd - Produce the integral for the given field for a chunk of elements by quadrature integration
1356afe6d6adSToby Isaac 
1357afe6d6adSToby Isaac   Not collective
1358afe6d6adSToby Isaac 
1359afe6d6adSToby Isaac   Input Parameters:
1360360cf244SMatthew G. Knepley + prob         - The PetscDS specifying the discretizations and continuum functions
1361afe6d6adSToby Isaac . field        - The field being integrated
1362afe6d6adSToby Isaac . obj_func     - The function to be integrated
1363afe6d6adSToby Isaac . Ne           - The number of elements in the chunk
1364afe6d6adSToby Isaac . fgeom        - The face geometry for each face in the chunk
1365afe6d6adSToby Isaac . coefficients - The array of FEM basis coefficients for the elements
1366afe6d6adSToby Isaac . probAux      - The PetscDS specifying the auxiliary discretizations
1367afe6d6adSToby Isaac - coefficientsAux - The array of FEM auxiliary basis coefficients for the elements
1368afe6d6adSToby Isaac 
13697a7aea1fSJed Brown   Output Parameter:
1370afe6d6adSToby Isaac . integral     - the integral for this field
1371afe6d6adSToby Isaac 
13722b99622eSMatthew G. Knepley   Level: intermediate
1373afe6d6adSToby Isaac 
1374afe6d6adSToby Isaac .seealso: PetscFEIntegrateResidual()
1375afe6d6adSToby Isaac @*/
13764bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBd(PetscDS prob, PetscInt field,
1377afe6d6adSToby Isaac                                   void (*obj_func)(PetscInt, PetscInt, PetscInt,
1378afe6d6adSToby Isaac                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1379afe6d6adSToby Isaac                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1380afe6d6adSToby Isaac                                                    PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1381afe6d6adSToby Isaac                                   PetscInt Ne, PetscFEGeom *geom, const PetscScalar coefficients[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscScalar integral[])
1382afe6d6adSToby Isaac {
13834bee2e38SMatthew G. Knepley   PetscFE        fe;
1384afe6d6adSToby Isaac   PetscErrorCode ierr;
1385afe6d6adSToby Isaac 
1386afe6d6adSToby Isaac   PetscFunctionBegin;
13874bee2e38SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
13884bee2e38SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr);
13894bee2e38SMatthew G. Knepley   if (fe->ops->integratebd) {ierr = (*fe->ops->integratebd)(prob, field, obj_func, Ne, geom, coefficients, probAux, coefficientsAux, integral);CHKERRQ(ierr);}
1390afe6d6adSToby Isaac   PetscFunctionReturn(0);
1391afe6d6adSToby Isaac }
1392afe6d6adSToby Isaac 
1393afe6d6adSToby Isaac /*@C
139420cf1dd8SToby Isaac   PetscFEIntegrateResidual - Produce the element residual vector for a chunk of elements by quadrature integration
139520cf1dd8SToby Isaac 
139620cf1dd8SToby Isaac   Not collective
139720cf1dd8SToby Isaac 
139820cf1dd8SToby Isaac   Input Parameters:
1399360cf244SMatthew G. Knepley + prob         - The PetscDS specifying the discretizations and continuum functions
140020cf1dd8SToby Isaac . field        - The field being integrated
140120cf1dd8SToby Isaac . Ne           - The number of elements in the chunk
140220cf1dd8SToby Isaac . cgeom        - The cell geometry for each cell in the chunk
140320cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements
140420cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements
140520cf1dd8SToby Isaac . probAux      - The PetscDS specifying the auxiliary discretizations
140620cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements
140720cf1dd8SToby Isaac - t            - The time
140820cf1dd8SToby Isaac 
14097a7aea1fSJed Brown   Output Parameter:
141020cf1dd8SToby Isaac . elemVec      - the element residual vectors from each element
141120cf1dd8SToby Isaac 
141220cf1dd8SToby Isaac   Note:
141320cf1dd8SToby Isaac $ Loop over batch of elements (e):
141420cf1dd8SToby Isaac $   Loop over quadrature points (q):
141520cf1dd8SToby Isaac $     Make u_q and gradU_q (loops over fields,Nb,Ncomp) and x_q
141620cf1dd8SToby Isaac $     Call f_0 and f_1
141720cf1dd8SToby Isaac $   Loop over element vector entries (f,fc --> i):
141820cf1dd8SToby Isaac $     elemVec[i] += \psi^{fc}_f(q) f0_{fc}(u, \nabla u) + \nabla\psi^{fc}_f(q) \cdot f1_{fc,df}(u, \nabla u)
141920cf1dd8SToby Isaac 
14202b99622eSMatthew G. Knepley   Level: intermediate
142120cf1dd8SToby Isaac 
142220cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual()
142320cf1dd8SToby Isaac @*/
14244bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateResidual(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom,
142520cf1dd8SToby Isaac                                         const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[])
142620cf1dd8SToby Isaac {
14274bee2e38SMatthew G. Knepley   PetscFE        fe;
142820cf1dd8SToby Isaac   PetscErrorCode ierr;
142920cf1dd8SToby Isaac 
143020cf1dd8SToby Isaac   PetscFunctionBegin;
14314bee2e38SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
14324bee2e38SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr);
14334bee2e38SMatthew G. Knepley   if (fe->ops->integrateresidual) {ierr = (*fe->ops->integrateresidual)(prob, field, Ne, cgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec);CHKERRQ(ierr);}
143420cf1dd8SToby Isaac   PetscFunctionReturn(0);
143520cf1dd8SToby Isaac }
143620cf1dd8SToby Isaac 
143720cf1dd8SToby Isaac /*@C
143820cf1dd8SToby Isaac   PetscFEIntegrateBdResidual - Produce the element residual vector for a chunk of elements by quadrature integration over a boundary
143920cf1dd8SToby Isaac 
144020cf1dd8SToby Isaac   Not collective
144120cf1dd8SToby Isaac 
144220cf1dd8SToby Isaac   Input Parameters:
1443360cf244SMatthew G. Knepley + prob         - The PetscDS specifying the discretizations and continuum functions
144420cf1dd8SToby Isaac . field        - The field being integrated
144520cf1dd8SToby Isaac . Ne           - The number of elements in the chunk
144620cf1dd8SToby Isaac . fgeom        - The face geometry for each cell in the chunk
144720cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements
144820cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements
144920cf1dd8SToby Isaac . probAux      - The PetscDS specifying the auxiliary discretizations
145020cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements
145120cf1dd8SToby Isaac - t            - The time
145220cf1dd8SToby Isaac 
14537a7aea1fSJed Brown   Output Parameter:
145420cf1dd8SToby Isaac . elemVec      - the element residual vectors from each element
145520cf1dd8SToby Isaac 
14562b99622eSMatthew G. Knepley   Level: intermediate
145720cf1dd8SToby Isaac 
145820cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual()
145920cf1dd8SToby Isaac @*/
14604bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdResidual(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *fgeom,
146120cf1dd8SToby Isaac                                           const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[])
146220cf1dd8SToby Isaac {
14634bee2e38SMatthew G. Knepley   PetscFE        fe;
146420cf1dd8SToby Isaac   PetscErrorCode ierr;
146520cf1dd8SToby Isaac 
146620cf1dd8SToby Isaac   PetscFunctionBegin;
14674bee2e38SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
14684bee2e38SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr);
14694bee2e38SMatthew G. Knepley   if (fe->ops->integratebdresidual) {ierr = (*fe->ops->integratebdresidual)(prob, field, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec);CHKERRQ(ierr);}
147020cf1dd8SToby Isaac   PetscFunctionReturn(0);
147120cf1dd8SToby Isaac }
147220cf1dd8SToby Isaac 
147320cf1dd8SToby Isaac /*@C
1474*27f02ce8SMatthew G. Knepley   PetscFEIntegrateHybridResidual - Produce the element residual vector for a chunk of hybrid element faces by quadrature integration
1475*27f02ce8SMatthew G. Knepley 
1476*27f02ce8SMatthew G. Knepley   Not collective
1477*27f02ce8SMatthew G. Knepley 
1478*27f02ce8SMatthew G. Knepley   Input Parameters:
1479*27f02ce8SMatthew G. Knepley + prob         - The PetscDS specifying the discretizations and continuum functions
1480*27f02ce8SMatthew G. Knepley . field        - The field being integrated
1481*27f02ce8SMatthew G. Knepley . Ne           - The number of elements in the chunk
1482*27f02ce8SMatthew G. Knepley . fgeom        - The face geometry for each cell in the chunk
1483*27f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements
1484*27f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements
1485*27f02ce8SMatthew G. Knepley . probAux      - The PetscDS specifying the auxiliary discretizations
1486*27f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements
1487*27f02ce8SMatthew G. Knepley - t            - The time
1488*27f02ce8SMatthew G. Knepley 
1489*27f02ce8SMatthew G. Knepley   Output Parameter
1490*27f02ce8SMatthew G. Knepley . elemVec      - the element residual vectors from each element
1491*27f02ce8SMatthew G. Knepley 
1492*27f02ce8SMatthew G. Knepley   Level: developer
1493*27f02ce8SMatthew G. Knepley 
1494*27f02ce8SMatthew G. Knepley .seealso: PetscFEIntegrateResidual()
1495*27f02ce8SMatthew G. Knepley @*/
1496*27f02ce8SMatthew G. Knepley PetscErrorCode PetscFEIntegrateHybridResidual(PetscDS prob, PetscInt field, PetscInt Ne, PetscFEGeom *fgeom,
1497*27f02ce8SMatthew G. Knepley                                               const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[])
1498*27f02ce8SMatthew G. Knepley {
1499*27f02ce8SMatthew G. Knepley   PetscFE        fe;
1500*27f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
1501*27f02ce8SMatthew G. Knepley 
1502*27f02ce8SMatthew G. Knepley   PetscFunctionBegin;
1503*27f02ce8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1504*27f02ce8SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr);
1505*27f02ce8SMatthew G. Knepley   if (fe->ops->integratehybridresidual) {ierr = (*fe->ops->integratehybridresidual)(prob, field, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, elemVec);CHKERRQ(ierr);}
1506*27f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
1507*27f02ce8SMatthew G. Knepley }
1508*27f02ce8SMatthew G. Knepley 
1509*27f02ce8SMatthew G. Knepley /*@C
151020cf1dd8SToby Isaac   PetscFEIntegrateJacobian - Produce the element Jacobian for a chunk of elements by quadrature integration
151120cf1dd8SToby Isaac 
151220cf1dd8SToby Isaac   Not collective
151320cf1dd8SToby Isaac 
151420cf1dd8SToby Isaac   Input Parameters:
1515360cf244SMatthew G. Knepley + prob         - The PetscDS specifying the discretizations and continuum functions
151620cf1dd8SToby Isaac . jtype        - The type of matrix pointwise functions that should be used
151720cf1dd8SToby Isaac . fieldI       - The test field being integrated
151820cf1dd8SToby Isaac . fieldJ       - The basis field being integrated
151920cf1dd8SToby Isaac . Ne           - The number of elements in the chunk
152020cf1dd8SToby Isaac . cgeom        - The cell geometry for each cell in the chunk
152120cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point
152220cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements
152320cf1dd8SToby Isaac . probAux      - The PetscDS specifying the auxiliary discretizations
152420cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements
152520cf1dd8SToby Isaac . t            - The time
152620cf1dd8SToby Isaac - u_tShift     - A multiplier for the dF/du_t term (as opposed to the dF/du term)
152720cf1dd8SToby Isaac 
15287a7aea1fSJed Brown   Output Parameter:
152920cf1dd8SToby Isaac . elemMat      - the element matrices for the Jacobian from each element
153020cf1dd8SToby Isaac 
153120cf1dd8SToby Isaac   Note:
153220cf1dd8SToby Isaac $ Loop over batch of elements (e):
153320cf1dd8SToby Isaac $   Loop over element matrix entries (f,fc,g,gc --> i,j):
153420cf1dd8SToby Isaac $     Loop over quadrature points (q):
153520cf1dd8SToby Isaac $       Make u_q and gradU_q (loops over fields,Nb,Ncomp)
153620cf1dd8SToby Isaac $         elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q)
153720cf1dd8SToby Isaac $                      + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q)
153820cf1dd8SToby Isaac $                      + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q)
153920cf1dd8SToby Isaac $                      + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q)
15402b99622eSMatthew G. Knepley   Level: intermediate
154120cf1dd8SToby Isaac 
154220cf1dd8SToby Isaac .seealso: PetscFEIntegrateResidual()
154320cf1dd8SToby Isaac @*/
15444bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateJacobian(PetscDS prob, PetscFEJacobianType jtype, PetscInt fieldI, PetscInt fieldJ, PetscInt Ne, PetscFEGeom *cgeom,
154520cf1dd8SToby Isaac                                         const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[])
154620cf1dd8SToby Isaac {
15474bee2e38SMatthew G. Knepley   PetscFE        fe;
154820cf1dd8SToby Isaac   PetscErrorCode ierr;
154920cf1dd8SToby Isaac 
155020cf1dd8SToby Isaac   PetscFunctionBegin;
15514bee2e38SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
15524bee2e38SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, fieldI, (PetscObject *) &fe);CHKERRQ(ierr);
15534bee2e38SMatthew 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);}
155420cf1dd8SToby Isaac   PetscFunctionReturn(0);
155520cf1dd8SToby Isaac }
155620cf1dd8SToby Isaac 
155720cf1dd8SToby Isaac /*@C
155820cf1dd8SToby Isaac   PetscFEIntegrateBdJacobian - Produce the boundary element Jacobian for a chunk of elements by quadrature integration
155920cf1dd8SToby Isaac 
156020cf1dd8SToby Isaac   Not collective
156120cf1dd8SToby Isaac 
156220cf1dd8SToby Isaac   Input Parameters:
1563f0fc11ceSJed Brown + prob         - The PetscDS specifying the discretizations and continuum functions
156420cf1dd8SToby Isaac . fieldI       - The test field being integrated
156520cf1dd8SToby Isaac . fieldJ       - The basis field being integrated
156620cf1dd8SToby Isaac . Ne           - The number of elements in the chunk
156720cf1dd8SToby Isaac . fgeom        - The face geometry for each cell in the chunk
156820cf1dd8SToby Isaac . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point
156920cf1dd8SToby Isaac . coefficients_t - The array of FEM basis time derivative coefficients for the elements
157020cf1dd8SToby Isaac . probAux      - The PetscDS specifying the auxiliary discretizations
157120cf1dd8SToby Isaac . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements
157220cf1dd8SToby Isaac . t            - The time
157320cf1dd8SToby Isaac - u_tShift     - A multiplier for the dF/du_t term (as opposed to the dF/du term)
157420cf1dd8SToby Isaac 
15757a7aea1fSJed Brown   Output Parameter:
157620cf1dd8SToby Isaac . elemMat              - the element matrices for the Jacobian from each element
157720cf1dd8SToby Isaac 
157820cf1dd8SToby Isaac   Note:
157920cf1dd8SToby Isaac $ Loop over batch of elements (e):
158020cf1dd8SToby Isaac $   Loop over element matrix entries (f,fc,g,gc --> i,j):
158120cf1dd8SToby Isaac $     Loop over quadrature points (q):
158220cf1dd8SToby Isaac $       Make u_q and gradU_q (loops over fields,Nb,Ncomp)
158320cf1dd8SToby Isaac $         elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q)
158420cf1dd8SToby Isaac $                      + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q)
158520cf1dd8SToby Isaac $                      + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q)
158620cf1dd8SToby Isaac $                      + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q)
15872b99622eSMatthew G. Knepley   Level: intermediate
158820cf1dd8SToby Isaac 
158920cf1dd8SToby Isaac .seealso: PetscFEIntegrateJacobian(), PetscFEIntegrateResidual()
159020cf1dd8SToby Isaac @*/
15914bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdJacobian(PetscDS prob, PetscInt fieldI, PetscInt fieldJ, PetscInt Ne, PetscFEGeom *fgeom,
159220cf1dd8SToby Isaac                                           const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[])
159320cf1dd8SToby Isaac {
15944bee2e38SMatthew G. Knepley   PetscFE        fe;
159520cf1dd8SToby Isaac   PetscErrorCode ierr;
159620cf1dd8SToby Isaac 
159720cf1dd8SToby Isaac   PetscFunctionBegin;
15984bee2e38SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
15994bee2e38SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, fieldI, (PetscObject *) &fe);CHKERRQ(ierr);
16004bee2e38SMatthew 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);}
160120cf1dd8SToby Isaac   PetscFunctionReturn(0);
160220cf1dd8SToby Isaac }
160320cf1dd8SToby Isaac 
1604*27f02ce8SMatthew G. Knepley /*@C
1605*27f02ce8SMatthew G. Knepley   PetscFEIntegrateHybridJacobian - Produce the boundary element Jacobian for a chunk of hybrid elements by quadrature integration
1606*27f02ce8SMatthew G. Knepley 
1607*27f02ce8SMatthew G. Knepley   Not collective
1608*27f02ce8SMatthew G. Knepley 
1609*27f02ce8SMatthew G. Knepley   Input Parameters:
1610*27f02ce8SMatthew G. Knepley . prob         - The PetscDS specifying the discretizations and continuum functions
1611*27f02ce8SMatthew G. Knepley . jtype        - The type of matrix pointwise functions that should be used
1612*27f02ce8SMatthew G. Knepley . fieldI       - The test field being integrated
1613*27f02ce8SMatthew G. Knepley . fieldJ       - The basis field being integrated
1614*27f02ce8SMatthew G. Knepley . Ne           - The number of elements in the chunk
1615*27f02ce8SMatthew G. Knepley . fgeom        - The face geometry for each cell in the chunk
1616*27f02ce8SMatthew G. Knepley . coefficients - The array of FEM basis coefficients for the elements for the Jacobian evaluation point
1617*27f02ce8SMatthew G. Knepley . coefficients_t - The array of FEM basis time derivative coefficients for the elements
1618*27f02ce8SMatthew G. Knepley . probAux      - The PetscDS specifying the auxiliary discretizations
1619*27f02ce8SMatthew G. Knepley . coefficientsAux - The array of FEM auxiliary basis coefficients for the elements
1620*27f02ce8SMatthew G. Knepley . t            - The time
1621*27f02ce8SMatthew G. Knepley - u_tShift     - A multiplier for the dF/du_t term (as opposed to the dF/du term)
1622*27f02ce8SMatthew G. Knepley 
1623*27f02ce8SMatthew G. Knepley   Output Parameter
1624*27f02ce8SMatthew G. Knepley . elemMat              - the element matrices for the Jacobian from each element
1625*27f02ce8SMatthew G. Knepley 
1626*27f02ce8SMatthew G. Knepley   Note:
1627*27f02ce8SMatthew G. Knepley $ Loop over batch of elements (e):
1628*27f02ce8SMatthew G. Knepley $   Loop over element matrix entries (f,fc,g,gc --> i,j):
1629*27f02ce8SMatthew G. Knepley $     Loop over quadrature points (q):
1630*27f02ce8SMatthew G. Knepley $       Make u_q and gradU_q (loops over fields,Nb,Ncomp)
1631*27f02ce8SMatthew G. Knepley $         elemMat[i,j] += \psi^{fc}_f(q) g0_{fc,gc}(u, \nabla u) \phi^{gc}_g(q)
1632*27f02ce8SMatthew G. Knepley $                      + \psi^{fc}_f(q) \cdot g1_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q)
1633*27f02ce8SMatthew G. Knepley $                      + \nabla\psi^{fc}_f(q) \cdot g2_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q)
1634*27f02ce8SMatthew G. Knepley $                      + \nabla\psi^{fc}_f(q) \cdot g3_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q)
1635*27f02ce8SMatthew G. Knepley   Level: developer
1636*27f02ce8SMatthew G. Knepley 
1637*27f02ce8SMatthew G. Knepley .seealso: PetscFEIntegrateJacobian(), PetscFEIntegrateResidual()
1638*27f02ce8SMatthew G. Knepley @*/
1639*27f02ce8SMatthew G. Knepley PetscErrorCode PetscFEIntegrateHybridJacobian(PetscDS prob, PetscFEJacobianType jtype, PetscInt fieldI, PetscInt fieldJ, PetscInt Ne, PetscFEGeom *fgeom,
1640*27f02ce8SMatthew G. Knepley                                               const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS probAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[])
1641*27f02ce8SMatthew G. Knepley {
1642*27f02ce8SMatthew G. Knepley   PetscFE        fe;
1643*27f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
1644*27f02ce8SMatthew G. Knepley 
1645*27f02ce8SMatthew G. Knepley   PetscFunctionBegin;
1646*27f02ce8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1647*27f02ce8SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, fieldI, (PetscObject *) &fe);CHKERRQ(ierr);
1648*27f02ce8SMatthew G. Knepley   if (fe->ops->integratehybridjacobian) {ierr = (*fe->ops->integratehybridjacobian)(prob, jtype, fieldI, fieldJ, Ne, fgeom, coefficients, coefficients_t, probAux, coefficientsAux, t, u_tshift, elemMat);CHKERRQ(ierr);}
1649*27f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
1650*27f02ce8SMatthew G. Knepley }
1651*27f02ce8SMatthew G. Knepley 
16522b99622eSMatthew G. Knepley /*@
16532b99622eSMatthew G. Knepley   PetscFEGetHeightSubspace - Get the subspace of this space for a mesh point of a given height
16542b99622eSMatthew G. Knepley 
16552b99622eSMatthew G. Knepley   Input Parameters:
16562b99622eSMatthew G. Knepley + fe     - The finite element space
16572b99622eSMatthew G. Knepley - height - The height of the Plex point
16582b99622eSMatthew G. Knepley 
16592b99622eSMatthew G. Knepley   Output Parameter:
16602b99622eSMatthew G. Knepley . subfe  - The subspace of this FE space
16612b99622eSMatthew G. Knepley 
16622b99622eSMatthew G. Knepley   Note: For example, if we want the subspace of this space for a face, we would choose height = 1.
16632b99622eSMatthew G. Knepley 
16642b99622eSMatthew G. Knepley   Level: advanced
16652b99622eSMatthew G. Knepley 
16662b99622eSMatthew G. Knepley .seealso: PetscFECreateDefault()
16672b99622eSMatthew G. Knepley @*/
166820cf1dd8SToby Isaac PetscErrorCode PetscFEGetHeightSubspace(PetscFE fe, PetscInt height, PetscFE *subfe)
166920cf1dd8SToby Isaac {
167020cf1dd8SToby Isaac   PetscSpace      P, subP;
167120cf1dd8SToby Isaac   PetscDualSpace  Q, subQ;
167220cf1dd8SToby Isaac   PetscQuadrature subq;
167320cf1dd8SToby Isaac   PetscFEType     fetype;
167420cf1dd8SToby Isaac   PetscInt        dim, Nc;
167520cf1dd8SToby Isaac   PetscErrorCode  ierr;
167620cf1dd8SToby Isaac 
167720cf1dd8SToby Isaac   PetscFunctionBegin;
167820cf1dd8SToby Isaac   PetscValidHeaderSpecific(fe, PETSCFE_CLASSID, 1);
167920cf1dd8SToby Isaac   PetscValidPointer(subfe, 3);
168020cf1dd8SToby Isaac   if (height == 0) {
168120cf1dd8SToby Isaac     *subfe = fe;
168220cf1dd8SToby Isaac     PetscFunctionReturn(0);
168320cf1dd8SToby Isaac   }
168420cf1dd8SToby Isaac   ierr = PetscFEGetBasisSpace(fe, &P);CHKERRQ(ierr);
168520cf1dd8SToby Isaac   ierr = PetscFEGetDualSpace(fe, &Q);CHKERRQ(ierr);
168620cf1dd8SToby Isaac   ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
168720cf1dd8SToby Isaac   ierr = PetscFEGetFaceQuadrature(fe, &subq);CHKERRQ(ierr);
168820cf1dd8SToby Isaac   ierr = PetscDualSpaceGetDimension(Q, &dim);CHKERRQ(ierr);
168920cf1dd8SToby 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);}
169020cf1dd8SToby Isaac   if (!fe->subspaces) {ierr = PetscCalloc1(dim, &fe->subspaces);CHKERRQ(ierr);}
169120cf1dd8SToby Isaac   if (height <= dim) {
169220cf1dd8SToby Isaac     if (!fe->subspaces[height-1]) {
169320cf1dd8SToby Isaac       PetscFE     sub;
16943f6b16c7SMatthew G. Knepley       const char *name;
169520cf1dd8SToby Isaac 
169620cf1dd8SToby Isaac       ierr = PetscSpaceGetHeightSubspace(P, height, &subP);CHKERRQ(ierr);
169720cf1dd8SToby Isaac       ierr = PetscDualSpaceGetHeightSubspace(Q, height, &subQ);CHKERRQ(ierr);
169820cf1dd8SToby Isaac       ierr = PetscFECreate(PetscObjectComm((PetscObject) fe), &sub);CHKERRQ(ierr);
16993f6b16c7SMatthew G. Knepley       ierr = PetscObjectGetName((PetscObject) fe,  &name);CHKERRQ(ierr);
17003f6b16c7SMatthew G. Knepley       ierr = PetscObjectSetName((PetscObject) sub,  name);CHKERRQ(ierr);
170120cf1dd8SToby Isaac       ierr = PetscFEGetType(fe, &fetype);CHKERRQ(ierr);
170220cf1dd8SToby Isaac       ierr = PetscFESetType(sub, fetype);CHKERRQ(ierr);
170320cf1dd8SToby Isaac       ierr = PetscFESetBasisSpace(sub, subP);CHKERRQ(ierr);
170420cf1dd8SToby Isaac       ierr = PetscFESetDualSpace(sub, subQ);CHKERRQ(ierr);
170520cf1dd8SToby Isaac       ierr = PetscFESetNumComponents(sub, Nc);CHKERRQ(ierr);
170620cf1dd8SToby Isaac       ierr = PetscFESetUp(sub);CHKERRQ(ierr);
170720cf1dd8SToby Isaac       ierr = PetscFESetQuadrature(sub, subq);CHKERRQ(ierr);
170820cf1dd8SToby Isaac       fe->subspaces[height-1] = sub;
170920cf1dd8SToby Isaac     }
171020cf1dd8SToby Isaac     *subfe = fe->subspaces[height-1];
171120cf1dd8SToby Isaac   } else {
171220cf1dd8SToby Isaac     *subfe = NULL;
171320cf1dd8SToby Isaac   }
171420cf1dd8SToby Isaac   PetscFunctionReturn(0);
171520cf1dd8SToby Isaac }
171620cf1dd8SToby Isaac 
171720cf1dd8SToby Isaac /*@
171820cf1dd8SToby Isaac   PetscFERefine - Create a "refined" PetscFE object that refines the reference cell into smaller copies. This is typically used
171920cf1dd8SToby Isaac   to precondition a higher order method with a lower order method on a refined mesh having the same number of dofs (but more
172020cf1dd8SToby Isaac   sparsity). It is also used to create an interpolation between regularly refined meshes.
172120cf1dd8SToby Isaac 
1722d083f849SBarry Smith   Collective on fem
172320cf1dd8SToby Isaac 
172420cf1dd8SToby Isaac   Input Parameter:
172520cf1dd8SToby Isaac . fe - The initial PetscFE
172620cf1dd8SToby Isaac 
172720cf1dd8SToby Isaac   Output Parameter:
172820cf1dd8SToby Isaac . feRef - The refined PetscFE
172920cf1dd8SToby Isaac 
17302b99622eSMatthew G. Knepley   Level: advanced
173120cf1dd8SToby Isaac 
173220cf1dd8SToby Isaac .seealso: PetscFEType, PetscFECreate(), PetscFESetType()
173320cf1dd8SToby Isaac @*/
173420cf1dd8SToby Isaac PetscErrorCode PetscFERefine(PetscFE fe, PetscFE *feRef)
173520cf1dd8SToby Isaac {
173620cf1dd8SToby Isaac   PetscSpace       P, Pref;
173720cf1dd8SToby Isaac   PetscDualSpace   Q, Qref;
173820cf1dd8SToby Isaac   DM               K, Kref;
173920cf1dd8SToby Isaac   PetscQuadrature  q, qref;
174020cf1dd8SToby Isaac   const PetscReal *v0, *jac;
174120cf1dd8SToby Isaac   PetscInt         numComp, numSubelements;
17421ac17e89SToby Isaac   PetscInt         cStart, cEnd, c;
17431ac17e89SToby Isaac   PetscDualSpace  *cellSpaces;
174420cf1dd8SToby Isaac   PetscErrorCode   ierr;
174520cf1dd8SToby Isaac 
174620cf1dd8SToby Isaac   PetscFunctionBegin;
174720cf1dd8SToby Isaac   ierr = PetscFEGetBasisSpace(fe, &P);CHKERRQ(ierr);
174820cf1dd8SToby Isaac   ierr = PetscFEGetDualSpace(fe, &Q);CHKERRQ(ierr);
174920cf1dd8SToby Isaac   ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
175020cf1dd8SToby Isaac   ierr = PetscDualSpaceGetDM(Q, &K);CHKERRQ(ierr);
175120cf1dd8SToby Isaac   /* Create space */
175220cf1dd8SToby Isaac   ierr = PetscObjectReference((PetscObject) P);CHKERRQ(ierr);
175320cf1dd8SToby Isaac   Pref = P;
175420cf1dd8SToby Isaac   /* Create dual space */
175520cf1dd8SToby Isaac   ierr = PetscDualSpaceDuplicate(Q, &Qref);CHKERRQ(ierr);
17561ac17e89SToby Isaac   ierr = PetscDualSpaceSetType(Qref, PETSCDUALSPACEREFINED);CHKERRQ(ierr);
175720cf1dd8SToby Isaac   ierr = DMRefine(K, PetscObjectComm((PetscObject) fe), &Kref);CHKERRQ(ierr);
175820cf1dd8SToby Isaac   ierr = PetscDualSpaceSetDM(Qref, Kref);CHKERRQ(ierr);
17591ac17e89SToby Isaac   ierr = DMPlexGetHeightStratum(Kref, 0, &cStart, &cEnd);CHKERRQ(ierr);
17601ac17e89SToby Isaac   ierr = PetscMalloc1(cEnd - cStart, &cellSpaces);CHKERRQ(ierr);
17611ac17e89SToby Isaac   /* TODO: fix for non-uniform refinement */
17621ac17e89SToby Isaac   for (c = 0; c < cEnd - cStart; c++) cellSpaces[c] = Q;
17631ac17e89SToby Isaac   ierr = PetscDualSpaceRefinedSetCellSpaces(Qref, cellSpaces);CHKERRQ(ierr);
17641ac17e89SToby Isaac   ierr = PetscFree(cellSpaces);CHKERRQ(ierr);
176520cf1dd8SToby Isaac   ierr = DMDestroy(&Kref);CHKERRQ(ierr);
176620cf1dd8SToby Isaac   ierr = PetscDualSpaceSetUp(Qref);CHKERRQ(ierr);
176720cf1dd8SToby Isaac   /* Create element */
176820cf1dd8SToby Isaac   ierr = PetscFECreate(PetscObjectComm((PetscObject) fe), feRef);CHKERRQ(ierr);
176920cf1dd8SToby Isaac   ierr = PetscFESetType(*feRef, PETSCFECOMPOSITE);CHKERRQ(ierr);
177020cf1dd8SToby Isaac   ierr = PetscFESetBasisSpace(*feRef, Pref);CHKERRQ(ierr);
177120cf1dd8SToby Isaac   ierr = PetscFESetDualSpace(*feRef, Qref);CHKERRQ(ierr);
177220cf1dd8SToby Isaac   ierr = PetscFEGetNumComponents(fe,    &numComp);CHKERRQ(ierr);
177320cf1dd8SToby Isaac   ierr = PetscFESetNumComponents(*feRef, numComp);CHKERRQ(ierr);
177420cf1dd8SToby Isaac   ierr = PetscFESetUp(*feRef);CHKERRQ(ierr);
177520cf1dd8SToby Isaac   ierr = PetscSpaceDestroy(&Pref);CHKERRQ(ierr);
177620cf1dd8SToby Isaac   ierr = PetscDualSpaceDestroy(&Qref);CHKERRQ(ierr);
177720cf1dd8SToby Isaac   /* Create quadrature */
177820cf1dd8SToby Isaac   ierr = PetscFECompositeGetMapping(*feRef, &numSubelements, &v0, &jac, NULL);CHKERRQ(ierr);
177920cf1dd8SToby Isaac   ierr = PetscQuadratureExpandComposite(q, numSubelements, v0, jac, &qref);CHKERRQ(ierr);
178020cf1dd8SToby Isaac   ierr = PetscFESetQuadrature(*feRef, qref);CHKERRQ(ierr);
178120cf1dd8SToby Isaac   ierr = PetscQuadratureDestroy(&qref);CHKERRQ(ierr);
178220cf1dd8SToby Isaac   PetscFunctionReturn(0);
178320cf1dd8SToby Isaac }
178420cf1dd8SToby Isaac 
178520cf1dd8SToby Isaac /*@C
178620cf1dd8SToby Isaac   PetscFECreateDefault - Create a PetscFE for basic FEM computation
178720cf1dd8SToby Isaac 
1788d083f849SBarry Smith   Collective
178920cf1dd8SToby Isaac 
179020cf1dd8SToby Isaac   Input Parameters:
17917be5e748SToby Isaac + comm      - The MPI comm
179220cf1dd8SToby Isaac . dim       - The spatial dimension
179320cf1dd8SToby Isaac . Nc        - The number of components
179420cf1dd8SToby Isaac . isSimplex - Flag for simplex reference cell, otherwise its a tensor product
179520cf1dd8SToby Isaac . prefix    - The options prefix, or NULL
1796727cddd5SJacob Faibussowitsch - qorder    - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree
179720cf1dd8SToby Isaac 
179820cf1dd8SToby Isaac   Output Parameter:
179920cf1dd8SToby Isaac . fem - The PetscFE object
180020cf1dd8SToby Isaac 
1801e703855dSMatthew G. Knepley   Note:
1802e703855dSMatthew G. Knepley   Each object is SetFromOption() during creation, so that the object may be customized from the command line.
1803e703855dSMatthew G. Knepley 
180420cf1dd8SToby Isaac   Level: beginner
180520cf1dd8SToby Isaac 
180620cf1dd8SToby Isaac .seealso: PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate()
180720cf1dd8SToby Isaac @*/
18087be5e748SToby Isaac PetscErrorCode PetscFECreateDefault(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, const char prefix[], PetscInt qorder, PetscFE *fem)
180920cf1dd8SToby Isaac {
181020cf1dd8SToby Isaac   PetscQuadrature q, fq;
181120cf1dd8SToby Isaac   DM              K;
181220cf1dd8SToby Isaac   PetscSpace      P;
181320cf1dd8SToby Isaac   PetscDualSpace  Q;
181420cf1dd8SToby Isaac   PetscInt        order, quadPointsPerEdge;
181520cf1dd8SToby Isaac   PetscBool       tensor = isSimplex ? PETSC_FALSE : PETSC_TRUE;
181620cf1dd8SToby Isaac   PetscErrorCode  ierr;
181720cf1dd8SToby Isaac 
181820cf1dd8SToby Isaac   PetscFunctionBegin;
181920cf1dd8SToby Isaac   /* Create space */
18207be5e748SToby Isaac   ierr = PetscSpaceCreate(comm, &P);CHKERRQ(ierr);
182120cf1dd8SToby Isaac   ierr = PetscObjectSetOptionsPrefix((PetscObject) P, prefix);CHKERRQ(ierr);
182220cf1dd8SToby Isaac   ierr = PetscSpacePolynomialSetTensor(P, tensor);CHKERRQ(ierr);
182320cf1dd8SToby Isaac   ierr = PetscSpaceSetNumComponents(P, Nc);CHKERRQ(ierr);
182420cf1dd8SToby Isaac   ierr = PetscSpaceSetNumVariables(P, dim);CHKERRQ(ierr);
1825028afddaSToby Isaac   ierr = PetscSpaceSetFromOptions(P);CHKERRQ(ierr);
182620cf1dd8SToby Isaac   ierr = PetscSpaceSetUp(P);CHKERRQ(ierr);
182720cf1dd8SToby Isaac   ierr = PetscSpaceGetDegree(P, &order, NULL);CHKERRQ(ierr);
182820cf1dd8SToby Isaac   ierr = PetscSpacePolynomialGetTensor(P, &tensor);CHKERRQ(ierr);
182920cf1dd8SToby Isaac   /* Create dual space */
18307be5e748SToby Isaac   ierr = PetscDualSpaceCreate(comm, &Q);CHKERRQ(ierr);
183120cf1dd8SToby Isaac   ierr = PetscDualSpaceSetType(Q,PETSCDUALSPACELAGRANGE);CHKERRQ(ierr);
183220cf1dd8SToby Isaac   ierr = PetscObjectSetOptionsPrefix((PetscObject) Q, prefix);CHKERRQ(ierr);
183320cf1dd8SToby Isaac   ierr = PetscDualSpaceCreateReferenceCell(Q, dim, isSimplex, &K);CHKERRQ(ierr);
183420cf1dd8SToby Isaac   ierr = PetscDualSpaceSetDM(Q, K);CHKERRQ(ierr);
183520cf1dd8SToby Isaac   ierr = DMDestroy(&K);CHKERRQ(ierr);
183620cf1dd8SToby Isaac   ierr = PetscDualSpaceSetNumComponents(Q, Nc);CHKERRQ(ierr);
183720cf1dd8SToby Isaac   ierr = PetscDualSpaceSetOrder(Q, order);CHKERRQ(ierr);
183820cf1dd8SToby Isaac   ierr = PetscDualSpaceLagrangeSetTensor(Q, tensor);CHKERRQ(ierr);
183920cf1dd8SToby Isaac   ierr = PetscDualSpaceSetFromOptions(Q);CHKERRQ(ierr);
184020cf1dd8SToby Isaac   ierr = PetscDualSpaceSetUp(Q);CHKERRQ(ierr);
184120cf1dd8SToby Isaac   /* Create element */
18427be5e748SToby Isaac   ierr = PetscFECreate(comm, fem);CHKERRQ(ierr);
184320cf1dd8SToby Isaac   ierr = PetscObjectSetOptionsPrefix((PetscObject) *fem, prefix);CHKERRQ(ierr);
184420cf1dd8SToby Isaac   ierr = PetscFESetBasisSpace(*fem, P);CHKERRQ(ierr);
184520cf1dd8SToby Isaac   ierr = PetscFESetDualSpace(*fem, Q);CHKERRQ(ierr);
184620cf1dd8SToby Isaac   ierr = PetscFESetNumComponents(*fem, Nc);CHKERRQ(ierr);
184791e89cf0SMatthew G. Knepley   ierr = PetscFESetFromOptions(*fem);CHKERRQ(ierr);
184820cf1dd8SToby Isaac   ierr = PetscFESetUp(*fem);CHKERRQ(ierr);
184920cf1dd8SToby Isaac   ierr = PetscSpaceDestroy(&P);CHKERRQ(ierr);
185020cf1dd8SToby Isaac   ierr = PetscDualSpaceDestroy(&Q);CHKERRQ(ierr);
185120cf1dd8SToby Isaac   /* Create quadrature (with specified order if given) */
185220cf1dd8SToby Isaac   qorder = qorder >= 0 ? qorder : order;
185320cf1dd8SToby Isaac   ierr = PetscObjectOptionsBegin((PetscObject)*fem);CHKERRQ(ierr);
18545a856986SBarry Smith   ierr = PetscOptionsBoundedInt("-petscfe_default_quadrature_order","Quadrature order is one less than quadrature points per edge","PetscFECreateDefault",qorder,&qorder,NULL,0);CHKERRQ(ierr);
185520cf1dd8SToby Isaac   ierr = PetscOptionsEnd();CHKERRQ(ierr);
185620cf1dd8SToby Isaac   quadPointsPerEdge = PetscMax(qorder + 1,1);
185720cf1dd8SToby Isaac   if (isSimplex) {
1858e6a796c3SToby Isaac     ierr = PetscDTStroudConicalQuadrature(dim,   1, quadPointsPerEdge, -1.0, 1.0, &q);CHKERRQ(ierr);
1859e6a796c3SToby Isaac     ierr = PetscDTStroudConicalQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, &fq);CHKERRQ(ierr);
18604ccfa306SStefano Zampini   } else {
186120cf1dd8SToby Isaac     ierr = PetscDTGaussTensorQuadrature(dim,   1, quadPointsPerEdge, -1.0, 1.0, &q);CHKERRQ(ierr);
186220cf1dd8SToby Isaac     ierr = PetscDTGaussTensorQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, &fq);CHKERRQ(ierr);
186320cf1dd8SToby Isaac   }
186420cf1dd8SToby Isaac   ierr = PetscFESetQuadrature(*fem, q);CHKERRQ(ierr);
186520cf1dd8SToby Isaac   ierr = PetscFESetFaceQuadrature(*fem, fq);CHKERRQ(ierr);
186620cf1dd8SToby Isaac   ierr = PetscQuadratureDestroy(&q);CHKERRQ(ierr);
186720cf1dd8SToby Isaac   ierr = PetscQuadratureDestroy(&fq);CHKERRQ(ierr);
186820cf1dd8SToby Isaac   PetscFunctionReturn(0);
186920cf1dd8SToby Isaac }
18703f6b16c7SMatthew G. Knepley 
1871e703855dSMatthew G. Knepley /*@
1872e703855dSMatthew G. Knepley   PetscFECreateLagrange - Create a PetscFE for the basic Lagrange space of degree k
1873e703855dSMatthew G. Knepley 
1874e703855dSMatthew G. Knepley   Collective
1875e703855dSMatthew G. Knepley 
1876e703855dSMatthew G. Knepley   Input Parameters:
1877e703855dSMatthew G. Knepley + comm      - The MPI comm
1878e703855dSMatthew G. Knepley . dim       - The spatial dimension
1879e703855dSMatthew G. Knepley . Nc        - The number of components
1880e703855dSMatthew G. Knepley . isSimplex - Flag for simplex reference cell, otherwise its a tensor product
1881e703855dSMatthew G. Knepley . k         - The degree k of the space
1882e703855dSMatthew G. Knepley - qorder    - The quadrature order or PETSC_DETERMINE to use PetscSpace polynomial degree
1883e703855dSMatthew G. Knepley 
1884e703855dSMatthew G. Knepley   Output Parameter:
1885e703855dSMatthew G. Knepley . fem       - The PetscFE object
1886e703855dSMatthew G. Knepley 
1887e703855dSMatthew G. Knepley   Level: beginner
1888e703855dSMatthew G. Knepley 
1889e703855dSMatthew G. Knepley   Notes:
1890e703855dSMatthew G. Knepley   For simplices, this element is the space of maximum polynomial degree k, otherwise it is a tensor product of 1D polynomials, each with maximal degree k.
1891e703855dSMatthew G. Knepley 
1892e703855dSMatthew G. Knepley .seealso: PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate()
1893e703855dSMatthew G. Knepley @*/
1894e703855dSMatthew G. Knepley PetscErrorCode PetscFECreateLagrange(MPI_Comm comm, PetscInt dim, PetscInt Nc, PetscBool isSimplex, PetscInt k, PetscInt qorder, PetscFE *fem)
1895e703855dSMatthew G. Knepley {
1896e703855dSMatthew G. Knepley   PetscQuadrature q, fq;
1897e703855dSMatthew G. Knepley   DM              K;
1898e703855dSMatthew G. Knepley   PetscSpace      P;
1899e703855dSMatthew G. Knepley   PetscDualSpace  Q;
1900e703855dSMatthew G. Knepley   PetscInt        quadPointsPerEdge;
1901e703855dSMatthew G. Knepley   PetscBool       tensor = isSimplex ? PETSC_FALSE : PETSC_TRUE;
1902e703855dSMatthew G. Knepley   char            name[64];
1903e703855dSMatthew G. Knepley   PetscErrorCode  ierr;
1904e703855dSMatthew G. Knepley 
1905e703855dSMatthew G. Knepley   PetscFunctionBegin;
1906e703855dSMatthew G. Knepley   /* Create space */
1907e703855dSMatthew G. Knepley   ierr = PetscSpaceCreate(comm, &P);CHKERRQ(ierr);
1908e703855dSMatthew G. Knepley   ierr = PetscSpaceSetType(P, PETSCSPACEPOLYNOMIAL);CHKERRQ(ierr);
1909e703855dSMatthew G. Knepley   ierr = PetscSpacePolynomialSetTensor(P, tensor);CHKERRQ(ierr);
1910e703855dSMatthew G. Knepley   ierr = PetscSpaceSetNumComponents(P, Nc);CHKERRQ(ierr);
1911e703855dSMatthew G. Knepley   ierr = PetscSpaceSetNumVariables(P, dim);CHKERRQ(ierr);
1912e703855dSMatthew G. Knepley   ierr = PetscSpaceSetDegree(P, k, PETSC_DETERMINE);CHKERRQ(ierr);
1913e703855dSMatthew G. Knepley   ierr = PetscSpaceSetUp(P);CHKERRQ(ierr);
1914e703855dSMatthew G. Knepley   /* Create dual space */
1915e703855dSMatthew G. Knepley   ierr = PetscDualSpaceCreate(comm, &Q);CHKERRQ(ierr);
1916e703855dSMatthew G. Knepley   ierr = PetscDualSpaceSetType(Q, PETSCDUALSPACELAGRANGE);CHKERRQ(ierr);
1917e703855dSMatthew G. Knepley   ierr = PetscDualSpaceCreateReferenceCell(Q, dim, isSimplex, &K);CHKERRQ(ierr);
1918e703855dSMatthew G. Knepley   ierr = PetscDualSpaceSetDM(Q, K);CHKERRQ(ierr);
1919e703855dSMatthew G. Knepley   ierr = DMDestroy(&K);CHKERRQ(ierr);
1920e703855dSMatthew G. Knepley   ierr = PetscDualSpaceSetNumComponents(Q, Nc);CHKERRQ(ierr);
1921e703855dSMatthew G. Knepley   ierr = PetscDualSpaceSetOrder(Q, k);CHKERRQ(ierr);
1922e703855dSMatthew G. Knepley   ierr = PetscDualSpaceLagrangeSetTensor(Q, tensor);CHKERRQ(ierr);
1923e703855dSMatthew G. Knepley   ierr = PetscDualSpaceSetUp(Q);CHKERRQ(ierr);
1924e703855dSMatthew G. Knepley   /* Create element */
1925e703855dSMatthew G. Knepley   ierr = PetscFECreate(comm, fem);CHKERRQ(ierr);
1926e703855dSMatthew G. Knepley   ierr = PetscSNPrintf(name, 64, "P%d", (int) k);CHKERRQ(ierr);
1927e703855dSMatthew G. Knepley   ierr = PetscObjectSetName((PetscObject) *fem, name);CHKERRQ(ierr);
1928e703855dSMatthew G. Knepley   ierr = PetscFESetType(*fem, PETSCFEBASIC);CHKERRQ(ierr);
1929e703855dSMatthew G. Knepley   ierr = PetscFESetBasisSpace(*fem, P);CHKERRQ(ierr);
1930e703855dSMatthew G. Knepley   ierr = PetscFESetDualSpace(*fem, Q);CHKERRQ(ierr);
1931e703855dSMatthew G. Knepley   ierr = PetscFESetNumComponents(*fem, Nc);CHKERRQ(ierr);
1932e703855dSMatthew G. Knepley   ierr = PetscFESetUp(*fem);CHKERRQ(ierr);
1933e703855dSMatthew G. Knepley   ierr = PetscSpaceDestroy(&P);CHKERRQ(ierr);
1934e703855dSMatthew G. Knepley   ierr = PetscDualSpaceDestroy(&Q);CHKERRQ(ierr);
1935e703855dSMatthew G. Knepley   /* Create quadrature (with specified order if given) */
1936e703855dSMatthew G. Knepley   qorder = qorder >= 0 ? qorder : k;
1937e703855dSMatthew G. Knepley   quadPointsPerEdge = PetscMax(qorder + 1,1);
1938e703855dSMatthew G. Knepley   if (isSimplex) {
1939e6a796c3SToby Isaac     ierr = PetscDTStroudConicalQuadrature(dim,   1, quadPointsPerEdge, -1.0, 1.0, &q);CHKERRQ(ierr);
1940e6a796c3SToby Isaac     ierr = PetscDTStroudConicalQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, &fq);CHKERRQ(ierr);
1941e703855dSMatthew G. Knepley   } else {
1942e703855dSMatthew G. Knepley     ierr = PetscDTGaussTensorQuadrature(dim,   1, quadPointsPerEdge, -1.0, 1.0, &q);CHKERRQ(ierr);
1943e703855dSMatthew G. Knepley     ierr = PetscDTGaussTensorQuadrature(dim-1, 1, quadPointsPerEdge, -1.0, 1.0, &fq);CHKERRQ(ierr);
1944e703855dSMatthew G. Knepley   }
1945e703855dSMatthew G. Knepley   ierr = PetscFESetQuadrature(*fem, q);CHKERRQ(ierr);
1946e703855dSMatthew G. Knepley   ierr = PetscFESetFaceQuadrature(*fem, fq);CHKERRQ(ierr);
1947e703855dSMatthew G. Knepley   ierr = PetscQuadratureDestroy(&q);CHKERRQ(ierr);
1948e703855dSMatthew G. Knepley   ierr = PetscQuadratureDestroy(&fq);CHKERRQ(ierr);
1949e703855dSMatthew G. Knepley   PetscFunctionReturn(0);
1950e703855dSMatthew G. Knepley }
1951e703855dSMatthew G. Knepley 
19523f6b16c7SMatthew G. Knepley /*@C
19533f6b16c7SMatthew G. Knepley   PetscFESetName - Names the FE and its subobjects
19543f6b16c7SMatthew G. Knepley 
19553f6b16c7SMatthew G. Knepley   Not collective
19563f6b16c7SMatthew G. Knepley 
19573f6b16c7SMatthew G. Knepley   Input Parameters:
19583f6b16c7SMatthew G. Knepley + fe   - The PetscFE
19593f6b16c7SMatthew G. Knepley - name - The name
19603f6b16c7SMatthew G. Knepley 
19612b99622eSMatthew G. Knepley   Level: intermediate
19623f6b16c7SMatthew G. Knepley 
19633f6b16c7SMatthew G. Knepley .seealso: PetscFECreate(), PetscSpaceCreate(), PetscDualSpaceCreate()
19643f6b16c7SMatthew G. Knepley @*/
19653f6b16c7SMatthew G. Knepley PetscErrorCode PetscFESetName(PetscFE fe, const char name[])
19663f6b16c7SMatthew G. Knepley {
19673f6b16c7SMatthew G. Knepley   PetscSpace     P;
19683f6b16c7SMatthew G. Knepley   PetscDualSpace Q;
19693f6b16c7SMatthew G. Knepley   PetscErrorCode ierr;
19703f6b16c7SMatthew G. Knepley 
19713f6b16c7SMatthew G. Knepley   PetscFunctionBegin;
19723f6b16c7SMatthew G. Knepley   ierr = PetscFEGetBasisSpace(fe, &P);CHKERRQ(ierr);
19733f6b16c7SMatthew G. Knepley   ierr = PetscFEGetDualSpace(fe, &Q);CHKERRQ(ierr);
19743f6b16c7SMatthew G. Knepley   ierr = PetscObjectSetName((PetscObject) fe, name);CHKERRQ(ierr);
19753f6b16c7SMatthew G. Knepley   ierr = PetscObjectSetName((PetscObject) P,  name);CHKERRQ(ierr);
19763f6b16c7SMatthew G. Knepley   ierr = PetscObjectSetName((PetscObject) Q,  name);CHKERRQ(ierr);
19773f6b16c7SMatthew G. Knepley   PetscFunctionReturn(0);
19783f6b16c7SMatthew G. Knepley }
1979a8f1f9e5SMatthew G. Knepley 
1980ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEEvaluateFieldJets_Internal(PetscDS ds, PetscInt Nf, PetscInt r, PetscInt q, PetscTabulation T[], PetscFEGeom *fegeom, const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscScalar u[], PetscScalar u_x[], PetscScalar u_t[])
1981a8f1f9e5SMatthew G. Knepley {
1982a8f1f9e5SMatthew G. Knepley   PetscInt       dOffset = 0, fOffset = 0, f;
1983a8f1f9e5SMatthew G. Knepley   PetscErrorCode ierr;
1984a8f1f9e5SMatthew G. Knepley 
1985a8f1f9e5SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
1986a8f1f9e5SMatthew G. Knepley     PetscFE          fe;
1987ef0bb6c7SMatthew G. Knepley     const PetscInt   cdim = T[f]->cdim;
1988ef0bb6c7SMatthew G. Knepley     const PetscInt   Nq   = T[f]->Np;
1989ef0bb6c7SMatthew G. Knepley     const PetscInt   Nbf  = T[f]->Nb;
1990ef0bb6c7SMatthew G. Knepley     const PetscInt   Ncf  = T[f]->Nc;
1991ef0bb6c7SMatthew G. Knepley     const PetscReal *Bq   = &T[f]->T[0][(r*Nq+q)*Nbf*Ncf];
1992ef0bb6c7SMatthew G. Knepley     const PetscReal *Dq   = &T[f]->T[1][(r*Nq+q)*Nbf*Ncf*cdim];
1993a8f1f9e5SMatthew G. Knepley     PetscInt         b, c, d;
1994a8f1f9e5SMatthew G. Knepley 
1995a8f1f9e5SMatthew G. Knepley     ierr = PetscDSGetDiscretization(ds, f, (PetscObject *) &fe);CHKERRQ(ierr);
1996a8f1f9e5SMatthew G. Knepley     for (c = 0; c < Ncf; ++c) u[fOffset+c] = 0.0;
1997ef0bb6c7SMatthew G. Knepley     for (d = 0; d < cdim*Ncf; ++d) u_x[fOffset*cdim+d] = 0.0;
1998a8f1f9e5SMatthew G. Knepley     for (b = 0; b < Nbf; ++b) {
1999a8f1f9e5SMatthew G. Knepley       for (c = 0; c < Ncf; ++c) {
2000a8f1f9e5SMatthew G. Knepley         const PetscInt cidx = b*Ncf+c;
2001a8f1f9e5SMatthew G. Knepley 
2002a8f1f9e5SMatthew G. Knepley         u[fOffset+c] += Bq[cidx]*coefficients[dOffset+b];
2003ef0bb6c7SMatthew G. Knepley         for (d = 0; d < cdim; ++d) u_x[(fOffset+c)*cdim+d] += Dq[cidx*cdim+d]*coefficients[dOffset+b];
2004a8f1f9e5SMatthew G. Knepley       }
2005a8f1f9e5SMatthew G. Knepley     }
20062edcad52SToby Isaac     ierr = PetscFEPushforward(fe, fegeom, 1, &u[fOffset]);CHKERRQ(ierr);
20072edcad52SToby Isaac     ierr = PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset*cdim]);CHKERRQ(ierr);
2008a8f1f9e5SMatthew G. Knepley     if (u_t) {
2009a8f1f9e5SMatthew G. Knepley       for (c = 0; c < Ncf; ++c) u_t[fOffset+c] = 0.0;
2010a8f1f9e5SMatthew G. Knepley       for (b = 0; b < Nbf; ++b) {
2011a8f1f9e5SMatthew G. Knepley         for (c = 0; c < Ncf; ++c) {
2012a8f1f9e5SMatthew G. Knepley           const PetscInt cidx = b*Ncf+c;
2013a8f1f9e5SMatthew G. Knepley 
2014a8f1f9e5SMatthew G. Knepley           u_t[fOffset+c] += Bq[cidx]*coefficients_t[dOffset+b];
2015a8f1f9e5SMatthew G. Knepley         }
2016a8f1f9e5SMatthew G. Knepley       }
20172edcad52SToby Isaac       ierr = PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset]);CHKERRQ(ierr);
2018a8f1f9e5SMatthew G. Knepley     }
2019a8f1f9e5SMatthew G. Knepley     fOffset += Ncf;
2020a8f1f9e5SMatthew G. Knepley     dOffset += Nbf;
2021a8f1f9e5SMatthew G. Knepley   }
2022a8f1f9e5SMatthew G. Knepley   return 0;
2023a8f1f9e5SMatthew G. Knepley }
2024a8f1f9e5SMatthew G. Knepley 
2025*27f02ce8SMatthew G. Knepley PetscErrorCode PetscFEEvaluateFieldJets_Hybrid_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[])
2026*27f02ce8SMatthew G. Knepley {
2027*27f02ce8SMatthew G. Knepley   const PetscInt dE = fegeom->dimEmbed;
2028*27f02ce8SMatthew G. Knepley   PetscInt       dOffset = 0, fOffset = 0, g;
2029*27f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
2030*27f02ce8SMatthew G. Knepley 
2031*27f02ce8SMatthew G. Knepley   for (g = 0; g < 2*Nf-1; ++g) {
2032*27f02ce8SMatthew G. Knepley     PetscFE          fe;
2033*27f02ce8SMatthew G. Knepley     const PetscInt   f   = g/2;
2034*27f02ce8SMatthew G. Knepley     const PetscInt   Nbf = Nb[f], Ncf = Nc[f];
2035*27f02ce8SMatthew G. Knepley     const PetscReal *Bq = &basisField[f][q*Nbf*Ncf];
2036*27f02ce8SMatthew G. Knepley     const PetscReal *Dq = &basisFieldDer[f][q*Nbf*Ncf*dim];
2037*27f02ce8SMatthew G. Knepley     PetscInt         b, c, d;
2038*27f02ce8SMatthew G. Knepley 
2039*27f02ce8SMatthew G. Knepley     fe = (PetscFE) ds->disc[f];
2040*27f02ce8SMatthew G. Knepley     for (c = 0; c < Ncf; ++c)     u[fOffset+c] = 0.0;
2041*27f02ce8SMatthew G. Knepley     for (d = 0; d < dim*Ncf; ++d) u_x[fOffset*dim+d] = 0.0;
2042*27f02ce8SMatthew G. Knepley     for (b = 0; b < Nbf; ++b) {
2043*27f02ce8SMatthew G. Knepley       for (c = 0; c < Ncf; ++c) {
2044*27f02ce8SMatthew G. Knepley         const PetscInt cidx = b*Ncf+c;
2045*27f02ce8SMatthew G. Knepley 
2046*27f02ce8SMatthew G. Knepley         u[fOffset+c] += Bq[cidx]*coefficients[dOffset+b];
2047*27f02ce8SMatthew G. Knepley         for (d = 0; d < dim; ++d) u_x[(fOffset+c)*dE+d] += Dq[cidx*dim+d]*coefficients[dOffset+b];
2048*27f02ce8SMatthew G. Knepley       }
2049*27f02ce8SMatthew G. Knepley     }
2050*27f02ce8SMatthew G. Knepley     ierr = PetscFEPushforward(fe, fegeom, 1, &u[fOffset]);CHKERRQ(ierr);
2051*27f02ce8SMatthew G. Knepley     ierr = PetscFEPushforwardGradient(fe, fegeom, 1, &u_x[fOffset*dim]);CHKERRQ(ierr);
2052*27f02ce8SMatthew G. Knepley     if (u_t) {
2053*27f02ce8SMatthew G. Knepley       for (c = 0; c < Ncf; ++c) u_t[fOffset+c] = 0.0;
2054*27f02ce8SMatthew G. Knepley       for (b = 0; b < Nbf; ++b) {
2055*27f02ce8SMatthew G. Knepley         for (c = 0; c < Ncf; ++c) {
2056*27f02ce8SMatthew G. Knepley           const PetscInt cidx = b*Ncf+c;
2057*27f02ce8SMatthew G. Knepley 
2058*27f02ce8SMatthew G. Knepley           u_t[fOffset+c] += Bq[cidx]*coefficients_t[dOffset+b];
2059*27f02ce8SMatthew G. Knepley         }
2060*27f02ce8SMatthew G. Knepley       }
2061*27f02ce8SMatthew G. Knepley       ierr = PetscFEPushforward(fe, fegeom, 1, &u_t[fOffset]);CHKERRQ(ierr);
2062*27f02ce8SMatthew G. Knepley     }
2063*27f02ce8SMatthew G. Knepley     fOffset += Ncf;
2064*27f02ce8SMatthew G. Knepley     dOffset += Nbf;
2065*27f02ce8SMatthew G. Knepley   }
2066*27f02ce8SMatthew G. Knepley   return 0;
2067*27f02ce8SMatthew G. Knepley }
2068*27f02ce8SMatthew G. Knepley 
2069a8f1f9e5SMatthew G. Knepley PetscErrorCode PetscFEEvaluateFaceFields_Internal(PetscDS prob, PetscInt field, PetscInt faceLoc, const PetscScalar coefficients[], PetscScalar u[])
2070a8f1f9e5SMatthew G. Knepley {
2071a8f1f9e5SMatthew G. Knepley   PetscFE         fe;
2072ef0bb6c7SMatthew G. Knepley   PetscTabulation Tc;
2073ef0bb6c7SMatthew G. Knepley   PetscInt        b, c;
2074a8f1f9e5SMatthew G. Knepley   PetscErrorCode  ierr;
2075a8f1f9e5SMatthew G. Knepley 
2076a8f1f9e5SMatthew G. Knepley   if (!prob) return 0;
2077a8f1f9e5SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, field, (PetscObject *) &fe);CHKERRQ(ierr);
2078ef0bb6c7SMatthew G. Knepley   ierr = PetscFEGetFaceCentroidTabulation(fe, &Tc);CHKERRQ(ierr);
2079ef0bb6c7SMatthew G. Knepley   {
2080ef0bb6c7SMatthew G. Knepley     const PetscReal *faceBasis = Tc->T[0];
2081ef0bb6c7SMatthew G. Knepley     const PetscInt   Nb        = Tc->Nb;
2082ef0bb6c7SMatthew G. Knepley     const PetscInt   Nc        = Tc->Nc;
2083ef0bb6c7SMatthew G. Knepley 
2084a8f1f9e5SMatthew G. Knepley     for (c = 0; c < Nc; ++c) {u[c] = 0.0;}
2085a8f1f9e5SMatthew G. Knepley     for (b = 0; b < Nb; ++b) {
2086a8f1f9e5SMatthew G. Knepley       for (c = 0; c < Nc; ++c) {
2087a8f1f9e5SMatthew G. Knepley         const PetscInt cidx = b*Nc+c;
2088a8f1f9e5SMatthew G. Knepley 
2089a8f1f9e5SMatthew G. Knepley         u[c] += coefficients[cidx]*faceBasis[faceLoc*Nb*Nc+cidx];
2090a8f1f9e5SMatthew G. Knepley       }
2091a8f1f9e5SMatthew G. Knepley     }
2092ef0bb6c7SMatthew G. Knepley   }
2093a8f1f9e5SMatthew G. Knepley   return 0;
2094a8f1f9e5SMatthew G. Knepley }
2095a8f1f9e5SMatthew G. Knepley 
2096ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEUpdateElementVec_Internal(PetscFE fe, PetscTabulation T, PetscInt r, PetscScalar tmpBasis[], PetscScalar tmpBasisDer[], PetscFEGeom *fegeom, PetscScalar f0[], PetscScalar f1[], PetscScalar elemVec[])
2097a8f1f9e5SMatthew G. Knepley {
2098*27f02ce8SMatthew G. Knepley   const PetscInt   dE       = T->cdim; /* fegeom->dimEmbed */
2099ef0bb6c7SMatthew G. Knepley   const PetscInt   Nq       = T->Np;
2100ef0bb6c7SMatthew G. Knepley   const PetscInt   Nb       = T->Nb;
2101ef0bb6c7SMatthew G. Knepley   const PetscInt   Nc       = T->Nc;
2102ef0bb6c7SMatthew G. Knepley   const PetscReal *basis    = &T->T[0][r*Nq*Nb*Nc];
2103ef0bb6c7SMatthew G. Knepley   const PetscReal *basisDer = &T->T[1][r*Nq*Nb*Nc*dim];
2104a8f1f9e5SMatthew G. Knepley   PetscInt         q, b, c, d;
2105a8f1f9e5SMatthew G. Knepley   PetscErrorCode   ierr;
2106a8f1f9e5SMatthew G. Knepley 
2107a8f1f9e5SMatthew G. Knepley   for (b = 0; b < Nb; ++b) elemVec[b] = 0.0;
2108a8f1f9e5SMatthew G. Knepley   for (q = 0; q < Nq; ++q) {
2109a8f1f9e5SMatthew G. Knepley     for (b = 0; b < Nb; ++b) {
2110a8f1f9e5SMatthew G. Knepley       for (c = 0; c < Nc; ++c) {
2111a8f1f9e5SMatthew G. Knepley         const PetscInt bcidx = b*Nc+c;
2112a8f1f9e5SMatthew G. Knepley 
2113a8f1f9e5SMatthew G. Knepley         tmpBasis[bcidx] = basis[q*Nb*Nc+bcidx];
2114*27f02ce8SMatthew G. Knepley         for (d = 0; d < dE; ++d) tmpBasisDer[bcidx*dE+d] = basisDer[q*Nb*Nc*dE+bcidx*dE+d];
2115a8f1f9e5SMatthew G. Knepley       }
2116a8f1f9e5SMatthew G. Knepley     }
21172edcad52SToby Isaac     ierr = PetscFEPushforward(fe, fegeom, Nb, tmpBasis);CHKERRQ(ierr);
21182edcad52SToby Isaac     ierr = PetscFEPushforwardGradient(fe, fegeom, Nb, tmpBasisDer);CHKERRQ(ierr);
2119a8f1f9e5SMatthew G. Knepley     for (b = 0; b < Nb; ++b) {
2120a8f1f9e5SMatthew G. Knepley       for (c = 0; c < Nc; ++c) {
2121a8f1f9e5SMatthew G. Knepley         const PetscInt bcidx = b*Nc+c;
2122a8f1f9e5SMatthew G. Knepley         const PetscInt qcidx = q*Nc+c;
2123a8f1f9e5SMatthew G. Knepley 
2124a8f1f9e5SMatthew G. Knepley         elemVec[b] += tmpBasis[bcidx]*f0[qcidx];
2125*27f02ce8SMatthew G. Knepley         for (d = 0; d < dE; ++d) elemVec[b] += tmpBasisDer[bcidx*dE+d]*f1[qcidx*dE+d];
2126*27f02ce8SMatthew G. Knepley       }
2127*27f02ce8SMatthew G. Knepley     }
2128*27f02ce8SMatthew G. Knepley   }
2129*27f02ce8SMatthew G. Knepley   return(0);
2130*27f02ce8SMatthew G. Knepley }
2131*27f02ce8SMatthew G. Knepley 
2132*27f02ce8SMatthew G. Knepley PetscErrorCode PetscFEUpdateElementVec_Hybrid_Internal(PetscFE fe, PetscTabulation T, PetscInt r, PetscScalar tmpBasis[], PetscScalar tmpBasisDer[], PetscFEGeom *fegeom, PetscScalar f0[], PetscScalar f1[], PetscScalar elemVec[])
2133*27f02ce8SMatthew G. Knepley {
2134*27f02ce8SMatthew G. Knepley   const PetscInt   dE       = T->cdim;
2135*27f02ce8SMatthew G. Knepley   const PetscInt   Nq       = T->Np;
2136*27f02ce8SMatthew G. Knepley   const PetscInt   Nb       = T->Nb;
2137*27f02ce8SMatthew G. Knepley   const PetscInt   Nc       = T->Nc;
2138*27f02ce8SMatthew G. Knepley   const PetscReal *basis    = &T->T[0][r*Nq*Nb*Nc];
2139*27f02ce8SMatthew G. Knepley   const PetscReal *basisDer = &T->T[1][r*Nq*Nb*Nc*dE];
2140*27f02ce8SMatthew G. Knepley   PetscInt         q, b, c, d, s;
2141*27f02ce8SMatthew G. Knepley   PetscErrorCode   ierr;
2142*27f02ce8SMatthew G. Knepley 
2143*27f02ce8SMatthew G. Knepley   for (b = 0; b < Nb*2; ++b) elemVec[b] = 0.0;
2144*27f02ce8SMatthew G. Knepley   for (q = 0; q < Nq; ++q) {
2145*27f02ce8SMatthew G. Knepley     for (b = 0; b < Nb; ++b) {
2146*27f02ce8SMatthew G. Knepley       for (c = 0; c < Nc; ++c) {
2147*27f02ce8SMatthew G. Knepley         const PetscInt bcidx = b*Nc+c;
2148*27f02ce8SMatthew G. Knepley 
2149*27f02ce8SMatthew G. Knepley         tmpBasis[bcidx] = basis[q*Nb*Nc+bcidx];
2150*27f02ce8SMatthew G. Knepley         for (d = 0; d < dE; ++d) tmpBasisDer[bcidx*dE+d] = basisDer[q*Nb*Nc*dE+bcidx*dE+d];
2151*27f02ce8SMatthew G. Knepley       }
2152*27f02ce8SMatthew G. Knepley     }
2153*27f02ce8SMatthew G. Knepley     ierr = PetscFEPushforward(fe, fegeom, Nb, tmpBasis);CHKERRQ(ierr);
2154*27f02ce8SMatthew G. Knepley     ierr = PetscFEPushforwardGradient(fe, fegeom, Nb, tmpBasisDer);CHKERRQ(ierr);
2155*27f02ce8SMatthew G. Knepley     for (s = 0; s < 2; ++s) {
2156*27f02ce8SMatthew G. Knepley       for (b = 0; b < Nb; ++b) {
2157*27f02ce8SMatthew G. Knepley         for (c = 0; c < Nc; ++c) {
2158*27f02ce8SMatthew G. Knepley           const PetscInt bcidx = b*Nc+c;
2159*27f02ce8SMatthew G. Knepley           const PetscInt qcidx = (q*2+s)*Nc+c;
2160*27f02ce8SMatthew G. Knepley 
2161*27f02ce8SMatthew G. Knepley           elemVec[Nb*s+b] += tmpBasis[bcidx]*f0[qcidx];
2162*27f02ce8SMatthew G. Knepley           for (d = 0; d < dE; ++d) elemVec[Nb*s+b] += tmpBasisDer[bcidx*dE+d]*f1[qcidx*dE+d];
2163*27f02ce8SMatthew G. Knepley         }
2164a8f1f9e5SMatthew G. Knepley       }
2165a8f1f9e5SMatthew G. Knepley     }
2166a8f1f9e5SMatthew G. Knepley   }
2167a8f1f9e5SMatthew G. Knepley   return(0);
2168a8f1f9e5SMatthew G. Knepley }
2169a8f1f9e5SMatthew G. Knepley 
2170ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscFEUpdateElementMat_Internal(PetscFE feI, PetscFE feJ, PetscInt r, PetscInt q, PetscTabulation TI, PetscScalar tmpBasisI[], PetscScalar tmpBasisDerI[], PetscTabulation TJ, PetscScalar tmpBasisJ[], PetscScalar tmpBasisDerJ[], PetscFEGeom *fegeom, const PetscScalar g0[], const PetscScalar g1[], const PetscScalar g2[], const PetscScalar g3[], PetscInt eOffset, PetscInt totDim, PetscInt offsetI, PetscInt offsetJ, PetscScalar elemMat[])
2171a8f1f9e5SMatthew G. Knepley {
2172*27f02ce8SMatthew G. Knepley   const PetscInt   dE        = TI->cdim;
2173ef0bb6c7SMatthew G. Knepley   const PetscInt   NqI       = TI->Np;
2174ef0bb6c7SMatthew G. Knepley   const PetscInt   NbI       = TI->Nb;
2175ef0bb6c7SMatthew G. Knepley   const PetscInt   NcI       = TI->Nc;
2176ef0bb6c7SMatthew G. Knepley   const PetscReal *basisI    = &TI->T[0][(r*NqI+q)*NbI*NcI];
2177ef0bb6c7SMatthew G. Knepley   const PetscReal *basisDerI = &TI->T[1][(r*NqI+q)*NbI*NcI*dim];
2178ef0bb6c7SMatthew G. Knepley   const PetscInt   NqJ       = TJ->Np;
2179ef0bb6c7SMatthew G. Knepley   const PetscInt   NbJ       = TJ->Nb;
2180ef0bb6c7SMatthew G. Knepley   const PetscInt   NcJ       = TJ->Nc;
2181ef0bb6c7SMatthew G. Knepley   const PetscReal *basisJ    = &TJ->T[0][(r*NqJ+q)*NbJ*NcJ];
2182ef0bb6c7SMatthew G. Knepley   const PetscReal *basisDerJ = &TJ->T[1][(r*NqJ+q)*NbJ*NcJ*dim];
2183a8f1f9e5SMatthew G. Knepley   PetscInt         f, fc, g, gc, df, dg;
2184a8f1f9e5SMatthew G. Knepley   PetscErrorCode   ierr;
2185a8f1f9e5SMatthew G. Knepley 
2186a8f1f9e5SMatthew G. Knepley   for (f = 0; f < NbI; ++f) {
2187a8f1f9e5SMatthew G. Knepley     for (fc = 0; fc < NcI; ++fc) {
2188a8f1f9e5SMatthew G. Knepley       const PetscInt fidx = f*NcI+fc; /* Test function basis index */
2189a8f1f9e5SMatthew G. Knepley 
2190a8f1f9e5SMatthew G. Knepley       tmpBasisI[fidx] = basisI[fidx];
2191*27f02ce8SMatthew G. Knepley       for (df = 0; df < dE; ++df) tmpBasisDerI[fidx*dE+df] = basisDerI[fidx*dE+df];
2192a8f1f9e5SMatthew G. Knepley     }
2193a8f1f9e5SMatthew G. Knepley   }
21942edcad52SToby Isaac   ierr = PetscFEPushforward(feI, fegeom, NbI, tmpBasisI);CHKERRQ(ierr);
21952edcad52SToby Isaac   ierr = PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI);CHKERRQ(ierr);
2196a8f1f9e5SMatthew G. Knepley   for (g = 0; g < NbJ; ++g) {
2197a8f1f9e5SMatthew G. Knepley     for (gc = 0; gc < NcJ; ++gc) {
2198a8f1f9e5SMatthew G. Knepley       const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */
2199a8f1f9e5SMatthew G. Knepley 
2200a8f1f9e5SMatthew G. Knepley       tmpBasisJ[gidx] = basisJ[gidx];
2201*27f02ce8SMatthew G. Knepley       for (dg = 0; dg < dE; ++dg) tmpBasisDerJ[gidx*dE+dg] = basisDerJ[gidx*dE+dg];
2202a8f1f9e5SMatthew G. Knepley     }
2203a8f1f9e5SMatthew G. Knepley   }
22042edcad52SToby Isaac   ierr = PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ);CHKERRQ(ierr);
22052edcad52SToby Isaac   ierr = PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ);CHKERRQ(ierr);
2206a8f1f9e5SMatthew G. Knepley   for (f = 0; f < NbI; ++f) {
2207a8f1f9e5SMatthew G. Knepley     for (fc = 0; fc < NcI; ++fc) {
2208a8f1f9e5SMatthew G. Knepley       const PetscInt fidx = f*NcI+fc; /* Test function basis index */
2209a8f1f9e5SMatthew G. Knepley       const PetscInt i    = offsetI+f; /* Element matrix row */
2210a8f1f9e5SMatthew G. Knepley       for (g = 0; g < NbJ; ++g) {
2211a8f1f9e5SMatthew G. Knepley         for (gc = 0; gc < NcJ; ++gc) {
2212a8f1f9e5SMatthew G. Knepley           const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */
2213a8f1f9e5SMatthew G. Knepley           const PetscInt j    = offsetJ+g; /* Element matrix column */
2214a8f1f9e5SMatthew G. Knepley           const PetscInt fOff = eOffset+i*totDim+j;
2215a8f1f9e5SMatthew G. Knepley 
2216a8f1f9e5SMatthew G. Knepley           elemMat[fOff] += tmpBasisI[fidx]*g0[fc*NcJ+gc]*tmpBasisJ[gidx];
2217*27f02ce8SMatthew G. Knepley           for (df = 0; df < dE; ++df) {
2218*27f02ce8SMatthew G. Knepley             elemMat[fOff] += tmpBasisI[fidx]*g1[(fc*NcJ+gc)*dE+df]*tmpBasisDerJ[gidx*dE+df];
2219*27f02ce8SMatthew G. Knepley             elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g2[(fc*NcJ+gc)*dE+df]*tmpBasisJ[gidx];
2220*27f02ce8SMatthew G. Knepley             for (dg = 0; dg < dE; ++dg) {
2221*27f02ce8SMatthew G. Knepley               elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g3[((fc*NcJ+gc)*dE+df)*dE+dg]*tmpBasisDerJ[gidx*dE+dg];
2222*27f02ce8SMatthew G. Knepley             }
2223*27f02ce8SMatthew G. Knepley           }
2224*27f02ce8SMatthew G. Knepley         }
2225*27f02ce8SMatthew G. Knepley       }
2226*27f02ce8SMatthew G. Knepley     }
2227*27f02ce8SMatthew G. Knepley   }
2228*27f02ce8SMatthew G. Knepley   return(0);
2229*27f02ce8SMatthew G. Knepley }
2230*27f02ce8SMatthew G. Knepley 
2231*27f02ce8SMatthew G. Knepley PetscErrorCode PetscFEUpdateElementMat_Hybrid_Internal(PetscFE feI, PetscBool isHybridI, PetscFE feJ, PetscBool isHybridJ, 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[])
2232*27f02ce8SMatthew G. Knepley {
2233*27f02ce8SMatthew G. Knepley   const PetscInt dE = fegeom->dimEmbed;
2234*27f02ce8SMatthew G. Knepley   const PetscInt Ns = isHybridI ? 1 : 2;
2235*27f02ce8SMatthew G. Knepley   const PetscInt Nt = isHybridJ ? 1 : 2;
2236*27f02ce8SMatthew G. Knepley   PetscInt       f, fc, g, gc, df, dg, s, t;
2237*27f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
2238*27f02ce8SMatthew G. Knepley 
2239*27f02ce8SMatthew G. Knepley   for (f = 0; f < NbI; ++f) {
2240*27f02ce8SMatthew G. Knepley     for (fc = 0; fc < NcI; ++fc) {
2241*27f02ce8SMatthew G. Knepley       const PetscInt fidx = f*NcI+fc; /* Test function basis index */
2242*27f02ce8SMatthew G. Knepley 
2243*27f02ce8SMatthew G. Knepley       tmpBasisI[fidx] = basisI[fidx];
2244*27f02ce8SMatthew G. Knepley       for (df = 0; df < dim; ++df) tmpBasisDerI[fidx*dE+df] = basisDerI[fidx*dim+df];
2245*27f02ce8SMatthew G. Knepley     }
2246*27f02ce8SMatthew G. Knepley   }
2247*27f02ce8SMatthew G. Knepley   ierr = PetscFEPushforward(feI, fegeom, NbI, tmpBasisI);CHKERRQ(ierr);
2248*27f02ce8SMatthew G. Knepley   ierr = PetscFEPushforwardGradient(feI, fegeom, NbI, tmpBasisDerI);CHKERRQ(ierr);
2249*27f02ce8SMatthew G. Knepley   for (g = 0; g < NbJ; ++g) {
2250*27f02ce8SMatthew G. Knepley     for (gc = 0; gc < NcJ; ++gc) {
2251*27f02ce8SMatthew G. Knepley       const PetscInt gidx = g*NcJ+gc; /* Trial function basis index */
2252*27f02ce8SMatthew G. Knepley 
2253*27f02ce8SMatthew G. Knepley       tmpBasisJ[gidx] = basisJ[gidx];
2254*27f02ce8SMatthew G. Knepley       for (dg = 0; dg < dim; ++dg) tmpBasisDerJ[gidx*dE+dg] = basisDerJ[gidx*dim+dg];
2255*27f02ce8SMatthew G. Knepley     }
2256*27f02ce8SMatthew G. Knepley   }
2257*27f02ce8SMatthew G. Knepley   ierr = PetscFEPushforward(feJ, fegeom, NbJ, tmpBasisJ);CHKERRQ(ierr);
2258*27f02ce8SMatthew G. Knepley   ierr = PetscFEPushforwardGradient(feJ, fegeom, NbJ, tmpBasisDerJ);CHKERRQ(ierr);
2259*27f02ce8SMatthew G. Knepley   for (s = 0; s < Ns; ++s) {
2260*27f02ce8SMatthew G. Knepley     for (f = 0; f < NbI; ++f) {
2261*27f02ce8SMatthew G. Knepley       for (fc = 0; fc < NcI; ++fc) {
2262*27f02ce8SMatthew G. Knepley         const PetscInt sc   = NcI*s+fc;  /* components from each side of the surface */
2263*27f02ce8SMatthew G. Knepley         const PetscInt fidx = f*NcI+fc;  /* Test function basis index */
2264*27f02ce8SMatthew G. Knepley         const PetscInt i    = offsetI+NbI*s+f; /* Element matrix row */
2265*27f02ce8SMatthew G. Knepley         for (t = 0; t < Nt; ++t) {
2266*27f02ce8SMatthew G. Knepley           for (g = 0; g < NbJ; ++g) {
2267*27f02ce8SMatthew G. Knepley             for (gc = 0; gc < NcJ; ++gc) {
2268*27f02ce8SMatthew G. Knepley               const PetscInt tc   = NcJ*t+gc;  /* components from each side of the surface */
2269*27f02ce8SMatthew G. Knepley               const PetscInt gidx = g*NcJ+gc;  /* Trial function basis index */
2270*27f02ce8SMatthew G. Knepley               const PetscInt j    = offsetJ+NbJ*t+g; /* Element matrix column */
2271*27f02ce8SMatthew G. Knepley               const PetscInt fOff = eOffset+i*totDim+j;
2272*27f02ce8SMatthew G. Knepley 
2273*27f02ce8SMatthew G. Knepley               elemMat[fOff] += tmpBasisI[fidx]*g0[sc*NcJ*Nt+tc]*tmpBasisJ[gidx];
2274*27f02ce8SMatthew G. Knepley               for (df = 0; df < dE; ++df) {
2275*27f02ce8SMatthew G. Knepley                 elemMat[fOff] += tmpBasisI[fidx]*g1[(sc*NcJ*Nt+tc)*dE+df]*tmpBasisDerJ[gidx*dE+df];
2276*27f02ce8SMatthew G. Knepley                 elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g2[(sc*NcJ*Nt+tc)*dE+df]*tmpBasisJ[gidx];
2277*27f02ce8SMatthew G. Knepley                 for (dg = 0; dg < dE; ++dg) {
2278*27f02ce8SMatthew G. Knepley                   elemMat[fOff] += tmpBasisDerI[fidx*dE+df]*g3[((sc*NcJ*Nt+tc)*dE+df)*dE+dg]*tmpBasisDerJ[gidx*dE+dg];
2279*27f02ce8SMatthew G. Knepley                 }
2280*27f02ce8SMatthew G. Knepley               }
2281a8f1f9e5SMatthew G. Knepley             }
2282a8f1f9e5SMatthew G. Knepley           }
2283a8f1f9e5SMatthew G. Knepley         }
2284a8f1f9e5SMatthew G. Knepley       }
2285a8f1f9e5SMatthew G. Knepley     }
2286a8f1f9e5SMatthew G. Knepley   }
2287a8f1f9e5SMatthew G. Knepley   return(0);
2288a8f1f9e5SMatthew G. Knepley }
2289c9ba7969SMatthew G. Knepley 
2290c9ba7969SMatthew G. Knepley PetscErrorCode PetscFECreateCellGeometry(PetscFE fe, PetscQuadrature quad, PetscFEGeom *cgeom)
2291c9ba7969SMatthew G. Knepley {
2292c9ba7969SMatthew G. Knepley   PetscDualSpace  dsp;
2293c9ba7969SMatthew G. Knepley   DM              dm;
2294c9ba7969SMatthew G. Knepley   PetscQuadrature quadDef;
2295c9ba7969SMatthew G. Knepley   PetscInt        dim, cdim, Nq;
2296c9ba7969SMatthew G. Knepley   PetscErrorCode  ierr;
2297c9ba7969SMatthew G. Knepley 
2298c9ba7969SMatthew G. Knepley   PetscFunctionBegin;
2299c9ba7969SMatthew G. Knepley   ierr = PetscFEGetDualSpace(fe, &dsp);CHKERRQ(ierr);
2300c9ba7969SMatthew G. Knepley   ierr = PetscDualSpaceGetDM(dsp, &dm);CHKERRQ(ierr);
2301c9ba7969SMatthew G. Knepley   ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
2302c9ba7969SMatthew G. Knepley   ierr = DMGetCoordinateDim(dm, &cdim);CHKERRQ(ierr);
2303c9ba7969SMatthew G. Knepley   ierr = PetscFEGetQuadrature(fe, &quadDef);CHKERRQ(ierr);
2304c9ba7969SMatthew G. Knepley   quad = quad ? quad : quadDef;
2305c9ba7969SMatthew G. Knepley   ierr = PetscQuadratureGetData(quad, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);
2306c9ba7969SMatthew G. Knepley   ierr = PetscMalloc1(Nq*cdim,      &cgeom->v);CHKERRQ(ierr);
2307c9ba7969SMatthew G. Knepley   ierr = PetscMalloc1(Nq*cdim*cdim, &cgeom->J);CHKERRQ(ierr);
2308c9ba7969SMatthew G. Knepley   ierr = PetscMalloc1(Nq*cdim*cdim, &cgeom->invJ);CHKERRQ(ierr);
2309c9ba7969SMatthew G. Knepley   ierr = PetscMalloc1(Nq,           &cgeom->detJ);CHKERRQ(ierr);
2310c9ba7969SMatthew G. Knepley   cgeom->dim       = dim;
2311c9ba7969SMatthew G. Knepley   cgeom->dimEmbed  = cdim;
2312c9ba7969SMatthew G. Knepley   cgeom->numCells  = 1;
2313c9ba7969SMatthew G. Knepley   cgeom->numPoints = Nq;
2314c9ba7969SMatthew G. Knepley   ierr = DMPlexComputeCellGeometryFEM(dm, 0, quad, cgeom->v, cgeom->J, cgeom->invJ, cgeom->detJ);CHKERRQ(ierr);
2315c9ba7969SMatthew G. Knepley   PetscFunctionReturn(0);
2316c9ba7969SMatthew G. Knepley }
2317c9ba7969SMatthew G. Knepley 
2318c9ba7969SMatthew G. Knepley PetscErrorCode PetscFEDestroyCellGeometry(PetscFE fe, PetscFEGeom *cgeom)
2319c9ba7969SMatthew G. Knepley {
2320c9ba7969SMatthew G. Knepley   PetscErrorCode ierr;
2321c9ba7969SMatthew G. Knepley 
2322c9ba7969SMatthew G. Knepley   PetscFunctionBegin;
2323c9ba7969SMatthew G. Knepley   ierr = PetscFree(cgeom->v);CHKERRQ(ierr);
2324c9ba7969SMatthew G. Knepley   ierr = PetscFree(cgeom->J);CHKERRQ(ierr);
2325c9ba7969SMatthew G. Knepley   ierr = PetscFree(cgeom->invJ);CHKERRQ(ierr);
2326c9ba7969SMatthew G. Knepley   ierr = PetscFree(cgeom->detJ);CHKERRQ(ierr);
2327c9ba7969SMatthew G. Knepley   PetscFunctionReturn(0);
2328c9ba7969SMatthew G. Knepley }
2329