xref: /petsc/src/dm/dt/interface/dtds.c (revision 8e0d8d9c84ac09268995920ad4223a294a51783d)
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) {
188*8e0d8d9cSMatthew G. Knepley       const char *name;
18940967b3bSMatthew G. Knepley       PetscInt    c, i;
19040967b3bSMatthew G. Knepley 
19140967b3bSMatthew G. Knepley       if (b->field != f) continue;
19240967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
19340967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->labelname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr);
19440967b3bSMatthew G. Knepley       if (!b->numcomps) {
19540967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "  all components\n");CHKERRQ(ierr);
19640967b3bSMatthew G. Knepley       } else {
19740967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "  components: ");CHKERRQ(ierr);
19840967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
19940967b3bSMatthew G. Knepley         for (c = 0; c < b->numcomps; ++c) {
20040967b3bSMatthew G. Knepley           if (c > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
20140967b3bSMatthew G. Knepley           ierr = PetscViewerASCIIPrintf(viewer, "%D", b->comps[c]);CHKERRQ(ierr);
20240967b3bSMatthew G. Knepley         }
20340967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
20440967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
20540967b3bSMatthew G. Knepley       }
20640967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "  ids: ");CHKERRQ(ierr);
20740967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
20840967b3bSMatthew G. Knepley       for (i = 0; i < b->numids; ++i) {
20940967b3bSMatthew G. Knepley         if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
21040967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "%D", b->ids[i]);CHKERRQ(ierr);
21140967b3bSMatthew G. Knepley       }
21240967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
21340967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
214*8e0d8d9cSMatthew G. Knepley       if (b->func) {
215*8e0d8d9cSMatthew G. Knepley         ierr = PetscDLAddr(b->func, &name);CHKERRQ(ierr);
216*8e0d8d9cSMatthew G. Knepley         if (name) {ierr = PetscViewerASCIIPrintf(viewer, "  func: %s\n", name);CHKERRQ(ierr);}
217*8e0d8d9cSMatthew G. Knepley         else      {ierr = PetscViewerASCIIPrintf(viewer, "  func: %p\n", b->func);CHKERRQ(ierr);}
218*8e0d8d9cSMatthew G. Knepley       }
219*8e0d8d9cSMatthew G. Knepley       if (b->func_t) {
220*8e0d8d9cSMatthew G. Knepley         ierr = PetscDLAddr(b->func_t, &name);CHKERRQ(ierr);
221*8e0d8d9cSMatthew G. Knepley         if (name) {ierr = PetscViewerASCIIPrintf(viewer, "  func: %s\n", name);CHKERRQ(ierr);}
222*8e0d8d9cSMatthew G. Knepley         else      {ierr = PetscViewerASCIIPrintf(viewer, "  func: %p\n", b->func_t);CHKERRQ(ierr);}
223*8e0d8d9cSMatthew G. Knepley       }
22440967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
22540967b3bSMatthew G. Knepley     }
2267d8a60eaSMatthew G. Knepley   }
22797b6e6e8SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr);
22897b6e6e8SMatthew G. Knepley   if (numConstants) {
22997b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr);
23097b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
23157fc01e9SMatthew G. Knepley     for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);}
23297b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
23397b6e6e8SMatthew G. Knepley   }
2346528b96dSMatthew G. Knepley   ierr = PetscWeakFormView(prob->wf, viewer);CHKERRQ(ierr);
2357d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
2367d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
2377d8a60eaSMatthew G. Knepley }
2387d8a60eaSMatthew G. Knepley 
2392764a2aaSMatthew G. Knepley /*@C
240fe2efc57SMark    PetscDSViewFromOptions - View from Options
241fe2efc57SMark 
242fe2efc57SMark    Collective on PetscDS
243fe2efc57SMark 
244fe2efc57SMark    Input Parameters:
245fe2efc57SMark +  A - the PetscDS object
246736c3998SJose E. Roman .  obj - Optional object
247736c3998SJose E. Roman -  name - command line option
248fe2efc57SMark 
249fe2efc57SMark    Level: intermediate
250fe2efc57SMark .seealso:  PetscDS, PetscDSView, PetscObjectViewFromOptions(), PetscDSCreate()
251fe2efc57SMark @*/
252fe2efc57SMark PetscErrorCode  PetscDSViewFromOptions(PetscDS A,PetscObject obj,const char name[])
253fe2efc57SMark {
254fe2efc57SMark   PetscErrorCode ierr;
255fe2efc57SMark 
256fe2efc57SMark   PetscFunctionBegin;
257fe2efc57SMark   PetscValidHeaderSpecific(A,PETSCDS_CLASSID,1);
258fe2efc57SMark   ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr);
259fe2efc57SMark   PetscFunctionReturn(0);
260fe2efc57SMark }
261fe2efc57SMark 
262fe2efc57SMark /*@C
2632764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
2642764a2aaSMatthew G. Knepley 
265d083f849SBarry Smith   Collective on prob
2662764a2aaSMatthew G. Knepley 
2672764a2aaSMatthew G. Knepley   Input Parameter:
2682764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
2692764a2aaSMatthew G. Knepley - v  - the viewer
2702764a2aaSMatthew G. Knepley 
2712764a2aaSMatthew G. Knepley   Level: developer
2722764a2aaSMatthew G. Knepley 
2732764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
2742764a2aaSMatthew G. Knepley @*/
2752764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
2762764a2aaSMatthew G. Knepley {
2777d8a60eaSMatthew G. Knepley   PetscBool      iascii;
2782764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2792764a2aaSMatthew G. Knepley 
2802764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2812764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2822764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
2837d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
2847d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
2857d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2862764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2872764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2882764a2aaSMatthew G. Knepley }
2892764a2aaSMatthew G. Knepley 
2902764a2aaSMatthew G. Knepley /*@
2912764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2922764a2aaSMatthew G. Knepley 
293d083f849SBarry Smith   Collective on prob
2942764a2aaSMatthew G. Knepley 
2952764a2aaSMatthew G. Knepley   Input Parameter:
2962764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2972764a2aaSMatthew G. Knepley 
2982764a2aaSMatthew G. Knepley   Options Database:
29955c1f793SMatthew G. Knepley + -petscds_type <type>     : Set the DS type
30055c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS
30155c1f793SMatthew G. Knepley . -petscds_jac_pre         : Turn formation of a separate Jacobian preconditioner on and off
30255c1f793SMatthew G. Knepley . -bc_<name> <ids>         : Specify a list of label ids for a boundary condition
30355c1f793SMatthew G. Knepley - -bc_<name>_comp <comps>  : Specify a list of field components to constrain for a boundary condition
3042764a2aaSMatthew G. Knepley 
3052764a2aaSMatthew G. Knepley   Level: developer
3062764a2aaSMatthew G. Knepley 
3072764a2aaSMatthew G. Knepley .seealso PetscDSView()
3082764a2aaSMatthew G. Knepley @*/
3092764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
3102764a2aaSMatthew G. Knepley {
311f1fd5e65SToby Isaac   DSBoundary     b;
3122764a2aaSMatthew G. Knepley   const char    *defaultType;
3132764a2aaSMatthew G. Knepley   char           name[256];
3142764a2aaSMatthew G. Knepley   PetscBool      flg;
3152764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3162764a2aaSMatthew G. Knepley 
3172764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3182764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3192764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
3202764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
3212764a2aaSMatthew G. Knepley   } else {
3222764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
3232764a2aaSMatthew G. Knepley   }
3240f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
3252764a2aaSMatthew G. Knepley 
3262764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
327f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
328f1fd5e65SToby Isaac     char       optname[1024];
329f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
330f1fd5e65SToby Isaac     PetscBool  flg;
331f1fd5e65SToby Isaac 
332f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
333f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
334f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
335f1fd5e65SToby Isaac     if (flg) {
336f1fd5e65SToby Isaac       b->numids = len;
337f1fd5e65SToby Isaac       ierr = PetscFree(b->ids);CHKERRQ(ierr);
338f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr);
339580bdb30SBarry Smith       ierr = PetscArraycpy(b->ids, ids, len);CHKERRQ(ierr);
340f1fd5e65SToby Isaac     }
341e7b0402cSSander Arens     len = 1024;
342f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
343f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
344f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
345f1fd5e65SToby Isaac     if (flg) {
346f1fd5e65SToby Isaac       b->numcomps = len;
347f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
348f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
349580bdb30SBarry Smith       ierr = PetscArraycpy(b->comps, ids, len);CHKERRQ(ierr);
350f1fd5e65SToby Isaac     }
351f1fd5e65SToby Isaac   }
3522764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
3532764a2aaSMatthew G. Knepley   if (flg) {
3542764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
3552764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
3562764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
3572764a2aaSMatthew G. Knepley   }
35855c1f793SMatthew G. Knepley   ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr);
3592764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
3602764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
3610633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
3622764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
3635d160056SMatthew G. Knepley   if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);}
3642764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3652764a2aaSMatthew G. Knepley }
3662764a2aaSMatthew G. Knepley 
3672764a2aaSMatthew G. Knepley /*@C
3682764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
3692764a2aaSMatthew G. Knepley 
370d083f849SBarry Smith   Collective on prob
3712764a2aaSMatthew G. Knepley 
3722764a2aaSMatthew G. Knepley   Input Parameter:
3732764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
3742764a2aaSMatthew G. Knepley 
3752764a2aaSMatthew G. Knepley   Level: developer
3762764a2aaSMatthew G. Knepley 
3772764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
3782764a2aaSMatthew G. Knepley @*/
3792764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
3802764a2aaSMatthew G. Knepley {
3812764a2aaSMatthew G. Knepley   const PetscInt Nf   = prob->Nf;
382f9244615SMatthew G. Knepley   PetscBool      hasH = PETSC_FALSE;
3834bee2e38SMatthew G. Knepley   PetscInt       dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f;
3842764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3852764a2aaSMatthew G. Knepley 
3862764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3872764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3882764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3892764a2aaSMatthew G. Knepley   /* Calculate sizes */
3902764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
391d1506c7cSMatthew G. Knepley   ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr);
392f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
39347e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
394f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
395ef0bb6c7SMatthew G. Knepley   ierr = PetscMalloc2(Nf,&prob->T,Nf,&prob->Tf);CHKERRQ(ierr);
3962764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3979de99aefSMatthew G. Knepley     PetscObject     obj;
3989de99aefSMatthew G. Knepley     PetscClassId    id;
399665f567fSMatthew G. Knepley     PetscQuadrature q = NULL;
4009de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
4012764a2aaSMatthew G. Knepley 
4029de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
403f9244615SMatthew G. Knepley     if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE;
404665f567fSMatthew G. Knepley     if (!obj) {
405665f567fSMatthew G. Knepley       /* Empty mesh */
406665f567fSMatthew G. Knepley       Nb = Nc = 0;
407665f567fSMatthew G. Knepley       prob->T[f] = prob->Tf[f] = NULL;
408665f567fSMatthew G. Knepley     } else {
4099de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
4109de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {
4119de99aefSMatthew G. Knepley         PetscFE fe = (PetscFE) obj;
4129de99aefSMatthew G. Knepley 
4132764a2aaSMatthew G. Knepley         ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
4142764a2aaSMatthew G. Knepley         ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
4152764a2aaSMatthew G. Knepley         ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
416f9244615SMatthew G. Knepley         ierr = PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f]);CHKERRQ(ierr);
417f9244615SMatthew G. Knepley         ierr = PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f]);CHKERRQ(ierr);
4189de99aefSMatthew G. Knepley       } else if (id == PETSCFV_CLASSID) {
4199de99aefSMatthew G. Knepley         PetscFV fv = (PetscFV) obj;
4209de99aefSMatthew G. Knepley 
4219de99aefSMatthew G. Knepley         ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
4229de99aefSMatthew G. Knepley         ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
4239c3cf19fSMatthew G. Knepley         Nb   = Nc;
424ef0bb6c7SMatthew G. Knepley         ierr = PetscFVGetCellTabulation(fv, &prob->T[f]);CHKERRQ(ierr);
4254d0b9603SSander Arens         /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
426abac5ca0SMatthew G. Knepley       } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
427665f567fSMatthew G. Knepley     }
42847e57110SSander Arens     prob->Nc[f]       = Nc;
42947e57110SSander Arens     prob->Nb[f]       = Nb;
430194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
431194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
432a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
4332764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
4344bee2e38SMatthew G. Knepley     NbMax          = PetscMax(NbMax, Nb);
4352764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
4369c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
4372764a2aaSMatthew G. Knepley     prob->totComp += Nc;
43894a5e212SMatthew G. Knepley     /* There are two faces for all fields but the cohesive field on a hybrid cell */
43994a5e212SMatthew G. Knepley     if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb;
4402764a2aaSMatthew G. Knepley   }
4412764a2aaSMatthew G. Knepley   /* Allocate works space */
44294a5e212SMatthew G. Knepley   if (prob->isHybrid) NsMax = 2;
443f9244615SMatthew 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);
4444bee2e38SMatthew 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);
44527f02ce8SMatthew G. Knepley   ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dimEmbed,&prob->f1,
44627f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g1,
44727f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed*dimEmbed,&prob->g3);CHKERRQ(ierr);
4482764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
4492764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
4502764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4512764a2aaSMatthew G. Knepley }
4522764a2aaSMatthew G. Knepley 
4532764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
4542764a2aaSMatthew G. Knepley {
4552764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4562764a2aaSMatthew G. Knepley 
4572764a2aaSMatthew G. Knepley   PetscFunctionBegin;
45847e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
459f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
460ef0bb6c7SMatthew G. Knepley   ierr = PetscFree2(prob->T,prob->Tf);CHKERRQ(ierr);
4614bee2e38SMatthew G. Knepley   ierr = PetscFree3(prob->u,prob->u_t,prob->u_x);CHKERRQ(ierr);
4624bee2e38SMatthew G. Knepley   ierr = PetscFree5(prob->x,prob->basisReal, prob->basisDerReal,prob->testReal,prob->testDerReal);CHKERRQ(ierr);
4632764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
4642764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4652764a2aaSMatthew G. Knepley }
4662764a2aaSMatthew G. Knepley 
4672764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
4682764a2aaSMatthew G. Knepley {
469f744cafaSSander Arens   PetscObject      *tmpd;
47034aa8a36SMatthew G. Knepley   PetscBool        *tmpi;
471f9244615SMatthew G. Knepley   PetscInt         *tmpk;
4726528b96dSMatthew G. Knepley   PetscPointFunc   *tmpup;
473f2cacb80SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol,  *tmpexactSol_t;
474f2cacb80SMatthew G. Knepley   void                **tmpexactCtx, **tmpexactCtx_t;
4750c2f2876SMatthew G. Knepley   void            **tmpctx;
47634aa8a36SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f;
4772764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
4782764a2aaSMatthew G. Knepley 
4792764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4802764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
4812764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
4822764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
483f9244615SMatthew G. Knepley   ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpk);CHKERRQ(ierr);
484f9244615SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; tmpk[f] = prob->jetDegree[f];}
485f9244615SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpk[f] = 1;}
486f9244615SMatthew G. Knepley   ierr = PetscFree3(prob->disc, prob->implicit, prob->jetDegree);CHKERRQ(ierr);
4876528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(prob->wf, NfNew);CHKERRQ(ierr);
4882764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
4892764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
490249df284SMatthew G. Knepley   prob->implicit  = tmpi;
491f9244615SMatthew G. Knepley   prob->jetDegree = tmpk;
4926528b96dSMatthew G. Knepley   ierr = PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx);CHKERRQ(ierr);
49332d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
4940c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
49532d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
4960c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
4976528b96dSMatthew G. Knepley   ierr = PetscFree2(prob->update, prob->ctx);CHKERRQ(ierr);
49832d2bbc9SMatthew G. Knepley   prob->update = tmpup;
4990c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
5006528b96dSMatthew G. Knepley   ierr = PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t);CHKERRQ(ierr);
501c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
50295cbbfd3SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f];
503f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f];
504f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f];
505c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
50695cbbfd3SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL;
507f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL;
508f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL;
5096528b96dSMatthew G. Knepley   ierr = PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t);CHKERRQ(ierr);
510c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
51195cbbfd3SMatthew G. Knepley   prob->exactCtx = tmpexactCtx;
512f2cacb80SMatthew G. Knepley   prob->exactSol_t = tmpexactSol_t;
513f2cacb80SMatthew G. Knepley   prob->exactCtx_t = tmpexactCtx_t;
5142764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5152764a2aaSMatthew G. Knepley }
5162764a2aaSMatthew G. Knepley 
5172764a2aaSMatthew G. Knepley /*@
5182764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
5192764a2aaSMatthew G. Knepley 
520d083f849SBarry Smith   Collective on prob
5212764a2aaSMatthew G. Knepley 
5222764a2aaSMatthew G. Knepley   Input Parameter:
5232764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
5242764a2aaSMatthew G. Knepley 
5252764a2aaSMatthew G. Knepley   Level: developer
5262764a2aaSMatthew G. Knepley 
5272764a2aaSMatthew G. Knepley .seealso PetscDSView()
5282764a2aaSMatthew G. Knepley @*/
5296528b96dSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *ds)
5302764a2aaSMatthew G. Knepley {
5312764a2aaSMatthew G. Knepley   PetscInt       f;
53258ebd649SToby Isaac   DSBoundary     next;
5332764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5342764a2aaSMatthew G. Knepley 
5352764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5366528b96dSMatthew G. Knepley   if (!*ds) PetscFunctionReturn(0);
5376528b96dSMatthew G. Knepley   PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1);
5382764a2aaSMatthew G. Knepley 
5396528b96dSMatthew G. Knepley   if (--((PetscObject)(*ds))->refct > 0) {*ds = NULL; PetscFunctionReturn(0);}
5406528b96dSMatthew G. Knepley   ((PetscObject) (*ds))->refct = 0;
5416528b96dSMatthew G. Knepley   if ((*ds)->subprobs) {
542df3a45bdSMatthew G. Knepley     PetscInt dim, d;
543df3a45bdSMatthew G. Knepley 
5446528b96dSMatthew G. Knepley     ierr = PetscDSGetSpatialDimension(*ds, &dim);CHKERRQ(ierr);
5456528b96dSMatthew G. Knepley     for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*ds)->subprobs[d]);CHKERRQ(ierr);}
546df3a45bdSMatthew G. Knepley   }
5476528b96dSMatthew G. Knepley   ierr = PetscFree((*ds)->subprobs);CHKERRQ(ierr);
5486528b96dSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*ds);CHKERRQ(ierr);
5496528b96dSMatthew G. Knepley   for (f = 0; f < (*ds)->Nf; ++f) {
5506528b96dSMatthew G. Knepley     ierr = PetscObjectDereference((*ds)->disc[f]);CHKERRQ(ierr);
5512764a2aaSMatthew G. Knepley   }
5526528b96dSMatthew G. Knepley   ierr = PetscFree3((*ds)->disc, (*ds)->implicit, (*ds)->jetDegree);CHKERRQ(ierr);
5536528b96dSMatthew G. Knepley   ierr = PetscWeakFormDestroy(&(*ds)->wf);CHKERRQ(ierr);
5546528b96dSMatthew G. Knepley   ierr = PetscFree2((*ds)->update,(*ds)->ctx);CHKERRQ(ierr);
5556528b96dSMatthew G. Knepley   ierr = PetscFree4((*ds)->exactSol,(*ds)->exactCtx,(*ds)->exactSol_t,(*ds)->exactCtx_t);CHKERRQ(ierr);
5566528b96dSMatthew G. Knepley   if ((*ds)->ops->destroy) {ierr = (*(*ds)->ops->destroy)(*ds);CHKERRQ(ierr);}
5576528b96dSMatthew G. Knepley   next = (*ds)->boundary;
55858ebd649SToby Isaac   while (next) {
55958ebd649SToby Isaac     DSBoundary b = next;
56058ebd649SToby Isaac 
56158ebd649SToby Isaac     next = b->next;
56258ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
56358ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
56458ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
56558ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
56658ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
56758ebd649SToby Isaac   }
5686528b96dSMatthew G. Knepley   ierr = PetscFree((*ds)->constants);CHKERRQ(ierr);
5696528b96dSMatthew G. Knepley   ierr = PetscHeaderDestroy(ds);CHKERRQ(ierr);
5702764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5712764a2aaSMatthew G. Knepley }
5722764a2aaSMatthew G. Knepley 
5732764a2aaSMatthew G. Knepley /*@
5742764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
5752764a2aaSMatthew G. Knepley 
576d083f849SBarry Smith   Collective
5772764a2aaSMatthew G. Knepley 
5782764a2aaSMatthew G. Knepley   Input Parameter:
5792764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
5802764a2aaSMatthew G. Knepley 
5812764a2aaSMatthew G. Knepley   Output Parameter:
5826528b96dSMatthew G. Knepley . ds   - The PetscDS object
5832764a2aaSMatthew G. Knepley 
5842764a2aaSMatthew G. Knepley   Level: beginner
5852764a2aaSMatthew G. Knepley 
5862764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
5872764a2aaSMatthew G. Knepley @*/
5886528b96dSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds)
5892764a2aaSMatthew G. Knepley {
5902764a2aaSMatthew G. Knepley   PetscDS        p;
5912764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5922764a2aaSMatthew G. Knepley 
5932764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5946528b96dSMatthew G. Knepley   PetscValidPointer(ds, 2);
5956528b96dSMatthew G. Knepley   *ds  = NULL;
5962764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5972764a2aaSMatthew G. Knepley 
59873107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5992764a2aaSMatthew G. Knepley 
6002764a2aaSMatthew G. Knepley   p->Nf           = 0;
6012764a2aaSMatthew G. Knepley   p->setup        = PETSC_FALSE;
60297b6e6e8SMatthew G. Knepley   p->numConstants = 0;
60397b6e6e8SMatthew G. Knepley   p->constants    = NULL;
604a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
60555c1f793SMatthew G. Knepley   p->useJacPre    = PETSC_TRUE;
6066528b96dSMatthew G. Knepley   ierr = PetscWeakFormCreate(comm, &p->wf);CHKERRQ(ierr);
6072764a2aaSMatthew G. Knepley 
6086528b96dSMatthew G. Knepley   *ds = p;
6092764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6102764a2aaSMatthew G. Knepley }
6112764a2aaSMatthew G. Knepley 
612bc4ae4beSMatthew G. Knepley /*@
613bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
614bc4ae4beSMatthew G. Knepley 
615bc4ae4beSMatthew G. Knepley   Not collective
616bc4ae4beSMatthew G. Knepley 
617bc4ae4beSMatthew G. Knepley   Input Parameter:
618bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
619bc4ae4beSMatthew G. Knepley 
620bc4ae4beSMatthew G. Knepley   Output Parameter:
621bc4ae4beSMatthew G. Knepley . Nf - The number of fields
622bc4ae4beSMatthew G. Knepley 
623bc4ae4beSMatthew G. Knepley   Level: beginner
624bc4ae4beSMatthew G. Knepley 
625bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
626bc4ae4beSMatthew G. Knepley @*/
6272764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
6282764a2aaSMatthew G. Knepley {
6292764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6302764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6312764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
6322764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
6332764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6342764a2aaSMatthew G. Knepley }
6352764a2aaSMatthew G. Knepley 
636bc4ae4beSMatthew G. Knepley /*@
637a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
638bc4ae4beSMatthew G. Knepley 
639bc4ae4beSMatthew G. Knepley   Not collective
640bc4ae4beSMatthew G. Knepley 
641bc4ae4beSMatthew G. Knepley   Input Parameter:
642bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
643bc4ae4beSMatthew G. Knepley 
644bc4ae4beSMatthew G. Knepley   Output Parameter:
645bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
646bc4ae4beSMatthew G. Knepley 
647bc4ae4beSMatthew G. Knepley   Level: beginner
648bc4ae4beSMatthew G. Knepley 
649a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate()
650bc4ae4beSMatthew G. Knepley @*/
6512764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
6522764a2aaSMatthew G. Knepley {
6532764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6542764a2aaSMatthew G. Knepley 
6552764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6562764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6572764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6582764a2aaSMatthew G. Knepley   *dim = 0;
6599de99aefSMatthew G. Knepley   if (prob->Nf) {
6609de99aefSMatthew G. Knepley     PetscObject  obj;
6619de99aefSMatthew G. Knepley     PetscClassId id;
6629de99aefSMatthew G. Knepley 
6639de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
664665f567fSMatthew G. Knepley     if (obj) {
6659de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
6669de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
6679de99aefSMatthew G. Knepley       else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
6689de99aefSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
6699de99aefSMatthew G. Knepley     }
670665f567fSMatthew G. Knepley   }
6712764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6722764a2aaSMatthew G. Knepley }
6732764a2aaSMatthew G. Knepley 
674bc4ae4beSMatthew G. Knepley /*@
675a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
676a859676bSMatthew G. Knepley 
677a859676bSMatthew G. Knepley   Not collective
678a859676bSMatthew G. Knepley 
679a859676bSMatthew G. Knepley   Input Parameter:
680a859676bSMatthew G. Knepley . prob - The PetscDS object
681a859676bSMatthew G. Knepley 
682a859676bSMatthew G. Knepley   Output Parameter:
683a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
684a859676bSMatthew G. Knepley 
685a859676bSMatthew G. Knepley   Level: beginner
686a859676bSMatthew G. Knepley 
687a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
688a859676bSMatthew G. Knepley @*/
689a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
690a859676bSMatthew G. Knepley {
691a859676bSMatthew G. Knepley   PetscFunctionBegin;
692a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
693a859676bSMatthew G. Knepley   PetscValidPointer(dimEmbed, 2);
694a859676bSMatthew G. Knepley   if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
695a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
696a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
697a859676bSMatthew G. Knepley }
698a859676bSMatthew G. Knepley 
699a859676bSMatthew G. Knepley /*@
700a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
701a859676bSMatthew G. Knepley 
702d083f849SBarry Smith   Logically collective on prob
703a859676bSMatthew G. Knepley 
704a859676bSMatthew G. Knepley   Input Parameters:
705a859676bSMatthew G. Knepley + prob - The PetscDS object
706a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
707a859676bSMatthew G. Knepley 
708a859676bSMatthew G. Knepley   Level: beginner
709a859676bSMatthew G. Knepley 
710a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
711a859676bSMatthew G. Knepley @*/
712a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
713a859676bSMatthew G. Knepley {
714a859676bSMatthew G. Knepley   PetscFunctionBegin;
715a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
716ebfe4b0dSMatthew G. Knepley   if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed);
717a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
718a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
719a859676bSMatthew G. Knepley }
720a859676bSMatthew G. Knepley 
721a859676bSMatthew G. Knepley /*@
7228edf6225SMatthew G. Knepley   PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell
7238edf6225SMatthew G. Knepley 
7248edf6225SMatthew G. Knepley   Not collective
7258edf6225SMatthew G. Knepley 
7268edf6225SMatthew G. Knepley   Input Parameter:
7278edf6225SMatthew G. Knepley . prob - The PetscDS object
7288edf6225SMatthew G. Knepley 
7298edf6225SMatthew G. Knepley   Output Parameter:
7308edf6225SMatthew G. Knepley . isHybrid - The flag
7318edf6225SMatthew G. Knepley 
7328edf6225SMatthew G. Knepley   Level: developer
7338edf6225SMatthew G. Knepley 
7348edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate()
7358edf6225SMatthew G. Knepley @*/
7368edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid)
7378edf6225SMatthew G. Knepley {
7388edf6225SMatthew G. Knepley   PetscFunctionBegin;
7398edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7408edf6225SMatthew G. Knepley   PetscValidPointer(isHybrid, 2);
7418edf6225SMatthew G. Knepley   *isHybrid = prob->isHybrid;
7428edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7438edf6225SMatthew G. Knepley }
7448edf6225SMatthew G. Knepley 
7458edf6225SMatthew G. Knepley /*@
7468edf6225SMatthew G. Knepley   PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell
7478edf6225SMatthew G. Knepley 
7488edf6225SMatthew G. Knepley   Not collective
7498edf6225SMatthew G. Knepley 
7508edf6225SMatthew G. Knepley   Input Parameters:
7518edf6225SMatthew G. Knepley + prob - The PetscDS object
7528edf6225SMatthew G. Knepley - isHybrid - The flag
7538edf6225SMatthew G. Knepley 
7548edf6225SMatthew G. Knepley   Level: developer
7558edf6225SMatthew G. Knepley 
7568edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate()
7578edf6225SMatthew G. Knepley @*/
7588edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid)
7598edf6225SMatthew G. Knepley {
7608edf6225SMatthew G. Knepley   PetscFunctionBegin;
7618edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7628edf6225SMatthew G. Knepley   prob->isHybrid = isHybrid;
7638edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7648edf6225SMatthew G. Knepley }
7658edf6225SMatthew G. Knepley 
7668edf6225SMatthew G. Knepley /*@
767bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
768bc4ae4beSMatthew G. Knepley 
769bc4ae4beSMatthew G. Knepley   Not collective
770bc4ae4beSMatthew G. Knepley 
771bc4ae4beSMatthew G. Knepley   Input Parameter:
772bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
773bc4ae4beSMatthew G. Knepley 
774bc4ae4beSMatthew G. Knepley   Output Parameter:
775bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
776bc4ae4beSMatthew G. Knepley 
777bc4ae4beSMatthew G. Knepley   Level: beginner
778bc4ae4beSMatthew G. Knepley 
779bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
780bc4ae4beSMatthew G. Knepley @*/
7812764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
7822764a2aaSMatthew G. Knepley {
7832764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7842764a2aaSMatthew G. Knepley 
7852764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7862764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7872764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
7882764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
7892764a2aaSMatthew G. Knepley   *dim = prob->totDim;
7902764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7912764a2aaSMatthew G. Knepley }
7922764a2aaSMatthew G. Knepley 
793bc4ae4beSMatthew G. Knepley /*@
794bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
795bc4ae4beSMatthew G. Knepley 
796bc4ae4beSMatthew G. Knepley   Not collective
797bc4ae4beSMatthew G. Knepley 
798bc4ae4beSMatthew G. Knepley   Input Parameter:
799bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
800bc4ae4beSMatthew G. Knepley 
801bc4ae4beSMatthew G. Knepley   Output Parameter:
802bc4ae4beSMatthew G. Knepley . dim - The total number of components
803bc4ae4beSMatthew G. Knepley 
804bc4ae4beSMatthew G. Knepley   Level: beginner
805bc4ae4beSMatthew G. Knepley 
806bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
807bc4ae4beSMatthew G. Knepley @*/
8082764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
8092764a2aaSMatthew G. Knepley {
8102764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8112764a2aaSMatthew G. Knepley 
8122764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8132764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8142764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
8152764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
8162764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
8172764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8182764a2aaSMatthew G. Knepley }
8192764a2aaSMatthew G. Knepley 
820bc4ae4beSMatthew G. Knepley /*@
821bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
822bc4ae4beSMatthew G. Knepley 
823bc4ae4beSMatthew G. Knepley   Not collective
824bc4ae4beSMatthew G. Knepley 
825bc4ae4beSMatthew G. Knepley   Input Parameters:
826bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
827bc4ae4beSMatthew G. Knepley - f - The field number
828bc4ae4beSMatthew G. Knepley 
829bc4ae4beSMatthew G. Knepley   Output Parameter:
830bc4ae4beSMatthew G. Knepley . disc - The discretization object
831bc4ae4beSMatthew G. Knepley 
832bc4ae4beSMatthew G. Knepley   Level: beginner
833bc4ae4beSMatthew G. Knepley 
834f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
835bc4ae4beSMatthew G. Knepley @*/
8362764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
8372764a2aaSMatthew G. Knepley {
8386528b96dSMatthew G. Knepley   PetscFunctionBeginHot;
8392764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8402764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
8412764a2aaSMatthew 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);
8422764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
8432764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8442764a2aaSMatthew G. Knepley }
8452764a2aaSMatthew G. Knepley 
846bc4ae4beSMatthew G. Knepley /*@
847bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
848bc4ae4beSMatthew G. Knepley 
849bc4ae4beSMatthew G. Knepley   Not collective
850bc4ae4beSMatthew G. Knepley 
851bc4ae4beSMatthew G. Knepley   Input Parameters:
852bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
853bc4ae4beSMatthew G. Knepley . f - The field number
854bc4ae4beSMatthew G. Knepley - disc - The discretization object
855bc4ae4beSMatthew G. Knepley 
856bc4ae4beSMatthew G. Knepley   Level: beginner
857bc4ae4beSMatthew G. Knepley 
858bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
859bc4ae4beSMatthew G. Knepley @*/
8602764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
8612764a2aaSMatthew G. Knepley {
8622764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8632764a2aaSMatthew G. Knepley 
8642764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8652764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
866665f567fSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
8672764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
8682764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
869c10f2116SMatthew G. Knepley   ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);
8702764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
8712764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
872665f567fSMatthew G. Knepley   if (disc) {
873249df284SMatthew G. Knepley     PetscClassId id;
874249df284SMatthew G. Knepley 
875249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
8761cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
8771cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr);
8781cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
8791cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr);
880a6cbbb48SMatthew G. Knepley     }
881f9244615SMatthew G. Knepley     ierr = PetscDSSetJetDegree(prob, f, 1);CHKERRQ(ierr);
882249df284SMatthew G. Knepley   }
8832764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8842764a2aaSMatthew G. Knepley }
8852764a2aaSMatthew G. Knepley 
886bc4ae4beSMatthew G. Knepley /*@
8876528b96dSMatthew G. Knepley   PetscDSGetWeakForm - Returns the weak form object
8886528b96dSMatthew G. Knepley 
8896528b96dSMatthew G. Knepley   Not collective
8906528b96dSMatthew G. Knepley 
8916528b96dSMatthew G. Knepley   Input Parameter:
8926528b96dSMatthew G. Knepley . ds - The PetscDS object
8936528b96dSMatthew G. Knepley 
8946528b96dSMatthew G. Knepley   Output Parameter:
8956528b96dSMatthew G. Knepley . wf - The weak form object
8966528b96dSMatthew G. Knepley 
8976528b96dSMatthew G. Knepley   Level: beginner
8986528b96dSMatthew G. Knepley 
8996528b96dSMatthew G. Knepley .seealso: PetscDSSetWeakForm(), PetscDSGetNumFields(), PetscDSCreate()
9006528b96dSMatthew G. Knepley @*/
9016528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf)
9026528b96dSMatthew G. Knepley {
9036528b96dSMatthew G. Knepley   PetscFunctionBegin;
9046528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
9056528b96dSMatthew G. Knepley   PetscValidPointer(wf, 2);
9066528b96dSMatthew G. Knepley   *wf = ds->wf;
9076528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9086528b96dSMatthew G. Knepley }
9096528b96dSMatthew G. Knepley 
9106528b96dSMatthew G. Knepley /*@
9116528b96dSMatthew G. Knepley   PetscDSSetWeakForm - Sets the weak form object
9126528b96dSMatthew G. Knepley 
9136528b96dSMatthew G. Knepley   Not collective
9146528b96dSMatthew G. Knepley 
9156528b96dSMatthew G. Knepley   Input Parameters:
9166528b96dSMatthew G. Knepley + ds - The PetscDS object
9176528b96dSMatthew G. Knepley - wf - The weak form object
9186528b96dSMatthew G. Knepley 
9196528b96dSMatthew G. Knepley   Level: beginner
9206528b96dSMatthew G. Knepley 
9216528b96dSMatthew G. Knepley .seealso: PetscDSGetWeakForm(), PetscDSGetNumFields(), PetscDSCreate()
9226528b96dSMatthew G. Knepley @*/
9236528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf)
9246528b96dSMatthew G. Knepley {
9256528b96dSMatthew G. Knepley   PetscErrorCode ierr;
9266528b96dSMatthew G. Knepley 
9276528b96dSMatthew G. Knepley   PetscFunctionBegin;
9286528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
9296528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2);
9306528b96dSMatthew G. Knepley   ierr = PetscObjectDereference((PetscObject) ds->wf);CHKERRQ(ierr);
9316528b96dSMatthew G. Knepley   ds->wf = wf;
9326528b96dSMatthew G. Knepley   ierr = PetscObjectReference((PetscObject) wf);CHKERRQ(ierr);
9336528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(wf, ds->Nf);CHKERRQ(ierr);
9346528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9356528b96dSMatthew G. Knepley }
9366528b96dSMatthew G. Knepley 
9376528b96dSMatthew G. Knepley /*@
938bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
939bc4ae4beSMatthew G. Knepley 
940bc4ae4beSMatthew G. Knepley   Not collective
941bc4ae4beSMatthew G. Knepley 
942bc4ae4beSMatthew G. Knepley   Input Parameters:
943bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
944bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
945bc4ae4beSMatthew G. Knepley 
946bc4ae4beSMatthew G. Knepley   Level: beginner
947bc4ae4beSMatthew G. Knepley 
948bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
949bc4ae4beSMatthew G. Knepley @*/
9502764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
9512764a2aaSMatthew G. Knepley {
9522764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9532764a2aaSMatthew G. Knepley 
9542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9552764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
9562764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9572764a2aaSMatthew G. Knepley }
9582764a2aaSMatthew G. Knepley 
959249df284SMatthew G. Knepley /*@
960083401c6SMatthew G. Knepley   PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS
961083401c6SMatthew G. Knepley 
962083401c6SMatthew G. Knepley   Not collective
963083401c6SMatthew G. Knepley 
964083401c6SMatthew G. Knepley   Input Parameter:
965083401c6SMatthew G. Knepley . prob - The PetscDS object
966083401c6SMatthew G. Knepley 
967083401c6SMatthew G. Knepley   Output Parameter:
968083401c6SMatthew G. Knepley . q - The quadrature object
969083401c6SMatthew G. Knepley 
970083401c6SMatthew G. Knepley Level: intermediate
971083401c6SMatthew G. Knepley 
972083401c6SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
973083401c6SMatthew G. Knepley @*/
974083401c6SMatthew G. Knepley PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q)
975083401c6SMatthew G. Knepley {
976083401c6SMatthew G. Knepley   PetscObject    obj;
977083401c6SMatthew G. Knepley   PetscClassId   id;
978083401c6SMatthew G. Knepley   PetscErrorCode ierr;
979083401c6SMatthew G. Knepley 
980083401c6SMatthew G. Knepley   PetscFunctionBegin;
981083401c6SMatthew G. Knepley   *q = NULL;
982083401c6SMatthew G. Knepley   if (!prob->Nf) PetscFunctionReturn(0);
983083401c6SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
984083401c6SMatthew G. Knepley   ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
985083401c6SMatthew G. Knepley   if      (id == PETSCFE_CLASSID) {ierr = PetscFEGetQuadrature((PetscFE) obj, q);CHKERRQ(ierr);}
986083401c6SMatthew G. Knepley   else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetQuadrature((PetscFV) obj, q);CHKERRQ(ierr);}
987083401c6SMatthew G. Knepley   else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
988083401c6SMatthew G. Knepley   PetscFunctionReturn(0);
989083401c6SMatthew G. Knepley }
990083401c6SMatthew G. Knepley 
991083401c6SMatthew G. Knepley /*@
992249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
993249df284SMatthew G. Knepley 
994249df284SMatthew G. Knepley   Not collective
995249df284SMatthew G. Knepley 
996249df284SMatthew G. Knepley   Input Parameters:
997249df284SMatthew G. Knepley + prob - The PetscDS object
998249df284SMatthew G. Knepley - f - The field number
999249df284SMatthew G. Knepley 
1000249df284SMatthew G. Knepley   Output Parameter:
1001249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
1002249df284SMatthew G. Knepley 
1003249df284SMatthew G. Knepley   Level: developer
1004249df284SMatthew G. Knepley 
1005f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1006249df284SMatthew G. Knepley @*/
1007249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
1008249df284SMatthew G. Knepley {
1009249df284SMatthew G. Knepley   PetscFunctionBegin;
1010249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1011249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
1012249df284SMatthew 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);
1013249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
1014249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1015249df284SMatthew G. Knepley }
1016249df284SMatthew G. Knepley 
1017249df284SMatthew G. Knepley /*@
1018249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
1019249df284SMatthew G. Knepley 
1020249df284SMatthew G. Knepley   Not collective
1021249df284SMatthew G. Knepley 
1022249df284SMatthew G. Knepley   Input Parameters:
1023249df284SMatthew G. Knepley + prob - The PetscDS object
1024249df284SMatthew G. Knepley . f - The field number
1025249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
1026249df284SMatthew G. Knepley 
1027249df284SMatthew G. Knepley   Level: developer
1028249df284SMatthew G. Knepley 
1029f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1030249df284SMatthew G. Knepley @*/
1031249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
1032249df284SMatthew G. Knepley {
1033249df284SMatthew G. Knepley   PetscFunctionBegin;
1034249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1035249df284SMatthew 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);
1036249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
1037249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1038249df284SMatthew G. Knepley }
1039249df284SMatthew G. Knepley 
1040f9244615SMatthew G. Knepley /*@
1041f9244615SMatthew G. Knepley   PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1042f9244615SMatthew G. Knepley 
1043f9244615SMatthew G. Knepley   Not collective
1044f9244615SMatthew G. Knepley 
1045f9244615SMatthew G. Knepley   Input Parameters:
1046f9244615SMatthew G. Knepley + ds - The PetscDS object
1047f9244615SMatthew G. Knepley - f  - The field number
1048f9244615SMatthew G. Knepley 
1049f9244615SMatthew G. Knepley   Output Parameter:
1050f9244615SMatthew G. Knepley . k  - The highest derivative we need to tabulate
1051f9244615SMatthew G. Knepley 
1052f9244615SMatthew G. Knepley   Level: developer
1053f9244615SMatthew G. Knepley 
1054f9244615SMatthew G. Knepley .seealso: PetscDSSetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1055f9244615SMatthew G. Knepley @*/
1056f9244615SMatthew G. Knepley PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k)
1057f9244615SMatthew G. Knepley {
1058f9244615SMatthew G. Knepley   PetscFunctionBegin;
1059f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1060f9244615SMatthew G. Knepley   PetscValidPointer(k, 3);
1061f9244615SMatthew 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);
1062f9244615SMatthew G. Knepley   *k = ds->jetDegree[f];
1063f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1064f9244615SMatthew G. Knepley }
1065f9244615SMatthew G. Knepley 
1066f9244615SMatthew G. Knepley /*@
1067f9244615SMatthew G. Knepley   PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1068f9244615SMatthew G. Knepley 
1069f9244615SMatthew G. Knepley   Not collective
1070f9244615SMatthew G. Knepley 
1071f9244615SMatthew G. Knepley   Input Parameters:
1072f9244615SMatthew G. Knepley + ds - The PetscDS object
1073f9244615SMatthew G. Knepley . f  - The field number
1074f9244615SMatthew G. Knepley - k  - The highest derivative we need to tabulate
1075f9244615SMatthew G. Knepley 
1076f9244615SMatthew G. Knepley   Level: developer
1077f9244615SMatthew G. Knepley 
1078f9244615SMatthew G. Knepley .seealso: PetscDSGetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1079f9244615SMatthew G. Knepley @*/
1080f9244615SMatthew G. Knepley PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k)
1081f9244615SMatthew G. Knepley {
1082f9244615SMatthew G. Knepley   PetscFunctionBegin;
1083f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1084f9244615SMatthew 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);
1085f9244615SMatthew G. Knepley   ds->jetDegree[f] = k;
1086f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1087f9244615SMatthew G. Knepley }
1088f9244615SMatthew G. Knepley 
10896528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS ds, PetscInt f,
109030b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1091194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1092194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
109397b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
10942764a2aaSMatthew G. Knepley {
10956528b96dSMatthew G. Knepley   PetscPointFunc *tmp;
10966528b96dSMatthew G. Knepley   PetscInt        n;
10976528b96dSMatthew G. Knepley   PetscErrorCode  ierr;
10986528b96dSMatthew G. Knepley 
10992764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11006528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11016528b96dSMatthew G. Knepley   PetscValidPointer(obj, 3);
11026528b96dSMatthew 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);
11036528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetObjective(ds->wf, NULL, 0, f, &n, &tmp);CHKERRQ(ierr);
11046528b96dSMatthew G. Knepley   *obj = tmp ? tmp[0] : NULL;
11052764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11062764a2aaSMatthew G. Knepley }
11072764a2aaSMatthew G. Knepley 
11086528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS ds, PetscInt f,
110930b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1110194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1111194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
111297b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
11132764a2aaSMatthew G. Knepley {
11142764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
11152764a2aaSMatthew G. Knepley 
11162764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11176528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11186528b96dSMatthew G. Knepley   if (obj) PetscValidFunction(obj, 3);
11192764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
11206528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, obj);CHKERRQ(ierr);
11212764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11222764a2aaSMatthew G. Knepley }
11232764a2aaSMatthew G. Knepley 
1124194d53e6SMatthew G. Knepley /*@C
1125194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1126194d53e6SMatthew G. Knepley 
1127194d53e6SMatthew G. Knepley   Not collective
1128194d53e6SMatthew G. Knepley 
1129194d53e6SMatthew G. Knepley   Input Parameters:
11306528b96dSMatthew G. Knepley + ds - The PetscDS
1131194d53e6SMatthew G. Knepley - f  - The test field number
1132194d53e6SMatthew G. Knepley 
1133194d53e6SMatthew G. Knepley   Output Parameters:
1134194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1135194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1136194d53e6SMatthew G. Knepley 
1137194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1138194d53e6SMatthew G. Knepley 
1139194d53e6SMatthew 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)
1140194d53e6SMatthew G. Knepley 
1141194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1142194d53e6SMatthew G. Knepley 
114330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1144194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1145194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
114630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1147194d53e6SMatthew G. Knepley 
1148194d53e6SMatthew G. Knepley + dim - the spatial dimension
1149194d53e6SMatthew G. Knepley . Nf - the number of fields
1150194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1151194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1152194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1153194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1154194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1155194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1156194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1157194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1158194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1159194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1160194d53e6SMatthew G. Knepley . t - current time
1161194d53e6SMatthew G. Knepley . x - coordinates of the current point
116297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
116397b6e6e8SMatthew G. Knepley . constants - constant parameters
1164194d53e6SMatthew G. Knepley - f0 - output values at the current point
1165194d53e6SMatthew G. Knepley 
1166194d53e6SMatthew G. Knepley   Level: intermediate
1167194d53e6SMatthew G. Knepley 
1168194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
1169194d53e6SMatthew G. Knepley @*/
11706528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS ds, PetscInt f,
117130b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1172194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1173194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117497b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
117530b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1176194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1177194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117897b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
11792764a2aaSMatthew G. Knepley {
11806528b96dSMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
11816528b96dSMatthew G. Knepley   PetscInt        n0, n1;
11826528b96dSMatthew G. Knepley   PetscErrorCode  ierr;
11836528b96dSMatthew G. Knepley 
11842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11856528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11866528b96dSMatthew 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);
11876528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetResidual(ds->wf, NULL, 0, f, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
11886528b96dSMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
11896528b96dSMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
11902764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11912764a2aaSMatthew G. Knepley }
11922764a2aaSMatthew G. Knepley 
1193194d53e6SMatthew G. Knepley /*@C
1194194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1195194d53e6SMatthew G. Knepley 
1196194d53e6SMatthew G. Knepley   Not collective
1197194d53e6SMatthew G. Knepley 
1198194d53e6SMatthew G. Knepley   Input Parameters:
11996528b96dSMatthew G. Knepley + ds - The PetscDS
1200194d53e6SMatthew G. Knepley . f  - The test field number
1201194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1202194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1203194d53e6SMatthew G. Knepley 
1204194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1205194d53e6SMatthew G. Knepley 
1206194d53e6SMatthew 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)
1207194d53e6SMatthew G. Knepley 
1208194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1209194d53e6SMatthew G. Knepley 
121030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1211194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1212194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
121330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1214194d53e6SMatthew G. Knepley 
1215194d53e6SMatthew G. Knepley + dim - the spatial dimension
1216194d53e6SMatthew G. Knepley . Nf - the number of fields
1217194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1218194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1219194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1220194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1221194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1222194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1223194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1224194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1225194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1226194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1227194d53e6SMatthew G. Knepley . t - current time
1228194d53e6SMatthew G. Knepley . x - coordinates of the current point
122997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
123097b6e6e8SMatthew G. Knepley . constants - constant parameters
1231194d53e6SMatthew G. Knepley - f0 - output values at the current point
1232194d53e6SMatthew G. Knepley 
1233194d53e6SMatthew G. Knepley   Level: intermediate
1234194d53e6SMatthew G. Knepley 
1235194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1236194d53e6SMatthew G. Knepley @*/
12376528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS ds, PetscInt f,
123830b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1239194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1240194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
124197b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
124230b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1243194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1244194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
124597b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
12462764a2aaSMatthew G. Knepley {
12472764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
12482764a2aaSMatthew G. Knepley 
12492764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12506528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1251f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1252f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
12532764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
12546528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, f0, 0, f1);CHKERRQ(ierr);
12552764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12562764a2aaSMatthew G. Knepley }
12572764a2aaSMatthew G. Knepley 
12583e75805dSMatthew G. Knepley /*@C
12593e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
12603e75805dSMatthew G. Knepley 
12613e75805dSMatthew G. Knepley   Not collective
12623e75805dSMatthew G. Knepley 
12633e75805dSMatthew G. Knepley   Input Parameter:
12643e75805dSMatthew G. Knepley . prob - The PetscDS
12653e75805dSMatthew G. Knepley 
12663e75805dSMatthew G. Knepley   Output Parameter:
12673e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
12683e75805dSMatthew G. Knepley 
12693e75805dSMatthew G. Knepley   Level: intermediate
12703e75805dSMatthew G. Knepley 
12713e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
12723e75805dSMatthew G. Knepley @*/
12736528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac)
12743e75805dSMatthew G. Knepley {
12756528b96dSMatthew G. Knepley   PetscErrorCode ierr;
12763e75805dSMatthew G. Knepley 
12773e75805dSMatthew G. Knepley   PetscFunctionBegin;
12786528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
12796528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobian(ds->wf, hasJac);CHKERRQ(ierr);
12803e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
12813e75805dSMatthew G. Knepley }
12823e75805dSMatthew G. Knepley 
1283194d53e6SMatthew G. Knepley /*@C
1284194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1285194d53e6SMatthew G. Knepley 
1286194d53e6SMatthew G. Knepley   Not collective
1287194d53e6SMatthew G. Knepley 
1288194d53e6SMatthew G. Knepley   Input Parameters:
12896528b96dSMatthew G. Knepley + ds - The PetscDS
1290194d53e6SMatthew G. Knepley . f  - The test field number
1291194d53e6SMatthew G. Knepley - g  - The field number
1292194d53e6SMatthew G. Knepley 
1293194d53e6SMatthew G. Knepley   Output Parameters:
1294194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1295194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1296194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1297194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1298194d53e6SMatthew G. Knepley 
1299194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1300194d53e6SMatthew G. Knepley 
1301194d53e6SMatthew 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
1302194d53e6SMatthew G. Knepley 
1303194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1304194d53e6SMatthew G. Knepley 
130530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1306194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1307194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1309194d53e6SMatthew G. Knepley 
1310194d53e6SMatthew G. Knepley + dim - the spatial dimension
1311194d53e6SMatthew G. Knepley . Nf - the number of fields
1312194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1313194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1314194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1315194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1316194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1317194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1318194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1319194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1320194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1321194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1322194d53e6SMatthew G. Knepley . t - current time
13232aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1324194d53e6SMatthew G. Knepley . x - coordinates of the current point
132597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
132697b6e6e8SMatthew G. Knepley . constants - constant parameters
1327194d53e6SMatthew G. Knepley - g0 - output values at the current point
1328194d53e6SMatthew G. Knepley 
1329194d53e6SMatthew G. Knepley   Level: intermediate
1330194d53e6SMatthew G. Knepley 
1331194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1332194d53e6SMatthew G. Knepley @*/
13336528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS ds, PetscInt f, PetscInt g,
133430b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1335194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1336194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
133797b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
133830b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1339194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1340194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
134197b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
134230b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1343194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1344194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
134597b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
134630b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1347194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1348194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
134997b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
13502764a2aaSMatthew G. Knepley {
13516528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
13526528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
13536528b96dSMatthew G. Knepley   PetscErrorCode ierr;
13546528b96dSMatthew G. Knepley 
13552764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13566528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
13576528b96dSMatthew 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);
13586528b96dSMatthew 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);
13596528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
13606528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
13616528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
13626528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
13636528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
13642764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
13652764a2aaSMatthew G. Knepley }
13662764a2aaSMatthew G. Knepley 
1367194d53e6SMatthew G. Knepley /*@C
1368194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1369194d53e6SMatthew G. Knepley 
1370194d53e6SMatthew G. Knepley   Not collective
1371194d53e6SMatthew G. Knepley 
1372194d53e6SMatthew G. Knepley   Input Parameters:
13736528b96dSMatthew G. Knepley + ds - The PetscDS
1374194d53e6SMatthew G. Knepley . f  - The test field number
1375194d53e6SMatthew G. Knepley . g  - The field number
1376194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1377194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1378194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1379194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1380194d53e6SMatthew G. Knepley 
1381194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1382194d53e6SMatthew G. Knepley 
1383194d53e6SMatthew 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
1384194d53e6SMatthew G. Knepley 
1385194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1386194d53e6SMatthew G. Knepley 
138730b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1388194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1389194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
139030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1391194d53e6SMatthew G. Knepley 
1392194d53e6SMatthew G. Knepley + dim - the spatial dimension
1393194d53e6SMatthew G. Knepley . Nf - the number of fields
1394194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1395194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1396194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1397194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1398194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1399194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1400194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1401194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1402194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1403194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1404194d53e6SMatthew G. Knepley . t - current time
14052aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1406194d53e6SMatthew G. Knepley . x - coordinates of the current point
140797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
140897b6e6e8SMatthew G. Knepley . constants - constant parameters
1409194d53e6SMatthew G. Knepley - g0 - output values at the current point
1410194d53e6SMatthew G. Knepley 
1411194d53e6SMatthew G. Knepley   Level: intermediate
1412194d53e6SMatthew G. Knepley 
1413194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1414194d53e6SMatthew G. Knepley @*/
14156528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS ds, PetscInt f, PetscInt g,
141630b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1417194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1418194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
141997b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
142030b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1421194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1422194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
142397b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
142430b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1425194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1426194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
142797b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
142830b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1429194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1430194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
143197b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
14322764a2aaSMatthew G. Knepley {
14332764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
14342764a2aaSMatthew G. Knepley 
14352764a2aaSMatthew G. Knepley   PetscFunctionBegin;
14366528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
14372764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
14382764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
14392764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
14402764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
14412764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
14422764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
14436528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
14442764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
14452764a2aaSMatthew G. Knepley }
14462764a2aaSMatthew G. Knepley 
1447475e0ac9SMatthew G. Knepley /*@C
144855c1f793SMatthew G. Knepley   PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner
144955c1f793SMatthew G. Knepley 
145055c1f793SMatthew G. Knepley   Not collective
145155c1f793SMatthew G. Knepley 
145255c1f793SMatthew G. Knepley   Input Parameters:
145355c1f793SMatthew G. Knepley + prob - The PetscDS
145455c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
145555c1f793SMatthew G. Knepley 
145655c1f793SMatthew G. Knepley   Level: intermediate
145755c1f793SMatthew G. Knepley 
145855c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
145955c1f793SMatthew G. Knepley @*/
146055c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
146155c1f793SMatthew G. Knepley {
146255c1f793SMatthew G. Knepley   PetscFunctionBegin;
146355c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
146455c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
146555c1f793SMatthew G. Knepley   PetscFunctionReturn(0);
146655c1f793SMatthew G. Knepley }
146755c1f793SMatthew G. Knepley 
146855c1f793SMatthew G. Knepley /*@C
1469475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1470475e0ac9SMatthew G. Knepley 
1471475e0ac9SMatthew G. Knepley   Not collective
1472475e0ac9SMatthew G. Knepley 
1473475e0ac9SMatthew G. Knepley   Input Parameter:
1474475e0ac9SMatthew G. Knepley . prob - The PetscDS
1475475e0ac9SMatthew G. Knepley 
1476475e0ac9SMatthew G. Knepley   Output Parameter:
1477475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1478475e0ac9SMatthew G. Knepley 
1479475e0ac9SMatthew G. Knepley   Level: intermediate
1480475e0ac9SMatthew G. Knepley 
1481475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1482475e0ac9SMatthew G. Knepley @*/
14836528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre)
1484475e0ac9SMatthew G. Knepley {
14856528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1486475e0ac9SMatthew G. Knepley 
1487475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
14886528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1489475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
14906528b96dSMatthew G. Knepley   if (!ds->useJacPre) PetscFunctionReturn(0);
14916528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre);CHKERRQ(ierr);
1492475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1493475e0ac9SMatthew G. Knepley }
1494475e0ac9SMatthew G. Knepley 
1495475e0ac9SMatthew G. Knepley /*@C
1496475e0ac9SMatthew 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.
1497475e0ac9SMatthew G. Knepley 
1498475e0ac9SMatthew G. Knepley   Not collective
1499475e0ac9SMatthew G. Knepley 
1500475e0ac9SMatthew G. Knepley   Input Parameters:
15016528b96dSMatthew G. Knepley + ds - The PetscDS
1502475e0ac9SMatthew G. Knepley . f  - The test field number
1503475e0ac9SMatthew G. Knepley - g  - The field number
1504475e0ac9SMatthew G. Knepley 
1505475e0ac9SMatthew G. Knepley   Output Parameters:
1506475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1507475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1508475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1509475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1510475e0ac9SMatthew G. Knepley 
1511475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1512475e0ac9SMatthew G. Knepley 
1513475e0ac9SMatthew 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
1514475e0ac9SMatthew G. Knepley 
1515475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1516475e0ac9SMatthew G. Knepley 
1517475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1518475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1519475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1520475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1521475e0ac9SMatthew G. Knepley 
1522475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1523475e0ac9SMatthew G. Knepley . Nf - the number of fields
1524475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1525475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1526475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1527475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1528475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1529475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1530475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1531475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1532475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1533475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1534475e0ac9SMatthew G. Knepley . t - current time
1535475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1536475e0ac9SMatthew G. Knepley . x - coordinates of the current point
153797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
153897b6e6e8SMatthew G. Knepley . constants - constant parameters
1539475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1540475e0ac9SMatthew G. Knepley 
1541475e0ac9SMatthew G. Knepley   Level: intermediate
1542475e0ac9SMatthew G. Knepley 
1543475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1544475e0ac9SMatthew G. Knepley @*/
15456528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1546475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1547475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1548475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154997b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1550475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1551475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1552475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
155397b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1554475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1555475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1556475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
155797b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1558475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1559475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1560475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
156197b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1562475e0ac9SMatthew G. Knepley {
15636528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
15646528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
15656528b96dSMatthew G. Knepley   PetscErrorCode ierr;
15666528b96dSMatthew G. Knepley 
1567475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
15686528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
15696528b96dSMatthew 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);
15706528b96dSMatthew 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);
15716528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
15726528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
15736528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
15746528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
15756528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1576475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1577475e0ac9SMatthew G. Knepley }
1578475e0ac9SMatthew G. Knepley 
1579475e0ac9SMatthew G. Knepley /*@C
1580475e0ac9SMatthew 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.
1581475e0ac9SMatthew G. Knepley 
1582475e0ac9SMatthew G. Knepley   Not collective
1583475e0ac9SMatthew G. Knepley 
1584475e0ac9SMatthew G. Knepley   Input Parameters:
15856528b96dSMatthew G. Knepley + ds - The PetscDS
1586475e0ac9SMatthew G. Knepley . f  - The test field number
1587475e0ac9SMatthew G. Knepley . g  - The field number
1588475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1589475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1590475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1591475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1592475e0ac9SMatthew G. Knepley 
1593475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1594475e0ac9SMatthew G. Knepley 
1595475e0ac9SMatthew 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
1596475e0ac9SMatthew G. Knepley 
1597475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1598475e0ac9SMatthew G. Knepley 
1599475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1600475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1601475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1602475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1603475e0ac9SMatthew G. Knepley 
1604475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1605475e0ac9SMatthew G. Knepley . Nf - the number of fields
1606475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1607475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1608475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1609475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1610475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1611475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1612475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1613475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1614475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1615475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1616475e0ac9SMatthew G. Knepley . t - current time
1617475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1618475e0ac9SMatthew G. Knepley . x - coordinates of the current point
161997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
162097b6e6e8SMatthew G. Knepley . constants - constant parameters
1621475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1622475e0ac9SMatthew G. Knepley 
1623475e0ac9SMatthew G. Knepley   Level: intermediate
1624475e0ac9SMatthew G. Knepley 
1625475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1626475e0ac9SMatthew G. Knepley @*/
16276528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1628475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1629475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1630475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
163197b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1632475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1633475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1634475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
163597b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1636475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1637475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1638475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
163997b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1640475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1641475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1642475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
164397b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1644475e0ac9SMatthew G. Knepley {
1645475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1646475e0ac9SMatthew G. Knepley 
1647475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
16486528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1649475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1650475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1651475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1652475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1653475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1654475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
16556528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
1656475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1657475e0ac9SMatthew G. Knepley }
1658475e0ac9SMatthew G. Knepley 
1659b7e05686SMatthew G. Knepley /*@C
1660b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1661b7e05686SMatthew G. Knepley 
1662b7e05686SMatthew G. Knepley   Not collective
1663b7e05686SMatthew G. Knepley 
1664b7e05686SMatthew G. Knepley   Input Parameter:
16656528b96dSMatthew G. Knepley . ds - The PetscDS
1666b7e05686SMatthew G. Knepley 
1667b7e05686SMatthew G. Knepley   Output Parameter:
1668b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1669b7e05686SMatthew G. Knepley 
1670b7e05686SMatthew G. Knepley   Level: intermediate
1671b7e05686SMatthew G. Knepley 
1672b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1673b7e05686SMatthew G. Knepley @*/
16746528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac)
1675b7e05686SMatthew G. Knepley {
16766528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1677b7e05686SMatthew G. Knepley 
1678b7e05686SMatthew G. Knepley   PetscFunctionBegin;
16796528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
16806528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac);CHKERRQ(ierr);
1681b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1682b7e05686SMatthew G. Knepley }
1683b7e05686SMatthew G. Knepley 
1684b7e05686SMatthew G. Knepley /*@C
1685b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1686b7e05686SMatthew G. Knepley 
1687b7e05686SMatthew G. Knepley   Not collective
1688b7e05686SMatthew G. Knepley 
1689b7e05686SMatthew G. Knepley   Input Parameters:
16906528b96dSMatthew G. Knepley + ds - The PetscDS
1691b7e05686SMatthew G. Knepley . f  - The test field number
1692b7e05686SMatthew G. Knepley - g  - The field number
1693b7e05686SMatthew G. Knepley 
1694b7e05686SMatthew G. Knepley   Output Parameters:
1695b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1696b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1697b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1698b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1699b7e05686SMatthew G. Knepley 
1700b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1701b7e05686SMatthew G. Knepley 
1702b7e05686SMatthew 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
1703b7e05686SMatthew G. Knepley 
1704b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1705b7e05686SMatthew G. Knepley 
1706b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1707b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1708b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1709b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1710b7e05686SMatthew G. Knepley 
1711b7e05686SMatthew G. Knepley + dim - the spatial dimension
1712b7e05686SMatthew G. Knepley . Nf - the number of fields
1713b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1714b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1715b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1716b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1717b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1718b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1719b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1720b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1721b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1722b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1723b7e05686SMatthew G. Knepley . t - current time
1724b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1725b7e05686SMatthew G. Knepley . x - coordinates of the current point
172697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
172797b6e6e8SMatthew G. Knepley . constants - constant parameters
1728b7e05686SMatthew G. Knepley - g0 - output values at the current point
1729b7e05686SMatthew G. Knepley 
1730b7e05686SMatthew G. Knepley   Level: intermediate
1731b7e05686SMatthew G. Knepley 
1732b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1733b7e05686SMatthew G. Knepley @*/
17346528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
1735b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1736b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1737b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
173897b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1739b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1740b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1741b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
174297b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1743b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1744b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1745b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
174697b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1747b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1748b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1749b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
175097b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1751b7e05686SMatthew G. Knepley {
17526528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
17536528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
17546528b96dSMatthew G. Knepley   PetscErrorCode ierr;
17556528b96dSMatthew G. Knepley 
1756b7e05686SMatthew G. Knepley   PetscFunctionBegin;
17576528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
17586528b96dSMatthew 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);
17596528b96dSMatthew 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);
17606528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
17616528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
17626528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
17636528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
17646528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1765b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1766b7e05686SMatthew G. Knepley }
1767b7e05686SMatthew G. Knepley 
1768b7e05686SMatthew G. Knepley /*@C
1769b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1770b7e05686SMatthew G. Knepley 
1771b7e05686SMatthew G. Knepley   Not collective
1772b7e05686SMatthew G. Knepley 
1773b7e05686SMatthew G. Knepley   Input Parameters:
17746528b96dSMatthew G. Knepley + ds - The PetscDS
1775b7e05686SMatthew G. Knepley . f  - The test field number
1776b7e05686SMatthew G. Knepley . g  - The field number
1777b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1778b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1779b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1780b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1781b7e05686SMatthew G. Knepley 
1782b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1783b7e05686SMatthew G. Knepley 
1784b7e05686SMatthew 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
1785b7e05686SMatthew G. Knepley 
1786b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1787b7e05686SMatthew G. Knepley 
1788b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1789b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1790b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1791b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1792b7e05686SMatthew G. Knepley 
1793b7e05686SMatthew G. Knepley + dim - the spatial dimension
1794b7e05686SMatthew G. Knepley . Nf - the number of fields
1795b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1796b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1797b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1798b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1799b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1800b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1801b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1802b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1803b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1804b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1805b7e05686SMatthew G. Knepley . t - current time
1806b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1807b7e05686SMatthew G. Knepley . x - coordinates of the current point
180897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
180997b6e6e8SMatthew G. Knepley . constants - constant parameters
1810b7e05686SMatthew G. Knepley - g0 - output values at the current point
1811b7e05686SMatthew G. Knepley 
1812b7e05686SMatthew G. Knepley   Level: intermediate
1813b7e05686SMatthew G. Knepley 
1814b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1815b7e05686SMatthew G. Knepley @*/
18166528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
1817b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1818b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1819b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
182097b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1821b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1822b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1823b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
182497b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1825b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1826b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1827b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
182897b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1829b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1830b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1831b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
183297b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1833b7e05686SMatthew G. Knepley {
1834b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1835b7e05686SMatthew G. Knepley 
1836b7e05686SMatthew G. Knepley   PetscFunctionBegin;
18376528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1838b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1839b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1840b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1841b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1842b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1843b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
18446528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
1845b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1846b7e05686SMatthew G. Knepley }
1847b7e05686SMatthew G. Knepley 
18480c2f2876SMatthew G. Knepley /*@C
18490c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
18500c2f2876SMatthew G. Knepley 
18510c2f2876SMatthew G. Knepley   Not collective
18520c2f2876SMatthew G. Knepley 
18530c2f2876SMatthew G. Knepley   Input Arguments:
18546528b96dSMatthew G. Knepley + ds - The PetscDS object
18550c2f2876SMatthew G. Knepley - f  - The field number
18560c2f2876SMatthew G. Knepley 
18570c2f2876SMatthew G. Knepley   Output Argument:
18580c2f2876SMatthew G. Knepley . r    - Riemann solver
18590c2f2876SMatthew G. Knepley 
18600c2f2876SMatthew G. Knepley   Calling sequence for r:
18610c2f2876SMatthew G. Knepley 
18625db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
18630c2f2876SMatthew G. Knepley 
18645db36cf9SMatthew G. Knepley + dim  - The spatial dimension
18655db36cf9SMatthew G. Knepley . Nf   - The number of fields
18665db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
18670c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
18680c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
18690c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
18700c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
187197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
187297b6e6e8SMatthew G. Knepley . constants - constant parameters
18730c2f2876SMatthew G. Knepley - ctx  - optional user context
18740c2f2876SMatthew G. Knepley 
18750c2f2876SMatthew G. Knepley   Level: intermediate
18760c2f2876SMatthew G. Knepley 
18770c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
18780c2f2876SMatthew G. Knepley @*/
18796528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS ds, PetscInt f,
188097b6e6e8SMatthew 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))
18810c2f2876SMatthew G. Knepley {
18826528b96dSMatthew G. Knepley   PetscRiemannFunc *tmp;
18836528b96dSMatthew G. Knepley   PetscInt          n;
18846528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
18856528b96dSMatthew G. Knepley 
18860c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18876528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
18880c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
18896528b96dSMatthew 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);
18906528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, &n, &tmp);CHKERRQ(ierr);
18916528b96dSMatthew G. Knepley   *r   = tmp ? tmp[0] : NULL;
18920c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18930c2f2876SMatthew G. Knepley }
18940c2f2876SMatthew G. Knepley 
18950c2f2876SMatthew G. Knepley /*@C
18960c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
18970c2f2876SMatthew G. Knepley 
18980c2f2876SMatthew G. Knepley   Not collective
18990c2f2876SMatthew G. Knepley 
19000c2f2876SMatthew G. Knepley   Input Arguments:
19016528b96dSMatthew G. Knepley + ds - The PetscDS object
19020c2f2876SMatthew G. Knepley . f  - The field number
19030c2f2876SMatthew G. Knepley - r  - Riemann solver
19040c2f2876SMatthew G. Knepley 
19050c2f2876SMatthew G. Knepley   Calling sequence for r:
19060c2f2876SMatthew G. Knepley 
19075db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
19080c2f2876SMatthew G. Knepley 
19095db36cf9SMatthew G. Knepley + dim  - The spatial dimension
19105db36cf9SMatthew G. Knepley . Nf   - The number of fields
19115db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
19120c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
19130c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
19140c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
19150c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
191697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
191797b6e6e8SMatthew G. Knepley . constants - constant parameters
19180c2f2876SMatthew G. Knepley - ctx  - optional user context
19190c2f2876SMatthew G. Knepley 
19200c2f2876SMatthew G. Knepley   Level: intermediate
19210c2f2876SMatthew G. Knepley 
19220c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
19230c2f2876SMatthew G. Knepley @*/
19246528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS ds, PetscInt f,
192597b6e6e8SMatthew 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))
19260c2f2876SMatthew G. Knepley {
19270c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
19280c2f2876SMatthew G. Knepley 
19290c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19306528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1931de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
19320c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19336528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, r);CHKERRQ(ierr);
19340c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19350c2f2876SMatthew G. Knepley }
19360c2f2876SMatthew G. Knepley 
193732d2bbc9SMatthew G. Knepley /*@C
193832d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
193932d2bbc9SMatthew G. Knepley 
194032d2bbc9SMatthew G. Knepley   Not collective
194132d2bbc9SMatthew G. Knepley 
194232d2bbc9SMatthew G. Knepley   Input Parameters:
19436528b96dSMatthew G. Knepley + ds - The PetscDS
194432d2bbc9SMatthew G. Knepley - f  - The field number
194532d2bbc9SMatthew G. Knepley 
194632d2bbc9SMatthew G. Knepley   Output Parameters:
1947a2b725a8SWilliam Gropp . update - update function
194832d2bbc9SMatthew G. Knepley 
194932d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
195032d2bbc9SMatthew G. Knepley 
195132d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
195232d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
195332d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
195432d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
195532d2bbc9SMatthew G. Knepley 
195632d2bbc9SMatthew G. Knepley + dim - the spatial dimension
195732d2bbc9SMatthew G. Knepley . Nf - the number of fields
195832d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
195932d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
196032d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
196132d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
196232d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
196332d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
196432d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
196532d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
196632d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
196732d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
196832d2bbc9SMatthew G. Knepley . t - current time
196932d2bbc9SMatthew G. Knepley . x - coordinates of the current point
197032d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
197132d2bbc9SMatthew G. Knepley 
197232d2bbc9SMatthew G. Knepley   Level: intermediate
197332d2bbc9SMatthew G. Knepley 
197432d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
197532d2bbc9SMatthew G. Knepley @*/
19766528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS ds, PetscInt f,
197732d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
197832d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
197932d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19803fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
198132d2bbc9SMatthew G. Knepley {
198232d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
19836528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
19846528b96dSMatthew 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);
19856528b96dSMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = ds->update[f];}
198632d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
198732d2bbc9SMatthew G. Knepley }
198832d2bbc9SMatthew G. Knepley 
198932d2bbc9SMatthew G. Knepley /*@C
19903fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
199132d2bbc9SMatthew G. Knepley 
199232d2bbc9SMatthew G. Knepley   Not collective
199332d2bbc9SMatthew G. Knepley 
199432d2bbc9SMatthew G. Knepley   Input Parameters:
19956528b96dSMatthew G. Knepley + ds     - The PetscDS
199632d2bbc9SMatthew G. Knepley . f      - The field number
199732d2bbc9SMatthew G. Knepley - update - update function
199832d2bbc9SMatthew G. Knepley 
199932d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
200032d2bbc9SMatthew G. Knepley 
200132d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
200232d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
200332d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
200432d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
200532d2bbc9SMatthew G. Knepley 
200632d2bbc9SMatthew G. Knepley + dim - the spatial dimension
200732d2bbc9SMatthew G. Knepley . Nf - the number of fields
200832d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
200932d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
201032d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
201132d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
201232d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
201332d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
201432d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
201532d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
201632d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
201732d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
201832d2bbc9SMatthew G. Knepley . t - current time
201932d2bbc9SMatthew G. Knepley . x - coordinates of the current point
202032d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
202132d2bbc9SMatthew G. Knepley 
202232d2bbc9SMatthew G. Knepley   Level: intermediate
202332d2bbc9SMatthew G. Knepley 
202432d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
202532d2bbc9SMatthew G. Knepley @*/
20266528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS ds, PetscInt f,
202732d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
202832d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
202932d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20303fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
203132d2bbc9SMatthew G. Knepley {
203232d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
203332d2bbc9SMatthew G. Knepley 
203432d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
20356528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
203632d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
203732d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
20386528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
20396528b96dSMatthew G. Knepley   ds->update[f] = update;
204032d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
204132d2bbc9SMatthew G. Knepley }
204232d2bbc9SMatthew G. Knepley 
20436528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void **ctx)
20440c2f2876SMatthew G. Knepley {
20450c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20466528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
20476528b96dSMatthew 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);
20480c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
20496528b96dSMatthew G. Knepley   *ctx = ds->ctx[f];
20500c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20510c2f2876SMatthew G. Knepley }
20520c2f2876SMatthew G. Knepley 
20536528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx)
20540c2f2876SMatthew G. Knepley {
20550c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
20560c2f2876SMatthew G. Knepley 
20570c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20586528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
20590c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
20606528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
20616528b96dSMatthew G. Knepley   ds->ctx[f] = ctx;
20620c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20630c2f2876SMatthew G. Knepley }
20640c2f2876SMatthew G. Knepley 
2065194d53e6SMatthew G. Knepley /*@C
2066194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
2067194d53e6SMatthew G. Knepley 
2068194d53e6SMatthew G. Knepley   Not collective
2069194d53e6SMatthew G. Knepley 
2070194d53e6SMatthew G. Knepley   Input Parameters:
20716528b96dSMatthew G. Knepley + ds - The PetscDS
2072194d53e6SMatthew G. Knepley - f  - The test field number
2073194d53e6SMatthew G. Knepley 
2074194d53e6SMatthew G. Knepley   Output Parameters:
2075194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
2076194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2077194d53e6SMatthew G. Knepley 
2078194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2079194d53e6SMatthew G. Knepley 
2080194d53e6SMatthew 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
2081194d53e6SMatthew G. Knepley 
2082194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2083194d53e6SMatthew G. Knepley 
208430b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2085194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2086194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
208730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2088194d53e6SMatthew G. Knepley 
2089194d53e6SMatthew G. Knepley + dim - the spatial dimension
2090194d53e6SMatthew G. Knepley . Nf - the number of fields
2091194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2092194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2093194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2094194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2095194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2096194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2097194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2098194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2099194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2100194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2101194d53e6SMatthew G. Knepley . t - current time
2102194d53e6SMatthew G. Knepley . x - coordinates of the current point
2103194d53e6SMatthew G. Knepley . n - unit normal at the current point
210497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
210597b6e6e8SMatthew G. Knepley . constants - constant parameters
2106194d53e6SMatthew G. Knepley - f0 - output values at the current point
2107194d53e6SMatthew G. Knepley 
2108194d53e6SMatthew G. Knepley   Level: intermediate
2109194d53e6SMatthew G. Knepley 
2110194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
2111194d53e6SMatthew G. Knepley @*/
21126528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS ds, PetscInt f,
211330b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2114194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2115194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
211697b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
211730b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2118194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2119194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
212097b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
21212764a2aaSMatthew G. Knepley {
21226528b96dSMatthew G. Knepley   PetscBdPointFunc *tmp0, *tmp1;
21236528b96dSMatthew G. Knepley   PetscInt          n0, n1;
21246528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
21256528b96dSMatthew G. Knepley 
21262764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21276528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
21286528b96dSMatthew 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);
21296528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
21306528b96dSMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
21316528b96dSMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
21322764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21332764a2aaSMatthew G. Knepley }
21342764a2aaSMatthew G. Knepley 
2135194d53e6SMatthew G. Knepley /*@C
2136194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2137194d53e6SMatthew G. Knepley 
2138194d53e6SMatthew G. Knepley   Not collective
2139194d53e6SMatthew G. Knepley 
2140194d53e6SMatthew G. Knepley   Input Parameters:
21416528b96dSMatthew G. Knepley + ds - The PetscDS
2142194d53e6SMatthew G. Knepley . f  - The test field number
2143194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2144194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2145194d53e6SMatthew G. Knepley 
2146194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2147194d53e6SMatthew G. Knepley 
2148194d53e6SMatthew 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
2149194d53e6SMatthew G. Knepley 
2150194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2151194d53e6SMatthew G. Knepley 
215230b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2153194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2154194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
215530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2156194d53e6SMatthew G. Knepley 
2157194d53e6SMatthew G. Knepley + dim - the spatial dimension
2158194d53e6SMatthew G. Knepley . Nf - the number of fields
2159194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2160194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2161194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2162194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2163194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2164194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2165194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2166194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2167194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2168194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2169194d53e6SMatthew G. Knepley . t - current time
2170194d53e6SMatthew G. Knepley . x - coordinates of the current point
2171194d53e6SMatthew G. Knepley . n - unit normal at the current point
217297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
217397b6e6e8SMatthew G. Knepley . constants - constant parameters
2174194d53e6SMatthew G. Knepley - f0 - output values at the current point
2175194d53e6SMatthew G. Knepley 
2176194d53e6SMatthew G. Knepley   Level: intermediate
2177194d53e6SMatthew G. Knepley 
2178194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
2179194d53e6SMatthew G. Knepley @*/
21806528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS ds, PetscInt f,
218130b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2182194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2183194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
218497b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
218530b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2186194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2187194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
218897b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
21892764a2aaSMatthew G. Knepley {
21902764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21912764a2aaSMatthew G. Knepley 
21922764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21936528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
21942764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21956528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, f0, 0, f1);CHKERRQ(ierr);
21962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21972764a2aaSMatthew G. Knepley }
21982764a2aaSMatthew G. Knepley 
219927f02ce8SMatthew G. Knepley /*@
220027f02ce8SMatthew G. Knepley   PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set
220127f02ce8SMatthew G. Knepley 
220227f02ce8SMatthew G. Knepley   Not collective
220327f02ce8SMatthew G. Knepley 
220427f02ce8SMatthew G. Knepley   Input Parameter:
22056528b96dSMatthew G. Knepley . ds - The PetscDS
220627f02ce8SMatthew G. Knepley 
220727f02ce8SMatthew G. Knepley   Output Parameter:
220827f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set
220927f02ce8SMatthew G. Knepley 
221027f02ce8SMatthew G. Knepley   Level: intermediate
221127f02ce8SMatthew G. Knepley 
221227f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
221327f02ce8SMatthew G. Knepley @*/
22146528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac)
221527f02ce8SMatthew G. Knepley {
22166528b96dSMatthew G. Knepley   PetscErrorCode ierr;
221727f02ce8SMatthew G. Knepley 
221827f02ce8SMatthew G. Knepley   PetscFunctionBegin;
22196528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
22206528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJac, 2);
22216528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobian(ds->wf, hasBdJac);CHKERRQ(ierr);
222227f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
222327f02ce8SMatthew G. Knepley }
222427f02ce8SMatthew G. Knepley 
2225194d53e6SMatthew G. Knepley /*@C
2226194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2227194d53e6SMatthew G. Knepley 
2228194d53e6SMatthew G. Knepley   Not collective
2229194d53e6SMatthew G. Knepley 
2230194d53e6SMatthew G. Knepley   Input Parameters:
22316528b96dSMatthew G. Knepley + ds - The PetscDS
2232194d53e6SMatthew G. Knepley . f  - The test field number
2233194d53e6SMatthew G. Knepley - g  - The field number
2234194d53e6SMatthew G. Knepley 
2235194d53e6SMatthew G. Knepley   Output Parameters:
2236194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2237194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2238194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2239194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2240194d53e6SMatthew G. Knepley 
2241194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2242194d53e6SMatthew G. Knepley 
2243194d53e6SMatthew 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
2244194d53e6SMatthew G. Knepley 
2245194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2246194d53e6SMatthew G. Knepley 
224730b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2248194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2249194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
225030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2251194d53e6SMatthew G. Knepley 
2252194d53e6SMatthew G. Knepley + dim - the spatial dimension
2253194d53e6SMatthew G. Knepley . Nf - the number of fields
2254194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2255194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2256194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2257194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2258194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2259194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2260194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2261194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2262194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2263194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2264194d53e6SMatthew G. Knepley . t - current time
22652aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2266194d53e6SMatthew G. Knepley . x - coordinates of the current point
2267194d53e6SMatthew G. Knepley . n - normal at the current point
226897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
226997b6e6e8SMatthew G. Knepley . constants - constant parameters
2270194d53e6SMatthew G. Knepley - g0 - output values at the current point
2271194d53e6SMatthew G. Knepley 
2272194d53e6SMatthew G. Knepley   Level: intermediate
2273194d53e6SMatthew G. Knepley 
2274194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2275194d53e6SMatthew G. Knepley @*/
22766528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
227730b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2278194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2279194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
228097b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
228130b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2282194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2283194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
228497b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
228530b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2286194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2287194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
228897b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
228930b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2290194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2291194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
229297b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
22932764a2aaSMatthew G. Knepley {
22946528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
22956528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
22966528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
22976528b96dSMatthew G. Knepley 
22982764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22996528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
23006528b96dSMatthew 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);
23016528b96dSMatthew 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);
23026528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
23036528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
23046528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
23056528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
23066528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
23072764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23082764a2aaSMatthew G. Knepley }
23092764a2aaSMatthew G. Knepley 
2310194d53e6SMatthew G. Knepley /*@C
2311194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2312194d53e6SMatthew G. Knepley 
2313194d53e6SMatthew G. Knepley   Not collective
2314194d53e6SMatthew G. Knepley 
2315194d53e6SMatthew G. Knepley   Input Parameters:
23166528b96dSMatthew G. Knepley + ds - The PetscDS
2317194d53e6SMatthew G. Knepley . f  - The test field number
2318194d53e6SMatthew G. Knepley . g  - The field number
2319194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2320194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2321194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2322194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2323194d53e6SMatthew G. Knepley 
2324194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2325194d53e6SMatthew G. Knepley 
2326194d53e6SMatthew 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
2327194d53e6SMatthew G. Knepley 
2328194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2329194d53e6SMatthew G. Knepley 
233030b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2331194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2332194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
233330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2334194d53e6SMatthew G. Knepley 
2335194d53e6SMatthew G. Knepley + dim - the spatial dimension
2336194d53e6SMatthew G. Knepley . Nf - the number of fields
2337194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2338194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2339194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2340194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2341194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2342194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2343194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2344194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2345194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2346194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2347194d53e6SMatthew G. Knepley . t - current time
23482aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2349194d53e6SMatthew G. Knepley . x - coordinates of the current point
2350194d53e6SMatthew G. Knepley . n - normal at the current point
235197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
235297b6e6e8SMatthew G. Knepley . constants - constant parameters
2353194d53e6SMatthew G. Knepley - g0 - output values at the current point
2354194d53e6SMatthew G. Knepley 
2355194d53e6SMatthew G. Knepley   Level: intermediate
2356194d53e6SMatthew G. Knepley 
2357194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2358194d53e6SMatthew G. Knepley @*/
23596528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
236030b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2361194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2362194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
236397b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
236430b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2365194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2366194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
236797b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
236830b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2369194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2370194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
237197b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
237230b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2373194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2374194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
237597b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
23762764a2aaSMatthew G. Knepley {
23772764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23782764a2aaSMatthew G. Knepley 
23792764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23806528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
23812764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
23822764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
23832764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
23842764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
23852764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
23862764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
23876528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
23882764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23892764a2aaSMatthew G. Knepley }
23902764a2aaSMatthew G. Knepley 
239127f02ce8SMatthew G. Knepley /*@
239227f02ce8SMatthew G. Knepley   PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set
239327f02ce8SMatthew G. Knepley 
239427f02ce8SMatthew G. Knepley   Not collective
239527f02ce8SMatthew G. Knepley 
239627f02ce8SMatthew G. Knepley   Input Parameter:
23976528b96dSMatthew G. Knepley . ds - The PetscDS
239827f02ce8SMatthew G. Knepley 
239927f02ce8SMatthew G. Knepley   Output Parameter:
240027f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set
240127f02ce8SMatthew G. Knepley 
240227f02ce8SMatthew G. Knepley   Level: intermediate
240327f02ce8SMatthew G. Knepley 
240427f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
240527f02ce8SMatthew G. Knepley @*/
24066528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre)
240727f02ce8SMatthew G. Knepley {
24086528b96dSMatthew G. Knepley   PetscErrorCode ierr;
240927f02ce8SMatthew G. Knepley 
241027f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24116528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24126528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJacPre, 2);
24136528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre);CHKERRQ(ierr);
241427f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
241527f02ce8SMatthew G. Knepley }
241627f02ce8SMatthew G. Knepley 
241727f02ce8SMatthew G. Knepley /*@C
241827f02ce8SMatthew G. Knepley   PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field
241927f02ce8SMatthew G. Knepley 
242027f02ce8SMatthew G. Knepley   Not collective
242127f02ce8SMatthew G. Knepley 
242227f02ce8SMatthew G. Knepley   Input Parameters:
24236528b96dSMatthew G. Knepley + ds - The PetscDS
242427f02ce8SMatthew G. Knepley . f  - The test field number
242527f02ce8SMatthew G. Knepley - g  - The field number
242627f02ce8SMatthew G. Knepley 
242727f02ce8SMatthew G. Knepley   Output Parameters:
242827f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term
242927f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
243027f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
243127f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
243227f02ce8SMatthew G. Knepley 
243327f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
243427f02ce8SMatthew G. Knepley 
243527f02ce8SMatthew 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
243627f02ce8SMatthew G. Knepley 
243727f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
243827f02ce8SMatthew G. Knepley 
243927f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
244027f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
244127f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
244227f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
244327f02ce8SMatthew G. Knepley 
244427f02ce8SMatthew G. Knepley + dim - the spatial dimension
244527f02ce8SMatthew G. Knepley . Nf - the number of fields
244627f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
244727f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
244827f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
244927f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
245027f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
245127f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
245227f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
245327f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
245427f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
245527f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
245627f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
245727f02ce8SMatthew G. Knepley . t - current time
245827f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
245927f02ce8SMatthew G. Knepley . x - coordinates of the current point
246027f02ce8SMatthew G. Knepley . n - normal at the current point
246127f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
246227f02ce8SMatthew G. Knepley . constants - constant parameters
246327f02ce8SMatthew G. Knepley - g0 - output values at the current point
246427f02ce8SMatthew G. Knepley 
246527f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
246627f02ce8SMatthew G. Knepley 
246727f02ce8SMatthew G. Knepley   Level: intermediate
246827f02ce8SMatthew G. Knepley 
246927f02ce8SMatthew G. Knepley .seealso: PetscDSSetBdJacobianPreconditioner()
247027f02ce8SMatthew G. Knepley @*/
24716528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
247227f02ce8SMatthew G. Knepley                                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
247327f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
247427f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
247527f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
247627f02ce8SMatthew G. Knepley                                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
247727f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
247827f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
247927f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
248027f02ce8SMatthew G. Knepley                                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
248127f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
248227f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
248327f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
248427f02ce8SMatthew G. Knepley                                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
248527f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
248627f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
248727f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
248827f02ce8SMatthew G. Knepley {
24896528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
24906528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
24916528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
24926528b96dSMatthew G. Knepley 
249327f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24946528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24956528b96dSMatthew 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);
24966528b96dSMatthew 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);
24976528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
24986528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
24996528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
25006528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
25016528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
250227f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
250327f02ce8SMatthew G. Knepley }
250427f02ce8SMatthew G. Knepley 
250527f02ce8SMatthew G. Knepley /*@C
250627f02ce8SMatthew G. Knepley   PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field
250727f02ce8SMatthew G. Knepley 
250827f02ce8SMatthew G. Knepley   Not collective
250927f02ce8SMatthew G. Knepley 
251027f02ce8SMatthew G. Knepley   Input Parameters:
25116528b96dSMatthew G. Knepley + ds - The PetscDS
251227f02ce8SMatthew G. Knepley . f  - The test field number
251327f02ce8SMatthew G. Knepley . g  - The field number
251427f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term
251527f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
251627f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
251727f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
251827f02ce8SMatthew G. Knepley 
251927f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
252027f02ce8SMatthew G. Knepley 
252127f02ce8SMatthew 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
252227f02ce8SMatthew G. Knepley 
252327f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
252427f02ce8SMatthew G. Knepley 
252527f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
252627f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
252727f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
252827f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
252927f02ce8SMatthew G. Knepley 
253027f02ce8SMatthew G. Knepley + dim - the spatial dimension
253127f02ce8SMatthew G. Knepley . Nf - the number of fields
253227f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
253327f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
253427f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
253527f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
253627f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
253727f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
253827f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
253927f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
254027f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
254127f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
254227f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
254327f02ce8SMatthew G. Knepley . t - current time
254427f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
254527f02ce8SMatthew G. Knepley . x - coordinates of the current point
254627f02ce8SMatthew G. Knepley . n - normal at the current point
254727f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
254827f02ce8SMatthew G. Knepley . constants - constant parameters
254927f02ce8SMatthew G. Knepley - g0 - output values at the current point
255027f02ce8SMatthew G. Knepley 
255127f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
255227f02ce8SMatthew G. Knepley 
255327f02ce8SMatthew G. Knepley   Level: intermediate
255427f02ce8SMatthew G. Knepley 
255527f02ce8SMatthew G. Knepley .seealso: PetscDSGetBdJacobianPreconditioner()
255627f02ce8SMatthew G. Knepley @*/
25576528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
255827f02ce8SMatthew G. Knepley                                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
255927f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
256027f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
256127f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
256227f02ce8SMatthew G. Knepley                                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
256327f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
256427f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
256527f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
256627f02ce8SMatthew G. Knepley                                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
256727f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
256827f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
256927f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
257027f02ce8SMatthew G. Knepley                                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
257127f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
257227f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
257327f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
257427f02ce8SMatthew G. Knepley {
257527f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
257627f02ce8SMatthew G. Knepley 
257727f02ce8SMatthew G. Knepley   PetscFunctionBegin;
25786528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
257927f02ce8SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
258027f02ce8SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
258127f02ce8SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
258227f02ce8SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
258327f02ce8SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
258427f02ce8SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
25856528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
258627f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
258727f02ce8SMatthew G. Knepley }
258827f02ce8SMatthew G. Knepley 
25890d3e9b51SMatthew G. Knepley /*@C
2590c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2591c371a6d1SMatthew G. Knepley 
2592c371a6d1SMatthew G. Knepley   Not collective
2593c371a6d1SMatthew G. Knepley 
2594c371a6d1SMatthew G. Knepley   Input Parameters:
2595c371a6d1SMatthew G. Knepley + prob - The PetscDS
2596c371a6d1SMatthew G. Knepley - f    - The test field number
2597c371a6d1SMatthew G. Knepley 
2598c371a6d1SMatthew G. Knepley   Output Parameter:
259995cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field
260095cbbfd3SMatthew G. Knepley - exactCtx - exact solution context
2601c371a6d1SMatthew G. Knepley 
2602c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2603c371a6d1SMatthew G. Knepley 
2604c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2605c371a6d1SMatthew G. Knepley 
2606c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2607c371a6d1SMatthew G. Knepley . t - current time
2608c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2609c371a6d1SMatthew G. Knepley . Nc - the number of field components
2610c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2611c371a6d1SMatthew G. Knepley - ctx - a user context
2612c371a6d1SMatthew G. Knepley 
2613c371a6d1SMatthew G. Knepley   Level: intermediate
2614c371a6d1SMatthew G. Knepley 
2615f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolution(), PetscDSGetExactSolutionTimeDerivative()
2616c371a6d1SMatthew G. Knepley @*/
261795cbbfd3SMatthew 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)
2618c371a6d1SMatthew G. Knepley {
2619c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2620c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2621c371a6d1SMatthew 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);
2622c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
262395cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];}
2624c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2625c371a6d1SMatthew G. Knepley }
2626c371a6d1SMatthew G. Knepley 
2627c371a6d1SMatthew G. Knepley /*@C
2628578a5ef5SMatthew Knepley   PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field
2629c371a6d1SMatthew G. Knepley 
2630c371a6d1SMatthew G. Knepley   Not collective
2631c371a6d1SMatthew G. Knepley 
2632c371a6d1SMatthew G. Knepley   Input Parameters:
2633c371a6d1SMatthew G. Knepley + prob - The PetscDS
2634c371a6d1SMatthew G. Knepley . f    - The test field number
263595cbbfd3SMatthew G. Knepley . sol  - solution function for the test fields
263695cbbfd3SMatthew G. Knepley - ctx  - solution context or NULL
2637c371a6d1SMatthew G. Knepley 
2638c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2639c371a6d1SMatthew G. Knepley 
2640c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2641c371a6d1SMatthew G. Knepley 
2642c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2643c371a6d1SMatthew G. Knepley . t - current time
2644c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2645c371a6d1SMatthew G. Knepley . Nc - the number of field components
2646c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2647c371a6d1SMatthew G. Knepley - ctx - a user context
2648c371a6d1SMatthew G. Knepley 
2649c371a6d1SMatthew G. Knepley   Level: intermediate
2650c371a6d1SMatthew G. Knepley 
2651c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2652c371a6d1SMatthew G. Knepley @*/
265395cbbfd3SMatthew 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)
2654c371a6d1SMatthew G. Knepley {
2655c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2656c371a6d1SMatthew G. Knepley 
2657c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2658c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2659c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2660c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2661c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
266295cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;}
2663c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2664c371a6d1SMatthew G. Knepley }
2665c371a6d1SMatthew G. Knepley 
26665638fd0eSMatthew G. Knepley /*@C
2667f2cacb80SMatthew G. Knepley   PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field
2668f2cacb80SMatthew G. Knepley 
2669f2cacb80SMatthew G. Knepley   Not collective
2670f2cacb80SMatthew G. Knepley 
2671f2cacb80SMatthew G. Knepley   Input Parameters:
2672f2cacb80SMatthew G. Knepley + prob - The PetscDS
2673f2cacb80SMatthew G. Knepley - f    - The test field number
2674f2cacb80SMatthew G. Knepley 
2675f2cacb80SMatthew G. Knepley   Output Parameter:
2676f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field
2677f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context
2678f2cacb80SMatthew G. Knepley 
2679f2cacb80SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2680f2cacb80SMatthew G. Knepley 
2681f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2682f2cacb80SMatthew G. Knepley 
2683f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2684f2cacb80SMatthew G. Knepley . t - current time
2685f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2686f2cacb80SMatthew G. Knepley . Nc - the number of field components
2687f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2688f2cacb80SMatthew G. Knepley - ctx - a user context
2689f2cacb80SMatthew G. Knepley 
2690f2cacb80SMatthew G. Knepley   Level: intermediate
2691f2cacb80SMatthew G. Knepley 
2692f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolutionTimeDerivative(), PetscDSGetExactSolution()
2693f2cacb80SMatthew G. Knepley @*/
2694f2cacb80SMatthew 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)
2695f2cacb80SMatthew G. Knepley {
2696f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2697f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2698f2cacb80SMatthew 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);
2699f2cacb80SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol_t[f];}
2700f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx_t[f];}
2701f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2702f2cacb80SMatthew G. Knepley }
2703f2cacb80SMatthew G. Knepley 
2704f2cacb80SMatthew G. Knepley /*@C
2705f2cacb80SMatthew G. Knepley   PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field
2706f2cacb80SMatthew G. Knepley 
2707f2cacb80SMatthew G. Knepley   Not collective
2708f2cacb80SMatthew G. Knepley 
2709f2cacb80SMatthew G. Knepley   Input Parameters:
2710f2cacb80SMatthew G. Knepley + prob - The PetscDS
2711f2cacb80SMatthew G. Knepley . f    - The test field number
2712f2cacb80SMatthew G. Knepley . sol  - time derivative of the solution function for the test fields
2713f2cacb80SMatthew G. Knepley - ctx  - time derivative of the solution context or NULL
2714f2cacb80SMatthew G. Knepley 
2715f2cacb80SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2716f2cacb80SMatthew G. Knepley 
2717f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2718f2cacb80SMatthew G. Knepley 
2719f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2720f2cacb80SMatthew G. Knepley . t - current time
2721f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2722f2cacb80SMatthew G. Knepley . Nc - the number of field components
2723f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2724f2cacb80SMatthew G. Knepley - ctx - a user context
2725f2cacb80SMatthew G. Knepley 
2726f2cacb80SMatthew G. Knepley   Level: intermediate
2727f2cacb80SMatthew G. Knepley 
2728f2cacb80SMatthew G. Knepley .seealso: PetscDSGetExactSolutionTimeDerivative(), PetscDSSetExactSolution()
2729f2cacb80SMatthew G. Knepley @*/
2730f2cacb80SMatthew 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)
2731f2cacb80SMatthew G. Knepley {
2732f2cacb80SMatthew G. Knepley   PetscErrorCode ierr;
2733f2cacb80SMatthew G. Knepley 
2734f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2735f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2736f2cacb80SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2737f2cacb80SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2738f2cacb80SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol_t[f] = sol;}
2739f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx_t[f] = ctx;}
2740f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2741f2cacb80SMatthew G. Knepley }
2742f2cacb80SMatthew G. Knepley 
2743f2cacb80SMatthew G. Knepley /*@C
274497b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
274597b6e6e8SMatthew G. Knepley 
274697b6e6e8SMatthew G. Knepley   Not collective
274797b6e6e8SMatthew G. Knepley 
274897b6e6e8SMatthew G. Knepley   Input Parameter:
274997b6e6e8SMatthew G. Knepley . prob - The PetscDS object
275097b6e6e8SMatthew G. Knepley 
275197b6e6e8SMatthew G. Knepley   Output Parameters:
275297b6e6e8SMatthew G. Knepley + numConstants - The number of constants
275397b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
275497b6e6e8SMatthew G. Knepley 
275597b6e6e8SMatthew G. Knepley   Level: intermediate
275697b6e6e8SMatthew G. Knepley 
275797b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
275897b6e6e8SMatthew G. Knepley @*/
275997b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
276097b6e6e8SMatthew G. Knepley {
276197b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
276297b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
276397b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
276497b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
276597b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
276697b6e6e8SMatthew G. Knepley }
276797b6e6e8SMatthew G. Knepley 
27680d3e9b51SMatthew G. Knepley /*@C
276997b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
277097b6e6e8SMatthew G. Knepley 
277197b6e6e8SMatthew G. Knepley   Not collective
277297b6e6e8SMatthew G. Knepley 
277397b6e6e8SMatthew G. Knepley   Input Parameters:
277497b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
277597b6e6e8SMatthew G. Knepley . numConstants - The number of constants
277697b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
277797b6e6e8SMatthew G. Knepley 
277897b6e6e8SMatthew G. Knepley   Level: intermediate
277997b6e6e8SMatthew G. Knepley 
278097b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
278197b6e6e8SMatthew G. Knepley @*/
278297b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
278397b6e6e8SMatthew G. Knepley {
278497b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
278597b6e6e8SMatthew G. Knepley 
278697b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
278797b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
278897b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
278997b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
279097b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
279197b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
279297b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
279320be0f5bSMatthew G. Knepley     } else {
279420be0f5bSMatthew G. Knepley       prob->constants = NULL;
279520be0f5bSMatthew G. Knepley     }
279620be0f5bSMatthew G. Knepley   }
279720be0f5bSMatthew G. Knepley   if (prob->numConstants) {
279820be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
2799580bdb30SBarry Smith     ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr);
280097b6e6e8SMatthew G. Knepley   }
280197b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
280297b6e6e8SMatthew G. Knepley }
280397b6e6e8SMatthew G. Knepley 
28044cd1e086SMatthew G. Knepley /*@
28054cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
28064cd1e086SMatthew G. Knepley 
28074cd1e086SMatthew G. Knepley   Not collective
28084cd1e086SMatthew G. Knepley 
28094cd1e086SMatthew G. Knepley   Input Parameters:
28104cd1e086SMatthew G. Knepley + prob - The PetscDS object
28114cd1e086SMatthew G. Knepley - disc - The discretization object
28124cd1e086SMatthew G. Knepley 
28134cd1e086SMatthew G. Knepley   Output Parameter:
28144cd1e086SMatthew G. Knepley . f - The field number
28154cd1e086SMatthew G. Knepley 
28164cd1e086SMatthew G. Knepley   Level: beginner
28174cd1e086SMatthew G. Knepley 
2818f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
28194cd1e086SMatthew G. Knepley @*/
28204cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
28214cd1e086SMatthew G. Knepley {
28224cd1e086SMatthew G. Knepley   PetscInt g;
28234cd1e086SMatthew G. Knepley 
28244cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28254cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28264cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
28274cd1e086SMatthew G. Knepley   *f = -1;
28284cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
28294cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
28304cd1e086SMatthew G. Knepley   *f = g;
28314cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
28324cd1e086SMatthew G. Knepley }
28334cd1e086SMatthew G. Knepley 
28344cd1e086SMatthew G. Knepley /*@
28354cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
28364cd1e086SMatthew G. Knepley 
28374cd1e086SMatthew G. Knepley   Not collective
28384cd1e086SMatthew G. Knepley 
28394cd1e086SMatthew G. Knepley   Input Parameters:
28404cd1e086SMatthew G. Knepley + prob - The PetscDS object
28414cd1e086SMatthew G. Knepley - f - The field number
28424cd1e086SMatthew G. Knepley 
28434cd1e086SMatthew G. Knepley   Output Parameter:
28444cd1e086SMatthew G. Knepley . size - The size
28454cd1e086SMatthew G. Knepley 
28464cd1e086SMatthew G. Knepley   Level: beginner
28474cd1e086SMatthew G. Knepley 
2848f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
28494cd1e086SMatthew G. Knepley @*/
28504cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
28514cd1e086SMatthew G. Knepley {
28522166fd64SMatthew G. Knepley   PetscErrorCode ierr;
28532166fd64SMatthew G. Knepley 
28544cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28554cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28564cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
28574cd1e086SMatthew 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);
28582166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2859d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
28604cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
28614cd1e086SMatthew G. Knepley }
28624cd1e086SMatthew G. Knepley 
2863bc4ae4beSMatthew G. Knepley /*@
2864bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2865bc4ae4beSMatthew G. Knepley 
2866bc4ae4beSMatthew G. Knepley   Not collective
2867bc4ae4beSMatthew G. Knepley 
2868bc4ae4beSMatthew G. Knepley   Input Parameters:
2869bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2870bc4ae4beSMatthew G. Knepley - f - The field number
2871bc4ae4beSMatthew G. Knepley 
2872bc4ae4beSMatthew G. Knepley   Output Parameter:
2873bc4ae4beSMatthew G. Knepley . off - The offset
2874bc4ae4beSMatthew G. Knepley 
2875bc4ae4beSMatthew G. Knepley   Level: beginner
2876bc4ae4beSMatthew G. Knepley 
2877f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2878bc4ae4beSMatthew G. Knepley @*/
28792764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
28802764a2aaSMatthew G. Knepley {
28814cd1e086SMatthew G. Knepley   PetscInt       size, g;
28822764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
28832764a2aaSMatthew G. Knepley 
28842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28852764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28862764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
28872764a2aaSMatthew 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);
28882764a2aaSMatthew G. Knepley   *off = 0;
28892764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
28904cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
28914cd1e086SMatthew G. Knepley     *off += size;
28922764a2aaSMatthew G. Knepley   }
28932764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28942764a2aaSMatthew G. Knepley }
28952764a2aaSMatthew G. Knepley 
2896bc4ae4beSMatthew G. Knepley /*@
289747e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2898bc4ae4beSMatthew G. Knepley 
2899bc4ae4beSMatthew G. Knepley   Not collective
2900bc4ae4beSMatthew G. Knepley 
290147e57110SSander Arens   Input Parameter:
290247e57110SSander Arens . prob - The PetscDS object
2903bc4ae4beSMatthew G. Knepley 
2904bc4ae4beSMatthew G. Knepley   Output Parameter:
290547e57110SSander Arens . dimensions - The number of dimensions
2906bc4ae4beSMatthew G. Knepley 
2907bc4ae4beSMatthew G. Knepley   Level: beginner
2908bc4ae4beSMatthew G. Knepley 
290947e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2910bc4ae4beSMatthew G. Knepley @*/
291147e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
29122764a2aaSMatthew G. Knepley {
29132764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
29142764a2aaSMatthew G. Knepley 
29152764a2aaSMatthew G. Knepley   PetscFunctionBegin;
29162764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
291747e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
291847e57110SSander Arens   PetscValidPointer(dimensions, 2);
291947e57110SSander Arens   *dimensions = prob->Nb;
292047e57110SSander Arens   PetscFunctionReturn(0);
29216ce16762SMatthew G. Knepley }
292247e57110SSander Arens 
292347e57110SSander Arens /*@
292447e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
292547e57110SSander Arens 
292647e57110SSander Arens   Not collective
292747e57110SSander Arens 
292847e57110SSander Arens   Input Parameter:
292947e57110SSander Arens . prob - The PetscDS object
293047e57110SSander Arens 
293147e57110SSander Arens   Output Parameter:
293247e57110SSander Arens . components - The number of components
293347e57110SSander Arens 
293447e57110SSander Arens   Level: beginner
293547e57110SSander Arens 
293647e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
293747e57110SSander Arens @*/
293847e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
293947e57110SSander Arens {
294047e57110SSander Arens   PetscErrorCode ierr;
294147e57110SSander Arens 
294247e57110SSander Arens   PetscFunctionBegin;
294347e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
294447e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
294547e57110SSander Arens   PetscValidPointer(components, 2);
294647e57110SSander Arens   *components = prob->Nc;
29476ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
29486ce16762SMatthew G. Knepley }
29496ce16762SMatthew G. Knepley 
29506ce16762SMatthew G. Knepley /*@
29516ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
29526ce16762SMatthew G. Knepley 
29536ce16762SMatthew G. Knepley   Not collective
29546ce16762SMatthew G. Knepley 
29556ce16762SMatthew G. Knepley   Input Parameters:
29566ce16762SMatthew G. Knepley + prob - The PetscDS object
29576ce16762SMatthew G. Knepley - f - The field number
29586ce16762SMatthew G. Knepley 
29596ce16762SMatthew G. Knepley   Output Parameter:
29606ce16762SMatthew G. Knepley . off - The offset
29616ce16762SMatthew G. Knepley 
29626ce16762SMatthew G. Knepley   Level: beginner
29636ce16762SMatthew G. Knepley 
2964f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
29656ce16762SMatthew G. Knepley @*/
29666ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
29676ce16762SMatthew G. Knepley {
29686ce16762SMatthew G. Knepley   PetscFunctionBegin;
29696ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29706ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
29716ce16762SMatthew 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);
297247e57110SSander Arens   *off = prob->off[f];
29732764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29742764a2aaSMatthew G. Knepley }
29752764a2aaSMatthew G. Knepley 
2976194d53e6SMatthew G. Knepley /*@
2977194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2978194d53e6SMatthew G. Knepley 
2979194d53e6SMatthew G. Knepley   Not collective
2980194d53e6SMatthew G. Knepley 
2981194d53e6SMatthew G. Knepley   Input Parameter:
2982194d53e6SMatthew G. Knepley . prob - The PetscDS object
2983194d53e6SMatthew G. Knepley 
2984194d53e6SMatthew G. Knepley   Output Parameter:
2985194d53e6SMatthew G. Knepley . offsets - The offsets
2986194d53e6SMatthew G. Knepley 
2987194d53e6SMatthew G. Knepley   Level: beginner
2988194d53e6SMatthew G. Knepley 
2989f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2990194d53e6SMatthew G. Knepley @*/
2991194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2992194d53e6SMatthew G. Knepley {
2993194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2994194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2995194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2996194d53e6SMatthew G. Knepley   *offsets = prob->off;
2997194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2998194d53e6SMatthew G. Knepley }
2999194d53e6SMatthew G. Knepley 
3000194d53e6SMatthew G. Knepley /*@
3001194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
3002194d53e6SMatthew G. Knepley 
3003194d53e6SMatthew G. Knepley   Not collective
3004194d53e6SMatthew G. Knepley 
3005194d53e6SMatthew G. Knepley   Input Parameter:
3006194d53e6SMatthew G. Knepley . prob - The PetscDS object
3007194d53e6SMatthew G. Knepley 
3008194d53e6SMatthew G. Knepley   Output Parameter:
3009194d53e6SMatthew G. Knepley . offsets - The offsets
3010194d53e6SMatthew G. Knepley 
3011194d53e6SMatthew G. Knepley   Level: beginner
3012194d53e6SMatthew G. Knepley 
3013f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
3014194d53e6SMatthew G. Knepley @*/
3015194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
3016194d53e6SMatthew G. Knepley {
3017194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3018194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3019194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
3020194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
3021194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
3022194d53e6SMatthew G. Knepley }
3023194d53e6SMatthew G. Knepley 
302468c9edb9SMatthew G. Knepley /*@C
302568c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
302668c9edb9SMatthew G. Knepley 
302768c9edb9SMatthew G. Knepley   Not collective
302868c9edb9SMatthew G. Knepley 
302968c9edb9SMatthew G. Knepley   Input Parameter:
303068c9edb9SMatthew G. Knepley . prob - The PetscDS object
303168c9edb9SMatthew G. Knepley 
3032ef0bb6c7SMatthew G. Knepley   Output Parameter:
3033ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field
303468c9edb9SMatthew G. Knepley 
303568c9edb9SMatthew G. Knepley   Level: intermediate
303668c9edb9SMatthew G. Knepley 
3037f744cafaSSander Arens .seealso: PetscDSCreate()
303868c9edb9SMatthew G. Knepley @*/
3039ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[])
30402764a2aaSMatthew G. Knepley {
30412764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30422764a2aaSMatthew G. Knepley 
30432764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30442764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3045ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
30462764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3047ef0bb6c7SMatthew G. Knepley   *T = prob->T;
30482764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30492764a2aaSMatthew G. Knepley }
30502764a2aaSMatthew G. Knepley 
305168c9edb9SMatthew G. Knepley /*@C
30524d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
305368c9edb9SMatthew G. Knepley 
305468c9edb9SMatthew G. Knepley   Not collective
305568c9edb9SMatthew G. Knepley 
305668c9edb9SMatthew G. Knepley   Input Parameter:
305768c9edb9SMatthew G. Knepley . prob - The PetscDS object
305868c9edb9SMatthew G. Knepley 
3059ef0bb6c7SMatthew G. Knepley   Output Parameter:
306019815104SMartin Diehl . Tf - The basis function and derviative tabulation on each local face at quadrature points for each and field
306168c9edb9SMatthew G. Knepley 
306268c9edb9SMatthew G. Knepley   Level: intermediate
306368c9edb9SMatthew G. Knepley 
306468c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
306568c9edb9SMatthew G. Knepley @*/
3066ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[])
30672764a2aaSMatthew G. Knepley {
30682764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30692764a2aaSMatthew G. Knepley 
30702764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30712764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3072ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
30732764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3074ef0bb6c7SMatthew G. Knepley   *Tf = prob->Tf;
30752764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30762764a2aaSMatthew G. Knepley }
30772764a2aaSMatthew G. Knepley 
30782764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
30792764a2aaSMatthew G. Knepley {
30802764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30812764a2aaSMatthew G. Knepley 
30822764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30832764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30842764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
30852764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
30862764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
30872764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
30882764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30892764a2aaSMatthew G. Knepley }
30902764a2aaSMatthew G. Knepley 
30912764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
30922764a2aaSMatthew G. Knepley {
30932764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30942764a2aaSMatthew G. Knepley 
30952764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30962764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30972764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
30982764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
30992764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
31002764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
31012764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
31022764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
31032764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
31042764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31052764a2aaSMatthew G. Knepley }
31062764a2aaSMatthew G. Knepley 
31074bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal)
31082764a2aaSMatthew G. Knepley {
31092764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
31102764a2aaSMatthew G. Knepley 
31112764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31122764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31132764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
31142764a2aaSMatthew G. Knepley   if (x)            {PetscValidPointer(x, 2);            *x            = prob->x;}
31154bee2e38SMatthew G. Knepley   if (basisReal)    {PetscValidPointer(basisReal, 3);    *basisReal    = prob->basisReal;}
31167506b574SStefano Zampini   if (basisDerReal) {PetscValidPointer(basisDerReal, 4); *basisDerReal = prob->basisDerReal;}
31177506b574SStefano Zampini   if (testReal)     {PetscValidPointer(testReal, 5);     *testReal     = prob->testReal;}
31187506b574SStefano Zampini   if (testDerReal)  {PetscValidPointer(testDerReal, 6);  *testDerReal  = prob->testDerReal;}
31192764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31202764a2aaSMatthew G. Knepley }
31212764a2aaSMatthew G. Knepley 
312258ebd649SToby Isaac /*@C
312356cf3b9cSMatthew 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().
312458ebd649SToby Isaac 
3125783e2ec8SMatthew G. Knepley   Collective on ds
3126783e2ec8SMatthew G. Knepley 
312758ebd649SToby Isaac   Input Parameters:
312858ebd649SToby Isaac + ds          - The PetscDS object
31292d47a189SJulian Andrej . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
313058ebd649SToby Isaac . name        - The BC name
313158ebd649SToby Isaac . labelname   - The label defining constrained points
313258ebd649SToby Isaac . field       - The field to constrain
3133e8ecbf3fSStefano Zampini . numcomps    - The number of constrained field components (0 will constrain all fields)
313458ebd649SToby Isaac . comps       - An array of constrained component numbers
313558ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
313656cf3b9cSMatthew G. Knepley . bcFunc_t    - A pointwise function giving the time derviative of the boundary values, or NULL
313758ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
313858ebd649SToby Isaac . ids         - An array of ids for constrained points
313958ebd649SToby Isaac - ctx         - An optional user context for bcFunc
314058ebd649SToby Isaac 
314158ebd649SToby Isaac   Options Database Keys:
314258ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
314358ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
314458ebd649SToby Isaac 
314556cf3b9cSMatthew G. Knepley   Note:
314656cf3b9cSMatthew 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:
314756cf3b9cSMatthew G. Knepley 
314856cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
314956cf3b9cSMatthew G. Knepley 
315056cf3b9cSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
315156cf3b9cSMatthew G. Knepley 
315256cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
315356cf3b9cSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
315456cf3b9cSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
315556cf3b9cSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
315656cf3b9cSMatthew G. Knepley 
315756cf3b9cSMatthew G. Knepley + dim - the spatial dimension
315856cf3b9cSMatthew G. Knepley . Nf - the number of fields
315956cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
316056cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
316156cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point
316256cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
316356cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
316456cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
316556cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
316656cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
316756cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
316856cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
316956cf3b9cSMatthew G. Knepley . t - current time
317056cf3b9cSMatthew G. Knepley . x - coordinates of the current point
317156cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters
317256cf3b9cSMatthew G. Knepley . constants - constant parameters
317356cf3b9cSMatthew G. Knepley - bcval - output values at the current point
317456cf3b9cSMatthew G. Knepley 
317558ebd649SToby Isaac   Level: developer
317658ebd649SToby Isaac 
317756cf3b9cSMatthew G. Knepley .seealso: PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual()
317858ebd649SToby Isaac @*/
317956cf3b9cSMatthew 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)
318058ebd649SToby Isaac {
318158ebd649SToby Isaac   DSBoundary     b;
318258ebd649SToby Isaac   PetscErrorCode ierr;
318358ebd649SToby Isaac 
318458ebd649SToby Isaac   PetscFunctionBegin;
318558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3186783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
3187783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 5);
3188783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, numcomps, 6);
3189783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, numids, 9);
319058ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
319158ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
319258ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
319358ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
3194580bdb30SBarry Smith   if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);}
319558ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
3196580bdb30SBarry Smith   if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);}
3197f971fd6bSMatthew G. Knepley   b->type            = type;
319858ebd649SToby Isaac   b->field           = field;
319958ebd649SToby Isaac   b->numcomps        = numcomps;
320058ebd649SToby Isaac   b->func            = bcFunc;
320156cf3b9cSMatthew G. Knepley   b->func_t          = bcFunc_t;
320258ebd649SToby Isaac   b->numids          = numids;
320358ebd649SToby Isaac   b->ctx             = ctx;
320458ebd649SToby Isaac   b->next            = ds->boundary;
320558ebd649SToby Isaac   ds->boundary       = b;
320658ebd649SToby Isaac   PetscFunctionReturn(0);
320758ebd649SToby Isaac }
320858ebd649SToby Isaac 
3209b67eacb3SMatthew G. Knepley /*@C
321056cf3b9cSMatthew 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().
3211b67eacb3SMatthew G. Knepley 
3212b67eacb3SMatthew G. Knepley   Input Parameters:
3213b67eacb3SMatthew G. Knepley + ds          - The PetscDS object
3214b67eacb3SMatthew G. Knepley . bd          - The boundary condition number
3215b67eacb3SMatthew G. Knepley . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
3216b67eacb3SMatthew G. Knepley . name        - The BC name
3217b67eacb3SMatthew G. Knepley . labelname   - The label defining constrained points
3218b67eacb3SMatthew G. Knepley . field       - The field to constrain
3219b67eacb3SMatthew G. Knepley . numcomps    - The number of constrained field components
3220b67eacb3SMatthew G. Knepley . comps       - An array of constrained component numbers
3221b67eacb3SMatthew G. Knepley . bcFunc      - A pointwise function giving boundary values
322256cf3b9cSMatthew G. Knepley . bcFunc_t    - A pointwise function giving the time derviative of the boundary values, or NULL
3223b67eacb3SMatthew G. Knepley . numids      - The number of DMLabel ids for constrained points
3224b67eacb3SMatthew G. Knepley . ids         - An array of ids for constrained points
3225b67eacb3SMatthew G. Knepley - ctx         - An optional user context for bcFunc
3226b67eacb3SMatthew G. Knepley 
322756cf3b9cSMatthew G. Knepley   Note:
322856cf3b9cSMatthew 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.
32299a6efb6aSMatthew G. Knepley 
3230b67eacb3SMatthew G. Knepley   Level: developer
3231b67eacb3SMatthew G. Knepley 
32329a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary()
3233b67eacb3SMatthew G. Knepley @*/
323456cf3b9cSMatthew 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)
3235b67eacb3SMatthew G. Knepley {
3236b67eacb3SMatthew G. Knepley   DSBoundary     b = ds->boundary;
3237b67eacb3SMatthew G. Knepley   PetscInt       n = 0;
3238b67eacb3SMatthew G. Knepley   PetscErrorCode ierr;
3239b67eacb3SMatthew G. Knepley 
3240b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
3241b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3242b67eacb3SMatthew G. Knepley   while (b) {
3243b67eacb3SMatthew G. Knepley     if (n == bd) break;
3244b67eacb3SMatthew G. Knepley     b = b->next;
3245b67eacb3SMatthew G. Knepley     ++n;
3246b67eacb3SMatthew G. Knepley   }
3247b67eacb3SMatthew G. Knepley   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
3248b67eacb3SMatthew G. Knepley   if (name) {
3249b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
3250b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
3251b67eacb3SMatthew G. Knepley   }
3252b67eacb3SMatthew G. Knepley   if (labelname) {
3253b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
3254b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
3255b67eacb3SMatthew G. Knepley   }
3256b67eacb3SMatthew G. Knepley   if (numcomps >= 0 && numcomps != b->numcomps) {
3257b67eacb3SMatthew G. Knepley     b->numcomps = numcomps;
3258b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
3259b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
3260580bdb30SBarry Smith     if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);}
3261b67eacb3SMatthew G. Knepley   }
3262b67eacb3SMatthew G. Knepley   if (numids >= 0 && numids != b->numids) {
3263b67eacb3SMatthew G. Knepley     b->numids = numids;
3264b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->ids);CHKERRQ(ierr);
3265b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
3266580bdb30SBarry Smith     if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);}
3267b67eacb3SMatthew G. Knepley   }
3268b67eacb3SMatthew G. Knepley   b->type = type;
3269b67eacb3SMatthew G. Knepley   if (field >= 0) {b->field  = field;}
3270b67eacb3SMatthew G. Knepley   if (bcFunc)     {b->func   = bcFunc;}
327156cf3b9cSMatthew G. Knepley   if (bcFunc_t)   {b->func_t = bcFunc_t;}
3272b67eacb3SMatthew G. Knepley   if (ctx)        {b->ctx    = ctx;}
3273b67eacb3SMatthew G. Knepley   PetscFunctionReturn(0);
3274b67eacb3SMatthew G. Knepley }
3275b67eacb3SMatthew G. Knepley 
327658ebd649SToby Isaac /*@
327758ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
327858ebd649SToby Isaac 
327958ebd649SToby Isaac   Input Parameters:
328058ebd649SToby Isaac . ds - The PetscDS object
328158ebd649SToby Isaac 
328258ebd649SToby Isaac   Output Parameters:
328358ebd649SToby Isaac . numBd - The number of BC
328458ebd649SToby Isaac 
328558ebd649SToby Isaac   Level: intermediate
328658ebd649SToby Isaac 
328758ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
328858ebd649SToby Isaac @*/
328958ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
329058ebd649SToby Isaac {
329158ebd649SToby Isaac   DSBoundary b = ds->boundary;
329258ebd649SToby Isaac 
329358ebd649SToby Isaac   PetscFunctionBegin;
329458ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
329558ebd649SToby Isaac   PetscValidPointer(numBd, 2);
329658ebd649SToby Isaac   *numBd = 0;
329758ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
329858ebd649SToby Isaac   PetscFunctionReturn(0);
329958ebd649SToby Isaac }
330058ebd649SToby Isaac 
330158ebd649SToby Isaac /*@C
33029a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
330358ebd649SToby Isaac 
330458ebd649SToby Isaac   Input Parameters:
330558ebd649SToby Isaac + ds          - The PetscDS object
330658ebd649SToby Isaac - bd          - The BC number
330758ebd649SToby Isaac 
330858ebd649SToby Isaac   Output Parameters:
33092d47a189SJulian Andrej + type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
331058ebd649SToby Isaac . name        - The BC name
331158ebd649SToby Isaac . labelname   - The label defining constrained points
331258ebd649SToby Isaac . field       - The field to constrain
331358ebd649SToby Isaac . numcomps    - The number of constrained field components
331458ebd649SToby Isaac . comps       - An array of constrained component numbers
331558ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
331656cf3b9cSMatthew G. Knepley . bcFunc_t    - A pointwise function giving the time derviative of the boundary values
331758ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
331858ebd649SToby Isaac . ids         - An array of ids for constrained points
331958ebd649SToby Isaac - ctx         - An optional user context for bcFunc
332058ebd649SToby Isaac 
332158ebd649SToby Isaac   Options Database Keys:
332258ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
332358ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
332458ebd649SToby Isaac 
332558ebd649SToby Isaac   Level: developer
332658ebd649SToby Isaac 
332758ebd649SToby Isaac .seealso: PetscDSAddBoundary()
332858ebd649SToby Isaac @*/
332956cf3b9cSMatthew 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)
333058ebd649SToby Isaac {
333158ebd649SToby Isaac   DSBoundary b    = ds->boundary;
333258ebd649SToby Isaac   PetscInt   n    = 0;
333358ebd649SToby Isaac 
333458ebd649SToby Isaac   PetscFunctionBegin;
333558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
333658ebd649SToby Isaac   while (b) {
333758ebd649SToby Isaac     if (n == bd) break;
333858ebd649SToby Isaac     b = b->next;
333958ebd649SToby Isaac     ++n;
334058ebd649SToby Isaac   }
334158ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
3342f971fd6bSMatthew G. Knepley   if (type) {
3343f971fd6bSMatthew G. Knepley     PetscValidPointer(type, 3);
3344f971fd6bSMatthew G. Knepley     *type = b->type;
334558ebd649SToby Isaac   }
334658ebd649SToby Isaac   if (name) {
334758ebd649SToby Isaac     PetscValidPointer(name, 4);
334858ebd649SToby Isaac     *name = b->name;
334958ebd649SToby Isaac   }
335058ebd649SToby Isaac   if (labelname) {
335158ebd649SToby Isaac     PetscValidPointer(labelname, 5);
335258ebd649SToby Isaac     *labelname = b->labelname;
335358ebd649SToby Isaac   }
335458ebd649SToby Isaac   if (field) {
335558ebd649SToby Isaac     PetscValidPointer(field, 6);
335658ebd649SToby Isaac     *field = b->field;
335758ebd649SToby Isaac   }
335858ebd649SToby Isaac   if (numcomps) {
335958ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
336058ebd649SToby Isaac     *numcomps = b->numcomps;
336158ebd649SToby Isaac   }
336258ebd649SToby Isaac   if (comps) {
336358ebd649SToby Isaac     PetscValidPointer(comps, 8);
336458ebd649SToby Isaac     *comps = b->comps;
336558ebd649SToby Isaac   }
336658ebd649SToby Isaac   if (func) {
336758ebd649SToby Isaac     PetscValidPointer(func, 9);
336858ebd649SToby Isaac     *func = b->func;
336958ebd649SToby Isaac   }
337056cf3b9cSMatthew G. Knepley   if (func_t) {
337156cf3b9cSMatthew G. Knepley     PetscValidPointer(func_t, 10);
337256cf3b9cSMatthew G. Knepley     *func_t = b->func_t;
337356cf3b9cSMatthew G. Knepley   }
337458ebd649SToby Isaac   if (numids) {
337556cf3b9cSMatthew G. Knepley     PetscValidPointer(numids, 11);
337658ebd649SToby Isaac     *numids = b->numids;
337758ebd649SToby Isaac   }
337858ebd649SToby Isaac   if (ids) {
337956cf3b9cSMatthew G. Knepley     PetscValidPointer(ids, 12);
338058ebd649SToby Isaac     *ids = b->ids;
338158ebd649SToby Isaac   }
338258ebd649SToby Isaac   if (ctx) {
338356cf3b9cSMatthew G. Knepley     PetscValidPointer(ctx, 13);
338458ebd649SToby Isaac     *ctx = b->ctx;
338558ebd649SToby Isaac   }
338658ebd649SToby Isaac   PetscFunctionReturn(0);
338758ebd649SToby Isaac }
338858ebd649SToby Isaac 
33899252d075SMatthew G. Knepley /*@
33909252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
33919252d075SMatthew G. Knepley 
33929252d075SMatthew G. Knepley   Not collective
33939252d075SMatthew G. Knepley 
339436951cb5SMatthew G. Knepley   Input Parameters:
339536951cb5SMatthew G. Knepley + ds        - The source PetscDS object
339636951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields
339736951cb5SMatthew G. Knepley - fields    - The selected fields, or NULL for all fields
33989252d075SMatthew G. Knepley 
33999252d075SMatthew G. Knepley   Output Parameter:
340036951cb5SMatthew G. Knepley . newds     - The target PetscDS, now with a copy of the boundary conditions
34019252d075SMatthew G. Knepley 
34029252d075SMatthew G. Knepley   Level: intermediate
34039252d075SMatthew G. Knepley 
34049252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
34059252d075SMatthew G. Knepley @*/
340636951cb5SMatthew G. Knepley PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds)
3407dff059c6SToby Isaac {
3408dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
3409dff059c6SToby Isaac   PetscErrorCode ierr;
3410dff059c6SToby Isaac 
3411dff059c6SToby Isaac   PetscFunctionBegin;
341236951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(ds,    PETSCDS_CLASSID, 1);
341336951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4);
341436951cb5SMatthew G. Knepley   if (ds == newds) PetscFunctionReturn(0);
341536951cb5SMatthew G. Knepley   next = newds->boundary;
3416dff059c6SToby Isaac   while (next) {
3417dff059c6SToby Isaac     DSBoundary b = next;
3418dff059c6SToby Isaac 
3419dff059c6SToby Isaac     next = b->next;
3420dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
3421dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
3422dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
3423dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
3424dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
3425dff059c6SToby Isaac   }
342636951cb5SMatthew G. Knepley   lastnext = &(newds->boundary);
342736951cb5SMatthew G. Knepley   for (b = ds->boundary; b; b = b->next) {
3428dff059c6SToby Isaac     DSBoundary bNew;
342936951cb5SMatthew G. Knepley     PetscInt   fieldNew = -1;
3430dff059c6SToby Isaac 
343136951cb5SMatthew G. Knepley     if (numFields > 0 && fields) {
343236951cb5SMatthew G. Knepley       PetscInt f;
343336951cb5SMatthew G. Knepley 
343436951cb5SMatthew G. Knepley       for (f = 0; f < numFields; ++f) if (b->field == fields[f]) break;
343536951cb5SMatthew G. Knepley       if (f == numFields) continue;
343636951cb5SMatthew G. Knepley       fieldNew = f;
343736951cb5SMatthew G. Knepley     }
3438459726d8SSatish Balay     ierr = PetscNew(&bNew);CHKERRQ(ierr);
3439dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
3440dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
3441580bdb30SBarry Smith     ierr = PetscArraycpy(bNew->comps, b->comps, bNew->numcomps);CHKERRQ(ierr);
3442dff059c6SToby Isaac     bNew->numids = b->numids;
3443dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
3444580bdb30SBarry Smith     ierr = PetscArraycpy(bNew->ids, b->ids, bNew->numids);CHKERRQ(ierr);
3445dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
3446dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
3447dff059c6SToby Isaac     bNew->ctx   = b->ctx;
3448f971fd6bSMatthew G. Knepley     bNew->type  = b->type;
344936951cb5SMatthew G. Knepley     bNew->field = fieldNew < 0 ? b->field : fieldNew;
3450dff059c6SToby Isaac     bNew->func  = b->func;
3451dff059c6SToby Isaac 
3452dff059c6SToby Isaac     *lastnext = bNew;
3453dff059c6SToby Isaac     lastnext = &(bNew->next);
3454dff059c6SToby Isaac   }
3455dff059c6SToby Isaac   PetscFunctionReturn(0);
3456dff059c6SToby Isaac }
3457dff059c6SToby Isaac 
34586c1eb96dSMatthew G. Knepley /*@
34596c1eb96dSMatthew G. Knepley   PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout
34606c1eb96dSMatthew G. Knepley 
34616c1eb96dSMatthew G. Knepley   Not collective
34626c1eb96dSMatthew G. Knepley 
34636c1eb96dSMatthew G. Knepley   Input Parameter:
34646c1eb96dSMatthew G. Knepley + prob - The PetscDS object
34656c1eb96dSMatthew G. Knepley . numFields - Number of new fields
34666c1eb96dSMatthew G. Knepley - fields - Old field number for each new field
34676c1eb96dSMatthew G. Knepley 
34686c1eb96dSMatthew G. Knepley   Output Parameter:
34696c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy
34706c1eb96dSMatthew G. Knepley 
34716c1eb96dSMatthew G. Knepley   Level: intermediate
34726c1eb96dSMatthew G. Knepley 
34736c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectEquations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
34746c1eb96dSMatthew G. Knepley @*/
34756c1eb96dSMatthew G. Knepley PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
34766c1eb96dSMatthew G. Knepley {
34776c1eb96dSMatthew G. Knepley   PetscInt       Nf, Nfn, fn;
34786c1eb96dSMatthew G. Knepley   PetscErrorCode ierr;
34796c1eb96dSMatthew G. Knepley 
34806c1eb96dSMatthew G. Knepley   PetscFunctionBegin;
34816c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
34826c1eb96dSMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
34836c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
34846c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
34856c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
34866c1eb96dSMatthew 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);
34876c1eb96dSMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
34886c1eb96dSMatthew G. Knepley     const PetscInt f = fields ? fields[fn] : fn;
34896c1eb96dSMatthew G. Knepley     PetscObject    disc;
34906c1eb96dSMatthew G. Knepley 
34916c1eb96dSMatthew G. Knepley     if (f >= Nf) continue;
34926c1eb96dSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &disc);CHKERRQ(ierr);
34936c1eb96dSMatthew G. Knepley     ierr = PetscDSSetDiscretization(newprob, fn, disc);CHKERRQ(ierr);
34946c1eb96dSMatthew G. Knepley   }
34956c1eb96dSMatthew G. Knepley   PetscFunctionReturn(0);
34966c1eb96dSMatthew G. Knepley }
34976c1eb96dSMatthew G. Knepley 
34986c1eb96dSMatthew G. Knepley /*@
34999252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
35009252d075SMatthew G. Knepley 
35019252d075SMatthew G. Knepley   Not collective
35029252d075SMatthew G. Knepley 
35039252d075SMatthew G. Knepley   Input Parameter:
35049252d075SMatthew G. Knepley + prob - The PetscDS object
35059252d075SMatthew G. Knepley . numFields - Number of new fields
35069252d075SMatthew G. Knepley - fields - Old field number for each new field
35079252d075SMatthew G. Knepley 
35089252d075SMatthew G. Knepley   Output Parameter:
35099252d075SMatthew G. Knepley . newprob - The PetscDS copy
35109252d075SMatthew G. Knepley 
35119252d075SMatthew G. Knepley   Level: intermediate
35129252d075SMatthew G. Knepley 
35136c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectDiscretizations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
35149252d075SMatthew G. Knepley @*/
35159252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
35169252d075SMatthew G. Knepley {
35179252d075SMatthew G. Knepley   PetscInt       Nf, Nfn, fn, gn;
35189252d075SMatthew G. Knepley   PetscErrorCode ierr;
35199252d075SMatthew G. Knepley 
35209252d075SMatthew G. Knepley   PetscFunctionBegin;
35219252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
35229252d075SMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
35239252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
35249252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
35259252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
35269252d075SMatthew 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);
35279252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
35289252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
35299252d075SMatthew G. Knepley     PetscPointFunc   obj;
35309252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
35319252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
35329252d075SMatthew G. Knepley     PetscRiemannFunc r;
35339252d075SMatthew G. Knepley 
3534c52f1e13SMatthew G. Knepley     if (f >= Nf) continue;
35359252d075SMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
35369252d075SMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
35379252d075SMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
35389252d075SMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
35399252d075SMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr);
35409252d075SMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr);
35419252d075SMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr);
35429252d075SMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr);
35439252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
35449252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
35459252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
35469252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
35479252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
35489252d075SMatthew G. Knepley 
3549c52f1e13SMatthew G. Knepley       if (g >= Nf) continue;
35509252d075SMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
35519252d075SMatthew G. Knepley       ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr);
35529252d075SMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
35539252d075SMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr);
35546c1eb96dSMatthew G. Knepley       ierr = PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr);
35559252d075SMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
35569252d075SMatthew G. Knepley     }
35579252d075SMatthew G. Knepley   }
35589252d075SMatthew G. Knepley   PetscFunctionReturn(0);
35599252d075SMatthew G. Knepley }
35609252d075SMatthew G. Knepley 
3561da51fcedSMatthew G. Knepley /*@
3562da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
3563da51fcedSMatthew G. Knepley 
3564da51fcedSMatthew G. Knepley   Not collective
3565da51fcedSMatthew G. Knepley 
3566da51fcedSMatthew G. Knepley   Input Parameter:
3567da51fcedSMatthew G. Knepley . prob - The PetscDS object
3568da51fcedSMatthew G. Knepley 
3569da51fcedSMatthew G. Knepley   Output Parameter:
3570da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
3571da51fcedSMatthew G. Knepley 
3572da51fcedSMatthew G. Knepley   Level: intermediate
3573da51fcedSMatthew G. Knepley 
35749252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
3575da51fcedSMatthew G. Knepley @*/
3576da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
3577da51fcedSMatthew G. Knepley {
35789252d075SMatthew G. Knepley   PetscInt       Nf, Ng;
3579da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
3580da51fcedSMatthew G. Knepley 
3581da51fcedSMatthew G. Knepley   PetscFunctionBegin;
3582da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3583da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
3584da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3585da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
358613903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
35879252d075SMatthew G. Knepley   ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr);
35889252d075SMatthew G. Knepley   PetscFunctionReturn(0);
35899252d075SMatthew G. Knepley }
35909252d075SMatthew G. Knepley /*@
35919252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
3592da51fcedSMatthew G. Knepley 
35939252d075SMatthew G. Knepley   Not collective
35949252d075SMatthew G. Knepley 
35959252d075SMatthew G. Knepley   Input Parameter:
35969252d075SMatthew G. Knepley . prob - The PetscDS object
35979252d075SMatthew G. Knepley 
35989252d075SMatthew G. Knepley   Output Parameter:
35999252d075SMatthew G. Knepley . newprob - The PetscDS copy
36009252d075SMatthew G. Knepley 
36019252d075SMatthew G. Knepley   Level: intermediate
36029252d075SMatthew G. Knepley 
36039252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
36049252d075SMatthew G. Knepley @*/
36059252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
36069252d075SMatthew G. Knepley {
36079252d075SMatthew G. Knepley   PetscInt           Nc;
36089252d075SMatthew G. Knepley   const PetscScalar *constants;
36099252d075SMatthew G. Knepley   PetscErrorCode     ierr;
36109252d075SMatthew G. Knepley 
36119252d075SMatthew G. Knepley   PetscFunctionBegin;
36129252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
36139252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
36149252d075SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr);
36159252d075SMatthew G. Knepley   ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr);
3616da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
3617da51fcedSMatthew G. Knepley }
3618da51fcedSMatthew G. Knepley 
3619b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
3620b1353e8eSMatthew G. Knepley {
3621df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
3622b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
3623b1353e8eSMatthew G. Knepley 
3624b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
3625b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3626b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
3627b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
3628b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3629df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
3630df3a45bdSMatthew 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);
3631df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
3632df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
3633b1353e8eSMatthew G. Knepley     PetscInt cdim;
3634b1353e8eSMatthew G. Knepley 
3635df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
3636b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
3637df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
3638b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
3639b1353e8eSMatthew G. Knepley       PetscFE      subfe;
3640b1353e8eSMatthew G. Knepley       PetscObject  obj;
3641b1353e8eSMatthew G. Knepley       PetscClassId id;
3642b1353e8eSMatthew G. Knepley 
3643b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3644b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3645b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
3646b1353e8eSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
3647df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
3648b1353e8eSMatthew G. Knepley     }
3649b1353e8eSMatthew G. Knepley   }
3650df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
3651b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
3652b1353e8eSMatthew G. Knepley }
3653b1353e8eSMatthew G. Knepley 
3654665f567fSMatthew G. Knepley PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype)
3655c7bd5f0bSMatthew G. Knepley {
3656c7bd5f0bSMatthew G. Knepley   PetscObject    obj;
3657c7bd5f0bSMatthew G. Knepley   PetscClassId   id;
3658c7bd5f0bSMatthew G. Knepley   PetscInt       Nf;
3659c7bd5f0bSMatthew G. Knepley   PetscErrorCode ierr;
3660c7bd5f0bSMatthew G. Knepley 
3661c7bd5f0bSMatthew G. Knepley   PetscFunctionBegin;
3662c7bd5f0bSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3663665f567fSMatthew G. Knepley   PetscValidPointer(disctype, 3);
3664665f567fSMatthew G. Knepley   *disctype = PETSC_DISC_NONE;
3665c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
3666c7bd5f0bSMatthew G. Knepley   if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf);
3667c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr);
3668665f567fSMatthew G. Knepley   if (obj) {
3669c7bd5f0bSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3670665f567fSMatthew G. Knepley     if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE;
3671665f567fSMatthew G. Knepley     else                       *disctype = PETSC_DISC_FV;
3672665f567fSMatthew G. Knepley   }
3673c7bd5f0bSMatthew G. Knepley   PetscFunctionReturn(0);
3674c7bd5f0bSMatthew G. Knepley }
3675c7bd5f0bSMatthew G. Knepley 
36766528b96dSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds)
36772764a2aaSMatthew G. Knepley {
3678931fb3b8SToby Isaac   PetscErrorCode ierr;
3679931fb3b8SToby Isaac 
36802764a2aaSMatthew G. Knepley   PetscFunctionBegin;
36816528b96dSMatthew G. Knepley   ierr = PetscFree(ds->data);CHKERRQ(ierr);
36822764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
36832764a2aaSMatthew G. Knepley }
36842764a2aaSMatthew G. Knepley 
36856528b96dSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds)
36862764a2aaSMatthew G. Knepley {
36872764a2aaSMatthew G. Knepley   PetscFunctionBegin;
36886528b96dSMatthew G. Knepley   ds->ops->setfromoptions = NULL;
36896528b96dSMatthew G. Knepley   ds->ops->setup          = NULL;
36906528b96dSMatthew G. Knepley   ds->ops->view           = NULL;
36916528b96dSMatthew G. Knepley   ds->ops->destroy        = PetscDSDestroy_Basic;
36922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
36932764a2aaSMatthew G. Knepley }
36942764a2aaSMatthew G. Knepley 
36952764a2aaSMatthew G. Knepley /*MC
36962764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
36972764a2aaSMatthew G. Knepley 
36982764a2aaSMatthew G. Knepley   Level: intermediate
36992764a2aaSMatthew G. Knepley 
37002764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
37012764a2aaSMatthew G. Knepley M*/
37022764a2aaSMatthew G. Knepley 
37036528b96dSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds)
37042764a2aaSMatthew G. Knepley {
37052764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
37062764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
37072764a2aaSMatthew G. Knepley 
37082764a2aaSMatthew G. Knepley   PetscFunctionBegin;
37096528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
37106528b96dSMatthew G. Knepley   ierr = PetscNewLog(ds, &b);CHKERRQ(ierr);
37116528b96dSMatthew G. Knepley   ds->data = b;
37122764a2aaSMatthew G. Knepley 
37136528b96dSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(ds);CHKERRQ(ierr);
37142764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
37152764a2aaSMatthew G. Knepley }
3716