xref: /petsc/src/dm/dt/interface/dtds.c (revision 2c71b3e237ead271e4f3aa1505f92bf476e3413d)
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);
95*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(!r,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 
1355fedec97SMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS ds, PetscViewer viewer)
1367d8a60eaSMatthew G. Knepley {
1377d8a60eaSMatthew G. Knepley   PetscViewerFormat  format;
13897b6e6e8SMatthew G. Knepley   const PetscScalar *constants;
1395fedec97SMatthew G. Knepley   PetscInt           Nf, numConstants, f;
1407d8a60eaSMatthew G. Knepley   PetscErrorCode     ierr;
1417d8a60eaSMatthew G. Knepley 
1427d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1435fedec97SMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
1447d8a60eaSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
1455fedec97SMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", Nf);CHKERRQ(ierr);
1467d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1475fedec97SMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "  cell total dim %D total comp %D\n", ds->totDim, ds->totComp);CHKERRQ(ierr);
1485fedec97SMatthew G. Knepley   if (ds->isCohesive) {ierr = PetscViewerASCIIPrintf(viewer, "  cohesive cell\n");CHKERRQ(ierr);}
1495fedec97SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
15040967b3bSMatthew G. Knepley     DSBoundary      b;
1517d8a60eaSMatthew G. Knepley     PetscObject     obj;
1527d8a60eaSMatthew G. Knepley     PetscClassId    id;
153f35450b9SMatthew G. Knepley     PetscQuadrature q;
1547d8a60eaSMatthew G. Knepley     const char     *name;
155f35450b9SMatthew G. Knepley     PetscInt        Nc, Nq, Nqc;
1567d8a60eaSMatthew G. Knepley 
1575fedec97SMatthew G. Knepley     ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr);
1587d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
1597d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr);
1607d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr);
1614727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
1627d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
1637d8a60eaSMatthew G. Knepley       ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr);
164f35450b9SMatthew G. Knepley       ierr = PetscFEGetQuadrature((PetscFE) obj, &q);CHKERRQ(ierr);
1657d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr);
1667d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1677d8a60eaSMatthew G. Knepley       ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr);
168f35450b9SMatthew G. Knepley       ierr = PetscFVGetQuadrature((PetscFV) obj, &q);CHKERRQ(ierr);
1697d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr);
1707d8a60eaSMatthew G. Knepley     }
17198921bdaSJacob Faibussowitsch     else SETERRQ(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f);
17297b6e6e8SMatthew G. Knepley     if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, " %D components", Nc);CHKERRQ(ierr);}
17397b6e6e8SMatthew G. Knepley     else        {ierr = PetscViewerASCIIPrintf(viewer, " %D component ", Nc);CHKERRQ(ierr);}
1745fedec97SMatthew G. Knepley     if (ds->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);}
175249df284SMatthew G. Knepley     else                 {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);}
1763e60c2a6SMatthew G. Knepley     if (q) {
177f35450b9SMatthew G. Knepley       ierr = PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL);CHKERRQ(ierr);
178f35450b9SMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " (Nq %D Nqc %D)", Nq, Nqc);CHKERRQ(ierr);
1793e60c2a6SMatthew G. Knepley     }
1805fedec97SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, " %D-jet", ds->jetDegree[f]);CHKERRQ(ierr);
1817d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
1824727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
1835d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1847d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);}
1857d8a60eaSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);}
1865d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
18740967b3bSMatthew G. Knepley 
1885fedec97SMatthew G. Knepley     for (b = ds->boundary; b; b = b->next) {
18906ad1575SMatthew G. Knepley       char     *name;
19040967b3bSMatthew G. Knepley       PetscInt  c, i;
19140967b3bSMatthew G. Knepley 
19240967b3bSMatthew G. Knepley       if (b->field != f) continue;
19340967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
19445480ffeSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->lname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr);
19545480ffeSMatthew G. Knepley       if (!b->Nc) {
19640967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "  all components\n");CHKERRQ(ierr);
19740967b3bSMatthew G. Knepley       } else {
19840967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "  components: ");CHKERRQ(ierr);
19940967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
20045480ffeSMatthew G. Knepley         for (c = 0; c < b->Nc; ++c) {
20140967b3bSMatthew G. Knepley           if (c > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
20240967b3bSMatthew G. Knepley           ierr = PetscViewerASCIIPrintf(viewer, "%D", b->comps[c]);CHKERRQ(ierr);
20340967b3bSMatthew G. Knepley         }
20440967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
20540967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
20640967b3bSMatthew G. Knepley       }
20745480ffeSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "  values: ");CHKERRQ(ierr);
20840967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
20945480ffeSMatthew G. Knepley       for (i = 0; i < b->Nv; ++i) {
21040967b3bSMatthew G. Knepley         if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
21145480ffeSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "%D", b->values[i]);CHKERRQ(ierr);
21240967b3bSMatthew G. Knepley       }
21340967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
21440967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
2158e0d8d9cSMatthew G. Knepley       if (b->func) {
2168e0d8d9cSMatthew G. Knepley         ierr = PetscDLAddr(b->func, &name);CHKERRQ(ierr);
2178e0d8d9cSMatthew G. Knepley         if (name) {ierr = PetscViewerASCIIPrintf(viewer, "  func: %s\n", name);CHKERRQ(ierr);}
2188e0d8d9cSMatthew G. Knepley         else      {ierr = PetscViewerASCIIPrintf(viewer, "  func: %p\n", b->func);CHKERRQ(ierr);}
21906ad1575SMatthew G. Knepley         ierr = PetscFree(name);CHKERRQ(ierr);
2208e0d8d9cSMatthew G. Knepley       }
2218e0d8d9cSMatthew G. Knepley       if (b->func_t) {
2228e0d8d9cSMatthew G. Knepley         ierr = PetscDLAddr(b->func_t, &name);CHKERRQ(ierr);
2232e144d55SMatthew G. Knepley         if (name) {ierr = PetscViewerASCIIPrintf(viewer, "  func_t: %s\n", name);CHKERRQ(ierr);}
2242e144d55SMatthew G. Knepley         else      {ierr = PetscViewerASCIIPrintf(viewer, "  func_t: %p\n", b->func_t);CHKERRQ(ierr);}
22506ad1575SMatthew G. Knepley         ierr = PetscFree(name);CHKERRQ(ierr);
2268e0d8d9cSMatthew G. Knepley       }
22745480ffeSMatthew G. Knepley       ierr = PetscWeakFormView(b->wf, viewer);CHKERRQ(ierr);
22840967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
22940967b3bSMatthew G. Knepley     }
2307d8a60eaSMatthew G. Knepley   }
2315fedec97SMatthew G. Knepley   ierr = PetscDSGetConstants(ds, &numConstants, &constants);CHKERRQ(ierr);
23297b6e6e8SMatthew G. Knepley   if (numConstants) {
23397b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr);
23497b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
23557fc01e9SMatthew G. Knepley     for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);}
23697b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
23797b6e6e8SMatthew G. Knepley   }
2385fedec97SMatthew G. Knepley   ierr = PetscWeakFormView(ds->wf, viewer);CHKERRQ(ierr);
2397d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
2407d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
2417d8a60eaSMatthew G. Knepley }
2427d8a60eaSMatthew G. Knepley 
2432764a2aaSMatthew G. Knepley /*@C
244fe2efc57SMark    PetscDSViewFromOptions - View from Options
245fe2efc57SMark 
246fe2efc57SMark    Collective on PetscDS
247fe2efc57SMark 
248fe2efc57SMark    Input Parameters:
249fe2efc57SMark +  A - the PetscDS object
250736c3998SJose E. Roman .  obj - Optional object
251736c3998SJose E. Roman -  name - command line option
252fe2efc57SMark 
253fe2efc57SMark    Level: intermediate
254fe2efc57SMark .seealso:  PetscDS, PetscDSView, PetscObjectViewFromOptions(), PetscDSCreate()
255fe2efc57SMark @*/
256fe2efc57SMark PetscErrorCode  PetscDSViewFromOptions(PetscDS A,PetscObject obj,const char name[])
257fe2efc57SMark {
258fe2efc57SMark   PetscErrorCode ierr;
259fe2efc57SMark 
260fe2efc57SMark   PetscFunctionBegin;
261fe2efc57SMark   PetscValidHeaderSpecific(A,PETSCDS_CLASSID,1);
262fe2efc57SMark   ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr);
263fe2efc57SMark   PetscFunctionReturn(0);
264fe2efc57SMark }
265fe2efc57SMark 
266fe2efc57SMark /*@C
2672764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
2682764a2aaSMatthew G. Knepley 
269d083f849SBarry Smith   Collective on prob
2702764a2aaSMatthew G. Knepley 
271d8d19677SJose E. Roman   Input Parameters:
2722764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
2732764a2aaSMatthew G. Knepley - v  - the viewer
2742764a2aaSMatthew G. Knepley 
2752764a2aaSMatthew G. Knepley   Level: developer
2762764a2aaSMatthew G. Knepley 
2772764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
2782764a2aaSMatthew G. Knepley @*/
2792764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
2802764a2aaSMatthew G. Knepley {
2817d8a60eaSMatthew G. Knepley   PetscBool      iascii;
2822764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2832764a2aaSMatthew G. Knepley 
2842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2852764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2862764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
2877d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
2887d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
2897d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2902764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2912764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2922764a2aaSMatthew G. Knepley }
2932764a2aaSMatthew G. Knepley 
2942764a2aaSMatthew G. Knepley /*@
2952764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2962764a2aaSMatthew G. Knepley 
297d083f849SBarry Smith   Collective on prob
2982764a2aaSMatthew G. Knepley 
2992764a2aaSMatthew G. Knepley   Input Parameter:
3002764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
3012764a2aaSMatthew G. Knepley 
3022764a2aaSMatthew G. Knepley   Options Database:
30355c1f793SMatthew G. Knepley + -petscds_type <type>     : Set the DS type
30455c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS
30555c1f793SMatthew G. Knepley . -petscds_jac_pre         : Turn formation of a separate Jacobian preconditioner on and off
30655c1f793SMatthew G. Knepley . -bc_<name> <ids>         : Specify a list of label ids for a boundary condition
30755c1f793SMatthew G. Knepley - -bc_<name>_comp <comps>  : Specify a list of field components to constrain for a boundary condition
3082764a2aaSMatthew G. Knepley 
3092764a2aaSMatthew G. Knepley   Level: developer
3102764a2aaSMatthew G. Knepley 
3112764a2aaSMatthew G. Knepley .seealso PetscDSView()
3122764a2aaSMatthew G. Knepley @*/
3132764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
3142764a2aaSMatthew G. Knepley {
315f1fd5e65SToby Isaac   DSBoundary     b;
3162764a2aaSMatthew G. Knepley   const char    *defaultType;
3172764a2aaSMatthew G. Knepley   char           name[256];
3182764a2aaSMatthew G. Knepley   PetscBool      flg;
3192764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3202764a2aaSMatthew G. Knepley 
3212764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3222764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3232764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
3242764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
3252764a2aaSMatthew G. Knepley   } else {
3262764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
3272764a2aaSMatthew G. Knepley   }
3280f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
3292764a2aaSMatthew G. Knepley 
3302764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
331f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
332f1fd5e65SToby Isaac     char       optname[1024];
333f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
334f1fd5e65SToby Isaac     PetscBool  flg;
335f1fd5e65SToby Isaac 
336f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
337f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
338f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
339f1fd5e65SToby Isaac     if (flg) {
34045480ffeSMatthew G. Knepley       b->Nv = len;
34145480ffeSMatthew G. Knepley       ierr = PetscFree(b->values);CHKERRQ(ierr);
34245480ffeSMatthew G. Knepley       ierr = PetscMalloc1(len, &b->values);CHKERRQ(ierr);
34345480ffeSMatthew G. Knepley       ierr = PetscArraycpy(b->values, ids, len);CHKERRQ(ierr);
34445480ffeSMatthew G. Knepley       ierr = PetscWeakFormRewriteKeys(b->wf, b->label, len, b->values);CHKERRQ(ierr);
345f1fd5e65SToby Isaac     }
346e7b0402cSSander Arens     len = 1024;
347f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
348f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
349f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
350f1fd5e65SToby Isaac     if (flg) {
35145480ffeSMatthew G. Knepley       b->Nc = len;
352f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
353f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
354580bdb30SBarry Smith       ierr = PetscArraycpy(b->comps, ids, len);CHKERRQ(ierr);
355f1fd5e65SToby Isaac     }
356f1fd5e65SToby Isaac   }
3572764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
3582764a2aaSMatthew G. Knepley   if (flg) {
3592764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
3602764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
3612764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
3622764a2aaSMatthew G. Knepley   }
36355c1f793SMatthew G. Knepley   ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr);
3642764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
3652764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
3660633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
3672764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
3685d160056SMatthew G. Knepley   if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);}
3692764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3702764a2aaSMatthew G. Knepley }
3712764a2aaSMatthew G. Knepley 
3722764a2aaSMatthew G. Knepley /*@C
3732764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
3742764a2aaSMatthew G. Knepley 
375d083f849SBarry Smith   Collective on prob
3762764a2aaSMatthew G. Knepley 
3772764a2aaSMatthew G. Knepley   Input Parameter:
3782764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
3792764a2aaSMatthew G. Knepley 
3802764a2aaSMatthew G. Knepley   Level: developer
3812764a2aaSMatthew G. Knepley 
3822764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
3832764a2aaSMatthew G. Knepley @*/
3842764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
3852764a2aaSMatthew G. Knepley {
3862764a2aaSMatthew G. Knepley   const PetscInt Nf   = prob->Nf;
387f9244615SMatthew G. Knepley   PetscBool      hasH = PETSC_FALSE;
3884bee2e38SMatthew G. Knepley   PetscInt       dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f;
3892764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3902764a2aaSMatthew G. Knepley 
3912764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3922764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3932764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3942764a2aaSMatthew G. Knepley   /* Calculate sizes */
3952764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
396d1506c7cSMatthew G. Knepley   ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr);
397f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
39847e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
399f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
4009ee2af8cSMatthew G. Knepley   ierr = PetscCalloc6(Nf+1,&prob->offCohesive[0],Nf+1,&prob->offCohesive[1],Nf+1,&prob->offCohesive[2],Nf+1,&prob->offDerCohesive[0],Nf+1,&prob->offDerCohesive[1],Nf+1,&prob->offDerCohesive[2]);CHKERRQ(ierr);
401ef0bb6c7SMatthew G. Knepley   ierr = PetscMalloc2(Nf,&prob->T,Nf,&prob->Tf);CHKERRQ(ierr);
4022764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
4039de99aefSMatthew G. Knepley     PetscObject     obj;
4049de99aefSMatthew G. Knepley     PetscClassId    id;
405665f567fSMatthew G. Knepley     PetscQuadrature q = NULL;
4069de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
4072764a2aaSMatthew G. Knepley 
4089de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
409f9244615SMatthew G. Knepley     if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE;
410665f567fSMatthew G. Knepley     if (!obj) {
411665f567fSMatthew G. Knepley       /* Empty mesh */
412665f567fSMatthew G. Knepley       Nb = Nc = 0;
413665f567fSMatthew G. Knepley       prob->T[f] = prob->Tf[f] = NULL;
414665f567fSMatthew G. Knepley     } else {
4159de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
4169de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {
4179de99aefSMatthew G. Knepley         PetscFE fe = (PetscFE) obj;
4189de99aefSMatthew G. Knepley 
4192764a2aaSMatthew G. Knepley         ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
4202764a2aaSMatthew G. Knepley         ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
4212764a2aaSMatthew G. Knepley         ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
422f9244615SMatthew G. Knepley         ierr = PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f]);CHKERRQ(ierr);
423f9244615SMatthew G. Knepley         ierr = PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f]);CHKERRQ(ierr);
4249de99aefSMatthew G. Knepley       } else if (id == PETSCFV_CLASSID) {
4259de99aefSMatthew G. Knepley         PetscFV fv = (PetscFV) obj;
4269de99aefSMatthew G. Knepley 
4279de99aefSMatthew G. Knepley         ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
4289de99aefSMatthew G. Knepley         ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
4299c3cf19fSMatthew G. Knepley         Nb   = Nc;
430ef0bb6c7SMatthew G. Knepley         ierr = PetscFVGetCellTabulation(fv, &prob->T[f]);CHKERRQ(ierr);
4314d0b9603SSander Arens         /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
43298921bdaSJacob Faibussowitsch       } else SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
433665f567fSMatthew G. Knepley     }
43447e57110SSander Arens     prob->Nc[f]       = Nc;
43547e57110SSander Arens     prob->Nb[f]       = Nb;
436194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
437194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
4389ee2af8cSMatthew G. Knepley     prob->offCohesive[0][f+1]    = (prob->cohesive[f] ? Nc : Nc*2)          + prob->offCohesive[0][f];
4399ee2af8cSMatthew G. Knepley     prob->offDerCohesive[0][f+1] = (prob->cohesive[f] ? Nc : Nc*2)*dimEmbed + prob->offDerCohesive[0][f];
4409ee2af8cSMatthew G. Knepley     prob->offCohesive[1][f]      = (prob->cohesive[f] ? 0 : Nc)             + prob->offCohesive[0][f];
4419ee2af8cSMatthew G. Knepley     prob->offDerCohesive[1][f]   = (prob->cohesive[f] ? 0 : Nc)*dimEmbed    + prob->offDerCohesive[0][f];
4429ee2af8cSMatthew G. Knepley     prob->offCohesive[2][f+1]    = (prob->cohesive[f] ? Nc : Nc*2)          + prob->offCohesive[2][f];
4439ee2af8cSMatthew G. Knepley     prob->offDerCohesive[2][f+1] = (prob->cohesive[f] ? Nc : Nc*2)*dimEmbed + prob->offDerCohesive[2][f];
444a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
4452764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
4464bee2e38SMatthew G. Knepley     NbMax          = PetscMax(NbMax, Nb);
4472764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
4489c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
4492764a2aaSMatthew G. Knepley     prob->totComp += Nc;
4505fedec97SMatthew G. Knepley     /* There are two faces for all fields on a cohesive cell, except for cohesive fields */
4515fedec97SMatthew G. Knepley     if (prob->isCohesive && !prob->cohesive[f]) prob->totDim += Nb;
4522764a2aaSMatthew G. Knepley   }
4539ee2af8cSMatthew G. Knepley   prob->offCohesive[1][Nf]    = prob->offCohesive[0][Nf];
4549ee2af8cSMatthew G. Knepley   prob->offDerCohesive[1][Nf] = prob->offDerCohesive[0][Nf];
4552764a2aaSMatthew G. Knepley   /* Allocate works space */
4565fedec97SMatthew G. Knepley   NsMax = 2; /* A non-cohesive discretizations can be used on a cohesive cell, so we need this extra workspace for all DS */
457f9244615SMatthew 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);
4584bee2e38SMatthew 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);
45927f02ce8SMatthew G. Knepley   ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dimEmbed,&prob->f1,
46027f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g1,
46127f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed*dimEmbed,&prob->g3);CHKERRQ(ierr);
4622764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
4632764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
4642764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4652764a2aaSMatthew G. Knepley }
4662764a2aaSMatthew G. Knepley 
4672764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
4682764a2aaSMatthew G. Knepley {
4692764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4702764a2aaSMatthew G. Knepley 
4712764a2aaSMatthew G. Knepley   PetscFunctionBegin;
47247e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
473f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
4749ee2af8cSMatthew G. Knepley   ierr = PetscFree6(prob->offCohesive[0],prob->offCohesive[1],prob->offCohesive[2],prob->offDerCohesive[0],prob->offDerCohesive[1],prob->offDerCohesive[2]);CHKERRQ(ierr);
475ef0bb6c7SMatthew G. Knepley   ierr = PetscFree2(prob->T,prob->Tf);CHKERRQ(ierr);
4764bee2e38SMatthew G. Knepley   ierr = PetscFree3(prob->u,prob->u_t,prob->u_x);CHKERRQ(ierr);
4774bee2e38SMatthew G. Knepley   ierr = PetscFree5(prob->x,prob->basisReal, prob->basisDerReal,prob->testReal,prob->testDerReal);CHKERRQ(ierr);
4782764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
4792764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4802764a2aaSMatthew G. Knepley }
4812764a2aaSMatthew G. Knepley 
4822764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
4832764a2aaSMatthew G. Knepley {
484f744cafaSSander Arens   PetscObject      *tmpd;
48534aa8a36SMatthew G. Knepley   PetscBool        *tmpi;
486f9244615SMatthew G. Knepley   PetscInt         *tmpk;
4875fedec97SMatthew G. Knepley   PetscBool        *tmpc;
4886528b96dSMatthew G. Knepley   PetscPointFunc   *tmpup;
489f2cacb80SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol,  *tmpexactSol_t;
490f2cacb80SMatthew G. Knepley   void                **tmpexactCtx, **tmpexactCtx_t;
4910c2f2876SMatthew G. Knepley   void            **tmpctx;
49234aa8a36SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f;
4932764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
4942764a2aaSMatthew G. Knepley 
4952764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4962764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
4972764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
4982764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
4995fedec97SMatthew G. Knepley   ierr = PetscMalloc4(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpc, NfNew, &tmpk);CHKERRQ(ierr);
5005fedec97SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; tmpc[f] = prob->cohesive[f]; tmpk[f] = prob->jetDegree[f];}
5015fedec97SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE, tmpc[f] = PETSC_FALSE; tmpk[f] = 1;}
5025fedec97SMatthew G. Knepley   ierr = PetscFree4(prob->disc, prob->implicit, prob->cohesive, prob->jetDegree);CHKERRQ(ierr);
5036528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(prob->wf, NfNew);CHKERRQ(ierr);
5042764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
5052764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
506249df284SMatthew G. Knepley   prob->implicit  = tmpi;
5075fedec97SMatthew G. Knepley   prob->cohesive  = tmpc;
508f9244615SMatthew G. Knepley   prob->jetDegree = tmpk;
5096528b96dSMatthew G. Knepley   ierr = PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx);CHKERRQ(ierr);
51032d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
5110c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
51232d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
5130c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
5146528b96dSMatthew G. Knepley   ierr = PetscFree2(prob->update, prob->ctx);CHKERRQ(ierr);
51532d2bbc9SMatthew G. Knepley   prob->update = tmpup;
5160c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
5176528b96dSMatthew G. Knepley   ierr = PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t);CHKERRQ(ierr);
518c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
51995cbbfd3SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f];
520f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f];
521f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f];
522c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
52395cbbfd3SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL;
524f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL;
525f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL;
5266528b96dSMatthew G. Knepley   ierr = PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t);CHKERRQ(ierr);
527c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
52895cbbfd3SMatthew G. Knepley   prob->exactCtx = tmpexactCtx;
529f2cacb80SMatthew G. Knepley   prob->exactSol_t = tmpexactSol_t;
530f2cacb80SMatthew G. Knepley   prob->exactCtx_t = tmpexactCtx_t;
5312764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5322764a2aaSMatthew G. Knepley }
5332764a2aaSMatthew G. Knepley 
5342764a2aaSMatthew G. Knepley /*@
5352764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
5362764a2aaSMatthew G. Knepley 
537d083f849SBarry Smith   Collective on prob
5382764a2aaSMatthew G. Knepley 
5392764a2aaSMatthew G. Knepley   Input Parameter:
5402764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
5412764a2aaSMatthew G. Knepley 
5422764a2aaSMatthew G. Knepley   Level: developer
5432764a2aaSMatthew G. Knepley 
5442764a2aaSMatthew G. Knepley .seealso PetscDSView()
5452764a2aaSMatthew G. Knepley @*/
5466528b96dSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *ds)
5472764a2aaSMatthew G. Knepley {
5482764a2aaSMatthew G. Knepley   PetscInt       f;
5492764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5502764a2aaSMatthew G. Knepley 
5512764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5526528b96dSMatthew G. Knepley   if (!*ds) PetscFunctionReturn(0);
5536528b96dSMatthew G. Knepley   PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1);
5542764a2aaSMatthew G. Knepley 
5556528b96dSMatthew G. Knepley   if (--((PetscObject)(*ds))->refct > 0) {*ds = NULL; PetscFunctionReturn(0);}
5566528b96dSMatthew G. Knepley   ((PetscObject) (*ds))->refct = 0;
5576528b96dSMatthew G. Knepley   if ((*ds)->subprobs) {
558df3a45bdSMatthew G. Knepley     PetscInt dim, d;
559df3a45bdSMatthew G. Knepley 
5606528b96dSMatthew G. Knepley     ierr = PetscDSGetSpatialDimension(*ds, &dim);CHKERRQ(ierr);
5616528b96dSMatthew G. Knepley     for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*ds)->subprobs[d]);CHKERRQ(ierr);}
562df3a45bdSMatthew G. Knepley   }
5636528b96dSMatthew G. Knepley   ierr = PetscFree((*ds)->subprobs);CHKERRQ(ierr);
5646528b96dSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*ds);CHKERRQ(ierr);
5656528b96dSMatthew G. Knepley   for (f = 0; f < (*ds)->Nf; ++f) {
5666528b96dSMatthew G. Knepley     ierr = PetscObjectDereference((*ds)->disc[f]);CHKERRQ(ierr);
5672764a2aaSMatthew G. Knepley   }
5685fedec97SMatthew G. Knepley   ierr = PetscFree4((*ds)->disc, (*ds)->implicit, (*ds)->cohesive, (*ds)->jetDegree);CHKERRQ(ierr);
5696528b96dSMatthew G. Knepley   ierr = PetscWeakFormDestroy(&(*ds)->wf);CHKERRQ(ierr);
5706528b96dSMatthew G. Knepley   ierr = PetscFree2((*ds)->update,(*ds)->ctx);CHKERRQ(ierr);
5716528b96dSMatthew G. Knepley   ierr = PetscFree4((*ds)->exactSol,(*ds)->exactCtx,(*ds)->exactSol_t,(*ds)->exactCtx_t);CHKERRQ(ierr);
5726528b96dSMatthew G. Knepley   if ((*ds)->ops->destroy) {ierr = (*(*ds)->ops->destroy)(*ds);CHKERRQ(ierr);}
57345480ffeSMatthew G. Knepley   ierr = PetscDSDestroyBoundary(*ds);CHKERRQ(ierr);
5746528b96dSMatthew G. Knepley   ierr = PetscFree((*ds)->constants);CHKERRQ(ierr);
5756528b96dSMatthew G. Knepley   ierr = PetscHeaderDestroy(ds);CHKERRQ(ierr);
5762764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5772764a2aaSMatthew G. Knepley }
5782764a2aaSMatthew G. Knepley 
5792764a2aaSMatthew G. Knepley /*@
5802764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
5812764a2aaSMatthew G. Knepley 
582d083f849SBarry Smith   Collective
5832764a2aaSMatthew G. Knepley 
5842764a2aaSMatthew G. Knepley   Input Parameter:
5852764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
5862764a2aaSMatthew G. Knepley 
5872764a2aaSMatthew G. Knepley   Output Parameter:
5886528b96dSMatthew G. Knepley . ds   - The PetscDS object
5892764a2aaSMatthew G. Knepley 
5902764a2aaSMatthew G. Knepley   Level: beginner
5912764a2aaSMatthew G. Knepley 
5922764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
5932764a2aaSMatthew G. Knepley @*/
5946528b96dSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds)
5952764a2aaSMatthew G. Knepley {
5962764a2aaSMatthew G. Knepley   PetscDS        p;
5972764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5982764a2aaSMatthew G. Knepley 
5992764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6006528b96dSMatthew G. Knepley   PetscValidPointer(ds, 2);
6016528b96dSMatthew G. Knepley   *ds  = NULL;
6022764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
6032764a2aaSMatthew G. Knepley 
60473107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
6052764a2aaSMatthew G. Knepley 
6062764a2aaSMatthew G. Knepley   p->Nf           = 0;
6072764a2aaSMatthew G. Knepley   p->setup        = PETSC_FALSE;
60897b6e6e8SMatthew G. Knepley   p->numConstants = 0;
60997b6e6e8SMatthew G. Knepley   p->constants    = NULL;
610a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
61155c1f793SMatthew G. Knepley   p->useJacPre    = PETSC_TRUE;
6126528b96dSMatthew G. Knepley   ierr = PetscWeakFormCreate(comm, &p->wf);CHKERRQ(ierr);
6132764a2aaSMatthew G. Knepley 
6146528b96dSMatthew G. Knepley   *ds = p;
6152764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6162764a2aaSMatthew G. Knepley }
6172764a2aaSMatthew G. Knepley 
618bc4ae4beSMatthew G. Knepley /*@
619bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
620bc4ae4beSMatthew G. Knepley 
621bc4ae4beSMatthew G. Knepley   Not collective
622bc4ae4beSMatthew G. Knepley 
623bc4ae4beSMatthew G. Knepley   Input Parameter:
624bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
625bc4ae4beSMatthew G. Knepley 
626bc4ae4beSMatthew G. Knepley   Output Parameter:
627bc4ae4beSMatthew G. Knepley . Nf - The number of fields
628bc4ae4beSMatthew G. Knepley 
629bc4ae4beSMatthew G. Knepley   Level: beginner
630bc4ae4beSMatthew G. Knepley 
631bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
632bc4ae4beSMatthew G. Knepley @*/
6332764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
6342764a2aaSMatthew G. Knepley {
6352764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6362764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6372764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
6382764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
6392764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6402764a2aaSMatthew G. Knepley }
6412764a2aaSMatthew G. Knepley 
642bc4ae4beSMatthew G. Knepley /*@
643a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
644bc4ae4beSMatthew G. Knepley 
645bc4ae4beSMatthew G. Knepley   Not collective
646bc4ae4beSMatthew G. Knepley 
647bc4ae4beSMatthew G. Knepley   Input Parameter:
648bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
649bc4ae4beSMatthew G. Knepley 
650bc4ae4beSMatthew G. Knepley   Output Parameter:
651bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
652bc4ae4beSMatthew G. Knepley 
653bc4ae4beSMatthew G. Knepley   Level: beginner
654bc4ae4beSMatthew G. Knepley 
655a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate()
656bc4ae4beSMatthew G. Knepley @*/
6572764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
6582764a2aaSMatthew G. Knepley {
6592764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6602764a2aaSMatthew G. Knepley 
6612764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6622764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6632764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6642764a2aaSMatthew G. Knepley   *dim = 0;
6659de99aefSMatthew G. Knepley   if (prob->Nf) {
6669de99aefSMatthew G. Knepley     PetscObject  obj;
6679de99aefSMatthew G. Knepley     PetscClassId id;
6689de99aefSMatthew G. Knepley 
6699de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
670665f567fSMatthew G. Knepley     if (obj) {
6719de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
6729de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
6739de99aefSMatthew G. Knepley       else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
67498921bdaSJacob Faibussowitsch       else SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
6759de99aefSMatthew G. Knepley     }
676665f567fSMatthew G. Knepley   }
6772764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6782764a2aaSMatthew G. Knepley }
6792764a2aaSMatthew G. Knepley 
680bc4ae4beSMatthew G. Knepley /*@
681a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
682a859676bSMatthew G. Knepley 
683a859676bSMatthew G. Knepley   Not collective
684a859676bSMatthew G. Knepley 
685a859676bSMatthew G. Knepley   Input Parameter:
686a859676bSMatthew G. Knepley . prob - The PetscDS object
687a859676bSMatthew G. Knepley 
688a859676bSMatthew G. Knepley   Output Parameter:
689a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
690a859676bSMatthew G. Knepley 
691a859676bSMatthew G. Knepley   Level: beginner
692a859676bSMatthew G. Knepley 
693a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
694a859676bSMatthew G. Knepley @*/
695a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
696a859676bSMatthew G. Knepley {
697a859676bSMatthew G. Knepley   PetscFunctionBegin;
698a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
699a859676bSMatthew G. Knepley   PetscValidPointer(dimEmbed, 2);
700*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(prob->dimEmbed < 0,PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
701a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
702a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
703a859676bSMatthew G. Knepley }
704a859676bSMatthew G. Knepley 
705a859676bSMatthew G. Knepley /*@
706a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
707a859676bSMatthew G. Knepley 
708d083f849SBarry Smith   Logically collective on prob
709a859676bSMatthew G. Knepley 
710a859676bSMatthew G. Knepley   Input Parameters:
711a859676bSMatthew G. Knepley + prob - The PetscDS object
712a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
713a859676bSMatthew G. Knepley 
714a859676bSMatthew G. Knepley   Level: beginner
715a859676bSMatthew G. Knepley 
716a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
717a859676bSMatthew G. Knepley @*/
718a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
719a859676bSMatthew G. Knepley {
720a859676bSMatthew G. Knepley   PetscFunctionBegin;
721a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
722*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(dimEmbed < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed);
723a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
724a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
725a859676bSMatthew G. Knepley }
726a859676bSMatthew G. Knepley 
727a859676bSMatthew G. Knepley /*@
7285fedec97SMatthew G. Knepley   PetscDSIsCohesive - Returns the flag indicating that this DS is for a cohesive cell
7298edf6225SMatthew G. Knepley 
7308edf6225SMatthew G. Knepley   Not collective
7318edf6225SMatthew G. Knepley 
7328edf6225SMatthew G. Knepley   Input Parameter:
7335fedec97SMatthew G. Knepley . ds - The PetscDS object
7348edf6225SMatthew G. Knepley 
7358edf6225SMatthew G. Knepley   Output Parameter:
7365fedec97SMatthew G. Knepley . isCohesive - The flag
7378edf6225SMatthew G. Knepley 
7388edf6225SMatthew G. Knepley   Level: developer
7398edf6225SMatthew G. Knepley 
7405fedec97SMatthew G. Knepley .seealso: PetscDSGetNumCohesive(), PetscDSGetCohesive(), PetscDSSetCohesive(), PetscDSCreate()
7418edf6225SMatthew G. Knepley @*/
7425fedec97SMatthew G. Knepley PetscErrorCode PetscDSIsCohesive(PetscDS ds, PetscBool *isCohesive)
7438edf6225SMatthew G. Knepley {
7448edf6225SMatthew G. Knepley   PetscFunctionBegin;
7455fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
7465fedec97SMatthew G. Knepley   PetscValidPointer(isCohesive, 2);
7475fedec97SMatthew G. Knepley   *isCohesive = ds->isCohesive;
7488edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7498edf6225SMatthew G. Knepley }
7508edf6225SMatthew G. Knepley 
7518edf6225SMatthew G. Knepley /*@
7525fedec97SMatthew G. Knepley   PetscDSGetNumCohesive - Returns the numer of cohesive fields, meaning those defined on the interior of a cohesive cell
7535fedec97SMatthew G. Knepley 
7545fedec97SMatthew G. Knepley   Not collective
7555fedec97SMatthew G. Knepley 
7565fedec97SMatthew G. Knepley   Input Parameter:
7575fedec97SMatthew G. Knepley . ds - The PetscDS object
7585fedec97SMatthew G. Knepley 
7595fedec97SMatthew G. Knepley   Output Parameter:
7605fedec97SMatthew G. Knepley . numCohesive - The number of cohesive fields
7615fedec97SMatthew G. Knepley 
7625fedec97SMatthew G. Knepley   Level: developer
7635fedec97SMatthew G. Knepley 
7645fedec97SMatthew G. Knepley .seealso: PetscDSSetCohesive(), PetscDSCreate()
7655fedec97SMatthew G. Knepley @*/
7665fedec97SMatthew G. Knepley PetscErrorCode PetscDSGetNumCohesive(PetscDS ds, PetscInt *numCohesive)
7675fedec97SMatthew G. Knepley {
7685fedec97SMatthew G. Knepley   PetscInt f;
7695fedec97SMatthew G. Knepley 
7705fedec97SMatthew G. Knepley   PetscFunctionBegin;
7715fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
7725fedec97SMatthew G. Knepley   PetscValidPointer(numCohesive, 2);
7735fedec97SMatthew G. Knepley   *numCohesive = 0;
7745fedec97SMatthew G. Knepley   for (f = 0;  f < ds->Nf; ++f) *numCohesive += ds->cohesive[f] ? 1 : 0;
7755fedec97SMatthew G. Knepley   PetscFunctionReturn(0);
7765fedec97SMatthew G. Knepley }
7775fedec97SMatthew G. Knepley 
7785fedec97SMatthew G. Knepley /*@
7795fedec97SMatthew G. Knepley   PetscDSGetCohesive - Returns the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell
7805fedec97SMatthew G. Knepley 
7815fedec97SMatthew G. Knepley   Not collective
7825fedec97SMatthew G. Knepley 
7835fedec97SMatthew G. Knepley   Input Parameter:
7845fedec97SMatthew G. Knepley + ds - The PetscDS object
7855fedec97SMatthew G. Knepley - f  - The field index
7865fedec97SMatthew G. Knepley 
7875fedec97SMatthew G. Knepley   Output Parameter:
7885fedec97SMatthew G. Knepley . isCohesive - The flag
7895fedec97SMatthew G. Knepley 
7905fedec97SMatthew G. Knepley   Level: developer
7915fedec97SMatthew G. Knepley 
7925fedec97SMatthew G. Knepley .seealso: PetscDSSetCohesive(), PetscDSIsCohesive(), PetscDSCreate()
7935fedec97SMatthew G. Knepley @*/
7945fedec97SMatthew G. Knepley PetscErrorCode PetscDSGetCohesive(PetscDS ds, PetscInt f, PetscBool *isCohesive)
7955fedec97SMatthew G. Knepley {
7965fedec97SMatthew G. Knepley   PetscFunctionBegin;
7975fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
7985fedec97SMatthew G. Knepley   PetscValidPointer(isCohesive, 3);
799*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
8005fedec97SMatthew G. Knepley   *isCohesive = ds->cohesive[f];
8015fedec97SMatthew G. Knepley   PetscFunctionReturn(0);
8025fedec97SMatthew G. Knepley }
8035fedec97SMatthew G. Knepley 
8045fedec97SMatthew G. Knepley /*@
8055fedec97SMatthew G. Knepley   PetscDSSetCohesive - Set the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell
8068edf6225SMatthew G. Knepley 
8078edf6225SMatthew G. Knepley   Not collective
8088edf6225SMatthew G. Knepley 
8098edf6225SMatthew G. Knepley   Input Parameters:
8105fedec97SMatthew G. Knepley + ds - The PetscDS object
8115fedec97SMatthew G. Knepley . f  - The field index
8125fedec97SMatthew G. Knepley - isCohesive - The flag for a cohesive field
8138edf6225SMatthew G. Knepley 
8148edf6225SMatthew G. Knepley   Level: developer
8158edf6225SMatthew G. Knepley 
8165fedec97SMatthew G. Knepley .seealso: PetscDSGetCohesive(), PetscDSIsCohesive(), PetscDSCreate()
8178edf6225SMatthew G. Knepley @*/
8185fedec97SMatthew G. Knepley PetscErrorCode PetscDSSetCohesive(PetscDS ds, PetscInt f, PetscBool isCohesive)
8198edf6225SMatthew G. Knepley {
8205fedec97SMatthew G. Knepley   PetscInt i;
8215fedec97SMatthew G. Knepley 
8228edf6225SMatthew G. Knepley   PetscFunctionBegin;
8235fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
824*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
8255fedec97SMatthew G. Knepley   ds->cohesive[f] = isCohesive;
8265fedec97SMatthew G. Knepley   ds->isCohesive = PETSC_FALSE;
8275fedec97SMatthew G. Knepley   for (i = 0; i < ds->Nf; ++i) ds->isCohesive = ds->isCohesive || ds->cohesive[f] ? PETSC_TRUE : PETSC_FALSE;
8288edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
8298edf6225SMatthew G. Knepley }
8308edf6225SMatthew G. Knepley 
8318edf6225SMatthew G. Knepley /*@
832bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
833bc4ae4beSMatthew G. Knepley 
834bc4ae4beSMatthew G. Knepley   Not collective
835bc4ae4beSMatthew G. Knepley 
836bc4ae4beSMatthew G. Knepley   Input Parameter:
837bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
838bc4ae4beSMatthew G. Knepley 
839bc4ae4beSMatthew G. Knepley   Output Parameter:
840bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
841bc4ae4beSMatthew G. Knepley 
842bc4ae4beSMatthew G. Knepley   Level: beginner
843bc4ae4beSMatthew G. Knepley 
844bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
845bc4ae4beSMatthew G. Knepley @*/
8462764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
8472764a2aaSMatthew G. Knepley {
8482764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8492764a2aaSMatthew G. Knepley 
8502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8512764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8522764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
8532764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
8542764a2aaSMatthew G. Knepley   *dim = prob->totDim;
8552764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8562764a2aaSMatthew G. Knepley }
8572764a2aaSMatthew G. Knepley 
858bc4ae4beSMatthew G. Knepley /*@
859bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
860bc4ae4beSMatthew G. Knepley 
861bc4ae4beSMatthew G. Knepley   Not collective
862bc4ae4beSMatthew G. Knepley 
863bc4ae4beSMatthew G. Knepley   Input Parameter:
864bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
865bc4ae4beSMatthew G. Knepley 
866bc4ae4beSMatthew G. Knepley   Output Parameter:
867bc4ae4beSMatthew G. Knepley . dim - The total number of components
868bc4ae4beSMatthew G. Knepley 
869bc4ae4beSMatthew G. Knepley   Level: beginner
870bc4ae4beSMatthew G. Knepley 
871bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
872bc4ae4beSMatthew G. Knepley @*/
8732764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
8742764a2aaSMatthew G. Knepley {
8752764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8762764a2aaSMatthew G. Knepley 
8772764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8782764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8792764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
8802764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
8812764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
8822764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8832764a2aaSMatthew G. Knepley }
8842764a2aaSMatthew G. Knepley 
885bc4ae4beSMatthew G. Knepley /*@
886bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
887bc4ae4beSMatthew G. Knepley 
888bc4ae4beSMatthew G. Knepley   Not collective
889bc4ae4beSMatthew G. Knepley 
890bc4ae4beSMatthew G. Knepley   Input Parameters:
891bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
892bc4ae4beSMatthew G. Knepley - f - The field number
893bc4ae4beSMatthew G. Knepley 
894bc4ae4beSMatthew G. Knepley   Output Parameter:
895bc4ae4beSMatthew G. Knepley . disc - The discretization object
896bc4ae4beSMatthew G. Knepley 
897bc4ae4beSMatthew G. Knepley   Level: beginner
898bc4ae4beSMatthew G. Knepley 
899f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
900bc4ae4beSMatthew G. Knepley @*/
9012764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
9022764a2aaSMatthew G. Knepley {
9036528b96dSMatthew G. Knepley   PetscFunctionBeginHot;
9042764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9052764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
906*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= prob->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
9072764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
9082764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9092764a2aaSMatthew G. Knepley }
9102764a2aaSMatthew G. Knepley 
911bc4ae4beSMatthew G. Knepley /*@
912bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
913bc4ae4beSMatthew G. Knepley 
914bc4ae4beSMatthew G. Knepley   Not collective
915bc4ae4beSMatthew G. Knepley 
916bc4ae4beSMatthew G. Knepley   Input Parameters:
917bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
918bc4ae4beSMatthew G. Knepley . f - The field number
919bc4ae4beSMatthew G. Knepley - disc - The discretization object
920bc4ae4beSMatthew G. Knepley 
921bc4ae4beSMatthew G. Knepley   Level: beginner
922bc4ae4beSMatthew G. Knepley 
923bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
924bc4ae4beSMatthew G. Knepley @*/
9252764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
9262764a2aaSMatthew G. Knepley {
9272764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9282764a2aaSMatthew G. Knepley 
9292764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9302764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
931665f567fSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
932*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
9332764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
934c10f2116SMatthew G. Knepley   ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);
9352764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
9362764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
937665f567fSMatthew G. Knepley   if (disc) {
938249df284SMatthew G. Knepley     PetscClassId id;
939249df284SMatthew G. Knepley 
940249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
9411cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
9421cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr);
9431cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
9441cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr);
945a6cbbb48SMatthew G. Knepley     }
946f9244615SMatthew G. Knepley     ierr = PetscDSSetJetDegree(prob, f, 1);CHKERRQ(ierr);
947249df284SMatthew G. Knepley   }
9482764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9492764a2aaSMatthew G. Knepley }
9502764a2aaSMatthew G. Knepley 
951bc4ae4beSMatthew G. Knepley /*@
9526528b96dSMatthew G. Knepley   PetscDSGetWeakForm - Returns the weak form object
9536528b96dSMatthew G. Knepley 
9546528b96dSMatthew G. Knepley   Not collective
9556528b96dSMatthew G. Knepley 
9566528b96dSMatthew G. Knepley   Input Parameter:
9576528b96dSMatthew G. Knepley . ds - The PetscDS object
9586528b96dSMatthew G. Knepley 
9596528b96dSMatthew G. Knepley   Output Parameter:
9606528b96dSMatthew G. Knepley . wf - The weak form object
9616528b96dSMatthew G. Knepley 
9626528b96dSMatthew G. Knepley   Level: beginner
9636528b96dSMatthew G. Knepley 
9646528b96dSMatthew G. Knepley .seealso: PetscDSSetWeakForm(), PetscDSGetNumFields(), PetscDSCreate()
9656528b96dSMatthew G. Knepley @*/
9666528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf)
9676528b96dSMatthew G. Knepley {
9686528b96dSMatthew G. Knepley   PetscFunctionBegin;
9696528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
9706528b96dSMatthew G. Knepley   PetscValidPointer(wf, 2);
9716528b96dSMatthew G. Knepley   *wf = ds->wf;
9726528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9736528b96dSMatthew G. Knepley }
9746528b96dSMatthew G. Knepley 
9756528b96dSMatthew G. Knepley /*@
9766528b96dSMatthew G. Knepley   PetscDSSetWeakForm - Sets the weak form object
9776528b96dSMatthew G. Knepley 
9786528b96dSMatthew G. Knepley   Not collective
9796528b96dSMatthew G. Knepley 
9806528b96dSMatthew G. Knepley   Input Parameters:
9816528b96dSMatthew G. Knepley + ds - The PetscDS object
9826528b96dSMatthew G. Knepley - wf - The weak form object
9836528b96dSMatthew G. Knepley 
9846528b96dSMatthew G. Knepley   Level: beginner
9856528b96dSMatthew G. Knepley 
9866528b96dSMatthew G. Knepley .seealso: PetscDSGetWeakForm(), PetscDSGetNumFields(), PetscDSCreate()
9876528b96dSMatthew G. Knepley @*/
9886528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf)
9896528b96dSMatthew G. Knepley {
9906528b96dSMatthew G. Knepley   PetscErrorCode ierr;
9916528b96dSMatthew G. Knepley 
9926528b96dSMatthew G. Knepley   PetscFunctionBegin;
9936528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
9946528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2);
9956528b96dSMatthew G. Knepley   ierr = PetscObjectDereference((PetscObject) ds->wf);CHKERRQ(ierr);
9966528b96dSMatthew G. Knepley   ds->wf = wf;
9976528b96dSMatthew G. Knepley   ierr = PetscObjectReference((PetscObject) wf);CHKERRQ(ierr);
9986528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(wf, ds->Nf);CHKERRQ(ierr);
9996528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
10006528b96dSMatthew G. Knepley }
10016528b96dSMatthew G. Knepley 
10026528b96dSMatthew G. Knepley /*@
1003bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
1004bc4ae4beSMatthew G. Knepley 
1005bc4ae4beSMatthew G. Knepley   Not collective
1006bc4ae4beSMatthew G. Knepley 
1007bc4ae4beSMatthew G. Knepley   Input Parameters:
1008bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
1009bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
1010bc4ae4beSMatthew G. Knepley 
1011bc4ae4beSMatthew G. Knepley   Level: beginner
1012bc4ae4beSMatthew G. Knepley 
1013bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1014bc4ae4beSMatthew G. Knepley @*/
10152764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
10162764a2aaSMatthew G. Knepley {
10172764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
10182764a2aaSMatthew G. Knepley 
10192764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10202764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
10212764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10222764a2aaSMatthew G. Knepley }
10232764a2aaSMatthew G. Knepley 
1024249df284SMatthew G. Knepley /*@
1025083401c6SMatthew G. Knepley   PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS
1026083401c6SMatthew G. Knepley 
1027083401c6SMatthew G. Knepley   Not collective
1028083401c6SMatthew G. Knepley 
1029083401c6SMatthew G. Knepley   Input Parameter:
1030083401c6SMatthew G. Knepley . prob - The PetscDS object
1031083401c6SMatthew G. Knepley 
1032083401c6SMatthew G. Knepley   Output Parameter:
1033083401c6SMatthew G. Knepley . q - The quadrature object
1034083401c6SMatthew G. Knepley 
1035083401c6SMatthew G. Knepley Level: intermediate
1036083401c6SMatthew G. Knepley 
1037083401c6SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1038083401c6SMatthew G. Knepley @*/
1039083401c6SMatthew G. Knepley PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q)
1040083401c6SMatthew G. Knepley {
1041083401c6SMatthew G. Knepley   PetscObject    obj;
1042083401c6SMatthew G. Knepley   PetscClassId   id;
1043083401c6SMatthew G. Knepley   PetscErrorCode ierr;
1044083401c6SMatthew G. Knepley 
1045083401c6SMatthew G. Knepley   PetscFunctionBegin;
1046083401c6SMatthew G. Knepley   *q = NULL;
1047083401c6SMatthew G. Knepley   if (!prob->Nf) PetscFunctionReturn(0);
1048083401c6SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
1049083401c6SMatthew G. Knepley   ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
1050083401c6SMatthew G. Knepley   if      (id == PETSCFE_CLASSID) {ierr = PetscFEGetQuadrature((PetscFE) obj, q);CHKERRQ(ierr);}
1051083401c6SMatthew G. Knepley   else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetQuadrature((PetscFV) obj, q);CHKERRQ(ierr);}
105298921bdaSJacob Faibussowitsch   else SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
1053083401c6SMatthew G. Knepley   PetscFunctionReturn(0);
1054083401c6SMatthew G. Knepley }
1055083401c6SMatthew G. Knepley 
1056083401c6SMatthew G. Knepley /*@
1057249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
1058249df284SMatthew G. Knepley 
1059249df284SMatthew G. Knepley   Not collective
1060249df284SMatthew G. Knepley 
1061249df284SMatthew G. Knepley   Input Parameters:
1062249df284SMatthew G. Knepley + prob - The PetscDS object
1063249df284SMatthew G. Knepley - f - The field number
1064249df284SMatthew G. Knepley 
1065249df284SMatthew G. Knepley   Output Parameter:
1066249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
1067249df284SMatthew G. Knepley 
1068249df284SMatthew G. Knepley   Level: developer
1069249df284SMatthew G. Knepley 
1070f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1071249df284SMatthew G. Knepley @*/
1072249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
1073249df284SMatthew G. Knepley {
1074249df284SMatthew G. Knepley   PetscFunctionBegin;
1075249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1076249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
1077*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= prob->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
1078249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
1079249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1080249df284SMatthew G. Knepley }
1081249df284SMatthew G. Knepley 
1082249df284SMatthew G. Knepley /*@
1083249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
1084249df284SMatthew G. Knepley 
1085249df284SMatthew G. Knepley   Not collective
1086249df284SMatthew G. Knepley 
1087249df284SMatthew G. Knepley   Input Parameters:
1088249df284SMatthew G. Knepley + prob - The PetscDS object
1089249df284SMatthew G. Knepley . f - The field number
1090249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
1091249df284SMatthew G. Knepley 
1092249df284SMatthew G. Knepley   Level: developer
1093249df284SMatthew G. Knepley 
1094f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1095249df284SMatthew G. Knepley @*/
1096249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
1097249df284SMatthew G. Knepley {
1098249df284SMatthew G. Knepley   PetscFunctionBegin;
1099249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1100*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= prob->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
1101249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
1102249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1103249df284SMatthew G. Knepley }
1104249df284SMatthew G. Knepley 
1105f9244615SMatthew G. Knepley /*@
1106f9244615SMatthew G. Knepley   PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1107f9244615SMatthew G. Knepley 
1108f9244615SMatthew G. Knepley   Not collective
1109f9244615SMatthew G. Knepley 
1110f9244615SMatthew G. Knepley   Input Parameters:
1111f9244615SMatthew G. Knepley + ds - The PetscDS object
1112f9244615SMatthew G. Knepley - f  - The field number
1113f9244615SMatthew G. Knepley 
1114f9244615SMatthew G. Knepley   Output Parameter:
1115f9244615SMatthew G. Knepley . k  - The highest derivative we need to tabulate
1116f9244615SMatthew G. Knepley 
1117f9244615SMatthew G. Knepley   Level: developer
1118f9244615SMatthew G. Knepley 
1119f9244615SMatthew G. Knepley .seealso: PetscDSSetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1120f9244615SMatthew G. Knepley @*/
1121f9244615SMatthew G. Knepley PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k)
1122f9244615SMatthew G. Knepley {
1123f9244615SMatthew G. Knepley   PetscFunctionBegin;
1124f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1125f9244615SMatthew G. Knepley   PetscValidPointer(k, 3);
1126*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1127f9244615SMatthew G. Knepley   *k = ds->jetDegree[f];
1128f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1129f9244615SMatthew G. Knepley }
1130f9244615SMatthew G. Knepley 
1131f9244615SMatthew G. Knepley /*@
1132f9244615SMatthew G. Knepley   PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1133f9244615SMatthew G. Knepley 
1134f9244615SMatthew G. Knepley   Not collective
1135f9244615SMatthew G. Knepley 
1136f9244615SMatthew G. Knepley   Input Parameters:
1137f9244615SMatthew G. Knepley + ds - The PetscDS object
1138f9244615SMatthew G. Knepley . f  - The field number
1139f9244615SMatthew G. Knepley - k  - The highest derivative we need to tabulate
1140f9244615SMatthew G. Knepley 
1141f9244615SMatthew G. Knepley   Level: developer
1142f9244615SMatthew G. Knepley 
1143f9244615SMatthew G. Knepley .seealso: PetscDSGetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1144f9244615SMatthew G. Knepley @*/
1145f9244615SMatthew G. Knepley PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k)
1146f9244615SMatthew G. Knepley {
1147f9244615SMatthew G. Knepley   PetscFunctionBegin;
1148f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1149*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1150f9244615SMatthew G. Knepley   ds->jetDegree[f] = k;
1151f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1152f9244615SMatthew G. Knepley }
1153f9244615SMatthew G. Knepley 
11546528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS ds, PetscInt f,
115530b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1156194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1157194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
115897b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
11592764a2aaSMatthew G. Knepley {
11606528b96dSMatthew G. Knepley   PetscPointFunc *tmp;
11616528b96dSMatthew G. Knepley   PetscInt        n;
11626528b96dSMatthew G. Knepley   PetscErrorCode  ierr;
11636528b96dSMatthew G. Knepley 
11642764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11656528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11666528b96dSMatthew G. Knepley   PetscValidPointer(obj, 3);
1167*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
116806ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetObjective(ds->wf, NULL, 0, f, 0, &n, &tmp);CHKERRQ(ierr);
11696528b96dSMatthew G. Knepley   *obj = tmp ? tmp[0] : NULL;
11702764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11712764a2aaSMatthew G. Knepley }
11722764a2aaSMatthew G. Knepley 
11736528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS ds, PetscInt f,
117430b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1175194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1176194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117797b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
11782764a2aaSMatthew G. Knepley {
11792764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
11802764a2aaSMatthew G. Knepley 
11812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11826528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11836528b96dSMatthew G. Knepley   if (obj) PetscValidFunction(obj, 3);
1184*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
118506ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, 0, obj);CHKERRQ(ierr);
11862764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11872764a2aaSMatthew G. Knepley }
11882764a2aaSMatthew G. Knepley 
1189194d53e6SMatthew G. Knepley /*@C
1190194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1191194d53e6SMatthew G. Knepley 
1192194d53e6SMatthew G. Knepley   Not collective
1193194d53e6SMatthew G. Knepley 
1194194d53e6SMatthew G. Knepley   Input Parameters:
11956528b96dSMatthew G. Knepley + ds - The PetscDS
1196194d53e6SMatthew G. Knepley - f  - The test field number
1197194d53e6SMatthew G. Knepley 
1198194d53e6SMatthew G. Knepley   Output Parameters:
1199194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1200194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1201194d53e6SMatthew G. Knepley 
1202194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1203194d53e6SMatthew G. Knepley 
1204194d53e6SMatthew 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)
1205194d53e6SMatthew G. Knepley 
1206194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1207194d53e6SMatthew G. Knepley 
120830b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1209194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1210194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
121130b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1212194d53e6SMatthew G. Knepley 
1213194d53e6SMatthew G. Knepley + dim - the spatial dimension
1214194d53e6SMatthew G. Knepley . Nf - the number of fields
1215194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1216194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1217194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1218194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1219194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1220194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1221194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1222194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1223194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1224194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1225194d53e6SMatthew G. Knepley . t - current time
1226194d53e6SMatthew G. Knepley . x - coordinates of the current point
122797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
122897b6e6e8SMatthew G. Knepley . constants - constant parameters
1229194d53e6SMatthew G. Knepley - f0 - output values at the current point
1230194d53e6SMatthew G. Knepley 
1231194d53e6SMatthew G. Knepley   Level: intermediate
1232194d53e6SMatthew G. Knepley 
1233194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
1234194d53e6SMatthew G. Knepley @*/
12356528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS ds, PetscInt f,
123630b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1237194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1238194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123997b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
124030b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1241194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1242194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
124397b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
12442764a2aaSMatthew G. Knepley {
12456528b96dSMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
12466528b96dSMatthew G. Knepley   PetscInt        n0, n1;
12476528b96dSMatthew G. Knepley   PetscErrorCode  ierr;
12486528b96dSMatthew G. Knepley 
12492764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12506528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1251*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
125206ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
12536528b96dSMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
12546528b96dSMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
12552764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12562764a2aaSMatthew G. Knepley }
12572764a2aaSMatthew G. Knepley 
1258194d53e6SMatthew G. Knepley /*@C
1259194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1260194d53e6SMatthew G. Knepley 
1261194d53e6SMatthew G. Knepley   Not collective
1262194d53e6SMatthew G. Knepley 
1263194d53e6SMatthew G. Knepley   Input Parameters:
12646528b96dSMatthew G. Knepley + ds - The PetscDS
1265194d53e6SMatthew G. Knepley . f  - The test field number
1266194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1267194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1268194d53e6SMatthew G. Knepley 
1269194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1270194d53e6SMatthew G. Knepley 
1271194d53e6SMatthew 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)
1272194d53e6SMatthew G. Knepley 
1273194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1274194d53e6SMatthew G. Knepley 
127530b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1276194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1277194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
127830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1279194d53e6SMatthew G. Knepley 
1280194d53e6SMatthew G. Knepley + dim - the spatial dimension
1281194d53e6SMatthew G. Knepley . Nf - the number of fields
1282194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1283194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1284194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1285194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1286194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1287194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1288194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1289194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1290194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1291194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1292194d53e6SMatthew G. Knepley . t - current time
1293194d53e6SMatthew G. Knepley . x - coordinates of the current point
129497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
129597b6e6e8SMatthew G. Knepley . constants - constant parameters
1296194d53e6SMatthew G. Knepley - f0 - output values at the current point
1297194d53e6SMatthew G. Knepley 
1298194d53e6SMatthew G. Knepley   Level: intermediate
1299194d53e6SMatthew G. Knepley 
1300194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1301194d53e6SMatthew G. Knepley @*/
13026528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS ds, PetscInt f,
130330b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1304194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1305194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130697b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
130730b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1308194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1309194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
131097b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
13112764a2aaSMatthew G. Knepley {
13122764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
13132764a2aaSMatthew G. Knepley 
13142764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13156528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1316f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1317f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
1318*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
131906ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1);CHKERRQ(ierr);
13202764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
13212764a2aaSMatthew G. Knepley }
13222764a2aaSMatthew G. Knepley 
13233e75805dSMatthew G. Knepley /*@C
1324cb36c0f9SMatthew G. Knepley   PetscDSGetRHSResidual - Get the pointwise RHS residual function for explicit timestepping for a given test field
1325cb36c0f9SMatthew G. Knepley 
1326cb36c0f9SMatthew G. Knepley   Not collective
1327cb36c0f9SMatthew G. Knepley 
1328cb36c0f9SMatthew G. Knepley   Input Parameters:
1329cb36c0f9SMatthew G. Knepley + ds - The PetscDS
1330cb36c0f9SMatthew G. Knepley - f  - The test field number
1331cb36c0f9SMatthew G. Knepley 
1332cb36c0f9SMatthew G. Knepley   Output Parameters:
1333cb36c0f9SMatthew G. Knepley + f0 - integrand for the test function term
1334cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term
1335cb36c0f9SMatthew G. Knepley 
1336cb36c0f9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1337cb36c0f9SMatthew G. Knepley 
1338cb36c0f9SMatthew 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)
1339cb36c0f9SMatthew G. Knepley 
1340cb36c0f9SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1341cb36c0f9SMatthew G. Knepley 
1342cb36c0f9SMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1343cb36c0f9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1344cb36c0f9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1345cb36c0f9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1346cb36c0f9SMatthew G. Knepley 
1347cb36c0f9SMatthew G. Knepley + dim - the spatial dimension
1348cb36c0f9SMatthew G. Knepley . Nf - the number of fields
1349cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1350cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1351cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point
1352cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1353cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1354cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1355cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1356cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1357cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1358cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1359cb36c0f9SMatthew G. Knepley . t - current time
1360cb36c0f9SMatthew G. Knepley . x - coordinates of the current point
1361cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters
1362cb36c0f9SMatthew G. Knepley . constants - constant parameters
1363cb36c0f9SMatthew G. Knepley - f0 - output values at the current point
1364cb36c0f9SMatthew G. Knepley 
1365cb36c0f9SMatthew G. Knepley   Level: intermediate
1366cb36c0f9SMatthew G. Knepley 
1367cb36c0f9SMatthew G. Knepley .seealso: PetscDSSetRHSResidual()
1368cb36c0f9SMatthew G. Knepley @*/
1369cb36c0f9SMatthew G. Knepley PetscErrorCode PetscDSGetRHSResidual(PetscDS ds, PetscInt f,
1370cb36c0f9SMatthew G. Knepley                                      void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1371cb36c0f9SMatthew G. Knepley                                                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1372cb36c0f9SMatthew G. Knepley                                                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1373cb36c0f9SMatthew G. Knepley                                                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
1374cb36c0f9SMatthew G. Knepley                                      void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1375cb36c0f9SMatthew G. Knepley                                                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1376cb36c0f9SMatthew G. Knepley                                                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1377cb36c0f9SMatthew G. Knepley                                                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
1378cb36c0f9SMatthew G. Knepley {
1379cb36c0f9SMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
1380cb36c0f9SMatthew G. Knepley   PetscInt        n0, n1;
1381cb36c0f9SMatthew G. Knepley   PetscErrorCode  ierr;
1382cb36c0f9SMatthew G. Knepley 
1383cb36c0f9SMatthew G. Knepley   PetscFunctionBegin;
1384cb36c0f9SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1385*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1386cb36c0f9SMatthew G. Knepley   ierr = PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 100, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
1387cb36c0f9SMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
1388cb36c0f9SMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
1389cb36c0f9SMatthew G. Knepley   PetscFunctionReturn(0);
1390cb36c0f9SMatthew G. Knepley }
1391cb36c0f9SMatthew G. Knepley 
1392cb36c0f9SMatthew G. Knepley /*@C
1393cb36c0f9SMatthew G. Knepley   PetscDSSetRHSResidual - Set the pointwise residual function for explicit timestepping for a given test field
1394cb36c0f9SMatthew G. Knepley 
1395cb36c0f9SMatthew G. Knepley   Not collective
1396cb36c0f9SMatthew G. Knepley 
1397cb36c0f9SMatthew G. Knepley   Input Parameters:
1398cb36c0f9SMatthew G. Knepley + ds - The PetscDS
1399cb36c0f9SMatthew G. Knepley . f  - The test field number
1400cb36c0f9SMatthew G. Knepley . f0 - integrand for the test function term
1401cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term
1402cb36c0f9SMatthew G. Knepley 
1403cb36c0f9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1404cb36c0f9SMatthew G. Knepley 
1405cb36c0f9SMatthew 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)
1406cb36c0f9SMatthew G. Knepley 
1407cb36c0f9SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1408cb36c0f9SMatthew G. Knepley 
1409cb36c0f9SMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1410cb36c0f9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1411cb36c0f9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1412cb36c0f9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1413cb36c0f9SMatthew G. Knepley 
1414cb36c0f9SMatthew G. Knepley + dim - the spatial dimension
1415cb36c0f9SMatthew G. Knepley . Nf - the number of fields
1416cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1417cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1418cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point
1419cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1420cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1421cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1422cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1423cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1424cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1425cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1426cb36c0f9SMatthew G. Knepley . t - current time
1427cb36c0f9SMatthew G. Knepley . x - coordinates of the current point
1428cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters
1429cb36c0f9SMatthew G. Knepley . constants - constant parameters
1430cb36c0f9SMatthew G. Knepley - f0 - output values at the current point
1431cb36c0f9SMatthew G. Knepley 
1432cb36c0f9SMatthew G. Knepley   Level: intermediate
1433cb36c0f9SMatthew G. Knepley 
1434cb36c0f9SMatthew G. Knepley .seealso: PetscDSGetResidual()
1435cb36c0f9SMatthew G. Knepley @*/
1436cb36c0f9SMatthew G. Knepley PetscErrorCode PetscDSSetRHSResidual(PetscDS ds, PetscInt f,
1437cb36c0f9SMatthew G. Knepley                                      void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1438cb36c0f9SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1439cb36c0f9SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1440cb36c0f9SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
1441cb36c0f9SMatthew G. Knepley                                      void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1442cb36c0f9SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1443cb36c0f9SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1444cb36c0f9SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
1445cb36c0f9SMatthew G. Knepley {
1446cb36c0f9SMatthew G. Knepley   PetscErrorCode ierr;
1447cb36c0f9SMatthew G. Knepley 
1448cb36c0f9SMatthew G. Knepley   PetscFunctionBegin;
1449cb36c0f9SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1450cb36c0f9SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1451cb36c0f9SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
1452*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1453cb36c0f9SMatthew G. Knepley   ierr = PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 100, 0, f0, 0, f1);CHKERRQ(ierr);
1454cb36c0f9SMatthew G. Knepley   PetscFunctionReturn(0);
1455cb36c0f9SMatthew G. Knepley }
1456cb36c0f9SMatthew G. Knepley 
1457cb36c0f9SMatthew G. Knepley /*@C
14583e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
14593e75805dSMatthew G. Knepley 
14603e75805dSMatthew G. Knepley   Not collective
14613e75805dSMatthew G. Knepley 
14623e75805dSMatthew G. Knepley   Input Parameter:
14633e75805dSMatthew G. Knepley . prob - The PetscDS
14643e75805dSMatthew G. Knepley 
14653e75805dSMatthew G. Knepley   Output Parameter:
14663e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
14673e75805dSMatthew G. Knepley 
14683e75805dSMatthew G. Knepley   Level: intermediate
14693e75805dSMatthew G. Knepley 
14703e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
14713e75805dSMatthew G. Knepley @*/
14726528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac)
14733e75805dSMatthew G. Knepley {
14746528b96dSMatthew G. Knepley   PetscErrorCode ierr;
14753e75805dSMatthew G. Knepley 
14763e75805dSMatthew G. Knepley   PetscFunctionBegin;
14776528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
14786528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobian(ds->wf, hasJac);CHKERRQ(ierr);
14793e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
14803e75805dSMatthew G. Knepley }
14813e75805dSMatthew G. Knepley 
1482194d53e6SMatthew G. Knepley /*@C
1483194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1484194d53e6SMatthew G. Knepley 
1485194d53e6SMatthew G. Knepley   Not collective
1486194d53e6SMatthew G. Knepley 
1487194d53e6SMatthew G. Knepley   Input Parameters:
14886528b96dSMatthew G. Knepley + ds - The PetscDS
1489194d53e6SMatthew G. Knepley . f  - The test field number
1490194d53e6SMatthew G. Knepley - g  - The field number
1491194d53e6SMatthew G. Knepley 
1492194d53e6SMatthew G. Knepley   Output Parameters:
1493194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1494194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1495194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1496194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1497194d53e6SMatthew G. Knepley 
1498194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1499194d53e6SMatthew G. Knepley 
1500194d53e6SMatthew 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
1501194d53e6SMatthew G. Knepley 
1502194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1503194d53e6SMatthew G. Knepley 
150430b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1505194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1506194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
150730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1508194d53e6SMatthew G. Knepley 
1509194d53e6SMatthew G. Knepley + dim - the spatial dimension
1510194d53e6SMatthew G. Knepley . Nf - the number of fields
1511194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1512194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1513194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1514194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1515194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1516194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1517194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1518194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1519194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1520194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1521194d53e6SMatthew G. Knepley . t - current time
15222aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1523194d53e6SMatthew G. Knepley . x - coordinates of the current point
152497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
152597b6e6e8SMatthew G. Knepley . constants - constant parameters
1526194d53e6SMatthew G. Knepley - g0 - output values at the current point
1527194d53e6SMatthew G. Knepley 
1528194d53e6SMatthew G. Knepley   Level: intermediate
1529194d53e6SMatthew G. Knepley 
1530194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1531194d53e6SMatthew G. Knepley @*/
15326528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS ds, PetscInt f, PetscInt g,
153330b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1534194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1535194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
153697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
153730b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1538194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1539194d53e6SMatthew 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 g1[]),
154130b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1542194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1543194d53e6SMatthew 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 g2[]),
154530b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1546194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1547194d53e6SMatthew 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 g3[]))
15492764a2aaSMatthew G. Knepley {
15506528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
15516528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
15526528b96dSMatthew G. Knepley   PetscErrorCode ierr;
15536528b96dSMatthew G. Knepley 
15542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
15556528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1556*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1557*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((g < 0) || (g >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
155806ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
15596528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
15606528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
15616528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
15626528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
15632764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
15642764a2aaSMatthew G. Knepley }
15652764a2aaSMatthew G. Knepley 
1566194d53e6SMatthew G. Knepley /*@C
1567194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1568194d53e6SMatthew G. Knepley 
1569194d53e6SMatthew G. Knepley   Not collective
1570194d53e6SMatthew G. Knepley 
1571194d53e6SMatthew G. Knepley   Input Parameters:
15726528b96dSMatthew G. Knepley + ds - The PetscDS
1573194d53e6SMatthew G. Knepley . f  - The test field number
1574194d53e6SMatthew G. Knepley . g  - The field number
1575194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1576194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1577194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1578194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1579194d53e6SMatthew G. Knepley 
1580194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1581194d53e6SMatthew G. Knepley 
1582194d53e6SMatthew 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
1583194d53e6SMatthew G. Knepley 
1584194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1585194d53e6SMatthew G. Knepley 
158630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1587194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1588194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
158930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1590194d53e6SMatthew G. Knepley 
1591194d53e6SMatthew G. Knepley + dim - the spatial dimension
1592194d53e6SMatthew G. Knepley . Nf - the number of fields
1593194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1594194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1595194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1596194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1597194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1598194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1599194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1600194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1601194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1602194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1603194d53e6SMatthew G. Knepley . t - current time
16042aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1605194d53e6SMatthew G. Knepley . x - coordinates of the current point
160697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
160797b6e6e8SMatthew G. Knepley . constants - constant parameters
1608194d53e6SMatthew G. Knepley - g0 - output values at the current point
1609194d53e6SMatthew G. Knepley 
1610194d53e6SMatthew G. Knepley   Level: intermediate
1611194d53e6SMatthew G. Knepley 
1612194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1613194d53e6SMatthew G. Knepley @*/
16146528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS ds, PetscInt f, PetscInt g,
161530b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1616194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1617194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
161897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
161930b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1620194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1621194d53e6SMatthew 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 g1[]),
162330b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1624194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1625194d53e6SMatthew 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 g2[]),
162730b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1628194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1629194d53e6SMatthew 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 g3[]))
16312764a2aaSMatthew G. Knepley {
16322764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
16332764a2aaSMatthew G. Knepley 
16342764a2aaSMatthew G. Knepley   PetscFunctionBegin;
16356528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
16362764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
16372764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
16382764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
16392764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1640*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1641*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(g < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
164206ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
16432764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
16442764a2aaSMatthew G. Knepley }
16452764a2aaSMatthew G. Knepley 
1646475e0ac9SMatthew G. Knepley /*@C
164755c1f793SMatthew G. Knepley   PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner
164855c1f793SMatthew G. Knepley 
164955c1f793SMatthew G. Knepley   Not collective
165055c1f793SMatthew G. Knepley 
165155c1f793SMatthew G. Knepley   Input Parameters:
165255c1f793SMatthew G. Knepley + prob - The PetscDS
165355c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
165455c1f793SMatthew G. Knepley 
165555c1f793SMatthew G. Knepley   Level: intermediate
165655c1f793SMatthew G. Knepley 
165755c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
165855c1f793SMatthew G. Knepley @*/
165955c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
166055c1f793SMatthew G. Knepley {
166155c1f793SMatthew G. Knepley   PetscFunctionBegin;
166255c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
166355c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
166455c1f793SMatthew G. Knepley   PetscFunctionReturn(0);
166555c1f793SMatthew G. Knepley }
166655c1f793SMatthew G. Knepley 
166755c1f793SMatthew G. Knepley /*@C
1668475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1669475e0ac9SMatthew G. Knepley 
1670475e0ac9SMatthew G. Knepley   Not collective
1671475e0ac9SMatthew G. Knepley 
1672475e0ac9SMatthew G. Knepley   Input Parameter:
1673475e0ac9SMatthew G. Knepley . prob - The PetscDS
1674475e0ac9SMatthew G. Knepley 
1675475e0ac9SMatthew G. Knepley   Output Parameter:
1676475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1677475e0ac9SMatthew G. Knepley 
1678475e0ac9SMatthew G. Knepley   Level: intermediate
1679475e0ac9SMatthew G. Knepley 
1680475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1681475e0ac9SMatthew G. Knepley @*/
16826528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre)
1683475e0ac9SMatthew G. Knepley {
16846528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1685475e0ac9SMatthew G. Knepley 
1686475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
16876528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1688475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
16896528b96dSMatthew G. Knepley   if (!ds->useJacPre) PetscFunctionReturn(0);
16906528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre);CHKERRQ(ierr);
1691475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1692475e0ac9SMatthew G. Knepley }
1693475e0ac9SMatthew G. Knepley 
1694475e0ac9SMatthew G. Knepley /*@C
1695475e0ac9SMatthew 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.
1696475e0ac9SMatthew G. Knepley 
1697475e0ac9SMatthew G. Knepley   Not collective
1698475e0ac9SMatthew G. Knepley 
1699475e0ac9SMatthew G. Knepley   Input Parameters:
17006528b96dSMatthew G. Knepley + ds - The PetscDS
1701475e0ac9SMatthew G. Knepley . f  - The test field number
1702475e0ac9SMatthew G. Knepley - g  - The field number
1703475e0ac9SMatthew G. Knepley 
1704475e0ac9SMatthew G. Knepley   Output Parameters:
1705475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1706475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1707475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1708475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1709475e0ac9SMatthew G. Knepley 
1710475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1711475e0ac9SMatthew G. Knepley 
1712475e0ac9SMatthew 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
1713475e0ac9SMatthew G. Knepley 
1714475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1715475e0ac9SMatthew G. Knepley 
1716475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1717475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1718475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1719475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1720475e0ac9SMatthew G. Knepley 
1721475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1722475e0ac9SMatthew G. Knepley . Nf - the number of fields
1723475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1724475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1725475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1726475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1727475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1728475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1729475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1730475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1731475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1732475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1733475e0ac9SMatthew G. Knepley . t - current time
1734475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1735475e0ac9SMatthew G. Knepley . x - coordinates of the current point
173697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
173797b6e6e8SMatthew G. Knepley . constants - constant parameters
1738475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1739475e0ac9SMatthew G. Knepley 
1740475e0ac9SMatthew G. Knepley   Level: intermediate
1741475e0ac9SMatthew G. Knepley 
1742475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1743475e0ac9SMatthew G. Knepley @*/
17446528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1745475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1746475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1747475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
174897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1749475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1750475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1751475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
175297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1753475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1754475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1755475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
175697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1757475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1758475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1759475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
176097b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1761475e0ac9SMatthew G. Knepley {
17626528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
17636528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
17646528b96dSMatthew G. Knepley   PetscErrorCode ierr;
17656528b96dSMatthew G. Knepley 
1766475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
17676528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1768*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1769*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((g < 0) || (g >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
177006ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
17716528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
17726528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
17736528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
17746528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1775475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1776475e0ac9SMatthew G. Knepley }
1777475e0ac9SMatthew G. Knepley 
1778475e0ac9SMatthew G. Knepley /*@C
1779475e0ac9SMatthew 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.
1780475e0ac9SMatthew G. Knepley 
1781475e0ac9SMatthew G. Knepley   Not collective
1782475e0ac9SMatthew G. Knepley 
1783475e0ac9SMatthew G. Knepley   Input Parameters:
17846528b96dSMatthew G. Knepley + ds - The PetscDS
1785475e0ac9SMatthew G. Knepley . f  - The test field number
1786475e0ac9SMatthew G. Knepley . g  - The field number
1787475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1788475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1789475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1790475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1791475e0ac9SMatthew G. Knepley 
1792475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1793475e0ac9SMatthew G. Knepley 
1794475e0ac9SMatthew 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
1795475e0ac9SMatthew G. Knepley 
1796475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1797475e0ac9SMatthew G. Knepley 
1798475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1799475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1800475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1801475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1802475e0ac9SMatthew G. Knepley 
1803475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1804475e0ac9SMatthew G. Knepley . Nf - the number of fields
1805475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1806475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1807475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1808475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1809475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1810475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1811475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1812475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1813475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1814475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1815475e0ac9SMatthew G. Knepley . t - current time
1816475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1817475e0ac9SMatthew G. Knepley . x - coordinates of the current point
181897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
181997b6e6e8SMatthew G. Knepley . constants - constant parameters
1820475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1821475e0ac9SMatthew G. Knepley 
1822475e0ac9SMatthew G. Knepley   Level: intermediate
1823475e0ac9SMatthew G. Knepley 
1824475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1825475e0ac9SMatthew G. Knepley @*/
18266528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1827475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1828475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1829475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
183097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1831475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1832475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1833475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
183497b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1835475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1836475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1837475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
183897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1839475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1840475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1841475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
184297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1843475e0ac9SMatthew G. Knepley {
1844475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1845475e0ac9SMatthew G. Knepley 
1846475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
18476528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1848475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1849475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1850475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1851475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1852*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1853*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(g < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
185406ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
1855475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1856475e0ac9SMatthew G. Knepley }
1857475e0ac9SMatthew G. Knepley 
1858b7e05686SMatthew G. Knepley /*@C
1859b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1860b7e05686SMatthew G. Knepley 
1861b7e05686SMatthew G. Knepley   Not collective
1862b7e05686SMatthew G. Knepley 
1863b7e05686SMatthew G. Knepley   Input Parameter:
18646528b96dSMatthew G. Knepley . ds - The PetscDS
1865b7e05686SMatthew G. Knepley 
1866b7e05686SMatthew G. Knepley   Output Parameter:
1867b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1868b7e05686SMatthew G. Knepley 
1869b7e05686SMatthew G. Knepley   Level: intermediate
1870b7e05686SMatthew G. Knepley 
1871b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1872b7e05686SMatthew G. Knepley @*/
18736528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac)
1874b7e05686SMatthew G. Knepley {
18756528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1876b7e05686SMatthew G. Knepley 
1877b7e05686SMatthew G. Knepley   PetscFunctionBegin;
18786528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
18796528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac);CHKERRQ(ierr);
1880b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1881b7e05686SMatthew G. Knepley }
1882b7e05686SMatthew G. Knepley 
1883b7e05686SMatthew G. Knepley /*@C
1884b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1885b7e05686SMatthew G. Knepley 
1886b7e05686SMatthew G. Knepley   Not collective
1887b7e05686SMatthew G. Knepley 
1888b7e05686SMatthew G. Knepley   Input Parameters:
18896528b96dSMatthew G. Knepley + ds - The PetscDS
1890b7e05686SMatthew G. Knepley . f  - The test field number
1891b7e05686SMatthew G. Knepley - g  - The field number
1892b7e05686SMatthew G. Knepley 
1893b7e05686SMatthew G. Knepley   Output Parameters:
1894b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1895b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1896b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1897b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1898b7e05686SMatthew G. Knepley 
1899b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1900b7e05686SMatthew G. Knepley 
1901b7e05686SMatthew 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
1902b7e05686SMatthew G. Knepley 
1903b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1904b7e05686SMatthew G. Knepley 
1905b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1906b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1907b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1908b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1909b7e05686SMatthew G. Knepley 
1910b7e05686SMatthew G. Knepley + dim - the spatial dimension
1911b7e05686SMatthew G. Knepley . Nf - the number of fields
1912b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1913b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1914b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1915b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1916b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1917b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1918b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1919b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1920b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1921b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1922b7e05686SMatthew G. Knepley . t - current time
1923b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1924b7e05686SMatthew G. Knepley . x - coordinates of the current point
192597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
192697b6e6e8SMatthew G. Knepley . constants - constant parameters
1927b7e05686SMatthew G. Knepley - g0 - output values at the current point
1928b7e05686SMatthew G. Knepley 
1929b7e05686SMatthew G. Knepley   Level: intermediate
1930b7e05686SMatthew G. Knepley 
1931b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1932b7e05686SMatthew G. Knepley @*/
19336528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
1934b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1935b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1936b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
193797b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1938b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1939b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1940b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194197b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1942b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1943b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1944b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194597b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1946b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1947b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1948b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194997b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1950b7e05686SMatthew G. Knepley {
19516528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
19526528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
19536528b96dSMatthew G. Knepley   PetscErrorCode ierr;
19546528b96dSMatthew G. Knepley 
1955b7e05686SMatthew G. Knepley   PetscFunctionBegin;
19566528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1957*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1958*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((g < 0) || (g >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
195906ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
19606528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
19616528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
19626528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
19636528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1964b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1965b7e05686SMatthew G. Knepley }
1966b7e05686SMatthew G. Knepley 
1967b7e05686SMatthew G. Knepley /*@C
1968b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1969b7e05686SMatthew G. Knepley 
1970b7e05686SMatthew G. Knepley   Not collective
1971b7e05686SMatthew G. Knepley 
1972b7e05686SMatthew G. Knepley   Input Parameters:
19736528b96dSMatthew G. Knepley + ds - The PetscDS
1974b7e05686SMatthew G. Knepley . f  - The test field number
1975b7e05686SMatthew G. Knepley . g  - The field number
1976b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1977b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1978b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1979b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1980b7e05686SMatthew G. Knepley 
1981b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1982b7e05686SMatthew G. Knepley 
1983b7e05686SMatthew 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
1984b7e05686SMatthew G. Knepley 
1985b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1986b7e05686SMatthew G. Knepley 
1987b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1988b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1989b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1990b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1991b7e05686SMatthew G. Knepley 
1992b7e05686SMatthew G. Knepley + dim - the spatial dimension
1993b7e05686SMatthew G. Knepley . Nf - the number of fields
1994b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1995b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1996b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1997b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1998b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1999b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2000b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2001b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2002b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2003b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2004b7e05686SMatthew G. Knepley . t - current time
2005b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2006b7e05686SMatthew G. Knepley . x - coordinates of the current point
200797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
200897b6e6e8SMatthew G. Knepley . constants - constant parameters
2009b7e05686SMatthew G. Knepley - g0 - output values at the current point
2010b7e05686SMatthew G. Knepley 
2011b7e05686SMatthew G. Knepley   Level: intermediate
2012b7e05686SMatthew G. Knepley 
2013b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
2014b7e05686SMatthew G. Knepley @*/
20156528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
2016b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2017b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2018b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
201997b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
2020b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2021b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2022b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
202397b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
2024b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2025b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2026b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
202797b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
2028b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2029b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2030b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
203197b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
2032b7e05686SMatthew G. Knepley {
2033b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
2034b7e05686SMatthew G. Knepley 
2035b7e05686SMatthew G. Knepley   PetscFunctionBegin;
20366528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2037b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
2038b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
2039b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
2040b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
2041*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2042*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(g < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
204306ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
2044b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
2045b7e05686SMatthew G. Knepley }
2046b7e05686SMatthew G. Knepley 
20470c2f2876SMatthew G. Knepley /*@C
20480c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
20490c2f2876SMatthew G. Knepley 
20500c2f2876SMatthew G. Knepley   Not collective
20510c2f2876SMatthew G. Knepley 
20524165533cSJose E. Roman   Input Parameters:
20536528b96dSMatthew G. Knepley + ds - The PetscDS object
20540c2f2876SMatthew G. Knepley - f  - The field number
20550c2f2876SMatthew G. Knepley 
20564165533cSJose E. Roman   Output Parameter:
20570c2f2876SMatthew G. Knepley . r    - Riemann solver
20580c2f2876SMatthew G. Knepley 
20590c2f2876SMatthew G. Knepley   Calling sequence for r:
20600c2f2876SMatthew G. Knepley 
20615db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
20620c2f2876SMatthew G. Knepley 
20635db36cf9SMatthew G. Knepley + dim  - The spatial dimension
20645db36cf9SMatthew G. Knepley . Nf   - The number of fields
20655db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
20660c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
20670c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
20680c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
20690c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
207097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
207197b6e6e8SMatthew G. Knepley . constants - constant parameters
20720c2f2876SMatthew G. Knepley - ctx  - optional user context
20730c2f2876SMatthew G. Knepley 
20740c2f2876SMatthew G. Knepley   Level: intermediate
20750c2f2876SMatthew G. Knepley 
20760c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
20770c2f2876SMatthew G. Knepley @*/
20786528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS ds, PetscInt f,
207997b6e6e8SMatthew 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))
20800c2f2876SMatthew G. Knepley {
20816528b96dSMatthew G. Knepley   PetscRiemannFunc *tmp;
20826528b96dSMatthew G. Knepley   PetscInt          n;
20836528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
20846528b96dSMatthew G. Knepley 
20850c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20866528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
20870c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
2088*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
208906ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, 0, &n, &tmp);CHKERRQ(ierr);
20906528b96dSMatthew G. Knepley   *r   = tmp ? tmp[0] : NULL;
20910c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20920c2f2876SMatthew G. Knepley }
20930c2f2876SMatthew G. Knepley 
20940c2f2876SMatthew G. Knepley /*@C
20950c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
20960c2f2876SMatthew G. Knepley 
20970c2f2876SMatthew G. Knepley   Not collective
20980c2f2876SMatthew G. Knepley 
20994165533cSJose E. Roman   Input Parameters:
21006528b96dSMatthew G. Knepley + ds - The PetscDS object
21010c2f2876SMatthew G. Knepley . f  - The field number
21020c2f2876SMatthew G. Knepley - r  - Riemann solver
21030c2f2876SMatthew G. Knepley 
21040c2f2876SMatthew G. Knepley   Calling sequence for r:
21050c2f2876SMatthew G. Knepley 
21065db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
21070c2f2876SMatthew G. Knepley 
21085db36cf9SMatthew G. Knepley + dim  - The spatial dimension
21095db36cf9SMatthew G. Knepley . Nf   - The number of fields
21105db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
21110c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
21120c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
21130c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
21140c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
211597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
211697b6e6e8SMatthew G. Knepley . constants - constant parameters
21170c2f2876SMatthew G. Knepley - ctx  - optional user context
21180c2f2876SMatthew G. Knepley 
21190c2f2876SMatthew G. Knepley   Level: intermediate
21200c2f2876SMatthew G. Knepley 
21210c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
21220c2f2876SMatthew G. Knepley @*/
21236528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS ds, PetscInt f,
212497b6e6e8SMatthew 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))
21250c2f2876SMatthew G. Knepley {
21260c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
21270c2f2876SMatthew G. Knepley 
21280c2f2876SMatthew G. Knepley   PetscFunctionBegin;
21296528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2130de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
2131*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
213206ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, 0, r);CHKERRQ(ierr);
21330c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
21340c2f2876SMatthew G. Knepley }
21350c2f2876SMatthew G. Knepley 
213632d2bbc9SMatthew G. Knepley /*@C
213732d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
213832d2bbc9SMatthew G. Knepley 
213932d2bbc9SMatthew G. Knepley   Not collective
214032d2bbc9SMatthew G. Knepley 
214132d2bbc9SMatthew G. Knepley   Input Parameters:
21426528b96dSMatthew G. Knepley + ds - The PetscDS
214332d2bbc9SMatthew G. Knepley - f  - The field number
214432d2bbc9SMatthew G. Knepley 
2145f899ff85SJose E. Roman   Output Parameter:
2146a2b725a8SWilliam Gropp . update - update function
214732d2bbc9SMatthew G. Knepley 
214832d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
214932d2bbc9SMatthew G. Knepley 
215032d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
215132d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
215232d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
215332d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
215432d2bbc9SMatthew G. Knepley 
215532d2bbc9SMatthew G. Knepley + dim - the spatial dimension
215632d2bbc9SMatthew G. Knepley . Nf - the number of fields
215732d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
215832d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
215932d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
216032d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
216132d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
216232d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
216332d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
216432d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
216532d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
216632d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
216732d2bbc9SMatthew G. Knepley . t - current time
216832d2bbc9SMatthew G. Knepley . x - coordinates of the current point
216932d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
217032d2bbc9SMatthew G. Knepley 
217132d2bbc9SMatthew G. Knepley   Level: intermediate
217232d2bbc9SMatthew G. Knepley 
217332d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
217432d2bbc9SMatthew G. Knepley @*/
21756528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS ds, PetscInt f,
217632d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
217732d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
217832d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
21793fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
218032d2bbc9SMatthew G. Knepley {
218132d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
21826528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2183*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
21846528b96dSMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = ds->update[f];}
218532d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
218632d2bbc9SMatthew G. Knepley }
218732d2bbc9SMatthew G. Knepley 
218832d2bbc9SMatthew G. Knepley /*@C
21893fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
219032d2bbc9SMatthew G. Knepley 
219132d2bbc9SMatthew G. Knepley   Not collective
219232d2bbc9SMatthew G. Knepley 
219332d2bbc9SMatthew G. Knepley   Input Parameters:
21946528b96dSMatthew G. Knepley + ds     - The PetscDS
219532d2bbc9SMatthew G. Knepley . f      - The field number
219632d2bbc9SMatthew G. Knepley - update - update function
219732d2bbc9SMatthew G. Knepley 
219832d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
219932d2bbc9SMatthew G. Knepley 
220032d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
220132d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
220232d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
220332d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
220432d2bbc9SMatthew G. Knepley 
220532d2bbc9SMatthew G. Knepley + dim - the spatial dimension
220632d2bbc9SMatthew G. Knepley . Nf - the number of fields
220732d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
220832d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
220932d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
221032d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
221132d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
221232d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
221332d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
221432d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
221532d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
221632d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
221732d2bbc9SMatthew G. Knepley . t - current time
221832d2bbc9SMatthew G. Knepley . x - coordinates of the current point
221932d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
222032d2bbc9SMatthew G. Knepley 
222132d2bbc9SMatthew G. Knepley   Level: intermediate
222232d2bbc9SMatthew G. Knepley 
222332d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
222432d2bbc9SMatthew G. Knepley @*/
22256528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS ds, PetscInt f,
222632d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
222732d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
222832d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
22293fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
223032d2bbc9SMatthew G. Knepley {
223132d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
223232d2bbc9SMatthew G. Knepley 
223332d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
22346528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
223532d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
2236*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
22376528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
22386528b96dSMatthew G. Knepley   ds->update[f] = update;
223932d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
224032d2bbc9SMatthew G. Knepley }
224132d2bbc9SMatthew G. Knepley 
22423ec1f749SStefano Zampini PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void *ctx)
22430c2f2876SMatthew G. Knepley {
22440c2f2876SMatthew G. Knepley   PetscFunctionBegin;
22456528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2246*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
22470c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
22483ec1f749SStefano Zampini   *(void**)ctx = ds->ctx[f];
22490c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
22500c2f2876SMatthew G. Knepley }
22510c2f2876SMatthew G. Knepley 
22526528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx)
22530c2f2876SMatthew G. Knepley {
22540c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
22550c2f2876SMatthew G. Knepley 
22560c2f2876SMatthew G. Knepley   PetscFunctionBegin;
22576528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2258*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
22596528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
22606528b96dSMatthew G. Knepley   ds->ctx[f] = ctx;
22610c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
22620c2f2876SMatthew G. Knepley }
22630c2f2876SMatthew G. Knepley 
2264194d53e6SMatthew G. Knepley /*@C
2265194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
2266194d53e6SMatthew G. Knepley 
2267194d53e6SMatthew G. Knepley   Not collective
2268194d53e6SMatthew G. Knepley 
2269194d53e6SMatthew G. Knepley   Input Parameters:
22706528b96dSMatthew G. Knepley + ds - The PetscDS
2271194d53e6SMatthew G. Knepley - f  - The test field number
2272194d53e6SMatthew G. Knepley 
2273194d53e6SMatthew G. Knepley   Output Parameters:
2274194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
2275194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2276194d53e6SMatthew G. Knepley 
2277194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2278194d53e6SMatthew G. Knepley 
2279194d53e6SMatthew 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
2280194d53e6SMatthew G. Knepley 
2281194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2282194d53e6SMatthew G. Knepley 
228330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2284194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2285194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
228630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2287194d53e6SMatthew G. Knepley 
2288194d53e6SMatthew G. Knepley + dim - the spatial dimension
2289194d53e6SMatthew G. Knepley . Nf - the number of fields
2290194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2291194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2292194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2293194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2294194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2295194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2296194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2297194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2298194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2299194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2300194d53e6SMatthew G. Knepley . t - current time
2301194d53e6SMatthew G. Knepley . x - coordinates of the current point
2302194d53e6SMatthew G. Knepley . n - unit normal at the current point
230397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
230497b6e6e8SMatthew G. Knepley . constants - constant parameters
2305194d53e6SMatthew G. Knepley - f0 - output values at the current point
2306194d53e6SMatthew G. Knepley 
2307194d53e6SMatthew G. Knepley   Level: intermediate
2308194d53e6SMatthew G. Knepley 
2309194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
2310194d53e6SMatthew G. Knepley @*/
23116528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS ds, PetscInt f,
231230b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2313194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2314194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
231597b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
231630b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2317194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2318194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
231997b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
23202764a2aaSMatthew G. Knepley {
23216528b96dSMatthew G. Knepley   PetscBdPointFunc *tmp0, *tmp1;
23226528b96dSMatthew G. Knepley   PetscInt          n0, n1;
23236528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
23246528b96dSMatthew G. Knepley 
23252764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23266528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2327*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
232806ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
23296528b96dSMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
23306528b96dSMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
23312764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23322764a2aaSMatthew G. Knepley }
23332764a2aaSMatthew G. Knepley 
2334194d53e6SMatthew G. Knepley /*@C
2335194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2336194d53e6SMatthew G. Knepley 
2337194d53e6SMatthew G. Knepley   Not collective
2338194d53e6SMatthew G. Knepley 
2339194d53e6SMatthew G. Knepley   Input Parameters:
23406528b96dSMatthew G. Knepley + ds - The PetscDS
2341194d53e6SMatthew G. Knepley . f  - The test field number
2342194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2343194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2344194d53e6SMatthew G. Knepley 
2345194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2346194d53e6SMatthew G. Knepley 
2347194d53e6SMatthew 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
2348194d53e6SMatthew G. Knepley 
2349194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2350194d53e6SMatthew G. Knepley 
235130b9ff8bSMatthew G. Knepley $ f0(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[],
235430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2355194d53e6SMatthew G. Knepley 
2356194d53e6SMatthew G. Knepley + dim - the spatial dimension
2357194d53e6SMatthew G. Knepley . Nf - the number of fields
2358194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2359194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2360194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2361194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2362194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2363194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2364194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2365194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2366194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2367194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2368194d53e6SMatthew G. Knepley . t - current time
2369194d53e6SMatthew G. Knepley . x - coordinates of the current point
2370194d53e6SMatthew G. Knepley . n - unit normal at the current point
237197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
237297b6e6e8SMatthew G. Knepley . constants - constant parameters
2373194d53e6SMatthew G. Knepley - f0 - output values at the current point
2374194d53e6SMatthew G. Knepley 
2375194d53e6SMatthew G. Knepley   Level: intermediate
2376194d53e6SMatthew G. Knepley 
2377194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
2378194d53e6SMatthew G. Knepley @*/
23796528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS ds, PetscInt f,
238030b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2381194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2382194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
238397b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
238430b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2385194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2386194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
238797b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
23882764a2aaSMatthew G. Knepley {
23892764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23902764a2aaSMatthew G. Knepley 
23912764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23926528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2393*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
239406ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1);CHKERRQ(ierr);
23952764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23962764a2aaSMatthew G. Knepley }
23972764a2aaSMatthew G. Knepley 
239827f02ce8SMatthew G. Knepley /*@
239927f02ce8SMatthew G. Knepley   PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set
240027f02ce8SMatthew G. Knepley 
240127f02ce8SMatthew G. Knepley   Not collective
240227f02ce8SMatthew G. Knepley 
240327f02ce8SMatthew G. Knepley   Input Parameter:
24046528b96dSMatthew G. Knepley . ds - The PetscDS
240527f02ce8SMatthew G. Knepley 
240627f02ce8SMatthew G. Knepley   Output Parameter:
240727f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set
240827f02ce8SMatthew G. Knepley 
240927f02ce8SMatthew G. Knepley   Level: intermediate
241027f02ce8SMatthew G. Knepley 
241127f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
241227f02ce8SMatthew G. Knepley @*/
24136528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac)
241427f02ce8SMatthew G. Knepley {
24156528b96dSMatthew G. Knepley   PetscErrorCode ierr;
241627f02ce8SMatthew G. Knepley 
241727f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24186528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24196528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJac, 2);
24206528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobian(ds->wf, hasBdJac);CHKERRQ(ierr);
242127f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
242227f02ce8SMatthew G. Knepley }
242327f02ce8SMatthew G. Knepley 
2424194d53e6SMatthew G. Knepley /*@C
2425194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2426194d53e6SMatthew G. Knepley 
2427194d53e6SMatthew G. Knepley   Not collective
2428194d53e6SMatthew G. Knepley 
2429194d53e6SMatthew G. Knepley   Input Parameters:
24306528b96dSMatthew G. Knepley + ds - The PetscDS
2431194d53e6SMatthew G. Knepley . f  - The test field number
2432194d53e6SMatthew G. Knepley - g  - The field number
2433194d53e6SMatthew G. Knepley 
2434194d53e6SMatthew G. Knepley   Output Parameters:
2435194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2436194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2437194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2438194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2439194d53e6SMatthew G. Knepley 
2440194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2441194d53e6SMatthew G. Knepley 
2442194d53e6SMatthew 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
2443194d53e6SMatthew G. Knepley 
2444194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2445194d53e6SMatthew G. Knepley 
244630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2447194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2448194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
244930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2450194d53e6SMatthew G. Knepley 
2451194d53e6SMatthew G. Knepley + dim - the spatial dimension
2452194d53e6SMatthew G. Knepley . Nf - the number of fields
2453194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2454194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2455194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2456194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2457194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2458194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2459194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2460194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2461194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2462194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2463194d53e6SMatthew G. Knepley . t - current time
24642aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2465194d53e6SMatthew G. Knepley . x - coordinates of the current point
2466194d53e6SMatthew G. Knepley . n - normal at the current point
246797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
246897b6e6e8SMatthew G. Knepley . constants - constant parameters
2469194d53e6SMatthew G. Knepley - g0 - output values at the current point
2470194d53e6SMatthew G. Knepley 
2471194d53e6SMatthew G. Knepley   Level: intermediate
2472194d53e6SMatthew G. Knepley 
2473194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2474194d53e6SMatthew G. Knepley @*/
24756528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
247630b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2477194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2478194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
247997b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
248030b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2481194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2482194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
248397b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
248430b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2485194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2486194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
248797b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
248830b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2489194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2490194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
249197b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
24922764a2aaSMatthew G. Knepley {
24936528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
24946528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
24956528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
24966528b96dSMatthew G. Knepley 
24972764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24986528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2499*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
2500*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((g < 0) || (g >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
250106ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
25026528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
25036528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
25046528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
25056528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
25062764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25072764a2aaSMatthew G. Knepley }
25082764a2aaSMatthew G. Knepley 
2509194d53e6SMatthew G. Knepley /*@C
2510194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2511194d53e6SMatthew G. Knepley 
2512194d53e6SMatthew G. Knepley   Not collective
2513194d53e6SMatthew G. Knepley 
2514194d53e6SMatthew G. Knepley   Input Parameters:
25156528b96dSMatthew G. Knepley + ds - The PetscDS
2516194d53e6SMatthew G. Knepley . f  - The test field number
2517194d53e6SMatthew G. Knepley . g  - The field number
2518194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2519194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2520194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2521194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2522194d53e6SMatthew G. Knepley 
2523194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2524194d53e6SMatthew G. Knepley 
2525194d53e6SMatthew 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
2526194d53e6SMatthew G. Knepley 
2527194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2528194d53e6SMatthew G. Knepley 
252930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2530194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2531194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
253230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2533194d53e6SMatthew G. Knepley 
2534194d53e6SMatthew G. Knepley + dim - the spatial dimension
2535194d53e6SMatthew G. Knepley . Nf - the number of fields
2536194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2537194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2538194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2539194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2540194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2541194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2542194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2543194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2544194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2545194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2546194d53e6SMatthew G. Knepley . t - current time
25472aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2548194d53e6SMatthew G. Knepley . x - coordinates of the current point
2549194d53e6SMatthew G. Knepley . n - normal at the current point
255097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
255197b6e6e8SMatthew G. Knepley . constants - constant parameters
2552194d53e6SMatthew G. Knepley - g0 - output values at the current point
2553194d53e6SMatthew G. Knepley 
2554194d53e6SMatthew G. Knepley   Level: intermediate
2555194d53e6SMatthew G. Knepley 
2556194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2557194d53e6SMatthew G. Knepley @*/
25586528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
255930b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2560194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2561194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
256297b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
256330b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2564194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2565194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
256697b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
256730b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2568194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2569194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
257097b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
257130b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2572194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2573194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
257497b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
25752764a2aaSMatthew G. Knepley {
25762764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25772764a2aaSMatthew G. Knepley 
25782764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25796528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
25802764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
25812764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
25822764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
25832764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
2584*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2585*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(g < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
258606ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
25872764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25882764a2aaSMatthew G. Knepley }
25892764a2aaSMatthew G. Knepley 
259027f02ce8SMatthew G. Knepley /*@
259127f02ce8SMatthew G. Knepley   PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set
259227f02ce8SMatthew G. Knepley 
259327f02ce8SMatthew G. Knepley   Not collective
259427f02ce8SMatthew G. Knepley 
259527f02ce8SMatthew G. Knepley   Input Parameter:
25966528b96dSMatthew G. Knepley . ds - The PetscDS
259727f02ce8SMatthew G. Knepley 
259827f02ce8SMatthew G. Knepley   Output Parameter:
259927f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set
260027f02ce8SMatthew G. Knepley 
260127f02ce8SMatthew G. Knepley   Level: intermediate
260227f02ce8SMatthew G. Knepley 
260327f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
260427f02ce8SMatthew G. Knepley @*/
26056528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre)
260627f02ce8SMatthew G. Knepley {
26076528b96dSMatthew G. Knepley   PetscErrorCode ierr;
260827f02ce8SMatthew G. Knepley 
260927f02ce8SMatthew G. Knepley   PetscFunctionBegin;
26106528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
26116528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJacPre, 2);
26126528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre);CHKERRQ(ierr);
261327f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
261427f02ce8SMatthew G. Knepley }
261527f02ce8SMatthew G. Knepley 
261627f02ce8SMatthew G. Knepley /*@C
261727f02ce8SMatthew G. Knepley   PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field
261827f02ce8SMatthew G. Knepley 
261927f02ce8SMatthew G. Knepley   Not collective
262027f02ce8SMatthew G. Knepley 
262127f02ce8SMatthew G. Knepley   Input Parameters:
26226528b96dSMatthew G. Knepley + ds - The PetscDS
262327f02ce8SMatthew G. Knepley . f  - The test field number
262427f02ce8SMatthew G. Knepley - g  - The field number
262527f02ce8SMatthew G. Knepley 
262627f02ce8SMatthew G. Knepley   Output Parameters:
262727f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term
262827f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
262927f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
263027f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
263127f02ce8SMatthew G. Knepley 
263227f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
263327f02ce8SMatthew G. Knepley 
263427f02ce8SMatthew 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
263527f02ce8SMatthew G. Knepley 
263627f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
263727f02ce8SMatthew G. Knepley 
263827f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
263927f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
264027f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
264127f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
264227f02ce8SMatthew G. Knepley 
264327f02ce8SMatthew G. Knepley + dim - the spatial dimension
264427f02ce8SMatthew G. Knepley . Nf - the number of fields
264527f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
264627f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
264727f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
264827f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
264927f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
265027f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
265127f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
265227f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
265327f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
265427f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
265527f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
265627f02ce8SMatthew G. Knepley . t - current time
265727f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
265827f02ce8SMatthew G. Knepley . x - coordinates of the current point
265927f02ce8SMatthew G. Knepley . n - normal at the current point
266027f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
266127f02ce8SMatthew G. Knepley . constants - constant parameters
266227f02ce8SMatthew G. Knepley - g0 - output values at the current point
266327f02ce8SMatthew G. Knepley 
266427f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
266527f02ce8SMatthew G. Knepley 
266627f02ce8SMatthew G. Knepley   Level: intermediate
266727f02ce8SMatthew G. Knepley 
266827f02ce8SMatthew G. Knepley .seealso: PetscDSSetBdJacobianPreconditioner()
266927f02ce8SMatthew G. Knepley @*/
26706528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
267127f02ce8SMatthew G. Knepley                                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
267227f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
267327f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
267427f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
267527f02ce8SMatthew G. Knepley                                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
267627f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
267727f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
267827f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
267927f02ce8SMatthew G. Knepley                                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
268027f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
268127f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
268227f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
268327f02ce8SMatthew G. Knepley                                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
268427f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
268527f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
268627f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
268727f02ce8SMatthew G. Knepley {
26886528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
26896528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
26906528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
26916528b96dSMatthew G. Knepley 
269227f02ce8SMatthew G. Knepley   PetscFunctionBegin;
26936528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2694*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
2695*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((g < 0) || (g >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
269606ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
26976528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
26986528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
26996528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
27006528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
270127f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
270227f02ce8SMatthew G. Knepley }
270327f02ce8SMatthew G. Knepley 
270427f02ce8SMatthew G. Knepley /*@C
270527f02ce8SMatthew G. Knepley   PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field
270627f02ce8SMatthew G. Knepley 
270727f02ce8SMatthew G. Knepley   Not collective
270827f02ce8SMatthew G. Knepley 
270927f02ce8SMatthew G. Knepley   Input Parameters:
27106528b96dSMatthew G. Knepley + ds - The PetscDS
271127f02ce8SMatthew G. Knepley . f  - The test field number
271227f02ce8SMatthew G. Knepley . g  - The field number
271327f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term
271427f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
271527f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
271627f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
271727f02ce8SMatthew G. Knepley 
271827f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
271927f02ce8SMatthew G. Knepley 
272027f02ce8SMatthew 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
272127f02ce8SMatthew G. Knepley 
272227f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
272327f02ce8SMatthew G. Knepley 
272427f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
272527f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
272627f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
272727f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
272827f02ce8SMatthew G. Knepley 
272927f02ce8SMatthew G. Knepley + dim - the spatial dimension
273027f02ce8SMatthew G. Knepley . Nf - the number of fields
273127f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
273227f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
273327f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
273427f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
273527f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
273627f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
273727f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
273827f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
273927f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
274027f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
274127f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
274227f02ce8SMatthew G. Knepley . t - current time
274327f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
274427f02ce8SMatthew G. Knepley . x - coordinates of the current point
274527f02ce8SMatthew G. Knepley . n - normal at the current point
274627f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
274727f02ce8SMatthew G. Knepley . constants - constant parameters
274827f02ce8SMatthew G. Knepley - g0 - output values at the current point
274927f02ce8SMatthew G. Knepley 
275027f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
275127f02ce8SMatthew G. Knepley 
275227f02ce8SMatthew G. Knepley   Level: intermediate
275327f02ce8SMatthew G. Knepley 
275427f02ce8SMatthew G. Knepley .seealso: PetscDSGetBdJacobianPreconditioner()
275527f02ce8SMatthew G. Knepley @*/
27566528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
275727f02ce8SMatthew G. Knepley                                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
275827f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
275927f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
276027f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
276127f02ce8SMatthew G. Knepley                                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
276227f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
276327f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
276427f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
276527f02ce8SMatthew G. Knepley                                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
276627f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
276727f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
276827f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
276927f02ce8SMatthew G. Knepley                                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
277027f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
277127f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
277227f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
277327f02ce8SMatthew G. Knepley {
277427f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
277527f02ce8SMatthew G. Knepley 
277627f02ce8SMatthew G. Knepley   PetscFunctionBegin;
27776528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
277827f02ce8SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
277927f02ce8SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
278027f02ce8SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
278127f02ce8SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
2782*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2783*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(g < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
278406ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
278527f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
278627f02ce8SMatthew G. Knepley }
278727f02ce8SMatthew G. Knepley 
27880d3e9b51SMatthew G. Knepley /*@C
2789c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2790c371a6d1SMatthew G. Knepley 
2791c371a6d1SMatthew G. Knepley   Not collective
2792c371a6d1SMatthew G. Knepley 
2793c371a6d1SMatthew G. Knepley   Input Parameters:
2794c371a6d1SMatthew G. Knepley + prob - The PetscDS
2795c371a6d1SMatthew G. Knepley - f    - The test field number
2796c371a6d1SMatthew G. Knepley 
2797d8d19677SJose E. Roman   Output Parameters:
279895cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field
279995cbbfd3SMatthew G. Knepley - exactCtx - exact solution context
2800c371a6d1SMatthew G. Knepley 
2801c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2802c371a6d1SMatthew G. Knepley 
2803c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2804c371a6d1SMatthew G. Knepley 
2805c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2806c371a6d1SMatthew G. Knepley . t - current time
2807c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2808c371a6d1SMatthew G. Knepley . Nc - the number of field components
2809c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2810c371a6d1SMatthew G. Knepley - ctx - a user context
2811c371a6d1SMatthew G. Knepley 
2812c371a6d1SMatthew G. Knepley   Level: intermediate
2813c371a6d1SMatthew G. Knepley 
2814f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolution(), PetscDSGetExactSolutionTimeDerivative()
2815c371a6d1SMatthew G. Knepley @*/
281695cbbfd3SMatthew 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)
2817c371a6d1SMatthew G. Knepley {
2818c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2819c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2820*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= prob->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
2821c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
282295cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];}
2823c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2824c371a6d1SMatthew G. Knepley }
2825c371a6d1SMatthew G. Knepley 
2826c371a6d1SMatthew G. Knepley /*@C
2827578a5ef5SMatthew Knepley   PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field
2828c371a6d1SMatthew G. Knepley 
2829c371a6d1SMatthew G. Knepley   Not collective
2830c371a6d1SMatthew G. Knepley 
2831c371a6d1SMatthew G. Knepley   Input Parameters:
2832c371a6d1SMatthew G. Knepley + prob - The PetscDS
2833c371a6d1SMatthew G. Knepley . f    - The test field number
283495cbbfd3SMatthew G. Knepley . sol  - solution function for the test fields
283595cbbfd3SMatthew G. Knepley - ctx  - solution context or NULL
2836c371a6d1SMatthew G. Knepley 
2837c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2838c371a6d1SMatthew G. Knepley 
2839c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2840c371a6d1SMatthew G. Knepley 
2841c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2842c371a6d1SMatthew G. Knepley . t - current time
2843c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2844c371a6d1SMatthew G. Knepley . Nc - the number of field components
2845c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2846c371a6d1SMatthew G. Knepley - ctx - a user context
2847c371a6d1SMatthew G. Knepley 
2848c371a6d1SMatthew G. Knepley   Level: intermediate
2849c371a6d1SMatthew G. Knepley 
2850c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2851c371a6d1SMatthew G. Knepley @*/
285295cbbfd3SMatthew 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)
2853c371a6d1SMatthew G. Knepley {
2854c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2855c371a6d1SMatthew G. Knepley 
2856c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2857c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2858*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2859c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2860c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
286195cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;}
2862c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2863c371a6d1SMatthew G. Knepley }
2864c371a6d1SMatthew G. Knepley 
28655638fd0eSMatthew G. Knepley /*@C
2866f2cacb80SMatthew G. Knepley   PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field
2867f2cacb80SMatthew G. Knepley 
2868f2cacb80SMatthew G. Knepley   Not collective
2869f2cacb80SMatthew G. Knepley 
2870f2cacb80SMatthew G. Knepley   Input Parameters:
2871f2cacb80SMatthew G. Knepley + prob - The PetscDS
2872f2cacb80SMatthew G. Knepley - f    - The test field number
2873f2cacb80SMatthew G. Knepley 
2874d8d19677SJose E. Roman   Output Parameters:
2875f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field
2876f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context
2877f2cacb80SMatthew G. Knepley 
2878f2cacb80SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2879f2cacb80SMatthew G. Knepley 
2880f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2881f2cacb80SMatthew G. Knepley 
2882f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2883f2cacb80SMatthew G. Knepley . t - current time
2884f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2885f2cacb80SMatthew G. Knepley . Nc - the number of field components
2886f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2887f2cacb80SMatthew G. Knepley - ctx - a user context
2888f2cacb80SMatthew G. Knepley 
2889f2cacb80SMatthew G. Knepley   Level: intermediate
2890f2cacb80SMatthew G. Knepley 
2891f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolutionTimeDerivative(), PetscDSGetExactSolution()
2892f2cacb80SMatthew G. Knepley @*/
2893f2cacb80SMatthew 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)
2894f2cacb80SMatthew G. Knepley {
2895f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2896f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2897*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= prob->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
2898f2cacb80SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol_t[f];}
2899f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx_t[f];}
2900f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2901f2cacb80SMatthew G. Knepley }
2902f2cacb80SMatthew G. Knepley 
2903f2cacb80SMatthew G. Knepley /*@C
2904f2cacb80SMatthew G. Knepley   PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field
2905f2cacb80SMatthew G. Knepley 
2906f2cacb80SMatthew G. Knepley   Not collective
2907f2cacb80SMatthew G. Knepley 
2908f2cacb80SMatthew G. Knepley   Input Parameters:
2909f2cacb80SMatthew G. Knepley + prob - The PetscDS
2910f2cacb80SMatthew G. Knepley . f    - The test field number
2911f2cacb80SMatthew G. Knepley . sol  - time derivative of the solution function for the test fields
2912f2cacb80SMatthew G. Knepley - ctx  - time derivative of the solution context or NULL
2913f2cacb80SMatthew G. Knepley 
2914f2cacb80SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2915f2cacb80SMatthew G. Knepley 
2916f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2917f2cacb80SMatthew G. Knepley 
2918f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2919f2cacb80SMatthew G. Knepley . t - current time
2920f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2921f2cacb80SMatthew G. Knepley . Nc - the number of field components
2922f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2923f2cacb80SMatthew G. Knepley - ctx - a user context
2924f2cacb80SMatthew G. Knepley 
2925f2cacb80SMatthew G. Knepley   Level: intermediate
2926f2cacb80SMatthew G. Knepley 
2927f2cacb80SMatthew G. Knepley .seealso: PetscDSGetExactSolutionTimeDerivative(), PetscDSSetExactSolution()
2928f2cacb80SMatthew G. Knepley @*/
2929f2cacb80SMatthew 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)
2930f2cacb80SMatthew G. Knepley {
2931f2cacb80SMatthew G. Knepley   PetscErrorCode ierr;
2932f2cacb80SMatthew G. Knepley 
2933f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2934f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2935*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f < 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2936f2cacb80SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2937f2cacb80SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol_t[f] = sol;}
2938f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx_t[f] = ctx;}
2939f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2940f2cacb80SMatthew G. Knepley }
2941f2cacb80SMatthew G. Knepley 
2942f2cacb80SMatthew G. Knepley /*@C
294397b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
294497b6e6e8SMatthew G. Knepley 
294597b6e6e8SMatthew G. Knepley   Not collective
294697b6e6e8SMatthew G. Knepley 
294797b6e6e8SMatthew G. Knepley   Input Parameter:
294897b6e6e8SMatthew G. Knepley . prob - The PetscDS object
294997b6e6e8SMatthew G. Knepley 
295097b6e6e8SMatthew G. Knepley   Output Parameters:
295197b6e6e8SMatthew G. Knepley + numConstants - The number of constants
295297b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
295397b6e6e8SMatthew G. Knepley 
295497b6e6e8SMatthew G. Knepley   Level: intermediate
295597b6e6e8SMatthew G. Knepley 
295697b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
295797b6e6e8SMatthew G. Knepley @*/
295897b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
295997b6e6e8SMatthew G. Knepley {
296097b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
296197b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
296297b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
296397b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
296497b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
296597b6e6e8SMatthew G. Knepley }
296697b6e6e8SMatthew G. Knepley 
29670d3e9b51SMatthew G. Knepley /*@C
296897b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
296997b6e6e8SMatthew G. Knepley 
297097b6e6e8SMatthew G. Knepley   Not collective
297197b6e6e8SMatthew G. Knepley 
297297b6e6e8SMatthew G. Knepley   Input Parameters:
297397b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
297497b6e6e8SMatthew G. Knepley . numConstants - The number of constants
297597b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
297697b6e6e8SMatthew G. Knepley 
297797b6e6e8SMatthew G. Knepley   Level: intermediate
297897b6e6e8SMatthew G. Knepley 
297997b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
298097b6e6e8SMatthew G. Knepley @*/
298197b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
298297b6e6e8SMatthew G. Knepley {
298397b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
298497b6e6e8SMatthew G. Knepley 
298597b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
298697b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
298797b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
298897b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
298997b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
299097b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
299197b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
299220be0f5bSMatthew G. Knepley     } else {
299320be0f5bSMatthew G. Knepley       prob->constants = NULL;
299420be0f5bSMatthew G. Knepley     }
299520be0f5bSMatthew G. Knepley   }
299620be0f5bSMatthew G. Knepley   if (prob->numConstants) {
299720be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
2998580bdb30SBarry Smith     ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr);
299997b6e6e8SMatthew G. Knepley   }
300097b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
300197b6e6e8SMatthew G. Knepley }
300297b6e6e8SMatthew G. Knepley 
30034cd1e086SMatthew G. Knepley /*@
30044cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
30054cd1e086SMatthew G. Knepley 
30064cd1e086SMatthew G. Knepley   Not collective
30074cd1e086SMatthew G. Knepley 
30084cd1e086SMatthew G. Knepley   Input Parameters:
30094cd1e086SMatthew G. Knepley + prob - The PetscDS object
30104cd1e086SMatthew G. Knepley - disc - The discretization object
30114cd1e086SMatthew G. Knepley 
30124cd1e086SMatthew G. Knepley   Output Parameter:
30134cd1e086SMatthew G. Knepley . f - The field number
30144cd1e086SMatthew G. Knepley 
30154cd1e086SMatthew G. Knepley   Level: beginner
30164cd1e086SMatthew G. Knepley 
3017f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
30184cd1e086SMatthew G. Knepley @*/
30194cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
30204cd1e086SMatthew G. Knepley {
30214cd1e086SMatthew G. Knepley   PetscInt g;
30224cd1e086SMatthew G. Knepley 
30234cd1e086SMatthew G. Knepley   PetscFunctionBegin;
30244cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30254cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
30264cd1e086SMatthew G. Knepley   *f = -1;
30274cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
3028*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(g == prob->Nf,PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
30294cd1e086SMatthew G. Knepley   *f = g;
30304cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
30314cd1e086SMatthew G. Knepley }
30324cd1e086SMatthew G. Knepley 
30334cd1e086SMatthew G. Knepley /*@
30344cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
30354cd1e086SMatthew G. Knepley 
30364cd1e086SMatthew G. Knepley   Not collective
30374cd1e086SMatthew G. Knepley 
30384cd1e086SMatthew G. Knepley   Input Parameters:
30394cd1e086SMatthew G. Knepley + prob - The PetscDS object
30404cd1e086SMatthew G. Knepley - f - The field number
30414cd1e086SMatthew G. Knepley 
30424cd1e086SMatthew G. Knepley   Output Parameter:
30434cd1e086SMatthew G. Knepley . size - The size
30444cd1e086SMatthew G. Knepley 
30454cd1e086SMatthew G. Knepley   Level: beginner
30464cd1e086SMatthew G. Knepley 
3047f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
30484cd1e086SMatthew G. Knepley @*/
30494cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
30504cd1e086SMatthew G. Knepley {
30512166fd64SMatthew G. Knepley   PetscErrorCode ierr;
30522166fd64SMatthew G. Knepley 
30534cd1e086SMatthew G. Knepley   PetscFunctionBegin;
30544cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30554cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
3056*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= prob->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
30572166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3058d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
30594cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
30604cd1e086SMatthew G. Knepley }
30614cd1e086SMatthew G. Knepley 
3062bc4ae4beSMatthew G. Knepley /*@
3063bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
3064bc4ae4beSMatthew G. Knepley 
3065bc4ae4beSMatthew G. Knepley   Not collective
3066bc4ae4beSMatthew G. Knepley 
3067bc4ae4beSMatthew G. Knepley   Input Parameters:
3068bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
3069bc4ae4beSMatthew G. Knepley - f - The field number
3070bc4ae4beSMatthew G. Knepley 
3071bc4ae4beSMatthew G. Knepley   Output Parameter:
3072bc4ae4beSMatthew G. Knepley . off - The offset
3073bc4ae4beSMatthew G. Knepley 
3074bc4ae4beSMatthew G. Knepley   Level: beginner
3075bc4ae4beSMatthew G. Knepley 
3076f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
3077bc4ae4beSMatthew G. Knepley @*/
30782764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
30792764a2aaSMatthew G. Knepley {
30804cd1e086SMatthew G. Knepley   PetscInt       size, g;
30812764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30822764a2aaSMatthew G. Knepley 
30832764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30842764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30852764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
3086*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= prob->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
30872764a2aaSMatthew G. Knepley   *off = 0;
30882764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
30894cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
30904cd1e086SMatthew G. Knepley     *off += size;
30912764a2aaSMatthew G. Knepley   }
30922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30932764a2aaSMatthew G. Knepley }
30942764a2aaSMatthew G. Knepley 
3095bc4ae4beSMatthew G. Knepley /*@
30965fedec97SMatthew G. Knepley   PetscDSGetFieldOffsetCohesive - Returns the offset of the given field in the full space basis on a cohesive cell
30975fedec97SMatthew G. Knepley 
30985fedec97SMatthew G. Knepley   Not collective
30995fedec97SMatthew G. Knepley 
31005fedec97SMatthew G. Knepley   Input Parameters:
31015fedec97SMatthew G. Knepley + prob - The PetscDS object
31025fedec97SMatthew G. Knepley - f - The field number
31035fedec97SMatthew G. Knepley 
31045fedec97SMatthew G. Knepley   Output Parameter:
31055fedec97SMatthew G. Knepley . off - The offset
31065fedec97SMatthew G. Knepley 
31075fedec97SMatthew G. Knepley   Level: beginner
31085fedec97SMatthew G. Knepley 
31095fedec97SMatthew G. Knepley .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
31105fedec97SMatthew G. Knepley @*/
31115fedec97SMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffsetCohesive(PetscDS ds, PetscInt f, PetscInt *off)
31125fedec97SMatthew G. Knepley {
31135fedec97SMatthew G. Knepley   PetscInt       size, g;
31145fedec97SMatthew G. Knepley   PetscErrorCode ierr;
31155fedec97SMatthew G. Knepley 
31165fedec97SMatthew G. Knepley   PetscFunctionBegin;
31175fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
31185fedec97SMatthew G. Knepley   PetscValidPointer(off, 3);
3119*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= ds->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
31205fedec97SMatthew G. Knepley   *off = 0;
31215fedec97SMatthew G. Knepley   for (g = 0; g < f; ++g) {
31225fedec97SMatthew G. Knepley     PetscBool cohesive;
31235fedec97SMatthew G. Knepley 
31245fedec97SMatthew G. Knepley     ierr = PetscDSGetCohesive(ds, g, &cohesive);CHKERRQ(ierr);
31255fedec97SMatthew G. Knepley     ierr = PetscDSGetFieldSize(ds, g, &size);CHKERRQ(ierr);
31265fedec97SMatthew G. Knepley     *off += cohesive ? size : size*2;
31275fedec97SMatthew G. Knepley   }
31285fedec97SMatthew G. Knepley   PetscFunctionReturn(0);
31295fedec97SMatthew G. Knepley }
31305fedec97SMatthew G. Knepley 
31315fedec97SMatthew G. Knepley /*@
313247e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
3133bc4ae4beSMatthew G. Knepley 
3134bc4ae4beSMatthew G. Knepley   Not collective
3135bc4ae4beSMatthew G. Knepley 
313647e57110SSander Arens   Input Parameter:
313747e57110SSander Arens . prob - The PetscDS object
3138bc4ae4beSMatthew G. Knepley 
3139bc4ae4beSMatthew G. Knepley   Output Parameter:
314047e57110SSander Arens . dimensions - The number of dimensions
3141bc4ae4beSMatthew G. Knepley 
3142bc4ae4beSMatthew G. Knepley   Level: beginner
3143bc4ae4beSMatthew G. Knepley 
314447e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
3145bc4ae4beSMatthew G. Knepley @*/
314647e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
31472764a2aaSMatthew G. Knepley {
31482764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
31492764a2aaSMatthew G. Knepley 
31502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31512764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
315247e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
315347e57110SSander Arens   PetscValidPointer(dimensions, 2);
315447e57110SSander Arens   *dimensions = prob->Nb;
315547e57110SSander Arens   PetscFunctionReturn(0);
31566ce16762SMatthew G. Knepley }
315747e57110SSander Arens 
315847e57110SSander Arens /*@
315947e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
316047e57110SSander Arens 
316147e57110SSander Arens   Not collective
316247e57110SSander Arens 
316347e57110SSander Arens   Input Parameter:
316447e57110SSander Arens . prob - The PetscDS object
316547e57110SSander Arens 
316647e57110SSander Arens   Output Parameter:
316747e57110SSander Arens . components - The number of components
316847e57110SSander Arens 
316947e57110SSander Arens   Level: beginner
317047e57110SSander Arens 
317147e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
317247e57110SSander Arens @*/
317347e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
317447e57110SSander Arens {
317547e57110SSander Arens   PetscErrorCode ierr;
317647e57110SSander Arens 
317747e57110SSander Arens   PetscFunctionBegin;
317847e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
317947e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
318047e57110SSander Arens   PetscValidPointer(components, 2);
318147e57110SSander Arens   *components = prob->Nc;
31826ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
31836ce16762SMatthew G. Knepley }
31846ce16762SMatthew G. Knepley 
31856ce16762SMatthew G. Knepley /*@
31866ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
31876ce16762SMatthew G. Knepley 
31886ce16762SMatthew G. Knepley   Not collective
31896ce16762SMatthew G. Knepley 
31906ce16762SMatthew G. Knepley   Input Parameters:
31916ce16762SMatthew G. Knepley + prob - The PetscDS object
31926ce16762SMatthew G. Knepley - f - The field number
31936ce16762SMatthew G. Knepley 
31946ce16762SMatthew G. Knepley   Output Parameter:
31956ce16762SMatthew G. Knepley . off - The offset
31966ce16762SMatthew G. Knepley 
31976ce16762SMatthew G. Knepley   Level: beginner
31986ce16762SMatthew G. Knepley 
3199f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
32006ce16762SMatthew G. Knepley @*/
32016ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
32026ce16762SMatthew G. Knepley {
3203e1d313ffSMatthew G. Knepley   PetscErrorCode ierr;
3204e1d313ffSMatthew G. Knepley 
32056ce16762SMatthew G. Knepley   PetscFunctionBegin;
32066ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
32076ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
3208*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((f < 0) || (f >= prob->Nf),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
3209e1d313ffSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
321047e57110SSander Arens   *off = prob->off[f];
32112764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
32122764a2aaSMatthew G. Knepley }
32132764a2aaSMatthew G. Knepley 
3214194d53e6SMatthew G. Knepley /*@
3215194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
3216194d53e6SMatthew G. Knepley 
3217194d53e6SMatthew G. Knepley   Not collective
3218194d53e6SMatthew G. Knepley 
3219194d53e6SMatthew G. Knepley   Input Parameter:
3220194d53e6SMatthew G. Knepley . prob - The PetscDS object
3221194d53e6SMatthew G. Knepley 
3222194d53e6SMatthew G. Knepley   Output Parameter:
3223194d53e6SMatthew G. Knepley . offsets - The offsets
3224194d53e6SMatthew G. Knepley 
3225194d53e6SMatthew G. Knepley   Level: beginner
3226194d53e6SMatthew G. Knepley 
3227f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
3228194d53e6SMatthew G. Knepley @*/
3229194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
3230194d53e6SMatthew G. Knepley {
3231e1d313ffSMatthew G. Knepley   PetscErrorCode ierr;
3232e1d313ffSMatthew G. Knepley 
3233194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3234194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3235194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
3236e1d313ffSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3237194d53e6SMatthew G. Knepley   *offsets = prob->off;
3238194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
3239194d53e6SMatthew G. Knepley }
3240194d53e6SMatthew G. Knepley 
3241194d53e6SMatthew G. Knepley /*@
3242194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
3243194d53e6SMatthew G. Knepley 
3244194d53e6SMatthew G. Knepley   Not collective
3245194d53e6SMatthew G. Knepley 
3246194d53e6SMatthew G. Knepley   Input Parameter:
3247194d53e6SMatthew G. Knepley . prob - The PetscDS object
3248194d53e6SMatthew G. Knepley 
3249194d53e6SMatthew G. Knepley   Output Parameter:
3250194d53e6SMatthew G. Knepley . offsets - The offsets
3251194d53e6SMatthew G. Knepley 
3252194d53e6SMatthew G. Knepley   Level: beginner
3253194d53e6SMatthew G. Knepley 
3254f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
3255194d53e6SMatthew G. Knepley @*/
3256194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
3257194d53e6SMatthew G. Knepley {
3258e1d313ffSMatthew G. Knepley   PetscErrorCode ierr;
3259e1d313ffSMatthew G. Knepley 
3260194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3261194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3262194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
3263e1d313ffSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3264194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
3265194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
3266194d53e6SMatthew G. Knepley }
3267194d53e6SMatthew G. Knepley 
32689ee2af8cSMatthew G. Knepley /*@
32699ee2af8cSMatthew G. Knepley   PetscDSGetComponentOffsetsCohesive - Returns the offset of each field on an evaluation point
32709ee2af8cSMatthew G. Knepley 
32719ee2af8cSMatthew G. Knepley   Not collective
32729ee2af8cSMatthew G. Knepley 
32739ee2af8cSMatthew G. Knepley   Input Parameters:
32749ee2af8cSMatthew G. Knepley + ds - The PetscDS object
32759ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
32769ee2af8cSMatthew G. Knepley 
32779ee2af8cSMatthew G. Knepley   Output Parameter:
32789ee2af8cSMatthew G. Knepley . offsets - The offsets
32799ee2af8cSMatthew G. Knepley 
32809ee2af8cSMatthew G. Knepley   Level: beginner
32819ee2af8cSMatthew G. Knepley 
32829ee2af8cSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
32839ee2af8cSMatthew G. Knepley @*/
32849ee2af8cSMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
32859ee2af8cSMatthew G. Knepley {
32869ee2af8cSMatthew G. Knepley   PetscErrorCode ierr;
32879ee2af8cSMatthew G. Knepley 
32889ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
32899ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
32909ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
3291*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(!ds->isCohesive,PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
3292*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((s < 0) || (s > 2),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %D is not in [0, 2]", s);
32939ee2af8cSMatthew G. Knepley   ierr = PetscDSSetUp(ds);CHKERRQ(ierr);
32949ee2af8cSMatthew G. Knepley   *offsets = ds->offCohesive[s];
32959ee2af8cSMatthew G. Knepley   PetscFunctionReturn(0);
32969ee2af8cSMatthew G. Knepley }
32979ee2af8cSMatthew G. Knepley 
32989ee2af8cSMatthew G. Knepley /*@
32999ee2af8cSMatthew G. Knepley   PetscDSGetComponentDerivativeOffsetsCohesive - Returns the offset of each field derivative on an evaluation point
33009ee2af8cSMatthew G. Knepley 
33019ee2af8cSMatthew G. Knepley   Not collective
33029ee2af8cSMatthew G. Knepley 
33039ee2af8cSMatthew G. Knepley   Input Parameters:
33049ee2af8cSMatthew G. Knepley + ds - The PetscDS object
33059ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
33069ee2af8cSMatthew G. Knepley 
33079ee2af8cSMatthew G. Knepley   Output Parameter:
33089ee2af8cSMatthew G. Knepley . offsets - The offsets
33099ee2af8cSMatthew G. Knepley 
33109ee2af8cSMatthew G. Knepley   Level: beginner
33119ee2af8cSMatthew G. Knepley 
33129ee2af8cSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
33139ee2af8cSMatthew G. Knepley @*/
33149ee2af8cSMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
33159ee2af8cSMatthew G. Knepley {
33169ee2af8cSMatthew G. Knepley   PetscErrorCode ierr;
33179ee2af8cSMatthew G. Knepley 
33189ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
33199ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
33209ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
3321*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(!ds->isCohesive,PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
3322*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse((s < 0) || (s > 2),PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %D is not in [0, 2]", s);
33239ee2af8cSMatthew G. Knepley   ierr = PetscDSSetUp(ds);CHKERRQ(ierr);
33249ee2af8cSMatthew G. Knepley   *offsets = ds->offDerCohesive[s];
33259ee2af8cSMatthew G. Knepley   PetscFunctionReturn(0);
33269ee2af8cSMatthew G. Knepley }
33279ee2af8cSMatthew G. Knepley 
332868c9edb9SMatthew G. Knepley /*@C
332968c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
333068c9edb9SMatthew G. Knepley 
333168c9edb9SMatthew G. Knepley   Not collective
333268c9edb9SMatthew G. Knepley 
333368c9edb9SMatthew G. Knepley   Input Parameter:
333468c9edb9SMatthew G. Knepley . prob - The PetscDS object
333568c9edb9SMatthew G. Knepley 
3336ef0bb6c7SMatthew G. Knepley   Output Parameter:
3337ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field
333868c9edb9SMatthew G. Knepley 
333968c9edb9SMatthew G. Knepley   Level: intermediate
334068c9edb9SMatthew G. Knepley 
3341f744cafaSSander Arens .seealso: PetscDSCreate()
334268c9edb9SMatthew G. Knepley @*/
3343ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[])
33442764a2aaSMatthew G. Knepley {
33452764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
33462764a2aaSMatthew G. Knepley 
33472764a2aaSMatthew G. Knepley   PetscFunctionBegin;
33482764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3349ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
33502764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3351ef0bb6c7SMatthew G. Knepley   *T = prob->T;
33522764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
33532764a2aaSMatthew G. Knepley }
33542764a2aaSMatthew G. Knepley 
335568c9edb9SMatthew G. Knepley /*@C
33564d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
335768c9edb9SMatthew G. Knepley 
335868c9edb9SMatthew G. Knepley   Not collective
335968c9edb9SMatthew G. Knepley 
336068c9edb9SMatthew G. Knepley   Input Parameter:
336168c9edb9SMatthew G. Knepley . prob - The PetscDS object
336268c9edb9SMatthew G. Knepley 
3363ef0bb6c7SMatthew G. Knepley   Output Parameter:
3364a5b23f4aSJose E. Roman . Tf - The basis function and derivative tabulation on each local face at quadrature points for each and field
336568c9edb9SMatthew G. Knepley 
336668c9edb9SMatthew G. Knepley   Level: intermediate
336768c9edb9SMatthew G. Knepley 
336868c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
336968c9edb9SMatthew G. Knepley @*/
3370ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[])
33712764a2aaSMatthew G. Knepley {
33722764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
33732764a2aaSMatthew G. Knepley 
33742764a2aaSMatthew G. Knepley   PetscFunctionBegin;
33752764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3376ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
33772764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3378ef0bb6c7SMatthew G. Knepley   *Tf = prob->Tf;
33792764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
33802764a2aaSMatthew G. Knepley }
33812764a2aaSMatthew G. Knepley 
33822764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
33832764a2aaSMatthew G. Knepley {
33842764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
33852764a2aaSMatthew G. Knepley 
33862764a2aaSMatthew G. Knepley   PetscFunctionBegin;
33872764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
33882764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
33892764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
33902764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
33912764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
33922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
33932764a2aaSMatthew G. Knepley }
33942764a2aaSMatthew G. Knepley 
33952764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
33962764a2aaSMatthew G. Knepley {
33972764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
33982764a2aaSMatthew G. Knepley 
33992764a2aaSMatthew G. Knepley   PetscFunctionBegin;
34002764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
34012764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
34022764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
34032764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
34042764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
34052764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
34062764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
34072764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
34082764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
34092764a2aaSMatthew G. Knepley }
34102764a2aaSMatthew G. Knepley 
34114bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal)
34122764a2aaSMatthew G. Knepley {
34132764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
34142764a2aaSMatthew G. Knepley 
34152764a2aaSMatthew G. Knepley   PetscFunctionBegin;
34162764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
34172764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
34182764a2aaSMatthew G. Knepley   if (x)            {PetscValidPointer(x, 2);            *x            = prob->x;}
34194bee2e38SMatthew G. Knepley   if (basisReal)    {PetscValidPointer(basisReal, 3);    *basisReal    = prob->basisReal;}
34207506b574SStefano Zampini   if (basisDerReal) {PetscValidPointer(basisDerReal, 4); *basisDerReal = prob->basisDerReal;}
34217506b574SStefano Zampini   if (testReal)     {PetscValidPointer(testReal, 5);     *testReal     = prob->testReal;}
34227506b574SStefano Zampini   if (testDerReal)  {PetscValidPointer(testDerReal, 6);  *testDerReal  = prob->testDerReal;}
34232764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
34242764a2aaSMatthew G. Knepley }
34252764a2aaSMatthew G. Knepley 
342658ebd649SToby Isaac /*@C
342756cf3b9cSMatthew 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().
342858ebd649SToby Isaac 
3429783e2ec8SMatthew G. Knepley   Collective on ds
3430783e2ec8SMatthew G. Knepley 
343158ebd649SToby Isaac   Input Parameters:
343258ebd649SToby Isaac + ds       - The PetscDS object
34332d47a189SJulian Andrej . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
343458ebd649SToby Isaac . name     - The BC name
343545480ffeSMatthew G. Knepley . label    - The label defining constrained points
343645480ffeSMatthew G. Knepley . Nv       - The number of DMLabel values for constrained points
343745480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
343858ebd649SToby Isaac . field    - The field to constrain
343945480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
344058ebd649SToby Isaac . comps    - An array of constrained component numbers
344158ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3442a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
344358ebd649SToby Isaac - ctx      - An optional user context for bcFunc
344458ebd649SToby Isaac 
344545480ffeSMatthew G. Knepley   Output Parameters:
344645480ffeSMatthew G. Knepley - bd       - The boundary number
344745480ffeSMatthew G. Knepley 
344858ebd649SToby Isaac   Options Database Keys:
344958ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
345058ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
345158ebd649SToby Isaac 
345256cf3b9cSMatthew G. Knepley   Note:
345356cf3b9cSMatthew 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:
345456cf3b9cSMatthew G. Knepley 
345556cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
345656cf3b9cSMatthew G. Knepley 
345756cf3b9cSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
345856cf3b9cSMatthew G. Knepley 
345956cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
346056cf3b9cSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
346156cf3b9cSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
346256cf3b9cSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
346356cf3b9cSMatthew G. Knepley 
346456cf3b9cSMatthew G. Knepley + dim - the spatial dimension
346556cf3b9cSMatthew G. Knepley . Nf - the number of fields
346656cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
346756cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
346856cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point
346956cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
347056cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
347156cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
347256cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
347356cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
347456cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
347556cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
347656cf3b9cSMatthew G. Knepley . t - current time
347756cf3b9cSMatthew G. Knepley . x - coordinates of the current point
347856cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters
347956cf3b9cSMatthew G. Knepley . constants - constant parameters
348056cf3b9cSMatthew G. Knepley - bcval - output values at the current point
348156cf3b9cSMatthew G. Knepley 
348258ebd649SToby Isaac   Level: developer
348358ebd649SToby Isaac 
348445480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundaryByName(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual()
348558ebd649SToby Isaac @*/
348645480ffeSMatthew 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)
348758ebd649SToby Isaac {
348845480ffeSMatthew G. Knepley   DSBoundary     head = ds->boundary, b;
348945480ffeSMatthew G. Knepley   PetscInt       n    = 0;
349045480ffeSMatthew G. Knepley   const char    *lname;
349158ebd649SToby Isaac   PetscErrorCode ierr;
349258ebd649SToby Isaac 
349358ebd649SToby Isaac   PetscFunctionBegin;
349458ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3495783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
349645480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
349745480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4);
349845480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
349945480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
350045480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
3501d57bb9dbSMatthew G. Knepley   if (Nc > 0) {
3502d57bb9dbSMatthew G. Knepley     PetscInt *fcomps;
3503d57bb9dbSMatthew G. Knepley     PetscInt  c;
3504d57bb9dbSMatthew G. Knepley 
3505d57bb9dbSMatthew G. Knepley     ierr = PetscDSGetComponents(ds, &fcomps);CHKERRQ(ierr);
3506*2c71b3e2SJacob Faibussowitsch     PetscCheckFalse(Nc > fcomps[field],PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_OUTOFRANGE, "Number of constrained components %D > %D components for field %D", Nc, fcomps[field], field);
3507d57bb9dbSMatthew G. Knepley     for (c = 0; c < Nc; ++c) {
3508*2c71b3e2SJacob Faibussowitsch       PetscCheckFalse(comps[c] < 0 || comps[c] >= fcomps[field],PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_OUTOFRANGE, "Constrained component[%D] %D not in [0, %D) components for field %D", c, comps[c], fcomps[field], field);
3509d57bb9dbSMatthew G. Knepley     }
3510d57bb9dbSMatthew G. Knepley   }
351158ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
351258ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
351345480ffeSMatthew G. Knepley   ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr);
351445480ffeSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr);
351545480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr);
351645480ffeSMatthew G. Knepley   if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);}
351745480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr);
351845480ffeSMatthew G. Knepley   if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);}
351945480ffeSMatthew G. Knepley   ierr = PetscObjectGetName((PetscObject) label, &lname);CHKERRQ(ierr);
352045480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr);
3521f971fd6bSMatthew G. Knepley   b->type   = type;
352245480ffeSMatthew G. Knepley   b->label  = label;
352345480ffeSMatthew G. Knepley   b->Nv     = Nv;
352458ebd649SToby Isaac   b->field  = field;
352545480ffeSMatthew G. Knepley   b->Nc     = Nc;
352658ebd649SToby Isaac   b->func   = bcFunc;
352756cf3b9cSMatthew G. Knepley   b->func_t = bcFunc_t;
352858ebd649SToby Isaac   b->ctx    = ctx;
352945480ffeSMatthew G. Knepley   b->next   = NULL;
353045480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
353145480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
353245480ffeSMatthew G. Knepley   while (head) {
353345480ffeSMatthew G. Knepley     if (!head->next) {
353445480ffeSMatthew G. Knepley       head->next = b;
353545480ffeSMatthew G. Knepley       head       = b;
353645480ffeSMatthew G. Knepley     }
353745480ffeSMatthew G. Knepley     head = head->next;
353845480ffeSMatthew G. Knepley     ++n;
353945480ffeSMatthew G. Knepley   }
3540064a246eSJacob Faibussowitsch   if (bd) {PetscValidIntPointer(bd, 13); *bd = n;}
354145480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
354245480ffeSMatthew G. Knepley }
354345480ffeSMatthew G. Knepley 
354445480ffeSMatthew G. Knepley /*@C
354545480ffeSMatthew 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().
354645480ffeSMatthew G. Knepley 
354745480ffeSMatthew G. Knepley   Collective on ds
354845480ffeSMatthew G. Knepley 
354945480ffeSMatthew G. Knepley   Input Parameters:
355045480ffeSMatthew G. Knepley + ds       - The PetscDS object
355145480ffeSMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
355245480ffeSMatthew G. Knepley . name     - The BC name
355345480ffeSMatthew G. Knepley . lname    - The naem of the label defining constrained points
355445480ffeSMatthew G. Knepley . Nv       - The number of DMLabel values for constrained points
355545480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
355645480ffeSMatthew G. Knepley . field    - The field to constrain
355745480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
355845480ffeSMatthew G. Knepley . comps    - An array of constrained component numbers
355945480ffeSMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3560a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
356145480ffeSMatthew G. Knepley - ctx      - An optional user context for bcFunc
356245480ffeSMatthew G. Knepley 
356345480ffeSMatthew G. Knepley   Output Parameters:
356445480ffeSMatthew G. Knepley - bd       - The boundary number
356545480ffeSMatthew G. Knepley 
356645480ffeSMatthew G. Knepley   Options Database Keys:
356745480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids
356845480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components
356945480ffeSMatthew G. Knepley 
357045480ffeSMatthew G. Knepley   Note:
357145480ffeSMatthew G. Knepley   This function should only be used with DMForest currently, since labels cannot be defined before the underlygin Plex is built.
357245480ffeSMatthew G. Knepley 
357345480ffeSMatthew 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:
357445480ffeSMatthew G. Knepley 
357545480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
357645480ffeSMatthew G. Knepley 
357745480ffeSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
357845480ffeSMatthew G. Knepley 
357945480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
358045480ffeSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
358145480ffeSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
358245480ffeSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
358345480ffeSMatthew G. Knepley 
358445480ffeSMatthew G. Knepley + dim - the spatial dimension
358545480ffeSMatthew G. Knepley . Nf - the number of fields
358645480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
358745480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
358845480ffeSMatthew G. Knepley . u - each field evaluated at the current point
358945480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
359045480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
359145480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
359245480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
359345480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
359445480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
359545480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
359645480ffeSMatthew G. Knepley . t - current time
359745480ffeSMatthew G. Knepley . x - coordinates of the current point
359845480ffeSMatthew G. Knepley . numConstants - number of constant parameters
359945480ffeSMatthew G. Knepley . constants - constant parameters
360045480ffeSMatthew G. Knepley - bcval - output values at the current point
360145480ffeSMatthew G. Knepley 
360245480ffeSMatthew G. Knepley   Level: developer
360345480ffeSMatthew G. Knepley 
360445480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual()
360545480ffeSMatthew G. Knepley @*/
360645480ffeSMatthew 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)
360745480ffeSMatthew G. Knepley {
360845480ffeSMatthew G. Knepley   DSBoundary     head = ds->boundary, b;
360945480ffeSMatthew G. Knepley   PetscInt       n    = 0;
361045480ffeSMatthew G. Knepley   PetscErrorCode ierr;
361145480ffeSMatthew G. Knepley 
361245480ffeSMatthew G. Knepley   PetscFunctionBegin;
361345480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
361445480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
361545480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
361645480ffeSMatthew G. Knepley   PetscValidCharPointer(lname, 4);
361745480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
361845480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
361945480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
362045480ffeSMatthew G. Knepley   ierr = PetscNew(&b);CHKERRQ(ierr);
362145480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
362245480ffeSMatthew G. Knepley   ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr);
362345480ffeSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr);
362445480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr);
362545480ffeSMatthew G. Knepley   if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);}
362645480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr);
362745480ffeSMatthew G. Knepley   if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);}
362845480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr);
362945480ffeSMatthew G. Knepley   b->type   = type;
363045480ffeSMatthew G. Knepley   b->label  = NULL;
363145480ffeSMatthew G. Knepley   b->Nv     = Nv;
363245480ffeSMatthew G. Knepley   b->field  = field;
363345480ffeSMatthew G. Knepley   b->Nc     = Nc;
363445480ffeSMatthew G. Knepley   b->func   = bcFunc;
363545480ffeSMatthew G. Knepley   b->func_t = bcFunc_t;
363645480ffeSMatthew G. Knepley   b->ctx    = ctx;
363745480ffeSMatthew G. Knepley   b->next   = NULL;
363845480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
363945480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
364045480ffeSMatthew G. Knepley   while (head) {
364145480ffeSMatthew G. Knepley     if (!head->next) {
364245480ffeSMatthew G. Knepley       head->next = b;
364345480ffeSMatthew G. Knepley       head       = b;
364445480ffeSMatthew G. Knepley     }
364545480ffeSMatthew G. Knepley     head = head->next;
364645480ffeSMatthew G. Knepley     ++n;
364745480ffeSMatthew G. Knepley   }
3648064a246eSJacob Faibussowitsch   if (bd) {PetscValidIntPointer(bd, 13); *bd = n;}
364958ebd649SToby Isaac   PetscFunctionReturn(0);
365058ebd649SToby Isaac }
365158ebd649SToby Isaac 
3652b67eacb3SMatthew G. Knepley /*@C
365356cf3b9cSMatthew 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().
3654b67eacb3SMatthew G. Knepley 
3655b67eacb3SMatthew G. Knepley   Input Parameters:
3656b67eacb3SMatthew G. Knepley + ds       - The PetscDS object
3657b67eacb3SMatthew G. Knepley . bd       - The boundary condition number
3658b67eacb3SMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
3659b67eacb3SMatthew G. Knepley . name     - The BC name
366045480ffeSMatthew G. Knepley . label    - The label defining constrained points
366145480ffeSMatthew G. Knepley . Nv       - The number of DMLabel ids for constrained points
366245480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
3663b67eacb3SMatthew G. Knepley . field    - The field to constrain
366445480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
3665b67eacb3SMatthew G. Knepley . comps    - An array of constrained component numbers
3666b67eacb3SMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3667a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
3668b67eacb3SMatthew G. Knepley - ctx      - An optional user context for bcFunc
3669b67eacb3SMatthew G. Knepley 
367056cf3b9cSMatthew G. Knepley   Note:
367156cf3b9cSMatthew 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.
36729a6efb6aSMatthew G. Knepley 
3673b67eacb3SMatthew G. Knepley   Level: developer
3674b67eacb3SMatthew G. Knepley 
36759a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary()
3676b67eacb3SMatthew G. Knepley @*/
367745480ffeSMatthew 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)
3678b67eacb3SMatthew G. Knepley {
3679b67eacb3SMatthew G. Knepley   DSBoundary     b = ds->boundary;
3680b67eacb3SMatthew G. Knepley   PetscInt       n = 0;
3681b67eacb3SMatthew G. Knepley   PetscErrorCode ierr;
3682b67eacb3SMatthew G. Knepley 
3683b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
3684b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3685b67eacb3SMatthew G. Knepley   while (b) {
3686b67eacb3SMatthew G. Knepley     if (n == bd) break;
3687b67eacb3SMatthew G. Knepley     b = b->next;
3688b67eacb3SMatthew G. Knepley     ++n;
3689b67eacb3SMatthew G. Knepley   }
3690*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(!b,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
3691b67eacb3SMatthew G. Knepley   if (name) {
3692b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
3693b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
3694b67eacb3SMatthew G. Knepley   }
3695b67eacb3SMatthew G. Knepley   b->type = type;
369645480ffeSMatthew G. Knepley   if (label) {
369745480ffeSMatthew G. Knepley     const char *name;
369845480ffeSMatthew G. Knepley 
369945480ffeSMatthew G. Knepley     b->label = label;
370045480ffeSMatthew G. Knepley     ierr = PetscFree(b->lname);CHKERRQ(ierr);
370145480ffeSMatthew G. Knepley     ierr = PetscObjectGetName((PetscObject) label, &name);CHKERRQ(ierr);
370245480ffeSMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->lname);CHKERRQ(ierr);
370345480ffeSMatthew G. Knepley   }
370445480ffeSMatthew G. Knepley   if (Nv >= 0) {
370545480ffeSMatthew G. Knepley     b->Nv = Nv;
370645480ffeSMatthew G. Knepley     ierr = PetscFree(b->values);CHKERRQ(ierr);
370745480ffeSMatthew G. Knepley     ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr);
370845480ffeSMatthew G. Knepley     if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);}
370945480ffeSMatthew G. Knepley   }
371045480ffeSMatthew G. Knepley   if (field >= 0) b->field = field;
371145480ffeSMatthew G. Knepley   if (Nc >= 0) {
371245480ffeSMatthew G. Knepley     b->Nc = Nc;
371345480ffeSMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
371445480ffeSMatthew G. Knepley     ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr);
371545480ffeSMatthew G. Knepley     if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);}
371645480ffeSMatthew G. Knepley   }
371745480ffeSMatthew G. Knepley   if (bcFunc)   b->func   = bcFunc;
371845480ffeSMatthew G. Knepley   if (bcFunc_t) b->func_t = bcFunc_t;
371945480ffeSMatthew G. Knepley   if (ctx)      b->ctx    = ctx;
3720b67eacb3SMatthew G. Knepley   PetscFunctionReturn(0);
3721b67eacb3SMatthew G. Knepley }
3722b67eacb3SMatthew G. Knepley 
372358ebd649SToby Isaac /*@
372458ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
372558ebd649SToby Isaac 
372658ebd649SToby Isaac   Input Parameters:
372758ebd649SToby Isaac . ds - The PetscDS object
372858ebd649SToby Isaac 
372958ebd649SToby Isaac   Output Parameters:
373058ebd649SToby Isaac . numBd - The number of BC
373158ebd649SToby Isaac 
373258ebd649SToby Isaac   Level: intermediate
373358ebd649SToby Isaac 
373458ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
373558ebd649SToby Isaac @*/
373658ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
373758ebd649SToby Isaac {
373858ebd649SToby Isaac   DSBoundary b = ds->boundary;
373958ebd649SToby Isaac 
374058ebd649SToby Isaac   PetscFunctionBegin;
374158ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
374258ebd649SToby Isaac   PetscValidPointer(numBd, 2);
374358ebd649SToby Isaac   *numBd = 0;
374458ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
374558ebd649SToby Isaac   PetscFunctionReturn(0);
374658ebd649SToby Isaac }
374758ebd649SToby Isaac 
374858ebd649SToby Isaac /*@C
37499a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
375058ebd649SToby Isaac 
375158ebd649SToby Isaac   Input Parameters:
375258ebd649SToby Isaac + ds          - The PetscDS object
375358ebd649SToby Isaac - bd          - The BC number
375458ebd649SToby Isaac 
375558ebd649SToby Isaac   Output Parameters:
375645480ffeSMatthew G. Knepley + wf       - The PetscWeakForm holding the pointwise functions
375745480ffeSMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
375858ebd649SToby Isaac . name     - The BC name
375945480ffeSMatthew G. Knepley . label    - The label defining constrained points
376045480ffeSMatthew G. Knepley . Nv       - The number of DMLabel ids for constrained points
376145480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
376258ebd649SToby Isaac . field    - The field to constrain
376345480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
376458ebd649SToby Isaac . comps    - An array of constrained component numbers
376558ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3766a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values
376758ebd649SToby Isaac - ctx      - An optional user context for bcFunc
376858ebd649SToby Isaac 
376958ebd649SToby Isaac   Options Database Keys:
377058ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
377158ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
377258ebd649SToby Isaac 
377358ebd649SToby Isaac   Level: developer
377458ebd649SToby Isaac 
377558ebd649SToby Isaac .seealso: PetscDSAddBoundary()
377658ebd649SToby Isaac @*/
377745480ffeSMatthew 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)
377858ebd649SToby Isaac {
377958ebd649SToby Isaac   DSBoundary b = ds->boundary;
378058ebd649SToby Isaac   PetscInt   n = 0;
378158ebd649SToby Isaac 
378258ebd649SToby Isaac   PetscFunctionBegin;
378358ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
378458ebd649SToby Isaac   while (b) {
378558ebd649SToby Isaac     if (n == bd) break;
378658ebd649SToby Isaac     b = b->next;
378758ebd649SToby Isaac     ++n;
378858ebd649SToby Isaac   }
3789*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(!b,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
379045480ffeSMatthew G. Knepley   if (wf) {
379145480ffeSMatthew G. Knepley     PetscValidPointer(wf, 3);
379245480ffeSMatthew G. Knepley     *wf = b->wf;
379345480ffeSMatthew G. Knepley   }
3794f971fd6bSMatthew G. Knepley   if (type) {
379545480ffeSMatthew G. Knepley     PetscValidPointer(type, 4);
3796f971fd6bSMatthew G. Knepley     *type = b->type;
379758ebd649SToby Isaac   }
379858ebd649SToby Isaac   if (name) {
379945480ffeSMatthew G. Knepley     PetscValidPointer(name, 5);
380058ebd649SToby Isaac     *name = b->name;
380158ebd649SToby Isaac   }
380245480ffeSMatthew G. Knepley   if (label) {
380345480ffeSMatthew G. Knepley     PetscValidPointer(label, 6);
380445480ffeSMatthew G. Knepley     *label = b->label;
380545480ffeSMatthew G. Knepley   }
380645480ffeSMatthew G. Knepley   if (Nv) {
380745480ffeSMatthew G. Knepley     PetscValidIntPointer(Nv, 7);
380845480ffeSMatthew G. Knepley     *Nv = b->Nv;
380945480ffeSMatthew G. Knepley   }
381045480ffeSMatthew G. Knepley   if (values) {
381145480ffeSMatthew G. Knepley     PetscValidPointer(values, 8);
381245480ffeSMatthew G. Knepley     *values = b->values;
381358ebd649SToby Isaac   }
381458ebd649SToby Isaac   if (field) {
381545480ffeSMatthew G. Knepley     PetscValidIntPointer(field, 9);
381658ebd649SToby Isaac     *field = b->field;
381758ebd649SToby Isaac   }
381845480ffeSMatthew G. Knepley   if (Nc) {
381945480ffeSMatthew G. Knepley     PetscValidIntPointer(Nc, 10);
382045480ffeSMatthew G. Knepley     *Nc = b->Nc;
382158ebd649SToby Isaac   }
382258ebd649SToby Isaac   if (comps) {
382345480ffeSMatthew G. Knepley     PetscValidPointer(comps, 11);
382458ebd649SToby Isaac     *comps = b->comps;
382558ebd649SToby Isaac   }
382658ebd649SToby Isaac   if (func) {
382745480ffeSMatthew G. Knepley     PetscValidPointer(func, 12);
382858ebd649SToby Isaac     *func = b->func;
382958ebd649SToby Isaac   }
383056cf3b9cSMatthew G. Knepley   if (func_t) {
383145480ffeSMatthew G. Knepley     PetscValidPointer(func_t, 13);
383256cf3b9cSMatthew G. Knepley     *func_t = b->func_t;
383356cf3b9cSMatthew G. Knepley   }
383458ebd649SToby Isaac   if (ctx) {
383545480ffeSMatthew G. Knepley     PetscValidPointer(ctx, 14);
383658ebd649SToby Isaac     *ctx = b->ctx;
383758ebd649SToby Isaac   }
383858ebd649SToby Isaac   PetscFunctionReturn(0);
383958ebd649SToby Isaac }
384058ebd649SToby Isaac 
384145480ffeSMatthew G. Knepley static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew)
384245480ffeSMatthew G. Knepley {
384345480ffeSMatthew G. Knepley   PetscErrorCode ierr;
384445480ffeSMatthew G. Knepley 
384545480ffeSMatthew G. Knepley   PetscFunctionBegin;
384645480ffeSMatthew G. Knepley   ierr = PetscNew(bNew);CHKERRQ(ierr);
384745480ffeSMatthew G. Knepley   ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf);CHKERRQ(ierr);
384845480ffeSMatthew G. Knepley   ierr = PetscWeakFormCopy(b->wf, (*bNew)->wf);CHKERRQ(ierr);
384945480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(b->name,(char **) &((*bNew)->name));CHKERRQ(ierr);
385045480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(b->lname,(char **) &((*bNew)->lname));CHKERRQ(ierr);
385145480ffeSMatthew G. Knepley   (*bNew)->type   = b->type;
385245480ffeSMatthew G. Knepley   (*bNew)->label  = b->label;
385345480ffeSMatthew G. Knepley   (*bNew)->Nv     = b->Nv;
385445480ffeSMatthew G. Knepley   ierr = PetscMalloc1(b->Nv, &(*bNew)->values);CHKERRQ(ierr);
385545480ffeSMatthew G. Knepley   ierr = PetscArraycpy((*bNew)->values, b->values, b->Nv);CHKERRQ(ierr);
385645480ffeSMatthew G. Knepley   (*bNew)->field  = b->field;
385745480ffeSMatthew G. Knepley   (*bNew)->Nc     = b->Nc;
385845480ffeSMatthew G. Knepley   ierr = PetscMalloc1(b->Nc, &(*bNew)->comps);CHKERRQ(ierr);
385945480ffeSMatthew G. Knepley   ierr = PetscArraycpy((*bNew)->comps, b->comps, b->Nc);CHKERRQ(ierr);
386045480ffeSMatthew G. Knepley   (*bNew)->func   = b->func;
386145480ffeSMatthew G. Knepley   (*bNew)->func_t = b->func_t;
386245480ffeSMatthew G. Knepley   (*bNew)->ctx    = b->ctx;
386345480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
386445480ffeSMatthew G. Knepley }
386545480ffeSMatthew G. Knepley 
38669252d075SMatthew G. Knepley /*@
38679252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
38689252d075SMatthew G. Knepley 
38699252d075SMatthew G. Knepley   Not collective
38709252d075SMatthew G. Knepley 
387136951cb5SMatthew G. Knepley   Input Parameters:
387236951cb5SMatthew G. Knepley + ds        - The source PetscDS object
387336951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields
387436951cb5SMatthew G. Knepley - fields    - The selected fields, or NULL for all fields
38759252d075SMatthew G. Knepley 
38769252d075SMatthew G. Knepley   Output Parameter:
387736951cb5SMatthew G. Knepley . newds     - The target PetscDS, now with a copy of the boundary conditions
38789252d075SMatthew G. Knepley 
38799252d075SMatthew G. Knepley   Level: intermediate
38809252d075SMatthew G. Knepley 
38819252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
38829252d075SMatthew G. Knepley @*/
388336951cb5SMatthew G. Knepley PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds)
3884dff059c6SToby Isaac {
388545480ffeSMatthew G. Knepley   DSBoundary     b, *lastnext;
3886dff059c6SToby Isaac   PetscErrorCode ierr;
3887dff059c6SToby Isaac 
3888dff059c6SToby Isaac   PetscFunctionBegin;
388936951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(ds,    PETSCDS_CLASSID, 1);
389036951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4);
389136951cb5SMatthew G. Knepley   if (ds == newds) PetscFunctionReturn(0);
389245480ffeSMatthew G. Knepley   ierr = PetscDSDestroyBoundary(newds);CHKERRQ(ierr);
389336951cb5SMatthew G. Knepley   lastnext = &(newds->boundary);
389436951cb5SMatthew G. Knepley   for (b = ds->boundary; b; b = b->next) {
3895dff059c6SToby Isaac     DSBoundary bNew;
389636951cb5SMatthew G. Knepley     PetscInt   fieldNew = -1;
3897dff059c6SToby Isaac 
389836951cb5SMatthew G. Knepley     if (numFields > 0 && fields) {
389936951cb5SMatthew G. Knepley       PetscInt f;
390036951cb5SMatthew G. Knepley 
390136951cb5SMatthew G. Knepley       for (f = 0; f < numFields; ++f) if (b->field == fields[f]) break;
390236951cb5SMatthew G. Knepley       if (f == numFields) continue;
390336951cb5SMatthew G. Knepley       fieldNew = f;
390436951cb5SMatthew G. Knepley     }
390545480ffeSMatthew G. Knepley     ierr = DSBoundaryDuplicate_Internal(b, &bNew);CHKERRQ(ierr);
390636951cb5SMatthew G. Knepley     bNew->field = fieldNew < 0 ? b->field : fieldNew;
3907dff059c6SToby Isaac     *lastnext = bNew;
3908dff059c6SToby Isaac     lastnext  = &(bNew->next);
3909dff059c6SToby Isaac   }
3910dff059c6SToby Isaac   PetscFunctionReturn(0);
3911dff059c6SToby Isaac }
3912dff059c6SToby Isaac 
39136c1eb96dSMatthew G. Knepley /*@
391445480ffeSMatthew G. Knepley   PetscDSDestroyBoundary - Remove all DMBoundary objects from the PetscDS
391545480ffeSMatthew G. Knepley 
391645480ffeSMatthew G. Knepley   Not collective
391745480ffeSMatthew G. Knepley 
391845480ffeSMatthew G. Knepley   Input Parameter:
391945480ffeSMatthew G. Knepley . ds - The PetscDS object
392045480ffeSMatthew G. Knepley 
392145480ffeSMatthew G. Knepley   Level: intermediate
392245480ffeSMatthew G. Knepley 
392345480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations()
392445480ffeSMatthew G. Knepley @*/
392545480ffeSMatthew G. Knepley PetscErrorCode PetscDSDestroyBoundary(PetscDS ds)
392645480ffeSMatthew G. Knepley {
392745480ffeSMatthew G. Knepley   DSBoundary     next = ds->boundary;
392845480ffeSMatthew G. Knepley   PetscErrorCode ierr;
392945480ffeSMatthew G. Knepley 
393045480ffeSMatthew G. Knepley   PetscFunctionBegin;
393145480ffeSMatthew G. Knepley   while (next) {
393245480ffeSMatthew G. Knepley     DSBoundary b = next;
393345480ffeSMatthew G. Knepley 
393445480ffeSMatthew G. Knepley     next = b->next;
393545480ffeSMatthew G. Knepley     ierr = PetscWeakFormDestroy(&b->wf);CHKERRQ(ierr);
393645480ffeSMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
393745480ffeSMatthew G. Knepley     ierr = PetscFree(b->lname);CHKERRQ(ierr);
393845480ffeSMatthew G. Knepley     ierr = PetscFree(b->values);CHKERRQ(ierr);
393945480ffeSMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
394045480ffeSMatthew G. Knepley     ierr = PetscFree(b);CHKERRQ(ierr);
394145480ffeSMatthew G. Knepley   }
394245480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
394345480ffeSMatthew G. Knepley }
394445480ffeSMatthew G. Knepley 
394545480ffeSMatthew G. Knepley /*@
39466c1eb96dSMatthew G. Knepley   PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout
39476c1eb96dSMatthew G. Knepley 
39486c1eb96dSMatthew G. Knepley   Not collective
39496c1eb96dSMatthew G. Knepley 
3950d8d19677SJose E. Roman   Input Parameters:
39516c1eb96dSMatthew G. Knepley + prob - The PetscDS object
39526c1eb96dSMatthew G. Knepley . numFields - Number of new fields
39536c1eb96dSMatthew G. Knepley - fields - Old field number for each new field
39546c1eb96dSMatthew G. Knepley 
39556c1eb96dSMatthew G. Knepley   Output Parameter:
39566c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy
39576c1eb96dSMatthew G. Knepley 
39586c1eb96dSMatthew G. Knepley   Level: intermediate
39596c1eb96dSMatthew G. Knepley 
39606c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectEquations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
39616c1eb96dSMatthew G. Knepley @*/
39626c1eb96dSMatthew G. Knepley PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
39636c1eb96dSMatthew G. Knepley {
39646c1eb96dSMatthew G. Knepley   PetscInt       Nf, Nfn, fn;
39656c1eb96dSMatthew G. Knepley   PetscErrorCode ierr;
39666c1eb96dSMatthew G. Knepley 
39676c1eb96dSMatthew G. Knepley   PetscFunctionBegin;
39686c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
39696c1eb96dSMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
39706c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
39716c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
39726c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
397345480ffeSMatthew G. Knepley   numFields = numFields < 0 ? Nf : numFields;
39746c1eb96dSMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
39756c1eb96dSMatthew G. Knepley     const PetscInt f = fields ? fields[fn] : fn;
39766c1eb96dSMatthew G. Knepley     PetscObject    disc;
39776c1eb96dSMatthew G. Knepley 
39786c1eb96dSMatthew G. Knepley     if (f >= Nf) continue;
39796c1eb96dSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &disc);CHKERRQ(ierr);
39806c1eb96dSMatthew G. Knepley     ierr = PetscDSSetDiscretization(newprob, fn, disc);CHKERRQ(ierr);
39816c1eb96dSMatthew G. Knepley   }
39826c1eb96dSMatthew G. Knepley   PetscFunctionReturn(0);
39836c1eb96dSMatthew G. Knepley }
39846c1eb96dSMatthew G. Knepley 
39856c1eb96dSMatthew G. Knepley /*@
39869252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
39879252d075SMatthew G. Knepley 
39889252d075SMatthew G. Knepley   Not collective
39899252d075SMatthew G. Knepley 
3990d8d19677SJose E. Roman   Input Parameters:
39919252d075SMatthew G. Knepley + prob - The PetscDS object
39929252d075SMatthew G. Knepley . numFields - Number of new fields
39939252d075SMatthew G. Knepley - fields - Old field number for each new field
39949252d075SMatthew G. Knepley 
39959252d075SMatthew G. Knepley   Output Parameter:
39969252d075SMatthew G. Knepley . newprob - The PetscDS copy
39979252d075SMatthew G. Knepley 
39989252d075SMatthew G. Knepley   Level: intermediate
39999252d075SMatthew G. Knepley 
40006c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectDiscretizations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
40019252d075SMatthew G. Knepley @*/
40029252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
40039252d075SMatthew G. Knepley {
40049252d075SMatthew G. Knepley   PetscInt       Nf, Nfn, fn, gn;
40059252d075SMatthew G. Knepley   PetscErrorCode ierr;
40069252d075SMatthew G. Knepley 
40079252d075SMatthew G. Knepley   PetscFunctionBegin;
40089252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
40099252d075SMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
40109252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
40119252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
40129252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
4013*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(numFields > Nfn,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);
40149252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
40159252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
40169252d075SMatthew G. Knepley     PetscPointFunc   obj;
40179252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
40189252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
40199252d075SMatthew G. Knepley     PetscRiemannFunc r;
40209252d075SMatthew G. Knepley 
4021c52f1e13SMatthew G. Knepley     if (f >= Nf) continue;
40229252d075SMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
40239252d075SMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
40249252d075SMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
40259252d075SMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
40269252d075SMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr);
40279252d075SMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr);
40289252d075SMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr);
40299252d075SMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr);
40309252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
40319252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
40329252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
40339252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
40349252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
40359252d075SMatthew G. Knepley 
4036c52f1e13SMatthew G. Knepley       if (g >= Nf) continue;
40379252d075SMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
40389252d075SMatthew G. Knepley       ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr);
40399252d075SMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
40409252d075SMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr);
40416c1eb96dSMatthew G. Knepley       ierr = PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr);
40429252d075SMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
40439252d075SMatthew G. Knepley     }
40449252d075SMatthew G. Knepley   }
40459252d075SMatthew G. Knepley   PetscFunctionReturn(0);
40469252d075SMatthew G. Knepley }
40479252d075SMatthew G. Knepley 
4048da51fcedSMatthew G. Knepley /*@
4049da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
4050da51fcedSMatthew G. Knepley 
4051da51fcedSMatthew G. Knepley   Not collective
4052da51fcedSMatthew G. Knepley 
4053da51fcedSMatthew G. Knepley   Input Parameter:
4054da51fcedSMatthew G. Knepley . prob - The PetscDS object
4055da51fcedSMatthew G. Knepley 
4056da51fcedSMatthew G. Knepley   Output Parameter:
4057da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
4058da51fcedSMatthew G. Knepley 
4059da51fcedSMatthew G. Knepley   Level: intermediate
4060da51fcedSMatthew G. Knepley 
40619252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
4062da51fcedSMatthew G. Knepley @*/
4063da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
4064da51fcedSMatthew G. Knepley {
4065b8025e53SMatthew G. Knepley   PetscWeakForm  wf, newwf;
40669252d075SMatthew G. Knepley   PetscInt       Nf, Ng;
4067da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
4068da51fcedSMatthew G. Knepley 
4069da51fcedSMatthew G. Knepley   PetscFunctionBegin;
4070da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
4071da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
4072da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
4073da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
4074*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(Nf != Ng,PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
4075b8025e53SMatthew G. Knepley   ierr = PetscDSGetWeakForm(prob, &wf);CHKERRQ(ierr);
4076b8025e53SMatthew G. Knepley   ierr = PetscDSGetWeakForm(newprob, &newwf);CHKERRQ(ierr);
4077b8025e53SMatthew G. Knepley   ierr = PetscWeakFormCopy(wf, newwf);CHKERRQ(ierr);
40789252d075SMatthew G. Knepley   PetscFunctionReturn(0);
40799252d075SMatthew G. Knepley }
408045480ffeSMatthew G. Knepley 
40819252d075SMatthew G. Knepley /*@
40829252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
4083da51fcedSMatthew G. Knepley 
40849252d075SMatthew G. Knepley   Not collective
40859252d075SMatthew G. Knepley 
40869252d075SMatthew G. Knepley   Input Parameter:
40879252d075SMatthew G. Knepley . prob - The PetscDS object
40889252d075SMatthew G. Knepley 
40899252d075SMatthew G. Knepley   Output Parameter:
40909252d075SMatthew G. Knepley . newprob - The PetscDS copy
40919252d075SMatthew G. Knepley 
40929252d075SMatthew G. Knepley   Level: intermediate
40939252d075SMatthew G. Knepley 
40949252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
40959252d075SMatthew G. Knepley @*/
40969252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
40979252d075SMatthew G. Knepley {
40989252d075SMatthew G. Knepley   PetscInt           Nc;
40999252d075SMatthew G. Knepley   const PetscScalar *constants;
41009252d075SMatthew G. Knepley   PetscErrorCode     ierr;
41019252d075SMatthew G. Knepley 
41029252d075SMatthew G. Knepley   PetscFunctionBegin;
41039252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
41049252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
41059252d075SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr);
41069252d075SMatthew G. Knepley   ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr);
4107da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
4108da51fcedSMatthew G. Knepley }
4109da51fcedSMatthew G. Knepley 
411045480ffeSMatthew G. Knepley /*@
411145480ffeSMatthew G. Knepley   PetscDSCopyExactSolutions - Copy all exact solutions to the new problem
411245480ffeSMatthew G. Knepley 
411345480ffeSMatthew G. Knepley   Not collective
411445480ffeSMatthew G. Knepley 
411545480ffeSMatthew G. Knepley   Input Parameter:
411645480ffeSMatthew G. Knepley . ds - The PetscDS object
411745480ffeSMatthew G. Knepley 
411845480ffeSMatthew G. Knepley   Output Parameter:
411945480ffeSMatthew G. Knepley . newds - The PetscDS copy
412045480ffeSMatthew G. Knepley 
412145480ffeSMatthew G. Knepley   Level: intermediate
412245480ffeSMatthew G. Knepley 
412345480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
412445480ffeSMatthew G. Knepley @*/
412545480ffeSMatthew G. Knepley PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds)
412645480ffeSMatthew G. Knepley {
412745480ffeSMatthew G. Knepley   PetscSimplePointFunc sol;
412845480ffeSMatthew G. Knepley   void                *ctx;
412945480ffeSMatthew G. Knepley   PetscInt             Nf, f;
413045480ffeSMatthew G. Knepley   PetscErrorCode       ierr;
413145480ffeSMatthew G. Knepley 
413245480ffeSMatthew G. Knepley   PetscFunctionBegin;
413345480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
413445480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2);
413545480ffeSMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
413645480ffeSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
413745480ffeSMatthew G. Knepley     ierr = PetscDSGetExactSolution(ds,    f, &sol, &ctx);CHKERRQ(ierr);
413845480ffeSMatthew G. Knepley     ierr = PetscDSSetExactSolution(newds, f,  sol,  ctx);CHKERRQ(ierr);
413945480ffeSMatthew G. Knepley     ierr = PetscDSGetExactSolutionTimeDerivative(ds,    f, &sol, &ctx);CHKERRQ(ierr);
414045480ffeSMatthew G. Knepley     ierr = PetscDSSetExactSolutionTimeDerivative(newds, f,  sol,  ctx);CHKERRQ(ierr);
414145480ffeSMatthew G. Knepley   }
414245480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
414345480ffeSMatthew G. Knepley }
414445480ffeSMatthew G. Knepley 
4145b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
4146b1353e8eSMatthew G. Knepley {
4147df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
4148b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
4149b1353e8eSMatthew G. Knepley 
4150b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
4151b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
4152b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
4153b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
4154b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
4155df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
4156*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(height > dim,PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_OUTOFRANGE, "DS can only handle height in [0, %D], not %D", dim, height);
4157df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
4158df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
4159b1353e8eSMatthew G. Knepley     PetscInt cdim;
4160b1353e8eSMatthew G. Knepley 
4161df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
4162b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
4163df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
4164b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
4165b1353e8eSMatthew G. Knepley       PetscFE      subfe;
4166b1353e8eSMatthew G. Knepley       PetscObject  obj;
4167b1353e8eSMatthew G. Knepley       PetscClassId id;
4168b1353e8eSMatthew G. Knepley 
4169b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
4170b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
4171b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
417298921bdaSJacob Faibussowitsch       else SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
4173df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
4174b1353e8eSMatthew G. Knepley     }
4175b1353e8eSMatthew G. Knepley   }
4176df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
4177b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
4178b1353e8eSMatthew G. Knepley }
4179b1353e8eSMatthew G. Knepley 
4180665f567fSMatthew G. Knepley PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype)
4181c7bd5f0bSMatthew G. Knepley {
4182c7bd5f0bSMatthew G. Knepley   PetscObject    obj;
4183c7bd5f0bSMatthew G. Knepley   PetscClassId   id;
4184c7bd5f0bSMatthew G. Knepley   PetscInt       Nf;
4185c7bd5f0bSMatthew G. Knepley   PetscErrorCode ierr;
4186c7bd5f0bSMatthew G. Knepley 
4187c7bd5f0bSMatthew G. Knepley   PetscFunctionBegin;
4188c7bd5f0bSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
4189665f567fSMatthew G. Knepley   PetscValidPointer(disctype, 3);
4190665f567fSMatthew G. Knepley   *disctype = PETSC_DISC_NONE;
4191c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
4192*2c71b3e2SJacob Faibussowitsch   PetscCheckFalse(f >= Nf,PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf);
4193c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr);
4194665f567fSMatthew G. Knepley   if (obj) {
4195c7bd5f0bSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
4196665f567fSMatthew G. Knepley     if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE;
4197665f567fSMatthew G. Knepley     else                       *disctype = PETSC_DISC_FV;
4198665f567fSMatthew G. Knepley   }
4199c7bd5f0bSMatthew G. Knepley   PetscFunctionReturn(0);
4200c7bd5f0bSMatthew G. Knepley }
4201c7bd5f0bSMatthew G. Knepley 
42026528b96dSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds)
42032764a2aaSMatthew G. Knepley {
4204931fb3b8SToby Isaac   PetscErrorCode ierr;
4205931fb3b8SToby Isaac 
42062764a2aaSMatthew G. Knepley   PetscFunctionBegin;
42076528b96dSMatthew G. Knepley   ierr = PetscFree(ds->data);CHKERRQ(ierr);
42082764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
42092764a2aaSMatthew G. Knepley }
42102764a2aaSMatthew G. Knepley 
42116528b96dSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds)
42122764a2aaSMatthew G. Knepley {
42132764a2aaSMatthew G. Knepley   PetscFunctionBegin;
42146528b96dSMatthew G. Knepley   ds->ops->setfromoptions = NULL;
42156528b96dSMatthew G. Knepley   ds->ops->setup          = NULL;
42166528b96dSMatthew G. Knepley   ds->ops->view           = NULL;
42176528b96dSMatthew G. Knepley   ds->ops->destroy        = PetscDSDestroy_Basic;
42182764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
42192764a2aaSMatthew G. Knepley }
42202764a2aaSMatthew G. Knepley 
42212764a2aaSMatthew G. Knepley /*MC
42222764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
42232764a2aaSMatthew G. Knepley 
42242764a2aaSMatthew G. Knepley   Level: intermediate
42252764a2aaSMatthew G. Knepley 
42262764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
42272764a2aaSMatthew G. Knepley M*/
42282764a2aaSMatthew G. Knepley 
42296528b96dSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds)
42302764a2aaSMatthew G. Knepley {
42312764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
42322764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
42332764a2aaSMatthew G. Knepley 
42342764a2aaSMatthew G. Knepley   PetscFunctionBegin;
42356528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
42366528b96dSMatthew G. Knepley   ierr = PetscNewLog(ds, &b);CHKERRQ(ierr);
42376528b96dSMatthew G. Knepley   ds->data = b;
42382764a2aaSMatthew G. Knepley 
42396528b96dSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(ds);CHKERRQ(ierr);
42402764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
42412764a2aaSMatthew G. Knepley }
4242