xref: /petsc/src/dm/dt/interface/dtds.c (revision 9ee2af8c7763dac4b62cac00949a80c96f42d293)
1af0996ceSBarry Smith #include <petsc/private/petscdsimpl.h> /*I "petscds.h" I*/
22764a2aaSMatthew G. Knepley 
32764a2aaSMatthew G. Knepley PetscClassId PETSCDS_CLASSID = 0;
42764a2aaSMatthew G. Knepley 
52764a2aaSMatthew G. Knepley PetscFunctionList PetscDSList              = NULL;
62764a2aaSMatthew G. Knepley PetscBool         PetscDSRegisterAllCalled = PETSC_FALSE;
72764a2aaSMatthew G. Knepley 
894dcdc3fSMatthew G. Knepley /* A PetscDS (Discrete System) encodes a set of equations posed in a discrete space, which represents a set of
994dcdc3fSMatthew G. Knepley    nonlinear continuum equations. The equations can have multiple fields, each field having a different
1094dcdc3fSMatthew G. Knepley    discretization. In addition, different pieces of the domain can have different field combinations and equations.
1194dcdc3fSMatthew G. Knepley 
1294dcdc3fSMatthew G. Knepley    The DS provides the user a description of the approximation space on any given cell. It also gives pointwise
1394dcdc3fSMatthew G. Knepley    functions representing the equations.
1494dcdc3fSMatthew G. Knepley 
1594dcdc3fSMatthew G. Knepley    Each field is associated with a label, marking the cells on which it is supported. Note that a field can be
1694dcdc3fSMatthew G. Knepley    supported on the closure of a cell not in the label due to overlap of the boundary of neighboring cells. The DM
1794dcdc3fSMatthew G. Knepley    then creates a DS for each set of cells with identical approximation spaces. When assembling, the user asks for
1894dcdc3fSMatthew G. Knepley    the space associated with a given cell. DMPlex uses the labels associated with each DS in the default integration loop.
1994dcdc3fSMatthew G. Knepley */
2094dcdc3fSMatthew G. Knepley 
212764a2aaSMatthew G. Knepley /*@C
222764a2aaSMatthew G. Knepley   PetscDSRegister - Adds a new PetscDS implementation
232764a2aaSMatthew G. Knepley 
242764a2aaSMatthew G. Knepley   Not Collective
252764a2aaSMatthew G. Knepley 
262764a2aaSMatthew G. Knepley   Input Parameters:
272764a2aaSMatthew G. Knepley + name        - The name of a new user-defined creation routine
282764a2aaSMatthew G. Knepley - create_func - The creation routine itself
292764a2aaSMatthew G. Knepley 
302764a2aaSMatthew G. Knepley   Notes:
312764a2aaSMatthew G. Knepley   PetscDSRegister() may be called multiple times to add several user-defined PetscDSs
322764a2aaSMatthew G. Knepley 
332764a2aaSMatthew G. Knepley   Sample usage:
342764a2aaSMatthew G. Knepley .vb
352764a2aaSMatthew G. Knepley     PetscDSRegister("my_ds", MyPetscDSCreate);
362764a2aaSMatthew G. Knepley .ve
372764a2aaSMatthew G. Knepley 
382764a2aaSMatthew G. Knepley   Then, your PetscDS type can be chosen with the procedural interface via
392764a2aaSMatthew G. Knepley .vb
402764a2aaSMatthew G. Knepley     PetscDSCreate(MPI_Comm, PetscDS *);
412764a2aaSMatthew G. Knepley     PetscDSSetType(PetscDS, "my_ds");
422764a2aaSMatthew G. Knepley .ve
432764a2aaSMatthew G. Knepley    or at runtime via the option
442764a2aaSMatthew G. Knepley .vb
452764a2aaSMatthew G. Knepley     -petscds_type my_ds
462764a2aaSMatthew G. Knepley .ve
472764a2aaSMatthew G. Knepley 
482764a2aaSMatthew G. Knepley   Level: advanced
492764a2aaSMatthew G. Knepley 
50f5f57ec0SBarry Smith    Not available from Fortran
51f5f57ec0SBarry Smith 
522764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy()
532764a2aaSMatthew G. Knepley 
542764a2aaSMatthew G. Knepley @*/
552764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
562764a2aaSMatthew G. Knepley {
572764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
582764a2aaSMatthew G. Knepley 
592764a2aaSMatthew G. Knepley   PetscFunctionBegin;
602764a2aaSMatthew G. Knepley   ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr);
612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
622764a2aaSMatthew G. Knepley }
632764a2aaSMatthew G. Knepley 
642764a2aaSMatthew G. Knepley /*@C
652764a2aaSMatthew G. Knepley   PetscDSSetType - Builds a particular PetscDS
662764a2aaSMatthew G. Knepley 
67d083f849SBarry Smith   Collective on prob
682764a2aaSMatthew G. Knepley 
692764a2aaSMatthew G. Knepley   Input Parameters:
702764a2aaSMatthew G. Knepley + prob - The PetscDS object
712764a2aaSMatthew G. Knepley - name - The kind of system
722764a2aaSMatthew G. Knepley 
732764a2aaSMatthew G. Knepley   Options Database Key:
742764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
752764a2aaSMatthew G. Knepley 
762764a2aaSMatthew G. Knepley   Level: intermediate
772764a2aaSMatthew G. Knepley 
78f5f57ec0SBarry Smith    Not available from Fortran
79f5f57ec0SBarry Smith 
802764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate()
812764a2aaSMatthew G. Knepley @*/
822764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
832764a2aaSMatthew G. Knepley {
842764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
852764a2aaSMatthew G. Knepley   PetscBool      match;
862764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
872764a2aaSMatthew G. Knepley 
882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
902764a2aaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr);
912764a2aaSMatthew G. Knepley   if (match) PetscFunctionReturn(0);
922764a2aaSMatthew G. Knepley 
930f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
942764a2aaSMatthew G. Knepley   ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr);
952764a2aaSMatthew G. Knepley   if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
962764a2aaSMatthew G. Knepley 
972764a2aaSMatthew G. Knepley   if (prob->ops->destroy) {
982764a2aaSMatthew G. Knepley     ierr             = (*prob->ops->destroy)(prob);CHKERRQ(ierr);
992764a2aaSMatthew G. Knepley     prob->ops->destroy = NULL;
1002764a2aaSMatthew G. Knepley   }
1012764a2aaSMatthew G. Knepley   ierr = (*r)(prob);CHKERRQ(ierr);
1022764a2aaSMatthew G. Knepley   ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr);
1032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1042764a2aaSMatthew G. Knepley }
1052764a2aaSMatthew G. Knepley 
1062764a2aaSMatthew G. Knepley /*@C
1072764a2aaSMatthew G. Knepley   PetscDSGetType - Gets the PetscDS type name (as a string) from the object.
1082764a2aaSMatthew G. Knepley 
1092764a2aaSMatthew G. Knepley   Not Collective
1102764a2aaSMatthew G. Knepley 
1112764a2aaSMatthew G. Knepley   Input Parameter:
1122764a2aaSMatthew G. Knepley . prob  - The PetscDS
1132764a2aaSMatthew G. Knepley 
1142764a2aaSMatthew G. Knepley   Output Parameter:
1152764a2aaSMatthew G. Knepley . name - The PetscDS type name
1162764a2aaSMatthew G. Knepley 
1172764a2aaSMatthew G. Knepley   Level: intermediate
1182764a2aaSMatthew G. Knepley 
119f5f57ec0SBarry Smith    Not available from Fortran
120f5f57ec0SBarry Smith 
1212764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate()
1222764a2aaSMatthew G. Knepley @*/
1232764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
1242764a2aaSMatthew G. Knepley {
1252764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1262764a2aaSMatthew G. Knepley 
1272764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1282764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
129c959eef4SJed Brown   PetscValidPointer(name, 2);
1300f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
1312764a2aaSMatthew G. Knepley   *name = ((PetscObject) prob)->type_name;
1322764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1332764a2aaSMatthew G. Knepley }
1342764a2aaSMatthew G. Knepley 
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     }
1715fedec97SMatthew G. Knepley     else SETERRQ1(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);
400*9ee2af8cSMatthew 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 */
432abac5ca0SMatthew G. Knepley       } else SETERRQ1(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];
438*9ee2af8cSMatthew G. Knepley     prob->offCohesive[0][f+1]    = (prob->cohesive[f] ? Nc : Nc*2)          + prob->offCohesive[0][f];
439*9ee2af8cSMatthew G. Knepley     prob->offDerCohesive[0][f+1] = (prob->cohesive[f] ? Nc : Nc*2)*dimEmbed + prob->offDerCohesive[0][f];
440*9ee2af8cSMatthew G. Knepley     prob->offCohesive[1][f]      = (prob->cohesive[f] ? 0 : Nc)             + prob->offCohesive[0][f];
441*9ee2af8cSMatthew G. Knepley     prob->offDerCohesive[1][f]   = (prob->cohesive[f] ? 0 : Nc)*dimEmbed    + prob->offDerCohesive[0][f];
442*9ee2af8cSMatthew G. Knepley     prob->offCohesive[2][f+1]    = (prob->cohesive[f] ? Nc : Nc*2)          + prob->offCohesive[2][f];
443*9ee2af8cSMatthew 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   }
453*9ee2af8cSMatthew G. Knepley   prob->offCohesive[1][Nf]    = prob->offCohesive[0][Nf];
454*9ee2af8cSMatthew 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);
474*9ee2af8cSMatthew 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);}
6749de99aefSMatthew G. Knepley       else SETERRQ1(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);
700a859676bSMatthew G. Knepley   if (prob->dimEmbed < 0) SETERRQ(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);
722ebfe4b0dSMatthew G. Knepley   if (dimEmbed < 0) SETERRQ1(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);
7995fedec97SMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
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);
8245fedec97SMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
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);
9062764a2aaSMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
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);
9322764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(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);}
1052083401c6SMatthew G. Knepley   else SETERRQ1(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);
1077249df284SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
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);
1100249df284SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
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);
1126f9244615SMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
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);
1149f9244615SMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
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);
11676528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
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);
11842764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(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);
12516528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
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);
13182764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(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
13243e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
13253e75805dSMatthew G. Knepley 
13263e75805dSMatthew G. Knepley   Not collective
13273e75805dSMatthew G. Knepley 
13283e75805dSMatthew G. Knepley   Input Parameter:
13293e75805dSMatthew G. Knepley . prob - The PetscDS
13303e75805dSMatthew G. Knepley 
13313e75805dSMatthew G. Knepley   Output Parameter:
13323e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
13333e75805dSMatthew G. Knepley 
13343e75805dSMatthew G. Knepley   Level: intermediate
13353e75805dSMatthew G. Knepley 
13363e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
13373e75805dSMatthew G. Knepley @*/
13386528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac)
13393e75805dSMatthew G. Knepley {
13406528b96dSMatthew G. Knepley   PetscErrorCode ierr;
13413e75805dSMatthew G. Knepley 
13423e75805dSMatthew G. Knepley   PetscFunctionBegin;
13436528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
13446528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobian(ds->wf, hasJac);CHKERRQ(ierr);
13453e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
13463e75805dSMatthew G. Knepley }
13473e75805dSMatthew G. Knepley 
1348194d53e6SMatthew G. Knepley /*@C
1349194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1350194d53e6SMatthew G. Knepley 
1351194d53e6SMatthew G. Knepley   Not collective
1352194d53e6SMatthew G. Knepley 
1353194d53e6SMatthew G. Knepley   Input Parameters:
13546528b96dSMatthew G. Knepley + ds - The PetscDS
1355194d53e6SMatthew G. Knepley . f  - The test field number
1356194d53e6SMatthew G. Knepley - g  - The field number
1357194d53e6SMatthew G. Knepley 
1358194d53e6SMatthew G. Knepley   Output Parameters:
1359194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1360194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1361194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1362194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1363194d53e6SMatthew G. Knepley 
1364194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1365194d53e6SMatthew G. Knepley 
1366194d53e6SMatthew 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
1367194d53e6SMatthew G. Knepley 
1368194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1369194d53e6SMatthew G. Knepley 
137030b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1371194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1372194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
137330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1374194d53e6SMatthew G. Knepley 
1375194d53e6SMatthew G. Knepley + dim - the spatial dimension
1376194d53e6SMatthew G. Knepley . Nf - the number of fields
1377194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1378194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1379194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1380194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1381194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1382194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1383194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1384194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1385194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1386194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1387194d53e6SMatthew G. Knepley . t - current time
13882aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1389194d53e6SMatthew G. Knepley . x - coordinates of the current point
139097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
139197b6e6e8SMatthew G. Knepley . constants - constant parameters
1392194d53e6SMatthew G. Knepley - g0 - output values at the current point
1393194d53e6SMatthew G. Knepley 
1394194d53e6SMatthew G. Knepley   Level: intermediate
1395194d53e6SMatthew G. Knepley 
1396194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1397194d53e6SMatthew G. Knepley @*/
13986528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS ds, PetscInt f, PetscInt g,
139930b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1400194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1401194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
140297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
140330b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1404194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1405194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
140697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
140730b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1408194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1409194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
141097b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
141130b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1412194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1413194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
141497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
14152764a2aaSMatthew G. Knepley {
14166528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
14176528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
14186528b96dSMatthew G. Knepley   PetscErrorCode ierr;
14196528b96dSMatthew G. Knepley 
14202764a2aaSMatthew G. Knepley   PetscFunctionBegin;
14216528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
14226528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
14236528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
142406ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
14256528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
14266528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
14276528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
14286528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
14292764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
14302764a2aaSMatthew G. Knepley }
14312764a2aaSMatthew G. Knepley 
1432194d53e6SMatthew G. Knepley /*@C
1433194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1434194d53e6SMatthew G. Knepley 
1435194d53e6SMatthew G. Knepley   Not collective
1436194d53e6SMatthew G. Knepley 
1437194d53e6SMatthew G. Knepley   Input Parameters:
14386528b96dSMatthew G. Knepley + ds - The PetscDS
1439194d53e6SMatthew G. Knepley . f  - The test field number
1440194d53e6SMatthew G. Knepley . g  - The field number
1441194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1442194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1443194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1444194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1445194d53e6SMatthew G. Knepley 
1446194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1447194d53e6SMatthew G. Knepley 
1448194d53e6SMatthew 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
1449194d53e6SMatthew G. Knepley 
1450194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1451194d53e6SMatthew G. Knepley 
145230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1453194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1454194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
145530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1456194d53e6SMatthew G. Knepley 
1457194d53e6SMatthew G. Knepley + dim - the spatial dimension
1458194d53e6SMatthew G. Knepley . Nf - the number of fields
1459194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1460194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1461194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1462194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1463194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1464194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1465194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1466194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1467194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1468194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1469194d53e6SMatthew G. Knepley . t - current time
14702aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1471194d53e6SMatthew G. Knepley . x - coordinates of the current point
147297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
147397b6e6e8SMatthew G. Knepley . constants - constant parameters
1474194d53e6SMatthew G. Knepley - g0 - output values at the current point
1475194d53e6SMatthew G. Knepley 
1476194d53e6SMatthew G. Knepley   Level: intermediate
1477194d53e6SMatthew G. Knepley 
1478194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1479194d53e6SMatthew G. Knepley @*/
14806528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS ds, PetscInt f, PetscInt g,
148130b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1482194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1483194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
148497b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
148530b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1486194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1487194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
148897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
148930b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1490194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1491194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
149297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
149330b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1494194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1495194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
149697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
14972764a2aaSMatthew G. Knepley {
14982764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
14992764a2aaSMatthew G. Knepley 
15002764a2aaSMatthew G. Knepley   PetscFunctionBegin;
15016528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
15022764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
15032764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
15042764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
15052764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
15062764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
15072764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
150806ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
15092764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
15102764a2aaSMatthew G. Knepley }
15112764a2aaSMatthew G. Knepley 
1512475e0ac9SMatthew G. Knepley /*@C
151355c1f793SMatthew G. Knepley   PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner
151455c1f793SMatthew G. Knepley 
151555c1f793SMatthew G. Knepley   Not collective
151655c1f793SMatthew G. Knepley 
151755c1f793SMatthew G. Knepley   Input Parameters:
151855c1f793SMatthew G. Knepley + prob - The PetscDS
151955c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
152055c1f793SMatthew G. Knepley 
152155c1f793SMatthew G. Knepley   Level: intermediate
152255c1f793SMatthew G. Knepley 
152355c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
152455c1f793SMatthew G. Knepley @*/
152555c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
152655c1f793SMatthew G. Knepley {
152755c1f793SMatthew G. Knepley   PetscFunctionBegin;
152855c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
152955c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
153055c1f793SMatthew G. Knepley   PetscFunctionReturn(0);
153155c1f793SMatthew G. Knepley }
153255c1f793SMatthew G. Knepley 
153355c1f793SMatthew G. Knepley /*@C
1534475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1535475e0ac9SMatthew G. Knepley 
1536475e0ac9SMatthew G. Knepley   Not collective
1537475e0ac9SMatthew G. Knepley 
1538475e0ac9SMatthew G. Knepley   Input Parameter:
1539475e0ac9SMatthew G. Knepley . prob - The PetscDS
1540475e0ac9SMatthew G. Knepley 
1541475e0ac9SMatthew G. Knepley   Output Parameter:
1542475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1543475e0ac9SMatthew G. Knepley 
1544475e0ac9SMatthew G. Knepley   Level: intermediate
1545475e0ac9SMatthew G. Knepley 
1546475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1547475e0ac9SMatthew G. Knepley @*/
15486528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre)
1549475e0ac9SMatthew G. Knepley {
15506528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1551475e0ac9SMatthew G. Knepley 
1552475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
15536528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1554475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
15556528b96dSMatthew G. Knepley   if (!ds->useJacPre) PetscFunctionReturn(0);
15566528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre);CHKERRQ(ierr);
1557475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1558475e0ac9SMatthew G. Knepley }
1559475e0ac9SMatthew G. Knepley 
1560475e0ac9SMatthew G. Knepley /*@C
1561475e0ac9SMatthew 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.
1562475e0ac9SMatthew G. Knepley 
1563475e0ac9SMatthew G. Knepley   Not collective
1564475e0ac9SMatthew G. Knepley 
1565475e0ac9SMatthew G. Knepley   Input Parameters:
15666528b96dSMatthew G. Knepley + ds - The PetscDS
1567475e0ac9SMatthew G. Knepley . f  - The test field number
1568475e0ac9SMatthew G. Knepley - g  - The field number
1569475e0ac9SMatthew G. Knepley 
1570475e0ac9SMatthew G. Knepley   Output Parameters:
1571475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1572475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1573475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1574475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1575475e0ac9SMatthew G. Knepley 
1576475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1577475e0ac9SMatthew G. Knepley 
1578475e0ac9SMatthew 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
1579475e0ac9SMatthew G. Knepley 
1580475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1581475e0ac9SMatthew G. Knepley 
1582475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1583475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1584475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1585475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1586475e0ac9SMatthew G. Knepley 
1587475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1588475e0ac9SMatthew G. Knepley . Nf - the number of fields
1589475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1590475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1591475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1592475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1593475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1594475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1595475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1596475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1597475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1598475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1599475e0ac9SMatthew G. Knepley . t - current time
1600475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1601475e0ac9SMatthew G. Knepley . x - coordinates of the current point
160297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
160397b6e6e8SMatthew G. Knepley . constants - constant parameters
1604475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1605475e0ac9SMatthew G. Knepley 
1606475e0ac9SMatthew G. Knepley   Level: intermediate
1607475e0ac9SMatthew G. Knepley 
1608475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1609475e0ac9SMatthew G. Knepley @*/
16106528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1611475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1612475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1613475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
161497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1615475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1616475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1617475e0ac9SMatthew 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 g1[]),
1619475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1620475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1621475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1623475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1624475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1625475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1627475e0ac9SMatthew G. Knepley {
16286528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
16296528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
16306528b96dSMatthew G. Knepley   PetscErrorCode ierr;
16316528b96dSMatthew G. Knepley 
1632475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
16336528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
16346528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
16356528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
163606ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
16376528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
16386528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
16396528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
16406528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1641475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1642475e0ac9SMatthew G. Knepley }
1643475e0ac9SMatthew G. Knepley 
1644475e0ac9SMatthew G. Knepley /*@C
1645475e0ac9SMatthew 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.
1646475e0ac9SMatthew G. Knepley 
1647475e0ac9SMatthew G. Knepley   Not collective
1648475e0ac9SMatthew G. Knepley 
1649475e0ac9SMatthew G. Knepley   Input Parameters:
16506528b96dSMatthew G. Knepley + ds - The PetscDS
1651475e0ac9SMatthew G. Knepley . f  - The test field number
1652475e0ac9SMatthew G. Knepley . g  - The field number
1653475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1654475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1655475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1656475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1657475e0ac9SMatthew G. Knepley 
1658475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1659475e0ac9SMatthew G. Knepley 
1660475e0ac9SMatthew 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
1661475e0ac9SMatthew G. Knepley 
1662475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1663475e0ac9SMatthew G. Knepley 
1664475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1665475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1666475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1667475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1668475e0ac9SMatthew G. Knepley 
1669475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1670475e0ac9SMatthew G. Knepley . Nf - the number of fields
1671475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1672475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1673475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1674475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1675475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1676475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1677475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1678475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1679475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1680475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1681475e0ac9SMatthew G. Knepley . t - current time
1682475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1683475e0ac9SMatthew G. Knepley . x - coordinates of the current point
168497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
168597b6e6e8SMatthew G. Knepley . constants - constant parameters
1686475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1687475e0ac9SMatthew G. Knepley 
1688475e0ac9SMatthew G. Knepley   Level: intermediate
1689475e0ac9SMatthew G. Knepley 
1690475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1691475e0ac9SMatthew G. Knepley @*/
16926528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
1693475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1694475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1695475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
169697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1697475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1698475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1699475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
170097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1701475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1702475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1703475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
170497b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1705475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1706475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1707475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
170897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1709475e0ac9SMatthew G. Knepley {
1710475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1711475e0ac9SMatthew G. Knepley 
1712475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
17136528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1714475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1715475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1716475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1717475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1718475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1719475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
172006ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
1721475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1722475e0ac9SMatthew G. Knepley }
1723475e0ac9SMatthew G. Knepley 
1724b7e05686SMatthew G. Knepley /*@C
1725b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1726b7e05686SMatthew G. Knepley 
1727b7e05686SMatthew G. Knepley   Not collective
1728b7e05686SMatthew G. Knepley 
1729b7e05686SMatthew G. Knepley   Input Parameter:
17306528b96dSMatthew G. Knepley . ds - The PetscDS
1731b7e05686SMatthew G. Knepley 
1732b7e05686SMatthew G. Knepley   Output Parameter:
1733b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1734b7e05686SMatthew G. Knepley 
1735b7e05686SMatthew G. Knepley   Level: intermediate
1736b7e05686SMatthew G. Knepley 
1737b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1738b7e05686SMatthew G. Knepley @*/
17396528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac)
1740b7e05686SMatthew G. Knepley {
17416528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1742b7e05686SMatthew G. Knepley 
1743b7e05686SMatthew G. Knepley   PetscFunctionBegin;
17446528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
17456528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac);CHKERRQ(ierr);
1746b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1747b7e05686SMatthew G. Knepley }
1748b7e05686SMatthew G. Knepley 
1749b7e05686SMatthew G. Knepley /*@C
1750b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1751b7e05686SMatthew G. Knepley 
1752b7e05686SMatthew G. Knepley   Not collective
1753b7e05686SMatthew G. Knepley 
1754b7e05686SMatthew G. Knepley   Input Parameters:
17556528b96dSMatthew G. Knepley + ds - The PetscDS
1756b7e05686SMatthew G. Knepley . f  - The test field number
1757b7e05686SMatthew G. Knepley - g  - The field number
1758b7e05686SMatthew G. Knepley 
1759b7e05686SMatthew G. Knepley   Output Parameters:
1760b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1761b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1762b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1763b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1764b7e05686SMatthew G. Knepley 
1765b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1766b7e05686SMatthew G. Knepley 
1767b7e05686SMatthew 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
1768b7e05686SMatthew G. Knepley 
1769b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1770b7e05686SMatthew G. Knepley 
1771b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1772b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1773b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1774b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1775b7e05686SMatthew G. Knepley 
1776b7e05686SMatthew G. Knepley + dim - the spatial dimension
1777b7e05686SMatthew G. Knepley . Nf - the number of fields
1778b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1779b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1780b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1781b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1782b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1783b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1784b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1785b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1786b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1787b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1788b7e05686SMatthew G. Knepley . t - current time
1789b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1790b7e05686SMatthew G. Knepley . x - coordinates of the current point
179197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
179297b6e6e8SMatthew G. Knepley . constants - constant parameters
1793b7e05686SMatthew G. Knepley - g0 - output values at the current point
1794b7e05686SMatthew G. Knepley 
1795b7e05686SMatthew G. Knepley   Level: intermediate
1796b7e05686SMatthew G. Knepley 
1797b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1798b7e05686SMatthew G. Knepley @*/
17996528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
1800b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1801b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1802b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
180397b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1804b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1805b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1806b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
180797b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1808b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1809b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1810b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
181197b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1812b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1813b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1814b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
181597b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1816b7e05686SMatthew G. Knepley {
18176528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
18186528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
18196528b96dSMatthew G. Knepley   PetscErrorCode ierr;
18206528b96dSMatthew G. Knepley 
1821b7e05686SMatthew G. Knepley   PetscFunctionBegin;
18226528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
18236528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
18246528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
182506ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
18266528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
18276528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
18286528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
18296528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
1830b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1831b7e05686SMatthew G. Knepley }
1832b7e05686SMatthew G. Knepley 
1833b7e05686SMatthew G. Knepley /*@C
1834b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1835b7e05686SMatthew G. Knepley 
1836b7e05686SMatthew G. Knepley   Not collective
1837b7e05686SMatthew G. Knepley 
1838b7e05686SMatthew G. Knepley   Input Parameters:
18396528b96dSMatthew G. Knepley + ds - The PetscDS
1840b7e05686SMatthew G. Knepley . f  - The test field number
1841b7e05686SMatthew G. Knepley . g  - The field number
1842b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1843b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1844b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1845b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1846b7e05686SMatthew G. Knepley 
1847b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1848b7e05686SMatthew G. Knepley 
1849b7e05686SMatthew 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
1850b7e05686SMatthew G. Knepley 
1851b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1852b7e05686SMatthew G. Knepley 
1853b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1854b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1855b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1856b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1857b7e05686SMatthew G. Knepley 
1858b7e05686SMatthew G. Knepley + dim - the spatial dimension
1859b7e05686SMatthew G. Knepley . Nf - the number of fields
1860b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1861b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1862b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1863b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1864b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1865b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1866b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1867b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1868b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1869b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1870b7e05686SMatthew G. Knepley . t - current time
1871b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1872b7e05686SMatthew G. Knepley . x - coordinates of the current point
187397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
187497b6e6e8SMatthew G. Knepley . constants - constant parameters
1875b7e05686SMatthew G. Knepley - g0 - output values at the current point
1876b7e05686SMatthew G. Knepley 
1877b7e05686SMatthew G. Knepley   Level: intermediate
1878b7e05686SMatthew G. Knepley 
1879b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1880b7e05686SMatthew G. Knepley @*/
18816528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g,
1882b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1883b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1884b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
188597b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1886b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1887b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1888b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
188997b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1890b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1891b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1892b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
189397b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1894b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1895b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1896b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
189797b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1898b7e05686SMatthew G. Knepley {
1899b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1900b7e05686SMatthew G. Knepley 
1901b7e05686SMatthew G. Knepley   PetscFunctionBegin;
19026528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1903b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1904b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1905b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1906b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1907b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1908b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
190906ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
1910b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1911b7e05686SMatthew G. Knepley }
1912b7e05686SMatthew G. Knepley 
19130c2f2876SMatthew G. Knepley /*@C
19140c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
19150c2f2876SMatthew G. Knepley 
19160c2f2876SMatthew G. Knepley   Not collective
19170c2f2876SMatthew G. Knepley 
19184165533cSJose E. Roman   Input Parameters:
19196528b96dSMatthew G. Knepley + ds - The PetscDS object
19200c2f2876SMatthew G. Knepley - f  - The field number
19210c2f2876SMatthew G. Knepley 
19224165533cSJose E. Roman   Output Parameter:
19230c2f2876SMatthew G. Knepley . r    - Riemann solver
19240c2f2876SMatthew G. Knepley 
19250c2f2876SMatthew G. Knepley   Calling sequence for r:
19260c2f2876SMatthew G. Knepley 
19275db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
19280c2f2876SMatthew G. Knepley 
19295db36cf9SMatthew G. Knepley + dim  - The spatial dimension
19305db36cf9SMatthew G. Knepley . Nf   - The number of fields
19315db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
19320c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
19330c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
19340c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
19350c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
193697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
193797b6e6e8SMatthew G. Knepley . constants - constant parameters
19380c2f2876SMatthew G. Knepley - ctx  - optional user context
19390c2f2876SMatthew G. Knepley 
19400c2f2876SMatthew G. Knepley   Level: intermediate
19410c2f2876SMatthew G. Knepley 
19420c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
19430c2f2876SMatthew G. Knepley @*/
19446528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS ds, PetscInt f,
194597b6e6e8SMatthew 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))
19460c2f2876SMatthew G. Knepley {
19476528b96dSMatthew G. Knepley   PetscRiemannFunc *tmp;
19486528b96dSMatthew G. Knepley   PetscInt          n;
19496528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
19506528b96dSMatthew G. Knepley 
19510c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19526528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
19530c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
19546528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
195506ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, 0, &n, &tmp);CHKERRQ(ierr);
19566528b96dSMatthew G. Knepley   *r   = tmp ? tmp[0] : NULL;
19570c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19580c2f2876SMatthew G. Knepley }
19590c2f2876SMatthew G. Knepley 
19600c2f2876SMatthew G. Knepley /*@C
19610c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
19620c2f2876SMatthew G. Knepley 
19630c2f2876SMatthew G. Knepley   Not collective
19640c2f2876SMatthew G. Knepley 
19654165533cSJose E. Roman   Input Parameters:
19666528b96dSMatthew G. Knepley + ds - The PetscDS object
19670c2f2876SMatthew G. Knepley . f  - The field number
19680c2f2876SMatthew G. Knepley - r  - Riemann solver
19690c2f2876SMatthew G. Knepley 
19700c2f2876SMatthew G. Knepley   Calling sequence for r:
19710c2f2876SMatthew G. Knepley 
19725db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
19730c2f2876SMatthew G. Knepley 
19745db36cf9SMatthew G. Knepley + dim  - The spatial dimension
19755db36cf9SMatthew G. Knepley . Nf   - The number of fields
19765db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
19770c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
19780c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
19790c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
19800c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
198197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
198297b6e6e8SMatthew G. Knepley . constants - constant parameters
19830c2f2876SMatthew G. Knepley - ctx  - optional user context
19840c2f2876SMatthew G. Knepley 
19850c2f2876SMatthew G. Knepley   Level: intermediate
19860c2f2876SMatthew G. Knepley 
19870c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
19880c2f2876SMatthew G. Knepley @*/
19896528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS ds, PetscInt f,
199097b6e6e8SMatthew 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))
19910c2f2876SMatthew G. Knepley {
19920c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
19930c2f2876SMatthew G. Knepley 
19940c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19956528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1996de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
19970c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
199806ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, 0, r);CHKERRQ(ierr);
19990c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20000c2f2876SMatthew G. Knepley }
20010c2f2876SMatthew G. Knepley 
200232d2bbc9SMatthew G. Knepley /*@C
200332d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
200432d2bbc9SMatthew G. Knepley 
200532d2bbc9SMatthew G. Knepley   Not collective
200632d2bbc9SMatthew G. Knepley 
200732d2bbc9SMatthew G. Knepley   Input Parameters:
20086528b96dSMatthew G. Knepley + ds - The PetscDS
200932d2bbc9SMatthew G. Knepley - f  - The field number
201032d2bbc9SMatthew G. Knepley 
2011f899ff85SJose E. Roman   Output Parameter:
2012a2b725a8SWilliam Gropp . update - update function
201332d2bbc9SMatthew G. Knepley 
201432d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
201532d2bbc9SMatthew G. Knepley 
201632d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
201732d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
201832d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
201932d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
202032d2bbc9SMatthew G. Knepley 
202132d2bbc9SMatthew G. Knepley + dim - the spatial dimension
202232d2bbc9SMatthew G. Knepley . Nf - the number of fields
202332d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
202432d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
202532d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
202632d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
202732d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
202832d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
202932d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
203032d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
203132d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
203232d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
203332d2bbc9SMatthew G. Knepley . t - current time
203432d2bbc9SMatthew G. Knepley . x - coordinates of the current point
203532d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
203632d2bbc9SMatthew G. Knepley 
203732d2bbc9SMatthew G. Knepley   Level: intermediate
203832d2bbc9SMatthew G. Knepley 
203932d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
204032d2bbc9SMatthew G. Knepley @*/
20416528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS ds, PetscInt f,
204232d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
204332d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
204432d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20453fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
204632d2bbc9SMatthew G. Knepley {
204732d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
20486528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
20496528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
20506528b96dSMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = ds->update[f];}
205132d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
205232d2bbc9SMatthew G. Knepley }
205332d2bbc9SMatthew G. Knepley 
205432d2bbc9SMatthew G. Knepley /*@C
20553fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
205632d2bbc9SMatthew G. Knepley 
205732d2bbc9SMatthew G. Knepley   Not collective
205832d2bbc9SMatthew G. Knepley 
205932d2bbc9SMatthew G. Knepley   Input Parameters:
20606528b96dSMatthew G. Knepley + ds     - The PetscDS
206132d2bbc9SMatthew G. Knepley . f      - The field number
206232d2bbc9SMatthew G. Knepley - update - update function
206332d2bbc9SMatthew G. Knepley 
206432d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
206532d2bbc9SMatthew G. Knepley 
206632d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
206732d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
206832d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
206932d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
207032d2bbc9SMatthew G. Knepley 
207132d2bbc9SMatthew G. Knepley + dim - the spatial dimension
207232d2bbc9SMatthew G. Knepley . Nf - the number of fields
207332d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
207432d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
207532d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
207632d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
207732d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
207832d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
207932d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
208032d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
208132d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
208232d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
208332d2bbc9SMatthew G. Knepley . t - current time
208432d2bbc9SMatthew G. Knepley . x - coordinates of the current point
208532d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
208632d2bbc9SMatthew G. Knepley 
208732d2bbc9SMatthew G. Knepley   Level: intermediate
208832d2bbc9SMatthew G. Knepley 
208932d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
209032d2bbc9SMatthew G. Knepley @*/
20916528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS ds, PetscInt f,
209232d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
209332d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
209432d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20953fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
209632d2bbc9SMatthew G. Knepley {
209732d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
209832d2bbc9SMatthew G. Knepley 
209932d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
21006528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
210132d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
210232d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21036528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
21046528b96dSMatthew G. Knepley   ds->update[f] = update;
210532d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
210632d2bbc9SMatthew G. Knepley }
210732d2bbc9SMatthew G. Knepley 
21083ec1f749SStefano Zampini PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void *ctx)
21090c2f2876SMatthew G. Knepley {
21100c2f2876SMatthew G. Knepley   PetscFunctionBegin;
21116528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
21126528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
21130c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
21143ec1f749SStefano Zampini   *(void**)ctx = ds->ctx[f];
21150c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
21160c2f2876SMatthew G. Knepley }
21170c2f2876SMatthew G. Knepley 
21186528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx)
21190c2f2876SMatthew G. Knepley {
21200c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
21210c2f2876SMatthew G. Knepley 
21220c2f2876SMatthew G. Knepley   PetscFunctionBegin;
21236528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
21240c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21256528b96dSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr);
21266528b96dSMatthew G. Knepley   ds->ctx[f] = ctx;
21270c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
21280c2f2876SMatthew G. Knepley }
21290c2f2876SMatthew G. Knepley 
2130194d53e6SMatthew G. Knepley /*@C
2131194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
2132194d53e6SMatthew G. Knepley 
2133194d53e6SMatthew G. Knepley   Not collective
2134194d53e6SMatthew G. Knepley 
2135194d53e6SMatthew G. Knepley   Input Parameters:
21366528b96dSMatthew G. Knepley + ds - The PetscDS
2137194d53e6SMatthew G. Knepley - f  - The test field number
2138194d53e6SMatthew G. Knepley 
2139194d53e6SMatthew G. Knepley   Output Parameters:
2140194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
2141194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2142194d53e6SMatthew G. Knepley 
2143194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2144194d53e6SMatthew G. Knepley 
2145194d53e6SMatthew 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
2146194d53e6SMatthew G. Knepley 
2147194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2148194d53e6SMatthew G. Knepley 
214930b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2150194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2151194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
215230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2153194d53e6SMatthew G. Knepley 
2154194d53e6SMatthew G. Knepley + dim - the spatial dimension
2155194d53e6SMatthew G. Knepley . Nf - the number of fields
2156194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2157194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2158194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2159194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2160194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2161194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2162194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2163194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2164194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2165194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2166194d53e6SMatthew G. Knepley . t - current time
2167194d53e6SMatthew G. Knepley . x - coordinates of the current point
2168194d53e6SMatthew G. Knepley . n - unit normal at the current point
216997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
217097b6e6e8SMatthew G. Knepley . constants - constant parameters
2171194d53e6SMatthew G. Knepley - f0 - output values at the current point
2172194d53e6SMatthew G. Knepley 
2173194d53e6SMatthew G. Knepley   Level: intermediate
2174194d53e6SMatthew G. Knepley 
2175194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
2176194d53e6SMatthew G. Knepley @*/
21776528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS ds, PetscInt f,
217830b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2179194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2180194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
218197b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
218230b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2183194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2184194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
218597b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
21862764a2aaSMatthew G. Knepley {
21876528b96dSMatthew G. Knepley   PetscBdPointFunc *tmp0, *tmp1;
21886528b96dSMatthew G. Knepley   PetscInt          n0, n1;
21896528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
21906528b96dSMatthew G. Knepley 
21912764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21926528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
21936528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
219406ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr);
21956528b96dSMatthew G. Knepley   *f0  = tmp0 ? tmp0[0] : NULL;
21966528b96dSMatthew G. Knepley   *f1  = tmp1 ? tmp1[0] : NULL;
21972764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21982764a2aaSMatthew G. Knepley }
21992764a2aaSMatthew G. Knepley 
2200194d53e6SMatthew G. Knepley /*@C
2201194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2202194d53e6SMatthew G. Knepley 
2203194d53e6SMatthew G. Knepley   Not collective
2204194d53e6SMatthew G. Knepley 
2205194d53e6SMatthew G. Knepley   Input Parameters:
22066528b96dSMatthew G. Knepley + ds - The PetscDS
2207194d53e6SMatthew G. Knepley . f  - The test field number
2208194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2209194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2210194d53e6SMatthew G. Knepley 
2211194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2212194d53e6SMatthew G. Knepley 
2213194d53e6SMatthew 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
2214194d53e6SMatthew G. Knepley 
2215194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2216194d53e6SMatthew G. Knepley 
221730b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2218194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2219194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
222030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2221194d53e6SMatthew G. Knepley 
2222194d53e6SMatthew G. Knepley + dim - the spatial dimension
2223194d53e6SMatthew G. Knepley . Nf - the number of fields
2224194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2225194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2226194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2227194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2228194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2229194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2230194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2231194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2232194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2233194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2234194d53e6SMatthew G. Knepley . t - current time
2235194d53e6SMatthew G. Knepley . x - coordinates of the current point
2236194d53e6SMatthew G. Knepley . n - unit normal at the current point
223797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
223897b6e6e8SMatthew G. Knepley . constants - constant parameters
2239194d53e6SMatthew G. Knepley - f0 - output values at the current point
2240194d53e6SMatthew G. Knepley 
2241194d53e6SMatthew G. Knepley   Level: intermediate
2242194d53e6SMatthew G. Knepley 
2243194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
2244194d53e6SMatthew G. Knepley @*/
22456528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS ds, PetscInt f,
224630b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2247194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2248194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
224997b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
225030b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2251194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2252194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
225397b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
22542764a2aaSMatthew G. Knepley {
22552764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
22562764a2aaSMatthew G. Knepley 
22572764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22586528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
22592764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
226006ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1);CHKERRQ(ierr);
22612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22622764a2aaSMatthew G. Knepley }
22632764a2aaSMatthew G. Knepley 
226427f02ce8SMatthew G. Knepley /*@
226527f02ce8SMatthew G. Knepley   PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set
226627f02ce8SMatthew G. Knepley 
226727f02ce8SMatthew G. Knepley   Not collective
226827f02ce8SMatthew G. Knepley 
226927f02ce8SMatthew G. Knepley   Input Parameter:
22706528b96dSMatthew G. Knepley . ds - The PetscDS
227127f02ce8SMatthew G. Knepley 
227227f02ce8SMatthew G. Knepley   Output Parameter:
227327f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set
227427f02ce8SMatthew G. Knepley 
227527f02ce8SMatthew G. Knepley   Level: intermediate
227627f02ce8SMatthew G. Knepley 
227727f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
227827f02ce8SMatthew G. Knepley @*/
22796528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac)
228027f02ce8SMatthew G. Knepley {
22816528b96dSMatthew G. Knepley   PetscErrorCode ierr;
228227f02ce8SMatthew G. Knepley 
228327f02ce8SMatthew G. Knepley   PetscFunctionBegin;
22846528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
22856528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJac, 2);
22866528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobian(ds->wf, hasBdJac);CHKERRQ(ierr);
228727f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
228827f02ce8SMatthew G. Knepley }
228927f02ce8SMatthew G. Knepley 
2290194d53e6SMatthew G. Knepley /*@C
2291194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2292194d53e6SMatthew G. Knepley 
2293194d53e6SMatthew G. Knepley   Not collective
2294194d53e6SMatthew G. Knepley 
2295194d53e6SMatthew G. Knepley   Input Parameters:
22966528b96dSMatthew G. Knepley + ds - The PetscDS
2297194d53e6SMatthew G. Knepley . f  - The test field number
2298194d53e6SMatthew G. Knepley - g  - The field number
2299194d53e6SMatthew G. Knepley 
2300194d53e6SMatthew G. Knepley   Output Parameters:
2301194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2302194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2303194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2304194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2305194d53e6SMatthew G. Knepley 
2306194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2307194d53e6SMatthew G. Knepley 
2308194d53e6SMatthew 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
2309194d53e6SMatthew G. Knepley 
2310194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2311194d53e6SMatthew G. Knepley 
231230b9ff8bSMatthew G. Knepley $ g0(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[],
231530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2316194d53e6SMatthew G. Knepley 
2317194d53e6SMatthew G. Knepley + dim - the spatial dimension
2318194d53e6SMatthew G. Knepley . Nf - the number of fields
2319194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2320194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2321194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2322194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2323194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2324194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2325194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2326194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2327194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2328194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2329194d53e6SMatthew G. Knepley . t - current time
23302aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2331194d53e6SMatthew G. Knepley . x - coordinates of the current point
2332194d53e6SMatthew G. Knepley . n - normal at the current point
233397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
233497b6e6e8SMatthew G. Knepley . constants - constant parameters
2335194d53e6SMatthew G. Knepley - g0 - output values at the current point
2336194d53e6SMatthew G. Knepley 
2337194d53e6SMatthew G. Knepley   Level: intermediate
2338194d53e6SMatthew G. Knepley 
2339194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2340194d53e6SMatthew G. Knepley @*/
23416528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
234230b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2343194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2344194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
234597b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
234630b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2347194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2348194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
234997b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
235030b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2351194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2352194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
235397b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
235430b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2355194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2356194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
235797b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
23582764a2aaSMatthew G. Knepley {
23596528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
23606528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
23616528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
23626528b96dSMatthew G. Knepley 
23632764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23646528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
23656528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
23666528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
236706ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
23686528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
23696528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
23706528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
23716528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
23722764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23732764a2aaSMatthew G. Knepley }
23742764a2aaSMatthew G. Knepley 
2375194d53e6SMatthew G. Knepley /*@C
2376194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2377194d53e6SMatthew G. Knepley 
2378194d53e6SMatthew G. Knepley   Not collective
2379194d53e6SMatthew G. Knepley 
2380194d53e6SMatthew G. Knepley   Input Parameters:
23816528b96dSMatthew G. Knepley + ds - The PetscDS
2382194d53e6SMatthew G. Knepley . f  - The test field number
2383194d53e6SMatthew G. Knepley . g  - The field number
2384194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2385194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2386194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2387194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2388194d53e6SMatthew G. Knepley 
2389194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2390194d53e6SMatthew G. Knepley 
2391194d53e6SMatthew 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
2392194d53e6SMatthew G. Knepley 
2393194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2394194d53e6SMatthew G. Knepley 
239530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2396194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2397194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
239830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2399194d53e6SMatthew G. Knepley 
2400194d53e6SMatthew G. Knepley + dim - the spatial dimension
2401194d53e6SMatthew G. Knepley . Nf - the number of fields
2402194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2403194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2404194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2405194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2406194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2407194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2408194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2409194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2410194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2411194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2412194d53e6SMatthew G. Knepley . t - current time
24132aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2414194d53e6SMatthew G. Knepley . x - coordinates of the current point
2415194d53e6SMatthew G. Knepley . n - normal at the current point
241697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
241797b6e6e8SMatthew G. Knepley . constants - constant parameters
2418194d53e6SMatthew G. Knepley - g0 - output values at the current point
2419194d53e6SMatthew G. Knepley 
2420194d53e6SMatthew G. Knepley   Level: intermediate
2421194d53e6SMatthew G. Knepley 
2422194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2423194d53e6SMatthew G. Knepley @*/
24246528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS ds, PetscInt f, PetscInt g,
242530b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2426194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2427194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
242897b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
242930b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2430194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2431194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
243297b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
243330b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2434194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2435194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
243697b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
243730b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2438194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2439194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
244097b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
24412764a2aaSMatthew G. Knepley {
24422764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24432764a2aaSMatthew G. Knepley 
24442764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24456528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24462764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
24472764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
24482764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
24492764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
24502764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
24512764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
245206ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
24532764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
24542764a2aaSMatthew G. Knepley }
24552764a2aaSMatthew G. Knepley 
245627f02ce8SMatthew G. Knepley /*@
245727f02ce8SMatthew G. Knepley   PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set
245827f02ce8SMatthew G. Knepley 
245927f02ce8SMatthew G. Knepley   Not collective
246027f02ce8SMatthew G. Knepley 
246127f02ce8SMatthew G. Knepley   Input Parameter:
24626528b96dSMatthew G. Knepley . ds - The PetscDS
246327f02ce8SMatthew G. Knepley 
246427f02ce8SMatthew G. Knepley   Output Parameter:
246527f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set
246627f02ce8SMatthew G. Knepley 
246727f02ce8SMatthew G. Knepley   Level: intermediate
246827f02ce8SMatthew G. Knepley 
246927f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
247027f02ce8SMatthew G. Knepley @*/
24716528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre)
247227f02ce8SMatthew G. Knepley {
24736528b96dSMatthew G. Knepley   PetscErrorCode ierr;
247427f02ce8SMatthew G. Knepley 
247527f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24766528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24776528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJacPre, 2);
24786528b96dSMatthew G. Knepley   ierr = PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre);CHKERRQ(ierr);
247927f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
248027f02ce8SMatthew G. Knepley }
248127f02ce8SMatthew G. Knepley 
248227f02ce8SMatthew G. Knepley /*@C
248327f02ce8SMatthew G. Knepley   PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field
248427f02ce8SMatthew G. Knepley 
248527f02ce8SMatthew G. Knepley   Not collective
248627f02ce8SMatthew G. Knepley 
248727f02ce8SMatthew G. Knepley   Input Parameters:
24886528b96dSMatthew G. Knepley + ds - The PetscDS
248927f02ce8SMatthew G. Knepley . f  - The test field number
249027f02ce8SMatthew G. Knepley - g  - The field number
249127f02ce8SMatthew G. Knepley 
249227f02ce8SMatthew G. Knepley   Output Parameters:
249327f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term
249427f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
249527f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
249627f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
249727f02ce8SMatthew G. Knepley 
249827f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
249927f02ce8SMatthew G. Knepley 
250027f02ce8SMatthew 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
250127f02ce8SMatthew G. Knepley 
250227f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
250327f02ce8SMatthew G. Knepley 
250427f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
250527f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
250627f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
250727f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
250827f02ce8SMatthew G. Knepley 
250927f02ce8SMatthew G. Knepley + dim - the spatial dimension
251027f02ce8SMatthew G. Knepley . Nf - the number of fields
251127f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
251227f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
251327f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
251427f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
251527f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
251627f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
251727f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
251827f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
251927f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
252027f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
252127f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
252227f02ce8SMatthew G. Knepley . t - current time
252327f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
252427f02ce8SMatthew G. Knepley . x - coordinates of the current point
252527f02ce8SMatthew G. Knepley . n - normal at the current point
252627f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
252727f02ce8SMatthew G. Knepley . constants - constant parameters
252827f02ce8SMatthew G. Knepley - g0 - output values at the current point
252927f02ce8SMatthew G. Knepley 
253027f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
253127f02ce8SMatthew G. Knepley 
253227f02ce8SMatthew G. Knepley   Level: intermediate
253327f02ce8SMatthew G. Knepley 
253427f02ce8SMatthew G. Knepley .seealso: PetscDSSetBdJacobianPreconditioner()
253527f02ce8SMatthew G. Knepley @*/
25366528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
253727f02ce8SMatthew G. Knepley                                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
253827f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
253927f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
254027f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
254127f02ce8SMatthew G. Knepley                                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
254227f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
254327f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
254427f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
254527f02ce8SMatthew G. Knepley                                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
254627f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
254727f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
254827f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
254927f02ce8SMatthew G. Knepley                                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
255027f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
255127f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
255227f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
255327f02ce8SMatthew G. Knepley {
25546528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
25556528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
25566528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
25576528b96dSMatthew G. Knepley 
255827f02ce8SMatthew G. Knepley   PetscFunctionBegin;
25596528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
25606528b96dSMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
25616528b96dSMatthew G. Knepley   if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf);
256206ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr);
25636528b96dSMatthew G. Knepley   *g0  = tmp0 ? tmp0[0] : NULL;
25646528b96dSMatthew G. Knepley   *g1  = tmp1 ? tmp1[0] : NULL;
25656528b96dSMatthew G. Knepley   *g2  = tmp2 ? tmp2[0] : NULL;
25666528b96dSMatthew G. Knepley   *g3  = tmp3 ? tmp3[0] : NULL;
256727f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
256827f02ce8SMatthew G. Knepley }
256927f02ce8SMatthew G. Knepley 
257027f02ce8SMatthew G. Knepley /*@C
257127f02ce8SMatthew G. Knepley   PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field
257227f02ce8SMatthew G. Knepley 
257327f02ce8SMatthew G. Knepley   Not collective
257427f02ce8SMatthew G. Knepley 
257527f02ce8SMatthew G. Knepley   Input Parameters:
25766528b96dSMatthew G. Knepley + ds - The PetscDS
257727f02ce8SMatthew G. Knepley . f  - The test field number
257827f02ce8SMatthew G. Knepley . g  - The field number
257927f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term
258027f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
258127f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
258227f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
258327f02ce8SMatthew G. Knepley 
258427f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
258527f02ce8SMatthew G. Knepley 
258627f02ce8SMatthew 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
258727f02ce8SMatthew G. Knepley 
258827f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
258927f02ce8SMatthew G. Knepley 
259027f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
259127f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
259227f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
259327f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
259427f02ce8SMatthew G. Knepley 
259527f02ce8SMatthew G. Knepley + dim - the spatial dimension
259627f02ce8SMatthew G. Knepley . Nf - the number of fields
259727f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
259827f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
259927f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
260027f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
260127f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
260227f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
260327f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
260427f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
260527f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
260627f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
260727f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
260827f02ce8SMatthew G. Knepley . t - current time
260927f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
261027f02ce8SMatthew G. Knepley . x - coordinates of the current point
261127f02ce8SMatthew G. Knepley . n - normal at the current point
261227f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
261327f02ce8SMatthew G. Knepley . constants - constant parameters
261427f02ce8SMatthew G. Knepley - g0 - output values at the current point
261527f02ce8SMatthew G. Knepley 
261627f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
261727f02ce8SMatthew G. Knepley 
261827f02ce8SMatthew G. Knepley   Level: intermediate
261927f02ce8SMatthew G. Knepley 
262027f02ce8SMatthew G. Knepley .seealso: PetscDSGetBdJacobianPreconditioner()
262127f02ce8SMatthew G. Knepley @*/
26226528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g,
262327f02ce8SMatthew G. Knepley                                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
262427f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
262527f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
262627f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
262727f02ce8SMatthew G. Knepley                                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
262827f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
262927f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
263027f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
263127f02ce8SMatthew G. Knepley                                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
263227f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
263327f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
263427f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
263527f02ce8SMatthew G. Knepley                                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
263627f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
263727f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
263827f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
263927f02ce8SMatthew G. Knepley {
264027f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
264127f02ce8SMatthew G. Knepley 
264227f02ce8SMatthew G. Knepley   PetscFunctionBegin;
26436528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
264427f02ce8SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
264527f02ce8SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
264627f02ce8SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
264727f02ce8SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
264827f02ce8SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
264927f02ce8SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
265006ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr);
265127f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
265227f02ce8SMatthew G. Knepley }
265327f02ce8SMatthew G. Knepley 
26540d3e9b51SMatthew G. Knepley /*@C
2655c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2656c371a6d1SMatthew G. Knepley 
2657c371a6d1SMatthew G. Knepley   Not collective
2658c371a6d1SMatthew G. Knepley 
2659c371a6d1SMatthew G. Knepley   Input Parameters:
2660c371a6d1SMatthew G. Knepley + prob - The PetscDS
2661c371a6d1SMatthew G. Knepley - f    - The test field number
2662c371a6d1SMatthew G. Knepley 
2663d8d19677SJose E. Roman   Output Parameters:
266495cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field
266595cbbfd3SMatthew G. Knepley - exactCtx - exact solution context
2666c371a6d1SMatthew G. Knepley 
2667c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2668c371a6d1SMatthew G. Knepley 
2669c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2670c371a6d1SMatthew G. Knepley 
2671c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2672c371a6d1SMatthew G. Knepley . t - current time
2673c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2674c371a6d1SMatthew G. Knepley . Nc - the number of field components
2675c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2676c371a6d1SMatthew G. Knepley - ctx - a user context
2677c371a6d1SMatthew G. Knepley 
2678c371a6d1SMatthew G. Knepley   Level: intermediate
2679c371a6d1SMatthew G. Knepley 
2680f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolution(), PetscDSGetExactSolutionTimeDerivative()
2681c371a6d1SMatthew G. Knepley @*/
268295cbbfd3SMatthew 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)
2683c371a6d1SMatthew G. Knepley {
2684c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2685c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2686c371a6d1SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
2687c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
268895cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];}
2689c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2690c371a6d1SMatthew G. Knepley }
2691c371a6d1SMatthew G. Knepley 
2692c371a6d1SMatthew G. Knepley /*@C
2693578a5ef5SMatthew Knepley   PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field
2694c371a6d1SMatthew G. Knepley 
2695c371a6d1SMatthew G. Knepley   Not collective
2696c371a6d1SMatthew G. Knepley 
2697c371a6d1SMatthew G. Knepley   Input Parameters:
2698c371a6d1SMatthew G. Knepley + prob - The PetscDS
2699c371a6d1SMatthew G. Knepley . f    - The test field number
270095cbbfd3SMatthew G. Knepley . sol  - solution function for the test fields
270195cbbfd3SMatthew G. Knepley - ctx  - solution context or NULL
2702c371a6d1SMatthew G. Knepley 
2703c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2704c371a6d1SMatthew G. Knepley 
2705c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2706c371a6d1SMatthew G. Knepley 
2707c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2708c371a6d1SMatthew G. Knepley . t - current time
2709c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2710c371a6d1SMatthew G. Knepley . Nc - the number of field components
2711c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2712c371a6d1SMatthew G. Knepley - ctx - a user context
2713c371a6d1SMatthew G. Knepley 
2714c371a6d1SMatthew G. Knepley   Level: intermediate
2715c371a6d1SMatthew G. Knepley 
2716c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2717c371a6d1SMatthew G. Knepley @*/
271895cbbfd3SMatthew 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)
2719c371a6d1SMatthew G. Knepley {
2720c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2721c371a6d1SMatthew G. Knepley 
2722c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2723c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2724c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2725c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2726c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
272795cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;}
2728c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2729c371a6d1SMatthew G. Knepley }
2730c371a6d1SMatthew G. Knepley 
27315638fd0eSMatthew G. Knepley /*@C
2732f2cacb80SMatthew G. Knepley   PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field
2733f2cacb80SMatthew G. Knepley 
2734f2cacb80SMatthew G. Knepley   Not collective
2735f2cacb80SMatthew G. Knepley 
2736f2cacb80SMatthew G. Knepley   Input Parameters:
2737f2cacb80SMatthew G. Knepley + prob - The PetscDS
2738f2cacb80SMatthew G. Knepley - f    - The test field number
2739f2cacb80SMatthew G. Knepley 
2740d8d19677SJose E. Roman   Output Parameters:
2741f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field
2742f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context
2743f2cacb80SMatthew G. Knepley 
2744f2cacb80SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2745f2cacb80SMatthew G. Knepley 
2746f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2747f2cacb80SMatthew G. Knepley 
2748f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2749f2cacb80SMatthew G. Knepley . t - current time
2750f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2751f2cacb80SMatthew G. Knepley . Nc - the number of field components
2752f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2753f2cacb80SMatthew G. Knepley - ctx - a user context
2754f2cacb80SMatthew G. Knepley 
2755f2cacb80SMatthew G. Knepley   Level: intermediate
2756f2cacb80SMatthew G. Knepley 
2757f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolutionTimeDerivative(), PetscDSGetExactSolution()
2758f2cacb80SMatthew G. Knepley @*/
2759f2cacb80SMatthew 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)
2760f2cacb80SMatthew G. Knepley {
2761f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2762f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2763f2cacb80SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
2764f2cacb80SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol_t[f];}
2765f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx_t[f];}
2766f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2767f2cacb80SMatthew G. Knepley }
2768f2cacb80SMatthew G. Knepley 
2769f2cacb80SMatthew G. Knepley /*@C
2770f2cacb80SMatthew G. Knepley   PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field
2771f2cacb80SMatthew G. Knepley 
2772f2cacb80SMatthew G. Knepley   Not collective
2773f2cacb80SMatthew G. Knepley 
2774f2cacb80SMatthew G. Knepley   Input Parameters:
2775f2cacb80SMatthew G. Knepley + prob - The PetscDS
2776f2cacb80SMatthew G. Knepley . f    - The test field number
2777f2cacb80SMatthew G. Knepley . sol  - time derivative of the solution function for the test fields
2778f2cacb80SMatthew G. Knepley - ctx  - time derivative of the solution context or NULL
2779f2cacb80SMatthew G. Knepley 
2780f2cacb80SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2781f2cacb80SMatthew G. Knepley 
2782f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2783f2cacb80SMatthew G. Knepley 
2784f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2785f2cacb80SMatthew G. Knepley . t - current time
2786f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2787f2cacb80SMatthew G. Knepley . Nc - the number of field components
2788f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2789f2cacb80SMatthew G. Knepley - ctx - a user context
2790f2cacb80SMatthew G. Knepley 
2791f2cacb80SMatthew G. Knepley   Level: intermediate
2792f2cacb80SMatthew G. Knepley 
2793f2cacb80SMatthew G. Knepley .seealso: PetscDSGetExactSolutionTimeDerivative(), PetscDSSetExactSolution()
2794f2cacb80SMatthew G. Knepley @*/
2795f2cacb80SMatthew 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)
2796f2cacb80SMatthew G. Knepley {
2797f2cacb80SMatthew G. Knepley   PetscErrorCode ierr;
2798f2cacb80SMatthew G. Knepley 
2799f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2800f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2801f2cacb80SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2802f2cacb80SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2803f2cacb80SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol_t[f] = sol;}
2804f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx_t[f] = ctx;}
2805f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2806f2cacb80SMatthew G. Knepley }
2807f2cacb80SMatthew G. Knepley 
2808f2cacb80SMatthew G. Knepley /*@C
280997b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
281097b6e6e8SMatthew G. Knepley 
281197b6e6e8SMatthew G. Knepley   Not collective
281297b6e6e8SMatthew G. Knepley 
281397b6e6e8SMatthew G. Knepley   Input Parameter:
281497b6e6e8SMatthew G. Knepley . prob - The PetscDS object
281597b6e6e8SMatthew G. Knepley 
281697b6e6e8SMatthew G. Knepley   Output Parameters:
281797b6e6e8SMatthew G. Knepley + numConstants - The number of constants
281897b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
281997b6e6e8SMatthew G. Knepley 
282097b6e6e8SMatthew G. Knepley   Level: intermediate
282197b6e6e8SMatthew G. Knepley 
282297b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
282397b6e6e8SMatthew G. Knepley @*/
282497b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
282597b6e6e8SMatthew G. Knepley {
282697b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
282797b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
282897b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
282997b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
283097b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
283197b6e6e8SMatthew G. Knepley }
283297b6e6e8SMatthew G. Knepley 
28330d3e9b51SMatthew G. Knepley /*@C
283497b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
283597b6e6e8SMatthew G. Knepley 
283697b6e6e8SMatthew G. Knepley   Not collective
283797b6e6e8SMatthew G. Knepley 
283897b6e6e8SMatthew G. Knepley   Input Parameters:
283997b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
284097b6e6e8SMatthew G. Knepley . numConstants - The number of constants
284197b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
284297b6e6e8SMatthew G. Knepley 
284397b6e6e8SMatthew G. Knepley   Level: intermediate
284497b6e6e8SMatthew G. Knepley 
284597b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
284697b6e6e8SMatthew G. Knepley @*/
284797b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
284897b6e6e8SMatthew G. Knepley {
284997b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
285097b6e6e8SMatthew G. Knepley 
285197b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
285297b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
285397b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
285497b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
285597b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
285697b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
285797b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
285820be0f5bSMatthew G. Knepley     } else {
285920be0f5bSMatthew G. Knepley       prob->constants = NULL;
286020be0f5bSMatthew G. Knepley     }
286120be0f5bSMatthew G. Knepley   }
286220be0f5bSMatthew G. Knepley   if (prob->numConstants) {
286320be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
2864580bdb30SBarry Smith     ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr);
286597b6e6e8SMatthew G. Knepley   }
286697b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
286797b6e6e8SMatthew G. Knepley }
286897b6e6e8SMatthew G. Knepley 
28694cd1e086SMatthew G. Knepley /*@
28704cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
28714cd1e086SMatthew G. Knepley 
28724cd1e086SMatthew G. Knepley   Not collective
28734cd1e086SMatthew G. Knepley 
28744cd1e086SMatthew G. Knepley   Input Parameters:
28754cd1e086SMatthew G. Knepley + prob - The PetscDS object
28764cd1e086SMatthew G. Knepley - disc - The discretization object
28774cd1e086SMatthew G. Knepley 
28784cd1e086SMatthew G. Knepley   Output Parameter:
28794cd1e086SMatthew G. Knepley . f - The field number
28804cd1e086SMatthew G. Knepley 
28814cd1e086SMatthew G. Knepley   Level: beginner
28824cd1e086SMatthew G. Knepley 
2883f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
28844cd1e086SMatthew G. Knepley @*/
28854cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
28864cd1e086SMatthew G. Knepley {
28874cd1e086SMatthew G. Knepley   PetscInt g;
28884cd1e086SMatthew G. Knepley 
28894cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28904cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28914cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
28924cd1e086SMatthew G. Knepley   *f = -1;
28934cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
28944cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
28954cd1e086SMatthew G. Knepley   *f = g;
28964cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
28974cd1e086SMatthew G. Knepley }
28984cd1e086SMatthew G. Knepley 
28994cd1e086SMatthew G. Knepley /*@
29004cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
29014cd1e086SMatthew G. Knepley 
29024cd1e086SMatthew G. Knepley   Not collective
29034cd1e086SMatthew G. Knepley 
29044cd1e086SMatthew G. Knepley   Input Parameters:
29054cd1e086SMatthew G. Knepley + prob - The PetscDS object
29064cd1e086SMatthew G. Knepley - f - The field number
29074cd1e086SMatthew G. Knepley 
29084cd1e086SMatthew G. Knepley   Output Parameter:
29094cd1e086SMatthew G. Knepley . size - The size
29104cd1e086SMatthew G. Knepley 
29114cd1e086SMatthew G. Knepley   Level: beginner
29124cd1e086SMatthew G. Knepley 
2913f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
29144cd1e086SMatthew G. Knepley @*/
29154cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
29164cd1e086SMatthew G. Knepley {
29172166fd64SMatthew G. Knepley   PetscErrorCode ierr;
29182166fd64SMatthew G. Knepley 
29194cd1e086SMatthew G. Knepley   PetscFunctionBegin;
29204cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29214cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
29224cd1e086SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
29232166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2924d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
29254cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
29264cd1e086SMatthew G. Knepley }
29274cd1e086SMatthew G. Knepley 
2928bc4ae4beSMatthew G. Knepley /*@
2929bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2930bc4ae4beSMatthew G. Knepley 
2931bc4ae4beSMatthew G. Knepley   Not collective
2932bc4ae4beSMatthew G. Knepley 
2933bc4ae4beSMatthew G. Knepley   Input Parameters:
2934bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2935bc4ae4beSMatthew G. Knepley - f - The field number
2936bc4ae4beSMatthew G. Knepley 
2937bc4ae4beSMatthew G. Knepley   Output Parameter:
2938bc4ae4beSMatthew G. Knepley . off - The offset
2939bc4ae4beSMatthew G. Knepley 
2940bc4ae4beSMatthew G. Knepley   Level: beginner
2941bc4ae4beSMatthew G. Knepley 
2942f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2943bc4ae4beSMatthew G. Knepley @*/
29442764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
29452764a2aaSMatthew G. Knepley {
29464cd1e086SMatthew G. Knepley   PetscInt       size, g;
29472764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
29482764a2aaSMatthew G. Knepley 
29492764a2aaSMatthew G. Knepley   PetscFunctionBegin;
29502764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29512764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
29522764a2aaSMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
29532764a2aaSMatthew G. Knepley   *off = 0;
29542764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
29554cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
29564cd1e086SMatthew G. Knepley     *off += size;
29572764a2aaSMatthew G. Knepley   }
29582764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29592764a2aaSMatthew G. Knepley }
29602764a2aaSMatthew G. Knepley 
2961bc4ae4beSMatthew G. Knepley /*@
29625fedec97SMatthew G. Knepley   PetscDSGetFieldOffsetCohesive - Returns the offset of the given field in the full space basis on a cohesive cell
29635fedec97SMatthew G. Knepley 
29645fedec97SMatthew G. Knepley   Not collective
29655fedec97SMatthew G. Knepley 
29665fedec97SMatthew G. Knepley   Input Parameters:
29675fedec97SMatthew G. Knepley + prob - The PetscDS object
29685fedec97SMatthew G. Knepley - f - The field number
29695fedec97SMatthew G. Knepley 
29705fedec97SMatthew G. Knepley   Output Parameter:
29715fedec97SMatthew G. Knepley . off - The offset
29725fedec97SMatthew G. Knepley 
29735fedec97SMatthew G. Knepley   Level: beginner
29745fedec97SMatthew G. Knepley 
29755fedec97SMatthew G. Knepley .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
29765fedec97SMatthew G. Knepley @*/
29775fedec97SMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffsetCohesive(PetscDS ds, PetscInt f, PetscInt *off)
29785fedec97SMatthew G. Knepley {
29795fedec97SMatthew G. Knepley   PetscInt       size, g;
29805fedec97SMatthew G. Knepley   PetscErrorCode ierr;
29815fedec97SMatthew G. Knepley 
29825fedec97SMatthew G. Knepley   PetscFunctionBegin;
29835fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
29845fedec97SMatthew G. Knepley   PetscValidPointer(off, 3);
29855fedec97SMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
29865fedec97SMatthew G. Knepley   *off = 0;
29875fedec97SMatthew G. Knepley   for (g = 0; g < f; ++g) {
29885fedec97SMatthew G. Knepley     PetscBool cohesive;
29895fedec97SMatthew G. Knepley 
29905fedec97SMatthew G. Knepley     ierr = PetscDSGetCohesive(ds, g, &cohesive);CHKERRQ(ierr);
29915fedec97SMatthew G. Knepley     ierr = PetscDSGetFieldSize(ds, g, &size);CHKERRQ(ierr);
29925fedec97SMatthew G. Knepley     *off += cohesive ? size : size*2;
29935fedec97SMatthew G. Knepley   }
29945fedec97SMatthew G. Knepley   PetscFunctionReturn(0);
29955fedec97SMatthew G. Knepley }
29965fedec97SMatthew G. Knepley 
29975fedec97SMatthew G. Knepley /*@
299847e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2999bc4ae4beSMatthew G. Knepley 
3000bc4ae4beSMatthew G. Knepley   Not collective
3001bc4ae4beSMatthew G. Knepley 
300247e57110SSander Arens   Input Parameter:
300347e57110SSander Arens . prob - The PetscDS object
3004bc4ae4beSMatthew G. Knepley 
3005bc4ae4beSMatthew G. Knepley   Output Parameter:
300647e57110SSander Arens . dimensions - The number of dimensions
3007bc4ae4beSMatthew G. Knepley 
3008bc4ae4beSMatthew G. Knepley   Level: beginner
3009bc4ae4beSMatthew G. Knepley 
301047e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
3011bc4ae4beSMatthew G. Knepley @*/
301247e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
30132764a2aaSMatthew G. Knepley {
30142764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30152764a2aaSMatthew G. Knepley 
30162764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30172764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
301847e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
301947e57110SSander Arens   PetscValidPointer(dimensions, 2);
302047e57110SSander Arens   *dimensions = prob->Nb;
302147e57110SSander Arens   PetscFunctionReturn(0);
30226ce16762SMatthew G. Knepley }
302347e57110SSander Arens 
302447e57110SSander Arens /*@
302547e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
302647e57110SSander Arens 
302747e57110SSander Arens   Not collective
302847e57110SSander Arens 
302947e57110SSander Arens   Input Parameter:
303047e57110SSander Arens . prob - The PetscDS object
303147e57110SSander Arens 
303247e57110SSander Arens   Output Parameter:
303347e57110SSander Arens . components - The number of components
303447e57110SSander Arens 
303547e57110SSander Arens   Level: beginner
303647e57110SSander Arens 
303747e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
303847e57110SSander Arens @*/
303947e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
304047e57110SSander Arens {
304147e57110SSander Arens   PetscErrorCode ierr;
304247e57110SSander Arens 
304347e57110SSander Arens   PetscFunctionBegin;
304447e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
304547e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
304647e57110SSander Arens   PetscValidPointer(components, 2);
304747e57110SSander Arens   *components = prob->Nc;
30486ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
30496ce16762SMatthew G. Knepley }
30506ce16762SMatthew G. Knepley 
30516ce16762SMatthew G. Knepley /*@
30526ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
30536ce16762SMatthew G. Knepley 
30546ce16762SMatthew G. Knepley   Not collective
30556ce16762SMatthew G. Knepley 
30566ce16762SMatthew G. Knepley   Input Parameters:
30576ce16762SMatthew G. Knepley + prob - The PetscDS object
30586ce16762SMatthew G. Knepley - f - The field number
30596ce16762SMatthew G. Knepley 
30606ce16762SMatthew G. Knepley   Output Parameter:
30616ce16762SMatthew G. Knepley . off - The offset
30626ce16762SMatthew G. Knepley 
30636ce16762SMatthew G. Knepley   Level: beginner
30646ce16762SMatthew G. Knepley 
3065f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
30666ce16762SMatthew G. Knepley @*/
30676ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
30686ce16762SMatthew G. Knepley {
3069e1d313ffSMatthew G. Knepley   PetscErrorCode ierr;
3070e1d313ffSMatthew G. Knepley 
30716ce16762SMatthew G. Knepley   PetscFunctionBegin;
30726ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30736ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
30746ce16762SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
3075e1d313ffSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
307647e57110SSander Arens   *off = prob->off[f];
30772764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30782764a2aaSMatthew G. Knepley }
30792764a2aaSMatthew G. Knepley 
3080194d53e6SMatthew G. Knepley /*@
3081194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
3082194d53e6SMatthew G. Knepley 
3083194d53e6SMatthew G. Knepley   Not collective
3084194d53e6SMatthew G. Knepley 
3085194d53e6SMatthew G. Knepley   Input Parameter:
3086194d53e6SMatthew G. Knepley . prob - The PetscDS object
3087194d53e6SMatthew G. Knepley 
3088194d53e6SMatthew G. Knepley   Output Parameter:
3089194d53e6SMatthew G. Knepley . offsets - The offsets
3090194d53e6SMatthew G. Knepley 
3091194d53e6SMatthew G. Knepley   Level: beginner
3092194d53e6SMatthew G. Knepley 
3093f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
3094194d53e6SMatthew G. Knepley @*/
3095194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
3096194d53e6SMatthew G. Knepley {
3097e1d313ffSMatthew G. Knepley   PetscErrorCode ierr;
3098e1d313ffSMatthew G. Knepley 
3099194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3100194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3101194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
3102e1d313ffSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3103194d53e6SMatthew G. Knepley   *offsets = prob->off;
3104194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
3105194d53e6SMatthew G. Knepley }
3106194d53e6SMatthew G. Knepley 
3107194d53e6SMatthew G. Knepley /*@
3108194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
3109194d53e6SMatthew G. Knepley 
3110194d53e6SMatthew G. Knepley   Not collective
3111194d53e6SMatthew G. Knepley 
3112194d53e6SMatthew G. Knepley   Input Parameter:
3113194d53e6SMatthew G. Knepley . prob - The PetscDS object
3114194d53e6SMatthew G. Knepley 
3115194d53e6SMatthew G. Knepley   Output Parameter:
3116194d53e6SMatthew G. Knepley . offsets - The offsets
3117194d53e6SMatthew G. Knepley 
3118194d53e6SMatthew G. Knepley   Level: beginner
3119194d53e6SMatthew G. Knepley 
3120f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
3121194d53e6SMatthew G. Knepley @*/
3122194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
3123194d53e6SMatthew G. Knepley {
3124e1d313ffSMatthew G. Knepley   PetscErrorCode ierr;
3125e1d313ffSMatthew G. Knepley 
3126194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3127194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3128194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
3129e1d313ffSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3130194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
3131194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
3132194d53e6SMatthew G. Knepley }
3133194d53e6SMatthew G. Knepley 
3134*9ee2af8cSMatthew G. Knepley /*@
3135*9ee2af8cSMatthew G. Knepley   PetscDSGetComponentOffsetsCohesive - Returns the offset of each field on an evaluation point
3136*9ee2af8cSMatthew G. Knepley 
3137*9ee2af8cSMatthew G. Knepley   Not collective
3138*9ee2af8cSMatthew G. Knepley 
3139*9ee2af8cSMatthew G. Knepley   Input Parameters:
3140*9ee2af8cSMatthew G. Knepley + ds - The PetscDS object
3141*9ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
3142*9ee2af8cSMatthew G. Knepley 
3143*9ee2af8cSMatthew G. Knepley   Output Parameter:
3144*9ee2af8cSMatthew G. Knepley . offsets - The offsets
3145*9ee2af8cSMatthew G. Knepley 
3146*9ee2af8cSMatthew G. Knepley   Level: beginner
3147*9ee2af8cSMatthew G. Knepley 
3148*9ee2af8cSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
3149*9ee2af8cSMatthew G. Knepley @*/
3150*9ee2af8cSMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
3151*9ee2af8cSMatthew G. Knepley {
3152*9ee2af8cSMatthew G. Knepley   PetscErrorCode ierr;
3153*9ee2af8cSMatthew G. Knepley 
3154*9ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
3155*9ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3156*9ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
3157*9ee2af8cSMatthew G. Knepley   if (!ds->isCohesive) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
3158*9ee2af8cSMatthew G. Knepley   if ((s < 0) || (s > 2)) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %D is not in [0, 2]", s);
3159*9ee2af8cSMatthew G. Knepley   ierr = PetscDSSetUp(ds);CHKERRQ(ierr);
3160*9ee2af8cSMatthew G. Knepley   *offsets = ds->offCohesive[s];
3161*9ee2af8cSMatthew G. Knepley   PetscFunctionReturn(0);
3162*9ee2af8cSMatthew G. Knepley }
3163*9ee2af8cSMatthew G. Knepley 
3164*9ee2af8cSMatthew G. Knepley /*@
3165*9ee2af8cSMatthew G. Knepley   PetscDSGetComponentDerivativeOffsetsCohesive - Returns the offset of each field derivative on an evaluation point
3166*9ee2af8cSMatthew G. Knepley 
3167*9ee2af8cSMatthew G. Knepley   Not collective
3168*9ee2af8cSMatthew G. Knepley 
3169*9ee2af8cSMatthew G. Knepley   Input Parameters:
3170*9ee2af8cSMatthew G. Knepley + ds - The PetscDS object
3171*9ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
3172*9ee2af8cSMatthew G. Knepley 
3173*9ee2af8cSMatthew G. Knepley   Output Parameter:
3174*9ee2af8cSMatthew G. Knepley . offsets - The offsets
3175*9ee2af8cSMatthew G. Knepley 
3176*9ee2af8cSMatthew G. Knepley   Level: beginner
3177*9ee2af8cSMatthew G. Knepley 
3178*9ee2af8cSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
3179*9ee2af8cSMatthew G. Knepley @*/
3180*9ee2af8cSMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
3181*9ee2af8cSMatthew G. Knepley {
3182*9ee2af8cSMatthew G. Knepley   PetscErrorCode ierr;
3183*9ee2af8cSMatthew G. Knepley 
3184*9ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
3185*9ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3186*9ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
3187*9ee2af8cSMatthew G. Knepley   if (!ds->isCohesive) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
3188*9ee2af8cSMatthew G. Knepley   if ((s < 0) || (s > 2)) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %D is not in [0, 2]", s);
3189*9ee2af8cSMatthew G. Knepley   ierr = PetscDSSetUp(ds);CHKERRQ(ierr);
3190*9ee2af8cSMatthew G. Knepley   *offsets = ds->offDerCohesive[s];
3191*9ee2af8cSMatthew G. Knepley   PetscFunctionReturn(0);
3192*9ee2af8cSMatthew G. Knepley }
3193*9ee2af8cSMatthew G. Knepley 
319468c9edb9SMatthew G. Knepley /*@C
319568c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
319668c9edb9SMatthew G. Knepley 
319768c9edb9SMatthew G. Knepley   Not collective
319868c9edb9SMatthew G. Knepley 
319968c9edb9SMatthew G. Knepley   Input Parameter:
320068c9edb9SMatthew G. Knepley . prob - The PetscDS object
320168c9edb9SMatthew G. Knepley 
3202ef0bb6c7SMatthew G. Knepley   Output Parameter:
3203ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field
320468c9edb9SMatthew G. Knepley 
320568c9edb9SMatthew G. Knepley   Level: intermediate
320668c9edb9SMatthew G. Knepley 
3207f744cafaSSander Arens .seealso: PetscDSCreate()
320868c9edb9SMatthew G. Knepley @*/
3209ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[])
32102764a2aaSMatthew G. Knepley {
32112764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
32122764a2aaSMatthew G. Knepley 
32132764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32142764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3215ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
32162764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3217ef0bb6c7SMatthew G. Knepley   *T = prob->T;
32182764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
32192764a2aaSMatthew G. Knepley }
32202764a2aaSMatthew G. Knepley 
322168c9edb9SMatthew G. Knepley /*@C
32224d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
322368c9edb9SMatthew G. Knepley 
322468c9edb9SMatthew G. Knepley   Not collective
322568c9edb9SMatthew G. Knepley 
322668c9edb9SMatthew G. Knepley   Input Parameter:
322768c9edb9SMatthew G. Knepley . prob - The PetscDS object
322868c9edb9SMatthew G. Knepley 
3229ef0bb6c7SMatthew G. Knepley   Output Parameter:
3230a5b23f4aSJose E. Roman . Tf - The basis function and derivative tabulation on each local face at quadrature points for each and field
323168c9edb9SMatthew G. Knepley 
323268c9edb9SMatthew G. Knepley   Level: intermediate
323368c9edb9SMatthew G. Knepley 
323468c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
323568c9edb9SMatthew G. Knepley @*/
3236ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[])
32372764a2aaSMatthew G. Knepley {
32382764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
32392764a2aaSMatthew G. Knepley 
32402764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32412764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3242ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
32432764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3244ef0bb6c7SMatthew G. Knepley   *Tf = prob->Tf;
32452764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
32462764a2aaSMatthew G. Knepley }
32472764a2aaSMatthew G. Knepley 
32482764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
32492764a2aaSMatthew G. Knepley {
32502764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
32512764a2aaSMatthew G. Knepley 
32522764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32532764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
32542764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
32552764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
32562764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
32572764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
32582764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
32592764a2aaSMatthew G. Knepley }
32602764a2aaSMatthew G. Knepley 
32612764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
32622764a2aaSMatthew G. Knepley {
32632764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
32642764a2aaSMatthew G. Knepley 
32652764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32662764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
32672764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
32682764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
32692764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
32702764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
32712764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
32722764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
32732764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
32742764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
32752764a2aaSMatthew G. Knepley }
32762764a2aaSMatthew G. Knepley 
32774bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal)
32782764a2aaSMatthew G. Knepley {
32792764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
32802764a2aaSMatthew G. Knepley 
32812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32822764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
32832764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
32842764a2aaSMatthew G. Knepley   if (x)            {PetscValidPointer(x, 2);            *x            = prob->x;}
32854bee2e38SMatthew G. Knepley   if (basisReal)    {PetscValidPointer(basisReal, 3);    *basisReal    = prob->basisReal;}
32867506b574SStefano Zampini   if (basisDerReal) {PetscValidPointer(basisDerReal, 4); *basisDerReal = prob->basisDerReal;}
32877506b574SStefano Zampini   if (testReal)     {PetscValidPointer(testReal, 5);     *testReal     = prob->testReal;}
32887506b574SStefano Zampini   if (testDerReal)  {PetscValidPointer(testDerReal, 6);  *testDerReal  = prob->testDerReal;}
32892764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
32902764a2aaSMatthew G. Knepley }
32912764a2aaSMatthew G. Knepley 
329258ebd649SToby Isaac /*@C
329356cf3b9cSMatthew 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().
329458ebd649SToby Isaac 
3295783e2ec8SMatthew G. Knepley   Collective on ds
3296783e2ec8SMatthew G. Knepley 
329758ebd649SToby Isaac   Input Parameters:
329858ebd649SToby Isaac + ds       - The PetscDS object
32992d47a189SJulian Andrej . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
330058ebd649SToby Isaac . name     - The BC name
330145480ffeSMatthew G. Knepley . label    - The label defining constrained points
330245480ffeSMatthew G. Knepley . Nv       - The number of DMLabel values for constrained points
330345480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
330458ebd649SToby Isaac . field    - The field to constrain
330545480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
330658ebd649SToby Isaac . comps    - An array of constrained component numbers
330758ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3308a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
330958ebd649SToby Isaac - ctx      - An optional user context for bcFunc
331058ebd649SToby Isaac 
331145480ffeSMatthew G. Knepley   Output Parameters:
331245480ffeSMatthew G. Knepley - bd       - The boundary number
331345480ffeSMatthew G. Knepley 
331458ebd649SToby Isaac   Options Database Keys:
331558ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
331658ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
331758ebd649SToby Isaac 
331856cf3b9cSMatthew G. Knepley   Note:
331956cf3b9cSMatthew 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:
332056cf3b9cSMatthew G. Knepley 
332156cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
332256cf3b9cSMatthew G. Knepley 
332356cf3b9cSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
332456cf3b9cSMatthew G. Knepley 
332556cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
332656cf3b9cSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
332756cf3b9cSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
332856cf3b9cSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
332956cf3b9cSMatthew G. Knepley 
333056cf3b9cSMatthew G. Knepley + dim - the spatial dimension
333156cf3b9cSMatthew G. Knepley . Nf - the number of fields
333256cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
333356cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
333456cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point
333556cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
333656cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
333756cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
333856cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
333956cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
334056cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
334156cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
334256cf3b9cSMatthew G. Knepley . t - current time
334356cf3b9cSMatthew G. Knepley . x - coordinates of the current point
334456cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters
334556cf3b9cSMatthew G. Knepley . constants - constant parameters
334656cf3b9cSMatthew G. Knepley - bcval - output values at the current point
334756cf3b9cSMatthew G. Knepley 
334858ebd649SToby Isaac   Level: developer
334958ebd649SToby Isaac 
335045480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundaryByName(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual()
335158ebd649SToby Isaac @*/
335245480ffeSMatthew 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)
335358ebd649SToby Isaac {
335445480ffeSMatthew G. Knepley   DSBoundary     head = ds->boundary, b;
335545480ffeSMatthew G. Knepley   PetscInt       n    = 0;
335645480ffeSMatthew G. Knepley   const char    *lname;
335758ebd649SToby Isaac   PetscErrorCode ierr;
335858ebd649SToby Isaac 
335958ebd649SToby Isaac   PetscFunctionBegin;
336058ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3361783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
336245480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
336345480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4);
336445480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
336545480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
336645480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
3367d57bb9dbSMatthew G. Knepley   if (Nc > 0) {
3368d57bb9dbSMatthew G. Knepley     PetscInt *fcomps;
3369d57bb9dbSMatthew G. Knepley     PetscInt  c;
3370d57bb9dbSMatthew G. Knepley 
3371d57bb9dbSMatthew G. Knepley     ierr = PetscDSGetComponents(ds, &fcomps);CHKERRQ(ierr);
3372d57bb9dbSMatthew G. Knepley     if (Nc > fcomps[field]) SETERRQ3(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_OUTOFRANGE, "Number of constrained components %D > %D components for field %D", Nc, fcomps[field], field);
3373d57bb9dbSMatthew G. Knepley     for (c = 0; c < Nc; ++c) {
3374d57bb9dbSMatthew G. Knepley       if (comps[c] < 0 || comps[c] >= fcomps[field]) SETERRQ4(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);
3375d57bb9dbSMatthew G. Knepley     }
3376d57bb9dbSMatthew G. Knepley   }
337758ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
337858ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
337945480ffeSMatthew G. Knepley   ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr);
338045480ffeSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr);
338145480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr);
338245480ffeSMatthew G. Knepley   if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);}
338345480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr);
338445480ffeSMatthew G. Knepley   if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);}
338545480ffeSMatthew G. Knepley   ierr = PetscObjectGetName((PetscObject) label, &lname);CHKERRQ(ierr);
338645480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr);
3387f971fd6bSMatthew G. Knepley   b->type   = type;
338845480ffeSMatthew G. Knepley   b->label  = label;
338945480ffeSMatthew G. Knepley   b->Nv     = Nv;
339058ebd649SToby Isaac   b->field  = field;
339145480ffeSMatthew G. Knepley   b->Nc     = Nc;
339258ebd649SToby Isaac   b->func   = bcFunc;
339356cf3b9cSMatthew G. Knepley   b->func_t = bcFunc_t;
339458ebd649SToby Isaac   b->ctx    = ctx;
339545480ffeSMatthew G. Knepley   b->next   = NULL;
339645480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
339745480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
339845480ffeSMatthew G. Knepley   while (head) {
339945480ffeSMatthew G. Knepley     if (!head->next) {
340045480ffeSMatthew G. Knepley       head->next = b;
340145480ffeSMatthew G. Knepley       head       = b;
340245480ffeSMatthew G. Knepley     }
340345480ffeSMatthew G. Knepley     head = head->next;
340445480ffeSMatthew G. Knepley     ++n;
340545480ffeSMatthew G. Knepley   }
3406064a246eSJacob Faibussowitsch   if (bd) {PetscValidIntPointer(bd, 13); *bd = n;}
340745480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
340845480ffeSMatthew G. Knepley }
340945480ffeSMatthew G. Knepley 
341045480ffeSMatthew G. Knepley /*@C
341145480ffeSMatthew 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().
341245480ffeSMatthew G. Knepley 
341345480ffeSMatthew G. Knepley   Collective on ds
341445480ffeSMatthew G. Knepley 
341545480ffeSMatthew G. Knepley   Input Parameters:
341645480ffeSMatthew G. Knepley + ds       - The PetscDS object
341745480ffeSMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
341845480ffeSMatthew G. Knepley . name     - The BC name
341945480ffeSMatthew G. Knepley . lname    - The naem of the label defining constrained points
342045480ffeSMatthew G. Knepley . Nv       - The number of DMLabel values for constrained points
342145480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
342245480ffeSMatthew G. Knepley . field    - The field to constrain
342345480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
342445480ffeSMatthew G. Knepley . comps    - An array of constrained component numbers
342545480ffeSMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3426a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
342745480ffeSMatthew G. Knepley - ctx      - An optional user context for bcFunc
342845480ffeSMatthew G. Knepley 
342945480ffeSMatthew G. Knepley   Output Parameters:
343045480ffeSMatthew G. Knepley - bd       - The boundary number
343145480ffeSMatthew G. Knepley 
343245480ffeSMatthew G. Knepley   Options Database Keys:
343345480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids
343445480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components
343545480ffeSMatthew G. Knepley 
343645480ffeSMatthew G. Knepley   Note:
343745480ffeSMatthew G. Knepley   This function should only be used with DMForest currently, since labels cannot be defined before the underlygin Plex is built.
343845480ffeSMatthew G. Knepley 
343945480ffeSMatthew 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:
344045480ffeSMatthew G. Knepley 
344145480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
344245480ffeSMatthew G. Knepley 
344345480ffeSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
344445480ffeSMatthew G. Knepley 
344545480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
344645480ffeSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
344745480ffeSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
344845480ffeSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
344945480ffeSMatthew G. Knepley 
345045480ffeSMatthew G. Knepley + dim - the spatial dimension
345145480ffeSMatthew G. Knepley . Nf - the number of fields
345245480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
345345480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
345445480ffeSMatthew G. Knepley . u - each field evaluated at the current point
345545480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
345645480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
345745480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
345845480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
345945480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
346045480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
346145480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
346245480ffeSMatthew G. Knepley . t - current time
346345480ffeSMatthew G. Knepley . x - coordinates of the current point
346445480ffeSMatthew G. Knepley . numConstants - number of constant parameters
346545480ffeSMatthew G. Knepley . constants - constant parameters
346645480ffeSMatthew G. Knepley - bcval - output values at the current point
346745480ffeSMatthew G. Knepley 
346845480ffeSMatthew G. Knepley   Level: developer
346945480ffeSMatthew G. Knepley 
347045480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual()
347145480ffeSMatthew G. Knepley @*/
347245480ffeSMatthew 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)
347345480ffeSMatthew G. Knepley {
347445480ffeSMatthew G. Knepley   DSBoundary     head = ds->boundary, b;
347545480ffeSMatthew G. Knepley   PetscInt       n    = 0;
347645480ffeSMatthew G. Knepley   PetscErrorCode ierr;
347745480ffeSMatthew G. Knepley 
347845480ffeSMatthew G. Knepley   PetscFunctionBegin;
347945480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
348045480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
348145480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
348245480ffeSMatthew G. Knepley   PetscValidCharPointer(lname, 4);
348345480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
348445480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
348545480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
348645480ffeSMatthew G. Knepley   ierr = PetscNew(&b);CHKERRQ(ierr);
348745480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
348845480ffeSMatthew G. Knepley   ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr);
348945480ffeSMatthew G. Knepley   ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr);
349045480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr);
349145480ffeSMatthew G. Knepley   if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);}
349245480ffeSMatthew G. Knepley   ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr);
349345480ffeSMatthew G. Knepley   if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);}
349445480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr);
349545480ffeSMatthew G. Knepley   b->type   = type;
349645480ffeSMatthew G. Knepley   b->label  = NULL;
349745480ffeSMatthew G. Knepley   b->Nv     = Nv;
349845480ffeSMatthew G. Knepley   b->field  = field;
349945480ffeSMatthew G. Knepley   b->Nc     = Nc;
350045480ffeSMatthew G. Knepley   b->func   = bcFunc;
350145480ffeSMatthew G. Knepley   b->func_t = bcFunc_t;
350245480ffeSMatthew G. Knepley   b->ctx    = ctx;
350345480ffeSMatthew G. Knepley   b->next   = NULL;
350445480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
350545480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
350645480ffeSMatthew G. Knepley   while (head) {
350745480ffeSMatthew G. Knepley     if (!head->next) {
350845480ffeSMatthew G. Knepley       head->next = b;
350945480ffeSMatthew G. Knepley       head       = b;
351045480ffeSMatthew G. Knepley     }
351145480ffeSMatthew G. Knepley     head = head->next;
351245480ffeSMatthew G. Knepley     ++n;
351345480ffeSMatthew G. Knepley   }
3514064a246eSJacob Faibussowitsch   if (bd) {PetscValidIntPointer(bd, 13); *bd = n;}
351558ebd649SToby Isaac   PetscFunctionReturn(0);
351658ebd649SToby Isaac }
351758ebd649SToby Isaac 
3518b67eacb3SMatthew G. Knepley /*@C
351956cf3b9cSMatthew 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().
3520b67eacb3SMatthew G. Knepley 
3521b67eacb3SMatthew G. Knepley   Input Parameters:
3522b67eacb3SMatthew G. Knepley + ds       - The PetscDS object
3523b67eacb3SMatthew G. Knepley . bd       - The boundary condition number
3524b67eacb3SMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
3525b67eacb3SMatthew G. Knepley . name     - The BC name
352645480ffeSMatthew G. Knepley . label    - The label defining constrained points
352745480ffeSMatthew G. Knepley . Nv       - The number of DMLabel ids for constrained points
352845480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
3529b67eacb3SMatthew G. Knepley . field    - The field to constrain
353045480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
3531b67eacb3SMatthew G. Knepley . comps    - An array of constrained component numbers
3532b67eacb3SMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3533a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
3534b67eacb3SMatthew G. Knepley - ctx      - An optional user context for bcFunc
3535b67eacb3SMatthew G. Knepley 
353656cf3b9cSMatthew G. Knepley   Note:
353756cf3b9cSMatthew 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.
35389a6efb6aSMatthew G. Knepley 
3539b67eacb3SMatthew G. Knepley   Level: developer
3540b67eacb3SMatthew G. Knepley 
35419a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary()
3542b67eacb3SMatthew G. Knepley @*/
354345480ffeSMatthew 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)
3544b67eacb3SMatthew G. Knepley {
3545b67eacb3SMatthew G. Knepley   DSBoundary     b = ds->boundary;
3546b67eacb3SMatthew G. Knepley   PetscInt       n = 0;
3547b67eacb3SMatthew G. Knepley   PetscErrorCode ierr;
3548b67eacb3SMatthew G. Knepley 
3549b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
3550b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3551b67eacb3SMatthew G. Knepley   while (b) {
3552b67eacb3SMatthew G. Knepley     if (n == bd) break;
3553b67eacb3SMatthew G. Knepley     b = b->next;
3554b67eacb3SMatthew G. Knepley     ++n;
3555b67eacb3SMatthew G. Knepley   }
3556b67eacb3SMatthew G. Knepley   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
3557b67eacb3SMatthew G. Knepley   if (name) {
3558b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
3559b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
3560b67eacb3SMatthew G. Knepley   }
3561b67eacb3SMatthew G. Knepley   b->type = type;
356245480ffeSMatthew G. Knepley   if (label) {
356345480ffeSMatthew G. Knepley     const char *name;
356445480ffeSMatthew G. Knepley 
356545480ffeSMatthew G. Knepley     b->label = label;
356645480ffeSMatthew G. Knepley     ierr = PetscFree(b->lname);CHKERRQ(ierr);
356745480ffeSMatthew G. Knepley     ierr = PetscObjectGetName((PetscObject) label, &name);CHKERRQ(ierr);
356845480ffeSMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->lname);CHKERRQ(ierr);
356945480ffeSMatthew G. Knepley   }
357045480ffeSMatthew G. Knepley   if (Nv >= 0) {
357145480ffeSMatthew G. Knepley     b->Nv = Nv;
357245480ffeSMatthew G. Knepley     ierr = PetscFree(b->values);CHKERRQ(ierr);
357345480ffeSMatthew G. Knepley     ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr);
357445480ffeSMatthew G. Knepley     if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);}
357545480ffeSMatthew G. Knepley   }
357645480ffeSMatthew G. Knepley   if (field >= 0) b->field = field;
357745480ffeSMatthew G. Knepley   if (Nc >= 0) {
357845480ffeSMatthew G. Knepley     b->Nc = Nc;
357945480ffeSMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
358045480ffeSMatthew G. Knepley     ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr);
358145480ffeSMatthew G. Knepley     if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);}
358245480ffeSMatthew G. Knepley   }
358345480ffeSMatthew G. Knepley   if (bcFunc)   b->func   = bcFunc;
358445480ffeSMatthew G. Knepley   if (bcFunc_t) b->func_t = bcFunc_t;
358545480ffeSMatthew G. Knepley   if (ctx)      b->ctx    = ctx;
3586b67eacb3SMatthew G. Knepley   PetscFunctionReturn(0);
3587b67eacb3SMatthew G. Knepley }
3588b67eacb3SMatthew G. Knepley 
358958ebd649SToby Isaac /*@
359058ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
359158ebd649SToby Isaac 
359258ebd649SToby Isaac   Input Parameters:
359358ebd649SToby Isaac . ds - The PetscDS object
359458ebd649SToby Isaac 
359558ebd649SToby Isaac   Output Parameters:
359658ebd649SToby Isaac . numBd - The number of BC
359758ebd649SToby Isaac 
359858ebd649SToby Isaac   Level: intermediate
359958ebd649SToby Isaac 
360058ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
360158ebd649SToby Isaac @*/
360258ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
360358ebd649SToby Isaac {
360458ebd649SToby Isaac   DSBoundary b = ds->boundary;
360558ebd649SToby Isaac 
360658ebd649SToby Isaac   PetscFunctionBegin;
360758ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
360858ebd649SToby Isaac   PetscValidPointer(numBd, 2);
360958ebd649SToby Isaac   *numBd = 0;
361058ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
361158ebd649SToby Isaac   PetscFunctionReturn(0);
361258ebd649SToby Isaac }
361358ebd649SToby Isaac 
361458ebd649SToby Isaac /*@C
36159a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
361658ebd649SToby Isaac 
361758ebd649SToby Isaac   Input Parameters:
361858ebd649SToby Isaac + ds          - The PetscDS object
361958ebd649SToby Isaac - bd          - The BC number
362058ebd649SToby Isaac 
362158ebd649SToby Isaac   Output Parameters:
362245480ffeSMatthew G. Knepley + wf       - The PetscWeakForm holding the pointwise functions
362345480ffeSMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
362458ebd649SToby Isaac . name     - The BC name
362545480ffeSMatthew G. Knepley . label    - The label defining constrained points
362645480ffeSMatthew G. Knepley . Nv       - The number of DMLabel ids for constrained points
362745480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
362858ebd649SToby Isaac . field    - The field to constrain
362945480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
363058ebd649SToby Isaac . comps    - An array of constrained component numbers
363158ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3632a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values
363358ebd649SToby Isaac - ctx      - An optional user context for bcFunc
363458ebd649SToby Isaac 
363558ebd649SToby Isaac   Options Database Keys:
363658ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
363758ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
363858ebd649SToby Isaac 
363958ebd649SToby Isaac   Level: developer
364058ebd649SToby Isaac 
364158ebd649SToby Isaac .seealso: PetscDSAddBoundary()
364258ebd649SToby Isaac @*/
364345480ffeSMatthew 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)
364458ebd649SToby Isaac {
364558ebd649SToby Isaac   DSBoundary b = ds->boundary;
364658ebd649SToby Isaac   PetscInt   n = 0;
364758ebd649SToby Isaac 
364858ebd649SToby Isaac   PetscFunctionBegin;
364958ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
365058ebd649SToby Isaac   while (b) {
365158ebd649SToby Isaac     if (n == bd) break;
365258ebd649SToby Isaac     b = b->next;
365358ebd649SToby Isaac     ++n;
365458ebd649SToby Isaac   }
365558ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
365645480ffeSMatthew G. Knepley   if (wf) {
365745480ffeSMatthew G. Knepley     PetscValidPointer(wf, 3);
365845480ffeSMatthew G. Knepley     *wf = b->wf;
365945480ffeSMatthew G. Knepley   }
3660f971fd6bSMatthew G. Knepley   if (type) {
366145480ffeSMatthew G. Knepley     PetscValidPointer(type, 4);
3662f971fd6bSMatthew G. Knepley     *type = b->type;
366358ebd649SToby Isaac   }
366458ebd649SToby Isaac   if (name) {
366545480ffeSMatthew G. Knepley     PetscValidPointer(name, 5);
366658ebd649SToby Isaac     *name = b->name;
366758ebd649SToby Isaac   }
366845480ffeSMatthew G. Knepley   if (label) {
366945480ffeSMatthew G. Knepley     PetscValidPointer(label, 6);
367045480ffeSMatthew G. Knepley     *label = b->label;
367145480ffeSMatthew G. Knepley   }
367245480ffeSMatthew G. Knepley   if (Nv) {
367345480ffeSMatthew G. Knepley     PetscValidIntPointer(Nv, 7);
367445480ffeSMatthew G. Knepley     *Nv = b->Nv;
367545480ffeSMatthew G. Knepley   }
367645480ffeSMatthew G. Knepley   if (values) {
367745480ffeSMatthew G. Knepley     PetscValidPointer(values, 8);
367845480ffeSMatthew G. Knepley     *values = b->values;
367958ebd649SToby Isaac   }
368058ebd649SToby Isaac   if (field) {
368145480ffeSMatthew G. Knepley     PetscValidIntPointer(field, 9);
368258ebd649SToby Isaac     *field = b->field;
368358ebd649SToby Isaac   }
368445480ffeSMatthew G. Knepley   if (Nc) {
368545480ffeSMatthew G. Knepley     PetscValidIntPointer(Nc, 10);
368645480ffeSMatthew G. Knepley     *Nc = b->Nc;
368758ebd649SToby Isaac   }
368858ebd649SToby Isaac   if (comps) {
368945480ffeSMatthew G. Knepley     PetscValidPointer(comps, 11);
369058ebd649SToby Isaac     *comps = b->comps;
369158ebd649SToby Isaac   }
369258ebd649SToby Isaac   if (func) {
369345480ffeSMatthew G. Knepley     PetscValidPointer(func, 12);
369458ebd649SToby Isaac     *func = b->func;
369558ebd649SToby Isaac   }
369656cf3b9cSMatthew G. Knepley   if (func_t) {
369745480ffeSMatthew G. Knepley     PetscValidPointer(func_t, 13);
369856cf3b9cSMatthew G. Knepley     *func_t = b->func_t;
369956cf3b9cSMatthew G. Knepley   }
370058ebd649SToby Isaac   if (ctx) {
370145480ffeSMatthew G. Knepley     PetscValidPointer(ctx, 14);
370258ebd649SToby Isaac     *ctx = b->ctx;
370358ebd649SToby Isaac   }
370458ebd649SToby Isaac   PetscFunctionReturn(0);
370558ebd649SToby Isaac }
370658ebd649SToby Isaac 
370745480ffeSMatthew G. Knepley static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew)
370845480ffeSMatthew G. Knepley {
370945480ffeSMatthew G. Knepley   PetscErrorCode ierr;
371045480ffeSMatthew G. Knepley 
371145480ffeSMatthew G. Knepley   PetscFunctionBegin;
371245480ffeSMatthew G. Knepley   ierr = PetscNew(bNew);CHKERRQ(ierr);
371345480ffeSMatthew G. Knepley   ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf);CHKERRQ(ierr);
371445480ffeSMatthew G. Knepley   ierr = PetscWeakFormCopy(b->wf, (*bNew)->wf);CHKERRQ(ierr);
371545480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(b->name,(char **) &((*bNew)->name));CHKERRQ(ierr);
371645480ffeSMatthew G. Knepley   ierr = PetscStrallocpy(b->lname,(char **) &((*bNew)->lname));CHKERRQ(ierr);
371745480ffeSMatthew G. Knepley   (*bNew)->type   = b->type;
371845480ffeSMatthew G. Knepley   (*bNew)->label  = b->label;
371945480ffeSMatthew G. Knepley   (*bNew)->Nv     = b->Nv;
372045480ffeSMatthew G. Knepley   ierr = PetscMalloc1(b->Nv, &(*bNew)->values);CHKERRQ(ierr);
372145480ffeSMatthew G. Knepley   ierr = PetscArraycpy((*bNew)->values, b->values, b->Nv);CHKERRQ(ierr);
372245480ffeSMatthew G. Knepley   (*bNew)->field  = b->field;
372345480ffeSMatthew G. Knepley   (*bNew)->Nc     = b->Nc;
372445480ffeSMatthew G. Knepley   ierr = PetscMalloc1(b->Nc, &(*bNew)->comps);CHKERRQ(ierr);
372545480ffeSMatthew G. Knepley   ierr = PetscArraycpy((*bNew)->comps, b->comps, b->Nc);CHKERRQ(ierr);
372645480ffeSMatthew G. Knepley   (*bNew)->func   = b->func;
372745480ffeSMatthew G. Knepley   (*bNew)->func_t = b->func_t;
372845480ffeSMatthew G. Knepley   (*bNew)->ctx    = b->ctx;
372945480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
373045480ffeSMatthew G. Knepley }
373145480ffeSMatthew G. Knepley 
37329252d075SMatthew G. Knepley /*@
37339252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
37349252d075SMatthew G. Knepley 
37359252d075SMatthew G. Knepley   Not collective
37369252d075SMatthew G. Knepley 
373736951cb5SMatthew G. Knepley   Input Parameters:
373836951cb5SMatthew G. Knepley + ds        - The source PetscDS object
373936951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields
374036951cb5SMatthew G. Knepley - fields    - The selected fields, or NULL for all fields
37419252d075SMatthew G. Knepley 
37429252d075SMatthew G. Knepley   Output Parameter:
374336951cb5SMatthew G. Knepley . newds     - The target PetscDS, now with a copy of the boundary conditions
37449252d075SMatthew G. Knepley 
37459252d075SMatthew G. Knepley   Level: intermediate
37469252d075SMatthew G. Knepley 
37479252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
37489252d075SMatthew G. Knepley @*/
374936951cb5SMatthew G. Knepley PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds)
3750dff059c6SToby Isaac {
375145480ffeSMatthew G. Knepley   DSBoundary     b, *lastnext;
3752dff059c6SToby Isaac   PetscErrorCode ierr;
3753dff059c6SToby Isaac 
3754dff059c6SToby Isaac   PetscFunctionBegin;
375536951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(ds,    PETSCDS_CLASSID, 1);
375636951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4);
375736951cb5SMatthew G. Knepley   if (ds == newds) PetscFunctionReturn(0);
375845480ffeSMatthew G. Knepley   ierr = PetscDSDestroyBoundary(newds);CHKERRQ(ierr);
375936951cb5SMatthew G. Knepley   lastnext = &(newds->boundary);
376036951cb5SMatthew G. Knepley   for (b = ds->boundary; b; b = b->next) {
3761dff059c6SToby Isaac     DSBoundary bNew;
376236951cb5SMatthew G. Knepley     PetscInt   fieldNew = -1;
3763dff059c6SToby Isaac 
376436951cb5SMatthew G. Knepley     if (numFields > 0 && fields) {
376536951cb5SMatthew G. Knepley       PetscInt f;
376636951cb5SMatthew G. Knepley 
376736951cb5SMatthew G. Knepley       for (f = 0; f < numFields; ++f) if (b->field == fields[f]) break;
376836951cb5SMatthew G. Knepley       if (f == numFields) continue;
376936951cb5SMatthew G. Knepley       fieldNew = f;
377036951cb5SMatthew G. Knepley     }
377145480ffeSMatthew G. Knepley     ierr = DSBoundaryDuplicate_Internal(b, &bNew);CHKERRQ(ierr);
377236951cb5SMatthew G. Knepley     bNew->field = fieldNew < 0 ? b->field : fieldNew;
3773dff059c6SToby Isaac     *lastnext = bNew;
3774dff059c6SToby Isaac     lastnext  = &(bNew->next);
3775dff059c6SToby Isaac   }
3776dff059c6SToby Isaac   PetscFunctionReturn(0);
3777dff059c6SToby Isaac }
3778dff059c6SToby Isaac 
37796c1eb96dSMatthew G. Knepley /*@
378045480ffeSMatthew G. Knepley   PetscDSDestroyBoundary - Remove all DMBoundary objects from the PetscDS
378145480ffeSMatthew G. Knepley 
378245480ffeSMatthew G. Knepley   Not collective
378345480ffeSMatthew G. Knepley 
378445480ffeSMatthew G. Knepley   Input Parameter:
378545480ffeSMatthew G. Knepley . ds - The PetscDS object
378645480ffeSMatthew G. Knepley 
378745480ffeSMatthew G. Knepley   Level: intermediate
378845480ffeSMatthew G. Knepley 
378945480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations()
379045480ffeSMatthew G. Knepley @*/
379145480ffeSMatthew G. Knepley PetscErrorCode PetscDSDestroyBoundary(PetscDS ds)
379245480ffeSMatthew G. Knepley {
379345480ffeSMatthew G. Knepley   DSBoundary     next = ds->boundary;
379445480ffeSMatthew G. Knepley   PetscErrorCode ierr;
379545480ffeSMatthew G. Knepley 
379645480ffeSMatthew G. Knepley   PetscFunctionBegin;
379745480ffeSMatthew G. Knepley   while (next) {
379845480ffeSMatthew G. Knepley     DSBoundary b = next;
379945480ffeSMatthew G. Knepley 
380045480ffeSMatthew G. Knepley     next = b->next;
380145480ffeSMatthew G. Knepley     ierr = PetscWeakFormDestroy(&b->wf);CHKERRQ(ierr);
380245480ffeSMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
380345480ffeSMatthew G. Knepley     ierr = PetscFree(b->lname);CHKERRQ(ierr);
380445480ffeSMatthew G. Knepley     ierr = PetscFree(b->values);CHKERRQ(ierr);
380545480ffeSMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
380645480ffeSMatthew G. Knepley     ierr = PetscFree(b);CHKERRQ(ierr);
380745480ffeSMatthew G. Knepley   }
380845480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
380945480ffeSMatthew G. Knepley }
381045480ffeSMatthew G. Knepley 
381145480ffeSMatthew G. Knepley /*@
38126c1eb96dSMatthew G. Knepley   PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout
38136c1eb96dSMatthew G. Knepley 
38146c1eb96dSMatthew G. Knepley   Not collective
38156c1eb96dSMatthew G. Knepley 
3816d8d19677SJose E. Roman   Input Parameters:
38176c1eb96dSMatthew G. Knepley + prob - The PetscDS object
38186c1eb96dSMatthew G. Knepley . numFields - Number of new fields
38196c1eb96dSMatthew G. Knepley - fields - Old field number for each new field
38206c1eb96dSMatthew G. Knepley 
38216c1eb96dSMatthew G. Knepley   Output Parameter:
38226c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy
38236c1eb96dSMatthew G. Knepley 
38246c1eb96dSMatthew G. Knepley   Level: intermediate
38256c1eb96dSMatthew G. Knepley 
38266c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectEquations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
38276c1eb96dSMatthew G. Knepley @*/
38286c1eb96dSMatthew G. Knepley PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
38296c1eb96dSMatthew G. Knepley {
38306c1eb96dSMatthew G. Knepley   PetscInt       Nf, Nfn, fn;
38316c1eb96dSMatthew G. Knepley   PetscErrorCode ierr;
38326c1eb96dSMatthew G. Knepley 
38336c1eb96dSMatthew G. Knepley   PetscFunctionBegin;
38346c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
38356c1eb96dSMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
38366c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
38376c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
38386c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
383945480ffeSMatthew G. Knepley   numFields = numFields < 0 ? Nf : numFields;
38406c1eb96dSMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
38416c1eb96dSMatthew G. Knepley     const PetscInt f = fields ? fields[fn] : fn;
38426c1eb96dSMatthew G. Knepley     PetscObject    disc;
38436c1eb96dSMatthew G. Knepley 
38446c1eb96dSMatthew G. Knepley     if (f >= Nf) continue;
38456c1eb96dSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &disc);CHKERRQ(ierr);
38466c1eb96dSMatthew G. Knepley     ierr = PetscDSSetDiscretization(newprob, fn, disc);CHKERRQ(ierr);
38476c1eb96dSMatthew G. Knepley   }
38486c1eb96dSMatthew G. Knepley   PetscFunctionReturn(0);
38496c1eb96dSMatthew G. Knepley }
38506c1eb96dSMatthew G. Knepley 
38516c1eb96dSMatthew G. Knepley /*@
38529252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
38539252d075SMatthew G. Knepley 
38549252d075SMatthew G. Knepley   Not collective
38559252d075SMatthew G. Knepley 
3856d8d19677SJose E. Roman   Input Parameters:
38579252d075SMatthew G. Knepley + prob - The PetscDS object
38589252d075SMatthew G. Knepley . numFields - Number of new fields
38599252d075SMatthew G. Knepley - fields - Old field number for each new field
38609252d075SMatthew G. Knepley 
38619252d075SMatthew G. Knepley   Output Parameter:
38629252d075SMatthew G. Knepley . newprob - The PetscDS copy
38639252d075SMatthew G. Knepley 
38649252d075SMatthew G. Knepley   Level: intermediate
38659252d075SMatthew G. Knepley 
38666c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectDiscretizations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
38679252d075SMatthew G. Knepley @*/
38689252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
38699252d075SMatthew G. Knepley {
38709252d075SMatthew G. Knepley   PetscInt       Nf, Nfn, fn, gn;
38719252d075SMatthew G. Knepley   PetscErrorCode ierr;
38729252d075SMatthew G. Knepley 
38739252d075SMatthew G. Knepley   PetscFunctionBegin;
38749252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
38759252d075SMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
38769252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
38779252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
38789252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
38799252d075SMatthew G. Knepley   if (numFields > Nfn) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields %D to transfer must not be greater then the total number of fields %D", numFields, Nfn);
38809252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
38819252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
38829252d075SMatthew G. Knepley     PetscPointFunc   obj;
38839252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
38849252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
38859252d075SMatthew G. Knepley     PetscRiemannFunc r;
38869252d075SMatthew G. Knepley 
3887c52f1e13SMatthew G. Knepley     if (f >= Nf) continue;
38889252d075SMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
38899252d075SMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
38909252d075SMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
38919252d075SMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
38929252d075SMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr);
38939252d075SMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr);
38949252d075SMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr);
38959252d075SMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr);
38969252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
38979252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
38989252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
38999252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
39009252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
39019252d075SMatthew G. Knepley 
3902c52f1e13SMatthew G. Knepley       if (g >= Nf) continue;
39039252d075SMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
39049252d075SMatthew G. Knepley       ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr);
39059252d075SMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
39069252d075SMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr);
39076c1eb96dSMatthew G. Knepley       ierr = PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr);
39089252d075SMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
39099252d075SMatthew G. Knepley     }
39109252d075SMatthew G. Knepley   }
39119252d075SMatthew G. Knepley   PetscFunctionReturn(0);
39129252d075SMatthew G. Knepley }
39139252d075SMatthew G. Knepley 
3914da51fcedSMatthew G. Knepley /*@
3915da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
3916da51fcedSMatthew G. Knepley 
3917da51fcedSMatthew G. Knepley   Not collective
3918da51fcedSMatthew G. Knepley 
3919da51fcedSMatthew G. Knepley   Input Parameter:
3920da51fcedSMatthew G. Knepley . prob - The PetscDS object
3921da51fcedSMatthew G. Knepley 
3922da51fcedSMatthew G. Knepley   Output Parameter:
3923da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
3924da51fcedSMatthew G. Knepley 
3925da51fcedSMatthew G. Knepley   Level: intermediate
3926da51fcedSMatthew G. Knepley 
39279252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
3928da51fcedSMatthew G. Knepley @*/
3929da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
3930da51fcedSMatthew G. Knepley {
3931b8025e53SMatthew G. Knepley   PetscWeakForm  wf, newwf;
39329252d075SMatthew G. Knepley   PetscInt       Nf, Ng;
3933da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
3934da51fcedSMatthew G. Knepley 
3935da51fcedSMatthew G. Knepley   PetscFunctionBegin;
3936da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3937da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
3938da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3939da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
394013903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
3941b8025e53SMatthew G. Knepley   ierr = PetscDSGetWeakForm(prob, &wf);CHKERRQ(ierr);
3942b8025e53SMatthew G. Knepley   ierr = PetscDSGetWeakForm(newprob, &newwf);CHKERRQ(ierr);
3943b8025e53SMatthew G. Knepley   ierr = PetscWeakFormCopy(wf, newwf);CHKERRQ(ierr);
39449252d075SMatthew G. Knepley   PetscFunctionReturn(0);
39459252d075SMatthew G. Knepley }
394645480ffeSMatthew G. Knepley 
39479252d075SMatthew G. Knepley /*@
39489252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
3949da51fcedSMatthew G. Knepley 
39509252d075SMatthew G. Knepley   Not collective
39519252d075SMatthew G. Knepley 
39529252d075SMatthew G. Knepley   Input Parameter:
39539252d075SMatthew G. Knepley . prob - The PetscDS object
39549252d075SMatthew G. Knepley 
39559252d075SMatthew G. Knepley   Output Parameter:
39569252d075SMatthew G. Knepley . newprob - The PetscDS copy
39579252d075SMatthew G. Knepley 
39589252d075SMatthew G. Knepley   Level: intermediate
39599252d075SMatthew G. Knepley 
39609252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
39619252d075SMatthew G. Knepley @*/
39629252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
39639252d075SMatthew G. Knepley {
39649252d075SMatthew G. Knepley   PetscInt           Nc;
39659252d075SMatthew G. Knepley   const PetscScalar *constants;
39669252d075SMatthew G. Knepley   PetscErrorCode     ierr;
39679252d075SMatthew G. Knepley 
39689252d075SMatthew G. Knepley   PetscFunctionBegin;
39699252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
39709252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
39719252d075SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr);
39729252d075SMatthew G. Knepley   ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr);
3973da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
3974da51fcedSMatthew G. Knepley }
3975da51fcedSMatthew G. Knepley 
397645480ffeSMatthew G. Knepley /*@
397745480ffeSMatthew G. Knepley   PetscDSCopyExactSolutions - Copy all exact solutions to the new problem
397845480ffeSMatthew G. Knepley 
397945480ffeSMatthew G. Knepley   Not collective
398045480ffeSMatthew G. Knepley 
398145480ffeSMatthew G. Knepley   Input Parameter:
398245480ffeSMatthew G. Knepley . ds - The PetscDS object
398345480ffeSMatthew G. Knepley 
398445480ffeSMatthew G. Knepley   Output Parameter:
398545480ffeSMatthew G. Knepley . newds - The PetscDS copy
398645480ffeSMatthew G. Knepley 
398745480ffeSMatthew G. Knepley   Level: intermediate
398845480ffeSMatthew G. Knepley 
398945480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
399045480ffeSMatthew G. Knepley @*/
399145480ffeSMatthew G. Knepley PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds)
399245480ffeSMatthew G. Knepley {
399345480ffeSMatthew G. Knepley   PetscSimplePointFunc sol;
399445480ffeSMatthew G. Knepley   void                *ctx;
399545480ffeSMatthew G. Knepley   PetscInt             Nf, f;
399645480ffeSMatthew G. Knepley   PetscErrorCode       ierr;
399745480ffeSMatthew G. Knepley 
399845480ffeSMatthew G. Knepley   PetscFunctionBegin;
399945480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
400045480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2);
400145480ffeSMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
400245480ffeSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
400345480ffeSMatthew G. Knepley     ierr = PetscDSGetExactSolution(ds,    f, &sol, &ctx);CHKERRQ(ierr);
400445480ffeSMatthew G. Knepley     ierr = PetscDSSetExactSolution(newds, f,  sol,  ctx);CHKERRQ(ierr);
400545480ffeSMatthew G. Knepley     ierr = PetscDSGetExactSolutionTimeDerivative(ds,    f, &sol, &ctx);CHKERRQ(ierr);
400645480ffeSMatthew G. Knepley     ierr = PetscDSSetExactSolutionTimeDerivative(newds, f,  sol,  ctx);CHKERRQ(ierr);
400745480ffeSMatthew G. Knepley   }
400845480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
400945480ffeSMatthew G. Knepley }
401045480ffeSMatthew G. Knepley 
4011b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
4012b1353e8eSMatthew G. Knepley {
4013df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
4014b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
4015b1353e8eSMatthew G. Knepley 
4016b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
4017b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
4018b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
4019b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
4020b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
4021df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
4022df3a45bdSMatthew G. Knepley   if (height > dim) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_OUTOFRANGE, "DS can only handle height in [0, %D], not %D", dim, height);
4023df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
4024df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
4025b1353e8eSMatthew G. Knepley     PetscInt cdim;
4026b1353e8eSMatthew G. Knepley 
4027df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
4028b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
4029df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
4030b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
4031b1353e8eSMatthew G. Knepley       PetscFE      subfe;
4032b1353e8eSMatthew G. Knepley       PetscObject  obj;
4033b1353e8eSMatthew G. Knepley       PetscClassId id;
4034b1353e8eSMatthew G. Knepley 
4035b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
4036b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
4037b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
4038b1353e8eSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
4039df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
4040b1353e8eSMatthew G. Knepley     }
4041b1353e8eSMatthew G. Knepley   }
4042df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
4043b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
4044b1353e8eSMatthew G. Knepley }
4045b1353e8eSMatthew G. Knepley 
4046665f567fSMatthew G. Knepley PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype)
4047c7bd5f0bSMatthew G. Knepley {
4048c7bd5f0bSMatthew G. Knepley   PetscObject    obj;
4049c7bd5f0bSMatthew G. Knepley   PetscClassId   id;
4050c7bd5f0bSMatthew G. Knepley   PetscInt       Nf;
4051c7bd5f0bSMatthew G. Knepley   PetscErrorCode ierr;
4052c7bd5f0bSMatthew G. Knepley 
4053c7bd5f0bSMatthew G. Knepley   PetscFunctionBegin;
4054c7bd5f0bSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
4055665f567fSMatthew G. Knepley   PetscValidPointer(disctype, 3);
4056665f567fSMatthew G. Knepley   *disctype = PETSC_DISC_NONE;
4057c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
4058c7bd5f0bSMatthew G. Knepley   if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf);
4059c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr);
4060665f567fSMatthew G. Knepley   if (obj) {
4061c7bd5f0bSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
4062665f567fSMatthew G. Knepley     if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE;
4063665f567fSMatthew G. Knepley     else                       *disctype = PETSC_DISC_FV;
4064665f567fSMatthew G. Knepley   }
4065c7bd5f0bSMatthew G. Knepley   PetscFunctionReturn(0);
4066c7bd5f0bSMatthew G. Knepley }
4067c7bd5f0bSMatthew G. Knepley 
40686528b96dSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds)
40692764a2aaSMatthew G. Knepley {
4070931fb3b8SToby Isaac   PetscErrorCode ierr;
4071931fb3b8SToby Isaac 
40722764a2aaSMatthew G. Knepley   PetscFunctionBegin;
40736528b96dSMatthew G. Knepley   ierr = PetscFree(ds->data);CHKERRQ(ierr);
40742764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
40752764a2aaSMatthew G. Knepley }
40762764a2aaSMatthew G. Knepley 
40776528b96dSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds)
40782764a2aaSMatthew G. Knepley {
40792764a2aaSMatthew G. Knepley   PetscFunctionBegin;
40806528b96dSMatthew G. Knepley   ds->ops->setfromoptions = NULL;
40816528b96dSMatthew G. Knepley   ds->ops->setup          = NULL;
40826528b96dSMatthew G. Knepley   ds->ops->view           = NULL;
40836528b96dSMatthew G. Knepley   ds->ops->destroy        = PetscDSDestroy_Basic;
40842764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
40852764a2aaSMatthew G. Knepley }
40862764a2aaSMatthew G. Knepley 
40872764a2aaSMatthew G. Knepley /*MC
40882764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
40892764a2aaSMatthew G. Knepley 
40902764a2aaSMatthew G. Knepley   Level: intermediate
40912764a2aaSMatthew G. Knepley 
40922764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
40932764a2aaSMatthew G. Knepley M*/
40942764a2aaSMatthew G. Knepley 
40956528b96dSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds)
40962764a2aaSMatthew G. Knepley {
40972764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
40982764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
40992764a2aaSMatthew G. Knepley 
41002764a2aaSMatthew G. Knepley   PetscFunctionBegin;
41016528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
41026528b96dSMatthew G. Knepley   ierr = PetscNewLog(ds, &b);CHKERRQ(ierr);
41036528b96dSMatthew G. Knepley   ds->data = b;
41042764a2aaSMatthew G. Knepley 
41056528b96dSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(ds);CHKERRQ(ierr);
41062764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
41072764a2aaSMatthew G. Knepley }
4108