xref: /petsc/src/dm/dt/interface/dtds.c (revision 6528b96d098a3a0d8b5eec2f1c205a3c25c0d721)
1af0996ceSBarry Smith #include <petsc/private/petscdsimpl.h> /*I "petscds.h" I*/
22764a2aaSMatthew G. Knepley 
32764a2aaSMatthew G. Knepley PetscClassId PETSCDS_CLASSID = 0;
42764a2aaSMatthew G. Knepley 
52764a2aaSMatthew G. Knepley PetscFunctionList PetscDSList              = NULL;
62764a2aaSMatthew G. Knepley PetscBool         PetscDSRegisterAllCalled = PETSC_FALSE;
72764a2aaSMatthew G. Knepley 
894dcdc3fSMatthew G. Knepley /* A PetscDS (Discrete System) encodes a set of equations posed in a discrete space, which represents a set of
994dcdc3fSMatthew G. Knepley    nonlinear continuum equations. The equations can have multiple fields, each field having a different
1094dcdc3fSMatthew G. Knepley    discretization. In addition, different pieces of the domain can have different field combinations and equations.
1194dcdc3fSMatthew G. Knepley 
1294dcdc3fSMatthew G. Knepley    The DS provides the user a description of the approximation space on any given cell. It also gives pointwise
1394dcdc3fSMatthew G. Knepley    functions representing the equations.
1494dcdc3fSMatthew G. Knepley 
1594dcdc3fSMatthew G. Knepley    Each field is associated with a label, marking the cells on which it is supported. Note that a field can be
1694dcdc3fSMatthew G. Knepley    supported on the closure of a cell not in the label due to overlap of the boundary of neighboring cells. The DM
1794dcdc3fSMatthew G. Knepley    then creates a DS for each set of cells with identical approximation spaces. When assembling, the user asks for
1894dcdc3fSMatthew G. Knepley    the space associated with a given cell. DMPlex uses the labels associated with each DS in the default integration loop.
1994dcdc3fSMatthew G. Knepley */
2094dcdc3fSMatthew G. Knepley 
212764a2aaSMatthew G. Knepley /*@C
222764a2aaSMatthew G. Knepley   PetscDSRegister - Adds a new PetscDS implementation
232764a2aaSMatthew G. Knepley 
242764a2aaSMatthew G. Knepley   Not Collective
252764a2aaSMatthew G. Knepley 
262764a2aaSMatthew G. Knepley   Input Parameters:
272764a2aaSMatthew G. Knepley + name        - The name of a new user-defined creation routine
282764a2aaSMatthew G. Knepley - create_func - The creation routine itself
292764a2aaSMatthew G. Knepley 
302764a2aaSMatthew G. Knepley   Notes:
312764a2aaSMatthew G. Knepley   PetscDSRegister() may be called multiple times to add several user-defined PetscDSs
322764a2aaSMatthew G. Knepley 
332764a2aaSMatthew G. Knepley   Sample usage:
342764a2aaSMatthew G. Knepley .vb
352764a2aaSMatthew G. Knepley     PetscDSRegister("my_ds", MyPetscDSCreate);
362764a2aaSMatthew G. Knepley .ve
372764a2aaSMatthew G. Knepley 
382764a2aaSMatthew G. Knepley   Then, your PetscDS type can be chosen with the procedural interface via
392764a2aaSMatthew G. Knepley .vb
402764a2aaSMatthew G. Knepley     PetscDSCreate(MPI_Comm, PetscDS *);
412764a2aaSMatthew G. Knepley     PetscDSSetType(PetscDS, "my_ds");
422764a2aaSMatthew G. Knepley .ve
432764a2aaSMatthew G. Knepley    or at runtime via the option
442764a2aaSMatthew G. Knepley .vb
452764a2aaSMatthew G. Knepley     -petscds_type my_ds
462764a2aaSMatthew G. Knepley .ve
472764a2aaSMatthew G. Knepley 
482764a2aaSMatthew G. Knepley   Level: advanced
492764a2aaSMatthew G. Knepley 
50f5f57ec0SBarry Smith    Not available from Fortran
51f5f57ec0SBarry Smith 
522764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy()
532764a2aaSMatthew G. Knepley 
542764a2aaSMatthew G. Knepley @*/
552764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
562764a2aaSMatthew G. Knepley {
572764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
582764a2aaSMatthew G. Knepley 
592764a2aaSMatthew G. Knepley   PetscFunctionBegin;
602764a2aaSMatthew G. Knepley   ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr);
612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
622764a2aaSMatthew G. Knepley }
632764a2aaSMatthew G. Knepley 
642764a2aaSMatthew G. Knepley /*@C
652764a2aaSMatthew G. Knepley   PetscDSSetType - Builds a particular PetscDS
662764a2aaSMatthew G. Knepley 
67d083f849SBarry Smith   Collective on prob
682764a2aaSMatthew G. Knepley 
692764a2aaSMatthew G. Knepley   Input Parameters:
702764a2aaSMatthew G. Knepley + prob - The PetscDS object
712764a2aaSMatthew G. Knepley - name - The kind of system
722764a2aaSMatthew G. Knepley 
732764a2aaSMatthew G. Knepley   Options Database Key:
742764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
752764a2aaSMatthew G. Knepley 
762764a2aaSMatthew G. Knepley   Level: intermediate
772764a2aaSMatthew G. Knepley 
78f5f57ec0SBarry Smith    Not available from Fortran
79f5f57ec0SBarry Smith 
802764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate()
812764a2aaSMatthew G. Knepley @*/
822764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
832764a2aaSMatthew G. Knepley {
842764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
852764a2aaSMatthew G. Knepley   PetscBool      match;
862764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
872764a2aaSMatthew G. Knepley 
882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
902764a2aaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr);
912764a2aaSMatthew G. Knepley   if (match) PetscFunctionReturn(0);
922764a2aaSMatthew G. Knepley 
930f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
942764a2aaSMatthew G. Knepley   ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr);
952764a2aaSMatthew G. Knepley   if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
962764a2aaSMatthew G. Knepley 
972764a2aaSMatthew G. Knepley   if (prob->ops->destroy) {
982764a2aaSMatthew G. Knepley     ierr             = (*prob->ops->destroy)(prob);CHKERRQ(ierr);
992764a2aaSMatthew G. Knepley     prob->ops->destroy = NULL;
1002764a2aaSMatthew G. Knepley   }
1012764a2aaSMatthew G. Knepley   ierr = (*r)(prob);CHKERRQ(ierr);
1022764a2aaSMatthew G. Knepley   ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr);
1032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1042764a2aaSMatthew G. Knepley }
1052764a2aaSMatthew G. Knepley 
1062764a2aaSMatthew G. Knepley /*@C
1072764a2aaSMatthew G. Knepley   PetscDSGetType - Gets the PetscDS type name (as a string) from the object.
1082764a2aaSMatthew G. Knepley 
1092764a2aaSMatthew G. Knepley   Not Collective
1102764a2aaSMatthew G. Knepley 
1112764a2aaSMatthew G. Knepley   Input Parameter:
1122764a2aaSMatthew G. Knepley . prob  - The PetscDS
1132764a2aaSMatthew G. Knepley 
1142764a2aaSMatthew G. Knepley   Output Parameter:
1152764a2aaSMatthew G. Knepley . name - The PetscDS type name
1162764a2aaSMatthew G. Knepley 
1172764a2aaSMatthew G. Knepley   Level: intermediate
1182764a2aaSMatthew G. Knepley 
119f5f57ec0SBarry Smith    Not available from Fortran
120f5f57ec0SBarry Smith 
1212764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate()
1222764a2aaSMatthew G. Knepley @*/
1232764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
1242764a2aaSMatthew G. Knepley {
1252764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1262764a2aaSMatthew G. Knepley 
1272764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1282764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
129c959eef4SJed Brown   PetscValidPointer(name, 2);
1300f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
1312764a2aaSMatthew G. Knepley   *name = ((PetscObject) prob)->type_name;
1322764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1332764a2aaSMatthew G. Knepley }
1342764a2aaSMatthew G. Knepley 
1357d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer)
1367d8a60eaSMatthew G. Knepley {
1377d8a60eaSMatthew G. Knepley   PetscViewerFormat  format;
13897b6e6e8SMatthew G. Knepley   const PetscScalar *constants;
13997b6e6e8SMatthew G. Knepley   PetscInt           numConstants, f;
1407d8a60eaSMatthew G. Knepley   PetscErrorCode     ierr;
1417d8a60eaSMatthew G. Knepley 
1427d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1437d8a60eaSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
1447d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr);
1457d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1464727e194SMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "  cell total dim %D total comp %D\n", prob->totDim, prob->totComp);CHKERRQ(ierr);
1474727e194SMatthew G. Knepley   if (prob->isHybrid) {ierr = PetscViewerASCIIPrintf(viewer, "  hybrid cell\n");CHKERRQ(ierr);}
1487d8a60eaSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
14940967b3bSMatthew G. Knepley     DSBoundary      b;
1507d8a60eaSMatthew G. Knepley     PetscObject     obj;
1517d8a60eaSMatthew G. Knepley     PetscClassId    id;
152f35450b9SMatthew G. Knepley     PetscQuadrature q;
1537d8a60eaSMatthew G. Knepley     const char     *name;
154f35450b9SMatthew G. Knepley     PetscInt        Nc, Nq, Nqc;
1557d8a60eaSMatthew G. Knepley 
1567d8a60eaSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
1577d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
1587d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr);
1597d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr);
1604727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
1617d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
1627d8a60eaSMatthew G. Knepley       ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr);
163f35450b9SMatthew G. Knepley       ierr = PetscFEGetQuadrature((PetscFE) obj, &q);CHKERRQ(ierr);
1647d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr);
1657d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1667d8a60eaSMatthew G. Knepley       ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr);
167f35450b9SMatthew G. Knepley       ierr = PetscFVGetQuadrature((PetscFV) obj, &q);CHKERRQ(ierr);
1687d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr);
1697d8a60eaSMatthew G. Knepley     }
17097b6e6e8SMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f);
17197b6e6e8SMatthew G. Knepley     if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%D components", Nc);CHKERRQ(ierr);}
17297b6e6e8SMatthew G. Knepley     else        {ierr = PetscViewerASCIIPrintf(viewer, "%D component ", Nc);CHKERRQ(ierr);}
173249df284SMatthew G. Knepley     if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);}
174249df284SMatthew G. Knepley     else                   {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);}
1753e60c2a6SMatthew G. Knepley     if (q) {
176f35450b9SMatthew G. Knepley       ierr = PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL);CHKERRQ(ierr);
177f35450b9SMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " (Nq %D Nqc %D)", Nq, Nqc);CHKERRQ(ierr);
1783e60c2a6SMatthew G. Knepley     }
179f9244615SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, " %D-jet", prob->jetDegree[f]);CHKERRQ(ierr);
1807d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
1814727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
1825d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1837d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);}
1847d8a60eaSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);}
1855d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
18640967b3bSMatthew G. Knepley 
18740967b3bSMatthew G. Knepley     for (b = prob->boundary; b; b = b->next) {
18840967b3bSMatthew G. Knepley       PetscInt c, i;
18940967b3bSMatthew G. Knepley 
19040967b3bSMatthew G. Knepley       if (b->field != f) continue;
19140967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
19240967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->labelname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr);
19340967b3bSMatthew G. Knepley       if (!b->numcomps) {
19440967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "  all components\n");CHKERRQ(ierr);
19540967b3bSMatthew G. Knepley       } else {
19640967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "  components: ");CHKERRQ(ierr);
19740967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
19840967b3bSMatthew G. Knepley         for (c = 0; c < b->numcomps; ++c) {
19940967b3bSMatthew G. Knepley           if (c > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
20040967b3bSMatthew G. Knepley           ierr = PetscViewerASCIIPrintf(viewer, "%D", b->comps[c]);CHKERRQ(ierr);
20140967b3bSMatthew G. Knepley         }
20240967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
20340967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
20440967b3bSMatthew G. Knepley       }
20540967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "  ids: ");CHKERRQ(ierr);
20640967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
20740967b3bSMatthew G. Knepley       for (i = 0; i < b->numids; ++i) {
20840967b3bSMatthew G. Knepley         if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
20940967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "%D", b->ids[i]);CHKERRQ(ierr);
21040967b3bSMatthew G. Knepley       }
21140967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
21240967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
21340967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
21440967b3bSMatthew G. Knepley     }
2157d8a60eaSMatthew G. Knepley   }
21697b6e6e8SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr);
21797b6e6e8SMatthew G. Knepley   if (numConstants) {
21897b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr);
21997b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
22057fc01e9SMatthew G. Knepley     for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);}
22197b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
22297b6e6e8SMatthew G. Knepley   }
223*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormView(prob->wf, viewer);CHKERRQ(ierr);
2247d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
2257d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
2267d8a60eaSMatthew G. Knepley }
2277d8a60eaSMatthew G. Knepley 
2282764a2aaSMatthew G. Knepley /*@C
229fe2efc57SMark    PetscDSViewFromOptions - View from Options
230fe2efc57SMark 
231fe2efc57SMark    Collective on PetscDS
232fe2efc57SMark 
233fe2efc57SMark    Input Parameters:
234fe2efc57SMark +  A - the PetscDS object
235736c3998SJose E. Roman .  obj - Optional object
236736c3998SJose E. Roman -  name - command line option
237fe2efc57SMark 
238fe2efc57SMark    Level: intermediate
239fe2efc57SMark .seealso:  PetscDS, PetscDSView, PetscObjectViewFromOptions(), PetscDSCreate()
240fe2efc57SMark @*/
241fe2efc57SMark PetscErrorCode  PetscDSViewFromOptions(PetscDS A,PetscObject obj,const char name[])
242fe2efc57SMark {
243fe2efc57SMark   PetscErrorCode ierr;
244fe2efc57SMark 
245fe2efc57SMark   PetscFunctionBegin;
246fe2efc57SMark   PetscValidHeaderSpecific(A,PETSCDS_CLASSID,1);
247fe2efc57SMark   ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr);
248fe2efc57SMark   PetscFunctionReturn(0);
249fe2efc57SMark }
250fe2efc57SMark 
251fe2efc57SMark /*@C
2522764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
2532764a2aaSMatthew G. Knepley 
254d083f849SBarry Smith   Collective on prob
2552764a2aaSMatthew G. Knepley 
2562764a2aaSMatthew G. Knepley   Input Parameter:
2572764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
2582764a2aaSMatthew G. Knepley - v  - the viewer
2592764a2aaSMatthew G. Knepley 
2602764a2aaSMatthew G. Knepley   Level: developer
2612764a2aaSMatthew G. Knepley 
2622764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
2632764a2aaSMatthew G. Knepley @*/
2642764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
2652764a2aaSMatthew G. Knepley {
2667d8a60eaSMatthew G. Knepley   PetscBool      iascii;
2672764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2682764a2aaSMatthew G. Knepley 
2692764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2702764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2712764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
2727d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
2737d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
2747d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2752764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2762764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2772764a2aaSMatthew G. Knepley }
2782764a2aaSMatthew G. Knepley 
2792764a2aaSMatthew G. Knepley /*@
2802764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2812764a2aaSMatthew G. Knepley 
282d083f849SBarry Smith   Collective on prob
2832764a2aaSMatthew G. Knepley 
2842764a2aaSMatthew G. Knepley   Input Parameter:
2852764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2862764a2aaSMatthew G. Knepley 
2872764a2aaSMatthew G. Knepley   Options Database:
28855c1f793SMatthew G. Knepley + -petscds_type <type>     : Set the DS type
28955c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS
29055c1f793SMatthew G. Knepley . -petscds_jac_pre         : Turn formation of a separate Jacobian preconditioner on and off
29155c1f793SMatthew G. Knepley . -bc_<name> <ids>         : Specify a list of label ids for a boundary condition
29255c1f793SMatthew G. Knepley - -bc_<name>_comp <comps>  : Specify a list of field components to constrain for a boundary condition
2932764a2aaSMatthew G. Knepley 
2942764a2aaSMatthew G. Knepley   Level: developer
2952764a2aaSMatthew G. Knepley 
2962764a2aaSMatthew G. Knepley .seealso PetscDSView()
2972764a2aaSMatthew G. Knepley @*/
2982764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
2992764a2aaSMatthew G. Knepley {
300f1fd5e65SToby Isaac   DSBoundary     b;
3012764a2aaSMatthew G. Knepley   const char    *defaultType;
3022764a2aaSMatthew G. Knepley   char           name[256];
3032764a2aaSMatthew G. Knepley   PetscBool      flg;
3042764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3052764a2aaSMatthew G. Knepley 
3062764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3072764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3082764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
3092764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
3102764a2aaSMatthew G. Knepley   } else {
3112764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
3122764a2aaSMatthew G. Knepley   }
3130f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
3142764a2aaSMatthew G. Knepley 
3152764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
316f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
317f1fd5e65SToby Isaac     char       optname[1024];
318f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
319f1fd5e65SToby Isaac     PetscBool  flg;
320f1fd5e65SToby Isaac 
321f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
322f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
323f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
324f1fd5e65SToby Isaac     if (flg) {
325f1fd5e65SToby Isaac       b->numids = len;
326f1fd5e65SToby Isaac       ierr = PetscFree(b->ids);CHKERRQ(ierr);
327f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr);
328580bdb30SBarry Smith       ierr = PetscArraycpy(b->ids, ids, len);CHKERRQ(ierr);
329f1fd5e65SToby Isaac     }
330e7b0402cSSander Arens     len = 1024;
331f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
332f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
333f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
334f1fd5e65SToby Isaac     if (flg) {
335f1fd5e65SToby Isaac       b->numcomps = len;
336f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
337f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
338580bdb30SBarry Smith       ierr = PetscArraycpy(b->comps, ids, len);CHKERRQ(ierr);
339f1fd5e65SToby Isaac     }
340f1fd5e65SToby Isaac   }
3412764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
3422764a2aaSMatthew G. Knepley   if (flg) {
3432764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
3442764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
3452764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
3462764a2aaSMatthew G. Knepley   }
34755c1f793SMatthew G. Knepley   ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr);
3482764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
3492764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
3500633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
3512764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
3525d160056SMatthew G. Knepley   if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);}
3532764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3542764a2aaSMatthew G. Knepley }
3552764a2aaSMatthew G. Knepley 
3562764a2aaSMatthew G. Knepley /*@C
3572764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
3582764a2aaSMatthew G. Knepley 
359d083f849SBarry Smith   Collective on prob
3602764a2aaSMatthew G. Knepley 
3612764a2aaSMatthew G. Knepley   Input Parameter:
3622764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
3632764a2aaSMatthew G. Knepley 
3642764a2aaSMatthew G. Knepley   Level: developer
3652764a2aaSMatthew G. Knepley 
3662764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
3672764a2aaSMatthew G. Knepley @*/
3682764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
3692764a2aaSMatthew G. Knepley {
3702764a2aaSMatthew G. Knepley   const PetscInt Nf   = prob->Nf;
371f9244615SMatthew G. Knepley   PetscBool      hasH = PETSC_FALSE;
3724bee2e38SMatthew G. Knepley   PetscInt       dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f;
3732764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3742764a2aaSMatthew G. Knepley 
3752764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3762764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3772764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3782764a2aaSMatthew G. Knepley   /* Calculate sizes */
3792764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
380d1506c7cSMatthew G. Knepley   ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr);
381f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
38247e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
383f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
384ef0bb6c7SMatthew G. Knepley   ierr = PetscMalloc2(Nf,&prob->T,Nf,&prob->Tf);CHKERRQ(ierr);
3852764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3869de99aefSMatthew G. Knepley     PetscObject     obj;
3879de99aefSMatthew G. Knepley     PetscClassId    id;
388665f567fSMatthew G. Knepley     PetscQuadrature q = NULL;
3899de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
3902764a2aaSMatthew G. Knepley 
3919de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
392f9244615SMatthew G. Knepley     if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE;
393665f567fSMatthew G. Knepley     if (!obj) {
394665f567fSMatthew G. Knepley       /* Empty mesh */
395665f567fSMatthew G. Knepley       Nb = Nc = 0;
396665f567fSMatthew G. Knepley       prob->T[f] = prob->Tf[f] = NULL;
397665f567fSMatthew G. Knepley     } else {
3989de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3999de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {
4009de99aefSMatthew G. Knepley         PetscFE fe = (PetscFE) obj;
4019de99aefSMatthew G. Knepley 
4022764a2aaSMatthew G. Knepley         ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
4032764a2aaSMatthew G. Knepley         ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
4042764a2aaSMatthew G. Knepley         ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
405f9244615SMatthew G. Knepley         ierr = PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f]);CHKERRQ(ierr);
406f9244615SMatthew G. Knepley         ierr = PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f]);CHKERRQ(ierr);
4079de99aefSMatthew G. Knepley       } else if (id == PETSCFV_CLASSID) {
4089de99aefSMatthew G. Knepley         PetscFV fv = (PetscFV) obj;
4099de99aefSMatthew G. Knepley 
4109de99aefSMatthew G. Knepley         ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
4119de99aefSMatthew G. Knepley         ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
4129c3cf19fSMatthew G. Knepley         Nb   = Nc;
413ef0bb6c7SMatthew G. Knepley         ierr = PetscFVGetCellTabulation(fv, &prob->T[f]);CHKERRQ(ierr);
4144d0b9603SSander Arens         /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
415abac5ca0SMatthew G. Knepley       } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
416665f567fSMatthew G. Knepley     }
41747e57110SSander Arens     prob->Nc[f]       = Nc;
41847e57110SSander Arens     prob->Nb[f]       = Nb;
419194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
420194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
421a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
4222764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
4234bee2e38SMatthew G. Knepley     NbMax          = PetscMax(NbMax, Nb);
4242764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
4259c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
4262764a2aaSMatthew G. Knepley     prob->totComp += Nc;
42794a5e212SMatthew G. Knepley     /* There are two faces for all fields but the cohesive field on a hybrid cell */
42894a5e212SMatthew G. Knepley     if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb;
4292764a2aaSMatthew G. Knepley   }
4302764a2aaSMatthew G. Knepley   /* Allocate works space */
43194a5e212SMatthew G. Knepley   if (prob->isHybrid) NsMax = 2;
432f9244615SMatthew G. Knepley   ierr = PetscMalloc3(NsMax*prob->totComp,&prob->u,NsMax*prob->totComp,&prob->u_t,NsMax*prob->totComp*dimEmbed + (hasH ? NsMax*prob->totComp*dimEmbed*dimEmbed : 0),&prob->u_x);CHKERRQ(ierr);
4334bee2e38SMatthew G. Knepley   ierr = PetscMalloc5(dimEmbed,&prob->x,NbMax*NcMax,&prob->basisReal,NbMax*NcMax*dimEmbed,&prob->basisDerReal,NbMax*NcMax,&prob->testReal,NbMax*NcMax*dimEmbed,&prob->testDerReal);CHKERRQ(ierr);
43427f02ce8SMatthew G. Knepley   ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dimEmbed,&prob->f1,
43527f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g1,
43627f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed*dimEmbed,&prob->g3);CHKERRQ(ierr);
4372764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
4382764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
4392764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4402764a2aaSMatthew G. Knepley }
4412764a2aaSMatthew G. Knepley 
4422764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
4432764a2aaSMatthew G. Knepley {
4442764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4452764a2aaSMatthew G. Knepley 
4462764a2aaSMatthew G. Knepley   PetscFunctionBegin;
44747e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
448f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
449ef0bb6c7SMatthew G. Knepley   ierr = PetscFree2(prob->T,prob->Tf);CHKERRQ(ierr);
4504bee2e38SMatthew G. Knepley   ierr = PetscFree3(prob->u,prob->u_t,prob->u_x);CHKERRQ(ierr);
4514bee2e38SMatthew G. Knepley   ierr = PetscFree5(prob->x,prob->basisReal, prob->basisDerReal,prob->testReal,prob->testDerReal);CHKERRQ(ierr);
4522764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
4532764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4542764a2aaSMatthew G. Knepley }
4552764a2aaSMatthew G. Knepley 
4562764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
4572764a2aaSMatthew G. Knepley {
458f744cafaSSander Arens   PetscObject      *tmpd;
45934aa8a36SMatthew G. Knepley   PetscBool        *tmpi;
460f9244615SMatthew G. Knepley   PetscInt         *tmpk;
461*6528b96dSMatthew G. Knepley   PetscPointFunc   *tmpup;
462f2cacb80SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol,  *tmpexactSol_t;
463f2cacb80SMatthew G. Knepley   void                **tmpexactCtx, **tmpexactCtx_t;
4640c2f2876SMatthew G. Knepley   void            **tmpctx;
46534aa8a36SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f;
4662764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
4672764a2aaSMatthew G. Knepley 
4682764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4692764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
4702764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
4712764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
472f9244615SMatthew G. Knepley   ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpk);CHKERRQ(ierr);
473f9244615SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; tmpk[f] = prob->jetDegree[f];}
474f9244615SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpk[f] = 1;}
475f9244615SMatthew G. Knepley   ierr = PetscFree3(prob->disc, prob->implicit, prob->jetDegree);CHKERRQ(ierr);
476*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(prob->wf, NfNew);CHKERRQ(ierr);
4772764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
4782764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
479249df284SMatthew G. Knepley   prob->implicit  = tmpi;
480f9244615SMatthew G. Knepley   prob->jetDegree = tmpk;
481*6528b96dSMatthew G. Knepley   ierr = PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx);CHKERRQ(ierr);
48232d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
4830c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
48432d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
4850c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
486*6528b96dSMatthew G. Knepley   ierr = PetscFree2(prob->update, prob->ctx);CHKERRQ(ierr);
48732d2bbc9SMatthew G. Knepley   prob->update = tmpup;
4880c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
489*6528b96dSMatthew G. Knepley   ierr = PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t);CHKERRQ(ierr);
490c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
49195cbbfd3SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f];
492f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f];
493f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f];
494c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
49595cbbfd3SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL;
496f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL;
497f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL;
498*6528b96dSMatthew G. Knepley   ierr = PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t);CHKERRQ(ierr);
499c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
50095cbbfd3SMatthew G. Knepley   prob->exactCtx = tmpexactCtx;
501f2cacb80SMatthew G. Knepley   prob->exactSol_t = tmpexactSol_t;
502f2cacb80SMatthew G. Knepley   prob->exactCtx_t = tmpexactCtx_t;
5032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5042764a2aaSMatthew G. Knepley }
5052764a2aaSMatthew G. Knepley 
5062764a2aaSMatthew G. Knepley /*@
5072764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
5082764a2aaSMatthew G. Knepley 
509d083f849SBarry Smith   Collective on prob
5102764a2aaSMatthew G. Knepley 
5112764a2aaSMatthew G. Knepley   Input Parameter:
5122764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
5132764a2aaSMatthew G. Knepley 
5142764a2aaSMatthew G. Knepley   Level: developer
5152764a2aaSMatthew G. Knepley 
5162764a2aaSMatthew G. Knepley .seealso PetscDSView()
5172764a2aaSMatthew G. Knepley @*/
518*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *ds)
5192764a2aaSMatthew G. Knepley {
5202764a2aaSMatthew G. Knepley   PetscInt       f;
52158ebd649SToby Isaac   DSBoundary     next;
5222764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5232764a2aaSMatthew G. Knepley 
5242764a2aaSMatthew G. Knepley   PetscFunctionBegin;
525*6528b96dSMatthew G. Knepley   if (!*ds) PetscFunctionReturn(0);
526*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1);
5272764a2aaSMatthew G. Knepley 
528*6528b96dSMatthew G. Knepley   if (--((PetscObject)(*ds))->refct > 0) {*ds = NULL; PetscFunctionReturn(0);}
529*6528b96dSMatthew G. Knepley   ((PetscObject) (*ds))->refct = 0;
530*6528b96dSMatthew G. Knepley   if ((*ds)->subprobs) {
531df3a45bdSMatthew G. Knepley     PetscInt dim, d;
532df3a45bdSMatthew G. Knepley 
533*6528b96dSMatthew G. Knepley     ierr = PetscDSGetSpatialDimension(*ds, &dim);CHKERRQ(ierr);
534*6528b96dSMatthew G. Knepley     for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*ds)->subprobs[d]);CHKERRQ(ierr);}
535df3a45bdSMatthew G. Knepley   }
536*6528b96dSMatthew G. Knepley   ierr = PetscFree((*ds)->subprobs);CHKERRQ(ierr);
537*6528b96dSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*ds);CHKERRQ(ierr);
538*6528b96dSMatthew G. Knepley   for (f = 0; f < (*ds)->Nf; ++f) {
539*6528b96dSMatthew G. Knepley     ierr = PetscObjectDereference((*ds)->disc[f]);CHKERRQ(ierr);
5402764a2aaSMatthew G. Knepley   }
541*6528b96dSMatthew G. Knepley   ierr = PetscFree3((*ds)->disc, (*ds)->implicit, (*ds)->jetDegree);CHKERRQ(ierr);
542*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormDestroy(&(*ds)->wf);CHKERRQ(ierr);
543*6528b96dSMatthew G. Knepley   ierr = PetscFree2((*ds)->update,(*ds)->ctx);CHKERRQ(ierr);
544*6528b96dSMatthew G. Knepley   ierr = PetscFree4((*ds)->exactSol,(*ds)->exactCtx,(*ds)->exactSol_t,(*ds)->exactCtx_t);CHKERRQ(ierr);
545*6528b96dSMatthew G. Knepley   if ((*ds)->ops->destroy) {ierr = (*(*ds)->ops->destroy)(*ds);CHKERRQ(ierr);}
546*6528b96dSMatthew G. Knepley   next = (*ds)->boundary;
54758ebd649SToby Isaac   while (next) {
54858ebd649SToby Isaac     DSBoundary b = next;
54958ebd649SToby Isaac 
55058ebd649SToby Isaac     next = b->next;
55158ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
55258ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
55358ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
55458ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
55558ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
55658ebd649SToby Isaac   }
557*6528b96dSMatthew G. Knepley   ierr = PetscFree((*ds)->constants);CHKERRQ(ierr);
558*6528b96dSMatthew G. Knepley   ierr = PetscHeaderDestroy(ds);CHKERRQ(ierr);
5592764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5602764a2aaSMatthew G. Knepley }
5612764a2aaSMatthew G. Knepley 
5622764a2aaSMatthew G. Knepley /*@
5632764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
5642764a2aaSMatthew G. Knepley 
565d083f849SBarry Smith   Collective
5662764a2aaSMatthew G. Knepley 
5672764a2aaSMatthew G. Knepley   Input Parameter:
5682764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
5692764a2aaSMatthew G. Knepley 
5702764a2aaSMatthew G. Knepley   Output Parameter:
571*6528b96dSMatthew G. Knepley . ds   - The PetscDS object
5722764a2aaSMatthew G. Knepley 
5732764a2aaSMatthew G. Knepley   Level: beginner
5742764a2aaSMatthew G. Knepley 
5752764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
5762764a2aaSMatthew G. Knepley @*/
577*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds)
5782764a2aaSMatthew G. Knepley {
5792764a2aaSMatthew G. Knepley   PetscDS        p;
5802764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5812764a2aaSMatthew G. Knepley 
5822764a2aaSMatthew G. Knepley   PetscFunctionBegin;
583*6528b96dSMatthew G. Knepley   PetscValidPointer(ds, 2);
584*6528b96dSMatthew G. Knepley   *ds  = NULL;
5852764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5862764a2aaSMatthew G. Knepley 
58773107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5882764a2aaSMatthew G. Knepley 
5892764a2aaSMatthew G. Knepley   p->Nf           = 0;
5902764a2aaSMatthew G. Knepley   p->setup        = PETSC_FALSE;
59197b6e6e8SMatthew G. Knepley   p->numConstants = 0;
59297b6e6e8SMatthew G. Knepley   p->constants    = NULL;
593a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
59455c1f793SMatthew G. Knepley   p->useJacPre    = PETSC_TRUE;
595*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormCreate(comm, &p->wf);CHKERRQ(ierr);
5962764a2aaSMatthew G. Knepley 
597*6528b96dSMatthew G. Knepley   *ds = p;
5982764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5992764a2aaSMatthew G. Knepley }
6002764a2aaSMatthew G. Knepley 
601bc4ae4beSMatthew G. Knepley /*@
602bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
603bc4ae4beSMatthew G. Knepley 
604bc4ae4beSMatthew G. Knepley   Not collective
605bc4ae4beSMatthew G. Knepley 
606bc4ae4beSMatthew G. Knepley   Input Parameter:
607bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
608bc4ae4beSMatthew G. Knepley 
609bc4ae4beSMatthew G. Knepley   Output Parameter:
610bc4ae4beSMatthew G. Knepley . Nf - The number of fields
611bc4ae4beSMatthew G. Knepley 
612bc4ae4beSMatthew G. Knepley   Level: beginner
613bc4ae4beSMatthew G. Knepley 
614bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
615bc4ae4beSMatthew G. Knepley @*/
6162764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
6172764a2aaSMatthew G. Knepley {
6182764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6192764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6202764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
6212764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
6222764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6232764a2aaSMatthew G. Knepley }
6242764a2aaSMatthew G. Knepley 
625bc4ae4beSMatthew G. Knepley /*@
626a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
627bc4ae4beSMatthew G. Knepley 
628bc4ae4beSMatthew G. Knepley   Not collective
629bc4ae4beSMatthew G. Knepley 
630bc4ae4beSMatthew G. Knepley   Input Parameter:
631bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
632bc4ae4beSMatthew G. Knepley 
633bc4ae4beSMatthew G. Knepley   Output Parameter:
634bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
635bc4ae4beSMatthew G. Knepley 
636bc4ae4beSMatthew G. Knepley   Level: beginner
637bc4ae4beSMatthew G. Knepley 
638a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate()
639bc4ae4beSMatthew G. Knepley @*/
6402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
6412764a2aaSMatthew G. Knepley {
6422764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6432764a2aaSMatthew G. Knepley 
6442764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6452764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6462764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6472764a2aaSMatthew G. Knepley   *dim = 0;
6489de99aefSMatthew G. Knepley   if (prob->Nf) {
6499de99aefSMatthew G. Knepley     PetscObject  obj;
6509de99aefSMatthew G. Knepley     PetscClassId id;
6519de99aefSMatthew G. Knepley 
6529de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
653665f567fSMatthew G. Knepley     if (obj) {
6549de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
6559de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
6569de99aefSMatthew G. Knepley       else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
6579de99aefSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
6589de99aefSMatthew G. Knepley     }
659665f567fSMatthew G. Knepley   }
6602764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6612764a2aaSMatthew G. Knepley }
6622764a2aaSMatthew G. Knepley 
663bc4ae4beSMatthew G. Knepley /*@
664a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
665a859676bSMatthew G. Knepley 
666a859676bSMatthew G. Knepley   Not collective
667a859676bSMatthew G. Knepley 
668a859676bSMatthew G. Knepley   Input Parameter:
669a859676bSMatthew G. Knepley . prob - The PetscDS object
670a859676bSMatthew G. Knepley 
671a859676bSMatthew G. Knepley   Output Parameter:
672a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
673a859676bSMatthew G. Knepley 
674a859676bSMatthew G. Knepley   Level: beginner
675a859676bSMatthew G. Knepley 
676a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
677a859676bSMatthew G. Knepley @*/
678a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
679a859676bSMatthew G. Knepley {
680a859676bSMatthew G. Knepley   PetscFunctionBegin;
681a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
682a859676bSMatthew G. Knepley   PetscValidPointer(dimEmbed, 2);
683a859676bSMatthew G. Knepley   if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
684a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
685a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
686a859676bSMatthew G. Knepley }
687a859676bSMatthew G. Knepley 
688a859676bSMatthew G. Knepley /*@
689a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
690a859676bSMatthew G. Knepley 
691d083f849SBarry Smith   Logically collective on prob
692a859676bSMatthew G. Knepley 
693a859676bSMatthew G. Knepley   Input Parameters:
694a859676bSMatthew G. Knepley + prob - The PetscDS object
695a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
696a859676bSMatthew G. Knepley 
697a859676bSMatthew G. Knepley   Level: beginner
698a859676bSMatthew G. Knepley 
699a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
700a859676bSMatthew G. Knepley @*/
701a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
702a859676bSMatthew G. Knepley {
703a859676bSMatthew G. Knepley   PetscFunctionBegin;
704a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
705ebfe4b0dSMatthew G. Knepley   if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed);
706a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
707a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
708a859676bSMatthew G. Knepley }
709a859676bSMatthew G. Knepley 
710a859676bSMatthew G. Knepley /*@
7118edf6225SMatthew G. Knepley   PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell
7128edf6225SMatthew G. Knepley 
7138edf6225SMatthew G. Knepley   Not collective
7148edf6225SMatthew G. Knepley 
7158edf6225SMatthew G. Knepley   Input Parameter:
7168edf6225SMatthew G. Knepley . prob - The PetscDS object
7178edf6225SMatthew G. Knepley 
7188edf6225SMatthew G. Knepley   Output Parameter:
7198edf6225SMatthew G. Knepley . isHybrid - The flag
7208edf6225SMatthew G. Knepley 
7218edf6225SMatthew G. Knepley   Level: developer
7228edf6225SMatthew G. Knepley 
7238edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate()
7248edf6225SMatthew G. Knepley @*/
7258edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid)
7268edf6225SMatthew G. Knepley {
7278edf6225SMatthew G. Knepley   PetscFunctionBegin;
7288edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7298edf6225SMatthew G. Knepley   PetscValidPointer(isHybrid, 2);
7308edf6225SMatthew G. Knepley   *isHybrid = prob->isHybrid;
7318edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7328edf6225SMatthew G. Knepley }
7338edf6225SMatthew G. Knepley 
7348edf6225SMatthew G. Knepley /*@
7358edf6225SMatthew G. Knepley   PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell
7368edf6225SMatthew G. Knepley 
7378edf6225SMatthew G. Knepley   Not collective
7388edf6225SMatthew G. Knepley 
7398edf6225SMatthew G. Knepley   Input Parameters:
7408edf6225SMatthew G. Knepley + prob - The PetscDS object
7418edf6225SMatthew G. Knepley - isHybrid - The flag
7428edf6225SMatthew G. Knepley 
7438edf6225SMatthew G. Knepley   Level: developer
7448edf6225SMatthew G. Knepley 
7458edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate()
7468edf6225SMatthew G. Knepley @*/
7478edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid)
7488edf6225SMatthew G. Knepley {
7498edf6225SMatthew G. Knepley   PetscFunctionBegin;
7508edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7518edf6225SMatthew G. Knepley   prob->isHybrid = isHybrid;
7528edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7538edf6225SMatthew G. Knepley }
7548edf6225SMatthew G. Knepley 
7558edf6225SMatthew G. Knepley /*@
756bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
757bc4ae4beSMatthew G. Knepley 
758bc4ae4beSMatthew G. Knepley   Not collective
759bc4ae4beSMatthew G. Knepley 
760bc4ae4beSMatthew G. Knepley   Input Parameter:
761bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
762bc4ae4beSMatthew G. Knepley 
763bc4ae4beSMatthew G. Knepley   Output Parameter:
764bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
765bc4ae4beSMatthew G. Knepley 
766bc4ae4beSMatthew G. Knepley   Level: beginner
767bc4ae4beSMatthew G. Knepley 
768bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
769bc4ae4beSMatthew G. Knepley @*/
7702764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
7712764a2aaSMatthew G. Knepley {
7722764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7732764a2aaSMatthew G. Knepley 
7742764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7752764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7762764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
7772764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
7782764a2aaSMatthew G. Knepley   *dim = prob->totDim;
7792764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7802764a2aaSMatthew G. Knepley }
7812764a2aaSMatthew G. Knepley 
782bc4ae4beSMatthew G. Knepley /*@
783bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
784bc4ae4beSMatthew G. Knepley 
785bc4ae4beSMatthew G. Knepley   Not collective
786bc4ae4beSMatthew G. Knepley 
787bc4ae4beSMatthew G. Knepley   Input Parameter:
788bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
789bc4ae4beSMatthew G. Knepley 
790bc4ae4beSMatthew G. Knepley   Output Parameter:
791bc4ae4beSMatthew G. Knepley . dim - The total number of components
792bc4ae4beSMatthew G. Knepley 
793bc4ae4beSMatthew G. Knepley   Level: beginner
794bc4ae4beSMatthew G. Knepley 
795bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
796bc4ae4beSMatthew G. Knepley @*/
7972764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
7982764a2aaSMatthew G. Knepley {
7992764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8002764a2aaSMatthew G. Knepley 
8012764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8022764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8032764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
8042764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
8052764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
8062764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8072764a2aaSMatthew G. Knepley }
8082764a2aaSMatthew G. Knepley 
809bc4ae4beSMatthew G. Knepley /*@
810bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
811bc4ae4beSMatthew G. Knepley 
812bc4ae4beSMatthew G. Knepley   Not collective
813bc4ae4beSMatthew G. Knepley 
814bc4ae4beSMatthew G. Knepley   Input Parameters:
815bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
816bc4ae4beSMatthew G. Knepley - f - The field number
817bc4ae4beSMatthew G. Knepley 
818bc4ae4beSMatthew G. Knepley   Output Parameter:
819bc4ae4beSMatthew G. Knepley . disc - The discretization object
820bc4ae4beSMatthew G. Knepley 
821bc4ae4beSMatthew G. Knepley   Level: beginner
822bc4ae4beSMatthew G. Knepley 
823f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
824bc4ae4beSMatthew G. Knepley @*/
8252764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
8262764a2aaSMatthew G. Knepley {
827*6528b96dSMatthew G. Knepley   PetscFunctionBeginHot;
8282764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8292764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
8302764a2aaSMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
8312764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
8322764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8332764a2aaSMatthew G. Knepley }
8342764a2aaSMatthew G. Knepley 
835bc4ae4beSMatthew G. Knepley /*@
836bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
837bc4ae4beSMatthew G. Knepley 
838bc4ae4beSMatthew G. Knepley   Not collective
839bc4ae4beSMatthew G. Knepley 
840bc4ae4beSMatthew G. Knepley   Input Parameters:
841bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
842bc4ae4beSMatthew G. Knepley . f - The field number
843bc4ae4beSMatthew G. Knepley - disc - The discretization object
844bc4ae4beSMatthew G. Knepley 
845bc4ae4beSMatthew G. Knepley   Level: beginner
846bc4ae4beSMatthew G. Knepley 
847bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
848bc4ae4beSMatthew G. Knepley @*/
8492764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
8502764a2aaSMatthew G. Knepley {
8512764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8522764a2aaSMatthew G. Knepley 
8532764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8542764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
855665f567fSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
8562764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
8572764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
858c10f2116SMatthew G. Knepley   ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);
8592764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
8602764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
861665f567fSMatthew G. Knepley   if (disc) {
862249df284SMatthew G. Knepley     PetscClassId id;
863249df284SMatthew G. Knepley 
864249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
8651cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
8661cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr);
8671cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
8681cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr);
869a6cbbb48SMatthew G. Knepley     }
870f9244615SMatthew G. Knepley     ierr = PetscDSSetJetDegree(prob, f, 1);CHKERRQ(ierr);
871249df284SMatthew G. Knepley   }
8722764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8732764a2aaSMatthew G. Knepley }
8742764a2aaSMatthew G. Knepley 
875bc4ae4beSMatthew G. Knepley /*@
876*6528b96dSMatthew G. Knepley   PetscDSGetWeakForm - Returns the weak form object
877*6528b96dSMatthew G. Knepley 
878*6528b96dSMatthew G. Knepley   Not collective
879*6528b96dSMatthew G. Knepley 
880*6528b96dSMatthew G. Knepley   Input Parameter:
881*6528b96dSMatthew G. Knepley . ds - The PetscDS object
882*6528b96dSMatthew G. Knepley 
883*6528b96dSMatthew G. Knepley   Output Parameter:
884*6528b96dSMatthew G. Knepley . wf - The weak form object
885*6528b96dSMatthew G. Knepley 
886*6528b96dSMatthew G. Knepley   Level: beginner
887*6528b96dSMatthew G. Knepley 
888*6528b96dSMatthew G. Knepley .seealso: PetscDSSetWeakForm(), PetscDSGetNumFields(), PetscDSCreate()
889*6528b96dSMatthew G. Knepley @*/
890*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf)
891*6528b96dSMatthew G. Knepley {
892*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
893*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
894*6528b96dSMatthew G. Knepley   PetscValidPointer(wf, 2);
895*6528b96dSMatthew G. Knepley   *wf = ds->wf;
896*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
897*6528b96dSMatthew G. Knepley }
898*6528b96dSMatthew G. Knepley 
899*6528b96dSMatthew G. Knepley /*@
900*6528b96dSMatthew G. Knepley   PetscDSSetWeakForm - Sets the weak form object
901*6528b96dSMatthew G. Knepley 
902*6528b96dSMatthew G. Knepley   Not collective
903*6528b96dSMatthew G. Knepley 
904*6528b96dSMatthew G. Knepley   Input Parameters:
905*6528b96dSMatthew G. Knepley + ds - The PetscDS object
906*6528b96dSMatthew G. Knepley - wf - The weak form object
907*6528b96dSMatthew G. Knepley 
908*6528b96dSMatthew G. Knepley   Level: beginner
909*6528b96dSMatthew G. Knepley 
910*6528b96dSMatthew G. Knepley .seealso: PetscDSGetWeakForm(), PetscDSGetNumFields(), PetscDSCreate()
911*6528b96dSMatthew G. Knepley @*/
912*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf)
913*6528b96dSMatthew G. Knepley {
914*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
915*6528b96dSMatthew G. Knepley 
916*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
917*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
918*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2);
919*6528b96dSMatthew G. Knepley   ierr = PetscObjectDereference((PetscObject) ds->wf);CHKERRQ(ierr);
920*6528b96dSMatthew G. Knepley   ds->wf = wf;
921*6528b96dSMatthew G. Knepley   ierr = PetscObjectReference((PetscObject) wf);CHKERRQ(ierr);
922*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(wf, ds->Nf);CHKERRQ(ierr);
923*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
924*6528b96dSMatthew G. Knepley }
925*6528b96dSMatthew G. Knepley 
926*6528b96dSMatthew G. Knepley /*@
927bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
928bc4ae4beSMatthew G. Knepley 
929bc4ae4beSMatthew G. Knepley   Not collective
930bc4ae4beSMatthew G. Knepley 
931bc4ae4beSMatthew G. Knepley   Input Parameters:
932bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
933bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
934bc4ae4beSMatthew G. Knepley 
935bc4ae4beSMatthew G. Knepley   Level: beginner
936bc4ae4beSMatthew G. Knepley 
937bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
938bc4ae4beSMatthew G. Knepley @*/
9392764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
9402764a2aaSMatthew G. Knepley {
9412764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9422764a2aaSMatthew G. Knepley 
9432764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9442764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
9452764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9462764a2aaSMatthew G. Knepley }
9472764a2aaSMatthew G. Knepley 
948249df284SMatthew G. Knepley /*@
949083401c6SMatthew G. Knepley   PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS
950083401c6SMatthew G. Knepley 
951083401c6SMatthew G. Knepley   Not collective
952083401c6SMatthew G. Knepley 
953083401c6SMatthew G. Knepley   Input Parameter:
954083401c6SMatthew G. Knepley . prob - The PetscDS object
955083401c6SMatthew G. Knepley 
956083401c6SMatthew G. Knepley   Output Parameter:
957083401c6SMatthew G. Knepley . q - The quadrature object
958083401c6SMatthew G. Knepley 
959083401c6SMatthew G. Knepley Level: intermediate
960083401c6SMatthew G. Knepley 
961083401c6SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
962083401c6SMatthew G. Knepley @*/
963083401c6SMatthew G. Knepley PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q)
964083401c6SMatthew G. Knepley {
965083401c6SMatthew G. Knepley   PetscObject    obj;
966083401c6SMatthew G. Knepley   PetscClassId   id;
967083401c6SMatthew G. Knepley   PetscErrorCode ierr;
968083401c6SMatthew G. Knepley 
969083401c6SMatthew G. Knepley   PetscFunctionBegin;
970083401c6SMatthew G. Knepley   *q = NULL;
971083401c6SMatthew G. Knepley   if (!prob->Nf) PetscFunctionReturn(0);
972083401c6SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
973083401c6SMatthew G. Knepley   ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
974083401c6SMatthew G. Knepley   if      (id == PETSCFE_CLASSID) {ierr = PetscFEGetQuadrature((PetscFE) obj, q);CHKERRQ(ierr);}
975083401c6SMatthew G. Knepley   else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetQuadrature((PetscFV) obj, q);CHKERRQ(ierr);}
976083401c6SMatthew G. Knepley   else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
977083401c6SMatthew G. Knepley   PetscFunctionReturn(0);
978083401c6SMatthew G. Knepley }
979083401c6SMatthew G. Knepley 
980083401c6SMatthew G. Knepley /*@
981249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
982249df284SMatthew G. Knepley 
983249df284SMatthew G. Knepley   Not collective
984249df284SMatthew G. Knepley 
985249df284SMatthew G. Knepley   Input Parameters:
986249df284SMatthew G. Knepley + prob - The PetscDS object
987249df284SMatthew G. Knepley - f - The field number
988249df284SMatthew G. Knepley 
989249df284SMatthew G. Knepley   Output Parameter:
990249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
991249df284SMatthew G. Knepley 
992249df284SMatthew G. Knepley   Level: developer
993249df284SMatthew G. Knepley 
994f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
995249df284SMatthew G. Knepley @*/
996249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
997249df284SMatthew G. Knepley {
998249df284SMatthew G. Knepley   PetscFunctionBegin;
999249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1000249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
1001249df284SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
1002249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
1003249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1004249df284SMatthew G. Knepley }
1005249df284SMatthew G. Knepley 
1006249df284SMatthew G. Knepley /*@
1007249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
1008249df284SMatthew G. Knepley 
1009249df284SMatthew G. Knepley   Not collective
1010249df284SMatthew G. Knepley 
1011249df284SMatthew G. Knepley   Input Parameters:
1012249df284SMatthew G. Knepley + prob - The PetscDS object
1013249df284SMatthew G. Knepley . f - The field number
1014249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
1015249df284SMatthew G. Knepley 
1016249df284SMatthew G. Knepley   Level: developer
1017249df284SMatthew G. Knepley 
1018f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1019249df284SMatthew G. Knepley @*/
1020249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
1021249df284SMatthew G. Knepley {
1022249df284SMatthew G. Knepley   PetscFunctionBegin;
1023249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1024249df284SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
1025249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
1026249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1027249df284SMatthew G. Knepley }
1028249df284SMatthew G. Knepley 
1029f9244615SMatthew G. Knepley /*@
1030f9244615SMatthew G. Knepley   PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1031f9244615SMatthew G. Knepley 
1032f9244615SMatthew G. Knepley   Not collective
1033f9244615SMatthew G. Knepley 
1034f9244615SMatthew G. Knepley   Input Parameters:
1035f9244615SMatthew G. Knepley + ds - The PetscDS object
1036f9244615SMatthew G. Knepley - f  - The field number
1037f9244615SMatthew G. Knepley 
1038f9244615SMatthew G. Knepley   Output Parameter:
1039f9244615SMatthew G. Knepley . k  - The highest derivative we need to tabulate
1040f9244615SMatthew G. Knepley 
1041f9244615SMatthew G. Knepley   Level: developer
1042f9244615SMatthew G. Knepley 
1043f9244615SMatthew G. Knepley .seealso: PetscDSSetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1044f9244615SMatthew G. Knepley @*/
1045f9244615SMatthew G. Knepley PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k)
1046f9244615SMatthew G. Knepley {
1047f9244615SMatthew G. Knepley   PetscFunctionBegin;
1048f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1049f9244615SMatthew G. Knepley   PetscValidPointer(k, 3);
1050f9244615SMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1051f9244615SMatthew G. Knepley   *k = ds->jetDegree[f];
1052f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1053f9244615SMatthew G. Knepley }
1054f9244615SMatthew G. Knepley 
1055f9244615SMatthew G. Knepley /*@
1056f9244615SMatthew G. Knepley   PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1057f9244615SMatthew G. Knepley 
1058f9244615SMatthew G. Knepley   Not collective
1059f9244615SMatthew G. Knepley 
1060f9244615SMatthew G. Knepley   Input Parameters:
1061f9244615SMatthew G. Knepley + ds - The PetscDS object
1062f9244615SMatthew G. Knepley . f  - The field number
1063f9244615SMatthew G. Knepley - k  - The highest derivative we need to tabulate
1064f9244615SMatthew G. Knepley 
1065f9244615SMatthew G. Knepley   Level: developer
1066f9244615SMatthew G. Knepley 
1067f9244615SMatthew G. Knepley .seealso: PetscDSGetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1068f9244615SMatthew G. Knepley @*/
1069f9244615SMatthew G. Knepley PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k)
1070f9244615SMatthew G. Knepley {
1071f9244615SMatthew G. Knepley   PetscFunctionBegin;
1072f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1073f9244615SMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1074f9244615SMatthew G. Knepley   ds->jetDegree[f] = k;
1075f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1076f9244615SMatthew G. Knepley }
1077f9244615SMatthew G. Knepley 
1078*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS ds, PetscInt f,
107930b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1080194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1081194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
108297b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
10832764a2aaSMatthew G. Knepley {
1084*6528b96dSMatthew G. Knepley   PetscPointFunc *tmp;
1085*6528b96dSMatthew G. Knepley   PetscInt        n;
1086*6528b96dSMatthew G. Knepley   PetscErrorCode  ierr;
1087*6528b96dSMatthew G. Knepley 
10882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1089*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1090*6528b96dSMatthew G. Knepley   PetscValidPointer(obj, 3);
1091*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1092*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetObjective(ds->wf, NULL, 0, f, &n, &tmp);CHKERRQ(ierr);
1093*6528b96dSMatthew G. Knepley   *obj = tmp ? tmp[0] : NULL;
10942764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10952764a2aaSMatthew G. Knepley }
10962764a2aaSMatthew G. Knepley 
1097*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS ds, PetscInt f,
109830b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1099194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1100194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
110197b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
11022764a2aaSMatthew G. Knepley {
11032764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
11042764a2aaSMatthew G. Knepley 
11052764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1106*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1107*6528b96dSMatthew G. Knepley   if (obj) PetscValidFunction(obj, 3);
11082764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1109*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, obj);CHKERRQ(ierr);
11102764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11112764a2aaSMatthew G. Knepley }
11122764a2aaSMatthew G. Knepley 
1113194d53e6SMatthew G. Knepley /*@C
1114194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1115194d53e6SMatthew G. Knepley 
1116194d53e6SMatthew G. Knepley   Not collective
1117194d53e6SMatthew G. Knepley 
1118194d53e6SMatthew G. Knepley   Input Parameters:
1119*6528b96dSMatthew G. Knepley + ds - The PetscDS
1120194d53e6SMatthew G. Knepley - f  - The test field number
1121194d53e6SMatthew G. Knepley 
1122194d53e6SMatthew G. Knepley   Output Parameters:
1123194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1124194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1125194d53e6SMatthew G. Knepley 
1126194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1127194d53e6SMatthew G. Knepley 
1128194d53e6SMatthew G. Knepley   \int_\Omega \phi f_0(u, u_t, \nabla u, x, t) + \nabla\phi \cdot {\vec f}_1(u, u_t, \nabla u, x, t)
1129194d53e6SMatthew G. Knepley 
1130194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1131194d53e6SMatthew G. Knepley 
113230b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1133194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1134194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
113530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1136194d53e6SMatthew G. Knepley 
1137194d53e6SMatthew G. Knepley + dim - the spatial dimension
1138194d53e6SMatthew G. Knepley . Nf - the number of fields
1139194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1140194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1141194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1142194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1143194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1144194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1145194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1146194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1147194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1148194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1149194d53e6SMatthew G. Knepley . t - current time
1150194d53e6SMatthew G. Knepley . x - coordinates of the current point
115197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
115297b6e6e8SMatthew G. Knepley . constants - constant parameters
1153194d53e6SMatthew G. Knepley - f0 - output values at the current point
1154194d53e6SMatthew G. Knepley 
1155194d53e6SMatthew G. Knepley   Level: intermediate
1156194d53e6SMatthew G. Knepley 
1157194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
1158194d53e6SMatthew G. Knepley @*/
1159*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS ds, PetscInt f,
116030b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1161194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1162194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
116397b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
116430b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1165194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1166194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
116797b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
11682764a2aaSMatthew G. Knepley {
1169*6528b96dSMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
1170*6528b96dSMatthew G. Knepley   PetscInt        n0, n1;
1171*6528b96dSMatthew G. Knepley   PetscErrorCode  ierr;
1172*6528b96dSMatthew G. Knepley 
11732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1174*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1175*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1176*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetResidual(ds->wf, NULL, 0, f, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
1177*6528b96dSMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
1178*6528b96dSMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
11792764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11802764a2aaSMatthew G. Knepley }
11812764a2aaSMatthew G. Knepley 
1182194d53e6SMatthew G. Knepley /*@C
1183194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1184194d53e6SMatthew G. Knepley 
1185194d53e6SMatthew G. Knepley   Not collective
1186194d53e6SMatthew G. Knepley 
1187194d53e6SMatthew G. Knepley   Input Parameters:
1188*6528b96dSMatthew G. Knepley + ds - The PetscDS
1189194d53e6SMatthew G. Knepley . f  - The test field number
1190194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1191194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1192194d53e6SMatthew G. Knepley 
1193194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1194194d53e6SMatthew G. Knepley 
1195194d53e6SMatthew G. Knepley   \int_\Omega \phi f_0(u, u_t, \nabla u, x, t) + \nabla\phi \cdot {\vec f}_1(u, u_t, \nabla u, x, t)
1196194d53e6SMatthew G. Knepley 
1197194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1198194d53e6SMatthew G. Knepley 
119930b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1200194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1201194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
120230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1203194d53e6SMatthew G. Knepley 
1204194d53e6SMatthew G. Knepley + dim - the spatial dimension
1205194d53e6SMatthew G. Knepley . Nf - the number of fields
1206194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1207194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1208194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1209194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1210194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1211194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1212194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1213194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1214194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1215194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1216194d53e6SMatthew G. Knepley . t - current time
1217194d53e6SMatthew G. Knepley . x - coordinates of the current point
121897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
121997b6e6e8SMatthew G. Knepley . constants - constant parameters
1220194d53e6SMatthew G. Knepley - f0 - output values at the current point
1221194d53e6SMatthew G. Knepley 
1222194d53e6SMatthew G. Knepley   Level: intermediate
1223194d53e6SMatthew G. Knepley 
1224194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1225194d53e6SMatthew G. Knepley @*/
1226*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS ds, PetscInt f,
122730b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1228194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1229194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123097b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
123130b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1232194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1233194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123497b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
12352764a2aaSMatthew G. Knepley {
12362764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
12372764a2aaSMatthew G. Knepley 
12382764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1239*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1240f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1241f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
12422764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1243*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, f0, 0, f1);CHKERRQ(ierr);
12442764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12452764a2aaSMatthew G. Knepley }
12462764a2aaSMatthew G. Knepley 
12473e75805dSMatthew G. Knepley /*@C
12483e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
12493e75805dSMatthew G. Knepley 
12503e75805dSMatthew G. Knepley   Not collective
12513e75805dSMatthew G. Knepley 
12523e75805dSMatthew G. Knepley   Input Parameter:
12533e75805dSMatthew G. Knepley . prob - The PetscDS
12543e75805dSMatthew G. Knepley 
12553e75805dSMatthew G. Knepley   Output Parameter:
12563e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
12573e75805dSMatthew G. Knepley 
12583e75805dSMatthew G. Knepley   Level: intermediate
12593e75805dSMatthew G. Knepley 
12603e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
12613e75805dSMatthew G. Knepley @*/
1262*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac)
12633e75805dSMatthew G. Knepley {
1264*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
12653e75805dSMatthew G. Knepley 
12663e75805dSMatthew G. Knepley   PetscFunctionBegin;
1267*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1268*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobian(ds->wf, hasJac);CHKERRQ(ierr);
12693e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
12703e75805dSMatthew G. Knepley }
12713e75805dSMatthew G. Knepley 
1272194d53e6SMatthew G. Knepley /*@C
1273194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1274194d53e6SMatthew G. Knepley 
1275194d53e6SMatthew G. Knepley   Not collective
1276194d53e6SMatthew G. Knepley 
1277194d53e6SMatthew G. Knepley   Input Parameters:
1278*6528b96dSMatthew G. Knepley + ds - The PetscDS
1279194d53e6SMatthew G. Knepley . f  - The test field number
1280194d53e6SMatthew G. Knepley - g  - The field number
1281194d53e6SMatthew G. Knepley 
1282194d53e6SMatthew G. Knepley   Output Parameters:
1283194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1284194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1285194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1286194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1287194d53e6SMatthew G. Knepley 
1288194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1289194d53e6SMatthew G. Knepley 
1290194d53e6SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1291194d53e6SMatthew G. Knepley 
1292194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1293194d53e6SMatthew G. Knepley 
129430b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1295194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1296194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
129730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1298194d53e6SMatthew G. Knepley 
1299194d53e6SMatthew G. Knepley + dim - the spatial dimension
1300194d53e6SMatthew G. Knepley . Nf - the number of fields
1301194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1302194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1303194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1304194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1305194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1306194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1307194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1308194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1309194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1310194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1311194d53e6SMatthew G. Knepley . t - current time
13122aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1313194d53e6SMatthew G. Knepley . x - coordinates of the current point
131497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
131597b6e6e8SMatthew G. Knepley . constants - constant parameters
1316194d53e6SMatthew G. Knepley - g0 - output values at the current point
1317194d53e6SMatthew G. Knepley 
1318194d53e6SMatthew G. Knepley   Level: intermediate
1319194d53e6SMatthew G. Knepley 
1320194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1321194d53e6SMatthew G. Knepley @*/
1322*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS ds, PetscInt f, PetscInt g,
132330b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1324194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1325194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
132697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
132730b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1328194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1329194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
133097b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
133130b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1332194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1333194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
133497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
133530b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1336194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1337194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
133897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
13392764a2aaSMatthew G. Knepley {
1340*6528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
1341*6528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
1342*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1343*6528b96dSMatthew G. Knepley 
13442764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1345*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1346*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1347*6528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
1348*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
1349*6528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
1350*6528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
1351*6528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
1352*6528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
13532764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
13542764a2aaSMatthew G. Knepley }
13552764a2aaSMatthew G. Knepley 
1356194d53e6SMatthew G. Knepley /*@C
1357194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1358194d53e6SMatthew G. Knepley 
1359194d53e6SMatthew G. Knepley   Not collective
1360194d53e6SMatthew G. Knepley 
1361194d53e6SMatthew G. Knepley   Input Parameters:
1362*6528b96dSMatthew G. Knepley + ds - The PetscDS
1363194d53e6SMatthew G. Knepley . f  - The test field number
1364194d53e6SMatthew G. Knepley . g  - The field number
1365194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1366194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1367194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1368194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1369194d53e6SMatthew G. Knepley 
1370194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1371194d53e6SMatthew G. Knepley 
1372194d53e6SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1373194d53e6SMatthew G. Knepley 
1374194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1375194d53e6SMatthew G. Knepley 
137630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1377194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1378194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
137930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1380194d53e6SMatthew G. Knepley 
1381194d53e6SMatthew G. Knepley + dim - the spatial dimension
1382194d53e6SMatthew G. Knepley . Nf - the number of fields
1383194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1384194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1385194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1386194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1387194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1388194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1389194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1390194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1391194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1392194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1393194d53e6SMatthew G. Knepley . t - current time
13942aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1395194d53e6SMatthew G. Knepley . x - coordinates of the current point
139697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
139797b6e6e8SMatthew G. Knepley . constants - constant parameters
1398194d53e6SMatthew G. Knepley - g0 - output values at the current point
1399194d53e6SMatthew G. Knepley 
1400194d53e6SMatthew G. Knepley   Level: intermediate
1401194d53e6SMatthew G. Knepley 
1402194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1403194d53e6SMatthew G. Knepley @*/
1404*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS ds, PetscInt f, PetscInt g,
140530b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1406194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1407194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
140897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
140930b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1410194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1411194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
141297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
141330b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1414194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1415194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
141697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
141730b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1418194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1419194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
142097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
14212764a2aaSMatthew G. Knepley {
14222764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
14232764a2aaSMatthew G. Knepley 
14242764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1425*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
14262764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
14272764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
14282764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
14292764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
14302764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
14312764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1432*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
14332764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
14342764a2aaSMatthew G. Knepley }
14352764a2aaSMatthew G. Knepley 
1436475e0ac9SMatthew G. Knepley /*@C
143755c1f793SMatthew G. Knepley   PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner
143855c1f793SMatthew G. Knepley 
143955c1f793SMatthew G. Knepley   Not collective
144055c1f793SMatthew G. Knepley 
144155c1f793SMatthew G. Knepley   Input Parameters:
144255c1f793SMatthew G. Knepley + prob - The PetscDS
144355c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
144455c1f793SMatthew G. Knepley 
144555c1f793SMatthew G. Knepley   Level: intermediate
144655c1f793SMatthew G. Knepley 
144755c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
144855c1f793SMatthew G. Knepley @*/
144955c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
145055c1f793SMatthew G. Knepley {
145155c1f793SMatthew G. Knepley   PetscFunctionBegin;
145255c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
145355c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
145455c1f793SMatthew G. Knepley   PetscFunctionReturn(0);
145555c1f793SMatthew G. Knepley }
145655c1f793SMatthew G. Knepley 
145755c1f793SMatthew G. Knepley /*@C
1458475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1459475e0ac9SMatthew G. Knepley 
1460475e0ac9SMatthew G. Knepley   Not collective
1461475e0ac9SMatthew G. Knepley 
1462475e0ac9SMatthew G. Knepley   Input Parameter:
1463475e0ac9SMatthew G. Knepley . prob - The PetscDS
1464475e0ac9SMatthew G. Knepley 
1465475e0ac9SMatthew G. Knepley   Output Parameter:
1466475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1467475e0ac9SMatthew G. Knepley 
1468475e0ac9SMatthew G. Knepley   Level: intermediate
1469475e0ac9SMatthew G. Knepley 
1470475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1471475e0ac9SMatthew G. Knepley @*/
1472*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre)
1473475e0ac9SMatthew G. Knepley {
1474*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1475475e0ac9SMatthew G. Knepley 
1476475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1477*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1478475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
1479*6528b96dSMatthew G. Knepley   if (!ds->useJacPre) PetscFunctionReturn(0);
1480*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre);CHKERRQ(ierr);
1481475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1482475e0ac9SMatthew G. Knepley }
1483475e0ac9SMatthew G. Knepley 
1484475e0ac9SMatthew G. Knepley /*@C
1485475e0ac9SMatthew G. Knepley   PetscDSGetJacobianPreconditioner - Get the pointwise Jacobian preconditioner function for given test and basis field. If this is missing, the system matrix is used to build the preconditioner.
1486475e0ac9SMatthew G. Knepley 
1487475e0ac9SMatthew G. Knepley   Not collective
1488475e0ac9SMatthew G. Knepley 
1489475e0ac9SMatthew G. Knepley   Input Parameters:
1490*6528b96dSMatthew G. Knepley + ds - The PetscDS
1491475e0ac9SMatthew G. Knepley . f  - The test field number
1492475e0ac9SMatthew G. Knepley - g  - The field number
1493475e0ac9SMatthew G. Knepley 
1494475e0ac9SMatthew G. Knepley   Output Parameters:
1495475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1496475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1497475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1498475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1499475e0ac9SMatthew G. Knepley 
1500475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1501475e0ac9SMatthew G. Knepley 
1502475e0ac9SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1503475e0ac9SMatthew G. Knepley 
1504475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1505475e0ac9SMatthew G. Knepley 
1506475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1507475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1508475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1509475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1510475e0ac9SMatthew G. Knepley 
1511475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1512475e0ac9SMatthew G. Knepley . Nf - the number of fields
1513475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1514475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1515475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1516475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1517475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1518475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1519475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1520475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1521475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1522475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1523475e0ac9SMatthew G. Knepley . t - current time
1524475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1525475e0ac9SMatthew G. Knepley . x - coordinates of the current point
152697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
152797b6e6e8SMatthew G. Knepley . constants - constant parameters
1528475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1529475e0ac9SMatthew G. Knepley 
1530475e0ac9SMatthew G. Knepley   Level: intermediate
1531475e0ac9SMatthew G. Knepley 
1532475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1533475e0ac9SMatthew G. Knepley @*/
1534*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1535475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1536475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1537475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
153897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1539475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1540475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1541475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1543475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1544475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1545475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1547475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1548475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1549475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
155097b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1551475e0ac9SMatthew G. Knepley {
1552*6528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
1553*6528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
1554*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1555*6528b96dSMatthew G. Knepley 
1556475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1557*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1558*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1559*6528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
1560*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
1561*6528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
1562*6528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
1563*6528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
1564*6528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1565475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1566475e0ac9SMatthew G. Knepley }
1567475e0ac9SMatthew G. Knepley 
1568475e0ac9SMatthew G. Knepley /*@C
1569475e0ac9SMatthew G. Knepley   PetscDSSetJacobianPreconditioner - Set the pointwise Jacobian preconditioner function for given test and basis fields. If this is missing, the system matrix is used to build the preconditioner.
1570475e0ac9SMatthew G. Knepley 
1571475e0ac9SMatthew G. Knepley   Not collective
1572475e0ac9SMatthew G. Knepley 
1573475e0ac9SMatthew G. Knepley   Input Parameters:
1574*6528b96dSMatthew G. Knepley + ds - The PetscDS
1575475e0ac9SMatthew G. Knepley . f  - The test field number
1576475e0ac9SMatthew G. Knepley . g  - The field number
1577475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1578475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1579475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1580475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1581475e0ac9SMatthew G. Knepley 
1582475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1583475e0ac9SMatthew G. Knepley 
1584475e0ac9SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1585475e0ac9SMatthew G. Knepley 
1586475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1587475e0ac9SMatthew G. Knepley 
1588475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1589475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1590475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1591475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1592475e0ac9SMatthew G. Knepley 
1593475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1594475e0ac9SMatthew G. Knepley . Nf - the number of fields
1595475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1596475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1597475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1598475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1599475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1600475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1601475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1602475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1603475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1604475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1605475e0ac9SMatthew G. Knepley . t - current time
1606475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1607475e0ac9SMatthew G. Knepley . x - coordinates of the current point
160897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
160997b6e6e8SMatthew G. Knepley . constants - constant parameters
1610475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1611475e0ac9SMatthew G. Knepley 
1612475e0ac9SMatthew G. Knepley   Level: intermediate
1613475e0ac9SMatthew G. Knepley 
1614475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1615475e0ac9SMatthew G. Knepley @*/
1616*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1617475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1618475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1619475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1621475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1622475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1623475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162497b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1625475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1626475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1627475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1629475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1630475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1631475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
163297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1633475e0ac9SMatthew G. Knepley {
1634475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1635475e0ac9SMatthew G. Knepley 
1636475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1637*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1638475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1639475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1640475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1641475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1642475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1643475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1644*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
1645475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1646475e0ac9SMatthew G. Knepley }
1647475e0ac9SMatthew G. Knepley 
1648b7e05686SMatthew G. Knepley /*@C
1649b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1650b7e05686SMatthew G. Knepley 
1651b7e05686SMatthew G. Knepley   Not collective
1652b7e05686SMatthew G. Knepley 
1653b7e05686SMatthew G. Knepley   Input Parameter:
1654*6528b96dSMatthew G. Knepley . ds - The PetscDS
1655b7e05686SMatthew G. Knepley 
1656b7e05686SMatthew G. Knepley   Output Parameter:
1657b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1658b7e05686SMatthew G. Knepley 
1659b7e05686SMatthew G. Knepley   Level: intermediate
1660b7e05686SMatthew G. Knepley 
1661b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1662b7e05686SMatthew G. Knepley @*/
1663*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac)
1664b7e05686SMatthew G. Knepley {
1665*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1666b7e05686SMatthew G. Knepley 
1667b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1668*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1669*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac);CHKERRQ(ierr);
1670b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1671b7e05686SMatthew G. Knepley }
1672b7e05686SMatthew G. Knepley 
1673b7e05686SMatthew G. Knepley /*@C
1674b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1675b7e05686SMatthew G. Knepley 
1676b7e05686SMatthew G. Knepley   Not collective
1677b7e05686SMatthew G. Knepley 
1678b7e05686SMatthew G. Knepley   Input Parameters:
1679*6528b96dSMatthew G. Knepley + ds - The PetscDS
1680b7e05686SMatthew G. Knepley . f  - The test field number
1681b7e05686SMatthew G. Knepley - g  - The field number
1682b7e05686SMatthew G. Knepley 
1683b7e05686SMatthew G. Knepley   Output Parameters:
1684b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1685b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1686b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1687b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1688b7e05686SMatthew G. Knepley 
1689b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1690b7e05686SMatthew G. Knepley 
1691b7e05686SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1692b7e05686SMatthew G. Knepley 
1693b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1694b7e05686SMatthew G. Knepley 
1695b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1696b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1697b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1698b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1699b7e05686SMatthew G. Knepley 
1700b7e05686SMatthew G. Knepley + dim - the spatial dimension
1701b7e05686SMatthew G. Knepley . Nf - the number of fields
1702b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1703b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1704b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1705b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1706b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1707b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1708b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1709b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1710b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1711b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1712b7e05686SMatthew G. Knepley . t - current time
1713b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1714b7e05686SMatthew G. Knepley . x - coordinates of the current point
171597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
171697b6e6e8SMatthew G. Knepley . constants - constant parameters
1717b7e05686SMatthew G. Knepley - g0 - output values at the current point
1718b7e05686SMatthew G. Knepley 
1719b7e05686SMatthew G. Knepley   Level: intermediate
1720b7e05686SMatthew G. Knepley 
1721b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1722b7e05686SMatthew G. Knepley @*/
1723*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
1724b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1725b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1726b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
172797b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1728b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1729b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1730b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
173197b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1732b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1733b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1734b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
173597b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1736b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1737b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1738b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
173997b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1740b7e05686SMatthew G. Knepley {
1741*6528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
1742*6528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
1743*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1744*6528b96dSMatthew G. Knepley 
1745b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1746*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1747*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1748*6528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
1749*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
1750*6528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
1751*6528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
1752*6528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
1753*6528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1754b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1755b7e05686SMatthew G. Knepley }
1756b7e05686SMatthew G. Knepley 
1757b7e05686SMatthew G. Knepley /*@C
1758b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1759b7e05686SMatthew G. Knepley 
1760b7e05686SMatthew G. Knepley   Not collective
1761b7e05686SMatthew G. Knepley 
1762b7e05686SMatthew G. Knepley   Input Parameters:
1763*6528b96dSMatthew G. Knepley + ds - The PetscDS
1764b7e05686SMatthew G. Knepley . f  - The test field number
1765b7e05686SMatthew G. Knepley . g  - The field number
1766b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1767b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1768b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1769b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1770b7e05686SMatthew G. Knepley 
1771b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1772b7e05686SMatthew G. Knepley 
1773b7e05686SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1774b7e05686SMatthew G. Knepley 
1775b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1776b7e05686SMatthew G. Knepley 
1777b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1778b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1779b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1780b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1781b7e05686SMatthew G. Knepley 
1782b7e05686SMatthew G. Knepley + dim - the spatial dimension
1783b7e05686SMatthew G. Knepley . Nf - the number of fields
1784b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1785b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1786b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1787b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1788b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1789b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1790b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1791b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1792b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1793b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1794b7e05686SMatthew G. Knepley . t - current time
1795b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1796b7e05686SMatthew G. Knepley . x - coordinates of the current point
179797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
179897b6e6e8SMatthew G. Knepley . constants - constant parameters
1799b7e05686SMatthew G. Knepley - g0 - output values at the current point
1800b7e05686SMatthew G. Knepley 
1801b7e05686SMatthew G. Knepley   Level: intermediate
1802b7e05686SMatthew G. Knepley 
1803b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1804b7e05686SMatthew G. Knepley @*/
1805*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
1806b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1807b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1808b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
180997b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1810b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1811b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1812b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
181397b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1814b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1815b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1816b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
181797b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1818b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1819b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1820b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
182197b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1822b7e05686SMatthew G. Knepley {
1823b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1824b7e05686SMatthew G. Knepley 
1825b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1826*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1827b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1828b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1829b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1830b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1831b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1832b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1833*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
1834b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1835b7e05686SMatthew G. Knepley }
1836b7e05686SMatthew G. Knepley 
18370c2f2876SMatthew G. Knepley /*@C
18380c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
18390c2f2876SMatthew G. Knepley 
18400c2f2876SMatthew G. Knepley   Not collective
18410c2f2876SMatthew G. Knepley 
18420c2f2876SMatthew G. Knepley   Input Arguments:
1843*6528b96dSMatthew G. Knepley + ds - The PetscDS object
18440c2f2876SMatthew G. Knepley - f  - The field number
18450c2f2876SMatthew G. Knepley 
18460c2f2876SMatthew G. Knepley   Output Argument:
18470c2f2876SMatthew G. Knepley . r    - Riemann solver
18480c2f2876SMatthew G. Knepley 
18490c2f2876SMatthew G. Knepley   Calling sequence for r:
18500c2f2876SMatthew G. Knepley 
18515db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
18520c2f2876SMatthew G. Knepley 
18535db36cf9SMatthew G. Knepley + dim  - The spatial dimension
18545db36cf9SMatthew G. Knepley . Nf   - The number of fields
18555db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
18560c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
18570c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
18580c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
18590c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
186097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
186197b6e6e8SMatthew G. Knepley . constants - constant parameters
18620c2f2876SMatthew G. Knepley - ctx  - optional user context
18630c2f2876SMatthew G. Knepley 
18640c2f2876SMatthew G. Knepley   Level: intermediate
18650c2f2876SMatthew G. Knepley 
18660c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
18670c2f2876SMatthew G. Knepley @*/
1868*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS ds, PetscInt f,
186997b6e6e8SMatthew G. Knepley                                        void (**r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscInt numConstants, const PetscScalar constants[], PetscScalar flux[], void *ctx))
18700c2f2876SMatthew G. Knepley {
1871*6528b96dSMatthew G. Knepley   PetscRiemannFunc *tmp;
1872*6528b96dSMatthew G. Knepley   PetscInt          n;
1873*6528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
1874*6528b96dSMatthew G. Knepley 
18750c2f2876SMatthew G. Knepley   PetscFunctionBegin;
1876*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
18770c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
1878*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1879*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, &n, &tmp);CHKERRQ(ierr);
1880*6528b96dSMatthew G. Knepley   *r   = tmp ? tmp[0] : NULL;
18810c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18820c2f2876SMatthew G. Knepley }
18830c2f2876SMatthew G. Knepley 
18840c2f2876SMatthew G. Knepley /*@C
18850c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
18860c2f2876SMatthew G. Knepley 
18870c2f2876SMatthew G. Knepley   Not collective
18880c2f2876SMatthew G. Knepley 
18890c2f2876SMatthew G. Knepley   Input Arguments:
1890*6528b96dSMatthew G. Knepley + ds - The PetscDS object
18910c2f2876SMatthew G. Knepley . f  - The field number
18920c2f2876SMatthew G. Knepley - r  - Riemann solver
18930c2f2876SMatthew G. Knepley 
18940c2f2876SMatthew G. Knepley   Calling sequence for r:
18950c2f2876SMatthew G. Knepley 
18965db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
18970c2f2876SMatthew G. Knepley 
18985db36cf9SMatthew G. Knepley + dim  - The spatial dimension
18995db36cf9SMatthew G. Knepley . Nf   - The number of fields
19005db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
19010c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
19020c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
19030c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
19040c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
190597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
190697b6e6e8SMatthew G. Knepley . constants - constant parameters
19070c2f2876SMatthew G. Knepley - ctx  - optional user context
19080c2f2876SMatthew G. Knepley 
19090c2f2876SMatthew G. Knepley   Level: intermediate
19100c2f2876SMatthew G. Knepley 
19110c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
19120c2f2876SMatthew G. Knepley @*/
1913*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS ds, PetscInt f,
191497b6e6e8SMatthew G. Knepley                                        void (*r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscInt numConstants, const PetscScalar constants[], PetscScalar flux[], void *ctx))
19150c2f2876SMatthew G. Knepley {
19160c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
19170c2f2876SMatthew G. Knepley 
19180c2f2876SMatthew G. Knepley   PetscFunctionBegin;
1919*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1920de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
19210c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1922*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, r);CHKERRQ(ierr);
19230c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19240c2f2876SMatthew G. Knepley }
19250c2f2876SMatthew G. Knepley 
192632d2bbc9SMatthew G. Knepley /*@C
192732d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
192832d2bbc9SMatthew G. Knepley 
192932d2bbc9SMatthew G. Knepley   Not collective
193032d2bbc9SMatthew G. Knepley 
193132d2bbc9SMatthew G. Knepley   Input Parameters:
1932*6528b96dSMatthew G. Knepley + ds - The PetscDS
193332d2bbc9SMatthew G. Knepley - f  - The field number
193432d2bbc9SMatthew G. Knepley 
193532d2bbc9SMatthew G. Knepley   Output Parameters:
1936a2b725a8SWilliam Gropp . update - update function
193732d2bbc9SMatthew G. Knepley 
193832d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
193932d2bbc9SMatthew G. Knepley 
194032d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
194132d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
194232d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194332d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
194432d2bbc9SMatthew G. Knepley 
194532d2bbc9SMatthew G. Knepley + dim - the spatial dimension
194632d2bbc9SMatthew G. Knepley . Nf - the number of fields
194732d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
194832d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
194932d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
195032d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
195132d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
195232d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
195332d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
195432d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
195532d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
195632d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
195732d2bbc9SMatthew G. Knepley . t - current time
195832d2bbc9SMatthew G. Knepley . x - coordinates of the current point
195932d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
196032d2bbc9SMatthew G. Knepley 
196132d2bbc9SMatthew G. Knepley   Level: intermediate
196232d2bbc9SMatthew G. Knepley 
196332d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
196432d2bbc9SMatthew G. Knepley @*/
1965*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS ds, PetscInt f,
196632d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
196732d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
196832d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19693fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
197032d2bbc9SMatthew G. Knepley {
197132d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
1972*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1973*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1974*6528b96dSMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = ds->update[f];}
197532d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
197632d2bbc9SMatthew G. Knepley }
197732d2bbc9SMatthew G. Knepley 
197832d2bbc9SMatthew G. Knepley /*@C
19793fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
198032d2bbc9SMatthew G. Knepley 
198132d2bbc9SMatthew G. Knepley   Not collective
198232d2bbc9SMatthew G. Knepley 
198332d2bbc9SMatthew G. Knepley   Input Parameters:
1984*6528b96dSMatthew G. Knepley + ds     - The PetscDS
198532d2bbc9SMatthew G. Knepley . f      - The field number
198632d2bbc9SMatthew G. Knepley - update - update function
198732d2bbc9SMatthew G. Knepley 
198832d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
198932d2bbc9SMatthew G. Knepley 
199032d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
199132d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
199232d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
199332d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
199432d2bbc9SMatthew G. Knepley 
199532d2bbc9SMatthew G. Knepley + dim - the spatial dimension
199632d2bbc9SMatthew G. Knepley . Nf - the number of fields
199732d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
199832d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
199932d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
200032d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
200132d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
200232d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
200332d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
200432d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
200532d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
200632d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
200732d2bbc9SMatthew G. Knepley . t - current time
200832d2bbc9SMatthew G. Knepley . x - coordinates of the current point
200932d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
201032d2bbc9SMatthew G. Knepley 
201132d2bbc9SMatthew G. Knepley   Level: intermediate
201232d2bbc9SMatthew G. Knepley 
201332d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
201432d2bbc9SMatthew G. Knepley @*/
2015*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS ds, PetscInt f,
201632d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
201732d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
201832d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20193fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
202032d2bbc9SMatthew G. Knepley {
202132d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
202232d2bbc9SMatthew G. Knepley 
202332d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
2024*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
202532d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
202632d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2027*6528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
2028*6528b96dSMatthew G. Knepley   ds->update[f] = update;
202932d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
203032d2bbc9SMatthew G. Knepley }
203132d2bbc9SMatthew G. Knepley 
2032*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void **ctx)
20330c2f2876SMatthew G. Knepley {
20340c2f2876SMatthew G. Knepley   PetscFunctionBegin;
2035*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2036*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
20370c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
2038*6528b96dSMatthew G. Knepley   *ctx = ds->ctx[f];
20390c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20400c2f2876SMatthew G. Knepley }
20410c2f2876SMatthew G. Knepley 
2042*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx)
20430c2f2876SMatthew G. Knepley {
20440c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
20450c2f2876SMatthew G. Knepley 
20460c2f2876SMatthew G. Knepley   PetscFunctionBegin;
2047*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
20480c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2049*6528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
2050*6528b96dSMatthew G. Knepley   ds->ctx[f] = ctx;
20510c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20520c2f2876SMatthew G. Knepley }
20530c2f2876SMatthew G. Knepley 
2054194d53e6SMatthew G. Knepley /*@C
2055194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
2056194d53e6SMatthew G. Knepley 
2057194d53e6SMatthew G. Knepley   Not collective
2058194d53e6SMatthew G. Knepley 
2059194d53e6SMatthew G. Knepley   Input Parameters:
2060*6528b96dSMatthew G. Knepley + ds - The PetscDS
2061194d53e6SMatthew G. Knepley - f  - The test field number
2062194d53e6SMatthew G. Knepley 
2063194d53e6SMatthew G. Knepley   Output Parameters:
2064194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
2065194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2066194d53e6SMatthew G. Knepley 
2067194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2068194d53e6SMatthew G. Knepley 
2069194d53e6SMatthew G. Knepley   \int_\Gamma \phi {\vec f}_0(u, u_t, \nabla u, x, t) \cdot \hat n + \nabla\phi \cdot {\overleftrightarrow f}_1(u, u_t, \nabla u, x, t) \cdot \hat n
2070194d53e6SMatthew G. Knepley 
2071194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2072194d53e6SMatthew G. Knepley 
207330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2074194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2075194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
207630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2077194d53e6SMatthew G. Knepley 
2078194d53e6SMatthew G. Knepley + dim - the spatial dimension
2079194d53e6SMatthew G. Knepley . Nf - the number of fields
2080194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2081194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2082194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2083194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2084194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2085194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2086194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2087194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2088194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2089194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2090194d53e6SMatthew G. Knepley . t - current time
2091194d53e6SMatthew G. Knepley . x - coordinates of the current point
2092194d53e6SMatthew G. Knepley . n - unit normal at the current point
209397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
209497b6e6e8SMatthew G. Knepley . constants - constant parameters
2095194d53e6SMatthew G. Knepley - f0 - output values at the current point
2096194d53e6SMatthew G. Knepley 
2097194d53e6SMatthew G. Knepley   Level: intermediate
2098194d53e6SMatthew G. Knepley 
2099194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
2100194d53e6SMatthew G. Knepley @*/
2101*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS ds, PetscInt f,
210230b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2103194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2104194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
210597b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
210630b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2107194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2108194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
210997b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
21102764a2aaSMatthew G. Knepley {
2111*6528b96dSMatthew G. Knepley   PetscBdPointFunc *tmp0, *tmp1;
2112*6528b96dSMatthew G. Knepley   PetscInt          n0, n1;
2113*6528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
2114*6528b96dSMatthew G. Knepley 
21152764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2116*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2117*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
2118*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
2119*6528b96dSMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
2120*6528b96dSMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
21212764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21222764a2aaSMatthew G. Knepley }
21232764a2aaSMatthew G. Knepley 
2124194d53e6SMatthew G. Knepley /*@C
2125194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2126194d53e6SMatthew G. Knepley 
2127194d53e6SMatthew G. Knepley   Not collective
2128194d53e6SMatthew G. Knepley 
2129194d53e6SMatthew G. Knepley   Input Parameters:
2130*6528b96dSMatthew G. Knepley + ds - The PetscDS
2131194d53e6SMatthew G. Knepley . f  - The test field number
2132194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2133194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2134194d53e6SMatthew G. Knepley 
2135194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2136194d53e6SMatthew G. Knepley 
2137194d53e6SMatthew G. Knepley   \int_\Gamma \phi {\vec f}_0(u, u_t, \nabla u, x, t) \cdot \hat n + \nabla\phi \cdot {\overleftrightarrow f}_1(u, u_t, \nabla u, x, t) \cdot \hat n
2138194d53e6SMatthew G. Knepley 
2139194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2140194d53e6SMatthew G. Knepley 
214130b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2142194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2143194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
214430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2145194d53e6SMatthew G. Knepley 
2146194d53e6SMatthew G. Knepley + dim - the spatial dimension
2147194d53e6SMatthew G. Knepley . Nf - the number of fields
2148194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2149194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2150194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2151194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2152194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2153194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2154194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2155194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2156194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2157194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2158194d53e6SMatthew G. Knepley . t - current time
2159194d53e6SMatthew G. Knepley . x - coordinates of the current point
2160194d53e6SMatthew G. Knepley . n - unit normal at the current point
216197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
216297b6e6e8SMatthew G. Knepley . constants - constant parameters
2163194d53e6SMatthew G. Knepley - f0 - output values at the current point
2164194d53e6SMatthew G. Knepley 
2165194d53e6SMatthew G. Knepley   Level: intermediate
2166194d53e6SMatthew G. Knepley 
2167194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
2168194d53e6SMatthew G. Knepley @*/
2169*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS ds, PetscInt f,
217030b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2171194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2172194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
217397b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
217430b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2175194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2176194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
217797b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
21782764a2aaSMatthew G. Knepley {
21792764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21802764a2aaSMatthew G. Knepley 
21812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2182*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
21832764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2184*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, f0, 0, f1);CHKERRQ(ierr);
21852764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21862764a2aaSMatthew G. Knepley }
21872764a2aaSMatthew G. Knepley 
218827f02ce8SMatthew G. Knepley /*@
218927f02ce8SMatthew G. Knepley   PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set
219027f02ce8SMatthew G. Knepley 
219127f02ce8SMatthew G. Knepley   Not collective
219227f02ce8SMatthew G. Knepley 
219327f02ce8SMatthew G. Knepley   Input Parameter:
2194*6528b96dSMatthew G. Knepley . ds - The PetscDS
219527f02ce8SMatthew G. Knepley 
219627f02ce8SMatthew G. Knepley   Output Parameter:
219727f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set
219827f02ce8SMatthew G. Knepley 
219927f02ce8SMatthew G. Knepley   Level: intermediate
220027f02ce8SMatthew G. Knepley 
220127f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
220227f02ce8SMatthew G. Knepley @*/
2203*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac)
220427f02ce8SMatthew G. Knepley {
2205*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
220627f02ce8SMatthew G. Knepley 
220727f02ce8SMatthew G. Knepley   PetscFunctionBegin;
2208*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2209*6528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJac, 2);
2210*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobian(ds->wf, hasBdJac);CHKERRQ(ierr);
221127f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
221227f02ce8SMatthew G. Knepley }
221327f02ce8SMatthew G. Knepley 
2214194d53e6SMatthew G. Knepley /*@C
2215194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2216194d53e6SMatthew G. Knepley 
2217194d53e6SMatthew G. Knepley   Not collective
2218194d53e6SMatthew G. Knepley 
2219194d53e6SMatthew G. Knepley   Input Parameters:
2220*6528b96dSMatthew G. Knepley + ds - The PetscDS
2221194d53e6SMatthew G. Knepley . f  - The test field number
2222194d53e6SMatthew G. Knepley - g  - The field number
2223194d53e6SMatthew G. Knepley 
2224194d53e6SMatthew G. Knepley   Output Parameters:
2225194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2226194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2227194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2228194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2229194d53e6SMatthew G. Knepley 
2230194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2231194d53e6SMatthew G. Knepley 
2232194d53e6SMatthew G. Knepley   \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi
2233194d53e6SMatthew G. Knepley 
2234194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2235194d53e6SMatthew G. Knepley 
223630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2237194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2238194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
223930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2240194d53e6SMatthew G. Knepley 
2241194d53e6SMatthew G. Knepley + dim - the spatial dimension
2242194d53e6SMatthew G. Knepley . Nf - the number of fields
2243194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2244194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2245194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2246194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2247194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2248194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2249194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2250194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2251194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2252194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2253194d53e6SMatthew G. Knepley . t - current time
22542aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2255194d53e6SMatthew G. Knepley . x - coordinates of the current point
2256194d53e6SMatthew G. Knepley . n - normal at the current point
225797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
225897b6e6e8SMatthew G. Knepley . constants - constant parameters
2259194d53e6SMatthew G. Knepley - g0 - output values at the current point
2260194d53e6SMatthew G. Knepley 
2261194d53e6SMatthew G. Knepley   Level: intermediate
2262194d53e6SMatthew G. Knepley 
2263194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2264194d53e6SMatthew G. Knepley @*/
2265*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
226630b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2267194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2268194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
226997b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
227030b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2271194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2272194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
227397b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
227430b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2275194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2276194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
227797b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
227830b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2279194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2280194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
228197b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
22822764a2aaSMatthew G. Knepley {
2283*6528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
2284*6528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
2285*6528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
2286*6528b96dSMatthew G. Knepley 
22872764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2288*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2289*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
2290*6528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
2291*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
2292*6528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
2293*6528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
2294*6528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
2295*6528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
22962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22972764a2aaSMatthew G. Knepley }
22982764a2aaSMatthew G. Knepley 
2299194d53e6SMatthew G. Knepley /*@C
2300194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2301194d53e6SMatthew G. Knepley 
2302194d53e6SMatthew G. Knepley   Not collective
2303194d53e6SMatthew G. Knepley 
2304194d53e6SMatthew G. Knepley   Input Parameters:
2305*6528b96dSMatthew G. Knepley + ds - The PetscDS
2306194d53e6SMatthew G. Knepley . f  - The test field number
2307194d53e6SMatthew G. Knepley . g  - The field number
2308194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2309194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2310194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2311194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2312194d53e6SMatthew G. Knepley 
2313194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2314194d53e6SMatthew G. Knepley 
2315194d53e6SMatthew G. Knepley   \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi
2316194d53e6SMatthew G. Knepley 
2317194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2318194d53e6SMatthew G. Knepley 
231930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2320194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2321194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
232230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2323194d53e6SMatthew G. Knepley 
2324194d53e6SMatthew G. Knepley + dim - the spatial dimension
2325194d53e6SMatthew G. Knepley . Nf - the number of fields
2326194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2327194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2328194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2329194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2330194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2331194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2332194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2333194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2334194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2335194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2336194d53e6SMatthew G. Knepley . t - current time
23372aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2338194d53e6SMatthew G. Knepley . x - coordinates of the current point
2339194d53e6SMatthew G. Knepley . n - normal at the current point
234097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
234197b6e6e8SMatthew G. Knepley . constants - constant parameters
2342194d53e6SMatthew G. Knepley - g0 - output values at the current point
2343194d53e6SMatthew G. Knepley 
2344194d53e6SMatthew G. Knepley   Level: intermediate
2345194d53e6SMatthew G. Knepley 
2346194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2347194d53e6SMatthew G. Knepley @*/
2348*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
234930b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2350194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2351194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
235297b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
235330b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2354194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2355194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
235697b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
235730b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2358194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2359194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
236097b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
236130b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2362194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2363194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
236497b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
23652764a2aaSMatthew G. Knepley {
23662764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23672764a2aaSMatthew G. Knepley 
23682764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2369*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
23702764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
23712764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
23722764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
23732764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
23742764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
23752764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
2376*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
23772764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23782764a2aaSMatthew G. Knepley }
23792764a2aaSMatthew G. Knepley 
238027f02ce8SMatthew G. Knepley /*@
238127f02ce8SMatthew G. Knepley   PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set
238227f02ce8SMatthew G. Knepley 
238327f02ce8SMatthew G. Knepley   Not collective
238427f02ce8SMatthew G. Knepley 
238527f02ce8SMatthew G. Knepley   Input Parameter:
2386*6528b96dSMatthew G. Knepley . ds - The PetscDS
238727f02ce8SMatthew G. Knepley 
238827f02ce8SMatthew G. Knepley   Output Parameter:
238927f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set
239027f02ce8SMatthew G. Knepley 
239127f02ce8SMatthew G. Knepley   Level: intermediate
239227f02ce8SMatthew G. Knepley 
239327f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
239427f02ce8SMatthew G. Knepley @*/
2395*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre)
239627f02ce8SMatthew G. Knepley {
2397*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
239827f02ce8SMatthew G. Knepley 
239927f02ce8SMatthew G. Knepley   PetscFunctionBegin;
2400*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2401*6528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJacPre, 2);
2402*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre);CHKERRQ(ierr);
240327f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
240427f02ce8SMatthew G. Knepley }
240527f02ce8SMatthew G. Knepley 
240627f02ce8SMatthew G. Knepley /*@C
240727f02ce8SMatthew G. Knepley   PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field
240827f02ce8SMatthew G. Knepley 
240927f02ce8SMatthew G. Knepley   Not collective
241027f02ce8SMatthew G. Knepley 
241127f02ce8SMatthew G. Knepley   Input Parameters:
2412*6528b96dSMatthew G. Knepley + ds - The PetscDS
241327f02ce8SMatthew G. Knepley . f  - The test field number
241427f02ce8SMatthew G. Knepley - g  - The field number
241527f02ce8SMatthew G. Knepley 
241627f02ce8SMatthew G. Knepley   Output Parameters:
241727f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term
241827f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
241927f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
242027f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
242127f02ce8SMatthew G. Knepley 
242227f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
242327f02ce8SMatthew G. Knepley 
242427f02ce8SMatthew G. Knepley   \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi
242527f02ce8SMatthew G. Knepley 
242627f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
242727f02ce8SMatthew G. Knepley 
242827f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
242927f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
243027f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
243127f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
243227f02ce8SMatthew G. Knepley 
243327f02ce8SMatthew G. Knepley + dim - the spatial dimension
243427f02ce8SMatthew G. Knepley . Nf - the number of fields
243527f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
243627f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
243727f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
243827f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
243927f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
244027f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
244127f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
244227f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
244327f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
244427f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
244527f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
244627f02ce8SMatthew G. Knepley . t - current time
244727f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
244827f02ce8SMatthew G. Knepley . x - coordinates of the current point
244927f02ce8SMatthew G. Knepley . n - normal at the current point
245027f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
245127f02ce8SMatthew G. Knepley . constants - constant parameters
245227f02ce8SMatthew G. Knepley - g0 - output values at the current point
245327f02ce8SMatthew G. Knepley 
245427f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
245527f02ce8SMatthew G. Knepley 
245627f02ce8SMatthew G. Knepley   Level: intermediate
245727f02ce8SMatthew G. Knepley 
245827f02ce8SMatthew G. Knepley .seealso: PetscDSSetBdJacobianPreconditioner()
245927f02ce8SMatthew G. Knepley @*/
2460*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
246127f02ce8SMatthew G. Knepley                                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
246227f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
246327f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
246427f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
246527f02ce8SMatthew G. Knepley                                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
246627f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
246727f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
246827f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
246927f02ce8SMatthew G. Knepley                                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
247027f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
247127f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
247227f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
247327f02ce8SMatthew G. Knepley                                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
247427f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
247527f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
247627f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
247727f02ce8SMatthew G. Knepley {
2478*6528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
2479*6528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
2480*6528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
2481*6528b96dSMatthew G. Knepley 
248227f02ce8SMatthew G. Knepley   PetscFunctionBegin;
2483*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2484*6528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
2485*6528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
2486*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
2487*6528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
2488*6528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
2489*6528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
2490*6528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
249127f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
249227f02ce8SMatthew G. Knepley }
249327f02ce8SMatthew G. Knepley 
249427f02ce8SMatthew G. Knepley /*@C
249527f02ce8SMatthew G. Knepley   PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field
249627f02ce8SMatthew G. Knepley 
249727f02ce8SMatthew G. Knepley   Not collective
249827f02ce8SMatthew G. Knepley 
249927f02ce8SMatthew G. Knepley   Input Parameters:
2500*6528b96dSMatthew G. Knepley + ds - The PetscDS
250127f02ce8SMatthew G. Knepley . f  - The test field number
250227f02ce8SMatthew G. Knepley . g  - The field number
250327f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term
250427f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
250527f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
250627f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
250727f02ce8SMatthew G. Knepley 
250827f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
250927f02ce8SMatthew G. Knepley 
251027f02ce8SMatthew G. Knepley   \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi
251127f02ce8SMatthew G. Knepley 
251227f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
251327f02ce8SMatthew G. Knepley 
251427f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
251527f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
251627f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
251727f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
251827f02ce8SMatthew G. Knepley 
251927f02ce8SMatthew G. Knepley + dim - the spatial dimension
252027f02ce8SMatthew G. Knepley . Nf - the number of fields
252127f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
252227f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
252327f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
252427f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
252527f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
252627f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
252727f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
252827f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
252927f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
253027f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
253127f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
253227f02ce8SMatthew G. Knepley . t - current time
253327f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
253427f02ce8SMatthew G. Knepley . x - coordinates of the current point
253527f02ce8SMatthew G. Knepley . n - normal at the current point
253627f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
253727f02ce8SMatthew G. Knepley . constants - constant parameters
253827f02ce8SMatthew G. Knepley - g0 - output values at the current point
253927f02ce8SMatthew G. Knepley 
254027f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
254127f02ce8SMatthew G. Knepley 
254227f02ce8SMatthew G. Knepley   Level: intermediate
254327f02ce8SMatthew G. Knepley 
254427f02ce8SMatthew G. Knepley .seealso: PetscDSGetBdJacobianPreconditioner()
254527f02ce8SMatthew G. Knepley @*/
2546*6528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
254727f02ce8SMatthew G. Knepley                                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
254827f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
254927f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
255027f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
255127f02ce8SMatthew G. Knepley                                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
255227f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
255327f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
255427f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
255527f02ce8SMatthew G. Knepley                                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
255627f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
255727f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
255827f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
255927f02ce8SMatthew G. Knepley                                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
256027f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
256127f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
256227f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
256327f02ce8SMatthew G. Knepley {
256427f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
256527f02ce8SMatthew G. Knepley 
256627f02ce8SMatthew G. Knepley   PetscFunctionBegin;
2567*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
256827f02ce8SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
256927f02ce8SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
257027f02ce8SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
257127f02ce8SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
257227f02ce8SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
257327f02ce8SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
2574*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
257527f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
257627f02ce8SMatthew G. Knepley }
257727f02ce8SMatthew G. Knepley 
25780d3e9b51SMatthew G. Knepley /*@C
2579c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2580c371a6d1SMatthew G. Knepley 
2581c371a6d1SMatthew G. Knepley   Not collective
2582c371a6d1SMatthew G. Knepley 
2583c371a6d1SMatthew G. Knepley   Input Parameters:
2584c371a6d1SMatthew G. Knepley + prob - The PetscDS
2585c371a6d1SMatthew G. Knepley - f    - The test field number
2586c371a6d1SMatthew G. Knepley 
2587c371a6d1SMatthew G. Knepley   Output Parameter:
258895cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field
258995cbbfd3SMatthew G. Knepley - exactCtx - exact solution context
2590c371a6d1SMatthew G. Knepley 
2591c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2592c371a6d1SMatthew G. Knepley 
2593c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2594c371a6d1SMatthew G. Knepley 
2595c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2596c371a6d1SMatthew G. Knepley . t - current time
2597c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2598c371a6d1SMatthew G. Knepley . Nc - the number of field components
2599c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2600c371a6d1SMatthew G. Knepley - ctx - a user context
2601c371a6d1SMatthew G. Knepley 
2602c371a6d1SMatthew G. Knepley   Level: intermediate
2603c371a6d1SMatthew G. Knepley 
2604f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolution(), PetscDSGetExactSolutionTimeDerivative()
2605c371a6d1SMatthew G. Knepley @*/
260695cbbfd3SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2607c371a6d1SMatthew G. Knepley {
2608c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2609c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2610c371a6d1SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
2611c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
261295cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];}
2613c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2614c371a6d1SMatthew G. Knepley }
2615c371a6d1SMatthew G. Knepley 
2616c371a6d1SMatthew G. Knepley /*@C
2617578a5ef5SMatthew Knepley   PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field
2618c371a6d1SMatthew G. Knepley 
2619c371a6d1SMatthew G. Knepley   Not collective
2620c371a6d1SMatthew G. Knepley 
2621c371a6d1SMatthew G. Knepley   Input Parameters:
2622c371a6d1SMatthew G. Knepley + prob - The PetscDS
2623c371a6d1SMatthew G. Knepley . f    - The test field number
262495cbbfd3SMatthew G. Knepley . sol  - solution function for the test fields
262595cbbfd3SMatthew G. Knepley - ctx  - solution context or NULL
2626c371a6d1SMatthew G. Knepley 
2627c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2628c371a6d1SMatthew G. Knepley 
2629c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2630c371a6d1SMatthew G. Knepley 
2631c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2632c371a6d1SMatthew G. Knepley . t - current time
2633c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2634c371a6d1SMatthew G. Knepley . Nc - the number of field components
2635c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2636c371a6d1SMatthew G. Knepley - ctx - a user context
2637c371a6d1SMatthew G. Knepley 
2638c371a6d1SMatthew G. Knepley   Level: intermediate
2639c371a6d1SMatthew G. Knepley 
2640c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2641c371a6d1SMatthew G. Knepley @*/
264295cbbfd3SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2643c371a6d1SMatthew G. Knepley {
2644c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2645c371a6d1SMatthew G. Knepley 
2646c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2647c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2648c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2649c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2650c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
265195cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;}
2652c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2653c371a6d1SMatthew G. Knepley }
2654c371a6d1SMatthew G. Knepley 
26555638fd0eSMatthew G. Knepley /*@C
2656f2cacb80SMatthew G. Knepley   PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field
2657f2cacb80SMatthew G. Knepley 
2658f2cacb80SMatthew G. Knepley   Not collective
2659f2cacb80SMatthew G. Knepley 
2660f2cacb80SMatthew G. Knepley   Input Parameters:
2661f2cacb80SMatthew G. Knepley + prob - The PetscDS
2662f2cacb80SMatthew G. Knepley - f    - The test field number
2663f2cacb80SMatthew G. Knepley 
2664f2cacb80SMatthew G. Knepley   Output Parameter:
2665f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field
2666f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context
2667f2cacb80SMatthew G. Knepley 
2668f2cacb80SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2669f2cacb80SMatthew G. Knepley 
2670f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2671f2cacb80SMatthew G. Knepley 
2672f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2673f2cacb80SMatthew G. Knepley . t - current time
2674f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2675f2cacb80SMatthew G. Knepley . Nc - the number of field components
2676f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2677f2cacb80SMatthew G. Knepley - ctx - a user context
2678f2cacb80SMatthew G. Knepley 
2679f2cacb80SMatthew G. Knepley   Level: intermediate
2680f2cacb80SMatthew G. Knepley 
2681f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolutionTimeDerivative(), PetscDSGetExactSolution()
2682f2cacb80SMatthew G. Knepley @*/
2683f2cacb80SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2684f2cacb80SMatthew G. Knepley {
2685f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2686f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2687f2cacb80SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
2688f2cacb80SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol_t[f];}
2689f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx_t[f];}
2690f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2691f2cacb80SMatthew G. Knepley }
2692f2cacb80SMatthew G. Knepley 
2693f2cacb80SMatthew G. Knepley /*@C
2694f2cacb80SMatthew G. Knepley   PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field
2695f2cacb80SMatthew G. Knepley 
2696f2cacb80SMatthew G. Knepley   Not collective
2697f2cacb80SMatthew G. Knepley 
2698f2cacb80SMatthew G. Knepley   Input Parameters:
2699f2cacb80SMatthew G. Knepley + prob - The PetscDS
2700f2cacb80SMatthew G. Knepley . f    - The test field number
2701f2cacb80SMatthew G. Knepley . sol  - time derivative of the solution function for the test fields
2702f2cacb80SMatthew G. Knepley - ctx  - time derivative of the solution context or NULL
2703f2cacb80SMatthew G. Knepley 
2704f2cacb80SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2705f2cacb80SMatthew G. Knepley 
2706f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2707f2cacb80SMatthew G. Knepley 
2708f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2709f2cacb80SMatthew G. Knepley . t - current time
2710f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2711f2cacb80SMatthew G. Knepley . Nc - the number of field components
2712f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2713f2cacb80SMatthew G. Knepley - ctx - a user context
2714f2cacb80SMatthew G. Knepley 
2715f2cacb80SMatthew G. Knepley   Level: intermediate
2716f2cacb80SMatthew G. Knepley 
2717f2cacb80SMatthew G. Knepley .seealso: PetscDSGetExactSolutionTimeDerivative(), PetscDSSetExactSolution()
2718f2cacb80SMatthew G. Knepley @*/
2719f2cacb80SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2720f2cacb80SMatthew G. Knepley {
2721f2cacb80SMatthew G. Knepley   PetscErrorCode ierr;
2722f2cacb80SMatthew G. Knepley 
2723f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2724f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2725f2cacb80SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2726f2cacb80SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2727f2cacb80SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol_t[f] = sol;}
2728f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx_t[f] = ctx;}
2729f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2730f2cacb80SMatthew G. Knepley }
2731f2cacb80SMatthew G. Knepley 
2732f2cacb80SMatthew G. Knepley /*@C
273397b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
273497b6e6e8SMatthew G. Knepley 
273597b6e6e8SMatthew G. Knepley   Not collective
273697b6e6e8SMatthew G. Knepley 
273797b6e6e8SMatthew G. Knepley   Input Parameter:
273897b6e6e8SMatthew G. Knepley . prob - The PetscDS object
273997b6e6e8SMatthew G. Knepley 
274097b6e6e8SMatthew G. Knepley   Output Parameters:
274197b6e6e8SMatthew G. Knepley + numConstants - The number of constants
274297b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
274397b6e6e8SMatthew G. Knepley 
274497b6e6e8SMatthew G. Knepley   Level: intermediate
274597b6e6e8SMatthew G. Knepley 
274697b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
274797b6e6e8SMatthew G. Knepley @*/
274897b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
274997b6e6e8SMatthew G. Knepley {
275097b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
275197b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
275297b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
275397b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
275497b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
275597b6e6e8SMatthew G. Knepley }
275697b6e6e8SMatthew G. Knepley 
27570d3e9b51SMatthew G. Knepley /*@C
275897b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
275997b6e6e8SMatthew G. Knepley 
276097b6e6e8SMatthew G. Knepley   Not collective
276197b6e6e8SMatthew G. Knepley 
276297b6e6e8SMatthew G. Knepley   Input Parameters:
276397b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
276497b6e6e8SMatthew G. Knepley . numConstants - The number of constants
276597b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
276697b6e6e8SMatthew G. Knepley 
276797b6e6e8SMatthew G. Knepley   Level: intermediate
276897b6e6e8SMatthew G. Knepley 
276997b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
277097b6e6e8SMatthew G. Knepley @*/
277197b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
277297b6e6e8SMatthew G. Knepley {
277397b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
277497b6e6e8SMatthew G. Knepley 
277597b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
277697b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
277797b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
277897b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
277997b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
278097b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
278197b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
278220be0f5bSMatthew G. Knepley     } else {
278320be0f5bSMatthew G. Knepley       prob->constants = NULL;
278420be0f5bSMatthew G. Knepley     }
278520be0f5bSMatthew G. Knepley   }
278620be0f5bSMatthew G. Knepley   if (prob->numConstants) {
278720be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
2788580bdb30SBarry Smith     ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr);
278997b6e6e8SMatthew G. Knepley   }
279097b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
279197b6e6e8SMatthew G. Knepley }
279297b6e6e8SMatthew G. Knepley 
27934cd1e086SMatthew G. Knepley /*@
27944cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
27954cd1e086SMatthew G. Knepley 
27964cd1e086SMatthew G. Knepley   Not collective
27974cd1e086SMatthew G. Knepley 
27984cd1e086SMatthew G. Knepley   Input Parameters:
27994cd1e086SMatthew G. Knepley + prob - The PetscDS object
28004cd1e086SMatthew G. Knepley - disc - The discretization object
28014cd1e086SMatthew G. Knepley 
28024cd1e086SMatthew G. Knepley   Output Parameter:
28034cd1e086SMatthew G. Knepley . f - The field number
28044cd1e086SMatthew G. Knepley 
28054cd1e086SMatthew G. Knepley   Level: beginner
28064cd1e086SMatthew G. Knepley 
2807f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
28084cd1e086SMatthew G. Knepley @*/
28094cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
28104cd1e086SMatthew G. Knepley {
28114cd1e086SMatthew G. Knepley   PetscInt g;
28124cd1e086SMatthew G. Knepley 
28134cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28144cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28154cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
28164cd1e086SMatthew G. Knepley   *f = -1;
28174cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
28184cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
28194cd1e086SMatthew G. Knepley   *f = g;
28204cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
28214cd1e086SMatthew G. Knepley }
28224cd1e086SMatthew G. Knepley 
28234cd1e086SMatthew G. Knepley /*@
28244cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
28254cd1e086SMatthew G. Knepley 
28264cd1e086SMatthew G. Knepley   Not collective
28274cd1e086SMatthew G. Knepley 
28284cd1e086SMatthew G. Knepley   Input Parameters:
28294cd1e086SMatthew G. Knepley + prob - The PetscDS object
28304cd1e086SMatthew G. Knepley - f - The field number
28314cd1e086SMatthew G. Knepley 
28324cd1e086SMatthew G. Knepley   Output Parameter:
28334cd1e086SMatthew G. Knepley . size - The size
28344cd1e086SMatthew G. Knepley 
28354cd1e086SMatthew G. Knepley   Level: beginner
28364cd1e086SMatthew G. Knepley 
2837f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
28384cd1e086SMatthew G. Knepley @*/
28394cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
28404cd1e086SMatthew G. Knepley {
28412166fd64SMatthew G. Knepley   PetscErrorCode ierr;
28422166fd64SMatthew G. Knepley 
28434cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28444cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28454cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
28464cd1e086SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
28472166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2848d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
28494cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
28504cd1e086SMatthew G. Knepley }
28514cd1e086SMatthew G. Knepley 
2852bc4ae4beSMatthew G. Knepley /*@
2853bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2854bc4ae4beSMatthew G. Knepley 
2855bc4ae4beSMatthew G. Knepley   Not collective
2856bc4ae4beSMatthew G. Knepley 
2857bc4ae4beSMatthew G. Knepley   Input Parameters:
2858bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2859bc4ae4beSMatthew G. Knepley - f - The field number
2860bc4ae4beSMatthew G. Knepley 
2861bc4ae4beSMatthew G. Knepley   Output Parameter:
2862bc4ae4beSMatthew G. Knepley . off - The offset
2863bc4ae4beSMatthew G. Knepley 
2864bc4ae4beSMatthew G. Knepley   Level: beginner
2865bc4ae4beSMatthew G. Knepley 
2866f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2867bc4ae4beSMatthew G. Knepley @*/
28682764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
28692764a2aaSMatthew G. Knepley {
28704cd1e086SMatthew G. Knepley   PetscInt       size, g;
28712764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
28722764a2aaSMatthew G. Knepley 
28732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28742764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28752764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
28762764a2aaSMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
28772764a2aaSMatthew G. Knepley   *off = 0;
28782764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
28794cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
28804cd1e086SMatthew G. Knepley     *off += size;
28812764a2aaSMatthew G. Knepley   }
28822764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28832764a2aaSMatthew G. Knepley }
28842764a2aaSMatthew G. Knepley 
2885bc4ae4beSMatthew G. Knepley /*@
288647e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2887bc4ae4beSMatthew G. Knepley 
2888bc4ae4beSMatthew G. Knepley   Not collective
2889bc4ae4beSMatthew G. Knepley 
289047e57110SSander Arens   Input Parameter:
289147e57110SSander Arens . prob - The PetscDS object
2892bc4ae4beSMatthew G. Knepley 
2893bc4ae4beSMatthew G. Knepley   Output Parameter:
289447e57110SSander Arens . dimensions - The number of dimensions
2895bc4ae4beSMatthew G. Knepley 
2896bc4ae4beSMatthew G. Knepley   Level: beginner
2897bc4ae4beSMatthew G. Knepley 
289847e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2899bc4ae4beSMatthew G. Knepley @*/
290047e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
29012764a2aaSMatthew G. Knepley {
29022764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
29032764a2aaSMatthew G. Knepley 
29042764a2aaSMatthew G. Knepley   PetscFunctionBegin;
29052764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
290647e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
290747e57110SSander Arens   PetscValidPointer(dimensions, 2);
290847e57110SSander Arens   *dimensions = prob->Nb;
290947e57110SSander Arens   PetscFunctionReturn(0);
29106ce16762SMatthew G. Knepley }
291147e57110SSander Arens 
291247e57110SSander Arens /*@
291347e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
291447e57110SSander Arens 
291547e57110SSander Arens   Not collective
291647e57110SSander Arens 
291747e57110SSander Arens   Input Parameter:
291847e57110SSander Arens . prob - The PetscDS object
291947e57110SSander Arens 
292047e57110SSander Arens   Output Parameter:
292147e57110SSander Arens . components - The number of components
292247e57110SSander Arens 
292347e57110SSander Arens   Level: beginner
292447e57110SSander Arens 
292547e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
292647e57110SSander Arens @*/
292747e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
292847e57110SSander Arens {
292947e57110SSander Arens   PetscErrorCode ierr;
293047e57110SSander Arens 
293147e57110SSander Arens   PetscFunctionBegin;
293247e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
293347e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
293447e57110SSander Arens   PetscValidPointer(components, 2);
293547e57110SSander Arens   *components = prob->Nc;
29366ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
29376ce16762SMatthew G. Knepley }
29386ce16762SMatthew G. Knepley 
29396ce16762SMatthew G. Knepley /*@
29406ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
29416ce16762SMatthew G. Knepley 
29426ce16762SMatthew G. Knepley   Not collective
29436ce16762SMatthew G. Knepley 
29446ce16762SMatthew G. Knepley   Input Parameters:
29456ce16762SMatthew G. Knepley + prob - The PetscDS object
29466ce16762SMatthew G. Knepley - f - The field number
29476ce16762SMatthew G. Knepley 
29486ce16762SMatthew G. Knepley   Output Parameter:
29496ce16762SMatthew G. Knepley . off - The offset
29506ce16762SMatthew G. Knepley 
29516ce16762SMatthew G. Knepley   Level: beginner
29526ce16762SMatthew G. Knepley 
2953f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
29546ce16762SMatthew G. Knepley @*/
29556ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
29566ce16762SMatthew G. Knepley {
29576ce16762SMatthew G. Knepley   PetscFunctionBegin;
29586ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29596ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
29606ce16762SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
296147e57110SSander Arens   *off = prob->off[f];
29622764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29632764a2aaSMatthew G. Knepley }
29642764a2aaSMatthew G. Knepley 
2965194d53e6SMatthew G. Knepley /*@
2966194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2967194d53e6SMatthew G. Knepley 
2968194d53e6SMatthew G. Knepley   Not collective
2969194d53e6SMatthew G. Knepley 
2970194d53e6SMatthew G. Knepley   Input Parameter:
2971194d53e6SMatthew G. Knepley . prob - The PetscDS object
2972194d53e6SMatthew G. Knepley 
2973194d53e6SMatthew G. Knepley   Output Parameter:
2974194d53e6SMatthew G. Knepley . offsets - The offsets
2975194d53e6SMatthew G. Knepley 
2976194d53e6SMatthew G. Knepley   Level: beginner
2977194d53e6SMatthew G. Knepley 
2978f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2979194d53e6SMatthew G. Knepley @*/
2980194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2981194d53e6SMatthew G. Knepley {
2982194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2983194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2984194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2985194d53e6SMatthew G. Knepley   *offsets = prob->off;
2986194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2987194d53e6SMatthew G. Knepley }
2988194d53e6SMatthew G. Knepley 
2989194d53e6SMatthew G. Knepley /*@
2990194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2991194d53e6SMatthew G. Knepley 
2992194d53e6SMatthew G. Knepley   Not collective
2993194d53e6SMatthew G. Knepley 
2994194d53e6SMatthew G. Knepley   Input Parameter:
2995194d53e6SMatthew G. Knepley . prob - The PetscDS object
2996194d53e6SMatthew G. Knepley 
2997194d53e6SMatthew G. Knepley   Output Parameter:
2998194d53e6SMatthew G. Knepley . offsets - The offsets
2999194d53e6SMatthew G. Knepley 
3000194d53e6SMatthew G. Knepley   Level: beginner
3001194d53e6SMatthew G. Knepley 
3002f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
3003194d53e6SMatthew G. Knepley @*/
3004194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
3005194d53e6SMatthew G. Knepley {
3006194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3007194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3008194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
3009194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
3010194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
3011194d53e6SMatthew G. Knepley }
3012194d53e6SMatthew G. Knepley 
301368c9edb9SMatthew G. Knepley /*@C
301468c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
301568c9edb9SMatthew G. Knepley 
301668c9edb9SMatthew G. Knepley   Not collective
301768c9edb9SMatthew G. Knepley 
301868c9edb9SMatthew G. Knepley   Input Parameter:
301968c9edb9SMatthew G. Knepley . prob - The PetscDS object
302068c9edb9SMatthew G. Knepley 
3021ef0bb6c7SMatthew G. Knepley   Output Parameter:
3022ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field
302368c9edb9SMatthew G. Knepley 
302468c9edb9SMatthew G. Knepley   Level: intermediate
302568c9edb9SMatthew G. Knepley 
3026f744cafaSSander Arens .seealso: PetscDSCreate()
302768c9edb9SMatthew G. Knepley @*/
3028ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[])
30292764a2aaSMatthew G. Knepley {
30302764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30312764a2aaSMatthew G. Knepley 
30322764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30332764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3034ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
30352764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3036ef0bb6c7SMatthew G. Knepley   *T = prob->T;
30372764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30382764a2aaSMatthew G. Knepley }
30392764a2aaSMatthew G. Knepley 
304068c9edb9SMatthew G. Knepley /*@C
30414d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
304268c9edb9SMatthew G. Knepley 
304368c9edb9SMatthew G. Knepley   Not collective
304468c9edb9SMatthew G. Knepley 
304568c9edb9SMatthew G. Knepley   Input Parameter:
304668c9edb9SMatthew G. Knepley . prob - The PetscDS object
304768c9edb9SMatthew G. Knepley 
3048ef0bb6c7SMatthew G. Knepley   Output Parameter:
304919815104SMartin Diehl . Tf - The basis function and derviative tabulation on each local face at quadrature points for each and field
305068c9edb9SMatthew G. Knepley 
305168c9edb9SMatthew G. Knepley   Level: intermediate
305268c9edb9SMatthew G. Knepley 
305368c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
305468c9edb9SMatthew G. Knepley @*/
3055ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[])
30562764a2aaSMatthew G. Knepley {
30572764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30582764a2aaSMatthew G. Knepley 
30592764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30602764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3061ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
30622764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3063ef0bb6c7SMatthew G. Knepley   *Tf = prob->Tf;
30642764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30652764a2aaSMatthew G. Knepley }
30662764a2aaSMatthew G. Knepley 
30672764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
30682764a2aaSMatthew G. Knepley {
30692764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30702764a2aaSMatthew G. Knepley 
30712764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30722764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30732764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
30742764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
30752764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
30762764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
30772764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30782764a2aaSMatthew G. Knepley }
30792764a2aaSMatthew G. Knepley 
30802764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
30812764a2aaSMatthew G. Knepley {
30822764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30832764a2aaSMatthew G. Knepley 
30842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30852764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30862764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
30872764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
30882764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
30892764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
30902764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
30912764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
30922764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
30932764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30942764a2aaSMatthew G. Knepley }
30952764a2aaSMatthew G. Knepley 
30964bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal)
30972764a2aaSMatthew G. Knepley {
30982764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30992764a2aaSMatthew G. Knepley 
31002764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31012764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31022764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
31032764a2aaSMatthew G. Knepley   if (x)            {PetscValidPointer(x, 2);            *x            = prob->x;}
31044bee2e38SMatthew G. Knepley   if (basisReal)    {PetscValidPointer(basisReal, 3);    *basisReal    = prob->basisReal;}
31057506b574SStefano Zampini   if (basisDerReal) {PetscValidPointer(basisDerReal, 4); *basisDerReal = prob->basisDerReal;}
31067506b574SStefano Zampini   if (testReal)     {PetscValidPointer(testReal, 5);     *testReal     = prob->testReal;}
31077506b574SStefano Zampini   if (testDerReal)  {PetscValidPointer(testDerReal, 6);  *testDerReal  = prob->testDerReal;}
31082764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31092764a2aaSMatthew G. Knepley }
31102764a2aaSMatthew G. Knepley 
311158ebd649SToby Isaac /*@C
311256cf3b9cSMatthew G. Knepley   PetscDSAddBoundary - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performaed, using the kernels from PetscDSSetBdResidual().
311358ebd649SToby Isaac 
3114783e2ec8SMatthew G. Knepley   Collective on ds
3115783e2ec8SMatthew G. Knepley 
311658ebd649SToby Isaac   Input Parameters:
311758ebd649SToby Isaac + ds          - The PetscDS object
31182d47a189SJulian Andrej . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
311958ebd649SToby Isaac . name        - The BC name
312058ebd649SToby Isaac . labelname   - The label defining constrained points
312158ebd649SToby Isaac . field       - The field to constrain
3122e8ecbf3fSStefano Zampini . numcomps    - The number of constrained field components (0 will constrain all fields)
312358ebd649SToby Isaac . comps       - An array of constrained component numbers
312458ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
312556cf3b9cSMatthew G. Knepley . bcFunc_t    - A pointwise function giving the time derviative of the boundary values, or NULL
312658ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
312758ebd649SToby Isaac . ids         - An array of ids for constrained points
312858ebd649SToby Isaac - ctx         - An optional user context for bcFunc
312958ebd649SToby Isaac 
313058ebd649SToby Isaac   Options Database Keys:
313158ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
313258ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
313358ebd649SToby Isaac 
313456cf3b9cSMatthew G. Knepley   Note:
313556cf3b9cSMatthew G. Knepley   Both bcFunc abd bcFunc_t will depend on the boundary condition type. If the type if DM_BC_ESSENTIAL, Then the calling sequence is:
313656cf3b9cSMatthew G. Knepley 
313756cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
313856cf3b9cSMatthew G. Knepley 
313956cf3b9cSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
314056cf3b9cSMatthew G. Knepley 
314156cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
314256cf3b9cSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
314356cf3b9cSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
314456cf3b9cSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
314556cf3b9cSMatthew G. Knepley 
314656cf3b9cSMatthew G. Knepley + dim - the spatial dimension
314756cf3b9cSMatthew G. Knepley . Nf - the number of fields
314856cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
314956cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
315056cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point
315156cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
315256cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
315356cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
315456cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
315556cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
315656cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
315756cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
315856cf3b9cSMatthew G. Knepley . t - current time
315956cf3b9cSMatthew G. Knepley . x - coordinates of the current point
316056cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters
316156cf3b9cSMatthew G. Knepley . constants - constant parameters
316256cf3b9cSMatthew G. Knepley - bcval - output values at the current point
316356cf3b9cSMatthew G. Knepley 
316458ebd649SToby Isaac   Level: developer
316558ebd649SToby Isaac 
316656cf3b9cSMatthew G. Knepley .seealso: PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual()
316758ebd649SToby Isaac @*/
316856cf3b9cSMatthew G. Knepley PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), void (*bcFunc_t)(void), PetscInt numids, const PetscInt *ids, void *ctx)
316958ebd649SToby Isaac {
317058ebd649SToby Isaac   DSBoundary     b;
317158ebd649SToby Isaac   PetscErrorCode ierr;
317258ebd649SToby Isaac 
317358ebd649SToby Isaac   PetscFunctionBegin;
317458ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3175783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
3176783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 5);
3177783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, numcomps, 6);
3178783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, numids, 9);
317958ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
318058ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
318158ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
318258ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
3183580bdb30SBarry Smith   if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);}
318458ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
3185580bdb30SBarry Smith   if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);}
3186f971fd6bSMatthew G. Knepley   b->type            = type;
318758ebd649SToby Isaac   b->field           = field;
318858ebd649SToby Isaac   b->numcomps        = numcomps;
318958ebd649SToby Isaac   b->func            = bcFunc;
319056cf3b9cSMatthew G. Knepley   b->func_t          = bcFunc_t;
319158ebd649SToby Isaac   b->numids          = numids;
319258ebd649SToby Isaac   b->ctx             = ctx;
319358ebd649SToby Isaac   b->next            = ds->boundary;
319458ebd649SToby Isaac   ds->boundary       = b;
319558ebd649SToby Isaac   PetscFunctionReturn(0);
319658ebd649SToby Isaac }
319758ebd649SToby Isaac 
3198b67eacb3SMatthew G. Knepley /*@C
319956cf3b9cSMatthew G. Knepley   PetscDSUpdateBoundary - Change a boundary condition for the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performaed, using the kernels from PetscDSSetBdResidual().
3200b67eacb3SMatthew G. Knepley 
3201b67eacb3SMatthew G. Knepley   Input Parameters:
3202b67eacb3SMatthew G. Knepley + ds          - The PetscDS object
3203b67eacb3SMatthew G. Knepley . bd          - The boundary condition number
3204b67eacb3SMatthew G. Knepley . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
3205b67eacb3SMatthew G. Knepley . name        - The BC name
3206b67eacb3SMatthew G. Knepley . labelname   - The label defining constrained points
3207b67eacb3SMatthew G. Knepley . field       - The field to constrain
3208b67eacb3SMatthew G. Knepley . numcomps    - The number of constrained field components
3209b67eacb3SMatthew G. Knepley . comps       - An array of constrained component numbers
3210b67eacb3SMatthew G. Knepley . bcFunc      - A pointwise function giving boundary values
321156cf3b9cSMatthew G. Knepley . bcFunc_t    - A pointwise function giving the time derviative of the boundary values, or NULL
3212b67eacb3SMatthew G. Knepley . numids      - The number of DMLabel ids for constrained points
3213b67eacb3SMatthew G. Knepley . ids         - An array of ids for constrained points
3214b67eacb3SMatthew G. Knepley - ctx         - An optional user context for bcFunc
3215b67eacb3SMatthew G. Knepley 
321656cf3b9cSMatthew G. Knepley   Note:
321756cf3b9cSMatthew G. Knepley   The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from PetscDSGetNumBoundary(). See PetscDSAddBoundary() for a description of the calling sequences for the callbacks.
32189a6efb6aSMatthew G. Knepley 
3219b67eacb3SMatthew G. Knepley   Level: developer
3220b67eacb3SMatthew G. Knepley 
32219a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary()
3222b67eacb3SMatthew G. Knepley @*/
322356cf3b9cSMatthew G. Knepley PetscErrorCode PetscDSUpdateBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), void (*bcFunc_t)(void), PetscInt numids, const PetscInt *ids, void *ctx)
3224b67eacb3SMatthew G. Knepley {
3225b67eacb3SMatthew G. Knepley   DSBoundary     b = ds->boundary;
3226b67eacb3SMatthew G. Knepley   PetscInt       n = 0;
3227b67eacb3SMatthew G. Knepley   PetscErrorCode ierr;
3228b67eacb3SMatthew G. Knepley 
3229b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
3230b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3231b67eacb3SMatthew G. Knepley   while (b) {
3232b67eacb3SMatthew G. Knepley     if (n == bd) break;
3233b67eacb3SMatthew G. Knepley     b = b->next;
3234b67eacb3SMatthew G. Knepley     ++n;
3235b67eacb3SMatthew G. Knepley   }
3236b67eacb3SMatthew G. Knepley   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
3237b67eacb3SMatthew G. Knepley   if (name) {
3238b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
3239b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
3240b67eacb3SMatthew G. Knepley   }
3241b67eacb3SMatthew G. Knepley   if (labelname) {
3242b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
3243b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
3244b67eacb3SMatthew G. Knepley   }
3245b67eacb3SMatthew G. Knepley   if (numcomps >= 0 && numcomps != b->numcomps) {
3246b67eacb3SMatthew G. Knepley     b->numcomps = numcomps;
3247b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
3248b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
3249580bdb30SBarry Smith     if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);}
3250b67eacb3SMatthew G. Knepley   }
3251b67eacb3SMatthew G. Knepley   if (numids >= 0 && numids != b->numids) {
3252b67eacb3SMatthew G. Knepley     b->numids = numids;
3253b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->ids);CHKERRQ(ierr);
3254b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
3255580bdb30SBarry Smith     if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);}
3256b67eacb3SMatthew G. Knepley   }
3257b67eacb3SMatthew G. Knepley   b->type = type;
3258b67eacb3SMatthew G. Knepley   if (field >= 0) {b->field  = field;}
3259b67eacb3SMatthew G. Knepley   if (bcFunc)     {b->func   = bcFunc;}
326056cf3b9cSMatthew G. Knepley   if (bcFunc_t)   {b->func_t = bcFunc_t;}
3261b67eacb3SMatthew G. Knepley   if (ctx)        {b->ctx    = ctx;}
3262b67eacb3SMatthew G. Knepley   PetscFunctionReturn(0);
3263b67eacb3SMatthew G. Knepley }
3264b67eacb3SMatthew G. Knepley 
326558ebd649SToby Isaac /*@
326658ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
326758ebd649SToby Isaac 
326858ebd649SToby Isaac   Input Parameters:
326958ebd649SToby Isaac . ds - The PetscDS object
327058ebd649SToby Isaac 
327158ebd649SToby Isaac   Output Parameters:
327258ebd649SToby Isaac . numBd - The number of BC
327358ebd649SToby Isaac 
327458ebd649SToby Isaac   Level: intermediate
327558ebd649SToby Isaac 
327658ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
327758ebd649SToby Isaac @*/
327858ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
327958ebd649SToby Isaac {
328058ebd649SToby Isaac   DSBoundary b = ds->boundary;
328158ebd649SToby Isaac 
328258ebd649SToby Isaac   PetscFunctionBegin;
328358ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
328458ebd649SToby Isaac   PetscValidPointer(numBd, 2);
328558ebd649SToby Isaac   *numBd = 0;
328658ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
328758ebd649SToby Isaac   PetscFunctionReturn(0);
328858ebd649SToby Isaac }
328958ebd649SToby Isaac 
329058ebd649SToby Isaac /*@C
32919a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
329258ebd649SToby Isaac 
329358ebd649SToby Isaac   Input Parameters:
329458ebd649SToby Isaac + ds          - The PetscDS object
329558ebd649SToby Isaac - bd          - The BC number
329658ebd649SToby Isaac 
329758ebd649SToby Isaac   Output Parameters:
32982d47a189SJulian Andrej + type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
329958ebd649SToby Isaac . name        - The BC name
330058ebd649SToby Isaac . labelname   - The label defining constrained points
330158ebd649SToby Isaac . field       - The field to constrain
330258ebd649SToby Isaac . numcomps    - The number of constrained field components
330358ebd649SToby Isaac . comps       - An array of constrained component numbers
330458ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
330556cf3b9cSMatthew G. Knepley . bcFunc_t    - A pointwise function giving the time derviative of the boundary values
330658ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
330758ebd649SToby Isaac . ids         - An array of ids for constrained points
330858ebd649SToby Isaac - ctx         - An optional user context for bcFunc
330958ebd649SToby Isaac 
331058ebd649SToby Isaac   Options Database Keys:
331158ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
331258ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
331358ebd649SToby Isaac 
331458ebd649SToby Isaac   Level: developer
331558ebd649SToby Isaac 
331658ebd649SToby Isaac .seealso: PetscDSAddBoundary()
331758ebd649SToby Isaac @*/
331856cf3b9cSMatthew G. Knepley PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType *type, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(void), void (**func_t)(void), PetscInt *numids, const PetscInt **ids, void **ctx)
331958ebd649SToby Isaac {
332058ebd649SToby Isaac   DSBoundary b    = ds->boundary;
332158ebd649SToby Isaac   PetscInt   n    = 0;
332258ebd649SToby Isaac 
332358ebd649SToby Isaac   PetscFunctionBegin;
332458ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
332558ebd649SToby Isaac   while (b) {
332658ebd649SToby Isaac     if (n == bd) break;
332758ebd649SToby Isaac     b = b->next;
332858ebd649SToby Isaac     ++n;
332958ebd649SToby Isaac   }
333058ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
3331f971fd6bSMatthew G. Knepley   if (type) {
3332f971fd6bSMatthew G. Knepley     PetscValidPointer(type, 3);
3333f971fd6bSMatthew G. Knepley     *type = b->type;
333458ebd649SToby Isaac   }
333558ebd649SToby Isaac   if (name) {
333658ebd649SToby Isaac     PetscValidPointer(name, 4);
333758ebd649SToby Isaac     *name = b->name;
333858ebd649SToby Isaac   }
333958ebd649SToby Isaac   if (labelname) {
334058ebd649SToby Isaac     PetscValidPointer(labelname, 5);
334158ebd649SToby Isaac     *labelname = b->labelname;
334258ebd649SToby Isaac   }
334358ebd649SToby Isaac   if (field) {
334458ebd649SToby Isaac     PetscValidPointer(field, 6);
334558ebd649SToby Isaac     *field = b->field;
334658ebd649SToby Isaac   }
334758ebd649SToby Isaac   if (numcomps) {
334858ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
334958ebd649SToby Isaac     *numcomps = b->numcomps;
335058ebd649SToby Isaac   }
335158ebd649SToby Isaac   if (comps) {
335258ebd649SToby Isaac     PetscValidPointer(comps, 8);
335358ebd649SToby Isaac     *comps = b->comps;
335458ebd649SToby Isaac   }
335558ebd649SToby Isaac   if (func) {
335658ebd649SToby Isaac     PetscValidPointer(func, 9);
335758ebd649SToby Isaac     *func = b->func;
335858ebd649SToby Isaac   }
335956cf3b9cSMatthew G. Knepley   if (func_t) {
336056cf3b9cSMatthew G. Knepley     PetscValidPointer(func_t, 10);
336156cf3b9cSMatthew G. Knepley     *func_t = b->func_t;
336256cf3b9cSMatthew G. Knepley   }
336358ebd649SToby Isaac   if (numids) {
336456cf3b9cSMatthew G. Knepley     PetscValidPointer(numids, 11);
336558ebd649SToby Isaac     *numids = b->numids;
336658ebd649SToby Isaac   }
336758ebd649SToby Isaac   if (ids) {
336856cf3b9cSMatthew G. Knepley     PetscValidPointer(ids, 12);
336958ebd649SToby Isaac     *ids = b->ids;
337058ebd649SToby Isaac   }
337158ebd649SToby Isaac   if (ctx) {
337256cf3b9cSMatthew G. Knepley     PetscValidPointer(ctx, 13);
337358ebd649SToby Isaac     *ctx = b->ctx;
337458ebd649SToby Isaac   }
337558ebd649SToby Isaac   PetscFunctionReturn(0);
337658ebd649SToby Isaac }
337758ebd649SToby Isaac 
33789252d075SMatthew G. Knepley /*@
33799252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
33809252d075SMatthew G. Knepley 
33819252d075SMatthew G. Knepley   Not collective
33829252d075SMatthew G. Knepley 
338336951cb5SMatthew G. Knepley   Input Parameters:
338436951cb5SMatthew G. Knepley + ds        - The source PetscDS object
338536951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields
338636951cb5SMatthew G. Knepley - fields    - The selected fields, or NULL for all fields
33879252d075SMatthew G. Knepley 
33889252d075SMatthew G. Knepley   Output Parameter:
338936951cb5SMatthew G. Knepley . newds     - The target PetscDS, now with a copy of the boundary conditions
33909252d075SMatthew G. Knepley 
33919252d075SMatthew G. Knepley   Level: intermediate
33929252d075SMatthew G. Knepley 
33939252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
33949252d075SMatthew G. Knepley @*/
339536951cb5SMatthew G. Knepley PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds)
3396dff059c6SToby Isaac {
3397dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
3398dff059c6SToby Isaac   PetscErrorCode ierr;
3399dff059c6SToby Isaac 
3400dff059c6SToby Isaac   PetscFunctionBegin;
340136951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(ds,    PETSCDS_CLASSID, 1);
340236951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4);
340336951cb5SMatthew G. Knepley   if (ds == newds) PetscFunctionReturn(0);
340436951cb5SMatthew G. Knepley   next = newds->boundary;
3405dff059c6SToby Isaac   while (next) {
3406dff059c6SToby Isaac     DSBoundary b = next;
3407dff059c6SToby Isaac 
3408dff059c6SToby Isaac     next = b->next;
3409dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
3410dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
3411dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
3412dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
3413dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
3414dff059c6SToby Isaac   }
341536951cb5SMatthew G. Knepley   lastnext = &(newds->boundary);
341636951cb5SMatthew G. Knepley   for (b = ds->boundary; b; b = b->next) {
3417dff059c6SToby Isaac     DSBoundary bNew;
341836951cb5SMatthew G. Knepley     PetscInt   fieldNew = -1;
3419dff059c6SToby Isaac 
342036951cb5SMatthew G. Knepley     if (numFields > 0 && fields) {
342136951cb5SMatthew G. Knepley       PetscInt f;
342236951cb5SMatthew G. Knepley 
342336951cb5SMatthew G. Knepley       for (f = 0; f < numFields; ++f) if (b->field == fields[f]) break;
342436951cb5SMatthew G. Knepley       if (f == numFields) continue;
342536951cb5SMatthew G. Knepley       fieldNew = f;
342636951cb5SMatthew G. Knepley     }
3427459726d8SSatish Balay     ierr = PetscNew(&bNew);CHKERRQ(ierr);
3428dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
3429dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
3430580bdb30SBarry Smith     ierr = PetscArraycpy(bNew->comps, b->comps, bNew->numcomps);CHKERRQ(ierr);
3431dff059c6SToby Isaac     bNew->numids = b->numids;
3432dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
3433580bdb30SBarry Smith     ierr = PetscArraycpy(bNew->ids, b->ids, bNew->numids);CHKERRQ(ierr);
3434dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
3435dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
3436dff059c6SToby Isaac     bNew->ctx   = b->ctx;
3437f971fd6bSMatthew G. Knepley     bNew->type  = b->type;
343836951cb5SMatthew G. Knepley     bNew->field = fieldNew < 0 ? b->field : fieldNew;
3439dff059c6SToby Isaac     bNew->func  = b->func;
3440dff059c6SToby Isaac 
3441dff059c6SToby Isaac     *lastnext = bNew;
3442dff059c6SToby Isaac     lastnext = &(bNew->next);
3443dff059c6SToby Isaac   }
3444dff059c6SToby Isaac   PetscFunctionReturn(0);
3445dff059c6SToby Isaac }
3446dff059c6SToby Isaac 
34476c1eb96dSMatthew G. Knepley /*@
34486c1eb96dSMatthew G. Knepley   PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout
34496c1eb96dSMatthew G. Knepley 
34506c1eb96dSMatthew G. Knepley   Not collective
34516c1eb96dSMatthew G. Knepley 
34526c1eb96dSMatthew G. Knepley   Input Parameter:
34536c1eb96dSMatthew G. Knepley + prob - The PetscDS object
34546c1eb96dSMatthew G. Knepley . numFields - Number of new fields
34556c1eb96dSMatthew G. Knepley - fields - Old field number for each new field
34566c1eb96dSMatthew G. Knepley 
34576c1eb96dSMatthew G. Knepley   Output Parameter:
34586c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy
34596c1eb96dSMatthew G. Knepley 
34606c1eb96dSMatthew G. Knepley   Level: intermediate
34616c1eb96dSMatthew G. Knepley 
34626c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectEquations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
34636c1eb96dSMatthew G. Knepley @*/
34646c1eb96dSMatthew G. Knepley PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
34656c1eb96dSMatthew G. Knepley {
34666c1eb96dSMatthew G. Knepley   PetscInt       Nf, Nfn, fn;
34676c1eb96dSMatthew G. Knepley   PetscErrorCode ierr;
34686c1eb96dSMatthew G. Knepley 
34696c1eb96dSMatthew G. Knepley   PetscFunctionBegin;
34706c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
34716c1eb96dSMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
34726c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
34736c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
34746c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
34756c1eb96dSMatthew G. Knepley   if (numFields > Nfn) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields %D to transfer must not be greater then the total number of fields %D", numFields, Nfn);
34766c1eb96dSMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
34776c1eb96dSMatthew G. Knepley     const PetscInt f = fields ? fields[fn] : fn;
34786c1eb96dSMatthew G. Knepley     PetscObject    disc;
34796c1eb96dSMatthew G. Knepley 
34806c1eb96dSMatthew G. Knepley     if (f >= Nf) continue;
34816c1eb96dSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &disc);CHKERRQ(ierr);
34826c1eb96dSMatthew G. Knepley     ierr = PetscDSSetDiscretization(newprob, fn, disc);CHKERRQ(ierr);
34836c1eb96dSMatthew G. Knepley   }
34846c1eb96dSMatthew G. Knepley   PetscFunctionReturn(0);
34856c1eb96dSMatthew G. Knepley }
34866c1eb96dSMatthew G. Knepley 
34876c1eb96dSMatthew G. Knepley /*@
34889252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
34899252d075SMatthew G. Knepley 
34909252d075SMatthew G. Knepley   Not collective
34919252d075SMatthew G. Knepley 
34929252d075SMatthew G. Knepley   Input Parameter:
34939252d075SMatthew G. Knepley + prob - The PetscDS object
34949252d075SMatthew G. Knepley . numFields - Number of new fields
34959252d075SMatthew G. Knepley - fields - Old field number for each new field
34969252d075SMatthew G. Knepley 
34979252d075SMatthew G. Knepley   Output Parameter:
34989252d075SMatthew G. Knepley . newprob - The PetscDS copy
34999252d075SMatthew G. Knepley 
35009252d075SMatthew G. Knepley   Level: intermediate
35019252d075SMatthew G. Knepley 
35026c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectDiscretizations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
35039252d075SMatthew G. Knepley @*/
35049252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
35059252d075SMatthew G. Knepley {
35069252d075SMatthew G. Knepley   PetscInt       Nf, Nfn, fn, gn;
35079252d075SMatthew G. Knepley   PetscErrorCode ierr;
35089252d075SMatthew G. Knepley 
35099252d075SMatthew G. Knepley   PetscFunctionBegin;
35109252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
35119252d075SMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
35129252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
35139252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
35149252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
35159252d075SMatthew G. Knepley   if (numFields > Nfn) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields %D to transfer must not be greater then the total number of fields %D", numFields, Nfn);
35169252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
35179252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
35189252d075SMatthew G. Knepley     PetscPointFunc   obj;
35199252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
35209252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
35219252d075SMatthew G. Knepley     PetscRiemannFunc r;
35229252d075SMatthew G. Knepley 
3523c52f1e13SMatthew G. Knepley     if (f >= Nf) continue;
35249252d075SMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
35259252d075SMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
35269252d075SMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
35279252d075SMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
35289252d075SMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr);
35299252d075SMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr);
35309252d075SMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr);
35319252d075SMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr);
35329252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
35339252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
35349252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
35359252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
35369252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
35379252d075SMatthew G. Knepley 
3538c52f1e13SMatthew G. Knepley       if (g >= Nf) continue;
35399252d075SMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
35409252d075SMatthew G. Knepley       ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr);
35419252d075SMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
35429252d075SMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr);
35436c1eb96dSMatthew G. Knepley       ierr = PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr);
35449252d075SMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
35459252d075SMatthew G. Knepley     }
35469252d075SMatthew G. Knepley   }
35479252d075SMatthew G. Knepley   PetscFunctionReturn(0);
35489252d075SMatthew G. Knepley }
35499252d075SMatthew G. Knepley 
3550da51fcedSMatthew G. Knepley /*@
3551da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
3552da51fcedSMatthew G. Knepley 
3553da51fcedSMatthew G. Knepley   Not collective
3554da51fcedSMatthew G. Knepley 
3555da51fcedSMatthew G. Knepley   Input Parameter:
3556da51fcedSMatthew G. Knepley . prob - The PetscDS object
3557da51fcedSMatthew G. Knepley 
3558da51fcedSMatthew G. Knepley   Output Parameter:
3559da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
3560da51fcedSMatthew G. Knepley 
3561da51fcedSMatthew G. Knepley   Level: intermediate
3562da51fcedSMatthew G. Knepley 
35639252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
3564da51fcedSMatthew G. Knepley @*/
3565da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
3566da51fcedSMatthew G. Knepley {
35679252d075SMatthew G. Knepley   PetscInt       Nf, Ng;
3568da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
3569da51fcedSMatthew G. Knepley 
3570da51fcedSMatthew G. Knepley   PetscFunctionBegin;
3571da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3572da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
3573da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3574da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
357513903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
35769252d075SMatthew G. Knepley   ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr);
35779252d075SMatthew G. Knepley   PetscFunctionReturn(0);
35789252d075SMatthew G. Knepley }
35799252d075SMatthew G. Knepley /*@
35809252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
3581da51fcedSMatthew G. Knepley 
35829252d075SMatthew G. Knepley   Not collective
35839252d075SMatthew G. Knepley 
35849252d075SMatthew G. Knepley   Input Parameter:
35859252d075SMatthew G. Knepley . prob - The PetscDS object
35869252d075SMatthew G. Knepley 
35879252d075SMatthew G. Knepley   Output Parameter:
35889252d075SMatthew G. Knepley . newprob - The PetscDS copy
35899252d075SMatthew G. Knepley 
35909252d075SMatthew G. Knepley   Level: intermediate
35919252d075SMatthew G. Knepley 
35929252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
35939252d075SMatthew G. Knepley @*/
35949252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
35959252d075SMatthew G. Knepley {
35969252d075SMatthew G. Knepley   PetscInt           Nc;
35979252d075SMatthew G. Knepley   const PetscScalar *constants;
35989252d075SMatthew G. Knepley   PetscErrorCode     ierr;
35999252d075SMatthew G. Knepley 
36009252d075SMatthew G. Knepley   PetscFunctionBegin;
36019252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
36029252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
36039252d075SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr);
36049252d075SMatthew G. Knepley   ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr);
3605da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
3606da51fcedSMatthew G. Knepley }
3607da51fcedSMatthew G. Knepley 
3608b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
3609b1353e8eSMatthew G. Knepley {
3610df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
3611b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
3612b1353e8eSMatthew G. Knepley 
3613b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
3614b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3615b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
3616b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
3617b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3618df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
3619df3a45bdSMatthew G. Knepley   if (height > dim) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_OUTOFRANGE, "DS can only handle height in [0, %D], not %D", dim, height);
3620df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
3621df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
3622b1353e8eSMatthew G. Knepley     PetscInt cdim;
3623b1353e8eSMatthew G. Knepley 
3624df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
3625b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
3626df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
3627b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
3628b1353e8eSMatthew G. Knepley       PetscFE      subfe;
3629b1353e8eSMatthew G. Knepley       PetscObject  obj;
3630b1353e8eSMatthew G. Knepley       PetscClassId id;
3631b1353e8eSMatthew G. Knepley 
3632b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3633b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3634b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
3635b1353e8eSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
3636df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
3637b1353e8eSMatthew G. Knepley     }
3638b1353e8eSMatthew G. Knepley   }
3639df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
3640b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
3641b1353e8eSMatthew G. Knepley }
3642b1353e8eSMatthew G. Knepley 
3643665f567fSMatthew G. Knepley PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype)
3644c7bd5f0bSMatthew G. Knepley {
3645c7bd5f0bSMatthew G. Knepley   PetscObject    obj;
3646c7bd5f0bSMatthew G. Knepley   PetscClassId   id;
3647c7bd5f0bSMatthew G. Knepley   PetscInt       Nf;
3648c7bd5f0bSMatthew G. Knepley   PetscErrorCode ierr;
3649c7bd5f0bSMatthew G. Knepley 
3650c7bd5f0bSMatthew G. Knepley   PetscFunctionBegin;
3651c7bd5f0bSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3652665f567fSMatthew G. Knepley   PetscValidPointer(disctype, 3);
3653665f567fSMatthew G. Knepley   *disctype = PETSC_DISC_NONE;
3654c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
3655c7bd5f0bSMatthew G. Knepley   if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf);
3656c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr);
3657665f567fSMatthew G. Knepley   if (obj) {
3658c7bd5f0bSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3659665f567fSMatthew G. Knepley     if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE;
3660665f567fSMatthew G. Knepley     else                       *disctype = PETSC_DISC_FV;
3661665f567fSMatthew G. Knepley   }
3662c7bd5f0bSMatthew G. Knepley   PetscFunctionReturn(0);
3663c7bd5f0bSMatthew G. Knepley }
3664c7bd5f0bSMatthew G. Knepley 
3665*6528b96dSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds)
36662764a2aaSMatthew G. Knepley {
3667931fb3b8SToby Isaac   PetscErrorCode ierr;
3668931fb3b8SToby Isaac 
36692764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3670*6528b96dSMatthew G. Knepley   ierr = PetscFree(ds->data);CHKERRQ(ierr);
36712764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
36722764a2aaSMatthew G. Knepley }
36732764a2aaSMatthew G. Knepley 
3674*6528b96dSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds)
36752764a2aaSMatthew G. Knepley {
36762764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3677*6528b96dSMatthew G. Knepley   ds->ops->setfromoptions = NULL;
3678*6528b96dSMatthew G. Knepley   ds->ops->setup          = NULL;
3679*6528b96dSMatthew G. Knepley   ds->ops->view           = NULL;
3680*6528b96dSMatthew G. Knepley   ds->ops->destroy        = PetscDSDestroy_Basic;
36812764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
36822764a2aaSMatthew G. Knepley }
36832764a2aaSMatthew G. Knepley 
36842764a2aaSMatthew G. Knepley /*MC
36852764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
36862764a2aaSMatthew G. Knepley 
36872764a2aaSMatthew G. Knepley   Level: intermediate
36882764a2aaSMatthew G. Knepley 
36892764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
36902764a2aaSMatthew G. Knepley M*/
36912764a2aaSMatthew G. Knepley 
3692*6528b96dSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds)
36932764a2aaSMatthew G. Knepley {
36942764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
36952764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
36962764a2aaSMatthew G. Knepley 
36972764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3698*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3699*6528b96dSMatthew G. Knepley   ierr = PetscNewLog(ds, &b);CHKERRQ(ierr);
3700*6528b96dSMatthew G. Knepley   ds->data = b;
37012764a2aaSMatthew G. Knepley 
3702*6528b96dSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(ds);CHKERRQ(ierr);
37032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
37042764a2aaSMatthew G. Knepley }
3705