xref: /petsc/src/dm/dt/interface/dtds.c (revision ebfe4b0dd6720ceca8680e82f5a07cba83b366b4)
1af0996ceSBarry Smith #include <petsc/private/petscdsimpl.h> /*I "petscds.h" I*/
22764a2aaSMatthew G. Knepley 
32764a2aaSMatthew G. Knepley PetscClassId PETSCDS_CLASSID = 0;
42764a2aaSMatthew G. Knepley 
52764a2aaSMatthew G. Knepley PetscFunctionList PetscDSList              = NULL;
62764a2aaSMatthew G. Knepley PetscBool         PetscDSRegisterAllCalled = PETSC_FALSE;
72764a2aaSMatthew G. Knepley 
894dcdc3fSMatthew G. Knepley /* A PetscDS (Discrete System) encodes a set of equations posed in a discrete space, which represents a set of
994dcdc3fSMatthew G. Knepley    nonlinear continuum equations. The equations can have multiple fields, each field having a different
1094dcdc3fSMatthew G. Knepley    discretization. In addition, different pieces of the domain can have different field combinations and equations.
1194dcdc3fSMatthew G. Knepley 
1294dcdc3fSMatthew G. Knepley    The DS provides the user a description of the approximation space on any given cell. It also gives pointwise
1394dcdc3fSMatthew G. Knepley    functions representing the equations.
1494dcdc3fSMatthew G. Knepley 
1594dcdc3fSMatthew G. Knepley    Each field is associated with a label, marking the cells on which it is supported. Note that a field can be
1694dcdc3fSMatthew G. Knepley    supported on the closure of a cell not in the label due to overlap of the boundary of neighboring cells. The DM
1794dcdc3fSMatthew G. Knepley    then creates a DS for each set of cells with identical approximation spaces. When assembling, the user asks for
1894dcdc3fSMatthew G. Knepley    the space associated with a given cell. DMPlex uses the labels associated with each DS in the default integration loop.
1994dcdc3fSMatthew G. Knepley */
2094dcdc3fSMatthew G. Knepley 
212764a2aaSMatthew G. Knepley /*@C
222764a2aaSMatthew G. Knepley   PetscDSRegister - Adds a new PetscDS implementation
232764a2aaSMatthew G. Knepley 
242764a2aaSMatthew G. Knepley   Not Collective
252764a2aaSMatthew G. Knepley 
262764a2aaSMatthew G. Knepley   Input Parameters:
272764a2aaSMatthew G. Knepley + name        - The name of a new user-defined creation routine
282764a2aaSMatthew G. Knepley - create_func - The creation routine itself
292764a2aaSMatthew G. Knepley 
302764a2aaSMatthew G. Knepley   Notes:
312764a2aaSMatthew G. Knepley   PetscDSRegister() may be called multiple times to add several user-defined PetscDSs
322764a2aaSMatthew G. Knepley 
332764a2aaSMatthew G. Knepley   Sample usage:
342764a2aaSMatthew G. Knepley .vb
352764a2aaSMatthew G. Knepley     PetscDSRegister("my_ds", MyPetscDSCreate);
362764a2aaSMatthew G. Knepley .ve
372764a2aaSMatthew G. Knepley 
382764a2aaSMatthew G. Knepley   Then, your PetscDS type can be chosen with the procedural interface via
392764a2aaSMatthew G. Knepley .vb
402764a2aaSMatthew G. Knepley     PetscDSCreate(MPI_Comm, PetscDS *);
412764a2aaSMatthew G. Knepley     PetscDSSetType(PetscDS, "my_ds");
422764a2aaSMatthew G. Knepley .ve
432764a2aaSMatthew G. Knepley    or at runtime via the option
442764a2aaSMatthew G. Knepley .vb
452764a2aaSMatthew G. Knepley     -petscds_type my_ds
462764a2aaSMatthew G. Knepley .ve
472764a2aaSMatthew G. Knepley 
482764a2aaSMatthew G. Knepley   Level: advanced
492764a2aaSMatthew G. Knepley 
50f5f57ec0SBarry Smith    Not available from Fortran
51f5f57ec0SBarry Smith 
522764a2aaSMatthew G. Knepley .keywords: PetscDS, register
532764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy()
542764a2aaSMatthew G. Knepley 
552764a2aaSMatthew G. Knepley @*/
562764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
572764a2aaSMatthew G. Knepley {
582764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
592764a2aaSMatthew G. Knepley 
602764a2aaSMatthew G. Knepley   PetscFunctionBegin;
612764a2aaSMatthew G. Knepley   ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr);
622764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
632764a2aaSMatthew G. Knepley }
642764a2aaSMatthew G. Knepley 
652764a2aaSMatthew G. Knepley /*@C
662764a2aaSMatthew G. Knepley   PetscDSSetType - Builds a particular PetscDS
672764a2aaSMatthew G. Knepley 
682764a2aaSMatthew G. Knepley   Collective on PetscDS
692764a2aaSMatthew G. Knepley 
702764a2aaSMatthew G. Knepley   Input Parameters:
712764a2aaSMatthew G. Knepley + prob - The PetscDS object
722764a2aaSMatthew G. Knepley - name - The kind of system
732764a2aaSMatthew G. Knepley 
742764a2aaSMatthew G. Knepley   Options Database Key:
752764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
762764a2aaSMatthew G. Knepley 
772764a2aaSMatthew G. Knepley   Level: intermediate
782764a2aaSMatthew G. Knepley 
79f5f57ec0SBarry Smith    Not available from Fortran
80f5f57ec0SBarry Smith 
812764a2aaSMatthew G. Knepley .keywords: PetscDS, set, type
822764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate()
832764a2aaSMatthew G. Knepley @*/
842764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
852764a2aaSMatthew G. Knepley {
862764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
872764a2aaSMatthew G. Knepley   PetscBool      match;
882764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
892764a2aaSMatthew G. Knepley 
902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
912764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
922764a2aaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr);
932764a2aaSMatthew G. Knepley   if (match) PetscFunctionReturn(0);
942764a2aaSMatthew G. Knepley 
950f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
962764a2aaSMatthew G. Knepley   ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr);
972764a2aaSMatthew G. Knepley   if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
982764a2aaSMatthew G. Knepley 
992764a2aaSMatthew G. Knepley   if (prob->ops->destroy) {
1002764a2aaSMatthew G. Knepley     ierr             = (*prob->ops->destroy)(prob);CHKERRQ(ierr);
1012764a2aaSMatthew G. Knepley     prob->ops->destroy = NULL;
1022764a2aaSMatthew G. Knepley   }
1032764a2aaSMatthew G. Knepley   ierr = (*r)(prob);CHKERRQ(ierr);
1042764a2aaSMatthew G. Knepley   ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr);
1052764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1062764a2aaSMatthew G. Knepley }
1072764a2aaSMatthew G. Knepley 
1082764a2aaSMatthew G. Knepley /*@C
1092764a2aaSMatthew G. Knepley   PetscDSGetType - Gets the PetscDS type name (as a string) from the object.
1102764a2aaSMatthew G. Knepley 
1112764a2aaSMatthew G. Knepley   Not Collective
1122764a2aaSMatthew G. Knepley 
1132764a2aaSMatthew G. Knepley   Input Parameter:
1142764a2aaSMatthew G. Knepley . prob  - The PetscDS
1152764a2aaSMatthew G. Knepley 
1162764a2aaSMatthew G. Knepley   Output Parameter:
1172764a2aaSMatthew G. Knepley . name - The PetscDS type name
1182764a2aaSMatthew G. Knepley 
1192764a2aaSMatthew G. Knepley   Level: intermediate
1202764a2aaSMatthew G. Knepley 
121f5f57ec0SBarry Smith    Not available from Fortran
122f5f57ec0SBarry Smith 
1232764a2aaSMatthew G. Knepley .keywords: PetscDS, get, type, name
1242764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate()
1252764a2aaSMatthew G. Knepley @*/
1262764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
1272764a2aaSMatthew G. Knepley {
1282764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1292764a2aaSMatthew G. Knepley 
1302764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1312764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
132c959eef4SJed Brown   PetscValidPointer(name, 2);
1330f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
1342764a2aaSMatthew G. Knepley   *name = ((PetscObject) prob)->type_name;
1352764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1362764a2aaSMatthew G. Knepley }
1372764a2aaSMatthew G. Knepley 
1387d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer)
1397d8a60eaSMatthew G. Knepley {
1407d8a60eaSMatthew G. Knepley   PetscViewerFormat  format;
14197b6e6e8SMatthew G. Knepley   const PetscScalar *constants;
14297b6e6e8SMatthew G. Knepley   PetscInt           numConstants, f;
1437d8a60eaSMatthew G. Knepley   PetscErrorCode     ierr;
1447d8a60eaSMatthew G. Knepley 
1457d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1467d8a60eaSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
1477d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr);
1487d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1494727e194SMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "  cell total dim %D total comp %D\n", prob->totDim, prob->totComp);CHKERRQ(ierr);
1504727e194SMatthew G. Knepley   if (prob->isHybrid) {ierr = PetscViewerASCIIPrintf(viewer, "  hybrid cell\n");CHKERRQ(ierr);}
1517d8a60eaSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1527d8a60eaSMatthew G. Knepley     PetscObject     obj;
1537d8a60eaSMatthew G. Knepley     PetscClassId    id;
154f35450b9SMatthew G. Knepley     PetscQuadrature q;
1557d8a60eaSMatthew G. Knepley     const char     *name;
156f35450b9SMatthew G. Knepley     PetscInt        Nc, Nq, Nqc;
1577d8a60eaSMatthew G. Knepley 
1587d8a60eaSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
1597d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
1607d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr);
1617d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr);
1624727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
1637d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
1647d8a60eaSMatthew G. Knepley       ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr);
165f35450b9SMatthew G. Knepley       ierr = PetscFEGetQuadrature((PetscFE) obj, &q);CHKERRQ(ierr);
1667d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr);
1677d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1687d8a60eaSMatthew G. Knepley       ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr);
169f35450b9SMatthew G. Knepley       ierr = PetscFVGetQuadrature((PetscFV) obj, &q);CHKERRQ(ierr);
1707d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr);
1717d8a60eaSMatthew G. Knepley     }
17297b6e6e8SMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f);
17397b6e6e8SMatthew G. Knepley     if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%D components", Nc);CHKERRQ(ierr);}
17497b6e6e8SMatthew G. Knepley     else        {ierr = PetscViewerASCIIPrintf(viewer, "%D component ", Nc);CHKERRQ(ierr);}
175249df284SMatthew G. Knepley     if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);}
176249df284SMatthew G. Knepley     else                   {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);}
177a6cbbb48SMatthew G. Knepley     if (prob->adjacency[f*2+0]) {
178a6cbbb48SMatthew G. Knepley       if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM++)");CHKERRQ(ierr);}
179a6cbbb48SMatthew G. Knepley       else                        {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM)");CHKERRQ(ierr);}
180a6cbbb48SMatthew G. Knepley     } else {
181a6cbbb48SMatthew G. Knepley       if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FEM)");CHKERRQ(ierr);}
182a6cbbb48SMatthew G. Knepley       else                        {ierr = PetscViewerASCIIPrintf(viewer, " (adj FUNKY)");CHKERRQ(ierr);}
183a6cbbb48SMatthew G. Knepley     }
1843e60c2a6SMatthew G. Knepley     if (q) {
185f35450b9SMatthew G. Knepley       ierr = PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL);CHKERRQ(ierr);
186f35450b9SMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " (Nq %D Nqc %D)", Nq, Nqc);CHKERRQ(ierr);
1873e60c2a6SMatthew G. Knepley     }
1887d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
1894727e194SMatthew G. Knepley     ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
1905d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1917d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);}
1927d8a60eaSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);}
1935d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
1947d8a60eaSMatthew G. Knepley   }
19597b6e6e8SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr);
19697b6e6e8SMatthew G. Knepley   if (numConstants) {
19797b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr);
19897b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
19957fc01e9SMatthew G. Knepley     for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);}
20097b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
20197b6e6e8SMatthew G. Knepley   }
2027d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
2037d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
2047d8a60eaSMatthew G. Knepley }
2057d8a60eaSMatthew G. Knepley 
2062764a2aaSMatthew G. Knepley /*@C
2072764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
2082764a2aaSMatthew G. Knepley 
2092764a2aaSMatthew G. Knepley   Collective on PetscDS
2102764a2aaSMatthew G. Knepley 
2112764a2aaSMatthew G. Knepley   Input Parameter:
2122764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
2132764a2aaSMatthew G. Knepley - v  - the viewer
2142764a2aaSMatthew G. Knepley 
2152764a2aaSMatthew G. Knepley   Level: developer
2162764a2aaSMatthew G. Knepley 
2172764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
2182764a2aaSMatthew G. Knepley @*/
2192764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
2202764a2aaSMatthew G. Knepley {
2217d8a60eaSMatthew G. Knepley   PetscBool      iascii;
2222764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2232764a2aaSMatthew G. Knepley 
2242764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2252764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2262764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
2277d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
2287d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
2297d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2302764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2312764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2322764a2aaSMatthew G. Knepley }
2332764a2aaSMatthew G. Knepley 
2342764a2aaSMatthew G. Knepley /*@
2352764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2362764a2aaSMatthew G. Knepley 
2372764a2aaSMatthew G. Knepley   Collective on PetscDS
2382764a2aaSMatthew G. Knepley 
2392764a2aaSMatthew G. Knepley   Input Parameter:
2402764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2412764a2aaSMatthew G. Knepley 
2422764a2aaSMatthew G. Knepley   Options Database:
24355c1f793SMatthew G. Knepley + -petscds_type <type>     : Set the DS type
24455c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS
24555c1f793SMatthew G. Knepley . -petscds_jac_pre         : Turn formation of a separate Jacobian preconditioner on and off
24655c1f793SMatthew G. Knepley . -bc_<name> <ids>         : Specify a list of label ids for a boundary condition
24755c1f793SMatthew G. Knepley - -bc_<name>_comp <comps>  : Specify a list of field components to constrain for a boundary condition
2482764a2aaSMatthew G. Knepley 
2492764a2aaSMatthew G. Knepley   Level: developer
2502764a2aaSMatthew G. Knepley 
2512764a2aaSMatthew G. Knepley .seealso PetscDSView()
2522764a2aaSMatthew G. Knepley @*/
2532764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
2542764a2aaSMatthew G. Knepley {
255f1fd5e65SToby Isaac   DSBoundary     b;
2562764a2aaSMatthew G. Knepley   const char    *defaultType;
2572764a2aaSMatthew G. Knepley   char           name[256];
2582764a2aaSMatthew G. Knepley   PetscBool      flg;
2592764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2602764a2aaSMatthew G. Knepley 
2612764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2622764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2632764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
2642764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
2652764a2aaSMatthew G. Knepley   } else {
2662764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
2672764a2aaSMatthew G. Knepley   }
2680f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
2692764a2aaSMatthew G. Knepley 
2702764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
271f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
272f1fd5e65SToby Isaac     char       optname[1024];
273f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
274f1fd5e65SToby Isaac     PetscBool  flg;
275f1fd5e65SToby Isaac 
276f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
277f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
278f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
279f1fd5e65SToby Isaac     if (flg) {
280f1fd5e65SToby Isaac       b->numids = len;
281f1fd5e65SToby Isaac       ierr = PetscFree(b->ids);CHKERRQ(ierr);
282f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr);
283f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->ids, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
284f1fd5e65SToby Isaac     }
285e7b0402cSSander Arens     len = 1024;
286f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
287f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
288f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
289f1fd5e65SToby Isaac     if (flg) {
290f1fd5e65SToby Isaac       b->numcomps = len;
291f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
292f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
293f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->comps, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
294f1fd5e65SToby Isaac     }
295f1fd5e65SToby Isaac   }
2962764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
2972764a2aaSMatthew G. Knepley   if (flg) {
2982764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
2992764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
3002764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
3012764a2aaSMatthew G. Knepley   }
30255c1f793SMatthew G. Knepley   ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr);
3032764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
3042764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
3050633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
3062764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
3075d160056SMatthew G. Knepley   if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);}
3082764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3092764a2aaSMatthew G. Knepley }
3102764a2aaSMatthew G. Knepley 
3112764a2aaSMatthew G. Knepley /*@C
3122764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
3132764a2aaSMatthew G. Knepley 
3142764a2aaSMatthew G. Knepley   Collective on PetscDS
3152764a2aaSMatthew G. Knepley 
3162764a2aaSMatthew G. Knepley   Input Parameter:
3172764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
3182764a2aaSMatthew G. Knepley 
3192764a2aaSMatthew G. Knepley   Level: developer
3202764a2aaSMatthew G. Knepley 
3212764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
3222764a2aaSMatthew G. Knepley @*/
3232764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
3242764a2aaSMatthew G. Knepley {
3252764a2aaSMatthew G. Knepley   const PetscInt Nf = prob->Nf;
32694a5e212SMatthew G. Knepley   PetscInt       dim, dimEmbed, work, NcMax = 0, NqMax = 0, NsMax = 1, f;
3272764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3282764a2aaSMatthew G. Knepley 
3292764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3302764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3312764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3322764a2aaSMatthew G. Knepley   /* Calculate sizes */
3332764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
334d1506c7cSMatthew G. Knepley   ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr);
335f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
33647e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
337f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
338f744cafaSSander Arens   ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisFace,Nf,&prob->basisDerFace);CHKERRQ(ierr);
3392764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3409de99aefSMatthew G. Knepley     PetscObject     obj;
3419de99aefSMatthew G. Knepley     PetscClassId    id;
3422764a2aaSMatthew G. Knepley     PetscQuadrature q;
3439de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
3442764a2aaSMatthew G. Knepley 
3459de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3469de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3479de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
3489de99aefSMatthew G. Knepley       PetscFE fe = (PetscFE) obj;
3499de99aefSMatthew G. Knepley 
3502764a2aaSMatthew G. Knepley       ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
3512764a2aaSMatthew G. Knepley       ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
3522764a2aaSMatthew G. Knepley       ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
3532764a2aaSMatthew G. Knepley       ierr = PetscFEGetDefaultTabulation(fe, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3544d0b9603SSander Arens       ierr = PetscFEGetFaceTabulation(fe, &prob->basisFace[f], &prob->basisDerFace[f], NULL);CHKERRQ(ierr);
3559de99aefSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
3569de99aefSMatthew G. Knepley       PetscFV fv = (PetscFV) obj;
3579de99aefSMatthew G. Knepley 
3589de99aefSMatthew G. Knepley       ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
3599de99aefSMatthew G. Knepley       ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
3609c3cf19fSMatthew G. Knepley       Nb   = Nc;
3616c1a3d01SMatthew G. Knepley       ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3624d0b9603SSander Arens       /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
363abac5ca0SMatthew G. Knepley     } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
36447e57110SSander Arens     prob->Nc[f]       = Nc;
36547e57110SSander Arens     prob->Nb[f]       = Nb;
366194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
367194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
368a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
3692764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
3702764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
3719c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
3722764a2aaSMatthew G. Knepley     prob->totComp += Nc;
37394a5e212SMatthew G. Knepley     /* There are two faces for all fields but the cohesive field on a hybrid cell */
37494a5e212SMatthew G. Knepley     if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb;
3752764a2aaSMatthew G. Knepley   }
3762764a2aaSMatthew G. Knepley   work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim));
3772764a2aaSMatthew G. Knepley   /* Allocate works space */
37894a5e212SMatthew G. Knepley   if (prob->isHybrid) NsMax = 2;
37994a5e212SMatthew G. Knepley   ierr = PetscMalloc5(NsMax*prob->totComp,&prob->u,NsMax*prob->totComp,&prob->u_t,NsMax*prob->totComp*dimEmbed,&prob->u_x,dimEmbed,&prob->x,work,&prob->refSpaceDer);CHKERRQ(ierr);
38094a5e212SMatthew G. Knepley   ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dim,&prob->f1,
38194a5e212SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dim,&prob->g1,
38294a5e212SMatthew G. Knepley                       NsMax*NsMax*NqMax*NcMax*NcMax*dim,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dim*dim,&prob->g3);CHKERRQ(ierr);
3832764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
3842764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
3852764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3862764a2aaSMatthew G. Knepley }
3872764a2aaSMatthew G. Knepley 
3882764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
3892764a2aaSMatthew G. Knepley {
3902764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3912764a2aaSMatthew G. Knepley 
3922764a2aaSMatthew G. Knepley   PetscFunctionBegin;
39347e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
394f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
395f744cafaSSander Arens   ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisFace,prob->basisDerFace);CHKERRQ(ierr);
3962764a2aaSMatthew G. Knepley   ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr);
3972764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
3982764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3992764a2aaSMatthew G. Knepley }
4002764a2aaSMatthew G. Knepley 
4012764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
4022764a2aaSMatthew G. Knepley {
403f744cafaSSander Arens   PetscObject      *tmpd;
404a6cbbb48SMatthew G. Knepley   PetscBool        *tmpi, *tmpa;
40532d2bbc9SMatthew G. Knepley   PetscPointFunc   *tmpobj, *tmpf, *tmpup;
406b7e05686SMatthew G. Knepley   PetscPointJac    *tmpg, *tmpgp, *tmpgt;
4072aa1fc23SMatthew G. Knepley   PetscBdPointFunc *tmpfbd;
4082aa1fc23SMatthew G. Knepley   PetscBdPointJac  *tmpgbd;
409194d53e6SMatthew G. Knepley   PetscRiemannFunc *tmpr;
410c371a6d1SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol;
4110c2f2876SMatthew G. Knepley   void            **tmpctx;
412a6cbbb48SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f, i;
4132764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
4142764a2aaSMatthew G. Knepley 
4152764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4162764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
4172764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
4182764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
419f744cafaSSander Arens   ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr);
420f744cafaSSander Arens   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; for (i = 0; i < 2; ++i) tmpa[f*2+i] = prob->adjacency[f*2+i];}
421f744cafaSSander Arens   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpa[f*2+0] = PETSC_FALSE; tmpa[f*2+1] = PETSC_TRUE;}
422f744cafaSSander Arens   ierr = PetscFree3(prob->disc, prob->implicit, prob->adjacency);CHKERRQ(ierr);
4232764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
4242764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
425249df284SMatthew G. Knepley   prob->implicit  = tmpi;
426a6cbbb48SMatthew G. Knepley   prob->adjacency = tmpa;
427b7e05686SMatthew 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);
42832d2bbc9SMatthew G. Knepley   ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr);
4292764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f];
4302764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f];
4312764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f];
432475e0ac9SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f];
4330c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f];
43432d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
4350c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
4362764a2aaSMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL;
4372764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL;
4382764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL;
439475e0ac9SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL;
440b7e05686SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL;
4410c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL;
44232d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
4430c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
444b7e05686SMatthew G. Knepley   ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr);
44532d2bbc9SMatthew G. Knepley   ierr = PetscFree(prob->update);CHKERRQ(ierr);
4462764a2aaSMatthew G. Knepley   prob->obj = tmpobj;
4472764a2aaSMatthew G. Knepley   prob->f   = tmpf;
4482764a2aaSMatthew G. Knepley   prob->g   = tmpg;
449475e0ac9SMatthew G. Knepley   prob->gp  = tmpgp;
450b7e05686SMatthew G. Knepley   prob->gt  = tmpgt;
4510c2f2876SMatthew G. Knepley   prob->r   = tmpr;
45232d2bbc9SMatthew G. Knepley   prob->update = tmpup;
4530c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
454c371a6d1SMatthew G. Knepley   ierr = PetscCalloc3(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew, &tmpexactSol);CHKERRQ(ierr);
4552764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f];
4562764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f];
457c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
4582764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL;
4592764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL;
460c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
461c371a6d1SMatthew G. Knepley   ierr = PetscFree3(prob->fBd, prob->gBd, prob->exactSol);CHKERRQ(ierr);
4622764a2aaSMatthew G. Knepley   prob->fBd = tmpfbd;
4632764a2aaSMatthew G. Knepley   prob->gBd = tmpgbd;
464c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
4652764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4662764a2aaSMatthew G. Knepley }
4672764a2aaSMatthew G. Knepley 
4682764a2aaSMatthew G. Knepley /*@
4692764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
4702764a2aaSMatthew G. Knepley 
4712764a2aaSMatthew G. Knepley   Collective on PetscDS
4722764a2aaSMatthew G. Knepley 
4732764a2aaSMatthew G. Knepley   Input Parameter:
4742764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
4752764a2aaSMatthew G. Knepley 
4762764a2aaSMatthew G. Knepley   Level: developer
4772764a2aaSMatthew G. Knepley 
4782764a2aaSMatthew G. Knepley .seealso PetscDSView()
4792764a2aaSMatthew G. Knepley @*/
4802764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob)
4812764a2aaSMatthew G. Knepley {
4822764a2aaSMatthew G. Knepley   PetscInt       f;
48358ebd649SToby Isaac   DSBoundary     next;
4842764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4852764a2aaSMatthew G. Knepley 
4862764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4872764a2aaSMatthew G. Knepley   if (!*prob) PetscFunctionReturn(0);
4882764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1);
4892764a2aaSMatthew G. Knepley 
4902764a2aaSMatthew G. Knepley   if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);}
4912764a2aaSMatthew G. Knepley   ((PetscObject) (*prob))->refct = 0;
492df3a45bdSMatthew G. Knepley   if ((*prob)->subprobs) {
493df3a45bdSMatthew G. Knepley     PetscInt dim, d;
494df3a45bdSMatthew G. Knepley 
495df3a45bdSMatthew G. Knepley     ierr = PetscDSGetSpatialDimension(*prob, &dim);CHKERRQ(ierr);
496df3a45bdSMatthew G. Knepley     for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*prob)->subprobs[d]);CHKERRQ(ierr);}
497df3a45bdSMatthew G. Knepley   }
498df3a45bdSMatthew G. Knepley   ierr = PetscFree((*prob)->subprobs);CHKERRQ(ierr);
4992764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr);
5002764a2aaSMatthew G. Knepley   for (f = 0; f < (*prob)->Nf; ++f) {
5012764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr);
5022764a2aaSMatthew G. Knepley   }
503f744cafaSSander Arens   ierr = PetscFree3((*prob)->disc, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr);
504b7e05686SMatthew G. Knepley   ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr);
50532d2bbc9SMatthew G. Knepley   ierr = PetscFree((*prob)->update);CHKERRQ(ierr);
506c371a6d1SMatthew G. Knepley   ierr = PetscFree3((*prob)->fBd,(*prob)->gBd,(*prob)->exactSol);CHKERRQ(ierr);
5072764a2aaSMatthew G. Knepley   if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);}
50858ebd649SToby Isaac   next = (*prob)->boundary;
50958ebd649SToby Isaac   while (next) {
51058ebd649SToby Isaac     DSBoundary b = next;
51158ebd649SToby Isaac 
51258ebd649SToby Isaac     next = b->next;
51358ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
51458ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
51558ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
51658ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
51758ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
51858ebd649SToby Isaac   }
51997b6e6e8SMatthew G. Knepley   ierr = PetscFree((*prob)->constants);CHKERRQ(ierr);
5202764a2aaSMatthew G. Knepley   ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr);
5212764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5222764a2aaSMatthew G. Knepley }
5232764a2aaSMatthew G. Knepley 
5242764a2aaSMatthew G. Knepley /*@
5252764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
5262764a2aaSMatthew G. Knepley 
5272764a2aaSMatthew G. Knepley   Collective on MPI_Comm
5282764a2aaSMatthew G. Knepley 
5292764a2aaSMatthew G. Knepley   Input Parameter:
5302764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
5312764a2aaSMatthew G. Knepley 
5322764a2aaSMatthew G. Knepley   Output Parameter:
5332764a2aaSMatthew G. Knepley . prob - The PetscDS object
5342764a2aaSMatthew G. Knepley 
5352764a2aaSMatthew G. Knepley   Level: beginner
5362764a2aaSMatthew G. Knepley 
5372764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
5382764a2aaSMatthew G. Knepley @*/
5392764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob)
5402764a2aaSMatthew G. Knepley {
5412764a2aaSMatthew G. Knepley   PetscDS   p;
5422764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5432764a2aaSMatthew G. Knepley 
5442764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5452764a2aaSMatthew G. Knepley   PetscValidPointer(prob, 2);
5462764a2aaSMatthew G. Knepley   *prob  = NULL;
5472764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5482764a2aaSMatthew G. Knepley 
54973107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5502764a2aaSMatthew G. Knepley 
5512764a2aaSMatthew G. Knepley   p->Nf    = 0;
5522764a2aaSMatthew G. Knepley   p->setup = PETSC_FALSE;
55397b6e6e8SMatthew G. Knepley   p->numConstants  = 0;
55497b6e6e8SMatthew G. Knepley   p->constants     = NULL;
555a859676bSMatthew G. Knepley   p->dimEmbed      = -1;
55603d90f89SMatthew G. Knepley   p->defaultAdj[0] = PETSC_FALSE;
55703d90f89SMatthew G. Knepley   p->defaultAdj[1] = PETSC_TRUE;
55855c1f793SMatthew G. Knepley   p->useJacPre     = PETSC_TRUE;
5592764a2aaSMatthew G. Knepley 
5602764a2aaSMatthew G. Knepley   *prob = p;
5612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5622764a2aaSMatthew G. Knepley }
5632764a2aaSMatthew G. Knepley 
564bc4ae4beSMatthew G. Knepley /*@
565bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
566bc4ae4beSMatthew G. Knepley 
567bc4ae4beSMatthew G. Knepley   Not collective
568bc4ae4beSMatthew G. Knepley 
569bc4ae4beSMatthew G. Knepley   Input Parameter:
570bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
571bc4ae4beSMatthew G. Knepley 
572bc4ae4beSMatthew G. Knepley   Output Parameter:
573bc4ae4beSMatthew G. Knepley . Nf - The number of fields
574bc4ae4beSMatthew G. Knepley 
575bc4ae4beSMatthew G. Knepley   Level: beginner
576bc4ae4beSMatthew G. Knepley 
577bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
578bc4ae4beSMatthew G. Knepley @*/
5792764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
5802764a2aaSMatthew G. Knepley {
5812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5822764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5832764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
5842764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
5852764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5862764a2aaSMatthew G. Knepley }
5872764a2aaSMatthew G. Knepley 
588bc4ae4beSMatthew G. Knepley /*@
589a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
590bc4ae4beSMatthew G. Knepley 
591bc4ae4beSMatthew G. Knepley   Not collective
592bc4ae4beSMatthew G. Knepley 
593bc4ae4beSMatthew G. Knepley   Input Parameter:
594bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
595bc4ae4beSMatthew G. Knepley 
596bc4ae4beSMatthew G. Knepley   Output Parameter:
597bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
598bc4ae4beSMatthew G. Knepley 
599bc4ae4beSMatthew G. Knepley   Level: beginner
600bc4ae4beSMatthew G. Knepley 
601a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate()
602bc4ae4beSMatthew G. Knepley @*/
6032764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
6042764a2aaSMatthew G. Knepley {
6052764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6062764a2aaSMatthew G. Knepley 
6072764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6082764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6092764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6102764a2aaSMatthew G. Knepley   *dim = 0;
6119de99aefSMatthew G. Knepley   if (prob->Nf) {
6129de99aefSMatthew G. Knepley     PetscObject  obj;
6139de99aefSMatthew G. Knepley     PetscClassId id;
6149de99aefSMatthew G. Knepley 
6159de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
6169de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
6179de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
6189de99aefSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
6199de99aefSMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
6209de99aefSMatthew G. Knepley   }
6212764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6222764a2aaSMatthew G. Knepley }
6232764a2aaSMatthew G. Knepley 
624bc4ae4beSMatthew G. Knepley /*@
625a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
626a859676bSMatthew G. Knepley 
627a859676bSMatthew G. Knepley   Not collective
628a859676bSMatthew G. Knepley 
629a859676bSMatthew G. Knepley   Input Parameter:
630a859676bSMatthew G. Knepley . prob - The PetscDS object
631a859676bSMatthew G. Knepley 
632a859676bSMatthew G. Knepley   Output Parameter:
633a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
634a859676bSMatthew G. Knepley 
635a859676bSMatthew G. Knepley   Level: beginner
636a859676bSMatthew G. Knepley 
637a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
638a859676bSMatthew G. Knepley @*/
639a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
640a859676bSMatthew G. Knepley {
641a859676bSMatthew G. Knepley   PetscFunctionBegin;
642a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
643a859676bSMatthew G. Knepley   PetscValidPointer(dimEmbed, 2);
644a859676bSMatthew G. Knepley   if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
645a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
646a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
647a859676bSMatthew G. Knepley }
648a859676bSMatthew G. Knepley 
649a859676bSMatthew G. Knepley /*@
650a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
651a859676bSMatthew G. Knepley 
652*ebfe4b0dSMatthew G. Knepley   Logically collective on DS
653a859676bSMatthew G. Knepley 
654a859676bSMatthew G. Knepley   Input Parameters:
655a859676bSMatthew G. Knepley + prob - The PetscDS object
656a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
657a859676bSMatthew G. Knepley 
658a859676bSMatthew G. Knepley   Level: beginner
659a859676bSMatthew G. Knepley 
660a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
661a859676bSMatthew G. Knepley @*/
662a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
663a859676bSMatthew G. Knepley {
664a859676bSMatthew G. Knepley   PetscFunctionBegin;
665a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
666*ebfe4b0dSMatthew G. Knepley   if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed);
667a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
668a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
669a859676bSMatthew G. Knepley }
670a859676bSMatthew G. Knepley 
671a859676bSMatthew G. Knepley /*@
6728edf6225SMatthew G. Knepley   PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell
6738edf6225SMatthew G. Knepley 
6748edf6225SMatthew G. Knepley   Not collective
6758edf6225SMatthew G. Knepley 
6768edf6225SMatthew G. Knepley   Input Parameter:
6778edf6225SMatthew G. Knepley . prob - The PetscDS object
6788edf6225SMatthew G. Knepley 
6798edf6225SMatthew G. Knepley   Output Parameter:
6808edf6225SMatthew G. Knepley . isHybrid - The flag
6818edf6225SMatthew G. Knepley 
6828edf6225SMatthew G. Knepley   Level: developer
6838edf6225SMatthew G. Knepley 
6848edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate()
6858edf6225SMatthew G. Knepley @*/
6868edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid)
6878edf6225SMatthew G. Knepley {
6888edf6225SMatthew G. Knepley   PetscFunctionBegin;
6898edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6908edf6225SMatthew G. Knepley   PetscValidPointer(isHybrid, 2);
6918edf6225SMatthew G. Knepley   *isHybrid = prob->isHybrid;
6928edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
6938edf6225SMatthew G. Knepley }
6948edf6225SMatthew G. Knepley 
6958edf6225SMatthew G. Knepley /*@
6968edf6225SMatthew G. Knepley   PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell
6978edf6225SMatthew G. Knepley 
6988edf6225SMatthew G. Knepley   Not collective
6998edf6225SMatthew G. Knepley 
7008edf6225SMatthew G. Knepley   Input Parameters:
7018edf6225SMatthew G. Knepley + prob - The PetscDS object
7028edf6225SMatthew G. Knepley - isHybrid - The flag
7038edf6225SMatthew G. Knepley 
7048edf6225SMatthew G. Knepley   Level: developer
7058edf6225SMatthew G. Knepley 
7068edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate()
7078edf6225SMatthew G. Knepley @*/
7088edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid)
7098edf6225SMatthew G. Knepley {
7108edf6225SMatthew G. Knepley   PetscFunctionBegin;
7118edf6225SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7128edf6225SMatthew G. Knepley   prob->isHybrid = isHybrid;
7138edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7148edf6225SMatthew G. Knepley }
7158edf6225SMatthew G. Knepley 
7168edf6225SMatthew G. Knepley /*@
717bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
718bc4ae4beSMatthew G. Knepley 
719bc4ae4beSMatthew G. Knepley   Not collective
720bc4ae4beSMatthew G. Knepley 
721bc4ae4beSMatthew G. Knepley   Input Parameter:
722bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
723bc4ae4beSMatthew G. Knepley 
724bc4ae4beSMatthew G. Knepley   Output Parameter:
725bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
726bc4ae4beSMatthew G. Knepley 
727bc4ae4beSMatthew G. Knepley   Level: beginner
728bc4ae4beSMatthew G. Knepley 
729bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
730bc4ae4beSMatthew G. Knepley @*/
7312764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
7322764a2aaSMatthew G. Knepley {
7332764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7342764a2aaSMatthew G. Knepley 
7352764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7362764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7372764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
7382764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
7392764a2aaSMatthew G. Knepley   *dim = prob->totDim;
7402764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7412764a2aaSMatthew G. Knepley }
7422764a2aaSMatthew G. Knepley 
743bc4ae4beSMatthew G. Knepley /*@
744bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
745bc4ae4beSMatthew G. Knepley 
746bc4ae4beSMatthew G. Knepley   Not collective
747bc4ae4beSMatthew G. Knepley 
748bc4ae4beSMatthew G. Knepley   Input Parameter:
749bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
750bc4ae4beSMatthew G. Knepley 
751bc4ae4beSMatthew G. Knepley   Output Parameter:
752bc4ae4beSMatthew G. Knepley . dim - The total number of components
753bc4ae4beSMatthew G. Knepley 
754bc4ae4beSMatthew G. Knepley   Level: beginner
755bc4ae4beSMatthew G. Knepley 
756bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
757bc4ae4beSMatthew G. Knepley @*/
7582764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
7592764a2aaSMatthew G. Knepley {
7602764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7612764a2aaSMatthew G. Knepley 
7622764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7632764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7642764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
7652764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
7662764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
7672764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7682764a2aaSMatthew G. Knepley }
7692764a2aaSMatthew G. Knepley 
770bc4ae4beSMatthew G. Knepley /*@
771bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
772bc4ae4beSMatthew G. Knepley 
773bc4ae4beSMatthew G. Knepley   Not collective
774bc4ae4beSMatthew G. Knepley 
775bc4ae4beSMatthew G. Knepley   Input Parameters:
776bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
777bc4ae4beSMatthew G. Knepley - f - The field number
778bc4ae4beSMatthew G. Knepley 
779bc4ae4beSMatthew G. Knepley   Output Parameter:
780bc4ae4beSMatthew G. Knepley . disc - The discretization object
781bc4ae4beSMatthew G. Knepley 
782bc4ae4beSMatthew G. Knepley   Level: beginner
783bc4ae4beSMatthew G. Knepley 
784f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
785bc4ae4beSMatthew G. Knepley @*/
7862764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
7872764a2aaSMatthew G. Knepley {
7882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7902764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
7912764a2aaSMatthew 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);
7922764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
7932764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7942764a2aaSMatthew G. Knepley }
7952764a2aaSMatthew G. Knepley 
796bc4ae4beSMatthew G. Knepley /*@
797bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
798bc4ae4beSMatthew G. Knepley 
799bc4ae4beSMatthew G. Knepley   Not collective
800bc4ae4beSMatthew G. Knepley 
801bc4ae4beSMatthew G. Knepley   Input Parameters:
802bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
803bc4ae4beSMatthew G. Knepley . f - The field number
804bc4ae4beSMatthew G. Knepley - disc - The discretization object
805bc4ae4beSMatthew G. Knepley 
806bc4ae4beSMatthew G. Knepley   Level: beginner
807bc4ae4beSMatthew G. Knepley 
808bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
809bc4ae4beSMatthew G. Knepley @*/
8102764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
8112764a2aaSMatthew G. Knepley {
8122764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8132764a2aaSMatthew G. Knepley 
8142764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8152764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8162764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
8172764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
8182764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
819c10f2116SMatthew G. Knepley   ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);
8202764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
8212764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
822249df284SMatthew G. Knepley   {
823249df284SMatthew G. Knepley     PetscClassId id;
824249df284SMatthew G. Knepley 
825249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
8261cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
8271cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr);
8281cf84007SMatthew G. Knepley       ierr = PetscDSSetAdjacency(prob, f, PETSC_FALSE, PETSC_TRUE);CHKERRQ(ierr);
8291cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
8301cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr);
8311cf84007SMatthew G. Knepley       ierr = PetscDSSetAdjacency(prob, f, PETSC_TRUE, PETSC_FALSE);CHKERRQ(ierr);
832a6cbbb48SMatthew G. Knepley     }
833249df284SMatthew G. Knepley   }
8342764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8352764a2aaSMatthew G. Knepley }
8362764a2aaSMatthew G. Knepley 
837bc4ae4beSMatthew G. Knepley /*@
838bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
839bc4ae4beSMatthew G. Knepley 
840bc4ae4beSMatthew G. Knepley   Not collective
841bc4ae4beSMatthew G. Knepley 
842bc4ae4beSMatthew G. Knepley   Input Parameters:
843bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
844bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
845bc4ae4beSMatthew G. Knepley 
846bc4ae4beSMatthew G. Knepley   Level: beginner
847bc4ae4beSMatthew G. Knepley 
848bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
849bc4ae4beSMatthew G. Knepley @*/
8502764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
8512764a2aaSMatthew G. Knepley {
8522764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8532764a2aaSMatthew G. Knepley 
8542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8552764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
8562764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8572764a2aaSMatthew G. Knepley }
8582764a2aaSMatthew G. Knepley 
859249df284SMatthew G. Knepley /*@
860249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
861249df284SMatthew G. Knepley 
862249df284SMatthew G. Knepley   Not collective
863249df284SMatthew G. Knepley 
864249df284SMatthew G. Knepley   Input Parameters:
865249df284SMatthew G. Knepley + prob - The PetscDS object
866249df284SMatthew G. Knepley - f - The field number
867249df284SMatthew G. Knepley 
868249df284SMatthew G. Knepley   Output Parameter:
869249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
870249df284SMatthew G. Knepley 
871249df284SMatthew G. Knepley   Level: developer
872249df284SMatthew G. Knepley 
873f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
874249df284SMatthew G. Knepley @*/
875249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
876249df284SMatthew G. Knepley {
877249df284SMatthew G. Knepley   PetscFunctionBegin;
878249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
879249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
880249df284SMatthew 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);
881249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
882249df284SMatthew G. Knepley   PetscFunctionReturn(0);
883249df284SMatthew G. Knepley }
884249df284SMatthew G. Knepley 
885249df284SMatthew G. Knepley /*@
886249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
887249df284SMatthew G. Knepley 
888249df284SMatthew G. Knepley   Not collective
889249df284SMatthew G. Knepley 
890249df284SMatthew G. Knepley   Input Parameters:
891249df284SMatthew G. Knepley + prob - The PetscDS object
892249df284SMatthew G. Knepley . f - The field number
893249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
894249df284SMatthew G. Knepley 
895249df284SMatthew G. Knepley   Level: developer
896249df284SMatthew G. Knepley 
897f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
898249df284SMatthew G. Knepley @*/
899249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
900249df284SMatthew G. Knepley {
901249df284SMatthew G. Knepley   PetscFunctionBegin;
902249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
903249df284SMatthew 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);
904249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
905249df284SMatthew G. Knepley   PetscFunctionReturn(0);
906249df284SMatthew G. Knepley }
907249df284SMatthew G. Knepley 
908a6cbbb48SMatthew G. Knepley /*@
909a6cbbb48SMatthew G. Knepley   PetscDSGetAdjacency - Returns the flags for determining variable influence
910a6cbbb48SMatthew G. Knepley 
911a6cbbb48SMatthew G. Knepley   Not collective
912a6cbbb48SMatthew G. Knepley 
913a6cbbb48SMatthew G. Knepley   Input Parameters:
914a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
915a6cbbb48SMatthew G. Knepley - f - The field number
916a6cbbb48SMatthew G. Knepley 
917a6cbbb48SMatthew G. Knepley   Output Parameter:
918a6cbbb48SMatthew G. Knepley + useCone    - Flag for variable influence starting with the cone operation
919a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
920a6cbbb48SMatthew G. Knepley 
921a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
922a6cbbb48SMatthew G. Knepley 
923a6cbbb48SMatthew G. Knepley   Level: developer
924a6cbbb48SMatthew G. Knepley 
925f744cafaSSander Arens .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
926a6cbbb48SMatthew G. Knepley @*/
927a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure)
928a6cbbb48SMatthew G. Knepley {
929a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
930a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9311cf84007SMatthew G. Knepley   if (useCone) PetscValidPointer(useCone, 3);
9321cf84007SMatthew G. Knepley   if (useClosure) PetscValidPointer(useClosure, 4);
93306cc46feSMatthew G. Knepley   if (f < 0) {
93406cc46feSMatthew G. Knepley     if (useCone)    *useCone    = prob->defaultAdj[0];
93506cc46feSMatthew G. Knepley     if (useClosure) *useClosure = prob->defaultAdj[1];
93606cc46feSMatthew G. Knepley   } else {
93706cc46feSMatthew G. Knepley     if (f >= prob->Nf) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
9381cf84007SMatthew G. Knepley     if (useCone)    *useCone    = prob->adjacency[f*2+0];
9391cf84007SMatthew G. Knepley     if (useClosure) *useClosure = prob->adjacency[f*2+1];
94006cc46feSMatthew G. Knepley   }
941a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
942a6cbbb48SMatthew G. Knepley }
943a6cbbb48SMatthew G. Knepley 
944a6cbbb48SMatthew G. Knepley /*@
945a6cbbb48SMatthew G. Knepley   PetscDSSetAdjacency - Set the flags for determining variable influence
946a6cbbb48SMatthew G. Knepley 
947a6cbbb48SMatthew G. Knepley   Not collective
948a6cbbb48SMatthew G. Knepley 
949a6cbbb48SMatthew G. Knepley   Input Parameters:
950a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
951a6cbbb48SMatthew G. Knepley . f - The field number
952a6cbbb48SMatthew G. Knepley . useCone    - Flag for variable influence starting with the cone operation
953a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
954a6cbbb48SMatthew G. Knepley 
955a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
956a6cbbb48SMatthew G. Knepley 
957a6cbbb48SMatthew G. Knepley   Level: developer
958a6cbbb48SMatthew G. Knepley 
959f744cafaSSander Arens .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
960a6cbbb48SMatthew G. Knepley @*/
961a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure)
962a6cbbb48SMatthew G. Knepley {
963a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
964a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
96506cc46feSMatthew G. Knepley   if (f < 0) {
96606cc46feSMatthew G. Knepley     prob->defaultAdj[0] = useCone;
96706cc46feSMatthew G. Knepley     prob->defaultAdj[1] = useClosure;
96806cc46feSMatthew G. Knepley   } else {
96906cc46feSMatthew G. Knepley     if (f >= prob->Nf) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
970a6cbbb48SMatthew G. Knepley     prob->adjacency[f*2+0] = useCone;
971a6cbbb48SMatthew G. Knepley     prob->adjacency[f*2+1] = useClosure;
97206cc46feSMatthew G. Knepley   }
973a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
974a6cbbb48SMatthew G. Knepley }
975a6cbbb48SMatthew G. Knepley 
9762764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f,
97730b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
978194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
979194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
98097b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
9812764a2aaSMatthew G. Knepley {
9822764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9832764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9842764a2aaSMatthew G. Knepley   PetscValidPointer(obj, 2);
9852764a2aaSMatthew 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);
9862764a2aaSMatthew G. Knepley   *obj = prob->obj[f];
9872764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9882764a2aaSMatthew G. Knepley }
9892764a2aaSMatthew G. Knepley 
9902764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f,
99130b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
992194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
993194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
99497b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
9952764a2aaSMatthew G. Knepley {
9962764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9972764a2aaSMatthew G. Knepley 
9982764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9992764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1000de716cbcSToby Isaac   if (obj) PetscValidFunction(obj, 2);
10012764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
10022764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
10032764a2aaSMatthew G. Knepley   prob->obj[f] = obj;
10042764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10052764a2aaSMatthew G. Knepley }
10062764a2aaSMatthew G. Knepley 
1007194d53e6SMatthew G. Knepley /*@C
1008194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1009194d53e6SMatthew G. Knepley 
1010194d53e6SMatthew G. Knepley   Not collective
1011194d53e6SMatthew G. Knepley 
1012194d53e6SMatthew G. Knepley   Input Parameters:
1013194d53e6SMatthew G. Knepley + prob - The PetscDS
1014194d53e6SMatthew G. Knepley - f    - The test field number
1015194d53e6SMatthew G. Knepley 
1016194d53e6SMatthew G. Knepley   Output Parameters:
1017194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1018194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1019194d53e6SMatthew G. Knepley 
1020194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1021194d53e6SMatthew G. Knepley 
1022194d53e6SMatthew 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)
1023194d53e6SMatthew G. Knepley 
1024194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1025194d53e6SMatthew G. Knepley 
102630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1027194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1028194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
102930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1030194d53e6SMatthew G. Knepley 
1031194d53e6SMatthew G. Knepley + dim - the spatial dimension
1032194d53e6SMatthew G. Knepley . Nf - the number of fields
1033194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1034194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1035194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1036194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1037194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1038194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1039194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1040194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1041194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1042194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1043194d53e6SMatthew G. Knepley . t - current time
1044194d53e6SMatthew G. Knepley . x - coordinates of the current point
104597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
104697b6e6e8SMatthew G. Knepley . constants - constant parameters
1047194d53e6SMatthew G. Knepley - f0 - output values at the current point
1048194d53e6SMatthew G. Knepley 
1049194d53e6SMatthew G. Knepley   Level: intermediate
1050194d53e6SMatthew G. Knepley 
1051194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
1052194d53e6SMatthew G. Knepley @*/
10532764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f,
105430b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1055194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1056194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
105797b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
105830b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1059194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1060194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
106197b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
10622764a2aaSMatthew G. Knepley {
10632764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10642764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
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   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];}
10672764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];}
10682764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10692764a2aaSMatthew G. Knepley }
10702764a2aaSMatthew G. Knepley 
1071194d53e6SMatthew G. Knepley /*@C
1072194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1073194d53e6SMatthew G. Knepley 
1074194d53e6SMatthew G. Knepley   Not collective
1075194d53e6SMatthew G. Knepley 
1076194d53e6SMatthew G. Knepley   Input Parameters:
1077194d53e6SMatthew G. Knepley + prob - The PetscDS
1078194d53e6SMatthew G. Knepley . f    - The test field number
1079194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1080194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1081194d53e6SMatthew G. Knepley 
1082194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1083194d53e6SMatthew G. Knepley 
1084194d53e6SMatthew 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)
1085194d53e6SMatthew G. Knepley 
1086194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1087194d53e6SMatthew G. Knepley 
108830b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1089194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1090194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
109130b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1092194d53e6SMatthew G. Knepley 
1093194d53e6SMatthew G. Knepley + dim - the spatial dimension
1094194d53e6SMatthew G. Knepley . Nf - the number of fields
1095194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1096194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1097194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1098194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1099194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1100194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1101194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1102194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1103194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1104194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1105194d53e6SMatthew G. Knepley . t - current time
1106194d53e6SMatthew G. Knepley . x - coordinates of the current point
110797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
110897b6e6e8SMatthew G. Knepley . constants - constant parameters
1109194d53e6SMatthew G. Knepley - f0 - output values at the current point
1110194d53e6SMatthew G. Knepley 
1111194d53e6SMatthew G. Knepley   Level: intermediate
1112194d53e6SMatthew G. Knepley 
1113194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1114194d53e6SMatthew G. Knepley @*/
11152764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f,
111630b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1117194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1118194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
111997b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
112030b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1121194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1122194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
112397b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
11242764a2aaSMatthew G. Knepley {
11252764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
11262764a2aaSMatthew G. Knepley 
11272764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11282764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1129f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1130f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
11312764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
11322764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
11332764a2aaSMatthew G. Knepley   prob->f[f*2+0] = f0;
11342764a2aaSMatthew G. Knepley   prob->f[f*2+1] = f1;
11352764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11362764a2aaSMatthew G. Knepley }
11372764a2aaSMatthew G. Knepley 
11383e75805dSMatthew G. Knepley /*@C
11393e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
11403e75805dSMatthew G. Knepley 
11413e75805dSMatthew G. Knepley   Not collective
11423e75805dSMatthew G. Knepley 
11433e75805dSMatthew G. Knepley   Input Parameter:
11443e75805dSMatthew G. Knepley . prob - The PetscDS
11453e75805dSMatthew G. Knepley 
11463e75805dSMatthew G. Knepley   Output Parameter:
11473e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
11483e75805dSMatthew G. Knepley 
11493e75805dSMatthew G. Knepley   Level: intermediate
11503e75805dSMatthew G. Knepley 
11513e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
11523e75805dSMatthew G. Knepley @*/
11533e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac)
11543e75805dSMatthew G. Knepley {
11553e75805dSMatthew G. Knepley   PetscInt f, g, h;
11563e75805dSMatthew G. Knepley 
11573e75805dSMatthew G. Knepley   PetscFunctionBegin;
11583e75805dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11593e75805dSMatthew G. Knepley   *hasJac = PETSC_FALSE;
11603e75805dSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
11613e75805dSMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
11623e75805dSMatthew G. Knepley       for (h = 0; h < 4; ++h) {
11633e75805dSMatthew G. Knepley         if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE;
11643e75805dSMatthew G. Knepley       }
11653e75805dSMatthew G. Knepley     }
11663e75805dSMatthew G. Knepley   }
11673e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
11683e75805dSMatthew G. Knepley }
11693e75805dSMatthew G. Knepley 
1170194d53e6SMatthew G. Knepley /*@C
1171194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1172194d53e6SMatthew G. Knepley 
1173194d53e6SMatthew G. Knepley   Not collective
1174194d53e6SMatthew G. Knepley 
1175194d53e6SMatthew G. Knepley   Input Parameters:
1176194d53e6SMatthew G. Knepley + prob - The PetscDS
1177194d53e6SMatthew G. Knepley . f    - The test field number
1178194d53e6SMatthew G. Knepley - g    - The field number
1179194d53e6SMatthew G. Knepley 
1180194d53e6SMatthew G. Knepley   Output Parameters:
1181194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1182194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1183194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1184194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1185194d53e6SMatthew G. Knepley 
1186194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1187194d53e6SMatthew G. Knepley 
1188194d53e6SMatthew 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
1189194d53e6SMatthew G. Knepley 
1190194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1191194d53e6SMatthew G. Knepley 
119230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1193194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1194194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
119530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1196194d53e6SMatthew G. Knepley 
1197194d53e6SMatthew G. Knepley + dim - the spatial dimension
1198194d53e6SMatthew G. Knepley . Nf - the number of fields
1199194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1200194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1201194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1202194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1203194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1204194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1205194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1206194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1207194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1208194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1209194d53e6SMatthew G. Knepley . t - current time
12102aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1211194d53e6SMatthew G. Knepley . x - coordinates of the current point
121297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
121397b6e6e8SMatthew G. Knepley . constants - constant parameters
1214194d53e6SMatthew G. Knepley - g0 - output values at the current point
1215194d53e6SMatthew G. Knepley 
1216194d53e6SMatthew G. Knepley   Level: intermediate
1217194d53e6SMatthew G. Knepley 
1218194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1219194d53e6SMatthew G. Knepley @*/
12202764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g,
122130b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1222194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1223194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
122497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
122530b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1226194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1227194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
122897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
122930b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1230194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1231194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
123330b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1234194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1235194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
12372764a2aaSMatthew G. Knepley {
12382764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12392764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
12402764a2aaSMatthew 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);
12412764a2aaSMatthew 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);
12422764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];}
12432764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];}
12442764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];}
12452764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];}
12462764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12472764a2aaSMatthew G. Knepley }
12482764a2aaSMatthew G. Knepley 
1249194d53e6SMatthew G. Knepley /*@C
1250194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1251194d53e6SMatthew G. Knepley 
1252194d53e6SMatthew G. Knepley   Not collective
1253194d53e6SMatthew G. Knepley 
1254194d53e6SMatthew G. Knepley   Input Parameters:
1255194d53e6SMatthew G. Knepley + prob - The PetscDS
1256194d53e6SMatthew G. Knepley . f    - The test field number
1257194d53e6SMatthew G. Knepley . g    - The field number
1258194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1259194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1260194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1261194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1262194d53e6SMatthew G. Knepley 
1263194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1264194d53e6SMatthew G. Knepley 
1265194d53e6SMatthew 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
1266194d53e6SMatthew G. Knepley 
1267194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1268194d53e6SMatthew G. Knepley 
126930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1270194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1271194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
127230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1273194d53e6SMatthew G. Knepley 
1274194d53e6SMatthew G. Knepley + dim - the spatial dimension
1275194d53e6SMatthew G. Knepley . Nf - the number of fields
1276194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1277194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1278194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1279194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1280194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1281194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1282194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1283194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1284194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1285194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1286194d53e6SMatthew G. Knepley . t - current time
12872aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1288194d53e6SMatthew G. Knepley . x - coordinates of the current point
128997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
129097b6e6e8SMatthew G. Knepley . constants - constant parameters
1291194d53e6SMatthew G. Knepley - g0 - output values at the current point
1292194d53e6SMatthew G. Knepley 
1293194d53e6SMatthew G. Knepley   Level: intermediate
1294194d53e6SMatthew G. Knepley 
1295194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1296194d53e6SMatthew G. Knepley @*/
12972764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g,
129830b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1299194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1300194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130197b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
130230b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1303194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1304194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130597b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
130630b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1307194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1308194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130997b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
131030b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1311194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1312194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
131397b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
13142764a2aaSMatthew G. Knepley {
13152764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
13162764a2aaSMatthew G. Knepley 
13172764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13182764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
13192764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
13202764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
13212764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
13222764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
13232764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
13242764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
13252764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
13262764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+0] = g0;
13272764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+1] = g1;
13282764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+2] = g2;
13292764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+3] = g3;
13302764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
13312764a2aaSMatthew G. Knepley }
13322764a2aaSMatthew G. Knepley 
1333475e0ac9SMatthew G. Knepley /*@C
133455c1f793SMatthew G. Knepley   PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner
133555c1f793SMatthew G. Knepley 
133655c1f793SMatthew G. Knepley   Not collective
133755c1f793SMatthew G. Knepley 
133855c1f793SMatthew G. Knepley   Input Parameters:
133955c1f793SMatthew G. Knepley + prob - The PetscDS
134055c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
134155c1f793SMatthew G. Knepley 
134255c1f793SMatthew G. Knepley   Level: intermediate
134355c1f793SMatthew G. Knepley 
134455c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
134555c1f793SMatthew G. Knepley @*/
134655c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
134755c1f793SMatthew G. Knepley {
134855c1f793SMatthew G. Knepley   PetscFunctionBegin;
134955c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
135055c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
135155c1f793SMatthew G. Knepley   PetscFunctionReturn(0);
135255c1f793SMatthew G. Knepley }
135355c1f793SMatthew G. Knepley 
135455c1f793SMatthew G. Knepley /*@C
1355475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1356475e0ac9SMatthew G. Knepley 
1357475e0ac9SMatthew G. Knepley   Not collective
1358475e0ac9SMatthew G. Knepley 
1359475e0ac9SMatthew G. Knepley   Input Parameter:
1360475e0ac9SMatthew G. Knepley . prob - The PetscDS
1361475e0ac9SMatthew G. Knepley 
1362475e0ac9SMatthew G. Knepley   Output Parameter:
1363475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1364475e0ac9SMatthew G. Knepley 
1365475e0ac9SMatthew G. Knepley   Level: intermediate
1366475e0ac9SMatthew G. Knepley 
1367475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1368475e0ac9SMatthew G. Knepley @*/
1369475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre)
1370475e0ac9SMatthew G. Knepley {
1371475e0ac9SMatthew G. Knepley   PetscInt f, g, h;
1372475e0ac9SMatthew G. Knepley 
1373475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1374475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1375475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
137655c1f793SMatthew G. Knepley   if (!prob->useJacPre) PetscFunctionReturn(0);
1377475e0ac9SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1378475e0ac9SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1379475e0ac9SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1380475e0ac9SMatthew G. Knepley         if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE;
1381475e0ac9SMatthew G. Knepley       }
1382475e0ac9SMatthew G. Knepley     }
1383475e0ac9SMatthew G. Knepley   }
1384475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1385475e0ac9SMatthew G. Knepley }
1386475e0ac9SMatthew G. Knepley 
1387475e0ac9SMatthew G. Knepley /*@C
1388475e0ac9SMatthew 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.
1389475e0ac9SMatthew G. Knepley 
1390475e0ac9SMatthew G. Knepley   Not collective
1391475e0ac9SMatthew G. Knepley 
1392475e0ac9SMatthew G. Knepley   Input Parameters:
1393475e0ac9SMatthew G. Knepley + prob - The PetscDS
1394475e0ac9SMatthew G. Knepley . f    - The test field number
1395475e0ac9SMatthew G. Knepley - g    - The field number
1396475e0ac9SMatthew G. Knepley 
1397475e0ac9SMatthew G. Knepley   Output Parameters:
1398475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1399475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1400475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1401475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1402475e0ac9SMatthew G. Knepley 
1403475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1404475e0ac9SMatthew G. Knepley 
1405475e0ac9SMatthew 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
1406475e0ac9SMatthew G. Knepley 
1407475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1408475e0ac9SMatthew G. Knepley 
1409475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1410475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1411475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1412475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1413475e0ac9SMatthew G. Knepley 
1414475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1415475e0ac9SMatthew G. Knepley . Nf - the number of fields
1416475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1417475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1418475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1419475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1420475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1421475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1422475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1423475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1424475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1425475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1426475e0ac9SMatthew G. Knepley . t - current time
1427475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1428475e0ac9SMatthew G. Knepley . x - coordinates of the current point
142997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
143097b6e6e8SMatthew G. Knepley . constants - constant parameters
1431475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1432475e0ac9SMatthew G. Knepley 
1433475e0ac9SMatthew G. Knepley   Level: intermediate
1434475e0ac9SMatthew G. Knepley 
1435475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1436475e0ac9SMatthew G. Knepley @*/
1437475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1438475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1439475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1440475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
144197b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1442475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1443475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1444475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
144597b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1446475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1447475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1448475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
144997b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1450475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1451475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1452475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
145397b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1454475e0ac9SMatthew G. Knepley {
1455475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1456475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1457475e0ac9SMatthew 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);
1458475e0ac9SMatthew 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);
1459475e0ac9SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];}
1460475e0ac9SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];}
1461475e0ac9SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];}
1462475e0ac9SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];}
1463475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1464475e0ac9SMatthew G. Knepley }
1465475e0ac9SMatthew G. Knepley 
1466475e0ac9SMatthew G. Knepley /*@C
1467475e0ac9SMatthew 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.
1468475e0ac9SMatthew G. Knepley 
1469475e0ac9SMatthew G. Knepley   Not collective
1470475e0ac9SMatthew G. Knepley 
1471475e0ac9SMatthew G. Knepley   Input Parameters:
1472475e0ac9SMatthew G. Knepley + prob - The PetscDS
1473475e0ac9SMatthew G. Knepley . f    - The test field number
1474475e0ac9SMatthew G. Knepley . g    - The field number
1475475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1476475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1477475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1478475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1479475e0ac9SMatthew G. Knepley 
1480475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1481475e0ac9SMatthew G. Knepley 
1482475e0ac9SMatthew 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
1483475e0ac9SMatthew G. Knepley 
1484475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1485475e0ac9SMatthew G. Knepley 
1486475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1487475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1488475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1489475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1490475e0ac9SMatthew G. Knepley 
1491475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1492475e0ac9SMatthew G. Knepley . Nf - the number of fields
1493475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1494475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1495475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1496475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1497475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1498475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1499475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1500475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1501475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1502475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1503475e0ac9SMatthew G. Knepley . t - current time
1504475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1505475e0ac9SMatthew G. Knepley . x - coordinates of the current point
150697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
150797b6e6e8SMatthew G. Knepley . constants - constant parameters
1508475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1509475e0ac9SMatthew G. Knepley 
1510475e0ac9SMatthew G. Knepley   Level: intermediate
1511475e0ac9SMatthew G. Knepley 
1512475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1513475e0ac9SMatthew G. Knepley @*/
1514475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1515475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1516475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1517475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
151897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1519475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1520475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1521475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
152297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1523475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1524475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1525475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
152697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1527475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1528475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1529475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
153097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1531475e0ac9SMatthew G. Knepley {
1532475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1533475e0ac9SMatthew G. Knepley 
1534475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1535475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1536475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1537475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1538475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1539475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1540475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1541475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1542475e0ac9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1543475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+0] = g0;
1544475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+1] = g1;
1545475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+2] = g2;
1546475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+3] = g3;
1547475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1548475e0ac9SMatthew G. Knepley }
1549475e0ac9SMatthew G. Knepley 
1550b7e05686SMatthew G. Knepley /*@C
1551b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1552b7e05686SMatthew G. Knepley 
1553b7e05686SMatthew G. Knepley   Not collective
1554b7e05686SMatthew G. Knepley 
1555b7e05686SMatthew G. Knepley   Input Parameter:
1556b7e05686SMatthew G. Knepley . prob - The PetscDS
1557b7e05686SMatthew G. Knepley 
1558b7e05686SMatthew G. Knepley   Output Parameter:
1559b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1560b7e05686SMatthew G. Knepley 
1561b7e05686SMatthew G. Knepley   Level: intermediate
1562b7e05686SMatthew G. Knepley 
1563b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1564b7e05686SMatthew G. Knepley @*/
1565b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac)
1566b7e05686SMatthew G. Knepley {
1567b7e05686SMatthew G. Knepley   PetscInt f, g, h;
1568b7e05686SMatthew G. Knepley 
1569b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1570b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1571b7e05686SMatthew G. Knepley   *hasDynJac = PETSC_FALSE;
1572b7e05686SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1573b7e05686SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1574b7e05686SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1575b7e05686SMatthew G. Knepley         if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE;
1576b7e05686SMatthew G. Knepley       }
1577b7e05686SMatthew G. Knepley     }
1578b7e05686SMatthew G. Knepley   }
1579b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1580b7e05686SMatthew G. Knepley }
1581b7e05686SMatthew G. Knepley 
1582b7e05686SMatthew G. Knepley /*@C
1583b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1584b7e05686SMatthew G. Knepley 
1585b7e05686SMatthew G. Knepley   Not collective
1586b7e05686SMatthew G. Knepley 
1587b7e05686SMatthew G. Knepley   Input Parameters:
1588b7e05686SMatthew G. Knepley + prob - The PetscDS
1589b7e05686SMatthew G. Knepley . f    - The test field number
1590b7e05686SMatthew G. Knepley - g    - The field number
1591b7e05686SMatthew G. Knepley 
1592b7e05686SMatthew G. Knepley   Output Parameters:
1593b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1594b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1595b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1596b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1597b7e05686SMatthew G. Knepley 
1598b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1599b7e05686SMatthew G. Knepley 
1600b7e05686SMatthew 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
1601b7e05686SMatthew G. Knepley 
1602b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1603b7e05686SMatthew G. Knepley 
1604b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1605b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1606b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1607b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1608b7e05686SMatthew G. Knepley 
1609b7e05686SMatthew G. Knepley + dim - the spatial dimension
1610b7e05686SMatthew G. Knepley . Nf - the number of fields
1611b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1612b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1613b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1614b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1615b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1616b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1617b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1618b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1619b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1620b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1621b7e05686SMatthew G. Knepley . t - current time
1622b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1623b7e05686SMatthew G. Knepley . x - coordinates of the current point
162497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
162597b6e6e8SMatthew G. Knepley . constants - constant parameters
1626b7e05686SMatthew G. Knepley - g0 - output values at the current point
1627b7e05686SMatthew G. Knepley 
1628b7e05686SMatthew G. Knepley   Level: intermediate
1629b7e05686SMatthew G. Knepley 
1630b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1631b7e05686SMatthew G. Knepley @*/
1632b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1633b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1634b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1635b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
163697b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1637b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1638b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1639b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
164097b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1641b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1642b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1643b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
164497b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1645b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1646b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1647b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
164897b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1649b7e05686SMatthew G. Knepley {
1650b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1651b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1652b7e05686SMatthew 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);
1653b7e05686SMatthew 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);
1654b7e05686SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];}
1655b7e05686SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];}
1656b7e05686SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];}
1657b7e05686SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];}
1658b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1659b7e05686SMatthew G. Knepley }
1660b7e05686SMatthew G. Knepley 
1661b7e05686SMatthew G. Knepley /*@C
1662b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1663b7e05686SMatthew G. Knepley 
1664b7e05686SMatthew G. Knepley   Not collective
1665b7e05686SMatthew G. Knepley 
1666b7e05686SMatthew G. Knepley   Input Parameters:
1667b7e05686SMatthew G. Knepley + prob - The PetscDS
1668b7e05686SMatthew G. Knepley . f    - The test field number
1669b7e05686SMatthew G. Knepley . g    - The field number
1670b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1671b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1672b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1673b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1674b7e05686SMatthew G. Knepley 
1675b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1676b7e05686SMatthew G. Knepley 
1677b7e05686SMatthew 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
1678b7e05686SMatthew G. Knepley 
1679b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1680b7e05686SMatthew G. Knepley 
1681b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1682b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1683b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1684b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1685b7e05686SMatthew G. Knepley 
1686b7e05686SMatthew G. Knepley + dim - the spatial dimension
1687b7e05686SMatthew G. Knepley . Nf - the number of fields
1688b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1689b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1690b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1691b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1692b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1693b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1694b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1695b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1696b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1697b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1698b7e05686SMatthew G. Knepley . t - current time
1699b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1700b7e05686SMatthew G. Knepley . x - coordinates of the current point
170197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
170297b6e6e8SMatthew G. Knepley . constants - constant parameters
1703b7e05686SMatthew G. Knepley - g0 - output values at the current point
1704b7e05686SMatthew G. Knepley 
1705b7e05686SMatthew G. Knepley   Level: intermediate
1706b7e05686SMatthew G. Knepley 
1707b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1708b7e05686SMatthew G. Knepley @*/
1709b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1710b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1711b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1712b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
171397b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1714b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1715b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1716b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
171797b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1718b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1719b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1720b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
172197b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1722b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1723b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1724b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
172597b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1726b7e05686SMatthew G. Knepley {
1727b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1728b7e05686SMatthew G. Knepley 
1729b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1730b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1731b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1732b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1733b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1734b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1735b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1736b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1737b7e05686SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1738b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+0] = g0;
1739b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+1] = g1;
1740b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+2] = g2;
1741b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+3] = g3;
1742b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1743b7e05686SMatthew G. Knepley }
1744b7e05686SMatthew G. Knepley 
17450c2f2876SMatthew G. Knepley /*@C
17460c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
17470c2f2876SMatthew G. Knepley 
17480c2f2876SMatthew G. Knepley   Not collective
17490c2f2876SMatthew G. Knepley 
17500c2f2876SMatthew G. Knepley   Input Arguments:
17510c2f2876SMatthew G. Knepley + prob - The PetscDS object
17520c2f2876SMatthew G. Knepley - f    - The field number
17530c2f2876SMatthew G. Knepley 
17540c2f2876SMatthew G. Knepley   Output Argument:
17550c2f2876SMatthew G. Knepley . r    - Riemann solver
17560c2f2876SMatthew G. Knepley 
17570c2f2876SMatthew G. Knepley   Calling sequence for r:
17580c2f2876SMatthew G. Knepley 
17595db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
17600c2f2876SMatthew G. Knepley 
17615db36cf9SMatthew G. Knepley + dim  - The spatial dimension
17625db36cf9SMatthew G. Knepley . Nf   - The number of fields
17635db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
17640c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
17650c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
17660c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
17670c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
176897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
176997b6e6e8SMatthew G. Knepley . constants - constant parameters
17700c2f2876SMatthew G. Knepley - ctx  - optional user context
17710c2f2876SMatthew G. Knepley 
17720c2f2876SMatthew G. Knepley   Level: intermediate
17730c2f2876SMatthew G. Knepley 
17740c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
17750c2f2876SMatthew G. Knepley @*/
17760c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f,
177797b6e6e8SMatthew 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))
17780c2f2876SMatthew G. Knepley {
17790c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17800c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
17810c2f2876SMatthew 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);
17820c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
17830c2f2876SMatthew G. Knepley   *r = prob->r[f];
17840c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17850c2f2876SMatthew G. Knepley }
17860c2f2876SMatthew G. Knepley 
17870c2f2876SMatthew G. Knepley /*@C
17880c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
17890c2f2876SMatthew G. Knepley 
17900c2f2876SMatthew G. Knepley   Not collective
17910c2f2876SMatthew G. Knepley 
17920c2f2876SMatthew G. Knepley   Input Arguments:
17930c2f2876SMatthew G. Knepley + prob - The PetscDS object
17940c2f2876SMatthew G. Knepley . f    - The field number
17950c2f2876SMatthew G. Knepley - r    - Riemann solver
17960c2f2876SMatthew G. Knepley 
17970c2f2876SMatthew G. Knepley   Calling sequence for r:
17980c2f2876SMatthew G. Knepley 
17995db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
18000c2f2876SMatthew G. Knepley 
18015db36cf9SMatthew G. Knepley + dim  - The spatial dimension
18025db36cf9SMatthew G. Knepley . Nf   - The number of fields
18035db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
18040c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
18050c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
18060c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
18070c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
180897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
180997b6e6e8SMatthew G. Knepley . constants - constant parameters
18100c2f2876SMatthew G. Knepley - ctx  - optional user context
18110c2f2876SMatthew G. Knepley 
18120c2f2876SMatthew G. Knepley   Level: intermediate
18130c2f2876SMatthew G. Knepley 
18140c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
18150c2f2876SMatthew G. Knepley @*/
18160c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f,
181797b6e6e8SMatthew 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))
18180c2f2876SMatthew G. Knepley {
18190c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
18200c2f2876SMatthew G. Knepley 
18210c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18220c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1823de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
18240c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
18250c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
18260c2f2876SMatthew G. Knepley   prob->r[f] = r;
18270c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18280c2f2876SMatthew G. Knepley }
18290c2f2876SMatthew G. Knepley 
183032d2bbc9SMatthew G. Knepley /*@C
183132d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
183232d2bbc9SMatthew G. Knepley 
183332d2bbc9SMatthew G. Knepley   Not collective
183432d2bbc9SMatthew G. Knepley 
183532d2bbc9SMatthew G. Knepley   Input Parameters:
183632d2bbc9SMatthew G. Knepley + prob - The PetscDS
183732d2bbc9SMatthew G. Knepley - f    - The field number
183832d2bbc9SMatthew G. Knepley 
183932d2bbc9SMatthew G. Knepley   Output Parameters:
184032d2bbc9SMatthew G. Knepley + update - update function
184132d2bbc9SMatthew G. Knepley 
184232d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
184332d2bbc9SMatthew G. Knepley 
184432d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
184532d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
184632d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
184732d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
184832d2bbc9SMatthew G. Knepley 
184932d2bbc9SMatthew G. Knepley + dim - the spatial dimension
185032d2bbc9SMatthew G. Knepley . Nf - the number of fields
185132d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
185232d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
185332d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
185432d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
185532d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
185632d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
185732d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
185832d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
185932d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
186032d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
186132d2bbc9SMatthew G. Knepley . t - current time
186232d2bbc9SMatthew G. Knepley . x - coordinates of the current point
186332d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
186432d2bbc9SMatthew G. Knepley 
186532d2bbc9SMatthew G. Knepley   Level: intermediate
186632d2bbc9SMatthew G. Knepley 
186732d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
186832d2bbc9SMatthew G. Knepley @*/
186932d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f,
187032d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
187132d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
187232d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
18733fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
187432d2bbc9SMatthew G. Knepley {
187532d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
187632d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
187732d2bbc9SMatthew 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);
187832d2bbc9SMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = prob->update[f];}
187932d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
188032d2bbc9SMatthew G. Knepley }
188132d2bbc9SMatthew G. Knepley 
188232d2bbc9SMatthew G. Knepley /*@C
18833fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
188432d2bbc9SMatthew G. Knepley 
188532d2bbc9SMatthew G. Knepley   Not collective
188632d2bbc9SMatthew G. Knepley 
188732d2bbc9SMatthew G. Knepley   Input Parameters:
188832d2bbc9SMatthew G. Knepley + prob   - The PetscDS
188932d2bbc9SMatthew G. Knepley . f      - The field number
189032d2bbc9SMatthew G. Knepley - update - update function
189132d2bbc9SMatthew G. Knepley 
189232d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
189332d2bbc9SMatthew G. Knepley 
189432d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
189532d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
189632d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
189732d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
189832d2bbc9SMatthew G. Knepley 
189932d2bbc9SMatthew G. Knepley + dim - the spatial dimension
190032d2bbc9SMatthew G. Knepley . Nf - the number of fields
190132d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
190232d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
190332d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
190432d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
190532d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
190632d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
190732d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
190832d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
190932d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
191032d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
191132d2bbc9SMatthew G. Knepley . t - current time
191232d2bbc9SMatthew G. Knepley . x - coordinates of the current point
191332d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
191432d2bbc9SMatthew G. Knepley 
191532d2bbc9SMatthew G. Knepley   Level: intermediate
191632d2bbc9SMatthew G. Knepley 
191732d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
191832d2bbc9SMatthew G. Knepley @*/
191932d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f,
192032d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
192132d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
192232d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19233fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
192432d2bbc9SMatthew G. Knepley {
192532d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
192632d2bbc9SMatthew G. Knepley 
192732d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
192832d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
192932d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
193032d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
193132d2bbc9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
193232d2bbc9SMatthew G. Knepley   prob->update[f] = update;
193332d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
193432d2bbc9SMatthew G. Knepley }
193532d2bbc9SMatthew G. Knepley 
19360c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx)
19370c2f2876SMatthew G. Knepley {
19380c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19390c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19400c2f2876SMatthew 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);
19410c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
19420c2f2876SMatthew G. Knepley   *ctx = prob->ctx[f];
19430c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19440c2f2876SMatthew G. Knepley }
19450c2f2876SMatthew G. Knepley 
19460c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx)
19470c2f2876SMatthew G. Knepley {
19480c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
19490c2f2876SMatthew G. Knepley 
19500c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19510c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19520c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19530c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
19540c2f2876SMatthew G. Knepley   prob->ctx[f] = ctx;
19550c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19560c2f2876SMatthew G. Knepley }
19570c2f2876SMatthew G. Knepley 
1958194d53e6SMatthew G. Knepley /*@C
1959194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
1960194d53e6SMatthew G. Knepley 
1961194d53e6SMatthew G. Knepley   Not collective
1962194d53e6SMatthew G. Knepley 
1963194d53e6SMatthew G. Knepley   Input Parameters:
1964194d53e6SMatthew G. Knepley + prob - The PetscDS
1965194d53e6SMatthew G. Knepley - f    - The test field number
1966194d53e6SMatthew G. Knepley 
1967194d53e6SMatthew G. Knepley   Output Parameters:
1968194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
1969194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1970194d53e6SMatthew G. Knepley 
1971194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1972194d53e6SMatthew G. Knepley 
1973194d53e6SMatthew 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
1974194d53e6SMatthew G. Knepley 
1975194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1976194d53e6SMatthew G. Knepley 
197730b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1978194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1979194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
198030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1981194d53e6SMatthew G. Knepley 
1982194d53e6SMatthew G. Knepley + dim - the spatial dimension
1983194d53e6SMatthew G. Knepley . Nf - the number of fields
1984194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1985194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1986194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1987194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1988194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1989194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1990194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1991194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1992194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1993194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1994194d53e6SMatthew G. Knepley . t - current time
1995194d53e6SMatthew G. Knepley . x - coordinates of the current point
1996194d53e6SMatthew G. Knepley . n - unit normal at the current point
199797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
199897b6e6e8SMatthew G. Knepley . constants - constant parameters
1999194d53e6SMatthew G. Knepley - f0 - output values at the current point
2000194d53e6SMatthew G. Knepley 
2001194d53e6SMatthew G. Knepley   Level: intermediate
2002194d53e6SMatthew G. Knepley 
2003194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
2004194d53e6SMatthew G. Knepley @*/
20052764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f,
200630b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2007194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2008194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
200997b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
201030b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2011194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2012194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
201397b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
20142764a2aaSMatthew G. Knepley {
20152764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20162764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20172764a2aaSMatthew 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);
20182764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];}
20192764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];}
20202764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20212764a2aaSMatthew G. Knepley }
20222764a2aaSMatthew G. Knepley 
2023194d53e6SMatthew G. Knepley /*@C
2024194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2025194d53e6SMatthew G. Knepley 
2026194d53e6SMatthew G. Knepley   Not collective
2027194d53e6SMatthew G. Knepley 
2028194d53e6SMatthew G. Knepley   Input Parameters:
2029194d53e6SMatthew G. Knepley + prob - The PetscDS
2030194d53e6SMatthew G. Knepley . f    - The test field number
2031194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2032194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2033194d53e6SMatthew G. Knepley 
2034194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2035194d53e6SMatthew G. Knepley 
2036194d53e6SMatthew 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
2037194d53e6SMatthew G. Knepley 
2038194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2039194d53e6SMatthew G. Knepley 
204030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2041194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2042194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
204330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2044194d53e6SMatthew G. Knepley 
2045194d53e6SMatthew G. Knepley + dim - the spatial dimension
2046194d53e6SMatthew G. Knepley . Nf - the number of fields
2047194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2048194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2049194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2050194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2051194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2052194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2053194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2054194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2055194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2056194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2057194d53e6SMatthew G. Knepley . t - current time
2058194d53e6SMatthew G. Knepley . x - coordinates of the current point
2059194d53e6SMatthew G. Knepley . n - unit normal at the current point
206097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
206197b6e6e8SMatthew G. Knepley . constants - constant parameters
2062194d53e6SMatthew G. Knepley - f0 - output values at the current point
2063194d53e6SMatthew G. Knepley 
2064194d53e6SMatthew G. Knepley   Level: intermediate
2065194d53e6SMatthew G. Knepley 
2066194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
2067194d53e6SMatthew G. Knepley @*/
20682764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f,
206930b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2070194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2071194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
207297b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
207330b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2074194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2075194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
207697b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
20772764a2aaSMatthew G. Knepley {
20782764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
20792764a2aaSMatthew G. Knepley 
20802764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20812764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20822764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
20832764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
20842764a2aaSMatthew G. Knepley   if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;}
20852764a2aaSMatthew G. Knepley   if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;}
20862764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20872764a2aaSMatthew G. Knepley }
20882764a2aaSMatthew G. Knepley 
2089194d53e6SMatthew G. Knepley /*@C
2090194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2091194d53e6SMatthew G. Knepley 
2092194d53e6SMatthew G. Knepley   Not collective
2093194d53e6SMatthew G. Knepley 
2094194d53e6SMatthew G. Knepley   Input Parameters:
2095194d53e6SMatthew G. Knepley + prob - The PetscDS
2096194d53e6SMatthew G. Knepley . f    - The test field number
2097194d53e6SMatthew G. Knepley - g    - The field number
2098194d53e6SMatthew G. Knepley 
2099194d53e6SMatthew G. Knepley   Output Parameters:
2100194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2101194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2102194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2103194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2104194d53e6SMatthew G. Knepley 
2105194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2106194d53e6SMatthew G. Knepley 
2107194d53e6SMatthew 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
2108194d53e6SMatthew G. Knepley 
2109194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2110194d53e6SMatthew G. Knepley 
211130b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2112194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2113194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
211430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2115194d53e6SMatthew G. Knepley 
2116194d53e6SMatthew G. Knepley + dim - the spatial dimension
2117194d53e6SMatthew G. Knepley . Nf - the number of fields
2118194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2119194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2120194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2121194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2122194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2123194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2124194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2125194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2126194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2127194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2128194d53e6SMatthew G. Knepley . t - current time
21292aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2130194d53e6SMatthew G. Knepley . x - coordinates of the current point
2131194d53e6SMatthew G. Knepley . n - normal at the current point
213297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
213397b6e6e8SMatthew G. Knepley . constants - constant parameters
2134194d53e6SMatthew G. Knepley - g0 - output values at the current point
2135194d53e6SMatthew G. Knepley 
2136194d53e6SMatthew G. Knepley   Level: intermediate
2137194d53e6SMatthew G. Knepley 
2138194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2139194d53e6SMatthew G. Knepley @*/
21402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
214130b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2142194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2143194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
214497b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
214530b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2146194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2147194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
214897b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
214930b9ff8bSMatthew G. Knepley                                     void (**g2)(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, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
215330b9ff8bSMatthew G. Knepley                                     void (**g3)(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, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
21572764a2aaSMatthew G. Knepley {
21582764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21592764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21602764a2aaSMatthew 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);
21612764a2aaSMatthew 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);
21622764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];}
21632764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];}
21642764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];}
21652764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];}
21662764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21672764a2aaSMatthew G. Knepley }
21682764a2aaSMatthew G. Knepley 
2169194d53e6SMatthew G. Knepley /*@C
2170194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2171194d53e6SMatthew G. Knepley 
2172194d53e6SMatthew G. Knepley   Not collective
2173194d53e6SMatthew G. Knepley 
2174194d53e6SMatthew G. Knepley   Input Parameters:
2175194d53e6SMatthew G. Knepley + prob - The PetscDS
2176194d53e6SMatthew G. Knepley . f    - The test field number
2177194d53e6SMatthew G. Knepley . g    - The field number
2178194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2179194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2180194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2181194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2182194d53e6SMatthew G. Knepley 
2183194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2184194d53e6SMatthew G. Knepley 
2185194d53e6SMatthew 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
2186194d53e6SMatthew G. Knepley 
2187194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2188194d53e6SMatthew G. Knepley 
218930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2190194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2191194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
219230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2193194d53e6SMatthew G. Knepley 
2194194d53e6SMatthew G. Knepley + dim - the spatial dimension
2195194d53e6SMatthew G. Knepley . Nf - the number of fields
2196194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2197194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2198194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2199194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2200194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2201194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2202194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2203194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2204194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2205194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2206194d53e6SMatthew G. Knepley . t - current time
22072aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2208194d53e6SMatthew G. Knepley . x - coordinates of the current point
2209194d53e6SMatthew G. Knepley . n - normal at the current point
221097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
221197b6e6e8SMatthew G. Knepley . constants - constant parameters
2212194d53e6SMatthew G. Knepley - g0 - output values at the current point
2213194d53e6SMatthew G. Knepley 
2214194d53e6SMatthew G. Knepley   Level: intermediate
2215194d53e6SMatthew G. Knepley 
2216194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2217194d53e6SMatthew G. Knepley @*/
22182764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
221930b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2220194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2221194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
222297b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
222330b9ff8bSMatthew G. Knepley                                     void (*g1)(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[],
222697b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
222730b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2228194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2229194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
223097b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
223130b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2232194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2233194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
223497b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
22352764a2aaSMatthew G. Knepley {
22362764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
22372764a2aaSMatthew G. Knepley 
22382764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22392764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22402764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
22412764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
22422764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
22432764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
22442764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
22452764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
22462764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
22472764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+0] = g0;
22482764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+1] = g1;
22492764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+2] = g2;
22502764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+3] = g3;
22512764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22522764a2aaSMatthew G. Knepley }
22532764a2aaSMatthew G. Knepley 
22540d3e9b51SMatthew G. Knepley /*@C
2255c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2256c371a6d1SMatthew G. Knepley 
2257c371a6d1SMatthew G. Knepley   Not collective
2258c371a6d1SMatthew G. Knepley 
2259c371a6d1SMatthew G. Knepley   Input Parameters:
2260c371a6d1SMatthew G. Knepley + prob - The PetscDS
2261c371a6d1SMatthew G. Knepley - f    - The test field number
2262c371a6d1SMatthew G. Knepley 
2263c371a6d1SMatthew G. Knepley   Output Parameter:
2264c371a6d1SMatthew G. Knepley . exactSol - exact solution for the test field
2265c371a6d1SMatthew G. Knepley 
2266c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2267c371a6d1SMatthew G. Knepley 
2268c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2269c371a6d1SMatthew G. Knepley 
2270c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2271c371a6d1SMatthew G. Knepley . t - current time
2272c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2273c371a6d1SMatthew G. Knepley . Nc - the number of field components
2274c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2275c371a6d1SMatthew G. Knepley - ctx - a user context
2276c371a6d1SMatthew G. Knepley 
2277c371a6d1SMatthew G. Knepley   Level: intermediate
2278c371a6d1SMatthew G. Knepley 
2279c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution()
2280c371a6d1SMatthew G. Knepley @*/
2281c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2282c371a6d1SMatthew G. Knepley {
2283c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2284c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2285c371a6d1SMatthew 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);
2286c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
2287c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2288c371a6d1SMatthew G. Knepley }
2289c371a6d1SMatthew G. Knepley 
2290c371a6d1SMatthew G. Knepley /*@C
2291c371a6d1SMatthew G. Knepley   PetscDSSetExactSolution - Get the pointwise exact solution function for a given test field
2292c371a6d1SMatthew G. Knepley 
2293c371a6d1SMatthew G. Knepley   Not collective
2294c371a6d1SMatthew G. Knepley 
2295c371a6d1SMatthew G. Knepley   Input Parameters:
2296c371a6d1SMatthew G. Knepley + prob - The PetscDS
2297c371a6d1SMatthew G. Knepley . f    - The test field number
2298c371a6d1SMatthew G. Knepley - sol  - solution function for the test fields
2299c371a6d1SMatthew G. Knepley 
2300c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2301c371a6d1SMatthew G. Knepley 
2302c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2303c371a6d1SMatthew G. Knepley 
2304c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2305c371a6d1SMatthew G. Knepley . t - current time
2306c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2307c371a6d1SMatthew G. Knepley . Nc - the number of field components
2308c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2309c371a6d1SMatthew G. Knepley - ctx - a user context
2310c371a6d1SMatthew G. Knepley 
2311c371a6d1SMatthew G. Knepley   Level: intermediate
2312c371a6d1SMatthew G. Knepley 
2313c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2314c371a6d1SMatthew G. Knepley @*/
2315c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2316c371a6d1SMatthew G. Knepley {
2317c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2318c371a6d1SMatthew G. Knepley 
2319c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2320c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2321c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2322c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2323c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
2324c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2325c371a6d1SMatthew G. Knepley }
2326c371a6d1SMatthew G. Knepley 
23275638fd0eSMatthew G. Knepley /*@C
232897b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
232997b6e6e8SMatthew G. Knepley 
233097b6e6e8SMatthew G. Knepley   Not collective
233197b6e6e8SMatthew G. Knepley 
233297b6e6e8SMatthew G. Knepley   Input Parameter:
233397b6e6e8SMatthew G. Knepley . prob - The PetscDS object
233497b6e6e8SMatthew G. Knepley 
233597b6e6e8SMatthew G. Knepley   Output Parameters:
233697b6e6e8SMatthew G. Knepley + numConstants - The number of constants
233797b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
233897b6e6e8SMatthew G. Knepley 
233997b6e6e8SMatthew G. Knepley   Level: intermediate
234097b6e6e8SMatthew G. Knepley 
234197b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
234297b6e6e8SMatthew G. Knepley @*/
234397b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
234497b6e6e8SMatthew G. Knepley {
234597b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
234697b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
234797b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
234897b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
234997b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
235097b6e6e8SMatthew G. Knepley }
235197b6e6e8SMatthew G. Knepley 
23520d3e9b51SMatthew G. Knepley /*@C
235397b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
235497b6e6e8SMatthew G. Knepley 
235597b6e6e8SMatthew G. Knepley   Not collective
235697b6e6e8SMatthew G. Knepley 
235797b6e6e8SMatthew G. Knepley   Input Parameters:
235897b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
235997b6e6e8SMatthew G. Knepley . numConstants - The number of constants
236097b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
236197b6e6e8SMatthew G. Knepley 
236297b6e6e8SMatthew G. Knepley   Level: intermediate
236397b6e6e8SMatthew G. Knepley 
236497b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
236597b6e6e8SMatthew G. Knepley @*/
236697b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
236797b6e6e8SMatthew G. Knepley {
236897b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
236997b6e6e8SMatthew G. Knepley 
237097b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
237197b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
237297b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
237397b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
237497b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
237597b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
237697b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
237720be0f5bSMatthew G. Knepley     } else {
237820be0f5bSMatthew G. Knepley       prob->constants = NULL;
237920be0f5bSMatthew G. Knepley     }
238020be0f5bSMatthew G. Knepley   }
238120be0f5bSMatthew G. Knepley   if (prob->numConstants) {
238220be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
238397b6e6e8SMatthew G. Knepley     ierr = PetscMemcpy(prob->constants, constants, prob->numConstants * sizeof(PetscScalar));CHKERRQ(ierr);
238497b6e6e8SMatthew G. Knepley   }
238597b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
238697b6e6e8SMatthew G. Knepley }
238797b6e6e8SMatthew G. Knepley 
23884cd1e086SMatthew G. Knepley /*@
23894cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
23904cd1e086SMatthew G. Knepley 
23914cd1e086SMatthew G. Knepley   Not collective
23924cd1e086SMatthew G. Knepley 
23934cd1e086SMatthew G. Knepley   Input Parameters:
23944cd1e086SMatthew G. Knepley + prob - The PetscDS object
23954cd1e086SMatthew G. Knepley - disc - The discretization object
23964cd1e086SMatthew G. Knepley 
23974cd1e086SMatthew G. Knepley   Output Parameter:
23984cd1e086SMatthew G. Knepley . f - The field number
23994cd1e086SMatthew G. Knepley 
24004cd1e086SMatthew G. Knepley   Level: beginner
24014cd1e086SMatthew G. Knepley 
2402f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
24034cd1e086SMatthew G. Knepley @*/
24044cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
24054cd1e086SMatthew G. Knepley {
24064cd1e086SMatthew G. Knepley   PetscInt g;
24074cd1e086SMatthew G. Knepley 
24084cd1e086SMatthew G. Knepley   PetscFunctionBegin;
24094cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24104cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
24114cd1e086SMatthew G. Knepley   *f = -1;
24124cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
24134cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
24144cd1e086SMatthew G. Knepley   *f = g;
24154cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
24164cd1e086SMatthew G. Knepley }
24174cd1e086SMatthew G. Knepley 
24184cd1e086SMatthew G. Knepley /*@
24194cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
24204cd1e086SMatthew G. Knepley 
24214cd1e086SMatthew G. Knepley   Not collective
24224cd1e086SMatthew G. Knepley 
24234cd1e086SMatthew G. Knepley   Input Parameters:
24244cd1e086SMatthew G. Knepley + prob - The PetscDS object
24254cd1e086SMatthew G. Knepley - f - The field number
24264cd1e086SMatthew G. Knepley 
24274cd1e086SMatthew G. Knepley   Output Parameter:
24284cd1e086SMatthew G. Knepley . size - The size
24294cd1e086SMatthew G. Knepley 
24304cd1e086SMatthew G. Knepley   Level: beginner
24314cd1e086SMatthew G. Knepley 
2432f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
24334cd1e086SMatthew G. Knepley @*/
24344cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
24354cd1e086SMatthew G. Knepley {
24362166fd64SMatthew G. Knepley   PetscErrorCode ierr;
24372166fd64SMatthew G. Knepley 
24384cd1e086SMatthew G. Knepley   PetscFunctionBegin;
24394cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24404cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
24414cd1e086SMatthew 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);
24422166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2443d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
24444cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
24454cd1e086SMatthew G. Knepley }
24464cd1e086SMatthew G. Knepley 
2447bc4ae4beSMatthew G. Knepley /*@
2448bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2449bc4ae4beSMatthew G. Knepley 
2450bc4ae4beSMatthew G. Knepley   Not collective
2451bc4ae4beSMatthew G. Knepley 
2452bc4ae4beSMatthew G. Knepley   Input Parameters:
2453bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2454bc4ae4beSMatthew G. Knepley - f - The field number
2455bc4ae4beSMatthew G. Knepley 
2456bc4ae4beSMatthew G. Knepley   Output Parameter:
2457bc4ae4beSMatthew G. Knepley . off - The offset
2458bc4ae4beSMatthew G. Knepley 
2459bc4ae4beSMatthew G. Knepley   Level: beginner
2460bc4ae4beSMatthew G. Knepley 
2461f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2462bc4ae4beSMatthew G. Knepley @*/
24632764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
24642764a2aaSMatthew G. Knepley {
24654cd1e086SMatthew G. Knepley   PetscInt       size, g;
24662764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24672764a2aaSMatthew G. Knepley 
24682764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24692764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24702764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
24712764a2aaSMatthew 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);
24722764a2aaSMatthew G. Knepley   *off = 0;
24732764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
24744cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
24754cd1e086SMatthew G. Knepley     *off += size;
24762764a2aaSMatthew G. Knepley   }
24772764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
24782764a2aaSMatthew G. Knepley }
24792764a2aaSMatthew G. Knepley 
2480bc4ae4beSMatthew G. Knepley /*@
248147e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2482bc4ae4beSMatthew G. Knepley 
2483bc4ae4beSMatthew G. Knepley   Not collective
2484bc4ae4beSMatthew G. Knepley 
248547e57110SSander Arens   Input Parameter:
248647e57110SSander Arens . prob - The PetscDS object
2487bc4ae4beSMatthew G. Knepley 
2488bc4ae4beSMatthew G. Knepley   Output Parameter:
248947e57110SSander Arens . dimensions - The number of dimensions
2490bc4ae4beSMatthew G. Knepley 
2491bc4ae4beSMatthew G. Knepley   Level: beginner
2492bc4ae4beSMatthew G. Knepley 
249347e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2494bc4ae4beSMatthew G. Knepley @*/
249547e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
24962764a2aaSMatthew G. Knepley {
24972764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24982764a2aaSMatthew G. Knepley 
24992764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25002764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
250147e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
250247e57110SSander Arens   PetscValidPointer(dimensions, 2);
250347e57110SSander Arens   *dimensions = prob->Nb;
250447e57110SSander Arens   PetscFunctionReturn(0);
25056ce16762SMatthew G. Knepley }
250647e57110SSander Arens 
250747e57110SSander Arens /*@
250847e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
250947e57110SSander Arens 
251047e57110SSander Arens   Not collective
251147e57110SSander Arens 
251247e57110SSander Arens   Input Parameter:
251347e57110SSander Arens . prob - The PetscDS object
251447e57110SSander Arens 
251547e57110SSander Arens   Output Parameter:
251647e57110SSander Arens . components - The number of components
251747e57110SSander Arens 
251847e57110SSander Arens   Level: beginner
251947e57110SSander Arens 
252047e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
252147e57110SSander Arens @*/
252247e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
252347e57110SSander Arens {
252447e57110SSander Arens   PetscErrorCode ierr;
252547e57110SSander Arens 
252647e57110SSander Arens   PetscFunctionBegin;
252747e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
252847e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
252947e57110SSander Arens   PetscValidPointer(components, 2);
253047e57110SSander Arens   *components = prob->Nc;
25316ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
25326ce16762SMatthew G. Knepley }
25336ce16762SMatthew G. Knepley 
25346ce16762SMatthew G. Knepley /*@
25356ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
25366ce16762SMatthew G. Knepley 
25376ce16762SMatthew G. Knepley   Not collective
25386ce16762SMatthew G. Knepley 
25396ce16762SMatthew G. Knepley   Input Parameters:
25406ce16762SMatthew G. Knepley + prob - The PetscDS object
25416ce16762SMatthew G. Knepley - f - The field number
25426ce16762SMatthew G. Knepley 
25436ce16762SMatthew G. Knepley   Output Parameter:
25446ce16762SMatthew G. Knepley . off - The offset
25456ce16762SMatthew G. Knepley 
25466ce16762SMatthew G. Knepley   Level: beginner
25476ce16762SMatthew G. Knepley 
2548f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
25496ce16762SMatthew G. Knepley @*/
25506ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
25516ce16762SMatthew G. Knepley {
25526ce16762SMatthew G. Knepley   PetscFunctionBegin;
25536ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25546ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
25556ce16762SMatthew 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);
255647e57110SSander Arens   *off = prob->off[f];
25572764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25582764a2aaSMatthew G. Knepley }
25592764a2aaSMatthew G. Knepley 
2560194d53e6SMatthew G. Knepley /*@
2561194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2562194d53e6SMatthew G. Knepley 
2563194d53e6SMatthew G. Knepley   Not collective
2564194d53e6SMatthew G. Knepley 
2565194d53e6SMatthew G. Knepley   Input Parameter:
2566194d53e6SMatthew G. Knepley . prob - The PetscDS object
2567194d53e6SMatthew G. Knepley 
2568194d53e6SMatthew G. Knepley   Output Parameter:
2569194d53e6SMatthew G. Knepley . offsets - The offsets
2570194d53e6SMatthew G. Knepley 
2571194d53e6SMatthew G. Knepley   Level: beginner
2572194d53e6SMatthew G. Knepley 
2573f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2574194d53e6SMatthew G. Knepley @*/
2575194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2576194d53e6SMatthew G. Knepley {
2577194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2578194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2579194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2580194d53e6SMatthew G. Knepley   *offsets = prob->off;
2581194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2582194d53e6SMatthew G. Knepley }
2583194d53e6SMatthew G. Knepley 
2584194d53e6SMatthew G. Knepley /*@
2585194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2586194d53e6SMatthew G. Knepley 
2587194d53e6SMatthew G. Knepley   Not collective
2588194d53e6SMatthew G. Knepley 
2589194d53e6SMatthew G. Knepley   Input Parameter:
2590194d53e6SMatthew G. Knepley . prob - The PetscDS object
2591194d53e6SMatthew G. Knepley 
2592194d53e6SMatthew G. Knepley   Output Parameter:
2593194d53e6SMatthew G. Knepley . offsets - The offsets
2594194d53e6SMatthew G. Knepley 
2595194d53e6SMatthew G. Knepley   Level: beginner
2596194d53e6SMatthew G. Knepley 
2597f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2598194d53e6SMatthew G. Knepley @*/
2599194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2600194d53e6SMatthew G. Knepley {
2601194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2602194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2603194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2604194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
2605194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2606194d53e6SMatthew G. Knepley }
2607194d53e6SMatthew G. Knepley 
260868c9edb9SMatthew G. Knepley /*@C
260968c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
261068c9edb9SMatthew G. Knepley 
261168c9edb9SMatthew G. Knepley   Not collective
261268c9edb9SMatthew G. Knepley 
261368c9edb9SMatthew G. Knepley   Input Parameter:
261468c9edb9SMatthew G. Knepley . prob - The PetscDS object
261568c9edb9SMatthew G. Knepley 
261668c9edb9SMatthew G. Knepley   Output Parameters:
261768c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
261868c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
261968c9edb9SMatthew G. Knepley 
262068c9edb9SMatthew G. Knepley   Level: intermediate
262168c9edb9SMatthew G. Knepley 
2622f744cafaSSander Arens .seealso: PetscDSCreate()
262368c9edb9SMatthew G. Knepley @*/
26242764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
26252764a2aaSMatthew G. Knepley {
26262764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
26272764a2aaSMatthew G. Knepley 
26282764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26292764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26302764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
26312764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basis;}
26322764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;}
26332764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26342764a2aaSMatthew G. Knepley }
26352764a2aaSMatthew G. Knepley 
263668c9edb9SMatthew G. Knepley /*@C
26374d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
263868c9edb9SMatthew G. Knepley 
263968c9edb9SMatthew G. Knepley   Not collective
264068c9edb9SMatthew G. Knepley 
264168c9edb9SMatthew G. Knepley   Input Parameter:
264268c9edb9SMatthew G. Knepley . prob - The PetscDS object
264368c9edb9SMatthew G. Knepley 
264468c9edb9SMatthew G. Knepley   Output Parameters:
26454d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points
26464d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points
264768c9edb9SMatthew G. Knepley 
264868c9edb9SMatthew G. Knepley   Level: intermediate
264968c9edb9SMatthew G. Knepley 
265068c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
265168c9edb9SMatthew G. Knepley @*/
26524d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
26532764a2aaSMatthew G. Knepley {
26542764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
26552764a2aaSMatthew G. Knepley 
26562764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26572764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26582764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
26594d0b9603SSander Arens   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basisFace;}
26604d0b9603SSander Arens   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;}
26612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26622764a2aaSMatthew G. Knepley }
26632764a2aaSMatthew G. Knepley 
26642764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
26652764a2aaSMatthew G. Knepley {
26662764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
26672764a2aaSMatthew G. Knepley 
26682764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26692764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26702764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
26712764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
26722764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
26732764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
26742764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26752764a2aaSMatthew G. Knepley }
26762764a2aaSMatthew G. Knepley 
26772764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
26782764a2aaSMatthew G. Knepley {
26792764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
26802764a2aaSMatthew G. Knepley 
26812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26822764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26832764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
26842764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
26852764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
26862764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
26872764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
26882764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
26892764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
26902764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26912764a2aaSMatthew G. Knepley }
26922764a2aaSMatthew G. Knepley 
26932764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer)
26942764a2aaSMatthew G. Knepley {
26952764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
26962764a2aaSMatthew G. Knepley 
26972764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26982764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26992764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
27002764a2aaSMatthew G. Knepley   if (x)           {PetscValidPointer(x, 2);           *x           = prob->x;}
27012764a2aaSMatthew G. Knepley   if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;}
27022764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
27032764a2aaSMatthew G. Knepley }
27042764a2aaSMatthew G. Knepley 
270558ebd649SToby Isaac /*@C
270658ebd649SToby Isaac   PetscDSAddBoundary - Add a boundary condition to the model
270758ebd649SToby Isaac 
270858ebd649SToby Isaac   Input Parameters:
270958ebd649SToby Isaac + ds          - The PetscDS object
27102d47a189SJulian Andrej . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
271158ebd649SToby Isaac . name        - The BC name
271258ebd649SToby Isaac . labelname   - The label defining constrained points
271358ebd649SToby Isaac . field       - The field to constrain
2714e8ecbf3fSStefano Zampini . numcomps    - The number of constrained field components (0 will constrain all fields)
271558ebd649SToby Isaac . comps       - An array of constrained component numbers
271658ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
271758ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
271858ebd649SToby Isaac . ids         - An array of ids for constrained points
271958ebd649SToby Isaac - ctx         - An optional user context for bcFunc
272058ebd649SToby Isaac 
272158ebd649SToby Isaac   Options Database Keys:
272258ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
272358ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
272458ebd649SToby Isaac 
272558ebd649SToby Isaac   Level: developer
272658ebd649SToby Isaac 
272758ebd649SToby Isaac .seealso: PetscDSGetBoundary()
272858ebd649SToby Isaac @*/
2729a30ec4eaSSatish Balay PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), PetscInt numids, const PetscInt *ids, void *ctx)
273058ebd649SToby Isaac {
273158ebd649SToby Isaac   DSBoundary     b;
273258ebd649SToby Isaac   PetscErrorCode ierr;
273358ebd649SToby Isaac 
273458ebd649SToby Isaac   PetscFunctionBegin;
273558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
273658ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
273758ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
273858ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
273958ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
274058ebd649SToby Isaac   if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
274158ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
274258ebd649SToby Isaac   if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
2743f971fd6bSMatthew G. Knepley   b->type            = type;
274458ebd649SToby Isaac   b->field           = field;
274558ebd649SToby Isaac   b->numcomps        = numcomps;
274658ebd649SToby Isaac   b->func            = bcFunc;
274758ebd649SToby Isaac   b->numids          = numids;
274858ebd649SToby Isaac   b->ctx             = ctx;
274958ebd649SToby Isaac   b->next            = ds->boundary;
275058ebd649SToby Isaac   ds->boundary       = b;
275158ebd649SToby Isaac   PetscFunctionReturn(0);
275258ebd649SToby Isaac }
275358ebd649SToby Isaac 
2754b67eacb3SMatthew G. Knepley /*@C
2755b67eacb3SMatthew G. Knepley   PetscDSUpdateBoundary - Change a boundary condition for the model
2756b67eacb3SMatthew G. Knepley 
2757b67eacb3SMatthew G. Knepley   Input Parameters:
2758b67eacb3SMatthew G. Knepley + ds          - The PetscDS object
2759b67eacb3SMatthew G. Knepley . bd          - The boundary condition number
2760b67eacb3SMatthew G. Knepley . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
2761b67eacb3SMatthew G. Knepley . name        - The BC name
2762b67eacb3SMatthew G. Knepley . labelname   - The label defining constrained points
2763b67eacb3SMatthew G. Knepley . field       - The field to constrain
2764b67eacb3SMatthew G. Knepley . numcomps    - The number of constrained field components
2765b67eacb3SMatthew G. Knepley . comps       - An array of constrained component numbers
2766b67eacb3SMatthew G. Knepley . bcFunc      - A pointwise function giving boundary values
2767b67eacb3SMatthew G. Knepley . numids      - The number of DMLabel ids for constrained points
2768b67eacb3SMatthew G. Knepley . ids         - An array of ids for constrained points
2769b67eacb3SMatthew G. Knepley - ctx         - An optional user context for bcFunc
2770b67eacb3SMatthew G. Knepley 
27719a6efb6aSMatthew G. Knepley   Note: The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from PetscDSGetNumBoundary().
27729a6efb6aSMatthew G. Knepley 
2773b67eacb3SMatthew G. Knepley   Level: developer
2774b67eacb3SMatthew G. Knepley 
27759a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary()
2776b67eacb3SMatthew G. Knepley @*/
2777b67eacb3SMatthew G. Knepley PetscErrorCode PetscDSUpdateBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), PetscInt numids, const PetscInt *ids, void *ctx)
2778b67eacb3SMatthew G. Knepley {
2779b67eacb3SMatthew G. Knepley   DSBoundary     b = ds->boundary;
2780b67eacb3SMatthew G. Knepley   PetscInt       n = 0;
2781b67eacb3SMatthew G. Knepley   PetscErrorCode ierr;
2782b67eacb3SMatthew G. Knepley 
2783b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
2784b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2785b67eacb3SMatthew G. Knepley   while (b) {
2786b67eacb3SMatthew G. Knepley     if (n == bd) break;
2787b67eacb3SMatthew G. Knepley     b = b->next;
2788b67eacb3SMatthew G. Knepley     ++n;
2789b67eacb3SMatthew G. Knepley   }
2790b67eacb3SMatthew G. Knepley   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
2791b67eacb3SMatthew G. Knepley   if (name) {
2792b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->name);CHKERRQ(ierr);
2793b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
2794b67eacb3SMatthew G. Knepley   }
2795b67eacb3SMatthew G. Knepley   if (labelname) {
2796b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2797b67eacb3SMatthew G. Knepley     ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
2798b67eacb3SMatthew G. Knepley   }
2799b67eacb3SMatthew G. Knepley   if (numcomps >= 0 && numcomps != b->numcomps) {
2800b67eacb3SMatthew G. Knepley     b->numcomps = numcomps;
2801b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2802b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
2803b67eacb3SMatthew G. Knepley     if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
2804b67eacb3SMatthew G. Knepley   }
2805b67eacb3SMatthew G. Knepley   if (numids >= 0 && numids != b->numids) {
2806b67eacb3SMatthew G. Knepley     b->numids = numids;
2807b67eacb3SMatthew G. Knepley     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2808b67eacb3SMatthew G. Knepley     ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
2809b67eacb3SMatthew G. Knepley     if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
2810b67eacb3SMatthew G. Knepley   }
2811b67eacb3SMatthew G. Knepley   b->type = type;
2812b67eacb3SMatthew G. Knepley   if (field >= 0) {b->field  = field;}
2813b67eacb3SMatthew G. Knepley   if (bcFunc)     {b->func   = bcFunc;}
2814b67eacb3SMatthew G. Knepley   if (ctx)        {b->ctx    = ctx;}
2815b67eacb3SMatthew G. Knepley   PetscFunctionReturn(0);
2816b67eacb3SMatthew G. Knepley }
2817b67eacb3SMatthew G. Knepley 
281858ebd649SToby Isaac /*@
281958ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
282058ebd649SToby Isaac 
282158ebd649SToby Isaac   Input Parameters:
282258ebd649SToby Isaac . ds - The PetscDS object
282358ebd649SToby Isaac 
282458ebd649SToby Isaac   Output Parameters:
282558ebd649SToby Isaac . numBd - The number of BC
282658ebd649SToby Isaac 
282758ebd649SToby Isaac   Level: intermediate
282858ebd649SToby Isaac 
282958ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
283058ebd649SToby Isaac @*/
283158ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
283258ebd649SToby Isaac {
283358ebd649SToby Isaac   DSBoundary b = ds->boundary;
283458ebd649SToby Isaac 
283558ebd649SToby Isaac   PetscFunctionBegin;
283658ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
283758ebd649SToby Isaac   PetscValidPointer(numBd, 2);
283858ebd649SToby Isaac   *numBd = 0;
283958ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
284058ebd649SToby Isaac   PetscFunctionReturn(0);
284158ebd649SToby Isaac }
284258ebd649SToby Isaac 
284358ebd649SToby Isaac /*@C
28449a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
284558ebd649SToby Isaac 
284658ebd649SToby Isaac   Input Parameters:
284758ebd649SToby Isaac + ds          - The PetscDS object
284858ebd649SToby Isaac - bd          - The BC number
284958ebd649SToby Isaac 
285058ebd649SToby Isaac   Output Parameters:
28512d47a189SJulian Andrej + type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
285258ebd649SToby Isaac . name        - The BC name
285358ebd649SToby Isaac . labelname   - The label defining constrained points
285458ebd649SToby Isaac . field       - The field to constrain
285558ebd649SToby Isaac . numcomps    - The number of constrained field components
285658ebd649SToby Isaac . comps       - An array of constrained component numbers
285758ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
285858ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
285958ebd649SToby Isaac . ids         - An array of ids for constrained points
286058ebd649SToby Isaac - ctx         - An optional user context for bcFunc
286158ebd649SToby Isaac 
286258ebd649SToby Isaac   Options Database Keys:
286358ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
286458ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
286558ebd649SToby Isaac 
286658ebd649SToby Isaac   Level: developer
286758ebd649SToby Isaac 
286858ebd649SToby Isaac .seealso: PetscDSAddBoundary()
286958ebd649SToby Isaac @*/
2870a30ec4eaSSatish Balay PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType *type, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(void), PetscInt *numids, const PetscInt **ids, void **ctx)
287158ebd649SToby Isaac {
287258ebd649SToby Isaac   DSBoundary b    = ds->boundary;
287358ebd649SToby Isaac   PetscInt   n    = 0;
287458ebd649SToby Isaac 
287558ebd649SToby Isaac   PetscFunctionBegin;
287658ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
287758ebd649SToby Isaac   while (b) {
287858ebd649SToby Isaac     if (n == bd) break;
287958ebd649SToby Isaac     b = b->next;
288058ebd649SToby Isaac     ++n;
288158ebd649SToby Isaac   }
288258ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
2883f971fd6bSMatthew G. Knepley   if (type) {
2884f971fd6bSMatthew G. Knepley     PetscValidPointer(type, 3);
2885f971fd6bSMatthew G. Knepley     *type = b->type;
288658ebd649SToby Isaac   }
288758ebd649SToby Isaac   if (name) {
288858ebd649SToby Isaac     PetscValidPointer(name, 4);
288958ebd649SToby Isaac     *name = b->name;
289058ebd649SToby Isaac   }
289158ebd649SToby Isaac   if (labelname) {
289258ebd649SToby Isaac     PetscValidPointer(labelname, 5);
289358ebd649SToby Isaac     *labelname = b->labelname;
289458ebd649SToby Isaac   }
289558ebd649SToby Isaac   if (field) {
289658ebd649SToby Isaac     PetscValidPointer(field, 6);
289758ebd649SToby Isaac     *field = b->field;
289858ebd649SToby Isaac   }
289958ebd649SToby Isaac   if (numcomps) {
290058ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
290158ebd649SToby Isaac     *numcomps = b->numcomps;
290258ebd649SToby Isaac   }
290358ebd649SToby Isaac   if (comps) {
290458ebd649SToby Isaac     PetscValidPointer(comps, 8);
290558ebd649SToby Isaac     *comps = b->comps;
290658ebd649SToby Isaac   }
290758ebd649SToby Isaac   if (func) {
290858ebd649SToby Isaac     PetscValidPointer(func, 9);
290958ebd649SToby Isaac     *func = b->func;
291058ebd649SToby Isaac   }
291158ebd649SToby Isaac   if (numids) {
291258ebd649SToby Isaac     PetscValidPointer(numids, 10);
291358ebd649SToby Isaac     *numids = b->numids;
291458ebd649SToby Isaac   }
291558ebd649SToby Isaac   if (ids) {
291658ebd649SToby Isaac     PetscValidPointer(ids, 11);
291758ebd649SToby Isaac     *ids = b->ids;
291858ebd649SToby Isaac   }
291958ebd649SToby Isaac   if (ctx) {
292058ebd649SToby Isaac     PetscValidPointer(ctx, 12);
292158ebd649SToby Isaac     *ctx = b->ctx;
292258ebd649SToby Isaac   }
292358ebd649SToby Isaac   PetscFunctionReturn(0);
292458ebd649SToby Isaac }
292558ebd649SToby Isaac 
29269252d075SMatthew G. Knepley /*@
29279252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
29289252d075SMatthew G. Knepley 
29299252d075SMatthew G. Knepley   Not collective
29309252d075SMatthew G. Knepley 
29319252d075SMatthew G. Knepley   Input Parameter:
29329252d075SMatthew G. Knepley . prob - The PetscDS object
29339252d075SMatthew G. Knepley 
29349252d075SMatthew G. Knepley   Output Parameter:
29359252d075SMatthew G. Knepley . newprob - The PetscDS copy
29369252d075SMatthew G. Knepley 
29379252d075SMatthew G. Knepley   Level: intermediate
29389252d075SMatthew G. Knepley 
29399252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
29409252d075SMatthew G. Knepley @*/
2941dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB)
2942dff059c6SToby Isaac {
2943dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
2944dff059c6SToby Isaac   PetscErrorCode ierr;
2945dff059c6SToby Isaac 
2946dff059c6SToby Isaac   PetscFunctionBegin;
2947dff059c6SToby Isaac   PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1);
2948dff059c6SToby Isaac   PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2);
2949dff059c6SToby Isaac   if (probA == probB) PetscFunctionReturn(0);
2950dff059c6SToby Isaac   next = probB->boundary;
2951dff059c6SToby Isaac   while (next) {
2952dff059c6SToby Isaac     DSBoundary b = next;
2953dff059c6SToby Isaac 
2954dff059c6SToby Isaac     next = b->next;
2955dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2956dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2957dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
2958dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2959dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
2960dff059c6SToby Isaac   }
2961dff059c6SToby Isaac   lastnext = &(probB->boundary);
2962dff059c6SToby Isaac   for (b = probA->boundary; b; b = b->next) {
2963dff059c6SToby Isaac     DSBoundary bNew;
2964dff059c6SToby Isaac 
2965459726d8SSatish Balay     ierr = PetscNew(&bNew);CHKERRQ(ierr);
2966dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
2967dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
2968dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr);
2969dff059c6SToby Isaac     bNew->numids = b->numids;
2970dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
2971dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr);
2972dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
2973dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
2974dff059c6SToby Isaac     bNew->ctx   = b->ctx;
2975f971fd6bSMatthew G. Knepley     bNew->type  = b->type;
2976dff059c6SToby Isaac     bNew->field = b->field;
2977dff059c6SToby Isaac     bNew->func  = b->func;
2978dff059c6SToby Isaac 
2979dff059c6SToby Isaac     *lastnext = bNew;
2980dff059c6SToby Isaac     lastnext = &(bNew->next);
2981dff059c6SToby Isaac   }
2982dff059c6SToby Isaac   PetscFunctionReturn(0);
2983dff059c6SToby Isaac }
2984dff059c6SToby Isaac 
29859252d075SMatthew G. Knepley /*@C
29869252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
29879252d075SMatthew G. Knepley 
29889252d075SMatthew G. Knepley   Not collective
29899252d075SMatthew G. Knepley 
29909252d075SMatthew G. Knepley   Input Parameter:
29919252d075SMatthew G. Knepley + prob - The PetscDS object
29929252d075SMatthew G. Knepley . numFields - Number of new fields
29939252d075SMatthew G. Knepley - fields - Old field number for each new field
29949252d075SMatthew G. Knepley 
29959252d075SMatthew G. Knepley   Output Parameter:
29969252d075SMatthew G. Knepley . newprob - The PetscDS copy
29979252d075SMatthew G. Knepley 
29989252d075SMatthew G. Knepley   Level: intermediate
29999252d075SMatthew G. Knepley 
30009252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
30019252d075SMatthew G. Knepley @*/
30029252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
30039252d075SMatthew G. Knepley {
30049252d075SMatthew G. Knepley   PetscInt       Nf, Nfn, fn, gn;
30059252d075SMatthew G. Knepley   PetscErrorCode ierr;
30069252d075SMatthew G. Knepley 
30079252d075SMatthew G. Knepley   PetscFunctionBegin;
30089252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30099252d075SMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
30109252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
30119252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
30129252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
30139252d075SMatthew 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);
30149252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
30159252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
30169252d075SMatthew G. Knepley     PetscPointFunc   obj;
30179252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
30189252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
30199252d075SMatthew G. Knepley     PetscRiemannFunc r;
30209252d075SMatthew G. Knepley 
30219252d075SMatthew G. Knepley     if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf);
30229252d075SMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
30239252d075SMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
30249252d075SMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
30259252d075SMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
30269252d075SMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr);
30279252d075SMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr);
30289252d075SMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr);
30299252d075SMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr);
30309252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
30319252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
30329252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
30339252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
30349252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
30359252d075SMatthew G. Knepley 
30369252d075SMatthew G. Knepley       if (g >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", g, Nf);
30379252d075SMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
30389252d075SMatthew G. Knepley       ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr);
30399252d075SMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
30409252d075SMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr);
30419252d075SMatthew G. Knepley       ierr = PetscDSSetJacobianPreconditioner(prob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr);
30429252d075SMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
30439252d075SMatthew G. Knepley     }
30449252d075SMatthew G. Knepley   }
30459252d075SMatthew G. Knepley   PetscFunctionReturn(0);
30469252d075SMatthew G. Knepley }
30479252d075SMatthew G. Knepley 
3048da51fcedSMatthew G. Knepley /*@
3049da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
3050da51fcedSMatthew G. Knepley 
3051da51fcedSMatthew G. Knepley   Not collective
3052da51fcedSMatthew G. Knepley 
3053da51fcedSMatthew G. Knepley   Input Parameter:
3054da51fcedSMatthew G. Knepley . prob - The PetscDS object
3055da51fcedSMatthew G. Knepley 
3056da51fcedSMatthew G. Knepley   Output Parameter:
3057da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
3058da51fcedSMatthew G. Knepley 
3059da51fcedSMatthew G. Knepley   Level: intermediate
3060da51fcedSMatthew G. Knepley 
30619252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
3062da51fcedSMatthew G. Knepley @*/
3063da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
3064da51fcedSMatthew G. Knepley {
30659252d075SMatthew G. Knepley   PetscInt       Nf, Ng;
3066da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
3067da51fcedSMatthew G. Knepley 
3068da51fcedSMatthew G. Knepley   PetscFunctionBegin;
3069da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3070da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
3071da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3072da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
307313903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
30749252d075SMatthew G. Knepley   ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr);
30759252d075SMatthew G. Knepley   PetscFunctionReturn(0);
30769252d075SMatthew G. Knepley }
30779252d075SMatthew G. Knepley /*@
30789252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
3079da51fcedSMatthew G. Knepley 
30809252d075SMatthew G. Knepley   Not collective
30819252d075SMatthew G. Knepley 
30829252d075SMatthew G. Knepley   Input Parameter:
30839252d075SMatthew G. Knepley . prob - The PetscDS object
30849252d075SMatthew G. Knepley 
30859252d075SMatthew G. Knepley   Output Parameter:
30869252d075SMatthew G. Knepley . newprob - The PetscDS copy
30879252d075SMatthew G. Knepley 
30889252d075SMatthew G. Knepley   Level: intermediate
30899252d075SMatthew G. Knepley 
30909252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
30919252d075SMatthew G. Knepley @*/
30929252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
30939252d075SMatthew G. Knepley {
30949252d075SMatthew G. Knepley   PetscInt           Nc;
30959252d075SMatthew G. Knepley   const PetscScalar *constants;
30969252d075SMatthew G. Knepley   PetscErrorCode     ierr;
30979252d075SMatthew G. Knepley 
30989252d075SMatthew G. Knepley   PetscFunctionBegin;
30999252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31009252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
31019252d075SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr);
31029252d075SMatthew G. Knepley   ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr);
3103da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
3104da51fcedSMatthew G. Knepley }
3105da51fcedSMatthew G. Knepley 
3106b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
3107b1353e8eSMatthew G. Knepley {
3108df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
3109b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
3110b1353e8eSMatthew G. Knepley 
3111b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
3112b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3113b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
3114b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
3115b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
3116df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
3117df3a45bdSMatthew 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);
3118df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
3119df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
3120b1353e8eSMatthew G. Knepley     PetscInt cdim;
3121b1353e8eSMatthew G. Knepley 
3122df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
3123b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
3124df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
3125b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
3126b1353e8eSMatthew G. Knepley       PetscFE      subfe;
3127b1353e8eSMatthew G. Knepley       PetscObject  obj;
3128b1353e8eSMatthew G. Knepley       PetscClassId id;
3129b1353e8eSMatthew G. Knepley 
3130b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3131b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3132b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
3133b1353e8eSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
3134df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
3135b1353e8eSMatthew G. Knepley     }
3136b1353e8eSMatthew G. Knepley   }
3137df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
3138b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
3139b1353e8eSMatthew G. Knepley }
3140b1353e8eSMatthew G. Knepley 
3141bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob)
31422764a2aaSMatthew G. Knepley {
3143931fb3b8SToby Isaac   PetscErrorCode      ierr;
3144931fb3b8SToby Isaac 
31452764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3146931fb3b8SToby Isaac   ierr = PetscFree(prob->data);CHKERRQ(ierr);
31472764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31482764a2aaSMatthew G. Knepley }
31492764a2aaSMatthew G. Knepley 
3150bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob)
31512764a2aaSMatthew G. Knepley {
31522764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31532764a2aaSMatthew G. Knepley   prob->ops->setfromoptions = NULL;
31542764a2aaSMatthew G. Knepley   prob->ops->setup          = NULL;
31552764a2aaSMatthew G. Knepley   prob->ops->view           = NULL;
31562764a2aaSMatthew G. Knepley   prob->ops->destroy        = PetscDSDestroy_Basic;
31572764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31582764a2aaSMatthew G. Knepley }
31592764a2aaSMatthew G. Knepley 
31602764a2aaSMatthew G. Knepley /*MC
31612764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
31622764a2aaSMatthew G. Knepley 
31632764a2aaSMatthew G. Knepley   Level: intermediate
31642764a2aaSMatthew G. Knepley 
31652764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
31662764a2aaSMatthew G. Knepley M*/
31672764a2aaSMatthew G. Knepley 
31682764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob)
31692764a2aaSMatthew G. Knepley {
31702764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
31712764a2aaSMatthew G. Knepley   PetscErrorCode      ierr;
31722764a2aaSMatthew G. Knepley 
31732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3174931fb3b8SToby Isaac   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31752764a2aaSMatthew G. Knepley   ierr       = PetscNewLog(prob, &b);CHKERRQ(ierr);
31762764a2aaSMatthew G. Knepley   prob->data = b;
31772764a2aaSMatthew G. Knepley 
31782764a2aaSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr);
31792764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31802764a2aaSMatthew G. Knepley }
3181