xref: /petsc/src/dm/dt/interface/dtds.c (revision f9244615d353839f0b42dd6cc7ed58de3df1184a)
1af0996ceSBarry Smith #include <petsc/private/petscdsimpl.h> /*I "petscds.h" I*/
22764a2aaSMatthew G. Knepley 
32764a2aaSMatthew G. Knepley PetscClassId PETSCDS_CLASSID = 0;
42764a2aaSMatthew G. Knepley 
52764a2aaSMatthew G. Knepley PetscFunctionList PetscDSList              = NULL;
62764a2aaSMatthew G. Knepley PetscBool         PetscDSRegisterAllCalled = PETSC_FALSE;
72764a2aaSMatthew G. Knepley 
894dcdc3fSMatthew G. Knepley /* A PetscDS (Discrete System) encodes a set of equations posed in a discrete space, which represents a set of
994dcdc3fSMatthew G. Knepley    nonlinear continuum equations. The equations can have multiple fields, each field having a different
1094dcdc3fSMatthew G. Knepley    discretization. In addition, different pieces of the domain can have different field combinations and equations.
1194dcdc3fSMatthew G. Knepley 
1294dcdc3fSMatthew G. Knepley    The DS provides the user a description of the approximation space on any given cell. It also gives pointwise
1394dcdc3fSMatthew G. Knepley    functions representing the equations.
1494dcdc3fSMatthew G. Knepley 
1594dcdc3fSMatthew G. Knepley    Each field is associated with a label, marking the cells on which it is supported. Note that a field can be
1694dcdc3fSMatthew G. Knepley    supported on the closure of a cell not in the label due to overlap of the boundary of neighboring cells. The DM
1794dcdc3fSMatthew G. Knepley    then creates a DS for each set of cells with identical approximation spaces. When assembling, the user asks for
1894dcdc3fSMatthew G. Knepley    the space associated with a given cell. DMPlex uses the labels associated with each DS in the default integration loop.
1994dcdc3fSMatthew G. Knepley */
2094dcdc3fSMatthew G. Knepley 
212764a2aaSMatthew G. Knepley /*@C
222764a2aaSMatthew G. Knepley   PetscDSRegister - Adds a new PetscDS implementation
232764a2aaSMatthew G. Knepley 
242764a2aaSMatthew G. Knepley   Not Collective
252764a2aaSMatthew G. Knepley 
262764a2aaSMatthew G. Knepley   Input Parameters:
272764a2aaSMatthew G. Knepley + name        - The name of a new user-defined creation routine
282764a2aaSMatthew G. Knepley - create_func - The creation routine itself
292764a2aaSMatthew G. Knepley 
302764a2aaSMatthew G. Knepley   Notes:
312764a2aaSMatthew G. Knepley   PetscDSRegister() may be called multiple times to add several user-defined PetscDSs
322764a2aaSMatthew G. Knepley 
332764a2aaSMatthew G. Knepley   Sample usage:
342764a2aaSMatthew G. Knepley .vb
352764a2aaSMatthew G. Knepley     PetscDSRegister("my_ds", MyPetscDSCreate);
362764a2aaSMatthew G. Knepley .ve
372764a2aaSMatthew G. Knepley 
382764a2aaSMatthew G. Knepley   Then, your PetscDS type can be chosen with the procedural interface via
392764a2aaSMatthew G. Knepley .vb
402764a2aaSMatthew G. Knepley     PetscDSCreate(MPI_Comm, PetscDS *);
412764a2aaSMatthew G. Knepley     PetscDSSetType(PetscDS, "my_ds");
422764a2aaSMatthew G. Knepley .ve
432764a2aaSMatthew G. Knepley    or at runtime via the option
442764a2aaSMatthew G. Knepley .vb
452764a2aaSMatthew G. Knepley     -petscds_type my_ds
462764a2aaSMatthew G. Knepley .ve
472764a2aaSMatthew G. Knepley 
482764a2aaSMatthew G. Knepley   Level: advanced
492764a2aaSMatthew G. Knepley 
50f5f57ec0SBarry Smith    Not available from Fortran
51f5f57ec0SBarry Smith 
522764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy()
532764a2aaSMatthew G. Knepley 
542764a2aaSMatthew G. Knepley @*/
552764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
562764a2aaSMatthew G. Knepley {
572764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
582764a2aaSMatthew G. Knepley 
592764a2aaSMatthew G. Knepley   PetscFunctionBegin;
602764a2aaSMatthew G. Knepley   ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr);
612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
622764a2aaSMatthew G. Knepley }
632764a2aaSMatthew G. Knepley 
642764a2aaSMatthew G. Knepley /*@C
652764a2aaSMatthew G. Knepley   PetscDSSetType - Builds a particular PetscDS
662764a2aaSMatthew G. Knepley 
67d083f849SBarry Smith   Collective on prob
682764a2aaSMatthew G. Knepley 
692764a2aaSMatthew G. Knepley   Input Parameters:
702764a2aaSMatthew G. Knepley + prob - The PetscDS object
712764a2aaSMatthew G. Knepley - name - The kind of system
722764a2aaSMatthew G. Knepley 
732764a2aaSMatthew G. Knepley   Options Database Key:
742764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
752764a2aaSMatthew G. Knepley 
762764a2aaSMatthew G. Knepley   Level: intermediate
772764a2aaSMatthew G. Knepley 
78f5f57ec0SBarry Smith    Not available from Fortran
79f5f57ec0SBarry Smith 
802764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate()
812764a2aaSMatthew G. Knepley @*/
822764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
832764a2aaSMatthew G. Knepley {
842764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
852764a2aaSMatthew G. Knepley   PetscBool      match;
862764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
872764a2aaSMatthew G. Knepley 
882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
902764a2aaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr);
912764a2aaSMatthew G. Knepley   if (match) PetscFunctionReturn(0);
922764a2aaSMatthew G. Knepley 
930f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
942764a2aaSMatthew G. Knepley   ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr);
952764a2aaSMatthew G. Knepley   if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
962764a2aaSMatthew G. Knepley 
972764a2aaSMatthew G. Knepley   if (prob->ops->destroy) {
982764a2aaSMatthew G. Knepley     ierr             = (*prob->ops->destroy)(prob);CHKERRQ(ierr);
992764a2aaSMatthew G. Knepley     prob->ops->destroy = NULL;
1002764a2aaSMatthew G. Knepley   }
1012764a2aaSMatthew G. Knepley   ierr = (*r)(prob);CHKERRQ(ierr);
1022764a2aaSMatthew G. Knepley   ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr);
1032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1042764a2aaSMatthew G. Knepley }
1052764a2aaSMatthew G. Knepley 
1062764a2aaSMatthew G. Knepley /*@C
1072764a2aaSMatthew G. Knepley   PetscDSGetType - Gets the PetscDS type name (as a string) from the object.
1082764a2aaSMatthew G. Knepley 
1092764a2aaSMatthew G. Knepley   Not Collective
1102764a2aaSMatthew G. Knepley 
1112764a2aaSMatthew G. Knepley   Input Parameter:
1122764a2aaSMatthew G. Knepley . prob  - The PetscDS
1132764a2aaSMatthew G. Knepley 
1142764a2aaSMatthew G. Knepley   Output Parameter:
1152764a2aaSMatthew G. Knepley . name - The PetscDS type name
1162764a2aaSMatthew G. Knepley 
1172764a2aaSMatthew G. Knepley   Level: intermediate
1182764a2aaSMatthew G. Knepley 
119f5f57ec0SBarry Smith    Not available from Fortran
120f5f57ec0SBarry Smith 
1212764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate()
1222764a2aaSMatthew G. Knepley @*/
1232764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
1242764a2aaSMatthew G. Knepley {
1252764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1262764a2aaSMatthew G. Knepley 
1272764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1282764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
129c959eef4SJed Brown   PetscValidPointer(name, 2);
1300f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
1312764a2aaSMatthew G. Knepley   *name = ((PetscObject) prob)->type_name;
1322764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1332764a2aaSMatthew G. Knepley }
1342764a2aaSMatthew G. Knepley 
1357d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer)
1367d8a60eaSMatthew G. Knepley {
1377d8a60eaSMatthew G. Knepley   PetscViewerFormat  format;
13897b6e6e8SMatthew G. Knepley   const PetscScalar *constants;
13997b6e6e8SMatthew G. Knepley   PetscInt           numConstants, f;
1407d8a60eaSMatthew G. Knepley   PetscErrorCode     ierr;
1417d8a60eaSMatthew G. Knepley 
1427d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1437d8a60eaSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
1447d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr);
1457d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1464727e194SMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "  cell total dim %D total comp %D\n", prob->totDim, prob->totComp);CHKERRQ(ierr);
1474727e194SMatthew G. Knepley   if (prob->isHybrid) {ierr = PetscViewerASCIIPrintf(viewer, "  hybrid cell\n");CHKERRQ(ierr);}
1487d8a60eaSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
14940967b3bSMatthew G. Knepley     DSBoundary      b;
1507d8a60eaSMatthew G. Knepley     PetscObject     obj;
1517d8a60eaSMatthew G. Knepley     PetscClassId    id;
152f35450b9SMatthew G. Knepley     PetscQuadrature q;
1537d8a60eaSMatthew G. Knepley     const char     *name;
154f35450b9SMatthew G. Knepley     PetscInt        Nc, Nq, Nqc;
1557d8a60eaSMatthew G. Knepley 
1567d8a60eaSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
1577d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
1587d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr);
1597d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr);
1604727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
1617d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
1627d8a60eaSMatthew G. Knepley       ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr);
163f35450b9SMatthew G. Knepley       ierr = PetscFEGetQuadrature((PetscFE) obj, &q);CHKERRQ(ierr);
1647d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr);
1657d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1667d8a60eaSMatthew G. Knepley       ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr);
167f35450b9SMatthew G. Knepley       ierr = PetscFVGetQuadrature((PetscFV) obj, &q);CHKERRQ(ierr);
1687d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr);
1697d8a60eaSMatthew G. Knepley     }
17097b6e6e8SMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f);
17197b6e6e8SMatthew G. Knepley     if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%D components", Nc);CHKERRQ(ierr);}
17297b6e6e8SMatthew G. Knepley     else        {ierr = PetscViewerASCIIPrintf(viewer, "%D component ", Nc);CHKERRQ(ierr);}
173249df284SMatthew G. Knepley     if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);}
174249df284SMatthew G. Knepley     else                   {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);}
1753e60c2a6SMatthew G. Knepley     if (q) {
176f35450b9SMatthew G. Knepley       ierr = PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL);CHKERRQ(ierr);
177f35450b9SMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " (Nq %D Nqc %D)", Nq, Nqc);CHKERRQ(ierr);
1783e60c2a6SMatthew G. Knepley     }
179*f9244615SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, " %D-jet", prob->jetDegree[f]);CHKERRQ(ierr);
1807d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
1814727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
1825d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1837d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);}
1847d8a60eaSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);}
1855d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
18640967b3bSMatthew G. Knepley 
18740967b3bSMatthew G. Knepley     for (b = prob->boundary; b; b = b->next) {
18840967b3bSMatthew G. Knepley       PetscInt c, i;
18940967b3bSMatthew G. Knepley 
19040967b3bSMatthew G. Knepley       if (b->field != f) continue;
19140967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
19240967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->labelname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr);
19340967b3bSMatthew G. Knepley       if (!b->numcomps) {
19440967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "  all components\n");CHKERRQ(ierr);
19540967b3bSMatthew G. Knepley       } else {
19640967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "  components: ");CHKERRQ(ierr);
19740967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
19840967b3bSMatthew G. Knepley         for (c = 0; c < b->numcomps; ++c) {
19940967b3bSMatthew G. Knepley           if (c > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
20040967b3bSMatthew G. Knepley           ierr = PetscViewerASCIIPrintf(viewer, "%D", b->comps[c]);CHKERRQ(ierr);
20140967b3bSMatthew G. Knepley         }
20240967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
20340967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
20440967b3bSMatthew G. Knepley       }
20540967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "  ids: ");CHKERRQ(ierr);
20640967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
20740967b3bSMatthew G. Knepley       for (i = 0; i < b->numids; ++i) {
20840967b3bSMatthew G. Knepley         if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
20940967b3bSMatthew G. Knepley         ierr = PetscViewerASCIIPrintf(viewer, "%D", b->ids[i]);CHKERRQ(ierr);
21040967b3bSMatthew G. Knepley       }
21140967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
21240967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
21340967b3bSMatthew G. Knepley       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
21440967b3bSMatthew G. Knepley     }
2157d8a60eaSMatthew G. Knepley   }
21697b6e6e8SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr);
21797b6e6e8SMatthew G. Knepley   if (numConstants) {
21897b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr);
21997b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
22057fc01e9SMatthew G. Knepley     for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);}
22197b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
22297b6e6e8SMatthew G. Knepley   }
2237d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
2247d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
2257d8a60eaSMatthew G. Knepley }
2267d8a60eaSMatthew G. Knepley 
2272764a2aaSMatthew G. Knepley /*@C
228fe2efc57SMark    PetscDSViewFromOptions - View from Options
229fe2efc57SMark 
230fe2efc57SMark    Collective on PetscDS
231fe2efc57SMark 
232fe2efc57SMark    Input Parameters:
233fe2efc57SMark +  A - the PetscDS object
234736c3998SJose E. Roman .  obj - Optional object
235736c3998SJose E. Roman -  name - command line option
236fe2efc57SMark 
237fe2efc57SMark    Level: intermediate
238fe2efc57SMark .seealso:  PetscDS, PetscDSView, PetscObjectViewFromOptions(), PetscDSCreate()
239fe2efc57SMark @*/
240fe2efc57SMark PetscErrorCode  PetscDSViewFromOptions(PetscDS A,PetscObject obj,const char name[])
241fe2efc57SMark {
242fe2efc57SMark   PetscErrorCode ierr;
243fe2efc57SMark 
244fe2efc57SMark   PetscFunctionBegin;
245fe2efc57SMark   PetscValidHeaderSpecific(A,PETSCDS_CLASSID,1);
246fe2efc57SMark   ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr);
247fe2efc57SMark   PetscFunctionReturn(0);
248fe2efc57SMark }
249fe2efc57SMark 
250fe2efc57SMark /*@C
2512764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
2522764a2aaSMatthew G. Knepley 
253d083f849SBarry Smith   Collective on prob
2542764a2aaSMatthew G. Knepley 
2552764a2aaSMatthew G. Knepley   Input Parameter:
2562764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
2572764a2aaSMatthew G. Knepley - v  - the viewer
2582764a2aaSMatthew G. Knepley 
2592764a2aaSMatthew G. Knepley   Level: developer
2602764a2aaSMatthew G. Knepley 
2612764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
2622764a2aaSMatthew G. Knepley @*/
2632764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
2642764a2aaSMatthew G. Knepley {
2657d8a60eaSMatthew G. Knepley   PetscBool      iascii;
2662764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2672764a2aaSMatthew G. Knepley 
2682764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2692764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2702764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
2717d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
2727d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
2737d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2742764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2752764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2762764a2aaSMatthew G. Knepley }
2772764a2aaSMatthew G. Knepley 
2782764a2aaSMatthew G. Knepley /*@
2792764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2802764a2aaSMatthew G. Knepley 
281d083f849SBarry Smith   Collective on prob
2822764a2aaSMatthew G. Knepley 
2832764a2aaSMatthew G. Knepley   Input Parameter:
2842764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2852764a2aaSMatthew G. Knepley 
2862764a2aaSMatthew G. Knepley   Options Database:
28755c1f793SMatthew G. Knepley + -petscds_type <type>     : Set the DS type
28855c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS
28955c1f793SMatthew G. Knepley . -petscds_jac_pre         : Turn formation of a separate Jacobian preconditioner on and off
29055c1f793SMatthew G. Knepley . -bc_<name> <ids>         : Specify a list of label ids for a boundary condition
29155c1f793SMatthew G. Knepley - -bc_<name>_comp <comps>  : Specify a list of field components to constrain for a boundary condition
2922764a2aaSMatthew G. Knepley 
2932764a2aaSMatthew G. Knepley   Level: developer
2942764a2aaSMatthew G. Knepley 
2952764a2aaSMatthew G. Knepley .seealso PetscDSView()
2962764a2aaSMatthew G. Knepley @*/
2972764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
2982764a2aaSMatthew G. Knepley {
299f1fd5e65SToby Isaac   DSBoundary     b;
3002764a2aaSMatthew G. Knepley   const char    *defaultType;
3012764a2aaSMatthew G. Knepley   char           name[256];
3022764a2aaSMatthew G. Knepley   PetscBool      flg;
3032764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3042764a2aaSMatthew G. Knepley 
3052764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3062764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3072764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
3082764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
3092764a2aaSMatthew G. Knepley   } else {
3102764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
3112764a2aaSMatthew G. Knepley   }
3120f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
3132764a2aaSMatthew G. Knepley 
3142764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
315f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
316f1fd5e65SToby Isaac     char       optname[1024];
317f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
318f1fd5e65SToby Isaac     PetscBool  flg;
319f1fd5e65SToby Isaac 
320f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
321f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
322f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
323f1fd5e65SToby Isaac     if (flg) {
324f1fd5e65SToby Isaac       b->numids = len;
325f1fd5e65SToby Isaac       ierr = PetscFree(b->ids);CHKERRQ(ierr);
326f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr);
327580bdb30SBarry Smith       ierr = PetscArraycpy(b->ids, ids, len);CHKERRQ(ierr);
328f1fd5e65SToby Isaac     }
329e7b0402cSSander Arens     len = 1024;
330f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
331f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
332f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
333f1fd5e65SToby Isaac     if (flg) {
334f1fd5e65SToby Isaac       b->numcomps = len;
335f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
336f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
337580bdb30SBarry Smith       ierr = PetscArraycpy(b->comps, ids, len);CHKERRQ(ierr);
338f1fd5e65SToby Isaac     }
339f1fd5e65SToby Isaac   }
3402764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
3412764a2aaSMatthew G. Knepley   if (flg) {
3422764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
3432764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
3442764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
3452764a2aaSMatthew G. Knepley   }
34655c1f793SMatthew G. Knepley   ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr);
3472764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
3482764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
3490633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
3502764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
3515d160056SMatthew G. Knepley   if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);}
3522764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3532764a2aaSMatthew G. Knepley }
3542764a2aaSMatthew G. Knepley 
3552764a2aaSMatthew G. Knepley /*@C
3562764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
3572764a2aaSMatthew G. Knepley 
358d083f849SBarry Smith   Collective on prob
3592764a2aaSMatthew G. Knepley 
3602764a2aaSMatthew G. Knepley   Input Parameter:
3612764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
3622764a2aaSMatthew G. Knepley 
3632764a2aaSMatthew G. Knepley   Level: developer
3642764a2aaSMatthew G. Knepley 
3652764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
3662764a2aaSMatthew G. Knepley @*/
3672764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
3682764a2aaSMatthew G. Knepley {
3692764a2aaSMatthew G. Knepley   const PetscInt Nf   = prob->Nf;
370*f9244615SMatthew G. Knepley   PetscBool      hasH = PETSC_FALSE;
3714bee2e38SMatthew G. Knepley   PetscInt       dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f;
3722764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3732764a2aaSMatthew G. Knepley 
3742764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3752764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3762764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3772764a2aaSMatthew G. Knepley   /* Calculate sizes */
3782764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
379d1506c7cSMatthew G. Knepley   ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr);
380f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
38147e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
382f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
383ef0bb6c7SMatthew G. Knepley   ierr = PetscMalloc2(Nf,&prob->T,Nf,&prob->Tf);CHKERRQ(ierr);
3842764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3859de99aefSMatthew G. Knepley     PetscObject     obj;
3869de99aefSMatthew G. Knepley     PetscClassId    id;
387665f567fSMatthew G. Knepley     PetscQuadrature q = NULL;
3889de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
3892764a2aaSMatthew G. Knepley 
3909de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
391*f9244615SMatthew G. Knepley     if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE;
392665f567fSMatthew G. Knepley     if (!obj) {
393665f567fSMatthew G. Knepley       /* Empty mesh */
394665f567fSMatthew G. Knepley       Nb = Nc = 0;
395665f567fSMatthew G. Knepley       prob->T[f] = prob->Tf[f] = NULL;
396665f567fSMatthew G. Knepley     } else {
3979de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3989de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {
3999de99aefSMatthew G. Knepley         PetscFE fe = (PetscFE) obj;
4009de99aefSMatthew G. Knepley 
4012764a2aaSMatthew G. Knepley         ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
4022764a2aaSMatthew G. Knepley         ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
4032764a2aaSMatthew G. Knepley         ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
404*f9244615SMatthew G. Knepley         ierr = PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f]);CHKERRQ(ierr);
405*f9244615SMatthew G. Knepley         ierr = PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f]);CHKERRQ(ierr);
4069de99aefSMatthew G. Knepley       } else if (id == PETSCFV_CLASSID) {
4079de99aefSMatthew G. Knepley         PetscFV fv = (PetscFV) obj;
4089de99aefSMatthew G. Knepley 
4099de99aefSMatthew G. Knepley         ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
4109de99aefSMatthew G. Knepley         ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
4119c3cf19fSMatthew G. Knepley         Nb   = Nc;
412ef0bb6c7SMatthew G. Knepley         ierr = PetscFVGetCellTabulation(fv, &prob->T[f]);CHKERRQ(ierr);
4134d0b9603SSander Arens         /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
414abac5ca0SMatthew G. Knepley       } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
415665f567fSMatthew G. Knepley     }
41647e57110SSander Arens     prob->Nc[f]       = Nc;
41747e57110SSander Arens     prob->Nb[f]       = Nb;
418194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
419194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
420a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
4212764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
4224bee2e38SMatthew G. Knepley     NbMax          = PetscMax(NbMax, Nb);
4232764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
4249c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
4252764a2aaSMatthew G. Knepley     prob->totComp += Nc;
42694a5e212SMatthew G. Knepley     /* There are two faces for all fields but the cohesive field on a hybrid cell */
42794a5e212SMatthew G. Knepley     if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb;
4282764a2aaSMatthew G. Knepley   }
4292764a2aaSMatthew G. Knepley   /* Allocate works space */
43094a5e212SMatthew G. Knepley   if (prob->isHybrid) NsMax = 2;
431*f9244615SMatthew G. Knepley   ierr = PetscMalloc3(NsMax*prob->totComp,&prob->u,NsMax*prob->totComp,&prob->u_t,NsMax*prob->totComp*dimEmbed + (hasH ? NsMax*prob->totComp*dimEmbed*dimEmbed : 0),&prob->u_x);CHKERRQ(ierr);
4324bee2e38SMatthew G. Knepley   ierr = PetscMalloc5(dimEmbed,&prob->x,NbMax*NcMax,&prob->basisReal,NbMax*NcMax*dimEmbed,&prob->basisDerReal,NbMax*NcMax,&prob->testReal,NbMax*NcMax*dimEmbed,&prob->testDerReal);CHKERRQ(ierr);
43327f02ce8SMatthew G. Knepley   ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dimEmbed,&prob->f1,
43427f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g1,
43527f02ce8SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed*dimEmbed,&prob->g3);CHKERRQ(ierr);
4362764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
4372764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
4382764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4392764a2aaSMatthew G. Knepley }
4402764a2aaSMatthew G. Knepley 
4412764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
4422764a2aaSMatthew G. Knepley {
4432764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4442764a2aaSMatthew G. Knepley 
4452764a2aaSMatthew G. Knepley   PetscFunctionBegin;
44647e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
447f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
448ef0bb6c7SMatthew G. Knepley   ierr = PetscFree2(prob->T,prob->Tf);CHKERRQ(ierr);
4494bee2e38SMatthew G. Knepley   ierr = PetscFree3(prob->u,prob->u_t,prob->u_x);CHKERRQ(ierr);
4504bee2e38SMatthew G. Knepley   ierr = PetscFree5(prob->x,prob->basisReal, prob->basisDerReal,prob->testReal,prob->testDerReal);CHKERRQ(ierr);
4512764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
4522764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4532764a2aaSMatthew G. Knepley }
4542764a2aaSMatthew G. Knepley 
4552764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
4562764a2aaSMatthew G. Knepley {
457f744cafaSSander Arens   PetscObject      *tmpd;
45834aa8a36SMatthew G. Knepley   PetscBool        *tmpi;
459*f9244615SMatthew G. Knepley   PetscInt         *tmpk;
46032d2bbc9SMatthew G. Knepley   PetscPointFunc   *tmpobj, *tmpf, *tmpup;
461b7e05686SMatthew G. Knepley   PetscPointJac    *tmpg, *tmpgp, *tmpgt;
4622aa1fc23SMatthew G. Knepley   PetscBdPointFunc *tmpfbd;
46327f02ce8SMatthew G. Knepley   PetscBdPointJac  *tmpgbd, *tmpgpbd;
464194d53e6SMatthew G. Knepley   PetscRiemannFunc *tmpr;
465f2cacb80SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol,  *tmpexactSol_t;
466f2cacb80SMatthew G. Knepley   void                **tmpexactCtx, **tmpexactCtx_t;
4670c2f2876SMatthew G. Knepley   void            **tmpctx;
46834aa8a36SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f;
4692764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
4702764a2aaSMatthew G. Knepley 
4712764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4722764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
4732764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
4742764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
475*f9244615SMatthew G. Knepley   ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpk);CHKERRQ(ierr);
476*f9244615SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; tmpk[f] = prob->jetDegree[f];}
477*f9244615SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpk[f] = 1;}
478*f9244615SMatthew G. Knepley   ierr = PetscFree3(prob->disc, prob->implicit, prob->jetDegree);CHKERRQ(ierr);
4792764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
4802764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
481249df284SMatthew G. Knepley   prob->implicit  = tmpi;
482*f9244615SMatthew G. Knepley   prob->jetDegree = tmpk;
483b7e05686SMatthew 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);
48432d2bbc9SMatthew G. Knepley   ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr);
4852764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f];
4862764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f];
4872764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f];
488475e0ac9SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f];
4890c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f];
49032d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
4910c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
4922764a2aaSMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL;
4932764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL;
4942764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL;
495475e0ac9SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL;
496b7e05686SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL;
4970c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL;
49832d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
4990c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
500b7e05686SMatthew G. Knepley   ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr);
50132d2bbc9SMatthew G. Knepley   ierr = PetscFree(prob->update);CHKERRQ(ierr);
5022764a2aaSMatthew G. Knepley   prob->obj = tmpobj;
5032764a2aaSMatthew G. Knepley   prob->f   = tmpf;
5042764a2aaSMatthew G. Knepley   prob->g   = tmpg;
505475e0ac9SMatthew G. Knepley   prob->gp  = tmpgp;
506b7e05686SMatthew G. Knepley   prob->gt  = tmpgt;
5070c2f2876SMatthew G. Knepley   prob->r   = tmpr;
50832d2bbc9SMatthew G. Knepley   prob->update = tmpup;
5090c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
510f2cacb80SMatthew G. Knepley   ierr = PetscCalloc7(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew*NfNew*4, &tmpgpbd, NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t);CHKERRQ(ierr);
5112764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f];
5122764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f];
51327f02ce8SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgpbd[f] = prob->gpBd[f];
514c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
51595cbbfd3SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f];
516f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f];
517f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f];
5182764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL;
5192764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL;
52027f02ce8SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgpbd[f] = NULL;
521c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
52295cbbfd3SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL;
523f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL;
524f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL;
525f2cacb80SMatthew G. Knepley   ierr = PetscFree7(prob->fBd, prob->gBd, prob->gpBd, prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t);CHKERRQ(ierr);
5262764a2aaSMatthew G. Knepley   prob->fBd = tmpfbd;
5272764a2aaSMatthew G. Knepley   prob->gBd = tmpgbd;
52827f02ce8SMatthew G. Knepley   prob->gpBd = tmpgpbd;
529c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
53095cbbfd3SMatthew G. Knepley   prob->exactCtx = tmpexactCtx;
531f2cacb80SMatthew G. Knepley   prob->exactSol_t = tmpexactSol_t;
532f2cacb80SMatthew G. Knepley   prob->exactCtx_t = tmpexactCtx_t;
5332764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5342764a2aaSMatthew G. Knepley }
5352764a2aaSMatthew G. Knepley 
5362764a2aaSMatthew G. Knepley /*@
5372764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
5382764a2aaSMatthew G. Knepley 
539d083f849SBarry Smith   Collective on prob
5402764a2aaSMatthew G. Knepley 
5412764a2aaSMatthew G. Knepley   Input Parameter:
5422764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
5432764a2aaSMatthew G. Knepley 
5442764a2aaSMatthew G. Knepley   Level: developer
5452764a2aaSMatthew G. Knepley 
5462764a2aaSMatthew G. Knepley .seealso PetscDSView()
5472764a2aaSMatthew G. Knepley @*/
5482764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob)
5492764a2aaSMatthew G. Knepley {
5502764a2aaSMatthew G. Knepley   PetscInt       f;
55158ebd649SToby Isaac   DSBoundary     next;
5522764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5532764a2aaSMatthew G. Knepley 
5542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5552764a2aaSMatthew G. Knepley   if (!*prob) PetscFunctionReturn(0);
5562764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1);
5572764a2aaSMatthew G. Knepley 
558ea78f98cSLisandro Dalcin   if (--((PetscObject)(*prob))->refct > 0) {*prob = NULL; PetscFunctionReturn(0);}
5592764a2aaSMatthew G. Knepley   ((PetscObject) (*prob))->refct = 0;
560df3a45bdSMatthew G. Knepley   if ((*prob)->subprobs) {
561df3a45bdSMatthew G. Knepley     PetscInt dim, d;
562df3a45bdSMatthew G. Knepley 
563df3a45bdSMatthew G. Knepley     ierr = PetscDSGetSpatialDimension(*prob, &dim);CHKERRQ(ierr);
564df3a45bdSMatthew G. Knepley     for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*prob)->subprobs[d]);CHKERRQ(ierr);}
565df3a45bdSMatthew G. Knepley   }
566df3a45bdSMatthew G. Knepley   ierr = PetscFree((*prob)->subprobs);CHKERRQ(ierr);
5672764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr);
5682764a2aaSMatthew G. Knepley   for (f = 0; f < (*prob)->Nf; ++f) {
5692764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr);
5702764a2aaSMatthew G. Knepley   }
571*f9244615SMatthew G. Knepley   ierr = PetscFree3((*prob)->disc, (*prob)->implicit, (*prob)->jetDegree);CHKERRQ(ierr);
572b7e05686SMatthew G. Knepley   ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr);
57332d2bbc9SMatthew G. Knepley   ierr = PetscFree((*prob)->update);CHKERRQ(ierr);
574f2cacb80SMatthew G. Knepley   ierr = PetscFree7((*prob)->fBd,(*prob)->gBd,(*prob)->gpBd,(*prob)->exactSol,(*prob)->exactCtx,(*prob)->exactSol_t,(*prob)->exactCtx_t);CHKERRQ(ierr);
5752764a2aaSMatthew G. Knepley   if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);}
57658ebd649SToby Isaac   next = (*prob)->boundary;
57758ebd649SToby Isaac   while (next) {
57858ebd649SToby Isaac     DSBoundary b = next;
57958ebd649SToby Isaac 
58058ebd649SToby Isaac     next = b->next;
58158ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
58258ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
58358ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
58458ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
58558ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
58658ebd649SToby Isaac   }
58797b6e6e8SMatthew G. Knepley   ierr = PetscFree((*prob)->constants);CHKERRQ(ierr);
5882764a2aaSMatthew G. Knepley   ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr);
5892764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5902764a2aaSMatthew G. Knepley }
5912764a2aaSMatthew G. Knepley 
5922764a2aaSMatthew G. Knepley /*@
5932764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
5942764a2aaSMatthew G. Knepley 
595d083f849SBarry Smith   Collective
5962764a2aaSMatthew G. Knepley 
5972764a2aaSMatthew G. Knepley   Input Parameter:
5982764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
5992764a2aaSMatthew G. Knepley 
6002764a2aaSMatthew G. Knepley   Output Parameter:
6012764a2aaSMatthew G. Knepley . prob - The PetscDS object
6022764a2aaSMatthew G. Knepley 
6032764a2aaSMatthew G. Knepley   Level: beginner
6042764a2aaSMatthew G. Knepley 
6052764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
6062764a2aaSMatthew G. Knepley @*/
6072764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob)
6082764a2aaSMatthew G. Knepley {
6092764a2aaSMatthew G. Knepley   PetscDS   p;
6102764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6112764a2aaSMatthew G. Knepley 
6122764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6132764a2aaSMatthew G. Knepley   PetscValidPointer(prob, 2);
6142764a2aaSMatthew G. Knepley   *prob  = NULL;
6152764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
6162764a2aaSMatthew G. Knepley 
61773107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
6182764a2aaSMatthew G. Knepley 
6192764a2aaSMatthew G. Knepley   p->Nf           = 0;
6202764a2aaSMatthew G. Knepley   p->setup        = PETSC_FALSE;
62197b6e6e8SMatthew G. Knepley   p->numConstants = 0;
62297b6e6e8SMatthew G. Knepley   p->constants    = NULL;
623a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
62455c1f793SMatthew G. Knepley   p->useJacPre    = PETSC_TRUE;
6252764a2aaSMatthew G. Knepley 
6262764a2aaSMatthew G. Knepley   *prob = p;
6272764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6282764a2aaSMatthew G. Knepley }
6292764a2aaSMatthew G. Knepley 
630bc4ae4beSMatthew G. Knepley /*@
631bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
632bc4ae4beSMatthew G. Knepley 
633bc4ae4beSMatthew G. Knepley   Not collective
634bc4ae4beSMatthew G. Knepley 
635bc4ae4beSMatthew G. Knepley   Input Parameter:
636bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
637bc4ae4beSMatthew G. Knepley 
638bc4ae4beSMatthew G. Knepley   Output Parameter:
639bc4ae4beSMatthew G. Knepley . Nf - The number of fields
640bc4ae4beSMatthew G. Knepley 
641bc4ae4beSMatthew G. Knepley   Level: beginner
642bc4ae4beSMatthew G. Knepley 
643bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
644bc4ae4beSMatthew G. Knepley @*/
6452764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
6462764a2aaSMatthew G. Knepley {
6472764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6482764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6492764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
6502764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
6512764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6522764a2aaSMatthew G. Knepley }
6532764a2aaSMatthew G. Knepley 
654bc4ae4beSMatthew G. Knepley /*@
655a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
656bc4ae4beSMatthew G. Knepley 
657bc4ae4beSMatthew G. Knepley   Not collective
658bc4ae4beSMatthew G. Knepley 
659bc4ae4beSMatthew G. Knepley   Input Parameter:
660bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
661bc4ae4beSMatthew G. Knepley 
662bc4ae4beSMatthew G. Knepley   Output Parameter:
663bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
664bc4ae4beSMatthew G. Knepley 
665bc4ae4beSMatthew G. Knepley   Level: beginner
666bc4ae4beSMatthew G. Knepley 
667a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate()
668bc4ae4beSMatthew G. Knepley @*/
6692764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
6702764a2aaSMatthew G. Knepley {
6712764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6722764a2aaSMatthew G. Knepley 
6732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6742764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6752764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6762764a2aaSMatthew G. Knepley   *dim = 0;
6779de99aefSMatthew G. Knepley   if (prob->Nf) {
6789de99aefSMatthew G. Knepley     PetscObject  obj;
6799de99aefSMatthew G. Knepley     PetscClassId id;
6809de99aefSMatthew G. Knepley 
6819de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
682665f567fSMatthew G. Knepley     if (obj) {
6839de99aefSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
6849de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
6859de99aefSMatthew G. Knepley       else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
6869de99aefSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
6879de99aefSMatthew G. Knepley     }
688665f567fSMatthew G. Knepley   }
6892764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6902764a2aaSMatthew G. Knepley }
6912764a2aaSMatthew G. Knepley 
692bc4ae4beSMatthew G. Knepley /*@
693a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
694a859676bSMatthew G. Knepley 
695a859676bSMatthew G. Knepley   Not collective
696a859676bSMatthew G. Knepley 
697a859676bSMatthew G. Knepley   Input Parameter:
698a859676bSMatthew G. Knepley . prob - The PetscDS object
699a859676bSMatthew G. Knepley 
700a859676bSMatthew G. Knepley   Output Parameter:
701a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
702a859676bSMatthew G. Knepley 
703a859676bSMatthew G. Knepley   Level: beginner
704a859676bSMatthew G. Knepley 
705a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
706a859676bSMatthew G. Knepley @*/
707a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
708a859676bSMatthew G. Knepley {
709a859676bSMatthew G. Knepley   PetscFunctionBegin;
710a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
711a859676bSMatthew G. Knepley   PetscValidPointer(dimEmbed, 2);
712a859676bSMatthew G. Knepley   if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
713a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
714a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
715a859676bSMatthew G. Knepley }
716a859676bSMatthew G. Knepley 
717a859676bSMatthew G. Knepley /*@
718a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
719a859676bSMatthew G. Knepley 
720d083f849SBarry Smith   Logically collective on prob
721a859676bSMatthew G. Knepley 
722a859676bSMatthew G. Knepley   Input Parameters:
723a859676bSMatthew G. Knepley + prob - The PetscDS object
724a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
725a859676bSMatthew G. Knepley 
726a859676bSMatthew G. Knepley   Level: beginner
727a859676bSMatthew G. Knepley 
728a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
729a859676bSMatthew G. Knepley @*/
730a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
731a859676bSMatthew G. Knepley {
732a859676bSMatthew G. Knepley   PetscFunctionBegin;
733a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
734ebfe4b0dSMatthew G. Knepley   if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed);
735a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
736a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
737a859676bSMatthew G. Knepley }
738a859676bSMatthew G. Knepley 
739a859676bSMatthew G. Knepley /*@
7408edf6225SMatthew G. Knepley   PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell
7418edf6225SMatthew G. Knepley 
7428edf6225SMatthew G. Knepley   Not collective
7438edf6225SMatthew G. Knepley 
7448edf6225SMatthew G. Knepley   Input Parameter:
7458edf6225SMatthew G. Knepley . prob - The PetscDS object
7468edf6225SMatthew G. Knepley 
7478edf6225SMatthew G. Knepley   Output Parameter:
7488edf6225SMatthew G. Knepley . isHybrid - The flag
7498edf6225SMatthew G. Knepley 
7508edf6225SMatthew G. Knepley   Level: developer
7518edf6225SMatthew G. Knepley 
7528edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate()
7538edf6225SMatthew G. Knepley @*/
7548edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid)
7558edf6225SMatthew G. Knepley {
7568edf6225SMatthew G. Knepley   PetscFunctionBegin;
7578edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7588edf6225SMatthew G. Knepley   PetscValidPointer(isHybrid, 2);
7598edf6225SMatthew G. Knepley   *isHybrid = prob->isHybrid;
7608edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7618edf6225SMatthew G. Knepley }
7628edf6225SMatthew G. Knepley 
7638edf6225SMatthew G. Knepley /*@
7648edf6225SMatthew G. Knepley   PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell
7658edf6225SMatthew G. Knepley 
7668edf6225SMatthew G. Knepley   Not collective
7678edf6225SMatthew G. Knepley 
7688edf6225SMatthew G. Knepley   Input Parameters:
7698edf6225SMatthew G. Knepley + prob - The PetscDS object
7708edf6225SMatthew G. Knepley - isHybrid - The flag
7718edf6225SMatthew G. Knepley 
7728edf6225SMatthew G. Knepley   Level: developer
7738edf6225SMatthew G. Knepley 
7748edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate()
7758edf6225SMatthew G. Knepley @*/
7768edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid)
7778edf6225SMatthew G. Knepley {
7788edf6225SMatthew G. Knepley   PetscFunctionBegin;
7798edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7808edf6225SMatthew G. Knepley   prob->isHybrid = isHybrid;
7818edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7828edf6225SMatthew G. Knepley }
7838edf6225SMatthew G. Knepley 
7848edf6225SMatthew G. Knepley /*@
785bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
786bc4ae4beSMatthew G. Knepley 
787bc4ae4beSMatthew G. Knepley   Not collective
788bc4ae4beSMatthew G. Knepley 
789bc4ae4beSMatthew G. Knepley   Input Parameter:
790bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
791bc4ae4beSMatthew G. Knepley 
792bc4ae4beSMatthew G. Knepley   Output Parameter:
793bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
794bc4ae4beSMatthew G. Knepley 
795bc4ae4beSMatthew G. Knepley   Level: beginner
796bc4ae4beSMatthew G. Knepley 
797bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
798bc4ae4beSMatthew G. Knepley @*/
7992764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
8002764a2aaSMatthew G. Knepley {
8012764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8022764a2aaSMatthew G. Knepley 
8032764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8042764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8052764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
8062764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
8072764a2aaSMatthew G. Knepley   *dim = prob->totDim;
8082764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8092764a2aaSMatthew G. Knepley }
8102764a2aaSMatthew G. Knepley 
811bc4ae4beSMatthew G. Knepley /*@
812bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
813bc4ae4beSMatthew G. Knepley 
814bc4ae4beSMatthew G. Knepley   Not collective
815bc4ae4beSMatthew G. Knepley 
816bc4ae4beSMatthew G. Knepley   Input Parameter:
817bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
818bc4ae4beSMatthew G. Knepley 
819bc4ae4beSMatthew G. Knepley   Output Parameter:
820bc4ae4beSMatthew G. Knepley . dim - The total number of components
821bc4ae4beSMatthew G. Knepley 
822bc4ae4beSMatthew G. Knepley   Level: beginner
823bc4ae4beSMatthew G. Knepley 
824bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
825bc4ae4beSMatthew G. Knepley @*/
8262764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
8272764a2aaSMatthew G. Knepley {
8282764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8292764a2aaSMatthew G. Knepley 
8302764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8312764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8322764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
8332764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
8342764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
8352764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8362764a2aaSMatthew G. Knepley }
8372764a2aaSMatthew G. Knepley 
838bc4ae4beSMatthew G. Knepley /*@
839bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
840bc4ae4beSMatthew G. Knepley 
841bc4ae4beSMatthew G. Knepley   Not collective
842bc4ae4beSMatthew G. Knepley 
843bc4ae4beSMatthew G. Knepley   Input Parameters:
844bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
845bc4ae4beSMatthew G. Knepley - f - The field number
846bc4ae4beSMatthew G. Knepley 
847bc4ae4beSMatthew G. Knepley   Output Parameter:
848bc4ae4beSMatthew G. Knepley . disc - The discretization object
849bc4ae4beSMatthew G. Knepley 
850bc4ae4beSMatthew G. Knepley   Level: beginner
851bc4ae4beSMatthew G. Knepley 
852f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
853bc4ae4beSMatthew G. Knepley @*/
8542764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
8552764a2aaSMatthew G. Knepley {
8562764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8572764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8582764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
8592764a2aaSMatthew 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);
8602764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
8612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8622764a2aaSMatthew G. Knepley }
8632764a2aaSMatthew G. Knepley 
864bc4ae4beSMatthew G. Knepley /*@
865bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
866bc4ae4beSMatthew G. Knepley 
867bc4ae4beSMatthew G. Knepley   Not collective
868bc4ae4beSMatthew G. Knepley 
869bc4ae4beSMatthew G. Knepley   Input Parameters:
870bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
871bc4ae4beSMatthew G. Knepley . f - The field number
872bc4ae4beSMatthew G. Knepley - disc - The discretization object
873bc4ae4beSMatthew G. Knepley 
874bc4ae4beSMatthew G. Knepley   Level: beginner
875bc4ae4beSMatthew G. Knepley 
876bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
877bc4ae4beSMatthew G. Knepley @*/
8782764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
8792764a2aaSMatthew G. Knepley {
8802764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8812764a2aaSMatthew G. Knepley 
8822764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8832764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
884665f567fSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
8852764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
8862764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
887c10f2116SMatthew G. Knepley   ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);
8882764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
8892764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
890665f567fSMatthew G. Knepley   if (disc) {
891249df284SMatthew G. Knepley     PetscClassId id;
892249df284SMatthew G. Knepley 
893249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
8941cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
8951cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr);
8961cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
8971cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr);
898a6cbbb48SMatthew G. Knepley     }
899*f9244615SMatthew G. Knepley     ierr = PetscDSSetJetDegree(prob, f, 1);CHKERRQ(ierr);
900249df284SMatthew G. Knepley   }
9012764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9022764a2aaSMatthew G. Knepley }
9032764a2aaSMatthew G. Knepley 
904bc4ae4beSMatthew G. Knepley /*@
905bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
906bc4ae4beSMatthew G. Knepley 
907bc4ae4beSMatthew G. Knepley   Not collective
908bc4ae4beSMatthew G. Knepley 
909bc4ae4beSMatthew G. Knepley   Input Parameters:
910bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
911bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
912bc4ae4beSMatthew G. Knepley 
913bc4ae4beSMatthew G. Knepley   Level: beginner
914bc4ae4beSMatthew G. Knepley 
915bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
916bc4ae4beSMatthew G. Knepley @*/
9172764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
9182764a2aaSMatthew G. Knepley {
9192764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9202764a2aaSMatthew G. Knepley 
9212764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9222764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
9232764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9242764a2aaSMatthew G. Knepley }
9252764a2aaSMatthew G. Knepley 
926249df284SMatthew G. Knepley /*@
927083401c6SMatthew G. Knepley   PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS
928083401c6SMatthew G. Knepley 
929083401c6SMatthew G. Knepley   Not collective
930083401c6SMatthew G. Knepley 
931083401c6SMatthew G. Knepley   Input Parameter:
932083401c6SMatthew G. Knepley . prob - The PetscDS object
933083401c6SMatthew G. Knepley 
934083401c6SMatthew G. Knepley   Output Parameter:
935083401c6SMatthew G. Knepley . q - The quadrature object
936083401c6SMatthew G. Knepley 
937083401c6SMatthew G. Knepley Level: intermediate
938083401c6SMatthew G. Knepley 
939083401c6SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
940083401c6SMatthew G. Knepley @*/
941083401c6SMatthew G. Knepley PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q)
942083401c6SMatthew G. Knepley {
943083401c6SMatthew G. Knepley   PetscObject    obj;
944083401c6SMatthew G. Knepley   PetscClassId   id;
945083401c6SMatthew G. Knepley   PetscErrorCode ierr;
946083401c6SMatthew G. Knepley 
947083401c6SMatthew G. Knepley   PetscFunctionBegin;
948083401c6SMatthew G. Knepley   *q = NULL;
949083401c6SMatthew G. Knepley   if (!prob->Nf) PetscFunctionReturn(0);
950083401c6SMatthew G. Knepley   ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
951083401c6SMatthew G. Knepley   ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
952083401c6SMatthew G. Knepley   if      (id == PETSCFE_CLASSID) {ierr = PetscFEGetQuadrature((PetscFE) obj, q);CHKERRQ(ierr);}
953083401c6SMatthew G. Knepley   else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetQuadrature((PetscFV) obj, q);CHKERRQ(ierr);}
954083401c6SMatthew G. Knepley   else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
955083401c6SMatthew G. Knepley   PetscFunctionReturn(0);
956083401c6SMatthew G. Knepley }
957083401c6SMatthew G. Knepley 
958083401c6SMatthew G. Knepley /*@
959249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
960249df284SMatthew G. Knepley 
961249df284SMatthew G. Knepley   Not collective
962249df284SMatthew G. Knepley 
963249df284SMatthew G. Knepley   Input Parameters:
964249df284SMatthew G. Knepley + prob - The PetscDS object
965249df284SMatthew G. Knepley - f - The field number
966249df284SMatthew G. Knepley 
967249df284SMatthew G. Knepley   Output Parameter:
968249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
969249df284SMatthew G. Knepley 
970249df284SMatthew G. Knepley   Level: developer
971249df284SMatthew G. Knepley 
972f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
973249df284SMatthew G. Knepley @*/
974249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
975249df284SMatthew G. Knepley {
976249df284SMatthew G. Knepley   PetscFunctionBegin;
977249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
978249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
979249df284SMatthew 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);
980249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
981249df284SMatthew G. Knepley   PetscFunctionReturn(0);
982249df284SMatthew G. Knepley }
983249df284SMatthew G. Knepley 
984249df284SMatthew G. Knepley /*@
985249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
986249df284SMatthew G. Knepley 
987249df284SMatthew G. Knepley   Not collective
988249df284SMatthew G. Knepley 
989249df284SMatthew G. Knepley   Input Parameters:
990249df284SMatthew G. Knepley + prob - The PetscDS object
991249df284SMatthew G. Knepley . f - The field number
992249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
993249df284SMatthew G. Knepley 
994249df284SMatthew G. Knepley   Level: developer
995249df284SMatthew G. Knepley 
996f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
997249df284SMatthew G. Knepley @*/
998249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
999249df284SMatthew G. Knepley {
1000249df284SMatthew G. Knepley   PetscFunctionBegin;
1001249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1002249df284SMatthew 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);
1003249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
1004249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1005249df284SMatthew G. Knepley }
1006249df284SMatthew G. Knepley 
1007*f9244615SMatthew G. Knepley /*@
1008*f9244615SMatthew G. Knepley   PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1009*f9244615SMatthew G. Knepley 
1010*f9244615SMatthew G. Knepley   Not collective
1011*f9244615SMatthew G. Knepley 
1012*f9244615SMatthew G. Knepley   Input Parameters:
1013*f9244615SMatthew G. Knepley + ds - The PetscDS object
1014*f9244615SMatthew G. Knepley - f  - The field number
1015*f9244615SMatthew G. Knepley 
1016*f9244615SMatthew G. Knepley   Output Parameter:
1017*f9244615SMatthew G. Knepley . k  - The highest derivative we need to tabulate
1018*f9244615SMatthew G. Knepley 
1019*f9244615SMatthew G. Knepley   Level: developer
1020*f9244615SMatthew G. Knepley 
1021*f9244615SMatthew G. Knepley .seealso: PetscDSSetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1022*f9244615SMatthew G. Knepley @*/
1023*f9244615SMatthew G. Knepley PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k)
1024*f9244615SMatthew G. Knepley {
1025*f9244615SMatthew G. Knepley   PetscFunctionBegin;
1026*f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1027*f9244615SMatthew G. Knepley   PetscValidPointer(k, 3);
1028*f9244615SMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1029*f9244615SMatthew G. Knepley   *k = ds->jetDegree[f];
1030*f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1031*f9244615SMatthew G. Knepley }
1032*f9244615SMatthew G. Knepley 
1033*f9244615SMatthew G. Knepley /*@
1034*f9244615SMatthew G. Knepley   PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1035*f9244615SMatthew G. Knepley 
1036*f9244615SMatthew G. Knepley   Not collective
1037*f9244615SMatthew G. Knepley 
1038*f9244615SMatthew G. Knepley   Input Parameters:
1039*f9244615SMatthew G. Knepley + ds - The PetscDS object
1040*f9244615SMatthew G. Knepley . f  - The field number
1041*f9244615SMatthew G. Knepley - k  - The highest derivative we need to tabulate
1042*f9244615SMatthew G. Knepley 
1043*f9244615SMatthew G. Knepley   Level: developer
1044*f9244615SMatthew G. Knepley 
1045*f9244615SMatthew G. Knepley .seealso: PetscDSGetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
1046*f9244615SMatthew G. Knepley @*/
1047*f9244615SMatthew G. Knepley PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k)
1048*f9244615SMatthew G. Knepley {
1049*f9244615SMatthew G. Knepley   PetscFunctionBegin;
1050*f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1051*f9244615SMatthew G. Knepley   if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf);
1052*f9244615SMatthew G. Knepley   ds->jetDegree[f] = k;
1053*f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1054*f9244615SMatthew G. Knepley }
1055*f9244615SMatthew G. Knepley 
10562764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f,
105730b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1058194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1059194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
106097b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
10612764a2aaSMatthew G. Knepley {
10622764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10632764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10642764a2aaSMatthew G. Knepley   PetscValidPointer(obj, 2);
10652764a2aaSMatthew 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);
10662764a2aaSMatthew G. Knepley   *obj = prob->obj[f];
10672764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10682764a2aaSMatthew G. Knepley }
10692764a2aaSMatthew G. Knepley 
10702764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f,
107130b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1072194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1073194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
107497b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
10752764a2aaSMatthew G. Knepley {
10762764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
10772764a2aaSMatthew G. Knepley 
10782764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10792764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1080de716cbcSToby Isaac   if (obj) PetscValidFunction(obj, 2);
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->obj[f] = obj;
10842764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10852764a2aaSMatthew G. Knepley }
10862764a2aaSMatthew G. Knepley 
1087194d53e6SMatthew G. Knepley /*@C
1088194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1089194d53e6SMatthew G. Knepley 
1090194d53e6SMatthew G. Knepley   Not collective
1091194d53e6SMatthew G. Knepley 
1092194d53e6SMatthew G. Knepley   Input Parameters:
1093194d53e6SMatthew G. Knepley + prob - The PetscDS
1094194d53e6SMatthew G. Knepley - f    - The test field number
1095194d53e6SMatthew G. Knepley 
1096194d53e6SMatthew G. Knepley   Output Parameters:
1097194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1098194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1099194d53e6SMatthew G. Knepley 
1100194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1101194d53e6SMatthew G. Knepley 
1102194d53e6SMatthew 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)
1103194d53e6SMatthew G. Knepley 
1104194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1105194d53e6SMatthew G. Knepley 
110630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1107194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1108194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
110930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1110194d53e6SMatthew G. Knepley 
1111194d53e6SMatthew G. Knepley + dim - the spatial dimension
1112194d53e6SMatthew G. Knepley . Nf - the number of fields
1113194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1114194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1115194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1116194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1117194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1118194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1119194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1120194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1121194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1122194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1123194d53e6SMatthew G. Knepley . t - current time
1124194d53e6SMatthew G. Knepley . x - coordinates of the current point
112597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
112697b6e6e8SMatthew G. Knepley . constants - constant parameters
1127194d53e6SMatthew G. Knepley - f0 - output values at the current point
1128194d53e6SMatthew G. Knepley 
1129194d53e6SMatthew G. Knepley   Level: intermediate
1130194d53e6SMatthew G. Knepley 
1131194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
1132194d53e6SMatthew G. Knepley @*/
11332764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f,
113430b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1135194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1136194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
113797b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
113830b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1139194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1140194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
114197b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
11422764a2aaSMatthew G. Knepley {
11432764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11442764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11452764a2aaSMatthew 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);
11462764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];}
11472764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];}
11482764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11492764a2aaSMatthew G. Knepley }
11502764a2aaSMatthew G. Knepley 
1151194d53e6SMatthew G. Knepley /*@C
1152194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1153194d53e6SMatthew G. Knepley 
1154194d53e6SMatthew G. Knepley   Not collective
1155194d53e6SMatthew G. Knepley 
1156194d53e6SMatthew G. Knepley   Input Parameters:
1157194d53e6SMatthew G. Knepley + prob - The PetscDS
1158194d53e6SMatthew G. Knepley . f    - The test field number
1159194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1160194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1161194d53e6SMatthew G. Knepley 
1162194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1163194d53e6SMatthew G. Knepley 
1164194d53e6SMatthew 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)
1165194d53e6SMatthew G. Knepley 
1166194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1167194d53e6SMatthew G. Knepley 
116830b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1169194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1170194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117130b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1172194d53e6SMatthew G. Knepley 
1173194d53e6SMatthew G. Knepley + dim - the spatial dimension
1174194d53e6SMatthew G. Knepley . Nf - the number of fields
1175194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1176194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1177194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1178194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1179194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1180194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1181194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1182194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1183194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1184194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1185194d53e6SMatthew G. Knepley . t - current time
1186194d53e6SMatthew G. Knepley . x - coordinates of the current point
118797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
118897b6e6e8SMatthew G. Knepley . constants - constant parameters
1189194d53e6SMatthew G. Knepley - f0 - output values at the current point
1190194d53e6SMatthew G. Knepley 
1191194d53e6SMatthew G. Knepley   Level: intermediate
1192194d53e6SMatthew G. Knepley 
1193194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1194194d53e6SMatthew G. Knepley @*/
11952764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f,
119630b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1197194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1198194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
119997b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
120030b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1201194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1202194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
120397b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
12042764a2aaSMatthew G. Knepley {
12052764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
12062764a2aaSMatthew G. Knepley 
12072764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12082764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1209f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1210f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
12112764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
12122764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
12132764a2aaSMatthew G. Knepley   prob->f[f*2+0] = f0;
12142764a2aaSMatthew G. Knepley   prob->f[f*2+1] = f1;
12152764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12162764a2aaSMatthew G. Knepley }
12172764a2aaSMatthew G. Knepley 
12183e75805dSMatthew G. Knepley /*@C
12193e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
12203e75805dSMatthew G. Knepley 
12213e75805dSMatthew G. Knepley   Not collective
12223e75805dSMatthew G. Knepley 
12233e75805dSMatthew G. Knepley   Input Parameter:
12243e75805dSMatthew G. Knepley . prob - The PetscDS
12253e75805dSMatthew G. Knepley 
12263e75805dSMatthew G. Knepley   Output Parameter:
12273e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
12283e75805dSMatthew G. Knepley 
12293e75805dSMatthew G. Knepley   Level: intermediate
12303e75805dSMatthew G. Knepley 
12313e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
12323e75805dSMatthew G. Knepley @*/
12333e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac)
12343e75805dSMatthew G. Knepley {
12353e75805dSMatthew G. Knepley   PetscInt f, g, h;
12363e75805dSMatthew G. Knepley 
12373e75805dSMatthew G. Knepley   PetscFunctionBegin;
12383e75805dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
12393e75805dSMatthew G. Knepley   *hasJac = PETSC_FALSE;
12403e75805dSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
12413e75805dSMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
12423e75805dSMatthew G. Knepley       for (h = 0; h < 4; ++h) {
12433e75805dSMatthew G. Knepley         if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE;
12443e75805dSMatthew G. Knepley       }
12453e75805dSMatthew G. Knepley     }
12463e75805dSMatthew G. Knepley   }
12473e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
12483e75805dSMatthew G. Knepley }
12493e75805dSMatthew G. Knepley 
1250194d53e6SMatthew G. Knepley /*@C
1251194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1252194d53e6SMatthew G. Knepley 
1253194d53e6SMatthew G. Knepley   Not collective
1254194d53e6SMatthew G. Knepley 
1255194d53e6SMatthew G. Knepley   Input Parameters:
1256194d53e6SMatthew G. Knepley + prob - The PetscDS
1257194d53e6SMatthew G. Knepley . f    - The test field number
1258194d53e6SMatthew G. Knepley - g    - The field number
1259194d53e6SMatthew G. Knepley 
1260194d53e6SMatthew G. Knepley   Output Parameters:
1261194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1262194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1263194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1264194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1265194d53e6SMatthew G. Knepley 
1266194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1267194d53e6SMatthew G. Knepley 
1268194d53e6SMatthew 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
1269194d53e6SMatthew G. Knepley 
1270194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1271194d53e6SMatthew G. Knepley 
127230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1273194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1274194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
127530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1276194d53e6SMatthew G. Knepley 
1277194d53e6SMatthew G. Knepley + dim - the spatial dimension
1278194d53e6SMatthew G. Knepley . Nf - the number of fields
1279194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1280194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1281194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1282194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1283194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1284194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1285194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1286194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1287194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1288194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1289194d53e6SMatthew G. Knepley . t - current time
12902aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1291194d53e6SMatthew G. Knepley . x - coordinates of the current point
129297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
129397b6e6e8SMatthew G. Knepley . constants - constant parameters
1294194d53e6SMatthew G. Knepley - g0 - output values at the current point
1295194d53e6SMatthew G. Knepley 
1296194d53e6SMatthew G. Knepley   Level: intermediate
1297194d53e6SMatthew G. Knepley 
1298194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1299194d53e6SMatthew G. Knepley @*/
13002764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g,
130130b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1302194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1303194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
130530b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1306194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1307194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
130930b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1310194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1311194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
131297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
131330b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1314194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1315194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
131697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
13172764a2aaSMatthew G. Knepley {
13182764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13192764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
13202764a2aaSMatthew 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);
13212764a2aaSMatthew 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);
13222764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];}
13232764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];}
13242764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];}
13252764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];}
13262764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
13272764a2aaSMatthew G. Knepley }
13282764a2aaSMatthew G. Knepley 
1329194d53e6SMatthew G. Knepley /*@C
1330194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1331194d53e6SMatthew G. Knepley 
1332194d53e6SMatthew G. Knepley   Not collective
1333194d53e6SMatthew G. Knepley 
1334194d53e6SMatthew G. Knepley   Input Parameters:
1335194d53e6SMatthew G. Knepley + prob - The PetscDS
1336194d53e6SMatthew G. Knepley . f    - The test field number
1337194d53e6SMatthew G. Knepley . g    - The field number
1338194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1339194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1340194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1341194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1342194d53e6SMatthew G. Knepley 
1343194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1344194d53e6SMatthew G. Knepley 
1345194d53e6SMatthew 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
1346194d53e6SMatthew G. Knepley 
1347194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1348194d53e6SMatthew G. Knepley 
134930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1350194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1351194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
135230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1353194d53e6SMatthew G. Knepley 
1354194d53e6SMatthew G. Knepley + dim - the spatial dimension
1355194d53e6SMatthew G. Knepley . Nf - the number of fields
1356194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1357194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1358194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1359194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1360194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1361194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1362194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1363194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1364194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1365194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1366194d53e6SMatthew G. Knepley . t - current time
13672aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1368194d53e6SMatthew G. Knepley . x - coordinates of the current point
136997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
137097b6e6e8SMatthew G. Knepley . constants - constant parameters
1371194d53e6SMatthew G. Knepley - g0 - output values at the current point
1372194d53e6SMatthew G. Knepley 
1373194d53e6SMatthew G. Knepley   Level: intermediate
1374194d53e6SMatthew G. Knepley 
1375194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1376194d53e6SMatthew G. Knepley @*/
13772764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g,
137830b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1379194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1380194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
138197b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
138230b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1383194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1384194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
138597b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
138630b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1387194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1388194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
138997b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
139030b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1391194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1392194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
139397b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
13942764a2aaSMatthew G. Knepley {
13952764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
13962764a2aaSMatthew G. Knepley 
13972764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13982764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
13992764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
14002764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
14012764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
14022764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
14032764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
14042764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
14052764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
14062764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+0] = g0;
14072764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+1] = g1;
14082764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+2] = g2;
14092764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+3] = g3;
14102764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
14112764a2aaSMatthew G. Knepley }
14122764a2aaSMatthew G. Knepley 
1413475e0ac9SMatthew G. Knepley /*@C
141455c1f793SMatthew G. Knepley   PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner
141555c1f793SMatthew G. Knepley 
141655c1f793SMatthew G. Knepley   Not collective
141755c1f793SMatthew G. Knepley 
141855c1f793SMatthew G. Knepley   Input Parameters:
141955c1f793SMatthew G. Knepley + prob - The PetscDS
142055c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
142155c1f793SMatthew G. Knepley 
142255c1f793SMatthew G. Knepley   Level: intermediate
142355c1f793SMatthew G. Knepley 
142455c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
142555c1f793SMatthew G. Knepley @*/
142655c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
142755c1f793SMatthew G. Knepley {
142855c1f793SMatthew G. Knepley   PetscFunctionBegin;
142955c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
143055c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
143155c1f793SMatthew G. Knepley   PetscFunctionReturn(0);
143255c1f793SMatthew G. Knepley }
143355c1f793SMatthew G. Knepley 
143455c1f793SMatthew G. Knepley /*@C
1435475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1436475e0ac9SMatthew G. Knepley 
1437475e0ac9SMatthew G. Knepley   Not collective
1438475e0ac9SMatthew G. Knepley 
1439475e0ac9SMatthew G. Knepley   Input Parameter:
1440475e0ac9SMatthew G. Knepley . prob - The PetscDS
1441475e0ac9SMatthew G. Knepley 
1442475e0ac9SMatthew G. Knepley   Output Parameter:
1443475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1444475e0ac9SMatthew G. Knepley 
1445475e0ac9SMatthew G. Knepley   Level: intermediate
1446475e0ac9SMatthew G. Knepley 
1447475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1448475e0ac9SMatthew G. Knepley @*/
1449475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre)
1450475e0ac9SMatthew G. Knepley {
1451475e0ac9SMatthew G. Knepley   PetscInt f, g, h;
1452475e0ac9SMatthew G. Knepley 
1453475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1454475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1455475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
145655c1f793SMatthew G. Knepley   if (!prob->useJacPre) PetscFunctionReturn(0);
1457475e0ac9SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1458475e0ac9SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1459475e0ac9SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1460475e0ac9SMatthew G. Knepley         if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE;
1461475e0ac9SMatthew G. Knepley       }
1462475e0ac9SMatthew G. Knepley     }
1463475e0ac9SMatthew G. Knepley   }
1464475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1465475e0ac9SMatthew G. Knepley }
1466475e0ac9SMatthew G. Knepley 
1467475e0ac9SMatthew G. Knepley /*@C
1468475e0ac9SMatthew 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.
1469475e0ac9SMatthew G. Knepley 
1470475e0ac9SMatthew G. Knepley   Not collective
1471475e0ac9SMatthew G. Knepley 
1472475e0ac9SMatthew G. Knepley   Input Parameters:
1473475e0ac9SMatthew G. Knepley + prob - The PetscDS
1474475e0ac9SMatthew G. Knepley . f    - The test field number
1475475e0ac9SMatthew G. Knepley - g    - The field number
1476475e0ac9SMatthew G. Knepley 
1477475e0ac9SMatthew G. Knepley   Output Parameters:
1478475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1479475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1480475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1481475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1482475e0ac9SMatthew G. Knepley 
1483475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1484475e0ac9SMatthew G. Knepley 
1485475e0ac9SMatthew 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
1486475e0ac9SMatthew G. Knepley 
1487475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1488475e0ac9SMatthew G. Knepley 
1489475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1490475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1491475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1492475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1493475e0ac9SMatthew G. Knepley 
1494475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1495475e0ac9SMatthew G. Knepley . Nf - the number of fields
1496475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1497475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1498475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1499475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1500475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1501475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1502475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1503475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1504475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1505475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1506475e0ac9SMatthew G. Knepley . t - current time
1507475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1508475e0ac9SMatthew G. Knepley . x - coordinates of the current point
150997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
151097b6e6e8SMatthew G. Knepley . constants - constant parameters
1511475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1512475e0ac9SMatthew G. Knepley 
1513475e0ac9SMatthew G. Knepley   Level: intermediate
1514475e0ac9SMatthew G. Knepley 
1515475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1516475e0ac9SMatthew G. Knepley @*/
1517475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1518475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1519475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1520475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
152197b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1522475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1523475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1524475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
152597b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1526475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1527475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1528475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
152997b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1530475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1531475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1532475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
153397b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1534475e0ac9SMatthew G. Knepley {
1535475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1536475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1537475e0ac9SMatthew 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);
1538475e0ac9SMatthew 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);
1539475e0ac9SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];}
1540475e0ac9SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];}
1541475e0ac9SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];}
1542475e0ac9SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];}
1543475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1544475e0ac9SMatthew G. Knepley }
1545475e0ac9SMatthew G. Knepley 
1546475e0ac9SMatthew G. Knepley /*@C
1547475e0ac9SMatthew 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.
1548475e0ac9SMatthew G. Knepley 
1549475e0ac9SMatthew G. Knepley   Not collective
1550475e0ac9SMatthew G. Knepley 
1551475e0ac9SMatthew G. Knepley   Input Parameters:
1552475e0ac9SMatthew G. Knepley + prob - The PetscDS
1553475e0ac9SMatthew G. Knepley . f    - The test field number
1554475e0ac9SMatthew G. Knepley . g    - The field number
1555475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1556475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1557475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1558475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1559475e0ac9SMatthew G. Knepley 
1560475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1561475e0ac9SMatthew G. Knepley 
1562475e0ac9SMatthew 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
1563475e0ac9SMatthew G. Knepley 
1564475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1565475e0ac9SMatthew G. Knepley 
1566475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1567475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1568475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1569475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1570475e0ac9SMatthew G. Knepley 
1571475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1572475e0ac9SMatthew G. Knepley . Nf - the number of fields
1573475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1574475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1575475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1576475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1577475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1578475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1579475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1580475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1581475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1582475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1583475e0ac9SMatthew G. Knepley . t - current time
1584475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1585475e0ac9SMatthew G. Knepley . x - coordinates of the current point
158697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
158797b6e6e8SMatthew G. Knepley . constants - constant parameters
1588475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1589475e0ac9SMatthew G. Knepley 
1590475e0ac9SMatthew G. Knepley   Level: intermediate
1591475e0ac9SMatthew G. Knepley 
1592475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1593475e0ac9SMatthew G. Knepley @*/
1594475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1595475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1596475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1597475e0ac9SMatthew 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 g0[]),
1599475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1600475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1601475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
160297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1603475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1604475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1605475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
160697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1607475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1608475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1609475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
161097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1611475e0ac9SMatthew G. Knepley {
1612475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1613475e0ac9SMatthew G. Knepley 
1614475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1615475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1616475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1617475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1618475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1619475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1620475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1621475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1622475e0ac9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1623475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+0] = g0;
1624475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+1] = g1;
1625475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+2] = g2;
1626475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+3] = g3;
1627475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1628475e0ac9SMatthew G. Knepley }
1629475e0ac9SMatthew G. Knepley 
1630b7e05686SMatthew G. Knepley /*@C
1631b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1632b7e05686SMatthew G. Knepley 
1633b7e05686SMatthew G. Knepley   Not collective
1634b7e05686SMatthew G. Knepley 
1635b7e05686SMatthew G. Knepley   Input Parameter:
1636b7e05686SMatthew G. Knepley . prob - The PetscDS
1637b7e05686SMatthew G. Knepley 
1638b7e05686SMatthew G. Knepley   Output Parameter:
1639b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1640b7e05686SMatthew G. Knepley 
1641b7e05686SMatthew G. Knepley   Level: intermediate
1642b7e05686SMatthew G. Knepley 
1643b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1644b7e05686SMatthew G. Knepley @*/
1645b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac)
1646b7e05686SMatthew G. Knepley {
1647b7e05686SMatthew G. Knepley   PetscInt f, g, h;
1648b7e05686SMatthew G. Knepley 
1649b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1650b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1651b7e05686SMatthew G. Knepley   *hasDynJac = PETSC_FALSE;
1652b7e05686SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1653b7e05686SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1654b7e05686SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1655b7e05686SMatthew G. Knepley         if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE;
1656b7e05686SMatthew G. Knepley       }
1657b7e05686SMatthew G. Knepley     }
1658b7e05686SMatthew G. Knepley   }
1659b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1660b7e05686SMatthew G. Knepley }
1661b7e05686SMatthew G. Knepley 
1662b7e05686SMatthew G. Knepley /*@C
1663b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1664b7e05686SMatthew G. Knepley 
1665b7e05686SMatthew G. Knepley   Not collective
1666b7e05686SMatthew G. Knepley 
1667b7e05686SMatthew G. Knepley   Input Parameters:
1668b7e05686SMatthew G. Knepley + prob - The PetscDS
1669b7e05686SMatthew G. Knepley . f    - The test field number
1670b7e05686SMatthew G. Knepley - g    - The field number
1671b7e05686SMatthew G. Knepley 
1672b7e05686SMatthew G. Knepley   Output Parameters:
1673b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1674b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1675b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1676b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1677b7e05686SMatthew G. Knepley 
1678b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1679b7e05686SMatthew G. Knepley 
1680b7e05686SMatthew 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
1681b7e05686SMatthew G. Knepley 
1682b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1683b7e05686SMatthew G. Knepley 
1684b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1685b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1686b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1687b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1688b7e05686SMatthew G. Knepley 
1689b7e05686SMatthew G. Knepley + dim - the spatial dimension
1690b7e05686SMatthew G. Knepley . Nf - the number of fields
1691b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1692b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1693b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1694b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1695b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1696b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1697b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1698b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1699b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1700b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1701b7e05686SMatthew G. Knepley . t - current time
1702b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1703b7e05686SMatthew G. Knepley . x - coordinates of the current point
170497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
170597b6e6e8SMatthew G. Knepley . constants - constant parameters
1706b7e05686SMatthew G. Knepley - g0 - output values at the current point
1707b7e05686SMatthew G. Knepley 
1708b7e05686SMatthew G. Knepley   Level: intermediate
1709b7e05686SMatthew G. Knepley 
1710b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1711b7e05686SMatthew G. Knepley @*/
1712b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1713b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1714b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1715b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
171697b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1717b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1718b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1719b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
172097b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1721b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1722b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1723b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
172497b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1725b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1726b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1727b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
172897b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1729b7e05686SMatthew G. Knepley {
1730b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1731b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1732b7e05686SMatthew 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);
1733b7e05686SMatthew 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);
1734b7e05686SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];}
1735b7e05686SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];}
1736b7e05686SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];}
1737b7e05686SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];}
1738b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1739b7e05686SMatthew G. Knepley }
1740b7e05686SMatthew G. Knepley 
1741b7e05686SMatthew G. Knepley /*@C
1742b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1743b7e05686SMatthew G. Knepley 
1744b7e05686SMatthew G. Knepley   Not collective
1745b7e05686SMatthew G. Knepley 
1746b7e05686SMatthew G. Knepley   Input Parameters:
1747b7e05686SMatthew G. Knepley + prob - The PetscDS
1748b7e05686SMatthew G. Knepley . f    - The test field number
1749b7e05686SMatthew G. Knepley . g    - The field number
1750b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1751b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1752b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1753b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1754b7e05686SMatthew G. Knepley 
1755b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1756b7e05686SMatthew G. Knepley 
1757b7e05686SMatthew 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
1758b7e05686SMatthew G. Knepley 
1759b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1760b7e05686SMatthew G. Knepley 
1761b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1762b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1763b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1764b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1765b7e05686SMatthew G. Knepley 
1766b7e05686SMatthew G. Knepley + dim - the spatial dimension
1767b7e05686SMatthew G. Knepley . Nf - the number of fields
1768b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1769b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1770b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1771b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1772b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1773b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1774b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1775b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1776b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1777b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1778b7e05686SMatthew G. Knepley . t - current time
1779b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1780b7e05686SMatthew G. Knepley . x - coordinates of the current point
178197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
178297b6e6e8SMatthew G. Knepley . constants - constant parameters
1783b7e05686SMatthew G. Knepley - g0 - output values at the current point
1784b7e05686SMatthew G. Knepley 
1785b7e05686SMatthew G. Knepley   Level: intermediate
1786b7e05686SMatthew G. Knepley 
1787b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1788b7e05686SMatthew G. Knepley @*/
1789b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1790b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1791b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1792b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
179397b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1794b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1795b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1796b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
179797b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1798b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1799b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1800b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
180197b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1802b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1803b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1804b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
180597b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1806b7e05686SMatthew G. Knepley {
1807b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1808b7e05686SMatthew G. Knepley 
1809b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1810b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1811b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1812b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1813b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1814b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1815b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1816b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1817b7e05686SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1818b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+0] = g0;
1819b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+1] = g1;
1820b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+2] = g2;
1821b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+3] = g3;
1822b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1823b7e05686SMatthew G. Knepley }
1824b7e05686SMatthew G. Knepley 
18250c2f2876SMatthew G. Knepley /*@C
18260c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
18270c2f2876SMatthew G. Knepley 
18280c2f2876SMatthew G. Knepley   Not collective
18290c2f2876SMatthew G. Knepley 
18300c2f2876SMatthew G. Knepley   Input Arguments:
18310c2f2876SMatthew G. Knepley + prob - The PetscDS object
18320c2f2876SMatthew G. Knepley - f    - The field number
18330c2f2876SMatthew G. Knepley 
18340c2f2876SMatthew G. Knepley   Output Argument:
18350c2f2876SMatthew G. Knepley . r    - Riemann solver
18360c2f2876SMatthew G. Knepley 
18370c2f2876SMatthew G. Knepley   Calling sequence for r:
18380c2f2876SMatthew G. Knepley 
18395db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
18400c2f2876SMatthew G. Knepley 
18415db36cf9SMatthew G. Knepley + dim  - The spatial dimension
18425db36cf9SMatthew G. Knepley . Nf   - The number of fields
18435db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
18440c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
18450c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
18460c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
18470c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
184897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
184997b6e6e8SMatthew G. Knepley . constants - constant parameters
18500c2f2876SMatthew G. Knepley - ctx  - optional user context
18510c2f2876SMatthew G. Knepley 
18520c2f2876SMatthew G. Knepley   Level: intermediate
18530c2f2876SMatthew G. Knepley 
18540c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
18550c2f2876SMatthew G. Knepley @*/
18560c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f,
185797b6e6e8SMatthew 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))
18580c2f2876SMatthew G. Knepley {
18590c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18600c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18610c2f2876SMatthew 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);
18620c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
18630c2f2876SMatthew G. Knepley   *r = prob->r[f];
18640c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18650c2f2876SMatthew G. Knepley }
18660c2f2876SMatthew G. Knepley 
18670c2f2876SMatthew G. Knepley /*@C
18680c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
18690c2f2876SMatthew G. Knepley 
18700c2f2876SMatthew G. Knepley   Not collective
18710c2f2876SMatthew G. Knepley 
18720c2f2876SMatthew G. Knepley   Input Arguments:
18730c2f2876SMatthew G. Knepley + prob - The PetscDS object
18740c2f2876SMatthew G. Knepley . f    - The field number
18750c2f2876SMatthew G. Knepley - r    - Riemann solver
18760c2f2876SMatthew G. Knepley 
18770c2f2876SMatthew G. Knepley   Calling sequence for r:
18780c2f2876SMatthew G. Knepley 
18795db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
18800c2f2876SMatthew G. Knepley 
18815db36cf9SMatthew G. Knepley + dim  - The spatial dimension
18825db36cf9SMatthew G. Knepley . Nf   - The number of fields
18835db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
18840c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
18850c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
18860c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
18870c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
188897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
188997b6e6e8SMatthew G. Knepley . constants - constant parameters
18900c2f2876SMatthew G. Knepley - ctx  - optional user context
18910c2f2876SMatthew G. Knepley 
18920c2f2876SMatthew G. Knepley   Level: intermediate
18930c2f2876SMatthew G. Knepley 
18940c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
18950c2f2876SMatthew G. Knepley @*/
18960c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f,
189797b6e6e8SMatthew 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))
18980c2f2876SMatthew G. Knepley {
18990c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
19000c2f2876SMatthew G. Knepley 
19010c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19020c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1903de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
19040c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19050c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
19060c2f2876SMatthew G. Knepley   prob->r[f] = r;
19070c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19080c2f2876SMatthew G. Knepley }
19090c2f2876SMatthew G. Knepley 
191032d2bbc9SMatthew G. Knepley /*@C
191132d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
191232d2bbc9SMatthew G. Knepley 
191332d2bbc9SMatthew G. Knepley   Not collective
191432d2bbc9SMatthew G. Knepley 
191532d2bbc9SMatthew G. Knepley   Input Parameters:
191632d2bbc9SMatthew G. Knepley + prob - The PetscDS
191732d2bbc9SMatthew G. Knepley - f    - The field number
191832d2bbc9SMatthew G. Knepley 
191932d2bbc9SMatthew G. Knepley   Output Parameters:
1920a2b725a8SWilliam Gropp . update - update function
192132d2bbc9SMatthew G. Knepley 
192232d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
192332d2bbc9SMatthew G. Knepley 
192432d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
192532d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
192632d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
192732d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
192832d2bbc9SMatthew G. Knepley 
192932d2bbc9SMatthew G. Knepley + dim - the spatial dimension
193032d2bbc9SMatthew G. Knepley . Nf - the number of fields
193132d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
193232d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
193332d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
193432d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
193532d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
193632d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
193732d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
193832d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
193932d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
194032d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
194132d2bbc9SMatthew G. Knepley . t - current time
194232d2bbc9SMatthew G. Knepley . x - coordinates of the current point
194332d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
194432d2bbc9SMatthew G. Knepley 
194532d2bbc9SMatthew G. Knepley   Level: intermediate
194632d2bbc9SMatthew G. Knepley 
194732d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
194832d2bbc9SMatthew G. Knepley @*/
194932d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f,
195032d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
195132d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
195232d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19533fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
195432d2bbc9SMatthew G. Knepley {
195532d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
195632d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
195732d2bbc9SMatthew 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);
195832d2bbc9SMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = prob->update[f];}
195932d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
196032d2bbc9SMatthew G. Knepley }
196132d2bbc9SMatthew G. Knepley 
196232d2bbc9SMatthew G. Knepley /*@C
19633fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
196432d2bbc9SMatthew G. Knepley 
196532d2bbc9SMatthew G. Knepley   Not collective
196632d2bbc9SMatthew G. Knepley 
196732d2bbc9SMatthew G. Knepley   Input Parameters:
196832d2bbc9SMatthew G. Knepley + prob   - The PetscDS
196932d2bbc9SMatthew G. Knepley . f      - The field number
197032d2bbc9SMatthew G. Knepley - update - update function
197132d2bbc9SMatthew G. Knepley 
197232d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
197332d2bbc9SMatthew G. Knepley 
197432d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
197532d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
197632d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
197732d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
197832d2bbc9SMatthew G. Knepley 
197932d2bbc9SMatthew G. Knepley + dim - the spatial dimension
198032d2bbc9SMatthew G. Knepley . Nf - the number of fields
198132d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
198232d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
198332d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
198432d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
198532d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
198632d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
198732d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
198832d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
198932d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
199032d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
199132d2bbc9SMatthew G. Knepley . t - current time
199232d2bbc9SMatthew G. Knepley . x - coordinates of the current point
199332d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
199432d2bbc9SMatthew G. Knepley 
199532d2bbc9SMatthew G. Knepley   Level: intermediate
199632d2bbc9SMatthew G. Knepley 
199732d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
199832d2bbc9SMatthew G. Knepley @*/
199932d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f,
200032d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
200132d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
200232d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20033fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
200432d2bbc9SMatthew G. Knepley {
200532d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
200632d2bbc9SMatthew G. Knepley 
200732d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
200832d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
200932d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
201032d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
201132d2bbc9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
201232d2bbc9SMatthew G. Knepley   prob->update[f] = update;
201332d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
201432d2bbc9SMatthew G. Knepley }
201532d2bbc9SMatthew G. Knepley 
20160c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx)
20170c2f2876SMatthew G. Knepley {
20180c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20190c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20200c2f2876SMatthew 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);
20210c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
20220c2f2876SMatthew G. Knepley   *ctx = prob->ctx[f];
20230c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20240c2f2876SMatthew G. Knepley }
20250c2f2876SMatthew G. Knepley 
20260c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx)
20270c2f2876SMatthew G. Knepley {
20280c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
20290c2f2876SMatthew G. Knepley 
20300c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20310c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20320c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
20330c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
20340c2f2876SMatthew G. Knepley   prob->ctx[f] = ctx;
20350c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20360c2f2876SMatthew G. Knepley }
20370c2f2876SMatthew G. Knepley 
2038194d53e6SMatthew G. Knepley /*@C
2039194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
2040194d53e6SMatthew G. Knepley 
2041194d53e6SMatthew G. Knepley   Not collective
2042194d53e6SMatthew G. Knepley 
2043194d53e6SMatthew G. Knepley   Input Parameters:
2044194d53e6SMatthew G. Knepley + prob - The PetscDS
2045194d53e6SMatthew G. Knepley - f    - The test field number
2046194d53e6SMatthew G. Knepley 
2047194d53e6SMatthew G. Knepley   Output Parameters:
2048194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
2049194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2050194d53e6SMatthew G. Knepley 
2051194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2052194d53e6SMatthew G. Knepley 
2053194d53e6SMatthew 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
2054194d53e6SMatthew G. Knepley 
2055194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2056194d53e6SMatthew G. Knepley 
205730b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2058194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2059194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
206030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2061194d53e6SMatthew G. Knepley 
2062194d53e6SMatthew G. Knepley + dim - the spatial dimension
2063194d53e6SMatthew G. Knepley . Nf - the number of fields
2064194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2065194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2066194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2067194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2068194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2069194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2070194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2071194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2072194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2073194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2074194d53e6SMatthew G. Knepley . t - current time
2075194d53e6SMatthew G. Knepley . x - coordinates of the current point
2076194d53e6SMatthew G. Knepley . n - unit normal at the current point
207797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
207897b6e6e8SMatthew G. Knepley . constants - constant parameters
2079194d53e6SMatthew G. Knepley - f0 - output values at the current point
2080194d53e6SMatthew G. Knepley 
2081194d53e6SMatthew G. Knepley   Level: intermediate
2082194d53e6SMatthew G. Knepley 
2083194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
2084194d53e6SMatthew G. Knepley @*/
20852764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f,
208630b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2087194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2088194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
208997b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
209030b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2091194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2092194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
209397b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
20942764a2aaSMatthew G. Knepley {
20952764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20962764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20972764a2aaSMatthew 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);
20982764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];}
20992764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];}
21002764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21012764a2aaSMatthew G. Knepley }
21022764a2aaSMatthew G. Knepley 
2103194d53e6SMatthew G. Knepley /*@C
2104194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2105194d53e6SMatthew G. Knepley 
2106194d53e6SMatthew G. Knepley   Not collective
2107194d53e6SMatthew G. Knepley 
2108194d53e6SMatthew G. Knepley   Input Parameters:
2109194d53e6SMatthew G. Knepley + prob - The PetscDS
2110194d53e6SMatthew G. Knepley . f    - The test field number
2111194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2112194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2113194d53e6SMatthew G. Knepley 
2114194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2115194d53e6SMatthew G. Knepley 
2116194d53e6SMatthew 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
2117194d53e6SMatthew G. Knepley 
2118194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2119194d53e6SMatthew G. Knepley 
212030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2121194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2122194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
212330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2124194d53e6SMatthew G. Knepley 
2125194d53e6SMatthew G. Knepley + dim - the spatial dimension
2126194d53e6SMatthew G. Knepley . Nf - the number of fields
2127194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2128194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2129194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2130194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2131194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2132194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2133194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2134194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2135194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2136194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2137194d53e6SMatthew G. Knepley . t - current time
2138194d53e6SMatthew G. Knepley . x - coordinates of the current point
2139194d53e6SMatthew G. Knepley . n - unit normal at the current point
214097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
214197b6e6e8SMatthew G. Knepley . constants - constant parameters
2142194d53e6SMatthew G. Knepley - f0 - output values at the current point
2143194d53e6SMatthew G. Knepley 
2144194d53e6SMatthew G. Knepley   Level: intermediate
2145194d53e6SMatthew G. Knepley 
2146194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
2147194d53e6SMatthew G. Knepley @*/
21482764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f,
214930b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2150194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2151194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
215297b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
215330b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2154194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2155194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
215697b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
21572764a2aaSMatthew G. Knepley {
21582764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21592764a2aaSMatthew G. Knepley 
21602764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21612764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21622764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21632764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
21642764a2aaSMatthew G. Knepley   if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;}
21652764a2aaSMatthew G. Knepley   if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;}
21662764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21672764a2aaSMatthew G. Knepley }
21682764a2aaSMatthew G. Knepley 
216927f02ce8SMatthew G. Knepley /*@
217027f02ce8SMatthew G. Knepley   PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set
217127f02ce8SMatthew G. Knepley 
217227f02ce8SMatthew G. Knepley   Not collective
217327f02ce8SMatthew G. Knepley 
217427f02ce8SMatthew G. Knepley   Input Parameter:
217527f02ce8SMatthew G. Knepley . prob - The PetscDS
217627f02ce8SMatthew G. Knepley 
217727f02ce8SMatthew G. Knepley   Output Parameter:
217827f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set
217927f02ce8SMatthew G. Knepley 
218027f02ce8SMatthew G. Knepley   Level: intermediate
218127f02ce8SMatthew G. Knepley 
218227f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
218327f02ce8SMatthew G. Knepley @*/
218427f02ce8SMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobian(PetscDS prob, PetscBool *hasBdJac)
218527f02ce8SMatthew G. Knepley {
218627f02ce8SMatthew G. Knepley   PetscInt f, g, h;
218727f02ce8SMatthew G. Knepley 
218827f02ce8SMatthew G. Knepley   PetscFunctionBegin;
218927f02ce8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
219027f02ce8SMatthew G. Knepley   *hasBdJac = PETSC_FALSE;
219127f02ce8SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
219227f02ce8SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
219327f02ce8SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
219427f02ce8SMatthew G. Knepley         if (prob->gBd[(f*prob->Nf + g)*4+h]) *hasBdJac = PETSC_TRUE;
219527f02ce8SMatthew G. Knepley       }
219627f02ce8SMatthew G. Knepley     }
219727f02ce8SMatthew G. Knepley   }
219827f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
219927f02ce8SMatthew G. Knepley }
220027f02ce8SMatthew G. Knepley 
2201194d53e6SMatthew G. Knepley /*@C
2202194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2203194d53e6SMatthew G. Knepley 
2204194d53e6SMatthew G. Knepley   Not collective
2205194d53e6SMatthew G. Knepley 
2206194d53e6SMatthew G. Knepley   Input Parameters:
2207194d53e6SMatthew G. Knepley + prob - The PetscDS
2208194d53e6SMatthew G. Knepley . f    - The test field number
2209194d53e6SMatthew G. Knepley - g    - The field number
2210194d53e6SMatthew G. Knepley 
2211194d53e6SMatthew G. Knepley   Output Parameters:
2212194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2213194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2214194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2215194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2216194d53e6SMatthew G. Knepley 
2217194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2218194d53e6SMatthew G. Knepley 
2219194d53e6SMatthew 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
2220194d53e6SMatthew G. Knepley 
2221194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2222194d53e6SMatthew G. Knepley 
222330b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2224194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2225194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
222630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2227194d53e6SMatthew G. Knepley 
2228194d53e6SMatthew G. Knepley + dim - the spatial dimension
2229194d53e6SMatthew G. Knepley . Nf - the number of fields
2230194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2231194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2232194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2233194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2234194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2235194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2236194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2237194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2238194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2239194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2240194d53e6SMatthew G. Knepley . t - current time
22412aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2242194d53e6SMatthew G. Knepley . x - coordinates of the current point
2243194d53e6SMatthew G. Knepley . n - normal at the current point
224497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
224597b6e6e8SMatthew G. Knepley . constants - constant parameters
2246194d53e6SMatthew G. Knepley - g0 - output values at the current point
2247194d53e6SMatthew G. Knepley 
2248194d53e6SMatthew G. Knepley   Level: intermediate
2249194d53e6SMatthew G. Knepley 
2250194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2251194d53e6SMatthew G. Knepley @*/
22522764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
225330b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2254194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2255194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
225697b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
225730b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2258194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2259194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
226097b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
226130b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2262194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2263194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
226497b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
226530b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2266194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2267194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
226897b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
22692764a2aaSMatthew G. Knepley {
22702764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22712764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22722764a2aaSMatthew 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);
22732764a2aaSMatthew 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);
22742764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];}
22752764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];}
22762764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];}
22772764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];}
22782764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22792764a2aaSMatthew G. Knepley }
22802764a2aaSMatthew G. Knepley 
2281194d53e6SMatthew G. Knepley /*@C
2282194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2283194d53e6SMatthew G. Knepley 
2284194d53e6SMatthew G. Knepley   Not collective
2285194d53e6SMatthew G. Knepley 
2286194d53e6SMatthew G. Knepley   Input Parameters:
2287194d53e6SMatthew G. Knepley + prob - The PetscDS
2288194d53e6SMatthew G. Knepley . f    - The test field number
2289194d53e6SMatthew G. Knepley . g    - The field number
2290194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2291194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2292194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2293194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2294194d53e6SMatthew G. Knepley 
2295194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2296194d53e6SMatthew G. Knepley 
2297194d53e6SMatthew 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
2298194d53e6SMatthew G. Knepley 
2299194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2300194d53e6SMatthew G. Knepley 
230130b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2302194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2303194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
230430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2305194d53e6SMatthew G. Knepley 
2306194d53e6SMatthew G. Knepley + dim - the spatial dimension
2307194d53e6SMatthew G. Knepley . Nf - the number of fields
2308194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2309194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2310194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2311194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2312194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2313194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2314194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2315194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2316194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2317194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2318194d53e6SMatthew G. Knepley . t - current time
23192aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2320194d53e6SMatthew G. Knepley . x - coordinates of the current point
2321194d53e6SMatthew G. Knepley . n - normal at the current point
232297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
232397b6e6e8SMatthew G. Knepley . constants - constant parameters
2324194d53e6SMatthew G. Knepley - g0 - output values at the current point
2325194d53e6SMatthew G. Knepley 
2326194d53e6SMatthew G. Knepley   Level: intermediate
2327194d53e6SMatthew G. Knepley 
2328194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2329194d53e6SMatthew G. Knepley @*/
23302764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
233130b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2332194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2333194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
233497b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
233530b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2336194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2337194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
233897b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
233930b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2340194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2341194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
234297b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
234330b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2344194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2345194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
234697b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
23472764a2aaSMatthew G. Knepley {
23482764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23492764a2aaSMatthew G. Knepley 
23502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23512764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23522764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
23532764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
23542764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
23552764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
23562764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
23572764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
23582764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
23592764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+0] = g0;
23602764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+1] = g1;
23612764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+2] = g2;
23622764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+3] = g3;
23632764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23642764a2aaSMatthew G. Knepley }
23652764a2aaSMatthew G. Knepley 
236627f02ce8SMatthew G. Knepley /*@
236727f02ce8SMatthew G. Knepley   PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set
236827f02ce8SMatthew G. Knepley 
236927f02ce8SMatthew G. Knepley   Not collective
237027f02ce8SMatthew G. Knepley 
237127f02ce8SMatthew G. Knepley   Input Parameter:
237227f02ce8SMatthew G. Knepley . prob - The PetscDS
237327f02ce8SMatthew G. Knepley 
237427f02ce8SMatthew G. Knepley   Output Parameter:
237527f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set
237627f02ce8SMatthew G. Knepley 
237727f02ce8SMatthew G. Knepley   Level: intermediate
237827f02ce8SMatthew G. Knepley 
237927f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian()
238027f02ce8SMatthew G. Knepley @*/
238127f02ce8SMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS prob, PetscBool *hasBdJacPre)
238227f02ce8SMatthew G. Knepley {
238327f02ce8SMatthew G. Knepley   PetscInt f, g, h;
238427f02ce8SMatthew G. Knepley 
238527f02ce8SMatthew G. Knepley   PetscFunctionBegin;
238627f02ce8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
238727f02ce8SMatthew G. Knepley   *hasBdJacPre = PETSC_FALSE;
238827f02ce8SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
238927f02ce8SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
239027f02ce8SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
239127f02ce8SMatthew G. Knepley         if (prob->gpBd[(f*prob->Nf + g)*4+h]) *hasBdJacPre = PETSC_TRUE;
239227f02ce8SMatthew G. Knepley       }
239327f02ce8SMatthew G. Knepley     }
239427f02ce8SMatthew G. Knepley   }
239527f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
239627f02ce8SMatthew G. Knepley }
239727f02ce8SMatthew G. Knepley 
239827f02ce8SMatthew G. Knepley /*@C
239927f02ce8SMatthew G. Knepley   PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field
240027f02ce8SMatthew G. Knepley 
240127f02ce8SMatthew G. Knepley   Not collective
240227f02ce8SMatthew G. Knepley 
240327f02ce8SMatthew G. Knepley   Input Parameters:
240427f02ce8SMatthew G. Knepley + prob - The PetscDS
240527f02ce8SMatthew G. Knepley . f    - The test field number
240627f02ce8SMatthew G. Knepley - g    - The field number
240727f02ce8SMatthew G. Knepley 
240827f02ce8SMatthew G. Knepley   Output Parameters:
240927f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term
241027f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
241127f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
241227f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
241327f02ce8SMatthew G. Knepley 
241427f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
241527f02ce8SMatthew G. Knepley 
241627f02ce8SMatthew 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
241727f02ce8SMatthew G. Knepley 
241827f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
241927f02ce8SMatthew G. Knepley 
242027f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
242127f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
242227f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
242327f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
242427f02ce8SMatthew G. Knepley 
242527f02ce8SMatthew G. Knepley + dim - the spatial dimension
242627f02ce8SMatthew G. Knepley . Nf - the number of fields
242727f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
242827f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
242927f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
243027f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
243127f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
243227f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
243327f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
243427f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
243527f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
243627f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
243727f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
243827f02ce8SMatthew G. Knepley . t - current time
243927f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
244027f02ce8SMatthew G. Knepley . x - coordinates of the current point
244127f02ce8SMatthew G. Knepley . n - normal at the current point
244227f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
244327f02ce8SMatthew G. Knepley . constants - constant parameters
244427f02ce8SMatthew G. Knepley - g0 - output values at the current point
244527f02ce8SMatthew G. Knepley 
244627f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
244727f02ce8SMatthew G. Knepley 
244827f02ce8SMatthew G. Knepley   Level: intermediate
244927f02ce8SMatthew G. Knepley 
245027f02ce8SMatthew G. Knepley .seealso: PetscDSSetBdJacobianPreconditioner()
245127f02ce8SMatthew G. Knepley @*/
245227f02ce8SMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
245327f02ce8SMatthew G. Knepley                                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
245427f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
245527f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
245627f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
245727f02ce8SMatthew G. Knepley                                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
245827f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
245927f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
246027f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
246127f02ce8SMatthew G. Knepley                                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
246227f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
246327f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
246427f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
246527f02ce8SMatthew G. Knepley                                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
246627f02ce8SMatthew G. Knepley                                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
246727f02ce8SMatthew G. Knepley                                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
246827f02ce8SMatthew G. Knepley                                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
246927f02ce8SMatthew G. Knepley {
247027f02ce8SMatthew G. Knepley   PetscFunctionBegin;
247127f02ce8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
247227f02ce8SMatthew 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);
247327f02ce8SMatthew 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);
247427f02ce8SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gpBd[(f*prob->Nf + g)*4+0];}
247527f02ce8SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gpBd[(f*prob->Nf + g)*4+1];}
247627f02ce8SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gpBd[(f*prob->Nf + g)*4+2];}
247727f02ce8SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gpBd[(f*prob->Nf + g)*4+3];}
247827f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
247927f02ce8SMatthew G. Knepley }
248027f02ce8SMatthew G. Knepley 
248127f02ce8SMatthew G. Knepley /*@C
248227f02ce8SMatthew G. Knepley   PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field
248327f02ce8SMatthew G. Knepley 
248427f02ce8SMatthew G. Knepley   Not collective
248527f02ce8SMatthew G. Knepley 
248627f02ce8SMatthew G. Knepley   Input Parameters:
248727f02ce8SMatthew G. Knepley + prob - The PetscDS
248827f02ce8SMatthew G. Knepley . f    - The test field number
248927f02ce8SMatthew G. Knepley . g    - The field number
249027f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term
249127f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
249227f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
249327f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
249427f02ce8SMatthew G. Knepley 
249527f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
249627f02ce8SMatthew G. Knepley 
249727f02ce8SMatthew 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
249827f02ce8SMatthew G. Knepley 
249927f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
250027f02ce8SMatthew G. Knepley 
250127f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
250227f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
250327f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
250427f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
250527f02ce8SMatthew G. Knepley 
250627f02ce8SMatthew G. Knepley + dim - the spatial dimension
250727f02ce8SMatthew G. Knepley . Nf - the number of fields
250827f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
250927f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
251027f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
251127f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
251227f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
251327f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
251427f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
251527f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
251627f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
251727f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
251827f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
251927f02ce8SMatthew G. Knepley . t - current time
252027f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
252127f02ce8SMatthew G. Knepley . x - coordinates of the current point
252227f02ce8SMatthew G. Knepley . n - normal at the current point
252327f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
252427f02ce8SMatthew G. Knepley . constants - constant parameters
252527f02ce8SMatthew G. Knepley - g0 - output values at the current point
252627f02ce8SMatthew G. Knepley 
252727f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
252827f02ce8SMatthew G. Knepley 
252927f02ce8SMatthew G. Knepley   Level: intermediate
253027f02ce8SMatthew G. Knepley 
253127f02ce8SMatthew G. Knepley .seealso: PetscDSGetBdJacobianPreconditioner()
253227f02ce8SMatthew G. Knepley @*/
253327f02ce8SMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
253427f02ce8SMatthew G. Knepley                                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
253527f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
253627f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
253727f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
253827f02ce8SMatthew G. Knepley                                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
253927f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
254027f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
254127f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
254227f02ce8SMatthew G. Knepley                                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
254327f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
254427f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
254527f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
254627f02ce8SMatthew G. Knepley                                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
254727f02ce8SMatthew G. Knepley                                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
254827f02ce8SMatthew G. Knepley                                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
254927f02ce8SMatthew G. Knepley                                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
255027f02ce8SMatthew G. Knepley {
255127f02ce8SMatthew G. Knepley   PetscErrorCode ierr;
255227f02ce8SMatthew G. Knepley 
255327f02ce8SMatthew G. Knepley   PetscFunctionBegin;
255427f02ce8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
255527f02ce8SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
255627f02ce8SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
255727f02ce8SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
255827f02ce8SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
255927f02ce8SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
256027f02ce8SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
256127f02ce8SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
256227f02ce8SMatthew G. Knepley   prob->gpBd[(f*prob->Nf + g)*4+0] = g0;
256327f02ce8SMatthew G. Knepley   prob->gpBd[(f*prob->Nf + g)*4+1] = g1;
256427f02ce8SMatthew G. Knepley   prob->gpBd[(f*prob->Nf + g)*4+2] = g2;
256527f02ce8SMatthew G. Knepley   prob->gpBd[(f*prob->Nf + g)*4+3] = g3;
256627f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
256727f02ce8SMatthew G. Knepley }
256827f02ce8SMatthew G. Knepley 
25690d3e9b51SMatthew G. Knepley /*@C
2570c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2571c371a6d1SMatthew G. Knepley 
2572c371a6d1SMatthew G. Knepley   Not collective
2573c371a6d1SMatthew G. Knepley 
2574c371a6d1SMatthew G. Knepley   Input Parameters:
2575c371a6d1SMatthew G. Knepley + prob - The PetscDS
2576c371a6d1SMatthew G. Knepley - f    - The test field number
2577c371a6d1SMatthew G. Knepley 
2578c371a6d1SMatthew G. Knepley   Output Parameter:
257995cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field
258095cbbfd3SMatthew G. Knepley - exactCtx - exact solution context
2581c371a6d1SMatthew G. Knepley 
2582c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2583c371a6d1SMatthew G. Knepley 
2584c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2585c371a6d1SMatthew G. Knepley 
2586c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2587c371a6d1SMatthew G. Knepley . t - current time
2588c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2589c371a6d1SMatthew G. Knepley . Nc - the number of field components
2590c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2591c371a6d1SMatthew G. Knepley - ctx - a user context
2592c371a6d1SMatthew G. Knepley 
2593c371a6d1SMatthew G. Knepley   Level: intermediate
2594c371a6d1SMatthew G. Knepley 
2595f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolution(), PetscDSGetExactSolutionTimeDerivative()
2596c371a6d1SMatthew G. Knepley @*/
259795cbbfd3SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2598c371a6d1SMatthew G. Knepley {
2599c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2600c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2601c371a6d1SMatthew 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);
2602c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
260395cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];}
2604c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2605c371a6d1SMatthew G. Knepley }
2606c371a6d1SMatthew G. Knepley 
2607c371a6d1SMatthew G. Knepley /*@C
2608578a5ef5SMatthew Knepley   PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field
2609c371a6d1SMatthew G. Knepley 
2610c371a6d1SMatthew G. Knepley   Not collective
2611c371a6d1SMatthew G. Knepley 
2612c371a6d1SMatthew G. Knepley   Input Parameters:
2613c371a6d1SMatthew G. Knepley + prob - The PetscDS
2614c371a6d1SMatthew G. Knepley . f    - The test field number
261595cbbfd3SMatthew G. Knepley . sol  - solution function for the test fields
261695cbbfd3SMatthew G. Knepley - ctx  - solution context or NULL
2617c371a6d1SMatthew G. Knepley 
2618c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2619c371a6d1SMatthew G. Knepley 
2620c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2621c371a6d1SMatthew G. Knepley 
2622c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2623c371a6d1SMatthew G. Knepley . t - current time
2624c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2625c371a6d1SMatthew G. Knepley . Nc - the number of field components
2626c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2627c371a6d1SMatthew G. Knepley - ctx - a user context
2628c371a6d1SMatthew G. Knepley 
2629c371a6d1SMatthew G. Knepley   Level: intermediate
2630c371a6d1SMatthew G. Knepley 
2631c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2632c371a6d1SMatthew G. Knepley @*/
263395cbbfd3SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2634c371a6d1SMatthew G. Knepley {
2635c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2636c371a6d1SMatthew G. Knepley 
2637c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2638c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2639c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2640c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2641c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
264295cbbfd3SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;}
2643c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2644c371a6d1SMatthew G. Knepley }
2645c371a6d1SMatthew G. Knepley 
26465638fd0eSMatthew G. Knepley /*@C
2647f2cacb80SMatthew G. Knepley   PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field
2648f2cacb80SMatthew G. Knepley 
2649f2cacb80SMatthew G. Knepley   Not collective
2650f2cacb80SMatthew G. Knepley 
2651f2cacb80SMatthew G. Knepley   Input Parameters:
2652f2cacb80SMatthew G. Knepley + prob - The PetscDS
2653f2cacb80SMatthew G. Knepley - f    - The test field number
2654f2cacb80SMatthew G. Knepley 
2655f2cacb80SMatthew G. Knepley   Output Parameter:
2656f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field
2657f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context
2658f2cacb80SMatthew G. Knepley 
2659f2cacb80SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2660f2cacb80SMatthew G. Knepley 
2661f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2662f2cacb80SMatthew G. Knepley 
2663f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2664f2cacb80SMatthew G. Knepley . t - current time
2665f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2666f2cacb80SMatthew G. Knepley . Nc - the number of field components
2667f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2668f2cacb80SMatthew G. Knepley - ctx - a user context
2669f2cacb80SMatthew G. Knepley 
2670f2cacb80SMatthew G. Knepley   Level: intermediate
2671f2cacb80SMatthew G. Knepley 
2672f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolutionTimeDerivative(), PetscDSGetExactSolution()
2673f2cacb80SMatthew G. Knepley @*/
2674f2cacb80SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2675f2cacb80SMatthew G. Knepley {
2676f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2677f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2678f2cacb80SMatthew 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);
2679f2cacb80SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol_t[f];}
2680f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx_t[f];}
2681f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2682f2cacb80SMatthew G. Knepley }
2683f2cacb80SMatthew G. Knepley 
2684f2cacb80SMatthew G. Knepley /*@C
2685f2cacb80SMatthew G. Knepley   PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field
2686f2cacb80SMatthew G. Knepley 
2687f2cacb80SMatthew G. Knepley   Not collective
2688f2cacb80SMatthew G. Knepley 
2689f2cacb80SMatthew G. Knepley   Input Parameters:
2690f2cacb80SMatthew G. Knepley + prob - The PetscDS
2691f2cacb80SMatthew G. Knepley . f    - The test field number
2692f2cacb80SMatthew G. Knepley . sol  - time derivative of the solution function for the test fields
2693f2cacb80SMatthew G. Knepley - ctx  - time derivative of the solution context or NULL
2694f2cacb80SMatthew G. Knepley 
2695f2cacb80SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2696f2cacb80SMatthew G. Knepley 
2697f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2698f2cacb80SMatthew G. Knepley 
2699f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2700f2cacb80SMatthew G. Knepley . t - current time
2701f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2702f2cacb80SMatthew G. Knepley . Nc - the number of field components
2703f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2704f2cacb80SMatthew G. Knepley - ctx - a user context
2705f2cacb80SMatthew G. Knepley 
2706f2cacb80SMatthew G. Knepley   Level: intermediate
2707f2cacb80SMatthew G. Knepley 
2708f2cacb80SMatthew G. Knepley .seealso: PetscDSGetExactSolutionTimeDerivative(), PetscDSSetExactSolution()
2709f2cacb80SMatthew G. Knepley @*/
2710f2cacb80SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2711f2cacb80SMatthew G. Knepley {
2712f2cacb80SMatthew G. Knepley   PetscErrorCode ierr;
2713f2cacb80SMatthew G. Knepley 
2714f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2715f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2716f2cacb80SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2717f2cacb80SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2718f2cacb80SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol_t[f] = sol;}
2719f2cacb80SMatthew G. Knepley   if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx_t[f] = ctx;}
2720f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2721f2cacb80SMatthew G. Knepley }
2722f2cacb80SMatthew G. Knepley 
2723f2cacb80SMatthew G. Knepley /*@C
272497b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
272597b6e6e8SMatthew G. Knepley 
272697b6e6e8SMatthew G. Knepley   Not collective
272797b6e6e8SMatthew G. Knepley 
272897b6e6e8SMatthew G. Knepley   Input Parameter:
272997b6e6e8SMatthew G. Knepley . prob - The PetscDS object
273097b6e6e8SMatthew G. Knepley 
273197b6e6e8SMatthew G. Knepley   Output Parameters:
273297b6e6e8SMatthew G. Knepley + numConstants - The number of constants
273397b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
273497b6e6e8SMatthew G. Knepley 
273597b6e6e8SMatthew G. Knepley   Level: intermediate
273697b6e6e8SMatthew G. Knepley 
273797b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
273897b6e6e8SMatthew G. Knepley @*/
273997b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
274097b6e6e8SMatthew G. Knepley {
274197b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
274297b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
274397b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
274497b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
274597b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
274697b6e6e8SMatthew G. Knepley }
274797b6e6e8SMatthew G. Knepley 
27480d3e9b51SMatthew G. Knepley /*@C
274997b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
275097b6e6e8SMatthew G. Knepley 
275197b6e6e8SMatthew G. Knepley   Not collective
275297b6e6e8SMatthew G. Knepley 
275397b6e6e8SMatthew G. Knepley   Input Parameters:
275497b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
275597b6e6e8SMatthew G. Knepley . numConstants - The number of constants
275697b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
275797b6e6e8SMatthew G. Knepley 
275897b6e6e8SMatthew G. Knepley   Level: intermediate
275997b6e6e8SMatthew G. Knepley 
276097b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
276197b6e6e8SMatthew G. Knepley @*/
276297b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
276397b6e6e8SMatthew G. Knepley {
276497b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
276597b6e6e8SMatthew G. Knepley 
276697b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
276797b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
276897b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
276997b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
277097b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
277197b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
277297b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
277320be0f5bSMatthew G. Knepley     } else {
277420be0f5bSMatthew G. Knepley       prob->constants = NULL;
277520be0f5bSMatthew G. Knepley     }
277620be0f5bSMatthew G. Knepley   }
277720be0f5bSMatthew G. Knepley   if (prob->numConstants) {
277820be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
2779580bdb30SBarry Smith     ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr);
278097b6e6e8SMatthew G. Knepley   }
278197b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
278297b6e6e8SMatthew G. Knepley }
278397b6e6e8SMatthew G. Knepley 
27844cd1e086SMatthew G. Knepley /*@
27854cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
27864cd1e086SMatthew G. Knepley 
27874cd1e086SMatthew G. Knepley   Not collective
27884cd1e086SMatthew G. Knepley 
27894cd1e086SMatthew G. Knepley   Input Parameters:
27904cd1e086SMatthew G. Knepley + prob - The PetscDS object
27914cd1e086SMatthew G. Knepley - disc - The discretization object
27924cd1e086SMatthew G. Knepley 
27934cd1e086SMatthew G. Knepley   Output Parameter:
27944cd1e086SMatthew G. Knepley . f - The field number
27954cd1e086SMatthew G. Knepley 
27964cd1e086SMatthew G. Knepley   Level: beginner
27974cd1e086SMatthew G. Knepley 
2798f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
27994cd1e086SMatthew G. Knepley @*/
28004cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
28014cd1e086SMatthew G. Knepley {
28024cd1e086SMatthew G. Knepley   PetscInt g;
28034cd1e086SMatthew G. Knepley 
28044cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28054cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28064cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
28074cd1e086SMatthew G. Knepley   *f = -1;
28084cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
28094cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
28104cd1e086SMatthew G. Knepley   *f = g;
28114cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
28124cd1e086SMatthew G. Knepley }
28134cd1e086SMatthew G. Knepley 
28144cd1e086SMatthew G. Knepley /*@
28154cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
28164cd1e086SMatthew G. Knepley 
28174cd1e086SMatthew G. Knepley   Not collective
28184cd1e086SMatthew G. Knepley 
28194cd1e086SMatthew G. Knepley   Input Parameters:
28204cd1e086SMatthew G. Knepley + prob - The PetscDS object
28214cd1e086SMatthew G. Knepley - f - The field number
28224cd1e086SMatthew G. Knepley 
28234cd1e086SMatthew G. Knepley   Output Parameter:
28244cd1e086SMatthew G. Knepley . size - The size
28254cd1e086SMatthew G. Knepley 
28264cd1e086SMatthew G. Knepley   Level: beginner
28274cd1e086SMatthew G. Knepley 
2828f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
28294cd1e086SMatthew G. Knepley @*/
28304cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
28314cd1e086SMatthew G. Knepley {
28322166fd64SMatthew G. Knepley   PetscErrorCode ierr;
28332166fd64SMatthew G. Knepley 
28344cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28354cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28364cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
28374cd1e086SMatthew 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);
28382166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2839d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
28404cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
28414cd1e086SMatthew G. Knepley }
28424cd1e086SMatthew G. Knepley 
2843bc4ae4beSMatthew G. Knepley /*@
2844bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2845bc4ae4beSMatthew G. Knepley 
2846bc4ae4beSMatthew G. Knepley   Not collective
2847bc4ae4beSMatthew G. Knepley 
2848bc4ae4beSMatthew G. Knepley   Input Parameters:
2849bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2850bc4ae4beSMatthew G. Knepley - f - The field number
2851bc4ae4beSMatthew G. Knepley 
2852bc4ae4beSMatthew G. Knepley   Output Parameter:
2853bc4ae4beSMatthew G. Knepley . off - The offset
2854bc4ae4beSMatthew G. Knepley 
2855bc4ae4beSMatthew G. Knepley   Level: beginner
2856bc4ae4beSMatthew G. Knepley 
2857f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2858bc4ae4beSMatthew G. Knepley @*/
28592764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
28602764a2aaSMatthew G. Knepley {
28614cd1e086SMatthew G. Knepley   PetscInt       size, g;
28622764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
28632764a2aaSMatthew G. Knepley 
28642764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28652764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28662764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
28672764a2aaSMatthew 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);
28682764a2aaSMatthew G. Knepley   *off = 0;
28692764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
28704cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
28714cd1e086SMatthew G. Knepley     *off += size;
28722764a2aaSMatthew G. Knepley   }
28732764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28742764a2aaSMatthew G. Knepley }
28752764a2aaSMatthew G. Knepley 
2876bc4ae4beSMatthew G. Knepley /*@
287747e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2878bc4ae4beSMatthew G. Knepley 
2879bc4ae4beSMatthew G. Knepley   Not collective
2880bc4ae4beSMatthew G. Knepley 
288147e57110SSander Arens   Input Parameter:
288247e57110SSander Arens . prob - The PetscDS object
2883bc4ae4beSMatthew G. Knepley 
2884bc4ae4beSMatthew G. Knepley   Output Parameter:
288547e57110SSander Arens . dimensions - The number of dimensions
2886bc4ae4beSMatthew G. Knepley 
2887bc4ae4beSMatthew G. Knepley   Level: beginner
2888bc4ae4beSMatthew G. Knepley 
288947e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2890bc4ae4beSMatthew G. Knepley @*/
289147e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
28922764a2aaSMatthew G. Knepley {
28932764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
28942764a2aaSMatthew G. Knepley 
28952764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28962764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
289747e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
289847e57110SSander Arens   PetscValidPointer(dimensions, 2);
289947e57110SSander Arens   *dimensions = prob->Nb;
290047e57110SSander Arens   PetscFunctionReturn(0);
29016ce16762SMatthew G. Knepley }
290247e57110SSander Arens 
290347e57110SSander Arens /*@
290447e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
290547e57110SSander Arens 
290647e57110SSander Arens   Not collective
290747e57110SSander Arens 
290847e57110SSander Arens   Input Parameter:
290947e57110SSander Arens . prob - The PetscDS object
291047e57110SSander Arens 
291147e57110SSander Arens   Output Parameter:
291247e57110SSander Arens . components - The number of components
291347e57110SSander Arens 
291447e57110SSander Arens   Level: beginner
291547e57110SSander Arens 
291647e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
291747e57110SSander Arens @*/
291847e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
291947e57110SSander Arens {
292047e57110SSander Arens   PetscErrorCode ierr;
292147e57110SSander Arens 
292247e57110SSander Arens   PetscFunctionBegin;
292347e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
292447e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
292547e57110SSander Arens   PetscValidPointer(components, 2);
292647e57110SSander Arens   *components = prob->Nc;
29276ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
29286ce16762SMatthew G. Knepley }
29296ce16762SMatthew G. Knepley 
29306ce16762SMatthew G. Knepley /*@
29316ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
29326ce16762SMatthew G. Knepley 
29336ce16762SMatthew G. Knepley   Not collective
29346ce16762SMatthew G. Knepley 
29356ce16762SMatthew G. Knepley   Input Parameters:
29366ce16762SMatthew G. Knepley + prob - The PetscDS object
29376ce16762SMatthew G. Knepley - f - The field number
29386ce16762SMatthew G. Knepley 
29396ce16762SMatthew G. Knepley   Output Parameter:
29406ce16762SMatthew G. Knepley . off - The offset
29416ce16762SMatthew G. Knepley 
29426ce16762SMatthew G. Knepley   Level: beginner
29436ce16762SMatthew G. Knepley 
2944f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
29456ce16762SMatthew G. Knepley @*/
29466ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
29476ce16762SMatthew G. Knepley {
29486ce16762SMatthew G. Knepley   PetscFunctionBegin;
29496ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29506ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
29516ce16762SMatthew 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);
295247e57110SSander Arens   *off = prob->off[f];
29532764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29542764a2aaSMatthew G. Knepley }
29552764a2aaSMatthew G. Knepley 
2956194d53e6SMatthew G. Knepley /*@
2957194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2958194d53e6SMatthew G. Knepley 
2959194d53e6SMatthew G. Knepley   Not collective
2960194d53e6SMatthew G. Knepley 
2961194d53e6SMatthew G. Knepley   Input Parameter:
2962194d53e6SMatthew G. Knepley . prob - The PetscDS object
2963194d53e6SMatthew G. Knepley 
2964194d53e6SMatthew G. Knepley   Output Parameter:
2965194d53e6SMatthew G. Knepley . offsets - The offsets
2966194d53e6SMatthew G. Knepley 
2967194d53e6SMatthew G. Knepley   Level: beginner
2968194d53e6SMatthew G. Knepley 
2969f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2970194d53e6SMatthew G. Knepley @*/
2971194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2972194d53e6SMatthew G. Knepley {
2973194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2974194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2975194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2976194d53e6SMatthew G. Knepley   *offsets = prob->off;
2977194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2978194d53e6SMatthew G. Knepley }
2979194d53e6SMatthew G. Knepley 
2980194d53e6SMatthew G. Knepley /*@
2981194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2982194d53e6SMatthew G. Knepley 
2983194d53e6SMatthew G. Knepley   Not collective
2984194d53e6SMatthew G. Knepley 
2985194d53e6SMatthew G. Knepley   Input Parameter:
2986194d53e6SMatthew G. Knepley . prob - The PetscDS object
2987194d53e6SMatthew G. Knepley 
2988194d53e6SMatthew G. Knepley   Output Parameter:
2989194d53e6SMatthew G. Knepley . offsets - The offsets
2990194d53e6SMatthew G. Knepley 
2991194d53e6SMatthew G. Knepley   Level: beginner
2992194d53e6SMatthew G. Knepley 
2993f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2994194d53e6SMatthew G. Knepley @*/
2995194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2996194d53e6SMatthew G. Knepley {
2997194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2998194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2999194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
3000194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
3001194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
3002194d53e6SMatthew G. Knepley }
3003194d53e6SMatthew G. Knepley 
300468c9edb9SMatthew G. Knepley /*@C
300568c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
300668c9edb9SMatthew G. Knepley 
300768c9edb9SMatthew G. Knepley   Not collective
300868c9edb9SMatthew G. Knepley 
300968c9edb9SMatthew G. Knepley   Input Parameter:
301068c9edb9SMatthew G. Knepley . prob - The PetscDS object
301168c9edb9SMatthew G. Knepley 
3012ef0bb6c7SMatthew G. Knepley   Output Parameter:
3013ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field
301468c9edb9SMatthew G. Knepley 
301568c9edb9SMatthew G. Knepley   Level: intermediate
301668c9edb9SMatthew G. Knepley 
3017f744cafaSSander Arens .seealso: PetscDSCreate()
301868c9edb9SMatthew G. Knepley @*/
3019ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[])
30202764a2aaSMatthew G. Knepley {
30212764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30222764a2aaSMatthew G. Knepley 
30232764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30242764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3025ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
30262764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3027ef0bb6c7SMatthew G. Knepley   *T = prob->T;
30282764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30292764a2aaSMatthew G. Knepley }
30302764a2aaSMatthew G. Knepley 
303168c9edb9SMatthew G. Knepley /*@C
30324d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
303368c9edb9SMatthew G. Knepley 
303468c9edb9SMatthew G. Knepley   Not collective
303568c9edb9SMatthew G. Knepley 
303668c9edb9SMatthew G. Knepley   Input Parameter:
303768c9edb9SMatthew G. Knepley . prob - The PetscDS object
303868c9edb9SMatthew G. Knepley 
3039ef0bb6c7SMatthew G. Knepley   Output Parameter:
304019815104SMartin Diehl . Tf - The basis function and derviative tabulation on each local face at quadrature points for each and field
304168c9edb9SMatthew G. Knepley 
304268c9edb9SMatthew G. Knepley   Level: intermediate
304368c9edb9SMatthew G. Knepley 
304468c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
304568c9edb9SMatthew G. Knepley @*/
3046ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[])
30472764a2aaSMatthew G. Knepley {
30482764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30492764a2aaSMatthew G. Knepley 
30502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30512764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3052ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
30532764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
3054ef0bb6c7SMatthew G. Knepley   *Tf = prob->Tf;
30552764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30562764a2aaSMatthew G. Knepley }
30572764a2aaSMatthew G. Knepley 
30582764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
30592764a2aaSMatthew G. Knepley {
30602764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30612764a2aaSMatthew G. Knepley 
30622764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30632764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30642764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
30652764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
30662764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
30672764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
30682764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30692764a2aaSMatthew G. Knepley }
30702764a2aaSMatthew G. Knepley 
30712764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
30722764a2aaSMatthew G. Knepley {
30732764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30742764a2aaSMatthew G. Knepley 
30752764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30762764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30772764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
30782764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
30792764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
30802764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
30812764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
30822764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
30832764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
30842764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30852764a2aaSMatthew G. Knepley }
30862764a2aaSMatthew G. Knepley 
30874bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal)
30882764a2aaSMatthew G. Knepley {
30892764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
30902764a2aaSMatthew G. Knepley 
30912764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30922764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30932764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
30942764a2aaSMatthew G. Knepley   if (x)            {PetscValidPointer(x, 2);            *x            = prob->x;}
30954bee2e38SMatthew G. Knepley   if (basisReal)    {PetscValidPointer(basisReal, 3);    *basisReal    = prob->basisReal;}
30967506b574SStefano Zampini   if (basisDerReal) {PetscValidPointer(basisDerReal, 4); *basisDerReal = prob->basisDerReal;}
30977506b574SStefano Zampini   if (testReal)     {PetscValidPointer(testReal, 5);     *testReal     = prob->testReal;}
30987506b574SStefano Zampini   if (testDerReal)  {PetscValidPointer(testDerReal, 6);  *testDerReal  = prob->testDerReal;}
30992764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31002764a2aaSMatthew G. Knepley }
31012764a2aaSMatthew G. Knepley 
310258ebd649SToby Isaac /*@C
310356cf3b9cSMatthew G. Knepley   PetscDSAddBoundary - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performaed, using the kernels from PetscDSSetBdResidual().
310458ebd649SToby Isaac 
3105783e2ec8SMatthew G. Knepley   Collective on ds
3106783e2ec8SMatthew G. Knepley 
310758ebd649SToby Isaac   Input Parameters:
310858ebd649SToby Isaac + ds          - The PetscDS object
31092d47a189SJulian Andrej . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
311058ebd649SToby Isaac . name        - The BC name
311158ebd649SToby Isaac . labelname   - The label defining constrained points
311258ebd649SToby Isaac . field       - The field to constrain
3113e8ecbf3fSStefano Zampini . numcomps    - The number of constrained field components (0 will constrain all fields)
311458ebd649SToby Isaac . comps       - An array of constrained component numbers
311558ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
311656cf3b9cSMatthew G. Knepley . bcFunc_t    - A pointwise function giving the time derviative of the boundary values, or NULL
311758ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
311858ebd649SToby Isaac . ids         - An array of ids for constrained points
311958ebd649SToby Isaac - ctx         - An optional user context for bcFunc
312058ebd649SToby Isaac 
312158ebd649SToby Isaac   Options Database Keys:
312258ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
312358ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
312458ebd649SToby Isaac 
312556cf3b9cSMatthew G. Knepley   Note:
312656cf3b9cSMatthew G. Knepley   Both bcFunc abd bcFunc_t will depend on the boundary condition type. If the type if DM_BC_ESSENTIAL, Then the calling sequence is:
312756cf3b9cSMatthew G. Knepley 
312856cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
312956cf3b9cSMatthew G. Knepley 
313056cf3b9cSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
313156cf3b9cSMatthew G. Knepley 
313256cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
313356cf3b9cSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
313456cf3b9cSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
313556cf3b9cSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
313656cf3b9cSMatthew G. Knepley 
313756cf3b9cSMatthew G. Knepley + dim - the spatial dimension
313856cf3b9cSMatthew G. Knepley . Nf - the number of fields
313956cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
314056cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
314156cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point
314256cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
314356cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
314456cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
314556cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
314656cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
314756cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
314856cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
314956cf3b9cSMatthew G. Knepley . t - current time
315056cf3b9cSMatthew G. Knepley . x - coordinates of the current point
315156cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters
315256cf3b9cSMatthew G. Knepley . constants - constant parameters
315356cf3b9cSMatthew G. Knepley - bcval - output values at the current point
315456cf3b9cSMatthew G. Knepley 
315558ebd649SToby Isaac   Level: developer
315658ebd649SToby Isaac 
315756cf3b9cSMatthew G. Knepley .seealso: PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual()
315858ebd649SToby Isaac @*/
315956cf3b9cSMatthew G. Knepley PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), void (*bcFunc_t)(void), PetscInt numids, const PetscInt *ids, void *ctx)
316058ebd649SToby Isaac {
316158ebd649SToby Isaac   DSBoundary     b;
316258ebd649SToby Isaac   PetscErrorCode ierr;
316358ebd649SToby Isaac 
316458ebd649SToby Isaac   PetscFunctionBegin;
316558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3166783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
3167783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 5);
3168783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, numcomps, 6);
3169783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, numids, 9);
317058ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
317158ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
317258ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
317358ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
3174580bdb30SBarry Smith   if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);}
317558ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
3176580bdb30SBarry Smith   if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);}
3177f971fd6bSMatthew G. Knepley   b->type            = type;
317858ebd649SToby Isaac   b->field           = field;
317958ebd649SToby Isaac   b->numcomps        = numcomps;
318058ebd649SToby Isaac   b->func            = bcFunc;
318156cf3b9cSMatthew G. Knepley   b->func_t          = bcFunc_t;
318258ebd649SToby Isaac   b->numids          = numids;
318358ebd649SToby Isaac   b->ctx             = ctx;
318458ebd649SToby Isaac   b->next            = ds->boundary;
318558ebd649SToby Isaac   ds->boundary       = b;
318658ebd649SToby Isaac   PetscFunctionReturn(0);
318758ebd649SToby Isaac }
318858ebd649SToby Isaac 
3189b67eacb3SMatthew G. Knepley /*@C
319056cf3b9cSMatthew G. Knepley   PetscDSUpdateBoundary - Change a boundary condition for the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performaed, using the kernels from PetscDSSetBdResidual().
3191b67eacb3SMatthew G. Knepley 
3192b67eacb3SMatthew G. Knepley   Input Parameters:
3193b67eacb3SMatthew G. Knepley + ds          - The PetscDS object
3194b67eacb3SMatthew G. Knepley . bd          - The boundary condition number
3195b67eacb3SMatthew G. Knepley . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
3196b67eacb3SMatthew G. Knepley . name        - The BC name
3197b67eacb3SMatthew G. Knepley . labelname   - The label defining constrained points
3198b67eacb3SMatthew G. Knepley . field       - The field to constrain
3199b67eacb3SMatthew G. Knepley . numcomps    - The number of constrained field components
3200b67eacb3SMatthew G. Knepley . comps       - An array of constrained component numbers
3201b67eacb3SMatthew G. Knepley . bcFunc      - A pointwise function giving boundary values
320256cf3b9cSMatthew G. Knepley . bcFunc_t    - A pointwise function giving the time derviative of the boundary values, or NULL
3203b67eacb3SMatthew G. Knepley . numids      - The number of DMLabel ids for constrained points
3204b67eacb3SMatthew G. Knepley . ids         - An array of ids for constrained points
3205b67eacb3SMatthew G. Knepley - ctx         - An optional user context for bcFunc
3206b67eacb3SMatthew G. Knepley 
320756cf3b9cSMatthew G. Knepley   Note:
320856cf3b9cSMatthew G. Knepley   The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from PetscDSGetNumBoundary(). See PetscDSAddBoundary() for a description of the calling sequences for the callbacks.
32099a6efb6aSMatthew G. Knepley 
3210b67eacb3SMatthew G. Knepley   Level: developer
3211b67eacb3SMatthew G. Knepley 
32129a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary()
3213b67eacb3SMatthew G. Knepley @*/
321456cf3b9cSMatthew G. Knepley PetscErrorCode PetscDSUpdateBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), void (*bcFunc_t)(void), PetscInt numids, const PetscInt *ids, void *ctx)
3215b67eacb3SMatthew G. Knepley {
3216b67eacb3SMatthew G. Knepley   DSBoundary     b = ds->boundary;
3217b67eacb3SMatthew G. Knepley   PetscInt       n = 0;
3218b67eacb3SMatthew G. Knepley   PetscErrorCode ierr;
3219b67eacb3SMatthew G. Knepley 
3220b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
3221b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3222b67eacb3SMatthew G. Knepley   while (b) {
3223b67eacb3SMatthew G. Knepley     if (n == bd) break;
3224b67eacb3SMatthew G. Knepley     b = b->next;
3225b67eacb3SMatthew G. Knepley     ++n;
3226b67eacb3SMatthew G. Knepley   }
3227b67eacb3SMatthew G. Knepley   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
3228b67eacb3SMatthew G. Knepley   if (name) {
3229b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
3230b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
3231b67eacb3SMatthew G. Knepley   }
3232b67eacb3SMatthew G. Knepley   if (labelname) {
3233b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
3234b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
3235b67eacb3SMatthew G. Knepley   }
3236b67eacb3SMatthew G. Knepley   if (numcomps >= 0 && numcomps != b->numcomps) {
3237b67eacb3SMatthew G. Knepley     b->numcomps = numcomps;
3238b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
3239b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
3240580bdb30SBarry Smith     if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);}
3241b67eacb3SMatthew G. Knepley   }
3242b67eacb3SMatthew G. Knepley   if (numids >= 0 && numids != b->numids) {
3243b67eacb3SMatthew G. Knepley     b->numids = numids;
3244b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->ids);CHKERRQ(ierr);
3245b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
3246580bdb30SBarry Smith     if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);}
3247b67eacb3SMatthew G. Knepley   }
3248b67eacb3SMatthew G. Knepley   b->type = type;
3249b67eacb3SMatthew G. Knepley   if (field >= 0) {b->field  = field;}
3250b67eacb3SMatthew G. Knepley   if (bcFunc)     {b->func   = bcFunc;}
325156cf3b9cSMatthew G. Knepley   if (bcFunc_t)   {b->func_t = bcFunc_t;}
3252b67eacb3SMatthew G. Knepley   if (ctx)        {b->ctx    = ctx;}
3253b67eacb3SMatthew G. Knepley   PetscFunctionReturn(0);
3254b67eacb3SMatthew G. Knepley }
3255b67eacb3SMatthew G. Knepley 
325658ebd649SToby Isaac /*@
325758ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
325858ebd649SToby Isaac 
325958ebd649SToby Isaac   Input Parameters:
326058ebd649SToby Isaac . ds - The PetscDS object
326158ebd649SToby Isaac 
326258ebd649SToby Isaac   Output Parameters:
326358ebd649SToby Isaac . numBd - The number of BC
326458ebd649SToby Isaac 
326558ebd649SToby Isaac   Level: intermediate
326658ebd649SToby Isaac 
326758ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
326858ebd649SToby Isaac @*/
326958ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
327058ebd649SToby Isaac {
327158ebd649SToby Isaac   DSBoundary b = ds->boundary;
327258ebd649SToby Isaac 
327358ebd649SToby Isaac   PetscFunctionBegin;
327458ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
327558ebd649SToby Isaac   PetscValidPointer(numBd, 2);
327658ebd649SToby Isaac   *numBd = 0;
327758ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
327858ebd649SToby Isaac   PetscFunctionReturn(0);
327958ebd649SToby Isaac }
328058ebd649SToby Isaac 
328158ebd649SToby Isaac /*@C
32829a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
328358ebd649SToby Isaac 
328458ebd649SToby Isaac   Input Parameters:
328558ebd649SToby Isaac + ds          - The PetscDS object
328658ebd649SToby Isaac - bd          - The BC number
328758ebd649SToby Isaac 
328858ebd649SToby Isaac   Output Parameters:
32892d47a189SJulian Andrej + type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
329058ebd649SToby Isaac . name        - The BC name
329158ebd649SToby Isaac . labelname   - The label defining constrained points
329258ebd649SToby Isaac . field       - The field to constrain
329358ebd649SToby Isaac . numcomps    - The number of constrained field components
329458ebd649SToby Isaac . comps       - An array of constrained component numbers
329558ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
329656cf3b9cSMatthew G. Knepley . bcFunc_t    - A pointwise function giving the time derviative of the boundary values
329758ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
329858ebd649SToby Isaac . ids         - An array of ids for constrained points
329958ebd649SToby Isaac - ctx         - An optional user context for bcFunc
330058ebd649SToby Isaac 
330158ebd649SToby Isaac   Options Database Keys:
330258ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
330358ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
330458ebd649SToby Isaac 
330558ebd649SToby Isaac   Level: developer
330658ebd649SToby Isaac 
330758ebd649SToby Isaac .seealso: PetscDSAddBoundary()
330858ebd649SToby Isaac @*/
330956cf3b9cSMatthew G. Knepley PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType *type, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(void), void (**func_t)(void), PetscInt *numids, const PetscInt **ids, void **ctx)
331058ebd649SToby Isaac {
331158ebd649SToby Isaac   DSBoundary b    = ds->boundary;
331258ebd649SToby Isaac   PetscInt   n    = 0;
331358ebd649SToby Isaac 
331458ebd649SToby Isaac   PetscFunctionBegin;
331558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
331658ebd649SToby Isaac   while (b) {
331758ebd649SToby Isaac     if (n == bd) break;
331858ebd649SToby Isaac     b = b->next;
331958ebd649SToby Isaac     ++n;
332058ebd649SToby Isaac   }
332158ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
3322f971fd6bSMatthew G. Knepley   if (type) {
3323f971fd6bSMatthew G. Knepley     PetscValidPointer(type, 3);
3324f971fd6bSMatthew G. Knepley     *type = b->type;
332558ebd649SToby Isaac   }
332658ebd649SToby Isaac   if (name) {
332758ebd649SToby Isaac     PetscValidPointer(name, 4);
332858ebd649SToby Isaac     *name = b->name;
332958ebd649SToby Isaac   }
333058ebd649SToby Isaac   if (labelname) {
333158ebd649SToby Isaac     PetscValidPointer(labelname, 5);
333258ebd649SToby Isaac     *labelname = b->labelname;
333358ebd649SToby Isaac   }
333458ebd649SToby Isaac   if (field) {
333558ebd649SToby Isaac     PetscValidPointer(field, 6);
333658ebd649SToby Isaac     *field = b->field;
333758ebd649SToby Isaac   }
333858ebd649SToby Isaac   if (numcomps) {
333958ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
334058ebd649SToby Isaac     *numcomps = b->numcomps;
334158ebd649SToby Isaac   }
334258ebd649SToby Isaac   if (comps) {
334358ebd649SToby Isaac     PetscValidPointer(comps, 8);
334458ebd649SToby Isaac     *comps = b->comps;
334558ebd649SToby Isaac   }
334658ebd649SToby Isaac   if (func) {
334758ebd649SToby Isaac     PetscValidPointer(func, 9);
334858ebd649SToby Isaac     *func = b->func;
334958ebd649SToby Isaac   }
335056cf3b9cSMatthew G. Knepley   if (func_t) {
335156cf3b9cSMatthew G. Knepley     PetscValidPointer(func_t, 10);
335256cf3b9cSMatthew G. Knepley     *func_t = b->func_t;
335356cf3b9cSMatthew G. Knepley   }
335458ebd649SToby Isaac   if (numids) {
335556cf3b9cSMatthew G. Knepley     PetscValidPointer(numids, 11);
335658ebd649SToby Isaac     *numids = b->numids;
335758ebd649SToby Isaac   }
335858ebd649SToby Isaac   if (ids) {
335956cf3b9cSMatthew G. Knepley     PetscValidPointer(ids, 12);
336058ebd649SToby Isaac     *ids = b->ids;
336158ebd649SToby Isaac   }
336258ebd649SToby Isaac   if (ctx) {
336356cf3b9cSMatthew G. Knepley     PetscValidPointer(ctx, 13);
336458ebd649SToby Isaac     *ctx = b->ctx;
336558ebd649SToby Isaac   }
336658ebd649SToby Isaac   PetscFunctionReturn(0);
336758ebd649SToby Isaac }
336858ebd649SToby Isaac 
33699252d075SMatthew G. Knepley /*@
33709252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
33719252d075SMatthew G. Knepley 
33729252d075SMatthew G. Knepley   Not collective
33739252d075SMatthew G. Knepley 
337436951cb5SMatthew G. Knepley   Input Parameters:
337536951cb5SMatthew G. Knepley + ds        - The source PetscDS object
337636951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields
337736951cb5SMatthew G. Knepley - fields    - The selected fields, or NULL for all fields
33789252d075SMatthew G. Knepley 
33799252d075SMatthew G. Knepley   Output Parameter:
338036951cb5SMatthew G. Knepley . newds     - The target PetscDS, now with a copy of the boundary conditions
33819252d075SMatthew G. Knepley 
33829252d075SMatthew G. Knepley   Level: intermediate
33839252d075SMatthew G. Knepley 
33849252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
33859252d075SMatthew G. Knepley @*/
338636951cb5SMatthew G. Knepley PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds)
3387dff059c6SToby Isaac {
3388dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
3389dff059c6SToby Isaac   PetscErrorCode ierr;
3390dff059c6SToby Isaac 
3391dff059c6SToby Isaac   PetscFunctionBegin;
339236951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(ds,    PETSCDS_CLASSID, 1);
339336951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4);
339436951cb5SMatthew G. Knepley   if (ds == newds) PetscFunctionReturn(0);
339536951cb5SMatthew G. Knepley   next = newds->boundary;
3396dff059c6SToby Isaac   while (next) {
3397dff059c6SToby Isaac     DSBoundary b = next;
3398dff059c6SToby Isaac 
3399dff059c6SToby Isaac     next = b->next;
3400dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
3401dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
3402dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
3403dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
3404dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
3405dff059c6SToby Isaac   }
340636951cb5SMatthew G. Knepley   lastnext = &(newds->boundary);
340736951cb5SMatthew G. Knepley   for (b = ds->boundary; b; b = b->next) {
3408dff059c6SToby Isaac     DSBoundary bNew;
340936951cb5SMatthew G. Knepley     PetscInt   fieldNew = -1;
3410dff059c6SToby Isaac 
341136951cb5SMatthew G. Knepley     if (numFields > 0 && fields) {
341236951cb5SMatthew G. Knepley       PetscInt f;
341336951cb5SMatthew G. Knepley 
341436951cb5SMatthew G. Knepley       for (f = 0; f < numFields; ++f) if (b->field == fields[f]) break;
341536951cb5SMatthew G. Knepley       if (f == numFields) continue;
341636951cb5SMatthew G. Knepley       fieldNew = f;
341736951cb5SMatthew G. Knepley     }
3418459726d8SSatish Balay     ierr = PetscNew(&bNew);CHKERRQ(ierr);
3419dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
3420dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
3421580bdb30SBarry Smith     ierr = PetscArraycpy(bNew->comps, b->comps, bNew->numcomps);CHKERRQ(ierr);
3422dff059c6SToby Isaac     bNew->numids = b->numids;
3423dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
3424580bdb30SBarry Smith     ierr = PetscArraycpy(bNew->ids, b->ids, bNew->numids);CHKERRQ(ierr);
3425dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
3426dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
3427dff059c6SToby Isaac     bNew->ctx   = b->ctx;
3428f971fd6bSMatthew G. Knepley     bNew->type  = b->type;
342936951cb5SMatthew G. Knepley     bNew->field = fieldNew < 0 ? b->field : fieldNew;
3430dff059c6SToby Isaac     bNew->func  = b->func;
3431dff059c6SToby Isaac 
3432dff059c6SToby Isaac     *lastnext = bNew;
3433dff059c6SToby Isaac     lastnext = &(bNew->next);
3434dff059c6SToby Isaac   }
3435dff059c6SToby Isaac   PetscFunctionReturn(0);
3436dff059c6SToby Isaac }
3437dff059c6SToby Isaac 
34386c1eb96dSMatthew G. Knepley /*@
34396c1eb96dSMatthew G. Knepley   PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout
34406c1eb96dSMatthew G. Knepley 
34416c1eb96dSMatthew G. Knepley   Not collective
34426c1eb96dSMatthew G. Knepley 
34436c1eb96dSMatthew G. Knepley   Input Parameter:
34446c1eb96dSMatthew G. Knepley + prob - The PetscDS object
34456c1eb96dSMatthew G. Knepley . numFields - Number of new fields
34466c1eb96dSMatthew G. Knepley - fields - Old field number for each new field
34476c1eb96dSMatthew G. Knepley 
34486c1eb96dSMatthew G. Knepley   Output Parameter:
34496c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy
34506c1eb96dSMatthew G. Knepley 
34516c1eb96dSMatthew G. Knepley   Level: intermediate
34526c1eb96dSMatthew G. Knepley 
34536c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectEquations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
34546c1eb96dSMatthew G. Knepley @*/
34556c1eb96dSMatthew G. Knepley PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
34566c1eb96dSMatthew G. Knepley {
34576c1eb96dSMatthew G. Knepley   PetscInt       Nf, Nfn, fn;
34586c1eb96dSMatthew G. Knepley   PetscErrorCode ierr;
34596c1eb96dSMatthew G. Knepley 
34606c1eb96dSMatthew G. Knepley   PetscFunctionBegin;
34616c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
34626c1eb96dSMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
34636c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
34646c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
34656c1eb96dSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
34666c1eb96dSMatthew 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);
34676c1eb96dSMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
34686c1eb96dSMatthew G. Knepley     const PetscInt f = fields ? fields[fn] : fn;
34696c1eb96dSMatthew G. Knepley     PetscObject    disc;
34706c1eb96dSMatthew G. Knepley 
34716c1eb96dSMatthew G. Knepley     if (f >= Nf) continue;
34726c1eb96dSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &disc);CHKERRQ(ierr);
34736c1eb96dSMatthew G. Knepley     ierr = PetscDSSetDiscretization(newprob, fn, disc);CHKERRQ(ierr);
34746c1eb96dSMatthew G. Knepley   }
34756c1eb96dSMatthew G. Knepley   PetscFunctionReturn(0);
34766c1eb96dSMatthew G. Knepley }
34776c1eb96dSMatthew G. Knepley 
34786c1eb96dSMatthew G. Knepley /*@
34799252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
34809252d075SMatthew G. Knepley 
34819252d075SMatthew G. Knepley   Not collective
34829252d075SMatthew G. Knepley 
34839252d075SMatthew G. Knepley   Input Parameter:
34849252d075SMatthew G. Knepley + prob - The PetscDS object
34859252d075SMatthew G. Knepley . numFields - Number of new fields
34869252d075SMatthew G. Knepley - fields - Old field number for each new field
34879252d075SMatthew G. Knepley 
34889252d075SMatthew G. Knepley   Output Parameter:
34899252d075SMatthew G. Knepley . newprob - The PetscDS copy
34909252d075SMatthew G. Knepley 
34919252d075SMatthew G. Knepley   Level: intermediate
34929252d075SMatthew G. Knepley 
34936c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectDiscretizations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
34949252d075SMatthew G. Knepley @*/
34959252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
34969252d075SMatthew G. Knepley {
34979252d075SMatthew G. Knepley   PetscInt       Nf, Nfn, fn, gn;
34989252d075SMatthew G. Knepley   PetscErrorCode ierr;
34999252d075SMatthew G. Knepley 
35009252d075SMatthew G. Knepley   PetscFunctionBegin;
35019252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
35029252d075SMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
35039252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
35049252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
35059252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
35069252d075SMatthew 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);
35079252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
35089252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
35099252d075SMatthew G. Knepley     PetscPointFunc   obj;
35109252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
35119252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
35129252d075SMatthew G. Knepley     PetscRiemannFunc r;
35139252d075SMatthew G. Knepley 
3514c52f1e13SMatthew G. Knepley     if (f >= Nf) continue;
35159252d075SMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
35169252d075SMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
35179252d075SMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
35189252d075SMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
35199252d075SMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr);
35209252d075SMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr);
35219252d075SMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr);
35229252d075SMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr);
35239252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
35249252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
35259252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
35269252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
35279252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
35289252d075SMatthew G. Knepley 
3529c52f1e13SMatthew G. Knepley       if (g >= Nf) continue;
35309252d075SMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
35319252d075SMatthew G. Knepley       ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr);
35329252d075SMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
35339252d075SMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr);
35346c1eb96dSMatthew G. Knepley       ierr = PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr);
35359252d075SMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
35369252d075SMatthew G. Knepley     }
35379252d075SMatthew G. Knepley   }
35389252d075SMatthew G. Knepley   PetscFunctionReturn(0);
35399252d075SMatthew G. Knepley }
35409252d075SMatthew G. Knepley 
3541da51fcedSMatthew G. Knepley /*@
3542da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
3543da51fcedSMatthew G. Knepley 
3544da51fcedSMatthew G. Knepley   Not collective
3545da51fcedSMatthew G. Knepley 
3546da51fcedSMatthew G. Knepley   Input Parameter:
3547da51fcedSMatthew G. Knepley . prob - The PetscDS object
3548da51fcedSMatthew G. Knepley 
3549da51fcedSMatthew G. Knepley   Output Parameter:
3550da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
3551da51fcedSMatthew G. Knepley 
3552da51fcedSMatthew G. Knepley   Level: intermediate
3553da51fcedSMatthew G. Knepley 
35549252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
3555da51fcedSMatthew G. Knepley @*/
3556da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
3557da51fcedSMatthew G. Knepley {
35589252d075SMatthew G. Knepley   PetscInt       Nf, Ng;
3559da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
3560da51fcedSMatthew G. Knepley 
3561da51fcedSMatthew G. Knepley   PetscFunctionBegin;
3562da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3563da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
3564da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3565da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
356613903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
35679252d075SMatthew G. Knepley   ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr);
35689252d075SMatthew G. Knepley   PetscFunctionReturn(0);
35699252d075SMatthew G. Knepley }
35709252d075SMatthew G. Knepley /*@
35719252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
3572da51fcedSMatthew G. Knepley 
35739252d075SMatthew G. Knepley   Not collective
35749252d075SMatthew G. Knepley 
35759252d075SMatthew G. Knepley   Input Parameter:
35769252d075SMatthew G. Knepley . prob - The PetscDS object
35779252d075SMatthew G. Knepley 
35789252d075SMatthew G. Knepley   Output Parameter:
35799252d075SMatthew G. Knepley . newprob - The PetscDS copy
35809252d075SMatthew G. Knepley 
35819252d075SMatthew G. Knepley   Level: intermediate
35829252d075SMatthew G. Knepley 
35839252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
35849252d075SMatthew G. Knepley @*/
35859252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
35869252d075SMatthew G. Knepley {
35879252d075SMatthew G. Knepley   PetscInt           Nc;
35889252d075SMatthew G. Knepley   const PetscScalar *constants;
35899252d075SMatthew G. Knepley   PetscErrorCode     ierr;
35909252d075SMatthew G. Knepley 
35919252d075SMatthew G. Knepley   PetscFunctionBegin;
35929252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
35939252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
35949252d075SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr);
35959252d075SMatthew G. Knepley   ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr);
3596da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
3597da51fcedSMatthew G. Knepley }
3598da51fcedSMatthew G. Knepley 
3599b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
3600b1353e8eSMatthew G. Knepley {
3601df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
3602b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
3603b1353e8eSMatthew G. Knepley 
3604b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
3605b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3606b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
3607b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
3608b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3609df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
3610df3a45bdSMatthew 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);
3611df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
3612df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
3613b1353e8eSMatthew G. Knepley     PetscInt cdim;
3614b1353e8eSMatthew G. Knepley 
3615df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
3616b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
3617df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
3618b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
3619b1353e8eSMatthew G. Knepley       PetscFE      subfe;
3620b1353e8eSMatthew G. Knepley       PetscObject  obj;
3621b1353e8eSMatthew G. Knepley       PetscClassId id;
3622b1353e8eSMatthew G. Knepley 
3623b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3624b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3625b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
3626b1353e8eSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
3627df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
3628b1353e8eSMatthew G. Knepley     }
3629b1353e8eSMatthew G. Knepley   }
3630df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
3631b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
3632b1353e8eSMatthew G. Knepley }
3633b1353e8eSMatthew G. Knepley 
3634665f567fSMatthew G. Knepley PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype)
3635c7bd5f0bSMatthew G. Knepley {
3636c7bd5f0bSMatthew G. Knepley   PetscObject    obj;
3637c7bd5f0bSMatthew G. Knepley   PetscClassId   id;
3638c7bd5f0bSMatthew G. Knepley   PetscInt       Nf;
3639c7bd5f0bSMatthew G. Knepley   PetscErrorCode ierr;
3640c7bd5f0bSMatthew G. Knepley 
3641c7bd5f0bSMatthew G. Knepley   PetscFunctionBegin;
3642c7bd5f0bSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3643665f567fSMatthew G. Knepley   PetscValidPointer(disctype, 3);
3644665f567fSMatthew G. Knepley   *disctype = PETSC_DISC_NONE;
3645c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr);
3646c7bd5f0bSMatthew G. Knepley   if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf);
3647c7bd5f0bSMatthew G. Knepley   ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr);
3648665f567fSMatthew G. Knepley   if (obj) {
3649c7bd5f0bSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3650665f567fSMatthew G. Knepley     if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE;
3651665f567fSMatthew G. Knepley     else                       *disctype = PETSC_DISC_FV;
3652665f567fSMatthew G. Knepley   }
3653c7bd5f0bSMatthew G. Knepley   PetscFunctionReturn(0);
3654c7bd5f0bSMatthew G. Knepley }
3655c7bd5f0bSMatthew G. Knepley 
3656bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob)
36572764a2aaSMatthew G. Knepley {
3658931fb3b8SToby Isaac   PetscErrorCode      ierr;
3659931fb3b8SToby Isaac 
36602764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3661931fb3b8SToby Isaac   ierr = PetscFree(prob->data);CHKERRQ(ierr);
36622764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
36632764a2aaSMatthew G. Knepley }
36642764a2aaSMatthew G. Knepley 
3665bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob)
36662764a2aaSMatthew G. Knepley {
36672764a2aaSMatthew G. Knepley   PetscFunctionBegin;
36682764a2aaSMatthew G. Knepley   prob->ops->setfromoptions = NULL;
36692764a2aaSMatthew G. Knepley   prob->ops->setup          = NULL;
36702764a2aaSMatthew G. Knepley   prob->ops->view           = NULL;
36712764a2aaSMatthew G. Knepley   prob->ops->destroy        = PetscDSDestroy_Basic;
36722764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
36732764a2aaSMatthew G. Knepley }
36742764a2aaSMatthew G. Knepley 
36752764a2aaSMatthew G. Knepley /*MC
36762764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
36772764a2aaSMatthew G. Knepley 
36782764a2aaSMatthew G. Knepley   Level: intermediate
36792764a2aaSMatthew G. Knepley 
36802764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
36812764a2aaSMatthew G. Knepley M*/
36822764a2aaSMatthew G. Knepley 
36832764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob)
36842764a2aaSMatthew G. Knepley {
36852764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
36862764a2aaSMatthew G. Knepley   PetscErrorCode      ierr;
36872764a2aaSMatthew G. Knepley 
36882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3689931fb3b8SToby Isaac   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
36902764a2aaSMatthew G. Knepley   ierr       = PetscNewLog(prob, &b);CHKERRQ(ierr);
36912764a2aaSMatthew G. Knepley   prob->data = b;
36922764a2aaSMatthew G. Knepley 
36932764a2aaSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr);
36942764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
36952764a2aaSMatthew G. Knepley }
3696