xref: /petsc/src/dm/dt/interface/dtds.c (revision a2b725a8db0d6bf6cc2a1c6df7dd8029aadfff6e)
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 .keywords: PetscDS, register
532764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy()
542764a2aaSMatthew G. Knepley 
552764a2aaSMatthew G. Knepley @*/
562764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
572764a2aaSMatthew G. Knepley {
582764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
592764a2aaSMatthew G. Knepley 
602764a2aaSMatthew G. Knepley   PetscFunctionBegin;
612764a2aaSMatthew G. Knepley   ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr);
622764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
632764a2aaSMatthew G. Knepley }
642764a2aaSMatthew G. Knepley 
652764a2aaSMatthew G. Knepley /*@C
662764a2aaSMatthew G. Knepley   PetscDSSetType - Builds a particular PetscDS
672764a2aaSMatthew G. Knepley 
682764a2aaSMatthew G. Knepley   Collective on PetscDS
692764a2aaSMatthew G. Knepley 
702764a2aaSMatthew G. Knepley   Input Parameters:
712764a2aaSMatthew G. Knepley + prob - The PetscDS object
722764a2aaSMatthew G. Knepley - name - The kind of system
732764a2aaSMatthew G. Knepley 
742764a2aaSMatthew G. Knepley   Options Database Key:
752764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
762764a2aaSMatthew G. Knepley 
772764a2aaSMatthew G. Knepley   Level: intermediate
782764a2aaSMatthew G. Knepley 
79f5f57ec0SBarry Smith    Not available from Fortran
80f5f57ec0SBarry Smith 
812764a2aaSMatthew G. Knepley .keywords: PetscDS, set, type
822764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate()
832764a2aaSMatthew G. Knepley @*/
842764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
852764a2aaSMatthew G. Knepley {
862764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
872764a2aaSMatthew G. Knepley   PetscBool      match;
882764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
892764a2aaSMatthew G. Knepley 
902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
912764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
922764a2aaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr);
932764a2aaSMatthew G. Knepley   if (match) PetscFunctionReturn(0);
942764a2aaSMatthew G. Knepley 
950f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
962764a2aaSMatthew G. Knepley   ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr);
972764a2aaSMatthew G. Knepley   if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
982764a2aaSMatthew G. Knepley 
992764a2aaSMatthew G. Knepley   if (prob->ops->destroy) {
1002764a2aaSMatthew G. Knepley     ierr             = (*prob->ops->destroy)(prob);CHKERRQ(ierr);
1012764a2aaSMatthew G. Knepley     prob->ops->destroy = NULL;
1022764a2aaSMatthew G. Knepley   }
1032764a2aaSMatthew G. Knepley   ierr = (*r)(prob);CHKERRQ(ierr);
1042764a2aaSMatthew G. Knepley   ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr);
1052764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1062764a2aaSMatthew G. Knepley }
1072764a2aaSMatthew G. Knepley 
1082764a2aaSMatthew G. Knepley /*@C
1092764a2aaSMatthew G. Knepley   PetscDSGetType - Gets the PetscDS type name (as a string) from the object.
1102764a2aaSMatthew G. Knepley 
1112764a2aaSMatthew G. Knepley   Not Collective
1122764a2aaSMatthew G. Knepley 
1132764a2aaSMatthew G. Knepley   Input Parameter:
1142764a2aaSMatthew G. Knepley . prob  - The PetscDS
1152764a2aaSMatthew G. Knepley 
1162764a2aaSMatthew G. Knepley   Output Parameter:
1172764a2aaSMatthew G. Knepley . name - The PetscDS type name
1182764a2aaSMatthew G. Knepley 
1192764a2aaSMatthew G. Knepley   Level: intermediate
1202764a2aaSMatthew G. Knepley 
121f5f57ec0SBarry Smith    Not available from Fortran
122f5f57ec0SBarry Smith 
1232764a2aaSMatthew G. Knepley .keywords: PetscDS, get, type, name
1242764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate()
1252764a2aaSMatthew G. Knepley @*/
1262764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
1272764a2aaSMatthew G. Knepley {
1282764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1292764a2aaSMatthew G. Knepley 
1302764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1312764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
132c959eef4SJed Brown   PetscValidPointer(name, 2);
1330f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
1342764a2aaSMatthew G. Knepley   *name = ((PetscObject) prob)->type_name;
1352764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1362764a2aaSMatthew G. Knepley }
1372764a2aaSMatthew G. Knepley 
1387d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer)
1397d8a60eaSMatthew G. Knepley {
1407d8a60eaSMatthew G. Knepley   PetscViewerFormat  format;
14197b6e6e8SMatthew G. Knepley   const PetscScalar *constants;
14297b6e6e8SMatthew G. Knepley   PetscInt           numConstants, f;
1437d8a60eaSMatthew G. Knepley   PetscErrorCode     ierr;
1447d8a60eaSMatthew G. Knepley 
1457d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1467d8a60eaSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
1477d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr);
1487d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1494727e194SMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "  cell total dim %D total comp %D\n", prob->totDim, prob->totComp);CHKERRQ(ierr);
1504727e194SMatthew G. Knepley   if (prob->isHybrid) {ierr = PetscViewerASCIIPrintf(viewer, "  hybrid cell\n");CHKERRQ(ierr);}
1517d8a60eaSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
15240967b3bSMatthew G. Knepley     DSBoundary      b;
1537d8a60eaSMatthew G. Knepley     PetscObject     obj;
1547d8a60eaSMatthew G. Knepley     PetscClassId    id;
155f35450b9SMatthew G. Knepley     PetscQuadrature q;
1567d8a60eaSMatthew G. Knepley     const char     *name;
157f35450b9SMatthew G. Knepley     PetscInt        Nc, Nq, Nqc;
1587d8a60eaSMatthew G. Knepley 
1597d8a60eaSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
1607d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
1617d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr);
1627d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr);
1634727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
1647d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
1657d8a60eaSMatthew G. Knepley       ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr);
166f35450b9SMatthew G. Knepley       ierr = PetscFEGetQuadrature((PetscFE) obj, &q);CHKERRQ(ierr);
1677d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr);
1687d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1697d8a60eaSMatthew G. Knepley       ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr);
170f35450b9SMatthew G. Knepley       ierr = PetscFVGetQuadrature((PetscFV) obj, &q);CHKERRQ(ierr);
1717d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr);
1727d8a60eaSMatthew G. Knepley     }
17397b6e6e8SMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f);
17497b6e6e8SMatthew G. Knepley     if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%D components", Nc);CHKERRQ(ierr);}
17597b6e6e8SMatthew G. Knepley     else        {ierr = PetscViewerASCIIPrintf(viewer, "%D component ", Nc);CHKERRQ(ierr);}
176249df284SMatthew G. Knepley     if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);}
177249df284SMatthew G. Knepley     else                   {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);}
1783e60c2a6SMatthew G. Knepley     if (q) {
179f35450b9SMatthew G. Knepley       ierr = PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL);CHKERRQ(ierr);
180f35450b9SMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " (Nq %D Nqc %D)", Nq, Nqc);CHKERRQ(ierr);
1813e60c2a6SMatthew G. Knepley     }
1827d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
1834727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
1845d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1857d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);}
1867d8a60eaSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);}
1875d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
18840967b3bSMatthew G. Knepley 
18940967b3bSMatthew G. Knepley     for (b = prob->boundary; b; b = b->next) {
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);
19440967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->labelname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr);
19540967b3bSMatthew G. Knepley       if (!b->numcomps) {
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);
20040967b3bSMatthew G. Knepley         for (c = 0; c < b->numcomps; ++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       }
20740967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "  ids: ");CHKERRQ(ierr);
20840967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
20940967b3bSMatthew G. Knepley       for (i = 0; i < b->numids; ++i) {
21040967b3bSMatthew G. Knepley         if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
21140967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "%D", b->ids[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);
21540967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
21640967b3bSMatthew G. Knepley     }
2177d8a60eaSMatthew G. Knepley   }
21897b6e6e8SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr);
21997b6e6e8SMatthew G. Knepley   if (numConstants) {
22097b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr);
22197b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
22257fc01e9SMatthew G. Knepley     for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);}
22397b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
22497b6e6e8SMatthew G. Knepley   }
2257d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
2267d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
2277d8a60eaSMatthew G. Knepley }
2287d8a60eaSMatthew G. Knepley 
2292764a2aaSMatthew G. Knepley /*@C
2302764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
2312764a2aaSMatthew G. Knepley 
2322764a2aaSMatthew G. Knepley   Collective on PetscDS
2332764a2aaSMatthew G. Knepley 
2342764a2aaSMatthew G. Knepley   Input Parameter:
2352764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
2362764a2aaSMatthew G. Knepley - v  - the viewer
2372764a2aaSMatthew G. Knepley 
2382764a2aaSMatthew G. Knepley   Level: developer
2392764a2aaSMatthew G. Knepley 
2402764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
2412764a2aaSMatthew G. Knepley @*/
2422764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
2432764a2aaSMatthew G. Knepley {
2447d8a60eaSMatthew G. Knepley   PetscBool      iascii;
2452764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2462764a2aaSMatthew G. Knepley 
2472764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2482764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2492764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
2507d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
2517d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
2527d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2532764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2542764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2552764a2aaSMatthew G. Knepley }
2562764a2aaSMatthew G. Knepley 
2572764a2aaSMatthew G. Knepley /*@
2582764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2592764a2aaSMatthew G. Knepley 
2602764a2aaSMatthew G. Knepley   Collective on PetscDS
2612764a2aaSMatthew G. Knepley 
2622764a2aaSMatthew G. Knepley   Input Parameter:
2632764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2642764a2aaSMatthew G. Knepley 
2652764a2aaSMatthew G. Knepley   Options Database:
26655c1f793SMatthew G. Knepley + -petscds_type <type>     : Set the DS type
26755c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS
26855c1f793SMatthew G. Knepley . -petscds_jac_pre         : Turn formation of a separate Jacobian preconditioner on and off
26955c1f793SMatthew G. Knepley . -bc_<name> <ids>         : Specify a list of label ids for a boundary condition
27055c1f793SMatthew G. Knepley - -bc_<name>_comp <comps>  : Specify a list of field components to constrain for a boundary condition
2712764a2aaSMatthew G. Knepley 
2722764a2aaSMatthew G. Knepley   Level: developer
2732764a2aaSMatthew G. Knepley 
2742764a2aaSMatthew G. Knepley .seealso PetscDSView()
2752764a2aaSMatthew G. Knepley @*/
2762764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
2772764a2aaSMatthew G. Knepley {
278f1fd5e65SToby Isaac   DSBoundary     b;
2792764a2aaSMatthew G. Knepley   const char    *defaultType;
2802764a2aaSMatthew G. Knepley   char           name[256];
2812764a2aaSMatthew G. Knepley   PetscBool      flg;
2822764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2832764a2aaSMatthew G. Knepley 
2842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2852764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2862764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
2872764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
2882764a2aaSMatthew G. Knepley   } else {
2892764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
2902764a2aaSMatthew G. Knepley   }
2910f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
2922764a2aaSMatthew G. Knepley 
2932764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
294f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
295f1fd5e65SToby Isaac     char       optname[1024];
296f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
297f1fd5e65SToby Isaac     PetscBool  flg;
298f1fd5e65SToby Isaac 
299f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
300f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
301f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
302f1fd5e65SToby Isaac     if (flg) {
303f1fd5e65SToby Isaac       b->numids = len;
304f1fd5e65SToby Isaac       ierr = PetscFree(b->ids);CHKERRQ(ierr);
305f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr);
306f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->ids, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
307f1fd5e65SToby Isaac     }
308e7b0402cSSander Arens     len = 1024;
309f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
310f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
311f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
312f1fd5e65SToby Isaac     if (flg) {
313f1fd5e65SToby Isaac       b->numcomps = len;
314f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
315f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
316f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->comps, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
317f1fd5e65SToby Isaac     }
318f1fd5e65SToby Isaac   }
3192764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
3202764a2aaSMatthew G. Knepley   if (flg) {
3212764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
3222764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
3232764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
3242764a2aaSMatthew G. Knepley   }
32555c1f793SMatthew G. Knepley   ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr);
3262764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
3272764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
3280633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
3292764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
3305d160056SMatthew G. Knepley   if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);}
3312764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3322764a2aaSMatthew G. Knepley }
3332764a2aaSMatthew G. Knepley 
3342764a2aaSMatthew G. Knepley /*@C
3352764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
3362764a2aaSMatthew G. Knepley 
3372764a2aaSMatthew G. Knepley   Collective on PetscDS
3382764a2aaSMatthew G. Knepley 
3392764a2aaSMatthew G. Knepley   Input Parameter:
3402764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
3412764a2aaSMatthew G. Knepley 
3422764a2aaSMatthew G. Knepley   Level: developer
3432764a2aaSMatthew G. Knepley 
3442764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
3452764a2aaSMatthew G. Knepley @*/
3462764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
3472764a2aaSMatthew G. Knepley {
3482764a2aaSMatthew G. Knepley   const PetscInt Nf = prob->Nf;
34994a5e212SMatthew G. Knepley   PetscInt       dim, dimEmbed, work, NcMax = 0, NqMax = 0, NsMax = 1, f;
3502764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3512764a2aaSMatthew G. Knepley 
3522764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3532764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3542764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3552764a2aaSMatthew G. Knepley   /* Calculate sizes */
3562764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
357d1506c7cSMatthew G. Knepley   ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr);
358f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
35947e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
360f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
361f744cafaSSander Arens   ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisFace,Nf,&prob->basisDerFace);CHKERRQ(ierr);
3622764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3639de99aefSMatthew G. Knepley     PetscObject     obj;
3649de99aefSMatthew G. Knepley     PetscClassId    id;
3652764a2aaSMatthew G. Knepley     PetscQuadrature q;
3669de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
3672764a2aaSMatthew G. Knepley 
3689de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3699de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3709de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
3719de99aefSMatthew G. Knepley       PetscFE fe = (PetscFE) obj;
3729de99aefSMatthew G. Knepley 
3732764a2aaSMatthew G. Knepley       ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
3742764a2aaSMatthew G. Knepley       ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
3752764a2aaSMatthew G. Knepley       ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
3762764a2aaSMatthew G. Knepley       ierr = PetscFEGetDefaultTabulation(fe, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3774d0b9603SSander Arens       ierr = PetscFEGetFaceTabulation(fe, &prob->basisFace[f], &prob->basisDerFace[f], NULL);CHKERRQ(ierr);
3789de99aefSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
3799de99aefSMatthew G. Knepley       PetscFV fv = (PetscFV) obj;
3809de99aefSMatthew G. Knepley 
3819de99aefSMatthew G. Knepley       ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
3829de99aefSMatthew G. Knepley       ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
3839c3cf19fSMatthew G. Knepley       Nb   = Nc;
3846c1a3d01SMatthew G. Knepley       ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3854d0b9603SSander Arens       /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
386abac5ca0SMatthew G. Knepley     } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
38747e57110SSander Arens     prob->Nc[f]       = Nc;
38847e57110SSander Arens     prob->Nb[f]       = Nb;
389194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
390194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
391a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
3922764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
3932764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
3949c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
3952764a2aaSMatthew G. Knepley     prob->totComp += Nc;
39694a5e212SMatthew G. Knepley     /* There are two faces for all fields but the cohesive field on a hybrid cell */
39794a5e212SMatthew G. Knepley     if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb;
3982764a2aaSMatthew G. Knepley   }
3992764a2aaSMatthew G. Knepley   work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim));
4002764a2aaSMatthew G. Knepley   /* Allocate works space */
40194a5e212SMatthew G. Knepley   if (prob->isHybrid) NsMax = 2;
40294a5e212SMatthew G. Knepley   ierr = PetscMalloc5(NsMax*prob->totComp,&prob->u,NsMax*prob->totComp,&prob->u_t,NsMax*prob->totComp*dimEmbed,&prob->u_x,dimEmbed,&prob->x,work,&prob->refSpaceDer);CHKERRQ(ierr);
40394a5e212SMatthew G. Knepley   ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dim,&prob->f1,
40494a5e212SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dim,&prob->g1,
40594a5e212SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax*dim,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dim*dim,&prob->g3);CHKERRQ(ierr);
4062764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
4072764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
4082764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4092764a2aaSMatthew G. Knepley }
4102764a2aaSMatthew G. Knepley 
4112764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
4122764a2aaSMatthew G. Knepley {
4132764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4142764a2aaSMatthew G. Knepley 
4152764a2aaSMatthew G. Knepley   PetscFunctionBegin;
41647e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
417f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
418f744cafaSSander Arens   ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisFace,prob->basisDerFace);CHKERRQ(ierr);
4192764a2aaSMatthew G. Knepley   ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr);
4202764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
4212764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4222764a2aaSMatthew G. Knepley }
4232764a2aaSMatthew G. Knepley 
4242764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
4252764a2aaSMatthew G. Knepley {
426f744cafaSSander Arens   PetscObject      *tmpd;
42734aa8a36SMatthew G. Knepley   PetscBool        *tmpi;
42832d2bbc9SMatthew G. Knepley   PetscPointFunc   *tmpobj, *tmpf, *tmpup;
429b7e05686SMatthew G. Knepley   PetscPointJac    *tmpg, *tmpgp, *tmpgt;
4302aa1fc23SMatthew G. Knepley   PetscBdPointFunc *tmpfbd;
4312aa1fc23SMatthew G. Knepley   PetscBdPointJac  *tmpgbd;
432194d53e6SMatthew G. Knepley   PetscRiemannFunc *tmpr;
433c371a6d1SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol;
4340c2f2876SMatthew G. Knepley   void            **tmpctx;
43534aa8a36SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f;
4362764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
4372764a2aaSMatthew G. Knepley 
4382764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4392764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
4402764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
4412764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
44234aa8a36SMatthew G. Knepley   ierr = PetscMalloc2(NfNew, &tmpd, NfNew, &tmpi);CHKERRQ(ierr);
44334aa8a36SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f];}
44434aa8a36SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE;}
44534aa8a36SMatthew G. Knepley   ierr = PetscFree2(prob->disc, prob->implicit);CHKERRQ(ierr);
4462764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
4472764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
448249df284SMatthew G. Knepley   prob->implicit  = tmpi;
449b7e05686SMatthew G. Knepley   ierr = PetscCalloc7(NfNew, &tmpobj, NfNew*2, &tmpf, NfNew*NfNew*4, &tmpg, NfNew*NfNew*4, &tmpgp, NfNew*NfNew*4, &tmpgt, NfNew, &tmpr, NfNew, &tmpctx);CHKERRQ(ierr);
45032d2bbc9SMatthew G. Knepley   ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr);
4512764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f];
4522764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f];
4532764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f];
454475e0ac9SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f];
4550c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f];
45632d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
4570c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
4582764a2aaSMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL;
4592764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL;
4602764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL;
461475e0ac9SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL;
462b7e05686SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL;
4630c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL;
46432d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
4650c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
466b7e05686SMatthew G. Knepley   ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr);
46732d2bbc9SMatthew G. Knepley   ierr = PetscFree(prob->update);CHKERRQ(ierr);
4682764a2aaSMatthew G. Knepley   prob->obj = tmpobj;
4692764a2aaSMatthew G. Knepley   prob->f   = tmpf;
4702764a2aaSMatthew G. Knepley   prob->g   = tmpg;
471475e0ac9SMatthew G. Knepley   prob->gp  = tmpgp;
472b7e05686SMatthew G. Knepley   prob->gt  = tmpgt;
4730c2f2876SMatthew G. Knepley   prob->r   = tmpr;
47432d2bbc9SMatthew G. Knepley   prob->update = tmpup;
4750c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
476c371a6d1SMatthew G. Knepley   ierr = PetscCalloc3(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew, &tmpexactSol);CHKERRQ(ierr);
4772764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f];
4782764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f];
479c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
4802764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL;
4812764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL;
482c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
483c371a6d1SMatthew G. Knepley   ierr = PetscFree3(prob->fBd, prob->gBd, prob->exactSol);CHKERRQ(ierr);
4842764a2aaSMatthew G. Knepley   prob->fBd = tmpfbd;
4852764a2aaSMatthew G. Knepley   prob->gBd = tmpgbd;
486c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
4872764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4882764a2aaSMatthew G. Knepley }
4892764a2aaSMatthew G. Knepley 
4902764a2aaSMatthew G. Knepley /*@
4912764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
4922764a2aaSMatthew G. Knepley 
4932764a2aaSMatthew G. Knepley   Collective on PetscDS
4942764a2aaSMatthew G. Knepley 
4952764a2aaSMatthew G. Knepley   Input Parameter:
4962764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
4972764a2aaSMatthew G. Knepley 
4982764a2aaSMatthew G. Knepley   Level: developer
4992764a2aaSMatthew G. Knepley 
5002764a2aaSMatthew G. Knepley .seealso PetscDSView()
5012764a2aaSMatthew G. Knepley @*/
5022764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob)
5032764a2aaSMatthew G. Knepley {
5042764a2aaSMatthew G. Knepley   PetscInt       f;
50558ebd649SToby Isaac   DSBoundary     next;
5062764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5072764a2aaSMatthew G. Knepley 
5082764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5092764a2aaSMatthew G. Knepley   if (!*prob) PetscFunctionReturn(0);
5102764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1);
5112764a2aaSMatthew G. Knepley 
5122764a2aaSMatthew G. Knepley   if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);}
5132764a2aaSMatthew G. Knepley   ((PetscObject) (*prob))->refct = 0;
514df3a45bdSMatthew G. Knepley   if ((*prob)->subprobs) {
515df3a45bdSMatthew G. Knepley     PetscInt dim, d;
516df3a45bdSMatthew G. Knepley 
517df3a45bdSMatthew G. Knepley     ierr = PetscDSGetSpatialDimension(*prob, &dim);CHKERRQ(ierr);
518df3a45bdSMatthew G. Knepley     for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*prob)->subprobs[d]);CHKERRQ(ierr);}
519df3a45bdSMatthew G. Knepley   }
520df3a45bdSMatthew G. Knepley   ierr = PetscFree((*prob)->subprobs);CHKERRQ(ierr);
5212764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr);
5222764a2aaSMatthew G. Knepley   for (f = 0; f < (*prob)->Nf; ++f) {
5232764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr);
5242764a2aaSMatthew G. Knepley   }
52534aa8a36SMatthew G. Knepley   ierr = PetscFree2((*prob)->disc, (*prob)->implicit);CHKERRQ(ierr);
526b7e05686SMatthew G. Knepley   ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr);
52732d2bbc9SMatthew G. Knepley   ierr = PetscFree((*prob)->update);CHKERRQ(ierr);
528c371a6d1SMatthew G. Knepley   ierr = PetscFree3((*prob)->fBd,(*prob)->gBd,(*prob)->exactSol);CHKERRQ(ierr);
5292764a2aaSMatthew G. Knepley   if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);}
53058ebd649SToby Isaac   next = (*prob)->boundary;
53158ebd649SToby Isaac   while (next) {
53258ebd649SToby Isaac     DSBoundary b = next;
53358ebd649SToby Isaac 
53458ebd649SToby Isaac     next = b->next;
53558ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
53658ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
53758ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
53858ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
53958ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
54058ebd649SToby Isaac   }
54197b6e6e8SMatthew G. Knepley   ierr = PetscFree((*prob)->constants);CHKERRQ(ierr);
5422764a2aaSMatthew G. Knepley   ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr);
5432764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5442764a2aaSMatthew G. Knepley }
5452764a2aaSMatthew G. Knepley 
5462764a2aaSMatthew G. Knepley /*@
5472764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
5482764a2aaSMatthew G. Knepley 
5492764a2aaSMatthew G. Knepley   Collective on MPI_Comm
5502764a2aaSMatthew G. Knepley 
5512764a2aaSMatthew G. Knepley   Input Parameter:
5522764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
5532764a2aaSMatthew G. Knepley 
5542764a2aaSMatthew G. Knepley   Output Parameter:
5552764a2aaSMatthew G. Knepley . prob - The PetscDS object
5562764a2aaSMatthew G. Knepley 
5572764a2aaSMatthew G. Knepley   Level: beginner
5582764a2aaSMatthew G. Knepley 
5592764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
5602764a2aaSMatthew G. Knepley @*/
5612764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob)
5622764a2aaSMatthew G. Knepley {
5632764a2aaSMatthew G. Knepley   PetscDS   p;
5642764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5652764a2aaSMatthew G. Knepley 
5662764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5672764a2aaSMatthew G. Knepley   PetscValidPointer(prob, 2);
5682764a2aaSMatthew G. Knepley   *prob  = NULL;
5692764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5702764a2aaSMatthew G. Knepley 
57173107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5722764a2aaSMatthew G. Knepley 
5732764a2aaSMatthew G. Knepley   p->Nf           = 0;
5742764a2aaSMatthew G. Knepley   p->setup        = PETSC_FALSE;
57597b6e6e8SMatthew G. Knepley   p->numConstants = 0;
57697b6e6e8SMatthew G. Knepley   p->constants    = NULL;
577a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
57855c1f793SMatthew G. Knepley   p->useJacPre    = PETSC_TRUE;
5792764a2aaSMatthew G. Knepley 
5802764a2aaSMatthew G. Knepley   *prob = p;
5812764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5822764a2aaSMatthew G. Knepley }
5832764a2aaSMatthew G. Knepley 
584bc4ae4beSMatthew G. Knepley /*@
585bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
586bc4ae4beSMatthew G. Knepley 
587bc4ae4beSMatthew G. Knepley   Not collective
588bc4ae4beSMatthew G. Knepley 
589bc4ae4beSMatthew G. Knepley   Input Parameter:
590bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
591bc4ae4beSMatthew G. Knepley 
592bc4ae4beSMatthew G. Knepley   Output Parameter:
593bc4ae4beSMatthew G. Knepley . Nf - The number of fields
594bc4ae4beSMatthew G. Knepley 
595bc4ae4beSMatthew G. Knepley   Level: beginner
596bc4ae4beSMatthew G. Knepley 
597bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
598bc4ae4beSMatthew G. Knepley @*/
5992764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
6002764a2aaSMatthew G. Knepley {
6012764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6022764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6032764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
6042764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
6052764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6062764a2aaSMatthew G. Knepley }
6072764a2aaSMatthew G. Knepley 
608bc4ae4beSMatthew G. Knepley /*@
609a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
610bc4ae4beSMatthew G. Knepley 
611bc4ae4beSMatthew G. Knepley   Not collective
612bc4ae4beSMatthew G. Knepley 
613bc4ae4beSMatthew G. Knepley   Input Parameter:
614bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
615bc4ae4beSMatthew G. Knepley 
616bc4ae4beSMatthew G. Knepley   Output Parameter:
617bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
618bc4ae4beSMatthew G. Knepley 
619bc4ae4beSMatthew G. Knepley   Level: beginner
620bc4ae4beSMatthew G. Knepley 
621a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate()
622bc4ae4beSMatthew G. Knepley @*/
6232764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
6242764a2aaSMatthew G. Knepley {
6252764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6262764a2aaSMatthew G. Knepley 
6272764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6282764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6292764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6302764a2aaSMatthew G. Knepley   *dim = 0;
6319de99aefSMatthew G. Knepley   if (prob->Nf) {
6329de99aefSMatthew G. Knepley     PetscObject  obj;
6339de99aefSMatthew G. Knepley     PetscClassId id;
6349de99aefSMatthew G. Knepley 
6359de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
6369de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
6379de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
6389de99aefSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
6399de99aefSMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
6409de99aefSMatthew G. Knepley   }
6412764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6422764a2aaSMatthew G. Knepley }
6432764a2aaSMatthew G. Knepley 
644bc4ae4beSMatthew G. Knepley /*@
645a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
646a859676bSMatthew G. Knepley 
647a859676bSMatthew G. Knepley   Not collective
648a859676bSMatthew G. Knepley 
649a859676bSMatthew G. Knepley   Input Parameter:
650a859676bSMatthew G. Knepley . prob - The PetscDS object
651a859676bSMatthew G. Knepley 
652a859676bSMatthew G. Knepley   Output Parameter:
653a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
654a859676bSMatthew G. Knepley 
655a859676bSMatthew G. Knepley   Level: beginner
656a859676bSMatthew G. Knepley 
657a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
658a859676bSMatthew G. Knepley @*/
659a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
660a859676bSMatthew G. Knepley {
661a859676bSMatthew G. Knepley   PetscFunctionBegin;
662a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
663a859676bSMatthew G. Knepley   PetscValidPointer(dimEmbed, 2);
664a859676bSMatthew G. Knepley   if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
665a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
666a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
667a859676bSMatthew G. Knepley }
668a859676bSMatthew G. Knepley 
669a859676bSMatthew G. Knepley /*@
670a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
671a859676bSMatthew G. Knepley 
672ebfe4b0dSMatthew G. Knepley   Logically collective on DS
673a859676bSMatthew G. Knepley 
674a859676bSMatthew G. Knepley   Input Parameters:
675a859676bSMatthew G. Knepley + prob - The PetscDS object
676a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
677a859676bSMatthew G. Knepley 
678a859676bSMatthew G. Knepley   Level: beginner
679a859676bSMatthew G. Knepley 
680a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
681a859676bSMatthew G. Knepley @*/
682a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
683a859676bSMatthew G. Knepley {
684a859676bSMatthew G. Knepley   PetscFunctionBegin;
685a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
686ebfe4b0dSMatthew G. Knepley   if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed);
687a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
688a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
689a859676bSMatthew G. Knepley }
690a859676bSMatthew G. Knepley 
691a859676bSMatthew G. Knepley /*@
6928edf6225SMatthew G. Knepley   PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell
6938edf6225SMatthew G. Knepley 
6948edf6225SMatthew G. Knepley   Not collective
6958edf6225SMatthew G. Knepley 
6968edf6225SMatthew G. Knepley   Input Parameter:
6978edf6225SMatthew G. Knepley . prob - The PetscDS object
6988edf6225SMatthew G. Knepley 
6998edf6225SMatthew G. Knepley   Output Parameter:
7008edf6225SMatthew G. Knepley . isHybrid - The flag
7018edf6225SMatthew G. Knepley 
7028edf6225SMatthew G. Knepley   Level: developer
7038edf6225SMatthew G. Knepley 
7048edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate()
7058edf6225SMatthew G. Knepley @*/
7068edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid)
7078edf6225SMatthew G. Knepley {
7088edf6225SMatthew G. Knepley   PetscFunctionBegin;
7098edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7108edf6225SMatthew G. Knepley   PetscValidPointer(isHybrid, 2);
7118edf6225SMatthew G. Knepley   *isHybrid = prob->isHybrid;
7128edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7138edf6225SMatthew G. Knepley }
7148edf6225SMatthew G. Knepley 
7158edf6225SMatthew G. Knepley /*@
7168edf6225SMatthew G. Knepley   PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell
7178edf6225SMatthew G. Knepley 
7188edf6225SMatthew G. Knepley   Not collective
7198edf6225SMatthew G. Knepley 
7208edf6225SMatthew G. Knepley   Input Parameters:
7218edf6225SMatthew G. Knepley + prob - The PetscDS object
7228edf6225SMatthew G. Knepley - isHybrid - The flag
7238edf6225SMatthew G. Knepley 
7248edf6225SMatthew G. Knepley   Level: developer
7258edf6225SMatthew G. Knepley 
7268edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate()
7278edf6225SMatthew G. Knepley @*/
7288edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid)
7298edf6225SMatthew G. Knepley {
7308edf6225SMatthew G. Knepley   PetscFunctionBegin;
7318edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7328edf6225SMatthew G. Knepley   prob->isHybrid = isHybrid;
7338edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7348edf6225SMatthew G. Knepley }
7358edf6225SMatthew G. Knepley 
7368edf6225SMatthew G. Knepley /*@
737bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
738bc4ae4beSMatthew G. Knepley 
739bc4ae4beSMatthew G. Knepley   Not collective
740bc4ae4beSMatthew G. Knepley 
741bc4ae4beSMatthew G. Knepley   Input Parameter:
742bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
743bc4ae4beSMatthew G. Knepley 
744bc4ae4beSMatthew G. Knepley   Output Parameter:
745bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
746bc4ae4beSMatthew G. Knepley 
747bc4ae4beSMatthew G. Knepley   Level: beginner
748bc4ae4beSMatthew G. Knepley 
749bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
750bc4ae4beSMatthew G. Knepley @*/
7512764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
7522764a2aaSMatthew G. Knepley {
7532764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7542764a2aaSMatthew G. Knepley 
7552764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7562764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7572764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
7582764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
7592764a2aaSMatthew G. Knepley   *dim = prob->totDim;
7602764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7612764a2aaSMatthew G. Knepley }
7622764a2aaSMatthew G. Knepley 
763bc4ae4beSMatthew G. Knepley /*@
764bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
765bc4ae4beSMatthew G. Knepley 
766bc4ae4beSMatthew G. Knepley   Not collective
767bc4ae4beSMatthew G. Knepley 
768bc4ae4beSMatthew G. Knepley   Input Parameter:
769bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
770bc4ae4beSMatthew G. Knepley 
771bc4ae4beSMatthew G. Knepley   Output Parameter:
772bc4ae4beSMatthew G. Knepley . dim - The total number of components
773bc4ae4beSMatthew G. Knepley 
774bc4ae4beSMatthew G. Knepley   Level: beginner
775bc4ae4beSMatthew G. Knepley 
776bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
777bc4ae4beSMatthew G. Knepley @*/
7782764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
7792764a2aaSMatthew G. Knepley {
7802764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7812764a2aaSMatthew G. Knepley 
7822764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7832764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7842764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
7852764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
7862764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
7872764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7882764a2aaSMatthew G. Knepley }
7892764a2aaSMatthew G. Knepley 
790bc4ae4beSMatthew G. Knepley /*@
791bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
792bc4ae4beSMatthew G. Knepley 
793bc4ae4beSMatthew G. Knepley   Not collective
794bc4ae4beSMatthew G. Knepley 
795bc4ae4beSMatthew G. Knepley   Input Parameters:
796bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
797bc4ae4beSMatthew G. Knepley - f - The field number
798bc4ae4beSMatthew G. Knepley 
799bc4ae4beSMatthew G. Knepley   Output Parameter:
800bc4ae4beSMatthew G. Knepley . disc - The discretization object
801bc4ae4beSMatthew G. Knepley 
802bc4ae4beSMatthew G. Knepley   Level: beginner
803bc4ae4beSMatthew G. Knepley 
804f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
805bc4ae4beSMatthew G. Knepley @*/
8062764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
8072764a2aaSMatthew G. Knepley {
8082764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8092764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8102764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
8112764a2aaSMatthew 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);
8122764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
8132764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8142764a2aaSMatthew G. Knepley }
8152764a2aaSMatthew G. Knepley 
816bc4ae4beSMatthew G. Knepley /*@
817bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
818bc4ae4beSMatthew G. Knepley 
819bc4ae4beSMatthew G. Knepley   Not collective
820bc4ae4beSMatthew G. Knepley 
821bc4ae4beSMatthew G. Knepley   Input Parameters:
822bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
823bc4ae4beSMatthew G. Knepley . f - The field number
824bc4ae4beSMatthew G. Knepley - disc - The discretization object
825bc4ae4beSMatthew G. Knepley 
826bc4ae4beSMatthew G. Knepley   Level: beginner
827bc4ae4beSMatthew G. Knepley 
828bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
829bc4ae4beSMatthew G. Knepley @*/
8302764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
8312764a2aaSMatthew G. Knepley {
8322764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8332764a2aaSMatthew G. Knepley 
8342764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8352764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8362764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
8372764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
8382764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
839c10f2116SMatthew G. Knepley   ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);
8402764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
8412764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
842249df284SMatthew G. Knepley   {
843249df284SMatthew G. Knepley     PetscClassId id;
844249df284SMatthew G. Knepley 
845249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
8461cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
8471cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr);
8481cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
8491cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr);
850a6cbbb48SMatthew G. Knepley     }
851249df284SMatthew G. Knepley   }
8522764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8532764a2aaSMatthew G. Knepley }
8542764a2aaSMatthew G. Knepley 
855bc4ae4beSMatthew G. Knepley /*@
856bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
857bc4ae4beSMatthew G. Knepley 
858bc4ae4beSMatthew G. Knepley   Not collective
859bc4ae4beSMatthew G. Knepley 
860bc4ae4beSMatthew G. Knepley   Input Parameters:
861bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
862bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
863bc4ae4beSMatthew G. Knepley 
864bc4ae4beSMatthew G. Knepley   Level: beginner
865bc4ae4beSMatthew G. Knepley 
866bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
867bc4ae4beSMatthew G. Knepley @*/
8682764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
8692764a2aaSMatthew G. Knepley {
8702764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8712764a2aaSMatthew G. Knepley 
8722764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8732764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
8742764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8752764a2aaSMatthew G. Knepley }
8762764a2aaSMatthew G. Knepley 
877249df284SMatthew G. Knepley /*@
878249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
879249df284SMatthew G. Knepley 
880249df284SMatthew G. Knepley   Not collective
881249df284SMatthew G. Knepley 
882249df284SMatthew G. Knepley   Input Parameters:
883249df284SMatthew G. Knepley + prob - The PetscDS object
884249df284SMatthew G. Knepley - f - The field number
885249df284SMatthew G. Knepley 
886249df284SMatthew G. Knepley   Output Parameter:
887249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
888249df284SMatthew G. Knepley 
889249df284SMatthew G. Knepley   Level: developer
890249df284SMatthew G. Knepley 
891f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
892249df284SMatthew G. Knepley @*/
893249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
894249df284SMatthew G. Knepley {
895249df284SMatthew G. Knepley   PetscFunctionBegin;
896249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
897249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
898249df284SMatthew 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);
899249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
900249df284SMatthew G. Knepley   PetscFunctionReturn(0);
901249df284SMatthew G. Knepley }
902249df284SMatthew G. Knepley 
903249df284SMatthew G. Knepley /*@
904249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
905249df284SMatthew G. Knepley 
906249df284SMatthew G. Knepley   Not collective
907249df284SMatthew G. Knepley 
908249df284SMatthew G. Knepley   Input Parameters:
909249df284SMatthew G. Knepley + prob - The PetscDS object
910249df284SMatthew G. Knepley . f - The field number
911249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
912249df284SMatthew G. Knepley 
913249df284SMatthew G. Knepley   Level: developer
914249df284SMatthew G. Knepley 
915f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
916249df284SMatthew G. Knepley @*/
917249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
918249df284SMatthew G. Knepley {
919249df284SMatthew G. Knepley   PetscFunctionBegin;
920249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
921249df284SMatthew 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);
922249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
923249df284SMatthew G. Knepley   PetscFunctionReturn(0);
924249df284SMatthew G. Knepley }
925249df284SMatthew G. Knepley 
9262764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f,
92730b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
928194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
929194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
93097b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
9312764a2aaSMatthew G. Knepley {
9322764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9332764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9342764a2aaSMatthew G. Knepley   PetscValidPointer(obj, 2);
9352764a2aaSMatthew 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);
9362764a2aaSMatthew G. Knepley   *obj = prob->obj[f];
9372764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9382764a2aaSMatthew G. Knepley }
9392764a2aaSMatthew G. Knepley 
9402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f,
94130b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
942194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
943194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
94497b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
9452764a2aaSMatthew G. Knepley {
9462764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9472764a2aaSMatthew G. Knepley 
9482764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9492764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
950de716cbcSToby Isaac   if (obj) PetscValidFunction(obj, 2);
9512764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
9522764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
9532764a2aaSMatthew G. Knepley   prob->obj[f] = obj;
9542764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9552764a2aaSMatthew G. Knepley }
9562764a2aaSMatthew G. Knepley 
957194d53e6SMatthew G. Knepley /*@C
958194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
959194d53e6SMatthew G. Knepley 
960194d53e6SMatthew G. Knepley   Not collective
961194d53e6SMatthew G. Knepley 
962194d53e6SMatthew G. Knepley   Input Parameters:
963194d53e6SMatthew G. Knepley + prob - The PetscDS
964194d53e6SMatthew G. Knepley - f    - The test field number
965194d53e6SMatthew G. Knepley 
966194d53e6SMatthew G. Knepley   Output Parameters:
967194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
968194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
969194d53e6SMatthew G. Knepley 
970194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
971194d53e6SMatthew G. Knepley 
972194d53e6SMatthew 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)
973194d53e6SMatthew G. Knepley 
974194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
975194d53e6SMatthew G. Knepley 
97630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
977194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
978194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
97930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
980194d53e6SMatthew G. Knepley 
981194d53e6SMatthew G. Knepley + dim - the spatial dimension
982194d53e6SMatthew G. Knepley . Nf - the number of fields
983194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
984194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
985194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
986194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
987194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
988194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
989194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
990194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
991194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
992194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
993194d53e6SMatthew G. Knepley . t - current time
994194d53e6SMatthew G. Knepley . x - coordinates of the current point
99597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
99697b6e6e8SMatthew G. Knepley . constants - constant parameters
997194d53e6SMatthew G. Knepley - f0 - output values at the current point
998194d53e6SMatthew G. Knepley 
999194d53e6SMatthew G. Knepley   Level: intermediate
1000194d53e6SMatthew G. Knepley 
1001194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
1002194d53e6SMatthew G. Knepley @*/
10032764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f,
100430b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1005194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1006194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
100797b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
100830b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1009194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1010194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
101197b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
10122764a2aaSMatthew G. Knepley {
10132764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10142764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10152764a2aaSMatthew 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);
10162764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];}
10172764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];}
10182764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10192764a2aaSMatthew G. Knepley }
10202764a2aaSMatthew G. Knepley 
1021194d53e6SMatthew G. Knepley /*@C
1022194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1023194d53e6SMatthew G. Knepley 
1024194d53e6SMatthew G. Knepley   Not collective
1025194d53e6SMatthew G. Knepley 
1026194d53e6SMatthew G. Knepley   Input Parameters:
1027194d53e6SMatthew G. Knepley + prob - The PetscDS
1028194d53e6SMatthew G. Knepley . f    - The test field number
1029194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1030194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1031194d53e6SMatthew G. Knepley 
1032194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1033194d53e6SMatthew G. Knepley 
1034194d53e6SMatthew 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)
1035194d53e6SMatthew G. Knepley 
1036194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1037194d53e6SMatthew G. Knepley 
103830b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1039194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1040194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
104130b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1042194d53e6SMatthew G. Knepley 
1043194d53e6SMatthew G. Knepley + dim - the spatial dimension
1044194d53e6SMatthew G. Knepley . Nf - the number of fields
1045194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1046194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1047194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1048194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1049194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1050194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1051194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1052194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1053194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1054194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1055194d53e6SMatthew G. Knepley . t - current time
1056194d53e6SMatthew G. Knepley . x - coordinates of the current point
105797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
105897b6e6e8SMatthew G. Knepley . constants - constant parameters
1059194d53e6SMatthew G. Knepley - f0 - output values at the current point
1060194d53e6SMatthew G. Knepley 
1061194d53e6SMatthew G. Knepley   Level: intermediate
1062194d53e6SMatthew G. Knepley 
1063194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1064194d53e6SMatthew G. Knepley @*/
10652764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f,
106630b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1067194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1068194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
106997b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
107030b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1071194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1072194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
107397b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
10742764a2aaSMatthew G. Knepley {
10752764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
10762764a2aaSMatthew G. Knepley 
10772764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10782764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1079f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1080f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
10812764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
10822764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
10832764a2aaSMatthew G. Knepley   prob->f[f*2+0] = f0;
10842764a2aaSMatthew G. Knepley   prob->f[f*2+1] = f1;
10852764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10862764a2aaSMatthew G. Knepley }
10872764a2aaSMatthew G. Knepley 
10883e75805dSMatthew G. Knepley /*@C
10893e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
10903e75805dSMatthew G. Knepley 
10913e75805dSMatthew G. Knepley   Not collective
10923e75805dSMatthew G. Knepley 
10933e75805dSMatthew G. Knepley   Input Parameter:
10943e75805dSMatthew G. Knepley . prob - The PetscDS
10953e75805dSMatthew G. Knepley 
10963e75805dSMatthew G. Knepley   Output Parameter:
10973e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
10983e75805dSMatthew G. Knepley 
10993e75805dSMatthew G. Knepley   Level: intermediate
11003e75805dSMatthew G. Knepley 
11013e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
11023e75805dSMatthew G. Knepley @*/
11033e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac)
11043e75805dSMatthew G. Knepley {
11053e75805dSMatthew G. Knepley   PetscInt f, g, h;
11063e75805dSMatthew G. Knepley 
11073e75805dSMatthew G. Knepley   PetscFunctionBegin;
11083e75805dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11093e75805dSMatthew G. Knepley   *hasJac = PETSC_FALSE;
11103e75805dSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
11113e75805dSMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
11123e75805dSMatthew G. Knepley       for (h = 0; h < 4; ++h) {
11133e75805dSMatthew G. Knepley         if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE;
11143e75805dSMatthew G. Knepley       }
11153e75805dSMatthew G. Knepley     }
11163e75805dSMatthew G. Knepley   }
11173e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
11183e75805dSMatthew G. Knepley }
11193e75805dSMatthew G. Knepley 
1120194d53e6SMatthew G. Knepley /*@C
1121194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1122194d53e6SMatthew G. Knepley 
1123194d53e6SMatthew G. Knepley   Not collective
1124194d53e6SMatthew G. Knepley 
1125194d53e6SMatthew G. Knepley   Input Parameters:
1126194d53e6SMatthew G. Knepley + prob - The PetscDS
1127194d53e6SMatthew G. Knepley . f    - The test field number
1128194d53e6SMatthew G. Knepley - g    - The field number
1129194d53e6SMatthew G. Knepley 
1130194d53e6SMatthew G. Knepley   Output Parameters:
1131194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1132194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1133194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1134194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1135194d53e6SMatthew G. Knepley 
1136194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1137194d53e6SMatthew G. Knepley 
1138194d53e6SMatthew 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
1139194d53e6SMatthew G. Knepley 
1140194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1141194d53e6SMatthew G. Knepley 
114230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1143194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1144194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
114530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1146194d53e6SMatthew G. Knepley 
1147194d53e6SMatthew G. Knepley + dim - the spatial dimension
1148194d53e6SMatthew G. Knepley . Nf - the number of fields
1149194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1150194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1151194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1152194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1153194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1154194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1155194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1156194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1157194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1158194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1159194d53e6SMatthew G. Knepley . t - current time
11602aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1161194d53e6SMatthew G. Knepley . x - coordinates of the current point
116297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
116397b6e6e8SMatthew G. Knepley . constants - constant parameters
1164194d53e6SMatthew G. Knepley - g0 - output values at the current point
1165194d53e6SMatthew G. Knepley 
1166194d53e6SMatthew G. Knepley   Level: intermediate
1167194d53e6SMatthew G. Knepley 
1168194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1169194d53e6SMatthew G. Knepley @*/
11702764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g,
117130b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1172194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1173194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
117530b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1176194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1177194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
117930b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1180194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1181194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
118297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
118330b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1184194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1185194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
118697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
11872764a2aaSMatthew G. Knepley {
11882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11902764a2aaSMatthew 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);
11912764a2aaSMatthew G. Knepley   if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf);
11922764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];}
11932764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];}
11942764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];}
11952764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];}
11962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11972764a2aaSMatthew G. Knepley }
11982764a2aaSMatthew G. Knepley 
1199194d53e6SMatthew G. Knepley /*@C
1200194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1201194d53e6SMatthew G. Knepley 
1202194d53e6SMatthew G. Knepley   Not collective
1203194d53e6SMatthew G. Knepley 
1204194d53e6SMatthew G. Knepley   Input Parameters:
1205194d53e6SMatthew G. Knepley + prob - The PetscDS
1206194d53e6SMatthew G. Knepley . f    - The test field number
1207194d53e6SMatthew G. Knepley . g    - The field number
1208194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1209194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1210194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1211194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1212194d53e6SMatthew G. Knepley 
1213194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1214194d53e6SMatthew G. Knepley 
1215194d53e6SMatthew 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
1216194d53e6SMatthew G. Knepley 
1217194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1218194d53e6SMatthew G. Knepley 
121930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1220194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1221194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
122230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1223194d53e6SMatthew G. Knepley 
1224194d53e6SMatthew G. Knepley + dim - the spatial dimension
1225194d53e6SMatthew G. Knepley . Nf - the number of fields
1226194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1227194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1228194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1229194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1230194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1231194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1232194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1233194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1234194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1235194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1236194d53e6SMatthew G. Knepley . t - current time
12372aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1238194d53e6SMatthew G. Knepley . x - coordinates of the current point
123997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
124097b6e6e8SMatthew G. Knepley . constants - constant parameters
1241194d53e6SMatthew G. Knepley - g0 - output values at the current point
1242194d53e6SMatthew G. Knepley 
1243194d53e6SMatthew G. Knepley   Level: intermediate
1244194d53e6SMatthew G. Knepley 
1245194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1246194d53e6SMatthew G. Knepley @*/
12472764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g,
124830b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1249194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1250194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
125197b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
125230b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1253194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1254194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
125597b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
125630b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1257194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1258194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
125997b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
126030b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1261194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1262194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
126397b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
12642764a2aaSMatthew G. Knepley {
12652764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
12662764a2aaSMatthew G. Knepley 
12672764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12682764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
12692764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
12702764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
12712764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
12722764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
12732764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
12742764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
12752764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
12762764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+0] = g0;
12772764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+1] = g1;
12782764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+2] = g2;
12792764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+3] = g3;
12802764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12812764a2aaSMatthew G. Knepley }
12822764a2aaSMatthew G. Knepley 
1283475e0ac9SMatthew G. Knepley /*@C
128455c1f793SMatthew G. Knepley   PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner
128555c1f793SMatthew G. Knepley 
128655c1f793SMatthew G. Knepley   Not collective
128755c1f793SMatthew G. Knepley 
128855c1f793SMatthew G. Knepley   Input Parameters:
128955c1f793SMatthew G. Knepley + prob - The PetscDS
129055c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
129155c1f793SMatthew G. Knepley 
129255c1f793SMatthew G. Knepley   Level: intermediate
129355c1f793SMatthew G. Knepley 
129455c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
129555c1f793SMatthew G. Knepley @*/
129655c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
129755c1f793SMatthew G. Knepley {
129855c1f793SMatthew G. Knepley   PetscFunctionBegin;
129955c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
130055c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
130155c1f793SMatthew G. Knepley   PetscFunctionReturn(0);
130255c1f793SMatthew G. Knepley }
130355c1f793SMatthew G. Knepley 
130455c1f793SMatthew G. Knepley /*@C
1305475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1306475e0ac9SMatthew G. Knepley 
1307475e0ac9SMatthew G. Knepley   Not collective
1308475e0ac9SMatthew G. Knepley 
1309475e0ac9SMatthew G. Knepley   Input Parameter:
1310475e0ac9SMatthew G. Knepley . prob - The PetscDS
1311475e0ac9SMatthew G. Knepley 
1312475e0ac9SMatthew G. Knepley   Output Parameter:
1313475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1314475e0ac9SMatthew G. Knepley 
1315475e0ac9SMatthew G. Knepley   Level: intermediate
1316475e0ac9SMatthew G. Knepley 
1317475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1318475e0ac9SMatthew G. Knepley @*/
1319475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre)
1320475e0ac9SMatthew G. Knepley {
1321475e0ac9SMatthew G. Knepley   PetscInt f, g, h;
1322475e0ac9SMatthew G. Knepley 
1323475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1324475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1325475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
132655c1f793SMatthew G. Knepley   if (!prob->useJacPre) PetscFunctionReturn(0);
1327475e0ac9SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1328475e0ac9SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1329475e0ac9SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1330475e0ac9SMatthew G. Knepley         if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE;
1331475e0ac9SMatthew G. Knepley       }
1332475e0ac9SMatthew G. Knepley     }
1333475e0ac9SMatthew G. Knepley   }
1334475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1335475e0ac9SMatthew G. Knepley }
1336475e0ac9SMatthew G. Knepley 
1337475e0ac9SMatthew G. Knepley /*@C
1338475e0ac9SMatthew 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.
1339475e0ac9SMatthew G. Knepley 
1340475e0ac9SMatthew G. Knepley   Not collective
1341475e0ac9SMatthew G. Knepley 
1342475e0ac9SMatthew G. Knepley   Input Parameters:
1343475e0ac9SMatthew G. Knepley + prob - The PetscDS
1344475e0ac9SMatthew G. Knepley . f    - The test field number
1345475e0ac9SMatthew G. Knepley - g    - The field number
1346475e0ac9SMatthew G. Knepley 
1347475e0ac9SMatthew G. Knepley   Output Parameters:
1348475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1349475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1350475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1351475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1352475e0ac9SMatthew G. Knepley 
1353475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1354475e0ac9SMatthew G. Knepley 
1355475e0ac9SMatthew 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
1356475e0ac9SMatthew G. Knepley 
1357475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1358475e0ac9SMatthew G. Knepley 
1359475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1360475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1361475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1362475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1363475e0ac9SMatthew G. Knepley 
1364475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1365475e0ac9SMatthew G. Knepley . Nf - the number of fields
1366475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1367475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1368475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1369475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1370475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1371475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1372475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1373475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1374475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1375475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1376475e0ac9SMatthew G. Knepley . t - current time
1377475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1378475e0ac9SMatthew G. Knepley . x - coordinates of the current point
137997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
138097b6e6e8SMatthew G. Knepley . constants - constant parameters
1381475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1382475e0ac9SMatthew G. Knepley 
1383475e0ac9SMatthew G. Knepley   Level: intermediate
1384475e0ac9SMatthew G. Knepley 
1385475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1386475e0ac9SMatthew G. Knepley @*/
1387475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1388475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1389475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1390475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
139197b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1392475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1393475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1394475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
139597b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1396475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1397475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1398475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
139997b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1400475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1401475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1402475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
140397b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1404475e0ac9SMatthew G. Knepley {
1405475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1406475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1407475e0ac9SMatthew 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);
1408475e0ac9SMatthew G. Knepley   if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf);
1409475e0ac9SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];}
1410475e0ac9SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];}
1411475e0ac9SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];}
1412475e0ac9SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];}
1413475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1414475e0ac9SMatthew G. Knepley }
1415475e0ac9SMatthew G. Knepley 
1416475e0ac9SMatthew G. Knepley /*@C
1417475e0ac9SMatthew 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.
1418475e0ac9SMatthew G. Knepley 
1419475e0ac9SMatthew G. Knepley   Not collective
1420475e0ac9SMatthew G. Knepley 
1421475e0ac9SMatthew G. Knepley   Input Parameters:
1422475e0ac9SMatthew G. Knepley + prob - The PetscDS
1423475e0ac9SMatthew G. Knepley . f    - The test field number
1424475e0ac9SMatthew G. Knepley . g    - The field number
1425475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1426475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1427475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1428475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1429475e0ac9SMatthew G. Knepley 
1430475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1431475e0ac9SMatthew G. Knepley 
1432475e0ac9SMatthew 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
1433475e0ac9SMatthew G. Knepley 
1434475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1435475e0ac9SMatthew G. Knepley 
1436475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1437475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1438475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1439475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1440475e0ac9SMatthew G. Knepley 
1441475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1442475e0ac9SMatthew G. Knepley . Nf - the number of fields
1443475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1444475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1445475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1446475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1447475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1448475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1449475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1450475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1451475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1452475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1453475e0ac9SMatthew G. Knepley . t - current time
1454475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1455475e0ac9SMatthew G. Knepley . x - coordinates of the current point
145697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
145797b6e6e8SMatthew G. Knepley . constants - constant parameters
1458475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1459475e0ac9SMatthew G. Knepley 
1460475e0ac9SMatthew G. Knepley   Level: intermediate
1461475e0ac9SMatthew G. Knepley 
1462475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1463475e0ac9SMatthew G. Knepley @*/
1464475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1465475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1466475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1467475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
146897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1469475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1470475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1471475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
147297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1473475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1474475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1475475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
147697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1477475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1478475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1479475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
148097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1481475e0ac9SMatthew G. Knepley {
1482475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1483475e0ac9SMatthew G. Knepley 
1484475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1485475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1486475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1487475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1488475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1489475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1490475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1491475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1492475e0ac9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1493475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+0] = g0;
1494475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+1] = g1;
1495475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+2] = g2;
1496475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+3] = g3;
1497475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1498475e0ac9SMatthew G. Knepley }
1499475e0ac9SMatthew G. Knepley 
1500b7e05686SMatthew G. Knepley /*@C
1501b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1502b7e05686SMatthew G. Knepley 
1503b7e05686SMatthew G. Knepley   Not collective
1504b7e05686SMatthew G. Knepley 
1505b7e05686SMatthew G. Knepley   Input Parameter:
1506b7e05686SMatthew G. Knepley . prob - The PetscDS
1507b7e05686SMatthew G. Knepley 
1508b7e05686SMatthew G. Knepley   Output Parameter:
1509b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1510b7e05686SMatthew G. Knepley 
1511b7e05686SMatthew G. Knepley   Level: intermediate
1512b7e05686SMatthew G. Knepley 
1513b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1514b7e05686SMatthew G. Knepley @*/
1515b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac)
1516b7e05686SMatthew G. Knepley {
1517b7e05686SMatthew G. Knepley   PetscInt f, g, h;
1518b7e05686SMatthew G. Knepley 
1519b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1520b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1521b7e05686SMatthew G. Knepley   *hasDynJac = PETSC_FALSE;
1522b7e05686SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1523b7e05686SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1524b7e05686SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1525b7e05686SMatthew G. Knepley         if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE;
1526b7e05686SMatthew G. Knepley       }
1527b7e05686SMatthew G. Knepley     }
1528b7e05686SMatthew G. Knepley   }
1529b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1530b7e05686SMatthew G. Knepley }
1531b7e05686SMatthew G. Knepley 
1532b7e05686SMatthew G. Knepley /*@C
1533b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1534b7e05686SMatthew G. Knepley 
1535b7e05686SMatthew G. Knepley   Not collective
1536b7e05686SMatthew G. Knepley 
1537b7e05686SMatthew G. Knepley   Input Parameters:
1538b7e05686SMatthew G. Knepley + prob - The PetscDS
1539b7e05686SMatthew G. Knepley . f    - The test field number
1540b7e05686SMatthew G. Knepley - g    - The field number
1541b7e05686SMatthew G. Knepley 
1542b7e05686SMatthew G. Knepley   Output Parameters:
1543b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1544b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1545b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1546b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1547b7e05686SMatthew G. Knepley 
1548b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1549b7e05686SMatthew G. Knepley 
1550b7e05686SMatthew 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
1551b7e05686SMatthew G. Knepley 
1552b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1553b7e05686SMatthew G. Knepley 
1554b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1555b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1556b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1557b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1558b7e05686SMatthew G. Knepley 
1559b7e05686SMatthew G. Knepley + dim - the spatial dimension
1560b7e05686SMatthew G. Knepley . Nf - the number of fields
1561b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1562b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1563b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1564b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1565b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1566b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1567b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1568b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1569b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1570b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1571b7e05686SMatthew G. Knepley . t - current time
1572b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1573b7e05686SMatthew G. Knepley . x - coordinates of the current point
157497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
157597b6e6e8SMatthew G. Knepley . constants - constant parameters
1576b7e05686SMatthew G. Knepley - g0 - output values at the current point
1577b7e05686SMatthew G. Knepley 
1578b7e05686SMatthew G. Knepley   Level: intermediate
1579b7e05686SMatthew G. Knepley 
1580b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1581b7e05686SMatthew G. Knepley @*/
1582b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1583b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1584b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1585b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
158697b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1587b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1588b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1589b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
159097b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1591b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1592b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1593b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
159497b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1595b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1596b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1597b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
159897b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1599b7e05686SMatthew G. Knepley {
1600b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1601b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1602b7e05686SMatthew 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);
1603b7e05686SMatthew G. Knepley   if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf);
1604b7e05686SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];}
1605b7e05686SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];}
1606b7e05686SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];}
1607b7e05686SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];}
1608b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1609b7e05686SMatthew G. Knepley }
1610b7e05686SMatthew G. Knepley 
1611b7e05686SMatthew G. Knepley /*@C
1612b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1613b7e05686SMatthew G. Knepley 
1614b7e05686SMatthew G. Knepley   Not collective
1615b7e05686SMatthew G. Knepley 
1616b7e05686SMatthew G. Knepley   Input Parameters:
1617b7e05686SMatthew G. Knepley + prob - The PetscDS
1618b7e05686SMatthew G. Knepley . f    - The test field number
1619b7e05686SMatthew G. Knepley . g    - The field number
1620b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1621b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1622b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1623b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1624b7e05686SMatthew G. Knepley 
1625b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1626b7e05686SMatthew G. Knepley 
1627b7e05686SMatthew 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
1628b7e05686SMatthew G. Knepley 
1629b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1630b7e05686SMatthew G. Knepley 
1631b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1632b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1633b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1634b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1635b7e05686SMatthew G. Knepley 
1636b7e05686SMatthew G. Knepley + dim - the spatial dimension
1637b7e05686SMatthew G. Knepley . Nf - the number of fields
1638b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1639b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1640b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1641b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1642b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1643b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1644b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1645b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1646b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1647b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1648b7e05686SMatthew G. Knepley . t - current time
1649b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1650b7e05686SMatthew G. Knepley . x - coordinates of the current point
165197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
165297b6e6e8SMatthew G. Knepley . constants - constant parameters
1653b7e05686SMatthew G. Knepley - g0 - output values at the current point
1654b7e05686SMatthew G. Knepley 
1655b7e05686SMatthew G. Knepley   Level: intermediate
1656b7e05686SMatthew G. Knepley 
1657b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1658b7e05686SMatthew G. Knepley @*/
1659b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1660b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1661b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1662b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
166397b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1664b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1665b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1666b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
166797b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1668b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1669b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1670b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
167197b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1672b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1673b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1674b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
167597b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1676b7e05686SMatthew G. Knepley {
1677b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1678b7e05686SMatthew G. Knepley 
1679b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1680b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1681b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1682b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1683b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1684b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1685b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1686b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1687b7e05686SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1688b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+0] = g0;
1689b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+1] = g1;
1690b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+2] = g2;
1691b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+3] = g3;
1692b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1693b7e05686SMatthew G. Knepley }
1694b7e05686SMatthew G. Knepley 
16950c2f2876SMatthew G. Knepley /*@C
16960c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
16970c2f2876SMatthew G. Knepley 
16980c2f2876SMatthew G. Knepley   Not collective
16990c2f2876SMatthew G. Knepley 
17000c2f2876SMatthew G. Knepley   Input Arguments:
17010c2f2876SMatthew G. Knepley + prob - The PetscDS object
17020c2f2876SMatthew G. Knepley - f    - The field number
17030c2f2876SMatthew G. Knepley 
17040c2f2876SMatthew G. Knepley   Output Argument:
17050c2f2876SMatthew G. Knepley . r    - Riemann solver
17060c2f2876SMatthew G. Knepley 
17070c2f2876SMatthew G. Knepley   Calling sequence for r:
17080c2f2876SMatthew G. Knepley 
17095db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
17100c2f2876SMatthew G. Knepley 
17115db36cf9SMatthew G. Knepley + dim  - The spatial dimension
17125db36cf9SMatthew G. Knepley . Nf   - The number of fields
17135db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
17140c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
17150c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
17160c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
17170c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
171897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
171997b6e6e8SMatthew G. Knepley . constants - constant parameters
17200c2f2876SMatthew G. Knepley - ctx  - optional user context
17210c2f2876SMatthew G. Knepley 
17220c2f2876SMatthew G. Knepley   Level: intermediate
17230c2f2876SMatthew G. Knepley 
17240c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
17250c2f2876SMatthew G. Knepley @*/
17260c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f,
172797b6e6e8SMatthew 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))
17280c2f2876SMatthew G. Knepley {
17290c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17300c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
17310c2f2876SMatthew 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);
17320c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
17330c2f2876SMatthew G. Knepley   *r = prob->r[f];
17340c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17350c2f2876SMatthew G. Knepley }
17360c2f2876SMatthew G. Knepley 
17370c2f2876SMatthew G. Knepley /*@C
17380c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
17390c2f2876SMatthew G. Knepley 
17400c2f2876SMatthew G. Knepley   Not collective
17410c2f2876SMatthew G. Knepley 
17420c2f2876SMatthew G. Knepley   Input Arguments:
17430c2f2876SMatthew G. Knepley + prob - The PetscDS object
17440c2f2876SMatthew G. Knepley . f    - The field number
17450c2f2876SMatthew G. Knepley - r    - Riemann solver
17460c2f2876SMatthew G. Knepley 
17470c2f2876SMatthew G. Knepley   Calling sequence for r:
17480c2f2876SMatthew G. Knepley 
17495db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
17500c2f2876SMatthew G. Knepley 
17515db36cf9SMatthew G. Knepley + dim  - The spatial dimension
17525db36cf9SMatthew G. Knepley . Nf   - The number of fields
17535db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
17540c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
17550c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
17560c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
17570c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
175897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
175997b6e6e8SMatthew G. Knepley . constants - constant parameters
17600c2f2876SMatthew G. Knepley - ctx  - optional user context
17610c2f2876SMatthew G. Knepley 
17620c2f2876SMatthew G. Knepley   Level: intermediate
17630c2f2876SMatthew G. Knepley 
17640c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
17650c2f2876SMatthew G. Knepley @*/
17660c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f,
176797b6e6e8SMatthew 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))
17680c2f2876SMatthew G. Knepley {
17690c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
17700c2f2876SMatthew G. Knepley 
17710c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17720c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1773de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
17740c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
17750c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
17760c2f2876SMatthew G. Knepley   prob->r[f] = r;
17770c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17780c2f2876SMatthew G. Knepley }
17790c2f2876SMatthew G. Knepley 
178032d2bbc9SMatthew G. Knepley /*@C
178132d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
178232d2bbc9SMatthew G. Knepley 
178332d2bbc9SMatthew G. Knepley   Not collective
178432d2bbc9SMatthew G. Knepley 
178532d2bbc9SMatthew G. Knepley   Input Parameters:
178632d2bbc9SMatthew G. Knepley + prob - The PetscDS
178732d2bbc9SMatthew G. Knepley - f    - The field number
178832d2bbc9SMatthew G. Knepley 
178932d2bbc9SMatthew G. Knepley   Output Parameters:
1790*a2b725a8SWilliam Gropp . update - update function
179132d2bbc9SMatthew G. Knepley 
179232d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
179332d2bbc9SMatthew G. Knepley 
179432d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
179532d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
179632d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
179732d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
179832d2bbc9SMatthew G. Knepley 
179932d2bbc9SMatthew G. Knepley + dim - the spatial dimension
180032d2bbc9SMatthew G. Knepley . Nf - the number of fields
180132d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
180232d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
180332d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
180432d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
180532d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
180632d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
180732d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
180832d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
180932d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
181032d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
181132d2bbc9SMatthew G. Knepley . t - current time
181232d2bbc9SMatthew G. Knepley . x - coordinates of the current point
181332d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
181432d2bbc9SMatthew G. Knepley 
181532d2bbc9SMatthew G. Knepley   Level: intermediate
181632d2bbc9SMatthew G. Knepley 
181732d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
181832d2bbc9SMatthew G. Knepley @*/
181932d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f,
182032d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
182132d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
182232d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
18233fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
182432d2bbc9SMatthew G. Knepley {
182532d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
182632d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
182732d2bbc9SMatthew 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);
182832d2bbc9SMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = prob->update[f];}
182932d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
183032d2bbc9SMatthew G. Knepley }
183132d2bbc9SMatthew G. Knepley 
183232d2bbc9SMatthew G. Knepley /*@C
18333fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
183432d2bbc9SMatthew G. Knepley 
183532d2bbc9SMatthew G. Knepley   Not collective
183632d2bbc9SMatthew G. Knepley 
183732d2bbc9SMatthew G. Knepley   Input Parameters:
183832d2bbc9SMatthew G. Knepley + prob   - The PetscDS
183932d2bbc9SMatthew G. Knepley . f      - The field number
184032d2bbc9SMatthew G. Knepley - update - update function
184132d2bbc9SMatthew G. Knepley 
184232d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
184332d2bbc9SMatthew G. Knepley 
184432d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
184532d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
184632d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
184732d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
184832d2bbc9SMatthew G. Knepley 
184932d2bbc9SMatthew G. Knepley + dim - the spatial dimension
185032d2bbc9SMatthew G. Knepley . Nf - the number of fields
185132d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
185232d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
185332d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
185432d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
185532d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
185632d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
185732d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
185832d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
185932d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
186032d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
186132d2bbc9SMatthew G. Knepley . t - current time
186232d2bbc9SMatthew G. Knepley . x - coordinates of the current point
186332d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
186432d2bbc9SMatthew G. Knepley 
186532d2bbc9SMatthew G. Knepley   Level: intermediate
186632d2bbc9SMatthew G. Knepley 
186732d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
186832d2bbc9SMatthew G. Knepley @*/
186932d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f,
187032d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
187132d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
187232d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
18733fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
187432d2bbc9SMatthew G. Knepley {
187532d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
187632d2bbc9SMatthew G. Knepley 
187732d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
187832d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
187932d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
188032d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
188132d2bbc9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
188232d2bbc9SMatthew G. Knepley   prob->update[f] = update;
188332d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
188432d2bbc9SMatthew G. Knepley }
188532d2bbc9SMatthew G. Knepley 
18860c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx)
18870c2f2876SMatthew G. Knepley {
18880c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18890c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18900c2f2876SMatthew 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);
18910c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
18920c2f2876SMatthew G. Knepley   *ctx = prob->ctx[f];
18930c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18940c2f2876SMatthew G. Knepley }
18950c2f2876SMatthew G. Knepley 
18960c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx)
18970c2f2876SMatthew G. Knepley {
18980c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
18990c2f2876SMatthew G. Knepley 
19000c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19010c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19020c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19030c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
19040c2f2876SMatthew G. Knepley   prob->ctx[f] = ctx;
19050c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19060c2f2876SMatthew G. Knepley }
19070c2f2876SMatthew G. Knepley 
1908194d53e6SMatthew G. Knepley /*@C
1909194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
1910194d53e6SMatthew G. Knepley 
1911194d53e6SMatthew G. Knepley   Not collective
1912194d53e6SMatthew G. Knepley 
1913194d53e6SMatthew G. Knepley   Input Parameters:
1914194d53e6SMatthew G. Knepley + prob - The PetscDS
1915194d53e6SMatthew G. Knepley - f    - The test field number
1916194d53e6SMatthew G. Knepley 
1917194d53e6SMatthew G. Knepley   Output Parameters:
1918194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
1919194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1920194d53e6SMatthew G. Knepley 
1921194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1922194d53e6SMatthew G. Knepley 
1923194d53e6SMatthew 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
1924194d53e6SMatthew G. Knepley 
1925194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1926194d53e6SMatthew G. Knepley 
192730b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1928194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1929194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
193030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1931194d53e6SMatthew G. Knepley 
1932194d53e6SMatthew G. Knepley + dim - the spatial dimension
1933194d53e6SMatthew G. Knepley . Nf - the number of fields
1934194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1935194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1936194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1937194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1938194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1939194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1940194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1941194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1942194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1943194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1944194d53e6SMatthew G. Knepley . t - current time
1945194d53e6SMatthew G. Knepley . x - coordinates of the current point
1946194d53e6SMatthew G. Knepley . n - unit normal at the current point
194797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
194897b6e6e8SMatthew G. Knepley . constants - constant parameters
1949194d53e6SMatthew G. Knepley - f0 - output values at the current point
1950194d53e6SMatthew G. Knepley 
1951194d53e6SMatthew G. Knepley   Level: intermediate
1952194d53e6SMatthew G. Knepley 
1953194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
1954194d53e6SMatthew G. Knepley @*/
19552764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f,
195630b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1957194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1958194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
195997b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
196030b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1961194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1962194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
196397b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
19642764a2aaSMatthew G. Knepley {
19652764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19662764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19672764a2aaSMatthew 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);
19682764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];}
19692764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];}
19702764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
19712764a2aaSMatthew G. Knepley }
19722764a2aaSMatthew G. Knepley 
1973194d53e6SMatthew G. Knepley /*@C
1974194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
1975194d53e6SMatthew G. Knepley 
1976194d53e6SMatthew G. Knepley   Not collective
1977194d53e6SMatthew G. Knepley 
1978194d53e6SMatthew G. Knepley   Input Parameters:
1979194d53e6SMatthew G. Knepley + prob - The PetscDS
1980194d53e6SMatthew G. Knepley . f    - The test field number
1981194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
1982194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1983194d53e6SMatthew G. Knepley 
1984194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1985194d53e6SMatthew G. Knepley 
1986194d53e6SMatthew 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
1987194d53e6SMatthew G. Knepley 
1988194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1989194d53e6SMatthew G. Knepley 
199030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1991194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1992194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
199330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1994194d53e6SMatthew G. Knepley 
1995194d53e6SMatthew G. Knepley + dim - the spatial dimension
1996194d53e6SMatthew G. Knepley . Nf - the number of fields
1997194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1998194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1999194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2000194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2001194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2002194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2003194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2004194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2005194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2006194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2007194d53e6SMatthew G. Knepley . t - current time
2008194d53e6SMatthew G. Knepley . x - coordinates of the current point
2009194d53e6SMatthew G. Knepley . n - unit normal at the current point
201097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
201197b6e6e8SMatthew G. Knepley . constants - constant parameters
2012194d53e6SMatthew G. Knepley - f0 - output values at the current point
2013194d53e6SMatthew G. Knepley 
2014194d53e6SMatthew G. Knepley   Level: intermediate
2015194d53e6SMatthew G. Knepley 
2016194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
2017194d53e6SMatthew G. Knepley @*/
20182764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f,
201930b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2020194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2021194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
202297b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
202330b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2024194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2025194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
202697b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
20272764a2aaSMatthew G. Knepley {
20282764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
20292764a2aaSMatthew G. Knepley 
20302764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20312764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20322764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
20332764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
20342764a2aaSMatthew G. Knepley   if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;}
20352764a2aaSMatthew G. Knepley   if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;}
20362764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20372764a2aaSMatthew G. Knepley }
20382764a2aaSMatthew G. Knepley 
2039194d53e6SMatthew G. Knepley /*@C
2040194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2041194d53e6SMatthew G. Knepley 
2042194d53e6SMatthew G. Knepley   Not collective
2043194d53e6SMatthew G. Knepley 
2044194d53e6SMatthew G. Knepley   Input Parameters:
2045194d53e6SMatthew G. Knepley + prob - The PetscDS
2046194d53e6SMatthew G. Knepley . f    - The test field number
2047194d53e6SMatthew G. Knepley - g    - The field number
2048194d53e6SMatthew G. Knepley 
2049194d53e6SMatthew G. Knepley   Output Parameters:
2050194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2051194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2052194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2053194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2054194d53e6SMatthew G. Knepley 
2055194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2056194d53e6SMatthew G. Knepley 
2057194d53e6SMatthew 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
2058194d53e6SMatthew G. Knepley 
2059194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2060194d53e6SMatthew G. Knepley 
206130b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2062194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2063194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
206430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2065194d53e6SMatthew G. Knepley 
2066194d53e6SMatthew G. Knepley + dim - the spatial dimension
2067194d53e6SMatthew G. Knepley . Nf - the number of fields
2068194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2069194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2070194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2071194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2072194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2073194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2074194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2075194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2076194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2077194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2078194d53e6SMatthew G. Knepley . t - current time
20792aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2080194d53e6SMatthew G. Knepley . x - coordinates of the current point
2081194d53e6SMatthew G. Knepley . n - normal at the current point
208297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
208397b6e6e8SMatthew G. Knepley . constants - constant parameters
2084194d53e6SMatthew G. Knepley - g0 - output values at the current point
2085194d53e6SMatthew G. Knepley 
2086194d53e6SMatthew G. Knepley   Level: intermediate
2087194d53e6SMatthew G. Knepley 
2088194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2089194d53e6SMatthew G. Knepley @*/
20902764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
209130b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2092194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2093194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
209497b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
209530b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2096194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2097194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
209897b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
209930b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2100194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2101194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
210297b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
210330b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2104194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2105194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
210697b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
21072764a2aaSMatthew G. Knepley {
21082764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21092764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21102764a2aaSMatthew 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);
21112764a2aaSMatthew G. Knepley   if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf);
21122764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];}
21132764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];}
21142764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];}
21152764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];}
21162764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21172764a2aaSMatthew G. Knepley }
21182764a2aaSMatthew G. Knepley 
2119194d53e6SMatthew G. Knepley /*@C
2120194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2121194d53e6SMatthew G. Knepley 
2122194d53e6SMatthew G. Knepley   Not collective
2123194d53e6SMatthew G. Knepley 
2124194d53e6SMatthew G. Knepley   Input Parameters:
2125194d53e6SMatthew G. Knepley + prob - The PetscDS
2126194d53e6SMatthew G. Knepley . f    - The test field number
2127194d53e6SMatthew G. Knepley . g    - The field number
2128194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2129194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2130194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2131194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2132194d53e6SMatthew G. Knepley 
2133194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2134194d53e6SMatthew G. Knepley 
2135194d53e6SMatthew 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
2136194d53e6SMatthew G. Knepley 
2137194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2138194d53e6SMatthew G. Knepley 
213930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2140194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2141194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
214230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2143194d53e6SMatthew G. Knepley 
2144194d53e6SMatthew G. Knepley + dim - the spatial dimension
2145194d53e6SMatthew G. Knepley . Nf - the number of fields
2146194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2147194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2148194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2149194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2150194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2151194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2152194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2153194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2154194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2155194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2156194d53e6SMatthew G. Knepley . t - current time
21572aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2158194d53e6SMatthew G. Knepley . x - coordinates of the current point
2159194d53e6SMatthew G. Knepley . n - normal at the current point
216097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
216197b6e6e8SMatthew G. Knepley . constants - constant parameters
2162194d53e6SMatthew G. Knepley - g0 - output values at the current point
2163194d53e6SMatthew G. Knepley 
2164194d53e6SMatthew G. Knepley   Level: intermediate
2165194d53e6SMatthew G. Knepley 
2166194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2167194d53e6SMatthew G. Knepley @*/
21682764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
216930b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2170194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2171194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
217297b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
217330b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2174194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2175194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
217697b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
217730b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2178194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2179194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
218097b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
218130b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2182194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2183194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
218497b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
21852764a2aaSMatthew G. Knepley {
21862764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21872764a2aaSMatthew G. Knepley 
21882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21902764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
21912764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
21922764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
21932764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
21942764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21952764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
21962764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
21972764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+0] = g0;
21982764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+1] = g1;
21992764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+2] = g2;
22002764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+3] = g3;
22012764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22022764a2aaSMatthew G. Knepley }
22032764a2aaSMatthew G. Knepley 
22040d3e9b51SMatthew G. Knepley /*@C
2205c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2206c371a6d1SMatthew G. Knepley 
2207c371a6d1SMatthew G. Knepley   Not collective
2208c371a6d1SMatthew G. Knepley 
2209c371a6d1SMatthew G. Knepley   Input Parameters:
2210c371a6d1SMatthew G. Knepley + prob - The PetscDS
2211c371a6d1SMatthew G. Knepley - f    - The test field number
2212c371a6d1SMatthew G. Knepley 
2213c371a6d1SMatthew G. Knepley   Output Parameter:
2214c371a6d1SMatthew G. Knepley . exactSol - exact solution for the test field
2215c371a6d1SMatthew G. Knepley 
2216c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2217c371a6d1SMatthew G. Knepley 
2218c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2219c371a6d1SMatthew G. Knepley 
2220c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2221c371a6d1SMatthew G. Knepley . t - current time
2222c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2223c371a6d1SMatthew G. Knepley . Nc - the number of field components
2224c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2225c371a6d1SMatthew G. Knepley - ctx - a user context
2226c371a6d1SMatthew G. Knepley 
2227c371a6d1SMatthew G. Knepley   Level: intermediate
2228c371a6d1SMatthew G. Knepley 
2229c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution()
2230c371a6d1SMatthew G. Knepley @*/
2231c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2232c371a6d1SMatthew G. Knepley {
2233c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2234c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2235c371a6d1SMatthew 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);
2236c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
2237c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2238c371a6d1SMatthew G. Knepley }
2239c371a6d1SMatthew G. Knepley 
2240c371a6d1SMatthew G. Knepley /*@C
2241c371a6d1SMatthew G. Knepley   PetscDSSetExactSolution - Get the pointwise exact solution function for a given test field
2242c371a6d1SMatthew G. Knepley 
2243c371a6d1SMatthew G. Knepley   Not collective
2244c371a6d1SMatthew G. Knepley 
2245c371a6d1SMatthew G. Knepley   Input Parameters:
2246c371a6d1SMatthew G. Knepley + prob - The PetscDS
2247c371a6d1SMatthew G. Knepley . f    - The test field number
2248c371a6d1SMatthew G. Knepley - sol  - solution function for the test fields
2249c371a6d1SMatthew G. Knepley 
2250c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2251c371a6d1SMatthew G. Knepley 
2252c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2253c371a6d1SMatthew G. Knepley 
2254c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2255c371a6d1SMatthew G. Knepley . t - current time
2256c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2257c371a6d1SMatthew G. Knepley . Nc - the number of field components
2258c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2259c371a6d1SMatthew G. Knepley - ctx - a user context
2260c371a6d1SMatthew G. Knepley 
2261c371a6d1SMatthew G. Knepley   Level: intermediate
2262c371a6d1SMatthew G. Knepley 
2263c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2264c371a6d1SMatthew G. Knepley @*/
2265c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2266c371a6d1SMatthew G. Knepley {
2267c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2268c371a6d1SMatthew G. Knepley 
2269c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2270c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2271c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2272c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2273c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
2274c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2275c371a6d1SMatthew G. Knepley }
2276c371a6d1SMatthew G. Knepley 
22775638fd0eSMatthew G. Knepley /*@C
227897b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
227997b6e6e8SMatthew G. Knepley 
228097b6e6e8SMatthew G. Knepley   Not collective
228197b6e6e8SMatthew G. Knepley 
228297b6e6e8SMatthew G. Knepley   Input Parameter:
228397b6e6e8SMatthew G. Knepley . prob - The PetscDS object
228497b6e6e8SMatthew G. Knepley 
228597b6e6e8SMatthew G. Knepley   Output Parameters:
228697b6e6e8SMatthew G. Knepley + numConstants - The number of constants
228797b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
228897b6e6e8SMatthew G. Knepley 
228997b6e6e8SMatthew G. Knepley   Level: intermediate
229097b6e6e8SMatthew G. Knepley 
229197b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
229297b6e6e8SMatthew G. Knepley @*/
229397b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
229497b6e6e8SMatthew G. Knepley {
229597b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
229697b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
229797b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
229897b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
229997b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
230097b6e6e8SMatthew G. Knepley }
230197b6e6e8SMatthew G. Knepley 
23020d3e9b51SMatthew G. Knepley /*@C
230397b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
230497b6e6e8SMatthew G. Knepley 
230597b6e6e8SMatthew G. Knepley   Not collective
230697b6e6e8SMatthew G. Knepley 
230797b6e6e8SMatthew G. Knepley   Input Parameters:
230897b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
230997b6e6e8SMatthew G. Knepley . numConstants - The number of constants
231097b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
231197b6e6e8SMatthew G. Knepley 
231297b6e6e8SMatthew G. Knepley   Level: intermediate
231397b6e6e8SMatthew G. Knepley 
231497b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
231597b6e6e8SMatthew G. Knepley @*/
231697b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
231797b6e6e8SMatthew G. Knepley {
231897b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
231997b6e6e8SMatthew G. Knepley 
232097b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
232197b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
232297b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
232397b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
232497b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
232597b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
232697b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
232720be0f5bSMatthew G. Knepley     } else {
232820be0f5bSMatthew G. Knepley       prob->constants = NULL;
232920be0f5bSMatthew G. Knepley     }
233020be0f5bSMatthew G. Knepley   }
233120be0f5bSMatthew G. Knepley   if (prob->numConstants) {
233220be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
233397b6e6e8SMatthew G. Knepley     ierr = PetscMemcpy(prob->constants, constants, prob->numConstants * sizeof(PetscScalar));CHKERRQ(ierr);
233497b6e6e8SMatthew G. Knepley   }
233597b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
233697b6e6e8SMatthew G. Knepley }
233797b6e6e8SMatthew G. Knepley 
23384cd1e086SMatthew G. Knepley /*@
23394cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
23404cd1e086SMatthew G. Knepley 
23414cd1e086SMatthew G. Knepley   Not collective
23424cd1e086SMatthew G. Knepley 
23434cd1e086SMatthew G. Knepley   Input Parameters:
23444cd1e086SMatthew G. Knepley + prob - The PetscDS object
23454cd1e086SMatthew G. Knepley - disc - The discretization object
23464cd1e086SMatthew G. Knepley 
23474cd1e086SMatthew G. Knepley   Output Parameter:
23484cd1e086SMatthew G. Knepley . f - The field number
23494cd1e086SMatthew G. Knepley 
23504cd1e086SMatthew G. Knepley   Level: beginner
23514cd1e086SMatthew G. Knepley 
2352f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
23534cd1e086SMatthew G. Knepley @*/
23544cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
23554cd1e086SMatthew G. Knepley {
23564cd1e086SMatthew G. Knepley   PetscInt g;
23574cd1e086SMatthew G. Knepley 
23584cd1e086SMatthew G. Knepley   PetscFunctionBegin;
23594cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23604cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
23614cd1e086SMatthew G. Knepley   *f = -1;
23624cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
23634cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
23644cd1e086SMatthew G. Knepley   *f = g;
23654cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
23664cd1e086SMatthew G. Knepley }
23674cd1e086SMatthew G. Knepley 
23684cd1e086SMatthew G. Knepley /*@
23694cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
23704cd1e086SMatthew G. Knepley 
23714cd1e086SMatthew G. Knepley   Not collective
23724cd1e086SMatthew G. Knepley 
23734cd1e086SMatthew G. Knepley   Input Parameters:
23744cd1e086SMatthew G. Knepley + prob - The PetscDS object
23754cd1e086SMatthew G. Knepley - f - The field number
23764cd1e086SMatthew G. Knepley 
23774cd1e086SMatthew G. Knepley   Output Parameter:
23784cd1e086SMatthew G. Knepley . size - The size
23794cd1e086SMatthew G. Knepley 
23804cd1e086SMatthew G. Knepley   Level: beginner
23814cd1e086SMatthew G. Knepley 
2382f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
23834cd1e086SMatthew G. Knepley @*/
23844cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
23854cd1e086SMatthew G. Knepley {
23862166fd64SMatthew G. Knepley   PetscErrorCode ierr;
23872166fd64SMatthew G. Knepley 
23884cd1e086SMatthew G. Knepley   PetscFunctionBegin;
23894cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23904cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
23914cd1e086SMatthew 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);
23922166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2393d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
23944cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
23954cd1e086SMatthew G. Knepley }
23964cd1e086SMatthew G. Knepley 
2397bc4ae4beSMatthew G. Knepley /*@
2398bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2399bc4ae4beSMatthew G. Knepley 
2400bc4ae4beSMatthew G. Knepley   Not collective
2401bc4ae4beSMatthew G. Knepley 
2402bc4ae4beSMatthew G. Knepley   Input Parameters:
2403bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2404bc4ae4beSMatthew G. Knepley - f - The field number
2405bc4ae4beSMatthew G. Knepley 
2406bc4ae4beSMatthew G. Knepley   Output Parameter:
2407bc4ae4beSMatthew G. Knepley . off - The offset
2408bc4ae4beSMatthew G. Knepley 
2409bc4ae4beSMatthew G. Knepley   Level: beginner
2410bc4ae4beSMatthew G. Knepley 
2411f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2412bc4ae4beSMatthew G. Knepley @*/
24132764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
24142764a2aaSMatthew G. Knepley {
24154cd1e086SMatthew G. Knepley   PetscInt       size, g;
24162764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24172764a2aaSMatthew G. Knepley 
24182764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24192764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24202764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
24212764a2aaSMatthew 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);
24222764a2aaSMatthew G. Knepley   *off = 0;
24232764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
24244cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
24254cd1e086SMatthew G. Knepley     *off += size;
24262764a2aaSMatthew G. Knepley   }
24272764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
24282764a2aaSMatthew G. Knepley }
24292764a2aaSMatthew G. Knepley 
2430bc4ae4beSMatthew G. Knepley /*@
243147e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2432bc4ae4beSMatthew G. Knepley 
2433bc4ae4beSMatthew G. Knepley   Not collective
2434bc4ae4beSMatthew G. Knepley 
243547e57110SSander Arens   Input Parameter:
243647e57110SSander Arens . prob - The PetscDS object
2437bc4ae4beSMatthew G. Knepley 
2438bc4ae4beSMatthew G. Knepley   Output Parameter:
243947e57110SSander Arens . dimensions - The number of dimensions
2440bc4ae4beSMatthew G. Knepley 
2441bc4ae4beSMatthew G. Knepley   Level: beginner
2442bc4ae4beSMatthew G. Knepley 
244347e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2444bc4ae4beSMatthew G. Knepley @*/
244547e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
24462764a2aaSMatthew G. Knepley {
24472764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24482764a2aaSMatthew G. Knepley 
24492764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24502764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
245147e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
245247e57110SSander Arens   PetscValidPointer(dimensions, 2);
245347e57110SSander Arens   *dimensions = prob->Nb;
245447e57110SSander Arens   PetscFunctionReturn(0);
24556ce16762SMatthew G. Knepley }
245647e57110SSander Arens 
245747e57110SSander Arens /*@
245847e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
245947e57110SSander Arens 
246047e57110SSander Arens   Not collective
246147e57110SSander Arens 
246247e57110SSander Arens   Input Parameter:
246347e57110SSander Arens . prob - The PetscDS object
246447e57110SSander Arens 
246547e57110SSander Arens   Output Parameter:
246647e57110SSander Arens . components - The number of components
246747e57110SSander Arens 
246847e57110SSander Arens   Level: beginner
246947e57110SSander Arens 
247047e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
247147e57110SSander Arens @*/
247247e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
247347e57110SSander Arens {
247447e57110SSander Arens   PetscErrorCode ierr;
247547e57110SSander Arens 
247647e57110SSander Arens   PetscFunctionBegin;
247747e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
247847e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
247947e57110SSander Arens   PetscValidPointer(components, 2);
248047e57110SSander Arens   *components = prob->Nc;
24816ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
24826ce16762SMatthew G. Knepley }
24836ce16762SMatthew G. Knepley 
24846ce16762SMatthew G. Knepley /*@
24856ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
24866ce16762SMatthew G. Knepley 
24876ce16762SMatthew G. Knepley   Not collective
24886ce16762SMatthew G. Knepley 
24896ce16762SMatthew G. Knepley   Input Parameters:
24906ce16762SMatthew G. Knepley + prob - The PetscDS object
24916ce16762SMatthew G. Knepley - f - The field number
24926ce16762SMatthew G. Knepley 
24936ce16762SMatthew G. Knepley   Output Parameter:
24946ce16762SMatthew G. Knepley . off - The offset
24956ce16762SMatthew G. Knepley 
24966ce16762SMatthew G. Knepley   Level: beginner
24976ce16762SMatthew G. Knepley 
2498f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
24996ce16762SMatthew G. Knepley @*/
25006ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
25016ce16762SMatthew G. Knepley {
25026ce16762SMatthew G. Knepley   PetscFunctionBegin;
25036ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25046ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
25056ce16762SMatthew 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);
250647e57110SSander Arens   *off = prob->off[f];
25072764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25082764a2aaSMatthew G. Knepley }
25092764a2aaSMatthew G. Knepley 
2510194d53e6SMatthew G. Knepley /*@
2511194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2512194d53e6SMatthew G. Knepley 
2513194d53e6SMatthew G. Knepley   Not collective
2514194d53e6SMatthew G. Knepley 
2515194d53e6SMatthew G. Knepley   Input Parameter:
2516194d53e6SMatthew G. Knepley . prob - The PetscDS object
2517194d53e6SMatthew G. Knepley 
2518194d53e6SMatthew G. Knepley   Output Parameter:
2519194d53e6SMatthew G. Knepley . offsets - The offsets
2520194d53e6SMatthew G. Knepley 
2521194d53e6SMatthew G. Knepley   Level: beginner
2522194d53e6SMatthew G. Knepley 
2523f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2524194d53e6SMatthew G. Knepley @*/
2525194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2526194d53e6SMatthew G. Knepley {
2527194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2528194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2529194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2530194d53e6SMatthew G. Knepley   *offsets = prob->off;
2531194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2532194d53e6SMatthew G. Knepley }
2533194d53e6SMatthew G. Knepley 
2534194d53e6SMatthew G. Knepley /*@
2535194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2536194d53e6SMatthew G. Knepley 
2537194d53e6SMatthew G. Knepley   Not collective
2538194d53e6SMatthew G. Knepley 
2539194d53e6SMatthew G. Knepley   Input Parameter:
2540194d53e6SMatthew G. Knepley . prob - The PetscDS object
2541194d53e6SMatthew G. Knepley 
2542194d53e6SMatthew G. Knepley   Output Parameter:
2543194d53e6SMatthew G. Knepley . offsets - The offsets
2544194d53e6SMatthew G. Knepley 
2545194d53e6SMatthew G. Knepley   Level: beginner
2546194d53e6SMatthew G. Knepley 
2547f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2548194d53e6SMatthew G. Knepley @*/
2549194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2550194d53e6SMatthew G. Knepley {
2551194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2552194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2553194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2554194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
2555194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2556194d53e6SMatthew G. Knepley }
2557194d53e6SMatthew G. Knepley 
255868c9edb9SMatthew G. Knepley /*@C
255968c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
256068c9edb9SMatthew G. Knepley 
256168c9edb9SMatthew G. Knepley   Not collective
256268c9edb9SMatthew G. Knepley 
256368c9edb9SMatthew G. Knepley   Input Parameter:
256468c9edb9SMatthew G. Knepley . prob - The PetscDS object
256568c9edb9SMatthew G. Knepley 
256668c9edb9SMatthew G. Knepley   Output Parameters:
256768c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
256868c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
256968c9edb9SMatthew G. Knepley 
257068c9edb9SMatthew G. Knepley   Level: intermediate
257168c9edb9SMatthew G. Knepley 
2572f744cafaSSander Arens .seealso: PetscDSCreate()
257368c9edb9SMatthew G. Knepley @*/
25742764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
25752764a2aaSMatthew G. Knepley {
25762764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25772764a2aaSMatthew G. Knepley 
25782764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25792764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25802764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25812764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basis;}
25822764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;}
25832764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25842764a2aaSMatthew G. Knepley }
25852764a2aaSMatthew G. Knepley 
258668c9edb9SMatthew G. Knepley /*@C
25874d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
258868c9edb9SMatthew G. Knepley 
258968c9edb9SMatthew G. Knepley   Not collective
259068c9edb9SMatthew G. Knepley 
259168c9edb9SMatthew G. Knepley   Input Parameter:
259268c9edb9SMatthew G. Knepley . prob - The PetscDS object
259368c9edb9SMatthew G. Knepley 
259468c9edb9SMatthew G. Knepley   Output Parameters:
25954d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points
25964d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points
259768c9edb9SMatthew G. Knepley 
259868c9edb9SMatthew G. Knepley   Level: intermediate
259968c9edb9SMatthew G. Knepley 
260068c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
260168c9edb9SMatthew G. Knepley @*/
26024d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
26032764a2aaSMatthew G. Knepley {
26042764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
26052764a2aaSMatthew G. Knepley 
26062764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26072764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26082764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
26094d0b9603SSander Arens   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basisFace;}
26104d0b9603SSander Arens   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;}
26112764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26122764a2aaSMatthew G. Knepley }
26132764a2aaSMatthew G. Knepley 
26142764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
26152764a2aaSMatthew G. Knepley {
26162764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
26172764a2aaSMatthew G. Knepley 
26182764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26192764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26202764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
26212764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
26222764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
26232764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
26242764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26252764a2aaSMatthew G. Knepley }
26262764a2aaSMatthew G. Knepley 
26272764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
26282764a2aaSMatthew G. Knepley {
26292764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
26302764a2aaSMatthew G. Knepley 
26312764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26322764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26332764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
26342764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
26352764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
26362764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
26372764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
26382764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
26392764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
26402764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26412764a2aaSMatthew G. Knepley }
26422764a2aaSMatthew G. Knepley 
26432764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer)
26442764a2aaSMatthew G. Knepley {
26452764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
26462764a2aaSMatthew G. Knepley 
26472764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26482764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26492764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
26502764a2aaSMatthew G. Knepley   if (x)           {PetscValidPointer(x, 2);           *x           = prob->x;}
26512764a2aaSMatthew G. Knepley   if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;}
26522764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26532764a2aaSMatthew G. Knepley }
26542764a2aaSMatthew G. Knepley 
265558ebd649SToby Isaac /*@C
265658ebd649SToby Isaac   PetscDSAddBoundary - Add a boundary condition to the model
265758ebd649SToby Isaac 
265858ebd649SToby Isaac   Input Parameters:
265958ebd649SToby Isaac + ds          - The PetscDS object
26602d47a189SJulian Andrej . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
266158ebd649SToby Isaac . name        - The BC name
266258ebd649SToby Isaac . labelname   - The label defining constrained points
266358ebd649SToby Isaac . field       - The field to constrain
2664e8ecbf3fSStefano Zampini . numcomps    - The number of constrained field components (0 will constrain all fields)
266558ebd649SToby Isaac . comps       - An array of constrained component numbers
266658ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
266758ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
266858ebd649SToby Isaac . ids         - An array of ids for constrained points
266958ebd649SToby Isaac - ctx         - An optional user context for bcFunc
267058ebd649SToby Isaac 
267158ebd649SToby Isaac   Options Database Keys:
267258ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
267358ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
267458ebd649SToby Isaac 
267558ebd649SToby Isaac   Level: developer
267658ebd649SToby Isaac 
267758ebd649SToby Isaac .seealso: PetscDSGetBoundary()
267858ebd649SToby Isaac @*/
2679a30ec4eaSSatish Balay PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), PetscInt numids, const PetscInt *ids, void *ctx)
268058ebd649SToby Isaac {
268158ebd649SToby Isaac   DSBoundary     b;
268258ebd649SToby Isaac   PetscErrorCode ierr;
268358ebd649SToby Isaac 
268458ebd649SToby Isaac   PetscFunctionBegin;
268558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
268658ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
268758ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
268858ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
268958ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
269058ebd649SToby Isaac   if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
269158ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
269258ebd649SToby Isaac   if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
2693f971fd6bSMatthew G. Knepley   b->type            = type;
269458ebd649SToby Isaac   b->field           = field;
269558ebd649SToby Isaac   b->numcomps        = numcomps;
269658ebd649SToby Isaac   b->func            = bcFunc;
269758ebd649SToby Isaac   b->numids          = numids;
269858ebd649SToby Isaac   b->ctx             = ctx;
269958ebd649SToby Isaac   b->next            = ds->boundary;
270058ebd649SToby Isaac   ds->boundary       = b;
270158ebd649SToby Isaac   PetscFunctionReturn(0);
270258ebd649SToby Isaac }
270358ebd649SToby Isaac 
2704b67eacb3SMatthew G. Knepley /*@C
2705b67eacb3SMatthew G. Knepley   PetscDSUpdateBoundary - Change a boundary condition for the model
2706b67eacb3SMatthew G. Knepley 
2707b67eacb3SMatthew G. Knepley   Input Parameters:
2708b67eacb3SMatthew G. Knepley + ds          - The PetscDS object
2709b67eacb3SMatthew G. Knepley . bd          - The boundary condition number
2710b67eacb3SMatthew G. Knepley . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
2711b67eacb3SMatthew G. Knepley . name        - The BC name
2712b67eacb3SMatthew G. Knepley . labelname   - The label defining constrained points
2713b67eacb3SMatthew G. Knepley . field       - The field to constrain
2714b67eacb3SMatthew G. Knepley . numcomps    - The number of constrained field components
2715b67eacb3SMatthew G. Knepley . comps       - An array of constrained component numbers
2716b67eacb3SMatthew G. Knepley . bcFunc      - A pointwise function giving boundary values
2717b67eacb3SMatthew G. Knepley . numids      - The number of DMLabel ids for constrained points
2718b67eacb3SMatthew G. Knepley . ids         - An array of ids for constrained points
2719b67eacb3SMatthew G. Knepley - ctx         - An optional user context for bcFunc
2720b67eacb3SMatthew G. Knepley 
27219a6efb6aSMatthew G. Knepley   Note: The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from PetscDSGetNumBoundary().
27229a6efb6aSMatthew G. Knepley 
2723b67eacb3SMatthew G. Knepley   Level: developer
2724b67eacb3SMatthew G. Knepley 
27259a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary()
2726b67eacb3SMatthew G. Knepley @*/
2727b67eacb3SMatthew G. Knepley PetscErrorCode PetscDSUpdateBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), PetscInt numids, const PetscInt *ids, void *ctx)
2728b67eacb3SMatthew G. Knepley {
2729b67eacb3SMatthew G. Knepley   DSBoundary     b = ds->boundary;
2730b67eacb3SMatthew G. Knepley   PetscInt       n = 0;
2731b67eacb3SMatthew G. Knepley   PetscErrorCode ierr;
2732b67eacb3SMatthew G. Knepley 
2733b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
2734b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2735b67eacb3SMatthew G. Knepley   while (b) {
2736b67eacb3SMatthew G. Knepley     if (n == bd) break;
2737b67eacb3SMatthew G. Knepley     b = b->next;
2738b67eacb3SMatthew G. Knepley     ++n;
2739b67eacb3SMatthew G. Knepley   }
2740b67eacb3SMatthew G. Knepley   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
2741b67eacb3SMatthew G. Knepley   if (name) {
2742b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
2743b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
2744b67eacb3SMatthew G. Knepley   }
2745b67eacb3SMatthew G. Knepley   if (labelname) {
2746b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2747b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
2748b67eacb3SMatthew G. Knepley   }
2749b67eacb3SMatthew G. Knepley   if (numcomps >= 0 && numcomps != b->numcomps) {
2750b67eacb3SMatthew G. Knepley     b->numcomps = numcomps;
2751b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2752b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
2753b67eacb3SMatthew G. Knepley     if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
2754b67eacb3SMatthew G. Knepley   }
2755b67eacb3SMatthew G. Knepley   if (numids >= 0 && numids != b->numids) {
2756b67eacb3SMatthew G. Knepley     b->numids = numids;
2757b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2758b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
2759b67eacb3SMatthew G. Knepley     if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
2760b67eacb3SMatthew G. Knepley   }
2761b67eacb3SMatthew G. Knepley   b->type = type;
2762b67eacb3SMatthew G. Knepley   if (field >= 0) {b->field  = field;}
2763b67eacb3SMatthew G. Knepley   if (bcFunc)     {b->func   = bcFunc;}
2764b67eacb3SMatthew G. Knepley   if (ctx)        {b->ctx    = ctx;}
2765b67eacb3SMatthew G. Knepley   PetscFunctionReturn(0);
2766b67eacb3SMatthew G. Knepley }
2767b67eacb3SMatthew G. Knepley 
276858ebd649SToby Isaac /*@
276958ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
277058ebd649SToby Isaac 
277158ebd649SToby Isaac   Input Parameters:
277258ebd649SToby Isaac . ds - The PetscDS object
277358ebd649SToby Isaac 
277458ebd649SToby Isaac   Output Parameters:
277558ebd649SToby Isaac . numBd - The number of BC
277658ebd649SToby Isaac 
277758ebd649SToby Isaac   Level: intermediate
277858ebd649SToby Isaac 
277958ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
278058ebd649SToby Isaac @*/
278158ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
278258ebd649SToby Isaac {
278358ebd649SToby Isaac   DSBoundary b = ds->boundary;
278458ebd649SToby Isaac 
278558ebd649SToby Isaac   PetscFunctionBegin;
278658ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
278758ebd649SToby Isaac   PetscValidPointer(numBd, 2);
278858ebd649SToby Isaac   *numBd = 0;
278958ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
279058ebd649SToby Isaac   PetscFunctionReturn(0);
279158ebd649SToby Isaac }
279258ebd649SToby Isaac 
279358ebd649SToby Isaac /*@C
27949a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
279558ebd649SToby Isaac 
279658ebd649SToby Isaac   Input Parameters:
279758ebd649SToby Isaac + ds          - The PetscDS object
279858ebd649SToby Isaac - bd          - The BC number
279958ebd649SToby Isaac 
280058ebd649SToby Isaac   Output Parameters:
28012d47a189SJulian Andrej + type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
280258ebd649SToby Isaac . name        - The BC name
280358ebd649SToby Isaac . labelname   - The label defining constrained points
280458ebd649SToby Isaac . field       - The field to constrain
280558ebd649SToby Isaac . numcomps    - The number of constrained field components
280658ebd649SToby Isaac . comps       - An array of constrained component numbers
280758ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
280858ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
280958ebd649SToby Isaac . ids         - An array of ids for constrained points
281058ebd649SToby Isaac - ctx         - An optional user context for bcFunc
281158ebd649SToby Isaac 
281258ebd649SToby Isaac   Options Database Keys:
281358ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
281458ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
281558ebd649SToby Isaac 
281658ebd649SToby Isaac   Level: developer
281758ebd649SToby Isaac 
281858ebd649SToby Isaac .seealso: PetscDSAddBoundary()
281958ebd649SToby Isaac @*/
2820a30ec4eaSSatish Balay PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType *type, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(void), PetscInt *numids, const PetscInt **ids, void **ctx)
282158ebd649SToby Isaac {
282258ebd649SToby Isaac   DSBoundary b    = ds->boundary;
282358ebd649SToby Isaac   PetscInt   n    = 0;
282458ebd649SToby Isaac 
282558ebd649SToby Isaac   PetscFunctionBegin;
282658ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
282758ebd649SToby Isaac   while (b) {
282858ebd649SToby Isaac     if (n == bd) break;
282958ebd649SToby Isaac     b = b->next;
283058ebd649SToby Isaac     ++n;
283158ebd649SToby Isaac   }
283258ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
2833f971fd6bSMatthew G. Knepley   if (type) {
2834f971fd6bSMatthew G. Knepley     PetscValidPointer(type, 3);
2835f971fd6bSMatthew G. Knepley     *type = b->type;
283658ebd649SToby Isaac   }
283758ebd649SToby Isaac   if (name) {
283858ebd649SToby Isaac     PetscValidPointer(name, 4);
283958ebd649SToby Isaac     *name = b->name;
284058ebd649SToby Isaac   }
284158ebd649SToby Isaac   if (labelname) {
284258ebd649SToby Isaac     PetscValidPointer(labelname, 5);
284358ebd649SToby Isaac     *labelname = b->labelname;
284458ebd649SToby Isaac   }
284558ebd649SToby Isaac   if (field) {
284658ebd649SToby Isaac     PetscValidPointer(field, 6);
284758ebd649SToby Isaac     *field = b->field;
284858ebd649SToby Isaac   }
284958ebd649SToby Isaac   if (numcomps) {
285058ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
285158ebd649SToby Isaac     *numcomps = b->numcomps;
285258ebd649SToby Isaac   }
285358ebd649SToby Isaac   if (comps) {
285458ebd649SToby Isaac     PetscValidPointer(comps, 8);
285558ebd649SToby Isaac     *comps = b->comps;
285658ebd649SToby Isaac   }
285758ebd649SToby Isaac   if (func) {
285858ebd649SToby Isaac     PetscValidPointer(func, 9);
285958ebd649SToby Isaac     *func = b->func;
286058ebd649SToby Isaac   }
286158ebd649SToby Isaac   if (numids) {
286258ebd649SToby Isaac     PetscValidPointer(numids, 10);
286358ebd649SToby Isaac     *numids = b->numids;
286458ebd649SToby Isaac   }
286558ebd649SToby Isaac   if (ids) {
286658ebd649SToby Isaac     PetscValidPointer(ids, 11);
286758ebd649SToby Isaac     *ids = b->ids;
286858ebd649SToby Isaac   }
286958ebd649SToby Isaac   if (ctx) {
287058ebd649SToby Isaac     PetscValidPointer(ctx, 12);
287158ebd649SToby Isaac     *ctx = b->ctx;
287258ebd649SToby Isaac   }
287358ebd649SToby Isaac   PetscFunctionReturn(0);
287458ebd649SToby Isaac }
287558ebd649SToby Isaac 
28769252d075SMatthew G. Knepley /*@
28779252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
28789252d075SMatthew G. Knepley 
28799252d075SMatthew G. Knepley   Not collective
28809252d075SMatthew G. Knepley 
28819252d075SMatthew G. Knepley   Input Parameter:
28829252d075SMatthew G. Knepley . prob - The PetscDS object
28839252d075SMatthew G. Knepley 
28849252d075SMatthew G. Knepley   Output Parameter:
28859252d075SMatthew G. Knepley . newprob - The PetscDS copy
28869252d075SMatthew G. Knepley 
28879252d075SMatthew G. Knepley   Level: intermediate
28889252d075SMatthew G. Knepley 
28899252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
28909252d075SMatthew G. Knepley @*/
2891dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB)
2892dff059c6SToby Isaac {
2893dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
2894dff059c6SToby Isaac   PetscErrorCode ierr;
2895dff059c6SToby Isaac 
2896dff059c6SToby Isaac   PetscFunctionBegin;
2897dff059c6SToby Isaac   PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1);
2898dff059c6SToby Isaac   PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2);
2899dff059c6SToby Isaac   if (probA == probB) PetscFunctionReturn(0);
2900dff059c6SToby Isaac   next = probB->boundary;
2901dff059c6SToby Isaac   while (next) {
2902dff059c6SToby Isaac     DSBoundary b = next;
2903dff059c6SToby Isaac 
2904dff059c6SToby Isaac     next = b->next;
2905dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2906dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2907dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
2908dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2909dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
2910dff059c6SToby Isaac   }
2911dff059c6SToby Isaac   lastnext = &(probB->boundary);
2912dff059c6SToby Isaac   for (b = probA->boundary; b; b = b->next) {
2913dff059c6SToby Isaac     DSBoundary bNew;
2914dff059c6SToby Isaac 
2915459726d8SSatish Balay     ierr = PetscNew(&bNew);CHKERRQ(ierr);
2916dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
2917dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
2918dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr);
2919dff059c6SToby Isaac     bNew->numids = b->numids;
2920dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
2921dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr);
2922dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
2923dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
2924dff059c6SToby Isaac     bNew->ctx   = b->ctx;
2925f971fd6bSMatthew G. Knepley     bNew->type  = b->type;
2926dff059c6SToby Isaac     bNew->field = b->field;
2927dff059c6SToby Isaac     bNew->func  = b->func;
2928dff059c6SToby Isaac 
2929dff059c6SToby Isaac     *lastnext = bNew;
2930dff059c6SToby Isaac     lastnext = &(bNew->next);
2931dff059c6SToby Isaac   }
2932dff059c6SToby Isaac   PetscFunctionReturn(0);
2933dff059c6SToby Isaac }
2934dff059c6SToby Isaac 
29359252d075SMatthew G. Knepley /*@C
29369252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
29379252d075SMatthew G. Knepley 
29389252d075SMatthew G. Knepley   Not collective
29399252d075SMatthew G. Knepley 
29409252d075SMatthew G. Knepley   Input Parameter:
29419252d075SMatthew G. Knepley + prob - The PetscDS object
29429252d075SMatthew G. Knepley . numFields - Number of new fields
29439252d075SMatthew G. Knepley - fields - Old field number for each new field
29449252d075SMatthew G. Knepley 
29459252d075SMatthew G. Knepley   Output Parameter:
29469252d075SMatthew G. Knepley . newprob - The PetscDS copy
29479252d075SMatthew G. Knepley 
29489252d075SMatthew G. Knepley   Level: intermediate
29499252d075SMatthew G. Knepley 
29509252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
29519252d075SMatthew G. Knepley @*/
29529252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
29539252d075SMatthew G. Knepley {
29549252d075SMatthew G. Knepley   PetscInt       Nf, Nfn, fn, gn;
29559252d075SMatthew G. Knepley   PetscErrorCode ierr;
29569252d075SMatthew G. Knepley 
29579252d075SMatthew G. Knepley   PetscFunctionBegin;
29589252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29599252d075SMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
29609252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
29619252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
29629252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
29639252d075SMatthew 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);
29649252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
29659252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
29669252d075SMatthew G. Knepley     PetscPointFunc   obj;
29679252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
29689252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
29699252d075SMatthew G. Knepley     PetscRiemannFunc r;
29709252d075SMatthew G. Knepley 
29719252d075SMatthew G. Knepley     if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf);
29729252d075SMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
29739252d075SMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
29749252d075SMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
29759252d075SMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
29769252d075SMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr);
29779252d075SMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr);
29789252d075SMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr);
29799252d075SMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr);
29809252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
29819252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
29829252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
29839252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
29849252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
29859252d075SMatthew G. Knepley 
29869252d075SMatthew G. Knepley       if (g >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", g, Nf);
29879252d075SMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
29889252d075SMatthew G. Knepley       ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr);
29899252d075SMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
29909252d075SMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr);
29919252d075SMatthew G. Knepley       ierr = PetscDSSetJacobianPreconditioner(prob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr);
29929252d075SMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
29939252d075SMatthew G. Knepley     }
29949252d075SMatthew G. Knepley   }
29959252d075SMatthew G. Knepley   PetscFunctionReturn(0);
29969252d075SMatthew G. Knepley }
29979252d075SMatthew G. Knepley 
2998da51fcedSMatthew G. Knepley /*@
2999da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
3000da51fcedSMatthew G. Knepley 
3001da51fcedSMatthew G. Knepley   Not collective
3002da51fcedSMatthew G. Knepley 
3003da51fcedSMatthew G. Knepley   Input Parameter:
3004da51fcedSMatthew G. Knepley . prob - The PetscDS object
3005da51fcedSMatthew G. Knepley 
3006da51fcedSMatthew G. Knepley   Output Parameter:
3007da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
3008da51fcedSMatthew G. Knepley 
3009da51fcedSMatthew G. Knepley   Level: intermediate
3010da51fcedSMatthew G. Knepley 
30119252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
3012da51fcedSMatthew G. Knepley @*/
3013da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
3014da51fcedSMatthew G. Knepley {
30159252d075SMatthew G. Knepley   PetscInt       Nf, Ng;
3016da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
3017da51fcedSMatthew G. Knepley 
3018da51fcedSMatthew G. Knepley   PetscFunctionBegin;
3019da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3020da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
3021da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3022da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
302313903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
30249252d075SMatthew G. Knepley   ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr);
30259252d075SMatthew G. Knepley   PetscFunctionReturn(0);
30269252d075SMatthew G. Knepley }
30279252d075SMatthew G. Knepley /*@
30289252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
3029da51fcedSMatthew G. Knepley 
30309252d075SMatthew G. Knepley   Not collective
30319252d075SMatthew G. Knepley 
30329252d075SMatthew G. Knepley   Input Parameter:
30339252d075SMatthew G. Knepley . prob - The PetscDS object
30349252d075SMatthew G. Knepley 
30359252d075SMatthew G. Knepley   Output Parameter:
30369252d075SMatthew G. Knepley . newprob - The PetscDS copy
30379252d075SMatthew G. Knepley 
30389252d075SMatthew G. Knepley   Level: intermediate
30399252d075SMatthew G. Knepley 
30409252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
30419252d075SMatthew G. Knepley @*/
30429252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
30439252d075SMatthew G. Knepley {
30449252d075SMatthew G. Knepley   PetscInt           Nc;
30459252d075SMatthew G. Knepley   const PetscScalar *constants;
30469252d075SMatthew G. Knepley   PetscErrorCode     ierr;
30479252d075SMatthew G. Knepley 
30489252d075SMatthew G. Knepley   PetscFunctionBegin;
30499252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30509252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
30519252d075SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr);
30529252d075SMatthew G. Knepley   ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr);
3053da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
3054da51fcedSMatthew G. Knepley }
3055da51fcedSMatthew G. Knepley 
3056b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
3057b1353e8eSMatthew G. Knepley {
3058df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
3059b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
3060b1353e8eSMatthew G. Knepley 
3061b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
3062b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3063b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
3064b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
3065b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3066df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
3067df3a45bdSMatthew 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);
3068df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
3069df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
3070b1353e8eSMatthew G. Knepley     PetscInt cdim;
3071b1353e8eSMatthew G. Knepley 
3072df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
3073b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
3074df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
3075b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
3076b1353e8eSMatthew G. Knepley       PetscFE      subfe;
3077b1353e8eSMatthew G. Knepley       PetscObject  obj;
3078b1353e8eSMatthew G. Knepley       PetscClassId id;
3079b1353e8eSMatthew G. Knepley 
3080b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3081b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3082b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
3083b1353e8eSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
3084df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
3085b1353e8eSMatthew G. Knepley     }
3086b1353e8eSMatthew G. Knepley   }
3087df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
3088b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
3089b1353e8eSMatthew G. Knepley }
3090b1353e8eSMatthew G. Knepley 
3091bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob)
30922764a2aaSMatthew G. Knepley {
3093931fb3b8SToby Isaac   PetscErrorCode      ierr;
3094931fb3b8SToby Isaac 
30952764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3096931fb3b8SToby Isaac   ierr = PetscFree(prob->data);CHKERRQ(ierr);
30972764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30982764a2aaSMatthew G. Knepley }
30992764a2aaSMatthew G. Knepley 
3100bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob)
31012764a2aaSMatthew G. Knepley {
31022764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31032764a2aaSMatthew G. Knepley   prob->ops->setfromoptions = NULL;
31042764a2aaSMatthew G. Knepley   prob->ops->setup          = NULL;
31052764a2aaSMatthew G. Knepley   prob->ops->view           = NULL;
31062764a2aaSMatthew G. Knepley   prob->ops->destroy        = PetscDSDestroy_Basic;
31072764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31082764a2aaSMatthew G. Knepley }
31092764a2aaSMatthew G. Knepley 
31102764a2aaSMatthew G. Knepley /*MC
31112764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
31122764a2aaSMatthew G. Knepley 
31132764a2aaSMatthew G. Knepley   Level: intermediate
31142764a2aaSMatthew G. Knepley 
31152764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
31162764a2aaSMatthew G. Knepley M*/
31172764a2aaSMatthew G. Knepley 
31182764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob)
31192764a2aaSMatthew G. Knepley {
31202764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
31212764a2aaSMatthew G. Knepley   PetscErrorCode      ierr;
31222764a2aaSMatthew G. Knepley 
31232764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3124931fb3b8SToby Isaac   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31252764a2aaSMatthew G. Knepley   ierr       = PetscNewLog(prob, &b);CHKERRQ(ierr);
31262764a2aaSMatthew G. Knepley   prob->data = b;
31272764a2aaSMatthew G. Knepley 
31282764a2aaSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr);
31292764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31302764a2aaSMatthew G. Knepley }
3131