xref: /petsc/src/dm/dt/interface/dtds.c (revision 064a246e8b5c1f87897a54b4a9ec05181ea08258)
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) {
1888e0d8d9cSMatthew 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);
19345480ffeSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->lname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr);
19445480ffeSMatthew G. Knepley       if (!b->Nc) {
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);
19945480ffeSMatthew G. Knepley         for (c = 0; c < b->Nc; ++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       }
20645480ffeSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "  values: ");CHKERRQ(ierr);
20740967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
20845480ffeSMatthew G. Knepley       for (i = 0; i < b->Nv; ++i) {
20940967b3bSMatthew G. Knepley         if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
21045480ffeSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "%D", b->values[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);
2148e0d8d9cSMatthew G. Knepley       if (b->func) {
2158e0d8d9cSMatthew G. Knepley         ierr = PetscDLAddr(b->func, &name);CHKERRQ(ierr);
2168e0d8d9cSMatthew G. Knepley         if (name) {ierr = PetscViewerASCIIPrintf(viewer, "  func: %s\n", name);CHKERRQ(ierr);}
2178e0d8d9cSMatthew G. Knepley         else      {ierr = PetscViewerASCIIPrintf(viewer, "  func: %p\n", b->func);CHKERRQ(ierr);}
2188e0d8d9cSMatthew G. Knepley       }
2198e0d8d9cSMatthew G. Knepley       if (b->func_t) {
2208e0d8d9cSMatthew G. Knepley         ierr = PetscDLAddr(b->func_t, &name);CHKERRQ(ierr);
2218e0d8d9cSMatthew G. Knepley         if (name) {ierr = PetscViewerASCIIPrintf(viewer, "  func: %s\n", name);CHKERRQ(ierr);}
2228e0d8d9cSMatthew G. Knepley         else      {ierr = PetscViewerASCIIPrintf(viewer, "  func: %p\n", b->func_t);CHKERRQ(ierr);}
2238e0d8d9cSMatthew G. Knepley       }
22445480ffeSMatthew G. Knepley       ierr = PetscWeakFormView(b->wf, viewer);CHKERRQ(ierr);
22540967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
22640967b3bSMatthew G. Knepley     }
2277d8a60eaSMatthew G. Knepley   }
22897b6e6e8SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr);
22997b6e6e8SMatthew G. Knepley   if (numConstants) {
23097b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr);
23197b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
23257fc01e9SMatthew G. Knepley     for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);}
23397b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
23497b6e6e8SMatthew G. Knepley   }
2356528b96dSMatthew G. Knepley   ierr = PetscWeakFormView(prob->wf, viewer);CHKERRQ(ierr);
2367d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
2377d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
2387d8a60eaSMatthew G. Knepley }
2397d8a60eaSMatthew G. Knepley 
2402764a2aaSMatthew G. Knepley /*@C
241fe2efc57SMark    PetscDSViewFromOptions - View from Options
242fe2efc57SMark 
243fe2efc57SMark    Collective on PetscDS
244fe2efc57SMark 
245fe2efc57SMark    Input Parameters:
246fe2efc57SMark +  A - the PetscDS object
247736c3998SJose E. Roman .  obj - Optional object
248736c3998SJose E. Roman -  name - command line option
249fe2efc57SMark 
250fe2efc57SMark    Level: intermediate
251fe2efc57SMark .seealso:  PetscDS, PetscDSView, PetscObjectViewFromOptions(), PetscDSCreate()
252fe2efc57SMark @*/
253fe2efc57SMark PetscErrorCode  PetscDSViewFromOptions(PetscDS A,PetscObject obj,const char name[])
254fe2efc57SMark {
255fe2efc57SMark   PetscErrorCode ierr;
256fe2efc57SMark 
257fe2efc57SMark   PetscFunctionBegin;
258fe2efc57SMark   PetscValidHeaderSpecific(A,PETSCDS_CLASSID,1);
259fe2efc57SMark   ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr);
260fe2efc57SMark   PetscFunctionReturn(0);
261fe2efc57SMark }
262fe2efc57SMark 
263fe2efc57SMark /*@C
2642764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
2652764a2aaSMatthew G. Knepley 
266d083f849SBarry Smith   Collective on prob
2672764a2aaSMatthew G. Knepley 
2682764a2aaSMatthew G. Knepley   Input Parameter:
2692764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
2702764a2aaSMatthew G. Knepley - v  - the viewer
2712764a2aaSMatthew G. Knepley 
2722764a2aaSMatthew G. Knepley   Level: developer
2732764a2aaSMatthew G. Knepley 
2742764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
2752764a2aaSMatthew G. Knepley @*/
2762764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
2772764a2aaSMatthew G. Knepley {
2787d8a60eaSMatthew G. Knepley   PetscBool      iascii;
2792764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2802764a2aaSMatthew G. Knepley 
2812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2822764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2832764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
2847d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
2857d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
2867d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2872764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2882764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2892764a2aaSMatthew G. Knepley }
2902764a2aaSMatthew G. Knepley 
2912764a2aaSMatthew G. Knepley /*@
2922764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2932764a2aaSMatthew G. Knepley 
294d083f849SBarry Smith   Collective on prob
2952764a2aaSMatthew G. Knepley 
2962764a2aaSMatthew G. Knepley   Input Parameter:
2972764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2982764a2aaSMatthew G. Knepley 
2992764a2aaSMatthew G. Knepley   Options Database:
30055c1f793SMatthew G. Knepley + -petscds_type <type>     : Set the DS type
30155c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS
30255c1f793SMatthew G. Knepley . -petscds_jac_pre         : Turn formation of a separate Jacobian preconditioner on and off
30355c1f793SMatthew G. Knepley . -bc_<name> <ids>         : Specify a list of label ids for a boundary condition
30455c1f793SMatthew G. Knepley - -bc_<name>_comp <comps>  : Specify a list of field components to constrain for a boundary condition
3052764a2aaSMatthew G. Knepley 
3062764a2aaSMatthew G. Knepley   Level: developer
3072764a2aaSMatthew G. Knepley 
3082764a2aaSMatthew G. Knepley .seealso PetscDSView()
3092764a2aaSMatthew G. Knepley @*/
3102764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
3112764a2aaSMatthew G. Knepley {
312f1fd5e65SToby Isaac   DSBoundary     b;
3132764a2aaSMatthew G. Knepley   const char    *defaultType;
3142764a2aaSMatthew G. Knepley   char           name[256];
3152764a2aaSMatthew G. Knepley   PetscBool      flg;
3162764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3172764a2aaSMatthew G. Knepley 
3182764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3192764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3202764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
3212764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
3222764a2aaSMatthew G. Knepley   } else {
3232764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
3242764a2aaSMatthew G. Knepley   }
3250f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
3262764a2aaSMatthew G. Knepley 
3272764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
328f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
329f1fd5e65SToby Isaac     char       optname[1024];
330f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
331f1fd5e65SToby Isaac     PetscBool  flg;
332f1fd5e65SToby Isaac 
333f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
334f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
335f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
336f1fd5e65SToby Isaac     if (flg) {
33745480ffeSMatthew G. Knepley       b->Nv = len;
33845480ffeSMatthew G. Knepley       ierr = PetscFree(b->values);CHKERRQ(ierr);
33945480ffeSMatthew G. Knepley       ierr = PetscMalloc1(len, &b->values);CHKERRQ(ierr);
34045480ffeSMatthew G. Knepley       ierr = PetscArraycpy(b->values, ids, len);CHKERRQ(ierr);
34145480ffeSMatthew G. Knepley       ierr = PetscWeakFormRewriteKeys(b->wf, b->label, len, b->values);CHKERRQ(ierr);
342f1fd5e65SToby Isaac     }
343e7b0402cSSander Arens     len = 1024;
344f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
345f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
346f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
347f1fd5e65SToby Isaac     if (flg) {
34845480ffeSMatthew G. Knepley       b->Nc = len;
349f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
350f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
351580bdb30SBarry Smith       ierr = PetscArraycpy(b->comps, ids, len);CHKERRQ(ierr);
352f1fd5e65SToby Isaac     }
353f1fd5e65SToby Isaac   }
3542764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
3552764a2aaSMatthew G. Knepley   if (flg) {
3562764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
3572764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
3582764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
3592764a2aaSMatthew G. Knepley   }
36055c1f793SMatthew G. Knepley   ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr);
3612764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
3622764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
3630633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
3642764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
3655d160056SMatthew G. Knepley   if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);}
3662764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3672764a2aaSMatthew G. Knepley }
3682764a2aaSMatthew G. Knepley 
3692764a2aaSMatthew G. Knepley /*@C
3702764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
3712764a2aaSMatthew G. Knepley 
372d083f849SBarry Smith   Collective on prob
3732764a2aaSMatthew G. Knepley 
3742764a2aaSMatthew G. Knepley   Input Parameter:
3752764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
3762764a2aaSMatthew G. Knepley 
3772764a2aaSMatthew G. Knepley   Level: developer
3782764a2aaSMatthew G. Knepley 
3792764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
3802764a2aaSMatthew G. Knepley @*/
3812764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
3822764a2aaSMatthew G. Knepley {
3832764a2aaSMatthew G. Knepley   const PetscInt Nf   = prob->Nf;
384f9244615SMatthew G. Knepley   PetscBool      hasH = PETSC_FALSE;
3854bee2e38SMatthew G. Knepley   PetscInt       dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f;
3862764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3872764a2aaSMatthew G. Knepley 
3882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3902764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3912764a2aaSMatthew G. Knepley   /* Calculate sizes */
3922764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
393d1506c7cSMatthew G. Knepley   ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr);
394f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
39547e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
396f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
397ef0bb6c7SMatthew G. Knepley   ierr = PetscMalloc2(Nf,&prob->T,Nf,&prob->Tf);CHKERRQ(ierr);
3982764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3999de99aefSMatthew G. Knepley     PetscObject     obj;
4009de99aefSMatthew G. Knepley     PetscClassId    id;
401665f567fSMatthew G. Knepley     PetscQuadrature q = NULL;
4029de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
4032764a2aaSMatthew G. Knepley 
4049de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
405f9244615SMatthew G. Knepley     if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE;
406665f567fSMatthew G. Knepley     if (!obj) {
407665f567fSMatthew G. Knepley       /* Empty mesh */
408665f567fSMatthew G. Knepley       Nb = Nc = 0;
409665f567fSMatthew G. Knepley       prob->T[f] = prob->Tf[f] = NULL;
410665f567fSMatthew G. Knepley     } else {
4119de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
4129de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {
4139de99aefSMatthew G. Knepley         PetscFE fe = (PetscFE) obj;
4149de99aefSMatthew G. Knepley 
4152764a2aaSMatthew G. Knepley         ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
4162764a2aaSMatthew G. Knepley         ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
4172764a2aaSMatthew G. Knepley         ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
418f9244615SMatthew G. Knepley         ierr = PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f]);CHKERRQ(ierr);
419f9244615SMatthew G. Knepley         ierr = PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f]);CHKERRQ(ierr);
4209de99aefSMatthew G. Knepley       } else if (id == PETSCFV_CLASSID) {
4219de99aefSMatthew G. Knepley         PetscFV fv = (PetscFV) obj;
4229de99aefSMatthew G. Knepley 
4239de99aefSMatthew G. Knepley         ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
4249de99aefSMatthew G. Knepley         ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
4259c3cf19fSMatthew G. Knepley         Nb   = Nc;
426ef0bb6c7SMatthew G. Knepley         ierr = PetscFVGetCellTabulation(fv, &prob->T[f]);CHKERRQ(ierr);
4274d0b9603SSander Arens         /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
428abac5ca0SMatthew G. Knepley       } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
429665f567fSMatthew G. Knepley     }
43047e57110SSander Arens     prob->Nc[f]       = Nc;
43147e57110SSander Arens     prob->Nb[f]       = Nb;
432194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
433194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
434a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
4352764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
4364bee2e38SMatthew G. Knepley     NbMax          = PetscMax(NbMax, Nb);
4372764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
4389c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
4392764a2aaSMatthew G. Knepley     prob->totComp += Nc;
44094a5e212SMatthew G. Knepley     /* There are two faces for all fields but the cohesive field on a hybrid cell */
44194a5e212SMatthew G. Knepley     if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb;
4422764a2aaSMatthew G. Knepley   }
4432764a2aaSMatthew G. Knepley   /* Allocate works space */
44494a5e212SMatthew G. Knepley   if (prob->isHybrid) NsMax = 2;
445f9244615SMatthew 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);
4464bee2e38SMatthew 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);
44727f02ce8SMatthew G. Knepley   ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dimEmbed,&prob->f1,
44827f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g1,
44927f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed*dimEmbed,&prob->g3);CHKERRQ(ierr);
4502764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
4512764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
4522764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4532764a2aaSMatthew G. Knepley }
4542764a2aaSMatthew G. Knepley 
4552764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
4562764a2aaSMatthew G. Knepley {
4572764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4582764a2aaSMatthew G. Knepley 
4592764a2aaSMatthew G. Knepley   PetscFunctionBegin;
46047e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
461f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
462ef0bb6c7SMatthew G. Knepley   ierr = PetscFree2(prob->T,prob->Tf);CHKERRQ(ierr);
4634bee2e38SMatthew G. Knepley   ierr = PetscFree3(prob->u,prob->u_t,prob->u_x);CHKERRQ(ierr);
4644bee2e38SMatthew G. Knepley   ierr = PetscFree5(prob->x,prob->basisReal, prob->basisDerReal,prob->testReal,prob->testDerReal);CHKERRQ(ierr);
4652764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
4662764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4672764a2aaSMatthew G. Knepley }
4682764a2aaSMatthew G. Knepley 
4692764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
4702764a2aaSMatthew G. Knepley {
471f744cafaSSander Arens   PetscObject      *tmpd;
47234aa8a36SMatthew G. Knepley   PetscBool        *tmpi;
473f9244615SMatthew G. Knepley   PetscInt         *tmpk;
4746528b96dSMatthew G. Knepley   PetscPointFunc   *tmpup;
475f2cacb80SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol,  *tmpexactSol_t;
476f2cacb80SMatthew G. Knepley   void                **tmpexactCtx, **tmpexactCtx_t;
4770c2f2876SMatthew G. Knepley   void            **tmpctx;
47834aa8a36SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f;
4792764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
4802764a2aaSMatthew G. Knepley 
4812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4822764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
4832764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
4842764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
485f9244615SMatthew G. Knepley   ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpk);CHKERRQ(ierr);
486f9244615SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; tmpk[f] = prob->jetDegree[f];}
487f9244615SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpk[f] = 1;}
488f9244615SMatthew G. Knepley   ierr = PetscFree3(prob->disc, prob->implicit, prob->jetDegree);CHKERRQ(ierr);
4896528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(prob->wf, NfNew);CHKERRQ(ierr);
4902764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
4912764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
492249df284SMatthew G. Knepley   prob->implicit  = tmpi;
493f9244615SMatthew G. Knepley   prob->jetDegree = tmpk;
4946528b96dSMatthew G. Knepley   ierr = PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx);CHKERRQ(ierr);
49532d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
4960c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
49732d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
4980c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
4996528b96dSMatthew G. Knepley   ierr = PetscFree2(prob->update, prob->ctx);CHKERRQ(ierr);
50032d2bbc9SMatthew G. Knepley   prob->update = tmpup;
5010c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
5026528b96dSMatthew G. Knepley   ierr = PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t);CHKERRQ(ierr);
503c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
50495cbbfd3SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f];
505f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f];
506f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f];
507c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
50895cbbfd3SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL;
509f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL;
510f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL;
5116528b96dSMatthew G. Knepley   ierr = PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t);CHKERRQ(ierr);
512c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
51395cbbfd3SMatthew G. Knepley   prob->exactCtx = tmpexactCtx;
514f2cacb80SMatthew G. Knepley   prob->exactSol_t = tmpexactSol_t;
515f2cacb80SMatthew G. Knepley   prob->exactCtx_t = tmpexactCtx_t;
5162764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5172764a2aaSMatthew G. Knepley }
5182764a2aaSMatthew G. Knepley 
5192764a2aaSMatthew G. Knepley /*@
5202764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
5212764a2aaSMatthew G. Knepley 
522d083f849SBarry Smith   Collective on prob
5232764a2aaSMatthew G. Knepley 
5242764a2aaSMatthew G. Knepley   Input Parameter:
5252764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
5262764a2aaSMatthew G. Knepley 
5272764a2aaSMatthew G. Knepley   Level: developer
5282764a2aaSMatthew G. Knepley 
5292764a2aaSMatthew G. Knepley .seealso PetscDSView()
5302764a2aaSMatthew G. Knepley @*/
5316528b96dSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *ds)
5322764a2aaSMatthew G. Knepley {
5332764a2aaSMatthew G. Knepley   PetscInt       f;
5342764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5352764a2aaSMatthew G. Knepley 
5362764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5376528b96dSMatthew G. Knepley   if (!*ds) PetscFunctionReturn(0);
5386528b96dSMatthew G. Knepley   PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1);
5392764a2aaSMatthew G. Knepley 
5406528b96dSMatthew G. Knepley   if (--((PetscObject)(*ds))->refct > 0) {*ds = NULL; PetscFunctionReturn(0);}
5416528b96dSMatthew G. Knepley   ((PetscObject) (*ds))->refct = 0;
5426528b96dSMatthew G. Knepley   if ((*ds)->subprobs) {
543df3a45bdSMatthew G. Knepley     PetscInt dim, d;
544df3a45bdSMatthew G. Knepley 
5456528b96dSMatthew G. Knepley     ierr = PetscDSGetSpatialDimension(*ds, &dim);CHKERRQ(ierr);
5466528b96dSMatthew G. Knepley     for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*ds)->subprobs[d]);CHKERRQ(ierr);}
547df3a45bdSMatthew G. Knepley   }
5486528b96dSMatthew G. Knepley   ierr = PetscFree((*ds)->subprobs);CHKERRQ(ierr);
5496528b96dSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*ds);CHKERRQ(ierr);
5506528b96dSMatthew G. Knepley   for (f = 0; f < (*ds)->Nf; ++f) {
5516528b96dSMatthew G. Knepley     ierr = PetscObjectDereference((*ds)->disc[f]);CHKERRQ(ierr);
5522764a2aaSMatthew G. Knepley   }
5536528b96dSMatthew G. Knepley   ierr = PetscFree3((*ds)->disc, (*ds)->implicit, (*ds)->jetDegree);CHKERRQ(ierr);
5546528b96dSMatthew G. Knepley   ierr = PetscWeakFormDestroy(&(*ds)->wf);CHKERRQ(ierr);
5556528b96dSMatthew G. Knepley   ierr = PetscFree2((*ds)->update,(*ds)->ctx);CHKERRQ(ierr);
5566528b96dSMatthew G. Knepley   ierr = PetscFree4((*ds)->exactSol,(*ds)->exactCtx,(*ds)->exactSol_t,(*ds)->exactCtx_t);CHKERRQ(ierr);
5576528b96dSMatthew G. Knepley   if ((*ds)->ops->destroy) {ierr = (*(*ds)->ops->destroy)(*ds);CHKERRQ(ierr);}
55845480ffeSMatthew G. Knepley   ierr = PetscDSDestroyBoundary(*ds);CHKERRQ(ierr);
5596528b96dSMatthew G. Knepley   ierr = PetscFree((*ds)->constants);CHKERRQ(ierr);
5606528b96dSMatthew G. Knepley   ierr = PetscHeaderDestroy(ds);CHKERRQ(ierr);
5612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5622764a2aaSMatthew G. Knepley }
5632764a2aaSMatthew G. Knepley 
5642764a2aaSMatthew G. Knepley /*@
5652764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
5662764a2aaSMatthew G. Knepley 
567d083f849SBarry Smith   Collective
5682764a2aaSMatthew G. Knepley 
5692764a2aaSMatthew G. Knepley   Input Parameter:
5702764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
5712764a2aaSMatthew G. Knepley 
5722764a2aaSMatthew G. Knepley   Output Parameter:
5736528b96dSMatthew G. Knepley . ds   - The PetscDS object
5742764a2aaSMatthew G. Knepley 
5752764a2aaSMatthew G. Knepley   Level: beginner
5762764a2aaSMatthew G. Knepley 
5772764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
5782764a2aaSMatthew G. Knepley @*/
5796528b96dSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds)
5802764a2aaSMatthew G. Knepley {
5812764a2aaSMatthew G. Knepley   PetscDS        p;
5822764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5832764a2aaSMatthew G. Knepley 
5842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5856528b96dSMatthew G. Knepley   PetscValidPointer(ds, 2);
5866528b96dSMatthew G. Knepley   *ds  = NULL;
5872764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5882764a2aaSMatthew G. Knepley 
58973107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5902764a2aaSMatthew G. Knepley 
5912764a2aaSMatthew G. Knepley   p->Nf           = 0;
5922764a2aaSMatthew G. Knepley   p->setup        = PETSC_FALSE;
59397b6e6e8SMatthew G. Knepley   p->numConstants = 0;
59497b6e6e8SMatthew G. Knepley   p->constants    = NULL;
595a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
59655c1f793SMatthew G. Knepley   p->useJacPre    = PETSC_TRUE;
5976528b96dSMatthew G. Knepley   ierr = PetscWeakFormCreate(comm, &p->wf);CHKERRQ(ierr);
5982764a2aaSMatthew G. Knepley 
5996528b96dSMatthew G. Knepley   *ds = p;
6002764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6012764a2aaSMatthew G. Knepley }
6022764a2aaSMatthew G. Knepley 
603bc4ae4beSMatthew G. Knepley /*@
604bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
605bc4ae4beSMatthew G. Knepley 
606bc4ae4beSMatthew G. Knepley   Not collective
607bc4ae4beSMatthew G. Knepley 
608bc4ae4beSMatthew G. Knepley   Input Parameter:
609bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
610bc4ae4beSMatthew G. Knepley 
611bc4ae4beSMatthew G. Knepley   Output Parameter:
612bc4ae4beSMatthew G. Knepley . Nf - The number of fields
613bc4ae4beSMatthew G. Knepley 
614bc4ae4beSMatthew G. Knepley   Level: beginner
615bc4ae4beSMatthew G. Knepley 
616bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
617bc4ae4beSMatthew G. Knepley @*/
6182764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
6192764a2aaSMatthew G. Knepley {
6202764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6212764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6222764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
6232764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
6242764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6252764a2aaSMatthew G. Knepley }
6262764a2aaSMatthew G. Knepley 
627bc4ae4beSMatthew G. Knepley /*@
628a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
629bc4ae4beSMatthew G. Knepley 
630bc4ae4beSMatthew G. Knepley   Not collective
631bc4ae4beSMatthew G. Knepley 
632bc4ae4beSMatthew G. Knepley   Input Parameter:
633bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
634bc4ae4beSMatthew G. Knepley 
635bc4ae4beSMatthew G. Knepley   Output Parameter:
636bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
637bc4ae4beSMatthew G. Knepley 
638bc4ae4beSMatthew G. Knepley   Level: beginner
639bc4ae4beSMatthew G. Knepley 
640a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate()
641bc4ae4beSMatthew G. Knepley @*/
6422764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
6432764a2aaSMatthew G. Knepley {
6442764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6452764a2aaSMatthew G. Knepley 
6462764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6472764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6482764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6492764a2aaSMatthew G. Knepley   *dim = 0;
6509de99aefSMatthew G. Knepley   if (prob->Nf) {
6519de99aefSMatthew G. Knepley     PetscObject  obj;
6529de99aefSMatthew G. Knepley     PetscClassId id;
6539de99aefSMatthew G. Knepley 
6549de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
655665f567fSMatthew G. Knepley     if (obj) {
6569de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
6579de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
6589de99aefSMatthew G. Knepley       else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
6599de99aefSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
6609de99aefSMatthew G. Knepley     }
661665f567fSMatthew G. Knepley   }
6622764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6632764a2aaSMatthew G. Knepley }
6642764a2aaSMatthew G. Knepley 
665bc4ae4beSMatthew G. Knepley /*@
666a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
667a859676bSMatthew G. Knepley 
668a859676bSMatthew G. Knepley   Not collective
669a859676bSMatthew G. Knepley 
670a859676bSMatthew G. Knepley   Input Parameter:
671a859676bSMatthew G. Knepley . prob - The PetscDS object
672a859676bSMatthew G. Knepley 
673a859676bSMatthew G. Knepley   Output Parameter:
674a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
675a859676bSMatthew G. Knepley 
676a859676bSMatthew G. Knepley   Level: beginner
677a859676bSMatthew G. Knepley 
678a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
679a859676bSMatthew G. Knepley @*/
680a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
681a859676bSMatthew G. Knepley {
682a859676bSMatthew G. Knepley   PetscFunctionBegin;
683a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
684a859676bSMatthew G. Knepley   PetscValidPointer(dimEmbed, 2);
685a859676bSMatthew G. Knepley   if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
686a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
687a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
688a859676bSMatthew G. Knepley }
689a859676bSMatthew G. Knepley 
690a859676bSMatthew G. Knepley /*@
691a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
692a859676bSMatthew G. Knepley 
693d083f849SBarry Smith   Logically collective on prob
694a859676bSMatthew G. Knepley 
695a859676bSMatthew G. Knepley   Input Parameters:
696a859676bSMatthew G. Knepley + prob - The PetscDS object
697a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
698a859676bSMatthew G. Knepley 
699a859676bSMatthew G. Knepley   Level: beginner
700a859676bSMatthew G. Knepley 
701a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
702a859676bSMatthew G. Knepley @*/
703a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
704a859676bSMatthew G. Knepley {
705a859676bSMatthew G. Knepley   PetscFunctionBegin;
706a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
707ebfe4b0dSMatthew G. Knepley   if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed);
708a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
709a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
710a859676bSMatthew G. Knepley }
711a859676bSMatthew G. Knepley 
712a859676bSMatthew G. Knepley /*@
7138edf6225SMatthew G. Knepley   PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell
7148edf6225SMatthew G. Knepley 
7158edf6225SMatthew G. Knepley   Not collective
7168edf6225SMatthew G. Knepley 
7178edf6225SMatthew G. Knepley   Input Parameter:
7188edf6225SMatthew G. Knepley . prob - The PetscDS object
7198edf6225SMatthew G. Knepley 
7208edf6225SMatthew G. Knepley   Output Parameter:
7218edf6225SMatthew G. Knepley . isHybrid - The flag
7228edf6225SMatthew G. Knepley 
7238edf6225SMatthew G. Knepley   Level: developer
7248edf6225SMatthew G. Knepley 
7258edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate()
7268edf6225SMatthew G. Knepley @*/
7278edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid)
7288edf6225SMatthew G. Knepley {
7298edf6225SMatthew G. Knepley   PetscFunctionBegin;
7308edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7318edf6225SMatthew G. Knepley   PetscValidPointer(isHybrid, 2);
7328edf6225SMatthew G. Knepley   *isHybrid = prob->isHybrid;
7338edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7348edf6225SMatthew G. Knepley }
7358edf6225SMatthew G. Knepley 
7368edf6225SMatthew G. Knepley /*@
7378edf6225SMatthew G. Knepley   PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell
7388edf6225SMatthew G. Knepley 
7398edf6225SMatthew G. Knepley   Not collective
7408edf6225SMatthew G. Knepley 
7418edf6225SMatthew G. Knepley   Input Parameters:
7428edf6225SMatthew G. Knepley + prob - The PetscDS object
7438edf6225SMatthew G. Knepley - isHybrid - The flag
7448edf6225SMatthew G. Knepley 
7458edf6225SMatthew G. Knepley   Level: developer
7468edf6225SMatthew G. Knepley 
7478edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate()
7488edf6225SMatthew G. Knepley @*/
7498edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid)
7508edf6225SMatthew G. Knepley {
7518edf6225SMatthew G. Knepley   PetscFunctionBegin;
7528edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7538edf6225SMatthew G. Knepley   prob->isHybrid = isHybrid;
7548edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7558edf6225SMatthew G. Knepley }
7568edf6225SMatthew G. Knepley 
7578edf6225SMatthew G. Knepley /*@
758bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
759bc4ae4beSMatthew G. Knepley 
760bc4ae4beSMatthew G. Knepley   Not collective
761bc4ae4beSMatthew G. Knepley 
762bc4ae4beSMatthew G. Knepley   Input Parameter:
763bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
764bc4ae4beSMatthew G. Knepley 
765bc4ae4beSMatthew G. Knepley   Output Parameter:
766bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
767bc4ae4beSMatthew G. Knepley 
768bc4ae4beSMatthew G. Knepley   Level: beginner
769bc4ae4beSMatthew G. Knepley 
770bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
771bc4ae4beSMatthew G. Knepley @*/
7722764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
7732764a2aaSMatthew G. Knepley {
7742764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7752764a2aaSMatthew G. Knepley 
7762764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7772764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7782764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
7792764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
7802764a2aaSMatthew G. Knepley   *dim = prob->totDim;
7812764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7822764a2aaSMatthew G. Knepley }
7832764a2aaSMatthew G. Knepley 
784bc4ae4beSMatthew G. Knepley /*@
785bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
786bc4ae4beSMatthew G. Knepley 
787bc4ae4beSMatthew G. Knepley   Not collective
788bc4ae4beSMatthew G. Knepley 
789bc4ae4beSMatthew G. Knepley   Input Parameter:
790bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
791bc4ae4beSMatthew G. Knepley 
792bc4ae4beSMatthew G. Knepley   Output Parameter:
793bc4ae4beSMatthew G. Knepley . dim - The total number of components
794bc4ae4beSMatthew G. Knepley 
795bc4ae4beSMatthew G. Knepley   Level: beginner
796bc4ae4beSMatthew G. Knepley 
797bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
798bc4ae4beSMatthew G. Knepley @*/
7992764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
8002764a2aaSMatthew G. Knepley {
8012764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8022764a2aaSMatthew G. Knepley 
8032764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8042764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8052764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
8062764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
8072764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
8082764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8092764a2aaSMatthew G. Knepley }
8102764a2aaSMatthew G. Knepley 
811bc4ae4beSMatthew G. Knepley /*@
812bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
813bc4ae4beSMatthew G. Knepley 
814bc4ae4beSMatthew G. Knepley   Not collective
815bc4ae4beSMatthew G. Knepley 
816bc4ae4beSMatthew G. Knepley   Input Parameters:
817bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
818bc4ae4beSMatthew G. Knepley - f - The field number
819bc4ae4beSMatthew G. Knepley 
820bc4ae4beSMatthew G. Knepley   Output Parameter:
821bc4ae4beSMatthew G. Knepley . disc - The discretization object
822bc4ae4beSMatthew G. Knepley 
823bc4ae4beSMatthew G. Knepley   Level: beginner
824bc4ae4beSMatthew G. Knepley 
825f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
826bc4ae4beSMatthew G. Knepley @*/
8272764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
8282764a2aaSMatthew G. Knepley {
8296528b96dSMatthew G. Knepley   PetscFunctionBeginHot;
8302764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8312764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
8322764a2aaSMatthew 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);
8332764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
8342764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8352764a2aaSMatthew G. Knepley }
8362764a2aaSMatthew G. Knepley 
837bc4ae4beSMatthew G. Knepley /*@
838bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
839bc4ae4beSMatthew G. Knepley 
840bc4ae4beSMatthew G. Knepley   Not collective
841bc4ae4beSMatthew G. Knepley 
842bc4ae4beSMatthew G. Knepley   Input Parameters:
843bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
844bc4ae4beSMatthew G. Knepley . f - The field number
845bc4ae4beSMatthew G. Knepley - disc - The discretization object
846bc4ae4beSMatthew G. Knepley 
847bc4ae4beSMatthew G. Knepley   Level: beginner
848bc4ae4beSMatthew G. Knepley 
849bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
850bc4ae4beSMatthew G. Knepley @*/
8512764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
8522764a2aaSMatthew G. Knepley {
8532764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8542764a2aaSMatthew G. Knepley 
8552764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8562764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
857665f567fSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
8582764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
8592764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
860c10f2116SMatthew G. Knepley   ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);
8612764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
8622764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
863665f567fSMatthew G. Knepley   if (disc) {
864249df284SMatthew G. Knepley     PetscClassId id;
865249df284SMatthew G. Knepley 
866249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
8671cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
8681cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr);
8691cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
8701cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr);
871a6cbbb48SMatthew G. Knepley     }
872f9244615SMatthew G. Knepley     ierr = PetscDSSetJetDegree(prob, f, 1);CHKERRQ(ierr);
873249df284SMatthew G. Knepley   }
8742764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8752764a2aaSMatthew G. Knepley }
8762764a2aaSMatthew G. Knepley 
877bc4ae4beSMatthew G. Knepley /*@
8786528b96dSMatthew G. Knepley   PetscDSGetWeakForm - Returns the weak form object
8796528b96dSMatthew G. Knepley 
8806528b96dSMatthew G. Knepley   Not collective
8816528b96dSMatthew G. Knepley 
8826528b96dSMatthew G. Knepley   Input Parameter:
8836528b96dSMatthew G. Knepley . ds - The PetscDS object
8846528b96dSMatthew G. Knepley 
8856528b96dSMatthew G. Knepley   Output Parameter:
8866528b96dSMatthew G. Knepley . wf - The weak form object
8876528b96dSMatthew G. Knepley 
8886528b96dSMatthew G. Knepley   Level: beginner
8896528b96dSMatthew G. Knepley 
8906528b96dSMatthew G. Knepley .seealso: PetscDSSetWeakForm(), PetscDSGetNumFields(), PetscDSCreate()
8916528b96dSMatthew G. Knepley @*/
8926528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf)
8936528b96dSMatthew G. Knepley {
8946528b96dSMatthew G. Knepley   PetscFunctionBegin;
8956528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
8966528b96dSMatthew G. Knepley   PetscValidPointer(wf, 2);
8976528b96dSMatthew G. Knepley   *wf = ds->wf;
8986528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
8996528b96dSMatthew G. Knepley }
9006528b96dSMatthew G. Knepley 
9016528b96dSMatthew G. Knepley /*@
9026528b96dSMatthew G. Knepley   PetscDSSetWeakForm - Sets the weak form object
9036528b96dSMatthew G. Knepley 
9046528b96dSMatthew G. Knepley   Not collective
9056528b96dSMatthew G. Knepley 
9066528b96dSMatthew G. Knepley   Input Parameters:
9076528b96dSMatthew G. Knepley + ds - The PetscDS object
9086528b96dSMatthew G. Knepley - wf - The weak form object
9096528b96dSMatthew G. Knepley 
9106528b96dSMatthew G. Knepley   Level: beginner
9116528b96dSMatthew G. Knepley 
9126528b96dSMatthew G. Knepley .seealso: PetscDSGetWeakForm(), PetscDSGetNumFields(), PetscDSCreate()
9136528b96dSMatthew G. Knepley @*/
9146528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf)
9156528b96dSMatthew G. Knepley {
9166528b96dSMatthew G. Knepley   PetscErrorCode ierr;
9176528b96dSMatthew G. Knepley 
9186528b96dSMatthew G. Knepley   PetscFunctionBegin;
9196528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
9206528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2);
9216528b96dSMatthew G. Knepley   ierr = PetscObjectDereference((PetscObject) ds->wf);CHKERRQ(ierr);
9226528b96dSMatthew G. Knepley   ds->wf = wf;
9236528b96dSMatthew G. Knepley   ierr = PetscObjectReference((PetscObject) wf);CHKERRQ(ierr);
9246528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(wf, ds->Nf);CHKERRQ(ierr);
9256528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9266528b96dSMatthew G. Knepley }
9276528b96dSMatthew G. Knepley 
9286528b96dSMatthew G. Knepley /*@
929bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
930bc4ae4beSMatthew G. Knepley 
931bc4ae4beSMatthew G. Knepley   Not collective
932bc4ae4beSMatthew G. Knepley 
933bc4ae4beSMatthew G. Knepley   Input Parameters:
934bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
935bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
936bc4ae4beSMatthew G. Knepley 
937bc4ae4beSMatthew G. Knepley   Level: beginner
938bc4ae4beSMatthew G. Knepley 
939bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
940bc4ae4beSMatthew G. Knepley @*/
9412764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
9422764a2aaSMatthew G. Knepley {
9432764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9442764a2aaSMatthew G. Knepley 
9452764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9462764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
9472764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9482764a2aaSMatthew G. Knepley }
9492764a2aaSMatthew G. Knepley 
950249df284SMatthew G. Knepley /*@
951083401c6SMatthew G. Knepley   PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS
952083401c6SMatthew G. Knepley 
953083401c6SMatthew G. Knepley   Not collective
954083401c6SMatthew G. Knepley 
955083401c6SMatthew G. Knepley   Input Parameter:
956083401c6SMatthew G. Knepley . prob - The PetscDS object
957083401c6SMatthew G. Knepley 
958083401c6SMatthew G. Knepley   Output Parameter:
959083401c6SMatthew G. Knepley . q - The quadrature object
960083401c6SMatthew G. Knepley 
961083401c6SMatthew G. Knepley Level: intermediate
962083401c6SMatthew G. Knepley 
963083401c6SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
964083401c6SMatthew G. Knepley @*/
965083401c6SMatthew G. Knepley PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q)
966083401c6SMatthew G. Knepley {
967083401c6SMatthew G. Knepley   PetscObject    obj;
968083401c6SMatthew G. Knepley   PetscClassId   id;
969083401c6SMatthew G. Knepley   PetscErrorCode ierr;
970083401c6SMatthew G. Knepley 
971083401c6SMatthew G. Knepley   PetscFunctionBegin;
972083401c6SMatthew G. Knepley   *q = NULL;
973083401c6SMatthew G. Knepley   if (!prob->Nf) PetscFunctionReturn(0);
974083401c6SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
975083401c6SMatthew G. Knepley   ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
976083401c6SMatthew G. Knepley   if      (id == PETSCFE_CLASSID) {ierr = PetscFEGetQuadrature((PetscFE) obj, q);CHKERRQ(ierr);}
977083401c6SMatthew G. Knepley   else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetQuadrature((PetscFV) obj, q);CHKERRQ(ierr);}
978083401c6SMatthew G. Knepley   else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
979083401c6SMatthew G. Knepley   PetscFunctionReturn(0);
980083401c6SMatthew G. Knepley }
981083401c6SMatthew G. Knepley 
982083401c6SMatthew G. Knepley /*@
983249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
984249df284SMatthew G. Knepley 
985249df284SMatthew G. Knepley   Not collective
986249df284SMatthew G. Knepley 
987249df284SMatthew G. Knepley   Input Parameters:
988249df284SMatthew G. Knepley + prob - The PetscDS object
989249df284SMatthew G. Knepley - f - The field number
990249df284SMatthew G. Knepley 
991249df284SMatthew G. Knepley   Output Parameter:
992249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
993249df284SMatthew G. Knepley 
994249df284SMatthew G. Knepley   Level: developer
995249df284SMatthew G. Knepley 
996f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
997249df284SMatthew G. Knepley @*/
998249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
999249df284SMatthew G. Knepley {
1000249df284SMatthew G. Knepley   PetscFunctionBegin;
1001249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1002249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
1003249df284SMatthew 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);
1004249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
1005249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1006249df284SMatthew G. Knepley }
1007249df284SMatthew G. Knepley 
1008249df284SMatthew G. Knepley /*@
1009249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
1010249df284SMatthew G. Knepley 
1011249df284SMatthew G. Knepley   Not collective
1012249df284SMatthew G. Knepley 
1013249df284SMatthew G. Knepley   Input Parameters:
1014249df284SMatthew G. Knepley + prob - The PetscDS object
1015249df284SMatthew G. Knepley . f - The field number
1016249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
1017249df284SMatthew G. Knepley 
1018249df284SMatthew G. Knepley   Level: developer
1019249df284SMatthew G. Knepley 
1020f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1021249df284SMatthew G. Knepley @*/
1022249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
1023249df284SMatthew G. Knepley {
1024249df284SMatthew G. Knepley   PetscFunctionBegin;
1025249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1026249df284SMatthew 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);
1027249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
1028249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1029249df284SMatthew G. Knepley }
1030249df284SMatthew G. Knepley 
1031f9244615SMatthew G. Knepley /*@
1032f9244615SMatthew G. Knepley   PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1033f9244615SMatthew G. Knepley 
1034f9244615SMatthew G. Knepley   Not collective
1035f9244615SMatthew G. Knepley 
1036f9244615SMatthew G. Knepley   Input Parameters:
1037f9244615SMatthew G. Knepley + ds - The PetscDS object
1038f9244615SMatthew G. Knepley - f  - The field number
1039f9244615SMatthew G. Knepley 
1040f9244615SMatthew G. Knepley   Output Parameter:
1041f9244615SMatthew G. Knepley . k  - The highest derivative we need to tabulate
1042f9244615SMatthew G. Knepley 
1043f9244615SMatthew G. Knepley   Level: developer
1044f9244615SMatthew G. Knepley 
1045f9244615SMatthew G. Knepley .seealso: PetscDSSetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1046f9244615SMatthew G. Knepley @*/
1047f9244615SMatthew G. Knepley PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k)
1048f9244615SMatthew G. Knepley {
1049f9244615SMatthew G. Knepley   PetscFunctionBegin;
1050f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1051f9244615SMatthew G. Knepley   PetscValidPointer(k, 3);
1052f9244615SMatthew 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);
1053f9244615SMatthew G. Knepley   *k = ds->jetDegree[f];
1054f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1055f9244615SMatthew G. Knepley }
1056f9244615SMatthew G. Knepley 
1057f9244615SMatthew G. Knepley /*@
1058f9244615SMatthew G. Knepley   PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1059f9244615SMatthew G. Knepley 
1060f9244615SMatthew G. Knepley   Not collective
1061f9244615SMatthew G. Knepley 
1062f9244615SMatthew G. Knepley   Input Parameters:
1063f9244615SMatthew G. Knepley + ds - The PetscDS object
1064f9244615SMatthew G. Knepley . f  - The field number
1065f9244615SMatthew G. Knepley - k  - The highest derivative we need to tabulate
1066f9244615SMatthew G. Knepley 
1067f9244615SMatthew G. Knepley   Level: developer
1068f9244615SMatthew G. Knepley 
1069f9244615SMatthew G. Knepley .seealso: PetscDSGetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1070f9244615SMatthew G. Knepley @*/
1071f9244615SMatthew G. Knepley PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k)
1072f9244615SMatthew G. Knepley {
1073f9244615SMatthew G. Knepley   PetscFunctionBegin;
1074f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1075f9244615SMatthew 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);
1076f9244615SMatthew G. Knepley   ds->jetDegree[f] = k;
1077f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1078f9244615SMatthew G. Knepley }
1079f9244615SMatthew G. Knepley 
10806528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS ds, PetscInt f,
108130b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1082194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1083194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
108497b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
10852764a2aaSMatthew G. Knepley {
10866528b96dSMatthew G. Knepley   PetscPointFunc *tmp;
10876528b96dSMatthew G. Knepley   PetscInt        n;
10886528b96dSMatthew G. Knepley   PetscErrorCode  ierr;
10896528b96dSMatthew G. Knepley 
10902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10916528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
10926528b96dSMatthew G. Knepley   PetscValidPointer(obj, 3);
10936528b96dSMatthew 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);
10946528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetObjective(ds->wf, NULL, 0, f, &n, &tmp);CHKERRQ(ierr);
10956528b96dSMatthew G. Knepley   *obj = tmp ? tmp[0] : NULL;
10962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10972764a2aaSMatthew G. Knepley }
10982764a2aaSMatthew G. Knepley 
10996528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS ds, PetscInt f,
110030b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1101194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1102194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
110397b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
11042764a2aaSMatthew G. Knepley {
11052764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
11062764a2aaSMatthew G. Knepley 
11072764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11086528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11096528b96dSMatthew G. Knepley   if (obj) PetscValidFunction(obj, 3);
11102764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
11116528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, obj);CHKERRQ(ierr);
11122764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11132764a2aaSMatthew G. Knepley }
11142764a2aaSMatthew G. Knepley 
1115194d53e6SMatthew G. Knepley /*@C
1116194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1117194d53e6SMatthew G. Knepley 
1118194d53e6SMatthew G. Knepley   Not collective
1119194d53e6SMatthew G. Knepley 
1120194d53e6SMatthew G. Knepley   Input Parameters:
11216528b96dSMatthew G. Knepley + ds - The PetscDS
1122194d53e6SMatthew G. Knepley - f  - The test field number
1123194d53e6SMatthew G. Knepley 
1124194d53e6SMatthew G. Knepley   Output Parameters:
1125194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1126194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1127194d53e6SMatthew G. Knepley 
1128194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1129194d53e6SMatthew G. Knepley 
1130194d53e6SMatthew 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)
1131194d53e6SMatthew G. Knepley 
1132194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1133194d53e6SMatthew G. Knepley 
113430b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1135194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1136194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
113730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1138194d53e6SMatthew G. Knepley 
1139194d53e6SMatthew G. Knepley + dim - the spatial dimension
1140194d53e6SMatthew G. Knepley . Nf - the number of fields
1141194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1142194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1143194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1144194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1145194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1146194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1147194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1148194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1149194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1150194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1151194d53e6SMatthew G. Knepley . t - current time
1152194d53e6SMatthew G. Knepley . x - coordinates of the current point
115397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
115497b6e6e8SMatthew G. Knepley . constants - constant parameters
1155194d53e6SMatthew G. Knepley - f0 - output values at the current point
1156194d53e6SMatthew G. Knepley 
1157194d53e6SMatthew G. Knepley   Level: intermediate
1158194d53e6SMatthew G. Knepley 
1159194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
1160194d53e6SMatthew G. Knepley @*/
11616528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS ds, PetscInt f,
116230b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1163194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1164194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
116597b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
116630b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1167194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1168194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
116997b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
11702764a2aaSMatthew G. Knepley {
11716528b96dSMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
11726528b96dSMatthew G. Knepley   PetscInt        n0, n1;
11736528b96dSMatthew G. Knepley   PetscErrorCode  ierr;
11746528b96dSMatthew G. Knepley 
11752764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11766528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11776528b96dSMatthew 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);
11786528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetResidual(ds->wf, NULL, 0, f, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
11796528b96dSMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
11806528b96dSMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
11812764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11822764a2aaSMatthew G. Knepley }
11832764a2aaSMatthew G. Knepley 
1184194d53e6SMatthew G. Knepley /*@C
1185194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1186194d53e6SMatthew G. Knepley 
1187194d53e6SMatthew G. Knepley   Not collective
1188194d53e6SMatthew G. Knepley 
1189194d53e6SMatthew G. Knepley   Input Parameters:
11906528b96dSMatthew G. Knepley + ds - The PetscDS
1191194d53e6SMatthew G. Knepley . f  - The test field number
1192194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1193194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1194194d53e6SMatthew G. Knepley 
1195194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1196194d53e6SMatthew G. Knepley 
1197194d53e6SMatthew 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)
1198194d53e6SMatthew G. Knepley 
1199194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1200194d53e6SMatthew G. Knepley 
120130b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1202194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1203194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
120430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1205194d53e6SMatthew G. Knepley 
1206194d53e6SMatthew G. Knepley + dim - the spatial dimension
1207194d53e6SMatthew G. Knepley . Nf - the number of fields
1208194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1209194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1210194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1211194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1212194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1213194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1214194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1215194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1216194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1217194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1218194d53e6SMatthew G. Knepley . t - current time
1219194d53e6SMatthew G. Knepley . x - coordinates of the current point
122097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
122197b6e6e8SMatthew G. Knepley . constants - constant parameters
1222194d53e6SMatthew G. Knepley - f0 - output values at the current point
1223194d53e6SMatthew G. Knepley 
1224194d53e6SMatthew G. Knepley   Level: intermediate
1225194d53e6SMatthew G. Knepley 
1226194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1227194d53e6SMatthew G. Knepley @*/
12286528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS ds, PetscInt f,
122930b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1230194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1231194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123297b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
123330b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1234194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1235194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123697b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
12372764a2aaSMatthew G. Knepley {
12382764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
12392764a2aaSMatthew G. Knepley 
12402764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12416528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1242f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1243f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
12442764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
12456528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, f0, 0, f1);CHKERRQ(ierr);
12462764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12472764a2aaSMatthew G. Knepley }
12482764a2aaSMatthew G. Knepley 
12493e75805dSMatthew G. Knepley /*@C
12503e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
12513e75805dSMatthew G. Knepley 
12523e75805dSMatthew G. Knepley   Not collective
12533e75805dSMatthew G. Knepley 
12543e75805dSMatthew G. Knepley   Input Parameter:
12553e75805dSMatthew G. Knepley . prob - The PetscDS
12563e75805dSMatthew G. Knepley 
12573e75805dSMatthew G. Knepley   Output Parameter:
12583e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
12593e75805dSMatthew G. Knepley 
12603e75805dSMatthew G. Knepley   Level: intermediate
12613e75805dSMatthew G. Knepley 
12623e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
12633e75805dSMatthew G. Knepley @*/
12646528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac)
12653e75805dSMatthew G. Knepley {
12666528b96dSMatthew G. Knepley   PetscErrorCode ierr;
12673e75805dSMatthew G. Knepley 
12683e75805dSMatthew G. Knepley   PetscFunctionBegin;
12696528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
12706528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobian(ds->wf, hasJac);CHKERRQ(ierr);
12713e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
12723e75805dSMatthew G. Knepley }
12733e75805dSMatthew G. Knepley 
1274194d53e6SMatthew G. Knepley /*@C
1275194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1276194d53e6SMatthew G. Knepley 
1277194d53e6SMatthew G. Knepley   Not collective
1278194d53e6SMatthew G. Knepley 
1279194d53e6SMatthew G. Knepley   Input Parameters:
12806528b96dSMatthew G. Knepley + ds - The PetscDS
1281194d53e6SMatthew G. Knepley . f  - The test field number
1282194d53e6SMatthew G. Knepley - g  - The field number
1283194d53e6SMatthew G. Knepley 
1284194d53e6SMatthew G. Knepley   Output Parameters:
1285194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1286194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1287194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1288194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1289194d53e6SMatthew G. Knepley 
1290194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1291194d53e6SMatthew G. Knepley 
1292194d53e6SMatthew 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
1293194d53e6SMatthew G. Knepley 
1294194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1295194d53e6SMatthew G. Knepley 
129630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1297194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1298194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
129930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1300194d53e6SMatthew G. Knepley 
1301194d53e6SMatthew G. Knepley + dim - the spatial dimension
1302194d53e6SMatthew G. Knepley . Nf - the number of fields
1303194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1304194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1305194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1306194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1307194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1308194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1309194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1310194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1311194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1312194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1313194d53e6SMatthew G. Knepley . t - current time
13142aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1315194d53e6SMatthew G. Knepley . x - coordinates of the current point
131697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
131797b6e6e8SMatthew G. Knepley . constants - constant parameters
1318194d53e6SMatthew G. Knepley - g0 - output values at the current point
1319194d53e6SMatthew G. Knepley 
1320194d53e6SMatthew G. Knepley   Level: intermediate
1321194d53e6SMatthew G. Knepley 
1322194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1323194d53e6SMatthew G. Knepley @*/
13246528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS ds, PetscInt f, PetscInt g,
132530b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1326194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1327194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
132897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
132930b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1330194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1331194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
133297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
133330b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1334194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1335194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
133697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
133730b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1338194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1339194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
134097b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
13412764a2aaSMatthew G. Knepley {
13426528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
13436528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
13446528b96dSMatthew G. Knepley   PetscErrorCode ierr;
13456528b96dSMatthew G. Knepley 
13462764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13476528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
13486528b96dSMatthew 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);
13496528b96dSMatthew 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);
13506528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
13516528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
13526528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
13536528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
13546528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
13552764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
13562764a2aaSMatthew G. Knepley }
13572764a2aaSMatthew G. Knepley 
1358194d53e6SMatthew G. Knepley /*@C
1359194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1360194d53e6SMatthew G. Knepley 
1361194d53e6SMatthew G. Knepley   Not collective
1362194d53e6SMatthew G. Knepley 
1363194d53e6SMatthew G. Knepley   Input Parameters:
13646528b96dSMatthew G. Knepley + ds - The PetscDS
1365194d53e6SMatthew G. Knepley . f  - The test field number
1366194d53e6SMatthew G. Knepley . g  - The field number
1367194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1368194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1369194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1370194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1371194d53e6SMatthew G. Knepley 
1372194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1373194d53e6SMatthew G. Knepley 
1374194d53e6SMatthew 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
1375194d53e6SMatthew G. Knepley 
1376194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1377194d53e6SMatthew G. Knepley 
137830b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1379194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1380194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
138130b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1382194d53e6SMatthew G. Knepley 
1383194d53e6SMatthew G. Knepley + dim - the spatial dimension
1384194d53e6SMatthew G. Knepley . Nf - the number of fields
1385194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1386194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1387194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1388194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1389194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1390194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1391194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1392194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1393194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1394194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1395194d53e6SMatthew G. Knepley . t - current time
13962aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1397194d53e6SMatthew G. Knepley . x - coordinates of the current point
139897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
139997b6e6e8SMatthew G. Knepley . constants - constant parameters
1400194d53e6SMatthew G. Knepley - g0 - output values at the current point
1401194d53e6SMatthew G. Knepley 
1402194d53e6SMatthew G. Knepley   Level: intermediate
1403194d53e6SMatthew G. Knepley 
1404194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1405194d53e6SMatthew G. Knepley @*/
14066528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS ds, PetscInt f, PetscInt g,
140730b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1408194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1409194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
141097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
141130b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1412194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1413194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
141497b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
141530b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1416194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1417194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
141897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
141930b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1420194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1421194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
142297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
14232764a2aaSMatthew G. Knepley {
14242764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
14252764a2aaSMatthew G. Knepley 
14262764a2aaSMatthew G. Knepley   PetscFunctionBegin;
14276528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
14282764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
14292764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
14302764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
14312764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
14322764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
14332764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
14346528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
14352764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
14362764a2aaSMatthew G. Knepley }
14372764a2aaSMatthew G. Knepley 
1438475e0ac9SMatthew G. Knepley /*@C
143955c1f793SMatthew G. Knepley   PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner
144055c1f793SMatthew G. Knepley 
144155c1f793SMatthew G. Knepley   Not collective
144255c1f793SMatthew G. Knepley 
144355c1f793SMatthew G. Knepley   Input Parameters:
144455c1f793SMatthew G. Knepley + prob - The PetscDS
144555c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
144655c1f793SMatthew G. Knepley 
144755c1f793SMatthew G. Knepley   Level: intermediate
144855c1f793SMatthew G. Knepley 
144955c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
145055c1f793SMatthew G. Knepley @*/
145155c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
145255c1f793SMatthew G. Knepley {
145355c1f793SMatthew G. Knepley   PetscFunctionBegin;
145455c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
145555c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
145655c1f793SMatthew G. Knepley   PetscFunctionReturn(0);
145755c1f793SMatthew G. Knepley }
145855c1f793SMatthew G. Knepley 
145955c1f793SMatthew G. Knepley /*@C
1460475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1461475e0ac9SMatthew G. Knepley 
1462475e0ac9SMatthew G. Knepley   Not collective
1463475e0ac9SMatthew G. Knepley 
1464475e0ac9SMatthew G. Knepley   Input Parameter:
1465475e0ac9SMatthew G. Knepley . prob - The PetscDS
1466475e0ac9SMatthew G. Knepley 
1467475e0ac9SMatthew G. Knepley   Output Parameter:
1468475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1469475e0ac9SMatthew G. Knepley 
1470475e0ac9SMatthew G. Knepley   Level: intermediate
1471475e0ac9SMatthew G. Knepley 
1472475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1473475e0ac9SMatthew G. Knepley @*/
14746528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre)
1475475e0ac9SMatthew G. Knepley {
14766528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1477475e0ac9SMatthew G. Knepley 
1478475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
14796528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1480475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
14816528b96dSMatthew G. Knepley   if (!ds->useJacPre) PetscFunctionReturn(0);
14826528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre);CHKERRQ(ierr);
1483475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1484475e0ac9SMatthew G. Knepley }
1485475e0ac9SMatthew G. Knepley 
1486475e0ac9SMatthew G. Knepley /*@C
1487475e0ac9SMatthew 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.
1488475e0ac9SMatthew G. Knepley 
1489475e0ac9SMatthew G. Knepley   Not collective
1490475e0ac9SMatthew G. Knepley 
1491475e0ac9SMatthew G. Knepley   Input Parameters:
14926528b96dSMatthew G. Knepley + ds - The PetscDS
1493475e0ac9SMatthew G. Knepley . f  - The test field number
1494475e0ac9SMatthew G. Knepley - g  - The field number
1495475e0ac9SMatthew G. Knepley 
1496475e0ac9SMatthew G. Knepley   Output Parameters:
1497475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1498475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1499475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1500475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1501475e0ac9SMatthew G. Knepley 
1502475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1503475e0ac9SMatthew G. Knepley 
1504475e0ac9SMatthew 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
1505475e0ac9SMatthew G. Knepley 
1506475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1507475e0ac9SMatthew G. Knepley 
1508475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1509475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1510475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1511475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1512475e0ac9SMatthew G. Knepley 
1513475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1514475e0ac9SMatthew G. Knepley . Nf - the number of fields
1515475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1516475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1517475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1518475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1519475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1520475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1521475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1522475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1523475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1524475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1525475e0ac9SMatthew G. Knepley . t - current time
1526475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1527475e0ac9SMatthew G. Knepley . x - coordinates of the current point
152897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
152997b6e6e8SMatthew G. Knepley . constants - constant parameters
1530475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1531475e0ac9SMatthew G. Knepley 
1532475e0ac9SMatthew G. Knepley   Level: intermediate
1533475e0ac9SMatthew G. Knepley 
1534475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1535475e0ac9SMatthew G. Knepley @*/
15366528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1537475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1538475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1539475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154097b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1541475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1542475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1543475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1545475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1546475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1547475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1549475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1550475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1551475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
155297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1553475e0ac9SMatthew G. Knepley {
15546528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
15556528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
15566528b96dSMatthew G. Knepley   PetscErrorCode ierr;
15576528b96dSMatthew G. Knepley 
1558475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
15596528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
15606528b96dSMatthew 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);
15616528b96dSMatthew 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);
15626528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
15636528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
15646528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
15656528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
15666528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1567475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1568475e0ac9SMatthew G. Knepley }
1569475e0ac9SMatthew G. Knepley 
1570475e0ac9SMatthew G. Knepley /*@C
1571475e0ac9SMatthew 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.
1572475e0ac9SMatthew G. Knepley 
1573475e0ac9SMatthew G. Knepley   Not collective
1574475e0ac9SMatthew G. Knepley 
1575475e0ac9SMatthew G. Knepley   Input Parameters:
15766528b96dSMatthew G. Knepley + ds - The PetscDS
1577475e0ac9SMatthew G. Knepley . f  - The test field number
1578475e0ac9SMatthew G. Knepley . g  - The field number
1579475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1580475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1581475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1582475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1583475e0ac9SMatthew G. Knepley 
1584475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1585475e0ac9SMatthew G. Knepley 
1586475e0ac9SMatthew 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
1587475e0ac9SMatthew G. Knepley 
1588475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1589475e0ac9SMatthew G. Knepley 
1590475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1591475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1592475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1593475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1594475e0ac9SMatthew G. Knepley 
1595475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1596475e0ac9SMatthew G. Knepley . Nf - the number of fields
1597475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1598475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1599475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1600475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1601475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1602475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1603475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1604475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1605475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1606475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1607475e0ac9SMatthew G. Knepley . t - current time
1608475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1609475e0ac9SMatthew G. Knepley . x - coordinates of the current point
161097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
161197b6e6e8SMatthew G. Knepley . constants - constant parameters
1612475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1613475e0ac9SMatthew G. Knepley 
1614475e0ac9SMatthew G. Knepley   Level: intermediate
1615475e0ac9SMatthew G. Knepley 
1616475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1617475e0ac9SMatthew G. Knepley @*/
16186528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1619475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1620475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1621475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1623475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1624475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1625475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1627475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1628475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1629475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
163097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1631475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1632475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1633475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
163497b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1635475e0ac9SMatthew G. Knepley {
1636475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1637475e0ac9SMatthew G. Knepley 
1638475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
16396528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1640475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1641475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1642475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1643475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1644475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1645475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
16466528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
1647475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1648475e0ac9SMatthew G. Knepley }
1649475e0ac9SMatthew G. Knepley 
1650b7e05686SMatthew G. Knepley /*@C
1651b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1652b7e05686SMatthew G. Knepley 
1653b7e05686SMatthew G. Knepley   Not collective
1654b7e05686SMatthew G. Knepley 
1655b7e05686SMatthew G. Knepley   Input Parameter:
16566528b96dSMatthew G. Knepley . ds - The PetscDS
1657b7e05686SMatthew G. Knepley 
1658b7e05686SMatthew G. Knepley   Output Parameter:
1659b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1660b7e05686SMatthew G. Knepley 
1661b7e05686SMatthew G. Knepley   Level: intermediate
1662b7e05686SMatthew G. Knepley 
1663b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1664b7e05686SMatthew G. Knepley @*/
16656528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac)
1666b7e05686SMatthew G. Knepley {
16676528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1668b7e05686SMatthew G. Knepley 
1669b7e05686SMatthew G. Knepley   PetscFunctionBegin;
16706528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
16716528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac);CHKERRQ(ierr);
1672b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1673b7e05686SMatthew G. Knepley }
1674b7e05686SMatthew G. Knepley 
1675b7e05686SMatthew G. Knepley /*@C
1676b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1677b7e05686SMatthew G. Knepley 
1678b7e05686SMatthew G. Knepley   Not collective
1679b7e05686SMatthew G. Knepley 
1680b7e05686SMatthew G. Knepley   Input Parameters:
16816528b96dSMatthew G. Knepley + ds - The PetscDS
1682b7e05686SMatthew G. Knepley . f  - The test field number
1683b7e05686SMatthew G. Knepley - g  - The field number
1684b7e05686SMatthew G. Knepley 
1685b7e05686SMatthew G. Knepley   Output Parameters:
1686b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1687b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1688b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1689b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1690b7e05686SMatthew G. Knepley 
1691b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1692b7e05686SMatthew G. Knepley 
1693b7e05686SMatthew 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
1694b7e05686SMatthew G. Knepley 
1695b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1696b7e05686SMatthew G. Knepley 
1697b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1698b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1699b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1700b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1701b7e05686SMatthew G. Knepley 
1702b7e05686SMatthew G. Knepley + dim - the spatial dimension
1703b7e05686SMatthew G. Knepley . Nf - the number of fields
1704b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1705b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1706b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1707b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1708b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1709b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1710b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1711b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1712b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1713b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1714b7e05686SMatthew G. Knepley . t - current time
1715b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1716b7e05686SMatthew G. Knepley . x - coordinates of the current point
171797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
171897b6e6e8SMatthew G. Knepley . constants - constant parameters
1719b7e05686SMatthew G. Knepley - g0 - output values at the current point
1720b7e05686SMatthew G. Knepley 
1721b7e05686SMatthew G. Knepley   Level: intermediate
1722b7e05686SMatthew G. Knepley 
1723b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1724b7e05686SMatthew G. Knepley @*/
17256528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
1726b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1727b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1728b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
172997b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1730b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1731b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1732b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
173397b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1734b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1735b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1736b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
173797b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1738b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1739b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1740b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
174197b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1742b7e05686SMatthew G. Knepley {
17436528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
17446528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
17456528b96dSMatthew G. Knepley   PetscErrorCode ierr;
17466528b96dSMatthew G. Knepley 
1747b7e05686SMatthew G. Knepley   PetscFunctionBegin;
17486528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
17496528b96dSMatthew 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);
17506528b96dSMatthew 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);
17516528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
17526528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
17536528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
17546528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
17556528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1756b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1757b7e05686SMatthew G. Knepley }
1758b7e05686SMatthew G. Knepley 
1759b7e05686SMatthew G. Knepley /*@C
1760b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1761b7e05686SMatthew G. Knepley 
1762b7e05686SMatthew G. Knepley   Not collective
1763b7e05686SMatthew G. Knepley 
1764b7e05686SMatthew G. Knepley   Input Parameters:
17656528b96dSMatthew G. Knepley + ds - The PetscDS
1766b7e05686SMatthew G. Knepley . f  - The test field number
1767b7e05686SMatthew G. Knepley . g  - The field number
1768b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1769b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1770b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1771b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1772b7e05686SMatthew G. Knepley 
1773b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1774b7e05686SMatthew G. Knepley 
1775b7e05686SMatthew 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
1776b7e05686SMatthew G. Knepley 
1777b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1778b7e05686SMatthew G. Knepley 
1779b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1780b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1781b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1782b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1783b7e05686SMatthew G. Knepley 
1784b7e05686SMatthew G. Knepley + dim - the spatial dimension
1785b7e05686SMatthew G. Knepley . Nf - the number of fields
1786b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1787b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1788b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1789b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1790b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1791b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1792b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1793b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1794b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1795b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1796b7e05686SMatthew G. Knepley . t - current time
1797b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1798b7e05686SMatthew G. Knepley . x - coordinates of the current point
179997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
180097b6e6e8SMatthew G. Knepley . constants - constant parameters
1801b7e05686SMatthew G. Knepley - g0 - output values at the current point
1802b7e05686SMatthew G. Knepley 
1803b7e05686SMatthew G. Knepley   Level: intermediate
1804b7e05686SMatthew G. Knepley 
1805b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1806b7e05686SMatthew G. Knepley @*/
18076528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
1808b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1809b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1810b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
181197b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1812b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1813b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1814b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
181597b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1816b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1817b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1818b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
181997b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1820b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1821b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1822b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
182397b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1824b7e05686SMatthew G. Knepley {
1825b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1826b7e05686SMatthew G. Knepley 
1827b7e05686SMatthew G. Knepley   PetscFunctionBegin;
18286528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1829b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1830b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1831b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1832b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1833b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1834b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
18356528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
1836b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1837b7e05686SMatthew G. Knepley }
1838b7e05686SMatthew G. Knepley 
18390c2f2876SMatthew G. Knepley /*@C
18400c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
18410c2f2876SMatthew G. Knepley 
18420c2f2876SMatthew G. Knepley   Not collective
18430c2f2876SMatthew G. Knepley 
18440c2f2876SMatthew G. Knepley   Input Arguments:
18456528b96dSMatthew G. Knepley + ds - The PetscDS object
18460c2f2876SMatthew G. Knepley - f  - The field number
18470c2f2876SMatthew G. Knepley 
18480c2f2876SMatthew G. Knepley   Output Argument:
18490c2f2876SMatthew G. Knepley . r    - Riemann solver
18500c2f2876SMatthew G. Knepley 
18510c2f2876SMatthew G. Knepley   Calling sequence for r:
18520c2f2876SMatthew G. Knepley 
18535db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
18540c2f2876SMatthew G. Knepley 
18555db36cf9SMatthew G. Knepley + dim  - The spatial dimension
18565db36cf9SMatthew G. Knepley . Nf   - The number of fields
18575db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
18580c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
18590c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
18600c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
18610c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
186297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
186397b6e6e8SMatthew G. Knepley . constants - constant parameters
18640c2f2876SMatthew G. Knepley - ctx  - optional user context
18650c2f2876SMatthew G. Knepley 
18660c2f2876SMatthew G. Knepley   Level: intermediate
18670c2f2876SMatthew G. Knepley 
18680c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
18690c2f2876SMatthew G. Knepley @*/
18706528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS ds, PetscInt f,
187197b6e6e8SMatthew 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))
18720c2f2876SMatthew G. Knepley {
18736528b96dSMatthew G. Knepley   PetscRiemannFunc *tmp;
18746528b96dSMatthew G. Knepley   PetscInt          n;
18756528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
18766528b96dSMatthew G. Knepley 
18770c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18786528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
18790c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
18806528b96dSMatthew 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);
18816528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, &n, &tmp);CHKERRQ(ierr);
18826528b96dSMatthew G. Knepley   *r   = tmp ? tmp[0] : NULL;
18830c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18840c2f2876SMatthew G. Knepley }
18850c2f2876SMatthew G. Knepley 
18860c2f2876SMatthew G. Knepley /*@C
18870c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
18880c2f2876SMatthew G. Knepley 
18890c2f2876SMatthew G. Knepley   Not collective
18900c2f2876SMatthew G. Knepley 
18910c2f2876SMatthew G. Knepley   Input Arguments:
18926528b96dSMatthew G. Knepley + ds - The PetscDS object
18930c2f2876SMatthew G. Knepley . f  - The field number
18940c2f2876SMatthew G. Knepley - r  - Riemann solver
18950c2f2876SMatthew G. Knepley 
18960c2f2876SMatthew G. Knepley   Calling sequence for r:
18970c2f2876SMatthew G. Knepley 
18985db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
18990c2f2876SMatthew G. Knepley 
19005db36cf9SMatthew G. Knepley + dim  - The spatial dimension
19015db36cf9SMatthew G. Knepley . Nf   - The number of fields
19025db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
19030c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
19040c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
19050c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
19060c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
190797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
190897b6e6e8SMatthew G. Knepley . constants - constant parameters
19090c2f2876SMatthew G. Knepley - ctx  - optional user context
19100c2f2876SMatthew G. Knepley 
19110c2f2876SMatthew G. Knepley   Level: intermediate
19120c2f2876SMatthew G. Knepley 
19130c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
19140c2f2876SMatthew G. Knepley @*/
19156528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS ds, PetscInt f,
191697b6e6e8SMatthew 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))
19170c2f2876SMatthew G. Knepley {
19180c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
19190c2f2876SMatthew G. Knepley 
19200c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19216528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1922de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
19230c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19246528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, r);CHKERRQ(ierr);
19250c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19260c2f2876SMatthew G. Knepley }
19270c2f2876SMatthew G. Knepley 
192832d2bbc9SMatthew G. Knepley /*@C
192932d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
193032d2bbc9SMatthew G. Knepley 
193132d2bbc9SMatthew G. Knepley   Not collective
193232d2bbc9SMatthew G. Knepley 
193332d2bbc9SMatthew G. Knepley   Input Parameters:
19346528b96dSMatthew G. Knepley + ds - The PetscDS
193532d2bbc9SMatthew G. Knepley - f  - The field number
193632d2bbc9SMatthew G. Knepley 
193732d2bbc9SMatthew G. Knepley   Output Parameters:
1938a2b725a8SWilliam Gropp . update - update function
193932d2bbc9SMatthew G. Knepley 
194032d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
194132d2bbc9SMatthew G. Knepley 
194232d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
194332d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
194432d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194532d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
194632d2bbc9SMatthew G. Knepley 
194732d2bbc9SMatthew G. Knepley + dim - the spatial dimension
194832d2bbc9SMatthew G. Knepley . Nf - the number of fields
194932d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
195032d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
195132d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
195232d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
195332d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
195432d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
195532d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
195632d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
195732d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
195832d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
195932d2bbc9SMatthew G. Knepley . t - current time
196032d2bbc9SMatthew G. Knepley . x - coordinates of the current point
196132d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
196232d2bbc9SMatthew G. Knepley 
196332d2bbc9SMatthew G. Knepley   Level: intermediate
196432d2bbc9SMatthew G. Knepley 
196532d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
196632d2bbc9SMatthew G. Knepley @*/
19676528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS ds, PetscInt f,
196832d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
196932d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
197032d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19713fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
197232d2bbc9SMatthew G. Knepley {
197332d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
19746528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
19756528b96dSMatthew 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);
19766528b96dSMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = ds->update[f];}
197732d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
197832d2bbc9SMatthew G. Knepley }
197932d2bbc9SMatthew G. Knepley 
198032d2bbc9SMatthew G. Knepley /*@C
19813fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
198232d2bbc9SMatthew G. Knepley 
198332d2bbc9SMatthew G. Knepley   Not collective
198432d2bbc9SMatthew G. Knepley 
198532d2bbc9SMatthew G. Knepley   Input Parameters:
19866528b96dSMatthew G. Knepley + ds     - The PetscDS
198732d2bbc9SMatthew G. Knepley . f      - The field number
198832d2bbc9SMatthew G. Knepley - update - update function
198932d2bbc9SMatthew G. Knepley 
199032d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
199132d2bbc9SMatthew G. Knepley 
199232d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
199332d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
199432d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
199532d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
199632d2bbc9SMatthew G. Knepley 
199732d2bbc9SMatthew G. Knepley + dim - the spatial dimension
199832d2bbc9SMatthew G. Knepley . Nf - the number of fields
199932d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
200032d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
200132d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
200232d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
200332d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
200432d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
200532d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
200632d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
200732d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
200832d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
200932d2bbc9SMatthew G. Knepley . t - current time
201032d2bbc9SMatthew G. Knepley . x - coordinates of the current point
201132d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
201232d2bbc9SMatthew G. Knepley 
201332d2bbc9SMatthew G. Knepley   Level: intermediate
201432d2bbc9SMatthew G. Knepley 
201532d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
201632d2bbc9SMatthew G. Knepley @*/
20176528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS ds, PetscInt f,
201832d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
201932d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
202032d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20213fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
202232d2bbc9SMatthew G. Knepley {
202332d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
202432d2bbc9SMatthew G. Knepley 
202532d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
20266528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
202732d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
202832d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
20296528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
20306528b96dSMatthew G. Knepley   ds->update[f] = update;
203132d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
203232d2bbc9SMatthew G. Knepley }
203332d2bbc9SMatthew G. Knepley 
20346528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void **ctx)
20350c2f2876SMatthew G. Knepley {
20360c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20376528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
20386528b96dSMatthew 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);
20390c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
20406528b96dSMatthew G. Knepley   *ctx = ds->ctx[f];
20410c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20420c2f2876SMatthew G. Knepley }
20430c2f2876SMatthew G. Knepley 
20446528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx)
20450c2f2876SMatthew G. Knepley {
20460c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
20470c2f2876SMatthew G. Knepley 
20480c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20496528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
20500c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
20516528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
20526528b96dSMatthew G. Knepley   ds->ctx[f] = ctx;
20530c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20540c2f2876SMatthew G. Knepley }
20550c2f2876SMatthew G. Knepley 
2056194d53e6SMatthew G. Knepley /*@C
2057194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
2058194d53e6SMatthew G. Knepley 
2059194d53e6SMatthew G. Knepley   Not collective
2060194d53e6SMatthew G. Knepley 
2061194d53e6SMatthew G. Knepley   Input Parameters:
20626528b96dSMatthew G. Knepley + ds - The PetscDS
2063194d53e6SMatthew G. Knepley - f  - The test field number
2064194d53e6SMatthew G. Knepley 
2065194d53e6SMatthew G. Knepley   Output Parameters:
2066194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
2067194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2068194d53e6SMatthew G. Knepley 
2069194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2070194d53e6SMatthew G. Knepley 
2071194d53e6SMatthew 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
2072194d53e6SMatthew G. Knepley 
2073194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2074194d53e6SMatthew G. Knepley 
207530b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2076194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2077194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
207830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2079194d53e6SMatthew G. Knepley 
2080194d53e6SMatthew G. Knepley + dim - the spatial dimension
2081194d53e6SMatthew G. Knepley . Nf - the number of fields
2082194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2083194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2084194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2085194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2086194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2087194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2088194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2089194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2090194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2091194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2092194d53e6SMatthew G. Knepley . t - current time
2093194d53e6SMatthew G. Knepley . x - coordinates of the current point
2094194d53e6SMatthew G. Knepley . n - unit normal at the current point
209597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
209697b6e6e8SMatthew G. Knepley . constants - constant parameters
2097194d53e6SMatthew G. Knepley - f0 - output values at the current point
2098194d53e6SMatthew G. Knepley 
2099194d53e6SMatthew G. Knepley   Level: intermediate
2100194d53e6SMatthew G. Knepley 
2101194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
2102194d53e6SMatthew G. Knepley @*/
21036528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS ds, PetscInt f,
210430b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2105194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2106194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
210797b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
210830b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2109194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2110194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
211197b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
21122764a2aaSMatthew G. Knepley {
21136528b96dSMatthew G. Knepley   PetscBdPointFunc *tmp0, *tmp1;
21146528b96dSMatthew G. Knepley   PetscInt          n0, n1;
21156528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
21166528b96dSMatthew G. Knepley 
21172764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21186528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
21196528b96dSMatthew 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);
21206528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
21216528b96dSMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
21226528b96dSMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
21232764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21242764a2aaSMatthew G. Knepley }
21252764a2aaSMatthew G. Knepley 
2126194d53e6SMatthew G. Knepley /*@C
2127194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2128194d53e6SMatthew G. Knepley 
2129194d53e6SMatthew G. Knepley   Not collective
2130194d53e6SMatthew G. Knepley 
2131194d53e6SMatthew G. Knepley   Input Parameters:
21326528b96dSMatthew G. Knepley + ds - The PetscDS
2133194d53e6SMatthew G. Knepley . f  - The test field number
2134194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2135194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2136194d53e6SMatthew G. Knepley 
2137194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2138194d53e6SMatthew G. Knepley 
2139194d53e6SMatthew 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
2140194d53e6SMatthew G. Knepley 
2141194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2142194d53e6SMatthew G. Knepley 
214330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2144194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2145194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
214630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2147194d53e6SMatthew G. Knepley 
2148194d53e6SMatthew G. Knepley + dim - the spatial dimension
2149194d53e6SMatthew G. Knepley . Nf - the number of fields
2150194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2151194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2152194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2153194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2154194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2155194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2156194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2157194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2158194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2159194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2160194d53e6SMatthew G. Knepley . t - current time
2161194d53e6SMatthew G. Knepley . x - coordinates of the current point
2162194d53e6SMatthew G. Knepley . n - unit normal at the current point
216397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
216497b6e6e8SMatthew G. Knepley . constants - constant parameters
2165194d53e6SMatthew G. Knepley - f0 - output values at the current point
2166194d53e6SMatthew G. Knepley 
2167194d53e6SMatthew G. Knepley   Level: intermediate
2168194d53e6SMatthew G. Knepley 
2169194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
2170194d53e6SMatthew G. Knepley @*/
21716528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS ds, PetscInt f,
217230b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2173194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2174194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
217597b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
217630b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2177194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2178194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
217997b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
21802764a2aaSMatthew G. Knepley {
21812764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21822764a2aaSMatthew G. Knepley 
21832764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21846528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
21852764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21866528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, f0, 0, f1);CHKERRQ(ierr);
21872764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21882764a2aaSMatthew G. Knepley }
21892764a2aaSMatthew G. Knepley 
219027f02ce8SMatthew G. Knepley /*@
219127f02ce8SMatthew G. Knepley   PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set
219227f02ce8SMatthew G. Knepley 
219327f02ce8SMatthew G. Knepley   Not collective
219427f02ce8SMatthew G. Knepley 
219527f02ce8SMatthew G. Knepley   Input Parameter:
21966528b96dSMatthew G. Knepley . ds - The PetscDS
219727f02ce8SMatthew G. Knepley 
219827f02ce8SMatthew G. Knepley   Output Parameter:
219927f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set
220027f02ce8SMatthew G. Knepley 
220127f02ce8SMatthew G. Knepley   Level: intermediate
220227f02ce8SMatthew G. Knepley 
220327f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
220427f02ce8SMatthew G. Knepley @*/
22056528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac)
220627f02ce8SMatthew G. Knepley {
22076528b96dSMatthew G. Knepley   PetscErrorCode ierr;
220827f02ce8SMatthew G. Knepley 
220927f02ce8SMatthew G. Knepley   PetscFunctionBegin;
22106528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
22116528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJac, 2);
22126528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobian(ds->wf, hasBdJac);CHKERRQ(ierr);
221327f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
221427f02ce8SMatthew G. Knepley }
221527f02ce8SMatthew G. Knepley 
2216194d53e6SMatthew G. Knepley /*@C
2217194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2218194d53e6SMatthew G. Knepley 
2219194d53e6SMatthew G. Knepley   Not collective
2220194d53e6SMatthew G. Knepley 
2221194d53e6SMatthew G. Knepley   Input Parameters:
22226528b96dSMatthew G. Knepley + ds - The PetscDS
2223194d53e6SMatthew G. Knepley . f  - The test field number
2224194d53e6SMatthew G. Knepley - g  - The field number
2225194d53e6SMatthew G. Knepley 
2226194d53e6SMatthew G. Knepley   Output Parameters:
2227194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2228194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2229194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2230194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2231194d53e6SMatthew G. Knepley 
2232194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2233194d53e6SMatthew G. Knepley 
2234194d53e6SMatthew 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
2235194d53e6SMatthew G. Knepley 
2236194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2237194d53e6SMatthew G. Knepley 
223830b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2239194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2240194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
224130b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2242194d53e6SMatthew G. Knepley 
2243194d53e6SMatthew G. Knepley + dim - the spatial dimension
2244194d53e6SMatthew G. Knepley . Nf - the number of fields
2245194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2246194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2247194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2248194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2249194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2250194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2251194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2252194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2253194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2254194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2255194d53e6SMatthew G. Knepley . t - current time
22562aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2257194d53e6SMatthew G. Knepley . x - coordinates of the current point
2258194d53e6SMatthew G. Knepley . n - normal at the current point
225997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
226097b6e6e8SMatthew G. Knepley . constants - constant parameters
2261194d53e6SMatthew G. Knepley - g0 - output values at the current point
2262194d53e6SMatthew G. Knepley 
2263194d53e6SMatthew G. Knepley   Level: intermediate
2264194d53e6SMatthew G. Knepley 
2265194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2266194d53e6SMatthew G. Knepley @*/
22676528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
226830b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2269194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2270194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
227197b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
227230b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2273194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2274194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
227597b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
227630b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2277194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2278194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
227997b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
228030b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2281194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2282194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
228397b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
22842764a2aaSMatthew G. Knepley {
22856528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
22866528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
22876528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
22886528b96dSMatthew G. Knepley 
22892764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22906528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
22916528b96dSMatthew 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);
22926528b96dSMatthew 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);
22936528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
22946528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
22956528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
22966528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
22976528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
22982764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22992764a2aaSMatthew G. Knepley }
23002764a2aaSMatthew G. Knepley 
2301194d53e6SMatthew G. Knepley /*@C
2302194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2303194d53e6SMatthew G. Knepley 
2304194d53e6SMatthew G. Knepley   Not collective
2305194d53e6SMatthew G. Knepley 
2306194d53e6SMatthew G. Knepley   Input Parameters:
23076528b96dSMatthew G. Knepley + ds - The PetscDS
2308194d53e6SMatthew G. Knepley . f  - The test field number
2309194d53e6SMatthew G. Knepley . g  - The field number
2310194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2311194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2312194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2313194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2314194d53e6SMatthew G. Knepley 
2315194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2316194d53e6SMatthew G. Knepley 
2317194d53e6SMatthew 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
2318194d53e6SMatthew G. Knepley 
2319194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2320194d53e6SMatthew G. Knepley 
232130b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2322194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2323194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
232430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2325194d53e6SMatthew G. Knepley 
2326194d53e6SMatthew G. Knepley + dim - the spatial dimension
2327194d53e6SMatthew G. Knepley . Nf - the number of fields
2328194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2329194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2330194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2331194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2332194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2333194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2334194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2335194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2336194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2337194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2338194d53e6SMatthew G. Knepley . t - current time
23392aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2340194d53e6SMatthew G. Knepley . x - coordinates of the current point
2341194d53e6SMatthew G. Knepley . n - normal at the current point
234297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
234397b6e6e8SMatthew G. Knepley . constants - constant parameters
2344194d53e6SMatthew G. Knepley - g0 - output values at the current point
2345194d53e6SMatthew G. Knepley 
2346194d53e6SMatthew G. Knepley   Level: intermediate
2347194d53e6SMatthew G. Knepley 
2348194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2349194d53e6SMatthew G. Knepley @*/
23506528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
235130b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2352194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2353194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
235497b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
235530b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2356194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2357194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
235897b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
235930b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2360194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2361194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
236297b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
236330b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2364194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2365194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
236697b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
23672764a2aaSMatthew G. Knepley {
23682764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23692764a2aaSMatthew G. Knepley 
23702764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23716528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
23722764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
23732764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
23742764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
23752764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
23762764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
23772764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
23786528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
23792764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23802764a2aaSMatthew G. Knepley }
23812764a2aaSMatthew G. Knepley 
238227f02ce8SMatthew G. Knepley /*@
238327f02ce8SMatthew G. Knepley   PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set
238427f02ce8SMatthew G. Knepley 
238527f02ce8SMatthew G. Knepley   Not collective
238627f02ce8SMatthew G. Knepley 
238727f02ce8SMatthew G. Knepley   Input Parameter:
23886528b96dSMatthew G. Knepley . ds - The PetscDS
238927f02ce8SMatthew G. Knepley 
239027f02ce8SMatthew G. Knepley   Output Parameter:
239127f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set
239227f02ce8SMatthew G. Knepley 
239327f02ce8SMatthew G. Knepley   Level: intermediate
239427f02ce8SMatthew G. Knepley 
239527f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
239627f02ce8SMatthew G. Knepley @*/
23976528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre)
239827f02ce8SMatthew G. Knepley {
23996528b96dSMatthew G. Knepley   PetscErrorCode ierr;
240027f02ce8SMatthew G. Knepley 
240127f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24026528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24036528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJacPre, 2);
24046528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre);CHKERRQ(ierr);
240527f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
240627f02ce8SMatthew G. Knepley }
240727f02ce8SMatthew G. Knepley 
240827f02ce8SMatthew G. Knepley /*@C
240927f02ce8SMatthew G. Knepley   PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field
241027f02ce8SMatthew G. Knepley 
241127f02ce8SMatthew G. Knepley   Not collective
241227f02ce8SMatthew G. Knepley 
241327f02ce8SMatthew G. Knepley   Input Parameters:
24146528b96dSMatthew G. Knepley + ds - The PetscDS
241527f02ce8SMatthew G. Knepley . f  - The test field number
241627f02ce8SMatthew G. Knepley - g  - The field number
241727f02ce8SMatthew G. Knepley 
241827f02ce8SMatthew G. Knepley   Output Parameters:
241927f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term
242027f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
242127f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
242227f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
242327f02ce8SMatthew G. Knepley 
242427f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
242527f02ce8SMatthew G. Knepley 
242627f02ce8SMatthew 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
242727f02ce8SMatthew G. Knepley 
242827f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
242927f02ce8SMatthew G. Knepley 
243027f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
243127f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
243227f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
243327f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
243427f02ce8SMatthew G. Knepley 
243527f02ce8SMatthew G. Knepley + dim - the spatial dimension
243627f02ce8SMatthew G. Knepley . Nf - the number of fields
243727f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
243827f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
243927f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
244027f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
244127f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
244227f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
244327f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
244427f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
244527f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
244627f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
244727f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
244827f02ce8SMatthew G. Knepley . t - current time
244927f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
245027f02ce8SMatthew G. Knepley . x - coordinates of the current point
245127f02ce8SMatthew G. Knepley . n - normal at the current point
245227f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
245327f02ce8SMatthew G. Knepley . constants - constant parameters
245427f02ce8SMatthew G. Knepley - g0 - output values at the current point
245527f02ce8SMatthew G. Knepley 
245627f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
245727f02ce8SMatthew G. Knepley 
245827f02ce8SMatthew G. Knepley   Level: intermediate
245927f02ce8SMatthew G. Knepley 
246027f02ce8SMatthew G. Knepley .seealso: PetscDSSetBdJacobianPreconditioner()
246127f02ce8SMatthew G. Knepley @*/
24626528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
246327f02ce8SMatthew G. Knepley                                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
246427f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
246527f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
246627f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
246727f02ce8SMatthew G. Knepley                                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
246827f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
246927f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
247027f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
247127f02ce8SMatthew G. Knepley                                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
247227f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
247327f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
247427f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
247527f02ce8SMatthew G. Knepley                                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
247627f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
247727f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
247827f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
247927f02ce8SMatthew G. Knepley {
24806528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
24816528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
24826528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
24836528b96dSMatthew G. Knepley 
248427f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24856528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24866528b96dSMatthew 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);
24876528b96dSMatthew 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);
24886528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
24896528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
24906528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
24916528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
24926528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
249327f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
249427f02ce8SMatthew G. Knepley }
249527f02ce8SMatthew G. Knepley 
249627f02ce8SMatthew G. Knepley /*@C
249727f02ce8SMatthew G. Knepley   PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field
249827f02ce8SMatthew G. Knepley 
249927f02ce8SMatthew G. Knepley   Not collective
250027f02ce8SMatthew G. Knepley 
250127f02ce8SMatthew G. Knepley   Input Parameters:
25026528b96dSMatthew G. Knepley + ds - The PetscDS
250327f02ce8SMatthew G. Knepley . f  - The test field number
250427f02ce8SMatthew G. Knepley . g  - The field number
250527f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term
250627f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
250727f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
250827f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
250927f02ce8SMatthew G. Knepley 
251027f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
251127f02ce8SMatthew G. Knepley 
251227f02ce8SMatthew 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
251327f02ce8SMatthew G. Knepley 
251427f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
251527f02ce8SMatthew G. Knepley 
251627f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
251727f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
251827f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
251927f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
252027f02ce8SMatthew G. Knepley 
252127f02ce8SMatthew G. Knepley + dim - the spatial dimension
252227f02ce8SMatthew G. Knepley . Nf - the number of fields
252327f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
252427f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
252527f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
252627f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
252727f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
252827f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
252927f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
253027f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
253127f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
253227f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
253327f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
253427f02ce8SMatthew G. Knepley . t - current time
253527f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
253627f02ce8SMatthew G. Knepley . x - coordinates of the current point
253727f02ce8SMatthew G. Knepley . n - normal at the current point
253827f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
253927f02ce8SMatthew G. Knepley . constants - constant parameters
254027f02ce8SMatthew G. Knepley - g0 - output values at the current point
254127f02ce8SMatthew G. Knepley 
254227f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
254327f02ce8SMatthew G. Knepley 
254427f02ce8SMatthew G. Knepley   Level: intermediate
254527f02ce8SMatthew G. Knepley 
254627f02ce8SMatthew G. Knepley .seealso: PetscDSGetBdJacobianPreconditioner()
254727f02ce8SMatthew G. Knepley @*/
25486528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
254927f02ce8SMatthew G. Knepley                                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
255027f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
255127f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
255227f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
255327f02ce8SMatthew G. Knepley                                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
255427f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
255527f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
255627f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
255727f02ce8SMatthew G. Knepley                                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
255827f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
255927f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
256027f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
256127f02ce8SMatthew G. Knepley                                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
256227f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
256327f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
256427f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
256527f02ce8SMatthew G. Knepley {
256627f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
256727f02ce8SMatthew G. Knepley 
256827f02ce8SMatthew G. Knepley   PetscFunctionBegin;
25696528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
257027f02ce8SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
257127f02ce8SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
257227f02ce8SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
257327f02ce8SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
257427f02ce8SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
257527f02ce8SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
25766528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
257727f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
257827f02ce8SMatthew G. Knepley }
257927f02ce8SMatthew G. Knepley 
25800d3e9b51SMatthew G. Knepley /*@C
2581c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2582c371a6d1SMatthew G. Knepley 
2583c371a6d1SMatthew G. Knepley   Not collective
2584c371a6d1SMatthew G. Knepley 
2585c371a6d1SMatthew G. Knepley   Input Parameters:
2586c371a6d1SMatthew G. Knepley + prob - The PetscDS
2587c371a6d1SMatthew G. Knepley - f    - The test field number
2588c371a6d1SMatthew G. Knepley 
2589c371a6d1SMatthew G. Knepley   Output Parameter:
259095cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field
259195cbbfd3SMatthew G. Knepley - exactCtx - exact solution context
2592c371a6d1SMatthew G. Knepley 
2593c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2594c371a6d1SMatthew G. Knepley 
2595c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2596c371a6d1SMatthew G. Knepley 
2597c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2598c371a6d1SMatthew G. Knepley . t - current time
2599c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2600c371a6d1SMatthew G. Knepley . Nc - the number of field components
2601c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2602c371a6d1SMatthew G. Knepley - ctx - a user context
2603c371a6d1SMatthew G. Knepley 
2604c371a6d1SMatthew G. Knepley   Level: intermediate
2605c371a6d1SMatthew G. Knepley 
2606f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolution(), PetscDSGetExactSolutionTimeDerivative()
2607c371a6d1SMatthew G. Knepley @*/
260895cbbfd3SMatthew 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)
2609c371a6d1SMatthew G. Knepley {
2610c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2611c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2612c371a6d1SMatthew 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);
2613c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
261495cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];}
2615c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2616c371a6d1SMatthew G. Knepley }
2617c371a6d1SMatthew G. Knepley 
2618c371a6d1SMatthew G. Knepley /*@C
2619578a5ef5SMatthew Knepley   PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field
2620c371a6d1SMatthew G. Knepley 
2621c371a6d1SMatthew G. Knepley   Not collective
2622c371a6d1SMatthew G. Knepley 
2623c371a6d1SMatthew G. Knepley   Input Parameters:
2624c371a6d1SMatthew G. Knepley + prob - The PetscDS
2625c371a6d1SMatthew G. Knepley . f    - The test field number
262695cbbfd3SMatthew G. Knepley . sol  - solution function for the test fields
262795cbbfd3SMatthew G. Knepley - ctx  - solution context or NULL
2628c371a6d1SMatthew G. Knepley 
2629c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2630c371a6d1SMatthew G. Knepley 
2631c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2632c371a6d1SMatthew G. Knepley 
2633c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2634c371a6d1SMatthew G. Knepley . t - current time
2635c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2636c371a6d1SMatthew G. Knepley . Nc - the number of field components
2637c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2638c371a6d1SMatthew G. Knepley - ctx - a user context
2639c371a6d1SMatthew G. Knepley 
2640c371a6d1SMatthew G. Knepley   Level: intermediate
2641c371a6d1SMatthew G. Knepley 
2642c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2643c371a6d1SMatthew G. Knepley @*/
264495cbbfd3SMatthew 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)
2645c371a6d1SMatthew G. Knepley {
2646c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2647c371a6d1SMatthew G. Knepley 
2648c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2649c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2650c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2651c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2652c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
265395cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;}
2654c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2655c371a6d1SMatthew G. Knepley }
2656c371a6d1SMatthew G. Knepley 
26575638fd0eSMatthew G. Knepley /*@C
2658f2cacb80SMatthew G. Knepley   PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field
2659f2cacb80SMatthew G. Knepley 
2660f2cacb80SMatthew G. Knepley   Not collective
2661f2cacb80SMatthew G. Knepley 
2662f2cacb80SMatthew G. Knepley   Input Parameters:
2663f2cacb80SMatthew G. Knepley + prob - The PetscDS
2664f2cacb80SMatthew G. Knepley - f    - The test field number
2665f2cacb80SMatthew G. Knepley 
2666f2cacb80SMatthew G. Knepley   Output Parameter:
2667f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field
2668f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context
2669f2cacb80SMatthew G. Knepley 
2670f2cacb80SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2671f2cacb80SMatthew G. Knepley 
2672f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2673f2cacb80SMatthew G. Knepley 
2674f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2675f2cacb80SMatthew G. Knepley . t - current time
2676f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2677f2cacb80SMatthew G. Knepley . Nc - the number of field components
2678f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2679f2cacb80SMatthew G. Knepley - ctx - a user context
2680f2cacb80SMatthew G. Knepley 
2681f2cacb80SMatthew G. Knepley   Level: intermediate
2682f2cacb80SMatthew G. Knepley 
2683f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolutionTimeDerivative(), PetscDSGetExactSolution()
2684f2cacb80SMatthew G. Knepley @*/
2685f2cacb80SMatthew 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)
2686f2cacb80SMatthew G. Knepley {
2687f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2688f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2689f2cacb80SMatthew 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);
2690f2cacb80SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol_t[f];}
2691f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx_t[f];}
2692f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2693f2cacb80SMatthew G. Knepley }
2694f2cacb80SMatthew G. Knepley 
2695f2cacb80SMatthew G. Knepley /*@C
2696f2cacb80SMatthew G. Knepley   PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field
2697f2cacb80SMatthew G. Knepley 
2698f2cacb80SMatthew G. Knepley   Not collective
2699f2cacb80SMatthew G. Knepley 
2700f2cacb80SMatthew G. Knepley   Input Parameters:
2701f2cacb80SMatthew G. Knepley + prob - The PetscDS
2702f2cacb80SMatthew G. Knepley . f    - The test field number
2703f2cacb80SMatthew G. Knepley . sol  - time derivative of the solution function for the test fields
2704f2cacb80SMatthew G. Knepley - ctx  - time derivative of the solution context or NULL
2705f2cacb80SMatthew G. Knepley 
2706f2cacb80SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2707f2cacb80SMatthew G. Knepley 
2708f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2709f2cacb80SMatthew G. Knepley 
2710f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2711f2cacb80SMatthew G. Knepley . t - current time
2712f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2713f2cacb80SMatthew G. Knepley . Nc - the number of field components
2714f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2715f2cacb80SMatthew G. Knepley - ctx - a user context
2716f2cacb80SMatthew G. Knepley 
2717f2cacb80SMatthew G. Knepley   Level: intermediate
2718f2cacb80SMatthew G. Knepley 
2719f2cacb80SMatthew G. Knepley .seealso: PetscDSGetExactSolutionTimeDerivative(), PetscDSSetExactSolution()
2720f2cacb80SMatthew G. Knepley @*/
2721f2cacb80SMatthew 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)
2722f2cacb80SMatthew G. Knepley {
2723f2cacb80SMatthew G. Knepley   PetscErrorCode ierr;
2724f2cacb80SMatthew G. Knepley 
2725f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2726f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2727f2cacb80SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2728f2cacb80SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2729f2cacb80SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol_t[f] = sol;}
2730f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx_t[f] = ctx;}
2731f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2732f2cacb80SMatthew G. Knepley }
2733f2cacb80SMatthew G. Knepley 
2734f2cacb80SMatthew G. Knepley /*@C
273597b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
273697b6e6e8SMatthew G. Knepley 
273797b6e6e8SMatthew G. Knepley   Not collective
273897b6e6e8SMatthew G. Knepley 
273997b6e6e8SMatthew G. Knepley   Input Parameter:
274097b6e6e8SMatthew G. Knepley . prob - The PetscDS object
274197b6e6e8SMatthew G. Knepley 
274297b6e6e8SMatthew G. Knepley   Output Parameters:
274397b6e6e8SMatthew G. Knepley + numConstants - The number of constants
274497b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
274597b6e6e8SMatthew G. Knepley 
274697b6e6e8SMatthew G. Knepley   Level: intermediate
274797b6e6e8SMatthew G. Knepley 
274897b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
274997b6e6e8SMatthew G. Knepley @*/
275097b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
275197b6e6e8SMatthew G. Knepley {
275297b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
275397b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
275497b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
275597b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
275697b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
275797b6e6e8SMatthew G. Knepley }
275897b6e6e8SMatthew G. Knepley 
27590d3e9b51SMatthew G. Knepley /*@C
276097b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
276197b6e6e8SMatthew G. Knepley 
276297b6e6e8SMatthew G. Knepley   Not collective
276397b6e6e8SMatthew G. Knepley 
276497b6e6e8SMatthew G. Knepley   Input Parameters:
276597b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
276697b6e6e8SMatthew G. Knepley . numConstants - The number of constants
276797b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
276897b6e6e8SMatthew G. Knepley 
276997b6e6e8SMatthew G. Knepley   Level: intermediate
277097b6e6e8SMatthew G. Knepley 
277197b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
277297b6e6e8SMatthew G. Knepley @*/
277397b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
277497b6e6e8SMatthew G. Knepley {
277597b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
277697b6e6e8SMatthew G. Knepley 
277797b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
277897b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
277997b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
278097b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
278197b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
278297b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
278397b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
278420be0f5bSMatthew G. Knepley     } else {
278520be0f5bSMatthew G. Knepley       prob->constants = NULL;
278620be0f5bSMatthew G. Knepley     }
278720be0f5bSMatthew G. Knepley   }
278820be0f5bSMatthew G. Knepley   if (prob->numConstants) {
278920be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
2790580bdb30SBarry Smith     ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr);
279197b6e6e8SMatthew G. Knepley   }
279297b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
279397b6e6e8SMatthew G. Knepley }
279497b6e6e8SMatthew G. Knepley 
27954cd1e086SMatthew G. Knepley /*@
27964cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
27974cd1e086SMatthew G. Knepley 
27984cd1e086SMatthew G. Knepley   Not collective
27994cd1e086SMatthew G. Knepley 
28004cd1e086SMatthew G. Knepley   Input Parameters:
28014cd1e086SMatthew G. Knepley + prob - The PetscDS object
28024cd1e086SMatthew G. Knepley - disc - The discretization object
28034cd1e086SMatthew G. Knepley 
28044cd1e086SMatthew G. Knepley   Output Parameter:
28054cd1e086SMatthew G. Knepley . f - The field number
28064cd1e086SMatthew G. Knepley 
28074cd1e086SMatthew G. Knepley   Level: beginner
28084cd1e086SMatthew G. Knepley 
2809f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
28104cd1e086SMatthew G. Knepley @*/
28114cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
28124cd1e086SMatthew G. Knepley {
28134cd1e086SMatthew G. Knepley   PetscInt g;
28144cd1e086SMatthew G. Knepley 
28154cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28164cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28174cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
28184cd1e086SMatthew G. Knepley   *f = -1;
28194cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
28204cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
28214cd1e086SMatthew G. Knepley   *f = g;
28224cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
28234cd1e086SMatthew G. Knepley }
28244cd1e086SMatthew G. Knepley 
28254cd1e086SMatthew G. Knepley /*@
28264cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
28274cd1e086SMatthew G. Knepley 
28284cd1e086SMatthew G. Knepley   Not collective
28294cd1e086SMatthew G. Knepley 
28304cd1e086SMatthew G. Knepley   Input Parameters:
28314cd1e086SMatthew G. Knepley + prob - The PetscDS object
28324cd1e086SMatthew G. Knepley - f - The field number
28334cd1e086SMatthew G. Knepley 
28344cd1e086SMatthew G. Knepley   Output Parameter:
28354cd1e086SMatthew G. Knepley . size - The size
28364cd1e086SMatthew G. Knepley 
28374cd1e086SMatthew G. Knepley   Level: beginner
28384cd1e086SMatthew G. Knepley 
2839f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
28404cd1e086SMatthew G. Knepley @*/
28414cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
28424cd1e086SMatthew G. Knepley {
28432166fd64SMatthew G. Knepley   PetscErrorCode ierr;
28442166fd64SMatthew G. Knepley 
28454cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28464cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28474cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
28484cd1e086SMatthew 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);
28492166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2850d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
28514cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
28524cd1e086SMatthew G. Knepley }
28534cd1e086SMatthew G. Knepley 
2854bc4ae4beSMatthew G. Knepley /*@
2855bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2856bc4ae4beSMatthew G. Knepley 
2857bc4ae4beSMatthew G. Knepley   Not collective
2858bc4ae4beSMatthew G. Knepley 
2859bc4ae4beSMatthew G. Knepley   Input Parameters:
2860bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2861bc4ae4beSMatthew G. Knepley - f - The field number
2862bc4ae4beSMatthew G. Knepley 
2863bc4ae4beSMatthew G. Knepley   Output Parameter:
2864bc4ae4beSMatthew G. Knepley . off - The offset
2865bc4ae4beSMatthew G. Knepley 
2866bc4ae4beSMatthew G. Knepley   Level: beginner
2867bc4ae4beSMatthew G. Knepley 
2868f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2869bc4ae4beSMatthew G. Knepley @*/
28702764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
28712764a2aaSMatthew G. Knepley {
28724cd1e086SMatthew G. Knepley   PetscInt       size, g;
28732764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
28742764a2aaSMatthew G. Knepley 
28752764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28762764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28772764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
28782764a2aaSMatthew 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);
28792764a2aaSMatthew G. Knepley   *off = 0;
28802764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
28814cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
28824cd1e086SMatthew G. Knepley     *off += size;
28832764a2aaSMatthew G. Knepley   }
28842764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28852764a2aaSMatthew G. Knepley }
28862764a2aaSMatthew G. Knepley 
2887bc4ae4beSMatthew G. Knepley /*@
288847e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2889bc4ae4beSMatthew G. Knepley 
2890bc4ae4beSMatthew G. Knepley   Not collective
2891bc4ae4beSMatthew G. Knepley 
289247e57110SSander Arens   Input Parameter:
289347e57110SSander Arens . prob - The PetscDS object
2894bc4ae4beSMatthew G. Knepley 
2895bc4ae4beSMatthew G. Knepley   Output Parameter:
289647e57110SSander Arens . dimensions - The number of dimensions
2897bc4ae4beSMatthew G. Knepley 
2898bc4ae4beSMatthew G. Knepley   Level: beginner
2899bc4ae4beSMatthew G. Knepley 
290047e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2901bc4ae4beSMatthew G. Knepley @*/
290247e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
29032764a2aaSMatthew G. Knepley {
29042764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
29052764a2aaSMatthew G. Knepley 
29062764a2aaSMatthew G. Knepley   PetscFunctionBegin;
29072764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
290847e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
290947e57110SSander Arens   PetscValidPointer(dimensions, 2);
291047e57110SSander Arens   *dimensions = prob->Nb;
291147e57110SSander Arens   PetscFunctionReturn(0);
29126ce16762SMatthew G. Knepley }
291347e57110SSander Arens 
291447e57110SSander Arens /*@
291547e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
291647e57110SSander Arens 
291747e57110SSander Arens   Not collective
291847e57110SSander Arens 
291947e57110SSander Arens   Input Parameter:
292047e57110SSander Arens . prob - The PetscDS object
292147e57110SSander Arens 
292247e57110SSander Arens   Output Parameter:
292347e57110SSander Arens . components - The number of components
292447e57110SSander Arens 
292547e57110SSander Arens   Level: beginner
292647e57110SSander Arens 
292747e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
292847e57110SSander Arens @*/
292947e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
293047e57110SSander Arens {
293147e57110SSander Arens   PetscErrorCode ierr;
293247e57110SSander Arens 
293347e57110SSander Arens   PetscFunctionBegin;
293447e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
293547e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
293647e57110SSander Arens   PetscValidPointer(components, 2);
293747e57110SSander Arens   *components = prob->Nc;
29386ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
29396ce16762SMatthew G. Knepley }
29406ce16762SMatthew G. Knepley 
29416ce16762SMatthew G. Knepley /*@
29426ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
29436ce16762SMatthew G. Knepley 
29446ce16762SMatthew G. Knepley   Not collective
29456ce16762SMatthew G. Knepley 
29466ce16762SMatthew G. Knepley   Input Parameters:
29476ce16762SMatthew G. Knepley + prob - The PetscDS object
29486ce16762SMatthew G. Knepley - f - The field number
29496ce16762SMatthew G. Knepley 
29506ce16762SMatthew G. Knepley   Output Parameter:
29516ce16762SMatthew G. Knepley . off - The offset
29526ce16762SMatthew G. Knepley 
29536ce16762SMatthew G. Knepley   Level: beginner
29546ce16762SMatthew G. Knepley 
2955f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
29566ce16762SMatthew G. Knepley @*/
29576ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
29586ce16762SMatthew G. Knepley {
29596ce16762SMatthew G. Knepley   PetscFunctionBegin;
29606ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29616ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
29626ce16762SMatthew 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);
296347e57110SSander Arens   *off = prob->off[f];
29642764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29652764a2aaSMatthew G. Knepley }
29662764a2aaSMatthew G. Knepley 
2967194d53e6SMatthew G. Knepley /*@
2968194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2969194d53e6SMatthew G. Knepley 
2970194d53e6SMatthew G. Knepley   Not collective
2971194d53e6SMatthew G. Knepley 
2972194d53e6SMatthew G. Knepley   Input Parameter:
2973194d53e6SMatthew G. Knepley . prob - The PetscDS object
2974194d53e6SMatthew G. Knepley 
2975194d53e6SMatthew G. Knepley   Output Parameter:
2976194d53e6SMatthew G. Knepley . offsets - The offsets
2977194d53e6SMatthew G. Knepley 
2978194d53e6SMatthew G. Knepley   Level: beginner
2979194d53e6SMatthew G. Knepley 
2980f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2981194d53e6SMatthew G. Knepley @*/
2982194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2983194d53e6SMatthew G. Knepley {
2984194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2985194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2986194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2987194d53e6SMatthew G. Knepley   *offsets = prob->off;
2988194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2989194d53e6SMatthew G. Knepley }
2990194d53e6SMatthew G. Knepley 
2991194d53e6SMatthew G. Knepley /*@
2992194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2993194d53e6SMatthew G. Knepley 
2994194d53e6SMatthew G. Knepley   Not collective
2995194d53e6SMatthew G. Knepley 
2996194d53e6SMatthew G. Knepley   Input Parameter:
2997194d53e6SMatthew G. Knepley . prob - The PetscDS object
2998194d53e6SMatthew G. Knepley 
2999194d53e6SMatthew G. Knepley   Output Parameter:
3000194d53e6SMatthew G. Knepley . offsets - The offsets
3001194d53e6SMatthew G. Knepley 
3002194d53e6SMatthew G. Knepley   Level: beginner
3003194d53e6SMatthew G. Knepley 
3004f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
3005194d53e6SMatthew G. Knepley @*/
3006194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
3007194d53e6SMatthew G. Knepley {
3008194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3009194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3010194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
3011194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
3012194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
3013194d53e6SMatthew G. Knepley }
3014194d53e6SMatthew G. Knepley 
301568c9edb9SMatthew G. Knepley /*@C
301668c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
301768c9edb9SMatthew G. Knepley 
301868c9edb9SMatthew G. Knepley   Not collective
301968c9edb9SMatthew G. Knepley 
302068c9edb9SMatthew G. Knepley   Input Parameter:
302168c9edb9SMatthew G. Knepley . prob - The PetscDS object
302268c9edb9SMatthew G. Knepley 
3023ef0bb6c7SMatthew G. Knepley   Output Parameter:
3024ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field
302568c9edb9SMatthew G. Knepley 
302668c9edb9SMatthew G. Knepley   Level: intermediate
302768c9edb9SMatthew G. Knepley 
3028f744cafaSSander Arens .seealso: PetscDSCreate()
302968c9edb9SMatthew G. Knepley @*/
3030ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[])
30312764a2aaSMatthew G. Knepley {
30322764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30332764a2aaSMatthew G. Knepley 
30342764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30352764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3036ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
30372764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3038ef0bb6c7SMatthew G. Knepley   *T = prob->T;
30392764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30402764a2aaSMatthew G. Knepley }
30412764a2aaSMatthew G. Knepley 
304268c9edb9SMatthew G. Knepley /*@C
30434d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
304468c9edb9SMatthew G. Knepley 
304568c9edb9SMatthew G. Knepley   Not collective
304668c9edb9SMatthew G. Knepley 
304768c9edb9SMatthew G. Knepley   Input Parameter:
304868c9edb9SMatthew G. Knepley . prob - The PetscDS object
304968c9edb9SMatthew G. Knepley 
3050ef0bb6c7SMatthew G. Knepley   Output Parameter:
305119815104SMartin Diehl . Tf - The basis function and derviative tabulation on each local face at quadrature points for each and field
305268c9edb9SMatthew G. Knepley 
305368c9edb9SMatthew G. Knepley   Level: intermediate
305468c9edb9SMatthew G. Knepley 
305568c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
305668c9edb9SMatthew G. Knepley @*/
3057ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[])
30582764a2aaSMatthew G. Knepley {
30592764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30602764a2aaSMatthew G. Knepley 
30612764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30622764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3063ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
30642764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3065ef0bb6c7SMatthew G. Knepley   *Tf = prob->Tf;
30662764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30672764a2aaSMatthew G. Knepley }
30682764a2aaSMatthew G. Knepley 
30692764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
30702764a2aaSMatthew G. Knepley {
30712764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30722764a2aaSMatthew G. Knepley 
30732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30742764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30752764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
30762764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
30772764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
30782764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
30792764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30802764a2aaSMatthew G. Knepley }
30812764a2aaSMatthew G. Knepley 
30822764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
30832764a2aaSMatthew G. Knepley {
30842764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30852764a2aaSMatthew G. Knepley 
30862764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30872764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30882764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
30892764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
30902764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
30912764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
30922764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
30932764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
30942764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
30952764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30962764a2aaSMatthew G. Knepley }
30972764a2aaSMatthew G. Knepley 
30984bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal)
30992764a2aaSMatthew G. Knepley {
31002764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
31012764a2aaSMatthew G. Knepley 
31022764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31032764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31042764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
31052764a2aaSMatthew G. Knepley   if (x)            {PetscValidPointer(x, 2);            *x            = prob->x;}
31064bee2e38SMatthew G. Knepley   if (basisReal)    {PetscValidPointer(basisReal, 3);    *basisReal    = prob->basisReal;}
31077506b574SStefano Zampini   if (basisDerReal) {PetscValidPointer(basisDerReal, 4); *basisDerReal = prob->basisDerReal;}
31087506b574SStefano Zampini   if (testReal)     {PetscValidPointer(testReal, 5);     *testReal     = prob->testReal;}
31097506b574SStefano Zampini   if (testDerReal)  {PetscValidPointer(testDerReal, 6);  *testDerReal  = prob->testDerReal;}
31102764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31112764a2aaSMatthew G. Knepley }
31122764a2aaSMatthew G. Knepley 
311358ebd649SToby Isaac /*@C
311456cf3b9cSMatthew 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().
311558ebd649SToby Isaac 
3116783e2ec8SMatthew G. Knepley   Collective on ds
3117783e2ec8SMatthew G. Knepley 
311858ebd649SToby Isaac   Input Parameters:
311958ebd649SToby Isaac + ds       - The PetscDS object
31202d47a189SJulian Andrej . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
312158ebd649SToby Isaac . name     - The BC name
312245480ffeSMatthew G. Knepley . label    - The label defining constrained points
312345480ffeSMatthew G. Knepley . Nv       - The number of DMLabel values for constrained points
312445480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
312558ebd649SToby Isaac . field    - The field to constrain
312645480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
312758ebd649SToby Isaac . comps    - An array of constrained component numbers
312858ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
312956cf3b9cSMatthew G. Knepley . bcFunc_t - A pointwise function giving the time derviative of the boundary values, or NULL
313058ebd649SToby Isaac - ctx      - An optional user context for bcFunc
313158ebd649SToby Isaac 
313245480ffeSMatthew G. Knepley   Output Parameters:
313345480ffeSMatthew G. Knepley - bd       - The boundary number
313445480ffeSMatthew G. Knepley 
313558ebd649SToby Isaac   Options Database Keys:
313658ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
313758ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
313858ebd649SToby Isaac 
313956cf3b9cSMatthew G. Knepley   Note:
314056cf3b9cSMatthew 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:
314156cf3b9cSMatthew G. Knepley 
314256cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
314356cf3b9cSMatthew G. Knepley 
314456cf3b9cSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
314556cf3b9cSMatthew G. Knepley 
314656cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
314756cf3b9cSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
314856cf3b9cSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
314956cf3b9cSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
315056cf3b9cSMatthew G. Knepley 
315156cf3b9cSMatthew G. Knepley + dim - the spatial dimension
315256cf3b9cSMatthew G. Knepley . Nf - the number of fields
315356cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
315456cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
315556cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point
315656cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
315756cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
315856cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
315956cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
316056cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
316156cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
316256cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
316356cf3b9cSMatthew G. Knepley . t - current time
316456cf3b9cSMatthew G. Knepley . x - coordinates of the current point
316556cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters
316656cf3b9cSMatthew G. Knepley . constants - constant parameters
316756cf3b9cSMatthew G. Knepley - bcval - output values at the current point
316856cf3b9cSMatthew G. Knepley 
316958ebd649SToby Isaac   Level: developer
317058ebd649SToby Isaac 
317145480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundaryByName(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual()
317258ebd649SToby Isaac @*/
317345480ffeSMatthew G. Knepley PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], DMLabel label, PetscInt Nv, const PetscInt values[], PetscInt field, PetscInt Nc, const PetscInt comps[], void (*bcFunc)(void), void (*bcFunc_t)(void), void *ctx, PetscInt *bd)
317458ebd649SToby Isaac {
317545480ffeSMatthew G. Knepley   DSBoundary     head = ds->boundary, b;
317645480ffeSMatthew G. Knepley   PetscInt       n    = 0;
317745480ffeSMatthew G. Knepley   const char    *lname;
317858ebd649SToby Isaac   PetscErrorCode ierr;
317958ebd649SToby Isaac 
318058ebd649SToby Isaac   PetscFunctionBegin;
318158ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3182783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
318345480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
318445480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4);
318545480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
318645480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
318745480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
318858ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
318958ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
319045480ffeSMatthew G. Knepley   ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr);
319145480ffeSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr);
319245480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr);
319345480ffeSMatthew G. Knepley   if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);}
319445480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr);
319545480ffeSMatthew G. Knepley   if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);}
319645480ffeSMatthew G. Knepley   ierr = PetscObjectGetName((PetscObject) label, &lname);CHKERRQ(ierr);
319745480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr);
3198f971fd6bSMatthew G. Knepley   b->type   = type;
319945480ffeSMatthew G. Knepley   b->label  = label;
320045480ffeSMatthew G. Knepley   b->Nv     = Nv;
320158ebd649SToby Isaac   b->field  = field;
320245480ffeSMatthew G. Knepley   b->Nc     = Nc;
320358ebd649SToby Isaac   b->func   = bcFunc;
320456cf3b9cSMatthew G. Knepley   b->func_t = bcFunc_t;
320558ebd649SToby Isaac   b->ctx    = ctx;
320645480ffeSMatthew G. Knepley   b->next   = NULL;
320745480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
320845480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
320945480ffeSMatthew G. Knepley   while (head) {
321045480ffeSMatthew G. Knepley     if (!head->next) {
321145480ffeSMatthew G. Knepley       head->next = b;
321245480ffeSMatthew G. Knepley       head       = b;
321345480ffeSMatthew G. Knepley     }
321445480ffeSMatthew G. Knepley     head = head->next;
321545480ffeSMatthew G. Knepley     ++n;
321645480ffeSMatthew G. Knepley   }
3217*064a246eSJacob Faibussowitsch   if (bd) {PetscValidIntPointer(bd, 13); *bd = n;}
321845480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
321945480ffeSMatthew G. Knepley }
322045480ffeSMatthew G. Knepley 
322145480ffeSMatthew G. Knepley /*@C
322245480ffeSMatthew G. Knepley   PetscDSAddBoundaryByName - 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().
322345480ffeSMatthew G. Knepley 
322445480ffeSMatthew G. Knepley   Collective on ds
322545480ffeSMatthew G. Knepley 
322645480ffeSMatthew G. Knepley   Input Parameters:
322745480ffeSMatthew G. Knepley + ds       - The PetscDS object
322845480ffeSMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
322945480ffeSMatthew G. Knepley . name     - The BC name
323045480ffeSMatthew G. Knepley . lname    - The naem of the label defining constrained points
323145480ffeSMatthew G. Knepley . Nv       - The number of DMLabel values for constrained points
323245480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
323345480ffeSMatthew G. Knepley . field    - The field to constrain
323445480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
323545480ffeSMatthew G. Knepley . comps    - An array of constrained component numbers
323645480ffeSMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
323745480ffeSMatthew G. Knepley . bcFunc_t - A pointwise function giving the time derviative of the boundary values, or NULL
323845480ffeSMatthew G. Knepley - ctx      - An optional user context for bcFunc
323945480ffeSMatthew G. Knepley 
324045480ffeSMatthew G. Knepley   Output Parameters:
324145480ffeSMatthew G. Knepley - bd       - The boundary number
324245480ffeSMatthew G. Knepley 
324345480ffeSMatthew G. Knepley   Options Database Keys:
324445480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids
324545480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components
324645480ffeSMatthew G. Knepley 
324745480ffeSMatthew G. Knepley   Note:
324845480ffeSMatthew G. Knepley   This function should only be used with DMForest currently, since labels cannot be defined before the underlygin Plex is built.
324945480ffeSMatthew G. Knepley 
325045480ffeSMatthew 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:
325145480ffeSMatthew G. Knepley 
325245480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
325345480ffeSMatthew G. Knepley 
325445480ffeSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
325545480ffeSMatthew G. Knepley 
325645480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
325745480ffeSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
325845480ffeSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
325945480ffeSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
326045480ffeSMatthew G. Knepley 
326145480ffeSMatthew G. Knepley + dim - the spatial dimension
326245480ffeSMatthew G. Knepley . Nf - the number of fields
326345480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
326445480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
326545480ffeSMatthew G. Knepley . u - each field evaluated at the current point
326645480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
326745480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
326845480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
326945480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
327045480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
327145480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
327245480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
327345480ffeSMatthew G. Knepley . t - current time
327445480ffeSMatthew G. Knepley . x - coordinates of the current point
327545480ffeSMatthew G. Knepley . numConstants - number of constant parameters
327645480ffeSMatthew G. Knepley . constants - constant parameters
327745480ffeSMatthew G. Knepley - bcval - output values at the current point
327845480ffeSMatthew G. Knepley 
327945480ffeSMatthew G. Knepley   Level: developer
328045480ffeSMatthew G. Knepley 
328145480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual()
328245480ffeSMatthew G. Knepley @*/
328345480ffeSMatthew G. Knepley PetscErrorCode PetscDSAddBoundaryByName(PetscDS ds, DMBoundaryConditionType type, const char name[], const char lname[], PetscInt Nv, const PetscInt values[], PetscInt field, PetscInt Nc, const PetscInt comps[], void (*bcFunc)(void), void (*bcFunc_t)(void), void *ctx, PetscInt *bd)
328445480ffeSMatthew G. Knepley {
328545480ffeSMatthew G. Knepley   DSBoundary     head = ds->boundary, b;
328645480ffeSMatthew G. Knepley   PetscInt       n    = 0;
328745480ffeSMatthew G. Knepley   PetscErrorCode ierr;
328845480ffeSMatthew G. Knepley 
328945480ffeSMatthew G. Knepley   PetscFunctionBegin;
329045480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
329145480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
329245480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
329345480ffeSMatthew G. Knepley   PetscValidCharPointer(lname, 4);
329445480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
329545480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
329645480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
329745480ffeSMatthew G. Knepley   ierr = PetscNew(&b);CHKERRQ(ierr);
329845480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
329945480ffeSMatthew G. Knepley   ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr);
330045480ffeSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr);
330145480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr);
330245480ffeSMatthew G. Knepley   if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);}
330345480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr);
330445480ffeSMatthew G. Knepley   if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);}
330545480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr);
330645480ffeSMatthew G. Knepley   b->type   = type;
330745480ffeSMatthew G. Knepley   b->label  = NULL;
330845480ffeSMatthew G. Knepley   b->Nv     = Nv;
330945480ffeSMatthew G. Knepley   b->field  = field;
331045480ffeSMatthew G. Knepley   b->Nc     = Nc;
331145480ffeSMatthew G. Knepley   b->func   = bcFunc;
331245480ffeSMatthew G. Knepley   b->func_t = bcFunc_t;
331345480ffeSMatthew G. Knepley   b->ctx    = ctx;
331445480ffeSMatthew G. Knepley   b->next   = NULL;
331545480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
331645480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
331745480ffeSMatthew G. Knepley   while (head) {
331845480ffeSMatthew G. Knepley     if (!head->next) {
331945480ffeSMatthew G. Knepley       head->next = b;
332045480ffeSMatthew G. Knepley       head       = b;
332145480ffeSMatthew G. Knepley     }
332245480ffeSMatthew G. Knepley     head = head->next;
332345480ffeSMatthew G. Knepley     ++n;
332445480ffeSMatthew G. Knepley   }
3325*064a246eSJacob Faibussowitsch   if (bd) {PetscValidIntPointer(bd, 13); *bd = n;}
332658ebd649SToby Isaac   PetscFunctionReturn(0);
332758ebd649SToby Isaac }
332858ebd649SToby Isaac 
3329b67eacb3SMatthew G. Knepley /*@C
333056cf3b9cSMatthew 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().
3331b67eacb3SMatthew G. Knepley 
3332b67eacb3SMatthew G. Knepley   Input Parameters:
3333b67eacb3SMatthew G. Knepley + ds       - The PetscDS object
3334b67eacb3SMatthew G. Knepley . bd       - The boundary condition number
3335b67eacb3SMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
3336b67eacb3SMatthew G. Knepley . name     - The BC name
333745480ffeSMatthew G. Knepley . label    - The label defining constrained points
333845480ffeSMatthew G. Knepley . Nv       - The number of DMLabel ids for constrained points
333945480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
3340b67eacb3SMatthew G. Knepley . field    - The field to constrain
334145480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
3342b67eacb3SMatthew G. Knepley . comps    - An array of constrained component numbers
3343b67eacb3SMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
334456cf3b9cSMatthew G. Knepley . bcFunc_t - A pointwise function giving the time derviative of the boundary values, or NULL
3345b67eacb3SMatthew G. Knepley - ctx      - An optional user context for bcFunc
3346b67eacb3SMatthew G. Knepley 
334756cf3b9cSMatthew G. Knepley   Note:
334856cf3b9cSMatthew 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.
33499a6efb6aSMatthew G. Knepley 
3350b67eacb3SMatthew G. Knepley   Level: developer
3351b67eacb3SMatthew G. Knepley 
33529a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary()
3353b67eacb3SMatthew G. Knepley @*/
335445480ffeSMatthew G. Knepley PetscErrorCode PetscDSUpdateBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType type, const char name[], DMLabel label, PetscInt Nv, const PetscInt values[], PetscInt field, PetscInt Nc, const PetscInt comps[], void (*bcFunc)(void), void (*bcFunc_t)(void), void *ctx)
3355b67eacb3SMatthew G. Knepley {
3356b67eacb3SMatthew G. Knepley   DSBoundary     b = ds->boundary;
3357b67eacb3SMatthew G. Knepley   PetscInt       n = 0;
3358b67eacb3SMatthew G. Knepley   PetscErrorCode ierr;
3359b67eacb3SMatthew G. Knepley 
3360b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
3361b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3362b67eacb3SMatthew G. Knepley   while (b) {
3363b67eacb3SMatthew G. Knepley     if (n == bd) break;
3364b67eacb3SMatthew G. Knepley     b = b->next;
3365b67eacb3SMatthew G. Knepley     ++n;
3366b67eacb3SMatthew G. Knepley   }
3367b67eacb3SMatthew G. Knepley   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
3368b67eacb3SMatthew G. Knepley   if (name) {
3369b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
3370b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
3371b67eacb3SMatthew G. Knepley   }
3372b67eacb3SMatthew G. Knepley   b->type = type;
337345480ffeSMatthew G. Knepley   if (label) {
337445480ffeSMatthew G. Knepley     const char *name;
337545480ffeSMatthew G. Knepley 
337645480ffeSMatthew G. Knepley     b->label = label;
337745480ffeSMatthew G. Knepley     ierr = PetscFree(b->lname);CHKERRQ(ierr);
337845480ffeSMatthew G. Knepley     ierr = PetscObjectGetName((PetscObject) label, &name);CHKERRQ(ierr);
337945480ffeSMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->lname);CHKERRQ(ierr);
338045480ffeSMatthew G. Knepley   }
338145480ffeSMatthew G. Knepley   if (Nv >= 0) {
338245480ffeSMatthew G. Knepley     b->Nv = Nv;
338345480ffeSMatthew G. Knepley     ierr = PetscFree(b->values);CHKERRQ(ierr);
338445480ffeSMatthew G. Knepley     ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr);
338545480ffeSMatthew G. Knepley     if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);}
338645480ffeSMatthew G. Knepley   }
338745480ffeSMatthew G. Knepley   if (field >= 0) b->field = field;
338845480ffeSMatthew G. Knepley   if (Nc >= 0) {
338945480ffeSMatthew G. Knepley     b->Nc = Nc;
339045480ffeSMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
339145480ffeSMatthew G. Knepley     ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr);
339245480ffeSMatthew G. Knepley     if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);}
339345480ffeSMatthew G. Knepley   }
339445480ffeSMatthew G. Knepley   if (bcFunc)   b->func   = bcFunc;
339545480ffeSMatthew G. Knepley   if (bcFunc_t) b->func_t = bcFunc_t;
339645480ffeSMatthew G. Knepley   if (ctx)      b->ctx    = ctx;
3397b67eacb3SMatthew G. Knepley   PetscFunctionReturn(0);
3398b67eacb3SMatthew G. Knepley }
3399b67eacb3SMatthew G. Knepley 
340058ebd649SToby Isaac /*@
340158ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
340258ebd649SToby Isaac 
340358ebd649SToby Isaac   Input Parameters:
340458ebd649SToby Isaac . ds - The PetscDS object
340558ebd649SToby Isaac 
340658ebd649SToby Isaac   Output Parameters:
340758ebd649SToby Isaac . numBd - The number of BC
340858ebd649SToby Isaac 
340958ebd649SToby Isaac   Level: intermediate
341058ebd649SToby Isaac 
341158ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
341258ebd649SToby Isaac @*/
341358ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
341458ebd649SToby Isaac {
341558ebd649SToby Isaac   DSBoundary b = ds->boundary;
341658ebd649SToby Isaac 
341758ebd649SToby Isaac   PetscFunctionBegin;
341858ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
341958ebd649SToby Isaac   PetscValidPointer(numBd, 2);
342058ebd649SToby Isaac   *numBd = 0;
342158ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
342258ebd649SToby Isaac   PetscFunctionReturn(0);
342358ebd649SToby Isaac }
342458ebd649SToby Isaac 
342558ebd649SToby Isaac /*@C
34269a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
342758ebd649SToby Isaac 
342858ebd649SToby Isaac   Input Parameters:
342958ebd649SToby Isaac + ds          - The PetscDS object
343058ebd649SToby Isaac - bd          - The BC number
343158ebd649SToby Isaac 
343258ebd649SToby Isaac   Output Parameters:
343345480ffeSMatthew G. Knepley + wf       - The PetscWeakForm holding the pointwise functions
343445480ffeSMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
343558ebd649SToby Isaac . name     - The BC name
343645480ffeSMatthew G. Knepley . label    - The label defining constrained points
343745480ffeSMatthew G. Knepley . Nv       - The number of DMLabel ids for constrained points
343845480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
343958ebd649SToby Isaac . field    - The field to constrain
344045480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
344158ebd649SToby Isaac . comps    - An array of constrained component numbers
344258ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
344356cf3b9cSMatthew G. Knepley . bcFunc_t - A pointwise function giving the time derviative of the boundary values
344458ebd649SToby Isaac - ctx      - An optional user context for bcFunc
344558ebd649SToby Isaac 
344658ebd649SToby Isaac   Options Database Keys:
344758ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
344858ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
344958ebd649SToby Isaac 
345058ebd649SToby Isaac   Level: developer
345158ebd649SToby Isaac 
345258ebd649SToby Isaac .seealso: PetscDSAddBoundary()
345358ebd649SToby Isaac @*/
345445480ffeSMatthew G. Knepley PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, PetscWeakForm *wf, DMBoundaryConditionType *type, const char *name[], DMLabel *label, PetscInt *Nv, const PetscInt *values[], PetscInt *field, PetscInt *Nc, const PetscInt *comps[], void (**func)(void), void (**func_t)(void), void **ctx)
345558ebd649SToby Isaac {
345658ebd649SToby Isaac   DSBoundary b = ds->boundary;
345758ebd649SToby Isaac   PetscInt   n = 0;
345858ebd649SToby Isaac 
345958ebd649SToby Isaac   PetscFunctionBegin;
346058ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
346158ebd649SToby Isaac   while (b) {
346258ebd649SToby Isaac     if (n == bd) break;
346358ebd649SToby Isaac     b = b->next;
346458ebd649SToby Isaac     ++n;
346558ebd649SToby Isaac   }
346658ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
346745480ffeSMatthew G. Knepley   if (wf) {
346845480ffeSMatthew G. Knepley     PetscValidPointer(wf, 3);
346945480ffeSMatthew G. Knepley     *wf = b->wf;
347045480ffeSMatthew G. Knepley   }
3471f971fd6bSMatthew G. Knepley   if (type) {
347245480ffeSMatthew G. Knepley     PetscValidPointer(type, 4);
3473f971fd6bSMatthew G. Knepley     *type = b->type;
347458ebd649SToby Isaac   }
347558ebd649SToby Isaac   if (name) {
347645480ffeSMatthew G. Knepley     PetscValidPointer(name, 5);
347758ebd649SToby Isaac     *name = b->name;
347858ebd649SToby Isaac   }
347945480ffeSMatthew G. Knepley   if (label) {
348045480ffeSMatthew G. Knepley     PetscValidPointer(label, 6);
348145480ffeSMatthew G. Knepley     *label = b->label;
348245480ffeSMatthew G. Knepley   }
348345480ffeSMatthew G. Knepley   if (Nv) {
348445480ffeSMatthew G. Knepley     PetscValidIntPointer(Nv, 7);
348545480ffeSMatthew G. Knepley     *Nv = b->Nv;
348645480ffeSMatthew G. Knepley   }
348745480ffeSMatthew G. Knepley   if (values) {
348845480ffeSMatthew G. Knepley     PetscValidPointer(values, 8);
348945480ffeSMatthew G. Knepley     *values = b->values;
349058ebd649SToby Isaac   }
349158ebd649SToby Isaac   if (field) {
349245480ffeSMatthew G. Knepley     PetscValidIntPointer(field, 9);
349358ebd649SToby Isaac     *field = b->field;
349458ebd649SToby Isaac   }
349545480ffeSMatthew G. Knepley   if (Nc) {
349645480ffeSMatthew G. Knepley     PetscValidIntPointer(Nc, 10);
349745480ffeSMatthew G. Knepley     *Nc = b->Nc;
349858ebd649SToby Isaac   }
349958ebd649SToby Isaac   if (comps) {
350045480ffeSMatthew G. Knepley     PetscValidPointer(comps, 11);
350158ebd649SToby Isaac     *comps = b->comps;
350258ebd649SToby Isaac   }
350358ebd649SToby Isaac   if (func) {
350445480ffeSMatthew G. Knepley     PetscValidPointer(func, 12);
350558ebd649SToby Isaac     *func = b->func;
350658ebd649SToby Isaac   }
350756cf3b9cSMatthew G. Knepley   if (func_t) {
350845480ffeSMatthew G. Knepley     PetscValidPointer(func_t, 13);
350956cf3b9cSMatthew G. Knepley     *func_t = b->func_t;
351056cf3b9cSMatthew G. Knepley   }
351158ebd649SToby Isaac   if (ctx) {
351245480ffeSMatthew G. Knepley     PetscValidPointer(ctx, 14);
351358ebd649SToby Isaac     *ctx = b->ctx;
351458ebd649SToby Isaac   }
351558ebd649SToby Isaac   PetscFunctionReturn(0);
351658ebd649SToby Isaac }
351758ebd649SToby Isaac 
351845480ffeSMatthew G. Knepley static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew)
351945480ffeSMatthew G. Knepley {
352045480ffeSMatthew G. Knepley   PetscErrorCode ierr;
352145480ffeSMatthew G. Knepley 
352245480ffeSMatthew G. Knepley   PetscFunctionBegin;
352345480ffeSMatthew G. Knepley   ierr = PetscNew(bNew);CHKERRQ(ierr);
352445480ffeSMatthew G. Knepley   ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf);CHKERRQ(ierr);
352545480ffeSMatthew G. Knepley   ierr = PetscWeakFormCopy(b->wf, (*bNew)->wf);CHKERRQ(ierr);
352645480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(b->name,(char **) &((*bNew)->name));CHKERRQ(ierr);
352745480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(b->lname,(char **) &((*bNew)->lname));CHKERRQ(ierr);
352845480ffeSMatthew G. Knepley   (*bNew)->type   = b->type;
352945480ffeSMatthew G. Knepley   (*bNew)->label  = b->label;
353045480ffeSMatthew G. Knepley   (*bNew)->Nv     = b->Nv;
353145480ffeSMatthew G. Knepley   ierr = PetscMalloc1(b->Nv, &(*bNew)->values);CHKERRQ(ierr);
353245480ffeSMatthew G. Knepley   ierr = PetscArraycpy((*bNew)->values, b->values, b->Nv);CHKERRQ(ierr);
353345480ffeSMatthew G. Knepley   (*bNew)->field  = b->field;
353445480ffeSMatthew G. Knepley   (*bNew)->Nc     = b->Nc;
353545480ffeSMatthew G. Knepley   ierr = PetscMalloc1(b->Nc, &(*bNew)->comps);CHKERRQ(ierr);
353645480ffeSMatthew G. Knepley   ierr = PetscArraycpy((*bNew)->comps, b->comps, b->Nc);CHKERRQ(ierr);
353745480ffeSMatthew G. Knepley   (*bNew)->func   = b->func;
353845480ffeSMatthew G. Knepley   (*bNew)->func_t = b->func_t;
353945480ffeSMatthew G. Knepley   (*bNew)->ctx    = b->ctx;
354045480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
354145480ffeSMatthew G. Knepley }
354245480ffeSMatthew G. Knepley 
35439252d075SMatthew G. Knepley /*@
35449252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
35459252d075SMatthew G. Knepley 
35469252d075SMatthew G. Knepley   Not collective
35479252d075SMatthew G. Knepley 
354836951cb5SMatthew G. Knepley   Input Parameters:
354936951cb5SMatthew G. Knepley + ds        - The source PetscDS object
355036951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields
355136951cb5SMatthew G. Knepley - fields    - The selected fields, or NULL for all fields
35529252d075SMatthew G. Knepley 
35539252d075SMatthew G. Knepley   Output Parameter:
355436951cb5SMatthew G. Knepley . newds     - The target PetscDS, now with a copy of the boundary conditions
35559252d075SMatthew G. Knepley 
35569252d075SMatthew G. Knepley   Level: intermediate
35579252d075SMatthew G. Knepley 
35589252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
35599252d075SMatthew G. Knepley @*/
356036951cb5SMatthew G. Knepley PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds)
3561dff059c6SToby Isaac {
356245480ffeSMatthew G. Knepley   DSBoundary     b, *lastnext;
3563dff059c6SToby Isaac   PetscErrorCode ierr;
3564dff059c6SToby Isaac 
3565dff059c6SToby Isaac   PetscFunctionBegin;
356636951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(ds,    PETSCDS_CLASSID, 1);
356736951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4);
356836951cb5SMatthew G. Knepley   if (ds == newds) PetscFunctionReturn(0);
356945480ffeSMatthew G. Knepley   ierr = PetscDSDestroyBoundary(newds);CHKERRQ(ierr);
357036951cb5SMatthew G. Knepley   lastnext = &(newds->boundary);
357136951cb5SMatthew G. Knepley   for (b = ds->boundary; b; b = b->next) {
3572dff059c6SToby Isaac     DSBoundary bNew;
357336951cb5SMatthew G. Knepley     PetscInt   fieldNew = -1;
3574dff059c6SToby Isaac 
357536951cb5SMatthew G. Knepley     if (numFields > 0 && fields) {
357636951cb5SMatthew G. Knepley       PetscInt f;
357736951cb5SMatthew G. Knepley 
357836951cb5SMatthew G. Knepley       for (f = 0; f < numFields; ++f) if (b->field == fields[f]) break;
357936951cb5SMatthew G. Knepley       if (f == numFields) continue;
358036951cb5SMatthew G. Knepley       fieldNew = f;
358136951cb5SMatthew G. Knepley     }
358245480ffeSMatthew G. Knepley     ierr = DSBoundaryDuplicate_Internal(b, &bNew);CHKERRQ(ierr);
358336951cb5SMatthew G. Knepley     bNew->field = fieldNew < 0 ? b->field : fieldNew;
3584dff059c6SToby Isaac     *lastnext = bNew;
3585dff059c6SToby Isaac     lastnext  = &(bNew->next);
3586dff059c6SToby Isaac   }
3587dff059c6SToby Isaac   PetscFunctionReturn(0);
3588dff059c6SToby Isaac }
3589dff059c6SToby Isaac 
35906c1eb96dSMatthew G. Knepley /*@
359145480ffeSMatthew G. Knepley   PetscDSDestroyBoundary - Remove all DMBoundary objects from the PetscDS
359245480ffeSMatthew G. Knepley 
359345480ffeSMatthew G. Knepley   Not collective
359445480ffeSMatthew G. Knepley 
359545480ffeSMatthew G. Knepley   Input Parameter:
359645480ffeSMatthew G. Knepley . ds - The PetscDS object
359745480ffeSMatthew G. Knepley 
359845480ffeSMatthew G. Knepley   Level: intermediate
359945480ffeSMatthew G. Knepley 
360045480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations()
360145480ffeSMatthew G. Knepley @*/
360245480ffeSMatthew G. Knepley PetscErrorCode PetscDSDestroyBoundary(PetscDS ds)
360345480ffeSMatthew G. Knepley {
360445480ffeSMatthew G. Knepley   DSBoundary     next = ds->boundary;
360545480ffeSMatthew G. Knepley   PetscErrorCode ierr;
360645480ffeSMatthew G. Knepley 
360745480ffeSMatthew G. Knepley   PetscFunctionBegin;
360845480ffeSMatthew G. Knepley   while (next) {
360945480ffeSMatthew G. Knepley     DSBoundary b = next;
361045480ffeSMatthew G. Knepley 
361145480ffeSMatthew G. Knepley     next = b->next;
361245480ffeSMatthew G. Knepley     ierr = PetscWeakFormDestroy(&b->wf);CHKERRQ(ierr);
361345480ffeSMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
361445480ffeSMatthew G. Knepley     ierr = PetscFree(b->lname);CHKERRQ(ierr);
361545480ffeSMatthew G. Knepley     ierr = PetscFree(b->values);CHKERRQ(ierr);
361645480ffeSMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
361745480ffeSMatthew G. Knepley     ierr = PetscFree(b);CHKERRQ(ierr);
361845480ffeSMatthew G. Knepley   }
361945480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
362045480ffeSMatthew G. Knepley }
362145480ffeSMatthew G. Knepley 
362245480ffeSMatthew G. Knepley /*@
36236c1eb96dSMatthew G. Knepley   PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout
36246c1eb96dSMatthew G. Knepley 
36256c1eb96dSMatthew G. Knepley   Not collective
36266c1eb96dSMatthew G. Knepley 
36276c1eb96dSMatthew G. Knepley   Input Parameter:
36286c1eb96dSMatthew G. Knepley + prob - The PetscDS object
36296c1eb96dSMatthew G. Knepley . numFields - Number of new fields
36306c1eb96dSMatthew G. Knepley - fields - Old field number for each new field
36316c1eb96dSMatthew G. Knepley 
36326c1eb96dSMatthew G. Knepley   Output Parameter:
36336c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy
36346c1eb96dSMatthew G. Knepley 
36356c1eb96dSMatthew G. Knepley   Level: intermediate
36366c1eb96dSMatthew G. Knepley 
36376c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectEquations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
36386c1eb96dSMatthew G. Knepley @*/
36396c1eb96dSMatthew G. Knepley PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
36406c1eb96dSMatthew G. Knepley {
36416c1eb96dSMatthew G. Knepley   PetscInt       Nf, Nfn, fn;
36426c1eb96dSMatthew G. Knepley   PetscErrorCode ierr;
36436c1eb96dSMatthew G. Knepley 
36446c1eb96dSMatthew G. Knepley   PetscFunctionBegin;
36456c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
36466c1eb96dSMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
36476c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
36486c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
36496c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
365045480ffeSMatthew G. Knepley   numFields = numFields < 0 ? Nf : numFields;
36516c1eb96dSMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
36526c1eb96dSMatthew G. Knepley     const PetscInt f = fields ? fields[fn] : fn;
36536c1eb96dSMatthew G. Knepley     PetscObject    disc;
36546c1eb96dSMatthew G. Knepley 
36556c1eb96dSMatthew G. Knepley     if (f >= Nf) continue;
36566c1eb96dSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &disc);CHKERRQ(ierr);
36576c1eb96dSMatthew G. Knepley     ierr = PetscDSSetDiscretization(newprob, fn, disc);CHKERRQ(ierr);
36586c1eb96dSMatthew G. Knepley   }
36596c1eb96dSMatthew G. Knepley   PetscFunctionReturn(0);
36606c1eb96dSMatthew G. Knepley }
36616c1eb96dSMatthew G. Knepley 
36626c1eb96dSMatthew G. Knepley /*@
36639252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
36649252d075SMatthew G. Knepley 
36659252d075SMatthew G. Knepley   Not collective
36669252d075SMatthew G. Knepley 
36679252d075SMatthew G. Knepley   Input Parameter:
36689252d075SMatthew G. Knepley + prob - The PetscDS object
36699252d075SMatthew G. Knepley . numFields - Number of new fields
36709252d075SMatthew G. Knepley - fields - Old field number for each new field
36719252d075SMatthew G. Knepley 
36729252d075SMatthew G. Knepley   Output Parameter:
36739252d075SMatthew G. Knepley . newprob - The PetscDS copy
36749252d075SMatthew G. Knepley 
36759252d075SMatthew G. Knepley   Level: intermediate
36769252d075SMatthew G. Knepley 
36776c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectDiscretizations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
36789252d075SMatthew G. Knepley @*/
36799252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
36809252d075SMatthew G. Knepley {
36819252d075SMatthew G. Knepley   PetscInt       Nf, Nfn, fn, gn;
36829252d075SMatthew G. Knepley   PetscErrorCode ierr;
36839252d075SMatthew G. Knepley 
36849252d075SMatthew G. Knepley   PetscFunctionBegin;
36859252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
36869252d075SMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
36879252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
36889252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
36899252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
36909252d075SMatthew 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);
36919252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
36929252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
36939252d075SMatthew G. Knepley     PetscPointFunc   obj;
36949252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
36959252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
36969252d075SMatthew G. Knepley     PetscRiemannFunc r;
36979252d075SMatthew G. Knepley 
3698c52f1e13SMatthew G. Knepley     if (f >= Nf) continue;
36999252d075SMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
37009252d075SMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
37019252d075SMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
37029252d075SMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
37039252d075SMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr);
37049252d075SMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr);
37059252d075SMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr);
37069252d075SMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr);
37079252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
37089252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
37099252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
37109252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
37119252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
37129252d075SMatthew G. Knepley 
3713c52f1e13SMatthew G. Knepley       if (g >= Nf) continue;
37149252d075SMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
37159252d075SMatthew G. Knepley       ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr);
37169252d075SMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
37179252d075SMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr);
37186c1eb96dSMatthew G. Knepley       ierr = PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr);
37199252d075SMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
37209252d075SMatthew G. Knepley     }
37219252d075SMatthew G. Knepley   }
37229252d075SMatthew G. Knepley   PetscFunctionReturn(0);
37239252d075SMatthew G. Knepley }
37249252d075SMatthew G. Knepley 
3725da51fcedSMatthew G. Knepley /*@
3726da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
3727da51fcedSMatthew G. Knepley 
3728da51fcedSMatthew G. Knepley   Not collective
3729da51fcedSMatthew G. Knepley 
3730da51fcedSMatthew G. Knepley   Input Parameter:
3731da51fcedSMatthew G. Knepley . prob - The PetscDS object
3732da51fcedSMatthew G. Knepley 
3733da51fcedSMatthew G. Knepley   Output Parameter:
3734da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
3735da51fcedSMatthew G. Knepley 
3736da51fcedSMatthew G. Knepley   Level: intermediate
3737da51fcedSMatthew G. Knepley 
37389252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
3739da51fcedSMatthew G. Knepley @*/
3740da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
3741da51fcedSMatthew G. Knepley {
37429252d075SMatthew G. Knepley   PetscInt       Nf, Ng;
3743da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
3744da51fcedSMatthew G. Knepley 
3745da51fcedSMatthew G. Knepley   PetscFunctionBegin;
3746da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3747da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
3748da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3749da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
375013903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
37519252d075SMatthew G. Knepley   ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr);
37529252d075SMatthew G. Knepley   PetscFunctionReturn(0);
37539252d075SMatthew G. Knepley }
375445480ffeSMatthew G. Knepley 
37559252d075SMatthew G. Knepley /*@
37569252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
3757da51fcedSMatthew G. Knepley 
37589252d075SMatthew G. Knepley   Not collective
37599252d075SMatthew G. Knepley 
37609252d075SMatthew G. Knepley   Input Parameter:
37619252d075SMatthew G. Knepley . prob - The PetscDS object
37629252d075SMatthew G. Knepley 
37639252d075SMatthew G. Knepley   Output Parameter:
37649252d075SMatthew G. Knepley . newprob - The PetscDS copy
37659252d075SMatthew G. Knepley 
37669252d075SMatthew G. Knepley   Level: intermediate
37679252d075SMatthew G. Knepley 
37689252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
37699252d075SMatthew G. Knepley @*/
37709252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
37719252d075SMatthew G. Knepley {
37729252d075SMatthew G. Knepley   PetscInt           Nc;
37739252d075SMatthew G. Knepley   const PetscScalar *constants;
37749252d075SMatthew G. Knepley   PetscErrorCode     ierr;
37759252d075SMatthew G. Knepley 
37769252d075SMatthew G. Knepley   PetscFunctionBegin;
37779252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
37789252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
37799252d075SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr);
37809252d075SMatthew G. Knepley   ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr);
3781da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
3782da51fcedSMatthew G. Knepley }
3783da51fcedSMatthew G. Knepley 
378445480ffeSMatthew G. Knepley /*@
378545480ffeSMatthew G. Knepley   PetscDSCopyExactSolutions - Copy all exact solutions to the new problem
378645480ffeSMatthew G. Knepley 
378745480ffeSMatthew G. Knepley   Not collective
378845480ffeSMatthew G. Knepley 
378945480ffeSMatthew G. Knepley   Input Parameter:
379045480ffeSMatthew G. Knepley . ds - The PetscDS object
379145480ffeSMatthew G. Knepley 
379245480ffeSMatthew G. Knepley   Output Parameter:
379345480ffeSMatthew G. Knepley . newds - The PetscDS copy
379445480ffeSMatthew G. Knepley 
379545480ffeSMatthew G. Knepley   Level: intermediate
379645480ffeSMatthew G. Knepley 
379745480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
379845480ffeSMatthew G. Knepley @*/
379945480ffeSMatthew G. Knepley PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds)
380045480ffeSMatthew G. Knepley {
380145480ffeSMatthew G. Knepley   PetscSimplePointFunc sol;
380245480ffeSMatthew G. Knepley   void                *ctx;
380345480ffeSMatthew G. Knepley   PetscInt             Nf, f;
380445480ffeSMatthew G. Knepley   PetscErrorCode       ierr;
380545480ffeSMatthew G. Knepley 
380645480ffeSMatthew G. Knepley   PetscFunctionBegin;
380745480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
380845480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2);
380945480ffeSMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
381045480ffeSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
381145480ffeSMatthew G. Knepley     ierr = PetscDSGetExactSolution(ds,    f, &sol, &ctx);CHKERRQ(ierr);
381245480ffeSMatthew G. Knepley     ierr = PetscDSSetExactSolution(newds, f,  sol,  ctx);CHKERRQ(ierr);
381345480ffeSMatthew G. Knepley     ierr = PetscDSGetExactSolutionTimeDerivative(ds,    f, &sol, &ctx);CHKERRQ(ierr);
381445480ffeSMatthew G. Knepley     ierr = PetscDSSetExactSolutionTimeDerivative(newds, f,  sol,  ctx);CHKERRQ(ierr);
381545480ffeSMatthew G. Knepley   }
381645480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
381745480ffeSMatthew G. Knepley }
381845480ffeSMatthew G. Knepley 
3819b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
3820b1353e8eSMatthew G. Knepley {
3821df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
3822b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
3823b1353e8eSMatthew G. Knepley 
3824b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
3825b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3826b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
3827b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
3828b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3829df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
3830df3a45bdSMatthew 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);
3831df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
3832df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
3833b1353e8eSMatthew G. Knepley     PetscInt cdim;
3834b1353e8eSMatthew G. Knepley 
3835df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
3836b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
3837df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
3838b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
3839b1353e8eSMatthew G. Knepley       PetscFE      subfe;
3840b1353e8eSMatthew G. Knepley       PetscObject  obj;
3841b1353e8eSMatthew G. Knepley       PetscClassId id;
3842b1353e8eSMatthew G. Knepley 
3843b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3844b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3845b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
3846b1353e8eSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
3847df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
3848b1353e8eSMatthew G. Knepley     }
3849b1353e8eSMatthew G. Knepley   }
3850df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
3851b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
3852b1353e8eSMatthew G. Knepley }
3853b1353e8eSMatthew G. Knepley 
3854665f567fSMatthew G. Knepley PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype)
3855c7bd5f0bSMatthew G. Knepley {
3856c7bd5f0bSMatthew G. Knepley   PetscObject    obj;
3857c7bd5f0bSMatthew G. Knepley   PetscClassId   id;
3858c7bd5f0bSMatthew G. Knepley   PetscInt       Nf;
3859c7bd5f0bSMatthew G. Knepley   PetscErrorCode ierr;
3860c7bd5f0bSMatthew G. Knepley 
3861c7bd5f0bSMatthew G. Knepley   PetscFunctionBegin;
3862c7bd5f0bSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3863665f567fSMatthew G. Knepley   PetscValidPointer(disctype, 3);
3864665f567fSMatthew G. Knepley   *disctype = PETSC_DISC_NONE;
3865c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
3866c7bd5f0bSMatthew G. Knepley   if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf);
3867c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr);
3868665f567fSMatthew G. Knepley   if (obj) {
3869c7bd5f0bSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3870665f567fSMatthew G. Knepley     if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE;
3871665f567fSMatthew G. Knepley     else                       *disctype = PETSC_DISC_FV;
3872665f567fSMatthew G. Knepley   }
3873c7bd5f0bSMatthew G. Knepley   PetscFunctionReturn(0);
3874c7bd5f0bSMatthew G. Knepley }
3875c7bd5f0bSMatthew G. Knepley 
38766528b96dSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds)
38772764a2aaSMatthew G. Knepley {
3878931fb3b8SToby Isaac   PetscErrorCode ierr;
3879931fb3b8SToby Isaac 
38802764a2aaSMatthew G. Knepley   PetscFunctionBegin;
38816528b96dSMatthew G. Knepley   ierr = PetscFree(ds->data);CHKERRQ(ierr);
38822764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
38832764a2aaSMatthew G. Knepley }
38842764a2aaSMatthew G. Knepley 
38856528b96dSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds)
38862764a2aaSMatthew G. Knepley {
38872764a2aaSMatthew G. Knepley   PetscFunctionBegin;
38886528b96dSMatthew G. Knepley   ds->ops->setfromoptions = NULL;
38896528b96dSMatthew G. Knepley   ds->ops->setup          = NULL;
38906528b96dSMatthew G. Knepley   ds->ops->view           = NULL;
38916528b96dSMatthew G. Knepley   ds->ops->destroy        = PetscDSDestroy_Basic;
38922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
38932764a2aaSMatthew G. Knepley }
38942764a2aaSMatthew G. Knepley 
38952764a2aaSMatthew G. Knepley /*MC
38962764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
38972764a2aaSMatthew G. Knepley 
38982764a2aaSMatthew G. Knepley   Level: intermediate
38992764a2aaSMatthew G. Knepley 
39002764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
39012764a2aaSMatthew G. Knepley M*/
39022764a2aaSMatthew G. Knepley 
39036528b96dSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds)
39042764a2aaSMatthew G. Knepley {
39052764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
39062764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
39072764a2aaSMatthew G. Knepley 
39082764a2aaSMatthew G. Knepley   PetscFunctionBegin;
39096528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
39106528b96dSMatthew G. Knepley   ierr = PetscNewLog(ds, &b);CHKERRQ(ierr);
39116528b96dSMatthew G. Knepley   ds->data = b;
39122764a2aaSMatthew G. Knepley 
39136528b96dSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(ds);CHKERRQ(ierr);
39142764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
39152764a2aaSMatthew G. Knepley }
3916